| 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/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
| 10 #include "ash/shelf/shelf.h" | 10 #include "ash/shelf/shelf.h" |
| 11 #include "ash/shelf/shelf_constants.h" | 11 #include "ash/shelf/shelf_constants.h" |
| 12 #include "ash/shelf/shelf_view.h" | 12 #include "ash/shelf/shelf_view.h" |
| 13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 14 #include "ash/shell_window_ids.h" | 14 #include "ash/shell_window_ids.h" |
| 15 #include "ash/wm/common/shelf/wm_shelf_constants.h" | 15 #include "ash/wm/common/shelf/wm_shelf_constants.h" |
| 16 #include "ui/display/screen.h" |
| 16 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
| 17 #include "ui/gfx/geometry/insets.h" | 18 #include "ui/gfx/geometry/insets.h" |
| 18 #include "ui/gfx/screen.h" | |
| 19 #include "ui/views/bubble/bubble_frame_view.h" | 19 #include "ui/views/bubble/bubble_frame_view.h" |
| 20 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 21 | 21 |
| 22 namespace ash { | 22 namespace ash { |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // Max bubble size to screen size ratio. | 25 // Max bubble size to screen size ratio. |
| 26 const float kMaxBubbleSizeToScreenRatio = 0.5f; | 26 const float kMaxBubbleSizeToScreenRatio = 0.5f; |
| 27 | 27 |
| 28 // Inner padding in pixels for shelf view inside bubble. | 28 // Inner padding in pixels for shelf view inside bubble. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 DCHECK_GE(contents_size.width(), visible_bounds.width()); | 96 DCHECK_GE(contents_size.width(), visible_bounds.width()); |
| 97 int y = std::min(contents_size.height() - visible_bounds.height(), | 97 int y = std::min(contents_size.height() - visible_bounds.height(), |
| 98 std::max(0, scroll_offset_.y() + y_offset)); | 98 std::max(0, scroll_offset_.y() + y_offset)); |
| 99 scroll_offset_.set_y(y); | 99 scroll_offset_.set_y(y); |
| 100 } | 100 } |
| 101 | 101 |
| 102 gfx::Size OverflowBubbleView::GetPreferredSize() const { | 102 gfx::Size OverflowBubbleView::GetPreferredSize() const { |
| 103 gfx::Size preferred_size = GetContentsSize(); | 103 gfx::Size preferred_size = GetContentsSize(); |
| 104 | 104 |
| 105 const gfx::Rect monitor_rect = | 105 const gfx::Rect monitor_rect = |
| 106 gfx::Screen::GetScreen() | 106 display::Screen::GetScreen() |
| 107 ->GetDisplayNearestPoint(GetAnchorRect().CenterPoint()) | 107 ->GetDisplayNearestPoint(GetAnchorRect().CenterPoint()) |
| 108 .work_area(); | 108 .work_area(); |
| 109 if (!monitor_rect.IsEmpty()) { | 109 if (!monitor_rect.IsEmpty()) { |
| 110 if (IsHorizontalAlignment()) { | 110 if (IsHorizontalAlignment()) { |
| 111 preferred_size.set_width(std::min( | 111 preferred_size.set_width(std::min( |
| 112 preferred_size.width(), | 112 preferred_size.width(), |
| 113 static_cast<int>(monitor_rect.width() * | 113 static_cast<int>(monitor_rect.width() * |
| 114 kMaxBubbleSizeToScreenRatio))); | 114 kMaxBubbleSizeToScreenRatio))); |
| 115 } else { | 115 } else { |
| 116 preferred_size.set_height(std::min( | 116 preferred_size.set_height(std::min( |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 const gfx::Size content_size = GetPreferredSize(); | 179 const gfx::Size content_size = GetPreferredSize(); |
| 180 border->set_arrow_offset(arrow_offset); | 180 border->set_arrow_offset(arrow_offset); |
| 181 | 181 |
| 182 const gfx::Rect anchor_rect = GetAnchorRect(); | 182 const gfx::Rect anchor_rect = GetAnchorRect(); |
| 183 gfx::Rect bubble_rect = GetBubbleFrameView()->GetUpdatedWindowBounds( | 183 gfx::Rect bubble_rect = GetBubbleFrameView()->GetUpdatedWindowBounds( |
| 184 anchor_rect, | 184 anchor_rect, |
| 185 content_size, | 185 content_size, |
| 186 false); | 186 false); |
| 187 | 187 |
| 188 gfx::Rect monitor_rect = | 188 gfx::Rect monitor_rect = |
| 189 gfx::Screen::GetScreen() | 189 display::Screen::GetScreen() |
| 190 ->GetDisplayNearestPoint(anchor_rect.CenterPoint()) | 190 ->GetDisplayNearestPoint(anchor_rect.CenterPoint()) |
| 191 .work_area(); | 191 .work_area(); |
| 192 | 192 |
| 193 int offset = 0; | 193 int offset = 0; |
| 194 if (views::BubbleBorder::is_arrow_on_horizontal(arrow())) { | 194 if (views::BubbleBorder::is_arrow_on_horizontal(arrow())) { |
| 195 if (bubble_rect.x() < monitor_rect.x()) | 195 if (bubble_rect.x() < monitor_rect.x()) |
| 196 offset = monitor_rect.x() - bubble_rect.x(); | 196 offset = monitor_rect.x() - bubble_rect.x(); |
| 197 else if (bubble_rect.right() > monitor_rect.right()) | 197 else if (bubble_rect.right() > monitor_rect.right()) |
| 198 offset = monitor_rect.right() - bubble_rect.right(); | 198 offset = monitor_rect.right() - bubble_rect.right(); |
| 199 | 199 |
| 200 bubble_rect.Offset(offset, 0); | 200 bubble_rect.Offset(offset, 0); |
| 201 border->set_arrow_offset(anchor_rect.CenterPoint().x() - bubble_rect.x()); | 201 border->set_arrow_offset(anchor_rect.CenterPoint().x() - bubble_rect.x()); |
| 202 } else { | 202 } else { |
| 203 if (bubble_rect.y() < monitor_rect.y()) | 203 if (bubble_rect.y() < monitor_rect.y()) |
| 204 offset = monitor_rect.y() - bubble_rect.y(); | 204 offset = monitor_rect.y() - bubble_rect.y(); |
| 205 else if (bubble_rect.bottom() > monitor_rect.bottom()) | 205 else if (bubble_rect.bottom() > monitor_rect.bottom()) |
| 206 offset = monitor_rect.bottom() - bubble_rect.bottom(); | 206 offset = monitor_rect.bottom() - bubble_rect.bottom(); |
| 207 | 207 |
| 208 bubble_rect.Offset(0, offset); | 208 bubble_rect.Offset(0, offset); |
| 209 border->set_arrow_offset(anchor_rect.CenterPoint().y() - bubble_rect.y()); | 209 border->set_arrow_offset(anchor_rect.CenterPoint().y() - bubble_rect.y()); |
| 210 } | 210 } |
| 211 | 211 |
| 212 GetBubbleFrameView()->SchedulePaint(); | 212 GetBubbleFrameView()->SchedulePaint(); |
| 213 return bubble_rect; | 213 return bubble_rect; |
| 214 } | 214 } |
| 215 | 215 |
| 216 } // namespace ash | 216 } // namespace ash |
| OLD | NEW |