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

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

Issue 2899253002: chromeos: Rename ash::WmShelf to Shelf (Closed)
Patch Set: cleanup Created 3 years, 7 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
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/shelf/overflow_bubble_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/public/cpp/shell_window_ids.h" 9 #include "ash/public/cpp/shell_window_ids.h"
10 #include "ash/root_window_controller.h" 10 #include "ash/root_window_controller.h"
11 #include "ash/shelf/shelf.h"
11 #include "ash/shelf/shelf_constants.h" 12 #include "ash/shelf/shelf_constants.h"
12 #include "ash/shelf/wm_shelf.h"
13 #include "ash/shell.h" 13 #include "ash/shell.h"
14 #include "ash/wm_window.h" 14 #include "ash/wm_window.h"
15 #include "base/i18n/rtl.h" 15 #include "base/i18n/rtl.h"
16 #include "ui/display/display.h" 16 #include "ui/display/display.h"
17 #include "ui/display/screen.h" 17 #include "ui/display/screen.h"
18 #include "ui/events/event.h" 18 #include "ui/events/event.h"
19 #include "ui/gfx/geometry/insets.h" 19 #include "ui/gfx/geometry/insets.h"
20 #include "ui/views/bubble/bubble_frame_view.h" 20 #include "ui/views/bubble/bubble_frame_view.h"
21 #include "ui/views/view.h" 21 #include "ui/views/view.h"
22 #include "ui/views/widget/widget.h" 22 #include "ui/views/widget/widget.h"
23 23
24 namespace ash { 24 namespace ash {
25 namespace { 25 namespace {
26 26
27 // Padding at the two ends of the bubble. 27 // Padding at the two ends of the bubble.
28 const int kEndPadding = 16; 28 const int kEndPadding = 16;
29 29
30 // Distance between overflow bubble and the main shelf. 30 // Distance between overflow bubble and the main shelf.
31 const int kDistanceToMainShelf = 4; 31 const int kDistanceToMainShelf = 4;
32 32
33 } // namespace 33 } // namespace
34 34
35 OverflowBubbleView::OverflowBubbleView(WmShelf* wm_shelf) 35 OverflowBubbleView::OverflowBubbleView(Shelf* shelf)
36 : wm_shelf_(wm_shelf), 36 : shelf_(shelf),
37 shelf_view_(nullptr), 37 shelf_view_(nullptr),
38 background_animator_(SHELF_BACKGROUND_OVERLAP, 38 background_animator_(SHELF_BACKGROUND_OVERLAP,
39 // Don't pass the WmShelf so the translucent color is 39 // Don't pass the Shelf so the translucent color is
40 // always used. 40 // always used.
41 nullptr, 41 nullptr,
42 Shell::Get()->wallpaper_controller()) { 42 Shell::Get()->wallpaper_controller()) {
43 DCHECK(wm_shelf_); 43 DCHECK(shelf_);
44 44
45 background_animator_.AddObserver(this); 45 background_animator_.AddObserver(this);
46 } 46 }
47 47
48 OverflowBubbleView::~OverflowBubbleView() { 48 OverflowBubbleView::~OverflowBubbleView() {
49 background_animator_.RemoveObserver(this); 49 background_animator_.RemoveObserver(this);
50 } 50 }
51 51
52 void OverflowBubbleView::InitOverflowBubble(views::View* anchor, 52 void OverflowBubbleView::InitOverflowBubble(views::View* anchor,
53 views::View* shelf_view) { 53 views::View* shelf_view) {
54 shelf_view_ = shelf_view; 54 shelf_view_ = shelf_view;
55 55
56 SetAnchorView(anchor); 56 SetAnchorView(anchor);
57 set_arrow(views::BubbleBorder::NONE); 57 set_arrow(views::BubbleBorder::NONE);
58 set_background(nullptr); 58 set_background(nullptr);
59 if (wm_shelf_->IsHorizontalAlignment()) 59 if (shelf_->IsHorizontalAlignment())
60 set_margins(gfx::Insets(0, kEndPadding)); 60 set_margins(gfx::Insets(0, kEndPadding));
61 else 61 else
62 set_margins(gfx::Insets(kEndPadding, 0)); 62 set_margins(gfx::Insets(kEndPadding, 0));
63 set_shadow(views::BubbleBorder::NO_ASSETS); 63 set_shadow(views::BubbleBorder::NO_ASSETS);
64 // Overflow bubble should not get focus. If it get focus when it is shown, 64 // Overflow bubble should not get focus. If it get focus when it is shown,
65 // active state item is changed to running state. 65 // active state item is changed to running state.
66 set_can_activate(false); 66 set_can_activate(false);
67 67
68 // Makes bubble view has a layer and clip its children layers. 68 // Makes bubble view has a layer and clip its children layers.
69 SetPaintToLayer(); 69 SetPaintToLayer();
(...skipping 26 matching lines...) Expand all
96 } 96 }
97 97
98 gfx::Size OverflowBubbleView::CalculatePreferredSize() const { 98 gfx::Size OverflowBubbleView::CalculatePreferredSize() const {
99 gfx::Size preferred_size = shelf_view_->GetPreferredSize(); 99 gfx::Size preferred_size = shelf_view_->GetPreferredSize();
100 100
101 const gfx::Rect monitor_rect = 101 const gfx::Rect monitor_rect =
102 display::Screen::GetScreen() 102 display::Screen::GetScreen()
103 ->GetDisplayNearestPoint(GetAnchorRect().CenterPoint()) 103 ->GetDisplayNearestPoint(GetAnchorRect().CenterPoint())
104 .work_area(); 104 .work_area();
105 if (!monitor_rect.IsEmpty()) { 105 if (!monitor_rect.IsEmpty()) {
106 if (wm_shelf_->IsHorizontalAlignment()) { 106 if (shelf_->IsHorizontalAlignment()) {
107 preferred_size.set_width(std::min( 107 preferred_size.set_width(std::min(
108 preferred_size.width(), monitor_rect.width() - 2 * kEndPadding)); 108 preferred_size.width(), monitor_rect.width() - 2 * kEndPadding));
109 } else { 109 } else {
110 preferred_size.set_height(std::min( 110 preferred_size.set_height(std::min(
111 preferred_size.height(), monitor_rect.height() - 2 * kEndPadding)); 111 preferred_size.height(), monitor_rect.height() - 2 * kEndPadding));
112 } 112 }
113 } 113 }
114 114
115 return preferred_size; 115 return preferred_size;
116 } 116 }
117 117
118 void OverflowBubbleView::Layout() { 118 void OverflowBubbleView::Layout() {
119 shelf_view_->SetBoundsRect( 119 shelf_view_->SetBoundsRect(
120 gfx::Rect(gfx::PointAtOffsetFromOrigin(-scroll_offset_), 120 gfx::Rect(gfx::PointAtOffsetFromOrigin(-scroll_offset_),
121 shelf_view_->GetPreferredSize())); 121 shelf_view_->GetPreferredSize()));
122 } 122 }
123 123
124 void OverflowBubbleView::ChildPreferredSizeChanged(views::View* child) { 124 void OverflowBubbleView::ChildPreferredSizeChanged(views::View* child) {
125 // When contents size is changed, ContentsBounds should be updated before 125 // When contents size is changed, ContentsBounds should be updated before
126 // calculating scroll offset. 126 // calculating scroll offset.
127 SizeToContents(); 127 SizeToContents();
128 128
129 // Ensures |shelf_view_| is still visible. 129 // Ensures |shelf_view_| is still visible.
130 if (wm_shelf_->IsHorizontalAlignment()) 130 if (shelf_->IsHorizontalAlignment())
131 ScrollByXOffset(0); 131 ScrollByXOffset(0);
132 else 132 else
133 ScrollByYOffset(0); 133 ScrollByYOffset(0);
134 Layout(); 134 Layout();
135 } 135 }
136 136
137 bool OverflowBubbleView::OnMouseWheel(const ui::MouseWheelEvent& event) { 137 bool OverflowBubbleView::OnMouseWheel(const ui::MouseWheelEvent& event) {
138 // The MouseWheelEvent was changed to support both X and Y offsets 138 // The MouseWheelEvent was changed to support both X and Y offsets
139 // recently, but the behavior of this function was retained to continue 139 // recently, but the behavior of this function was retained to continue
140 // using Y offsets only. Might be good to simply scroll in both 140 // using Y offsets only. Might be good to simply scroll in both
141 // directions as in OverflowBubbleView::OnScrollEvent. 141 // directions as in OverflowBubbleView::OnScrollEvent.
142 if (wm_shelf_->IsHorizontalAlignment()) 142 if (shelf_->IsHorizontalAlignment())
143 ScrollByXOffset(-event.y_offset()); 143 ScrollByXOffset(-event.y_offset());
144 else 144 else
145 ScrollByYOffset(-event.y_offset()); 145 ScrollByYOffset(-event.y_offset());
146 Layout(); 146 Layout();
147 147
148 return true; 148 return true;
149 } 149 }
150 150
151 void OverflowBubbleView::OnScrollEvent(ui::ScrollEvent* event) { 151 void OverflowBubbleView::OnScrollEvent(ui::ScrollEvent* event) {
152 ScrollByXOffset(-event->x_offset()); 152 ScrollByXOffset(-event->x_offset());
(...skipping 17 matching lines...) Expand all
170 } 170 }
171 171
172 gfx::Rect OverflowBubbleView::GetBubbleBounds() { 172 gfx::Rect OverflowBubbleView::GetBubbleBounds() {
173 const gfx::Size content_size = GetPreferredSize(); 173 const gfx::Size content_size = GetPreferredSize();
174 const gfx::Rect anchor_rect = GetAnchorRect(); 174 const gfx::Rect anchor_rect = GetAnchorRect();
175 gfx::Rect monitor_rect = 175 gfx::Rect monitor_rect =
176 display::Screen::GetScreen() 176 display::Screen::GetScreen()
177 ->GetDisplayNearestPoint(anchor_rect.CenterPoint()) 177 ->GetDisplayNearestPoint(anchor_rect.CenterPoint())
178 .work_area(); 178 .work_area();
179 179
180 if (wm_shelf_->IsHorizontalAlignment()) { 180 if (shelf_->IsHorizontalAlignment()) {
181 gfx::Rect bounds( 181 gfx::Rect bounds(
182 base::i18n::IsRTL() 182 base::i18n::IsRTL()
183 ? anchor_rect.x() - kEndPadding 183 ? anchor_rect.x() - kEndPadding
184 : anchor_rect.right() - content_size.width() - kEndPadding, 184 : anchor_rect.right() - content_size.width() - kEndPadding,
185 anchor_rect.y() - kDistanceToMainShelf - content_size.height(), 185 anchor_rect.y() - kDistanceToMainShelf - content_size.height(),
186 content_size.width() + 2 * kEndPadding, content_size.height()); 186 content_size.width() + 2 * kEndPadding, content_size.height());
187 if (bounds.x() < monitor_rect.x()) 187 if (bounds.x() < monitor_rect.x())
188 bounds.Offset(monitor_rect.x() - bounds.x(), 0); 188 bounds.Offset(monitor_rect.x() - bounds.x(), 0);
189 else if (bounds.right() > monitor_rect.right()) 189 else if (bounds.right() > monitor_rect.right())
190 bounds.Offset(monitor_rect.right() - bounds.right(), 0); 190 bounds.Offset(monitor_rect.right() - bounds.right(), 0);
191 return bounds; 191 return bounds;
192 } 192 }
193 gfx::Rect bounds( 193 gfx::Rect bounds(
194 0, anchor_rect.bottom() - content_size.height() - kEndPadding, 194 0, anchor_rect.bottom() - content_size.height() - kEndPadding,
195 content_size.width(), content_size.height() + 2 * kEndPadding); 195 content_size.width(), content_size.height() + 2 * kEndPadding);
196 if (wm_shelf_->alignment() == SHELF_ALIGNMENT_LEFT) 196 if (shelf_->alignment() == SHELF_ALIGNMENT_LEFT)
197 bounds.set_x(anchor_rect.right() + kDistanceToMainShelf); 197 bounds.set_x(anchor_rect.right() + kDistanceToMainShelf);
198 else 198 else
199 bounds.set_x(anchor_rect.x() - kDistanceToMainShelf - content_size.width()); 199 bounds.set_x(anchor_rect.x() - kDistanceToMainShelf - content_size.width());
200 if (bounds.y() < monitor_rect.y()) 200 if (bounds.y() < monitor_rect.y())
201 bounds.Offset(0, monitor_rect.y() - bounds.y()); 201 bounds.Offset(0, monitor_rect.y() - bounds.y());
202 else if (bounds.bottom() > monitor_rect.bottom()) 202 else if (bounds.bottom() > monitor_rect.bottom())
203 bounds.Offset(monitor_rect.bottom() - bounds.bottom(), 0); 203 bounds.Offset(monitor_rect.bottom() - bounds.bottom(), 0);
204 return bounds; 204 return bounds;
205 } 205 }
206 206
207 void OverflowBubbleView::UpdateShelfBackground(SkColor color) { 207 void OverflowBubbleView::UpdateShelfBackground(SkColor color) {
208 set_color(color); 208 set_color(color);
209 } 209 }
210 210
211 } // namespace ash 211 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698