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 "base/auto_reset.h" | 20 #include "base/auto_reset.h" |
21 #include "base/i18n/number_formatting.h" | 21 #include "base/i18n/number_formatting.h" |
| 22 #include "base/i18n/rtl.h" |
22 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
23 #include "grit/ash_strings.h" | 24 #include "grit/ash_strings.h" |
24 #include "grit/ui_strings.h" | 25 #include "grit/ui_strings.h" |
25 #include "ui/aura/root_window.h" | 26 #include "ui/aura/root_window.h" |
26 #include "ui/aura/window.h" | 27 #include "ui/aura/window.h" |
27 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
28 #include "ui/gfx/screen.h" | 29 #include "ui/gfx/screen.h" |
| 30 #include "ui/message_center/message_center_style.h" |
29 #include "ui/message_center/message_center_tray_delegate.h" | 31 #include "ui/message_center/message_center_tray_delegate.h" |
30 #include "ui/message_center/message_center_util.h" | 32 #include "ui/message_center/message_center_util.h" |
31 #include "ui/message_center/views/message_bubble_base.h" | 33 #include "ui/message_center/views/message_bubble_base.h" |
32 #include "ui/message_center/views/message_center_bubble.h" | 34 #include "ui/message_center/views/message_center_bubble.h" |
33 #include "ui/message_center/views/message_popup_collection.h" | 35 #include "ui/message_center/views/message_popup_collection.h" |
34 #include "ui/views/bubble/tray_bubble_view.h" | 36 #include "ui/views/bubble/tray_bubble_view.h" |
35 #include "ui/views/controls/button/custom_button.h" | 37 #include "ui/views/controls/button/custom_button.h" |
36 #include "ui/views/controls/image_view.h" | 38 #include "ui/views/controls/image_view.h" |
37 #include "ui/views/controls/label.h" | 39 #include "ui/views/controls/label.h" |
38 #include "ui/views/controls/menu/menu_runner.h" | 40 #include "ui/views/controls/menu/menu_runner.h" |
(...skipping 28 matching lines...) Expand all Loading... |
67 | 69 |
68 // Observes the change of work area (including temporary change by auto-hide) | 70 // Observes the change of work area (including temporary change by auto-hide) |
69 // and notifies MessagePopupCollection. | 71 // and notifies MessagePopupCollection. |
70 class WorkAreaObserver : public ShelfLayoutManagerObserver, | 72 class WorkAreaObserver : public ShelfLayoutManagerObserver, |
71 public ShellObserver { | 73 public ShellObserver { |
72 public: | 74 public: |
73 WorkAreaObserver(message_center::MessagePopupCollection* collection, | 75 WorkAreaObserver(message_center::MessagePopupCollection* collection, |
74 ShelfLayoutManager* shelf); | 76 ShelfLayoutManager* shelf); |
75 virtual ~WorkAreaObserver(); | 77 virtual ~WorkAreaObserver(); |
76 | 78 |
| 79 void SetSystemTrayHeight(int height); |
| 80 |
77 // Overridden from ShellObserver: | 81 // Overridden from ShellObserver: |
78 virtual void OnDisplayWorkAreaInsetsChanged() OVERRIDE; | 82 virtual void OnDisplayWorkAreaInsetsChanged() OVERRIDE; |
79 | 83 |
80 // Overridden from ShelfLayoutManagerObserver: | 84 // Overridden from ShelfLayoutManagerObserver: |
81 virtual void OnAutoHideStateChanged(ShelfAutoHideState new_state) OVERRIDE; | 85 virtual void OnAutoHideStateChanged(ShelfAutoHideState new_state) OVERRIDE; |
82 | 86 |
83 private: | 87 private: |
84 message_center::MessagePopupCollection* collection_; | 88 message_center::MessagePopupCollection* collection_; |
85 ShelfLayoutManager* shelf_; | 89 ShelfLayoutManager* shelf_; |
| 90 int system_tray_height_; |
86 | 91 |
87 DISALLOW_COPY_AND_ASSIGN(WorkAreaObserver); | 92 DISALLOW_COPY_AND_ASSIGN(WorkAreaObserver); |
88 }; | 93 }; |
89 | 94 |
90 WorkAreaObserver::WorkAreaObserver( | 95 WorkAreaObserver::WorkAreaObserver( |
91 message_center::MessagePopupCollection* collection, | 96 message_center::MessagePopupCollection* collection, |
92 ShelfLayoutManager* shelf) | 97 ShelfLayoutManager* shelf) |
93 : collection_(collection), | 98 : collection_(collection), |
94 shelf_(shelf) { | 99 shelf_(shelf), |
| 100 system_tray_height_(0) { |
95 DCHECK(collection_); | 101 DCHECK(collection_); |
96 shelf_->AddObserver(this); | 102 shelf_->AddObserver(this); |
97 Shell::GetInstance()->AddShellObserver(this); | 103 Shell::GetInstance()->AddShellObserver(this); |
98 } | 104 } |
99 | 105 |
100 WorkAreaObserver::~WorkAreaObserver() { | 106 WorkAreaObserver::~WorkAreaObserver() { |
101 Shell::GetInstance()->RemoveShellObserver(this); | 107 Shell::GetInstance()->RemoveShellObserver(this); |
102 shelf_->RemoveObserver(this); | 108 shelf_->RemoveObserver(this); |
103 } | 109 } |
104 | 110 |
| 111 void WorkAreaObserver::SetSystemTrayHeight(int height) { |
| 112 system_tray_height_ = height; |
| 113 if (system_tray_height_ > 0 && ash::switches::UseAlternateShelfLayout()) |
| 114 system_tray_height_ += message_center::kMarginBetweenItems; |
| 115 |
| 116 OnAutoHideStateChanged(shelf_->auto_hide_state()); |
| 117 } |
| 118 |
105 void WorkAreaObserver::OnDisplayWorkAreaInsetsChanged() { | 119 void WorkAreaObserver::OnDisplayWorkAreaInsetsChanged() { |
106 collection_->OnDisplayBoundsChanged( | 120 collection_->OnDisplayBoundsChanged( |
107 Shell::GetScreen()->GetDisplayNearestWindow( | 121 Shell::GetScreen()->GetDisplayNearestWindow( |
108 shelf_->shelf_widget()->GetNativeView())); | 122 shelf_->shelf_widget()->GetNativeView())); |
109 } | 123 } |
110 | 124 |
111 void WorkAreaObserver::OnAutoHideStateChanged(ShelfAutoHideState new_state) { | 125 void WorkAreaObserver::OnAutoHideStateChanged(ShelfAutoHideState new_state) { |
112 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( | 126 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( |
113 shelf_->shelf_widget()->GetNativeView()); | 127 shelf_->shelf_widget()->GetNativeView()); |
114 gfx::Rect work_area = display.work_area(); | 128 gfx::Rect work_area = display.work_area(); |
115 int width = (new_state == SHELF_AUTO_HIDE_HIDDEN) ? | 129 int width = 0; |
116 ShelfLayoutManager::kAutoHideSize : | 130 if (shelf_->auto_hide_behavior() != SHELF_AUTO_HIDE_BEHAVIOR_NEVER) { |
117 ShelfLayoutManager::GetPreferredShelfSize(); | 131 width = (new_state == SHELF_AUTO_HIDE_HIDDEN) ? |
| 132 ShelfLayoutManager::kAutoHideSize : |
| 133 ShelfLayoutManager::GetPreferredShelfSize(); |
| 134 } |
118 switch (shelf_->GetAlignment()) { | 135 switch (shelf_->GetAlignment()) { |
119 case SHELF_ALIGNMENT_BOTTOM: | 136 case SHELF_ALIGNMENT_BOTTOM: |
120 work_area.Inset(0, 0, 0, width); | 137 work_area.Inset(0, 0, 0, width); |
| 138 if (system_tray_height_ > 0) { |
| 139 work_area.set_height( |
| 140 std::max(0, work_area.height() - system_tray_height_)); |
| 141 } |
121 break; | 142 break; |
122 case SHELF_ALIGNMENT_LEFT: | 143 case SHELF_ALIGNMENT_LEFT: |
123 work_area.Inset(width, 0, 0, 0); | 144 work_area.Inset(width, 0, 0, 0); |
| 145 // Popups appear on the left bottom only when UI is RTL. |
| 146 if (base::i18n::IsRTL() && system_tray_height_ > 0) { |
| 147 work_area.set_height( |
| 148 std::max(0, work_area.height() - system_tray_height_)); |
| 149 } |
124 break; | 150 break; |
125 case SHELF_ALIGNMENT_RIGHT: | 151 case SHELF_ALIGNMENT_RIGHT: |
126 work_area.Inset(0, 0, width, 0); | 152 work_area.Inset(0, 0, width, 0); |
| 153 // Popups appear on the right bottom only when UI isn't RTL. |
| 154 if (!base::i18n::IsRTL() && system_tray_height_ > 0) { |
| 155 work_area.set_height( |
| 156 std::max(0, work_area.height() - system_tray_height_)); |
| 157 } |
127 break; | 158 break; |
128 case SHELF_ALIGNMENT_TOP: | 159 case SHELF_ALIGNMENT_TOP: |
129 work_area.Inset(0, width, 0, 0); | 160 work_area.Inset(0, width, 0, 0); |
| 161 if (system_tray_height_ > 0) { |
| 162 work_area.set_y(work_area.y() + system_tray_height_); |
| 163 work_area.set_height( |
| 164 std::max(0, work_area.height() - system_tray_height_)); |
| 165 } |
130 break; | 166 break; |
131 } | 167 } |
132 collection_->SetDisplayInfo(work_area, display.bounds()); | 168 collection_->SetDisplayInfo(work_area, display.bounds()); |
133 } | 169 } |
134 | 170 |
135 // Class to initialize and manage the WebNotificationBubble and | 171 // Class to initialize and manage the WebNotificationBubble and |
136 // TrayBubbleWrapper instances for a bubble. | 172 // TrayBubbleWrapper instances for a bubble. |
137 class WebNotificationBubbleWrapper { | 173 class WebNotificationBubbleWrapper { |
138 public: | 174 public: |
139 // Takes ownership of |bubble| and creates |bubble_wrapper_|. | 175 // Takes ownership of |bubble| and creates |bubble_wrapper_|. |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 if (!message_center_bubble()) | 350 if (!message_center_bubble()) |
315 return; | 351 return; |
316 message_center_bubble_.reset(); | 352 message_center_bubble_.reset(); |
317 should_block_shelf_auto_hide_ = false; | 353 should_block_shelf_auto_hide_ = false; |
318 show_message_center_on_unlock_ = false; | 354 show_message_center_on_unlock_ = false; |
319 status_area_widget()->SetHideSystemNotifications(false); | 355 status_area_widget()->SetHideSystemNotifications(false); |
320 GetShelfLayoutManager()->UpdateAutoHideState(); | 356 GetShelfLayoutManager()->UpdateAutoHideState(); |
321 button_->SetBubbleVisible(false); | 357 button_->SetBubbleVisible(false); |
322 } | 358 } |
323 | 359 |
324 void WebNotificationTray::SetHidePopupBubble(bool hide) { | 360 void WebNotificationTray::SetSystemTrayHeight(int height) { |
325 if (hide) | 361 if (!work_area_observer_) |
326 message_center_tray_->HidePopupBubble(); | 362 return; |
327 else | 363 work_area_observer_->SetSystemTrayHeight(height); |
328 message_center_tray_->ShowPopupBubble(); | |
329 } | 364 } |
330 | 365 |
331 bool WebNotificationTray::ShowPopups() { | 366 bool WebNotificationTray::ShowPopups() { |
332 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED || | 367 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED || |
333 message_center_bubble() || | 368 message_center_bubble() || |
334 !status_area_widget()->ShouldShowWebNotifications()) { | 369 !status_area_widget()->ShouldShowWebNotifications()) { |
335 return false; | 370 return false; |
336 } | 371 } |
337 | 372 |
338 popup_collection_.reset(new message_center::MessagePopupCollection( | 373 popup_collection_.reset(new message_center::MessagePopupCollection( |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 | 598 |
564 message_center::MessageCenterBubble* | 599 message_center::MessageCenterBubble* |
565 WebNotificationTray::GetMessageCenterBubbleForTest() { | 600 WebNotificationTray::GetMessageCenterBubbleForTest() { |
566 if (!message_center_bubble()) | 601 if (!message_center_bubble()) |
567 return NULL; | 602 return NULL; |
568 return static_cast<message_center::MessageCenterBubble*>( | 603 return static_cast<message_center::MessageCenterBubble*>( |
569 message_center_bubble()->bubble()); | 604 message_center_bubble()->bubble()); |
570 } | 605 } |
571 | 606 |
572 } // namespace ash | 607 } // namespace ash |
OLD | NEW |