2 * Copyright (C) 2006 Apple 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 "HitTestLocation.h"
28 #include "HitTestRequest.h"
29 #include "LayoutRect.h"
30 #include "TextFlags.h"
32 #include <wtf/Forward.h>
33 #include <wtf/ListHashSet.h>
34 #include <wtf/RefPtr.h>
41 class HTMLMediaElement;
50 typedef ListHashSet<RefPtr<Node>> NodeSet;
52 WEBCORE_EXPORT HitTestResult();
53 WEBCORE_EXPORT explicit HitTestResult(const LayoutPoint&);
54 // Pass non-negative padding values to perform a rect-based hit test.
55 WEBCORE_EXPORT HitTestResult(const LayoutPoint& centerPoint, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding);
56 WEBCORE_EXPORT explicit HitTestResult(const HitTestLocation&);
57 WEBCORE_EXPORT HitTestResult(const HitTestResult&);
58 WEBCORE_EXPORT ~HitTestResult();
59 WEBCORE_EXPORT HitTestResult& operator=(const HitTestResult&);
61 Node* innerNode() const { return m_innerNode.get(); }
62 Node* innerNonSharedNode() const { return m_innerNonSharedNode.get(); }
63 WEBCORE_EXPORT Element* innerNonSharedElement() const;
64 Element* URLElement() const { return m_innerURLElement.get(); }
65 Scrollbar* scrollbar() const { return m_scrollbar.get(); }
66 bool isOverWidget() const { return m_isOverWidget; }
68 WEBCORE_EXPORT const AtomicString& URLElementDownloadAttribute() const;
70 // Forwarded from HitTestLocation
71 bool isRectBasedTest() const { return m_hitTestLocation.isRectBasedTest(); }
73 // The hit-tested point in the coordinates of the main frame.
74 const LayoutPoint& pointInMainFrame() const { return m_hitTestLocation.point(); }
75 IntPoint roundedPointInMainFrame() const { return roundedIntPoint(pointInMainFrame()); }
77 // The hit-tested point in the coordinates of the innerNode frame, the frame containing innerNode.
78 const LayoutPoint& pointInInnerNodeFrame() const { return m_pointInInnerNodeFrame; }
79 IntPoint roundedPointInInnerNodeFrame() const { return roundedIntPoint(pointInInnerNodeFrame()); }
80 WEBCORE_EXPORT Frame* innerNodeFrame() const;
82 // The hit-tested point in the coordinates of the inner node.
83 const LayoutPoint& localPoint() const { return m_localPoint; }
84 void setLocalPoint(const LayoutPoint& p) { m_localPoint = p; }
86 void setToNonUserAgentShadowAncestor();
88 const HitTestLocation& hitTestLocation() const { return m_hitTestLocation; }
90 WEBCORE_EXPORT void setInnerNode(Node*);
91 void setInnerNonSharedNode(Node*);
92 void setURLElement(Element*);
93 void setScrollbar(Scrollbar*);
94 void setIsOverWidget(bool b) { m_isOverWidget = b; }
96 WEBCORE_EXPORT Frame* targetFrame() const;
97 WEBCORE_EXPORT bool isSelected() const;
98 WEBCORE_EXPORT String selectedText() const;
99 WEBCORE_EXPORT String spellingToolTip(TextDirection&) const;
100 String replacedString() const;
101 WEBCORE_EXPORT String title(TextDirection&) const;
102 String innerTextIfTruncated(TextDirection&) const;
103 WEBCORE_EXPORT String altDisplayString() const;
104 WEBCORE_EXPORT String titleDisplayString() const;
105 WEBCORE_EXPORT Image* image() const;
106 WEBCORE_EXPORT IntRect imageRect() const;
107 WEBCORE_EXPORT URL absoluteImageURL() const;
108 WEBCORE_EXPORT URL absolutePDFURL() const;
109 WEBCORE_EXPORT URL absoluteMediaURL() const;
110 WEBCORE_EXPORT URL absoluteLinkURL() const;
111 #if ENABLE(ATTACHMENT_ELEMENT)
112 WEBCORE_EXPORT URL absoluteAttachmentURL() const;
114 WEBCORE_EXPORT String textContent() const;
115 bool isOverLink() const;
116 WEBCORE_EXPORT bool isContentEditable() const;
117 void toggleMediaControlsDisplay() const;
118 void toggleMediaLoopPlayback() const;
119 WEBCORE_EXPORT bool mediaIsInFullscreen() const;
120 void toggleMediaFullscreenState() const;
121 void enterFullscreenForVideo() const;
122 bool mediaControlsEnabled() const;
123 bool mediaLoopEnabled() const;
124 bool mediaPlaying() const;
125 bool mediaSupportsFullscreen() const;
126 void toggleMediaPlayState() const;
127 WEBCORE_EXPORT bool mediaHasAudio() const;
128 WEBCORE_EXPORT bool mediaIsVideo() const;
129 bool mediaMuted() const;
130 void toggleMediaMuteState() const;
131 bool mediaSupportsEnhancedFullscreen() const;
132 bool mediaIsInEnhancedFullscreen() const;
133 void toggleEnhancedFullscreenForVideo() const;
135 WEBCORE_EXPORT bool isDownloadableMedia() const;
136 WEBCORE_EXPORT bool isOverTextInsideFormControlElement() const;
137 WEBCORE_EXPORT bool allowsCopy() const;
139 // Returns true if it is rect-based hit test and needs to continue until the rect is fully
140 // enclosed by the boundaries of a node.
141 bool addNodeToRectBasedTestResult(Node*, const HitTestRequest&, const HitTestLocation& pointInContainer, const LayoutRect& = LayoutRect());
142 bool addNodeToRectBasedTestResult(Node*, const HitTestRequest&, const HitTestLocation& pointInContainer, const FloatRect&);
143 void append(const HitTestResult&);
145 // If m_rectBasedTestResult is 0 then set it to a new NodeSet. Return *m_rectBasedTestResult. Lazy allocation makes
146 // sense because the NodeSet is seldom necessary, and it's somewhat expensive to allocate and initialize. This method does
147 // the same thing as mutableRectBasedTestResult(), but here the return value is const.
148 WEBCORE_EXPORT const NodeSet& rectBasedTestResult() const;
150 Vector<String> dictationAlternatives() const;
152 Node* targetNode() const;
153 WEBCORE_EXPORT Element* targetElement() const;
156 NodeSet& mutableRectBasedTestResult(); // See above.
159 HTMLMediaElement* mediaElement() const;
161 HitTestLocation m_hitTestLocation;
163 RefPtr<Node> m_innerNode;
164 RefPtr<Node> m_innerNonSharedNode;
165 LayoutPoint m_pointInInnerNodeFrame; // The hit-tested point in innerNode frame coordinates.
166 LayoutPoint m_localPoint; // A point in the local coordinate space of m_innerNonSharedNode's renderer. Allows us to efficiently
167 // determine where inside the renderer we hit on subsequent operations.
168 RefPtr<Element> m_innerURLElement;
169 RefPtr<Scrollbar> m_scrollbar;
170 bool m_isOverWidget; // Returns true if we are over a widget (and not in the border/padding area of a RenderWidget for example).
172 mutable std::unique_ptr<NodeSet> m_rectBasedTestResult;
175 WEBCORE_EXPORT String displayString(const String&, const Node*);
177 } // namespace WebCore
179 #endif // HitTestResult_h