Chromium Code Reviews| Index: components/constrained_window/constrained_window_views.cc |
| diff --git a/components/constrained_window/constrained_window_views.cc b/components/constrained_window/constrained_window_views.cc |
| index 3ed86ce06852a9da707d5868000e19a7103a8b7d..762f6ae83819fed0229649914f28192593a99bac 100644 |
| --- a/components/constrained_window/constrained_window_views.cc |
| +++ b/components/constrained_window/constrained_window_views.cc |
| @@ -13,6 +13,9 @@ |
| #include "components/web_modal/web_contents_modal_dialog_host.h" |
| #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" |
| +#include "ui/display/display.h" |
| +#include "ui/display/display_finder.h" |
| +#include "ui/display/screen.h" |
| #include "ui/views/border.h" |
| #include "ui/views/widget/widget.h" |
| #include "ui/views/widget/widget_observer.h" |
| @@ -80,6 +83,18 @@ class WidgetModalDialogHostObserverViews |
| DISALLOW_COPY_AND_ASSIGN(WidgetModalDialogHostObserverViews); |
| }; |
| +gfx::Point MoveRectToNearestHostDisplay(const gfx::Rect& screen_rect, |
|
msw
2016/12/14 22:37:08
Inline this function or rename it, since it doesn'
|
| + const gfx::Rect& host_rect) { |
| + gfx::Rect display_rect = screen_rect; |
| + const display::Display* display = display::FindDisplayNearestPoint( |
|
msw
2016/12/14 22:37:08
Use Screen::GetDisplayNearestWindow(dialog_host->G
|
| + display::Screen::GetScreen()->GetAllDisplays(), host_rect.CenterPoint()); |
| + DCHECK(display); |
|
msw
2016/12/14 22:37:08
optional nit: DCHECK immediately before deference
|
| + const gfx::Rect work_area = display->work_area(); |
| + if (!work_area.Contains(display_rect)) |
| + display_rect.AdjustToFit(work_area); |
| + return display_rect.origin(); |
| +} |
| + |
| void UpdateModalDialogPosition(views::Widget* widget, |
| web_modal::ModalDialogHost* dialog_host, |
| const gfx::Size& size) { |
| @@ -108,8 +123,14 @@ void UpdateModalDialogPosition(views::Widget* widget, |
| position.set_y(position.y() - border->GetInsets().top()); |
| } |
| - if (widget->is_top_level()) |
| + if (widget->is_top_level()) { |
| position += host_widget->GetClientAreaBoundsInScreen().OffsetFromOrigin(); |
| + // If the dialog extends partially off any display, clamp its position to |
|
msw
2016/12/14 22:37:08
This should be a function comment on the helper (u
|
| + // be fully visible within that display. If the dialog doesn't intersect |
| + // with any display clamp its position to be fully on the nearest display. |
| + position = MoveRectToNearestHostDisplay( |
| + gfx::Rect(position, size), host_widget->GetWindowBoundsInScreen()); |
| + } |
| widget->SetBounds(gfx::Rect(position, size)); |
| } |