OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_VIEWS_VIEW_TARGETER_DELEGATE_H_ | 5 #ifndef UI_VIEWS_VIEW_TARGETER_DELEGATE_H_ |
6 #define UI_VIEWS_VIEW_TARGETER_DELEGATE_H_ | 6 #define UI_VIEWS_VIEW_TARGETER_DELEGATE_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "ui/views/views_export.h" | 9 #include "ui/views/views_export.h" |
10 | 10 |
11 namespace gfx { | 11 namespace gfx { |
12 class Rect; | 12 class Rect; |
13 } | 13 } |
14 | 14 |
15 namespace views { | 15 namespace views { |
16 class View; | 16 class View; |
17 | 17 |
18 // Defines the default behaviour for hit-testing a rectangular region against | 18 // Defines the default behaviour for hit-testing and event-targeting against a |
19 // the bounds of a View. Subclasses of View wishing to define custom | 19 // View using a rectangular region representing an event's location. Views |
20 // hit-testing behaviour can extend this class. | 20 // wishing to define custom hit-testing or event-targeting behaviour do so by |
| 21 // extending ViewTargeterDelegate and then installing a ViewTargeter on |
| 22 // themselves. |
21 class VIEWS_EXPORT ViewTargeterDelegate { | 23 class VIEWS_EXPORT ViewTargeterDelegate { |
22 public: | 24 public: |
23 ViewTargeterDelegate() {} | 25 ViewTargeterDelegate() {} |
24 virtual ~ViewTargeterDelegate() {} | 26 virtual ~ViewTargeterDelegate() {} |
25 | 27 |
26 // Returns true if the bounds of |target| intersects |rect|, where |rect| | 28 // Returns true if the bounds of |target| intersects |rect|, where |rect| |
27 // is in the local coodinate space of |target|. Overrides of this method by | 29 // is in the local coodinate space of |target|. Overrides of this method by |
28 // a View subclass should enforce DCHECK_EQ(this, target). | 30 // a View subclass should enforce DCHECK_EQ(this, target). |
29 virtual bool DoesIntersectRect(const View* target, | 31 virtual bool DoesIntersectRect(const View* target, |
30 const gfx::Rect& rect) const; | 32 const gfx::Rect& rect) const; |
31 | 33 |
32 // If point-based targeting should be used, return the deepest visible | 34 // If point-based targeting should be used, return the deepest visible |
33 // descendant of |root| that contains the center point of |rect|. | 35 // descendant of |root| that contains the center point of |rect|. |
34 // If rect-based targeting (i.e., fuzzing) should be used, return the | 36 // If rect-based targeting (i.e., fuzzing) should be used, return the |
35 // closest visible descendant of |root| having at least kRectTargetOverlap of | 37 // closest visible descendant of |root| having at least kRectTargetOverlap of |
36 // its area covered by |rect|. If no such descendant exists, return the | 38 // its area covered by |rect|. If no such descendant exists, return the |
37 // deepest visible descendant of |root| that contains the center point of | 39 // deepest visible descendant of |root| that contains the center point of |
38 // |rect|. See http://goo.gl/3Jp2BD for more information about rect-based | 40 // |rect|. See http://goo.gl/3Jp2BD for more information about rect-based |
39 // targeting. | 41 // targeting. |
40 virtual View* TargetForRect(View* root, const gfx::Rect& rect); | 42 virtual View* TargetForRect(View* root, const gfx::Rect& rect); |
41 | 43 |
42 private: | 44 private: |
43 DISALLOW_COPY_AND_ASSIGN(ViewTargeterDelegate); | 45 DISALLOW_COPY_AND_ASSIGN(ViewTargeterDelegate); |
44 }; | 46 }; |
45 | 47 |
46 } // namespace views | 48 } // namespace views |
47 | 49 |
48 #endif // UI_VIEWS_VIEW_TARGETER_DELEGATE_H_ | 50 #endif // UI_VIEWS_VIEW_TARGETER_DELEGATE_H_ |
OLD | NEW |