OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <memory> | 7 #include <memory> |
8 #include <vector> | |
8 | 9 |
9 #include "base/macros.h" | 10 #include "base/macros.h" |
10 #include "components/constrained_window/constrained_window_views_client.h" | 11 #include "components/constrained_window/constrained_window_views_client.h" |
11 #include "components/web_modal/test_web_contents_modal_dialog_host.h" | 12 #include "components/web_modal/test_web_contents_modal_dialog_host.h" |
13 #include "ui/display/display.h" | |
14 #include "ui/display/screen.h" | |
12 #include "ui/gfx/geometry/point.h" | 15 #include "ui/gfx/geometry/point.h" |
13 #include "ui/gfx/geometry/rect.h" | 16 #include "ui/gfx/geometry/rect.h" |
14 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
15 #include "ui/gfx/native_widget_types.h" | 18 #include "ui/gfx/native_widget_types.h" |
16 #include "ui/views/border.h" | 19 #include "ui/views/border.h" |
17 #include "ui/views/test/views_test_base.h" | 20 #include "ui/views/test/views_test_base.h" |
18 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
19 #include "ui/views/window/dialog_delegate.h" | 22 #include "ui/views/window/dialog_delegate.h" |
20 | 23 |
21 using views::Widget; | 24 using views::Widget; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 SetConstrainedWindowViewsClient( | 224 SetConstrainedWindowViewsClient( |
222 base::MakeUnique<TestConstrainedWindowViewsClient>()); | 225 base::MakeUnique<TestConstrainedWindowViewsClient>()); |
223 DialogContents* contents = new DialogContents; | 226 DialogContents* contents = new DialogContents; |
224 contents->set_modal_type(ui::MODAL_TYPE_WINDOW); | 227 contents->set_modal_type(ui::MODAL_TYPE_WINDOW); |
225 views::Widget* widget = CreateBrowserModalDialogViews(contents, nullptr); | 228 views::Widget* widget = CreateBrowserModalDialogViews(contents, nullptr); |
226 widget->Show(); | 229 widget->Show(); |
227 EXPECT_TRUE(widget->IsVisible()); | 230 EXPECT_TRUE(widget->IsVisible()); |
228 widget->CloseNow(); | 231 widget->CloseNow(); |
229 } | 232 } |
230 | 233 |
234 // Make sure dialogs presented off-screen are properly clamped to the nearest | |
235 // screen. | |
236 TEST_F(ConstrainedWindowViewsTest, ClampDialogToNearestDisplay) { | |
237 // First, make sure the host and dialog are sized and positioned. | |
238 UpdateWebContentsModalDialogPosition(dialog(), dialog_host()); | |
239 | |
240 const display::Screen* screen = display::Screen::GetScreen(); | |
241 const display::Display display = screen->GetPrimaryDisplay(); | |
242 // Within the tests there is only 1 display. Error if that ever changes. | |
243 EXPECT_EQ(screen->GetNumDisplays(), 1); | |
244 const gfx::Rect extents = display.work_area(); | |
245 | |
246 // Move the host completely off the screen. | |
247 views::Widget* host_widget = | |
248 views::Widget::GetWidgetForNativeView(dialog_host()->GetHostView()); | |
249 gfx::Rect host_bounds = host_widget->GetWindowBoundsInScreen(); | |
250 host_bounds.set_origin(gfx::Point(extents.right(), extents.bottom())); | |
251 host_widget->SetBounds(host_bounds); | |
252 | |
253 // Make sure the host is fully off the screen. | |
254 EXPECT_FALSE(extents.Intersects(host_widget->GetWindowBoundsInScreen())); | |
255 | |
256 // Now reposition the modal dialog into the display. | |
257 UpdateWebContentsModalDialogPosition(dialog(), dialog_host()); | |
258 | |
259 const gfx::Rect dialog_bounds = dialog()->GetRootView()->GetBoundsInScreen(); | |
260 | |
261 // As long as the dialog intersects the display, it has been moved to be | |
262 // visible. Due to the constraints set, it may extend off the display. | |
msw
2016/12/15 21:44:56
Can you explain what constraints you're referring
kylix_rd
2016/12/15 21:57:56
The default dialog constraints (min/max size) setu
msw
2016/12/15 22:17:40
It's a little silly that the test's SetUp makes th
kylix_rd
2016/12/15 22:21:53
I agree. However, out of the abundance of caution,
| |
263 EXPECT_TRUE(extents.Intersects(dialog_bounds)); | |
264 } | |
265 | |
231 } // namespace constrained_window | 266 } // namespace constrained_window |
OLD | NEW |