blob: 7291c60cd0fbb8e726f6d1edffb228afba50d715 [file] [log] [blame]
[email protected]538f9562012-01-17 17:46:041// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]81585f32011-07-29 19:32:062// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]81585f32011-07-29 19:32:065#include "base/at_exit.h"
6#include "base/command_line.h"
7#include "base/i18n/icu_util.h"
8#include "base/memory/scoped_ptr.h"
[email protected]905e19a2011-09-07 02:17:539#include "base/message_loop.h"
[email protected]81585f32011-07-29 19:32:0610#include "third_party/skia/include/core/SkXfermode.h"
[email protected]b370f4f2012-03-12 20:16:2311#include "ui/aura/client/stacking_client.h"
[email protected]e050ef142012-03-21 01:04:2412#include "ui/aura/env.h"
[email protected]dbf3d402011-09-14 21:32:1613#include "ui/aura/event.h"
[email protected]e050ef142012-03-21 01:04:2414#include "ui/aura/monitor_manager.h"
[email protected]f0e90a42012-03-13 23:05:5715#include "ui/aura/root_window.h"
[email protected]dbf3d402011-09-14 21:32:1616#include "ui/aura/window.h"
17#include "ui/aura/window_delegate.h"
[email protected]912be0e2011-11-09 19:05:2418#include "ui/base/hit_test.h"
[email protected]81585f32011-07-29 19:32:0619#include "ui/base/resource/resource_bundle.h"
[email protected]e599f0132011-08-24 19:03:3520#include "ui/base/ui_base_paths.h"
[email protected]94a0d2582012-03-09 00:30:5921#include "ui/gfx/canvas.h"
[email protected]fcb98b72011-11-18 04:29:1822#include "ui/gfx/compositor/test/compositor_test_support.h"
[email protected]81585f32011-07-29 19:32:0623#include "ui/gfx/rect.h"
[email protected]81585f32011-07-29 19:32:0624
[email protected]4a6bef32011-09-07 02:06:0125#if defined(USE_X11)
[email protected]4a6bef32011-09-07 02:06:0126#include "base/message_pump_x.h"
27#endif
28
[email protected]81585f32011-07-29 19:32:0629namespace {
30
[email protected]8d8c7732011-08-25 22:35:1331// Trivial WindowDelegate implementation that draws a colored background.
[email protected]81585f32011-07-29 19:32:0632class DemoWindowDelegate : public aura::WindowDelegate {
33 public:
[email protected]8d8c7732011-08-25 22:35:1334 explicit DemoWindowDelegate(SkColor color) : color_(color) {}
[email protected]81585f32011-07-29 19:32:0635
[email protected]8dd791d2011-09-16 16:37:3036 // Overridden from WindowDelegate:
[email protected]17a6cb952011-11-22 23:04:3837 virtual gfx::Size GetMinimumSize() const OVERRIDE {
38 return gfx::Size();
39 }
[email protected]8dd791d2011-09-16 16:37:3040 virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
41 const gfx::Rect& new_bounds) OVERRIDE {}
[email protected]c94f8592011-09-02 20:12:1342 virtual void OnFocus() OVERRIDE {}
43 virtual void OnBlur() OVERRIDE {}
44 virtual bool OnKeyEvent(aura::KeyEvent* event) OVERRIDE {
45 return false;
46 }
[email protected]0207c92d2011-10-04 14:45:0747 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
[email protected]9e591cb2011-10-17 18:14:3248 return gfx::kNullCursor;
[email protected]0207c92d2011-10-04 14:45:0749 }
[email protected]eaf6dd52011-09-02 00:39:2650 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE {
51 return HTCAPTION;
52 }
[email protected]e0dfebf82011-09-01 02:57:3253 virtual bool OnMouseEvent(aura::MouseEvent* event) OVERRIDE {
[email protected]970aa362011-08-30 20:03:3454 return true;
55 }
[email protected]5951806f2011-10-17 16:06:3556 virtual ui::TouchStatus OnTouchEvent(aura::TouchEvent* event) OVERRIDE {
57 return ui::TOUCH_STATUS_END;
58 }
[email protected]538f9562012-01-17 17:46:0459 virtual ui::GestureStatus OnGestureEvent(aura::GestureEvent* event) OVERRIDE {
60 return ui::GESTURE_STATUS_UNKNOWN;
61 }
[email protected]a8bb96702011-12-03 22:17:4062 virtual bool CanFocus() OVERRIDE { return true; }
[email protected]70ccf702011-09-22 18:15:5863 virtual void OnCaptureLost() OVERRIDE {}
[email protected]8d8c7732011-08-25 22:35:1364 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
[email protected]6fae7972012-04-10 20:12:0865 canvas->DrawColor(color_, SkXfermode::kSrc_Mode);
[email protected]8d8c7732011-08-25 22:35:1366 }
[email protected]658600e2011-09-07 21:16:2167 virtual void OnWindowDestroying() OVERRIDE {}
68 virtual void OnWindowDestroyed() OVERRIDE {}
[email protected]6fdefb02011-10-11 04:16:1869 virtual void OnWindowVisibilityChanged(bool visible) OVERRIDE {}
[email protected]970aa362011-08-30 20:03:3470
[email protected]81585f32011-07-29 19:32:0671 private:
[email protected]b1b155512011-08-18 22:47:5072 SkColor color_;
73
[email protected]81585f32011-07-29 19:32:0674 DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate);
75};
76
[email protected]b370f4f2012-03-12 20:16:2377class DemoStackingClient : public aura::client::StackingClient {
78 public:
79 explicit DemoStackingClient(aura::RootWindow* root_window)
80 : root_window_(root_window) {
81 aura::client::SetStackingClient(this);
82 }
83
84 virtual ~DemoStackingClient() {
85 aura::client::SetStackingClient(NULL);
86 }
87
88 // Overridden from aura::client::StackingClient:
89 virtual aura::Window* GetDefaultParent(aura::Window* window) OVERRIDE {
90 return root_window_;
91 }
92
93 private:
94 aura::RootWindow* root_window_;
95
96 DISALLOW_COPY_AND_ASSIGN(DemoStackingClient);
97};
[email protected]81585f32011-07-29 19:32:0698
99} // namespace
100
101int main(int argc, char** argv) {
102 CommandLine::Init(argc, argv);
103
104 // The exit manager is in charge of calling the dtors of singleton objects.
105 base::AtExitManager exit_manager;
106
107 ui::RegisterPathProvider();
108 icu_util::Initialize();
[email protected]70f9df12012-01-28 02:30:04109 ResourceBundle::InitSharedInstanceWithLocale("en-US");
[email protected]81585f32011-07-29 19:32:06110
[email protected]99f07e02011-12-07 00:02:59111 // Create the message-loop here before creating the root window.
[email protected]905e19a2011-09-07 02:17:53112 MessageLoop message_loop(MessageLoop::TYPE_UI);
[email protected]9783633c2011-10-27 15:41:52113 ui::CompositorTestSupport::Initialize();
[email protected]905e19a2011-09-07 02:17:53114
[email protected]e050ef142012-03-21 01:04:24115 scoped_ptr<aura::RootWindow> root_window(
116 aura::MonitorManager::CreateRootWindowForPrimaryMonitor());
[email protected]b370f4f2012-03-12 20:16:23117 scoped_ptr<DemoStackingClient> stacking_client(new DemoStackingClient(
118 root_window.get()));
[email protected]81585f32011-07-29 19:32:06119
[email protected]b1b155512011-08-18 22:47:50120 // Create a hierarchy of test windows.
[email protected]8d8c7732011-08-25 22:35:13121 DemoWindowDelegate window_delegate1(SK_ColorBLUE);
122 aura::Window window1(&window_delegate1);
[email protected]b1b155512011-08-18 22:47:50123 window1.set_id(1);
[email protected]595b52a2012-03-23 16:17:24124 window1.Init(ui::LAYER_TEXTURED);
[email protected]7fca53d42011-09-29 15:38:12125 window1.SetBounds(gfx::Rect(100, 100, 400, 400));
[email protected]a3929aba2011-09-30 18:30:17126 window1.Show();
[email protected]8d8c7732011-08-25 22:35:13127 window1.SetParent(NULL);
[email protected]b1b155512011-08-18 22:47:50128
[email protected]8d8c7732011-08-25 22:35:13129 DemoWindowDelegate window_delegate2(SK_ColorRED);
130 aura::Window window2(&window_delegate2);
[email protected]b1b155512011-08-18 22:47:50131 window2.set_id(2);
[email protected]595b52a2012-03-23 16:17:24132 window2.Init(ui::LAYER_TEXTURED);
[email protected]7fca53d42011-09-29 15:38:12133 window2.SetBounds(gfx::Rect(200, 200, 350, 350));
[email protected]a3929aba2011-09-30 18:30:17134 window2.Show();
[email protected]8d8c7732011-08-25 22:35:13135 window2.SetParent(NULL);
[email protected]b1b155512011-08-18 22:47:50136
[email protected]8d8c7732011-08-25 22:35:13137 DemoWindowDelegate window_delegate3(SK_ColorGREEN);
138 aura::Window window3(&window_delegate3);
[email protected]b1b155512011-08-18 22:47:50139 window3.set_id(3);
[email protected]595b52a2012-03-23 16:17:24140 window3.Init(ui::LAYER_TEXTURED);
[email protected]7fca53d42011-09-29 15:38:12141 window3.SetBounds(gfx::Rect(10, 10, 50, 50));
[email protected]a3929aba2011-09-30 18:30:17142 window3.Show();
[email protected]8d8c7732011-08-25 22:35:13143 window3.SetParent(&window2);
[email protected]b1b155512011-08-18 22:47:50144
[email protected]58482fa2012-03-02 14:57:39145 root_window->ShowRootWindow();
[email protected]01c5bab2012-02-25 02:37:43146 MessageLoopForUI::current()->Run();
[email protected]9783633c2011-10-27 15:41:52147
148 ui::CompositorTestSupport::Terminate();
149
[email protected]81585f32011-07-29 19:32:06150 return 0;
151}