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

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

Issue 2676673005: ash: Clean up shelf GetAlignment() and IsHorizontalAlignment() calls (Closed)
Patch Set: Created 3 years, 10 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/shelf_button.cc » ('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/common/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" 11 #include "ash/common/shelf/wm_shelf.h"
12 #include "ash/common/shelf/wm_shelf_util.h"
13 #include "ash/common/wm_lookup.h" 12 #include "ash/common/wm_lookup.h"
14 #include "ash/common/wm_window.h" 13 #include "ash/common/wm_window.h"
15 #include "ash/public/cpp/shell_window_ids.h" 14 #include "ash/public/cpp/shell_window_ids.h"
16 #include "ash/root_window_controller.h" 15 #include "ash/root_window_controller.h"
17 #include "ui/display/display.h" 16 #include "ui/display/display.h"
18 #include "ui/display/screen.h" 17 #include "ui/display/screen.h"
19 #include "ui/events/event.h" 18 #include "ui/events/event.h"
20 #include "ui/gfx/geometry/insets.h" 19 #include "ui/gfx/geometry/insets.h"
21 #include "ui/views/bubble/bubble_frame_view.h" 20 #include "ui/views/bubble/bubble_frame_view.h"
22 #include "ui/views/view.h" 21 #include "ui/views/view.h"
23 #include "ui/views/widget/widget.h" 22 #include "ui/views/widget/widget.h"
24 23
25 namespace ash { 24 namespace ash {
26 namespace { 25 namespace {
27 26
28 // Max bubble size to screen size ratio. 27 // Max bubble size to screen size ratio.
29 const float kMaxBubbleSizeToScreenRatio = 0.5f; 28 const float kMaxBubbleSizeToScreenRatio = 0.5f;
30 29
31 // Inner padding in pixels for shelf view inside bubble. 30 // Inner padding in pixels for shelf view inside bubble.
32 const int kPadding = 2; 31 const int kPadding = 2;
33 32
34 // Padding space in pixels between ShelfView's left/top edge to its contents. 33 // Padding space in pixels between ShelfView's left/top edge to its contents.
35 const int kShelfViewLeadingInset = 8; 34 const int kShelfViewLeadingInset = 8;
36 35
37 } // namespace 36 } // namespace
38 37
39 OverflowBubbleView::OverflowBubbleView(WmShelf* wm_shelf) 38 OverflowBubbleView::OverflowBubbleView(WmShelf* wm_shelf)
40 : wm_shelf_(wm_shelf), shelf_view_(nullptr) {} 39 : wm_shelf_(wm_shelf), shelf_view_(nullptr) {
40 DCHECK(wm_shelf_);
41 }
41 42
42 OverflowBubbleView::~OverflowBubbleView() {} 43 OverflowBubbleView::~OverflowBubbleView() {}
43 44
44 void OverflowBubbleView::InitOverflowBubble(views::View* anchor, 45 void OverflowBubbleView::InitOverflowBubble(views::View* anchor,
45 views::View* shelf_view) { 46 views::View* shelf_view) {
46 shelf_view_ = shelf_view; 47 shelf_view_ = shelf_view;
47 48
48 SetAnchorView(anchor); 49 SetAnchorView(anchor);
49 set_arrow(GetBubbleArrow()); 50 set_arrow(GetBubbleArrow());
50 set_mirror_arrow_in_rtl(false); 51 set_mirror_arrow_in_rtl(false);
(...skipping 11 matching lines...) Expand all
62 // Makes bubble view has a layer and clip its children layers. 63 // Makes bubble view has a layer and clip its children layers.
63 SetPaintToLayer(); 64 SetPaintToLayer();
64 layer()->SetFillsBoundsOpaquely(false); 65 layer()->SetFillsBoundsOpaquely(false);
65 layer()->SetMasksToBounds(true); 66 layer()->SetMasksToBounds(true);
66 67
67 // Calls into OnBeforeBubbleWidgetInit to set the window parent container. 68 // Calls into OnBeforeBubbleWidgetInit to set the window parent container.
68 views::BubbleDialogDelegateView::CreateBubble(this); 69 views::BubbleDialogDelegateView::CreateBubble(this);
69 AddChildView(shelf_view_); 70 AddChildView(shelf_view_);
70 } 71 }
71 72
72 bool OverflowBubbleView::IsHorizontalAlignment() const {
73 return ::ash::IsHorizontalAlignment(wm_shelf_->GetAlignment());
74 }
75
76 const gfx::Size OverflowBubbleView::GetContentsSize() const { 73 const gfx::Size OverflowBubbleView::GetContentsSize() const {
77 return shelf_view_->GetPreferredSize(); 74 return shelf_view_->GetPreferredSize();
78 } 75 }
79 76
80 // Gets arrow location based on shelf alignment. 77 // Gets arrow location based on shelf alignment.
81 views::BubbleBorder::Arrow OverflowBubbleView::GetBubbleArrow() const { 78 views::BubbleBorder::Arrow OverflowBubbleView::GetBubbleArrow() const {
82 switch (wm_shelf_->GetAlignment()) { 79 switch (wm_shelf_->GetAlignment()) {
83 case SHELF_ALIGNMENT_BOTTOM: 80 case SHELF_ALIGNMENT_BOTTOM:
84 case SHELF_ALIGNMENT_BOTTOM_LOCKED: 81 case SHELF_ALIGNMENT_BOTTOM_LOCKED:
85 return views::BubbleBorder::BOTTOM_LEFT; 82 return views::BubbleBorder::BOTTOM_LEFT;
(...skipping 27 matching lines...) Expand all
113 } 110 }
114 111
115 gfx::Size OverflowBubbleView::GetPreferredSize() const { 112 gfx::Size OverflowBubbleView::GetPreferredSize() const {
116 gfx::Size preferred_size = GetContentsSize(); 113 gfx::Size preferred_size = GetContentsSize();
117 114
118 const gfx::Rect monitor_rect = 115 const gfx::Rect monitor_rect =
119 display::Screen::GetScreen() 116 display::Screen::GetScreen()
120 ->GetDisplayNearestPoint(GetAnchorRect().CenterPoint()) 117 ->GetDisplayNearestPoint(GetAnchorRect().CenterPoint())
121 .work_area(); 118 .work_area();
122 if (!monitor_rect.IsEmpty()) { 119 if (!monitor_rect.IsEmpty()) {
123 if (IsHorizontalAlignment()) { 120 if (wm_shelf_->IsHorizontalAlignment()) {
124 preferred_size.set_width( 121 preferred_size.set_width(
125 std::min(preferred_size.width(), 122 std::min(preferred_size.width(),
126 static_cast<int>(monitor_rect.width() * 123 static_cast<int>(monitor_rect.width() *
127 kMaxBubbleSizeToScreenRatio))); 124 kMaxBubbleSizeToScreenRatio)));
128 } else { 125 } else {
129 preferred_size.set_height( 126 preferred_size.set_height(
130 std::min(preferred_size.height(), 127 std::min(preferred_size.height(),
131 static_cast<int>(monitor_rect.height() * 128 static_cast<int>(monitor_rect.height() *
132 kMaxBubbleSizeToScreenRatio))); 129 kMaxBubbleSizeToScreenRatio)));
133 } 130 }
134 } 131 }
135 132
136 return preferred_size; 133 return preferred_size;
137 } 134 }
138 135
139 void OverflowBubbleView::Layout() { 136 void OverflowBubbleView::Layout() {
140 shelf_view_->SetBoundsRect(gfx::Rect( 137 shelf_view_->SetBoundsRect(gfx::Rect(
141 gfx::PointAtOffsetFromOrigin(-scroll_offset_), GetContentsSize())); 138 gfx::PointAtOffsetFromOrigin(-scroll_offset_), GetContentsSize()));
142 } 139 }
143 140
144 void OverflowBubbleView::ChildPreferredSizeChanged(views::View* child) { 141 void OverflowBubbleView::ChildPreferredSizeChanged(views::View* child) {
145 // When contents size is changed, ContentsBounds should be updated before 142 // When contents size is changed, ContentsBounds should be updated before
146 // calculating scroll offset. 143 // calculating scroll offset.
147 SizeToContents(); 144 SizeToContents();
148 145
149 // Ensures |shelf_view_| is still visible. 146 // Ensures |shelf_view_| is still visible.
150 if (IsHorizontalAlignment()) 147 if (wm_shelf_->IsHorizontalAlignment())
151 ScrollByXOffset(0); 148 ScrollByXOffset(0);
152 else 149 else
153 ScrollByYOffset(0); 150 ScrollByYOffset(0);
154 Layout(); 151 Layout();
155 } 152 }
156 153
157 bool OverflowBubbleView::OnMouseWheel(const ui::MouseWheelEvent& event) { 154 bool OverflowBubbleView::OnMouseWheel(const ui::MouseWheelEvent& event) {
158 // The MouseWheelEvent was changed to support both X and Y offsets 155 // The MouseWheelEvent was changed to support both X and Y offsets
159 // recently, but the behavior of this function was retained to continue 156 // recently, but the behavior of this function was retained to continue
160 // using Y offsets only. Might be good to simply scroll in both 157 // using Y offsets only. Might be good to simply scroll in both
161 // directions as in OverflowBubbleView::OnScrollEvent. 158 // directions as in OverflowBubbleView::OnScrollEvent.
162 if (IsHorizontalAlignment()) 159 if (wm_shelf_->IsHorizontalAlignment())
163 ScrollByXOffset(-event.y_offset()); 160 ScrollByXOffset(-event.y_offset());
164 else 161 else
165 ScrollByYOffset(-event.y_offset()); 162 ScrollByYOffset(-event.y_offset());
166 Layout(); 163 Layout();
167 164
168 return true; 165 return true;
169 } 166 }
170 167
171 void OverflowBubbleView::OnScrollEvent(ui::ScrollEvent* event) { 168 void OverflowBubbleView::OnScrollEvent(ui::ScrollEvent* event) {
172 ScrollByXOffset(-event->x_offset()); 169 ScrollByXOffset(-event->x_offset());
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 226
230 bubble_rect.Offset(0, offset); 227 bubble_rect.Offset(0, offset);
231 border->set_arrow_offset(anchor_rect.CenterPoint().y() - bubble_rect.y()); 228 border->set_arrow_offset(anchor_rect.CenterPoint().y() - bubble_rect.y());
232 } 229 }
233 230
234 GetBubbleFrameView()->SchedulePaint(); 231 GetBubbleFrameView()->SchedulePaint();
235 return bubble_rect; 232 return bubble_rect;
236 } 233 }
237 234
238 } // namespace ash 235 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/shelf/overflow_bubble_view.h ('k') | ash/common/shelf/shelf_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698