1 // Copyright (c) 2012 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.
4
5 #include "ui/aura/test/test_windows.h"
6
7 #include "base/strings/string_number_conversions.h"
8 #include "ui/aura/client/aura_constants.h"
9 #include "ui/aura/window.h"
10 #include "ui/compositor/layer.h"
11 #include "ui/gfx/rect.h"
12
13 namespace aura {
14 namespace test {
15
CreateTestWindowWithId(int id,Window * parent)16 Window* CreateTestWindowWithId(int id, Window* parent) {
17 return CreateTestWindowWithDelegate(NULL, id, gfx::Rect(), parent);
18 }
19
CreateTestWindowWithBounds(const gfx::Rect & bounds,Window * parent)20 Window* CreateTestWindowWithBounds(const gfx::Rect& bounds, Window* parent) {
21 return CreateTestWindowWithDelegate(NULL, 0, bounds, parent);
22 }
23
CreateTestWindow(SkColor color,int id,const gfx::Rect & bounds,Window * parent)24 Window* CreateTestWindow(SkColor color,
25 int id,
26 const gfx::Rect& bounds,
27 Window* parent) {
28 return CreateTestWindowWithDelegate(new ColorTestWindowDelegate(color),
29 id, bounds, parent);
30 }
31
CreateTestWindowWithDelegate(WindowDelegate * delegate,int id,const gfx::Rect & bounds,Window * parent)32 Window* CreateTestWindowWithDelegate(WindowDelegate* delegate,
33 int id,
34 const gfx::Rect& bounds,
35 Window* parent) {
36 return CreateTestWindowWithDelegateAndType(
37 delegate, ui::wm::WINDOW_TYPE_NORMAL, id, bounds, parent);
38 }
39
CreateTestWindowWithDelegateAndType(WindowDelegate * delegate,ui::wm::WindowType type,int id,const gfx::Rect & bounds,Window * parent)40 Window* CreateTestWindowWithDelegateAndType(WindowDelegate* delegate,
41 ui::wm::WindowType type,
42 int id,
43 const gfx::Rect& bounds,
44 Window* parent) {
45 Window* window = new Window(delegate);
46 window->set_id(id);
47 window->SetType(type);
48 window->Init(aura::WINDOW_LAYER_TEXTURED);
49 window->SetBounds(bounds);
50 window->Show();
51 if (parent)
52 parent->AddChild(window);
53 window->SetProperty(aura::client::kCanMaximizeKey, true);
54 return window;
55 }
56
57 template <typename T>
ObjectIsAbove(T * upper,T * lower)58 bool ObjectIsAbove(T* upper, T* lower) {
59 DCHECK_EQ(upper->parent(), lower->parent());
60 DCHECK_NE(upper, lower);
61 const std::vector<T*>& children = upper->parent()->children();
62 const size_t upper_i =
63 std::find(children.begin(), children.end(), upper) - children.begin();
64 const size_t lower_i =
65 std::find(children.begin(), children.end(), lower) - children.begin();
66 return upper_i > lower_i;
67 }
68
WindowIsAbove(Window * upper,Window * lower)69 bool WindowIsAbove(Window* upper, Window* lower) {
70 return ObjectIsAbove<Window>(upper, lower);
71 }
72
LayerIsAbove(Window * upper,Window * lower)73 bool LayerIsAbove(Window* upper, Window* lower) {
74 return ObjectIsAbove<ui::Layer>(upper->layer(), lower->layer());
75 }
76
ChildWindowIDsAsString(aura::Window * parent)77 std::string ChildWindowIDsAsString(aura::Window* parent) {
78 std::string result;
79 for (Window::Windows::const_iterator i = parent->children().begin();
80 i != parent->children().end(); ++i) {
81 if (!result.empty())
82 result += " ";
83 result += base::IntToString((*i)->id());
84 }
85 return result;
86 }
87
88 } // namespace test
89 } // namespace aura
90