From c981c4fc5303e185120e59229a38f45a74a39ac0 Mon Sep 17 00:00:00 2001 From: "tdanderson@chromium.org" Date: Tue, 6 May 2014 19:16:35 +0000 Subject: Some minor refactoring/cleanup between EventTargeter, ViewTargeter, and WindowTargeter In preparation for using the unified event targeting and dispatch code for scroll events in views, make some changes to the EventTargeter, ViewTargeter, and WindowTargeter classes: * Rename WindowTargeter::WindowCanAcceptEvent() to SubtreeCanAcceptEvent() and move its declaration up into EventTargeter. Both WindowTargeter and ViewTargeter will override this function. * Move the declaration of EventLocationInsideBounds() into EventTargeter. Both WindowTargeter and ViewTargeter will override this function. * Move the implementation of WindowTargeter::SubtreeShouldBeExploredForEvent() into EventTargeter since both WindowTargeter and ViewTargeter will require identical implementations of this function. BUG=366171 TEST=none Review URL: https://codereview.chromium.org/248033004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@268576 0039d316-1c4b-4281-b951-d872f2087c98 --- ui/aura/window_targeter.cc | 58 ++++++++++++++----------------- ui/aura/window_targeter.h | 16 +++------ ui/events/event_targeter.cc | 13 ++++++- ui/events/event_targeter.h | 25 +++++++++++-- ui/views/view_targeter.cc | 18 ++++++++++ ui/views/view_targeter.h | 6 ++++ ui/wm/core/easy_resize_window_targeter.cc | 3 +- ui/wm/core/easy_resize_window_targeter.h | 4 +-- ui/wm/core/masked_window_targeter.cc | 3 +- ui/wm/core/masked_window_targeter.h | 4 +-- 10 files changed, 97 insertions(+), 53 deletions(-) (limited to 'ui') diff --git a/ui/aura/window_targeter.cc b/ui/aura/window_targeter.cc index a572094..7a32de5 100644 --- a/ui/aura/window_targeter.cc +++ b/ui/aura/window_targeter.cc @@ -18,32 +18,6 @@ namespace aura { WindowTargeter::WindowTargeter() {} WindowTargeter::~WindowTargeter() {} -bool WindowTargeter::WindowCanAcceptEvent(aura::Window* window, - const ui::LocatedEvent& event) const { - 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(); - if (parent && parent->delegate_ && !parent->delegate_-> - ShouldDescendIntoChildForEventHandling(window, event.location())) { - return false; - } - return true; -} - -bool WindowTargeter::EventLocationInsideBounds( - aura::Window* window, const ui::LocatedEvent& event) const { - gfx::Point point = event.location(); - if (window->parent()) - aura::Window::ConvertPointToTarget(window->parent(), window, &point); - return gfx::Rect(window->bounds().size()).Contains(point); -} - ui::EventTarget* WindowTargeter::FindTargetForEvent(ui::EventTarget* root, ui::Event* event) { Window* window = static_cast(root); @@ -64,14 +38,34 @@ ui::EventTarget* WindowTargeter::FindTargetForEvent(ui::EventTarget* root, return target; } -bool WindowTargeter::SubtreeShouldBeExploredForEvent( - ui::EventTarget* root, - const ui::LocatedEvent& event) { - Window* window = static_cast(root); - if (!WindowCanAcceptEvent(window, event)) +bool WindowTargeter::SubtreeCanAcceptEvent( + ui::EventTarget* target, + const ui::LocatedEvent& event) const { + aura::Window* window = static_cast(target); + 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(); + if (parent && parent->delegate_ && !parent->delegate_-> + ShouldDescendIntoChildForEventHandling(window, event.location())) { return false; + } + return true; +} - return EventLocationInsideBounds(window, event); +bool WindowTargeter::EventLocationInsideBounds( + ui::EventTarget* target, + const ui::LocatedEvent& event) const { + aura::Window* window = static_cast(target); + gfx::Point point = event.location(); + if (window->parent()) + aura::Window::ConvertPointToTarget(window->parent(), window, &point); + return gfx::Rect(window->bounds().size()).Contains(point); } ui::EventTarget* WindowTargeter::FindTargetForLocatedEvent( diff --git a/ui/aura/window_targeter.h b/ui/aura/window_targeter.h index 0b0acb3..e64ef75 100644 --- a/ui/aura/window_targeter.h +++ b/ui/aura/window_targeter.h @@ -18,24 +18,18 @@ class AURA_EXPORT WindowTargeter : public ui::EventTargeter { virtual ~WindowTargeter(); protected: - bool WindowCanAcceptEvent(aura::Window* window, - const ui::LocatedEvent& event) const; - - // Returns whether the location of the event is in an actionable region of the - // window. Note that the location etc. of |event| is in the |window|'s - // parent's coordinate system. - virtual bool EventLocationInsideBounds(aura::Window* window, - const ui::LocatedEvent& event) const; - // ui::EventTargeter: virtual ui::EventTarget* FindTargetForEvent(ui::EventTarget* root, ui::Event* event) OVERRIDE; virtual ui::EventTarget* FindTargetForLocatedEvent( ui::EventTarget* root, ui::LocatedEvent* event) OVERRIDE; - virtual bool SubtreeShouldBeExploredForEvent( + virtual bool SubtreeCanAcceptEvent( + ui::EventTarget* target, + const ui::LocatedEvent& event) const OVERRIDE; + virtual bool EventLocationInsideBounds( ui::EventTarget* target, - const ui::LocatedEvent& event) OVERRIDE; + const ui::LocatedEvent& event) const OVERRIDE; private: Window* FindTargetForKeyEvent(Window* root_window, diff --git a/ui/events/event_targeter.cc b/ui/events/event_targeter.cc index 85b4c3f..e76b589 100644 --- a/ui/events/event_targeter.cc +++ b/ui/events/event_targeter.cc @@ -52,7 +52,8 @@ EventTarget* EventTargeter::FindTargetForLocatedEvent(EventTarget* root, bool EventTargeter::SubtreeShouldBeExploredForEvent(EventTarget* target, const LocatedEvent& event) { - return true; + return SubtreeCanAcceptEvent(target, event) && + EventLocationInsideBounds(target, event); } EventTarget* EventTargeter::FindNextBestTarget(EventTarget* previous_target, @@ -60,4 +61,14 @@ EventTarget* EventTargeter::FindNextBestTarget(EventTarget* previous_target, return NULL; } +bool EventTargeter::SubtreeCanAcceptEvent(EventTarget* target, + const LocatedEvent& event) const { + return true; +} + +bool EventTargeter::EventLocationInsideBounds(EventTarget* target, + const LocatedEvent& event) const { + return true; +} + } // namespace ui diff --git a/ui/events/event_targeter.h b/ui/events/event_targeter.h index 44ea2a05..dead49f 100644 --- a/ui/events/event_targeter.h +++ b/ui/events/event_targeter.h @@ -32,9 +32,13 @@ class EVENTS_EXPORT EventTargeter { virtual EventTarget* FindTargetForLocatedEvent(EventTarget* root, LocatedEvent* event); - // Returns true of |target| or one of its descendants can be a target of - // |event|. Note that the location etc. of |event| is in |target|'s parent's - // coordinate system. + // Returns true if |target| or one of its descendants can be a target of + // |event|. This requires that |target| and its descendants are not + // prohibited from accepting the event, and that the event is within an + // actionable region of the target's bounds. Note that the location etc. of + // |event| is in |target|'s parent's coordinate system. + // TODO(tdanderson|sadrul): This function should be made non-virtual and + // non-public. virtual bool SubtreeShouldBeExploredForEvent(EventTarget* target, const LocatedEvent& event); @@ -44,6 +48,21 @@ class EVENTS_EXPORT EventTargeter { // coordinate space). virtual EventTarget* FindNextBestTarget(EventTarget* previous_target, Event* event); + + protected: + // Returns false if neither |target| nor any of its descendants are allowed + // to accept |event| for reasons unrelated to the event's location or the + // target's bounds. For example, overrides of this function may consider + // attributes such as the visibility or enabledness of |target|. Note that + // the location etc. of |event| is in |target|'s parent's coordinate system. + virtual bool SubtreeCanAcceptEvent(EventTarget* target, + const LocatedEvent& event) const; + + // Returns whether the location of the event is in an actionable region of the + // target. Note that the location etc. of |event| is in the |target|'s + // parent's coordinate system. + virtual bool EventLocationInsideBounds(EventTarget* target, + const LocatedEvent& event) const; }; } // namespace ui diff --git a/ui/views/view_targeter.cc b/ui/views/view_targeter.cc index 2ad07d7..7d7005a 100644 --- a/ui/views/view_targeter.cc +++ b/ui/views/view_targeter.cc @@ -29,6 +29,24 @@ ui::EventTarget* ViewTargeter::FindNextBestTarget( return previous_target->GetParentTarget(); } +bool ViewTargeter::SubtreeCanAcceptEvent( + ui::EventTarget* target, + const ui::LocatedEvent& event) const { + // TODO(tdanderson): Complete implementation when support for + // scroll events are added. + NOTREACHED(); + return true; +} + +bool ViewTargeter::EventLocationInsideBounds( + ui::EventTarget* target, + const ui::LocatedEvent& event) const { + // TODO(tdanderson): Complete implementation when support for + // scroll events are added. + NOTREACHED(); + return true; +} + View* ViewTargeter::FindTargetForKeyEvent(View* view, const ui::KeyEvent& key) { if (view->GetFocusManager()) return view->GetFocusManager()->GetFocusedView(); diff --git a/ui/views/view_targeter.h b/ui/views/view_targeter.h index 8426727..4cb3476 100644 --- a/ui/views/view_targeter.h +++ b/ui/views/view_targeter.h @@ -28,6 +28,12 @@ class VIEWS_EXPORT ViewTargeter : public ui::EventTargeter { ui::Event* event) OVERRIDE; virtual ui::EventTarget* FindNextBestTarget(ui::EventTarget* previous_target, ui::Event* event) OVERRIDE; + virtual bool SubtreeCanAcceptEvent( + ui::EventTarget* target, + const ui::LocatedEvent& event) const OVERRIDE; + virtual bool EventLocationInsideBounds( + ui::EventTarget* target, + const ui::LocatedEvent& event) const OVERRIDE; private: View* FindTargetForKeyEvent(View* view, const ui::KeyEvent& key); diff --git a/ui/wm/core/easy_resize_window_targeter.cc b/ui/wm/core/easy_resize_window_targeter.cc index d352e52..445028c 100644 --- a/ui/wm/core/easy_resize_window_targeter.cc +++ b/ui/wm/core/easy_resize_window_targeter.cc @@ -24,8 +24,9 @@ EasyResizeWindowTargeter::~EasyResizeWindowTargeter() { } bool EasyResizeWindowTargeter::EventLocationInsideBounds( - aura::Window* window, + ui::EventTarget* target, const ui::LocatedEvent& event) const { + aura::Window* window = static_cast(target); if (ShouldUseExtendedBounds(window)) { // Note that |event|'s location is in |window|'s parent's coordinate system, // so convert it to |window|'s coordinate system first. diff --git a/ui/wm/core/easy_resize_window_targeter.h b/ui/wm/core/easy_resize_window_targeter.h index 90b0848..35b9eb2 100644 --- a/ui/wm/core/easy_resize_window_targeter.h +++ b/ui/wm/core/easy_resize_window_targeter.h @@ -31,9 +31,9 @@ class WM_EXPORT EasyResizeWindowTargeter : public aura::WindowTargeter { touch_extend_ = touch_extend; } - // aura::WindowTargeter: + // ui::EventTargeter: virtual bool EventLocationInsideBounds( - aura::Window* window, + ui::EventTarget* target, const ui::LocatedEvent& event) const OVERRIDE; private: diff --git a/ui/wm/core/masked_window_targeter.cc b/ui/wm/core/masked_window_targeter.cc index 4cc26d5..5cbdb19 100644 --- a/ui/wm/core/masked_window_targeter.cc +++ b/ui/wm/core/masked_window_targeter.cc @@ -16,8 +16,9 @@ MaskedWindowTargeter::MaskedWindowTargeter(aura::Window* masked_window) MaskedWindowTargeter::~MaskedWindowTargeter() {} bool MaskedWindowTargeter::EventLocationInsideBounds( - aura::Window* window, + ui::EventTarget* target, const ui::LocatedEvent& event) const { + aura::Window* window = static_cast(target); if (window == masked_window_) { gfx::Path mask; if (!GetHitTestMask(window, &mask)) diff --git a/ui/wm/core/masked_window_targeter.h b/ui/wm/core/masked_window_targeter.h index 46cf4d2..61bb3b1e 100644 --- a/ui/wm/core/masked_window_targeter.h +++ b/ui/wm/core/masked_window_targeter.h @@ -24,9 +24,9 @@ class WM_EXPORT MaskedWindowTargeter : public aura::WindowTargeter { // coordinate system). Returns whether a valid mask has been set in |mask|. virtual bool GetHitTestMask(aura::Window* window, gfx::Path* mask) const = 0; - // aura::WindowTargeter: + // ui::EventTargeter: virtual bool EventLocationInsideBounds( - aura::Window* window, + ui::EventTarget* target, const ui::LocatedEvent& event) const OVERRIDE; private: -- cgit v1.1