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

Side by Side Diff: Source/core/dom/TreeScope.cpp

Issue 1032823003: Refactor HitTestResult to store the HitTestRequest (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Updated as per review comments Created 5 years, 8 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 | « Source/core/dom/Document.cpp ('k') | Source/core/editing/FrameSelection.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) 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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 return true; 262 return true;
263 } 263 }
264 264
265 HitTestResult hitTestInDocument(const Document* document, int x, int y) 265 HitTestResult hitTestInDocument(const Document* document, int x, int y)
266 { 266 {
267 IntPoint hitPoint(x, y); 267 IntPoint hitPoint(x, y);
268 if (!pointWithScrollAndZoomIfPossible(*document, hitPoint)) 268 if (!pointWithScrollAndZoomIfPossible(*document, hitPoint))
269 return HitTestResult(); 269 return HitTestResult();
270 270
271 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active); 271 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active);
272 HitTestResult result(hitPoint); 272 HitTestResult result(request, hitPoint);
273 document->layoutView()->hitTest(request, result); 273 document->layoutView()->hitTest(result);
274 return result; 274 return result;
275 } 275 }
276 276
277 Element* TreeScope::elementFromPoint(int x, int y) const 277 Element* TreeScope::elementFromPoint(int x, int y) const
278 { 278 {
279 HitTestResult result = hitTestInDocument(&rootNode().document(), x, y); 279 HitTestResult result = hitTestInDocument(&rootNode().document(), x, y);
280 Node* node = result.innerNode(); 280 Node* node = result.innerNode();
281 if (!node || node->isDocumentNode()) 281 if (!node || node->isDocumentNode())
282 return 0; 282 return 0;
283 if (node->isPseudoElement() || node->isTextNode()) 283 if (node->isPseudoElement() || node->isTextNode())
284 node = node->parentOrShadowHostNode(); 284 node = node->parentOrShadowHostNode();
285 ASSERT(!node || node->isElementNode() || node->isShadowRoot()); 285 ASSERT(!node || node->isElementNode() || node->isShadowRoot());
286 node = ancestorInThisScope(node); 286 node = ancestorInThisScope(node);
287 if (!node || !node->isElementNode()) 287 if (!node || !node->isElementNode())
288 return 0; 288 return 0;
289 return toElement(node); 289 return toElement(node);
290 } 290 }
291 291
292 Vector<Element*> TreeScope::elementsFromPoint(int x, int y) const 292 Vector<Element*> TreeScope::elementsFromPoint(int x, int y) const
293 { 293 {
294 Vector<Element*> elements; 294 Vector<Element*> elements;
295 295
296 Document& document = rootNode().document(); 296 Document& document = rootNode().document();
297 IntPoint hitPoint(x, y); 297 IntPoint hitPoint(x, y);
298 if (!pointWithScrollAndZoomIfPossible(document, hitPoint)) 298 if (!pointWithScrollAndZoomIfPossible(document, hitPoint))
299 return elements; 299 return elements;
300 300
301 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | H itTestRequest::ListBased | HitTestRequest::PenetratingList); 301 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | H itTestRequest::ListBased | HitTestRequest::PenetratingList);
302 HitTestResult result(hitPoint); 302 HitTestResult result(request, hitPoint);
303 document.layoutView()->hitTest(request, result); 303 document.layoutView()->hitTest(result);
304 304
305 Node* lastNode = nullptr; 305 Node* lastNode = nullptr;
306 for (const auto rectBasedNode : result.listBasedTestResult()) { 306 for (const auto rectBasedNode : result.listBasedTestResult()) {
307 Node* node = rectBasedNode.get(); 307 Node* node = rectBasedNode.get();
308 if (!node || !node->isElementNode() || node->isDocumentNode()) 308 if (!node || !node->isElementNode() || node->isDocumentNode())
309 continue; 309 continue;
310 310
311 if (node->isPseudoElement() || node->isTextNode()) 311 if (node->isPseudoElement() || node->isTextNode())
312 node = node->parentOrShadowHostNode(); 312 node = node->parentOrShadowHostNode();
313 node = ancestorInThisScope(node); 313 node = ancestorInThisScope(node);
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 visitor->trace(m_parentTreeScope); 575 visitor->trace(m_parentTreeScope);
576 visitor->trace(m_idTargetObserverRegistry); 576 visitor->trace(m_idTargetObserverRegistry);
577 visitor->trace(m_selection); 577 visitor->trace(m_selection);
578 visitor->trace(m_elementsById); 578 visitor->trace(m_elementsById);
579 visitor->trace(m_imageMapsByName); 579 visitor->trace(m_imageMapsByName);
580 visitor->trace(m_labelsByForAttribute); 580 visitor->trace(m_labelsByForAttribute);
581 visitor->trace(m_scopedStyleResolver); 581 visitor->trace(m_scopedStyleResolver);
582 } 582 }
583 583
584 } // namespace blink 584 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/dom/Document.cpp ('k') | Source/core/editing/FrameSelection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698