Commit 6c0fedf2 authored by riajiang's avatar riajiang Committed by Commit Bot

Add EventTargeterDelegate for EventTargeter in mus-ws.

Right now EventTargeter talks to EventDispatcherDelegate directly but it
should not have any knowledge of EventDispatcherDelegate. Adding an
EventTargeterDelegate to route calls to EventDispatcher and then
EventDispatcherDelegate.

BUG=none, related to https://codereview.chromium.org/2905333002/
TEST=covered by tests

Review-Url: https://codereview.chromium.org/2911293002
Cr-Commit-Position: refs/heads/master@{#476483}
parent 8ea647a2
...@@ -48,6 +48,7 @@ static_library("lib") { ...@@ -48,6 +48,7 @@ static_library("lib") {
"event_matcher.h", "event_matcher.h",
"event_targeter.cc", "event_targeter.cc",
"event_targeter.h", "event_targeter.h",
"event_targeter_delegate.h",
"focus_controller.cc", "focus_controller.cc",
"focus_controller.h", "focus_controller.h",
"focus_controller_delegate.h", "focus_controller_delegate.h",
......
...@@ -47,8 +47,7 @@ EventDispatcher::EventDispatcher(EventDispatcherDelegate* delegate) ...@@ -47,8 +47,7 @@ EventDispatcher::EventDispatcher(EventDispatcherDelegate* delegate)
capture_window_client_id_(kInvalidClientId), capture_window_client_id_(kInvalidClientId),
modal_window_controller_(this), modal_window_controller_(this),
event_targeter_( event_targeter_(
base::MakeUnique<EventTargeter>(delegate_, base::MakeUnique<EventTargeter>(this, &modal_window_controller_)),
&modal_window_controller_)),
mouse_button_down_(false), mouse_button_down_(false),
mouse_cursor_source_window_(nullptr), mouse_cursor_source_window_(nullptr),
mouse_cursor_in_non_client_area_(false) {} mouse_cursor_in_non_client_area_(false) {}
...@@ -317,6 +316,12 @@ void EventDispatcher::ProcessEvent(const ui::Event& event, ...@@ -317,6 +316,12 @@ void EventDispatcher::ProcessEvent(const ui::Event& event,
return; return;
} }
ServerWindow* EventDispatcher::GetRootWindowContaining(
gfx::Point* location_in_display,
int64_t* display_id) {
return delegate_->GetRootWindowContaining(location_in_display, display_id);
}
void EventDispatcher::SetMouseCursorSourceWindow(ServerWindow* window) { void EventDispatcher::SetMouseCursorSourceWindow(ServerWindow* window) {
if (mouse_cursor_source_window_ == window) if (mouse_cursor_source_window_ == window)
return; return;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "services/ui/public/interfaces/window_manager.mojom.h" #include "services/ui/public/interfaces/window_manager.mojom.h"
#include "services/ui/ws/drag_cursor_updater.h" #include "services/ui/ws/drag_cursor_updater.h"
#include "services/ui/ws/event_targeter.h" #include "services/ui/ws/event_targeter.h"
#include "services/ui/ws/event_targeter_delegate.h"
#include "services/ui/ws/modal_window_controller.h" #include "services/ui/ws/modal_window_controller.h"
#include "services/ui/ws/server_window_observer.h" #include "services/ui/ws/server_window_observer.h"
#include "ui/gfx/geometry/rect_f.h" #include "ui/gfx/geometry/rect_f.h"
...@@ -41,7 +42,9 @@ class EventDispatcherTestApi; ...@@ -41,7 +42,9 @@ class EventDispatcherTestApi;
} }
// Handles dispatching events to the right location as well as updating focus. // Handles dispatching events to the right location as well as updating focus.
class EventDispatcher : public ServerWindowObserver, public DragCursorUpdater { class EventDispatcher : public ServerWindowObserver,
public DragCursorUpdater,
public EventTargeterDelegate {
public: public:
enum class AcceleratorMatchPhase { enum class AcceleratorMatchPhase {
// Both pre and post should be considered. // Both pre and post should be considered.
...@@ -148,6 +151,10 @@ class EventDispatcher : public ServerWindowObserver, public DragCursorUpdater { ...@@ -148,6 +151,10 @@ class EventDispatcher : public ServerWindowObserver, public DragCursorUpdater {
const int64_t display_id, const int64_t display_id,
AcceleratorMatchPhase match_phase); AcceleratorMatchPhase match_phase);
// EventTargeterDelegate:
ServerWindow* GetRootWindowContaining(gfx::Point* location_in_display,
int64_t* display_id) override;
private: private:
friend class test::EventDispatcherTestApi; friend class test::EventDispatcherTestApi;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "services/ui/ws/event_targeter.h" #include "services/ui/ws/event_targeter.h"
#include "services/ui/ws/event_dispatcher_delegate.h" #include "services/ui/ws/event_targeter_delegate.h"
#include "services/ui/ws/modal_window_controller.h" #include "services/ui/ws/modal_window_controller.h"
#include "services/ui/ws/window_finder.h" #include "services/ui/ws/window_finder.h"
#include "ui/events/event.h" #include "ui/events/event.h"
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
namespace ui { namespace ui {
namespace ws { namespace ws {
EventTargeter::EventTargeter(EventDispatcherDelegate* event_dispatcher_delegate, EventTargeter::EventTargeter(EventTargeterDelegate* event_targeter_delegate,
ModalWindowController* modal_window_controller) ModalWindowController* modal_window_controller)
: event_dispatcher_delegate_(event_dispatcher_delegate), : event_targeter_delegate_(event_targeter_delegate),
modal_window_controller_(modal_window_controller) {} modal_window_controller_(modal_window_controller) {}
EventTargeter::~EventTargeter() {} EventTargeter::~EventTargeter() {}
...@@ -41,7 +41,7 @@ DeepestWindow EventTargeter::FindDeepestVisibleWindowForEvents( ...@@ -41,7 +41,7 @@ DeepestWindow EventTargeter::FindDeepestVisibleWindowForEvents(
gfx::Point* location, gfx::Point* location,
int64_t* display_id) { int64_t* display_id) {
ServerWindow* root = ServerWindow* root =
event_dispatcher_delegate_->GetRootWindowContaining(location, display_id); event_targeter_delegate_->GetRootWindowContaining(location, display_id);
return root ? ui::ws::FindDeepestVisibleWindowForEvents(root, *location) return root ? ui::ws::FindDeepestVisibleWindowForEvents(root, *location)
: DeepestWindow(); : DeepestWindow();
} }
......
...@@ -18,7 +18,7 @@ class LocatedEvent; ...@@ -18,7 +18,7 @@ class LocatedEvent;
namespace ws { namespace ws {
struct DeepestWindow; struct DeepestWindow;
class EventDispatcherDelegate; class EventTargeterDelegate;
class ModalWindowController; class ModalWindowController;
class ServerWindow; class ServerWindow;
...@@ -46,7 +46,7 @@ struct PointerTarget { ...@@ -46,7 +46,7 @@ struct PointerTarget {
// Finds the PointerTarget for an event or the DeepestWindow for a location. // Finds the PointerTarget for an event or the DeepestWindow for a location.
class EventTargeter { class EventTargeter {
public: public:
EventTargeter(EventDispatcherDelegate* event_dispatcher_delegate, EventTargeter(EventTargeterDelegate* event_targeter_delegate,
ModalWindowController* modal_window_controller); ModalWindowController* modal_window_controller);
~EventTargeter(); ~EventTargeter();
...@@ -62,7 +62,7 @@ class EventTargeter { ...@@ -62,7 +62,7 @@ class EventTargeter {
int64_t* display_id); int64_t* display_id);
private: private:
EventDispatcherDelegate* event_dispatcher_delegate_; EventTargeterDelegate* event_targeter_delegate_;
ModalWindowController* modal_window_controller_; ModalWindowController* modal_window_controller_;
DISALLOW_COPY_AND_ASSIGN(EventTargeter); DISALLOW_COPY_AND_ASSIGN(EventTargeter);
......
// Copyright 2017 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_TARGETER_DELEGATE_H_
#define SERVICES_UI_WS_EVENT_TARGETER_DELEGATE_H_
#include <stdint.h>
namespace gfx {
class Point;
}
namespace ui {
namespace ws {
class ServerWindow;
// Used by EventTargeter to talk to WindowManagerState.
class EventTargeterDelegate {
public:
// Calls EventDispatcherDelegate::GetRootWindowContaining, see
// event_dispatcher_delegate.h for details.
virtual ServerWindow* GetRootWindowContaining(gfx::Point* location_in_display,
int64_t* display_id) = 0;
protected:
virtual ~EventTargeterDelegate() {}
};
} // namespace ws
} // namespace ui
#endif // SERVICES_UI_WS_EVENT_TARGETER_DELEGATE_H_
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