| 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" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 namespace ash { | 61 namespace ash { |
| 62 namespace { | 62 namespace { |
| 63 | 63 |
| 64 // Menu commands | 64 // Menu commands |
| 65 constexpr int kToggleQuietMode = 0; | 65 constexpr int kToggleQuietMode = 0; |
| 66 constexpr int kEnableQuietModeDay = 2; | 66 constexpr int kEnableQuietModeDay = 2; |
| 67 | 67 |
| 68 constexpr int kMaximumSmallIconCount = 3; | 68 constexpr int kMaximumSmallIconCount = 3; |
| 69 | 69 |
| 70 constexpr gfx::Size kTrayItemInnerIconSize(16, 16); |
| 71 constexpr gfx::Size kTrayItemInnerBellIconSizeNonMd(18, 18); |
| 70 constexpr gfx::Size kTrayItemOuterSize(26, 26); | 72 constexpr gfx::Size kTrayItemOuterSize(26, 26); |
| 71 constexpr gfx::Insets kTrayItemInsets(3, 3); | 73 constexpr gfx::Insets kTrayItemInsets(3, 3); |
| 72 | 74 |
| 73 constexpr int kTrayItemAnimationDurationMS = 200; | 75 constexpr int kTrayItemAnimationDurationMS = 200; |
| 74 | 76 |
| 75 constexpr size_t kMaximumNotificationNumber = 99; | 77 constexpr size_t kMaximumNotificationNumber = 99; |
| 76 | 78 |
| 77 // Flag to disable animation. Only for testing. | 79 // Flag to disable animation. Only for testing. |
| 78 bool disable_animations_for_test = false; | 80 bool disable_animations_for_test = false; |
| 79 } | 81 } |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 std::unique_ptr<gfx::SlideAnimation> animation_; | 235 std::unique_ptr<gfx::SlideAnimation> animation_; |
| 234 bool delete_after_animation_ = false; | 236 bool delete_after_animation_ = false; |
| 235 WebNotificationTray* tray_; | 237 WebNotificationTray* tray_; |
| 236 | 238 |
| 237 DISALLOW_COPY_AND_ASSIGN(WebNotificationItem); | 239 DISALLOW_COPY_AND_ASSIGN(WebNotificationItem); |
| 238 }; | 240 }; |
| 239 | 241 |
| 240 class WebNotificationImage : public WebNotificationItem { | 242 class WebNotificationImage : public WebNotificationItem { |
| 241 public: | 243 public: |
| 242 WebNotificationImage(const gfx::ImageSkia& image, | 244 WebNotificationImage(const gfx::ImageSkia& image, |
| 245 const gfx::Size& size, |
| 243 gfx::AnimationContainer* container, | 246 gfx::AnimationContainer* container, |
| 244 WebNotificationTray* tray) | 247 WebNotificationTray* tray) |
| 245 : WebNotificationItem(container, tray) { | 248 : WebNotificationItem(container, tray) { |
| 246 view_ = new views::ImageView(); | 249 view_ = new views::ImageView(); |
| 247 view_->SetImage(image); | 250 view_->SetImage(image); |
| 251 view_->SetImageSize(size); |
| 248 AddChildView(view_); | 252 AddChildView(view_); |
| 249 } | 253 } |
| 250 | 254 |
| 251 private: | 255 private: |
| 252 views::ImageView* view_; | 256 views::ImageView* view_; |
| 253 | 257 |
| 254 DISALLOW_COPY_AND_ASSIGN(WebNotificationImage); | 258 DISALLOW_COPY_AND_ASSIGN(WebNotificationImage); |
| 255 }; | 259 }; |
| 256 | 260 |
| 257 class WebNotificationLabel : public WebNotificationItem { | 261 class WebNotificationLabel : public WebNotificationItem { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 : TrayBackgroundView(shelf), | 299 : TrayBackgroundView(shelf), |
| 296 status_area_window_(status_area_window), | 300 status_area_window_(status_area_window), |
| 297 system_tray_(system_tray), | 301 system_tray_(system_tray), |
| 298 show_message_center_on_unlock_(false), | 302 show_message_center_on_unlock_(false), |
| 299 should_update_tray_content_(false), | 303 should_update_tray_content_(false), |
| 300 should_block_shelf_auto_hide_(false) { | 304 should_block_shelf_auto_hide_(false) { |
| 301 DCHECK(shelf); | 305 DCHECK(shelf); |
| 302 DCHECK(status_area_window_); | 306 DCHECK(status_area_window_); |
| 303 DCHECK(system_tray_); | 307 DCHECK(system_tray_); |
| 304 | 308 |
| 309 const bool md_shelf = MaterialDesignController::IsShelfMaterial(); |
| 305 gfx::ImageSkia bell_image = | 310 gfx::ImageSkia bell_image = |
| 306 MaterialDesignController::IsShelfMaterial() | 311 md_shelf |
| 307 ? CreateVectorIcon(kShelfNotificationsIcon, kShelfIconColor) | 312 ? CreateVectorIcon(kShelfNotificationsIcon, kShelfIconColor) |
| 308 : CreateVectorIcon(gfx::VectorIconId::NOTIFICATIONS, | 313 : CreateVectorIcon(gfx::VectorIconId::NOTIFICATIONS, |
| 309 kNoUnreadIconSize, kWebNotificationColorNoUnread); | 314 kNoUnreadIconSize, kWebNotificationColorNoUnread); |
| 310 bell_icon_.reset(new WebNotificationImage(bell_image, | 315 const gfx::Size bell_icon_size = |
| 316 md_shelf ? kTrayItemInnerIconSize : kTrayItemInnerBellIconSizeNonMd; |
| 317 bell_icon_.reset(new WebNotificationImage(bell_image, bell_icon_size, |
| 311 animation_container_.get(), this)); | 318 animation_container_.get(), this)); |
| 312 tray_container()->AddChildView(bell_icon_.get()); | 319 tray_container()->AddChildView(bell_icon_.get()); |
| 313 | 320 |
| 314 counter_.reset(new WebNotificationLabel(animation_container_.get(), this)); | 321 counter_.reset(new WebNotificationLabel(animation_container_.get(), this)); |
| 315 tray_container()->AddChildView(counter_.get()); | 322 tray_container()->AddChildView(counter_.get()); |
| 316 | 323 |
| 317 SetContentsBackground(); | 324 SetContentsBackground(); |
| 318 message_center_tray_.reset(new message_center::MessageCenterTray( | 325 message_center_tray_.reset(new message_center::MessageCenterTray( |
| 319 this, message_center::MessageCenter::Get())); | 326 this, message_center::MessageCenter::Get())); |
| 320 popup_alignment_delegate_.reset(new AshPopupAlignmentDelegate(shelf)); | 327 popup_alignment_delegate_.reset(new AshPopupAlignmentDelegate(shelf)); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 continue; | 592 continue; |
| 586 | 593 |
| 587 if (visible_small_icon_count >= kMaximumSmallIconCount) | 594 if (visible_small_icon_count >= kMaximumSmallIconCount) |
| 588 break; | 595 break; |
| 589 visible_small_icon_count++; | 596 visible_small_icon_count++; |
| 590 | 597 |
| 591 notification_ids.erase(notification->id()); | 598 notification_ids.erase(notification->id()); |
| 592 if (visible_small_icons_.count(notification->id()) != 0) | 599 if (visible_small_icons_.count(notification->id()) != 0) |
| 593 continue; | 600 continue; |
| 594 | 601 |
| 595 auto* item = new WebNotificationImage(image.AsImageSkia(), | 602 auto* item = |
| 596 animation_container_.get(), this); | 603 new WebNotificationImage(image.AsImageSkia(), kTrayItemInnerIconSize, |
| 604 animation_container_.get(), this); |
| 597 visible_small_icons_.insert(std::make_pair(notification->id(), item)); | 605 visible_small_icons_.insert(std::make_pair(notification->id(), item)); |
| 598 | 606 |
| 599 tray_container()->AddChildViewAt(item, 0); | 607 tray_container()->AddChildViewAt(item, 0); |
| 600 item->SetVisible(true); | 608 item->SetVisible(true); |
| 601 } | 609 } |
| 602 | 610 |
| 603 // Remove unnecessary icons. | 611 // Remove unnecessary icons. |
| 604 for (const std::string& id : notification_ids) { | 612 for (const std::string& id : notification_ids) { |
| 605 WebNotificationImage* item = visible_small_icons_[id]; | 613 WebNotificationImage* item = visible_small_icons_[id]; |
| 606 visible_small_icons_.erase(id); | 614 visible_small_icons_.erase(id); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 | 666 |
| 659 message_center::MessageCenterBubble* | 667 message_center::MessageCenterBubble* |
| 660 WebNotificationTray::GetMessageCenterBubbleForTest() { | 668 WebNotificationTray::GetMessageCenterBubbleForTest() { |
| 661 if (!message_center_bubble()) | 669 if (!message_center_bubble()) |
| 662 return nullptr; | 670 return nullptr; |
| 663 return static_cast<message_center::MessageCenterBubble*>( | 671 return static_cast<message_center::MessageCenterBubble*>( |
| 664 message_center_bubble()->bubble()); | 672 message_center_bubble()->bubble()); |
| 665 } | 673 } |
| 666 | 674 |
| 667 } // namespace ash | 675 } // namespace ash |
| OLD | NEW |