Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / ui / aura / test / test_window_delegate.h
blob5ee001dde18ca957874ac52966c3c0bc3b5c307e
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 #ifndef UI_AURA_TEST_TEST_WINDOW_DELEGATE_H_
6 #define UI_AURA_TEST_TEST_WINDOW_DELEGATE_H_
8 #include <string>
10 #include "base/compiler_specific.h"
11 #include "third_party/skia/include/core/SkColor.h"
12 #include "ui/aura/window_delegate.h"
13 #include "ui/events/keycodes/keyboard_codes.h"
14 #include "ui/gfx/geometry/rect.h"
16 namespace aura {
17 namespace test {
19 // WindowDelegate implementation with all methods stubbed out.
20 class TestWindowDelegate : public WindowDelegate {
21 public:
22 TestWindowDelegate();
23 ~TestWindowDelegate() override;
25 // Returns a TestWindowDelegate that delete itself when
26 // the associated window is destroyed.
27 static TestWindowDelegate* CreateSelfDestroyingDelegate();
29 void set_window_component(int window_component) {
30 window_component_ = window_component;
33 void set_minimum_size(const gfx::Size& minimum_size) {
34 minimum_size_ = minimum_size;
37 void set_maximum_size(const gfx::Size& maximum_size) {
38 maximum_size_ = maximum_size;
41 // Sets the return value for CanFocus(). Default is true.
42 void set_can_focus(bool can_focus) { can_focus_ = can_focus; }
44 // Overridden from WindowDelegate:
45 gfx::Size GetMinimumSize() const override;
46 gfx::Size GetMaximumSize() const override;
47 void OnBoundsChanged(const gfx::Rect& old_bounds,
48 const gfx::Rect& new_bounds) override;
49 gfx::NativeCursor GetCursor(const gfx::Point& point) override;
50 int GetNonClientComponent(const gfx::Point& point) const override;
51 bool ShouldDescendIntoChildForEventHandling(
52 Window* child,
53 const gfx::Point& location) override;
54 bool CanFocus() override;
55 void OnCaptureLost() override;
56 void OnPaint(const ui::PaintContext& context) override;
57 void OnDeviceScaleFactorChanged(float device_scale_factor) override;
58 void OnWindowDestroying(Window* window) override;
59 void OnWindowDestroyed(Window* window) override;
60 void OnWindowTargetVisibilityChanged(bool visible) override;
61 bool HasHitTestMask() const override;
62 void GetHitTestMask(gfx::Path* mask) const override;
64 private:
65 int window_component_;
66 bool delete_on_destroyed_;
67 gfx::Size minimum_size_;
68 gfx::Size maximum_size_;
69 bool can_focus_;
71 DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate);
74 // A simple WindowDelegate implementation for these tests. It owns itself
75 // (deletes itself when the Window it is attached to is destroyed).
76 class ColorTestWindowDelegate : public TestWindowDelegate {
77 public:
78 explicit ColorTestWindowDelegate(SkColor color);
79 ~ColorTestWindowDelegate() override;
81 ui::KeyboardCode last_key_code() const { return last_key_code_; }
83 // Overridden from TestWindowDelegate:
84 void OnBoundsChanged(const gfx::Rect& old_bounds,
85 const gfx::Rect& new_bounds) override;
86 void OnKeyEvent(ui::KeyEvent* event) override;
87 void OnWindowDestroyed(Window* window) override;
88 void OnPaint(const ui::PaintContext& context) override;
90 private:
91 SkColor color_;
92 ui::KeyboardCode last_key_code_;
93 gfx::Size window_size_;
95 DISALLOW_COPY_AND_ASSIGN(ColorTestWindowDelegate);
98 // A simple WindowDelegate that has a hit-test mask.
99 class MaskedWindowDelegate : public TestWindowDelegate {
100 public:
101 explicit MaskedWindowDelegate(const gfx::Rect mask_rect);
103 // Overridden from TestWindowDelegate:
104 bool HasHitTestMask() const override;
105 void GetHitTestMask(gfx::Path* mask) const override;
107 private:
108 gfx::Rect mask_rect_;
110 DISALLOW_COPY_AND_ASSIGN(MaskedWindowDelegate);
113 // Keeps track of mouse/key events.
114 class EventCountDelegate : public TestWindowDelegate {
115 public:
116 EventCountDelegate();
118 // Overridden from TestWindowDelegate:
119 void OnKeyEvent(ui::KeyEvent* event) override;
120 void OnMouseEvent(ui::MouseEvent* event) override;
121 void OnGestureEvent(ui::GestureEvent* event) override;
123 // Returns the counts of mouse motion events in the
124 // form of "<enter> <move> <leave>".
125 std::string GetMouseMotionCountsAndReset();
127 // Returns the counts of mouse button events in the
128 // form of "<press> <release>".
129 std::string GetMouseButtonCountsAndReset();
131 // Returns the counts of key events in the form of
132 // "<press> <release>".
133 std::string GetKeyCountsAndReset();
135 // Returns number of gesture events.
136 int GetGestureCountAndReset();
138 private:
139 int mouse_enter_count_;
140 int mouse_move_count_;
141 int mouse_leave_count_;
142 int mouse_press_count_;
143 int mouse_release_count_;
144 int key_press_count_;
145 int key_release_count_;
146 int gesture_count_;
148 DISALLOW_COPY_AND_ASSIGN(EventCountDelegate);
151 } // namespace test
152 } // namespace aura
154 #endif // UI_AURA_TEST_TEST_WINDOW_DELEGATE_H_