Remove ExtensionPrefs::SetDidExtensionEscalatePermissions.
[chromium-blink-merge.git] / ui / aura / test / test_window_delegate.cc
blob4b0f8b77a03ded1928c71e9ca7bac16e1e2daca2
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"
16 #if defined(USE_AURA)
17 #include "ui/base/cursor/cursor.h"
18 #endif
20 namespace aura {
21 namespace test {
23 ////////////////////////////////////////////////////////////////////////////////
24 // TestWindowDelegate
26 TestWindowDelegate::TestWindowDelegate()
27 : window_component_(HTCLIENT),
28 delete_on_destroyed_(false),
29 can_focus_(true) {
32 TestWindowDelegate::~TestWindowDelegate() {
35 // static
36 TestWindowDelegate* TestWindowDelegate::CreateSelfDestroyingDelegate() {
37 TestWindowDelegate* delegate = new TestWindowDelegate;
38 delegate->delete_on_destroyed_ = true;
39 return delegate;
42 gfx::Size TestWindowDelegate::GetMinimumSize() const {
43 return minimum_size_;
46 gfx::Size TestWindowDelegate::GetMaximumSize() const {
47 return maximum_size_;
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(
67 Window* child,
68 const gfx::Point& location) {
69 return true;
72 bool TestWindowDelegate::CanFocus() {
73 return can_focus_;
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_)
91 delete this;
94 void TestWindowDelegate::OnWindowTargetVisibilityChanged(bool visible) {
97 bool TestWindowDelegate::HasHitTestMask() const {
98 return false;
101 void TestWindowDelegate::GetHitTestMask(gfx::Path* mask) const {
104 ////////////////////////////////////////////////////////////////////////////////
105 // ColorTestWindowDelegate
107 ColorTestWindowDelegate::ColorTestWindowDelegate(SkColor color)
108 : color_(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();
117 event->SetHandled();
120 void ColorTestWindowDelegate::OnWindowDestroyed(Window* window) {
121 delete this;
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 {
137 return true;
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),
153 key_press_count_(0),
154 key_release_count_(0),
155 gesture_count_(0) {
158 void EventCountDelegate::OnKeyEvent(ui::KeyEvent* event) {
159 switch (event->type()) {
160 case ui::ET_KEY_PRESSED:
161 key_press_count_++;
162 break;
163 case ui::ET_KEY_RELEASED:
164 key_release_count_++;
165 default:
166 break;
170 void EventCountDelegate::OnMouseEvent(ui::MouseEvent* event) {
171 switch (event->type()) {
172 case ui::ET_MOUSE_MOVED:
173 mouse_move_count_++;
174 break;
175 case ui::ET_MOUSE_ENTERED:
176 mouse_enter_count_++;
177 break;
178 case ui::ET_MOUSE_EXITED:
179 mouse_leave_count_++;
180 break;
181 case ui::ET_MOUSE_PRESSED:
182 mouse_press_count_++;
183 break;
184 case ui::ET_MOUSE_RELEASED:
185 mouse_release_count_++;
186 break;
187 default:
188 break;
192 void EventCountDelegate::OnGestureEvent(ui::GestureEvent* event) {
193 gesture_count_++;
196 std::string EventCountDelegate::GetMouseMotionCountsAndReset() {
197 std::string result = base::StringPrintf("%d %d %d",
198 mouse_enter_count_,
199 mouse_move_count_,
200 mouse_leave_count_);
201 mouse_enter_count_ = 0;
202 mouse_move_count_ = 0;
203 mouse_leave_count_ = 0;
204 return result;
207 std::string EventCountDelegate::GetMouseButtonCountsAndReset() {
208 std::string result = base::StringPrintf("%d %d",
209 mouse_press_count_,
210 mouse_release_count_);
211 mouse_press_count_ = 0;
212 mouse_release_count_ = 0;
213 return result;
217 std::string EventCountDelegate::GetKeyCountsAndReset() {
218 std::string result = base::StringPrintf("%d %d",
219 key_press_count_,
220 key_release_count_);
221 key_press_count_ = 0;
222 key_release_count_ = 0;
223 return result;
226 int EventCountDelegate::GetGestureCountAndReset() {
227 int gesture_count = gesture_count_;
228 gesture_count_ = 0;
229 return gesture_count;
232 } // namespace test
233 } // namespace aura