Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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. | |
| 4 | |
| 5 #ifndef UI_BASE_TEST_EVENT_GENERATOR_BASE_H_ | |
|
Ben Goodger (Google)
2014/07/11 18:26:50
I think this should go into ui/events/test rather
tapted
2014/07/14 11:37:47
Done.
| |
| 6 #define UI_BASE_TEST_EVENT_GENERATOR_BASE_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "ui/events/event_constants.h" | |
| 10 #include "ui/gfx/geometry/point.h" | |
| 11 | |
| 12 namespace ui { | |
| 13 namespace test { | |
| 14 | |
| 15 // Common base class for generating and dispatching platform-specific events. | |
| 16 // Unlike |ui_controls|, events are dispatched directly to the EventProcessor. | |
| 17 // MessageLoops are not used, and this interface is not suited to tests that | |
| 18 // require a RunLoop. | |
| 19 class EventGeneratorBase { | |
| 20 public: | |
| 21 explicit EventGeneratorBase(const gfx::Point& initial_location); | |
| 22 virtual ~EventGeneratorBase(); | |
| 23 | |
| 24 // Explicitly sets the location used by mouse/touch events. This is set by the | |
| 25 // various methods that take a location but can be manipulated directly, | |
| 26 // typically for touch. | |
| 27 void set_current_location(const gfx::Point& location) { | |
| 28 current_location_ = location; | |
| 29 } | |
| 30 const gfx::Point& current_location() const { return current_location_; } | |
| 31 | |
| 32 // Resets the event flags bitmask. | |
| 33 void set_flags(int flags) { flags_ = flags; } | |
| 34 int flags() const { return flags_; } | |
| 35 | |
| 36 bool grab() const { return grab_; } | |
| 37 | |
| 38 // Generates a left button press event. | |
| 39 void PressLeftButton(); | |
| 40 | |
| 41 // Generates a left button release event. | |
| 42 void ReleaseLeftButton(); | |
| 43 | |
| 44 // Generates events to click (press, release) left button. | |
| 45 void ClickLeftButton(); | |
| 46 | |
| 47 // Generates a double click event using the left button. | |
| 48 void DoubleClickLeftButton(); | |
| 49 | |
| 50 // Generates a right button press event. | |
| 51 void PressRightButton(); | |
| 52 | |
| 53 // Generates a right button release event. | |
| 54 void ReleaseRightButton(); | |
| 55 | |
| 56 // Generates events to move mouse to be the given |point| in screen | |
| 57 // coordinates. | |
| 58 void MoveMouseTo(const gfx::Point& point_in_screen, int count) { | |
| 59 DoMoveMouseTo(point_in_screen, count); | |
| 60 } | |
| 61 void MoveMouseTo(const gfx::Point& point_in_screen) { | |
| 62 MoveMouseTo(point_in_screen, 1); | |
| 63 } | |
| 64 void MoveMouseTo(int x, int y) { | |
| 65 MoveMouseTo(gfx::Point(x, y)); | |
| 66 } | |
| 67 | |
| 68 // Generates events to drag mouse to given |point|. | |
| 69 void DragMouseTo(const gfx::Point& point); | |
| 70 | |
| 71 void DragMouseTo(int x, int y) { | |
| 72 DragMouseTo(gfx::Point(x, y)); | |
| 73 } | |
| 74 | |
| 75 void DragMouseBy(int dx, int dy) { | |
| 76 DragMouseTo(current_location_ + gfx::Vector2d(dx, dy)); | |
| 77 } | |
| 78 | |
| 79 protected: | |
| 80 virtual gfx::Point GetLocationInCurrentRoot() const = 0; | |
| 81 virtual void DoMoveMouseTo(const gfx::Point& point_in_screen, int count) = 0; | |
| 82 virtual void DispatchMouseEvent(EventType type, | |
| 83 const gfx::Point& location_in_root, | |
| 84 int flags, | |
| 85 int changed_button_flags) = 0; | |
| 86 | |
| 87 void PressButton(int flag); | |
| 88 void ReleaseButton(int flag); | |
| 89 | |
| 90 private: | |
| 91 gfx::Point current_location_; | |
| 92 | |
| 93 // Current ui::EventFlag state. | |
| 94 int flags_; | |
| 95 | |
| 96 // Whether the event dispatcher should receive mousemove updates. | |
| 97 bool grab_; | |
| 98 | |
| 99 DISALLOW_COPY_AND_ASSIGN(EventGeneratorBase); | |
| 100 }; | |
| 101 | |
| 102 } // namespace test | |
| 103 } // namespace ui | |
| 104 | |
| 105 #endif // UI_BASE_TEST_EVENT_GENERATOR_BASE_H_ | |
| OLD | NEW |