Commit 1be79d6e authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

WindowService: separates event dispatch into own interface

This pulls the two event dispatch related functions out of
EventProcessorDelegate into a new interface. I'm doing this as a
precursor to moving the event dispatch related code out of
WindowManagerState.

BUG=none
TEST=none

Change-Id: I249581a109e38f535d1b48ebe0ebf9785738dbc2
Reviewed-on: https://chromium-review.googlesource.com/964783
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543540}
parent 50fbe94c
......@@ -44,6 +44,7 @@ static_library("lib") {
"drag_cursor_updater.h",
"drag_source.h",
"drag_target_connection.h",
"event_dispatcher.h",
"event_location.h",
"event_matcher.cc",
"event_matcher.h",
......
// 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 SERVICES_UI_WS_EVENT_DISPATCHER_H_
#define SERVICES_UI_WS_EVENT_DISPATCHER_H_
#include <stdint.h>
#include "services/ui/common/types.h"
namespace ui {
class Event;
namespace ws {
class Accelerator;
class ServerWindow;
struct EventLocation;
// EventDispatcher is called from EventProcessor once it determines the target
// for events as well as accelerators.
class EventDispatcher {
public:
enum class AcceleratorPhase {
kPre,
kPost,
};
// Called when the target Window is found for |event|.
// |post_target_accelerator| is the accelerator to run if the target doesn't
// handle the event. See EventProcessor for details on event processing
// phases. |client_id| is the id of tree the event should be sent to. See
// EventLocation for details on |event_location|. |event_location| is only
// useful for located events.
virtual void DispatchInputEventToWindow(
ServerWindow* target,
ClientSpecificId client_id,
const EventLocation& event_location,
const ui::Event& event,
Accelerator* post_target_accelerator) = 0;
// A matching accelerator was found for the specified phase of processing.
// |event| is the event that the accelerator matches and |display_id|
// identifies the display the event came in on.
virtual void OnAccelerator(uint32_t accelerator,
int64_t display_id,
const ui::Event& event,
AcceleratorPhase phase) = 0;
protected:
virtual ~EventDispatcher() {}
};
} // namespace ws
} // namespace ui
#endif // SERVICES_UI_WS_EVENT_DISPATCHER_H_
......@@ -11,6 +11,7 @@
#include "services/ui/ws/accelerator.h"
#include "services/ui/ws/drag_controller.h"
#include "services/ui/ws/drag_source.h"
#include "services/ui/ws/event_dispatcher.h"
#include "services/ui/ws/event_location.h"
#include "services/ui/ws/event_processor_delegate.h"
#include "services/ui/ws/server_window.h"
......@@ -63,8 +64,10 @@ int32_t GetPointerId(const Event& event) {
EventProcessor::ObservedWindow::ObservedWindow() = default;
EventProcessor::ObservedWindow::~ObservedWindow() = default;
EventProcessor::EventProcessor(EventProcessorDelegate* delegate)
EventProcessor::EventProcessor(EventProcessorDelegate* delegate,
EventDispatcher* event_dispatcher)
: delegate_(delegate),
event_dispatcher_(event_dispatcher),
capture_window_(nullptr),
capture_window_client_id_(kInvalidClientId),
event_targeter_(std::make_unique<EventTargeter>(this)),
......@@ -309,9 +312,9 @@ void EventProcessor::ProcessEvent(const ui::Event& event,
Accelerator* pre_target =
FindAccelerator(*key_event, ui::mojom::AcceleratorPhase::PRE_TARGET);
if (pre_target) {
delegate_->OnAccelerator(pre_target->id(), event_location.display_id,
event,
EventProcessorDelegate::AcceleratorPhase::PRE);
event_dispatcher_->OnAccelerator(
pre_target->id(), event_location.display_id, event,
EventDispatcher::AcceleratorPhase::kPre);
return;
}
}
......@@ -413,15 +416,15 @@ void EventProcessor::ProcessKeyEvent(const ui::KeyEvent& event,
const bool in_nonclient_area = false;
const ClientSpecificId client_id =
delegate_->GetEventTargetClientId(focused_window, in_nonclient_area);
delegate_->DispatchInputEventToWindow(focused_window, client_id,
EventLocation(display_id), event,
post_target);
event_dispatcher_->DispatchInputEventToWindow(focused_window, client_id,
EventLocation(display_id),
event, post_target);
return;
}
delegate_->OnEventTargetNotFound(event, display_id);
if (post_target)
delegate_->OnAccelerator(post_target->id(), display_id, event,
EventProcessorDelegate::AcceleratorPhase::POST);
event_dispatcher_->OnAccelerator(post_target->id(), display_id, event,
EventDispatcher::AcceleratorPhase::kPost);
}
void EventProcessor::HideCursorOnMatchedKeyEvent(const ui::KeyEvent& event) {
......@@ -736,8 +739,8 @@ void EventProcessor::DispatchToClient(ServerWindow* window,
clone->AsLocatedEvent()->set_location(location);
// TODO(jonross): add post-target accelerator support once accelerators
// support pointer events.
delegate_->DispatchInputEventToWindow(window, client_id, event_location,
*clone, nullptr);
event_dispatcher_->DispatchInputEventToWindow(
window, client_id, event_location, *clone, nullptr);
}
void EventProcessor::CancelPointerEventsToTarget(ServerWindow* window) {
......
......@@ -40,6 +40,7 @@ class Accelerator;
class DragController;
class DragSource;
class DragTargetConnection;
class EventDispatcher;
class EventProcessorDelegate;
class ServerWindow;
class ServerWindowDrawnTracker;
......@@ -67,7 +68,8 @@ class EventProcessor : public ServerWindowDrawnTrackerObserver,
POST_ONLY,
};
explicit EventProcessor(EventProcessorDelegate* delegate);
EventProcessor(EventProcessorDelegate* delegate,
EventDispatcher* event_dispatcher);
~EventProcessor() override;
ModalWindowController* modal_window_controller() {
......@@ -355,6 +357,7 @@ class EventProcessor : public ServerWindowDrawnTrackerObserver,
void OnDragCursorUpdated() override;
EventProcessorDelegate* delegate_;
EventDispatcher* event_dispatcher_;
ServerWindow* capture_window_;
ClientSpecificId capture_window_client_id_;
......
......@@ -23,23 +23,12 @@ class Event;
namespace ws {
class Accelerator;
class ServerWindow;
// Used by EventProcessor for dispatching of events, as well as to inform the
// delegate of various state changes.
class EventProcessorDelegate {
public:
enum class AcceleratorPhase {
PRE,
POST,
};
virtual void OnAccelerator(uint32_t accelerator,
int64_t display_id,
const ui::Event& event,
AcceleratorPhase phase) = 0;
virtual void SetFocusedWindowFromEventProcessor(ServerWindow* window) = 0;
virtual ServerWindow* GetFocusedWindowForEventProcessor(
int64_t display_id) = 0;
......@@ -71,13 +60,6 @@ class EventProcessorDelegate {
virtual void OnEventChangesCursorTouchVisibility(const ui::Event& event,
bool visible) = 0;
// Dispatches an event to the specific client.
virtual void DispatchInputEventToWindow(ServerWindow* target,
ClientSpecificId client_id,
const EventLocation& event_location,
const ui::Event& event,
Accelerator* accelerator) = 0;
// Returns the id of the client to send events to. |in_nonclient_area| is
// true if the event occurred in the non-client area of the window.
virtual ClientSpecificId GetEventTargetClientId(const ServerWindow* window,
......
......@@ -21,6 +21,7 @@
#include "services/ui/common/switches.h"
#include "services/ui/public/interfaces/window_tree_constants.mojom.h"
#include "services/ui/ws/accelerator.h"
#include "services/ui/ws/event_dispatcher.h"
#include "services/ui/ws/event_location.h"
#include "services/ui/ws/event_processor_delegate.h"
#include "services/ui/ws/server_window.h"
......@@ -52,7 +53,10 @@ struct DispatchedEventDetails {
Accelerator* accelerator;
};
class TestEventProcessorDelegate : public EventProcessorDelegate {
// Serves as both the EventProcessorDelegate and EventDispatcher
// implementation. Records interesting calls for various assertions.
class TestEventProcessorDelegate : public EventProcessorDelegate,
public EventDispatcher {
public:
// Delegate interface used by this class to release capture on event
// dispatcher.
......@@ -81,7 +85,7 @@ class TestEventProcessorDelegate : public EventProcessorDelegate {
uint32_t GetAndClearLastAccelerator() {
uint32_t return_value = last_accelerator_;
last_accelerator_ = 0;
last_accelerator_phase_ = AcceleratorPhase::POST;
last_accelerator_phase_ = AcceleratorPhase::kPost;
return return_value;
}
......@@ -131,7 +135,19 @@ class TestEventProcessorDelegate : public EventProcessorDelegate {
}
private:
// EventProcessorDelegate:
// EventDispatcher:
void DispatchInputEventToWindow(ServerWindow* target,
ClientSpecificId client_id,
const EventLocation& event_location,
const ui::Event& event,
Accelerator* accelerator) override {
std::unique_ptr<DispatchedEventDetails> details(new DispatchedEventDetails);
details->window = target;
details->client_id = client_id;
details->event = ui::Event::Clone(event);
details->accelerator = accelerator;
dispatched_event_queue_.push(std::move(details));
}
void OnAccelerator(uint32_t accelerator,
int64_t display_id,
const ui::Event& event,
......@@ -140,6 +156,8 @@ class TestEventProcessorDelegate : public EventProcessorDelegate {
last_accelerator_ = accelerator;
last_accelerator_phase_ = phase;
}
// EventProcessorDelegate:
ServerWindow* GetFocusedWindowForEventProcessor(int64_t display_id) override {
return focused_window_;
}
......@@ -161,18 +179,6 @@ class TestEventProcessorDelegate : public EventProcessorDelegate {
}
void OnEventChangesCursorTouchVisibility(const ui::Event& event,
bool visible) override {}
void DispatchInputEventToWindow(ServerWindow* target,
ClientSpecificId client_id,
const EventLocation& event_location,
const ui::Event& event,
Accelerator* accelerator) override {
std::unique_ptr<DispatchedEventDetails> details(new DispatchedEventDetails);
details->window = target;
details->client_id = client_id;
details->event = ui::Event::Clone(event);
details->accelerator = accelerator;
dispatched_event_queue_.push(std::move(details));
}
ClientSpecificId GetEventTargetClientId(const ServerWindow* window,
bool in_nonclient_area) override {
return in_nonclient_area ? kNonclientAreaId : kClientAreaId;
......@@ -211,7 +217,7 @@ class TestEventProcessorDelegate : public EventProcessorDelegate {
ServerWindow* focused_window_;
ServerWindow* lost_capture_window_;
uint32_t last_accelerator_;
AcceleratorPhase last_accelerator_phase_ = AcceleratorPhase::POST;
AcceleratorPhase last_accelerator_phase_ = AcceleratorPhase::kPost;
base::queue<std::unique_ptr<DispatchedEventDetails>> dispatched_event_queue_;
ServerWindow* root_ = nullptr;
std::unique_ptr<ui::Event> last_event_target_not_found_;
......@@ -452,7 +458,8 @@ void EventProcessorTest::SetUp() {
test_event_dispatcher_delegate_ =
std::make_unique<TestEventProcessorDelegate>(this);
event_dispatcher_ =
std::make_unique<EventProcessor>(test_event_dispatcher_delegate_.get());
std::make_unique<EventProcessor>(test_event_dispatcher_delegate_.get(),
test_event_dispatcher_delegate_.get());
test_event_dispatcher_delegate_->set_root(root_window_.get());
}
......@@ -538,7 +545,8 @@ void EventProcessorVizTargeterTest::SetUp() {
test_event_dispatcher_delegate_ =
std::make_unique<TestEventProcessorDelegate>(this);
event_dispatcher_ =
std::make_unique<EventProcessor>(test_event_dispatcher_delegate_.get());
std::make_unique<EventProcessor>(test_event_dispatcher_delegate_.get(),
test_event_dispatcher_delegate_.get());
test_event_dispatcher_delegate_->set_root(root_window_.get());
uint32_t handle_size = 100;
......@@ -603,7 +611,8 @@ TEST_P(EventProcessorTest, ProcessEventNoTarget) {
TEST_P(EventProcessorTest, AcceleratorBasic) {
ClearSetup();
TestEventProcessorDelegate event_dispatcher_delegate(nullptr);
EventProcessor dispatcher(&event_dispatcher_delegate);
EventProcessor dispatcher(&event_dispatcher_delegate,
&event_dispatcher_delegate);
uint32_t accelerator_1 = 1;
mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher(
......@@ -754,7 +763,7 @@ TEST_P(EventProcessorTest, ProcessPost) {
// DispatchInputEventToWindow().
ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
DispatchEvent(dispatcher, key, EventProcessor::AcceleratorMatchPhase::ANY);
EXPECT_EQ(EventProcessorDelegate::AcceleratorPhase::PRE,
EXPECT_EQ(EventDispatcher::AcceleratorPhase::kPre,
event_dispatcher_delegate->last_accelerator_phase());
EXPECT_EQ(pre_id, event_dispatcher_delegate->GetAndClearLastAccelerator());
EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
......
......@@ -204,7 +204,7 @@ struct WindowManagerState::EventTask {
WindowManagerState::WindowManagerState(WindowTree* window_tree)
: window_tree_(window_tree),
event_processor_(this),
event_processor_(this, this),
cursor_state_(window_tree_->display_manager(), this) {
frame_decoration_values_ = mojom::FrameDecorationValues::New();
frame_decoration_values_->max_title_bar_button_width = 0u;
......@@ -480,7 +480,7 @@ void WindowManagerState::OnEventAck(mojom::WindowTree* tree,
if (result == mojom::EventResult::UNHANDLED &&
details->post_target_accelerator) {
OnAccelerator(details->post_target_accelerator->id(), details->display_id,
*details->event, AcceleratorPhase::POST);
*details->event, AcceleratorPhase::kPost);
}
ProcessEventTasks();
......@@ -703,7 +703,7 @@ void WindowManagerState::OnAccelerator(uint32_t accelerator_id,
int64_t display_id,
const ui::Event& event,
AcceleratorPhase phase) {
const bool needs_ack = phase == AcceleratorPhase::PRE;
const bool needs_ack = phase == AcceleratorPhase::kPre;
WindowTree::AcceleratorCallback ack_callback;
if (needs_ack) {
DCHECK(!in_flight_event_dispatch_details_);
......
......@@ -18,6 +18,7 @@
#include "services/ui/public/interfaces/display_manager.mojom.h"
#include "services/ui/ws/cursor_state.h"
#include "services/ui/ws/cursor_state_delegate.h"
#include "services/ui/ws/event_dispatcher.h"
#include "services/ui/ws/event_processor.h"
#include "services/ui/ws/event_processor_delegate.h"
#include "services/ui/ws/server_window_observer.h"
......@@ -44,7 +45,8 @@ class WindowManagerStateTestApi;
// associated with.
class WindowManagerState : public EventProcessorDelegate,
public ServerWindowObserver,
public CursorStateDelegate {
public CursorStateDelegate,
public EventDispatcher {
public:
explicit WindowManagerState(WindowTree* window_tree);
~WindowManagerState() override;
......@@ -247,10 +249,6 @@ class WindowManagerState : public EventProcessorDelegate,
void AdjustEventLocation(int64_t display_id, LocatedEvent* event);
// EventProcessorDelegate:
void OnAccelerator(uint32_t accelerator_id,
int64_t display_id,
const Event& event,
AcceleratorPhase phase) override;
void SetFocusedWindowFromEventProcessor(ServerWindow* window) override;
ServerWindow* GetFocusedWindowForEventProcessor(int64_t display_id) override;
void SetNativeCapture(ServerWindow* window) override;
......@@ -264,11 +262,6 @@ class WindowManagerState : public EventProcessorDelegate,
bool visible) override;
void OnEventChangesCursorTouchVisibility(const ui::Event& event,
bool visible) override;
void DispatchInputEventToWindow(ServerWindow* target,
ClientSpecificId client_id,
const EventLocation& event_location,
const Event& event,
Accelerator* accelerator) override;
ClientSpecificId GetEventTargetClientId(const ServerWindow* window,
bool in_nonclient_area) override;
ServerWindow* GetRootWindowForDisplay(int64_t display_id) override;
......@@ -281,6 +274,17 @@ class WindowManagerState : public EventProcessorDelegate,
ServerWindow* GetWindowFromFrameSinkId(
const viz::FrameSinkId& frame_sink_id) override;
// EventDispatcher:
void DispatchInputEventToWindow(ServerWindow* target,
ClientSpecificId client_id,
const EventLocation& event_location,
const Event& event,
Accelerator* accelerator) override;
void OnAccelerator(uint32_t accelerator_id,
int64_t display_id,
const Event& event,
AcceleratorPhase phase) override;
// ServerWindowObserver:
void OnWindowEmbeddedAppDisconnected(ServerWindow* window) 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