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
3 // found in the LICENSE file.
5 #include "ui/views/test/widget_test.h"
7 #include "ui/aura/client/focus_client.h"
8 #include "ui/aura/window.h"
9 #include "ui/aura/window_tree_host.h"
10 #include "ui/views/widget/widget.h"
13 #include <X11/Xutil.h>
14 #include "ui/gfx/x/x11_types.h"
22 // Perform a pre-order traversal of |children| and all descendants, looking for
23 // |first| and |second|. If |first| is found before |second|, return true.
24 // When a layer is found, it is set to null. Returns once |second| is found, or
25 // when there are no children left.
26 // Note that ui::Layer children are bottom-to-top stacking order.
27 bool FindLayersInOrder(const std::vector
<ui::Layer
*>& children
,
28 const ui::Layer
** first
,
29 const ui::Layer
** second
) {
30 for (const ui::Layer
* child
: children
) {
31 if (child
== *second
) {
33 return *first
== nullptr;
39 if (FindLayersInOrder(child
->children(), first
, second
))
42 // If second is cleared without success, exit early with failure.
52 void WidgetTest::SimulateNativeDestroy(Widget
* widget
) {
53 delete widget
->GetNativeView();
57 void WidgetTest::SimulateNativeActivate(Widget
* widget
) {
58 gfx::NativeView native_view
= widget
->GetNativeView();
59 aura::client::GetFocusClient(native_view
)->FocusWindow(native_view
);
63 bool WidgetTest::IsNativeWindowVisible(gfx::NativeWindow window
) {
64 return window
->IsVisible();
68 bool WidgetTest::IsWindowStackedAbove(Widget
* above
, Widget
* below
) {
69 EXPECT_TRUE(above
->IsVisible());
70 EXPECT_TRUE(below
->IsVisible());
72 ui::Layer
* root_layer
= above
->GetNativeWindow()->GetRootWindow()->layer();
74 // Traversal is bottom-to-top, so |below| should be found first.
75 const ui::Layer
* first
= below
->GetLayer();
76 const ui::Layer
* second
= above
->GetLayer();
77 return FindLayersInOrder(root_layer
->children(), &first
, &second
);
81 gfx::Size
WidgetTest::GetNativeWidgetMinimumContentSize(Widget
* widget
) {
82 // On Windows, HWNDMessageHandler receives a WM_GETMINMAXINFO message whenever
83 // the window manager is interested in knowing the size constraints. On
84 // ChromeOS, it's handled internally. Elsewhere, the size constraints need to
85 // be pushed to the window server when they change.
86 #if defined(OS_CHROMEOS) || defined(OS_WIN)
87 return widget
->GetNativeWindow()->delegate()->GetMinimumSize();
88 #elif defined(USE_X11)
93 widget
->GetNativeWindow()->GetHost()->GetAcceleratedWidget(), &hints
,
95 return gfx::Size(hints
.min_width
, hints
.min_height
);
103 ui::EventProcessor
* WidgetTest::GetEventProcessor(Widget
* widget
) {
104 return widget
->GetNativeWindow()->GetHost()->event_processor();
108 ui::internal::InputMethodDelegate
* WidgetTest::GetInputMethodDelegateForWidget(
110 return widget
->GetNativeWindow()->GetRootWindow()->GetHost();