| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_AURA_TEST_EVENT_GENERATOR_H_ | 5 #ifndef UI_AURA_TEST_EVENT_GENERATOR_H_ |
| 6 #define UI_AURA_TEST_EVENT_GENERATOR_H_ | 6 #define UI_AURA_TEST_EVENT_GENERATOR_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 9 #include "ui/base/keycodes/keyboard_codes.h" | 10 #include "ui/base/keycodes/keyboard_codes.h" |
| 10 #include "ui/gfx/point.h" | 11 #include "ui/gfx/point.h" |
| 11 | 12 |
| 12 namespace base { | 13 namespace base { |
| 13 class TimeDelta; | 14 class TimeDelta; |
| 14 } | 15 } |
| 15 | 16 |
| 16 namespace ui { | 17 namespace ui { |
| 17 class Event; | 18 class Event; |
| 18 } | 19 } |
| 19 | 20 |
| 20 namespace aura { | 21 namespace aura { |
| 21 class RootWindow; | 22 class RootWindow; |
| 22 class Window; | 23 class Window; |
| 23 | 24 |
| 25 namespace client { |
| 26 class ScreenPositionClient; |
| 27 } |
| 28 |
| 24 namespace test { | 29 namespace test { |
| 25 | 30 |
| 26 // EventGenerator is a tool that generates and dispatch events. | 31 // A delegate interface for EventGenerator that provides a way to |
| 32 // locate aura root window for given point. |
| 33 class EventGeneratorDelegate { |
| 34 public: |
| 35 virtual ~EventGeneratorDelegate() {} |
| 36 |
| 37 // Returns a root window for given point. |
| 38 virtual RootWindow* GetRootWindowAt(const gfx::Point& point) const = 0; |
| 39 |
| 40 // Returns the screen position client that determines the |
| 41 // coordinates used in EventGenerator. EventGenerator uses |
| 42 // RootWindow's coordinate if this retruns NULL. |
| 43 virtual client::ScreenPositionClient* GetScreenPositionClient( |
| 44 const aura::Window* window) const = 0; |
| 45 }; |
| 46 |
| 47 // EventGenerator is a tool that generates and dispatch events. The |
| 48 // coordinates of the points in API is determined by the |
| 49 // EventGeneratorDelegate. |
| 27 class EventGenerator { | 50 class EventGenerator { |
| 28 public: | 51 public: |
| 29 // Creates an EventGenerator with the mouse/touch location (0,0). | 52 // Creates an EventGenerator with the mouse/touch location (0,0), |
| 53 // which uses the |root_window|'s coordinates. |
| 30 explicit EventGenerator(RootWindow* root_window); | 54 explicit EventGenerator(RootWindow* root_window); |
| 31 | 55 |
| 56 // Create an EventGenerator with EventGeneratorDelegate, |
| 57 // which uses the coordinates used by |delegate|. |
| 58 explicit EventGenerator(EventGeneratorDelegate* delegate); |
| 59 |
| 32 // Creates an EventGenerator with the mouse/touch location | 60 // Creates an EventGenerator with the mouse/touch location |
| 33 // at |initial_location|. | 61 // at |initial_location|, which uses the |root_window|'s coordinates. |
| 34 EventGenerator(RootWindow* root_window, const gfx::Point& initial_location); | 62 EventGenerator(RootWindow* root_window, const gfx::Point& initial_location); |
| 35 | 63 |
| 36 // Creates an EventGenerator with the mouse/touch location | 64 // Creates an EventGenerator with the mouse/touch location |
| 37 // centered over |window|. | 65 // centered over |window|, which uses the |root_window|'s coordinates. |
| 38 EventGenerator(RootWindow* root_window, Window* window); | 66 EventGenerator(RootWindow* root_window, Window* window); |
| 39 | 67 |
| 40 virtual ~EventGenerator(); | 68 virtual ~EventGenerator(); |
| 41 | 69 |
| 42 // Explicitly sets the location used by mouse/touch events. This is set by the | 70 // Explicitly sets the location used by mouse/touch events. This is set by the |
| 43 // various methods that take a location but can be manipulated directly, | 71 // various methods that take a location but can be manipulated directly, |
| 44 // typically for touch. | 72 // typically for touch. |
| 45 void set_current_location(const gfx::Point& location) { | 73 void set_current_location(const gfx::Point& location) { |
| 46 current_location_ = location; | 74 current_location_ = location; |
| 47 } | 75 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 197 |
| 170 // Generates a key release event. On platforms except Windows and X11, a key | 198 // Generates a key release event. On platforms except Windows and X11, a key |
| 171 // event without native_event() is generated. Note that ui::EF_ flags should | 199 // event without native_event() is generated. Note that ui::EF_ flags should |
| 172 // be passed as |flags|, not the native ones like 'ShiftMask' in <X11/X.h>. | 200 // be passed as |flags|, not the native ones like 'ShiftMask' in <X11/X.h>. |
| 173 // TODO(yusukes): Support native_event() on all platforms. | 201 // TODO(yusukes): Support native_event() on all platforms. |
| 174 void ReleaseKey(ui::KeyboardCode key_code, int flags); | 202 void ReleaseKey(ui::KeyboardCode key_code, int flags); |
| 175 | 203 |
| 176 // Dispatch the |event| to the RootWindow. | 204 // Dispatch the |event| to the RootWindow. |
| 177 void Dispatch(ui::Event& event); | 205 void Dispatch(ui::Event& event); |
| 178 | 206 |
| 207 void set_current_root_window(RootWindow* root_window) { |
| 208 current_root_window_ = root_window; |
| 209 } |
| 210 |
| 179 private: | 211 private: |
| 180 // Dispatch a key event to the RootWindow. | 212 // Dispatch a key event to the RootWindow. |
| 181 void DispatchKeyEvent(bool is_press, ui::KeyboardCode key_code, int flags); | 213 void DispatchKeyEvent(bool is_press, ui::KeyboardCode key_code, int flags); |
| 182 | 214 |
| 183 RootWindow* root_window_; | 215 void UpdateCurrentRootWindow(const gfx::Point& point); |
| 216 void PressButton(int flag); |
| 217 void ReleaseButton(int flag); |
| 218 |
| 219 // Convert a point between API's coordinates and |
| 220 // |target|'s coordinates. |
| 221 void ConvertPointFromTarget(const aura::Window* target, |
| 222 gfx::Point* point) const; |
| 223 void ConvertPointToTarget(const aura::Window* target, |
| 224 gfx::Point* point) const; |
| 225 |
| 226 gfx::Point GetLocationInCurrentRoot() const; |
| 227 gfx::Point CenterOfWindow(const Window* window) const; |
| 228 |
| 229 scoped_ptr<EventGeneratorDelegate> delegate_; |
| 230 gfx::Point current_location_; |
| 231 RootWindow* current_root_window_; |
| 184 int flags_; | 232 int flags_; |
| 185 gfx::Point current_location_; | 233 bool grab_; |
| 186 | 234 |
| 187 DISALLOW_COPY_AND_ASSIGN(EventGenerator); | 235 DISALLOW_COPY_AND_ASSIGN(EventGenerator); |
| 188 }; | 236 }; |
| 189 | 237 |
| 190 } // namespace test | 238 } // namespace test |
| 191 } // namespace aura | 239 } // namespace aura |
| 192 | 240 |
| 193 #endif // UI_AURA_TEST_EVENT_GENERATOR_H_ | 241 #endif // UI_AURA_TEST_EVENT_GENERATOR_H_ |
| OLD | NEW |