• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 Apple Computer, Inc.
3  * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  *
20 */
21 
22 #ifndef HitTestLocation_h
23 #define HitTestLocation_h
24 
25 #include "platform/geometry/FloatQuad.h"
26 #include "platform/geometry/FloatRect.h"
27 #include "platform/geometry/LayoutRect.h"
28 #include "platform/geometry/RoundedRect.h"
29 #include "wtf/Forward.h"
30 #include "wtf/ListHashSet.h"
31 #include "wtf/OwnPtr.h"
32 #include "wtf/RefPtr.h"
33 
34 namespace WebCore {
35 
36 class HitTestLocation {
37 public:
38 
39     HitTestLocation();
40     HitTestLocation(const LayoutPoint&);
41     HitTestLocation(const FloatPoint&);
42     HitTestLocation(const FloatPoint&, const FloatQuad&);
43     // Pass non-zero padding values to perform a rect-based hit test.
44     HitTestLocation(const LayoutPoint& centerPoint, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding);
45     HitTestLocation(const HitTestLocation&, const LayoutSize& offset);
46     HitTestLocation(const HitTestLocation&);
47     ~HitTestLocation();
48     HitTestLocation& operator=(const HitTestLocation&);
49 
point()50     const LayoutPoint& point() const { return m_point; }
roundedPoint()51     IntPoint roundedPoint() const { return roundedIntPoint(m_point); }
52 
53     // Rect-based hit test related methods.
isRectBasedTest()54     bool isRectBasedTest() const { return m_isRectBased; }
isRectilinear()55     bool isRectilinear() const { return m_isRectilinear; }
boundingBox()56     IntRect boundingBox() const { return m_boundingBox; }
57 
58     static IntRect rectForPoint(const LayoutPoint&, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding);
topPadding()59     int topPadding() const { return roundedPoint().y() - m_boundingBox.y(); }
rightPadding()60     int rightPadding() const { return m_boundingBox.maxX() - roundedPoint().x() - 1; }
bottomPadding()61     int bottomPadding() const { return m_boundingBox.maxY() - roundedPoint().y() - 1; }
leftPadding()62     int leftPadding() const { return roundedPoint().x() - m_boundingBox.x(); }
63 
64     bool intersects(const LayoutRect&) const;
65     bool intersects(const FloatRect&) const;
66     bool intersects(const RoundedRect&) const;
67 
transformedPoint()68     const FloatPoint& transformedPoint() const { return m_transformedPoint; }
transformedRect()69     const FloatQuad& transformedRect() const { return m_transformedRect; }
70 
71 private:
72     template<typename RectType>
73     bool intersectsRect(const RectType&) const;
74     void move(const LayoutSize& offset);
75 
76     // This is cached forms of the more accurate point and area below.
77     LayoutPoint m_point;
78     IntRect m_boundingBox;
79 
80     FloatPoint m_transformedPoint;
81     FloatQuad m_transformedRect;
82 
83     bool m_isRectBased;
84     bool m_isRectilinear;
85 };
86 
87 } // namespace WebCore
88 
89 #endif // HitTestLocation_h
90