[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] | 98096954 | 2013-10-18 22:07:34 | [diff] [blame] | 14 | #include "ui/aura/test/test_focus_client.h" |
[email protected] | 6bdf795 | 2012-11-14 10:10:58 | [diff] [blame] | 15 | #include "ui/aura/test/test_screen.h" |
[email protected] | dbf3d40 | 2011-09-14 21:32:16 | [diff] [blame] | 16 | #include "ui/aura/window.h" |
| 17 | #include "ui/aura/window_delegate.h" |
[email protected] | 2f262033 | 2014-02-28 10:07:38 | [diff] [blame] | 18 | #include "ui/aura/window_tree_host.h" |
[email protected] | 912be0e | 2011-11-09 19:05:24 | [diff] [blame] | 19 | #include "ui/base/hit_test.h" |
[email protected] | 27a80e75 | 2014-03-13 20:36:41 | [diff] [blame] | 20 | #include "ui/compositor/test/in_process_context_factory.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] | af7c5d9 | 2014-02-03 19:53:15 | [diff] [blame] | 24 | #include "ui/gl/gl_surface.h" |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 25 | |
[email protected] | 4a6bef3 | 2011-09-07 02:06:01 | [diff] [blame] | 26 | #if defined(USE_X11) |
[email protected] | 82f884d6ffb | 2014-04-15 03:34:54 | [diff] [blame] | 27 | #include "ui/gfx/x/x11_connection.h" |
[email protected] | 4a6bef3 | 2011-09-07 02:06:01 | [diff] [blame] | 28 | #endif |
| 29 | |
[email protected] | 804f479 | 2014-04-22 22:54:37 | [diff] [blame] | 30 | #if defined(OS_WIN) |
| 31 | #include "ui/gfx/win/dpi.h" |
| 32 | #endif |
| 33 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 34 | namespace { |
| 35 | |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 36 | // Trivial WindowDelegate implementation that draws a colored background. |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 37 | class DemoWindowDelegate : public aura::WindowDelegate { |
| 38 | public: |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 39 | explicit DemoWindowDelegate(SkColor color) : color_(color) {} |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 40 | |
[email protected] | 8dd791d | 2011-09-16 16:37:30 | [diff] [blame] | 41 | // Overridden from WindowDelegate: |
[email protected] | 17a6cb95 | 2011-11-22 23:04:38 | [diff] [blame] | 42 | virtual gfx::Size GetMinimumSize() const OVERRIDE { |
| 43 | return gfx::Size(); |
| 44 | } |
[email protected] | fa574b6 | 2012-11-26 04:11:38 | [diff] [blame] | 45 | |
| 46 | virtual gfx::Size GetMaximumSize() const OVERRIDE { |
| 47 | return gfx::Size(); |
| 48 | } |
| 49 | |
[email protected] | 8dd791d | 2011-09-16 16:37:30 | [diff] [blame] | 50 | virtual void OnBoundsChanged(const gfx::Rect& old_bounds, |
| 51 | const gfx::Rect& new_bounds) OVERRIDE {} |
[email protected] | 62c9f10 | 2014-03-27 06:07:04 | [diff] [blame] | 52 | virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE { |
| 53 | return gfx::kNullCursor; |
| 54 | } |
[email protected] | eaf6dd5 | 2011-09-02 00:39:26 | [diff] [blame] | 55 | virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { |
| 56 | return HTCAPTION; |
| 57 | } |
[email protected] | 334b8189 | 2012-06-16 16:38:14 | [diff] [blame] | 58 | virtual bool ShouldDescendIntoChildForEventHandling( |
| 59 | aura::Window* child, |
| 60 | const gfx::Point& location) OVERRIDE { |
| 61 | return true; |
| 62 | } |
[email protected] | a8bb9670 | 2011-12-03 22:17:40 | [diff] [blame] | 63 | virtual bool CanFocus() OVERRIDE { return true; } |
[email protected] | 70ccf70 | 2011-09-22 18:15:58 | [diff] [blame] | 64 | virtual void OnCaptureLost() OVERRIDE {} |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 65 | virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
[email protected] | 6fae797 | 2012-04-10 20:12:08 | [diff] [blame] | 66 | canvas->DrawColor(color_, SkXfermode::kSrc_Mode); |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 67 | } |
[email protected] | d3f5bbc1 | 2012-05-17 00:09:04 | [diff] [blame] | 68 | virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {} |
[email protected] | 48f36d9 | 2014-02-28 00:11:37 | [diff] [blame] | 69 | virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {} |
| 70 | virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE {} |
[email protected] | ab8f86b | 2012-07-30 14:38:50 | [diff] [blame] | 71 | virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {} |
[email protected] | ec0c94a | 2012-06-16 05:10:25 | [diff] [blame] | 72 | virtual bool HasHitTestMask() const OVERRIDE { return false; } |
| 73 | virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {} |
[email protected] | 970aa36 | 2011-08-30 20:03:34 | [diff] [blame] | 74 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 75 | private: |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 76 | SkColor color_; |
| 77 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 78 | DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate); |
| 79 | }; |
| 80 | |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 81 | class DemoWindowTreeClient : public aura::client::WindowTreeClient { |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 82 | public: |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 83 | explicit DemoWindowTreeClient(aura::Window* window) : window_(window) { |
| 84 | aura::client::SetWindowTreeClient(window_, this); |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 85 | } |
| 86 | |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 87 | virtual ~DemoWindowTreeClient() { |
| 88 | aura::client::SetWindowTreeClient(window_, NULL); |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 89 | } |
| 90 | |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 91 | // Overridden from aura::client::WindowTreeClient: |
[email protected] | d8f1004 | 2012-11-14 01:10:46 | [diff] [blame] | 92 | virtual aura::Window* GetDefaultParent(aura::Window* context, |
| 93 | aura::Window* window, |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 94 | const gfx::Rect& bounds) OVERRIDE { |
[email protected] | 363e754 | 2013-04-23 22:33:14 | [diff] [blame] | 95 | if (!capture_client_) { |
[email protected] | be2a0ac | 2012-07-24 11:23:22 | [diff] [blame] | 96 | capture_client_.reset( |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 97 | new aura::client::DefaultCaptureClient(window_->GetRootWindow())); |
[email protected] | be2a0ac | 2012-07-24 11:23:22 | [diff] [blame] | 98 | } |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 99 | return window_; |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | private: |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 103 | aura::Window* window_; |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 104 | |
[email protected] | 48dea15 | 2012-11-02 20:26:46 | [diff] [blame] | 105 | scoped_ptr<aura::client::DefaultCaptureClient> capture_client_; |
[email protected] | be2a0ac | 2012-07-24 11:23:22 | [diff] [blame] | 106 | |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 107 | DISALLOW_COPY_AND_ASSIGN(DemoWindowTreeClient); |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 108 | }; |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 109 | |
[email protected] | f7a0b4d2 | 2012-09-18 16:31:01 | [diff] [blame] | 110 | int DemoMain() { |
[email protected] | 27a80e75 | 2014-03-13 20:36:41 | [diff] [blame] | 111 | #if defined(USE_X11) |
| 112 | // This demo uses InProcessContextFactory which uses X on a separate Gpu |
| 113 | // thread. |
[email protected] | 82f884d6ffb | 2014-04-15 03:34:54 | [diff] [blame] | 114 | gfx::InitializeThreadedX11(); |
[email protected] | 27a80e75 | 2014-03-13 20:36:41 | [diff] [blame] | 115 | #endif |
[email protected] | f321f80b | 2013-09-11 22:59:14 | [diff] [blame] | 116 | |
[email protected] | af7c5d9 | 2014-02-03 19:53:15 | [diff] [blame] | 117 | gfx::GLSurface::InitializeOneOff(); |
| 118 | |
[email protected] | 804f479 | 2014-04-22 22:54:37 | [diff] [blame] | 119 | #if defined(OS_WIN) |
| 120 | gfx::InitDeviceScaleFactor(1.0f); |
| 121 | #endif |
| 122 | |
[email protected] | f321f80b | 2013-09-11 22:59:14 | [diff] [blame] | 123 | // The ContextFactory must exist before any Compositors are created. |
[email protected] | 27a80e75 | 2014-03-13 20:36:41 | [diff] [blame] | 124 | scoped_ptr<ui::InProcessContextFactory> context_factory( |
| 125 | new ui::InProcessContextFactory()); |
| 126 | ui::ContextFactory::SetInstance(context_factory.get()); |
| 127 | |
| 128 | // Create the message-loop here before creating the root window. |
| 129 | base::MessageLoopForUI message_loop; |
[email protected] | f321f80b | 2013-09-11 22:59:14 | [diff] [blame] | 130 | |
[email protected] | 5b883abb | 2014-05-05 06:44:10 | [diff] [blame] | 131 | aura::Env::CreateInstance(true); |
[email protected] | fa69f2b6 | 2014-05-22 21:47:58 | [diff] [blame^] | 132 | aura::Env::GetInstance()->set_context_factory(context_factory.get()); |
[email protected] | 2ad669a | 2013-02-15 04:36:56 | [diff] [blame] | 133 | scoped_ptr<aura::TestScreen> test_screen(aura::TestScreen::Create()); |
| 134 | gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen.get()); |
[email protected] | 2f262033 | 2014-02-28 10:07:38 | [diff] [blame] | 135 | scoped_ptr<aura::WindowTreeHost> host( |
| 136 | test_screen->CreateHostForPrimaryDisplay()); |
| 137 | scoped_ptr<DemoWindowTreeClient> window_tree_client( |
| 138 | new DemoWindowTreeClient(host->window())); |
[email protected] | 98096954 | 2013-10-18 22:07:34 | [diff] [blame] | 139 | aura::test::TestFocusClient focus_client; |
[email protected] | 2f262033 | 2014-02-28 10:07:38 | [diff] [blame] | 140 | aura::client::SetFocusClient(host->window(), &focus_client); |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 141 | |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 142 | // Create a hierarchy of test windows. |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 143 | DemoWindowDelegate window_delegate1(SK_ColorBLUE); |
| 144 | aura::Window window1(&window_delegate1); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 145 | window1.set_id(1); |
[email protected] | 52b02a7 | 2014-01-08 21:41:50 | [diff] [blame] | 146 | window1.Init(aura::WINDOW_LAYER_TEXTURED); |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 147 | window1.SetBounds(gfx::Rect(100, 100, 400, 400)); |
[email protected] | a3929aba | 2011-09-30 18:30:17 | [diff] [blame] | 148 | window1.Show(); |
[email protected] | 2f262033 | 2014-02-28 10:07:38 | [diff] [blame] | 149 | aura::client::ParentWindowWithContext(&window1, host->window(), gfx::Rect()); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 150 | |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 151 | DemoWindowDelegate window_delegate2(SK_ColorRED); |
| 152 | aura::Window window2(&window_delegate2); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 153 | window2.set_id(2); |
[email protected] | 52b02a7 | 2014-01-08 21:41:50 | [diff] [blame] | 154 | window2.Init(aura::WINDOW_LAYER_TEXTURED); |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 155 | window2.SetBounds(gfx::Rect(200, 200, 350, 350)); |
[email protected] | a3929aba | 2011-09-30 18:30:17 | [diff] [blame] | 156 | window2.Show(); |
[email protected] | 2f262033 | 2014-02-28 10:07:38 | [diff] [blame] | 157 | aura::client::ParentWindowWithContext(&window2, host->window(), gfx::Rect()); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 158 | |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 159 | DemoWindowDelegate window_delegate3(SK_ColorGREEN); |
| 160 | aura::Window window3(&window_delegate3); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 161 | window3.set_id(3); |
[email protected] | 52b02a7 | 2014-01-08 21:41:50 | [diff] [blame] | 162 | window3.Init(aura::WINDOW_LAYER_TEXTURED); |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 163 | window3.SetBounds(gfx::Rect(10, 10, 50, 50)); |
[email protected] | a3929aba | 2011-09-30 18:30:17 | [diff] [blame] | 164 | window3.Show(); |
[email protected] | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 165 | window2.AddChild(&window3); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 166 | |
[email protected] | 2f262033 | 2014-02-28 10:07:38 | [diff] [blame] | 167 | host->Show(); |
[email protected] | 7060d659 | 2013-04-29 19:01:48 | [diff] [blame] | 168 | base::MessageLoopForUI::current()->Run(); |
[email protected] | 9783633c | 2011-10-27 15:41:52 | [diff] [blame] | 169 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 170 | return 0; |
| 171 | } |
[email protected] | f7a0b4d2 | 2012-09-18 16:31:01 | [diff] [blame] | 172 | |
[email protected] | f7a0b4d2 | 2012-09-18 16:31:01 | [diff] [blame] | 173 | } // namespace |
| 174 | |
| 175 | int main(int argc, char** argv) { |
| 176 | CommandLine::Init(argc, argv); |
| 177 | |
| 178 | // The exit manager is in charge of calling the dtors of singleton objects. |
| 179 | base::AtExitManager exit_manager; |
| 180 | |
[email protected] | d7477f0 | 2013-08-23 00:39:09 | [diff] [blame] | 181 | base::i18n::InitializeICU(); |
[email protected] | f7a0b4d2 | 2012-09-18 16:31:01 | [diff] [blame] | 182 | |
[email protected] | 56deede | 2012-10-01 21:25:12 | [diff] [blame] | 183 | return DemoMain(); |
[email protected] | f7a0b4d2 | 2012-09-18 16:31:01 | [diff] [blame] | 184 | } |