| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef HitTestCache_h | 5 #ifndef HitTestCache_h |
| 6 #define HitTestCache_h | 6 #define HitTestCache_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "core/layout/HitTestResult.h" | 9 #include "core/layout/HitTestResult.h" |
| 10 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
| 11 #include "wtf/Noncopyable.h" |
| 11 #include "wtf/Vector.h" | 12 #include "wtf/Vector.h" |
| 12 | 13 |
| 13 namespace blink { | 14 namespace blink { |
| 14 | 15 |
| 15 // This object implements a cache for storing successful hit tests to DOM nodes | 16 // This object implements a cache for storing successful hit tests to DOM nodes |
| 16 // in the visible viewport. The cache is cleared on dom modifications, | 17 // in the visible viewport. The cache is cleared on dom modifications, |
| 17 // scrolling, CSS style modifications. | 18 // scrolling, CSS style modifications. |
| 18 // | 19 // |
| 19 // Multiple hit tests can occur when processing events. Typically the DOM doesn'
t | 20 // Multiple hit tests can occur when processing events. Typically the DOM doesn'
t |
| 20 // change when each event is processed so in order to decrease the time spent | 21 // change when each event is processed so in order to decrease the time spent |
| 21 // processing the events a hit cache is useful. For example a GestureTap event | 22 // processing the events a hit cache is useful. For example a GestureTap event |
| 22 // will generate a series of simulated mouse events (move, down, up, click) | 23 // will generate a series of simulated mouse events (move, down, up, click) |
| 23 // with the same co-ordinates and ideally we'd like to do the hit test once | 24 // with the same co-ordinates and ideally we'd like to do the hit test once |
| 24 // and use the result for the targetting of each event. | 25 // and use the result for the targetting of each event. |
| 25 // | 26 // |
| 26 // Some of the related design, motivation can be found in: | 27 // Some of the related design, motivation can be found in: |
| 27 // https://docs.google.com/document/d/1b0NYAD4S9BJIpHGa4JD2HLmW28f2rUh1jlqrgpU3z
VU/ | 28 // https://docs.google.com/document/d/1b0NYAD4S9BJIpHGa4JD2HLmW28f2rUh1jlqrgpU3z
VU/ |
| 28 // | 29 // |
| 29 | 30 |
| 30 // A cache size of 2 is used because it is relatively cheap to store; | 31 // A cache size of 2 is used because it is relatively cheap to store; |
| 31 // and the ping-pong behaviour of some of the HitTestRequest flags during | 32 // and the ping-pong behaviour of some of the HitTestRequest flags during |
| 32 // Mouse/Touch/Pointer events can generate increased cache misses with | 33 // Mouse/Touch/Pointer events can generate increased cache misses with |
| 33 // size of 1. | 34 // size of 1. |
| 34 #define HIT_TEST_CACHE_SIZE (2) | 35 #define HIT_TEST_CACHE_SIZE (2) |
| 35 | 36 |
| 36 class CORE_EXPORT HitTestCache final : public NoBaseWillBeGarbageCollectedFinali
zed<HitTestCache> { | 37 class CORE_EXPORT HitTestCache final : public NoBaseWillBeGarbageCollectedFinali
zed<HitTestCache> { |
| 38 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(HitTestCache); |
| 39 WTF_MAKE_NONCOPYABLE(HitTestCache); |
| 37 public: | 40 public: |
| 38 static PassOwnPtrWillBeRawPtr<HitTestCache> create() | 41 static PassOwnPtrWillBeRawPtr<HitTestCache> create() |
| 39 { | 42 { |
| 40 return adoptPtrWillBeNoop(new HitTestCache); | 43 return adoptPtrWillBeNoop(new HitTestCache); |
| 41 } | 44 } |
| 42 | 45 |
| 43 // Check the cache for a possible hit and update |result| if | 46 // Check the cache for a possible hit and update |result| if |
| 44 // hit encountered; returning true. Otherwise false. | 47 // hit encountered; returning true. Otherwise false. |
| 45 bool lookupCachedResult(HitTestResult&, uint64_t domTreeVersion); | 48 bool lookupCachedResult(HitTestResult&, uint64_t domTreeVersion); |
| 46 | 49 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 73 }; | 76 }; |
| 74 | 77 |
| 75 unsigned m_updateIndex; | 78 unsigned m_updateIndex; |
| 76 WillBeHeapVector<HitTestResult, HIT_TEST_CACHE_SIZE> m_items; | 79 WillBeHeapVector<HitTestResult, HIT_TEST_CACHE_SIZE> m_items; |
| 77 uint64_t m_domTreeVersion; | 80 uint64_t m_domTreeVersion; |
| 78 }; | 81 }; |
| 79 | 82 |
| 80 } // namespace blink | 83 } // namespace blink |
| 81 | 84 |
| 82 #endif // HitTestCache_h | 85 #endif // HitTestCache_h |
| OLD | NEW |