| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/common/system/web_notification/web_notification_tray.h" | 5 #include "ash/common/system/web_notification/web_notification_tray.h" |
| 6 | 6 |
| 7 #include "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
| 8 #include "ash/common/session/session_state_delegate.h" | 8 #include "ash/common/session/session_state_delegate.h" |
| 9 #include "ash/common/shelf/shelf_constants.h" | 9 #include "ash/common/shelf/shelf_constants.h" |
| 10 #include "ash/common/shelf/wm_shelf.h" | 10 #include "ash/common/shelf/wm_shelf.h" |
| 11 #include "ash/common/shelf/wm_shelf_util.h" | 11 #include "ash/common/shelf/wm_shelf_util.h" |
| 12 #include "ash/common/shell_window_ids.h" | 12 #include "ash/common/shell_window_ids.h" |
| 13 #include "ash/common/system/tray/system_tray.h" | 13 #include "ash/common/system/tray/system_tray.h" |
| 14 #include "ash/common/system/tray/system_tray_delegate.h" | 14 #include "ash/common/system/tray/system_tray_delegate.h" |
| 15 #include "ash/common/system/tray/tray_bubble_wrapper.h" | 15 #include "ash/common/system/tray/tray_bubble_wrapper.h" |
| 16 #include "ash/common/system/tray/tray_constants.h" | 16 #include "ash/common/system/tray/tray_constants.h" |
| 17 #include "ash/common/system/tray/tray_utils.h" | 17 #include "ash/common/system/tray/tray_utils.h" |
| 18 #include "ash/common/system/web_notification/ash_popup_alignment_delegate.h" | 18 #include "ash/common/system/web_notification/ash_popup_alignment_delegate.h" |
| 19 #include "ash/common/wm_lookup.h" | 19 #include "ash/common/wm_lookup.h" |
| 20 #include "ash/common/wm_root_window_controller.h" | 20 #include "ash/common/wm_root_window_controller.h" |
| 21 #include "ash/common/wm_shell.h" | 21 #include "ash/common/wm_shell.h" |
| 22 #include "ash/common/wm_window.h" | 22 #include "ash/common/wm_window.h" |
| 23 #include "ash/resources/vector_icons/vector_icons.h" |
| 23 #include "base/auto_reset.h" | 24 #include "base/auto_reset.h" |
| 24 #include "base/i18n/number_formatting.h" | 25 #include "base/i18n/number_formatting.h" |
| 25 #include "base/i18n/rtl.h" | 26 #include "base/i18n/rtl.h" |
| 26 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
| 27 #include "base/threading/thread_task_runner_handle.h" | 28 #include "base/threading/thread_task_runner_handle.h" |
| 28 #include "grit/ash_strings.h" | 29 #include "grit/ash_strings.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "ui/display/display.h" | 31 #include "ui/display/display.h" |
| 31 #include "ui/display/screen.h" | 32 #include "ui/display/screen.h" |
| 32 #include "ui/gfx/paint_vector_icon.h" | 33 #include "ui/gfx/paint_vector_icon.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 43 #include "ui/views/controls/menu/menu_runner.h" | 44 #include "ui/views/controls/menu/menu_runner.h" |
| 44 #include "ui/views/layout/fill_layout.h" | 45 #include "ui/views/layout/fill_layout.h" |
| 45 | 46 |
| 46 #if defined(OS_CHROMEOS) | 47 #if defined(OS_CHROMEOS) |
| 47 | 48 |
| 48 namespace message_center { | 49 namespace message_center { |
| 49 | 50 |
| 50 MessageCenterTrayDelegate* CreateMessageCenterTray() { | 51 MessageCenterTrayDelegate* CreateMessageCenterTray() { |
| 51 // On Windows+Ash the Tray will not be hosted in ash::Shell. | 52 // On Windows+Ash the Tray will not be hosted in ash::Shell. |
| 52 NOTREACHED(); | 53 NOTREACHED(); |
| 53 return NULL; | 54 return nullptr; |
| 54 } | 55 } |
| 55 | 56 |
| 56 } // namespace message_center | 57 } // namespace message_center |
| 57 | 58 |
| 58 #endif // defined(OS_CHROMEOS) | 59 #endif // defined(OS_CHROMEOS) |
| 59 | 60 |
| 60 namespace ash { | 61 namespace ash { |
| 61 namespace { | 62 namespace { |
| 62 | 63 |
| 63 // Menu commands | 64 // Menu commands |
| 64 constexpr int kToggleQuietMode = 0; | 65 constexpr int kToggleQuietMode = 0; |
| 65 constexpr int kEnableQuietModeDay = 2; | 66 constexpr int kEnableQuietModeDay = 2; |
| 66 | 67 |
| 67 constexpr int kMaximumSmallIconCount = 3; | 68 constexpr int kMaximumSmallIconCount = 3; |
| 68 | 69 |
| 69 constexpr gfx::Size kTrayItemInnerIconSize(16, 16); | |
| 70 constexpr gfx::Size kTrayItemInnerBellIconSize(18, 18); | |
| 71 constexpr gfx::Size kTrayItemOuterSize(26, 26); | 70 constexpr gfx::Size kTrayItemOuterSize(26, 26); |
| 72 constexpr gfx::Insets kTrayItemInsets(3, 3); | 71 constexpr gfx::Insets kTrayItemInsets(3, 3); |
| 73 | 72 |
| 74 constexpr int kTrayItemAnimationDurationMS = 200; | 73 constexpr int kTrayItemAnimationDurationMS = 200; |
| 75 | 74 |
| 76 constexpr size_t kMaximumNotificationNumber = 99; | 75 constexpr size_t kMaximumNotificationNumber = 99; |
| 77 | 76 |
| 78 // Flag to disable animation. Only for testing. | 77 // Flag to disable animation. Only for testing. |
| 79 bool disable_animations_for_test = false; | 78 bool disable_animations_for_test = false; |
| 80 } | 79 } |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 std::unique_ptr<gfx::SlideAnimation> animation_; | 233 std::unique_ptr<gfx::SlideAnimation> animation_; |
| 235 bool delete_after_animation_ = false; | 234 bool delete_after_animation_ = false; |
| 236 WebNotificationTray* tray_; | 235 WebNotificationTray* tray_; |
| 237 | 236 |
| 238 DISALLOW_COPY_AND_ASSIGN(WebNotificationItem); | 237 DISALLOW_COPY_AND_ASSIGN(WebNotificationItem); |
| 239 }; | 238 }; |
| 240 | 239 |
| 241 class WebNotificationImage : public WebNotificationItem { | 240 class WebNotificationImage : public WebNotificationItem { |
| 242 public: | 241 public: |
| 243 WebNotificationImage(const gfx::ImageSkia& image, | 242 WebNotificationImage(const gfx::ImageSkia& image, |
| 244 gfx::Size size, | |
| 245 gfx::AnimationContainer* container, | 243 gfx::AnimationContainer* container, |
| 246 WebNotificationTray* tray) | 244 WebNotificationTray* tray) |
| 247 : WebNotificationItem(container, tray) { | 245 : WebNotificationItem(container, tray) { |
| 248 view_ = new views::ImageView(); | 246 view_ = new views::ImageView(); |
| 249 view_->SetImage(image); | 247 view_->SetImage(image); |
| 250 view_->SetImageSize(size); | |
| 251 AddChildView(view_); | 248 AddChildView(view_); |
| 252 } | 249 } |
| 253 | 250 |
| 254 private: | 251 private: |
| 255 views::ImageView* view_; | 252 views::ImageView* view_; |
| 256 | 253 |
| 257 DISALLOW_COPY_AND_ASSIGN(WebNotificationImage); | 254 DISALLOW_COPY_AND_ASSIGN(WebNotificationImage); |
| 258 }; | 255 }; |
| 259 | 256 |
| 260 class WebNotificationLabel : public WebNotificationItem { | 257 class WebNotificationLabel : public WebNotificationItem { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 : TrayBackgroundView(shelf), | 295 : TrayBackgroundView(shelf), |
| 299 status_area_window_(status_area_window), | 296 status_area_window_(status_area_window), |
| 300 system_tray_(system_tray), | 297 system_tray_(system_tray), |
| 301 show_message_center_on_unlock_(false), | 298 show_message_center_on_unlock_(false), |
| 302 should_update_tray_content_(false), | 299 should_update_tray_content_(false), |
| 303 should_block_shelf_auto_hide_(false) { | 300 should_block_shelf_auto_hide_(false) { |
| 304 DCHECK(shelf); | 301 DCHECK(shelf); |
| 305 DCHECK(status_area_window_); | 302 DCHECK(status_area_window_); |
| 306 DCHECK(system_tray_); | 303 DCHECK(system_tray_); |
| 307 | 304 |
| 308 gfx::ImageSkia bell_image; | 305 gfx::ImageSkia bell_image = |
| 309 if (MaterialDesignController::IsShelfMaterial()) { | 306 MaterialDesignController::IsShelfMaterial() |
| 310 bell_image = CreateVectorIcon(gfx::VectorIconId::SHELF_NOTIFICATIONS, | 307 ? CreateVectorIcon(kShelfNotificationsIcon, kShelfIconColor) |
| 311 kShelfIconColor); | 308 : CreateVectorIcon(gfx::VectorIconId::NOTIFICATIONS, |
| 312 } else { | 309 kNoUnreadIconSize, kWebNotificationColorNoUnread); |
| 313 bell_image = | |
| 314 CreateVectorIcon(gfx::VectorIconId::NOTIFICATIONS, kNoUnreadIconSize, | |
| 315 kWebNotificationColorNoUnread); | |
| 316 } | |
| 317 bell_icon_.reset(new WebNotificationImage(bell_image, | 310 bell_icon_.reset(new WebNotificationImage(bell_image, |
| 318 kTrayItemInnerBellIconSize, | |
| 319 animation_container_.get(), this)); | 311 animation_container_.get(), this)); |
| 320 tray_container()->AddChildView(bell_icon_.get()); | 312 tray_container()->AddChildView(bell_icon_.get()); |
| 321 | 313 |
| 322 counter_.reset(new WebNotificationLabel(animation_container_.get(), this)); | 314 counter_.reset(new WebNotificationLabel(animation_container_.get(), this)); |
| 323 tray_container()->AddChildView(counter_.get()); | 315 tray_container()->AddChildView(counter_.get()); |
| 324 | 316 |
| 325 SetContentsBackground(); | 317 SetContentsBackground(); |
| 326 message_center_tray_.reset(new message_center::MessageCenterTray( | 318 message_center_tray_.reset(new message_center::MessageCenterTray( |
| 327 this, message_center::MessageCenter::Get())); | 319 this, message_center::MessageCenter::Get())); |
| 328 popup_alignment_delegate_.reset(new AshPopupAlignmentDelegate(shelf)); | 320 popup_alignment_delegate_.reset(new AshPopupAlignmentDelegate(shelf)); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 continue; | 585 continue; |
| 594 | 586 |
| 595 if (visible_small_icon_count >= kMaximumSmallIconCount) | 587 if (visible_small_icon_count >= kMaximumSmallIconCount) |
| 596 break; | 588 break; |
| 597 visible_small_icon_count++; | 589 visible_small_icon_count++; |
| 598 | 590 |
| 599 notification_ids.erase(notification->id()); | 591 notification_ids.erase(notification->id()); |
| 600 if (visible_small_icons_.count(notification->id()) != 0) | 592 if (visible_small_icons_.count(notification->id()) != 0) |
| 601 continue; | 593 continue; |
| 602 | 594 |
| 603 auto* item = | 595 auto* item = new WebNotificationImage(image.AsImageSkia(), |
| 604 new WebNotificationImage(image.AsImageSkia(), kTrayItemInnerIconSize, | 596 animation_container_.get(), this); |
| 605 animation_container_.get(), this); | |
| 606 visible_small_icons_.insert(std::make_pair(notification->id(), item)); | 597 visible_small_icons_.insert(std::make_pair(notification->id(), item)); |
| 607 | 598 |
| 608 tray_container()->AddChildViewAt(item, 0); | 599 tray_container()->AddChildViewAt(item, 0); |
| 609 item->SetVisible(true); | 600 item->SetVisible(true); |
| 610 } | 601 } |
| 611 | 602 |
| 612 // Remove unnecessary icons. | 603 // Remove unnecessary icons. |
| 613 for (const std::string& id : notification_ids) { | 604 for (const std::string& id : notification_ids) { |
| 614 WebNotificationImage* item = visible_small_icons_[id]; | 605 WebNotificationImage* item = visible_small_icons_[id]; |
| 615 visible_small_icons_.erase(id); | 606 visible_small_icons_.erase(id); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 | 652 |
| 662 // Methods for testing | 653 // Methods for testing |
| 663 | 654 |
| 664 bool WebNotificationTray::IsPopupVisible() const { | 655 bool WebNotificationTray::IsPopupVisible() const { |
| 665 return message_center_tray_->popups_visible(); | 656 return message_center_tray_->popups_visible(); |
| 666 } | 657 } |
| 667 | 658 |
| 668 message_center::MessageCenterBubble* | 659 message_center::MessageCenterBubble* |
| 669 WebNotificationTray::GetMessageCenterBubbleForTest() { | 660 WebNotificationTray::GetMessageCenterBubbleForTest() { |
| 670 if (!message_center_bubble()) | 661 if (!message_center_bubble()) |
| 671 return NULL; | 662 return nullptr; |
| 672 return static_cast<message_center::MessageCenterBubble*>( | 663 return static_cast<message_center::MessageCenterBubble*>( |
| 673 message_center_bubble()->bubble()); | 664 message_center_bubble()->bubble()); |
| 674 } | 665 } |
| 675 | 666 |
| 676 } // namespace ash | 667 } // namespace ash |
| OLD | NEW |