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 <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
8 #include <X11/Xregion.h> | 8 #include <X11/Xregion.h> |
9 #include <X11/extensions/shape.h> | 9 #include <X11/extensions/shape.h> |
10 #include <stddef.h> | 10 #include <stddef.h> |
11 | 11 |
12 #include <algorithm> | 12 #include <algorithm> |
13 #include <memory> | 13 #include <memory> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 // Get rid of X11 macros which conflict with gtest. | 16 // Get rid of X11 macros which conflict with gtest. |
17 #undef Bool | 17 #undef Bool |
18 #undef None | 18 #undef None |
19 | 19 |
20 #include "base/macros.h" | 20 #include "base/macros.h" |
21 #include "base/memory/ptr_util.h" | 21 #include "base/memory/ptr_util.h" |
22 #include "third_party/skia/include/core/SkRect.h" | 22 #include "third_party/skia/include/core/SkRect.h" |
23 #include "third_party/skia/include/core/SkRegion.h" | 23 #include "third_party/skia/include/core/SkRegion.h" |
24 #include "ui/aura/window.h" | 24 #include "ui/aura/window.h" |
25 #include "ui/aura/window_tree_host.h" | 25 #include "ui/aura/window_tree_host.h" |
26 #include "ui/events/platform/x11/x11_event_source.h" | 26 #include "ui/events/platform/x11/x11_event_source.h" |
27 #include "ui/gfx/path.h" | 27 #include "ui/gfx/path.h" |
28 #include "ui/gfx/path_x11.h" | 28 #include "ui/gfx/path_x11.h" |
29 #include "ui/gfx/x/x11_atom_cache.h" | |
30 #include "ui/views/test/views_interactive_ui_test_base.h" | 29 #include "ui/views/test/views_interactive_ui_test_base.h" |
31 #include "ui/views/test/x11_property_change_waiter.h" | 30 #include "ui/views/test/x11_property_change_waiter.h" |
32 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 31 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
33 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h" | 32 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h" |
34 #include "ui/views/widget/widget.h" | 33 #include "ui/views/widget/widget.h" |
35 | 34 |
36 namespace views { | 35 namespace views { |
37 | 36 |
38 namespace { | 37 namespace { |
39 | 38 |
40 // Waits till |window| is minimized. | 39 // Waits till |window| is minimized. |
41 class MinimizeWaiter : public X11PropertyChangeWaiter { | 40 class MinimizeWaiter : public X11PropertyChangeWaiter { |
42 public: | 41 public: |
43 explicit MinimizeWaiter(XID window) | 42 explicit MinimizeWaiter(XID window) |
44 : X11PropertyChangeWaiter(window, "_NET_WM_STATE") { | 43 : X11PropertyChangeWaiter(window, "_NET_WM_STATE") {} |
45 const char* const kAtomsToCache[] = {"_NET_WM_STATE_HIDDEN", nullptr}; | |
46 atom_cache_.reset(new ui::X11AtomCache(gfx::GetXDisplay(), kAtomsToCache)); | |
47 } | |
48 | 44 |
49 ~MinimizeWaiter() override {} | 45 ~MinimizeWaiter() override {} |
50 | 46 |
51 private: | 47 private: |
52 // X11PropertyChangeWaiter: | 48 // X11PropertyChangeWaiter: |
53 bool ShouldKeepOnWaiting(const ui::PlatformEvent& event) override { | 49 bool ShouldKeepOnWaiting(const ui::PlatformEvent& event) override { |
54 std::vector<Atom> wm_states; | 50 std::vector<Atom> wm_states; |
55 if (ui::GetAtomArrayProperty(xwindow(), "_NET_WM_STATE", &wm_states)) { | 51 if (ui::GetAtomArrayProperty(xwindow(), "_NET_WM_STATE", &wm_states)) { |
56 auto it = std::find(wm_states.cbegin(), wm_states.cend(), | 52 auto it = std::find(wm_states.cbegin(), wm_states.cend(), |
57 atom_cache_->GetAtom("_NET_WM_STATE_HIDDEN")); | 53 ui::GetAtom("_NET_WM_STATE_HIDDEN")); |
58 return it == wm_states.cend(); | 54 return it == wm_states.cend(); |
59 } | 55 } |
60 return true; | 56 return true; |
61 } | 57 } |
62 | 58 |
63 std::unique_ptr<ui::X11AtomCache> atom_cache_; | |
64 | |
65 DISALLOW_COPY_AND_ASSIGN(MinimizeWaiter); | 59 DISALLOW_COPY_AND_ASSIGN(MinimizeWaiter); |
66 }; | 60 }; |
67 | 61 |
68 // Waits till |_NET_CLIENT_LIST_STACKING| is updated to include | 62 // Waits till |_NET_CLIENT_LIST_STACKING| is updated to include |
69 // |expected_windows|. | 63 // |expected_windows|. |
70 class StackingClientListWaiter : public X11PropertyChangeWaiter { | 64 class StackingClientListWaiter : public X11PropertyChangeWaiter { |
71 public: | 65 public: |
72 StackingClientListWaiter(XID* expected_windows, size_t count) | 66 StackingClientListWaiter(XID* expected_windows, size_t count) |
73 : X11PropertyChangeWaiter(ui::GetX11RootWindow(), | 67 : X11PropertyChangeWaiter(ui::GetX11RootWindow(), |
74 "_NET_CLIENT_LIST_STACKING"), | 68 "_NET_CLIENT_LIST_STACKING"), |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 XID menu_xid = XCreateWindow(xdisplay(), | 387 XID menu_xid = XCreateWindow(xdisplay(), |
394 root, | 388 root, |
395 0, 0, 1, 1, | 389 0, 0, 1, 1, |
396 0, // border width | 390 0, // border width |
397 CopyFromParent, // depth | 391 CopyFromParent, // depth |
398 InputOutput, | 392 InputOutput, |
399 CopyFromParent, // visual | 393 CopyFromParent, // visual |
400 CWOverrideRedirect, | 394 CWOverrideRedirect, |
401 &swa); | 395 &swa); |
402 { | 396 { |
403 const char* const kAtomsToCache[] = {"_NET_WM_WINDOW_TYPE_MENU", nullptr}; | 397 ui::SetAtomProperty(menu_xid, "_NET_WM_WINDOW_TYPE", "ATOM", |
404 ui::X11AtomCache atom_cache(gfx::GetXDisplay(), kAtomsToCache); | 398 ui::GetAtom("_NET_WM_WINDOW_TYPE_MENU")); |
405 ui::SetAtomProperty(menu_xid, | |
406 "_NET_WM_WINDOW_TYPE", | |
407 "ATOM", | |
408 atom_cache.GetAtom("_NET_WM_WINDOW_TYPE_MENU")); | |
409 } | 399 } |
410 ui::SetUseOSWindowFrame(menu_xid, false); | 400 ui::SetUseOSWindowFrame(menu_xid, false); |
411 ShowAndSetXWindowBounds(menu_xid, gfx::Rect(140, 110, 100, 100)); | 401 ShowAndSetXWindowBounds(menu_xid, gfx::Rect(140, 110, 100, 100)); |
412 ui::X11EventSource::GetInstance()->DispatchXEvents(); | 402 ui::X11EventSource::GetInstance()->DispatchXEvents(); |
413 | 403 |
414 // |menu_xid| is never added to _NET_CLIENT_LIST_STACKING. | 404 // |menu_xid| is never added to _NET_CLIENT_LIST_STACKING. |
415 XID xids[] = { xid }; | 405 XID xids[] = { xid }; |
416 StackingClientListWaiter stack_waiter(xids, arraysize(xids)); | 406 StackingClientListWaiter stack_waiter(xids, arraysize(xids)); |
417 stack_waiter.Wait(); | 407 stack_waiter.Wait(); |
418 | 408 |
419 EXPECT_EQ(xid, FindTopmostXWindowAt(110, 110)); | 409 EXPECT_EQ(xid, FindTopmostXWindowAt(110, 110)); |
420 EXPECT_EQ(menu_xid, FindTopmostXWindowAt(150, 120)); | 410 EXPECT_EQ(menu_xid, FindTopmostXWindowAt(150, 120)); |
421 EXPECT_EQ(menu_xid, FindTopmostXWindowAt(210, 120)); | 411 EXPECT_EQ(menu_xid, FindTopmostXWindowAt(210, 120)); |
422 | 412 |
423 XDestroyWindow(xdisplay(), xid); | 413 XDestroyWindow(xdisplay(), xid); |
424 XDestroyWindow(xdisplay(), menu_xid); | 414 XDestroyWindow(xdisplay(), menu_xid); |
425 } | 415 } |
426 | 416 |
427 } // namespace views | 417 } // namespace views |
OLD | NEW |