1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/aura/test/test_windows.h"
#include <stddef.h>
#include <algorithm>
#include "base/strings/string_number_conversions.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
#include "ui/compositor/layer.h"
#include "ui/gfx/geometry/rect.h"
namespace aura {
namespace test {
Window* CreateTestWindowWithId(int id, Window* parent) {
return CreateTestWindowWithDelegate(NULL, id, gfx::Rect(), parent);
}
Window* CreateTestWindowWithBounds(const gfx::Rect& bounds, Window* parent) {
return CreateTestWindowWithDelegate(NULL, 0, bounds, parent);
}
Window* CreateTestWindow(SkColor color,
int id,
const gfx::Rect& bounds,
Window* parent) {
return CreateTestWindowWithDelegate(new ColorTestWindowDelegate(color), id,
bounds, parent);
}
Window* CreateTestWindowWithDelegate(WindowDelegate* delegate,
int id,
const gfx::Rect& bounds,
Window* parent) {
return CreateTestWindowWithDelegateAndType(
delegate, client::WINDOW_TYPE_NORMAL, id, bounds, parent, true);
}
Window* CreateTestWindowWithDelegateAndType(WindowDelegate* delegate,
client::WindowType type,
int id,
const gfx::Rect& bounds,
Window* parent,
bool show_on_creation) {
Window* window = new Window(delegate, type);
window->SetId(id);
window->Init(ui::LAYER_TEXTURED);
window->SetProperty(client::kResizeBehaviorKey,
client::kResizeBehaviorCanResize |
client::kResizeBehaviorCanMaximize |
client::kResizeBehaviorCanFullscreen);
window->SetBounds(bounds);
if (show_on_creation)
window->Show();
if (parent)
parent->AddChild(window);
return window;
}
template <typename T>
bool ObjectIsAbove(T* upper, T* lower) {
DCHECK_EQ(upper->parent(), lower->parent());
DCHECK_NE(upper, lower);
const auto& children = upper->parent()->children();
const size_t upper_i = std::ranges::find(children, upper) - children.begin();
const size_t lower_i = std::ranges::find(children, lower) - children.begin();
return upper_i > lower_i;
}
bool WindowIsAbove(Window* upper, Window* lower) {
return ObjectIsAbove<Window>(upper, lower);
}
bool LayerIsAbove(Window* upper, Window* lower) {
return ObjectIsAbove<ui::Layer>(upper->layer(), lower->layer());
}
std::string ChildWindowIDsAsString(aura::Window* parent) {
std::string result;
for (auto i = parent->children().begin(); i != parent->children().end();
++i) {
if (!result.empty())
result += " ";
result += base::NumberToString((*i)->GetId());
}
return result;
}
} // namespace test
} // namespace aura
|