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 static bool pointWithScrollAndZoomIfPossible(const Document& document, IntPoint&
point) |
| 245 { |
| 246 LocalFrame* frame = document.frame(); |
| 247 if (!frame) |
| 248 return false; |
| 249 FrameView* frameView = frame->view(); |
| 250 if (!frameView) |
| 251 return false; |
| 252 |
| 253 FloatPoint pointInDocument(point); |
| 254 pointInDocument.scale(frame->pageZoomFactor(), frame->pageZoomFactor()); |
| 255 pointInDocument.moveBy(frameView->scrollPosition()); |
| 256 IntPoint roundedPointInDocument = roundedIntPoint(pointInDocument); |
| 257 |
| 258 if (!frameView->visibleContentRect().contains(roundedPointInDocument)) |
| 259 return false; |
| 260 |
| 261 point = roundedPointInDocument; |
| 262 return true; |
| 263 } |
| 264 |
244 HitTestResult hitTestInDocument(const Document* document, int x, int y) | 265 HitTestResult hitTestInDocument(const Document* document, int x, int y) |
245 { | 266 { |
246 LocalFrame* frame = document->frame(); | 267 IntPoint hitPoint(x, y); |
247 | 268 if (!pointWithScrollAndZoomIfPossible(*document, hitPoint)) |
248 if (!frame) | |
249 return HitTestResult(); | |
250 FrameView* frameView = frame->view(); | |
251 if (!frameView) | |
252 return HitTestResult(); | |
253 | |
254 float scaleFactor = frame->pageZoomFactor(); | |
255 IntPoint point = roundedIntPoint(FloatPoint(x * scaleFactor + frameView->sc
rollX(), y * scaleFactor + frameView->scrollY())); | |
256 | |
257 if (!frameView->visibleContentRect().contains(point)) | |
258 return HitTestResult(); | 269 return HitTestResult(); |
259 | 270 |
260 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active); | 271 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active); |
261 HitTestResult result(point); | 272 HitTestResult result(hitPoint); |
262 document->renderView()->hitTest(request, result); | 273 document->renderView()->hitTest(request, result); |
263 return result; | 274 return result; |
264 } | 275 } |
265 | 276 |
266 Element* TreeScope::elementFromPoint(int x, int y) const | 277 Element* TreeScope::elementFromPoint(int x, int y) const |
267 { | 278 { |
268 HitTestResult result = hitTestInDocument(&rootNode().document(), x, y); | 279 HitTestResult result = hitTestInDocument(&rootNode().document(), x, y); |
269 Node* node = result.innerNode(); | 280 Node* node = result.innerNode(); |
270 if (!node || node->isDocumentNode()) | 281 if (!node || node->isDocumentNode()) |
271 return 0; | 282 return 0; |
272 if (node->isPseudoElement() || node->isTextNode()) | 283 if (node->isPseudoElement() || node->isTextNode()) |
273 node = node->parentOrShadowHostNode(); | 284 node = node->parentOrShadowHostNode(); |
274 ASSERT(!node || node->isElementNode() || node->isShadowRoot()); | 285 ASSERT(!node || node->isElementNode() || node->isShadowRoot()); |
275 node = ancestorInThisScope(node); | 286 node = ancestorInThisScope(node); |
276 if (!node || !node->isElementNode()) | 287 if (!node || !node->isElementNode()) |
277 return 0; | 288 return 0; |
278 return toElement(node); | 289 return toElement(node); |
279 } | 290 } |
280 | 291 |
| 292 Vector<Element*> TreeScope::elementsFromPoint(int x, int y) const |
| 293 { |
| 294 Vector<Element*> elements; |
| 295 |
| 296 Document& document = rootNode().document(); |
| 297 IntPoint hitPoint(x, y); |
| 298 if (!pointWithScrollAndZoomIfPossible(document, hitPoint)) |
| 299 return elements; |
| 300 |
| 301 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | H
itTestRequest::ListBased | HitTestRequest::PenetratingList); |
| 302 HitTestResult result(hitPoint); |
| 303 document.renderView()->hitTest(request, result); |
| 304 |
| 305 Node* lastNode = nullptr; |
| 306 for (const auto rectBasedNode : result.listBasedTestResult()) { |
| 307 Node* node = rectBasedNode.get(); |
| 308 if (!node || !node->isElementNode() || node->isDocumentNode()) |
| 309 continue; |
| 310 |
| 311 if (node->isPseudoElement() || node->isTextNode()) |
| 312 node = node->parentOrShadowHostNode(); |
| 313 node = ancestorInThisScope(node); |
| 314 |
| 315 // Prune duplicate entries. A pseduo ::before content above its parent |
| 316 // node should only result in a single entry. |
| 317 if (node == lastNode) |
| 318 continue; |
| 319 |
| 320 if (node && node->isElementNode()) { |
| 321 elements.append(toElement(node)); |
| 322 lastNode = node; |
| 323 } |
| 324 } |
| 325 |
| 326 if (m_document) { |
| 327 if (elements.isEmpty() || elements.last() != m_document->documentElement
()) |
| 328 elements.append(m_document->documentElement()); |
| 329 } |
| 330 |
| 331 return elements; |
| 332 } |
| 333 |
281 void TreeScope::addLabel(const AtomicString& forAttributeValue, HTMLLabelElement
* element) | 334 void TreeScope::addLabel(const AtomicString& forAttributeValue, HTMLLabelElement
* element) |
282 { | 335 { |
283 ASSERT(m_labelsByForAttribute); | 336 ASSERT(m_labelsByForAttribute); |
284 m_labelsByForAttribute->add(forAttributeValue, element); | 337 m_labelsByForAttribute->add(forAttributeValue, element); |
285 } | 338 } |
286 | 339 |
287 void TreeScope::removeLabel(const AtomicString& forAttributeValue, HTMLLabelElem
ent* element) | 340 void TreeScope::removeLabel(const AtomicString& forAttributeValue, HTMLLabelElem
ent* element) |
288 { | 341 { |
289 ASSERT(m_labelsByForAttribute); | 342 ASSERT(m_labelsByForAttribute); |
290 m_labelsByForAttribute->remove(forAttributeValue, element); | 343 m_labelsByForAttribute->remove(forAttributeValue, element); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 visitor->trace(m_parentTreeScope); | 573 visitor->trace(m_parentTreeScope); |
521 visitor->trace(m_idTargetObserverRegistry); | 574 visitor->trace(m_idTargetObserverRegistry); |
522 visitor->trace(m_selection); | 575 visitor->trace(m_selection); |
523 visitor->trace(m_elementsById); | 576 visitor->trace(m_elementsById); |
524 visitor->trace(m_imageMapsByName); | 577 visitor->trace(m_imageMapsByName); |
525 visitor->trace(m_labelsByForAttribute); | 578 visitor->trace(m_labelsByForAttribute); |
526 visitor->trace(m_scopedStyleResolver); | 579 visitor->trace(m_scopedStyleResolver); |
527 } | 580 } |
528 | 581 |
529 } // namespace blink | 582 } // namespace blink |
OLD | NEW |