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

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: fix 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.
James Cook 2013/07/17 21:14:14 nit: either "notifies MessagePopupCollection" or "
Jun Mukai 2013/07/18 17:55:43 Done.
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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
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();
253 work_area_observer_.reset();
186 } 254 }
187 255
188 // Public methods. 256 // Public methods.
189 257
190 bool WebNotificationTray::ShowMessageCenterInternal(bool show_settings) { 258 bool WebNotificationTray::ShowMessageCenterInternal(bool show_settings) {
191 if (!ShouldShowMessageCenter()) 259 if (!ShouldShowMessageCenter())
192 return false; 260 return false;
193 261
194 should_block_shelf_auto_hide_ = true; 262 should_block_shelf_auto_hide_ = true;
195 message_center::MessageCenterBubble* message_center_bubble = 263 message_center::MessageCenterBubble* message_center_bubble =
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 !status_area_widget()->ShouldShowWebNotifications()) { 329 !status_area_widget()->ShouldShowWebNotifications()) {
262 return false; 330 return false;
263 } 331 }
264 332
265 popup_collection_.reset(new message_center::MessagePopupCollection( 333 popup_collection_.reset(new message_center::MessagePopupCollection(
266 ash::Shell::GetContainer( 334 ash::Shell::GetContainer(
267 GetWidget()->GetNativeView()->GetRootWindow(), 335 GetWidget()->GetNativeView()->GetRootWindow(),
268 internal::kShellWindowId_StatusContainer), 336 internal::kShellWindowId_StatusContainer),
269 message_center(), 337 message_center(),
270 message_center_tray_.get())); 338 message_center_tray_.get()));
271 339 work_area_observer_.reset(new internal::WorkAreaObserver(
340 popup_collection_.get(), GetShelfLayoutManager()));
272 return true; 341 return true;
273 } 342 }
274 343
275 void WebNotificationTray::HidePopups() { 344 void WebNotificationTray::HidePopups() {
276 popup_collection_.reset(); 345 popup_collection_.reset();
346 work_area_observer_.reset();
277 } 347 }
278 348
279 // Private methods. 349 // Private methods.
280 350
281 bool WebNotificationTray::ShouldShowMessageCenter() { 351 bool WebNotificationTray::ShouldShowMessageCenter() {
282 return status_area_widget()->login_status() != user::LOGGED_IN_LOCKED && 352 return status_area_widget()->login_status() != user::LOGGED_IN_LOCKED &&
283 !(status_area_widget()->system_tray() && 353 !(status_area_widget()->system_tray() &&
284 status_area_widget()->system_tray()->HasNotificationBubble()); 354 status_area_widget()->system_tray()->HasNotificationBubble());
285 } 355 }
286 356
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 557
488 message_center::MessageCenterBubble* 558 message_center::MessageCenterBubble*
489 WebNotificationTray::GetMessageCenterBubbleForTest() { 559 WebNotificationTray::GetMessageCenterBubbleForTest() {
490 if (!message_center_bubble()) 560 if (!message_center_bubble())
491 return NULL; 561 return NULL;
492 return static_cast<message_center::MessageCenterBubble*>( 562 return static_cast<message_center::MessageCenterBubble*>(
493 message_center_bubble()->bubble()); 563 message_center_bubble()->bubble());
494 } 564 }
495 565
496 } // namespace ash 566 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698