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

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

Issue 2549543002: Clamp dialog bounds to be fully visible on the nearest display (Closed)
Patch Set: Make the dialog smaller than the display 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
« no previous file with comments | « components/constrained_window/constrained_window_views.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // Make sure the dialog will fit fully on the display
238 contents()->set_preferred_size(gfx::Size(200, 100));
239
240 // First, make sure the host and dialog are sized and positioned.
241 UpdateWebContentsModalDialogPosition(dialog(), dialog_host());
242
243 const display::Screen* screen = display::Screen::GetScreen();
244 const display::Display display = screen->GetPrimaryDisplay();
245 // Within the tests there is only 1 display. Error if that ever changes.
246 EXPECT_EQ(screen->GetNumDisplays(), 1);
247 const gfx::Rect extents = display.work_area();
248
249 // Move the host completely off the screen.
250 views::Widget* host_widget =
251 views::Widget::GetWidgetForNativeView(dialog_host()->GetHostView());
252 gfx::Rect host_bounds = host_widget->GetWindowBoundsInScreen();
253 host_bounds.set_origin(gfx::Point(extents.right(), extents.bottom()));
254 host_widget->SetBounds(host_bounds);
255
256 // Make sure the host is fully off the screen.
257 EXPECT_FALSE(extents.Intersects(host_widget->GetWindowBoundsInScreen()));
258
259 // Now reposition the modal dialog into the display.
260 UpdateWebContentsModalDialogPosition(dialog(), dialog_host());
261
262 const gfx::Rect dialog_bounds = dialog()->GetRootView()->GetBoundsInScreen();
263
264 // The dialog should now be fully on the display.
265 EXPECT_TRUE(extents.Contains(dialog_bounds));
266 }
267
231 } // namespace constrained_window 268 } // namespace constrained_window
OLDNEW
« no previous file with comments | « components/constrained_window/constrained_window_views.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698