Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: ash/common/system/web_notification/web_notification_tray.cc

Issue 2755843002: Remove pre-MD code from WebNotificationTray. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
8 #include "ash/common/session/session_state_delegate.h" 7 #include "ash/common/session/session_state_delegate.h"
9 #include "ash/common/shelf/shelf_constants.h" 8 #include "ash/common/shelf/shelf_constants.h"
10 #include "ash/common/shelf/wm_shelf.h" 9 #include "ash/common/shelf/wm_shelf.h"
11 #include "ash/common/shelf/wm_shelf_util.h" 10 #include "ash/common/shelf/wm_shelf_util.h"
12 #include "ash/common/system/status_area_widget.h" 11 #include "ash/common/system/status_area_widget.h"
13 #include "ash/common/system/tray/system_tray.h" 12 #include "ash/common/system/tray/system_tray.h"
14 #include "ash/common/system/tray/system_tray_delegate.h" 13 #include "ash/common/system/tray/system_tray_delegate.h"
15 #include "ash/common/system/tray/tray_bubble_wrapper.h" 14 #include "ash/common/system/tray/tray_bubble_wrapper.h"
16 #include "ash/common/system/tray/tray_constants.h" 15 #include "ash/common/system/tray/tray_constants.h"
17 #include "ash/common/system/tray/tray_utils.h" 16 #include "ash/common/system/tray/tray_utils.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 namespace ash { 56 namespace ash {
58 namespace { 57 namespace {
59 58
60 // Menu commands 59 // Menu commands
61 constexpr int kToggleQuietMode = 0; 60 constexpr int kToggleQuietMode = 0;
62 constexpr int kEnableQuietModeDay = 2; 61 constexpr int kEnableQuietModeDay = 2;
63 62
64 constexpr int kMaximumSmallIconCount = 3; 63 constexpr int kMaximumSmallIconCount = 3;
65 64
66 constexpr gfx::Size kTrayItemInnerIconSize(16, 16); 65 constexpr gfx::Size kTrayItemInnerIconSize(16, 16);
67 constexpr gfx::Size kTrayItemInnerBellIconSizeNonMd(18, 18);
68 constexpr gfx::Size kTrayItemOuterSize(26, 26); 66 constexpr gfx::Size kTrayItemOuterSize(26, 26);
69 constexpr int kTrayMainAxisInset = 3; 67 constexpr int kTrayMainAxisInset = 3;
70 constexpr int kTrayCrossAxisInset = 0; 68 constexpr int kTrayCrossAxisInset = 0;
71 69
72 constexpr int kTrayItemAnimationDurationMS = 200; 70 constexpr int kTrayItemAnimationDurationMS = 200;
73 71
74 constexpr size_t kMaximumNotificationNumber = 99; 72 constexpr size_t kMaximumNotificationNumber = 99;
75 73
76 // Flag to disable animation. Only for testing. 74 // Flag to disable animation. Only for testing.
77 bool disable_animations_for_test = false; 75 bool disable_animations_for_test = false;
78 }
79
80 namespace {
81
82 const SkColor kWebNotificationColorNoUnread =
83 SkColorSetARGB(128, 255, 255, 255);
84 const SkColor kWebNotificationColorWithUnread = SK_ColorWHITE;
85 const int kNoUnreadIconSize = 18;
86 76
87 } // namespace 77 } // namespace
88 78
89 // Class to initialize and manage the WebNotificationBubble and 79 // Class to initialize and manage the WebNotificationBubble and
90 // TrayBubbleWrapper instances for a bubble. 80 // TrayBubbleWrapper instances for a bubble.
91 class WebNotificationBubbleWrapper { 81 class WebNotificationBubbleWrapper {
92 public: 82 public:
93 // Takes ownership of |bubble| and creates |bubble_wrapper_|. 83 // Takes ownership of |bubble| and creates |bubble_wrapper_|.
94 WebNotificationBubbleWrapper(WebNotificationTray* tray, 84 WebNotificationBubbleWrapper(WebNotificationTray* tray,
95 TrayBackgroundView* anchor_tray, 85 TrayBackgroundView* anchor_tray,
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 std::unique_ptr<gfx::SlideAnimation> animation_; 215 std::unique_ptr<gfx::SlideAnimation> animation_;
226 bool delete_after_animation_ = false; 216 bool delete_after_animation_ = false;
227 WebNotificationTray* tray_; 217 WebNotificationTray* tray_;
228 218
229 DISALLOW_COPY_AND_ASSIGN(WebNotificationItem); 219 DISALLOW_COPY_AND_ASSIGN(WebNotificationItem);
230 }; 220 };
231 221
232 class WebNotificationImage : public WebNotificationItem { 222 class WebNotificationImage : public WebNotificationItem {
233 public: 223 public:
234 WebNotificationImage(const gfx::ImageSkia& image, 224 WebNotificationImage(const gfx::ImageSkia& image,
235 const gfx::Size& size,
236 gfx::AnimationContainer* container, 225 gfx::AnimationContainer* container,
237 WebNotificationTray* tray) 226 WebNotificationTray* tray)
238 : WebNotificationItem(container, tray) { 227 : WebNotificationItem(container, tray) {
239 view_ = new views::ImageView(); 228 view_ = new views::ImageView();
240 view_->SetImage(image); 229 view_->SetImage(image);
241 view_->SetImageSize(size); 230 view_->SetImageSize(kTrayItemInnerIconSize);
242 AddChildView(view_); 231 AddChildView(view_);
243 } 232 }
244 233
245 private: 234 private:
246 views::ImageView* view_; 235 views::ImageView* view_;
247 236
248 DISALLOW_COPY_AND_ASSIGN(WebNotificationImage); 237 DISALLOW_COPY_AND_ASSIGN(WebNotificationImage);
249 }; 238 };
250 239
251 class WebNotificationLabel : public WebNotificationItem { 240 class WebNotificationLabel : public WebNotificationItem {
(...skipping 13 matching lines...) Expand all
265 // TODO(yoshiki): Use a string for "99" and "+99". 254 // TODO(yoshiki): Use a string for "99" and "+99".
266 255
267 base::string16 str = base::FormatNumber(notification_count); 256 base::string16 str = base::FormatNumber(notification_count);
268 if (small_icons_exist) { 257 if (small_icons_exist) {
269 str = base::ASCIIToUTF16("+") + str; 258 str = base::ASCIIToUTF16("+") + str;
270 if (base::i18n::IsRTL()) 259 if (base::i18n::IsRTL())
271 base::i18n::WrapStringWithRTLFormatting(&str); 260 base::i18n::WrapStringWithRTLFormatting(&str);
272 } 261 }
273 262
274 view_->SetText(str); 263 view_->SetText(str);
275 view_->SetEnabledColor(kWebNotificationColorWithUnread);
Evan Stade 2017/03/16 00:41:58 this isn't necessary because the label's default c
276 SchedulePaint(); 264 SchedulePaint();
277 } 265 }
278 266
279 private: 267 private:
280 views::Label* view_; 268 views::Label* view_;
281 269
282 DISALLOW_COPY_AND_ASSIGN(WebNotificationLabel); 270 DISALLOW_COPY_AND_ASSIGN(WebNotificationLabel);
283 }; 271 };
284 272
285 WebNotificationTray::WebNotificationTray(WmShelf* shelf, 273 WebNotificationTray::WebNotificationTray(WmShelf* shelf,
286 WmWindow* status_area_window, 274 WmWindow* status_area_window,
287 SystemTray* system_tray) 275 SystemTray* system_tray)
288 : TrayBackgroundView(shelf, true), 276 : TrayBackgroundView(shelf, true),
289 status_area_window_(status_area_window), 277 status_area_window_(status_area_window),
290 system_tray_(system_tray), 278 system_tray_(system_tray),
291 show_message_center_on_unlock_(false), 279 show_message_center_on_unlock_(false),
292 should_update_tray_content_(false), 280 should_update_tray_content_(false),
293 should_block_shelf_auto_hide_(false) { 281 should_block_shelf_auto_hide_(false) {
294 DCHECK(shelf); 282 DCHECK(shelf);
295 DCHECK(status_area_window_); 283 DCHECK(status_area_window_);
296 DCHECK(system_tray_); 284 DCHECK(system_tray_);
297 285
298 if (MaterialDesignController::IsShelfMaterial()) { 286 SetInkDropMode(InkDropMode::ON);
299 SetInkDropMode(InkDropMode::ON); 287 gfx::ImageSkia bell_image =
300 gfx::ImageSkia bell_image = 288 CreateVectorIcon(kShelfNotificationsIcon, kShelfIconColor);
301 CreateVectorIcon(kShelfNotificationsIcon, kShelfIconColor); 289 bell_icon_.reset(
302 const gfx::Size bell_icon_size = kTrayItemInnerIconSize; 290 new WebNotificationImage(bell_image, animation_container_.get(), this));
303 bell_icon_.reset(new WebNotificationImage(
304 bell_image, bell_icon_size, animation_container_.get(), this));
305 } else {
306 gfx::ImageSkia bell_image =
307 CreateVectorIcon(ui::kNotificationsIcon, kNoUnreadIconSize,
308 kWebNotificationColorNoUnread);
309 const gfx::Size bell_icon_size = kTrayItemInnerBellIconSizeNonMd;
310 bell_icon_.reset(new WebNotificationImage(
311 bell_image, bell_icon_size, animation_container_.get(), this));
312 }
313 tray_container()->AddChildView(bell_icon_.get()); 291 tray_container()->AddChildView(bell_icon_.get());
314 292
315 counter_.reset(new WebNotificationLabel(animation_container_.get(), this)); 293 counter_.reset(new WebNotificationLabel(animation_container_.get(), this));
316 tray_container()->AddChildView(counter_.get()); 294 tray_container()->AddChildView(counter_.get());
317 295
318 message_center_tray_.reset(new message_center::MessageCenterTray( 296 message_center_tray_.reset(new message_center::MessageCenterTray(
319 this, message_center::MessageCenter::Get())); 297 this, message_center::MessageCenter::Get()));
320 popup_alignment_delegate_.reset(new AshPopupAlignmentDelegate(shelf)); 298 popup_alignment_delegate_.reset(new AshPopupAlignmentDelegate(shelf));
321 popup_collection_.reset(new message_center::MessagePopupCollection( 299 popup_collection_.reset(new message_center::MessagePopupCollection(
322 message_center(), message_center_tray_.get(), 300 message_center(), message_center_tray_.get(),
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 continue; 554 continue;
577 555
578 if (visible_small_icon_count >= kMaximumSmallIconCount) 556 if (visible_small_icon_count >= kMaximumSmallIconCount)
579 break; 557 break;
580 visible_small_icon_count++; 558 visible_small_icon_count++;
581 559
582 notification_ids.erase(notification->id()); 560 notification_ids.erase(notification->id());
583 if (visible_small_icons_.count(notification->id()) != 0) 561 if (visible_small_icons_.count(notification->id()) != 0)
584 continue; 562 continue;
585 563
586 auto* item = 564 auto* item = new WebNotificationImage(image.AsImageSkia(),
587 new WebNotificationImage(image.AsImageSkia(), kTrayItemInnerIconSize, 565 animation_container_.get(), this);
588 animation_container_.get(), this);
589 visible_small_icons_.insert(std::make_pair(notification->id(), item)); 566 visible_small_icons_.insert(std::make_pair(notification->id(), item));
590 567
591 tray_container()->AddChildViewAt(item, 0); 568 tray_container()->AddChildViewAt(item, 0);
592 item->SetVisible(true); 569 item->SetVisible(true);
593 } 570 }
594 571
595 // Remove unnecessary icons. 572 // Remove unnecessary icons.
596 for (const std::string& id : notification_ids) { 573 for (const std::string& id : notification_ids) {
597 WebNotificationImage* item = visible_small_icons_[id]; 574 WebNotificationImage* item = visible_small_icons_[id];
598 visible_small_icons_.erase(id); 575 visible_small_icons_.erase(id);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 627
651 message_center::MessageCenterBubble* 628 message_center::MessageCenterBubble*
652 WebNotificationTray::GetMessageCenterBubbleForTest() { 629 WebNotificationTray::GetMessageCenterBubbleForTest() {
653 if (!message_center_bubble()) 630 if (!message_center_bubble())
654 return nullptr; 631 return nullptr;
655 return static_cast<message_center::MessageCenterBubble*>( 632 return static_cast<message_center::MessageCenterBubble*>(
656 message_center_bubble()->bubble()); 633 message_center_bubble()->bubble());
657 } 634 }
658 635
659 } // namespace ash 636 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698