Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / HitTestResult.h
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 HitTestResult_h
23 #define HitTestResult_h
24
25 #include "core/rendering/HitTestLocation.h"
26 #include "core/rendering/HitTestRequest.h"
27 #include "platform/geometry/FloatQuad.h"
28 #include "platform/geometry/FloatRect.h"
29 #include "platform/geometry/LayoutRect.h"
30 #include "platform/heap/Handle.h"
31 #include "platform/text/TextDirection.h"
32 #include "wtf/Forward.h"
33 #include "wtf/ListHashSet.h"
34 #include "wtf/OwnPtr.h"
35 #include "wtf/RefPtr.h"
36
37 namespace blink {
38
39 class Element;
40 class LocalFrame;
41 class HTMLMediaElement;
42 class Image;
43 class KURL;
44 class Node;
45 class RenderObject;
46 class PositionWithAffinity;
47 class Scrollbar;
48
49 class HitTestResult {
50     DISALLOW_ALLOCATION();
51 public:
52     typedef WillBeHeapListHashSet<RefPtrWillBeMember<Node> > NodeSet;
53
54     HitTestResult();
55     HitTestResult(const LayoutPoint&);
56     // Pass non-negative padding values to perform a rect-based hit test.
57     HitTestResult(const LayoutPoint& centerPoint, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding);
58     HitTestResult(const HitTestLocation&);
59     HitTestResult(const HitTestResult&);
60     ~HitTestResult();
61     HitTestResult& operator=(const HitTestResult&);
62     void trace(Visitor*);
63
64     // For point-based hit tests, these accessors provide information about the node
65     // under the point. For rect-based hit tests they are meaningless (reflect the
66     // last candidate node observed in the rect).
67     // FIXME: Make these less error-prone for rect-based hit tests (center point or fail).
68     Node* innerNode() const { return m_innerNode.get(); }
69     Node* innerPossiblyPseudoNode() const { return m_innerPossiblyPseudoNode.get(); }
70     Element* innerElement() const;
71     Node* innerNonSharedNode() const { return m_innerNonSharedNode.get(); }
72     Element* URLElement() const { return m_innerURLElement.get(); }
73     Scrollbar* scrollbar() const { return m_scrollbar.get(); }
74     bool isOverWidget() const { return m_isOverWidget; }
75
76     // Forwarded from HitTestLocation
77     bool isRectBasedTest() const { return m_hitTestLocation.isRectBasedTest(); }
78
79     // The hit-tested point in the coordinates of the main frame.
80     const LayoutPoint& pointInMainFrame() const { return m_hitTestLocation.point(); }
81     IntPoint roundedPointInMainFrame() const { return roundedIntPoint(pointInMainFrame()); }
82
83     // The hit-tested point in the coordinates of the innerNode frame, the frame containing innerNode.
84     const LayoutPoint& pointInInnerNodeFrame() const { return m_pointInInnerNodeFrame; }
85     IntPoint roundedPointInInnerNodeFrame() const { return roundedIntPoint(pointInInnerNodeFrame()); }
86     LocalFrame* innerNodeFrame() const;
87
88     // The hit-tested point in the coordinates of the inner node.
89     const LayoutPoint& localPoint() const { return m_localPoint; }
90     void setLocalPoint(const LayoutPoint& p) { m_localPoint = p; }
91
92     PositionWithAffinity position() const;
93     RenderObject* renderer() const;
94
95     void setToShadowHostIfInUserAgentShadowRoot();
96
97     const HitTestLocation& hitTestLocation() const { return m_hitTestLocation; }
98
99     void setInnerNode(Node*);
100     void setInnerNonSharedNode(Node*);
101     void setURLElement(Element*);
102     void setScrollbar(Scrollbar*);
103     void setIsFirstLetter(bool b) { m_isFirstLetter = b; }
104     void setIsOverWidget(bool b) { m_isOverWidget = b; }
105
106     bool isSelected() const;
107     String spellingToolTip(TextDirection&) const;
108     String title(TextDirection&) const;
109     const AtomicString& altDisplayString() const;
110     Image* image() const;
111     IntRect imageRect() const;
112     KURL absoluteImageURL() const;
113     // This variant of absoluteImageURL will also convert <canvas> elements
114     // to huge image data URLs (very expensive).
115     KURL absoluteImageURLIncludingCanvasDataURL() const;
116     KURL absoluteMediaURL() const;
117     KURL absoluteLinkURL() const;
118     String textContent() const;
119     bool isLiveLink() const;
120     bool isMisspelled() const;
121     bool isContentEditable() const;
122
123     bool isOverLink() const;
124     // Returns true if it is rect-based hit test and needs to continue until the rect is fully
125     // enclosed by the boundaries of a node.
126     bool addNodeToRectBasedTestResult(Node*, const HitTestRequest&, const HitTestLocation& pointInContainer, const LayoutRect& = LayoutRect());
127     bool addNodeToRectBasedTestResult(Node*, const HitTestRequest&, const HitTestLocation& pointInContainer, const FloatRect&);
128     void append(const HitTestResult&);
129
130     // If m_rectBasedTestResult is 0 then set it to a new NodeSet. Return *m_rectBasedTestResult. Lazy allocation makes
131     // sense because the NodeSet is seldom necessary, and it's somewhat expensive to allocate and initialize. This method does
132     // the same thing as mutableRectBasedTestResult(), but here the return value is const.
133     const NodeSet& rectBasedTestResult() const;
134
135     // Collapse the rect-based test result into a single target at the specified location.
136     void resolveRectBasedTest(Node* resolvedInnerNode, const LayoutPoint& resolvedPointInMainFrame);
137
138     // FIXME: Remove this.
139     Node* targetNode() const { return innerNode(); }
140
141 private:
142     KURL absoluteImageURLInternal(bool allowCanvas) const;
143     NodeSet& mutableRectBasedTestResult(); // See above.
144     HTMLMediaElement* mediaElement() const;
145
146     HitTestLocation m_hitTestLocation;
147
148     RefPtrWillBeMember<Node> m_innerNode;
149     RefPtrWillBeMember<Node> m_innerPossiblyPseudoNode;
150     RefPtrWillBeMember<Node> m_innerNonSharedNode;
151     // FIXME: Nothing changes this to a value different from m_hitTestLocation!
152     LayoutPoint m_pointInInnerNodeFrame; // The hit-tested point in innerNode frame coordinates.
153     LayoutPoint m_localPoint; // A point in the local coordinate space of m_innerNonSharedNode's renderer. Allows us to efficiently
154                               // determine where inside the renderer we hit on subsequent operations.
155     RefPtrWillBeMember<Element> m_innerURLElement;
156     RefPtr<Scrollbar> m_scrollbar;
157     bool m_isOverWidget; // Returns true if we are over a widget (and not in the border/padding area of a RenderWidget for example).
158     bool m_isFirstLetter;
159
160     mutable OwnPtrWillBeMember<NodeSet> m_rectBasedTestResult;
161 };
162
163 } // namespace blink
164
165 #endif // HitTestResult_h