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/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 } |
|
stevenjb
2013/01/18 23:11:46
This does not belong here, it needs to be in src/c
dewittj
2013/01/20 19:02:06
This is now a static method on MessageCenterTrayDe
| |
| 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 Loading... | |
| 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)); |
|
stevenjb
2013/01/18 23:11:46
message_center_tray_.reset(new ...)
dewittj
2013/01/20 19:02:06
Done.
Pete Williamson
2013/01/23 19:52:16
Since WNT creates MCT, how does the outside world
dewittj
2013/01/23 22:07:51
The outside world adds notifications to the global
| |
| 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 // Public methods. |
| 108 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) | 106 |
| 109 return; | 107 bool WebNotificationTray::ShowMessageCenter( |
| 110 if (quiet_mode_bubble()) | 108 message_center::MessageBubbleBase* message_center_bubble) { |
| 111 quiet_mode_bubble_.reset(); | 109 if (!ShouldShowMessageCenter()) |
| 112 if (message_center_bubble()) { | 110 return false; |
| 113 UpdateTray(); | 111 |
| 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 | 112 // TODO(mukai): move this to WebNotificationBubbleWrapper if it's safe |
| 124 // to set the height of the popup. | 113 // to set the height of the popup. |
| 125 int max_height = 0; | 114 int max_height = 0; |
| 126 if (GetShelfLayoutManager()->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { | 115 if (GetShelfLayoutManager()->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { |
| 127 gfx::Rect shelf_bounds = GetShelfLayoutManager()->GetIdealBounds(); | 116 gfx::Rect shelf_bounds = GetShelfLayoutManager()->GetIdealBounds(); |
| 128 max_height = shelf_bounds.y(); | 117 max_height = shelf_bounds.y(); |
| 129 } else { | 118 } else { |
| 130 // Assume that the bottom line of the status area widget and the bubble are | 119 // Assume that the bottom line of the status area widget and the bubble are |
| 131 // aligned. | 120 // aligned. |
| 132 aura::Window* status_area_window = status_area_widget()->GetNativeWindow(); | 121 aura::Window* status_area_window = status_area_widget()->GetNativeWindow(); |
| 133 max_height = status_area_window->GetBoundsInRootWindow().bottom(); | 122 max_height = status_area_window->GetBoundsInRootWindow().bottom(); |
| 134 } | 123 } |
| 135 bubble->SetMaxHeight(max_height); | 124 message_center_bubble->SetMaxHeight(max_height); |
| 136 message_center_bubble_.reset( | 125 message_center_bubble_.reset( |
| 137 new internal::WebNotificationBubbleWrapper(this, bubble)); | 126 new internal::WebNotificationBubbleWrapper(this, message_center_bubble)); |
| 138 | 127 |
| 139 status_area_widget()->SetHideSystemNotifications(true); | 128 status_area_widget()->SetHideSystemNotifications(true); |
| 140 GetShelfLayoutManager()->UpdateAutoHideState(); | 129 GetShelfLayoutManager()->UpdateAutoHideState(); |
| 130 | |
| 131 return true; | |
| 141 } | 132 } |
| 142 | 133 |
| 143 void WebNotificationTray::HideMessageCenterBubble() { | 134 void WebNotificationTray::UpdateMessageCenter() { |
| 135 if (message_center_bubble()) | |
| 136 message_center_bubble_->bubble()->ScheduleUpdate(); | |
| 137 } | |
| 138 | |
| 139 void WebNotificationTray::HideMessageCenter() { | |
| 144 if (!message_center_bubble()) | 140 if (!message_center_bubble()) |
| 145 return; | 141 return; |
| 146 message_center_bubble_.reset(); | 142 message_center_bubble_.reset(); |
| 147 show_message_center_on_unlock_ = false; | 143 show_message_center_on_unlock_ = false; |
| 148 message_center_->SetMessageCenterVisible(false); | |
| 149 UpdateTray(); | |
| 150 status_area_widget()->SetHideSystemNotifications(false); | 144 status_area_widget()->SetHideSystemNotifications(false); |
| 151 GetShelfLayoutManager()->UpdateAutoHideState(); | 145 GetShelfLayoutManager()->UpdateAutoHideState(); |
| 152 } | 146 } |
| 153 | 147 |
| 154 void WebNotificationTray::SetHidePopupBubble(bool hide) { | 148 void WebNotificationTray::SetHidePopupBubble(bool hide) { |
| 155 if (hide) | 149 if (hide) |
| 156 HidePopupBubble(); | 150 message_center_tray_->HidePopupBubble(); |
| 157 else | 151 else |
| 158 ShowPopupBubble(); | 152 message_center_tray_->ShowPopupBubble(); |
| 159 } | 153 } |
| 160 | 154 |
| 161 void WebNotificationTray::ShowPopupBubble() { | 155 bool WebNotificationTray::ShowPopups( |
| 162 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) | 156 message_center::MessageBubbleBase* popup_bubble) { |
| 163 return; | 157 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED || |
| 164 if (message_center_bubble()) | 158 message_center_bubble() || |
| 165 return; | 159 !status_area_widget()->ShouldShowWebNotifications()) |
| 166 if (!status_area_widget()->ShouldShowWebNotifications()) | 160 return false; |
| 167 return; | 161 popup_bubble_.reset(new internal::WebNotificationBubbleWrapper( |
| 168 UpdateTray(); | 162 this, |
| 169 if (popup_bubble()) { | 163 popup_bubble)); |
|
stevenjb
2013/01/18 23:11:46
nit: this can be on the same line as 'this,'
dewittj
2013/01/20 19:02:06
Done.
| |
| 170 popup_bubble()->bubble()->ScheduleUpdate(); | 164 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 } | 165 } |
| 178 | 166 |
| 179 void WebNotificationTray::HidePopupBubble() { | 167 void WebNotificationTray::UpdatePopups() { |
| 168 if (popup_bubble()) | |
| 169 popup_bubble_->bubble()->ScheduleUpdate(); | |
| 170 }; | |
| 171 | |
| 172 void WebNotificationTray::HidePopups() { | |
| 180 popup_bubble_.reset(); | 173 popup_bubble_.reset(); |
| 181 } | 174 } |
| 182 | 175 |
| 176 // Private methods. | |
| 177 | |
| 178 bool WebNotificationTray::ShouldShowMessageCenter() { | |
| 179 return status_area_widget()->login_status() != user::LOGGED_IN_LOCKED && | |
| 180 status_area_widget()->ShouldShowWebNotifications(); | |
| 181 } | |
| 182 | |
| 183 bool WebNotificationTray::ShouldShowQuietModeBubble(const ui::Event& event) { | 183 bool WebNotificationTray::ShouldShowQuietModeBubble(const ui::Event& event) { |
| 184 // TODO(mukai): Add keyboard event handler. | 184 // TODO(mukai): Add keyboard event handler. |
| 185 if (!event.IsMouseEvent()) | 185 if (!event.IsMouseEvent()) |
| 186 return false; | 186 return false; |
| 187 | 187 |
| 188 const ui::MouseEvent* mouse_event = | 188 const ui::MouseEvent* mouse_event = |
| 189 static_cast<const ui::MouseEvent*>(&event); | 189 static_cast<const ui::MouseEvent*>(&event); |
| 190 | 190 |
| 191 return mouse_event->IsRightMouseButton(); | 191 return mouse_event->IsRightMouseButton(); |
| 192 } | 192 } |
| 193 | 193 |
| 194 void WebNotificationTray::ShowQuietModeBubble() { | 194 void WebNotificationTray::ShowQuietModeBubble() { |
| 195 aura::Window* parent = Shell::GetContainer( | 195 aura::Window* parent = Shell::GetContainer( |
| 196 Shell::GetPrimaryRootWindow(), | 196 Shell::GetPrimaryRootWindow(), |
| 197 internal::kShellWindowId_SettingBubbleContainer); | 197 internal::kShellWindowId_SettingBubbleContainer); |
| 198 quiet_mode_bubble_.reset(new message_center::QuietModeBubble( | 198 quiet_mode_bubble_.reset(new message_center::QuietModeBubble( |
| 199 button_, parent, message_center_->notification_list())); | 199 button_, |
| 200 parent, | |
| 201 message_center_tray_->message_center()->notification_list())); | |
| 200 quiet_mode_bubble_->GetBubbleWidget()->StackAtTop(); | 202 quiet_mode_bubble_->GetBubbleWidget()->StackAtTop(); |
| 201 quiet_mode_bubble_->GetBubbleWidget()->AddObserver(this); | 203 quiet_mode_bubble_->GetBubbleWidget()->AddObserver(this); |
| 202 } | 204 } |
| 203 | 205 |
| 204 void WebNotificationTray::UpdateAfterLoginStatusChange( | 206 void WebNotificationTray::UpdateAfterLoginStatusChange( |
| 205 user::LoginStatus login_status) { | 207 user::LoginStatus login_status) { |
| 206 if (login_status == user::LOGGED_IN_LOCKED) { | 208 if (login_status == user::LOGGED_IN_LOCKED) { |
| 207 if (message_center_bubble()) { | 209 bool hidden = message_center_tray_->HideMessageCenterBubble(); |
| 208 message_center_bubble_.reset(); | 210 if (hidden) |
| 209 show_message_center_on_unlock_ = true; | 211 show_message_center_on_unlock_ = true; |
| 210 } | 212 message_center_tray_->HidePopupBubble(); |
| 211 HidePopupBubble(); | |
| 212 } else { | 213 } else { |
| 213 if (show_message_center_on_unlock_) | 214 if (show_message_center_on_unlock_) |
| 214 ShowMessageCenterBubble(); | 215 message_center_tray_->ShowMessageCenterBubble(); |
| 215 show_message_center_on_unlock_ = false; | 216 show_message_center_on_unlock_ = false; |
| 216 } | 217 } |
| 217 // The status icon should be always visible except for lock screen / login | 218 // The status icon should be always visible except for lock screen / login |
| 218 // screen, to allow quiet mode and settings. | 219 // screen, to allow quiet mode and settings. |
| 219 SetVisible((login_status != user::LOGGED_IN_NONE) && | 220 SetVisible((login_status != user::LOGGED_IN_NONE) && |
| 220 (login_status != user::LOGGED_IN_LOCKED)); | 221 (login_status != user::LOGGED_IN_LOCKED)); |
| 221 UpdateTray(); | 222 OnMessageCenterTrayChanged(); |
| 222 } | 223 } |
| 223 | 224 |
| 224 bool WebNotificationTray::ShouldBlockLauncherAutoHide() const { | 225 bool WebNotificationTray::ShouldBlockLauncherAutoHide() const { |
| 225 return IsMessageCenterBubbleVisible() || quiet_mode_bubble() != NULL; | 226 return IsMessageCenterBubbleVisible() || quiet_mode_bubble() != NULL; |
| 226 } | 227 } |
| 227 | 228 |
| 228 bool WebNotificationTray::IsMessageCenterBubbleVisible() const { | 229 bool WebNotificationTray::IsMessageCenterBubbleVisible() const { |
| 229 return (message_center_bubble() && | 230 return (message_center_bubble() && |
| 230 message_center_bubble_->bubble()->IsVisible()); | 231 message_center_bubble_->bubble()->IsVisible()); |
| 231 } | 232 } |
| 232 | 233 |
| 233 bool WebNotificationTray::IsMouseInNotificationBubble() const { | 234 bool WebNotificationTray::IsMouseInNotificationBubble() const { |
| 234 if (!popup_bubble()) | 235 if (!popup_bubble()) |
| 235 return false; | 236 return false; |
| 236 return popup_bubble_->bubble_view()->GetBoundsInScreen().Contains( | 237 return popup_bubble_->bubble_view()->GetBoundsInScreen().Contains( |
| 237 Shell::GetScreen()->GetCursorScreenPoint()); | 238 Shell::GetScreen()->GetCursorScreenPoint()); |
| 238 } | 239 } |
| 239 | 240 |
| 240 void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) { | 241 void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) { |
| 241 if (alignment == shelf_alignment()) | 242 if (alignment == shelf_alignment()) |
| 242 return; | 243 return; |
| 243 internal::TrayBackgroundView::SetShelfAlignment(alignment); | 244 SetShelfAlignment(alignment); |
|
Pete Williamson
2013/01/23 19:52:16
Hmm, I don't see this function in the file, where
dewittj
2013/01/23 22:07:51
Good catch, that must have been a merge issue. Re
| |
| 244 // Destroy any existing bubble so that it will be rebuilt correctly. | 245 // Destroy any existing bubble so that it will be rebuilt correctly. |
| 245 HideMessageCenterBubble(); | 246 message_center_tray_->HideMessageCenterBubble(); |
| 246 HidePopupBubble(); | 247 message_center_tray_->HidePopupBubble(); |
| 247 } | 248 } |
| 248 | 249 |
| 249 void WebNotificationTray::AnchorUpdated() { | 250 void WebNotificationTray::AnchorUpdated() { |
| 250 if (popup_bubble_.get()) { | 251 if (popup_bubble_.get()) { |
| 251 popup_bubble_->bubble_view()->UpdateBubble(); | 252 popup_bubble_->bubble_view()->UpdateBubble(); |
| 252 // Ensure that the notification buble is above the launcher/status area. | 253 // Ensure that the notification buble is above the launcher/status area. |
| 253 popup_bubble_->bubble_view()->GetWidget()->StackAtTop(); | 254 popup_bubble_->bubble_view()->GetWidget()->StackAtTop(); |
| 254 UpdateBubbleViewArrow(popup_bubble_->bubble_view()); | 255 UpdateBubbleViewArrow(popup_bubble_->bubble_view()); |
| 255 } | 256 } |
| 256 if (message_center_bubble_.get()) { | 257 if (message_center_bubble_.get()) { |
| 257 message_center_bubble_->bubble_view()->UpdateBubble(); | 258 message_center_bubble_->bubble_view()->UpdateBubble(); |
| 258 UpdateBubbleViewArrow(message_center_bubble_->bubble_view()); | 259 UpdateBubbleViewArrow(message_center_bubble_->bubble_view()); |
| 259 } | 260 } |
| 260 // Quiet mode settings bubble has to be on top. | 261 // Quiet mode settings bubble has to be on top. |
| 261 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget()) | 262 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget()) |
| 262 quiet_mode_bubble_->GetBubbleWidget()->StackAtTop(); | 263 quiet_mode_bubble_->GetBubbleWidget()->StackAtTop(); |
| 263 } | 264 } |
| 264 | 265 |
| 265 string16 WebNotificationTray::GetAccessibleNameForTray() { | 266 string16 WebNotificationTray::GetAccessibleNameForTray() { |
| 266 return l10n_util::GetStringUTF16( | 267 return l10n_util::GetStringUTF16( |
| 267 IDS_ASH_WEB_NOTIFICATION_TRAY_ACCESSIBLE_NAME); | 268 IDS_ASH_WEB_NOTIFICATION_TRAY_ACCESSIBLE_NAME); |
| 268 } | 269 } |
| 269 | 270 |
| 270 void WebNotificationTray::HideBubbleWithView( | 271 void WebNotificationTray::HideBubbleWithView( |
| 271 const views::TrayBubbleView* bubble_view) { | 272 const views::TrayBubbleView* bubble_view) { |
| 272 if (message_center_bubble() && | 273 if (message_center_bubble() && |
| 273 bubble_view == message_center_bubble()->bubble_view()) { | 274 bubble_view == message_center_bubble()->bubble_view()) { |
| 274 HideMessageCenterBubble(); | 275 message_center_tray_->HideMessageCenterBubble(); |
| 275 } else if (popup_bubble() && bubble_view == popup_bubble()->bubble_view()) { | 276 } else if (popup_bubble() && bubble_view == popup_bubble()->bubble_view()) { |
| 276 HidePopupBubble(); | 277 message_center_tray_->HidePopupBubble(); |
| 277 } | 278 } |
| 278 } | 279 } |
| 279 | 280 |
| 280 bool WebNotificationTray::PerformAction(const ui::Event& event) { | 281 bool WebNotificationTray::PerformAction(const ui::Event& event) { |
| 281 if (!quiet_mode_bubble() && ShouldShowQuietModeBubble(event)) { | 282 if (!quiet_mode_bubble() && ShouldShowQuietModeBubble(event)) { |
| 282 ShowQuietModeBubble(); | 283 ShowQuietModeBubble(); |
| 283 return true; | 284 return true; |
| 284 } | 285 } |
| 285 quiet_mode_bubble_.reset(); | 286 quiet_mode_bubble_.reset(); |
| 286 ToggleMessageCenterBubble(); | 287 if (message_center_bubble()) |
| 288 message_center_tray_->HideMessageCenterBubble(); | |
| 289 else | |
| 290 message_center_tray_->ShowMessageCenterBubble(); | |
| 287 return true; | 291 return true; |
| 288 } | 292 } |
| 289 | 293 |
| 294 void WebNotificationTray::ShowMessageCenter() { | |
| 295 message_center_tray_->ShowMessageCenterBubble(); | |
| 296 } | |
| 297 | |
| 290 void WebNotificationTray::BubbleViewDestroyed() { | 298 void WebNotificationTray::BubbleViewDestroyed() { |
| 291 if (message_center_bubble()) | 299 if (message_center_bubble()) |
| 292 message_center_bubble()->bubble()->BubbleViewDestroyed(); | 300 message_center_bubble()->bubble()->BubbleViewDestroyed(); |
| 293 if (popup_bubble()) | 301 if (popup_bubble()) |
| 294 popup_bubble()->bubble()->BubbleViewDestroyed(); | 302 popup_bubble()->bubble()->BubbleViewDestroyed(); |
| 295 } | 303 } |
| 296 | 304 |
| 297 void WebNotificationTray::OnMouseEnteredView() { | 305 void WebNotificationTray::OnMouseEnteredView() { |
| 298 if (popup_bubble()) | 306 if (popup_bubble()) |
| 299 popup_bubble()->bubble()->OnMouseEnteredView(); | 307 popup_bubble()->bubble()->OnMouseEnteredView(); |
| 300 } | 308 } |
| 301 | 309 |
| 302 void WebNotificationTray::OnMouseExitedView() { | 310 void WebNotificationTray::OnMouseExitedView() { |
| 303 if (popup_bubble()) | 311 if (popup_bubble()) |
| 304 popup_bubble()->bubble()->OnMouseExitedView(); | 312 popup_bubble()->bubble()->OnMouseExitedView(); |
| 305 } | 313 } |
| 306 | 314 |
| 307 string16 WebNotificationTray::GetAccessibleNameForBubble() { | 315 string16 WebNotificationTray::GetAccessibleNameForBubble() { |
| 308 return GetAccessibleNameForTray(); | 316 return GetAccessibleNameForTray(); |
| 309 } | 317 } |
| 310 | 318 |
| 311 gfx::Rect WebNotificationTray::GetAnchorRect(views::Widget* anchor_widget, | 319 gfx::Rect WebNotificationTray::GetAnchorRect( |
|
Pete Williamson
2013/01/23 19:52:16
This function could use a better name, and possibl
dewittj
2013/01/23 22:07:51
As described elsewhere, sometimes the edge of the
| |
| 312 AnchorType anchor_type, | 320 views::Widget* anchor_widget, |
| 313 AnchorAlignment anchor_alignment) { | 321 views::TrayBubbleView::AnchorType anchor_type, |
| 322 views::TrayBubbleView::AnchorAlignment anchor_alignment) { | |
| 314 return GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment); | 323 return GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment); |
| 315 } | 324 } |
| 316 | 325 |
| 317 void WebNotificationTray::HideBubble(const views::TrayBubbleView* bubble_view) { | 326 void WebNotificationTray::HideBubble(const views::TrayBubbleView* bubble_view) { |
| 318 HideBubbleWithView(bubble_view); | 327 HideBubbleWithView(bubble_view); |
| 319 } | 328 } |
| 320 | 329 |
|
Pete Williamson
2013/01/23 19:52:16
Note to self - this moved, compare it with the new
dewittj
2013/01/23 22:07:51
Noted.
Pete Williamson
2013/01/24 19:41:59
OK, I compared the two implementations as part of
| |
| 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, | 330 void WebNotificationTray::ButtonPressed(views::Button* sender, |
| 340 const ui::Event& event) { | 331 const ui::Event& event) { |
| 341 DCHECK_EQ(button_, sender); | 332 DCHECK_EQ(button_, sender); |
| 342 PerformAction(event); | 333 PerformAction(event); |
| 343 } | 334 } |
| 344 | 335 |
| 345 void WebNotificationTray::OnWidgetClosing(views::Widget* widget) { | 336 void WebNotificationTray::OnWidgetClosing(views::Widget* widget) { |
| 346 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget() == widget) { | 337 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget() == widget) { |
| 347 widget->RemoveObserver(this); | 338 widget->RemoveObserver(this); |
| 348 } | 339 } |
| 349 quiet_mode_bubble_.reset(); | 340 quiet_mode_bubble_.reset(); |
| 350 } | 341 } |
| 351 | 342 |
| 352 // Private methods | 343 void WebNotificationTray::OnMessageCenterTrayChanged() { |
| 353 | |
| 354 void WebNotificationTray::ToggleMessageCenterBubble() { | |
| 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(); | 344 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 364 if (message_center_->UnreadNotificationCount() > 0) { | 345 message_center::MessageCenter* message_center = |
| 346 message_center_tray_->message_center(); | |
| 347 if (message_center->UnreadNotificationCount() > 0) { | |
| 365 button_->SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed( | 348 button_->SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed( |
| 366 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_NORMAL)); | 349 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_NORMAL)); |
| 367 button_->SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed( | 350 button_->SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed( |
| 368 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_HOVER)); | 351 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_HOVER)); |
| 369 button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed( | 352 button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed( |
| 370 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_PRESSED)); | 353 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_PRESSED)); |
| 371 } else { | 354 } else { |
| 372 button_->SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed( | 355 button_->SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed( |
| 373 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_NORMAL)); | 356 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_NORMAL)); |
| 374 button_->SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed( | 357 button_->SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed( |
| 375 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_HOVER)); | 358 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_HOVER)); |
| 376 button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed( | 359 button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed( |
| 377 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_PRESSED)); | 360 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_PRESSED)); |
| 378 } | 361 } |
| 379 if (message_center_bubble()) | 362 if (IsMessageCenterBubbleVisible()) |
| 380 button_->SetState(views::CustomButton::STATE_PRESSED); | 363 button_->SetState(views::CustomButton::STATE_PRESSED); |
| 381 else | 364 else |
| 382 button_->SetState(views::CustomButton::STATE_NORMAL); | 365 button_->SetState(views::CustomButton::STATE_NORMAL); |
| 383 Layout(); | 366 Layout(); |
| 384 SchedulePaint(); | 367 SchedulePaint(); |
| 385 } | 368 } |
| 386 | 369 |
| 387 bool WebNotificationTray::ClickedOutsideBubble() { | 370 bool WebNotificationTray::ClickedOutsideBubble() { |
| 388 // Only hide the message center and quiet mode bubble. | 371 // Only hide the message center and quiet mode bubble. |
| 389 if (!message_center_bubble() && !quiet_mode_bubble()) | 372 if (!message_center_bubble() && !quiet_mode_bubble()) |
| 390 return false; | 373 return false; |
| 391 quiet_mode_bubble_.reset(); | 374 quiet_mode_bubble_.reset(); |
| 392 HideMessageCenterBubble(); | 375 message_center_tray_->HideMessageCenterBubble(); |
| 393 return true; | 376 return true; |
| 394 } | 377 } |
| 395 | 378 |
| 379 message_center::MessageCenter* WebNotificationTray::message_center() { | |
| 380 return message_center_tray_->message_center(); | |
| 381 } | |
| 382 | |
| 396 // Methods for testing | 383 // Methods for testing |
| 397 | 384 |
| 385 bool WebNotificationTray::IsPopupVisible() const { | |
| 386 return message_center_tray_->IsPopupVisible(); | |
| 387 } | |
| 388 | |
| 398 message_center::MessageCenterBubble* | 389 message_center::MessageCenterBubble* |
| 399 WebNotificationTray::GetMessageCenterBubbleForTest() { | 390 WebNotificationTray::GetMessageCenterBubbleForTest() { |
| 400 if (!message_center_bubble_.get()) | 391 if (!message_center_bubble_.get()) |
| 401 return NULL; | 392 return NULL; |
| 402 return static_cast<message_center::MessageCenterBubble*>( | 393 return static_cast<message_center::MessageCenterBubble*>( |
| 403 message_center_bubble_->bubble()); | 394 message_center_bubble_->bubble()); |
| 404 } | 395 } |
| 405 | 396 |
| 406 message_center::MessagePopupBubble* | 397 message_center::MessagePopupBubble* |
| 407 WebNotificationTray::GetPopupBubbleForTest() { | 398 WebNotificationTray::GetPopupBubbleForTest() { |
| 408 if (!popup_bubble_.get()) | 399 if (!popup_bubble_.get()) |
| 409 return NULL; | 400 return NULL; |
| 410 return static_cast<message_center::MessagePopupBubble*>( | 401 return static_cast<message_center::MessagePopupBubble*>( |
| 411 popup_bubble_->bubble()); | 402 popup_bubble_->bubble()); |
| 412 } | 403 } |
| 413 | 404 |
| 414 } // namespace ash | 405 } // namespace ash |
| OLD | NEW |