| Index: ui/events/test/event_generator.h
|
| diff --git a/ui/aura/test/event_generator.h b/ui/events/test/event_generator.h
|
| similarity index 76%
|
| copy from ui/aura/test/event_generator.h
|
| copy to ui/events/test/event_generator.h
|
| index c436d3fbd1165571fdcaaf950577ca499dbaa3e2..3aa3664b382e838c2460cd928508b33b50def27d 100644
|
| --- a/ui/aura/test/event_generator.h
|
| +++ b/ui/events/test/event_generator.h
|
| @@ -1,9 +1,9 @@
|
| -// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#ifndef UI_AURA_TEST_EVENT_GENERATOR_H_
|
| -#define UI_AURA_TEST_EVENT_GENERATOR_H_
|
| +#ifndef UI_EVENTS_TEST_EVENT_GENERATOR_H_
|
| +#define UI_EVENTS_TEST_EVENT_GENERATOR_H_
|
|
|
| #include <list>
|
| #include <vector>
|
| @@ -14,6 +14,7 @@
|
| #include "base/time/time.h"
|
| #include "ui/events/event_constants.h"
|
| #include "ui/events/keycodes/keyboard_codes.h"
|
| +#include "ui/gfx/native_widget_types.h"
|
| #include "ui/gfx/point.h"
|
|
|
| namespace base {
|
| @@ -23,44 +24,49 @@ class TickClock;
|
| namespace ui {
|
| class Event;
|
| class EventProcessor;
|
| +class EventSource;
|
| +class EventTarget;
|
| class KeyEvent;
|
| class MouseEvent;
|
| class ScrollEvent;
|
| class TouchEvent;
|
| -}
|
| -
|
| -namespace aura {
|
| -class Window;
|
| -class WindowTreeHost;
|
| -
|
| -namespace client {
|
| -class ScreenPositionClient;
|
| -}
|
|
|
| namespace test {
|
|
|
| -typedef base::Callback<void(ui::EventType, const gfx::Vector2dF&)>
|
| +typedef base::Callback<void(EventType, const gfx::Vector2dF&)>
|
| ScrollStepCallback;
|
|
|
| -// A delegate interface for EventGenerator that provides a way to
|
| -// locate aura root window for given point.
|
| +// A delegate interface for EventGenerator to abstract platform-specific event
|
| +// targeting and coordinate conversion.
|
| class EventGeneratorDelegate {
|
| public:
|
| virtual ~EventGeneratorDelegate() {}
|
|
|
| - // Returns the host for given point.
|
| - virtual WindowTreeHost* GetHostAt(const gfx::Point& point) const = 0;
|
| + // The ui::EventTarget at the given |location|.
|
| + virtual EventTarget* GetTargetAt(const gfx::Point& location) = 0;
|
| +
|
| + // The ui::EventSource for the given |target|.
|
| + virtual EventSource* GetEventSource(EventTarget* target) = 0;
|
| +
|
| + // Helper functions to determine the center point of |target| or |window|.
|
| + virtual gfx::Point CenterOfTarget(const EventTarget* target) const = 0;
|
| + virtual gfx::Point CenterOfWindow(gfx::NativeWindow window) const = 0;
|
|
|
| - // Returns the screen position client that determines the
|
| - // coordinates used in EventGenerator. EventGenerator uses
|
| - // root Window's coordinate if this returns NULL.
|
| - virtual client::ScreenPositionClient* GetScreenPositionClient(
|
| - const aura::Window* window) const = 0;
|
| + // Convert a point between API's coordinates and |target|'s coordinates.
|
| + virtual void ConvertPointFromTarget(const EventTarget* target,
|
| + gfx::Point* point) const = 0;
|
| + virtual void ConvertPointToTarget(const EventTarget* target,
|
| + gfx::Point* point) const = 0;
|
| +
|
| + // Convert a point from the coordinate system in the host that contains
|
| + // |hosted_target| into the root window's coordinate system.
|
| + virtual void ConvertPointFromHost(const EventTarget* hosted_target,
|
| + gfx::Point* point) const = 0;
|
| };
|
|
|
| -// EventGenerator is a tool that generates and dispatch events.
|
| -// Unlike |ui_controls| package in ui/base/test, this does not generate platform
|
| -// native events. Instead, it sends events to |aura::WindowEventDispatcher|
|
| +// ui::test::EventGenerator is a tool that generates and dispatches events.
|
| +// Unlike |ui_controls| package in ui/base/test, this does not use platform
|
| +// native message loops. Instead, it sends events to the event dispatcher
|
| // synchronously.
|
| //
|
| // This class is not suited for the following cases:
|
| @@ -72,7 +78,7 @@ class EventGeneratorDelegate {
|
| // post an event to WindowEventDispatcher, this event will not be
|
| // handled in the nested message loop.
|
| // 3) Similarly, |base::MessagePumpObserver| will not be invoked.
|
| -// 4) Any other code that requires native events, such as
|
| +// 4) Any other code that requires native message loops, such as
|
| // tests for WindowTreeHostWin/WindowTreeHostX11.
|
| //
|
| // If one of these applies to your test, please use |ui_controls|
|
| @@ -83,20 +89,24 @@ class EventGeneratorDelegate {
|
| class EventGenerator {
|
| public:
|
| // Creates an EventGenerator with the mouse/touch location (0,0),
|
| - // which uses the |root_window|'s coordinates.
|
| - explicit EventGenerator(Window* root_window);
|
| + // which uses the |root_window|'s coordinates and the default delegate for
|
| + // this platform.
|
| + explicit EventGenerator(gfx::NativeWindow root_window);
|
|
|
| // Create an EventGenerator with EventGeneratorDelegate,
|
| - // which uses the coordinates used by |delegate|.
|
| + // which uses the coordinates conversions and targeting provided by
|
| + // |delegate|.
|
| explicit EventGenerator(EventGeneratorDelegate* delegate);
|
|
|
| // Creates an EventGenerator with the mouse/touch location
|
| // at |initial_location|, which uses the |root_window|'s coordinates.
|
| - EventGenerator(Window* root_window, const gfx::Point& initial_location);
|
| + EventGenerator(gfx::NativeWindow root_window,
|
| + const gfx::Point& initial_location);
|
|
|
| - // Creates an EventGenerator with the mouse/touch location
|
| - // centered over |window|, which uses the |root_window|'s coordinates.
|
| - EventGenerator(Window* root_window, Window* window);
|
| + // Creates an EventGenerator with the mouse/touch location centered over
|
| + // |window|. This is currently the only constructor that works on Mac, since
|
| + // a specific window is required (and there is no root window).
|
| + EventGenerator(gfx::NativeWindow root_window, gfx::NativeWindow window);
|
|
|
| virtual ~EventGenerator();
|
|
|
| @@ -113,6 +123,7 @@ class EventGenerator {
|
|
|
| // Resets the event flags bitmask.
|
| void set_flags(int flags) { flags_ = flags; }
|
| + int flags() const { return flags_; }
|
|
|
| // Generates a left button press event.
|
| void PressLeftButton();
|
| @@ -157,8 +168,8 @@ class EventGenerator {
|
|
|
| // Generates events to move mouse to be the given |point| in |window|'s
|
| // coordinates.
|
| - void MoveMouseRelativeTo(const Window* window, const gfx::Point& point);
|
| - void MoveMouseRelativeTo(const Window* window, int x, int y) {
|
| + void MoveMouseRelativeTo(const EventTarget* window, const gfx::Point& point);
|
| + void MoveMouseRelativeTo(const EventTarget* window, int x, int y) {
|
| MoveMouseRelativeTo(window, gfx::Point(x, y));
|
| }
|
|
|
| @@ -178,7 +189,7 @@ class EventGenerator {
|
| }
|
|
|
| // Generates events to move the mouse to the center of the window.
|
| - void MoveMouseToCenterOf(Window* window);
|
| + void MoveMouseToCenterOf(EventTarget* window);
|
|
|
| // Generates a touch press event.
|
| void PressTouch();
|
| @@ -212,7 +223,7 @@ class EventGenerator {
|
|
|
| // Generates press, move and release events to move touch
|
| // to the center of the window.
|
| - void PressMoveAndReleaseTouchToCenterOf(Window* window);
|
| + void PressMoveAndReleaseTouchToCenterOf(EventTarget* window);
|
|
|
| // Generates and dispatches a Win8 edge-swipe event (swipe up from bottom or
|
| // swipe down from top). Note that it is not possible to distinguish between
|
| @@ -303,19 +314,19 @@ class EventGenerator {
|
| // event without native_event() is generated. Note that ui::EF_ flags should
|
| // be passed as |flags|, not the native ones like 'ShiftMask' in <X11/X.h>.
|
| // TODO(yusukes): Support native_event() on all platforms.
|
| - void PressKey(ui::KeyboardCode key_code, int flags);
|
| + void PressKey(KeyboardCode key_code, int flags);
|
|
|
| // Generates a key release event. On platforms except Windows and X11, a key
|
| // event without native_event() is generated. Note that ui::EF_ flags should
|
| // be passed as |flags|, not the native ones like 'ShiftMask' in <X11/X.h>.
|
| // TODO(yusukes): Support native_event() on all platforms.
|
| - void ReleaseKey(ui::KeyboardCode key_code, int flags);
|
| + void ReleaseKey(KeyboardCode key_code, int flags);
|
|
|
| // Dispatch the event to the WindowEventDispatcher.
|
| - void Dispatch(ui::Event* event);
|
| + void Dispatch(Event* event);
|
|
|
| - void set_current_host(WindowTreeHost* host) {
|
| - current_host_ = host;
|
| + void set_current_target(EventTarget* target) {
|
| + current_target_ = target;
|
| }
|
|
|
| // Specify an alternative tick clock to be used for simulating time in tests.
|
| @@ -324,33 +335,35 @@ class EventGenerator {
|
| // Get the current time from the tick clock.
|
| base::TimeDelta Now();
|
|
|
| + protected:
|
| + EventGeneratorDelegate* delegate() { return delegate_.get(); }
|
| +
|
| private:
|
| + // Implemented per-platform to create the default EventGeneratorDelegate.
|
| + static EventGeneratorDelegate* CreateDefaultPlatformDelegate(
|
| + EventGenerator* owner,
|
| + gfx::NativeWindow root_window,
|
| + gfx::NativeWindow window);
|
| +
|
| // Dispatch a key event to the WindowEventDispatcher.
|
| - void DispatchKeyEvent(bool is_press, ui::KeyboardCode key_code, int flags);
|
| + void DispatchKeyEvent(bool is_press, KeyboardCode key_code, int flags);
|
|
|
| void UpdateCurrentDispatcher(const gfx::Point& point);
|
| void PressButton(int flag);
|
| void ReleaseButton(int flag);
|
|
|
| - // Convert a point between API's coordinates and
|
| - // |target|'s coordinates.
|
| - void ConvertPointFromTarget(const aura::Window* target,
|
| - gfx::Point* point) const;
|
| - void ConvertPointToTarget(const aura::Window* target,
|
| - gfx::Point* point) const;
|
| -
|
| gfx::Point GetLocationInCurrentRoot() const;
|
| - gfx::Point CenterOfWindow(const Window* window) const;
|
| + gfx::Point CenterOfWindow(const EventTarget* window) const;
|
|
|
| void DispatchNextPendingEvent();
|
| - void DoDispatchEvent(ui::Event* event, bool async);
|
| + void DoDispatchEvent(Event* event, bool async);
|
|
|
| scoped_ptr<EventGeneratorDelegate> delegate_;
|
| gfx::Point current_location_;
|
| - WindowTreeHost* current_host_;
|
| + EventTarget* current_target_;
|
| int flags_;
|
| bool grab_;
|
| - std::list<ui::Event*> pending_events_;
|
| + std::list<Event*> pending_events_;
|
| // Set to true to cause events to be posted asynchronously.
|
| bool async_;
|
| scoped_ptr<base::TickClock> tick_clock_;
|
| @@ -359,6 +372,6 @@ class EventGenerator {
|
| };
|
|
|
| } // namespace test
|
| -} // namespace aura
|
| +} // namespace ui
|
|
|
| -#endif // UI_AURA_TEST_EVENT_GENERATOR_H_
|
| +#endif // UI_EVENTS_TEST_EVENT_GENERATOR_H_
|
|
|