Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: ash/common/system/web_notification/web_notification_tray.cc

Issue 2491033006: Adjust positioning of cros tray bubbles. (Closed)
Patch Set: . Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 } 486 }
495 487
496 void WebNotificationTray::OnMouseEnteredView() {} 488 void WebNotificationTray::OnMouseEnteredView() {}
497 489
498 void WebNotificationTray::OnMouseExitedView() {} 490 void WebNotificationTray::OnMouseExitedView() {}
499 491
500 base::string16 WebNotificationTray::GetAccessibleNameForBubble() { 492 base::string16 WebNotificationTray::GetAccessibleNameForBubble() {
501 return GetAccessibleNameForTray(); 493 return GetAccessibleNameForTray();
502 } 494 }
503 495
504 gfx::Rect WebNotificationTray::GetAnchorRect(
505 views::Widget* anchor_widget,
506 views::TrayBubbleView::AnchorType anchor_type,
507 views::TrayBubbleView::AnchorAlignment anchor_alignment) const {
508 return GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment);
509 }
510
511 void WebNotificationTray::OnBeforeBubbleWidgetInit( 496 void WebNotificationTray::OnBeforeBubbleWidgetInit(
512 views::Widget* anchor_widget, 497 views::Widget* anchor_widget,
513 views::Widget* bubble_widget, 498 views::Widget* bubble_widget,
514 views::Widget::InitParams* params) const { 499 views::Widget::InitParams* params) const {
515 // Place the bubble in the same root window as |anchor_widget|. 500 // Place the bubble in the same root window as |anchor_widget|.
516 WmLookup::Get() 501 WmLookup::Get()
517 ->GetWindowForWidget(anchor_widget) 502 ->GetWindowForWidget(anchor_widget)
518 ->GetRootWindowController() 503 ->GetRootWindowController()
519 ->ConfigureWidgetInitParamsForContainer( 504 ->ConfigureWidgetInitParamsForContainer(
520 bubble_widget, kShellWindowId_SettingBubbleContainer, params); 505 bubble_widget, kShellWindowId_SettingBubbleContainer, params);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 652
668 message_center::MessageCenterBubble* 653 message_center::MessageCenterBubble*
669 WebNotificationTray::GetMessageCenterBubbleForTest() { 654 WebNotificationTray::GetMessageCenterBubbleForTest() {
670 if (!message_center_bubble()) 655 if (!message_center_bubble())
671 return nullptr; 656 return nullptr;
672 return static_cast<message_center::MessageCenterBubble*>( 657 return static_cast<message_center::MessageCenterBubble*>(
673 message_center_bubble()->bubble()); 658 message_center_bubble()->bubble());
674 } 659 }
675 660
676 } // namespace ash 661 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698