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 "base/macros.h" 9 #include "ui/events/event_targeter.h" 10 #include "ui/views/views_export.h" 11 12 namespace gfx { 13 class Rect; 14 } // namespace gfx 15 16 namespace ui { 17 class GestureEvent; 18 class KeyEvent; 19 class ScrollEvent; 20 } // namespace ui 21 22 namespace views { 23 24 class View; 25 class ViewTargeterDelegate; 26 27 // A ViewTargeter is installed on a View that wishes to use the custom 28 // hit-testing or event-targeting behaviour defined by |delegate|. 29 class VIEWS_EXPORT ViewTargeter : public ui::EventTargeter { 30 public: 31 explicit ViewTargeter(ViewTargeterDelegate* delegate); 32 ~ViewTargeter() override; 33 34 // A call-through to DoesIntersectRect() on |delegate_|. 35 bool DoesIntersectRect(const View* target, const gfx::Rect& rect) const; 36 37 // A call-through to TargetForRect() on |delegate_|. 38 View* TargetForRect(View* root, const gfx::Rect& rect) const; 39 40 protected: 41 // ui::EventTargeter: 42 ui::EventTarget* FindTargetForEvent(ui::EventTarget* root, 43 ui::Event* event) override; 44 ui::EventTarget* FindNextBestTarget(ui::EventTarget* previous_target, 45 ui::Event* event) override; 46 47 private: 48 View* FindTargetForKeyEvent(View* root, const ui::KeyEvent& key); 49 View* FindTargetForScrollEvent(View* root, const ui::ScrollEvent& scroll); 50 51 virtual View* FindTargetForGestureEvent(View* root, 52 const ui::GestureEvent& gesture); 53 virtual ui::EventTarget* FindNextBestTargetForGestureEvent( 54 ui::EventTarget* previous_target, 55 const ui::GestureEvent& gesture); 56 57 // ViewTargeter does not own the |delegate_|, but |delegate_| must 58 // outlive the targeter. 59 ViewTargeterDelegate* delegate_; 60 61 DISALLOW_COPY_AND_ASSIGN(ViewTargeter); 62 }; 63 64 } // namespace views 65 66 #endif // UI_VIEWS_VIEW_TARGETER_H_ 67