OLD | NEW |
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/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" |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 void OverflowBubbleView::InitOverflowBubble(views::View* anchor, | 41 void OverflowBubbleView::InitOverflowBubble(views::View* anchor, |
42 ShelfView* shelf_view) { | 42 ShelfView* shelf_view) { |
43 shelf_view_ = shelf_view; | 43 shelf_view_ = shelf_view; |
44 | 44 |
45 SetAnchorView(anchor); | 45 SetAnchorView(anchor); |
46 set_arrow(GetBubbleArrow()); | 46 set_arrow(GetBubbleArrow()); |
47 set_mirror_arrow_in_rtl(false); | 47 set_mirror_arrow_in_rtl(false); |
48 set_background(NULL); | 48 set_background(NULL); |
49 SkColor color = MaterialDesignController::IsShelfMaterial() | 49 SkColor color = MaterialDesignController::IsShelfMaterial() |
50 ? kShelfBaseColor | 50 ? kShelfBaseColor |
51 : SkColorSetA(kShelfBaseColor, GetShelfConstant(SHELF_BACKGROUND_ALPHA)); | 51 : SkColorSetA(kShelfBaseColor, |
| 52 GetShelfConstant(SHELF_BACKGROUND_ALPHA)); |
52 set_color(color); | 53 set_color(color); |
53 set_margins(gfx::Insets(kPadding, kPadding, kPadding, kPadding)); | 54 set_margins(gfx::Insets(kPadding, kPadding, kPadding, kPadding)); |
54 // Overflow bubble should not get focus. If it get focus when it is shown, | 55 // Overflow bubble should not get focus. If it get focus when it is shown, |
55 // active state item is changed to running state. | 56 // active state item is changed to running state. |
56 set_can_activate(false); | 57 set_can_activate(false); |
57 | 58 |
58 // Makes bubble view has a layer and clip its children layers. | 59 // Makes bubble view has a layer and clip its children layers. |
59 SetPaintToLayer(true); | 60 SetPaintToLayer(true); |
60 layer()->SetFillsBoundsOpaquely(false); | 61 layer()->SetFillsBoundsOpaquely(false); |
61 layer()->SetMasksToBounds(true); | 62 layer()->SetMasksToBounds(true); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 107 |
107 gfx::Size OverflowBubbleView::GetPreferredSize() const { | 108 gfx::Size OverflowBubbleView::GetPreferredSize() const { |
108 gfx::Size preferred_size = GetContentsSize(); | 109 gfx::Size preferred_size = GetContentsSize(); |
109 | 110 |
110 const gfx::Rect monitor_rect = | 111 const gfx::Rect monitor_rect = |
111 display::Screen::GetScreen() | 112 display::Screen::GetScreen() |
112 ->GetDisplayNearestPoint(GetAnchorRect().CenterPoint()) | 113 ->GetDisplayNearestPoint(GetAnchorRect().CenterPoint()) |
113 .work_area(); | 114 .work_area(); |
114 if (!monitor_rect.IsEmpty()) { | 115 if (!monitor_rect.IsEmpty()) { |
115 if (IsHorizontalAlignment()) { | 116 if (IsHorizontalAlignment()) { |
116 preferred_size.set_width(std::min( | 117 preferred_size.set_width( |
117 preferred_size.width(), | 118 std::min(preferred_size.width(), |
118 static_cast<int>(monitor_rect.width() * | 119 static_cast<int>(monitor_rect.width() * |
119 kMaxBubbleSizeToScreenRatio))); | 120 kMaxBubbleSizeToScreenRatio))); |
120 } else { | 121 } else { |
121 preferred_size.set_height(std::min( | 122 preferred_size.set_height( |
122 preferred_size.height(), | 123 std::min(preferred_size.height(), |
123 static_cast<int>(monitor_rect.height() * | 124 static_cast<int>(monitor_rect.height() * |
124 kMaxBubbleSizeToScreenRatio))); | 125 kMaxBubbleSizeToScreenRatio))); |
125 } | 126 } |
126 } | 127 } |
127 | 128 |
128 return preferred_size; | 129 return preferred_size; |
129 } | 130 } |
130 | 131 |
131 void OverflowBubbleView::Layout() { | 132 void OverflowBubbleView::Layout() { |
132 shelf_view_->SetBoundsRect(gfx::Rect( | 133 shelf_view_->SetBoundsRect(gfx::Rect( |
133 gfx::PointAtOffsetFromOrigin(-scroll_offset_), GetContentsSize())); | 134 gfx::PointAtOffsetFromOrigin(-scroll_offset_), GetContentsSize())); |
134 } | 135 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } | 169 } |
169 | 170 |
170 int OverflowBubbleView::GetDialogButtons() const { | 171 int OverflowBubbleView::GetDialogButtons() const { |
171 return ui::DIALOG_BUTTON_NONE; | 172 return ui::DIALOG_BUTTON_NONE; |
172 } | 173 } |
173 | 174 |
174 gfx::Rect OverflowBubbleView::GetBubbleBounds() { | 175 gfx::Rect OverflowBubbleView::GetBubbleBounds() { |
175 views::BubbleBorder* border = GetBubbleFrameView()->bubble_border(); | 176 views::BubbleBorder* border = GetBubbleFrameView()->bubble_border(); |
176 gfx::Insets bubble_insets = border->GetInsets(); | 177 gfx::Insets bubble_insets = border->GetInsets(); |
177 | 178 |
178 const int border_size = | 179 const int border_size = views::BubbleBorder::is_arrow_on_horizontal(arrow()) |
179 views::BubbleBorder::is_arrow_on_horizontal(arrow()) ? | 180 ? bubble_insets.left() |
180 bubble_insets.left() : bubble_insets.top(); | 181 : bubble_insets.top(); |
181 const int arrow_offset = border_size + kPadding + kShelfViewLeadingInset + | 182 const int arrow_offset = border_size + kPadding + kShelfViewLeadingInset + |
182 GetShelfConstant(SHELF_SIZE) / 2; | 183 GetShelfConstant(SHELF_SIZE) / 2; |
183 | 184 |
184 const gfx::Size content_size = GetPreferredSize(); | 185 const gfx::Size content_size = GetPreferredSize(); |
185 border->set_arrow_offset(arrow_offset); | 186 border->set_arrow_offset(arrow_offset); |
186 | 187 |
187 const gfx::Rect anchor_rect = GetAnchorRect(); | 188 const gfx::Rect anchor_rect = GetAnchorRect(); |
188 gfx::Rect bubble_rect = GetBubbleFrameView()->GetUpdatedWindowBounds( | 189 gfx::Rect bubble_rect = GetBubbleFrameView()->GetUpdatedWindowBounds( |
189 anchor_rect, | 190 anchor_rect, content_size, false); |
190 content_size, | |
191 false); | |
192 | 191 |
193 gfx::Rect monitor_rect = | 192 gfx::Rect monitor_rect = |
194 display::Screen::GetScreen() | 193 display::Screen::GetScreen() |
195 ->GetDisplayNearestPoint(anchor_rect.CenterPoint()) | 194 ->GetDisplayNearestPoint(anchor_rect.CenterPoint()) |
196 .work_area(); | 195 .work_area(); |
197 | 196 |
198 int offset = 0; | 197 int offset = 0; |
199 if (views::BubbleBorder::is_arrow_on_horizontal(arrow())) { | 198 if (views::BubbleBorder::is_arrow_on_horizontal(arrow())) { |
200 if (bubble_rect.x() < monitor_rect.x()) | 199 if (bubble_rect.x() < monitor_rect.x()) |
201 offset = monitor_rect.x() - bubble_rect.x(); | 200 offset = monitor_rect.x() - bubble_rect.x(); |
202 else if (bubble_rect.right() > monitor_rect.right()) | 201 else if (bubble_rect.right() > monitor_rect.right()) |
203 offset = monitor_rect.right() - bubble_rect.right(); | 202 offset = monitor_rect.right() - bubble_rect.right(); |
204 | 203 |
205 bubble_rect.Offset(offset, 0); | 204 bubble_rect.Offset(offset, 0); |
206 border->set_arrow_offset(anchor_rect.CenterPoint().x() - bubble_rect.x()); | 205 border->set_arrow_offset(anchor_rect.CenterPoint().x() - bubble_rect.x()); |
207 } else { | 206 } else { |
208 if (bubble_rect.y() < monitor_rect.y()) | 207 if (bubble_rect.y() < monitor_rect.y()) |
209 offset = monitor_rect.y() - bubble_rect.y(); | 208 offset = monitor_rect.y() - bubble_rect.y(); |
210 else if (bubble_rect.bottom() > monitor_rect.bottom()) | 209 else if (bubble_rect.bottom() > monitor_rect.bottom()) |
211 offset = monitor_rect.bottom() - bubble_rect.bottom(); | 210 offset = monitor_rect.bottom() - bubble_rect.bottom(); |
212 | 211 |
213 bubble_rect.Offset(0, offset); | 212 bubble_rect.Offset(0, offset); |
214 border->set_arrow_offset(anchor_rect.CenterPoint().y() - bubble_rect.y()); | 213 border->set_arrow_offset(anchor_rect.CenterPoint().y() - bubble_rect.y()); |
215 } | 214 } |
216 | 215 |
217 GetBubbleFrameView()->SchedulePaint(); | 216 GetBubbleFrameView()->SchedulePaint(); |
218 return bubble_rect; | 217 return bubble_rect; |
219 } | 218 } |
220 | 219 |
221 } // namespace ash | 220 } // namespace ash |
OLD | NEW |