OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All Rights Reserved. | 2 * Copyright (C) 2011 Google Inc. All Rights Reserved. |
3 * Copyright (C) 2012 Apple Inc. All rights reserved. | 3 * Copyright (C) 2012 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 return 0; | 234 return 0; |
235 if (!m_imageMapsByName) | 235 if (!m_imageMapsByName) |
236 return 0; | 236 return 0; |
237 size_t hashPos = url.find('#'); | 237 size_t hashPos = url.find('#'); |
238 String name = hashPos == kNotFound ? url : url.substring(hashPos + 1); | 238 String name = hashPos == kNotFound ? url : url.substring(hashPos + 1); |
239 if (rootNode().document().isHTMLDocument()) | 239 if (rootNode().document().isHTMLDocument()) |
240 return toHTMLMapElement(m_imageMapsByName->getElementByLowercasedMapName (AtomicString(name.lower()), this)); | 240 return toHTMLMapElement(m_imageMapsByName->getElementByLowercasedMapName (AtomicString(name.lower()), this)); |
241 return toHTMLMapElement(m_imageMapsByName->getElementByMapName(AtomicString( name), this)); | 241 return toHTMLMapElement(m_imageMapsByName->getElementByMapName(AtomicString( name), this)); |
242 } | 242 } |
243 | 243 |
244 HitTestResult hitTestInDocument(const Document* document, int x, int y) | 244 HitTestResult hitTestInDocument(const Document* document, int x, int y, HitTestR equest request) |
245 { | 245 { |
246 LocalFrame* frame = document->frame(); | 246 LocalFrame* frame = document->frame(); |
247 | 247 |
248 if (!frame) | 248 if (!frame) |
249 return HitTestResult(); | 249 return HitTestResult(); |
250 FrameView* frameView = frame->view(); | 250 FrameView* frameView = frame->view(); |
251 if (!frameView) | 251 if (!frameView) |
252 return HitTestResult(); | 252 return HitTestResult(); |
253 | 253 |
254 float scaleFactor = frame->pageZoomFactor(); | 254 float scaleFactor = frame->pageZoomFactor(); |
255 IntPoint point = roundedIntPoint(FloatPoint(x * scaleFactor + frameView->sc rollX(), y * scaleFactor + frameView->scrollY())); | 255 IntPoint point = roundedIntPoint(FloatPoint(x * scaleFactor + frameView->sc rollX(), y * scaleFactor + frameView->scrollY())); |
256 | 256 |
257 if (!frameView->visibleContentRect().contains(point)) | 257 if (!frameView->visibleContentRect().contains(point)) |
258 return HitTestResult(); | 258 return HitTestResult(); |
259 | 259 |
260 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active); | |
261 HitTestResult result(point); | 260 HitTestResult result(point); |
262 document->renderView()->hitTest(request, result); | 261 document->renderView()->hitTest(request, result); |
263 return result; | 262 return result; |
264 } | 263 } |
265 | 264 |
266 Element* TreeScope::elementFromPoint(int x, int y) const | 265 Element* TreeScope::elementFromPoint(int x, int y) const |
267 { | 266 { |
268 HitTestResult result = hitTestInDocument(&rootNode().document(), x, y); | 267 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active); |
268 HitTestResult result = hitTestInDocument(&rootNode().document(), x, y, reque st); | |
269 Node* node = result.innerNode(); | 269 Node* node = result.innerNode(); |
270 if (!node || node->isDocumentNode()) | 270 if (!node || node->isDocumentNode()) |
271 return 0; | 271 return 0; |
272 if (node->isPseudoElement() || node->isTextNode()) | 272 if (node->isPseudoElement() || node->isTextNode()) |
273 node = node->parentOrShadowHostNode(); | 273 node = node->parentOrShadowHostNode(); |
274 ASSERT(!node || node->isElementNode() || node->isShadowRoot()); | 274 ASSERT(!node || node->isElementNode() || node->isShadowRoot()); |
275 node = ancestorInThisScope(node); | 275 node = ancestorInThisScope(node); |
276 if (!node || !node->isElementNode()) | 276 if (!node || !node->isElementNode()) |
277 return 0; | 277 return 0; |
278 return toElement(node); | 278 return toElement(node); |
279 } | 279 } |
280 | 280 |
281 Vector<Element*> TreeScope::elementsFromPoint(int x, int y) const | |
282 { | |
283 Vector<Element*> elements; | |
284 | |
285 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | H itTestRequest::ListBased | HitTestRequest::Penetrating); | |
286 HitTestResult result = hitTestInDocument(&rootNode().document(), x, y, reque st); | |
287 | |
288 Node* lastNode = nullptr; | |
289 for (const auto rectBasedNode : result.listBasedTestResult()) { | |
290 Node* node = rectBasedNode.get(); | |
291 if (!node || !node->isElementNode() || node->isDocumentNode()) | |
292 continue; | |
293 | |
294 if (node->isPseudoElement() || node->isTextNode()) | |
295 node = node->parentOrShadowHostNode(); | |
296 node = ancestorInThisScope(node); | |
297 | |
298 // Prune duplicate entries. A pseduo ::before content above its parent | |
299 // node should only result in a single entry. | |
Rick Byers
2015/02/04 10:34:03
are duplicate notes guaranteed to be adjacent, or
pdr.
2015/02/17 04:10:13
This is a good question. Because result.listBasedT
| |
300 if (node == lastNode) | |
301 continue; | |
302 | |
303 if (node && node->isElementNode()) { | |
304 elements.append(toElement(node)); | |
305 lastNode = node; | |
306 } | |
307 } | |
308 return elements; | |
309 } | |
310 | |
281 void TreeScope::addLabel(const AtomicString& forAttributeValue, HTMLLabelElement * element) | 311 void TreeScope::addLabel(const AtomicString& forAttributeValue, HTMLLabelElement * element) |
282 { | 312 { |
283 ASSERT(m_labelsByForAttribute); | 313 ASSERT(m_labelsByForAttribute); |
284 m_labelsByForAttribute->add(forAttributeValue, element); | 314 m_labelsByForAttribute->add(forAttributeValue, element); |
285 } | 315 } |
286 | 316 |
287 void TreeScope::removeLabel(const AtomicString& forAttributeValue, HTMLLabelElem ent* element) | 317 void TreeScope::removeLabel(const AtomicString& forAttributeValue, HTMLLabelElem ent* element) |
288 { | 318 { |
289 ASSERT(m_labelsByForAttribute); | 319 ASSERT(m_labelsByForAttribute); |
290 m_labelsByForAttribute->remove(forAttributeValue, element); | 320 m_labelsByForAttribute->remove(forAttributeValue, element); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
520 visitor->trace(m_parentTreeScope); | 550 visitor->trace(m_parentTreeScope); |
521 visitor->trace(m_idTargetObserverRegistry); | 551 visitor->trace(m_idTargetObserverRegistry); |
522 visitor->trace(m_selection); | 552 visitor->trace(m_selection); |
523 visitor->trace(m_elementsById); | 553 visitor->trace(m_elementsById); |
524 visitor->trace(m_imageMapsByName); | 554 visitor->trace(m_imageMapsByName); |
525 visitor->trace(m_labelsByForAttribute); | 555 visitor->trace(m_labelsByForAttribute); |
526 visitor->trace(m_scopedStyleResolver); | 556 visitor->trace(m_scopedStyleResolver); |
527 } | 557 } |
528 | 558 |
529 } // namespace blink | 559 } // namespace blink |
OLD | NEW |