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 ui::TextInputClient
* TestWindowDelegate::GetFocusedTextInputClient() {
55 return &text_input_client_
;
58 gfx::NativeCursor
TestWindowDelegate::GetCursor(const gfx::Point
& point
) {
59 return gfx::kNullCursor
;
62 int TestWindowDelegate::GetNonClientComponent(const gfx::Point
& point
) const {
63 return window_component_
;
66 bool TestWindowDelegate::ShouldDescendIntoChildForEventHandling(
68 const gfx::Point
& location
) {
72 bool TestWindowDelegate::CanFocus() {
76 void TestWindowDelegate::OnCaptureLost() {
79 void TestWindowDelegate::OnPaint(const ui::PaintContext
& context
) {
82 void TestWindowDelegate::OnDeviceScaleFactorChanged(
83 float device_scale_factor
) {
86 void TestWindowDelegate::OnWindowDestroying(Window
* window
) {
89 void TestWindowDelegate::OnWindowDestroyed(Window
* window
) {
90 if (delete_on_destroyed_
)
94 void TestWindowDelegate::OnWindowTargetVisibilityChanged(bool visible
) {
97 bool TestWindowDelegate::HasHitTestMask() const {
101 void TestWindowDelegate::GetHitTestMask(gfx::Path
* mask
) const {
104 ////////////////////////////////////////////////////////////////////////////////
105 // ColorTestWindowDelegate
107 ColorTestWindowDelegate::ColorTestWindowDelegate(SkColor color
)
109 last_key_code_(ui::VKEY_UNKNOWN
) {
112 ColorTestWindowDelegate::~ColorTestWindowDelegate() {
115 void ColorTestWindowDelegate::OnKeyEvent(ui::KeyEvent
* event
) {
116 last_key_code_
= event
->key_code();
120 void ColorTestWindowDelegate::OnWindowDestroyed(Window
* window
) {
124 void ColorTestWindowDelegate::OnPaint(const ui::PaintContext
& context
) {
125 ui::PaintRecorder
recorder(context
);
126 recorder
.canvas()->DrawColor(color_
, SkXfermode::kSrc_Mode
);
129 ////////////////////////////////////////////////////////////////////////////////
130 // MaskedWindowDelegate
132 MaskedWindowDelegate::MaskedWindowDelegate(const gfx::Rect mask_rect
)
133 : mask_rect_(mask_rect
) {
136 bool MaskedWindowDelegate::HasHitTestMask() const {
140 void MaskedWindowDelegate::GetHitTestMask(gfx::Path
* mask
) const {
141 mask
->addRect(RectToSkRect(mask_rect_
));
144 ////////////////////////////////////////////////////////////////////////////////
145 // EventCountDelegate
147 EventCountDelegate::EventCountDelegate()
148 : mouse_enter_count_(0),
149 mouse_move_count_(0),
150 mouse_leave_count_(0),
151 mouse_press_count_(0),
152 mouse_release_count_(0),
154 key_release_count_(0),
158 void EventCountDelegate::OnKeyEvent(ui::KeyEvent
* event
) {
159 switch (event
->type()) {
160 case ui::ET_KEY_PRESSED
:
163 case ui::ET_KEY_RELEASED
:
164 key_release_count_
++;
170 void EventCountDelegate::OnMouseEvent(ui::MouseEvent
* event
) {
171 switch (event
->type()) {
172 case ui::ET_MOUSE_MOVED
:
175 case ui::ET_MOUSE_ENTERED
:
176 mouse_enter_count_
++;
178 case ui::ET_MOUSE_EXITED
:
179 mouse_leave_count_
++;
181 case ui::ET_MOUSE_PRESSED
:
182 mouse_press_count_
++;
184 case ui::ET_MOUSE_RELEASED
:
185 mouse_release_count_
++;
192 void EventCountDelegate::OnGestureEvent(ui::GestureEvent
* event
) {
196 std::string
EventCountDelegate::GetMouseMotionCountsAndReset() {
197 std::string result
= base::StringPrintf("%d %d %d",
201 mouse_enter_count_
= 0;
202 mouse_move_count_
= 0;
203 mouse_leave_count_
= 0;
207 std::string
EventCountDelegate::GetMouseButtonCountsAndReset() {
208 std::string result
= base::StringPrintf("%d %d",
210 mouse_release_count_
);
211 mouse_press_count_
= 0;
212 mouse_release_count_
= 0;
217 std::string
EventCountDelegate::GetKeyCountsAndReset() {
218 std::string result
= base::StringPrintf("%d %d",
221 key_press_count_
= 0;
222 key_release_count_
= 0;
226 int EventCountDelegate::GetGestureCountAndReset() {
227 int gesture_count
= gesture_count_
;
229 return gesture_count
;