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

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

Issue 19291004: Observes work area change and auto-hide for notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
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/system/web_notification/web_notification_tray.h" 5 #include "ash/system/web_notification/web_notification_tray.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/root_window_controller.h" 8 #include "ash/root_window_controller.h"
9 #include "ash/shelf/shelf_layout_manager.h" 9 #include "ash/shelf/shelf_layout_manager.h"
10 #include "ash/shelf/shelf_layout_manager_observer.h"
11 #include "ash/shelf/shelf_widget.h"
10 #include "ash/shell.h" 12 #include "ash/shell.h"
11 #include "ash/shell_window_ids.h" 13 #include "ash/shell_window_ids.h"
12 #include "ash/system/status_area_widget.h" 14 #include "ash/system/status_area_widget.h"
13 #include "ash/system/tray/system_tray.h" 15 #include "ash/system/tray/system_tray.h"
14 #include "ash/system/tray/tray_background_view.h" 16 #include "ash/system/tray/tray_background_view.h"
15 #include "ash/system/tray/tray_bubble_wrapper.h" 17 #include "ash/system/tray/tray_bubble_wrapper.h"
16 #include "ash/system/tray/tray_constants.h" 18 #include "ash/system/tray/tray_constants.h"
17 #include "ash/system/tray/tray_utils.h" 19 #include "ash/system/tray/tray_utils.h"
18 #include "base/auto_reset.h" 20 #include "base/auto_reset.h"
19 #include "base/i18n/number_formatting.h" 21 #include "base/i18n/number_formatting.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 58
57 const int kWebNotificationIconSize = 31; 59 const int kWebNotificationIconSize = 31;
58 // Height of the art assets used in alternate shelf layout, 60 // Height of the art assets used in alternate shelf layout,
59 // see ash/ash_switches.h:UseAlternateShelfLayout. 61 // see ash/ash_switches.h:UseAlternateShelfLayout.
60 const int kWebNotificationAlternateSize = 38; 62 const int kWebNotificationAlternateSize = 38;
61 const SkColor kWebNotificationColorNoUnread = SkColorSetA(SK_ColorWHITE, 128); 63 const SkColor kWebNotificationColorNoUnread = SkColorSetA(SK_ColorWHITE, 128);
62 const SkColor kWebNotificationColorWithUnread = SK_ColorWHITE; 64 const SkColor kWebNotificationColorWithUnread = SK_ColorWHITE;
63 65
64 } 66 }
65 67
68 // Observes the change of work area (including temporary change by auto-hide)
69 // and notifies to MessagePopupCollection.
70 class WorkAreaObserver : public ShelfLayoutManagerObserver,
71 public ShellObserver {
72 public:
73 WorkAreaObserver(message_center::MessagePopupCollection* collection,
74 ShelfLayoutManager* shelf);
75 virtual ~WorkAreaObserver();
76
77 // Overridden from ShellObserver:
78 virtual void OnDisplayWorkAreaInsetsChanged() OVERRIDE;
79
80 // Overridden from ShelfLayoutManagerObserver:
81 virtual void OnAutoHideStateChanged(ShelfAutoHideState new_state) OVERRIDE;
82
83 private:
84 message_center::MessagePopupCollection* collection_;
85 ShelfLayoutManager* shelf_;
86
87 DISALLOW_COPY_AND_ASSIGN(WorkAreaObserver);
88 };
89
90 WorkAreaObserver::WorkAreaObserver(
91 message_center::MessagePopupCollection* collection,
92 ShelfLayoutManager* shelf)
93 : collection_(collection),
94 shelf_(shelf) {
95 DCHECK(collection_);
96 shelf_->AddObserver(this);
97 Shell::GetInstance()->AddShellObserver(this);
98 }
99
100 WorkAreaObserver::~WorkAreaObserver() {
101 Shell::GetInstance()->RemoveShellObserver(this);
102 shelf_->RemoveObserver(this);
103 }
104
105 void WorkAreaObserver::OnDisplayWorkAreaInsetsChanged() {
106 collection_->OnDisplayBoundsChanged(
107 Shell::GetScreen()->GetDisplayNearestWindow(
108 shelf_->shelf_widget()->GetNativeView()));
109 }
110
111 void WorkAreaObserver::OnAutoHideStateChanged(ShelfAutoHideState new_state) {
112 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow(
113 shelf_->shelf_widget()->GetNativeView()).work_area();
114 int width = (new_state == SHELF_AUTO_HIDE_HIDDEN) ?
115 ShelfLayoutManager::kAutoHideSize :
116 ShelfLayoutManager::GetPreferredShelfSize();
117 switch (shelf_->GetAlignment()) {
118 case SHELF_ALIGNMENT_BOTTOM:
119 work_area.Inset(0, 0, 0, width);
120 break;
121 case SHELF_ALIGNMENT_LEFT:
122 work_area.Inset(width, 0, 0, 0);
123 break;
124 case SHELF_ALIGNMENT_RIGHT:
125 work_area.Inset(0, 0, width, 0);
126 break;
127 case SHELF_ALIGNMENT_TOP:
128 work_area.Inset(0, width, 0, 0);
129 break;
130 }
131 collection_->SetWorkArea(work_area);
132 }
133
66 // Class to initialize and manage the WebNotificationBubble and 134 // Class to initialize and manage the WebNotificationBubble and
67 // TrayBubbleWrapper instances for a bubble. 135 // TrayBubbleWrapper instances for a bubble.
68
69 class WebNotificationBubbleWrapper { 136 class WebNotificationBubbleWrapper {
70 public: 137 public:
71 // Takes ownership of |bubble| and creates |bubble_wrapper_|. 138 // Takes ownership of |bubble| and creates |bubble_wrapper_|.
72 WebNotificationBubbleWrapper(WebNotificationTray* tray, 139 WebNotificationBubbleWrapper(WebNotificationTray* tray,
73 message_center::MessageBubbleBase* bubble) { 140 message_center::MessageBubbleBase* bubble) {
74 bubble_.reset(bubble); 141 bubble_.reset(bubble);
75 views::TrayBubbleView::AnchorAlignment anchor_alignment = 142 views::TrayBubbleView::AnchorAlignment anchor_alignment =
76 tray->GetAnchorAlignment(); 143 tray->GetAnchorAlignment();
77 views::TrayBubbleView::InitParams init_params = 144 views::TrayBubbleView::InitParams init_params =
78 bubble->GetInitParams(anchor_alignment); 145 bubble->GetInitParams(anchor_alignment);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 SetVisible(false); 242 SetVisible(false);
176 message_center_tray_.reset(new message_center::MessageCenterTray( 243 message_center_tray_.reset(new message_center::MessageCenterTray(
177 this, 244 this,
178 message_center::MessageCenter::Get())); 245 message_center::MessageCenter::Get()));
179 OnMessageCenterTrayChanged(); 246 OnMessageCenterTrayChanged();
180 } 247 }
181 248
182 WebNotificationTray::~WebNotificationTray() { 249 WebNotificationTray::~WebNotificationTray() {
183 // Release any child views that might have back pointers before ~View(). 250 // Release any child views that might have back pointers before ~View().
184 message_center_bubble_.reset(); 251 message_center_bubble_.reset();
185 popup_collection_.reset(); 252 popup_collection_.reset();
dewittj 2013/07/16 21:31:33 work_area_observer_.reset() here?
Jun Mukai 2013/07/16 22:49:42 Done.
186 } 253 }
187 254
188 // Public methods. 255 // Public methods.
189 256
190 bool WebNotificationTray::ShowMessageCenterInternal(bool show_settings) { 257 bool WebNotificationTray::ShowMessageCenterInternal(bool show_settings) {
191 if (!ShouldShowMessageCenter()) 258 if (!ShouldShowMessageCenter())
192 return false; 259 return false;
193 260
194 should_block_shelf_auto_hide_ = true; 261 should_block_shelf_auto_hide_ = true;
195 message_center::MessageCenterBubble* message_center_bubble = 262 message_center::MessageCenterBubble* message_center_bubble =
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 !status_area_widget()->ShouldShowWebNotifications()) { 328 !status_area_widget()->ShouldShowWebNotifications()) {
262 return false; 329 return false;
263 } 330 }
264 331
265 popup_collection_.reset(new message_center::MessagePopupCollection( 332 popup_collection_.reset(new message_center::MessagePopupCollection(
266 ash::Shell::GetContainer( 333 ash::Shell::GetContainer(
267 GetWidget()->GetNativeView()->GetRootWindow(), 334 GetWidget()->GetNativeView()->GetRootWindow(),
268 internal::kShellWindowId_StatusContainer), 335 internal::kShellWindowId_StatusContainer),
269 message_center(), 336 message_center(),
270 message_center_tray_.get())); 337 message_center_tray_.get()));
271 338 work_area_observer_.reset(new internal::WorkAreaObserver(
339 popup_collection_.get(), GetShelfLayoutManager()));
272 return true; 340 return true;
273 } 341 }
274 342
275 void WebNotificationTray::HidePopups() { 343 void WebNotificationTray::HidePopups() {
276 popup_collection_.reset(); 344 popup_collection_.reset();
345 work_area_observer_.reset();
dewittj 2013/07/16 21:31:33 I don't love how the work_area_observer_ needs to
Jun Mukai 2013/07/16 22:49:42 we can disable work_area_observer_ or something, b
277 } 346 }
278 347
279 // Private methods. 348 // Private methods.
280 349
281 bool WebNotificationTray::ShouldShowMessageCenter() { 350 bool WebNotificationTray::ShouldShowMessageCenter() {
282 return status_area_widget()->login_status() != user::LOGGED_IN_LOCKED && 351 return status_area_widget()->login_status() != user::LOGGED_IN_LOCKED &&
283 !(status_area_widget()->system_tray() && 352 !(status_area_widget()->system_tray() &&
284 status_area_widget()->system_tray()->HasNotificationBubble()); 353 status_area_widget()->system_tray()->HasNotificationBubble());
285 } 354 }
286 355
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 556
488 message_center::MessageCenterBubble* 557 message_center::MessageCenterBubble*
489 WebNotificationTray::GetMessageCenterBubbleForTest() { 558 WebNotificationTray::GetMessageCenterBubbleForTest() {
490 if (!message_center_bubble()) 559 if (!message_center_bubble())
491 return NULL; 560 return NULL;
492 return static_cast<message_center::MessageCenterBubble*>( 561 return static_cast<message_center::MessageCenterBubble*>(
493 message_center_bubble()->bubble()); 562 message_center_bubble()->bubble());
494 } 563 }
495 564
496 } // namespace ash 565 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698