Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Unified Diff: components/constrained_window/constrained_window_views.cc

Issue 2549543002: Clamp dialog bounds to be fully visible on the nearest display (Closed)
Patch Set: Added unittest for clamping dialog Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..e493eaa708550c21c7901c251cf679adb48e05c5 100644
--- a/components/constrained_window/constrained_window_views.cc
+++ b/components/constrained_window/constrained_window_views.cc
@@ -13,6 +13,8 @@
#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/screen.h"
#include "ui/views/border.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_observer.h"
@@ -108,8 +110,20 @@ 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
+ // 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.
+ gfx::Rect display_rect = gfx::Rect(position, size);
+ const display::Display display =
+ display::Screen::GetScreen()->GetDisplayNearestWindow(
+ dialog_host->GetHostView());
+ const gfx::Rect work_area = display.work_area();
+ if (!work_area.Contains(display_rect))
+ display_rect.AdjustToFit(work_area);
+ position = display_rect.origin();
+ }
widget->SetBounds(gfx::Rect(position, size));
}

Powered by Google App Engine
This is Rietveld 408576698