blob: abdd514c95eb37804be924b957d070e9e2b4c284 [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]59e69e742013-06-18 20:27:529#include "base/message_loop/message_loop.h"
[email protected]81585f32011-07-29 19:32:0610#include "third_party/skia/include/core/SkXfermode.h"
[email protected]48dea152012-11-02 20:26:4611#include "ui/aura/client/default_capture_client.h"
[email protected]b370f4f2012-03-12 20:16:2312#include "ui/aura/client/stacking_client.h"
[email protected]e050ef142012-03-21 01:04:2413#include "ui/aura/env.h"
[email protected]f0e90a42012-03-13 23:05:5714#include "ui/aura/root_window.h"
[email protected]980969542013-10-18 22:07:3415#include "ui/aura/test/test_focus_client.h"
[email protected]6bdf7952012-11-14 10:10:5816#include "ui/aura/test/test_screen.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]f321f80b2013-09-11 22:59:1422#include "ui/compositor/compositor.h"
[email protected]86ccbd42013-09-18 18:11:5423#include "ui/events/event.h"
[email protected]94a0d2582012-03-09 00:30:5924#include "ui/gfx/canvas.h"
[email protected]81585f32011-07-29 19:32:0625#include "ui/gfx/rect.h"
[email protected]81585f32011-07-29 19:32:0626
[email protected]4a6bef32011-09-07 02:06:0127#if defined(USE_X11)
[email protected]bb99d702013-09-07 03:21:0428#include "base/message_loop/message_pump_x11.h"
[email protected]4a6bef32011-09-07 02:06:0129#endif
30
[email protected]81585f32011-07-29 19:32:0631namespace {
32
[email protected]8d8c7732011-08-25 22:35:1333// Trivial WindowDelegate implementation that draws a colored background.
[email protected]81585f32011-07-29 19:32:0634class DemoWindowDelegate : public aura::WindowDelegate {
35 public:
[email protected]8d8c7732011-08-25 22:35:1336 explicit DemoWindowDelegate(SkColor color) : color_(color) {}
[email protected]81585f32011-07-29 19:32:0637
[email protected]8dd791d2011-09-16 16:37:3038 // Overridden from WindowDelegate:
[email protected]17a6cb952011-11-22 23:04:3839 virtual gfx::Size GetMinimumSize() const OVERRIDE {
40 return gfx::Size();
41 }
[email protected]fa574b62012-11-26 04:11:3842
43 virtual gfx::Size GetMaximumSize() const OVERRIDE {
44 return gfx::Size();
45 }
46
[email protected]8dd791d2011-09-16 16:37:3047 virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
48 const gfx::Rect& new_bounds) OVERRIDE {}
[email protected]0207c92d2011-10-04 14:45:0749 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
[email protected]9e591cb2011-10-17 18:14:3250 return gfx::kNullCursor;
[email protected]0207c92d2011-10-04 14:45:0751 }
[email protected]eaf6dd52011-09-02 00:39:2652 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE {
53 return HTCAPTION;
54 }
[email protected]334b81892012-06-16 16:38:1455 virtual bool ShouldDescendIntoChildForEventHandling(
56 aura::Window* child,
57 const gfx::Point& location) OVERRIDE {
58 return true;
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]6fae7972012-04-10 20:12:0863 canvas->DrawColor(color_, SkXfermode::kSrc_Mode);
[email protected]8d8c7732011-08-25 22:35:1364 }
[email protected]d3f5bbc12012-05-17 00:09:0465 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {}
[email protected]658600e2011-09-07 21:16:2166 virtual void OnWindowDestroying() OVERRIDE {}
67 virtual void OnWindowDestroyed() OVERRIDE {}
[email protected]ab8f86b2012-07-30 14:38:5068 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {}
[email protected]ec0c94a2012-06-16 05:10:2569 virtual bool HasHitTestMask() const OVERRIDE { return false; }
70 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {}
[email protected]1ddbe932013-09-12 06:23:1671 virtual void DidRecreateLayer(ui::Layer* old_layer,
72 ui::Layer* new_layer) OVERRIDE {}
[email protected]970aa362011-08-30 20:03:3473
[email protected]81585f32011-07-29 19:32:0674 private:
[email protected]b1b155512011-08-18 22:47:5075 SkColor color_;
76
[email protected]81585f32011-07-29 19:32:0677 DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate);
78};
79
[email protected]b370f4f2012-03-12 20:16:2380class DemoStackingClient : public aura::client::StackingClient {
81 public:
82 explicit DemoStackingClient(aura::RootWindow* root_window)
83 : root_window_(root_window) {
[email protected]2a2caa02013-01-22 20:50:3684 aura::client::SetStackingClient(root_window_, this);
[email protected]b370f4f2012-03-12 20:16:2385 }
86
87 virtual ~DemoStackingClient() {
[email protected]2a2caa02013-01-22 20:50:3688 aura::client::SetStackingClient(root_window_, NULL);
[email protected]b370f4f2012-03-12 20:16:2389 }
90
91 // Overridden from aura::client::StackingClient:
[email protected]d8f10042012-11-14 01:10:4692 virtual aura::Window* GetDefaultParent(aura::Window* context,
93 aura::Window* window,
[email protected]20c59762012-06-23 01:10:2494 const gfx::Rect& bounds) OVERRIDE {
[email protected]363e7542013-04-23 22:33:1495 if (!capture_client_) {
[email protected]be2a0ac2012-07-24 11:23:2296 capture_client_.reset(
[email protected]48dea152012-11-02 20:26:4697 new aura::client::DefaultCaptureClient(root_window_));
[email protected]be2a0ac2012-07-24 11:23:2298 }
[email protected]b370f4f2012-03-12 20:16:2399 return root_window_;
100 }
101
102 private:
103 aura::RootWindow* root_window_;
104
[email protected]48dea152012-11-02 20:26:46105 scoped_ptr<aura::client::DefaultCaptureClient> capture_client_;
[email protected]be2a0ac2012-07-24 11:23:22106
[email protected]b370f4f2012-03-12 20:16:23107 DISALLOW_COPY_AND_ASSIGN(DemoStackingClient);
108};
[email protected]81585f32011-07-29 19:32:06109
[email protected]f7a0b4d22012-09-18 16:31:01110int DemoMain() {
[email protected]99f07e02011-12-07 00:02:59111 // Create the message-loop here before creating the root window.
[email protected]7060d6592013-04-29 19:01:48112 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI);
[email protected]f321f80b2013-09-11 22:59:14113
114 // The ContextFactory must exist before any Compositors are created.
115 bool allow_test_contexts = false;
116 ui::Compositor::InitializeContextFactoryForTests(allow_test_contexts);
117
[email protected]ecca62b2013-10-09 16:18:53118 aura::Env::CreateInstance();
[email protected]2ad669a2013-02-15 04:36:56119 scoped_ptr<aura::TestScreen> test_screen(aura::TestScreen::Create());
120 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen.get());
[email protected]e050ef142012-03-21 01:04:24121 scoped_ptr<aura::RootWindow> root_window(
[email protected]2ad669a2013-02-15 04:36:56122 test_screen->CreateRootWindowForPrimaryDisplay());
[email protected]b370f4f2012-03-12 20:16:23123 scoped_ptr<DemoStackingClient> stacking_client(new DemoStackingClient(
124 root_window.get()));
[email protected]980969542013-10-18 22:07:34125 aura::test::TestFocusClient focus_client;
126 aura::client::SetFocusClient(root_window.get(), &focus_client);
[email protected]81585f32011-07-29 19:32:06127
[email protected]b1b155512011-08-18 22:47:50128 // Create a hierarchy of test windows.
[email protected]8d8c7732011-08-25 22:35:13129 DemoWindowDelegate window_delegate1(SK_ColorBLUE);
130 aura::Window window1(&window_delegate1);
[email protected]b1b155512011-08-18 22:47:50131 window1.set_id(1);
[email protected]595b52a2012-03-23 16:17:24132 window1.Init(ui::LAYER_TEXTURED);
[email protected]7fca53d42011-09-29 15:38:12133 window1.SetBounds(gfx::Rect(100, 100, 400, 400));
[email protected]a3929aba2011-09-30 18:30:17134 window1.Show();
[email protected]5ebe6102012-11-28 21:00:03135 window1.SetDefaultParentByRootWindow(root_window.get(), gfx::Rect());
[email protected]b1b155512011-08-18 22:47:50136
[email protected]8d8c7732011-08-25 22:35:13137 DemoWindowDelegate window_delegate2(SK_ColorRED);
138 aura::Window window2(&window_delegate2);
[email protected]b1b155512011-08-18 22:47:50139 window2.set_id(2);
[email protected]595b52a2012-03-23 16:17:24140 window2.Init(ui::LAYER_TEXTURED);
[email protected]7fca53d42011-09-29 15:38:12141 window2.SetBounds(gfx::Rect(200, 200, 350, 350));
[email protected]a3929aba2011-09-30 18:30:17142 window2.Show();
[email protected]5ebe6102012-11-28 21:00:03143 window2.SetDefaultParentByRootWindow(root_window.get(), gfx::Rect());
[email protected]b1b155512011-08-18 22:47:50144
[email protected]8d8c7732011-08-25 22:35:13145 DemoWindowDelegate window_delegate3(SK_ColorGREEN);
146 aura::Window window3(&window_delegate3);
[email protected]b1b155512011-08-18 22:47:50147 window3.set_id(3);
[email protected]595b52a2012-03-23 16:17:24148 window3.Init(ui::LAYER_TEXTURED);
[email protected]7fca53d42011-09-29 15:38:12149 window3.SetBounds(gfx::Rect(10, 10, 50, 50));
[email protected]a3929aba2011-09-30 18:30:17150 window3.Show();
[email protected]5ebe6102012-11-28 21:00:03151 window2.AddChild(&window3);
[email protected]b1b155512011-08-18 22:47:50152
[email protected]58482fa2012-03-02 14:57:39153 root_window->ShowRootWindow();
[email protected]7060d6592013-04-29 19:01:48154 base::MessageLoopForUI::current()->Run();
[email protected]9783633c2011-10-27 15:41:52155
[email protected]81585f32011-07-29 19:32:06156 return 0;
157}
[email protected]f7a0b4d22012-09-18 16:31:01158
[email protected]f7a0b4d22012-09-18 16:31:01159} // namespace
160
161int main(int argc, char** argv) {
162 CommandLine::Init(argc, argv);
163
164 // The exit manager is in charge of calling the dtors of singleton objects.
165 base::AtExitManager exit_manager;
166
167 ui::RegisterPathProvider();
[email protected]d7477f02013-08-23 00:39:09168 base::i18n::InitializeICU();
[email protected]f7a0b4d22012-09-18 16:31:01169 ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL);
170
[email protected]56deede2012-10-01 21:25:12171 return DemoMain();
[email protected]f7a0b4d22012-09-18 16:31:01172}