OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/x11_topmost_window_finder.h" | 5 #include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 #include <X11/extensions/shape.h> | 9 #include <X11/extensions/shape.h> |
10 #include <X11/Xlib.h> | 10 #include <X11/Xlib.h> |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 | 349 |
350 // Repeat test for an X window which does not belong to a views::Widget | 350 // Repeat test for an X window which does not belong to a views::Widget |
351 // because the code path is different. | 351 // because the code path is different. |
352 EXPECT_EQ(xid2, FindTopmostXWindowAt(305, 120)); | 352 EXPECT_EQ(xid2, FindTopmostXWindowAt(305, 120)); |
353 EXPECT_NE(xid1, FindTopmostXWindowAt(305, 105)); | 353 EXPECT_NE(xid1, FindTopmostXWindowAt(305, 105)); |
354 EXPECT_NE(xid2, FindTopmostXWindowAt(305, 105)); | 354 EXPECT_NE(xid2, FindTopmostXWindowAt(305, 105)); |
355 | 355 |
356 XDestroyWindow(xdisplay(), xid2); | 356 XDestroyWindow(xdisplay(), xid2); |
357 } | 357 } |
358 | 358 |
| 359 // Test that a window with an empty shape are properly handled. |
| 360 TEST_F(X11TopmostWindowFinderTest, NonRectangularEmptyShape) { |
| 361 if (!ui::IsShapeExtensionAvailable()) |
| 362 return; |
| 363 |
| 364 scoped_ptr<Widget> widget1( |
| 365 CreateAndShowWidget(gfx::Rect(100, 100, 100, 100))); |
| 366 XID xid1 = widget1->GetNativeWindow()->GetHost()->GetAcceleratedWidget(); |
| 367 SkRegion* skregion1 = new SkRegion; |
| 368 skregion1->op(SkIRect::MakeXYWH(0, 0, 0, 0), SkRegion::kUnion_Op); |
| 369 // Widget takes ownership of |skregion1|. |
| 370 widget1->SetShape(skregion1); |
| 371 |
| 372 XID xids[] = { xid1 }; |
| 373 StackingClientListWaiter stack_waiter(xids, arraysize(xids)); |
| 374 stack_waiter.Wait(); |
| 375 ui::X11EventSource::GetInstance()->DispatchXEvents(); |
| 376 |
| 377 EXPECT_NE(xid1, FindTopmostXWindowAt(105, 105)); |
| 378 } |
| 379 |
| 380 // Test that setting a Null shape removes the shape. |
| 381 TEST_F(X11TopmostWindowFinderTest, NonRectangularNullShape) { |
| 382 if (!ui::IsShapeExtensionAvailable()) |
| 383 return; |
| 384 |
| 385 scoped_ptr<Widget> widget1( |
| 386 CreateAndShowWidget(gfx::Rect(100, 100, 100, 100))); |
| 387 XID xid1 = widget1->GetNativeWindow()->GetHost()->GetAcceleratedWidget(); |
| 388 SkRegion* skregion1 = new SkRegion; |
| 389 skregion1->op(SkIRect::MakeXYWH(0, 0, 0, 0), SkRegion::kUnion_Op); |
| 390 // Widget takes ownership of |skregion1|. |
| 391 widget1->SetShape(skregion1); |
| 392 |
| 393 // Remove the shape - this is now just a normal window. |
| 394 widget1->SetShape(NULL); |
| 395 |
| 396 XID xids[] = { xid1 }; |
| 397 StackingClientListWaiter stack_waiter(xids, arraysize(xids)); |
| 398 stack_waiter.Wait(); |
| 399 ui::X11EventSource::GetInstance()->DispatchXEvents(); |
| 400 |
| 401 EXPECT_EQ(xid1, FindTopmostXWindowAt(105, 105)); |
| 402 } |
| 403 |
359 // Test that the TopmostWindowFinder finds windows which belong to menus | 404 // Test that the TopmostWindowFinder finds windows which belong to menus |
360 // (which may or may not belong to Chrome). | 405 // (which may or may not belong to Chrome). |
361 TEST_F(X11TopmostWindowFinderTest, Menu) { | 406 TEST_F(X11TopmostWindowFinderTest, Menu) { |
362 XID xid = CreateAndShowXWindow(gfx::Rect(100, 100, 100, 100)); | 407 XID xid = CreateAndShowXWindow(gfx::Rect(100, 100, 100, 100)); |
363 | 408 |
364 XID root = DefaultRootWindow(xdisplay()); | 409 XID root = DefaultRootWindow(xdisplay()); |
365 XSetWindowAttributes swa; | 410 XSetWindowAttributes swa; |
366 swa.override_redirect = True; | 411 swa.override_redirect = True; |
367 XID menu_xid = XCreateWindow(xdisplay(), | 412 XID menu_xid = XCreateWindow(xdisplay(), |
368 root, | 413 root, |
(...skipping 23 matching lines...) Expand all Loading... |
392 | 437 |
393 EXPECT_EQ(xid, FindTopmostXWindowAt(110, 110)); | 438 EXPECT_EQ(xid, FindTopmostXWindowAt(110, 110)); |
394 EXPECT_EQ(menu_xid, FindTopmostXWindowAt(150, 120)); | 439 EXPECT_EQ(menu_xid, FindTopmostXWindowAt(150, 120)); |
395 EXPECT_EQ(menu_xid, FindTopmostXWindowAt(210, 120)); | 440 EXPECT_EQ(menu_xid, FindTopmostXWindowAt(210, 120)); |
396 | 441 |
397 XDestroyWindow(xdisplay(), xid); | 442 XDestroyWindow(xdisplay(), xid); |
398 XDestroyWindow(xdisplay(), menu_xid); | 443 XDestroyWindow(xdisplay(), menu_xid); |
399 } | 444 } |
400 | 445 |
401 } // namespace views | 446 } // namespace views |
OLD | NEW |