1 // Copyright (c) 2012 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.
5 #include "ui/aura/test/test_window_delegate.h"
7 #include "base/strings/stringprintf.h"
8 #include "ui/aura/window.h"
9 #include "ui/base/hit_test.h"
10 #include "ui/compositor/paint_recorder.h"
11 #include "ui/events/event.h"
12 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/path.h"
14 #include "ui/gfx/skia_util.h"
17 #include "ui/base/cursor/cursor.h"
23 ////////////////////////////////////////////////////////////////////////////////
26 TestWindowDelegate::TestWindowDelegate()
27 : window_component_(HTCLIENT
),
28 delete_on_destroyed_(false),
32 TestWindowDelegate::~TestWindowDelegate() {
36 TestWindowDelegate
* TestWindowDelegate::CreateSelfDestroyingDelegate() {
37 TestWindowDelegate
* delegate
= new TestWindowDelegate
;
38 delegate
->delete_on_destroyed_
= true;
42 gfx::Size
TestWindowDelegate::GetMinimumSize() const {
46 gfx::Size
TestWindowDelegate::GetMaximumSize() const {
50 void TestWindowDelegate::OnBoundsChanged(const gfx::Rect
& old_bounds
,
51 const gfx::Rect
& new_bounds
) {
54 gfx::NativeCursor
TestWindowDelegate::GetCursor(const gfx::Point
& point
) {
55 return gfx::kNullCursor
;
58 int TestWindowDelegate::GetNonClientComponent(const gfx::Point
& point
) const {
59 return window_component_
;
62 bool TestWindowDelegate::ShouldDescendIntoChildForEventHandling(
64 const gfx::Point
& location
) {
68 bool TestWindowDelegate::CanFocus() {
72 void TestWindowDelegate::OnCaptureLost() {
75 void TestWindowDelegate::OnPaint(const ui::PaintContext
& context
) {
78 void TestWindowDelegate::OnDeviceScaleFactorChanged(
79 float device_scale_factor
) {
82 void TestWindowDelegate::OnWindowDestroying(Window
* window
) {
85 void TestWindowDelegate::OnWindowDestroyed(Window
* window
) {
86 if (delete_on_destroyed_
)
90 void TestWindowDelegate::OnWindowTargetVisibilityChanged(bool visible
) {
93 bool TestWindowDelegate::HasHitTestMask() const {
97 void TestWindowDelegate::GetHitTestMask(gfx::Path
* mask
) const {
100 ////////////////////////////////////////////////////////////////////////////////
101 // ColorTestWindowDelegate
103 ColorTestWindowDelegate::ColorTestWindowDelegate(SkColor color
)
105 last_key_code_(ui::VKEY_UNKNOWN
) {
108 ColorTestWindowDelegate::~ColorTestWindowDelegate() {
111 void ColorTestWindowDelegate::OnBoundsChanged(const gfx::Rect
& old_bounds
,
112 const gfx::Rect
& new_bounds
) {
113 window_size_
= new_bounds
.size();
116 void ColorTestWindowDelegate::OnKeyEvent(ui::KeyEvent
* event
) {
117 last_key_code_
= event
->key_code();
121 void ColorTestWindowDelegate::OnWindowDestroyed(Window
* window
) {
125 void ColorTestWindowDelegate::OnPaint(const ui::PaintContext
& context
) {
126 ui::PaintRecorder
recorder(context
, window_size_
);
127 recorder
.canvas()->DrawColor(color_
, SkXfermode::kSrc_Mode
);
130 ////////////////////////////////////////////////////////////////////////////////
131 // MaskedWindowDelegate
133 MaskedWindowDelegate::MaskedWindowDelegate(const gfx::Rect mask_rect
)
134 : mask_rect_(mask_rect
) {
137 bool MaskedWindowDelegate::HasHitTestMask() const {
141 void MaskedWindowDelegate::GetHitTestMask(gfx::Path
* mask
) const {
142 mask
->addRect(RectToSkRect(mask_rect_
));
145 ////////////////////////////////////////////////////////////////////////////////
146 // EventCountDelegate
148 EventCountDelegate::EventCountDelegate()
149 : mouse_enter_count_(0),
150 mouse_move_count_(0),
151 mouse_leave_count_(0),
152 mouse_press_count_(0),
153 mouse_release_count_(0),
155 key_release_count_(0),
159 void EventCountDelegate::OnKeyEvent(ui::KeyEvent
* event
) {
160 switch (event
->type()) {
161 case ui::ET_KEY_PRESSED
:
164 case ui::ET_KEY_RELEASED
:
165 key_release_count_
++;
171 void EventCountDelegate::OnMouseEvent(ui::MouseEvent
* event
) {
172 switch (event
->type()) {
173 case ui::ET_MOUSE_MOVED
:
176 case ui::ET_MOUSE_ENTERED
:
177 mouse_enter_count_
++;
179 case ui::ET_MOUSE_EXITED
:
180 mouse_leave_count_
++;
182 case ui::ET_MOUSE_PRESSED
:
183 mouse_press_count_
++;
185 case ui::ET_MOUSE_RELEASED
:
186 mouse_release_count_
++;
193 void EventCountDelegate::OnGestureEvent(ui::GestureEvent
* event
) {
197 std::string
EventCountDelegate::GetMouseMotionCountsAndReset() {
198 std::string result
= base::StringPrintf("%d %d %d",
202 mouse_enter_count_
= 0;
203 mouse_move_count_
= 0;
204 mouse_leave_count_
= 0;
208 std::string
EventCountDelegate::GetMouseButtonCountsAndReset() {
209 std::string result
= base::StringPrintf("%d %d",
211 mouse_release_count_
);
212 mouse_press_count_
= 0;
213 mouse_release_count_
= 0;
218 std::string
EventCountDelegate::GetKeyCountsAndReset() {
219 std::string result
= base::StringPrintf("%d %d",
222 key_press_count_
= 0;
223 key_release_count_
= 0;
227 int EventCountDelegate::GetGestureCountAndReset() {
228 int gesture_count
= gesture_count_
;
230 return gesture_count
;