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_
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/base/ime/dummy_text_input_client.h"
14 #include "ui/events/keycodes/keyboard_codes.h"
15 #include "ui/gfx/geometry/rect.h"
20 // WindowDelegate implementation with all methods stubbed out.
21 class TestWindowDelegate
: public WindowDelegate
{
24 ~TestWindowDelegate() override
;
26 // Returns a TestWindowDelegate that delete itself when
27 // the associated window is destroyed.
28 static TestWindowDelegate
* CreateSelfDestroyingDelegate();
30 void set_window_component(int window_component
) {
31 window_component_
= window_component
;
34 void set_minimum_size(const gfx::Size
& minimum_size
) {
35 minimum_size_
= minimum_size
;
38 void set_maximum_size(const gfx::Size
& maximum_size
) {
39 maximum_size_
= maximum_size
;
42 // Sets the return value for CanFocus(). Default is true.
43 void set_can_focus(bool can_focus
) { can_focus_
= can_focus
; }
45 // Overridden from WindowDelegate:
46 gfx::Size
GetMinimumSize() const override
;
47 gfx::Size
GetMaximumSize() const override
;
48 void OnBoundsChanged(const gfx::Rect
& old_bounds
,
49 const gfx::Rect
& new_bounds
) override
;
50 ui::TextInputClient
* GetFocusedTextInputClient() override
;
51 gfx::NativeCursor
GetCursor(const gfx::Point
& point
) override
;
52 int GetNonClientComponent(const gfx::Point
& point
) const override
;
53 bool ShouldDescendIntoChildForEventHandling(
55 const gfx::Point
& location
) override
;
56 bool CanFocus() override
;
57 void OnCaptureLost() override
;
58 void OnPaint(const ui::PaintContext
& context
) override
;
59 void OnDeviceScaleFactorChanged(float device_scale_factor
) override
;
60 void OnWindowDestroying(Window
* window
) override
;
61 void OnWindowDestroyed(Window
* window
) override
;
62 void OnWindowTargetVisibilityChanged(bool visible
) override
;
63 bool HasHitTestMask() const override
;
64 void GetHitTestMask(gfx::Path
* mask
) const override
;
67 int window_component_
;
68 bool delete_on_destroyed_
;
69 gfx::Size minimum_size_
;
70 gfx::Size maximum_size_
;
71 ui::DummyTextInputClient text_input_client_
;
74 DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate
);
77 // A simple WindowDelegate implementation for these tests. It owns itself
78 // (deletes itself when the Window it is attached to is destroyed).
79 class ColorTestWindowDelegate
: public TestWindowDelegate
{
81 explicit ColorTestWindowDelegate(SkColor color
);
82 ~ColorTestWindowDelegate() override
;
84 ui::KeyboardCode
last_key_code() const { return last_key_code_
; }
86 // Overridden from TestWindowDelegate:
87 void OnKeyEvent(ui::KeyEvent
* event
) override
;
88 void OnWindowDestroyed(Window
* window
) override
;
89 void OnPaint(const ui::PaintContext
& context
) override
;
93 ui::KeyboardCode last_key_code_
;
95 DISALLOW_COPY_AND_ASSIGN(ColorTestWindowDelegate
);
98 // A simple WindowDelegate that has a hit-test mask.
99 class MaskedWindowDelegate
: public TestWindowDelegate
{
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
;
108 gfx::Rect mask_rect_
;
110 DISALLOW_COPY_AND_ASSIGN(MaskedWindowDelegate
);
113 // Keeps track of mouse/key events.
114 class EventCountDelegate
: public TestWindowDelegate
{
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();
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_
;
148 DISALLOW_COPY_AND_ASSIGN(EventCountDelegate
);
154 #endif // UI_AURA_TEST_TEST_WINDOW_DELEGATE_H_