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

Side by Side Diff: components/constrained_window/constrained_window_views.cc

Issue 2549543002: Clamp dialog bounds to be fully visible on the nearest display (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
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/screen.h"
16 #include "ui/views/border.h" 17 #include "ui/views/border.h"
17 #include "ui/views/widget/widget.h" 18 #include "ui/views/widget/widget.h"
18 #include "ui/views/widget/widget_observer.h" 19 #include "ui/views/widget/widget_observer.h"
19 #include "ui/views/window/dialog_delegate.h" 20 #include "ui/views/window/dialog_delegate.h"
20 21
21 #if defined(OS_MACOSX) 22 #if defined(OS_MACOSX)
22 #import "components/constrained_window/native_web_contents_modal_dialog_manager_ views_mac.h" 23 #import "components/constrained_window/native_web_contents_modal_dialog_manager_ views_mac.h"
23 #endif 24 #endif
24 25
25 using web_modal::ModalDialogHost; 26 using web_modal::ModalDialogHost;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 102
102 gfx::Point position = dialog_host->GetDialogPosition(size); 103 gfx::Point position = dialog_host->GetDialogPosition(size);
103 views::Border* border = widget->non_client_view()->frame_view()->border(); 104 views::Border* border = widget->non_client_view()->frame_view()->border();
104 // Border may be null during widget initialization. 105 // Border may be null during widget initialization.
105 if (border) { 106 if (border) {
106 // Align the first row of pixels inside the border. This is the apparent 107 // Align the first row of pixels inside the border. This is the apparent
107 // top of the dialog. 108 // top of the dialog.
108 position.set_y(position.y() - border->GetInsets().top()); 109 position.set_y(position.y() - border->GetInsets().top());
109 } 110 }
110 111
111 if (widget->is_top_level()) 112 if (widget->is_top_level()) {
112 position += host_widget->GetClientAreaBoundsInScreen().OffsetFromOrigin(); 113 position += host_widget->GetClientAreaBoundsInScreen().OffsetFromOrigin();
114 // If the dialog extends partially off any display, clamp its position to
115 // be fully visible within that display. If the dialog doesn't intersect
116 // with any display clamp its position to be fully on the nearest display.
117 position = display::Screen::MoveScreenRectToNearestDisplay(
118 gfx::Rect(position, size)).origin();
119 }
113 120
114 widget->SetBounds(gfx::Rect(position, size)); 121 widget->SetBounds(gfx::Rect(position, size));
115 } 122 }
116 123
117 } // namespace 124 } // namespace
118 125
119 // static 126 // static
120 void SetConstrainedWindowViewsClient( 127 void SetConstrainedWindowViewsClient(
121 std::unique_ptr<ConstrainedWindowViewsClient> new_client) { 128 std::unique_ptr<ConstrainedWindowViewsClient> new_client) {
122 delete constrained_window_views_client; 129 delete constrained_window_views_client;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 DCHECK_EQ(parent_view, host->GetHostView()); 233 DCHECK_EQ(parent_view, host->GetHostView());
227 ModalDialogHostObserver* dialog_host_observer = 234 ModalDialogHostObserver* dialog_host_observer =
228 new WidgetModalDialogHostObserverViews( 235 new WidgetModalDialogHostObserverViews(
229 host, widget, kWidgetModalDialogHostObserverViewsKey); 236 host, widget, kWidgetModalDialogHostObserverViewsKey);
230 dialog_host_observer->OnPositionRequiresUpdate(); 237 dialog_host_observer->OnPositionRequiresUpdate();
231 } 238 }
232 return widget; 239 return widget;
233 } 240 }
234 241
235 } // namespace constrained window 242 } // namespace constrained window
OLDNEW
« no previous file with comments | « components/constrained_window/DEPS ('k') | ui/display/screen.h » ('j') | ui/display/screen.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698