blob: 89bb411f1c3301dd54a2633706eecd134911b109 [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]dbf3d402011-09-14 21:32:1612#include "ui/aura/event.h"
[email protected]f0e90a42012-03-13 23:05:5713#include "ui/aura/root_window.h"
[email protected]dbf3d402011-09-14 21:32:1614#include "ui/aura/window.h"
15#include "ui/aura/window_delegate.h"
[email protected]912be0e2011-11-09 19:05:2416#include "ui/base/hit_test.h"
[email protected]81585f32011-07-29 19:32:0617#include "ui/base/resource/resource_bundle.h"
[email protected]e599f0132011-08-24 19:03:3518#include "ui/base/ui_base_paths.h"
[email protected]94a0d2582012-03-09 00:30:5919#include "ui/gfx/canvas.h"
[email protected]fcb98b72011-11-18 04:29:1820#include "ui/gfx/compositor/test/compositor_test_support.h"
[email protected]81585f32011-07-29 19:32:0621#include "ui/gfx/rect.h"
[email protected]81585f32011-07-29 19:32:0622
[email protected]4a6bef32011-09-07 02:06:0123#if defined(USE_X11)
[email protected]4a6bef32011-09-07 02:06:0124#include "base/message_pump_x.h"
25#endif
26
[email protected]81585f32011-07-29 19:32:0627namespace {
28
[email protected]8d8c7732011-08-25 22:35:1329// Trivial WindowDelegate implementation that draws a colored background.
[email protected]81585f32011-07-29 19:32:0630class DemoWindowDelegate : public aura::WindowDelegate {
31 public:
[email protected]8d8c7732011-08-25 22:35:1332 explicit DemoWindowDelegate(SkColor color) : color_(color) {}
[email protected]81585f32011-07-29 19:32:0633
[email protected]8dd791d2011-09-16 16:37:3034 // Overridden from WindowDelegate:
[email protected]17a6cb952011-11-22 23:04:3835 virtual gfx::Size GetMinimumSize() const OVERRIDE {
36 return gfx::Size();
37 }
[email protected]8dd791d2011-09-16 16:37:3038 virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
39 const gfx::Rect& new_bounds) OVERRIDE {}
[email protected]c94f8592011-09-02 20:12:1340 virtual void OnFocus() OVERRIDE {}
41 virtual void OnBlur() OVERRIDE {}
42 virtual bool OnKeyEvent(aura::KeyEvent* event) OVERRIDE {
43 return false;
44 }
[email protected]0207c92d2011-10-04 14:45:0745 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
[email protected]9e591cb2011-10-17 18:14:3246 return gfx::kNullCursor;
[email protected]0207c92d2011-10-04 14:45:0747 }
[email protected]eaf6dd52011-09-02 00:39:2648 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE {
49 return HTCAPTION;
50 }
[email protected]e0dfebf82011-09-01 02:57:3251 virtual bool OnMouseEvent(aura::MouseEvent* event) OVERRIDE {
[email protected]970aa362011-08-30 20:03:3452 return true;
53 }
[email protected]5951806f2011-10-17 16:06:3554 virtual ui::TouchStatus OnTouchEvent(aura::TouchEvent* event) OVERRIDE {
55 return ui::TOUCH_STATUS_END;
56 }
[email protected]538f9562012-01-17 17:46:0457 virtual ui::GestureStatus OnGestureEvent(aura::GestureEvent* event) OVERRIDE {
58 return ui::GESTURE_STATUS_UNKNOWN;
59 }
[email protected]a8bb96702011-12-03 22:17:4060 virtual bool CanFocus() OVERRIDE { return true; }
[email protected]70ccf702011-09-22 18:15:5861 virtual void OnCaptureLost() OVERRIDE {}
[email protected]8d8c7732011-08-25 22:35:1362 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
[email protected]f0e90a42012-03-13 23:05:5763 canvas->sk_canvas()->drawColor(color_, SkXfermode::kSrc_Mode);
[email protected]8d8c7732011-08-25 22:35:1364 }
[email protected]658600e2011-09-07 21:16:2165 virtual void OnWindowDestroying() OVERRIDE {}
66 virtual void OnWindowDestroyed() OVERRIDE {}
[email protected]6fdefb02011-10-11 04:16:1867 virtual void OnWindowVisibilityChanged(bool visible) OVERRIDE {}
[email protected]970aa362011-08-30 20:03:3468
[email protected]81585f32011-07-29 19:32:0669 private:
[email protected]b1b155512011-08-18 22:47:5070 SkColor color_;
71
[email protected]81585f32011-07-29 19:32:0672 DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate);
73};
74
[email protected]b370f4f2012-03-12 20:16:2375class DemoStackingClient : public aura::client::StackingClient {
76 public:
77 explicit DemoStackingClient(aura::RootWindow* root_window)
78 : root_window_(root_window) {
79 aura::client::SetStackingClient(this);
80 }
81
82 virtual ~DemoStackingClient() {
83 aura::client::SetStackingClient(NULL);
84 }
85
86 // Overridden from aura::client::StackingClient:
87 virtual aura::Window* GetDefaultParent(aura::Window* window) OVERRIDE {
88 return root_window_;
89 }
90
91 private:
92 aura::RootWindow* root_window_;
93
94 DISALLOW_COPY_AND_ASSIGN(DemoStackingClient);
95};
[email protected]81585f32011-07-29 19:32:0696
97} // namespace
98
99int main(int argc, char** argv) {
100 CommandLine::Init(argc, argv);
101
102 // The exit manager is in charge of calling the dtors of singleton objects.
103 base::AtExitManager exit_manager;
104
105 ui::RegisterPathProvider();
106 icu_util::Initialize();
[email protected]70f9df12012-01-28 02:30:04107 ResourceBundle::InitSharedInstanceWithLocale("en-US");
[email protected]81585f32011-07-29 19:32:06108
[email protected]99f07e02011-12-07 00:02:59109 // Create the message-loop here before creating the root window.
[email protected]905e19a2011-09-07 02:17:53110 MessageLoop message_loop(MessageLoop::TYPE_UI);
[email protected]9783633c2011-10-27 15:41:52111 ui::CompositorTestSupport::Initialize();
[email protected]905e19a2011-09-07 02:17:53112
[email protected]58482fa2012-03-02 14:57:39113 scoped_ptr<aura::RootWindow> root_window(new aura::RootWindow);
[email protected]b370f4f2012-03-12 20:16:23114 scoped_ptr<DemoStackingClient> stacking_client(new DemoStackingClient(
115 root_window.get()));
[email protected]81585f32011-07-29 19:32:06116
[email protected]b1b155512011-08-18 22:47:50117 // Create a hierarchy of test windows.
[email protected]8d8c7732011-08-25 22:35:13118 DemoWindowDelegate window_delegate1(SK_ColorBLUE);
119 aura::Window window1(&window_delegate1);
[email protected]b1b155512011-08-18 22:47:50120 window1.set_id(1);
[email protected]da7584c2012-01-28 03:19:12121 window1.Init(ui::Layer::LAYER_TEXTURED);
[email protected]7fca53d42011-09-29 15:38:12122 window1.SetBounds(gfx::Rect(100, 100, 400, 400));
[email protected]a3929aba2011-09-30 18:30:17123 window1.Show();
[email protected]8d8c7732011-08-25 22:35:13124 window1.SetParent(NULL);
[email protected]b1b155512011-08-18 22:47:50125
[email protected]8d8c7732011-08-25 22:35:13126 DemoWindowDelegate window_delegate2(SK_ColorRED);
127 aura::Window window2(&window_delegate2);
[email protected]b1b155512011-08-18 22:47:50128 window2.set_id(2);
[email protected]da7584c2012-01-28 03:19:12129 window2.Init(ui::Layer::LAYER_TEXTURED);
[email protected]7fca53d42011-09-29 15:38:12130 window2.SetBounds(gfx::Rect(200, 200, 350, 350));
[email protected]a3929aba2011-09-30 18:30:17131 window2.Show();
[email protected]8d8c7732011-08-25 22:35:13132 window2.SetParent(NULL);
[email protected]b1b155512011-08-18 22:47:50133
[email protected]8d8c7732011-08-25 22:35:13134 DemoWindowDelegate window_delegate3(SK_ColorGREEN);
135 aura::Window window3(&window_delegate3);
[email protected]b1b155512011-08-18 22:47:50136 window3.set_id(3);
[email protected]da7584c2012-01-28 03:19:12137 window3.Init(ui::Layer::LAYER_TEXTURED);
[email protected]7fca53d42011-09-29 15:38:12138 window3.SetBounds(gfx::Rect(10, 10, 50, 50));
[email protected]a3929aba2011-09-30 18:30:17139 window3.Show();
[email protected]8d8c7732011-08-25 22:35:13140 window3.SetParent(&window2);
[email protected]b1b155512011-08-18 22:47:50141
[email protected]58482fa2012-03-02 14:57:39142 root_window->ShowRootWindow();
[email protected]01c5bab2012-02-25 02:37:43143 MessageLoopForUI::current()->Run();
[email protected]9783633c2011-10-27 15:41:52144
145 ui::CompositorTestSupport::Terminate();
146
[email protected]81585f32011-07-29 19:32:06147 return 0;
148}