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 "HitTestLocation.h"
28 #include "HitTestRequest.h"
29 #include "LayoutRect.h"
30 #include "TextDirection.h"
31 #include <wtf/Forward.h>
32 #include <wtf/ListHashSet.h>
33 #include <wtf/OwnPtr.h>
34 #include <wtf/RefPtr.h>
41 class HTMLMediaElement;
51 typedef ListHashSet<RefPtr<Node> > NodeSet;
54 HitTestResult(const LayoutPoint&);
55 // Pass non-negative padding values to perform a rect-based hit test.
56 HitTestResult(const LayoutPoint& centerPoint, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding);
57 HitTestResult(const HitTestLocation&);
58 HitTestResult(const HitTestResult&);
60 HitTestResult& operator=(const HitTestResult&);
62 Node* innerNode() const { return m_innerNode.get(); }
63 Element* innerElement() const;
64 Node* innerNonSharedNode() const { return m_innerNonSharedNode.get(); }
65 Element* URLElement() const { return m_innerURLElement.get(); }
66 Scrollbar* scrollbar() const { return m_scrollbar.get(); }
67 bool isOverWidget() const { return m_isOverWidget; }
69 // Forwarded from HitTestLocation
70 bool isRectBasedTest() const { return m_hitTestLocation.isRectBasedTest(); }
72 // The hit-tested point in the coordinates of the main frame.
73 const LayoutPoint& pointInMainFrame() const { return m_hitTestLocation.point(); }
74 IntPoint roundedPointInMainFrame() const { return roundedIntPoint(pointInMainFrame()); }
76 // The hit-tested point in the coordinates of the innerNode frame, the frame containing innerNode.
77 const LayoutPoint& pointInInnerNodeFrame() const { return m_pointInInnerNodeFrame; }
78 IntPoint roundedPointInInnerNodeFrame() const { return roundedIntPoint(pointInInnerNodeFrame()); }
79 Frame* innerNodeFrame() const;
81 // The hit-tested point in the coordinates of the inner node.
82 const LayoutPoint& localPoint() const { return m_localPoint; }
83 void setLocalPoint(const LayoutPoint& p) { m_localPoint = p; }
85 void setToNonShadowAncestor();
87 const HitTestLocation& hitTestLocation() const { return m_hitTestLocation; }
89 void setInnerNode(Node*);
90 void setInnerNonSharedNode(Node*);
91 void setURLElement(Element*);
92 void setScrollbar(Scrollbar*);
93 void setIsOverWidget(bool b) { m_isOverWidget = b; }
95 Frame* targetFrame() const;
96 bool isSelected() const;
97 String spellingToolTip(TextDirection&) const;
98 String replacedString() const;
99 String title(TextDirection&) const;
100 String innerTextIfTruncated(TextDirection&) const;
101 String altDisplayString() const;
102 String titleDisplayString() const;
103 Image* image() const;
104 IntRect imageRect() const;
105 KURL absoluteImageURL() const;
106 KURL absolutePDFURL() const;
107 KURL absoluteMediaURL() const;
108 KURL absoluteLinkURL() const;
109 String textContent() const;
110 bool isLiveLink() const;
111 bool isContentEditable() const;
112 void toggleMediaControlsDisplay() const;
113 void toggleMediaLoopPlayback() 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 bool mediaHasAudio() const;
121 bool mediaIsVideo() const;
122 bool mediaMuted() const;
123 void toggleMediaMuteState() const;
125 // Returns true if it is rect-based hit test and needs to continue until the rect is fully
126 // enclosed by the boundaries of a node.
127 bool addNodeToRectBasedTestResult(Node*, const HitTestRequest&, const HitTestLocation& pointInContainer, const LayoutRect& = LayoutRect());
128 bool addNodeToRectBasedTestResult(Node*, const HitTestRequest&, const HitTestLocation& pointInContainer, const FloatRect&);
129 void append(const HitTestResult&);
131 // If m_rectBasedTestResult is 0 then set it to a new NodeSet. Return *m_rectBasedTestResult. Lazy allocation makes
132 // sense because the NodeSet is seldom necessary, and it's somewhat expensive to allocate and initialize. This method does
133 // the same thing as mutableRectBasedTestResult(), but here the return value is const.
134 const NodeSet& rectBasedTestResult() const;
136 Vector<String> dictationAlternatives() const;
138 Node* targetNode() const;
141 NodeSet& mutableRectBasedTestResult(); // See above.
144 HTMLMediaElement* mediaElement() const;
146 HitTestLocation m_hitTestLocation;
148 RefPtr<Node> m_innerNode;
149 RefPtr<Node> m_innerNonSharedNode;
150 LayoutPoint m_pointInInnerNodeFrame; // The hit-tested point in innerNode frame coordinates.
151 LayoutPoint m_localPoint; // A point in the local coordinate space of m_innerNonSharedNode's renderer. Allows us to efficiently
152 // determine where inside the renderer we hit on subsequent operations.
153 RefPtr<Element> m_innerURLElement;
154 RefPtr<Scrollbar> m_scrollbar;
155 bool m_isOverWidget; // Returns true if we are over a widget (and not in the border/padding area of a RenderWidget for example).
157 mutable OwnPtr<NodeSet> m_rectBasedTestResult;
160 String displayString(const String&, const Node*);
162 } // namespace WebCore
164 #endif // HitTestResult_h