1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "core/layout/HitTestCache.h"
8 #include "public/platform/Platform.h"
12 bool HitTestCache::lookupCachedResult(HitTestResult
& hitResult
, uint64_t domTreeVersion
)
15 HitHistogramMetric metric
= HitHistogramMetric::MISS
;
16 if (hitResult
.hitTestRequest().avoidCache()) {
17 metric
= HitHistogramMetric::MISS_EXPLICIT_AVOID
;
18 // For now we don't support rect based hit results.
19 } else if (domTreeVersion
== m_domTreeVersion
&& !hitResult
.hitTestLocation().isRectBasedTest()) {
20 for (const auto& cachedItem
: m_items
) {
21 if (cachedItem
.hitTestLocation().point() == hitResult
.hitTestLocation().point()) {
22 if (hitResult
.hitTestRequest().equalForCacheability(cachedItem
.hitTestRequest())) {
23 metric
= HitHistogramMetric::HIT_EXACT_MATCH
;
25 hitResult
= cachedItem
;
28 metric
= HitHistogramMetric::MISS_VALIDITY_RECT_MATCHES
;
32 Platform::current()->histogramEnumeration("Event.HitTest", static_cast<int>(metric
), static_cast<int>(HitHistogramMetric::MAX_HIT_METRIC
));
36 void HitTestCache::addCachedResult(const HitTestResult
& result
, uint64_t domTreeVersion
)
38 if (!result
.isCacheable())
41 // If the result was a hit test on an LayoutPart and the request allowed
42 // querying of the layout part; then the part hasn't been loaded yet.
43 if (result
.isOverWidget() && result
.hitTestRequest().allowsChildFrameContent())
46 // For now don't support rect based or list based requests.
47 if (result
.hitTestLocation().isRectBasedTest() || result
.hitTestRequest().listBased())
49 if (domTreeVersion
!= m_domTreeVersion
)
51 if (m_items
.size() < HIT_TEST_CACHE_SIZE
)
52 m_items
.resize(m_updateIndex
+ 1);
54 m_items
.at(m_updateIndex
).cacheValues(result
);
55 m_domTreeVersion
= domTreeVersion
;
58 if (m_updateIndex
>= HIT_TEST_CACHE_SIZE
)
62 void HitTestCache::clear()
68 DEFINE_TRACE(HitTestCache
)
70 visitor
->trace(m_items
);