blob: 3dcd7db3b0244853a2b49fed71d4c61b74c6cbf1 [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]e3225e02013-10-23 20:44:3712#include "ui/aura/client/window_tree_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]f6333942013-10-30 17:32:5520#include "ui/compositor/test/context_factories_for_test.h"
[email protected]86ccbd42013-09-18 18:11:5421#include "ui/events/event.h"
[email protected]94a0d2582012-03-09 00:30:5922#include "ui/gfx/canvas.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]bb99d702013-09-07 03:21:0426#include "base/message_loop/message_pump_x11.h"
[email protected]4a6bef32011-09-07 02:06:0127#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]fa574b62012-11-26 04:11:3840
41 virtual gfx::Size GetMaximumSize() const OVERRIDE {
42 return gfx::Size();
43 }
44
[email protected]8dd791d2011-09-16 16:37:3045 virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
46 const gfx::Rect& new_bounds) OVERRIDE {}
[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]334b81892012-06-16 16:38:1453 virtual bool ShouldDescendIntoChildForEventHandling(
54 aura::Window* child,
55 const gfx::Point& location) OVERRIDE {
56 return true;
57 }
[email protected]a8bb96702011-12-03 22:17:4058 virtual bool CanFocus() OVERRIDE { return true; }
[email protected]70ccf702011-09-22 18:15:5859 virtual void OnCaptureLost() OVERRIDE {}
[email protected]8d8c7732011-08-25 22:35:1360 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
[email protected]6fae7972012-04-10 20:12:0861 canvas->DrawColor(color_, SkXfermode::kSrc_Mode);
[email protected]8d8c7732011-08-25 22:35:1362 }
[email protected]d3f5bbc12012-05-17 00:09:0463 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {}
[email protected]658600e2011-09-07 21:16:2164 virtual void OnWindowDestroying() OVERRIDE {}
65 virtual void OnWindowDestroyed() OVERRIDE {}
[email protected]ab8f86b2012-07-30 14:38:5066 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {}
[email protected]ec0c94a2012-06-16 05:10:2567 virtual bool HasHitTestMask() const OVERRIDE { return false; }
68 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {}
[email protected]1ddbe932013-09-12 06:23:1669 virtual void DidRecreateLayer(ui::Layer* old_layer,
70 ui::Layer* new_layer) OVERRIDE {}
[email protected]970aa362011-08-30 20:03:3471
[email protected]81585f32011-07-29 19:32:0672 private:
[email protected]b1b155512011-08-18 22:47:5073 SkColor color_;
74
[email protected]81585f32011-07-29 19:32:0675 DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate);
76};
77
[email protected]e3225e02013-10-23 20:44:3778class DemoWindowTreeClient : public aura::client::WindowTreeClient {
[email protected]b370f4f2012-03-12 20:16:2379 public:
[email protected]e3225e02013-10-23 20:44:3780 explicit DemoWindowTreeClient(aura::Window* window) : window_(window) {
81 aura::client::SetWindowTreeClient(window_, this);
[email protected]b370f4f2012-03-12 20:16:2382 }
83
[email protected]e3225e02013-10-23 20:44:3784 virtual ~DemoWindowTreeClient() {
85 aura::client::SetWindowTreeClient(window_, NULL);
[email protected]b370f4f2012-03-12 20:16:2386 }
87
[email protected]e3225e02013-10-23 20:44:3788 // Overridden from aura::client::WindowTreeClient:
[email protected]d8f10042012-11-14 01:10:4689 virtual aura::Window* GetDefaultParent(aura::Window* context,
90 aura::Window* window,
[email protected]20c59762012-06-23 01:10:2491 const gfx::Rect& bounds) OVERRIDE {
[email protected]363e7542013-04-23 22:33:1492 if (!capture_client_) {
[email protected]be2a0ac2012-07-24 11:23:2293 capture_client_.reset(
[email protected]e3225e02013-10-23 20:44:3794 new aura::client::DefaultCaptureClient(window_->GetRootWindow()));
[email protected]be2a0ac2012-07-24 11:23:2295 }
[email protected]e3225e02013-10-23 20:44:3796 return window_;
[email protected]b370f4f2012-03-12 20:16:2397 }
98
99 private:
[email protected]e3225e02013-10-23 20:44:37100 aura::Window* window_;
[email protected]b370f4f2012-03-12 20:16:23101
[email protected]48dea152012-11-02 20:26:46102 scoped_ptr<aura::client::DefaultCaptureClient> capture_client_;
[email protected]be2a0ac2012-07-24 11:23:22103
[email protected]e3225e02013-10-23 20:44:37104 DISALLOW_COPY_AND_ASSIGN(DemoWindowTreeClient);
[email protected]b370f4f2012-03-12 20:16:23105};
[email protected]81585f32011-07-29 19:32:06106
[email protected]f7a0b4d22012-09-18 16:31:01107int DemoMain() {
[email protected]99f07e02011-12-07 00:02:59108 // Create the message-loop here before creating the root window.
[email protected]166f2ed2013-12-19 19:34:00109 base::MessageLoopForUI message_loop;
[email protected]f321f80b2013-09-11 22:59:14110
111 // The ContextFactory must exist before any Compositors are created.
112 bool allow_test_contexts = false;
[email protected]f6333942013-10-30 17:32:55113 ui::InitializeContextFactoryForTests(allow_test_contexts);
[email protected]f321f80b2013-09-11 22:59:14114
[email protected]ecca62b2013-10-09 16:18:53115 aura::Env::CreateInstance();
[email protected]2ad669a2013-02-15 04:36:56116 scoped_ptr<aura::TestScreen> test_screen(aura::TestScreen::Create());
117 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen.get());
[email protected]e050ef142012-03-21 01:04:24118 scoped_ptr<aura::RootWindow> root_window(
[email protected]2ad669a2013-02-15 04:36:56119 test_screen->CreateRootWindowForPrimaryDisplay());
[email protected]e3225e02013-10-23 20:44:37120 scoped_ptr<DemoWindowTreeClient> window_tree_client(new DemoWindowTreeClient(
[email protected]688c225e2013-11-10 06:16:08121 root_window->window()));
[email protected]980969542013-10-18 22:07:34122 aura::test::TestFocusClient focus_client;
[email protected]688c225e2013-11-10 06:16:08123 aura::client::SetFocusClient(root_window->window(), &focus_client);
[email protected]81585f32011-07-29 19:32:06124
[email protected]b1b155512011-08-18 22:47:50125 // Create a hierarchy of test windows.
[email protected]8d8c7732011-08-25 22:35:13126 DemoWindowDelegate window_delegate1(SK_ColorBLUE);
127 aura::Window window1(&window_delegate1);
[email protected]b1b155512011-08-18 22:47:50128 window1.set_id(1);
[email protected]52b02a72014-01-08 21:41:50129 window1.Init(aura::WINDOW_LAYER_TEXTURED);
[email protected]7fca53d42011-09-29 15:38:12130 window1.SetBounds(gfx::Rect(100, 100, 400, 400));
[email protected]a3929aba2011-09-30 18:30:17131 window1.Show();
[email protected]e3225e02013-10-23 20:44:37132 aura::client::ParentWindowWithContext(
[email protected]688c225e2013-11-10 06:16:08133 &window1, root_window->window(), gfx::Rect());
[email protected]b1b155512011-08-18 22:47:50134
[email protected]8d8c7732011-08-25 22:35:13135 DemoWindowDelegate window_delegate2(SK_ColorRED);
136 aura::Window window2(&window_delegate2);
[email protected]b1b155512011-08-18 22:47:50137 window2.set_id(2);
[email protected]52b02a72014-01-08 21:41:50138 window2.Init(aura::WINDOW_LAYER_TEXTURED);
[email protected]7fca53d42011-09-29 15:38:12139 window2.SetBounds(gfx::Rect(200, 200, 350, 350));
[email protected]a3929aba2011-09-30 18:30:17140 window2.Show();
[email protected]e3225e02013-10-23 20:44:37141 aura::client::ParentWindowWithContext(
[email protected]688c225e2013-11-10 06:16:08142 &window2, root_window->window(), gfx::Rect());
[email protected]b1b155512011-08-18 22:47:50143
[email protected]8d8c7732011-08-25 22:35:13144 DemoWindowDelegate window_delegate3(SK_ColorGREEN);
145 aura::Window window3(&window_delegate3);
[email protected]b1b155512011-08-18 22:47:50146 window3.set_id(3);
[email protected]52b02a72014-01-08 21:41:50147 window3.Init(aura::WINDOW_LAYER_TEXTURED);
[email protected]7fca53d42011-09-29 15:38:12148 window3.SetBounds(gfx::Rect(10, 10, 50, 50));
[email protected]a3929aba2011-09-30 18:30:17149 window3.Show();
[email protected]5ebe6102012-11-28 21:00:03150 window2.AddChild(&window3);
[email protected]b1b155512011-08-18 22:47:50151
[email protected]228f0f02013-11-15 05:58:36152 root_window->host()->Show();
[email protected]7060d6592013-04-29 19:01:48153 base::MessageLoopForUI::current()->Run();
[email protected]9783633c2011-10-27 15:41:52154
[email protected]81585f32011-07-29 19:32:06155 return 0;
156}
[email protected]f7a0b4d22012-09-18 16:31:01157
[email protected]f7a0b4d22012-09-18 16:31:01158} // namespace
159
160int main(int argc, char** argv) {
161 CommandLine::Init(argc, argv);
162
163 // The exit manager is in charge of calling the dtors of singleton objects.
164 base::AtExitManager exit_manager;
165
[email protected]d7477f02013-08-23 00:39:09166 base::i18n::InitializeICU();
[email protected]f7a0b4d22012-09-18 16:31:01167
[email protected]56deede2012-10-01 21:25:12168 return DemoMain();
[email protected]f7a0b4d22012-09-18 16:31:01169}