[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] | 905e19a | 2011-09-07 02:17:53 | [diff] [blame] | 9 | #include "base/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] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 12 | #include "ui/aura/client/stacking_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] | 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] | 153472d7 | 2012-09-04 21:33:02 | [diff] [blame] | 18 | #include "ui/base/events/event.h" |
[email protected] | 912be0e | 2011-11-09 19:05:24 | [diff] [blame] | 19 | #include "ui/base/hit_test.h" |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 20 | #include "ui/base/resource/resource_bundle.h" |
[email protected] | e599f013 | 2011-08-24 19:03:35 | [diff] [blame] | 21 | #include "ui/base/ui_base_paths.h" |
[email protected] | 5294a92 | 2012-11-23 21:05:58 | [diff] [blame] | 22 | #include "ui/compositor/test/compositor_test_support.h" |
[email protected] | 94a0d258 | 2012-03-09 00:30:59 | [diff] [blame] | 23 | #include "ui/gfx/canvas.h" |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 24 | #include "ui/gfx/rect.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] | 1a24da5 | 2012-05-29 23:25:38 | [diff] [blame] | 27 | #include "base/message_pump_aurax11.h" |
[email protected] | 4a6bef3 | 2011-09-07 02:06:01 | [diff] [blame] | 28 | #endif |
| 29 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 30 | namespace { |
| 31 | |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 32 | // Trivial WindowDelegate implementation that draws a colored background. |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 33 | class DemoWindowDelegate : public aura::WindowDelegate { |
| 34 | public: |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 35 | explicit DemoWindowDelegate(SkColor color) : color_(color) {} |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 36 | |
[email protected] | 8dd791d | 2011-09-16 16:37:30 | [diff] [blame] | 37 | // Overridden from WindowDelegate: |
[email protected] | 17a6cb95 | 2011-11-22 23:04:38 | [diff] [blame] | 38 | virtual gfx::Size GetMinimumSize() const OVERRIDE { |
| 39 | return gfx::Size(); |
| 40 | } |
[email protected] | fa574b6 | 2012-11-26 04:11:38 | [diff] [blame] | 41 | |
| 42 | virtual gfx::Size GetMaximumSize() const OVERRIDE { |
| 43 | return gfx::Size(); |
| 44 | } |
| 45 | |
[email protected] | 8dd791d | 2011-09-16 16:37:30 | [diff] [blame] | 46 | virtual void OnBoundsChanged(const gfx::Rect& old_bounds, |
| 47 | const gfx::Rect& new_bounds) OVERRIDE {} |
[email protected] | 87a4b99 | 2012-06-18 23:27:40 | [diff] [blame] | 48 | virtual void OnFocus(aura::Window* old_focused_window) OVERRIDE {} |
[email protected] | c94f859 | 2011-09-02 20:12:13 | [diff] [blame] | 49 | virtual void OnBlur() OVERRIDE {} |
[email protected] | 0207c92d | 2011-10-04 14:45:07 | [diff] [blame] | 50 | virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE { |
[email protected] | 9e591cb | 2011-10-17 18:14:32 | [diff] [blame] | 51 | return gfx::kNullCursor; |
[email protected] | 0207c92d | 2011-10-04 14:45:07 | [diff] [blame] | 52 | } |
[email protected] | eaf6dd5 | 2011-09-02 00:39:26 | [diff] [blame] | 53 | virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { |
| 54 | return HTCAPTION; |
| 55 | } |
[email protected] | 334b8189 | 2012-06-16 16:38:14 | [diff] [blame] | 56 | virtual bool ShouldDescendIntoChildForEventHandling( |
| 57 | aura::Window* child, |
| 58 | const gfx::Point& location) OVERRIDE { |
| 59 | return true; |
| 60 | } |
[email protected] | a8bb9670 | 2011-12-03 22:17:40 | [diff] [blame] | 61 | virtual bool CanFocus() OVERRIDE { return true; } |
[email protected] | 70ccf70 | 2011-09-22 18:15:58 | [diff] [blame] | 62 | virtual void OnCaptureLost() OVERRIDE {} |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 63 | virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
[email protected] | 6fae797 | 2012-04-10 20:12:08 | [diff] [blame] | 64 | canvas->DrawColor(color_, SkXfermode::kSrc_Mode); |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 65 | } |
[email protected] | d3f5bbc1 | 2012-05-17 00:09:04 | [diff] [blame] | 66 | virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {} |
[email protected] | 658600e | 2011-09-07 21:16:21 | [diff] [blame] | 67 | virtual void OnWindowDestroying() OVERRIDE {} |
| 68 | virtual void OnWindowDestroyed() OVERRIDE {} |
[email protected] | ab8f86b | 2012-07-30 14:38:50 | [diff] [blame] | 69 | virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {} |
[email protected] | ec0c94a | 2012-06-16 05:10:25 | [diff] [blame] | 70 | virtual bool HasHitTestMask() const OVERRIDE { return false; } |
| 71 | virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {} |
[email protected] | b6ea1c1 | 2012-09-13 17:28:50 | [diff] [blame] | 72 | scoped_refptr<ui::Texture> CopyTexture() { |
| 73 | return scoped_refptr<ui::Texture>(); |
| 74 | } |
[email protected] | 970aa36 | 2011-08-30 20:03:34 | [diff] [blame] | 75 | |
[email protected] | fa9faf5 | 2012-09-07 02:31:08 | [diff] [blame] | 76 | // Overridden from ui::EventHandler: |
| 77 | virtual ui::EventResult OnKeyEvent(ui::KeyEvent* event) OVERRIDE { |
| 78 | return ui::ER_UNHANDLED; |
| 79 | } |
| 80 | virtual ui::EventResult OnMouseEvent(ui::MouseEvent* event) OVERRIDE { |
| 81 | return ui::ER_HANDLED; |
| 82 | } |
[email protected] | 58bbb201 | 2012-09-27 17:25:52 | [diff] [blame] | 83 | virtual ui::EventResult OnTouchEvent(ui::TouchEvent* event) OVERRIDE { |
| 84 | return ui::ER_UNHANDLED; |
[email protected] | fa9faf5 | 2012-09-07 02:31:08 | [diff] [blame] | 85 | } |
| 86 | virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE { |
| 87 | return ui::ER_UNHANDLED; |
| 88 | } |
| 89 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 90 | private: |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 91 | SkColor color_; |
| 92 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 93 | DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate); |
| 94 | }; |
| 95 | |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 96 | class DemoStackingClient : public aura::client::StackingClient { |
| 97 | public: |
| 98 | explicit DemoStackingClient(aura::RootWindow* root_window) |
| 99 | : root_window_(root_window) { |
| 100 | aura::client::SetStackingClient(this); |
| 101 | } |
| 102 | |
| 103 | virtual ~DemoStackingClient() { |
| 104 | aura::client::SetStackingClient(NULL); |
| 105 | } |
| 106 | |
| 107 | // Overridden from aura::client::StackingClient: |
[email protected] | d8f1004 | 2012-11-14 01:10:46 | [diff] [blame] | 108 | virtual aura::Window* GetDefaultParent(aura::Window* context, |
| 109 | aura::Window* window, |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 110 | const gfx::Rect& bounds) OVERRIDE { |
[email protected] | be2a0ac | 2012-07-24 11:23:22 | [diff] [blame] | 111 | if (!capture_client_.get()) { |
| 112 | capture_client_.reset( |
[email protected] | 48dea15 | 2012-11-02 20:26:46 | [diff] [blame] | 113 | new aura::client::DefaultCaptureClient(root_window_)); |
[email protected] | be2a0ac | 2012-07-24 11:23:22 | [diff] [blame] | 114 | } |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 115 | return root_window_; |
| 116 | } |
| 117 | |
| 118 | private: |
| 119 | aura::RootWindow* root_window_; |
| 120 | |
[email protected] | 48dea15 | 2012-11-02 20:26:46 | [diff] [blame] | 121 | scoped_ptr<aura::client::DefaultCaptureClient> capture_client_; |
[email protected] | be2a0ac | 2012-07-24 11:23:22 | [diff] [blame] | 122 | |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 123 | DISALLOW_COPY_AND_ASSIGN(DemoStackingClient); |
| 124 | }; |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 125 | |
[email protected] | f7a0b4d2 | 2012-09-18 16:31:01 | [diff] [blame] | 126 | int DemoMain() { |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 127 | // Create the message-loop here before creating the root window. |
[email protected] | 905e19a | 2011-09-07 02:17:53 | [diff] [blame] | 128 | MessageLoop message_loop(MessageLoop::TYPE_UI); |
[email protected] | 5294a92 | 2012-11-23 21:05:58 | [diff] [blame] | 129 | ui::CompositorTestSupport::Initialize(); |
[email protected] | 6bdf795 | 2012-11-14 10:10:58 | [diff] [blame] | 130 | aura::Env::GetInstance(); |
| 131 | aura::TestScreen test_screen; |
| 132 | gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, &test_screen); |
[email protected] | e050ef14 | 2012-03-21 01:04:24 | [diff] [blame] | 133 | scoped_ptr<aura::RootWindow> root_window( |
[email protected] | 6bdf795 | 2012-11-14 10:10:58 | [diff] [blame] | 134 | test_screen.CreateRootWindowForPrimaryDisplay()); |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 135 | scoped_ptr<DemoStackingClient> stacking_client(new DemoStackingClient( |
| 136 | root_window.get())); |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 137 | |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 138 | // Create a hierarchy of test windows. |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 139 | DemoWindowDelegate window_delegate1(SK_ColorBLUE); |
| 140 | aura::Window window1(&window_delegate1); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 141 | window1.set_id(1); |
[email protected] | 595b52a | 2012-03-23 16:17:24 | [diff] [blame] | 142 | window1.Init(ui::LAYER_TEXTURED); |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 143 | window1.SetBounds(gfx::Rect(100, 100, 400, 400)); |
[email protected] | a3929aba | 2011-09-30 18:30:17 | [diff] [blame] | 144 | window1.Show(); |
[email protected] | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame^] | 145 | window1.SetDefaultParentByRootWindow(root_window.get(), gfx::Rect()); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 146 | |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 147 | DemoWindowDelegate window_delegate2(SK_ColorRED); |
| 148 | aura::Window window2(&window_delegate2); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 149 | window2.set_id(2); |
[email protected] | 595b52a | 2012-03-23 16:17:24 | [diff] [blame] | 150 | window2.Init(ui::LAYER_TEXTURED); |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 151 | window2.SetBounds(gfx::Rect(200, 200, 350, 350)); |
[email protected] | a3929aba | 2011-09-30 18:30:17 | [diff] [blame] | 152 | window2.Show(); |
[email protected] | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame^] | 153 | window2.SetDefaultParentByRootWindow(root_window.get(), gfx::Rect()); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 154 | |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 155 | DemoWindowDelegate window_delegate3(SK_ColorGREEN); |
| 156 | aura::Window window3(&window_delegate3); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 157 | window3.set_id(3); |
[email protected] | 595b52a | 2012-03-23 16:17:24 | [diff] [blame] | 158 | window3.Init(ui::LAYER_TEXTURED); |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 159 | window3.SetBounds(gfx::Rect(10, 10, 50, 50)); |
[email protected] | a3929aba | 2011-09-30 18:30:17 | [diff] [blame] | 160 | window3.Show(); |
[email protected] | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame^] | 161 | window2.AddChild(&window3); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 162 | |
[email protected] | 58482fa | 2012-03-02 14:57:39 | [diff] [blame] | 163 | root_window->ShowRootWindow(); |
[email protected] | 01c5bab | 2012-02-25 02:37:43 | [diff] [blame] | 164 | MessageLoopForUI::current()->Run(); |
[email protected] | 9783633c | 2011-10-27 15:41:52 | [diff] [blame] | 165 | |
[email protected] | 5294a92 | 2012-11-23 21:05:58 | [diff] [blame] | 166 | ui::CompositorTestSupport::Terminate(); |
| 167 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 168 | return 0; |
| 169 | } |
[email protected] | f7a0b4d2 | 2012-09-18 16:31:01 | [diff] [blame] | 170 | |
[email protected] | f7a0b4d2 | 2012-09-18 16:31:01 | [diff] [blame] | 171 | } // namespace |
| 172 | |
| 173 | int main(int argc, char** argv) { |
| 174 | CommandLine::Init(argc, argv); |
| 175 | |
| 176 | // The exit manager is in charge of calling the dtors of singleton objects. |
| 177 | base::AtExitManager exit_manager; |
| 178 | |
| 179 | ui::RegisterPathProvider(); |
| 180 | icu_util::Initialize(); |
| 181 | ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL); |
| 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 | } |