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