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

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

Issue 11819048: Implement message center on Windows (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase. Created 7 years, 11 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
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/root_window_controller.h"
7 #include "ash/shell.h" 8 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h" 9 #include "ash/shell_window_ids.h"
9 #include "ash/system/status_area_widget.h" 10 #include "ash/system/status_area_widget.h"
11 #include "ash/system/tray/tray_background_view.h"
10 #include "ash/system/tray/tray_bubble_wrapper.h" 12 #include "ash/system/tray/tray_bubble_wrapper.h"
11 #include "ash/system/tray/tray_constants.h"
12 #include "ash/system/tray/tray_views.h"
13 #include "ash/wm/shelf_layout_manager.h" 13 #include "ash/wm/shelf_layout_manager.h"
14 #include "base/message_loop.h"
15 #include "base/stringprintf.h"
16 #include "grit/ash_resources.h" 14 #include "grit/ash_resources.h"
17 #include "grit/ash_strings.h" 15 #include "grit/ash_strings.h"
18 #include "ui/aura/window.h" 16 #include "ui/aura/window.h"
19 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/base/resource/resource_bundle.h" 18 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/gfx/screen.h" 19 #include "ui/message_center/message_bubble_base.h"
22 #include "ui/message_center/message_center_bubble.h" 20 #include "ui/message_center/message_center_bubble.h"
21 #include "ui/message_center/message_center_tray.h"
23 #include "ui/message_center/message_popup_bubble.h" 22 #include "ui/message_center/message_popup_bubble.h"
24 #include "ui/message_center/quiet_mode_bubble.h" 23 #include "ui/message_center/quiet_mode_bubble.h"
25 #include "ui/views/bubble/tray_bubble_view.h" 24 #include "ui/views/bubble/tray_bubble_view.h"
26 #include "ui/views/widget/widget_observer.h"
27 25
28 namespace { 26 #if defined(ENABLE_MESSAGE_CENTER) && !defined(OS_WIN)
27 namespace chrome {
29 28
30 // Tray constants 29 ui::MessageCenterTrayDelegate* GetMessageCenterTray() {
31 const int kTrayContainerVerticalPaddingBottomAlignment = 3; 30 return ash::Shell::GetPrimaryRootWindowController()->status_area_widget()->
32 const int kTrayContainerHorizontalPaddingBottomAlignment = 1; 31 web_notification_tray();
33 const int kTrayContainerVerticalPaddingVerticalAlignment = 1; 32 }
34 const int kTrayContainerHorizontalPaddingVerticalAlignment = 0;
35 const int kPaddingFromLeftEdgeOfSystemTrayBottomAlignment = 8;
36 const int kPaddingFromTopEdgeOfSystemTrayVerticalAlignment = 10;
37 33
38 } // namespace 34 } // namespace chrome
35 #endif
36
39 37
40 namespace ash { 38 namespace ash {
41 39
42 namespace internal { 40 namespace internal {
43 41
44 // Class to initialize and manage the WebNotificationBubble and 42 // Class to initialize and manage the WebNotificationBubble and
45 // TrayBubbleWrapper instances for a bubble. 43 // TrayBubbleWrapper instances for a bubble.
46 44
47 class WebNotificationBubbleWrapper { 45 class WebNotificationBubbleWrapper {
48 public: 46 public:
(...skipping 14 matching lines...) Expand all
63 views::TrayBubbleView* bubble_view = views::TrayBubbleView::Create( 61 views::TrayBubbleView* bubble_view = views::TrayBubbleView::Create(
64 tray->GetBubbleWindowContainer(), anchor, tray, &init_params); 62 tray->GetBubbleWindowContainer(), anchor, tray, &init_params);
65 bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_view)); 63 bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_view));
66 bubble->InitializeContents(bubble_view); 64 bubble->InitializeContents(bubble_view);
67 } 65 }
68 66
69 message_center::MessageBubbleBase* bubble() const { return bubble_.get(); } 67 message_center::MessageBubbleBase* bubble() const { return bubble_.get(); }
70 68
71 // Convenience accessors. 69 // Convenience accessors.
72 views::TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); } 70 views::TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); }
71 views::Widget* bubble_widget() const {
72 return bubble_wrapper_->bubble_widget();
73 }
73 74
74 private: 75 private:
75 scoped_ptr<message_center::MessageBubbleBase> bubble_; 76 scoped_ptr<message_center::MessageBubbleBase> bubble_;
76 scoped_ptr<internal::TrayBubbleWrapper> bubble_wrapper_; 77 scoped_ptr<internal::TrayBubbleWrapper> bubble_wrapper_;
77 }; 78 };
78 79
79 } // namespace internal 80 } // namespace internal
80 81
81 WebNotificationTray::WebNotificationTray( 82 WebNotificationTray::WebNotificationTray(
82 internal::StatusAreaWidget* status_area_widget) 83 internal::StatusAreaWidget* status_area_widget)
83 : internal::TrayBackgroundView(status_area_widget), 84 : TrayBackgroundView(status_area_widget),
84 button_(NULL), 85 button_(NULL),
85 show_message_center_on_unlock_(false) { 86 show_message_center_on_unlock_(false) {
86 message_center_ = message_center::MessageCenter::GetInstance();
87 message_center_->AddObserver(this);
88 button_ = new views::ImageButton(this); 87 button_ = new views::ImageButton(this);
89 button_->set_triggerable_event_flags( 88 button_->set_triggerable_event_flags(
90 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); 89 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON);
91 tray_container()->AddChildView(button_); 90 tray_container()->AddChildView(button_);
92 SetVisible(false); 91 SetVisible(false);
93 UpdateTray(); 92 message_center_tray_ = make_scoped_ptr(new ui::MessageCenterTray(this));
93 OnMessageCenterTrayChanged();
94 } 94 }
95 95
96 WebNotificationTray::~WebNotificationTray() { 96 WebNotificationTray::~WebNotificationTray() {
97 // Ensure the message center doesn't notify a destroyed object.
98 message_center_->RemoveObserver(this);
99 // Release any child views that might have back pointers before ~View(). 97 // Release any child views that might have back pointers before ~View().
100 message_center_bubble_.reset(); 98 message_center_bubble_.reset();
101 popup_bubble_.reset(); 99 popup_bubble_.reset();
102 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget()) 100 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget())
103 quiet_mode_bubble_->GetBubbleWidget()->RemoveObserver(this); 101 quiet_mode_bubble_->GetBubbleWidget()->RemoveObserver(this);
104 quiet_mode_bubble_.reset(); 102 quiet_mode_bubble_.reset();
105 } 103 }
106 104
107 void WebNotificationTray::ShowMessageCenterBubble() { 105 bool WebNotificationTray::CanShowMessageCenter() {
108 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) 106 return status_area_widget()->login_status() != user::LOGGED_IN_LOCKED &&
109 return; 107 status_area_widget()->ShouldShowWebNotifications();
110 if (quiet_mode_bubble()) 108 }
111 quiet_mode_bubble_.reset(); 109
112 if (message_center_bubble()) { 110 bool WebNotificationTray::ShowMessageCenter(
113 UpdateTray(); 111 message_center::MessageBubbleBase* message_center_bubble) {
114 return; 112 if (!CanShowMessageCenter())
115 } 113 return false;
116 // Indicate that the message center is visible. Clears the unread count. 114
117 message_center_->SetMessageCenterVisible(true);
118 UpdateTray();
119 HidePopupBubble();
120 message_center::MessageCenterBubble* bubble =
121 new message_center::MessageCenterBubble(message_center_);
122 // Sets the maximum height of the bubble based on the screen.
123 // TODO(mukai): move this to WebNotificationBubbleWrapper if it's safe 115 // TODO(mukai): move this to WebNotificationBubbleWrapper if it's safe
124 // to set the height of the popup. 116 // to set the height of the popup.
125 int max_height = 0; 117 int max_height = 0;
126 if (GetShelfLayoutManager()->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { 118 if (GetShelfLayoutManager()->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) {
127 gfx::Rect shelf_bounds = GetShelfLayoutManager()->GetIdealBounds(); 119 gfx::Rect shelf_bounds = GetShelfLayoutManager()->GetIdealBounds();
128 max_height = shelf_bounds.y(); 120 max_height = shelf_bounds.y();
129 } else { 121 } else {
130 // Assume that the bottom line of the status area widget and the bubble are 122 // Assume that the bottom line of the status area widget and the bubble are
131 // aligned. 123 // aligned.
132 aura::Window* status_area_window = status_area_widget()->GetNativeWindow(); 124 aura::Window* status_area_window = status_area_widget()->GetNativeWindow();
133 max_height = status_area_window->GetBoundsInRootWindow().bottom(); 125 max_height = status_area_window->GetBoundsInRootWindow().bottom();
134 } 126 }
135 bubble->SetMaxHeight(max_height); 127 message_center_bubble->SetMaxHeight(max_height);
136 message_center_bubble_.reset( 128 message_center_bubble_.reset(
137 new internal::WebNotificationBubbleWrapper(this, bubble)); 129 new internal::WebNotificationBubbleWrapper(this, message_center_bubble));
138 130
139 status_area_widget()->SetHideSystemNotifications(true); 131 status_area_widget()->SetHideSystemNotifications(true);
140 GetShelfLayoutManager()->UpdateAutoHideState(); 132 GetShelfLayoutManager()->UpdateAutoHideState();
133
134 return true;
141 } 135 }
142 136
143 void WebNotificationTray::HideMessageCenterBubble() { 137 void WebNotificationTray::UpdateMessageCenter() {
138 if (message_center_bubble())
139 message_center_bubble_->bubble()->ScheduleUpdate();
140 }
141
142 void WebNotificationTray::HideMessageCenter() {
144 if (!message_center_bubble()) 143 if (!message_center_bubble())
145 return; 144 return;
146 message_center_bubble_.reset(); 145 message_center_bubble_.reset();
147 show_message_center_on_unlock_ = false; 146 show_message_center_on_unlock_ = false;
148 message_center_->SetMessageCenterVisible(false);
149 UpdateTray();
150 status_area_widget()->SetHideSystemNotifications(false); 147 status_area_widget()->SetHideSystemNotifications(false);
151 GetShelfLayoutManager()->UpdateAutoHideState(); 148 GetShelfLayoutManager()->UpdateAutoHideState();
152 } 149 }
153 150
154 void WebNotificationTray::SetHidePopupBubble(bool hide) { 151 void WebNotificationTray::SetHidePopupBubble(bool hide) {
155 if (hide) 152 if (hide)
156 HidePopupBubble(); 153 message_center_tray_->HidePopupBubble();
157 else 154 else
158 ShowPopupBubble(); 155 message_center_tray_->ShowPopupBubble();
159 } 156 }
160 157
161 void WebNotificationTray::ShowPopupBubble() { 158 bool WebNotificationTray::ShowPopups(
162 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) 159 message_center::MessageBubbleBase* popup_bubble) {
163 return; 160 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED ||
164 if (message_center_bubble()) 161 message_center_bubble() ||
165 return; 162 !status_area_widget()->ShouldShowWebNotifications())
166 if (!status_area_widget()->ShouldShowWebNotifications()) 163 return false;
167 return; 164 popup_bubble_.reset(new internal::WebNotificationBubbleWrapper(
168 UpdateTray(); 165 this,
169 if (popup_bubble()) { 166 popup_bubble));
170 popup_bubble()->bubble()->ScheduleUpdate(); 167 return true;
171 } else if (message_center_->HasPopupNotifications()) {
172 popup_bubble_.reset(
173 new internal::WebNotificationBubbleWrapper(
174 this, new message_center::MessagePopupBubble(
175 message_center_)));
176 }
177 } 168 }
178 169
179 void WebNotificationTray::HidePopupBubble() { 170 void WebNotificationTray::UpdatePopups() {
171 if (popup_bubble())
172 popup_bubble_->bubble()->ScheduleUpdate();
173 };
174
175 void WebNotificationTray::HidePopups() {
180 popup_bubble_.reset(); 176 popup_bubble_.reset();
181 } 177 }
182 178
183 bool WebNotificationTray::ShouldShowQuietModeBubble(const ui::Event& event) { 179 bool WebNotificationTray::ShouldShowQuietModeBubble(const ui::Event& event) {
184 // TODO(mukai): Add keyboard event handler. 180 // TODO(mukai): Add keyboard event handler.
185 if (!event.IsMouseEvent()) 181 if (!event.IsMouseEvent())
186 return false; 182 return false;
187 183
188 const ui::MouseEvent* mouse_event = 184 const ui::MouseEvent* mouse_event =
189 static_cast<const ui::MouseEvent*>(&event); 185 static_cast<const ui::MouseEvent*>(&event);
190 186
191 return mouse_event->IsRightMouseButton(); 187 return mouse_event->IsRightMouseButton();
192 } 188 }
193 189
194 void WebNotificationTray::ShowQuietModeBubble() { 190 void WebNotificationTray::ShowQuietModeBubble() {
195 aura::Window* parent = Shell::GetContainer( 191 aura::Window* parent = Shell::GetContainer(
196 Shell::GetPrimaryRootWindow(), 192 Shell::GetPrimaryRootWindow(),
197 internal::kShellWindowId_SettingBubbleContainer); 193 internal::kShellWindowId_SettingBubbleContainer);
198 quiet_mode_bubble_.reset(new message_center::QuietModeBubble( 194 quiet_mode_bubble_.reset(new message_center::QuietModeBubble(
199 button_, parent, message_center_->notification_list())); 195 button_,
196 parent,
197 message_center_tray_->message_center()->notification_list()));
200 quiet_mode_bubble_->GetBubbleWidget()->StackAtTop(); 198 quiet_mode_bubble_->GetBubbleWidget()->StackAtTop();
201 quiet_mode_bubble_->GetBubbleWidget()->AddObserver(this); 199 quiet_mode_bubble_->GetBubbleWidget()->AddObserver(this);
202 } 200 }
203 201
204 void WebNotificationTray::UpdateAfterLoginStatusChange( 202 void WebNotificationTray::UpdateAfterLoginStatusChange(
205 user::LoginStatus login_status) { 203 user::LoginStatus login_status) {
206 if (login_status == user::LOGGED_IN_LOCKED) { 204 if (login_status == user::LOGGED_IN_LOCKED) {
207 if (message_center_bubble()) { 205 bool hidden = message_center_tray_->HideMessageCenterBubble();
208 message_center_bubble_.reset(); 206 if (hidden)
209 show_message_center_on_unlock_ = true; 207 show_message_center_on_unlock_ = true;
210 } 208 message_center_tray_->HidePopupBubble();
211 HidePopupBubble();
212 } else { 209 } else {
213 if (show_message_center_on_unlock_) 210 if (show_message_center_on_unlock_)
214 ShowMessageCenterBubble(); 211 message_center_tray_->ShowMessageCenterBubble();
215 show_message_center_on_unlock_ = false; 212 show_message_center_on_unlock_ = false;
216 } 213 }
217 // The status icon should be always visible except for lock screen / login 214 // The status icon should be always visible except for lock screen / login
218 // screen, to allow quiet mode and settings. 215 // screen, to allow quiet mode and settings.
219 SetVisible((login_status != user::LOGGED_IN_NONE) && 216 SetVisible((login_status != user::LOGGED_IN_NONE) &&
220 (login_status != user::LOGGED_IN_LOCKED)); 217 (login_status != user::LOGGED_IN_LOCKED));
221 UpdateTray(); 218 OnMessageCenterTrayChanged();
222 } 219 }
223 220
224 bool WebNotificationTray::ShouldBlockLauncherAutoHide() const { 221 bool WebNotificationTray::ShouldBlockLauncherAutoHide() const {
225 return IsMessageCenterBubbleVisible() || quiet_mode_bubble() != NULL; 222 return IsMessageCenterBubbleVisible() || quiet_mode_bubble() != NULL;
226 } 223 }
227 224
228 bool WebNotificationTray::IsMessageCenterBubbleVisible() const { 225 bool WebNotificationTray::IsMessageCenterBubbleVisible() const {
229 return (message_center_bubble() && 226 return (message_center_bubble() &&
230 message_center_bubble_->bubble()->IsVisible()); 227 message_center_bubble_->bubble()->IsVisible());
231 } 228 }
232 229
233 bool WebNotificationTray::IsMouseInNotificationBubble() const { 230 bool WebNotificationTray::IsMouseInNotificationBubble() const {
234 if (!popup_bubble()) 231 // We only care about the mouse being in the popup view.
235 return false; 232 if (popup_bubble()) {
236 return popup_bubble_->bubble_view()->GetBoundsInScreen().Contains( 233 views::View* popup_bubble_view = popup_bubble_->bubble_view();
237 Shell::GetScreen()->GetCursorScreenPoint()); 234 if (!popup_bubble_view)
Pete Williamson 2013/01/17 19:07:45 While not harmful, this might not still be require
dewittj 2013/01/18 00:57:46 Done.
235 return false;
Pete Williamson 2013/01/17 19:07:45 While not necessary, this might not still be requi
dewittj 2013/01/18 00:57:46 Done.
236 return popup_bubble_view->GetBoundsInScreen().Contains(
237 Shell::GetScreen()->GetCursorScreenPoint());
238 }
239 return false;
240 }
241
242 message_center::MessageCenter* WebNotificationTray::message_center() {
243 return message_center_tray_->message_center();
238 } 244 }
239 245
240 void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) { 246 void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) {
241 if (alignment == shelf_alignment()) 247 if (alignment == shelf_alignment())
242 return; 248 return;
243 internal::TrayBackgroundView::SetShelfAlignment(alignment); 249 SetShelfAlignment(alignment);
244 // Destroy any existing bubble so that it will be rebuilt correctly. 250 // Destroy any existing bubble so that it will be rebuilt correctly.
245 HideMessageCenterBubble(); 251 message_center_tray_->HideMessageCenterBubble();
246 HidePopupBubble(); 252 message_center_tray_->HidePopupBubble();
247 } 253 }
248 254
249 void WebNotificationTray::AnchorUpdated() { 255 void WebNotificationTray::AnchorUpdated() {
250 if (popup_bubble_.get()) { 256 if (popup_bubble()) {
251 popup_bubble_->bubble_view()->UpdateBubble(); 257 views::TrayBubbleView* popup_bubble_view = popup_bubble_->bubble_view();
252 // Ensure that the notification buble is above the launcher/status area. 258 if (popup_bubble_view) {
253 popup_bubble_->bubble_view()->GetWidget()->StackAtTop(); 259 popup_bubble_view->UpdateBubble();
254 UpdateBubbleViewArrow(popup_bubble_->bubble_view()); 260 // Ensure that the notification buble is above the launcher/status area.
261 popup_bubble_view->GetWidget()->StackAtTop();
262 UpdateBubbleViewArrow(popup_bubble_view);
263 }
255 } 264 }
256 if (message_center_bubble_.get()) { 265 if (message_center_bubble()) {
257 message_center_bubble_->bubble_view()->UpdateBubble(); 266 views::TrayBubbleView* message_center_bubble_view =
258 UpdateBubbleViewArrow(message_center_bubble_->bubble_view()); 267 message_center_bubble_->bubble_view();
268 if (message_center_bubble_view) {
269 message_center_bubble_view->UpdateBubble();
270 UpdateBubbleViewArrow(message_center_bubble_view);
271 }
259 } 272 }
260 // Quiet mode settings bubble has to be on top. 273 // Quiet mode settings bubble has to be on top.
261 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget()) 274 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget())
262 quiet_mode_bubble_->GetBubbleWidget()->StackAtTop(); 275 quiet_mode_bubble_->GetBubbleWidget()->StackAtTop();
263 } 276 }
264 277
265 string16 WebNotificationTray::GetAccessibleNameForTray() { 278 string16 WebNotificationTray::GetAccessibleNameForTray() {
266 return l10n_util::GetStringUTF16( 279 return l10n_util::GetStringUTF16(
267 IDS_ASH_WEB_NOTIFICATION_TRAY_ACCESSIBLE_NAME); 280 IDS_ASH_WEB_NOTIFICATION_TRAY_ACCESSIBLE_NAME);
268 } 281 }
269 282
270 void WebNotificationTray::HideBubbleWithView( 283 void WebNotificationTray::HideBubbleWithView(
271 const views::TrayBubbleView* bubble_view) { 284 const views::TrayBubbleView* bubble_view) {
272 if (message_center_bubble() && 285 if (message_center_bubble() &&
273 bubble_view == message_center_bubble()->bubble_view()) { 286 bubble_view == message_center_bubble()->bubble_view()) {
274 HideMessageCenterBubble(); 287 message_center_tray_->HideMessageCenterBubble();
275 } else if (popup_bubble() && bubble_view == popup_bubble()->bubble_view()) { 288 } else if (popup_bubble() && bubble_view == popup_bubble()->bubble_view()) {
276 HidePopupBubble(); 289 message_center_tray_->HidePopupBubble();
277 } 290 }
278 } 291 }
279 292
280 bool WebNotificationTray::PerformAction(const ui::Event& event) { 293 bool WebNotificationTray::PerformAction(const ui::Event& event) {
281 if (!quiet_mode_bubble() && ShouldShowQuietModeBubble(event)) { 294 if (!quiet_mode_bubble() && ShouldShowQuietModeBubble(event)) {
282 ShowQuietModeBubble(); 295 ShowQuietModeBubble();
283 return true; 296 return true;
284 } 297 }
285 quiet_mode_bubble_.reset(); 298 quiet_mode_bubble_.reset();
286 ToggleMessageCenterBubble(); 299 if (message_center_bubble())
300 message_center_tray_->HideMessageCenterBubble();
301 else
302 message_center_tray_->ShowMessageCenterBubble();
287 return true; 303 return true;
288 } 304 }
289 305
306 void WebNotificationTray::ShowMessageCenter() {
307 message_center_tray_->ShowMessageCenterBubble();
308 }
309
290 void WebNotificationTray::BubbleViewDestroyed() { 310 void WebNotificationTray::BubbleViewDestroyed() {
291 if (message_center_bubble()) 311 if (message_center_bubble())
292 message_center_bubble()->bubble()->BubbleViewDestroyed(); 312 message_center_bubble()->bubble()->BubbleViewDestroyed();
293 if (popup_bubble()) 313 if (popup_bubble())
294 popup_bubble()->bubble()->BubbleViewDestroyed(); 314 popup_bubble()->bubble()->BubbleViewDestroyed();
295 } 315 }
296 316
297 void WebNotificationTray::OnMouseEnteredView() { 317 void WebNotificationTray::OnMouseEnteredView() {
298 if (popup_bubble()) 318 if (popup_bubble())
299 popup_bubble()->bubble()->OnMouseEnteredView(); 319 popup_bubble()->bubble()->OnMouseEnteredView();
300 } 320 }
301 321
302 void WebNotificationTray::OnMouseExitedView() { 322 void WebNotificationTray::OnMouseExitedView() {
303 if (popup_bubble()) 323 if (popup_bubble())
304 popup_bubble()->bubble()->OnMouseExitedView(); 324 popup_bubble()->bubble()->OnMouseExitedView();
305 } 325 }
306 326
307 string16 WebNotificationTray::GetAccessibleNameForBubble() { 327 string16 WebNotificationTray::GetAccessibleNameForBubble() {
308 return GetAccessibleNameForTray(); 328 return GetAccessibleNameForTray();
309 } 329 }
310 330
311 gfx::Rect WebNotificationTray::GetAnchorRect(views::Widget* anchor_widget, 331 gfx::Rect WebNotificationTray::GetAnchorRect(
Pete Williamson 2013/01/17 19:07:45 comment somewhere explaining what the anchor rect
dewittj 2013/01/18 00:57:46 BubbleDelegateView is where this originates, and i
312 AnchorType anchor_type, 332 views::Widget* anchor_widget,
313 AnchorAlignment anchor_alignment) { 333 views::TrayBubbleView::AnchorType anchor_type,
334 views::TrayBubbleView::AnchorAlignment anchor_alignment) {
314 return GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment); 335 return GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment);
315 } 336 }
316 337
317 void WebNotificationTray::HideBubble(const views::TrayBubbleView* bubble_view) { 338 void WebNotificationTray::HideBubble(const views::TrayBubbleView* bubble_view) {
318 HideBubbleWithView(bubble_view); 339 HideBubbleWithView(bubble_view);
319 } 340 }
320 341
321 void WebNotificationTray::OnMessageCenterChanged(bool new_notification) {
322 if (message_center_bubble()) {
323 if (message_center_->NotificationCount() == 0)
324 HideMessageCenterBubble();
325 else
326 message_center_bubble()->bubble()->ScheduleUpdate();
327 }
328 if (popup_bubble()) {
329 if (message_center_->NotificationCount() == 0)
330 HidePopupBubble();
331 else
332 popup_bubble()->bubble()->ScheduleUpdate();
333 }
334 UpdateTray();
335 if (new_notification)
336 ShowPopupBubble();
337 }
338
339 void WebNotificationTray::ButtonPressed(views::Button* sender, 342 void WebNotificationTray::ButtonPressed(views::Button* sender,
340 const ui::Event& event) { 343 const ui::Event& event) {
341 DCHECK_EQ(button_, sender); 344 DCHECK_EQ(button_, sender);
342 PerformAction(event); 345 PerformAction(event);
343 } 346 }
344 347
348
Pete Williamson 2013/01/17 19:07:45 remove extra blank line
345 void WebNotificationTray::OnWidgetClosing(views::Widget* widget) { 349 void WebNotificationTray::OnWidgetClosing(views::Widget* widget) {
346 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget() == widget) { 350 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget() == widget) {
347 widget->RemoveObserver(this); 351 widget->RemoveObserver(this);
348 } 352 }
349 quiet_mode_bubble_.reset(); 353 quiet_mode_bubble_.reset();
350 } 354 }
351 355
352 // Private methods
353 356
354 void WebNotificationTray::ToggleMessageCenterBubble() { 357 void WebNotificationTray::OnMessageCenterTrayChanged() {
355 if (message_center_bubble())
356 HideMessageCenterBubble();
357 else
358 ShowMessageCenterBubble();
359 UpdateTray();
360 }
361
362 void WebNotificationTray::UpdateTray() {
363 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 358 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
364 if (message_center_->UnreadNotificationCount() > 0) { 359 message_center::MessageCenter* message_center =
360 message_center_tray_->message_center();
361 if (message_center->UnreadNotificationCount() > 0) {
365 button_->SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed( 362 button_->SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed(
366 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_NORMAL)); 363 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_NORMAL));
367 button_->SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed( 364 button_->SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed(
368 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_HOVER)); 365 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_HOVER));
369 button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed( 366 button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed(
370 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_PRESSED)); 367 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_PRESSED));
371 } else { 368 } else {
372 button_->SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed( 369 button_->SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed(
373 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_NORMAL)); 370 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_NORMAL));
374 button_->SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed( 371 button_->SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed(
375 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_HOVER)); 372 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_HOVER));
376 button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed( 373 button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed(
377 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_PRESSED)); 374 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_PRESSED));
378 } 375 }
379 if (message_center_bubble()) 376 if (IsMessageCenterBubbleVisible())
380 button_->SetState(views::CustomButton::STATE_PRESSED); 377 button_->SetState(views::CustomButton::STATE_PRESSED);
381 else 378 else
382 button_->SetState(views::CustomButton::STATE_NORMAL); 379 button_->SetState(views::CustomButton::STATE_NORMAL);
383 Layout(); 380 Layout();
384 SchedulePaint(); 381 SchedulePaint();
385 } 382 }
386 383
387 bool WebNotificationTray::ClickedOutsideBubble() { 384 bool WebNotificationTray::ClickedOutsideBubble() {
388 // Only hide the message center and quiet mode bubble. 385 // Only hide the message center and quiet mode bubble.
389 if (!message_center_bubble() && !quiet_mode_bubble()) 386 if (!message_center_bubble() && !quiet_mode_bubble())
390 return false; 387 return false;
391 quiet_mode_bubble_.reset(); 388 quiet_mode_bubble_.reset();
392 HideMessageCenterBubble(); 389 message_center_tray_->HideMessageCenterBubble();
393 return true; 390 return true;
394 } 391 }
395 392
396 // Methods for testing 393 // Methods for testing
397 394
395 bool WebNotificationTray::IsPopupVisible() const {
396 return message_center_tray_->IsPopupVisible();
397 }
398
398 message_center::MessageCenterBubble* 399 message_center::MessageCenterBubble*
399 WebNotificationTray::GetMessageCenterBubbleForTest() { 400 WebNotificationTray::GetMessageCenterBubbleForTest() {
400 if (!message_center_bubble_.get()) 401 if (!message_center_bubble_.get())
401 return NULL; 402 return NULL;
402 return static_cast<message_center::MessageCenterBubble*>( 403 return static_cast<message_center::MessageCenterBubble*>(
403 message_center_bubble_->bubble()); 404 message_center_bubble_->bubble());
404 } 405 }
405 406
406 message_center::MessagePopupBubble* 407 message_center::MessagePopupBubble*
407 WebNotificationTray::GetPopupBubbleForTest() { 408 WebNotificationTray::GetPopupBubbleForTest() {
408 if (!popup_bubble_.get()) 409 if (!popup_bubble_.get())
409 return NULL; 410 return NULL;
410 return static_cast<message_center::MessagePopupBubble*>( 411 return static_cast<message_center::MessagePopupBubble*>(
411 popup_bubble_->bubble()); 412 popup_bubble_->bubble());
412 } 413 }
413 414
415
414 } // namespace ash 416 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698