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 "components/constrained_window/constrained_window_views.h" | 5 #include "components/constrained_window/constrained_window_views.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "components/constrained_window/constrained_window_views_client.h" | 11 #include "components/constrained_window/constrained_window_views_client.h" |
12 #include "components/guest_view/browser/guest_view_base.h" | 12 #include "components/guest_view/browser/guest_view_base.h" |
13 #include "components/web_modal/web_contents_modal_dialog_host.h" | 13 #include "components/web_modal/web_contents_modal_dialog_host.h" |
14 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 14 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
15 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | 15 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" |
| 16 #include "ui/display/display.h" |
| 17 #include "ui/display/screen.h" |
16 #include "ui/views/border.h" | 18 #include "ui/views/border.h" |
17 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
18 #include "ui/views/widget/widget_observer.h" | 20 #include "ui/views/widget/widget_observer.h" |
19 #include "ui/views/window/dialog_delegate.h" | 21 #include "ui/views/window/dialog_delegate.h" |
20 | 22 |
21 #if defined(OS_MACOSX) | 23 #if defined(OS_MACOSX) |
22 #import "components/constrained_window/native_web_contents_modal_dialog_manager_
views_mac.h" | 24 #import "components/constrained_window/native_web_contents_modal_dialog_manager_
views_mac.h" |
23 #endif | 25 #endif |
24 | 26 |
25 using web_modal::ModalDialogHost; | 27 using web_modal::ModalDialogHost; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 103 |
102 gfx::Point position = dialog_host->GetDialogPosition(size); | 104 gfx::Point position = dialog_host->GetDialogPosition(size); |
103 views::Border* border = widget->non_client_view()->frame_view()->border(); | 105 views::Border* border = widget->non_client_view()->frame_view()->border(); |
104 // Border may be null during widget initialization. | 106 // Border may be null during widget initialization. |
105 if (border) { | 107 if (border) { |
106 // Align the first row of pixels inside the border. This is the apparent | 108 // Align the first row of pixels inside the border. This is the apparent |
107 // top of the dialog. | 109 // top of the dialog. |
108 position.set_y(position.y() - border->GetInsets().top()); | 110 position.set_y(position.y() - border->GetInsets().top()); |
109 } | 111 } |
110 | 112 |
111 if (widget->is_top_level()) | 113 if (widget->is_top_level()) { |
112 position += host_widget->GetClientAreaBoundsInScreen().OffsetFromOrigin(); | 114 position += host_widget->GetClientAreaBoundsInScreen().OffsetFromOrigin(); |
| 115 // If the dialog extends partially off any display, clamp its position to |
| 116 // be fully visible within that display. If the dialog doesn't intersect |
| 117 // with any display clamp its position to be fully on the nearest display. |
| 118 gfx::Rect display_rect = gfx::Rect(position, size); |
| 119 const display::Display display = |
| 120 display::Screen::GetScreen()->GetDisplayNearestWindow( |
| 121 dialog_host->GetHostView()); |
| 122 const gfx::Rect work_area = display.work_area(); |
| 123 if (!work_area.Contains(display_rect)) |
| 124 display_rect.AdjustToFit(work_area); |
| 125 position = display_rect.origin(); |
| 126 } |
113 | 127 |
114 widget->SetBounds(gfx::Rect(position, size)); | 128 widget->SetBounds(gfx::Rect(position, size)); |
115 } | 129 } |
116 | 130 |
117 } // namespace | 131 } // namespace |
118 | 132 |
119 // static | 133 // static |
120 void SetConstrainedWindowViewsClient( | 134 void SetConstrainedWindowViewsClient( |
121 std::unique_ptr<ConstrainedWindowViewsClient> new_client) { | 135 std::unique_ptr<ConstrainedWindowViewsClient> new_client) { |
122 delete constrained_window_views_client; | 136 delete constrained_window_views_client; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 DCHECK_EQ(parent_view, host->GetHostView()); | 240 DCHECK_EQ(parent_view, host->GetHostView()); |
227 ModalDialogHostObserver* dialog_host_observer = | 241 ModalDialogHostObserver* dialog_host_observer = |
228 new WidgetModalDialogHostObserverViews( | 242 new WidgetModalDialogHostObserverViews( |
229 host, widget, kWidgetModalDialogHostObserverViewsKey); | 243 host, widget, kWidgetModalDialogHostObserverViewsKey); |
230 dialog_host_observer->OnPositionRequiresUpdate(); | 244 dialog_host_observer->OnPositionRequiresUpdate(); |
231 } | 245 } |
232 return widget; | 246 return widget; |
233 } | 247 } |
234 | 248 |
235 } // namespace constrained window | 249 } // namespace constrained window |
OLD | NEW |