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

Side by Side Diff: ash/common/shelf/overflow_bubble_view.cc

Issue 2164733002: mash: Convert ash shelf overflow bubble to wm common types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 5 months 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
« no previous file with comments | « ash/common/shelf/overflow_bubble_view.h ('k') | ash/common/shelf/overflow_button.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/shelf/overflow_bubble_view.h" 5 #include "ash/common/shelf/overflow_bubble_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/common/material_design/material_design_controller.h" 9 #include "ash/common/material_design/material_design_controller.h"
10 #include "ash/common/shelf/shelf_constants.h" 10 #include "ash/common/shelf/shelf_constants.h"
11 #include "ash/common/shelf/wm_shelf.h"
12 #include "ash/common/shelf/wm_shelf_util.h"
11 #include "ash/common/shell_window_ids.h" 13 #include "ash/common/shell_window_ids.h"
12 #include "ash/root_window_controller.h" 14 #include "ash/common/wm_lookup.h"
13 #include "ash/shelf/shelf.h" 15 #include "ash/common/wm_root_window_controller.h"
14 #include "ash/shelf/shelf_view.h" 16 #include "ash/common/wm_window.h"
15 #include "ash/shell.h"
16 #include "ui/display/display.h" 17 #include "ui/display/display.h"
17 #include "ui/display/screen.h" 18 #include "ui/display/screen.h"
18 #include "ui/events/event.h" 19 #include "ui/events/event.h"
19 #include "ui/gfx/geometry/insets.h" 20 #include "ui/gfx/geometry/insets.h"
20 #include "ui/views/bubble/bubble_frame_view.h" 21 #include "ui/views/bubble/bubble_frame_view.h"
22 #include "ui/views/view.h"
21 #include "ui/views/widget/widget.h" 23 #include "ui/views/widget/widget.h"
22 24
23 namespace ash { 25 namespace ash {
24 namespace { 26 namespace {
25 27
26 // Max bubble size to screen size ratio. 28 // Max bubble size to screen size ratio.
27 const float kMaxBubbleSizeToScreenRatio = 0.5f; 29 const float kMaxBubbleSizeToScreenRatio = 0.5f;
28 30
29 // Inner padding in pixels for shelf view inside bubble. 31 // Inner padding in pixels for shelf view inside bubble.
30 const int kPadding = 2; 32 const int kPadding = 2;
31 33
32 // Padding space in pixels between ShelfView's left/top edge to its contents. 34 // Padding space in pixels between ShelfView's left/top edge to its contents.
33 const int kShelfViewLeadingInset = 8; 35 const int kShelfViewLeadingInset = 8;
34 36
35 } // namespace 37 } // namespace
36 38
37 OverflowBubbleView::OverflowBubbleView() : shelf_view_(NULL) {} 39 OverflowBubbleView::OverflowBubbleView(WmShelf* wm_shelf)
40 : wm_shelf_(wm_shelf), shelf_view_(nullptr) {}
38 41
39 OverflowBubbleView::~OverflowBubbleView() {} 42 OverflowBubbleView::~OverflowBubbleView() {}
40 43
41 void OverflowBubbleView::InitOverflowBubble(views::View* anchor, 44 void OverflowBubbleView::InitOverflowBubble(views::View* anchor,
42 ShelfView* shelf_view) { 45 views::View* shelf_view) {
43 shelf_view_ = shelf_view; 46 shelf_view_ = shelf_view;
44 47
45 SetAnchorView(anchor); 48 SetAnchorView(anchor);
46 set_arrow(GetBubbleArrow()); 49 set_arrow(GetBubbleArrow());
47 set_mirror_arrow_in_rtl(false); 50 set_mirror_arrow_in_rtl(false);
48 set_background(NULL); 51 set_background(NULL);
49 SkColor color = MaterialDesignController::IsShelfMaterial() 52 SkColor color = MaterialDesignController::IsShelfMaterial()
50 ? kShelfBaseColor 53 ? kShelfBaseColor
51 : SkColorSetA(kShelfBaseColor, 54 : SkColorSetA(kShelfBaseColor,
52 GetShelfConstant(SHELF_BACKGROUND_ALPHA)); 55 GetShelfConstant(SHELF_BACKGROUND_ALPHA));
53 set_color(color); 56 set_color(color);
54 set_margins(gfx::Insets(kPadding, kPadding, kPadding, kPadding)); 57 set_margins(gfx::Insets(kPadding, kPadding, kPadding, kPadding));
55 // Overflow bubble should not get focus. If it get focus when it is shown, 58 // Overflow bubble should not get focus. If it get focus when it is shown,
56 // active state item is changed to running state. 59 // active state item is changed to running state.
57 set_can_activate(false); 60 set_can_activate(false);
58 61
59 // Makes bubble view has a layer and clip its children layers. 62 // Makes bubble view has a layer and clip its children layers.
60 SetPaintToLayer(true); 63 SetPaintToLayer(true);
61 layer()->SetFillsBoundsOpaquely(false); 64 layer()->SetFillsBoundsOpaquely(false);
62 layer()->SetMasksToBounds(true); 65 layer()->SetMasksToBounds(true);
63 66
64 set_parent_window(Shell::GetContainer( 67 // Calls into OnBeforeBubbleWidgetInit to set the window parent container.
65 anchor->GetWidget()->GetNativeWindow()->GetRootWindow(),
66 kShellWindowId_ShelfBubbleContainer));
67 views::BubbleDialogDelegateView::CreateBubble(this); 68 views::BubbleDialogDelegateView::CreateBubble(this);
68 AddChildView(shelf_view_); 69 AddChildView(shelf_view_);
69 } 70 }
70 71
71 bool OverflowBubbleView::IsHorizontalAlignment() const { 72 bool OverflowBubbleView::IsHorizontalAlignment() const {
72 return shelf_view_ ? shelf_view_->shelf()->IsHorizontalAlignment() : false; 73 return ::ash::IsHorizontalAlignment(wm_shelf_->GetAlignment());
73 } 74 }
74 75
75 const gfx::Size OverflowBubbleView::GetContentsSize() const { 76 const gfx::Size OverflowBubbleView::GetContentsSize() const {
76 return static_cast<views::View*>(shelf_view_)->GetPreferredSize(); 77 return shelf_view_->GetPreferredSize();
77 } 78 }
78 79
79 // Gets arrow location based on shelf alignment. 80 // Gets arrow location based on shelf alignment.
80 views::BubbleBorder::Arrow OverflowBubbleView::GetBubbleArrow() const { 81 views::BubbleBorder::Arrow OverflowBubbleView::GetBubbleArrow() const {
81 if (!shelf_view_) 82 switch (wm_shelf_->GetAlignment()) {
82 return views::BubbleBorder::NONE; 83 case SHELF_ALIGNMENT_BOTTOM:
83 return shelf_view_->shelf()->SelectValueForShelfAlignment( 84 case SHELF_ALIGNMENT_BOTTOM_LOCKED:
84 views::BubbleBorder::BOTTOM_LEFT, views::BubbleBorder::LEFT_TOP, 85 return views::BubbleBorder::BOTTOM_LEFT;
85 views::BubbleBorder::RIGHT_TOP); 86 case SHELF_ALIGNMENT_LEFT:
87 return views::BubbleBorder::LEFT_TOP;
88 case SHELF_ALIGNMENT_RIGHT:
89 return views::BubbleBorder::RIGHT_TOP;
90 }
91 NOTREACHED();
92 return views::BubbleBorder::NONE;
86 } 93 }
87 94
88 void OverflowBubbleView::ScrollByXOffset(int x_offset) { 95 void OverflowBubbleView::ScrollByXOffset(int x_offset) {
89 const gfx::Rect visible_bounds(GetContentsBounds()); 96 const gfx::Rect visible_bounds(GetContentsBounds());
90 const gfx::Size contents_size(GetContentsSize()); 97 const gfx::Size contents_size(GetContentsSize());
91 98
92 DCHECK_GE(contents_size.width(), visible_bounds.width()); 99 DCHECK_GE(contents_size.width(), visible_bounds.width());
93 int x = std::min(contents_size.width() - visible_bounds.width(), 100 int x = std::min(contents_size.width() - visible_bounds.width(),
94 std::max(0, scroll_offset_.x() + x_offset)); 101 std::max(0, scroll_offset_.x() + x_offset));
95 scroll_offset_.set_x(x); 102 scroll_offset_.set_x(x);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 ScrollByXOffset(-event->x_offset()); 172 ScrollByXOffset(-event->x_offset());
166 ScrollByYOffset(-event->y_offset()); 173 ScrollByYOffset(-event->y_offset());
167 Layout(); 174 Layout();
168 event->SetHandled(); 175 event->SetHandled();
169 } 176 }
170 177
171 int OverflowBubbleView::GetDialogButtons() const { 178 int OverflowBubbleView::GetDialogButtons() const {
172 return ui::DIALOG_BUTTON_NONE; 179 return ui::DIALOG_BUTTON_NONE;
173 } 180 }
174 181
182 void OverflowBubbleView::OnBeforeBubbleWidgetInit(
183 views::Widget::InitParams* params,
184 views::Widget* bubble_widget) const {
185 // Place the bubble in the same root window as the anchor.
186 WmLookup::Get()
187 ->GetWindowForWidget(anchor_widget())
188 ->GetRootWindowController()
189 ->ConfigureWidgetInitParamsForContainer(
190 bubble_widget, kShellWindowId_ShelfBubbleContainer, params);
191 }
192
175 gfx::Rect OverflowBubbleView::GetBubbleBounds() { 193 gfx::Rect OverflowBubbleView::GetBubbleBounds() {
176 views::BubbleBorder* border = GetBubbleFrameView()->bubble_border(); 194 views::BubbleBorder* border = GetBubbleFrameView()->bubble_border();
177 gfx::Insets bubble_insets = border->GetInsets(); 195 gfx::Insets bubble_insets = border->GetInsets();
178 196
179 const int border_size = views::BubbleBorder::is_arrow_on_horizontal(arrow()) 197 const int border_size = views::BubbleBorder::is_arrow_on_horizontal(arrow())
180 ? bubble_insets.left() 198 ? bubble_insets.left()
181 : bubble_insets.top(); 199 : bubble_insets.top();
182 const int arrow_offset = border_size + kPadding + kShelfViewLeadingInset + 200 const int arrow_offset = border_size + kPadding + kShelfViewLeadingInset +
183 GetShelfConstant(SHELF_SIZE) / 2; 201 GetShelfConstant(SHELF_SIZE) / 2;
184 202
(...skipping 26 matching lines...) Expand all
211 229
212 bubble_rect.Offset(0, offset); 230 bubble_rect.Offset(0, offset);
213 border->set_arrow_offset(anchor_rect.CenterPoint().y() - bubble_rect.y()); 231 border->set_arrow_offset(anchor_rect.CenterPoint().y() - bubble_rect.y());
214 } 232 }
215 233
216 GetBubbleFrameView()->SchedulePaint(); 234 GetBubbleFrameView()->SchedulePaint();
217 return bubble_rect; 235 return bubble_rect;
218 } 236 }
219 237
220 } // namespace ash 238 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/shelf/overflow_bubble_view.h ('k') | ash/common/shelf/overflow_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698