Index: ui/aura/test/event_generator.cc |
diff --git a/ui/aura/test/event_generator.cc b/ui/aura/test/event_generator.cc |
index 162770e67d0d254513ec0cb39801ade8fba040e8..892e7b2396e064daba84fe2b606b4c080a2dfa1f 100644 |
--- a/ui/aura/test/event_generator.cc |
+++ b/ui/aura/test/event_generator.cc |
@@ -80,44 +80,38 @@ class TestTouchEvent : public ui::TouchEvent { |
DISALLOW_COPY_AND_ASSIGN(TestTouchEvent); |
}; |
-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_)), |
- flags_(0), |
- grab_(false), |
+ : EventGeneratorBase(gfx::Point()), |
+ delegate_(new DefaultEventGeneratorDelegate(root_window)), |
+ current_host_(delegate_->GetHostAt(current_location())), |
async_(false), |
tick_clock_(new base::DefaultTickClock()) { |
} |
EventGenerator::EventGenerator(Window* root_window, const gfx::Point& point) |
- : delegate_(new DefaultEventGeneratorDelegate(root_window)), |
- current_location_(point), |
- current_host_(delegate_->GetHostAt(current_location_)), |
- flags_(0), |
- grab_(false), |
+ : EventGeneratorBase(point), |
+ delegate_(new DefaultEventGeneratorDelegate(root_window)), |
+ current_host_(delegate_->GetHostAt(current_location())), |
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_)), |
- flags_(0), |
- grab_(false), |
+ : EventGeneratorBase(gfx::Point()), |
+ delegate_(new DefaultEventGeneratorDelegate(root_window)), |
+ current_host_(NULL), |
async_(false), |
tick_clock_(new base::DefaultTickClock()) { |
+ set_current_location(CenterOfWindow(window)); |
+ current_host_ = delegate_->GetHostAt(current_location()); |
} |
EventGenerator::EventGenerator(EventGeneratorDelegate* delegate) |
- : delegate_(delegate), |
- current_host_(delegate_->GetHostAt(current_location_)), |
- flags_(0), |
- grab_(false), |
+ : EventGeneratorBase(gfx::Point()), |
+ delegate_(delegate), |
+ current_host_(delegate_->GetHostAt(current_location())), |
async_(false), |
tick_clock_(new base::DefaultTickClock()) { |
} |
@@ -129,77 +123,30 @@ EventGenerator::~EventGenerator() { |
pending_events_.clear(); |
} |
-void EventGenerator::PressLeftButton() { |
- PressButton(ui::EF_LEFT_MOUSE_BUTTON); |
-} |
- |
-void EventGenerator::ReleaseLeftButton() { |
- ReleaseButton(ui::EF_LEFT_MOUSE_BUTTON); |
-} |
- |
-void EventGenerator::ClickLeftButton() { |
- PressLeftButton(); |
- ReleaseLeftButton(); |
-} |
- |
-void EventGenerator::DoubleClickLeftButton() { |
- flags_ |= ui::EF_IS_DOUBLE_CLICK; |
- PressLeftButton(); |
- flags_ ^= ui::EF_IS_DOUBLE_CLICK; |
- ReleaseLeftButton(); |
-} |
- |
-void EventGenerator::PressRightButton() { |
- PressButton(ui::EF_RIGHT_MOUSE_BUTTON); |
-} |
- |
-void EventGenerator::ReleaseRightButton() { |
- ReleaseButton(ui::EF_RIGHT_MOUSE_BUTTON); |
-} |
- |
void EventGenerator::MoveMouseWheel(int delta_x, int delta_y) { |
gfx::Point location = GetLocationInCurrentRoot(); |
- ui::MouseEvent mouseev(ui::ET_MOUSEWHEEL, location, location, flags_, 0); |
+ ui::MouseEvent mouseev(ui::ET_MOUSEWHEEL, location, location, flags(), 0); |
ui::MouseWheelEvent wheelev(mouseev, delta_x, delta_y); |
Dispatch(&wheelev); |
} |
void EventGenerator::SendMouseExit() { |
- gfx::Point exit_location(current_location_); |
+ gfx::Point exit_location(current_location()); |
ConvertPointToTarget(current_host_->window(), &exit_location); |
ui::MouseEvent mouseev(ui::ET_MOUSE_EXITED, exit_location, exit_location, |
- flags_, 0); |
+ flags(), 0); |
Dispatch(&mouseev); |
} |
void EventGenerator::MoveMouseToInHost(const gfx::Point& point_in_host) { |
- const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ? |
+ const ui::EventType event_type = (flags() & ui::EF_LEFT_MOUSE_BUTTON) ? |
ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED; |
- ui::MouseEvent mouseev(event_type, point_in_host, point_in_host, flags_, 0); |
+ ui::MouseEvent mouseev(event_type, point_in_host, point_in_host, flags(), 0); |
Dispatch(&mouseev); |
- current_location_ = point_in_host; |
- current_host_->ConvertPointFromHost(¤t_location_); |
-} |
- |
-void EventGenerator::MoveMouseTo(const gfx::Point& point_in_screen, |
- int count) { |
- DCHECK_GT(count, 0); |
- const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ? |
- ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED; |
- |
- gfx::Vector2dF diff(point_in_screen - current_location_); |
- for (float i = 1; i <= count; i++) { |
- gfx::Vector2dF step(diff); |
- step.Scale(i / count); |
- gfx::Point move_point = current_location_ + gfx::ToRoundedVector2d(step); |
- if (!grab_) |
- UpdateCurrentDispatcher(move_point); |
- ConvertPointToTarget(current_host_->window(), &move_point); |
- ui::MouseEvent mouseev(event_type, move_point, move_point, flags_, 0); |
- Dispatch(&mouseev); |
- } |
- current_location_ = point_in_screen; |
+ gfx::Point new_location(point_in_host); |
+ current_host_->ConvertPointFromHost(&new_location); |
+ set_current_location(new_location); |
} |
void EventGenerator::MoveMouseRelativeTo(const Window* window, |
@@ -209,12 +156,6 @@ void EventGenerator::MoveMouseRelativeTo(const Window* window, |
MoveMouseTo(point); |
} |
-void EventGenerator::DragMouseTo(const gfx::Point& point) { |
- PressLeftButton(); |
- MoveMouseTo(point); |
- ReleaseLeftButton(); |
-} |
- |
void EventGenerator::MoveMouseToCenterOf(Window* window) { |
MoveMouseTo(CenterOfWindow(window)); |
} |
@@ -225,7 +166,7 @@ void EventGenerator::PressTouch() { |
void EventGenerator::PressTouchId(int touch_id) { |
TestTouchEvent touchev( |
- ui::ET_TOUCH_PRESSED, GetLocationInCurrentRoot(), touch_id, flags_, |
+ ui::ET_TOUCH_PRESSED, GetLocationInCurrentRoot(), touch_id, flags(), |
Now()); |
Dispatch(&touchev); |
} |
@@ -235,13 +176,13 @@ void EventGenerator::MoveTouch(const gfx::Point& point) { |
} |
void EventGenerator::MoveTouchId(const gfx::Point& point, int touch_id) { |
- current_location_ = point; |
+ set_current_location(point); |
TestTouchEvent touchev( |
- ui::ET_TOUCH_MOVED, GetLocationInCurrentRoot(), touch_id, flags_, |
+ ui::ET_TOUCH_MOVED, GetLocationInCurrentRoot(), touch_id, flags(), |
Now()); |
Dispatch(&touchev); |
- if (!grab_) |
+ if (!grab()) |
UpdateCurrentDispatcher(point); |
} |
@@ -251,7 +192,7 @@ void EventGenerator::ReleaseTouch() { |
void EventGenerator::ReleaseTouchId(int touch_id) { |
TestTouchEvent touchev( |
- ui::ET_TOUCH_RELEASED, GetLocationInCurrentRoot(), touch_id, flags_, |
+ ui::ET_TOUCH_RELEASED, GetLocationInCurrentRoot(), touch_id, flags(), |
Now()); |
Dispatch(&touchev); |
} |
@@ -520,6 +461,44 @@ base::TimeDelta EventGenerator::Now() { |
tick_clock_->NowTicks().ToInternalValue()); |
} |
+gfx::Point EventGenerator::GetLocationInCurrentRoot() const { |
+ gfx::Point p(current_location()); |
+ ConvertPointToTarget(current_host_->window(), &p); |
+ return p; |
+} |
+ |
+void EventGenerator::DoMoveMouseTo(const gfx::Point& point_in_screen, |
+ int count) { |
+ DCHECK_GT(count, 0); |
+ const ui::EventType event_type = (flags() & ui::EF_LEFT_MOUSE_BUTTON) ? |
+ ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED; |
+ |
+ gfx::Vector2dF diff(point_in_screen - current_location()); |
+ for (float i = 1; i <= count; i++) { |
+ gfx::Vector2dF step(diff); |
+ step.Scale(i / count); |
+ gfx::Point move_point = current_location() + gfx::ToRoundedVector2d(step); |
+ if (!grab()) |
+ UpdateCurrentDispatcher(move_point); |
+ ConvertPointToTarget(current_host_->window(), &move_point); |
+ ui::MouseEvent mouseev(event_type, move_point, move_point, flags(), 0); |
+ Dispatch(&mouseev); |
+ } |
+ set_current_location(point_in_screen); |
+} |
+ |
+void EventGenerator::DispatchMouseEvent(ui::EventType type, |
+ const gfx::Point& location_in_root, |
+ int flags, |
+ int changed_button_flags) { |
+ ui::MouseEvent mouseev(type, |
+ location_in_root, |
+ location_in_root, |
+ flags, |
+ changed_button_flags); |
+ Dispatch(&mouseev); |
+} |
+ |
void EventGenerator::DispatchKeyEvent(bool is_press, |
ui::KeyboardCode key_code, |
int flags) { |
@@ -555,28 +534,6 @@ void EventGenerator::UpdateCurrentDispatcher(const gfx::Point& point) { |
current_host_ = delegate_->GetHostAt(point); |
} |
-void EventGenerator::PressButton(int flag) { |
- if (!(flags_ & flag)) { |
- flags_ |= flag; |
- grab_ = flags_ & kAllButtonMask; |
- gfx::Point location = GetLocationInCurrentRoot(); |
- ui::MouseEvent mouseev(ui::ET_MOUSE_PRESSED, location, location, flags_, |
- flag); |
- Dispatch(&mouseev); |
- } |
-} |
- |
-void EventGenerator::ReleaseButton(int flag) { |
- if (flags_ & flag) { |
- gfx::Point location = GetLocationInCurrentRoot(); |
- ui::MouseEvent mouseev(ui::ET_MOUSE_RELEASED, location, |
- location, flags_, flag); |
- Dispatch(&mouseev); |
- flags_ ^= flag; |
- } |
- grab_ = flags_ & kAllButtonMask; |
-} |
- |
void EventGenerator::ConvertPointFromTarget(const aura::Window* target, |
gfx::Point* point) const { |
DCHECK(point); |
@@ -599,12 +556,6 @@ void EventGenerator::ConvertPointToTarget(const aura::Window* target, |
aura::Window::ConvertPointToTarget(target->GetRootWindow(), target, point); |
} |
-gfx::Point EventGenerator::GetLocationInCurrentRoot() const { |
- gfx::Point p(current_location_); |
- ConvertPointToTarget(current_host_->window(), &p); |
- return p; |
-} |
- |
gfx::Point EventGenerator::CenterOfWindow(const Window* window) const { |
gfx::Point center = gfx::Rect(window->bounds().size()).CenterPoint(); |
ConvertPointFromTarget(window, ¢er); |