| 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/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
| 9 #include "ash/shelf/shelf_layout_manager.h" | 9 #include "ash/shelf/shelf_layout_manager.h" |
| 10 #include "ash/shelf/shelf_layout_manager_observer.h" | 10 #include "ash/shelf/shelf_layout_manager_observer.h" |
| 11 #include "ash/shelf/shelf_widget.h" | 11 #include "ash/shelf/shelf_widget.h" |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "ash/shell_window_ids.h" | 13 #include "ash/shell_window_ids.h" |
| 14 #include "ash/system/status_area_widget.h" | 14 #include "ash/system/status_area_widget.h" |
| 15 #include "ash/system/tray/system_tray.h" | 15 #include "ash/system/tray/system_tray.h" |
| 16 #include "ash/system/tray/tray_background_view.h" | 16 #include "ash/system/tray/tray_background_view.h" |
| 17 #include "ash/system/tray/tray_bubble_wrapper.h" | 17 #include "ash/system/tray/tray_bubble_wrapper.h" |
| 18 #include "ash/system/tray/tray_constants.h" | 18 #include "ash/system/tray/tray_constants.h" |
| 19 #include "ash/system/tray/tray_utils.h" | 19 #include "ash/system/tray/tray_utils.h" |
| 20 #include "ash/system/web_notification/popup_alignment_delegate.h" |
| 20 #include "base/auto_reset.h" | 21 #include "base/auto_reset.h" |
| 21 #include "base/i18n/number_formatting.h" | 22 #include "base/i18n/number_formatting.h" |
| 22 #include "base/i18n/rtl.h" | 23 #include "base/i18n/rtl.h" |
| 23 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
| 24 #include "grit/ash_strings.h" | 25 #include "grit/ash_strings.h" |
| 25 #include "grit/ui_strings.h" | 26 #include "grit/ui_strings.h" |
| 26 #include "ui/aura/window.h" | 27 #include "ui/aura/window.h" |
| 27 #include "ui/aura/window_event_dispatcher.h" | 28 #include "ui/aura/window_event_dispatcher.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| 29 #include "ui/gfx/screen.h" | 30 #include "ui/gfx/screen.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 } | 64 } |
| 64 | 65 |
| 65 namespace { | 66 namespace { |
| 66 | 67 |
| 67 const SkColor kWebNotificationColorNoUnread = | 68 const SkColor kWebNotificationColorNoUnread = |
| 68 SkColorSetARGB(128, 255, 255, 255); | 69 SkColorSetARGB(128, 255, 255, 255); |
| 69 const SkColor kWebNotificationColorWithUnread = SK_ColorWHITE; | 70 const SkColor kWebNotificationColorWithUnread = SK_ColorWHITE; |
| 70 | 71 |
| 71 } | 72 } |
| 72 | 73 |
| 73 // Observes the change of work area (including temporary change by auto-hide) | |
| 74 // and notifies MessagePopupCollection. | |
| 75 class WorkAreaObserver : public ShelfLayoutManagerObserver, | |
| 76 public ShellObserver { | |
| 77 public: | |
| 78 WorkAreaObserver(); | |
| 79 virtual ~WorkAreaObserver(); | |
| 80 | |
| 81 void SetSystemTrayHeight(int height); | |
| 82 | |
| 83 // Starts observing |shelf| and shell and sends the change to |collection|. | |
| 84 void StartObserving(message_center::MessagePopupCollection* collection, | |
| 85 aura::Window* root_window); | |
| 86 | |
| 87 // Stops the observing session. | |
| 88 void StopObserving(); | |
| 89 | |
| 90 // Overridden from ShellObserver: | |
| 91 virtual void OnDisplayWorkAreaInsetsChanged() OVERRIDE; | |
| 92 | |
| 93 // Overridden from ShelfLayoutManagerObserver: | |
| 94 virtual void OnAutoHideStateChanged(ShelfAutoHideState new_state) OVERRIDE; | |
| 95 | |
| 96 private: | |
| 97 // Updates |shelf_| from |root_window_|. | |
| 98 void UpdateShelf(); | |
| 99 | |
| 100 message_center::MessagePopupCollection* collection_; | |
| 101 aura::Window* root_window_; | |
| 102 ShelfLayoutManager* shelf_; | |
| 103 int system_tray_height_; | |
| 104 | |
| 105 DISALLOW_COPY_AND_ASSIGN(WorkAreaObserver); | |
| 106 }; | |
| 107 | |
| 108 WorkAreaObserver::WorkAreaObserver() | |
| 109 : collection_(NULL), | |
| 110 root_window_(NULL), | |
| 111 shelf_(NULL), | |
| 112 system_tray_height_(0) { | |
| 113 } | |
| 114 | |
| 115 WorkAreaObserver::~WorkAreaObserver() { | |
| 116 StopObserving(); | |
| 117 } | |
| 118 | |
| 119 void WorkAreaObserver::SetSystemTrayHeight(int height) { | |
| 120 system_tray_height_ = height; | |
| 121 | |
| 122 // If the shelf is shown during auto-hide state, the distance from the edge | |
| 123 // should be reduced by the height of shelf's shown height. | |
| 124 if (shelf_ && shelf_->visibility_state() == SHELF_AUTO_HIDE && | |
| 125 shelf_->auto_hide_state() == SHELF_AUTO_HIDE_SHOWN) { | |
| 126 system_tray_height_ -= kShelfSize - ShelfLayoutManager::kAutoHideSize; | |
| 127 } | |
| 128 | |
| 129 if (system_tray_height_ > 0) | |
| 130 system_tray_height_ += message_center::kMarginBetweenItems; | |
| 131 | |
| 132 if (!shelf_) | |
| 133 return; | |
| 134 | |
| 135 OnAutoHideStateChanged(shelf_->auto_hide_state()); | |
| 136 } | |
| 137 | |
| 138 void WorkAreaObserver::StartObserving( | |
| 139 message_center::MessagePopupCollection* collection, | |
| 140 aura::Window* root_window) { | |
| 141 DCHECK(collection); | |
| 142 collection_ = collection; | |
| 143 root_window_ = root_window; | |
| 144 UpdateShelf(); | |
| 145 Shell::GetInstance()->AddShellObserver(this); | |
| 146 if (system_tray_height_ > 0) | |
| 147 OnAutoHideStateChanged(shelf_->auto_hide_state()); | |
| 148 } | |
| 149 | |
| 150 void WorkAreaObserver::StopObserving() { | |
| 151 Shell::GetInstance()->RemoveShellObserver(this); | |
| 152 if (shelf_) | |
| 153 shelf_->RemoveObserver(this); | |
| 154 collection_ = NULL; | |
| 155 shelf_ = NULL; | |
| 156 } | |
| 157 | |
| 158 void WorkAreaObserver::OnDisplayWorkAreaInsetsChanged() { | |
| 159 UpdateShelf(); | |
| 160 | |
| 161 collection_->OnDisplayMetricsChanged( | |
| 162 Shell::GetScreen()->GetDisplayNearestWindow( | |
| 163 shelf_->shelf_widget()->GetNativeView()), | |
| 164 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA); | |
| 165 } | |
| 166 | |
| 167 void WorkAreaObserver::OnAutoHideStateChanged(ShelfAutoHideState new_state) { | |
| 168 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( | |
| 169 shelf_->shelf_widget()->GetNativeView()); | |
| 170 gfx::Rect work_area = display.work_area(); | |
| 171 int width = 0; | |
| 172 if ((shelf_->visibility_state() == SHELF_AUTO_HIDE) && | |
| 173 new_state == SHELF_AUTO_HIDE_SHOWN) { | |
| 174 // Since the work_area is already reduced by kAutoHideSize, the inset width | |
| 175 // should be just the difference. | |
| 176 width = kShelfSize - ShelfLayoutManager::kAutoHideSize; | |
| 177 } | |
| 178 work_area.Inset(shelf_->SelectValueForShelfAlignment( | |
| 179 gfx::Insets(0, 0, width, 0), | |
| 180 gfx::Insets(0, width, 0, 0), | |
| 181 gfx::Insets(0, 0, 0, width), | |
| 182 gfx::Insets(width, 0, 0, 0))); | |
| 183 if (system_tray_height_ > 0) { | |
| 184 work_area.set_height( | |
| 185 std::max(0, work_area.height() - system_tray_height_)); | |
| 186 if (shelf_->GetAlignment() == SHELF_ALIGNMENT_TOP) | |
| 187 work_area.set_y(work_area.y() + system_tray_height_); | |
| 188 } | |
| 189 collection_->SetDisplayInfo(work_area, display.bounds()); | |
| 190 } | |
| 191 | |
| 192 void WorkAreaObserver::UpdateShelf() { | |
| 193 if (shelf_) | |
| 194 return; | |
| 195 | |
| 196 shelf_ = ShelfLayoutManager::ForShelf(root_window_); | |
| 197 if (shelf_) | |
| 198 shelf_->AddObserver(this); | |
| 199 } | |
| 200 | |
| 201 // Class to initialize and manage the WebNotificationBubble and | 74 // Class to initialize and manage the WebNotificationBubble and |
| 202 // TrayBubbleWrapper instances for a bubble. | 75 // TrayBubbleWrapper instances for a bubble. |
| 203 class WebNotificationBubbleWrapper { | 76 class WebNotificationBubbleWrapper { |
| 204 public: | 77 public: |
| 205 // Takes ownership of |bubble| and creates |bubble_wrapper_|. | 78 // Takes ownership of |bubble| and creates |bubble_wrapper_|. |
| 206 WebNotificationBubbleWrapper(WebNotificationTray* tray, | 79 WebNotificationBubbleWrapper(WebNotificationTray* tray, |
| 207 message_center::MessageBubbleBase* bubble) { | 80 message_center::MessageBubbleBase* bubble) { |
| 208 bubble_.reset(bubble); | 81 bubble_.reset(bubble); |
| 209 views::TrayBubbleView::AnchorAlignment anchor_alignment = | 82 views::TrayBubbleView::AnchorAlignment anchor_alignment = |
| 210 tray->GetAnchorAlignment(); | 83 tray->GetAnchorAlignment(); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 should_block_shelf_auto_hide_(false) { | 174 should_block_shelf_auto_hide_(false) { |
| 302 button_ = new WebNotificationButton(this); | 175 button_ = new WebNotificationButton(this); |
| 303 button_->set_triggerable_event_flags( | 176 button_->set_triggerable_event_flags( |
| 304 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); | 177 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); |
| 305 tray_container()->AddChildView(button_); | 178 tray_container()->AddChildView(button_); |
| 306 SetContentsBackground(); | 179 SetContentsBackground(); |
| 307 tray_container()->SetBorder(views::Border::NullBorder()); | 180 tray_container()->SetBorder(views::Border::NullBorder()); |
| 308 message_center_tray_.reset(new message_center::MessageCenterTray( | 181 message_center_tray_.reset(new message_center::MessageCenterTray( |
| 309 this, | 182 this, |
| 310 message_center::MessageCenter::Get())); | 183 message_center::MessageCenter::Get())); |
| 184 popup_alignment_delegate_.reset(new PopupAlignmentDelegate()); |
| 311 popup_collection_.reset(new message_center::MessagePopupCollection( | 185 popup_collection_.reset(new message_center::MessagePopupCollection( |
| 312 ash::Shell::GetContainer( | 186 ash::Shell::GetContainer( |
| 313 status_area_widget->GetNativeView()->GetRootWindow(), | 187 status_area_widget->GetNativeView()->GetRootWindow(), |
| 314 kShellWindowId_StatusContainer), | 188 kShellWindowId_StatusContainer), |
| 315 message_center(), | 189 message_center(), |
| 316 message_center_tray_.get(), | 190 message_center_tray_.get(), |
| 317 true)); | 191 popup_alignment_delegate_.get())); |
| 318 work_area_observer_.reset(new WorkAreaObserver()); | 192 const gfx::Display& display = Shell::GetScreen()->GetDisplayNearestWindow( |
| 319 work_area_observer_->StartObserving( | 193 status_area_widget->GetNativeView()); |
| 320 popup_collection_.get(), | 194 popup_alignment_delegate_->StartObserving(Shell::GetScreen(), display); |
| 321 status_area_widget->GetNativeView()->GetRootWindow()); | |
| 322 OnMessageCenterTrayChanged(); | 195 OnMessageCenterTrayChanged(); |
| 323 } | 196 } |
| 324 | 197 |
| 325 WebNotificationTray::~WebNotificationTray() { | 198 WebNotificationTray::~WebNotificationTray() { |
| 326 // Release any child views that might have back pointers before ~View(). | 199 // Release any child views that might have back pointers before ~View(). |
| 327 message_center_bubble_.reset(); | 200 message_center_bubble_.reset(); |
| 201 popup_alignment_delegate_.reset(); |
| 328 popup_collection_.reset(); | 202 popup_collection_.reset(); |
| 329 work_area_observer_.reset(); | |
| 330 } | 203 } |
| 331 | 204 |
| 332 // Public methods. | 205 // Public methods. |
| 333 | 206 |
| 334 bool WebNotificationTray::ShowMessageCenterInternal(bool show_settings) { | 207 bool WebNotificationTray::ShowMessageCenterInternal(bool show_settings) { |
| 335 if (!ShouldShowMessageCenter()) | 208 if (!ShouldShowMessageCenter()) |
| 336 return false; | 209 return false; |
| 337 | 210 |
| 338 should_block_shelf_auto_hide_ = true; | 211 should_block_shelf_auto_hide_ = true; |
| 339 message_center::MessageCenterBubble* message_center_bubble = | 212 message_center::MessageCenterBubble* message_center_bubble = |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 SetDrawBackgroundAsActive(false); | 264 SetDrawBackgroundAsActive(false); |
| 392 message_center_bubble_.reset(); | 265 message_center_bubble_.reset(); |
| 393 should_block_shelf_auto_hide_ = false; | 266 should_block_shelf_auto_hide_ = false; |
| 394 show_message_center_on_unlock_ = false; | 267 show_message_center_on_unlock_ = false; |
| 395 status_area_widget()->SetHideSystemNotifications(false); | 268 status_area_widget()->SetHideSystemNotifications(false); |
| 396 GetShelfLayoutManager()->UpdateAutoHideState(); | 269 GetShelfLayoutManager()->UpdateAutoHideState(); |
| 397 button_->SetBubbleVisible(false); | 270 button_->SetBubbleVisible(false); |
| 398 } | 271 } |
| 399 | 272 |
| 400 void WebNotificationTray::SetSystemTrayHeight(int height) { | 273 void WebNotificationTray::SetSystemTrayHeight(int height) { |
| 401 work_area_observer_->SetSystemTrayHeight(height); | 274 popup_alignment_delegate_->SetSystemTrayHeight(height); |
| 402 } | 275 } |
| 403 | 276 |
| 404 bool WebNotificationTray::ShowPopups() { | 277 bool WebNotificationTray::ShowPopups() { |
| 405 if (message_center_bubble()) | 278 if (message_center_bubble()) |
| 406 return false; | 279 return false; |
| 407 | 280 |
| 408 popup_collection_->DoUpdateIfPossible(); | 281 popup_collection_->DoUpdateIfPossible(); |
| 409 return true; | 282 return true; |
| 410 } | 283 } |
| 411 | 284 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 | 485 |
| 613 message_center::MessageCenterBubble* | 486 message_center::MessageCenterBubble* |
| 614 WebNotificationTray::GetMessageCenterBubbleForTest() { | 487 WebNotificationTray::GetMessageCenterBubbleForTest() { |
| 615 if (!message_center_bubble()) | 488 if (!message_center_bubble()) |
| 616 return NULL; | 489 return NULL; |
| 617 return static_cast<message_center::MessageCenterBubble*>( | 490 return static_cast<message_center::MessageCenterBubble*>( |
| 618 message_center_bubble()->bubble()); | 491 message_center_bubble()->bubble()); |
| 619 } | 492 } |
| 620 | 493 |
| 621 } // namespace ash | 494 } // namespace ash |
| OLD | NEW |