summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/layout/hit_test_location.h
blob: 08b8905658188a276c7d54c800c03c53571aef6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 * Copyright (C) 2006 Apple Computer, Inc.
 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
*/

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_HIT_TEST_LOCATION_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_HIT_TEST_LOCATION_H_

#include "base/memory/scoped_refptr.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/layout/geometry/physical_rect.h"
#include "third_party/blink/renderer/platform/geometry/float_quad.h"
#include "third_party/blink/renderer/platform/geometry/float_rect.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"

namespace blink {

class FloatRoundedRect;

class CORE_EXPORT HitTestLocation {
  DISALLOW_NEW();

 public:
  // Note that all points are in contents (aka "page") coordinate space for the
  // document that is being hit tested. All points and size are in root frame
  // coordinates (physical pixel scaled by page_scale when zoom for dsf is
  // enabled; otherwise in dip scaled by page_scale), Which means the points
  // should already applied page_scale_factor, but not page_zoom_factor and
  // scroll offset. See:
  // http://www.chromium.org/developers/design-documents/blink-coordinate-spaces
  HitTestLocation();
  explicit HitTestLocation(const PhysicalOffset&);
  explicit HitTestLocation(const IntPoint&);
  explicit HitTestLocation(const FloatPoint&);
  explicit HitTestLocation(const DoublePoint&);
  explicit HitTestLocation(const FloatPoint&, const FloatQuad&);
  explicit HitTestLocation(const PhysicalRect&);

  // The bounding box isn't always a 1x1 rect even when the hit test is not
  // rect-based. When we hit test a transformed box and transform the hit test
  // location into the box's local coordinate space, the bounding box should
  // also be transformed accordingly.
  explicit HitTestLocation(const FloatPoint& point,
                           const PhysicalRect& bounding_box);

  HitTestLocation(const HitTestLocation&, const PhysicalOffset& offset);
  HitTestLocation(const HitTestLocation&);
  ~HitTestLocation();
  HitTestLocation& operator=(const HitTestLocation&);

  const PhysicalOffset& Point() const { return point_; }
  IntPoint RoundedPoint() const { return RoundedIntPoint(point_); }

  // Rect-based hit test related methods.
  bool IsRectBasedTest() const { return is_rect_based_; }
  bool IsRectilinear() const { return is_rectilinear_; }
  const PhysicalRect& BoundingBox() const { return bounding_box_; }
  IntRect EnclosingIntRect() const {
    return ::blink::EnclosingIntRect(bounding_box_);
  }

  // Returns the 1px x 1px hit test rect for a point.
  static PhysicalRect RectForPoint(const PhysicalOffset& point) {
    return PhysicalRect(point, PhysicalSize(LayoutUnit(1), LayoutUnit(1)));
  }

  bool Intersects(const PhysicalRect&) const;
  // Uses floating-point intersection, which uses inclusive intersection
  // (see LayoutRect::InclusiveIntersect for a definition)
  bool Intersects(const FloatRect&) const;
  bool Intersects(const FloatRoundedRect&) const;
  bool Intersects(const FloatQuad&) const;
  bool ContainsPoint(const FloatPoint&) const;

  const FloatPoint& TransformedPoint() const { return transformed_point_; }
  const FloatQuad& TransformedRect() const { return transformed_rect_; }

 private:
  template <typename RectType>
  bool IntersectsRect(const RectType&, const RectType& bounding_box) const;
  void Move(const PhysicalOffset& offset);

  // These are cached forms of the more accurate |transformed_point_| and
  // |transformed_rect_|, below.
  PhysicalOffset point_;
  PhysicalRect bounding_box_;

  FloatPoint transformed_point_;
  FloatQuad transformed_rect_;

  bool is_rect_based_;
  bool is_rectilinear_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_HIT_TEST_LOCATION_H_