2 * Copyright (C) 2006 Apple Computer, Inc.
3 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
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.
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.
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.
22 #ifndef HitTestResult_h
23 #define HitTestResult_h
25 #include "FloatQuad.h"
26 #include "FloatRect.h"
27 #include "HitTestRequest.h"
28 #include "LayoutTypes.h"
29 #include "TextDirection.h"
30 #include <wtf/Forward.h>
31 #include <wtf/ListHashSet.h>
32 #include <wtf/OwnPtr.h>
33 #include <wtf/RefPtr.h>
40 class HTMLMediaElement;
48 enum ShadowContentFilterPolicy { DoNotAllowShadowContent, AllowShadowContent };
54 HitTestPoint(const LayoutPoint&);
55 HitTestPoint(const FloatPoint&);
56 HitTestPoint(const FloatPoint&, const FloatQuad&);
57 // Pass non-zero padding values to perform a rect-based hit test.
58 HitTestPoint(const LayoutPoint& centerPoint, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding);
59 // Make a copy the HitTestPoint in a new region by applying given offset to internal point and area.
60 HitTestPoint(const HitTestPoint&, const LayoutSize& offset, RenderRegion*);
61 HitTestPoint(const HitTestPoint&);
63 HitTestPoint& operator=(const HitTestPoint&);
65 LayoutPoint point() const { return m_point; }
66 IntPoint roundedPoint() const { return roundedIntPoint(m_point); }
68 RenderRegion* region() const { return m_region; }
70 // Rect-based hit test related methods.
71 bool isRectBasedTest() const { return m_isRectBased; }
72 bool isRectilinear() const { return m_isRectilinear; }
73 IntRect boundingBox() const { return m_boundingBox; }
75 static IntRect rectForPoint(const LayoutPoint&, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding);
76 int topPadding() const { return roundedPoint().y() - m_boundingBox.y(); }
77 int rightPadding() const { return m_boundingBox.maxX() - roundedPoint().x() - 1; }
78 int bottomPadding() const { return m_boundingBox.maxY() - roundedPoint().y() - 1; }
79 int leftPadding() const { return roundedPoint().x() - m_boundingBox.x(); }
81 bool intersects(const LayoutRect&) const;
82 bool intersects(const FloatRect&) const;
84 const FloatPoint& transformedPoint() const { return m_transformedPoint; }
85 const FloatQuad& transformedRect() const { return m_transformedRect; }
88 template<typename RectType>
89 bool intersectsRect(const RectType&) const;
90 void move(const LayoutSize& offset);
92 // This is cached forms of the more accurate point and area below.
94 IntRect m_boundingBox;
96 FloatPoint m_transformedPoint;
97 FloatQuad m_transformedRect;
99 RenderRegion* m_region; // The region we're inside.
102 bool m_isRectilinear;
105 class HitTestResult : public HitTestPoint {
107 typedef ListHashSet<RefPtr<Node> > NodeSet;
110 HitTestResult(const LayoutPoint&);
111 // Pass non-negative padding values to perform a rect-based hit test.
112 HitTestResult(const LayoutPoint& centerPoint, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding, ShadowContentFilterPolicy);
113 HitTestResult(const HitTestPoint&, ShadowContentFilterPolicy);
114 HitTestResult(const HitTestResult&);
116 HitTestResult& operator=(const HitTestResult&);
118 Node* innerNode() const { return m_innerNode.get(); }
119 Node* innerNonSharedNode() const { return m_innerNonSharedNode.get(); }
120 LayoutPoint localPoint() const { return m_localPoint; }
121 Element* URLElement() const { return m_innerURLElement.get(); }
122 Scrollbar* scrollbar() const { return m_scrollbar.get(); }
123 bool isOverWidget() const { return m_isOverWidget; }
125 void setToNonShadowAncestor();
127 const HitTestPoint& hitTestPoint() const { return *this; }
128 ShadowContentFilterPolicy shadowContentFilterPolicy() const { return m_shadowContentFilterPolicy; }
130 void setInnerNode(Node*);
131 void setInnerNonSharedNode(Node*);
132 void setLocalPoint(const LayoutPoint& p) { m_localPoint = p; }
133 void setURLElement(Element*);
134 void setScrollbar(Scrollbar*);
135 void setIsOverWidget(bool b) { m_isOverWidget = b; }
137 Frame* targetFrame() const;
138 bool isSelected() const;
139 String spellingToolTip(TextDirection&) const;
140 String replacedString() const;
141 String title(TextDirection&) const;
142 String innerTextIfTruncated(TextDirection&) const;
143 String altDisplayString() const;
144 String titleDisplayString() const;
145 Image* image() const;
146 IntRect imageRect() const;
147 KURL absoluteImageURL() const;
148 KURL absolutePDFURL() const;
149 KURL absoluteMediaURL() const;
150 KURL absoluteLinkURL() const;
151 String textContent() const;
152 bool isLiveLink() const;
153 bool isContentEditable() const;
154 void toggleMediaControlsDisplay() const;
155 void toggleMediaLoopPlayback() const;
156 void enterFullscreenForVideo() const;
157 bool mediaControlsEnabled() const;
158 bool mediaLoopEnabled() const;
159 bool mediaPlaying() const;
160 bool mediaSupportsFullscreen() const;
161 void toggleMediaPlayState() const;
162 bool mediaHasAudio() const;
163 bool mediaIsVideo() const;
164 bool mediaMuted() const;
165 void toggleMediaMuteState() const;
167 // Returns true if it is rect-based hit test and needs to continue until the rect is fully
168 // enclosed by the boundaries of a node.
169 bool addNodeToRectBasedTestResult(Node*, const HitTestPoint& pointInContainer, const LayoutRect& = LayoutRect());
170 bool addNodeToRectBasedTestResult(Node*, const HitTestPoint& pointInContainer, const FloatRect&);
171 void append(const HitTestResult&);
173 // If m_rectBasedTestResult is 0 then set it to a new NodeSet. Return *m_rectBasedTestResult. Lazy allocation makes
174 // sense because the NodeSet is seldom necessary, and it's somewhat expensive to allocate and initialize. This method does
175 // the same thing as mutableRectBasedTestResult(), but here the return value is const.
176 const NodeSet& rectBasedTestResult() const;
178 #if ENABLE(TIZEN_DRAG_SUPPORT)
179 bool isDragSupport() const;
182 Vector<String> dictationAlternatives() const;
185 NodeSet& mutableRectBasedTestResult(); // See above.
188 HTMLMediaElement* mediaElement() const;
191 RefPtr<Node> m_innerNode;
192 RefPtr<Node> m_innerNonSharedNode;
193 LayoutPoint m_localPoint; // A point in the local coordinate space of m_innerNonSharedNode's renderer. Allows us to efficiently
194 // determine where inside the renderer we hit on subsequent operations.
195 RefPtr<Element> m_innerURLElement;
196 RefPtr<Scrollbar> m_scrollbar;
197 bool m_isOverWidget; // Returns true if we are over a widget (and not in the border/padding area of a RenderWidget for example).
199 ShadowContentFilterPolicy m_shadowContentFilterPolicy;
201 mutable OwnPtr<NodeSet> m_rectBasedTestResult;
204 String displayString(const String&, const Node*);
206 } // namespace WebCore
208 #endif // HitTestResult_h