| 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" |
| 11 #include "ash/shelf/shelf_widget.h" |
| 10 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 11 #include "ash/shell_window_ids.h" | 13 #include "ash/shell_window_ids.h" |
| 12 #include "ash/system/status_area_widget.h" | 14 #include "ash/system/status_area_widget.h" |
| 13 #include "ash/system/tray/system_tray.h" | 15 #include "ash/system/tray/system_tray.h" |
| 14 #include "ash/system/tray/tray_background_view.h" | 16 #include "ash/system/tray/tray_background_view.h" |
| 15 #include "ash/system/tray/tray_bubble_wrapper.h" | 17 #include "ash/system/tray/tray_bubble_wrapper.h" |
| 16 #include "ash/system/tray/tray_constants.h" | 18 #include "ash/system/tray/tray_constants.h" |
| 17 #include "ash/system/tray/tray_utils.h" | 19 #include "ash/system/tray/tray_utils.h" |
| 18 #include "base/auto_reset.h" | 20 #include "base/auto_reset.h" |
| 19 #include "base/i18n/number_formatting.h" | 21 #include "base/i18n/number_formatting.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 58 |
| 57 const int kWebNotificationIconSize = 31; | 59 const int kWebNotificationIconSize = 31; |
| 58 // Height of the art assets used in alternate shelf layout, | 60 // Height of the art assets used in alternate shelf layout, |
| 59 // see ash/ash_switches.h:UseAlternateShelfLayout. | 61 // see ash/ash_switches.h:UseAlternateShelfLayout. |
| 60 const int kWebNotificationAlternateSize = 38; | 62 const int kWebNotificationAlternateSize = 38; |
| 61 const SkColor kWebNotificationColorNoUnread = SkColorSetA(SK_ColorWHITE, 128); | 63 const SkColor kWebNotificationColorNoUnread = SkColorSetA(SK_ColorWHITE, 128); |
| 62 const SkColor kWebNotificationColorWithUnread = SK_ColorWHITE; | 64 const SkColor kWebNotificationColorWithUnread = SK_ColorWHITE; |
| 63 | 65 |
| 64 } | 66 } |
| 65 | 67 |
| 68 // Observes the change of work area (including temporary change by auto-hide) |
| 69 // and notifies MessagePopupCollection. |
| 70 class WorkAreaObserver : public ShelfLayoutManagerObserver, |
| 71 public ShellObserver { |
| 72 public: |
| 73 WorkAreaObserver(message_center::MessagePopupCollection* collection, |
| 74 ShelfLayoutManager* shelf); |
| 75 virtual ~WorkAreaObserver(); |
| 76 |
| 77 // Overridden from ShellObserver: |
| 78 virtual void OnDisplayWorkAreaInsetsChanged() OVERRIDE; |
| 79 |
| 80 // Overridden from ShelfLayoutManagerObserver: |
| 81 virtual void OnAutoHideStateChanged(ShelfAutoHideState new_state) OVERRIDE; |
| 82 |
| 83 private: |
| 84 message_center::MessagePopupCollection* collection_; |
| 85 ShelfLayoutManager* shelf_; |
| 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(WorkAreaObserver); |
| 88 }; |
| 89 |
| 90 WorkAreaObserver::WorkAreaObserver( |
| 91 message_center::MessagePopupCollection* collection, |
| 92 ShelfLayoutManager* shelf) |
| 93 : collection_(collection), |
| 94 shelf_(shelf) { |
| 95 DCHECK(collection_); |
| 96 shelf_->AddObserver(this); |
| 97 Shell::GetInstance()->AddShellObserver(this); |
| 98 } |
| 99 |
| 100 WorkAreaObserver::~WorkAreaObserver() { |
| 101 Shell::GetInstance()->RemoveShellObserver(this); |
| 102 shelf_->RemoveObserver(this); |
| 103 } |
| 104 |
| 105 void WorkAreaObserver::OnDisplayWorkAreaInsetsChanged() { |
| 106 collection_->OnDisplayBoundsChanged( |
| 107 Shell::GetScreen()->GetDisplayNearestWindow( |
| 108 shelf_->shelf_widget()->GetNativeView())); |
| 109 } |
| 110 |
| 111 void WorkAreaObserver::OnAutoHideStateChanged(ShelfAutoHideState new_state) { |
| 112 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow( |
| 113 shelf_->shelf_widget()->GetNativeView()).work_area(); |
| 114 int width = (new_state == SHELF_AUTO_HIDE_HIDDEN) ? |
| 115 ShelfLayoutManager::kAutoHideSize : |
| 116 ShelfLayoutManager::GetPreferredShelfSize(); |
| 117 switch (shelf_->GetAlignment()) { |
| 118 case SHELF_ALIGNMENT_BOTTOM: |
| 119 work_area.Inset(0, 0, 0, width); |
| 120 break; |
| 121 case SHELF_ALIGNMENT_LEFT: |
| 122 work_area.Inset(width, 0, 0, 0); |
| 123 break; |
| 124 case SHELF_ALIGNMENT_RIGHT: |
| 125 work_area.Inset(0, 0, width, 0); |
| 126 break; |
| 127 case SHELF_ALIGNMENT_TOP: |
| 128 work_area.Inset(0, width, 0, 0); |
| 129 break; |
| 130 } |
| 131 collection_->SetWorkArea(work_area); |
| 132 } |
| 133 |
| 66 // Class to initialize and manage the WebNotificationBubble and | 134 // Class to initialize and manage the WebNotificationBubble and |
| 67 // TrayBubbleWrapper instances for a bubble. | 135 // TrayBubbleWrapper instances for a bubble. |
| 68 | |
| 69 class WebNotificationBubbleWrapper { | 136 class WebNotificationBubbleWrapper { |
| 70 public: | 137 public: |
| 71 // Takes ownership of |bubble| and creates |bubble_wrapper_|. | 138 // Takes ownership of |bubble| and creates |bubble_wrapper_|. |
| 72 WebNotificationBubbleWrapper(WebNotificationTray* tray, | 139 WebNotificationBubbleWrapper(WebNotificationTray* tray, |
| 73 message_center::MessageBubbleBase* bubble) { | 140 message_center::MessageBubbleBase* bubble) { |
| 74 bubble_.reset(bubble); | 141 bubble_.reset(bubble); |
| 75 views::TrayBubbleView::AnchorAlignment anchor_alignment = | 142 views::TrayBubbleView::AnchorAlignment anchor_alignment = |
| 76 tray->GetAnchorAlignment(); | 143 tray->GetAnchorAlignment(); |
| 77 views::TrayBubbleView::InitParams init_params = | 144 views::TrayBubbleView::InitParams init_params = |
| 78 bubble->GetInitParams(anchor_alignment); | 145 bubble->GetInitParams(anchor_alignment); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 message_center_tray_.reset(new message_center::MessageCenterTray( | 245 message_center_tray_.reset(new message_center::MessageCenterTray( |
| 179 this, | 246 this, |
| 180 message_center::MessageCenter::Get())); | 247 message_center::MessageCenter::Get())); |
| 181 OnMessageCenterTrayChanged(); | 248 OnMessageCenterTrayChanged(); |
| 182 } | 249 } |
| 183 | 250 |
| 184 WebNotificationTray::~WebNotificationTray() { | 251 WebNotificationTray::~WebNotificationTray() { |
| 185 // Release any child views that might have back pointers before ~View(). | 252 // Release any child views that might have back pointers before ~View(). |
| 186 message_center_bubble_.reset(); | 253 message_center_bubble_.reset(); |
| 187 popup_collection_.reset(); | 254 popup_collection_.reset(); |
| 255 work_area_observer_.reset(); |
| 188 } | 256 } |
| 189 | 257 |
| 190 // Public methods. | 258 // Public methods. |
| 191 | 259 |
| 192 bool WebNotificationTray::ShowMessageCenterInternal(bool show_settings) { | 260 bool WebNotificationTray::ShowMessageCenterInternal(bool show_settings) { |
| 193 if (!ShouldShowMessageCenter()) | 261 if (!ShouldShowMessageCenter()) |
| 194 return false; | 262 return false; |
| 195 | 263 |
| 196 should_block_shelf_auto_hide_ = true; | 264 should_block_shelf_auto_hide_ = true; |
| 197 message_center::MessageCenterBubble* message_center_bubble = | 265 message_center::MessageCenterBubble* message_center_bubble = |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 !status_area_widget()->ShouldShowWebNotifications()) { | 331 !status_area_widget()->ShouldShowWebNotifications()) { |
| 264 return false; | 332 return false; |
| 265 } | 333 } |
| 266 | 334 |
| 267 popup_collection_.reset(new message_center::MessagePopupCollection( | 335 popup_collection_.reset(new message_center::MessagePopupCollection( |
| 268 ash::Shell::GetContainer( | 336 ash::Shell::GetContainer( |
| 269 GetWidget()->GetNativeView()->GetRootWindow(), | 337 GetWidget()->GetNativeView()->GetRootWindow(), |
| 270 internal::kShellWindowId_StatusContainer), | 338 internal::kShellWindowId_StatusContainer), |
| 271 message_center(), | 339 message_center(), |
| 272 message_center_tray_.get())); | 340 message_center_tray_.get())); |
| 273 | 341 work_area_observer_.reset(new internal::WorkAreaObserver( |
| 342 popup_collection_.get(), GetShelfLayoutManager())); |
| 274 return true; | 343 return true; |
| 275 } | 344 } |
| 276 | 345 |
| 277 void WebNotificationTray::HidePopups() { | 346 void WebNotificationTray::HidePopups() { |
| 278 popup_collection_.reset(); | 347 popup_collection_.reset(); |
| 348 work_area_observer_.reset(); |
| 279 } | 349 } |
| 280 | 350 |
| 281 // Private methods. | 351 // Private methods. |
| 282 | 352 |
| 283 bool WebNotificationTray::ShouldShowMessageCenter() { | 353 bool WebNotificationTray::ShouldShowMessageCenter() { |
| 284 return status_area_widget()->login_status() != user::LOGGED_IN_LOCKED && | 354 return status_area_widget()->login_status() != user::LOGGED_IN_LOCKED && |
| 285 !(status_area_widget()->system_tray() && | 355 !(status_area_widget()->system_tray() && |
| 286 status_area_widget()->system_tray()->HasNotificationBubble()); | 356 status_area_widget()->system_tray()->HasNotificationBubble()); |
| 287 } | 357 } |
| 288 | 358 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 | 559 |
| 490 message_center::MessageCenterBubble* | 560 message_center::MessageCenterBubble* |
| 491 WebNotificationTray::GetMessageCenterBubbleForTest() { | 561 WebNotificationTray::GetMessageCenterBubbleForTest() { |
| 492 if (!message_center_bubble()) | 562 if (!message_center_bubble()) |
| 493 return NULL; | 563 return NULL; |
| 494 return static_cast<message_center::MessageCenterBubble*>( | 564 return static_cast<message_center::MessageCenterBubble*>( |
| 495 message_center_bubble()->bubble()); | 565 message_center_bubble()->bubble()); |
| 496 } | 566 } |
| 497 | 567 |
| 498 } // namespace ash | 568 } // namespace ash |
| OLD | NEW |