blob: 8c25f405c31180e551e3d3967fa4aa832065b93c [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]f0e90a42012-03-13 23:05:5714#include "ui/aura/root_window.h"
[email protected]2e236a52012-06-27 22:21:4715#include "ui/aura/single_display_manager.h"
[email protected]be2a0ac2012-07-24 11:23:2216#include "ui/aura/shared/root_window_capture_client.h"
[email protected]dbf3d402011-09-14 21:32:1617#include "ui/aura/window.h"
18#include "ui/aura/window_delegate.h"
[email protected]912be0e2011-11-09 19:05:2419#include "ui/base/hit_test.h"
[email protected]81585f32011-07-29 19:32:0620#include "ui/base/resource/resource_bundle.h"
[email protected]e599f0132011-08-24 19:03:3521#include "ui/base/ui_base_paths.h"
[email protected]116302fc2012-05-05 21:45:4122#include "ui/compositor/test/compositor_test_support.h"
[email protected]94a0d2582012-03-09 00:30:5923#include "ui/gfx/canvas.h"
[email protected]81585f32011-07-29 19:32:0624#include "ui/gfx/rect.h"
[email protected]81585f32011-07-29 19:32:0625
[email protected]4a6bef32011-09-07 02:06:0126#if defined(USE_X11)
[email protected]1a24da52012-05-29 23:25:3827#include "base/message_pump_aurax11.h"
[email protected]4a6bef32011-09-07 02:06:0128#endif
29
[email protected]81585f32011-07-29 19:32:0630namespace {
31
[email protected]8d8c7732011-08-25 22:35:1332// Trivial WindowDelegate implementation that draws a colored background.
[email protected]81585f32011-07-29 19:32:0633class DemoWindowDelegate : public aura::WindowDelegate {
34 public:
[email protected]8d8c7732011-08-25 22:35:1335 explicit DemoWindowDelegate(SkColor color) : color_(color) {}
[email protected]81585f32011-07-29 19:32:0636
[email protected]8dd791d2011-09-16 16:37:3037 // Overridden from WindowDelegate:
[email protected]17a6cb952011-11-22 23:04:3838 virtual gfx::Size GetMinimumSize() const OVERRIDE {
39 return gfx::Size();
40 }
[email protected]8dd791d2011-09-16 16:37:3041 virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
42 const gfx::Rect& new_bounds) OVERRIDE {}
[email protected]87a4b992012-06-18 23:27:4043 virtual void OnFocus(aura::Window* old_focused_window) OVERRIDE {}
[email protected]c94f8592011-09-02 20:12:1344 virtual void OnBlur() OVERRIDE {}
45 virtual bool OnKeyEvent(aura::KeyEvent* event) OVERRIDE {
46 return false;
47 }
[email protected]0207c92d2011-10-04 14:45:0748 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
[email protected]9e591cb2011-10-17 18:14:3249 return gfx::kNullCursor;
[email protected]0207c92d2011-10-04 14:45:0750 }
[email protected]eaf6dd52011-09-02 00:39:2651 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE {
52 return HTCAPTION;
53 }
[email protected]334b81892012-06-16 16:38:1454 virtual bool ShouldDescendIntoChildForEventHandling(
55 aura::Window* child,
56 const gfx::Point& location) OVERRIDE {
57 return true;
58 }
[email protected]e0dfebf82011-09-01 02:57:3259 virtual bool OnMouseEvent(aura::MouseEvent* event) OVERRIDE {
[email protected]970aa362011-08-30 20:03:3460 return true;
61 }
[email protected]5951806f2011-10-17 16:06:3562 virtual ui::TouchStatus OnTouchEvent(aura::TouchEvent* event) OVERRIDE {
63 return ui::TOUCH_STATUS_END;
64 }
[email protected]538f9562012-01-17 17:46:0465 virtual ui::GestureStatus OnGestureEvent(aura::GestureEvent* event) OVERRIDE {
66 return ui::GESTURE_STATUS_UNKNOWN;
67 }
[email protected]a8bb96702011-12-03 22:17:4068 virtual bool CanFocus() OVERRIDE { return true; }
[email protected]70ccf702011-09-22 18:15:5869 virtual void OnCaptureLost() OVERRIDE {}
[email protected]8d8c7732011-08-25 22:35:1370 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
[email protected]6fae7972012-04-10 20:12:0871 canvas->DrawColor(color_, SkXfermode::kSrc_Mode);
[email protected]8d8c7732011-08-25 22:35:1372 }
[email protected]d3f5bbc12012-05-17 00:09:0473 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {}
[email protected]658600e2011-09-07 21:16:2174 virtual void OnWindowDestroying() OVERRIDE {}
75 virtual void OnWindowDestroyed() OVERRIDE {}
[email protected]6fdefb02011-10-11 04:16:1876 virtual void OnWindowVisibilityChanged(bool visible) OVERRIDE {}
[email protected]ec0c94a2012-06-16 05:10:2577 virtual bool HasHitTestMask() const OVERRIDE { return false; }
78 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {}
[email protected]970aa362011-08-30 20:03:3479
[email protected]81585f32011-07-29 19:32:0680 private:
[email protected]b1b155512011-08-18 22:47:5081 SkColor color_;
82
[email protected]81585f32011-07-29 19:32:0683 DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate);
84};
85
[email protected]b370f4f2012-03-12 20:16:2386class DemoStackingClient : public aura::client::StackingClient {
87 public:
88 explicit DemoStackingClient(aura::RootWindow* root_window)
89 : root_window_(root_window) {
90 aura::client::SetStackingClient(this);
91 }
92
93 virtual ~DemoStackingClient() {
94 aura::client::SetStackingClient(NULL);
95 }
96
97 // Overridden from aura::client::StackingClient:
[email protected]20c59762012-06-23 01:10:2498 virtual aura::Window* GetDefaultParent(aura::Window* window,
99 const gfx::Rect& bounds) OVERRIDE {
[email protected]be2a0ac2012-07-24 11:23:22100
101 if (!capture_client_.get()) {
102 capture_client_.reset(
103 new aura::shared::RootWindowCaptureClient(root_window_));
104 }
[email protected]b370f4f2012-03-12 20:16:23105 return root_window_;
106 }
107
108 private:
109 aura::RootWindow* root_window_;
110
[email protected]be2a0ac2012-07-24 11:23:22111 scoped_ptr<aura::shared::RootWindowCaptureClient> capture_client_;
112
[email protected]b370f4f2012-03-12 20:16:23113 DISALLOW_COPY_AND_ASSIGN(DemoStackingClient);
114};
[email protected]81585f32011-07-29 19:32:06115
116} // namespace
117
118int main(int argc, char** argv) {
119 CommandLine::Init(argc, argv);
120
121 // The exit manager is in charge of calling the dtors of singleton objects.
122 base::AtExitManager exit_manager;
123
124 ui::RegisterPathProvider();
125 icu_util::Initialize();
[email protected]fb317a52012-05-09 15:57:47126 ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL);
[email protected]81585f32011-07-29 19:32:06127
[email protected]99f07e02011-12-07 00:02:59128 // Create the message-loop here before creating the root window.
[email protected]905e19a2011-09-07 02:17:53129 MessageLoop message_loop(MessageLoop::TYPE_UI);
[email protected]9783633c2011-10-27 15:41:52130 ui::CompositorTestSupport::Initialize();
[email protected]2e236a52012-06-27 22:21:47131 aura::Env::GetInstance()->SetDisplayManager(new aura::SingleDisplayManager);
[email protected]e050ef142012-03-21 01:04:24132 scoped_ptr<aura::RootWindow> root_window(
[email protected]2e236a52012-06-27 22:21:47133 aura::DisplayManager::CreateRootWindowForPrimaryDisplay());
[email protected]b370f4f2012-03-12 20:16:23134 scoped_ptr<DemoStackingClient> stacking_client(new DemoStackingClient(
135 root_window.get()));
[email protected]81585f32011-07-29 19:32:06136
[email protected]b1b155512011-08-18 22:47:50137 // Create a hierarchy of test windows.
[email protected]8d8c7732011-08-25 22:35:13138 DemoWindowDelegate window_delegate1(SK_ColorBLUE);
139 aura::Window window1(&window_delegate1);
[email protected]b1b155512011-08-18 22:47:50140 window1.set_id(1);
[email protected]595b52a2012-03-23 16:17:24141 window1.Init(ui::LAYER_TEXTURED);
[email protected]7fca53d42011-09-29 15:38:12142 window1.SetBounds(gfx::Rect(100, 100, 400, 400));
[email protected]a3929aba2011-09-30 18:30:17143 window1.Show();
[email protected]8d8c7732011-08-25 22:35:13144 window1.SetParent(NULL);
[email protected]b1b155512011-08-18 22:47:50145
[email protected]8d8c7732011-08-25 22:35:13146 DemoWindowDelegate window_delegate2(SK_ColorRED);
147 aura::Window window2(&window_delegate2);
[email protected]b1b155512011-08-18 22:47:50148 window2.set_id(2);
[email protected]595b52a2012-03-23 16:17:24149 window2.Init(ui::LAYER_TEXTURED);
[email protected]7fca53d42011-09-29 15:38:12150 window2.SetBounds(gfx::Rect(200, 200, 350, 350));
[email protected]a3929aba2011-09-30 18:30:17151 window2.Show();
[email protected]8d8c7732011-08-25 22:35:13152 window2.SetParent(NULL);
[email protected]b1b155512011-08-18 22:47:50153
[email protected]8d8c7732011-08-25 22:35:13154 DemoWindowDelegate window_delegate3(SK_ColorGREEN);
155 aura::Window window3(&window_delegate3);
[email protected]b1b155512011-08-18 22:47:50156 window3.set_id(3);
[email protected]595b52a2012-03-23 16:17:24157 window3.Init(ui::LAYER_TEXTURED);
[email protected]7fca53d42011-09-29 15:38:12158 window3.SetBounds(gfx::Rect(10, 10, 50, 50));
[email protected]a3929aba2011-09-30 18:30:17159 window3.Show();
[email protected]8d8c7732011-08-25 22:35:13160 window3.SetParent(&window2);
[email protected]b1b155512011-08-18 22:47:50161
[email protected]58482fa2012-03-02 14:57:39162 root_window->ShowRootWindow();
[email protected]01c5bab2012-02-25 02:37:43163 MessageLoopForUI::current()->Run();
[email protected]9783633c2011-10-27 15:41:52164
165 ui::CompositorTestSupport::Terminate();
166
[email protected]81585f32011-07-29 19:32:06167 return 0;
168}