[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] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 11 | #include "ui/aura/client/stacking_client.h" |
[email protected] | e050ef14 | 2012-03-21 01:04:24 | [diff] [blame] | 12 | #include "ui/aura/env.h" |
[email protected] | dbf3d40 | 2011-09-14 21:32:16 | [diff] [blame] | 13 | #include "ui/aura/event.h" |
[email protected] | e050ef14 | 2012-03-21 01:04:24 | [diff] [blame] | 14 | #include "ui/aura/monitor_manager.h" |
[email protected] | f0e90a4 | 2012-03-13 23:05:57 | [diff] [blame] | 15 | #include "ui/aura/root_window.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] | 912be0e | 2011-11-09 19:05:24 | [diff] [blame] | 18 | #include "ui/base/hit_test.h" |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 19 | #include "ui/base/resource/resource_bundle.h" |
[email protected] | e599f013 | 2011-08-24 19:03:35 | [diff] [blame] | 20 | #include "ui/base/ui_base_paths.h" |
[email protected] | 94a0d258 | 2012-03-09 00:30:59 | [diff] [blame] | 21 | #include "ui/gfx/canvas.h" |
[email protected] | fcb98b7 | 2011-11-18 04:29:18 | [diff] [blame] | 22 | #include "ui/gfx/compositor/test/compositor_test_support.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] | 4a6bef3 | 2011-09-07 02:06:01 | [diff] [blame] | 26 | #include "base/message_pump_x.h" |
| 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] | 8dd791d | 2011-09-16 16:37:30 | [diff] [blame] | 40 | virtual void OnBoundsChanged(const gfx::Rect& old_bounds, |
| 41 | const gfx::Rect& new_bounds) OVERRIDE {} |
[email protected] | c94f859 | 2011-09-02 20:12:13 | [diff] [blame] | 42 | virtual void OnFocus() OVERRIDE {} |
| 43 | virtual void OnBlur() OVERRIDE {} |
| 44 | virtual bool OnKeyEvent(aura::KeyEvent* event) OVERRIDE { |
| 45 | return false; |
| 46 | } |
[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] | e0dfebf8 | 2011-09-01 02:57:32 | [diff] [blame] | 53 | virtual bool OnMouseEvent(aura::MouseEvent* event) OVERRIDE { |
[email protected] | 970aa36 | 2011-08-30 20:03:34 | [diff] [blame] | 54 | return true; |
| 55 | } |
[email protected] | 5951806f | 2011-10-17 16:06:35 | [diff] [blame] | 56 | virtual ui::TouchStatus OnTouchEvent(aura::TouchEvent* event) OVERRIDE { |
| 57 | return ui::TOUCH_STATUS_END; |
| 58 | } |
[email protected] | 538f956 | 2012-01-17 17:46:04 | [diff] [blame] | 59 | virtual ui::GestureStatus OnGestureEvent(aura::GestureEvent* event) OVERRIDE { |
| 60 | return ui::GESTURE_STATUS_UNKNOWN; |
| 61 | } |
[email protected] | a8bb9670 | 2011-12-03 22:17:40 | [diff] [blame] | 62 | virtual bool CanFocus() OVERRIDE { return true; } |
[email protected] | 70ccf70 | 2011-09-22 18:15:58 | [diff] [blame] | 63 | virtual void OnCaptureLost() OVERRIDE {} |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 64 | virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
[email protected] | 6fae797 | 2012-04-10 20:12:08 | [diff] [blame^] | 65 | canvas->DrawColor(color_, SkXfermode::kSrc_Mode); |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 66 | } |
[email protected] | 658600e | 2011-09-07 21:16:21 | [diff] [blame] | 67 | virtual void OnWindowDestroying() OVERRIDE {} |
| 68 | virtual void OnWindowDestroyed() OVERRIDE {} |
[email protected] | 6fdefb0 | 2011-10-11 04:16:18 | [diff] [blame] | 69 | virtual void OnWindowVisibilityChanged(bool visible) OVERRIDE {} |
[email protected] | 970aa36 | 2011-08-30 20:03:34 | [diff] [blame] | 70 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 71 | private: |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 72 | SkColor color_; |
| 73 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 74 | DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate); |
| 75 | }; |
| 76 | |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 77 | class DemoStackingClient : public aura::client::StackingClient { |
| 78 | public: |
| 79 | explicit DemoStackingClient(aura::RootWindow* root_window) |
| 80 | : root_window_(root_window) { |
| 81 | aura::client::SetStackingClient(this); |
| 82 | } |
| 83 | |
| 84 | virtual ~DemoStackingClient() { |
| 85 | aura::client::SetStackingClient(NULL); |
| 86 | } |
| 87 | |
| 88 | // Overridden from aura::client::StackingClient: |
| 89 | virtual aura::Window* GetDefaultParent(aura::Window* window) OVERRIDE { |
| 90 | return root_window_; |
| 91 | } |
| 92 | |
| 93 | private: |
| 94 | aura::RootWindow* root_window_; |
| 95 | |
| 96 | DISALLOW_COPY_AND_ASSIGN(DemoStackingClient); |
| 97 | }; |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 98 | |
| 99 | } // namespace |
| 100 | |
| 101 | int main(int argc, char** argv) { |
| 102 | CommandLine::Init(argc, argv); |
| 103 | |
| 104 | // The exit manager is in charge of calling the dtors of singleton objects. |
| 105 | base::AtExitManager exit_manager; |
| 106 | |
| 107 | ui::RegisterPathProvider(); |
| 108 | icu_util::Initialize(); |
[email protected] | 70f9df1 | 2012-01-28 02:30:04 | [diff] [blame] | 109 | ResourceBundle::InitSharedInstanceWithLocale("en-US"); |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 110 | |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 111 | // Create the message-loop here before creating the root window. |
[email protected] | 905e19a | 2011-09-07 02:17:53 | [diff] [blame] | 112 | MessageLoop message_loop(MessageLoop::TYPE_UI); |
[email protected] | 9783633c | 2011-10-27 15:41:52 | [diff] [blame] | 113 | ui::CompositorTestSupport::Initialize(); |
[email protected] | 905e19a | 2011-09-07 02:17:53 | [diff] [blame] | 114 | |
[email protected] | e050ef14 | 2012-03-21 01:04:24 | [diff] [blame] | 115 | scoped_ptr<aura::RootWindow> root_window( |
| 116 | aura::MonitorManager::CreateRootWindowForPrimaryMonitor()); |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 117 | scoped_ptr<DemoStackingClient> stacking_client(new DemoStackingClient( |
| 118 | root_window.get())); |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 119 | |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 120 | // Create a hierarchy of test windows. |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 121 | DemoWindowDelegate window_delegate1(SK_ColorBLUE); |
| 122 | aura::Window window1(&window_delegate1); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 123 | window1.set_id(1); |
[email protected] | 595b52a | 2012-03-23 16:17:24 | [diff] [blame] | 124 | window1.Init(ui::LAYER_TEXTURED); |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 125 | window1.SetBounds(gfx::Rect(100, 100, 400, 400)); |
[email protected] | a3929aba | 2011-09-30 18:30:17 | [diff] [blame] | 126 | window1.Show(); |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 127 | window1.SetParent(NULL); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 128 | |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 129 | DemoWindowDelegate window_delegate2(SK_ColorRED); |
| 130 | aura::Window window2(&window_delegate2); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 131 | window2.set_id(2); |
[email protected] | 595b52a | 2012-03-23 16:17:24 | [diff] [blame] | 132 | window2.Init(ui::LAYER_TEXTURED); |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 133 | window2.SetBounds(gfx::Rect(200, 200, 350, 350)); |
[email protected] | a3929aba | 2011-09-30 18:30:17 | [diff] [blame] | 134 | window2.Show(); |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 135 | window2.SetParent(NULL); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 136 | |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 137 | DemoWindowDelegate window_delegate3(SK_ColorGREEN); |
| 138 | aura::Window window3(&window_delegate3); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 139 | window3.set_id(3); |
[email protected] | 595b52a | 2012-03-23 16:17:24 | [diff] [blame] | 140 | window3.Init(ui::LAYER_TEXTURED); |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 141 | window3.SetBounds(gfx::Rect(10, 10, 50, 50)); |
[email protected] | a3929aba | 2011-09-30 18:30:17 | [diff] [blame] | 142 | window3.Show(); |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 143 | window3.SetParent(&window2); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 144 | |
[email protected] | 58482fa | 2012-03-02 14:57:39 | [diff] [blame] | 145 | root_window->ShowRootWindow(); |
[email protected] | 01c5bab | 2012-02-25 02:37:43 | [diff] [blame] | 146 | MessageLoopForUI::current()->Run(); |
[email protected] | 9783633c | 2011-10-27 15:41:52 | [diff] [blame] | 147 | |
| 148 | ui::CompositorTestSupport::Terminate(); |
| 149 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 150 | return 0; |
| 151 | } |