Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: views/aura_desktop/aura_desktop_main.cc

Issue 8572016: views: Move more two directories into ui/views/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/animation/bounds_animator_unittest.cc ('k') | views/views.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
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"
9 #include "base/message_loop.h"
10 #include "base/utf_string_conversions.h"
11 #include "third_party/skia/include/core/SkXfermode.h"
12 #include "ui/aura/desktop.h"
13 #include "ui/aura/desktop_host.h"
14 #include "ui/aura/window.h"
15 #include "ui/aura/window_delegate.h"
16 #include "ui/base/hit_test.h"
17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/base/ui_base_paths.h"
19 #include "ui/gfx/canvas.h"
20 #include "ui/gfx/canvas_skia.h"
21 #include "ui/gfx/rect.h"
22 #include "views/widget/widget.h"
23 #include "views/widget/widget_delegate.h"
24
25 namespace {
26
27 // Trivial WindowDelegate implementation that draws a colored background.
28 class DemoWindowDelegate : public aura::WindowDelegate {
29 public:
30 explicit DemoWindowDelegate(SkColor color) : color_(color) {}
31
32 // Overridden from aura::WindowDelegate:
33 virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
34 const gfx::Rect& new_bounds) OVERRIDE {}
35 virtual void OnFocus() OVERRIDE {}
36 virtual void OnBlur() OVERRIDE {}
37 virtual bool OnKeyEvent(aura::KeyEvent* event) OVERRIDE {
38 return false;
39 }
40 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
41 return gfx::kNullCursor;
42 }
43 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE {
44 return HTCLIENT;
45 }
46 virtual bool OnMouseEvent(aura::MouseEvent* event) OVERRIDE {
47 return true;
48 }
49 virtual ui::TouchStatus OnTouchEvent(aura::TouchEvent* event) OVERRIDE {
50 return ui::TOUCH_STATUS_END;
51 }
52 virtual bool ShouldActivate(aura::Event* event) OVERRIDE {
53 return true;
54 }
55 virtual void OnActivated() OVERRIDE {}
56 virtual void OnLostActive() OVERRIDE {}
57 virtual void OnCaptureLost() OVERRIDE {}
58 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
59 canvas->GetSkCanvas()->drawColor(color_, SkXfermode::kSrc_Mode);
60 }
61 virtual void OnWindowDestroying() OVERRIDE {
62 }
63 virtual void OnWindowDestroyed() OVERRIDE {
64 }
65 virtual void OnWindowVisibilityChanged(bool visible) OVERRIDE {
66 }
67
68 private:
69 SkColor color_;
70
71 DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate);
72 };
73
74 class TestView : public views::View {
75 public:
76 TestView() : color_shifting_(false), color_(SK_ColorYELLOW) {}
77 virtual ~TestView() {}
78
79 private:
80 // Overridden from views::View:
81 virtual void OnPaint(gfx::Canvas* canvas) {
82 canvas->FillRect(color_, GetLocalBounds());
83 }
84 virtual bool OnMousePressed(const views::MouseEvent& event) {
85 color_shifting_ = true;
86 return true;
87 }
88 virtual void OnMouseMoved(const views::MouseEvent& event) {
89 if (color_shifting_) {
90 color_ = SkColorSetRGB((SkColorGetR(color_) + 5) % 255,
91 SkColorGetG(color_),
92 SkColorGetB(color_));
93 SchedulePaint();
94 }
95 }
96 virtual void OnMouseReleased(const views::MouseEvent& event) {
97 color_shifting_ = false;
98 }
99
100 bool color_shifting_;
101 SkColor color_;
102
103 DISALLOW_COPY_AND_ASSIGN(TestView);
104 };
105
106 class TestWindowContents : public views::WidgetDelegateView {
107 public:
108 TestWindowContents() {}
109 virtual ~TestWindowContents() {}
110
111 private:
112 // Overridden from views::View:
113 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
114 canvas->FillRect(SK_ColorGRAY, GetLocalBounds());
115 }
116
117 // Overridden from views::WidgetDelegateView:
118 virtual string16 GetWindowTitle() const OVERRIDE {
119 return ASCIIToUTF16("Test Window!");
120 }
121 virtual View* GetContentsView() OVERRIDE {
122 return this;
123 }
124
125 DISALLOW_COPY_AND_ASSIGN(TestWindowContents);
126 };
127
128 } // namespace
129
130 int main(int argc, char** argv) {
131 CommandLine::Init(argc, argv);
132
133 // The exit manager is in charge of calling the dtors of singleton objects.
134 base::AtExitManager exit_manager;
135
136 ui::RegisterPathProvider();
137 icu_util::Initialize();
138 ResourceBundle::InitSharedInstance("en-US");
139
140 // Create the message-loop here before creating the desktop.
141 MessageLoop message_loop(MessageLoop::TYPE_UI);
142
143 aura::Desktop::GetInstance();
144
145 // Create a hierarchy of test windows.
146 DemoWindowDelegate window_delegate1(SK_ColorBLUE);
147 aura::Window* window1 = new aura::Window(&window_delegate1);
148 window1->set_id(1);
149 window1->Init(ui::Layer::LAYER_HAS_TEXTURE);
150 window1->SetBounds(gfx::Rect(100, 100, 400, 400));
151 window1->Show();
152 window1->SetParent(NULL);
153
154 DemoWindowDelegate window_delegate2(SK_ColorRED);
155 aura::Window* window2 = new aura::Window(&window_delegate2);
156 window2->set_id(2);
157 window2->Init(ui::Layer::LAYER_HAS_TEXTURE);
158 window2->SetBounds(gfx::Rect(200, 200, 350, 350));
159 window2->Show();
160 window2->SetParent(NULL);
161
162 DemoWindowDelegate window_delegate3(SK_ColorGREEN);
163 aura::Window* window3 = new aura::Window(&window_delegate3);
164 window3->set_id(3);
165 window3->Init(ui::Layer::LAYER_HAS_TEXTURE);
166 window3->SetBounds(gfx::Rect(10, 10, 50, 50));
167 window3->Show();
168 window3->SetParent(window2);
169
170 views::Widget* widget = new views::Widget;
171 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
172 params.bounds = gfx::Rect(75, 75, 80, 80);
173 params.parent = window2;
174 widget->Init(params);
175 widget->SetContentsView(new TestView);
176
177 TestWindowContents* contents = new TestWindowContents;
178 views::Widget* views_window = views::Widget::CreateWindowWithParentAndBounds(
179 contents, window2, gfx::Rect(120, 150, 200, 200));
180 views_window->Show();
181
182 aura::Desktop::GetInstance()->Run();
183
184 delete aura::Desktop::GetInstance();
185
186 return 0;
187 }
188
OLDNEW
« no previous file with comments | « views/animation/bounds_animator_unittest.cc ('k') | views/views.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698