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/common/system/web_notification/web_notification_tray.h" | 5 #include "ash/common/system/web_notification/web_notification_tray.h" |
6 | 6 |
7 #include "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
8 #include "ash/common/session/session_state_delegate.h" | 8 #include "ash/common/session/session_state_delegate.h" |
9 #include "ash/common/shelf/shelf_constants.h" | 9 #include "ash/common/shelf/shelf_constants.h" |
10 #include "ash/common/shelf/wm_shelf.h" | 10 #include "ash/common/shelf/wm_shelf.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 // Flag to disable animation. Only for testing. | 80 // Flag to disable animation. Only for testing. |
81 bool disable_animations_for_test = false; | 81 bool disable_animations_for_test = false; |
82 } | 82 } |
83 | 83 |
84 namespace { | 84 namespace { |
85 | 85 |
86 const SkColor kWebNotificationColorNoUnread = | 86 const SkColor kWebNotificationColorNoUnread = |
87 SkColorSetARGB(128, 255, 255, 255); | 87 SkColorSetARGB(128, 255, 255, 255); |
88 const SkColor kWebNotificationColorWithUnread = SK_ColorWHITE; | 88 const SkColor kWebNotificationColorWithUnread = SK_ColorWHITE; |
89 const int kNoUnreadIconSize = 18; | 89 const int kNoUnreadIconSize = 18; |
90 } | 90 |
| 91 } // namespace |
91 | 92 |
92 // Class to initialize and manage the WebNotificationBubble and | 93 // Class to initialize and manage the WebNotificationBubble and |
93 // TrayBubbleWrapper instances for a bubble. | 94 // TrayBubbleWrapper instances for a bubble. |
94 class WebNotificationBubbleWrapper { | 95 class WebNotificationBubbleWrapper { |
95 public: | 96 public: |
96 // Takes ownership of |bubble| and creates |bubble_wrapper_|. | 97 // Takes ownership of |bubble| and creates |bubble_wrapper_|. |
97 WebNotificationBubbleWrapper(WebNotificationTray* tray, | 98 WebNotificationBubbleWrapper(WebNotificationTray* tray, |
98 message_center::MessageBubbleBase* bubble) { | 99 message_center::MessageBubbleBase* bubble) { |
99 bubble_.reset(bubble); | 100 bubble_.reset(bubble); |
100 views::TrayBubbleView::AnchorAlignment anchor_alignment = | 101 views::TrayBubbleView::AnchorAlignment anchor_alignment = |
101 tray->GetAnchorAlignment(); | 102 tray->GetAnchorAlignment(); |
102 views::TrayBubbleView::InitParams init_params = | 103 views::TrayBubbleView::InitParams init_params = |
103 bubble->GetInitParams(anchor_alignment); | 104 bubble->GetInitParams(anchor_alignment); |
104 views::View* anchor = tray->tray_container(); | 105 views::TrayBubbleView* bubble_view = views::TrayBubbleView::Create( |
105 if (anchor_alignment == views::TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { | 106 tray->GetBubbleAnchor(), tray, &init_params); |
106 gfx::Point bounds(anchor->width() / 2, 0); | 107 bubble_view->set_anchor_view_insets(tray->GetBubbleAnchorInsets()); |
107 views::View::ConvertPointToWidget(anchor, &bounds); | |
108 init_params.arrow_offset = bounds.x(); | |
109 } | |
110 DCHECK(anchor); | |
111 // TrayBubbleView uses |anchor| and |tray| to determine the parent | |
112 // container. See WebNotificationTray::OnBeforeBubbleWidgetInit(). | |
113 views::TrayBubbleView* bubble_view = | |
114 views::TrayBubbleView::Create(anchor, tray, &init_params); | |
115 bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_view)); | 108 bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_view)); |
116 bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); | |
117 bubble->InitializeContents(bubble_view); | 109 bubble->InitializeContents(bubble_view); |
118 } | 110 } |
119 | 111 |
120 message_center::MessageBubbleBase* bubble() const { return bubble_.get(); } | 112 message_center::MessageBubbleBase* bubble() const { return bubble_.get(); } |
121 | 113 |
122 // Convenience accessors. | 114 // Convenience accessors. |
123 views::TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); } | 115 views::TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); } |
124 | 116 |
125 private: | 117 private: |
126 std::unique_ptr<message_center::MessageBubbleBase> bubble_; | 118 std::unique_ptr<message_center::MessageBubbleBase> bubble_; |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 | 344 |
353 // Public methods. | 345 // Public methods. |
354 | 346 |
355 bool WebNotificationTray::ShowMessageCenterInternal(bool show_settings) { | 347 bool WebNotificationTray::ShowMessageCenterInternal(bool show_settings) { |
356 if (!ShouldShowMessageCenter()) | 348 if (!ShouldShowMessageCenter()) |
357 return false; | 349 return false; |
358 | 350 |
359 should_block_shelf_auto_hide_ = true; | 351 should_block_shelf_auto_hide_ = true; |
360 message_center::MessageCenterBubble* message_center_bubble = | 352 message_center::MessageCenterBubble* message_center_bubble = |
361 new message_center::MessageCenterBubble(message_center(), | 353 new message_center::MessageCenterBubble(message_center(), |
362 message_center_tray_.get(), true); | 354 message_center_tray_.get()); |
363 | 355 |
364 int max_height; | 356 int max_height; |
365 if (IsHorizontalAlignment(shelf_alignment())) { | 357 if (IsHorizontalAlignment(shelf_alignment())) { |
366 max_height = shelf()->GetIdealBounds().y(); | 358 max_height = shelf()->GetIdealBounds().y(); |
367 } else { | 359 } else { |
368 // Assume the status area and bubble bottoms are aligned when vertical. | 360 // Assume the status area and bubble bottoms are aligned when vertical. |
369 gfx::Rect bounds_in_root = | 361 gfx::Rect bounds_in_root = |
370 status_area_window_->GetRootWindow()->ConvertRectFromScreen( | 362 status_area_window_->GetRootWindow()->ConvertRectFromScreen( |
371 status_area_window_->GetBoundsInScreen()); | 363 status_area_window_->GetBoundsInScreen()); |
372 max_height = bounds_in_root.bottom(); | 364 max_height = bounds_in_root.bottom(); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 } | 487 } |
496 | 488 |
497 void WebNotificationTray::OnMouseEnteredView() {} | 489 void WebNotificationTray::OnMouseEnteredView() {} |
498 | 490 |
499 void WebNotificationTray::OnMouseExitedView() {} | 491 void WebNotificationTray::OnMouseExitedView() {} |
500 | 492 |
501 base::string16 WebNotificationTray::GetAccessibleNameForBubble() { | 493 base::string16 WebNotificationTray::GetAccessibleNameForBubble() { |
502 return GetAccessibleNameForTray(); | 494 return GetAccessibleNameForTray(); |
503 } | 495 } |
504 | 496 |
505 gfx::Rect WebNotificationTray::GetAnchorRect( | |
506 views::Widget* anchor_widget, | |
507 views::TrayBubbleView::AnchorType anchor_type, | |
508 views::TrayBubbleView::AnchorAlignment anchor_alignment) const { | |
509 return GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment); | |
510 } | |
511 | |
512 void WebNotificationTray::OnBeforeBubbleWidgetInit( | 497 void WebNotificationTray::OnBeforeBubbleWidgetInit( |
513 views::Widget* anchor_widget, | 498 views::Widget* anchor_widget, |
514 views::Widget* bubble_widget, | 499 views::Widget* bubble_widget, |
515 views::Widget::InitParams* params) const { | 500 views::Widget::InitParams* params) const { |
516 // Place the bubble in the same root window as |anchor_widget|. | 501 // Place the bubble in the same root window as |anchor_widget|. |
517 WmLookup::Get() | 502 WmLookup::Get() |
518 ->GetWindowForWidget(anchor_widget) | 503 ->GetWindowForWidget(anchor_widget) |
519 ->GetRootWindowController() | 504 ->GetRootWindowController() |
520 ->ConfigureWidgetInitParamsForContainer( | 505 ->ConfigureWidgetInitParamsForContainer( |
521 bubble_widget, kShellWindowId_SettingBubbleContainer, params); | 506 bubble_widget, kShellWindowId_SettingBubbleContainer, params); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 | 653 |
669 message_center::MessageCenterBubble* | 654 message_center::MessageCenterBubble* |
670 WebNotificationTray::GetMessageCenterBubbleForTest() { | 655 WebNotificationTray::GetMessageCenterBubbleForTest() { |
671 if (!message_center_bubble()) | 656 if (!message_center_bubble()) |
672 return nullptr; | 657 return nullptr; |
673 return static_cast<message_center::MessageCenterBubble*>( | 658 return static_cast<message_center::MessageCenterBubble*>( |
674 message_center_bubble()->bubble()); | 659 message_center_bubble()->bubble()); |
675 } | 660 } |
676 | 661 |
677 } // namespace ash | 662 } // namespace ash |
OLD | NEW |