Commit 354c0dd6 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Misc. cleanup related to EventGenerator.

* Remove unnecessary top_right() calls
* Use temps to reduce wrapping
* Use WindowFromTarget() more consistently
* For parallelism, always convert from targets to windows, instead of sometimes
  using the "target" version and sometimes the "window" version and mixing calls
* Group all the EventGenerator constructor variants that take a root window

Bug: none
Change-Id: I707780ee21ec2d3652fd3d1a38e3607e1ba980be
Reviewed-on: https://chromium-review.googlesource.com/c/1347277
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611291}
parent f37b3414
...@@ -728,7 +728,7 @@ TEST_F(WindowSelectorTest, ActiveWindowChangedUserActionWindowClose) { ...@@ -728,7 +728,7 @@ TEST_F(WindowSelectorTest, ActiveWindowChangedUserActionWindowClose) {
aura::Window* window = widget->GetNativeWindow(); aura::Window* window = widget->GetNativeWindow();
gfx::Rect bounds = GetTransformedBoundsInRootWindow(window); gfx::Rect bounds = GetTransformedBoundsInRootWindow(window);
gfx::Point point(bounds.top_right().x() - 5, bounds.top_right().y() + 5); gfx::Point point(bounds.right() - 5, bounds.y() + 5);
ui::test::EventGenerator event_generator(window->GetRootWindow(), point); ui::test::EventGenerator event_generator(window->GetRootWindow(), point);
ASSERT_FALSE(widget->IsClosed()); ASSERT_FALSE(widget->IsClosed());
...@@ -842,7 +842,7 @@ TEST_F(WindowSelectorTest, CloseButton) { ...@@ -842,7 +842,7 @@ TEST_F(WindowSelectorTest, CloseButton) {
aura::Window* window = widget->GetNativeWindow(); aura::Window* window = widget->GetNativeWindow();
gfx::Rect bounds = GetTransformedBoundsInRootWindow(window); gfx::Rect bounds = GetTransformedBoundsInRootWindow(window);
gfx::Point point(bounds.top_right().x() - 5, bounds.top_right().y() + 5); gfx::Point point(bounds.right() - 5, bounds.y() + 5);
ui::test::EventGenerator event_generator(window->GetRootWindow(), point); ui::test::EventGenerator event_generator(window->GetRootWindow(), point);
EXPECT_FALSE(widget->IsClosed()); EXPECT_FALSE(widget->IsClosed());
...@@ -858,8 +858,7 @@ TEST_F(WindowSelectorTest, CloseButton) { ...@@ -858,8 +858,7 @@ TEST_F(WindowSelectorTest, CloseButton) {
const gfx::Rect rect = const gfx::Rect rect =
GetTransformedBoundsInRootWindow(window_for_minimized_window); GetTransformedBoundsInRootWindow(window_for_minimized_window);
event_generator.MoveMouseTo( event_generator.MoveMouseTo(gfx::Point(rect.right() - 10, rect.y() - 10));
gfx::Point(rect.top_right().x() - 10, rect.top_right().y() - 10));
EXPECT_FALSE(minimized_widget->IsClosed()); EXPECT_FALSE(minimized_widget->IsClosed());
event_generator.ClickLeftButton(); event_generator.ClickLeftButton();
...@@ -921,7 +920,7 @@ TEST_F(WindowSelectorTest, CloseButtonOnMultipleDisplay) { ...@@ -921,7 +920,7 @@ TEST_F(WindowSelectorTest, CloseButtonOnMultipleDisplay) {
aura::Window* window2 = widget->GetNativeWindow(); aura::Window* window2 = widget->GetNativeWindow();
gfx::Rect bounds = GetTransformedBoundsInRootWindow(window2); gfx::Rect bounds = GetTransformedBoundsInRootWindow(window2);
gfx::Point point(bounds.top_right().x() - 5, bounds.top_right().y() + 5); gfx::Point point(bounds.right() - 5, bounds.y() + 5);
ui::test::EventGenerator event_generator(window2->GetRootWindow(), point); ui::test::EventGenerator event_generator(window2->GetRootWindow(), point);
EXPECT_FALSE(widget->IsClosed()); EXPECT_FALSE(widget->IsClosed());
...@@ -3341,8 +3340,7 @@ TEST_F(SplitViewWindowSelectorTest, Dragging) { ...@@ -3341,8 +3340,7 @@ TEST_F(SplitViewWindowSelectorTest, Dragging) {
ASSERT_LT( ASSERT_LT(
left_selector_item->target_bounds().origin().x() + selector_item_inset, left_selector_item->target_bounds().origin().x() + selector_item_inset,
edge_inset); edge_inset);
ASSERT_GT(right_selector_item->target_bounds().top_right().x() - ASSERT_GT(right_selector_item->target_bounds().right() - selector_item_inset,
selector_item_inset,
screen_width - edge_inset); screen_width - edge_inset);
// Verify if the drag is not started in either snap region, the drag still // Verify if the drag is not started in either snap region, the drag still
...@@ -3380,10 +3378,9 @@ TEST_F(SplitViewWindowSelectorTest, Dragging) { ...@@ -3380,10 +3378,9 @@ TEST_F(SplitViewWindowSelectorTest, Dragging) {
// move by |drag_offset_snap_region| towards the left side of the screen // move by |drag_offset_snap_region| towards the left side of the screen
// before split view acknowledges the drag. // before split view acknowledges the drag.
ASSERT_TRUE(window_selector_controller()->IsSelecting()); ASSERT_TRUE(window_selector_controller()->IsSelecting());
generator->set_current_screen_location( generator->set_current_screen_location(gfx::Point(
gfx::Point(right_selector_item->target_bounds().top_right().x() - right_selector_item->target_bounds().right() - selector_item_inset,
selector_item_inset, right_selector_item->target_bounds().CenterPoint().y()));
right_selector_item->target_bounds().CenterPoint().y()));
generator->PressLeftButton(); generator->PressLeftButton();
generator->MoveMouseBy(drag_offset, 0); generator->MoveMouseBy(drag_offset, 0);
EXPECT_FALSE(IsPreviewAreaShowing()); EXPECT_FALSE(IsPreviewAreaShowing());
......
...@@ -114,10 +114,8 @@ class EventGeneratorDelegateMus : public EventGeneratorDelegateAura { ...@@ -114,10 +114,8 @@ class EventGeneratorDelegateMus : public EventGeneratorDelegateAura {
gfx::Point CenterOfTarget(const ui::EventTarget* target) const override { gfx::Point CenterOfTarget(const ui::EventTarget* target) const override {
if (target != &event_targeter_) if (target != &event_targeter_)
return EventGeneratorDelegateAura::CenterOfTarget(target); return EventGeneratorDelegateAura::CenterOfTarget(target);
return display::Screen::GetScreen() display::Screen* const screen = display::Screen::GetScreen();
->GetPrimaryDisplay() return screen->GetPrimaryDisplay().bounds().CenterPoint();
.bounds()
.CenterPoint();
} }
void ConvertPointFromTarget(const ui::EventTarget* target, void ConvertPointFromTarget(const ui::EventTarget* target,
gfx::Point* point) const override { gfx::Point* point) const override {
...@@ -144,6 +142,9 @@ class EventGeneratorDelegateMus : public EventGeneratorDelegateAura { ...@@ -144,6 +142,9 @@ class EventGeneratorDelegateMus : public EventGeneratorDelegateAura {
const Window* WindowFromTarget(const ui::EventTarget* event_target) { const Window* WindowFromTarget(const ui::EventTarget* event_target) {
return static_cast<const Window*>(event_target); return static_cast<const Window*>(event_target);
} }
Window* WindowFromTarget(ui::EventTarget* event_target) {
return static_cast<Window*>(event_target);
}
} // namespace } // namespace
...@@ -178,32 +179,23 @@ EventGeneratorDelegateAura::GetScreenPositionClient( ...@@ -178,32 +179,23 @@ EventGeneratorDelegateAura::GetScreenPositionClient(
ui::EventSource* EventGeneratorDelegateAura::GetEventSource( ui::EventSource* EventGeneratorDelegateAura::GetEventSource(
ui::EventTarget* target) { ui::EventTarget* target) {
return static_cast<Window*>(target)->GetHost()->GetEventSource(); return WindowFromTarget(target)->GetHost()->GetEventSource();
} }
gfx::Point EventGeneratorDelegateAura::CenterOfTarget( gfx::Point EventGeneratorDelegateAura::CenterOfTarget(
const ui::EventTarget* target) const { const ui::EventTarget* target) const {
gfx::Point center = return CenterOfWindow(WindowFromTarget(target));
gfx::Rect(WindowFromTarget(target)->bounds().size()).CenterPoint();
ConvertPointFromTarget(target, &center);
return center;
} }
gfx::Point EventGeneratorDelegateAura::CenterOfWindow( gfx::Point EventGeneratorDelegateAura::CenterOfWindow(
gfx::NativeWindow window) const { gfx::NativeWindow window) const {
return CenterOfTarget(window); return CenterOfWindow(static_cast<const Window*>(window));
} }
void EventGeneratorDelegateAura::ConvertPointFromTarget( void EventGeneratorDelegateAura::ConvertPointFromTarget(
const ui::EventTarget* event_target, const ui::EventTarget* event_target,
gfx::Point* point) const { gfx::Point* point) const {
DCHECK(point); ConvertPointFromWindow(WindowFromTarget(event_target), point);
const Window* target = WindowFromTarget(event_target);
aura::client::ScreenPositionClient* client = GetScreenPositionClient(target);
if (client)
client->ConvertPointToScreen(target, point);
else
aura::Window::ConvertPointToTarget(target, target->GetRootWindow(), point);
} }
void EventGeneratorDelegateAura::ConvertPointToTarget( void EventGeneratorDelegateAura::ConvertPointToTarget(
...@@ -221,7 +213,7 @@ void EventGeneratorDelegateAura::ConvertPointToTarget( ...@@ -221,7 +213,7 @@ void EventGeneratorDelegateAura::ConvertPointToTarget(
void EventGeneratorDelegateAura::ConvertPointFromWindow( void EventGeneratorDelegateAura::ConvertPointFromWindow(
gfx::NativeWindow window, gfx::NativeWindow window,
gfx::Point* point) const { gfx::Point* point) const {
return ConvertPointFromTarget(window, point); return ConvertPointFromWindow(static_cast<const Window*>(window), point);
} }
void EventGeneratorDelegateAura::ConvertPointFromHost( void EventGeneratorDelegateAura::ConvertPointFromHost(
...@@ -234,9 +226,27 @@ void EventGeneratorDelegateAura::ConvertPointFromHost( ...@@ -234,9 +226,27 @@ void EventGeneratorDelegateAura::ConvertPointFromHost(
ui::EventDispatchDetails EventGeneratorDelegateAura::DispatchKeyEventToIME( ui::EventDispatchDetails EventGeneratorDelegateAura::DispatchKeyEventToIME(
ui::EventTarget* target, ui::EventTarget* target,
ui::KeyEvent* event) { ui::KeyEvent* event) {
Window* window = static_cast<Window*>(target); Window* const window = WindowFromTarget(target);
return window->GetHost()->GetInputMethod()->DispatchKeyEvent(event); return window->GetHost()->GetInputMethod()->DispatchKeyEvent(event);
} }
gfx::Point EventGeneratorDelegateAura::CenterOfWindow(
const Window* window) const {
gfx::Point center = gfx::Rect(window->bounds().size()).CenterPoint();
ConvertPointFromWindow(window, &center);
return center;
}
void EventGeneratorDelegateAura::ConvertPointFromWindow(
const Window* window,
gfx::Point* point) const {
DCHECK(point);
aura::client::ScreenPositionClient* client = GetScreenPositionClient(window);
if (client)
client->ConvertPointToScreen(window, point);
else
aura::Window::ConvertPointToTarget(window, window->GetRootWindow(), point);
}
} // namespace test } // namespace test
} // namespace aura } // namespace aura
...@@ -60,6 +60,9 @@ class EventGeneratorDelegateAura : public ui::test::EventGeneratorDelegate { ...@@ -60,6 +60,9 @@ class EventGeneratorDelegateAura : public ui::test::EventGeneratorDelegate {
ui::KeyEvent* event) override; ui::KeyEvent* event) override;
private: private:
gfx::Point CenterOfWindow(const Window* window) const;
void ConvertPointFromWindow(const Window* window, gfx::Point* point) const;
DISALLOW_COPY_AND_ASSIGN(EventGeneratorDelegateAura); DISALLOW_COPY_AND_ASSIGN(EventGeneratorDelegateAura);
}; };
......
...@@ -91,6 +91,11 @@ void EventGeneratorDelegate::SetFactoryFunction(FactoryFunction factory) { ...@@ -91,6 +91,11 @@ void EventGeneratorDelegate::SetFactoryFunction(FactoryFunction factory) {
g_event_generator_delegate_factory = std::move(factory); g_event_generator_delegate_factory = std::move(factory);
} }
EventGenerator::EventGenerator(std::unique_ptr<EventGeneratorDelegate> delegate)
: delegate_(std::move(delegate)) {
Init(nullptr, nullptr);
}
EventGenerator::EventGenerator(gfx::NativeWindow root_window) { EventGenerator::EventGenerator(gfx::NativeWindow root_window) {
Init(root_window, nullptr); Init(root_window, nullptr);
} }
...@@ -106,11 +111,6 @@ EventGenerator::EventGenerator(gfx::NativeWindow root_window, ...@@ -106,11 +111,6 @@ EventGenerator::EventGenerator(gfx::NativeWindow root_window,
Init(root_window, window); Init(root_window, window);
} }
EventGenerator::EventGenerator(std::unique_ptr<EventGeneratorDelegate> delegate)
: delegate_(std::move(delegate)) {
Init(nullptr, nullptr);
}
EventGenerator::~EventGenerator() { EventGenerator::~EventGenerator() {
ui::SetEventTickClockForTesting(nullptr); ui::SetEventTickClockForTesting(nullptr);
} }
......
...@@ -101,16 +101,16 @@ class EventGeneratorDelegate { ...@@ -101,16 +101,16 @@ class EventGeneratorDelegate {
// EventGeneratorDelegate. // EventGeneratorDelegate.
class EventGenerator { class EventGenerator {
public: public:
// Creates an EventGenerator with the mouse/touch location (0,0),
// 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, // Create an EventGenerator with EventGeneratorDelegate,
// which uses the coordinates conversions and targeting provided by // which uses the coordinates conversions and targeting provided by
// |delegate|. // |delegate|.
explicit EventGenerator(std::unique_ptr<EventGeneratorDelegate> delegate); explicit EventGenerator(std::unique_ptr<EventGeneratorDelegate> delegate);
// Creates an EventGenerator with the mouse/touch location (0,0),
// which uses the |root_window|'s coordinates and the default delegate for
// this platform.
explicit EventGenerator(gfx::NativeWindow root_window);
// Creates an EventGenerator with the mouse/touch location // Creates an EventGenerator with the mouse/touch location
// at |initial_location|, which uses the |root_window|'s coordinates. // at |initial_location|, which uses the |root_window|'s coordinates.
EventGenerator(gfx::NativeWindow root_window, EventGenerator(gfx::NativeWindow root_window,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment