| 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/test/widget_test.h" | 5 #include "ui/views/test/widget_test.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "ui/aura/client/focus_client.h" | 8 #include "ui/aura/client/focus_client.h" |
| 9 #include "ui/aura/mus/window_tree_client.h" |
| 10 #include "ui/aura/test/aura_test_helper.h" |
| 9 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 10 #include "ui/aura/window_delegate.h" | 12 #include "ui/aura/window_delegate.h" |
| 11 #include "ui/aura/window_tree_host.h" | 13 #include "ui/aura/window_tree_host.h" |
| 14 #include "ui/views/mus/mus_client.h" |
| 12 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
| 13 | 16 |
| 14 #if defined(USE_X11) | 17 #if defined(USE_X11) |
| 15 #include <X11/Xutil.h> | 18 #include <X11/Xutil.h> |
| 16 #include "ui/gfx/x/x11_types.h" // nogncheck | 19 #include "ui/gfx/x/x11_types.h" // nogncheck |
| 17 #endif | 20 #endif |
| 18 | 21 |
| 22 #if defined(USE_X11) && !defined(OS_CHROMEOS) |
| 23 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" |
| 24 #endif |
| 25 |
| 19 namespace views { | 26 namespace views { |
| 20 namespace test { | 27 namespace test { |
| 21 | 28 |
| 22 namespace { | 29 namespace { |
| 23 | 30 |
| 24 // Perform a pre-order traversal of |children| and all descendants, looking for | 31 // Perform a pre-order traversal of |children| and all descendants, looking for |
| 25 // |first| and |second|. If |first| is found before |second|, return true. | 32 // |first| and |second|. If |first| is found before |second|, return true. |
| 26 // When a layer is found, it is set to null. Returns once |second| is found, or | 33 // When a layer is found, it is set to null. Returns once |second| is found, or |
| 27 // when there are no children left. | 34 // when there are no children left. |
| 28 // Note that ui::Layer children are bottom-to-top stacking order. | 35 // Note that ui::Layer children are bottom-to-top stacking order. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 41 if (FindLayersInOrder(child->children(), first, second)) | 48 if (FindLayersInOrder(child->children(), first, second)) |
| 42 return true; | 49 return true; |
| 43 | 50 |
| 44 // If second is cleared without success, exit early with failure. | 51 // If second is cleared without success, exit early with failure. |
| 45 if (!*second) | 52 if (!*second) |
| 46 return false; | 53 return false; |
| 47 } | 54 } |
| 48 return false; | 55 return false; |
| 49 } | 56 } |
| 50 | 57 |
| 58 #if defined(OS_WIN) |
| 59 |
| 60 struct FindAllWindowsData { |
| 61 std::vector<aura::Window*>* windows; |
| 62 }; |
| 63 |
| 64 BOOL CALLBACK FindAllWindowsCallback(HWND hwnd, LPARAM param) { |
| 65 FindAllWindowsData* data = reinterpret_cast<FindAllWindowsData*>(param); |
| 66 if (aura::WindowTreeHost* host = |
| 67 aura::WindowTreeHost::GetForAcceleratedWidget(hwnd)) |
| 68 data->windows->push_back(host->window()); |
| 69 return TRUE; |
| 70 } |
| 71 |
| 72 #endif // OS_WIN |
| 73 |
| 74 std::vector<aura::Window*> GetAllTopLeveLWindows() { |
| 75 std::vector<aura::Window*> roots; |
| 76 #if defined(USE_X11) && !defined(OS_CHROMEOS) |
| 77 roots = DesktopWindowTreeHostX11::GetAllOpenWindows(); |
| 78 #endif |
| 79 #if defined(OS_WIN) |
| 80 { |
| 81 FindAllWindowsData data = {&roots}; |
| 82 EnumThreadWindows(GetCurrentThreadId(), FindAllWindowsCallback, |
| 83 reinterpret_cast<LPARAM>(&data)); |
| 84 } |
| 85 #endif // OS_WIN |
| 86 aura::test::AuraTestHelper* aura_test_helper = |
| 87 aura::test::AuraTestHelper::GetInstance(); |
| 88 if (aura_test_helper) |
| 89 roots.push_back(aura_test_helper->root_window()); |
| 90 |
| 91 if (MusClient::Get()) { |
| 92 auto mus_roots = MusClient::Get()->window_tree_client()->GetRoots(); |
| 93 roots.insert(roots.end(), mus_roots.begin(), mus_roots.end()); |
| 94 } |
| 95 return roots; |
| 96 } |
| 97 |
| 51 } // namespace | 98 } // namespace |
| 52 | 99 |
| 53 // static | 100 // static |
| 54 void WidgetTest::SimulateNativeActivate(Widget* widget) { | 101 void WidgetTest::SimulateNativeActivate(Widget* widget) { |
| 55 gfx::NativeView native_view = widget->GetNativeView(); | 102 gfx::NativeView native_view = widget->GetNativeView(); |
| 56 aura::client::GetFocusClient(native_view)->FocusWindow(native_view); | 103 aura::client::GetFocusClient(native_view)->FocusWindow(native_view); |
| 57 } | 104 } |
| 58 | 105 |
| 59 // static | 106 // static |
| 60 bool WidgetTest::IsNativeWindowVisible(gfx::NativeWindow window) { | 107 bool WidgetTest::IsNativeWindowVisible(gfx::NativeWindow window) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 ui::internal::InputMethodDelegate* WidgetTest::GetInputMethodDelegateForWidget( | 154 ui::internal::InputMethodDelegate* WidgetTest::GetInputMethodDelegateForWidget( |
| 108 Widget* widget) { | 155 Widget* widget) { |
| 109 return widget->GetNativeWindow()->GetRootWindow()->GetHost(); | 156 return widget->GetNativeWindow()->GetRootWindow()->GetHost(); |
| 110 } | 157 } |
| 111 | 158 |
| 112 // static | 159 // static |
| 113 bool WidgetTest::IsNativeWindowTransparent(gfx::NativeWindow window) { | 160 bool WidgetTest::IsNativeWindowTransparent(gfx::NativeWindow window) { |
| 114 return window->transparent(); | 161 return window->transparent(); |
| 115 } | 162 } |
| 116 | 163 |
| 164 // static |
| 165 Widget::Widgets WidgetTest::GetAllWidgets() { |
| 166 std::vector<aura::Window*> toplevel = GetAllTopLeveLWindows(); |
| 167 Widget::Widgets all_widgets; |
| 168 for (aura::Window* root : toplevel) |
| 169 Widget::GetAllChildWidgets(root, &all_widgets); |
| 170 return all_widgets; |
| 171 } |
| 172 |
| 117 } // namespace test | 173 } // namespace test |
| 118 } // namespace views | 174 } // namespace views |
| OLD | NEW |