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