OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "core/dom/IntersectionObservation.h" | 5 #include "core/dom/IntersectionObservation.h" |
6 | 6 |
7 #include "core/dom/ElementRareData.h" | 7 #include "core/dom/ElementRareData.h" |
8 #include "core/dom/IntersectionObserver.h" | 8 #include "core/dom/IntersectionObserver.h" |
| 9 #include "core/layout/IntersectionGeometry.h" |
9 | 10 |
10 namespace blink { | 11 namespace blink { |
11 | 12 |
12 IntersectionObservation::IntersectionObservation( | 13 IntersectionObservation::IntersectionObservation(IntersectionObserver& observer, |
13 IntersectionObserver& observer, | 14 Element& target, |
14 Element& target, | 15 bool shouldReportRootBounds) |
15 IntersectionGeometry::ReportRootBounds shouldReportRootBounds) | |
16 : m_observer(observer), | 16 : m_observer(observer), |
17 m_target(&target), | 17 m_target(&target), |
18 m_shouldReportRootBounds( | 18 m_shouldReportRootBounds(shouldReportRootBounds), |
19 shouldReportRootBounds == | |
20 IntersectionGeometry::ReportRootBounds::kShouldReportRootBounds), | |
21 m_lastThresholdIndex(0) {} | 19 m_lastThresholdIndex(0) {} |
22 | 20 |
23 void IntersectionObservation::computeIntersectionObservations( | 21 void IntersectionObservation::computeIntersectionObservations( |
24 DOMHighResTimeStamp timestamp) { | 22 DOMHighResTimeStamp timestamp) { |
25 if (!m_target) | 23 if (!m_target) |
26 return; | 24 return; |
27 Vector<Length> rootMargin(4); | 25 Vector<Length> rootMargin(4); |
28 rootMargin[0] = m_observer->topMargin(); | 26 rootMargin[0] = m_observer->topMargin(); |
29 rootMargin[1] = m_observer->rightMargin(); | 27 rootMargin[1] = m_observer->rightMargin(); |
30 rootMargin[2] = m_observer->bottomMargin(); | 28 rootMargin[2] = m_observer->bottomMargin(); |
31 rootMargin[3] = m_observer->leftMargin(); | 29 rootMargin[3] = m_observer->leftMargin(); |
| 30 Node* rootNode = m_observer->rootNode(); |
32 IntersectionGeometry geometry( | 31 IntersectionGeometry geometry( |
33 m_observer->rootNode(), target(), rootMargin, | 32 rootNode && !rootNode->isDocumentNode() ? toElement(rootNode) : nullptr, |
34 m_shouldReportRootBounds | 33 *target(), rootMargin, m_shouldReportRootBounds); |
35 ? IntersectionGeometry::ReportRootBounds::kShouldReportRootBounds | |
36 : IntersectionGeometry::ReportRootBounds::kShouldNotReportRootBounds); | |
37 geometry.computeGeometry(); | 34 geometry.computeGeometry(); |
38 | 35 |
39 // Some corner cases for threshold index: | 36 // Some corner cases for threshold index: |
40 // - If target rect is zero area, because it has zero width and/or zero | 37 // - If target rect is zero area, because it has zero width and/or zero |
41 // height, | 38 // height, |
42 // only two states are recognized: | 39 // only two states are recognized: |
43 // - 0 means not intersecting. | 40 // - 0 means not intersecting. |
44 // - 1 means intersecting. | 41 // - 1 means intersecting. |
45 // No other threshold crossings are possible. | 42 // No other threshold crossings are possible. |
46 // - Otherwise: | 43 // - Otherwise: |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 target()->ensureIntersectionObserverData().removeObservation(observer()); | 84 target()->ensureIntersectionObserverData().removeObservation(observer()); |
88 m_observer.clear(); | 85 m_observer.clear(); |
89 } | 86 } |
90 | 87 |
91 DEFINE_TRACE(IntersectionObservation) { | 88 DEFINE_TRACE(IntersectionObservation) { |
92 visitor->trace(m_observer); | 89 visitor->trace(m_observer); |
93 visitor->trace(m_target); | 90 visitor->trace(m_target); |
94 } | 91 } |
95 | 92 |
96 } // namespace blink | 93 } // namespace blink |
OLD | NEW |