[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] | dbf3d40 | 2011-09-14 21:32:16 | [diff] [blame] | 11 | #include "ui/aura/event.h" |
| 12 | #include "ui/aura/window.h" |
| 13 | #include "ui/aura/window_delegate.h" |
[email protected] | 912be0e | 2011-11-09 19:05:24 | [diff] [blame] | 14 | #include "ui/base/hit_test.h" |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 15 | #include "ui/base/resource/resource_bundle.h" |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 16 | #include "ui/aura/root_window.h" |
[email protected] | e599f013 | 2011-08-24 19:03:35 | [diff] [blame] | 17 | #include "ui/base/ui_base_paths.h" |
[email protected] | 94a0d258 | 2012-03-09 00:30:59 | [diff] [blame^] | 18 | #include "ui/gfx/canvas.h" |
[email protected] | fcb98b7 | 2011-11-18 04:29:18 | [diff] [blame] | 19 | #include "ui/gfx/compositor/test/compositor_test_support.h" |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 20 | #include "ui/gfx/rect.h" |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 21 | |
[email protected] | 4a6bef3 | 2011-09-07 02:06:01 | [diff] [blame] | 22 | #if defined(USE_X11) |
[email protected] | 4a6bef3 | 2011-09-07 02:06:01 | [diff] [blame] | 23 | #include "base/message_pump_x.h" |
| 24 | #endif |
| 25 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 26 | namespace { |
| 27 | |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 28 | // Trivial WindowDelegate implementation that draws a colored background. |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 29 | class DemoWindowDelegate : public aura::WindowDelegate { |
| 30 | public: |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 31 | explicit DemoWindowDelegate(SkColor color) : color_(color) {} |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 32 | |
[email protected] | 8dd791d | 2011-09-16 16:37:30 | [diff] [blame] | 33 | // Overridden from WindowDelegate: |
[email protected] | 17a6cb95 | 2011-11-22 23:04:38 | [diff] [blame] | 34 | virtual gfx::Size GetMinimumSize() const OVERRIDE { |
| 35 | return gfx::Size(); |
| 36 | } |
[email protected] | 8dd791d | 2011-09-16 16:37:30 | [diff] [blame] | 37 | virtual void OnBoundsChanged(const gfx::Rect& old_bounds, |
| 38 | const gfx::Rect& new_bounds) OVERRIDE {} |
[email protected] | c94f859 | 2011-09-02 20:12:13 | [diff] [blame] | 39 | virtual void OnFocus() OVERRIDE {} |
| 40 | virtual void OnBlur() OVERRIDE {} |
| 41 | virtual bool OnKeyEvent(aura::KeyEvent* event) OVERRIDE { |
| 42 | return false; |
| 43 | } |
[email protected] | 0207c92d | 2011-10-04 14:45:07 | [diff] [blame] | 44 | virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE { |
[email protected] | 9e591cb | 2011-10-17 18:14:32 | [diff] [blame] | 45 | return gfx::kNullCursor; |
[email protected] | 0207c92d | 2011-10-04 14:45:07 | [diff] [blame] | 46 | } |
[email protected] | eaf6dd5 | 2011-09-02 00:39:26 | [diff] [blame] | 47 | virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { |
| 48 | return HTCAPTION; |
| 49 | } |
[email protected] | e0dfebf8 | 2011-09-01 02:57:32 | [diff] [blame] | 50 | virtual bool OnMouseEvent(aura::MouseEvent* event) OVERRIDE { |
[email protected] | 970aa36 | 2011-08-30 20:03:34 | [diff] [blame] | 51 | return true; |
| 52 | } |
[email protected] | 5951806f | 2011-10-17 16:06:35 | [diff] [blame] | 53 | virtual ui::TouchStatus OnTouchEvent(aura::TouchEvent* event) OVERRIDE { |
| 54 | return ui::TOUCH_STATUS_END; |
| 55 | } |
[email protected] | 538f956 | 2012-01-17 17:46:04 | [diff] [blame] | 56 | virtual ui::GestureStatus OnGestureEvent(aura::GestureEvent* event) OVERRIDE { |
| 57 | return ui::GESTURE_STATUS_UNKNOWN; |
| 58 | } |
[email protected] | a8bb9670 | 2011-12-03 22:17:40 | [diff] [blame] | 59 | virtual bool CanFocus() OVERRIDE { return true; } |
[email protected] | 70ccf70 | 2011-09-22 18:15:58 | [diff] [blame] | 60 | virtual void OnCaptureLost() OVERRIDE {} |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 61 | virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
[email protected] | be172ba8 | 2011-10-05 19:05:07 | [diff] [blame] | 62 | canvas->GetSkCanvas()->drawColor(color_, SkXfermode::kSrc_Mode); |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 63 | } |
[email protected] | 658600e | 2011-09-07 21:16:21 | [diff] [blame] | 64 | virtual void OnWindowDestroying() OVERRIDE {} |
| 65 | virtual void OnWindowDestroyed() OVERRIDE {} |
[email protected] | 6fdefb0 | 2011-10-11 04:16:18 | [diff] [blame] | 66 | virtual void OnWindowVisibilityChanged(bool visible) OVERRIDE {} |
[email protected] | 970aa36 | 2011-08-30 20:03:34 | [diff] [blame] | 67 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 68 | private: |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 69 | SkColor color_; |
| 70 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 71 | DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate); |
| 72 | }; |
| 73 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 74 | |
| 75 | } // namespace |
| 76 | |
| 77 | int main(int argc, char** argv) { |
| 78 | CommandLine::Init(argc, argv); |
| 79 | |
| 80 | // The exit manager is in charge of calling the dtors of singleton objects. |
| 81 | base::AtExitManager exit_manager; |
| 82 | |
| 83 | ui::RegisterPathProvider(); |
| 84 | icu_util::Initialize(); |
[email protected] | 70f9df1 | 2012-01-28 02:30:04 | [diff] [blame] | 85 | ResourceBundle::InitSharedInstanceWithLocale("en-US"); |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 86 | |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 87 | // Create the message-loop here before creating the root window. |
[email protected] | 905e19a | 2011-09-07 02:17:53 | [diff] [blame] | 88 | MessageLoop message_loop(MessageLoop::TYPE_UI); |
[email protected] | 9783633c | 2011-10-27 15:41:52 | [diff] [blame] | 89 | ui::CompositorTestSupport::Initialize(); |
[email protected] | 905e19a | 2011-09-07 02:17:53 | [diff] [blame] | 90 | |
[email protected] | 58482fa | 2012-03-02 14:57:39 | [diff] [blame] | 91 | scoped_ptr<aura::RootWindow> root_window(new aura::RootWindow); |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 92 | |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 93 | // Create a hierarchy of test windows. |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 94 | DemoWindowDelegate window_delegate1(SK_ColorBLUE); |
| 95 | aura::Window window1(&window_delegate1); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 96 | window1.set_id(1); |
[email protected] | da7584c | 2012-01-28 03:19:12 | [diff] [blame] | 97 | window1.Init(ui::Layer::LAYER_TEXTURED); |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 98 | window1.SetBounds(gfx::Rect(100, 100, 400, 400)); |
[email protected] | a3929aba | 2011-09-30 18:30:17 | [diff] [blame] | 99 | window1.Show(); |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 100 | window1.SetParent(NULL); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 101 | |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 102 | DemoWindowDelegate window_delegate2(SK_ColorRED); |
| 103 | aura::Window window2(&window_delegate2); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 104 | window2.set_id(2); |
[email protected] | da7584c | 2012-01-28 03:19:12 | [diff] [blame] | 105 | window2.Init(ui::Layer::LAYER_TEXTURED); |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 106 | window2.SetBounds(gfx::Rect(200, 200, 350, 350)); |
[email protected] | a3929aba | 2011-09-30 18:30:17 | [diff] [blame] | 107 | window2.Show(); |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 108 | window2.SetParent(NULL); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 109 | |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 110 | DemoWindowDelegate window_delegate3(SK_ColorGREEN); |
| 111 | aura::Window window3(&window_delegate3); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 112 | window3.set_id(3); |
[email protected] | da7584c | 2012-01-28 03:19:12 | [diff] [blame] | 113 | window3.Init(ui::Layer::LAYER_TEXTURED); |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 114 | window3.SetBounds(gfx::Rect(10, 10, 50, 50)); |
[email protected] | a3929aba | 2011-09-30 18:30:17 | [diff] [blame] | 115 | window3.Show(); |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 116 | window3.SetParent(&window2); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 117 | |
[email protected] | 58482fa | 2012-03-02 14:57:39 | [diff] [blame] | 118 | root_window->ShowRootWindow(); |
[email protected] | 01c5bab | 2012-02-25 02:37:43 | [diff] [blame] | 119 | MessageLoopForUI::current()->Run(); |
[email protected] | 9783633c | 2011-10-27 15:41:52 | [diff] [blame] | 120 | |
| 121 | ui::CompositorTestSupport::Terminate(); |
| 122 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 123 | return 0; |
| 124 | } |