Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: sky/engine/core/rendering/HitTestResult.cpp

Issue 925933004: Prune HitTestResult and stop special-casing links. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: address review comments Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/engine/core/rendering/HitTestResult.h ('k') | sky/engine/core/rendering/RenderLayer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2008, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2008, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 19 matching lines...) Expand all
30 #include "sky/engine/core/fetch/ImageResource.h" 30 #include "sky/engine/core/fetch/ImageResource.h"
31 #include "sky/engine/core/frame/LocalFrame.h" 31 #include "sky/engine/core/frame/LocalFrame.h"
32 #include "sky/engine/core/html/HTMLAnchorElement.h" 32 #include "sky/engine/core/html/HTMLAnchorElement.h"
33 #include "sky/engine/core/html/HTMLImageElement.h" 33 #include "sky/engine/core/html/HTMLImageElement.h"
34 #include "sky/engine/core/html/parser/HTMLParserIdioms.h" 34 #include "sky/engine/core/html/parser/HTMLParserIdioms.h"
35 #include "sky/engine/core/rendering/RenderImage.h" 35 #include "sky/engine/core/rendering/RenderImage.h"
36 36
37 namespace blink { 37 namespace blink {
38 38
39 HitTestResult::HitTestResult() 39 HitTestResult::HitTestResult()
40 : m_isOverWidget(false)
41 { 40 {
42 } 41 }
43 42
44 HitTestResult::HitTestResult(const LayoutPoint& point) 43 HitTestResult::HitTestResult(const LayoutPoint& point)
45 : m_hitTestLocation(point) 44 : m_hitTestLocation(point)
46 , m_pointInInnerNodeFrame(point) 45 , m_pointInInnerNodeFrame(point)
47 , m_isOverWidget(false)
48 { 46 {
49 } 47 }
50 48
51 HitTestResult::HitTestResult(const LayoutPoint& centerPoint, unsigned topPadding , unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding) 49 HitTestResult::HitTestResult(const LayoutPoint& centerPoint, unsigned topPadding , unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding)
52 : m_hitTestLocation(centerPoint, topPadding, rightPadding, bottomPadding, le ftPadding) 50 : m_hitTestLocation(centerPoint, topPadding, rightPadding, bottomPadding, le ftPadding)
53 , m_pointInInnerNodeFrame(centerPoint) 51 , m_pointInInnerNodeFrame(centerPoint)
54 , m_isOverWidget(false)
55 { 52 {
56 } 53 }
57 54
58 HitTestResult::HitTestResult(const HitTestLocation& other) 55 HitTestResult::HitTestResult(const HitTestLocation& other)
59 : m_hitTestLocation(other) 56 : m_hitTestLocation(other)
60 , m_pointInInnerNodeFrame(m_hitTestLocation.point()) 57 , m_pointInInnerNodeFrame(m_hitTestLocation.point())
61 , m_isOverWidget(false)
62 { 58 {
63 } 59 }
64 60
65 HitTestResult::HitTestResult(const HitTestResult& other) 61 HitTestResult::HitTestResult(const HitTestResult& other)
66 : m_hitTestLocation(other.m_hitTestLocation) 62 : m_hitTestLocation(other.m_hitTestLocation)
67 , m_innerNode(other.innerNode()) 63 , m_innerNode(other.innerNode())
68 , m_innerPossiblyPseudoNode(other.m_innerPossiblyPseudoNode) 64 , m_innerPossiblyPseudoNode(other.m_innerPossiblyPseudoNode)
69 , m_innerNonSharedNode(other.innerNonSharedNode()) 65 , m_innerNonSharedNode(other.innerNonSharedNode())
70 , m_pointInInnerNodeFrame(other.m_pointInInnerNodeFrame) 66 , m_pointInInnerNodeFrame(other.m_pointInInnerNodeFrame)
71 , m_localPoint(other.localPoint()) 67 , m_localPoint(other.localPoint())
72 , m_innerURLElement(other.URLElement())
73 , m_isOverWidget(other.isOverWidget())
74 { 68 {
75 // Only copy the NodeSet in case of rect hit test. 69 // Only copy the NodeSet in case of rect hit test.
76 m_rectBasedTestResult = adoptPtr(other.m_rectBasedTestResult ? new NodeSet(* other.m_rectBasedTestResult) : 0); 70 m_rectBasedTestResult = adoptPtr(other.m_rectBasedTestResult ? new NodeSet(* other.m_rectBasedTestResult) : 0);
77 } 71 }
78 72
79 HitTestResult::~HitTestResult() 73 HitTestResult::~HitTestResult()
80 { 74 {
81 } 75 }
82 76
83 HitTestResult& HitTestResult::operator=(const HitTestResult& other) 77 HitTestResult& HitTestResult::operator=(const HitTestResult& other)
84 { 78 {
85 m_hitTestLocation = other.m_hitTestLocation; 79 m_hitTestLocation = other.m_hitTestLocation;
86 m_innerNode = other.innerNode(); 80 m_innerNode = other.innerNode();
87 m_innerPossiblyPseudoNode = other.innerPossiblyPseudoNode(); 81 m_innerPossiblyPseudoNode = other.innerPossiblyPseudoNode();
88 m_innerNonSharedNode = other.innerNonSharedNode(); 82 m_innerNonSharedNode = other.innerNonSharedNode();
89 m_pointInInnerNodeFrame = other.m_pointInInnerNodeFrame; 83 m_pointInInnerNodeFrame = other.m_pointInInnerNodeFrame;
90 m_localPoint = other.localPoint(); 84 m_localPoint = other.localPoint();
91 m_innerURLElement = other.URLElement();
92 m_isOverWidget = other.isOverWidget();
93 85
94 // Only copy the NodeSet in case of rect hit test. 86 // Only copy the NodeSet in case of rect hit test.
95 m_rectBasedTestResult = adoptPtr(other.m_rectBasedTestResult ? new NodeSet(* other.m_rectBasedTestResult) : 0); 87 m_rectBasedTestResult = adoptPtr(other.m_rectBasedTestResult ? new NodeSet(* other.m_rectBasedTestResult) : 0);
96 88
97 return *this; 89 return *this;
98 } 90 }
99 91
100 PositionWithAffinity HitTestResult::position() const 92 PositionWithAffinity HitTestResult::position() const
101 { 93 {
102 if (!m_innerPossiblyPseudoNode) 94 if (!m_innerPossiblyPseudoNode)
(...skipping 15 matching lines...) Expand all
118 { 110 {
119 m_innerPossiblyPseudoNode = n; 111 m_innerPossiblyPseudoNode = n;
120 m_innerNode = n; 112 m_innerNode = n;
121 } 113 }
122 114
123 void HitTestResult::setInnerNonSharedNode(Node* n) 115 void HitTestResult::setInnerNonSharedNode(Node* n)
124 { 116 {
125 m_innerNonSharedNode = n; 117 m_innerNonSharedNode = n;
126 } 118 }
127 119
128 void HitTestResult::setURLElement(Element* n)
129 {
130 m_innerURLElement = n;
131 }
132
133 LocalFrame* HitTestResult::innerNodeFrame() const 120 LocalFrame* HitTestResult::innerNodeFrame() const
134 { 121 {
135 if (m_innerNonSharedNode) 122 if (m_innerNonSharedNode)
136 return m_innerNonSharedNode->document().frame(); 123 return m_innerNonSharedNode->document().frame();
137 if (m_innerNode) 124 if (m_innerNode)
138 return m_innerNode->document().frame(); 125 return m_innerNode->document().frame();
139 return 0; 126 return 0;
140 } 127 }
141 128
142 bool HitTestResult::isSelected() const 129 bool HitTestResult::isSelected() const
(...skipping 21 matching lines...) Expand all
164 return 0; 151 return 0;
165 } 152 }
166 153
167 IntRect HitTestResult::imageRect() const 154 IntRect HitTestResult::imageRect() const
168 { 155 {
169 if (!image()) 156 if (!image())
170 return IntRect(); 157 return IntRect();
171 return m_innerNonSharedNode->renderBox()->absoluteContentQuad().enclosingBou ndingBox(); 158 return m_innerNonSharedNode->renderBox()->absoluteContentQuad().enclosingBou ndingBox();
172 } 159 }
173 160
174 KURL HitTestResult::absoluteImageURL() const
175 {
176 return absoluteImageURLInternal(false);
177 }
178
179 KURL HitTestResult::absoluteImageURLIncludingCanvasDataURL() const
180 {
181 return absoluteImageURLInternal(true);
182 }
183
184 KURL HitTestResult::absoluteImageURLInternal(bool allowCanvas) const
185 {
186 if (!m_innerNonSharedNode)
187 return KURL();
188
189 RenderObject* renderer = m_innerNonSharedNode->renderer();
190 if (!(renderer && (renderer->isImage() || renderer->isCanvas())))
191 return KURL();
192
193 AtomicString urlString;
194 if ((allowCanvas && isHTMLCanvasElement(*m_innerNonSharedNode))
195 || isHTMLImageElement(*m_innerNonSharedNode)
196 ) {
197 urlString = toElement(*m_innerNonSharedNode).imageSourceURL();
198 } else
199 return KURL();
200
201 return m_innerNonSharedNode->document().completeURL(stripLeadingAndTrailingH TMLSpaces(urlString));
202 }
203
204 KURL HitTestResult::absoluteLinkURL() const
205 {
206 if (!m_innerURLElement)
207 return KURL();
208 return m_innerURLElement->hrefURL();
209 }
210
211 bool HitTestResult::isLiveLink() const
212 {
213 return m_innerURLElement && m_innerURLElement->isLiveLink();
214 }
215
216 bool HitTestResult::isMisspelled() const 161 bool HitTestResult::isMisspelled() const
217 { 162 {
218 if (!targetNode() || !targetNode()->renderer()) 163 if (!targetNode() || !targetNode()->renderer())
219 return false; 164 return false;
220 VisiblePosition pos(targetNode()->renderer()->positionForPoint(localPoint()) ); 165 VisiblePosition pos(targetNode()->renderer()->positionForPoint(localPoint()) );
221 if (pos.isNull()) 166 if (pos.isNull())
222 return false; 167 return false;
223 return m_innerNonSharedNode->document().markers().markersInRange( 168 return m_innerNonSharedNode->document().markers().markersInRange(
224 makeRange(pos, pos).get(), DocumentMarker::MisspellingMarkers()).size() > 0; 169 makeRange(pos, pos).get(), DocumentMarker::MisspellingMarkers()).size() > 0;
225 } 170 }
226 171
227 bool HitTestResult::isOverLink() const
228 {
229 return m_innerURLElement && m_innerURLElement->isLink();
230 }
231
232 String HitTestResult::textContent() const
233 {
234 if (!m_innerURLElement)
235 return String();
236 return m_innerURLElement->textContent();
237 }
238
239 // FIXME: This function needs a better name and may belong in a different class. It's not 172 // FIXME: This function needs a better name and may belong in a different class. It's not
240 // really isContentEditable(); it's more like needsEditingContextMenu(). In many ways, this 173 // really isContentEditable(); it's more like needsEditingContextMenu(). In many ways, this
241 // function would make more sense in the ContextMenu class, except that WebEleme ntDictionary 174 // function would make more sense in the ContextMenu class, except that WebEleme ntDictionary
242 // hooks into it. Anyway, we should architect this better. 175 // hooks into it. Anyway, we should architect this better.
243 bool HitTestResult::isContentEditable() const 176 bool HitTestResult::isContentEditable() const
244 { 177 {
245 if (!m_innerNonSharedNode) 178 if (!m_innerNonSharedNode)
246 return false; 179 return false;
247 return m_innerNonSharedNode->hasEditableStyle(); 180 return m_innerNonSharedNode->hasEditableStyle();
248 } 181 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 void HitTestResult::append(const HitTestResult& other) 217 void HitTestResult::append(const HitTestResult& other)
285 { 218 {
286 ASSERT(isRectBasedTest() && other.isRectBasedTest()); 219 ASSERT(isRectBasedTest() && other.isRectBasedTest());
287 220
288 if (!m_innerNode && other.innerNode()) { 221 if (!m_innerNode && other.innerNode()) {
289 m_innerNode = other.innerNode(); 222 m_innerNode = other.innerNode();
290 m_innerPossiblyPseudoNode = other.innerPossiblyPseudoNode(); 223 m_innerPossiblyPseudoNode = other.innerPossiblyPseudoNode();
291 m_innerNonSharedNode = other.innerNonSharedNode(); 224 m_innerNonSharedNode = other.innerNonSharedNode();
292 m_localPoint = other.localPoint(); 225 m_localPoint = other.localPoint();
293 m_pointInInnerNodeFrame = other.m_pointInInnerNodeFrame; 226 m_pointInInnerNodeFrame = other.m_pointInInnerNodeFrame;
294 m_innerURLElement = other.URLElement();
295 m_isOverWidget = other.isOverWidget();
296 } 227 }
297 228
298 if (other.m_rectBasedTestResult) { 229 if (other.m_rectBasedTestResult) {
299 NodeSet& set = mutableRectBasedTestResult(); 230 NodeSet& set = mutableRectBasedTestResult();
300 for (NodeSet::const_iterator it = other.m_rectBasedTestResult->begin(), last = other.m_rectBasedTestResult->end(); it != last; ++it) 231 for (NodeSet::const_iterator it = other.m_rectBasedTestResult->begin(), last = other.m_rectBasedTestResult->end(); it != last; ++it)
301 set.add(it->get()); 232 set.add(it->get());
302 } 233 }
303 } 234 }
304 235
305 const HitTestResult::NodeSet& HitTestResult::rectBasedTestResult() const 236 const HitTestResult::NodeSet& HitTestResult::rectBasedTestResult() const
(...skipping 28 matching lines...) Expand all
334 { 265 {
335 for (Node* node = m_innerNode.get(); node; node = NodeRenderingTraversal::pa rent(node)) { 266 for (Node* node = m_innerNode.get(); node; node = NodeRenderingTraversal::pa rent(node)) {
336 if (node->isElementNode()) 267 if (node->isElementNode())
337 return toElement(node); 268 return toElement(node);
338 } 269 }
339 270
340 return 0; 271 return 0;
341 } 272 }
342 273
343 } // namespace blink 274 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/rendering/HitTestResult.h ('k') | sky/engine/core/rendering/RenderLayer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698