OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/bubble/bubble_frame_view.h" | 5 #include "ui/views/bubble/bubble_frame_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ui/gfx/screen.h" | 9 #include "ui/gfx/screen.h" |
10 #include "ui/views/bubble/bubble_border.h" | 10 #include "ui/views/bubble/bubble_border.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // Try to mirror the anchoring if the bubble does not fit on the screen. | 90 // Try to mirror the anchoring if the bubble does not fit on the screen. |
91 MirrorArrowIfOffScreen(true, anchor_rect, client_size); | 91 MirrorArrowIfOffScreen(true, anchor_rect, client_size); |
92 MirrorArrowIfOffScreen(false, anchor_rect, client_size); | 92 MirrorArrowIfOffScreen(false, anchor_rect, client_size); |
93 } | 93 } |
94 | 94 |
95 // Calculate the bounds with the arrow in its updated location. | 95 // Calculate the bounds with the arrow in its updated location. |
96 return bubble_border_->GetBounds(anchor_rect, client_size); | 96 return bubble_border_->GetBounds(anchor_rect, client_size); |
97 } | 97 } |
98 | 98 |
99 gfx::Rect BubbleFrameView::GetMonitorBounds(const gfx::Rect& rect) { | 99 gfx::Rect BubbleFrameView::GetMonitorBounds(const gfx::Rect& rect) { |
100 return gfx::Screen::GetMonitorWorkAreaNearestPoint(rect.CenterPoint()); | 100 return gfx::Screen::GetMonitorNearestPoint(rect.CenterPoint()).work_area(); |
101 } | 101 } |
102 | 102 |
103 void BubbleFrameView::MirrorArrowIfOffScreen( | 103 void BubbleFrameView::MirrorArrowIfOffScreen( |
104 bool vertical, | 104 bool vertical, |
105 const gfx::Rect& anchor_rect, | 105 const gfx::Rect& anchor_rect, |
106 const gfx::Size& client_size) { | 106 const gfx::Size& client_size) { |
107 // Check if the bounds don't fit on screen. | 107 // Check if the bounds don't fit on screen. |
108 gfx::Rect monitor_rect(GetMonitorBounds(anchor_rect)); | 108 gfx::Rect monitor_rect(GetMonitorBounds(anchor_rect)); |
109 gfx::Rect window_bounds(bubble_border_->GetBounds(anchor_rect, client_size)); | 109 gfx::Rect window_bounds(bubble_border_->GetBounds(anchor_rect, client_size)); |
110 if (GetOffScreenLength(monitor_rect, window_bounds, vertical) > 0) { | 110 if (GetOffScreenLength(monitor_rect, window_bounds, vertical) > 0) { |
111 BubbleBorder::ArrowLocation arrow = bubble_border()->arrow_location(); | 111 BubbleBorder::ArrowLocation arrow = bubble_border()->arrow_location(); |
112 // Mirror the arrow and get the new bounds. | 112 // Mirror the arrow and get the new bounds. |
113 bubble_border_->set_arrow_location( | 113 bubble_border_->set_arrow_location( |
114 vertical ? BubbleBorder::vertical_mirror(arrow) : | 114 vertical ? BubbleBorder::vertical_mirror(arrow) : |
115 BubbleBorder::horizontal_mirror(arrow)); | 115 BubbleBorder::horizontal_mirror(arrow)); |
116 gfx::Rect mirror_bounds = | 116 gfx::Rect mirror_bounds = |
117 bubble_border_->GetBounds(anchor_rect, client_size); | 117 bubble_border_->GetBounds(anchor_rect, client_size); |
118 // Restore the original arrow if mirroring doesn't show more of the bubble. | 118 // Restore the original arrow if mirroring doesn't show more of the bubble. |
119 if (GetOffScreenLength(monitor_rect, mirror_bounds, vertical) >= | 119 if (GetOffScreenLength(monitor_rect, mirror_bounds, vertical) >= |
120 GetOffScreenLength(monitor_rect, window_bounds, vertical)) | 120 GetOffScreenLength(monitor_rect, window_bounds, vertical)) |
121 bubble_border_->set_arrow_location(arrow); | 121 bubble_border_->set_arrow_location(arrow); |
122 else | 122 else |
123 SchedulePaint(); | 123 SchedulePaint(); |
124 } | 124 } |
125 } | 125 } |
126 | 126 |
127 } // namespace views | 127 } // namespace views |
OLD | NEW |