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_DELEGATE_H_
6#define UI_VIEWS_VIEW_TARGETER_DELEGATE_H_
7
8#include "base/macros.h"
9#include "ui/views/views_export.h"
10
11namespace gfx {
12class Rect;
13}
14
15namespace views {
16class View;
17
18// Defines the default behaviour for hit-testing and event-targeting against a
19// View using a rectangular region representing an event's location. Views
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.
23class VIEWS_EXPORT ViewTargeterDelegate {
24 public:
25  ViewTargeterDelegate() {}
26  virtual ~ViewTargeterDelegate() {}
27
28  // Returns true if the bounds of |target| intersects |rect|, where |rect|
29  // is in the local coodinate space of |target|. Overrides of this method by
30  // a View subclass should enforce DCHECK_EQ(this, target).
31  virtual bool DoesIntersectRect(const View* target,
32                                 const gfx::Rect& rect) const;
33
34  // If point-based targeting should be used, return the deepest visible
35  // descendant of |root| that contains the center point of |rect|.
36  // If rect-based targeting (i.e., fuzzing) should be used, return the
37  // closest visible descendant of |root| having at least kRectTargetOverlap of
38  // its area covered by |rect|. If no such descendant exists, return the
39  // deepest visible descendant of |root| that contains the center point of
40  // |rect|. See http://goo.gl/3Jp2BD for more information about rect-based
41  // targeting.
42  virtual View* TargetForRect(View* root, const gfx::Rect& rect);
43
44 private:
45  DISALLOW_COPY_AND_ASSIGN(ViewTargeterDelegate);
46};
47
48}  // namespace views
49
50#endif  // UI_VIEWS_VIEW_TARGETER_DELEGATE_H_
51