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/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/common/shell_window_ids.h" | 8 #include "ash/common/shell_window_ids.h" |
| 9 #include "ash/common/wm/shelf/wm_shelf_util.h" | 9 #include "ash/common/wm/shelf/wm_shelf_util.h" |
| 10 #include "ash/common/wm/wm_lookup.h" | |
| 11 #include "ash/common/wm/wm_root_window_controller.h" | |
| 12 #include "ash/common/wm/wm_window.h" | |
| 10 #include "ash/root_window_controller.h" | 13 #include "ash/root_window_controller.h" |
| 11 #include "ash/shelf/shelf_layout_manager.h" | 14 #include "ash/shelf/shelf_layout_manager.h" |
| 12 #include "ash/shelf/shelf_layout_manager_observer.h" | 15 #include "ash/shelf/shelf_layout_manager_observer.h" |
| 13 #include "ash/shelf/shelf_util.h" | 16 #include "ash/shelf/shelf_util.h" |
| 14 #include "ash/shelf/shelf_widget.h" | 17 #include "ash/shelf/shelf_widget.h" |
| 15 #include "ash/shell.h" | 18 #include "ash/shell.h" |
| 16 #include "ash/system/status_area_widget.h" | 19 #include "ash/system/status_area_widget.h" |
| 17 #include "ash/system/tray/system_tray.h" | 20 #include "ash/system/tray/system_tray.h" |
| 18 #include "ash/system/tray/tray_background_view.h" | 21 #include "ash/system/tray/tray_background_view.h" |
| 19 #include "ash/system/tray/tray_bubble_wrapper.h" | 22 #include "ash/system/tray/tray_bubble_wrapper.h" |
| 20 #include "ash/system/tray/tray_constants.h" | 23 #include "ash/system/tray/tray_constants.h" |
| 21 #include "ash/system/tray/tray_utils.h" | 24 #include "ash/system/tray/tray_utils.h" |
| 22 #include "ash/system/web_notification/ash_popup_alignment_delegate.h" | 25 #include "ash/system/web_notification/ash_popup_alignment_delegate.h" |
| 23 #include "base/auto_reset.h" | 26 #include "base/auto_reset.h" |
| 24 #include "base/i18n/number_formatting.h" | 27 #include "base/i18n/number_formatting.h" |
| 25 #include "base/i18n/rtl.h" | 28 #include "base/i18n/rtl.h" |
| 26 #include "base/strings/utf_string_conversions.h" | 29 #include "base/strings/utf_string_conversions.h" |
| 27 #include "base/threading/thread_task_runner_handle.h" | 30 #include "base/threading/thread_task_runner_handle.h" |
| 28 #include "grit/ash_strings.h" | 31 #include "grit/ash_strings.h" |
| 29 #include "ui/aura/window.h" | |
| 30 #include "ui/aura/window_event_dispatcher.h" | |
| 31 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 32 #include "ui/display/display.h" | 33 #include "ui/display/display.h" |
| 33 #include "ui/display/screen.h" | 34 #include "ui/display/screen.h" |
| 34 #include "ui/gfx/paint_vector_icon.h" | 35 #include "ui/gfx/paint_vector_icon.h" |
| 35 #include "ui/gfx/vector_icons_public.h" | 36 #include "ui/gfx/vector_icons_public.h" |
| 36 #include "ui/message_center/message_center_style.h" | 37 #include "ui/message_center/message_center_style.h" |
| 37 #include "ui/message_center/message_center_tray_delegate.h" | 38 #include "ui/message_center/message_center_tray_delegate.h" |
| 38 #include "ui/message_center/views/message_bubble_base.h" | 39 #include "ui/message_center/views/message_bubble_base.h" |
| 39 #include "ui/message_center/views/message_center_bubble.h" | 40 #include "ui/message_center/views/message_center_bubble.h" |
| 40 #include "ui/message_center/views/message_popup_collection.h" | 41 #include "ui/message_center/views/message_popup_collection.h" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 button_->set_triggerable_event_flags( | 204 button_->set_triggerable_event_flags( |
| 204 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); | 205 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); |
| 205 tray_container()->AddChildView(button_); | 206 tray_container()->AddChildView(button_); |
| 206 SetContentsBackground(); | 207 SetContentsBackground(); |
| 207 tray_container()->SetBorder(views::Border::NullBorder()); | 208 tray_container()->SetBorder(views::Border::NullBorder()); |
| 208 message_center_tray_.reset(new message_center::MessageCenterTray( | 209 message_center_tray_.reset(new message_center::MessageCenterTray( |
| 209 this, | 210 this, |
| 210 message_center::MessageCenter::Get())); | 211 message_center::MessageCenter::Get())); |
| 211 popup_alignment_delegate_.reset(new AshPopupAlignmentDelegate( | 212 popup_alignment_delegate_.reset(new AshPopupAlignmentDelegate( |
| 212 status_area_widget->shelf_widget()->shelf_layout_manager())); | 213 status_area_widget->shelf_widget()->shelf_layout_manager())); |
| 214 // TODO(jamescook): Either MessagePopupCollection needs to become aware of | |
| 215 // mus or we need some sort of parent/container provider. | |
| 213 popup_collection_.reset(new message_center::MessagePopupCollection( | 216 popup_collection_.reset(new message_center::MessagePopupCollection( |
| 214 ash::Shell::GetContainer( | 217 ash::Shell::GetContainer( |
|
James Cook
2016/06/02 18:01:29
I'm not sure what to do about this. MessagePopupCo
sky
2016/06/02 18:15:59
I'm not familiar enough with message_center to say
James Cook
2016/06/02 19:42:19
Unfortunately it is shared with desktop Chrome for
| |
| 215 status_area_widget->GetNativeView()->GetRootWindow(), | 218 status_area_widget->GetNativeView()->GetRootWindow(), |
| 216 kShellWindowId_StatusContainer), | 219 kShellWindowId_StatusContainer), |
| 217 message_center(), | 220 message_center(), |
| 218 message_center_tray_.get(), | 221 message_center_tray_.get(), |
| 219 popup_alignment_delegate_.get())); | 222 popup_alignment_delegate_.get())); |
| 220 const display::Display& display = | 223 const display::Display& display = wm::WmLookup::Get() |
| 221 display::Screen::GetScreen()->GetDisplayNearestWindow( | 224 ->GetWindowForWidget(status_area_widget) |
| 222 status_area_widget->GetNativeView()); | 225 ->GetDisplayNearestWindow(); |
| 223 popup_alignment_delegate_->StartObserving(display::Screen::GetScreen(), | 226 popup_alignment_delegate_->StartObserving(display::Screen::GetScreen(), |
| 224 display); | 227 display); |
| 225 OnMessageCenterTrayChanged(); | 228 OnMessageCenterTrayChanged(); |
| 226 } | 229 } |
| 227 | 230 |
| 228 WebNotificationTray::~WebNotificationTray() { | 231 WebNotificationTray::~WebNotificationTray() { |
| 229 // Release any child views that might have back pointers before ~View(). | 232 // Release any child views that might have back pointers before ~View(). |
| 230 message_center_bubble_.reset(); | 233 message_center_bubble_.reset(); |
| 231 popup_alignment_delegate_.reset(); | 234 popup_alignment_delegate_.reset(); |
| 232 popup_collection_.reset(); | 235 popup_collection_.reset(); |
| 233 } | 236 } |
| 234 | 237 |
| 235 // Public methods. | 238 // Public methods. |
| 236 | 239 |
| 237 bool WebNotificationTray::ShowMessageCenterInternal(bool show_settings) { | 240 bool WebNotificationTray::ShowMessageCenterInternal(bool show_settings) { |
| 238 if (!ShouldShowMessageCenter()) | 241 if (!ShouldShowMessageCenter()) |
| 239 return false; | 242 return false; |
| 240 | 243 |
| 241 should_block_shelf_auto_hide_ = true; | 244 should_block_shelf_auto_hide_ = true; |
| 242 message_center::MessageCenterBubble* message_center_bubble = | 245 message_center::MessageCenterBubble* message_center_bubble = |
| 243 new message_center::MessageCenterBubble( | 246 new message_center::MessageCenterBubble( |
| 244 message_center(), | 247 message_center(), |
| 245 message_center_tray_.get(), | 248 message_center_tray_.get(), |
| 246 true); | 249 true); |
| 247 | 250 |
| 248 // Assume the status area and bubble bottoms are aligned when vertical. | 251 int max_height; |
| 249 aura::Window* status_area_window = status_area_widget()->GetNativeView(); | 252 if (wm::IsHorizontalAlignment(GetShelfLayoutManager()->GetAlignment())) { |
| 250 const int max_height = | 253 max_height = GetShelfLayoutManager()->GetIdealBounds().y(); |
| 251 wm::IsHorizontalAlignment(GetShelfLayoutManager()->GetAlignment()) | 254 } else { |
| 252 ? GetShelfLayoutManager()->GetIdealBounds().y() | 255 // Assume the status area and bubble bottoms are aligned when vertical. |
| 253 : status_area_window->GetBoundsInRootWindow().bottom(); | 256 wm::WmWindow* status_area_window = |
| 254 | 257 wm::WmLookup::Get()->GetWindowForWidget(status_area_widget()); |
| 258 gfx::Rect bounds_in_root = | |
| 259 status_area_window->GetRootWindow()->ConvertRectFromScreen( | |
| 260 status_area_window->GetBoundsInScreen()); | |
| 261 max_height = bounds_in_root.bottom(); | |
| 262 } | |
| 255 message_center_bubble->SetMaxHeight(std::max(0, max_height - kTraySpacing)); | 263 message_center_bubble->SetMaxHeight(std::max(0, max_height - kTraySpacing)); |
| 256 if (show_settings) | 264 if (show_settings) |
| 257 message_center_bubble->SetSettingsVisible(); | 265 message_center_bubble->SetSettingsVisible(); |
| 258 message_center_bubble_.reset( | 266 message_center_bubble_.reset( |
| 259 new WebNotificationBubbleWrapper(this, message_center_bubble)); | 267 new WebNotificationBubbleWrapper(this, message_center_bubble)); |
| 260 | 268 |
| 261 status_area_widget()->SetHideSystemNotifications(true); | 269 status_area_widget()->SetHideSystemNotifications(true); |
| 262 GetShelfLayoutManager()->UpdateAutoHideState(); | 270 GetShelfLayoutManager()->UpdateAutoHideState(); |
| 263 button_->SetBubbleVisible(true); | 271 button_->SetBubbleVisible(true); |
| 264 SetDrawBackgroundAsActive(true); | 272 SetDrawBackgroundAsActive(true); |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 | 513 |
| 506 message_center::MessageCenterBubble* | 514 message_center::MessageCenterBubble* |
| 507 WebNotificationTray::GetMessageCenterBubbleForTest() { | 515 WebNotificationTray::GetMessageCenterBubbleForTest() { |
| 508 if (!message_center_bubble()) | 516 if (!message_center_bubble()) |
| 509 return NULL; | 517 return NULL; |
| 510 return static_cast<message_center::MessageCenterBubble*>( | 518 return static_cast<message_center::MessageCenterBubble*>( |
| 511 message_center_bubble()->bubble()); | 519 message_center_bubble()->bubble()); |
| 512 } | 520 } |
| 513 | 521 |
| 514 } // namespace ash | 522 } // namespace ash |
| OLD | NEW |