Commit 91c9d380 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

chromeos: remove unnecessary subclass of WindowTargeter

This was a subclass purely because WindowTargeter implements
EventTargeter functions in a protected block. Given it is expected
that WindowTargeter is an EventTargeter and EventTargeter is not an
implementation detail it seems the overrides should be in the public
section.

BUG=none
TEST=none

Change-Id: Ib93232ad50a072a63a4beb982e9f265a606b6cbe
Reviewed-on: https://chromium-review.googlesource.com/544680Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#481873}
parent 8d06e9e1
...@@ -38,47 +38,40 @@ void EnableMouseWarp(bool enable) { ...@@ -38,47 +38,40 @@ void EnableMouseWarp(bool enable) {
Shell::Get()->mouse_cursor_filter()->set_mouse_warp_enabled(enable); Shell::Get()->mouse_cursor_filter()->set_mouse_warp_enabled(enable);
} }
class ScreenshotWindowTargeter : public aura::WindowTargeter { // Returns the target for the specified event ignorning any capture windows.
public: aura::Window* FindWindowForEvent(const ui::LocatedEvent& event) {
ScreenshotWindowTargeter() = default; aura::Window* target = static_cast<aura::Window*>(event.target());
~ScreenshotWindowTargeter() override = default; aura::Window* target_root = target->GetRootWindow();
aura::Window* FindWindowForEvent(ui::LocatedEvent* event) {
aura::Window* target = static_cast<aura::Window*>(event->target());
aura::Window* target_root = target->GetRootWindow();
aura::client::ScreenPositionClient* position_client = aura::client::ScreenPositionClient* position_client =
aura::client::GetScreenPositionClient(target_root); aura::client::GetScreenPositionClient(target_root);
gfx::Point location = event->location(); gfx::Point location = event.location();
position_client->ConvertPointToScreen(target, &location); position_client->ConvertPointToScreen(target, &location);
display::Display display = display::Display display =
display::Screen::GetScreen()->GetDisplayNearestPoint(location); display::Screen::GetScreen()->GetDisplayNearestPoint(location);
aura::Window* root_window = Shell::GetRootWindowForDisplayId(display.id()); aura::Window* root_window = Shell::GetRootWindowForDisplayId(display.id());
position_client->ConvertPointFromScreen(root_window, &location); position_client->ConvertPointFromScreen(root_window, &location);
gfx::Point target_location = event->location(); std::unique_ptr<ui::Event> cloned_event = ui::Event::Clone(event);
event->set_location(location); ui::LocatedEvent* cloned_located_event = cloned_event->AsLocatedEvent();
cloned_located_event->set_location(location);
// Ignore capture window when finding the target for located event. // Ignore capture window when finding the target for located event.
aura::client::CaptureClient* original_capture_client = aura::client::CaptureClient* original_capture_client =
aura::client::GetCaptureClient(root_window); aura::client::GetCaptureClient(root_window);
aura::client::SetCaptureClient(root_window, nullptr); aura::client::SetCaptureClient(root_window, nullptr);
aura::Window* selected = aura::Window* selected =
static_cast<aura::Window*>(FindTargetForEvent(root_window, event)); static_cast<aura::Window*>(aura::WindowTargeter().FindTargetForEvent(
root_window, cloned_located_event));
// Restore State.
aura::client::SetCaptureClient(root_window, original_capture_client);
event->set_location(target_location);
return selected;
}
private: // Restore State.
DISALLOW_COPY_AND_ASSIGN(ScreenshotWindowTargeter); aura::client::SetCaptureClient(root_window, original_capture_client);
}; return selected;
}
} // namespace } // namespace
...@@ -425,8 +418,8 @@ void ScreenshotController::Update(const ui::LocatedEvent& event) { ...@@ -425,8 +418,8 @@ void ScreenshotController::Update(const ui::LocatedEvent& event) {
::abs(start_position_.y() - event.root_location().y()))); ::abs(start_position_.y() - event.root_location().y())));
} }
void ScreenshotController::UpdateSelectedWindow(ui::LocatedEvent* event) { void ScreenshotController::UpdateSelectedWindow(const ui::LocatedEvent& event) {
aura::Window* selected = ScreenshotWindowTargeter().FindWindowForEvent(event); aura::Window* selected = FindWindowForEvent(event);
// Find a window that is backed with a widget. // Find a window that is backed with a widget.
while (selected && (selected->type() == aura::client::WINDOW_TYPE_CONTROL || while (selected && (selected->type() == aura::client::WINDOW_TYPE_CONTROL ||
...@@ -495,7 +488,7 @@ void ScreenshotController::OnMouseEvent(ui::MouseEvent* event) { ...@@ -495,7 +488,7 @@ void ScreenshotController::OnMouseEvent(ui::MouseEvent* event) {
switch (event->type()) { switch (event->type()) {
case ui::ET_MOUSE_MOVED: case ui::ET_MOUSE_MOVED:
case ui::ET_MOUSE_DRAGGED: case ui::ET_MOUSE_DRAGGED:
UpdateSelectedWindow(event); UpdateSelectedWindow(*event);
break; break;
case ui::ET_MOUSE_RELEASED: case ui::ET_MOUSE_RELEASED:
CompleteWindowScreenshot(); CompleteWindowScreenshot();
...@@ -536,7 +529,7 @@ void ScreenshotController::OnTouchEvent(ui::TouchEvent* event) { ...@@ -536,7 +529,7 @@ void ScreenshotController::OnTouchEvent(ui::TouchEvent* event) {
switch (event->type()) { switch (event->type()) {
case ui::ET_TOUCH_PRESSED: case ui::ET_TOUCH_PRESSED:
case ui::ET_TOUCH_MOVED: case ui::ET_TOUCH_MOVED:
UpdateSelectedWindow(event); UpdateSelectedWindow(*event);
break; break;
case ui::ET_TOUCH_RELEASED: case ui::ET_TOUCH_RELEASED:
CompleteWindowScreenshot(); CompleteWindowScreenshot();
......
...@@ -90,7 +90,7 @@ class ASH_EXPORT ScreenshotController : public ui::EventHandler, ...@@ -90,7 +90,7 @@ class ASH_EXPORT ScreenshotController : public ui::EventHandler,
void CompleteWindowScreenshot(); void CompleteWindowScreenshot();
void CompletePartialScreenshot(); void CompletePartialScreenshot();
void Update(const ui::LocatedEvent& event); void Update(const ui::LocatedEvent& event);
void UpdateSelectedWindow(ui::LocatedEvent* event); void UpdateSelectedWindow(const ui::LocatedEvent& event);
void SetSelectedWindow(aura::Window* window); void SetSelectedWindow(aura::Window* window);
// Returns true if the event should be processed. // Returns true if the event should be processed.
......
...@@ -19,44 +19,48 @@ namespace aura { ...@@ -19,44 +19,48 @@ namespace aura {
WindowTargeter::WindowTargeter() {} WindowTargeter::WindowTargeter() {}
WindowTargeter::~WindowTargeter() {} WindowTargeter::~WindowTargeter() {}
Window* WindowTargeter::FindTargetForLocatedEvent(Window* window, bool WindowTargeter::SubtreeShouldBeExploredForEvent(
ui::LocatedEvent* event) { Window* window,
if (!window->parent()) { const ui::LocatedEvent& event) {
Window* target = FindTargetInRootWindow(window, *event); return SubtreeCanAcceptEvent(window, event) &&
if (target) { EventLocationInsideBounds(window, event);
window->ConvertEventToTarget(target, event);
return target;
}
}
return FindTargetForLocatedEventRecursively(window, event);
} }
bool WindowTargeter::SubtreeCanAcceptEvent( Window* WindowTargeter::FindTargetInRootWindow(Window* root_window,
Window* window, const ui::LocatedEvent& event) {
const ui::LocatedEvent& event) const { DCHECK_EQ(root_window, root_window->GetRootWindow());
if (!window->IsVisible())
return false;
if (window->ignore_events())
return false;
client::EventClient* client = client::GetEventClient(window->GetRootWindow());
if (client && !client->CanProcessEventsWithinSubtree(window))
return false;
Window* parent = window->parent(); // Mouse events should be dispatched to the window that processed the
if (parent && parent->delegate_ && !parent->delegate_-> // mouse-press events (if any).
ShouldDescendIntoChildForEventHandling(window, event.location())) { if (event.IsScrollEvent() || event.IsMouseEvent()) {
return false; WindowEventDispatcher* dispatcher = root_window->GetHost()->dispatcher();
if (dispatcher->mouse_pressed_handler())
return dispatcher->mouse_pressed_handler();
} }
return true;
}
bool WindowTargeter::EventLocationInsideBounds( // All events should be directed towards the capture window (if any).
Window* window, Window* capture_window = client::GetCaptureWindow(root_window);
const ui::LocatedEvent& event) const { if (capture_window)
gfx::Point point = event.location(); return capture_window;
if (window->parent())
Window::ConvertPointToTarget(window->parent(), window, &point); if (event.IsTouchEvent()) {
return gfx::Rect(window->bounds().size()).Contains(point); // Query the gesture-recognizer to find targets for touch events.
const ui::TouchEvent& touch = *event.AsTouchEvent();
ui::GestureConsumer* consumer =
ui::GestureRecognizer::Get()->GetTouchLockedTarget(touch);
if (consumer)
return static_cast<Window*>(consumer);
consumer = ui::GestureRecognizer::Get()->GetTargetForLocation(
event.location_f(), touch.source_device_id());
if (consumer)
return static_cast<Window*>(consumer);
// If the initial touch is outside the root window, target the root.
if (!root_window->bounds().Contains(event.location()))
return root_window;
}
return nullptr;
} }
ui::EventTarget* WindowTargeter::FindTargetForEvent(ui::EventTarget* root, ui::EventTarget* WindowTargeter::FindTargetForEvent(ui::EventTarget* root,
...@@ -95,11 +99,45 @@ ui::EventTarget* WindowTargeter::FindNextBestTarget( ...@@ -95,11 +99,45 @@ ui::EventTarget* WindowTargeter::FindNextBestTarget(
return nullptr; return nullptr;
} }
bool WindowTargeter::SubtreeShouldBeExploredForEvent( Window* WindowTargeter::FindTargetForLocatedEvent(Window* window,
ui::LocatedEvent* event) {
if (!window->parent()) {
Window* target = FindTargetInRootWindow(window, *event);
if (target) {
window->ConvertEventToTarget(target, event);
return target;
}
}
return FindTargetForLocatedEventRecursively(window, event);
}
bool WindowTargeter::SubtreeCanAcceptEvent(
Window* window, Window* window,
const ui::LocatedEvent& event) { const ui::LocatedEvent& event) const {
return SubtreeCanAcceptEvent(window, event) && if (!window->IsVisible())
EventLocationInsideBounds(window, event); return false;
if (window->ignore_events())
return false;
client::EventClient* client = client::GetEventClient(window->GetRootWindow());
if (client && !client->CanProcessEventsWithinSubtree(window))
return false;
Window* parent = window->parent();
if (parent && parent->delegate_ &&
!parent->delegate_->ShouldDescendIntoChildForEventHandling(
window, event.location())) {
return false;
}
return true;
}
bool WindowTargeter::EventLocationInsideBounds(
Window* window,
const ui::LocatedEvent& event) const {
gfx::Point point = event.location();
if (window->parent())
Window::ConvertPointToTarget(window->parent(), window, &point);
return gfx::Rect(window->bounds().size()).Contains(point);
} }
Window* WindowTargeter::FindTargetForKeyEvent(Window* window, Window* WindowTargeter::FindTargetForKeyEvent(Window* window,
...@@ -129,43 +167,6 @@ Window* WindowTargeter::FindTargetForNonKeyEvent(Window* root_window, ...@@ -129,43 +167,6 @@ Window* WindowTargeter::FindTargetForNonKeyEvent(Window* root_window,
static_cast<ui::LocatedEvent*>(event)); static_cast<ui::LocatedEvent*>(event));
} }
Window* WindowTargeter::FindTargetInRootWindow(Window* root_window,
const ui::LocatedEvent& event) {
DCHECK_EQ(root_window, root_window->GetRootWindow());
// Mouse events should be dispatched to the window that processed the
// mouse-press events (if any).
if (event.IsScrollEvent() || event.IsMouseEvent()) {
WindowEventDispatcher* dispatcher = root_window->GetHost()->dispatcher();
if (dispatcher->mouse_pressed_handler())
return dispatcher->mouse_pressed_handler();
}
// All events should be directed towards the capture window (if any).
Window* capture_window = client::GetCaptureWindow(root_window);
if (capture_window)
return capture_window;
if (event.IsTouchEvent()) {
// Query the gesture-recognizer to find targets for touch events.
const ui::TouchEvent& touch = *event.AsTouchEvent();
ui::GestureConsumer* consumer =
ui::GestureRecognizer::Get()->GetTouchLockedTarget(touch);
if (consumer)
return static_cast<Window*>(consumer);
consumer = ui::GestureRecognizer::Get()->GetTargetForLocation(
event.location_f(), touch.source_device_id());
if (consumer)
return static_cast<Window*>(consumer);
// If the initial touch is outside the root window, target the root.
if (!root_window->bounds().Contains(event.location()))
return root_window;
}
return nullptr;
}
Window* WindowTargeter::FindTargetForLocatedEventRecursively( Window* WindowTargeter::FindTargetForLocatedEventRecursively(
Window* root_window, Window* root_window,
ui::LocatedEvent* event) { ui::LocatedEvent* event) {
......
...@@ -34,6 +34,12 @@ class AURA_EXPORT WindowTargeter : public ui::EventTargeter { ...@@ -34,6 +34,12 @@ class AURA_EXPORT WindowTargeter : public ui::EventTargeter {
Window* FindTargetInRootWindow(Window* root_window, Window* FindTargetInRootWindow(Window* root_window,
const ui::LocatedEvent& event); const ui::LocatedEvent& event);
// ui::EventTargeter:
ui::EventTarget* FindTargetForEvent(ui::EventTarget* root,
ui::Event* event) override;
ui::EventTarget* FindNextBestTarget(ui::EventTarget* previous_target,
ui::Event* event) override;
protected: protected:
// Same as FindTargetForEvent(), but used for positional events. The location // Same as FindTargetForEvent(), but used for positional events. The location
// etc. of |event| are in |root|'s coordinate system. When finding the target // etc. of |event| are in |root|'s coordinate system. When finding the target
...@@ -57,12 +63,6 @@ class AURA_EXPORT WindowTargeter : public ui::EventTargeter { ...@@ -57,12 +63,6 @@ class AURA_EXPORT WindowTargeter : public ui::EventTargeter {
virtual bool EventLocationInsideBounds(Window* target, virtual bool EventLocationInsideBounds(Window* target,
const ui::LocatedEvent& event) const; const ui::LocatedEvent& event) const;
// ui::EventTargeter:
ui::EventTarget* FindTargetForEvent(ui::EventTarget* root,
ui::Event* event) override;
ui::EventTarget* FindNextBestTarget(ui::EventTarget* previous_target,
ui::Event* event) override;
private: private:
Window* FindTargetForKeyEvent(Window* root_window, const ui::KeyEvent& event); Window* FindTargetForKeyEvent(Window* root_window, const ui::KeyEvent& event);
Window* FindTargetForNonKeyEvent(Window* root_window, ui::Event* event); Window* FindTargetForNonKeyEvent(Window* root_window, ui::Event* event);
......
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