Chromium Code Reviews| 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 #include "core/layout/IntersectionGeometry.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 IntersectionObservation::IntersectionObservation(IntersectionObserver& observer, | 13 IntersectionObservation::IntersectionObservation(IntersectionObserver& observer, |
| 14 Element& target, | 14 Element& target, |
| 15 bool shouldReportRootBounds) | 15 bool shouldReportRootBounds) |
| 16 : m_observer(observer), | 16 : m_observer(observer), |
| 17 m_target(&target), | 17 m_target(&target), |
| 18 m_shouldReportRootBounds(shouldReportRootBounds), | 18 m_shouldReportRootBounds(shouldReportRootBounds), |
| 19 m_lastThresholdIndex(0) {} | 19 m_lastThresholdIndex(0) {} |
| 20 | 20 |
| 21 void IntersectionObservation::computeIntersectionObservations( | 21 void IntersectionObservation::computeIntersectionObservations( |
| 22 DOMHighResTimeStamp timestamp) { | 22 DOMHighResTimeStamp timestamp) { |
| 23 if (!m_target) | 23 if (!m_target) |
| 24 return; | 24 return; |
| 25 Vector<Length> rootMargin(4); | 25 Vector<Length> rootMargin(4); |
| 26 rootMargin[0] = m_observer->topMargin(); | 26 rootMargin[0] = m_observer->topMargin(); |
| 27 rootMargin[1] = m_observer->rightMargin(); | 27 rootMargin[1] = m_observer->rightMargin(); |
| 28 rootMargin[2] = m_observer->bottomMargin(); | 28 rootMargin[2] = m_observer->bottomMargin(); |
| 29 rootMargin[3] = m_observer->leftMargin(); | 29 rootMargin[3] = m_observer->leftMargin(); |
| 30 Node* rootNode = m_observer->rootNode(); | 30 IntersectionGeometry geometry(m_observer->root(), *target(), rootMargin, |
| 31 IntersectionGeometry geometry( | 31 m_shouldReportRootBounds); |
|
kenrb
2016/12/09 21:01:43
There is something I don't quite understand here.
szager1
2016/12/10 20:51:18
This patch depends on another patch (https://coder
| |
| 32 rootNode && !rootNode->isDocumentNode() ? toElement(rootNode) : nullptr, | |
| 33 *target(), rootMargin, m_shouldReportRootBounds); | |
| 34 geometry.computeGeometry(); | 32 geometry.computeGeometry(); |
| 35 | 33 |
| 36 // Some corner cases for threshold index: | 34 // Some corner cases for threshold index: |
| 37 // - If target rect is zero area, because it has zero width and/or zero | 35 // - If target rect is zero area, because it has zero width and/or zero |
| 38 // height, | 36 // height, |
| 39 // only two states are recognized: | 37 // only two states are recognized: |
| 40 // - 0 means not intersecting. | 38 // - 0 means not intersecting. |
| 41 // - 1 means intersecting. | 39 // - 1 means intersecting. |
| 42 // No other threshold crossings are possible. | 40 // No other threshold crossings are possible. |
| 43 // - Otherwise: | 41 // - Otherwise: |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 target()->ensureIntersectionObserverData().removeObservation(observer()); | 82 target()->ensureIntersectionObserverData().removeObservation(observer()); |
| 85 m_observer.clear(); | 83 m_observer.clear(); |
| 86 } | 84 } |
| 87 | 85 |
| 88 DEFINE_TRACE(IntersectionObservation) { | 86 DEFINE_TRACE(IntersectionObservation) { |
| 89 visitor->trace(m_observer); | 87 visitor->trace(m_observer); |
| 90 visitor->trace(m_target); | 88 visitor->trace(m_target); |
| 91 } | 89 } |
| 92 | 90 |
| 93 } // namespace blink | 91 } // namespace blink |
| OLD | NEW |