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

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

Issue 1142283004: Implement a Hit Test Cache. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix git cl format mangling Created 5 years, 6 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
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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 pointInDocument.moveBy(frameView->scrollPosition()); 255 pointInDocument.moveBy(frameView->scrollPosition());
256 IntPoint roundedPointInDocument = roundedIntPoint(pointInDocument); 256 IntPoint roundedPointInDocument = roundedIntPoint(pointInDocument);
257 257
258 if (!frameView->visibleContentRect().contains(roundedPointInDocument)) 258 if (!frameView->visibleContentRect().contains(roundedPointInDocument))
259 return false; 259 return false;
260 260
261 point = roundedPointInDocument; 261 point = roundedPointInDocument;
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, bool use Cache)
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 | ( useCache ? 0 : HitTestRequest::AvoidCache));
272 HitTestResult result(request, hitPoint); 272 HitTestResult result(request, hitPoint);
273 document->layoutView()->hitTest(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
esprehn 2015/06/06 21:14:29 elementFromPoint(int x, int y, HitTestCacheType =
dtapuska 2015/06/09 18:21:23 I'm just going to allow the HitTestRequest to be p
278 { 278 {
279 HitTestResult result = hitTestInDocument(&rootNode().document(), x, y); 279 return hitTestPoint(x, y, true);
280 }
281
282 Element* TreeScope::elementFromPointNoCache(int x, int y) const
esprehn 2015/06/06 21:14:29 Use default args instead, no need for two methods.
dtapuska 2015/06/09 18:21:23 Done.
283 {
284 return hitTestPoint(x, y, false);
285 }
286
287 Element* TreeScope::hitTestPoint(int x, int y, bool useCache) const
288 {
289 HitTestResult result = hitTestInDocument(&rootNode().document(), x, y, useCa che);
280 Node* node = result.innerNode(); 290 Node* node = result.innerNode();
281 if (!node || node->isDocumentNode()) 291 if (!node || node->isDocumentNode())
282 return 0; 292 return 0;
283 if (node->isPseudoElement() || node->isTextNode()) 293 if (node->isPseudoElement() || node->isTextNode())
284 node = node->parentOrShadowHostNode(); 294 node = node->parentOrShadowHostNode();
285 ASSERT(!node || node->isElementNode() || node->isShadowRoot()); 295 ASSERT(!node || node->isElementNode() || node->isShadowRoot());
286 node = ancestorInThisScope(node); 296 node = ancestorInThisScope(node);
287 if (!node || !node->isElementNode()) 297 if (!node || !node->isElementNode())
288 return 0; 298 return 0;
289 return toElement(node); 299 return toElement(node);
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 visitor->trace(m_parentTreeScope); 585 visitor->trace(m_parentTreeScope);
576 visitor->trace(m_idTargetObserverRegistry); 586 visitor->trace(m_idTargetObserverRegistry);
577 visitor->trace(m_selection); 587 visitor->trace(m_selection);
578 visitor->trace(m_elementsById); 588 visitor->trace(m_elementsById);
579 visitor->trace(m_imageMapsByName); 589 visitor->trace(m_imageMapsByName);
580 visitor->trace(m_labelsByForAttribute); 590 visitor->trace(m_labelsByForAttribute);
581 visitor->trace(m_scopedStyleResolver); 591 visitor->trace(m_scopedStyleResolver);
582 } 592 }
583 593
584 } // namespace blink 594 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698