1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef UI_VIEWS_VIEW_TARGETER_H_ 6#define UI_VIEWS_VIEW_TARGETER_H_ 7 8#include "ui/events/event_targeter.h" 9#include "ui/views/views_export.h" 10 11namespace views { 12 13namespace internal { 14class RootView; 15} // namespace internal 16 17class View; 18class ViewTargeterDelegate; 19 20// A ViewTargeter is installed on a View that wishes to use the custom 21// hit-testing or event-targeting behaviour defined by |delegate|. 22class VIEWS_EXPORT ViewTargeter : public ui::EventTargeter { 23 public: 24 explicit ViewTargeter(ViewTargeterDelegate* delegate); 25 virtual ~ViewTargeter(); 26 27 // A call-through to DoesIntersectRect() on |delegate_|. 28 bool DoesIntersectRect(const View* target, const gfx::Rect& rect) const; 29 30 // A call-through to TargetForRect() on |delegate_|. 31 View* TargetForRect(View* root, const gfx::Rect& rect) const; 32 33 protected: 34 // ui::EventTargeter: 35 virtual ui::EventTarget* FindTargetForEvent(ui::EventTarget* root, 36 ui::Event* event) OVERRIDE; 37 virtual ui::EventTarget* FindNextBestTarget(ui::EventTarget* previous_target, 38 ui::Event* event) OVERRIDE; 39 virtual bool SubtreeCanAcceptEvent( 40 ui::EventTarget* target, 41 const ui::LocatedEvent& event) const OVERRIDE; 42 virtual bool EventLocationInsideBounds( 43 ui::EventTarget* target, 44 const ui::LocatedEvent& event) const OVERRIDE; 45 46 private: 47 // TODO(tdanderson): Un-friend RootView once RootView::DispatchGestureEvent() 48 // has been removed. 49 friend class internal::RootView; 50 51 View* FindTargetForKeyEvent(View* root, const ui::KeyEvent& key); 52 View* FindTargetForScrollEvent(View* root, const ui::ScrollEvent& scroll); 53 54 virtual View* FindTargetForGestureEvent(View* root, 55 const ui::GestureEvent& gesture); 56 virtual ui::EventTarget* FindNextBestTargetForGestureEvent( 57 ui::EventTarget* previous_target, 58 const ui::GestureEvent& gesture); 59 60 // ViewTargeter does not own the |delegate_|, but |delegate_| must 61 // outlive the targeter. 62 ViewTargeterDelegate* delegate_; 63 64 DISALLOW_COPY_AND_ASSIGN(ViewTargeter); 65}; 66 67} // namespace views 68 69#endif // UI_VIEWS_VIEW_TARGETER_H_ 70