| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ui/views/widget/desktop_aura/desktop_screen_x11.h" | 5 #include "ui/views/widget/desktop_aura/desktop_screen_x11.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "ui/aura/client/aura_constants.cc" | |
| 12 #include "ui/aura/test/event_generator.h" | |
| 13 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 14 #include "ui/aura/window_event_dispatcher.h" | 12 #include "ui/aura/window_event_dispatcher.h" |
| 15 #include "ui/aura/window_tree_host.h" | 13 #include "ui/aura/window_tree_host.h" |
| 16 #include "ui/base/hit_test.h" | |
| 17 #include "ui/base/x/x11_util.h" | 14 #include "ui/base/x/x11_util.h" |
| 18 #include "ui/events/platform/platform_event_dispatcher.h" | 15 #include "ui/events/platform/platform_event_dispatcher.h" |
| 19 #include "ui/events/platform/platform_event_source.h" | 16 #include "ui/events/platform/platform_event_source.h" |
| 20 #include "ui/gfx/display_observer.h" | 17 #include "ui/gfx/display_observer.h" |
| 21 #include "ui/gfx/x/x11_atom_cache.h" | 18 #include "ui/gfx/x/x11_atom_cache.h" |
| 22 #include "ui/gfx/x/x11_types.h" | 19 #include "ui/gfx/x/x11_types.h" |
| 23 #include "ui/views/test/views_test_base.h" | 20 #include "ui/views/test/views_test_base.h" |
| 24 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 21 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 25 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" | 22 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" |
| 26 | 23 |
| 27 namespace { | |
| 28 | |
| 29 // Class which allows for the designation of non-client component targets of | |
| 30 // hit tests. | |
| 31 class TestDesktopNativeWidgetAura : public views::DesktopNativeWidgetAura { | |
| 32 public: | |
| 33 explicit TestDesktopNativeWidgetAura( | |
| 34 views::internal::NativeWidgetDelegate* delegate) | |
| 35 : views::DesktopNativeWidgetAura(delegate) {} | |
| 36 virtual ~TestDesktopNativeWidgetAura() {} | |
| 37 | |
| 38 void set_window_component(int window_component) { | |
| 39 window_component_ = window_component; | |
| 40 } | |
| 41 | |
| 42 // DesktopNativeWidgetAura: | |
| 43 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { | |
| 44 return window_component_; | |
| 45 } | |
| 46 | |
| 47 private: | |
| 48 int window_component_; | |
| 49 | |
| 50 DISALLOW_COPY_AND_ASSIGN(TestDesktopNativeWidgetAura); | |
| 51 }; | |
| 52 | |
| 53 } // namespace | |
| 54 | |
| 55 namespace views { | 24 namespace views { |
| 56 | 25 |
| 57 const int64 kFirstDisplay = 5321829; | 26 const int64 kFirstDisplay = 5321829; |
| 58 const int64 kSecondDisplay = 928310; | 27 const int64 kSecondDisplay = 928310; |
| 59 | 28 |
| 60 // Class which waits till the X11 window associated with the widget passed into | 29 // Class which waits till the X11 window associated with the widget passed into |
| 61 // the constructor is activated. We cannot listen for the widget's activation | 30 // the constructor is activated. We cannot listen for the widget's activation |
| 62 // because the _NET_ACTIVE_WINDOW property is changed after the widget is | 31 // because the _NET_ACTIVE_WINDOW property is changed after the widget is |
| 63 // activated. | 32 // activated. |
| 64 class ActivationWaiter : public ui::PlatformEventDispatcher { | 33 class ActivationWaiter : public ui::PlatformEventDispatcher { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 std::vector<gfx::Display> removed_display_; | 118 std::vector<gfx::Display> removed_display_; |
| 150 | 119 |
| 151 DesktopScreenX11* screen() { return screen_.get(); } | 120 DesktopScreenX11* screen() { return screen_.get(); } |
| 152 | 121 |
| 153 void ResetDisplayChanges() { | 122 void ResetDisplayChanges() { |
| 154 changed_display_.clear(); | 123 changed_display_.clear(); |
| 155 added_display_.clear(); | 124 added_display_.clear(); |
| 156 removed_display_.clear(); | 125 removed_display_.clear(); |
| 157 } | 126 } |
| 158 | 127 |
| 159 Widget* BuildTopLevelDesktopWidget(const gfx::Rect& bounds, | 128 Widget* BuildTopLevelDesktopWidget(const gfx::Rect& bounds) { |
| 160 bool use_test_native_widget) { | |
| 161 Widget* toplevel = new Widget; | 129 Widget* toplevel = new Widget; |
| 162 Widget::InitParams toplevel_params = | 130 Widget::InitParams toplevel_params = |
| 163 CreateParams(Widget::InitParams::TYPE_WINDOW); | 131 CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 164 if (use_test_native_widget) { | 132 toplevel_params.native_widget = |
| 165 toplevel_params.native_widget = | 133 new views::DesktopNativeWidgetAura(toplevel); |
| 166 new TestDesktopNativeWidgetAura(toplevel); | |
| 167 } else { | |
| 168 toplevel_params.native_widget = | |
| 169 new views::DesktopNativeWidgetAura(toplevel); | |
| 170 } | |
| 171 toplevel_params.bounds = bounds; | 134 toplevel_params.bounds = bounds; |
| 172 toplevel_params.remove_standard_frame = true; | 135 toplevel_params.remove_standard_frame = true; |
| 173 toplevel->Init(toplevel_params); | 136 toplevel->Init(toplevel_params); |
| 174 return toplevel; | 137 return toplevel; |
| 175 } | 138 } |
| 176 | 139 |
| 177 private: | 140 private: |
| 178 // Overridden from gfx::DisplayObserver: | 141 // Overridden from gfx::DisplayObserver: |
| 179 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE { | 142 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE { |
| 180 changed_display_.push_back(display); | 143 changed_display_.push_back(display); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 gfx::Rect(640, 0, 1024, 768))); | 268 gfx::Rect(640, 0, 1024, 768))); |
| 306 displays.push_back(gfx::Display(kSecondDisplay, gfx::Rect(0, 0, 640, 480))); | 269 displays.push_back(gfx::Display(kSecondDisplay, gfx::Rect(0, 0, 640, 480))); |
| 307 screen()->ProcessDisplayChange(displays); | 270 screen()->ProcessDisplayChange(displays); |
| 308 | 271 |
| 309 // The first display in the list is always the primary, even if other | 272 // The first display in the list is always the primary, even if other |
| 310 // displays are to the left in screen layout. | 273 // displays are to the left in screen layout. |
| 311 EXPECT_EQ(kFirstDisplay, screen()->GetPrimaryDisplay().id()); | 274 EXPECT_EQ(kFirstDisplay, screen()->GetPrimaryDisplay().id()); |
| 312 } | 275 } |
| 313 | 276 |
| 314 TEST_F(DesktopScreenX11Test, GetWindowAtScreenPoint) { | 277 TEST_F(DesktopScreenX11Test, GetWindowAtScreenPoint) { |
| 315 Widget* window_one = BuildTopLevelDesktopWidget(gfx::Rect(110, 110, 10, 10), | 278 Widget* window_one = BuildTopLevelDesktopWidget(gfx::Rect(110, 110, 10, 10)); |
| 316 false); | 279 Widget* window_two = BuildTopLevelDesktopWidget(gfx::Rect(150, 150, 10, 10)); |
| 317 Widget* window_two = BuildTopLevelDesktopWidget(gfx::Rect(150, 150, 10, 10), | |
| 318 false); | |
| 319 Widget* window_three = | 280 Widget* window_three = |
| 320 BuildTopLevelDesktopWidget(gfx::Rect(115, 115, 20, 20), false); | 281 BuildTopLevelDesktopWidget(gfx::Rect(115, 115, 20, 20)); |
| 321 | 282 |
| 322 window_three->Show(); | 283 window_three->Show(); |
| 323 window_two->Show(); | 284 window_two->Show(); |
| 324 window_one->Show(); | 285 window_one->Show(); |
| 325 | 286 |
| 326 // Make sure the internal state of DesktopWindowTreeHostX11 is set up | 287 // Make sure the internal state of DesktopWindowTreeHostX11 is set up |
| 327 // correctly. | 288 // correctly. |
| 328 ASSERT_EQ(3u, DesktopWindowTreeHostX11::GetAllOpenWindows().size()); | 289 ASSERT_EQ(3u, DesktopWindowTreeHostX11::GetAllOpenWindows().size()); |
| 329 | 290 |
| 330 EXPECT_EQ(window_one->GetNativeWindow(), | 291 EXPECT_EQ(window_one->GetNativeWindow(), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 349 } | 310 } |
| 350 | 311 |
| 351 TEST_F(DesktopScreenX11Test, GetDisplayNearestWindow) { | 312 TEST_F(DesktopScreenX11Test, GetDisplayNearestWindow) { |
| 352 // Set up a two monitor situation. | 313 // Set up a two monitor situation. |
| 353 std::vector<gfx::Display> displays; | 314 std::vector<gfx::Display> displays; |
| 354 displays.push_back(gfx::Display(kFirstDisplay, gfx::Rect(0, 0, 640, 480))); | 315 displays.push_back(gfx::Display(kFirstDisplay, gfx::Rect(0, 0, 640, 480))); |
| 355 displays.push_back(gfx::Display(kSecondDisplay, | 316 displays.push_back(gfx::Display(kSecondDisplay, |
| 356 gfx::Rect(640, 0, 1024, 768))); | 317 gfx::Rect(640, 0, 1024, 768))); |
| 357 screen()->ProcessDisplayChange(displays); | 318 screen()->ProcessDisplayChange(displays); |
| 358 | 319 |
| 359 Widget* window_one = BuildTopLevelDesktopWidget(gfx::Rect(10, 10, 10, 10), | 320 Widget* window_one = BuildTopLevelDesktopWidget(gfx::Rect(10, 10, 10, 10)); |
| 360 false); | 321 Widget* window_two = BuildTopLevelDesktopWidget(gfx::Rect(650, 50, 10, 10)); |
| 361 Widget* window_two = BuildTopLevelDesktopWidget(gfx::Rect(650, 50, 10, 10), | |
| 362 false); | |
| 363 | 322 |
| 364 EXPECT_EQ( | 323 EXPECT_EQ( |
| 365 kFirstDisplay, | 324 kFirstDisplay, |
| 366 screen()->GetDisplayNearestWindow(window_one->GetNativeWindow()).id()); | 325 screen()->GetDisplayNearestWindow(window_one->GetNativeWindow()).id()); |
| 367 EXPECT_EQ( | 326 EXPECT_EQ( |
| 368 kSecondDisplay, | 327 kSecondDisplay, |
| 369 screen()->GetDisplayNearestWindow(window_two->GetNativeWindow()).id()); | 328 screen()->GetDisplayNearestWindow(window_two->GetNativeWindow()).id()); |
| 370 | 329 |
| 371 window_one->CloseNow(); | 330 window_one->CloseNow(); |
| 372 window_two->CloseNow(); | 331 window_two->CloseNow(); |
| 373 } | 332 } |
| 374 | 333 |
| 375 // Tests that the window is maximized in response to a double click event. | |
| 376 TEST_F(DesktopScreenX11Test, DoubleClickHeaderMaximizes) { | |
| 377 Widget* widget = BuildTopLevelDesktopWidget(gfx::Rect(0, 0, 100, 100), true); | |
| 378 widget->Show(); | |
| 379 TestDesktopNativeWidgetAura* native_widget = | |
| 380 static_cast<TestDesktopNativeWidgetAura*>(widget->native_widget()); | |
| 381 native_widget->set_window_component(HTCAPTION); | |
| 382 | |
| 383 aura::Window* window = widget->GetNativeWindow(); | |
| 384 window->SetProperty(aura::client::kCanMaximizeKey, true); | |
| 385 | |
| 386 // Cast to superclass as DesktopWindowTreeHostX11 hide IsMaximized | |
| 387 DesktopWindowTreeHost* rwh = | |
| 388 DesktopWindowTreeHostX11::GetHostForXID(window->GetHost()-> | |
| 389 GetAcceleratedWidget()); | |
| 390 | |
| 391 aura::test::EventGenerator generator(window); | |
| 392 generator.ClickLeftButton(); | |
| 393 generator.DoubleClickLeftButton(); | |
| 394 RunPendingMessages(); | |
| 395 EXPECT_TRUE(rwh->IsMaximized()); | |
| 396 | |
| 397 widget->CloseNow(); | |
| 398 } | |
| 399 | |
| 400 // Tests that the window does not maximize in response to a double click event, | |
| 401 // if the first click was to a different target component than that of the | |
| 402 // second click. | |
| 403 TEST_F(DesktopScreenX11Test, DoubleClickTwoDifferentTargetsDoesntMaximizes) { | |
| 404 Widget* widget = BuildTopLevelDesktopWidget(gfx::Rect(0, 0, 100, 100), true); | |
| 405 widget->Show(); | |
| 406 TestDesktopNativeWidgetAura* native_widget = | |
| 407 static_cast<TestDesktopNativeWidgetAura*>(widget->native_widget()); | |
| 408 | |
| 409 aura::Window* window = widget->GetNativeWindow(); | |
| 410 window->SetProperty(aura::client::kCanMaximizeKey, true); | |
| 411 | |
| 412 // Cast to superclass as DesktopWindowTreeHostX11 hide IsMaximized | |
| 413 DesktopWindowTreeHost* rwh = | |
| 414 DesktopWindowTreeHostX11::GetHostForXID(window->GetHost()-> | |
| 415 GetAcceleratedWidget()); | |
| 416 | |
| 417 aura::test::EventGenerator generator(window); | |
| 418 native_widget->set_window_component(HTCLIENT); | |
| 419 generator.ClickLeftButton(); | |
| 420 native_widget->set_window_component(HTCAPTION); | |
| 421 generator.DoubleClickLeftButton(); | |
| 422 RunPendingMessages(); | |
| 423 EXPECT_FALSE(rwh->IsMaximized()); | |
| 424 | |
| 425 widget->CloseNow(); | |
| 426 } | |
| 427 | |
| 428 // Tests that the window does not maximize in response to a double click event, | |
| 429 // if the double click was interrupted by a right click. | |
| 430 TEST_F(DesktopScreenX11Test, RightClickDuringDoubleClickDoesntMaximize) { | |
| 431 Widget* widget = BuildTopLevelDesktopWidget(gfx::Rect(0, 0, 100, 100), true); | |
| 432 widget->Show(); | |
| 433 TestDesktopNativeWidgetAura* native_widget = | |
| 434 static_cast<TestDesktopNativeWidgetAura*>(widget->native_widget()); | |
| 435 | |
| 436 aura::Window* window = widget->GetNativeWindow(); | |
| 437 window->SetProperty(aura::client::kCanMaximizeKey, true); | |
| 438 | |
| 439 // Cast to superclass as DesktopWindowTreeHostX11 hide IsMaximized | |
| 440 DesktopWindowTreeHost* rwh = static_cast<DesktopWindowTreeHost*>( | |
| 441 DesktopWindowTreeHostX11::GetHostForXID(window->GetHost()-> | |
| 442 GetAcceleratedWidget())); | |
| 443 | |
| 444 aura::test::EventGenerator generator(window); | |
| 445 native_widget->set_window_component(HTCLIENT); | |
| 446 generator.ClickLeftButton(); | |
| 447 native_widget->set_window_component(HTCAPTION); | |
| 448 generator.PressRightButton(); | |
| 449 generator.ReleaseRightButton(); | |
| 450 EXPECT_FALSE(rwh->IsMaximized()); | |
| 451 generator.DoubleClickLeftButton(); | |
| 452 RunPendingMessages(); | |
| 453 EXPECT_FALSE(rwh->IsMaximized()); | |
| 454 | |
| 455 widget->CloseNow(); | |
| 456 } | |
| 457 | |
| 458 } // namespace views | 334 } // namespace views |
| OLD | NEW |