blob: be1c68471f7a8877980d84ad926ef604f207bd9e [file] [log] [blame]
[email protected]538f9562012-01-17 17:46:041// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]81585f32011-07-29 19:32:062// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]81585f32011-07-29 19:32:065#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]905e19a2011-09-07 02:17:539#include "base/message_loop.h"
[email protected]81585f32011-07-29 19:32:0610#include "third_party/skia/include/core/SkXfermode.h"
[email protected]dbf3d402011-09-14 21:32:1611#include "ui/aura/event.h"
12#include "ui/aura/window.h"
13#include "ui/aura/window_delegate.h"
[email protected]912be0e2011-11-09 19:05:2414#include "ui/base/hit_test.h"
[email protected]81585f32011-07-29 19:32:0615#include "ui/base/resource/resource_bundle.h"
[email protected]99f07e02011-12-07 00:02:5916#include "ui/aura/root_window.h"
[email protected]e599f0132011-08-24 19:03:3517#include "ui/base/ui_base_paths.h"
[email protected]94a0d2582012-03-09 00:30:5918#include "ui/gfx/canvas.h"
[email protected]fcb98b72011-11-18 04:29:1819#include "ui/gfx/compositor/test/compositor_test_support.h"
[email protected]81585f32011-07-29 19:32:0620#include "ui/gfx/rect.h"
[email protected]81585f32011-07-29 19:32:0621
[email protected]4a6bef32011-09-07 02:06:0122#if defined(USE_X11)
[email protected]4a6bef32011-09-07 02:06:0123#include "base/message_pump_x.h"
24#endif
25
[email protected]81585f32011-07-29 19:32:0626namespace {
27
[email protected]8d8c7732011-08-25 22:35:1328// Trivial WindowDelegate implementation that draws a colored background.
[email protected]81585f32011-07-29 19:32:0629class DemoWindowDelegate : public aura::WindowDelegate {
30 public:
[email protected]8d8c7732011-08-25 22:35:1331 explicit DemoWindowDelegate(SkColor color) : color_(color) {}
[email protected]81585f32011-07-29 19:32:0632
[email protected]8dd791d2011-09-16 16:37:3033 // Overridden from WindowDelegate:
[email protected]17a6cb952011-11-22 23:04:3834 virtual gfx::Size GetMinimumSize() const OVERRIDE {
35 return gfx::Size();
36 }
[email protected]8dd791d2011-09-16 16:37:3037 virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
38 const gfx::Rect& new_bounds) OVERRIDE {}
[email protected]c94f8592011-09-02 20:12:1339 virtual void OnFocus() OVERRIDE {}
40 virtual void OnBlur() OVERRIDE {}
41 virtual bool OnKeyEvent(aura::KeyEvent* event) OVERRIDE {
42 return false;
43 }
[email protected]0207c92d2011-10-04 14:45:0744 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
[email protected]9e591cb2011-10-17 18:14:3245 return gfx::kNullCursor;
[email protected]0207c92d2011-10-04 14:45:0746 }
[email protected]eaf6dd52011-09-02 00:39:2647 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE {
48 return HTCAPTION;
49 }
[email protected]e0dfebf82011-09-01 02:57:3250 virtual bool OnMouseEvent(aura::MouseEvent* event) OVERRIDE {
[email protected]970aa362011-08-30 20:03:3451 return true;
52 }
[email protected]5951806f2011-10-17 16:06:3553 virtual ui::TouchStatus OnTouchEvent(aura::TouchEvent* event) OVERRIDE {
54 return ui::TOUCH_STATUS_END;
55 }
[email protected]538f9562012-01-17 17:46:0456 virtual ui::GestureStatus OnGestureEvent(aura::GestureEvent* event) OVERRIDE {
57 return ui::GESTURE_STATUS_UNKNOWN;
58 }
[email protected]a8bb96702011-12-03 22:17:4059 virtual bool CanFocus() OVERRIDE { return true; }
[email protected]70ccf702011-09-22 18:15:5860 virtual void OnCaptureLost() OVERRIDE {}
[email protected]8d8c7732011-08-25 22:35:1361 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
[email protected]be172ba82011-10-05 19:05:0762 canvas->GetSkCanvas()->drawColor(color_, SkXfermode::kSrc_Mode);
[email protected]8d8c7732011-08-25 22:35:1363 }
[email protected]658600e2011-09-07 21:16:2164 virtual void OnWindowDestroying() OVERRIDE {}
65 virtual void OnWindowDestroyed() OVERRIDE {}
[email protected]6fdefb02011-10-11 04:16:1866 virtual void OnWindowVisibilityChanged(bool visible) OVERRIDE {}
[email protected]970aa362011-08-30 20:03:3467
[email protected]81585f32011-07-29 19:32:0668 private:
[email protected]b1b155512011-08-18 22:47:5069 SkColor color_;
70
[email protected]81585f32011-07-29 19:32:0671 DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate);
72};
73
[email protected]81585f32011-07-29 19:32:0674
75} // namespace
76
77int 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]70f9df12012-01-28 02:30:0485 ResourceBundle::InitSharedInstanceWithLocale("en-US");
[email protected]81585f32011-07-29 19:32:0686
[email protected]99f07e02011-12-07 00:02:5987 // Create the message-loop here before creating the root window.
[email protected]905e19a2011-09-07 02:17:5388 MessageLoop message_loop(MessageLoop::TYPE_UI);
[email protected]9783633c2011-10-27 15:41:5289 ui::CompositorTestSupport::Initialize();
[email protected]905e19a2011-09-07 02:17:5390
[email protected]58482fa2012-03-02 14:57:3991 scoped_ptr<aura::RootWindow> root_window(new aura::RootWindow);
[email protected]81585f32011-07-29 19:32:0692
[email protected]b1b155512011-08-18 22:47:5093 // Create a hierarchy of test windows.
[email protected]8d8c7732011-08-25 22:35:1394 DemoWindowDelegate window_delegate1(SK_ColorBLUE);
95 aura::Window window1(&window_delegate1);
[email protected]b1b155512011-08-18 22:47:5096 window1.set_id(1);
[email protected]da7584c2012-01-28 03:19:1297 window1.Init(ui::Layer::LAYER_TEXTURED);
[email protected]7fca53d42011-09-29 15:38:1298 window1.SetBounds(gfx::Rect(100, 100, 400, 400));
[email protected]a3929aba2011-09-30 18:30:1799 window1.Show();
[email protected]8d8c7732011-08-25 22:35:13100 window1.SetParent(NULL);
[email protected]b1b155512011-08-18 22:47:50101
[email protected]8d8c7732011-08-25 22:35:13102 DemoWindowDelegate window_delegate2(SK_ColorRED);
103 aura::Window window2(&window_delegate2);
[email protected]b1b155512011-08-18 22:47:50104 window2.set_id(2);
[email protected]da7584c2012-01-28 03:19:12105 window2.Init(ui::Layer::LAYER_TEXTURED);
[email protected]7fca53d42011-09-29 15:38:12106 window2.SetBounds(gfx::Rect(200, 200, 350, 350));
[email protected]a3929aba2011-09-30 18:30:17107 window2.Show();
[email protected]8d8c7732011-08-25 22:35:13108 window2.SetParent(NULL);
[email protected]b1b155512011-08-18 22:47:50109
[email protected]8d8c7732011-08-25 22:35:13110 DemoWindowDelegate window_delegate3(SK_ColorGREEN);
111 aura::Window window3(&window_delegate3);
[email protected]b1b155512011-08-18 22:47:50112 window3.set_id(3);
[email protected]da7584c2012-01-28 03:19:12113 window3.Init(ui::Layer::LAYER_TEXTURED);
[email protected]7fca53d42011-09-29 15:38:12114 window3.SetBounds(gfx::Rect(10, 10, 50, 50));
[email protected]a3929aba2011-09-30 18:30:17115 window3.Show();
[email protected]8d8c7732011-08-25 22:35:13116 window3.SetParent(&window2);
[email protected]b1b155512011-08-18 22:47:50117
[email protected]58482fa2012-03-02 14:57:39118 root_window->ShowRootWindow();
[email protected]01c5bab2012-02-25 02:37:43119 MessageLoopForUI::current()->Run();
[email protected]9783633c2011-10-27 15:41:52120
121 ui::CompositorTestSupport::Terminate();
122
[email protected]81585f32011-07-29 19:32:06123 return 0;
124}