Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Unified Diff: ui/events/test/event_generator.cc

Issue 322893005: MacViews: Add WidgetEventGenerator to abstract platform-specific event generation for tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: No inheritance Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/events/test/event_generator.cc
diff --git a/ui/aura/test/event_generator.cc b/ui/events/test/event_generator.cc
similarity index 83%
copy from ui/aura/test/event_generator.cc
copy to ui/events/test/event_generator.cc
index a2f36d2207a731e6841e56d3939df625f71190e9..6eff2d1ae838da59f782330fb51f1a62f217ee38 100644
--- a/ui/aura/test/event_generator.cc
+++ b/ui/events/test/event_generator.cc
@@ -1,16 +1,14 @@
-// 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.
-#include "ui/aura/test/event_generator.h"
+#include "ui/events/test/event_generator.h"
#include "base/bind.h"
+#include "base/location.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/time/default_tick_clock.h"
-#include "ui/aura/client/screen_position_client.h"
-#include "ui/aura/window_event_dispatcher.h"
-#include "ui/aura/window_tree_host.h"
#include "ui/events/event.h"
#include "ui/events/event_source.h"
#include "ui/events/event_utils.h"
@@ -19,8 +17,6 @@
#if defined(USE_X11)
#include <X11/Xlib.h>
-#include "ui/base/x/x11_util.h"
-#include "ui/events/event_utils.h"
#include "ui/events/test/events_test_utils_x11.h"
#endif
@@ -28,35 +24,13 @@
#include "ui/events/keycodes/keyboard_code_conversion.h"
#endif
-namespace aura {
+namespace ui {
namespace test {
namespace {
-void DummyCallback(ui::EventType, const gfx::Vector2dF&) {
+void DummyCallback(EventType, const gfx::Vector2dF&) {
}
-class DefaultEventGeneratorDelegate : public EventGeneratorDelegate {
- public:
- explicit DefaultEventGeneratorDelegate(Window* root_window)
- : root_window_(root_window) {}
- virtual ~DefaultEventGeneratorDelegate() {}
-
- // EventGeneratorDelegate overrides:
- virtual WindowTreeHost* GetHostAt(const gfx::Point& point) const OVERRIDE {
- return root_window_->GetHost();
- }
-
- virtual client::ScreenPositionClient* GetScreenPositionClient(
- const aura::Window* window) const OVERRIDE {
- return NULL;
- }
-
- private:
- Window* root_window_;
-
- DISALLOW_COPY_AND_ASSIGN(DefaultEventGeneratorDelegate);
-};
-
class TestKeyEvent : public ui::KeyEvent {
public:
TestKeyEvent(const base::NativeEvent& native_event, int flags, bool is_char)
@@ -84,29 +58,31 @@ const int kAllButtonMask = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON;
} // namespace
-EventGenerator::EventGenerator(Window* root_window)
- : delegate_(new DefaultEventGeneratorDelegate(root_window)),
- current_host_(delegate_->GetHostAt(current_location_)),
+EventGenerator::EventGenerator(gfx::NativeWindow root_window)
+ : delegate_(CreateDefaultPlatformDelegate(this, root_window, NULL)),
+ current_target_(delegate_->GetTargetAt(current_location_)),
flags_(0),
grab_(false),
async_(false),
tick_clock_(new base::DefaultTickClock()) {
}
-EventGenerator::EventGenerator(Window* root_window, const gfx::Point& point)
- : delegate_(new DefaultEventGeneratorDelegate(root_window)),
+EventGenerator::EventGenerator(gfx::NativeWindow root_window,
+ const gfx::Point& point)
+ : delegate_(CreateDefaultPlatformDelegate(this, root_window, NULL)),
current_location_(point),
- current_host_(delegate_->GetHostAt(current_location_)),
+ current_target_(delegate_->GetTargetAt(current_location_)),
flags_(0),
grab_(false),
async_(false),
tick_clock_(new base::DefaultTickClock()) {
}
-EventGenerator::EventGenerator(Window* root_window, Window* window)
- : delegate_(new DefaultEventGeneratorDelegate(root_window)),
- current_location_(CenterOfWindow(window)),
- current_host_(delegate_->GetHostAt(current_location_)),
+EventGenerator::EventGenerator(gfx::NativeWindow root_window,
+ gfx::NativeWindow window)
+ : delegate_(CreateDefaultPlatformDelegate(this, root_window, window)),
+ current_location_(delegate_->CenterOfWindow(window)),
+ current_target_(delegate_->GetTargetAt(current_location_)),
flags_(0),
grab_(false),
async_(false),
@@ -115,7 +91,7 @@ EventGenerator::EventGenerator(Window* root_window, Window* window)
EventGenerator::EventGenerator(EventGeneratorDelegate* delegate)
: delegate_(delegate),
- current_host_(delegate_->GetHostAt(current_location_)),
+ current_target_(delegate_->GetTargetAt(current_location_)),
flags_(0),
grab_(false),
async_(false),
@@ -166,7 +142,7 @@ void EventGenerator::MoveMouseWheel(int delta_x, int delta_y) {
void EventGenerator::SendMouseExit() {
gfx::Point exit_location(current_location_);
- ConvertPointToTarget(current_host_->window(), &exit_location);
+ delegate_->ConvertPointToTarget(current_target_, &exit_location);
ui::MouseEvent mouseev(ui::ET_MOUSE_EXITED, exit_location, exit_location,
flags_, 0);
Dispatch(&mouseev);
@@ -179,7 +155,7 @@ void EventGenerator::MoveMouseToInHost(const gfx::Point& point_in_host) {
Dispatch(&mouseev);
current_location_ = point_in_host;
- current_host_->ConvertPointFromHost(&current_location_);
+ delegate_->ConvertPointFromHost(current_target_, &current_location_);
}
void EventGenerator::MoveMouseTo(const gfx::Point& point_in_screen,
@@ -195,17 +171,17 @@ void EventGenerator::MoveMouseTo(const gfx::Point& point_in_screen,
gfx::Point move_point = current_location_ + gfx::ToRoundedVector2d(step);
if (!grab_)
UpdateCurrentDispatcher(move_point);
- ConvertPointToTarget(current_host_->window(), &move_point);
+ delegate_->ConvertPointToTarget(current_target_, &move_point);
ui::MouseEvent mouseev(event_type, move_point, move_point, flags_, 0);
Dispatch(&mouseev);
}
current_location_ = point_in_screen;
}
-void EventGenerator::MoveMouseRelativeTo(const Window* window,
+void EventGenerator::MoveMouseRelativeTo(const EventTarget* window,
const gfx::Point& point_in_parent) {
gfx::Point point(point_in_parent);
- ConvertPointFromTarget(window, &point);
+ delegate_->ConvertPointFromTarget(window, &point);
MoveMouseTo(point);
}
@@ -215,7 +191,7 @@ void EventGenerator::DragMouseTo(const gfx::Point& point) {
ReleaseLeftButton();
}
-void EventGenerator::MoveMouseToCenterOf(Window* window) {
+void EventGenerator::MoveMouseToCenterOf(EventTarget* window) {
MoveMouseTo(CenterOfWindow(window));
}
@@ -262,7 +238,7 @@ void EventGenerator::PressMoveAndReleaseTouchTo(const gfx::Point& point) {
ReleaseTouch();
}
-void EventGenerator::PressMoveAndReleaseTouchToCenterOf(Window* window) {
+void EventGenerator::PressMoveAndReleaseTouchToCenterOf(EventTarget* window) {
PressMoveAndReleaseTouchTo(CenterOfWindow(window));
}
@@ -462,7 +438,7 @@ void EventGenerator::ScrollSequence(const gfx::Point& start,
const base::TimeDelta& step_delay,
const std::vector<gfx::Point>& offsets,
int num_fingers) {
- int steps = offsets.size();
+ size_t steps = offsets.size();
base::TimeDelta timestamp = Now();
ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL,
start,
@@ -473,7 +449,7 @@ void EventGenerator::ScrollSequence(const gfx::Point& start,
num_fingers);
Dispatch(&fling_cancel);
- for (int i = 0; i < steps; ++i) {
+ for (size_t i = 0; i < steps; ++i) {
timestamp += step_delay;
ui::ScrollEvent scroll(ui::ET_SCROLL,
start,
@@ -550,13 +526,13 @@ void EventGenerator::DispatchKeyEvent(bool is_press,
}
void EventGenerator::UpdateCurrentDispatcher(const gfx::Point& point) {
- current_host_ = delegate_->GetHostAt(point);
+ current_target_ = delegate_->GetTargetAt(point);
}
void EventGenerator::PressButton(int flag) {
if (!(flags_ & flag)) {
flags_ |= flag;
- grab_ = flags_ & kAllButtonMask;
+ grab_ = (flags_ & kAllButtonMask) != 0;
gfx::Point location = GetLocationInCurrentRoot();
ui::MouseEvent mouseev(ui::ET_MOUSE_PRESSED, location, location, flags_,
flag);
@@ -572,41 +548,17 @@ void EventGenerator::ReleaseButton(int flag) {
Dispatch(&mouseev);
flags_ ^= flag;
}
- grab_ = flags_ & kAllButtonMask;
-}
-
-void EventGenerator::ConvertPointFromTarget(const aura::Window* target,
- gfx::Point* point) const {
- DCHECK(point);
- aura::client::ScreenPositionClient* client =
- delegate_->GetScreenPositionClient(target);
- if (client)
- client->ConvertPointToScreen(target, point);
- else
- aura::Window::ConvertPointToTarget(target, target->GetRootWindow(), point);
-}
-
-void EventGenerator::ConvertPointToTarget(const aura::Window* target,
- gfx::Point* point) const {
- DCHECK(point);
- aura::client::ScreenPositionClient* client =
- delegate_->GetScreenPositionClient(target);
- if (client)
- client->ConvertPointFromScreen(target, point);
- else
- aura::Window::ConvertPointToTarget(target->GetRootWindow(), target, point);
+ grab_ = (flags_ & kAllButtonMask) != 0;
}
gfx::Point EventGenerator::GetLocationInCurrentRoot() const {
gfx::Point p(current_location_);
- ConvertPointToTarget(current_host_->window(), &p);
+ delegate_->ConvertPointToTarget(current_target_, &p);
return p;
}
-gfx::Point EventGenerator::CenterOfWindow(const Window* window) const {
- gfx::Point center = gfx::Rect(window->bounds().size()).CenterPoint();
- ConvertPointFromTarget(window, &center);
- return center;
+gfx::Point EventGenerator::CenterOfWindow(const EventTarget* window) const {
+ return delegate_->CenterOfTarget(window);
}
void EventGenerator::DoDispatchEvent(ui::Event* event, bool async) {
@@ -633,7 +585,7 @@ void EventGenerator::DoDispatchEvent(ui::Event* event, bool async) {
}
pending_events_.push_back(pending_event);
} else {
- ui::EventSource* event_source = current_host_->GetEventSource();
+ ui::EventSource* event_source = delegate_->GetEventSource(current_target_);
ui::EventSourceTestApi event_source_test(event_source);
ui::EventDispatchDetails details =
event_source_test.SendEventToProcessor(event);
@@ -656,4 +608,4 @@ void EventGenerator::DispatchNextPendingEvent() {
}
} // namespace test
-} // namespace aura
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698