Commit 854590d2 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Share common code in event generator delegates where possible.

This factors DefaultEventGeneratorDelegate out to a separate file and uses it in
chromecast/.  It also adds a default ScreenPositionClient getter to
EventGeneratorDelegateAura and removes the duplicate overrides in various
subclasses.

Bug: none
Change-Id: I449cf1c10daa4a23b197679dcb428acbbe54a52f
Reviewed-on: https://chromium-review.googlesource.com/c/1338577
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609094}
parent 52c221e8
......@@ -44,7 +44,6 @@
#include "services/ws/window_tree.h"
#include "services/ws/window_tree_test_helper.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/client/window_parenting_client.h"
#include "ui/aura/env.h"
#include "ui/aura/mus/property_converter.h"
......@@ -82,11 +81,6 @@ class AshEventGeneratorDelegate
return Shell::GetRootWindowForDisplayId(display.id())->GetHost()->window();
}
aura::client::ScreenPositionClient* GetScreenPositionClient(
const aura::Window* window) const override {
return aura::client::GetScreenPositionClient(window->GetRootWindow());
}
ui::EventDispatchDetails DispatchKeyEventToIME(ui::EventTarget* target,
ui::KeyEvent* event) override {
// In Ash environment, the key event will be processed by event rewriters
......
......@@ -7,47 +7,29 @@
#include "ash/shell.h"
#include "base/macros.h"
#include "ui/aura/mus/window_tree_client.h"
#include "ui/aura/test/event_generator_delegate_aura.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/aura/test/default_event_generator_delegate.h"
#include "ui/base/ui_base_features.h"
#include "ui/views/mus/mus_client.h"
namespace {
class DefaultAshEventGeneratorDelegate
: public aura::test::EventGeneratorDelegateAura {
: public aura::test::DefaultEventGeneratorDelegate {
public:
explicit DefaultAshEventGeneratorDelegate(aura::Window* root_window);
~DefaultAshEventGeneratorDelegate() override = default;
// aura::test::EventGeneratorDelegateAura:
ui::EventTarget* GetTargetAt(const gfx::Point& location) override;
aura::client::ScreenPositionClient* GetScreenPositionClient(
const aura::Window* window) const override;
// aura::test::DefaultEventGeneratorDelegate:
ui::EventDispatchDetails DispatchKeyEventToIME(ui::EventTarget* target,
ui::KeyEvent* event) override;
private:
aura::Window* root_window_;
DISALLOW_COPY_AND_ASSIGN(DefaultAshEventGeneratorDelegate);
};
DefaultAshEventGeneratorDelegate::DefaultAshEventGeneratorDelegate(
aura::Window* root_window)
: root_window_(root_window) {}
ui::EventTarget* DefaultAshEventGeneratorDelegate::GetTargetAt(
const gfx::Point& location) {
return root_window_->GetHost()->window();
}
aura::client::ScreenPositionClient*
DefaultAshEventGeneratorDelegate::GetScreenPositionClient(
const aura::Window* window) const {
return nullptr;
}
: DefaultEventGeneratorDelegate(root_window) {}
ui::EventDispatchDetails
DefaultAshEventGeneratorDelegate::DispatchKeyEventToIME(ui::EventTarget* target,
......
......@@ -5,7 +5,7 @@
#include "chromecast/graphics/accessibility/partial_magnification_controller.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/test/event_generator_delegate_aura.h"
#include "ui/aura/test/default_event_generator_delegate.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/display/manager/display_manager.h"
#include "ui/events/test/event_generator.h"
......@@ -33,17 +33,13 @@ class CastTestWindowDelegate : public aura::test::TestWindowDelegate {
};
class TestEventGeneratorDelegate
: public aura::test::EventGeneratorDelegateAura {
: public aura::test::DefaultEventGeneratorDelegate {
public:
explicit TestEventGeneratorDelegate(aura::Window* root_window)
: root_window_(root_window) {}
: DefaultEventGeneratorDelegate(root_window), root_window_(root_window) {}
~TestEventGeneratorDelegate() override = default;
// EventGeneratorDelegateAura overrides:
ui::EventTarget* GetTargetAt(const gfx::Point& point) override {
return root_window_->GetHost()->window();
}
// aura::test::DefaultEventGeneratorDelegate:
aura::client::ScreenPositionClient* GetScreenPositionClient(
const aura::Window* window) const override {
return aura::client::GetScreenPositionClient(root_window_);
......
......@@ -11,9 +11,8 @@
#include "base/test/test_mock_time_task_runner.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/test/event_generator_delegate_aura.h"
#include "ui/aura/test/default_event_generator_delegate.h"
#include "ui/aura/window.h"
#include "ui/events/test/event_generator.h"
#include "ui/wm/core/default_screen_position_client.h"
......@@ -37,17 +36,13 @@ constexpr int kNumSteps = 5;
} // namespace
class TestEventGeneratorDelegate
: public aura::test::EventGeneratorDelegateAura {
: public aura::test::DefaultEventGeneratorDelegate {
public:
explicit TestEventGeneratorDelegate(aura::Window* root_window)
: root_window_(root_window) {}
: DefaultEventGeneratorDelegate(root_window), root_window_(root_window) {}
~TestEventGeneratorDelegate() override = default;
// EventGeneratorDelegateAura overrides:
ui::EventTarget* GetTargetAt(const gfx::Point& point) override {
return root_window_->GetHost()->window();
}
// aura::test::DefaultEventGeneratorDelegate:
aura::client::ScreenPositionClient* GetScreenPositionClient(
const aura::Window* window) const override {
return aura::client::GetScreenPositionClient(root_window_);
......
......@@ -13,7 +13,6 @@
#include "services/ws/window_service.h"
#include "services/ws/window_tree.h"
#include "services/ws/window_tree_binding.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/test/event_generator_delegate_aura.h"
#include "ui/aura/window_tree_host.h"
#include "ui/display/screen.h"
......@@ -107,10 +106,6 @@ class EventGeneratorDelegateWs : public aura::test::EventGeneratorDelegateAura {
ui::EventTarget* GetTargetAt(const gfx::Point& location) override {
return &event_targeter_;
}
aura::client::ScreenPositionClient* GetScreenPositionClient(
const aura::Window* window) const override {
return aura::client::GetScreenPositionClient(window->GetRootWindow());
}
ui::EventSource* GetEventSource(ui::EventTarget* target) override {
return target == &event_targeter_
? &event_targeter_
......
......@@ -247,6 +247,8 @@ jumbo_static_library("test_support") {
"test/aura_test_suite_setup.h",
"test/aura_test_utils.cc",
"test/aura_test_utils.h",
"test/default_event_generator_delegate.cc",
"test/default_event_generator_delegate.h",
"test/env_test_helper.cc",
"test/env_test_helper.h",
"test/event_generator_delegate_aura.cc",
......
// Copyright 2018 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/default_event_generator_delegate.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
namespace aura {
namespace test {
DefaultEventGeneratorDelegate::DefaultEventGeneratorDelegate(
gfx::NativeWindow root_window)
: root_window_(root_window) {}
ui::EventTarget* DefaultEventGeneratorDelegate::GetTargetAt(
const gfx::Point& location) {
return root_window_->GetHost()->window();
}
client::ScreenPositionClient*
DefaultEventGeneratorDelegate::GetScreenPositionClient(
const Window* window) const {
return nullptr;
}
} // namespace test
} // namespace aura
// Copyright 2018 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_DEFAULT_EVENT_GENERATOR_DELEGATE_H_
#define UI_AURA_TEST_DEFAULT_EVENT_GENERATOR_DELEGATE_H_
#include "ui/aura/test/event_generator_delegate_aura.h"
namespace aura {
namespace test {
class DefaultEventGeneratorDelegate : public EventGeneratorDelegateAura {
public:
explicit DefaultEventGeneratorDelegate(gfx::NativeWindow root_window);
~DefaultEventGeneratorDelegate() override = default;
// EventGeneratorDelegateAura:
ui::EventTarget* GetTargetAt(const gfx::Point& location) override;
client::ScreenPositionClient* GetScreenPositionClient(
const Window* window) const override;
private:
Window* root_window_;
DISALLOW_COPY_AND_ASSIGN(DefaultEventGeneratorDelegate);
};
} // namespace test
} // namespace aura
#endif // UI_AURA_TEST_DEFAULT_EVENT_GENERATOR_DELEGATE_H_
......@@ -12,6 +12,7 @@
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/env.h"
#include "ui/aura/mus/window_port_mus.h"
#include "ui/aura/test/default_event_generator_delegate.h"
#include "ui/aura/test/env_test_helper.h"
#include "ui/aura/test/mus/window_tree_client_test_api.h"
#include "ui/aura/window_event_dispatcher.h"
......@@ -26,29 +27,6 @@ namespace aura {
namespace test {
namespace {
class DefaultEventGeneratorDelegate : public EventGeneratorDelegateAura {
public:
explicit DefaultEventGeneratorDelegate(gfx::NativeWindow root_window)
: root_window_(root_window) {}
~DefaultEventGeneratorDelegate() override = default;
// EventGeneratorDelegateAura:
ui::EventTarget* GetTargetAt(const gfx::Point& location) override {
return root_window_->GetHost()->window();
}
client::ScreenPositionClient* GetScreenPositionClient(
const aura::Window* window) const override {
return nullptr;
}
private:
Window* root_window_;
DISALLOW_COPY_AND_ASSIGN(DefaultEventGeneratorDelegate);
};
// EventTargeterMus serves to send events to the remote window-service by way
// of the RemoteEventInjector interface.
class EventTargeterMus : public ui::EventTarget,
......@@ -128,10 +106,6 @@ class EventGeneratorDelegateMus : public EventGeneratorDelegateAura {
ui::EventTarget* GetTargetAt(const gfx::Point& location) override {
return &event_targeter_;
}
client::ScreenPositionClient* GetScreenPositionClient(
const aura::Window* window) const override {
return client::GetScreenPositionClient(window->GetRootWindow());
}
ui::EventSource* GetEventSource(ui::EventTarget* target) override {
return target == &event_targeter_
? &event_targeter_
......@@ -196,6 +170,12 @@ EventGeneratorDelegateAura::EventGeneratorDelegateAura() = default;
EventGeneratorDelegateAura::~EventGeneratorDelegateAura() = default;
client::ScreenPositionClient*
EventGeneratorDelegateAura::GetScreenPositionClient(
const Window* window) const {
return client::GetScreenPositionClient(window->GetRootWindow());
}
ui::EventSource* EventGeneratorDelegateAura::GetEventSource(
ui::EventTarget* target) {
return static_cast<Window*>(target)->GetHost()->GetEventSource();
......
......@@ -42,7 +42,7 @@ class EventGeneratorDelegateAura : public ui::test::EventGeneratorDelegate {
// coordinates used in EventGenerator. EventGenerator uses
// root Window's coordinate if this returns NULL.
virtual client::ScreenPositionClient* GetScreenPositionClient(
const aura::Window* window) const = 0;
const Window* window) const;
// Overridden from ui::test::EventGeneratorDelegate:
ui::EventSource* GetEventSource(ui::EventTarget* target) override;
......
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