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