[email protected] | 538f956 | 2012-01-17 17:46:04 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 5 | #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] | 59e69e74 | 2013-06-18 20:27:52 | [diff] [blame] | 9 | #include "base/message_loop/message_loop.h" |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 10 | #include "third_party/skia/include/core/SkXfermode.h" |
[email protected] | 48dea15 | 2012-11-02 20:26:46 | [diff] [blame] | 11 | #include "ui/aura/client/default_capture_client.h" |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 12 | #include "ui/aura/client/window_tree_client.h" |
[email protected] | e050ef14 | 2012-03-21 01:04:24 | [diff] [blame] | 13 | #include "ui/aura/env.h" |
[email protected] | f0e90a4 | 2012-03-13 23:05:57 | [diff] [blame] | 14 | #include "ui/aura/root_window.h" |
[email protected] | 98096954 | 2013-10-18 22:07:34 | [diff] [blame] | 15 | #include "ui/aura/test/test_focus_client.h" |
[email protected] | 6bdf795 | 2012-11-14 10:10:58 | [diff] [blame] | 16 | #include "ui/aura/test/test_screen.h" |
[email protected] | dbf3d40 | 2011-09-14 21:32:16 | [diff] [blame] | 17 | #include "ui/aura/window.h" |
| 18 | #include "ui/aura/window_delegate.h" |
[email protected] | 912be0e | 2011-11-09 19:05:24 | [diff] [blame] | 19 | #include "ui/base/hit_test.h" |
[email protected] | f633394 | 2013-10-30 17:32:55 | [diff] [blame] | 20 | #include "ui/compositor/test/context_factories_for_test.h" |
[email protected] | 86ccbd4 | 2013-09-18 18:11:54 | [diff] [blame] | 21 | #include "ui/events/event.h" |
[email protected] | 94a0d258 | 2012-03-09 00:30:59 | [diff] [blame] | 22 | #include "ui/gfx/canvas.h" |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 23 | #include "ui/gfx/rect.h" |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 24 | |
[email protected] | 4a6bef3 | 2011-09-07 02:06:01 | [diff] [blame] | 25 | #if defined(USE_X11) |
[email protected] | bb99d70 | 2013-09-07 03:21:04 | [diff] [blame] | 26 | #include "base/message_loop/message_pump_x11.h" |
[email protected] | 4a6bef3 | 2011-09-07 02:06:01 | [diff] [blame] | 27 | #endif |
| 28 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 29 | namespace { |
| 30 | |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 31 | // Trivial WindowDelegate implementation that draws a colored background. |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 32 | class DemoWindowDelegate : public aura::WindowDelegate { |
| 33 | public: |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 34 | explicit DemoWindowDelegate(SkColor color) : color_(color) {} |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 35 | |
[email protected] | 8dd791d | 2011-09-16 16:37:30 | [diff] [blame] | 36 | // Overridden from WindowDelegate: |
[email protected] | 17a6cb95 | 2011-11-22 23:04:38 | [diff] [blame] | 37 | virtual gfx::Size GetMinimumSize() const OVERRIDE { |
| 38 | return gfx::Size(); |
| 39 | } |
[email protected] | fa574b6 | 2012-11-26 04:11:38 | [diff] [blame] | 40 | |
| 41 | virtual gfx::Size GetMaximumSize() const OVERRIDE { |
| 42 | return gfx::Size(); |
| 43 | } |
| 44 | |
[email protected] | 8dd791d | 2011-09-16 16:37:30 | [diff] [blame] | 45 | virtual void OnBoundsChanged(const gfx::Rect& old_bounds, |
| 46 | const gfx::Rect& new_bounds) OVERRIDE {} |
[email protected] | 0207c92d | 2011-10-04 14:45:07 | [diff] [blame] | 47 | virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE { |
[email protected] | 9e591cb | 2011-10-17 18:14:32 | [diff] [blame] | 48 | return gfx::kNullCursor; |
[email protected] | 0207c92d | 2011-10-04 14:45:07 | [diff] [blame] | 49 | } |
[email protected] | eaf6dd5 | 2011-09-02 00:39:26 | [diff] [blame] | 50 | virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { |
| 51 | return HTCAPTION; |
| 52 | } |
[email protected] | 334b8189 | 2012-06-16 16:38:14 | [diff] [blame] | 53 | virtual bool ShouldDescendIntoChildForEventHandling( |
| 54 | aura::Window* child, |
| 55 | const gfx::Point& location) OVERRIDE { |
| 56 | return true; |
| 57 | } |
[email protected] | a8bb9670 | 2011-12-03 22:17:40 | [diff] [blame] | 58 | virtual bool CanFocus() OVERRIDE { return true; } |
[email protected] | 70ccf70 | 2011-09-22 18:15:58 | [diff] [blame] | 59 | virtual void OnCaptureLost() OVERRIDE {} |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 60 | virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
[email protected] | 6fae797 | 2012-04-10 20:12:08 | [diff] [blame] | 61 | canvas->DrawColor(color_, SkXfermode::kSrc_Mode); |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 62 | } |
[email protected] | d3f5bbc1 | 2012-05-17 00:09:04 | [diff] [blame] | 63 | virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {} |
[email protected] | 658600e | 2011-09-07 21:16:21 | [diff] [blame] | 64 | virtual void OnWindowDestroying() OVERRIDE {} |
| 65 | virtual void OnWindowDestroyed() OVERRIDE {} |
[email protected] | ab8f86b | 2012-07-30 14:38:50 | [diff] [blame] | 66 | virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {} |
[email protected] | ec0c94a | 2012-06-16 05:10:25 | [diff] [blame] | 67 | virtual bool HasHitTestMask() const OVERRIDE { return false; } |
| 68 | virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {} |
[email protected] | 1ddbe93 | 2013-09-12 06:23:16 | [diff] [blame] | 69 | virtual void DidRecreateLayer(ui::Layer* old_layer, |
| 70 | ui::Layer* new_layer) OVERRIDE {} |
[email protected] | 970aa36 | 2011-08-30 20:03:34 | [diff] [blame] | 71 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 72 | private: |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 73 | SkColor color_; |
| 74 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 75 | DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate); |
| 76 | }; |
| 77 | |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 78 | class DemoWindowTreeClient : public aura::client::WindowTreeClient { |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 79 | public: |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 80 | explicit DemoWindowTreeClient(aura::Window* window) : window_(window) { |
| 81 | aura::client::SetWindowTreeClient(window_, this); |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 82 | } |
| 83 | |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 84 | virtual ~DemoWindowTreeClient() { |
| 85 | aura::client::SetWindowTreeClient(window_, NULL); |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 86 | } |
| 87 | |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 88 | // Overridden from aura::client::WindowTreeClient: |
[email protected] | d8f1004 | 2012-11-14 01:10:46 | [diff] [blame] | 89 | virtual aura::Window* GetDefaultParent(aura::Window* context, |
| 90 | aura::Window* window, |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 91 | const gfx::Rect& bounds) OVERRIDE { |
[email protected] | 363e754 | 2013-04-23 22:33:14 | [diff] [blame] | 92 | if (!capture_client_) { |
[email protected] | be2a0ac | 2012-07-24 11:23:22 | [diff] [blame] | 93 | capture_client_.reset( |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 94 | new aura::client::DefaultCaptureClient(window_->GetRootWindow())); |
[email protected] | be2a0ac | 2012-07-24 11:23:22 | [diff] [blame] | 95 | } |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 96 | return window_; |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | private: |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 100 | aura::Window* window_; |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 101 | |
[email protected] | 48dea15 | 2012-11-02 20:26:46 | [diff] [blame] | 102 | scoped_ptr<aura::client::DefaultCaptureClient> capture_client_; |
[email protected] | be2a0ac | 2012-07-24 11:23:22 | [diff] [blame] | 103 | |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 104 | DISALLOW_COPY_AND_ASSIGN(DemoWindowTreeClient); |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 105 | }; |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 106 | |
[email protected] | f7a0b4d2 | 2012-09-18 16:31:01 | [diff] [blame] | 107 | int DemoMain() { |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 108 | // Create the message-loop here before creating the root window. |
[email protected] | 166f2ed | 2013-12-19 19:34:00 | [diff] [blame] | 109 | base::MessageLoopForUI message_loop; |
[email protected] | f321f80b | 2013-09-11 22:59:14 | [diff] [blame] | 110 | |
| 111 | // The ContextFactory must exist before any Compositors are created. |
| 112 | bool allow_test_contexts = false; |
[email protected] | f633394 | 2013-10-30 17:32:55 | [diff] [blame] | 113 | ui::InitializeContextFactoryForTests(allow_test_contexts); |
[email protected] | f321f80b | 2013-09-11 22:59:14 | [diff] [blame] | 114 | |
[email protected] | ecca62b | 2013-10-09 16:18:53 | [diff] [blame] | 115 | aura::Env::CreateInstance(); |
[email protected] | 2ad669a | 2013-02-15 04:36:56 | [diff] [blame] | 116 | scoped_ptr<aura::TestScreen> test_screen(aura::TestScreen::Create()); |
| 117 | gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen.get()); |
[email protected] | e050ef14 | 2012-03-21 01:04:24 | [diff] [blame] | 118 | scoped_ptr<aura::RootWindow> root_window( |
[email protected] | 2ad669a | 2013-02-15 04:36:56 | [diff] [blame] | 119 | test_screen->CreateRootWindowForPrimaryDisplay()); |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 120 | scoped_ptr<DemoWindowTreeClient> window_tree_client(new DemoWindowTreeClient( |
[email protected] | 688c225e | 2013-11-10 06:16:08 | [diff] [blame] | 121 | root_window->window())); |
[email protected] | 98096954 | 2013-10-18 22:07:34 | [diff] [blame] | 122 | aura::test::TestFocusClient focus_client; |
[email protected] | 688c225e | 2013-11-10 06:16:08 | [diff] [blame] | 123 | aura::client::SetFocusClient(root_window->window(), &focus_client); |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 124 | |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 125 | // Create a hierarchy of test windows. |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 126 | DemoWindowDelegate window_delegate1(SK_ColorBLUE); |
| 127 | aura::Window window1(&window_delegate1); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 128 | window1.set_id(1); |
[email protected] | 52b02a7 | 2014-01-08 21:41:50 | [diff] [blame^] | 129 | window1.Init(aura::WINDOW_LAYER_TEXTURED); |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 130 | window1.SetBounds(gfx::Rect(100, 100, 400, 400)); |
[email protected] | a3929aba | 2011-09-30 18:30:17 | [diff] [blame] | 131 | window1.Show(); |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 132 | aura::client::ParentWindowWithContext( |
[email protected] | 688c225e | 2013-11-10 06:16:08 | [diff] [blame] | 133 | &window1, root_window->window(), gfx::Rect()); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 134 | |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 135 | DemoWindowDelegate window_delegate2(SK_ColorRED); |
| 136 | aura::Window window2(&window_delegate2); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 137 | window2.set_id(2); |
[email protected] | 52b02a7 | 2014-01-08 21:41:50 | [diff] [blame^] | 138 | window2.Init(aura::WINDOW_LAYER_TEXTURED); |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 139 | window2.SetBounds(gfx::Rect(200, 200, 350, 350)); |
[email protected] | a3929aba | 2011-09-30 18:30:17 | [diff] [blame] | 140 | window2.Show(); |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 141 | aura::client::ParentWindowWithContext( |
[email protected] | 688c225e | 2013-11-10 06:16:08 | [diff] [blame] | 142 | &window2, root_window->window(), gfx::Rect()); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 143 | |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 144 | DemoWindowDelegate window_delegate3(SK_ColorGREEN); |
| 145 | aura::Window window3(&window_delegate3); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 146 | window3.set_id(3); |
[email protected] | 52b02a7 | 2014-01-08 21:41:50 | [diff] [blame^] | 147 | window3.Init(aura::WINDOW_LAYER_TEXTURED); |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 148 | window3.SetBounds(gfx::Rect(10, 10, 50, 50)); |
[email protected] | a3929aba | 2011-09-30 18:30:17 | [diff] [blame] | 149 | window3.Show(); |
[email protected] | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 150 | window2.AddChild(&window3); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 151 | |
[email protected] | 228f0f0 | 2013-11-15 05:58:36 | [diff] [blame] | 152 | root_window->host()->Show(); |
[email protected] | 7060d659 | 2013-04-29 19:01:48 | [diff] [blame] | 153 | base::MessageLoopForUI::current()->Run(); |
[email protected] | 9783633c | 2011-10-27 15:41:52 | [diff] [blame] | 154 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 155 | return 0; |
| 156 | } |
[email protected] | f7a0b4d2 | 2012-09-18 16:31:01 | [diff] [blame] | 157 | |
[email protected] | f7a0b4d2 | 2012-09-18 16:31:01 | [diff] [blame] | 158 | } // namespace |
| 159 | |
| 160 | int 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] | d7477f0 | 2013-08-23 00:39:09 | [diff] [blame] | 166 | base::i18n::InitializeICU(); |
[email protected] | f7a0b4d2 | 2012-09-18 16:31:01 | [diff] [blame] | 167 | |
[email protected] | 56deede | 2012-10-01 21:25:12 | [diff] [blame] | 168 | return DemoMain(); |
[email protected] | f7a0b4d2 | 2012-09-18 16:31:01 | [diff] [blame] | 169 | } |