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 | 9 |
10 namespace blink { | 10 namespace blink { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 // - Otherwise: | 46 // - Otherwise: |
47 // - If root and target do not intersect, the threshold index is 0. | 47 // - If root and target do not intersect, the threshold index is 0. |
48 // - If root and target intersect but the intersection has zero-area | 48 // - If root and target intersect but the intersection has zero-area |
49 // (i.e., they have a coincident edge or corner), we consider the | 49 // (i.e., they have a coincident edge or corner), we consider the |
50 // intersection to have "crossed" a zero threshold, but not crossed | 50 // intersection to have "crossed" a zero threshold, but not crossed |
51 // any non-zero threshold. | 51 // any non-zero threshold. |
52 unsigned newThresholdIndex; | 52 unsigned newThresholdIndex; |
53 float newVisibleRatio = 0; | 53 float newVisibleRatio = 0; |
54 if (geometry.targetRect().isEmpty()) { | 54 if (geometry.targetRect().isEmpty()) { |
55 newThresholdIndex = geometry.doesIntersect() ? 1 : 0; | 55 newThresholdIndex = geometry.doesIntersect() ? 1 : 0; |
56 newVisibleRatio = geometry.doesIntersect() ? 1 : 0; | |
szager1
2016/12/09 17:30:07
You also need to delete the preceding line, and in
Sami
2016/12/09 17:51:16
Good catch. Rewrote this as we discussed offline.
| |
56 } else if (!geometry.doesIntersect()) { | 57 } else if (!geometry.doesIntersect()) { |
57 newThresholdIndex = 0; | 58 newThresholdIndex = 0; |
58 } else { | 59 } else { |
59 float intersectionArea = | 60 float intersectionArea = |
60 geometry.intersectionRect().size().width().toFloat() * | 61 geometry.intersectionRect().size().width().toFloat() * |
61 geometry.intersectionRect().size().height().toFloat(); | 62 geometry.intersectionRect().size().height().toFloat(); |
62 float targetArea = geometry.targetRect().size().width().toFloat() * | 63 float targetArea = geometry.targetRect().size().width().toFloat() * |
63 geometry.targetRect().size().height().toFloat(); | 64 geometry.targetRect().size().height().toFloat(); |
64 newVisibleRatio = intersectionArea / targetArea; | 65 newVisibleRatio = intersectionArea / targetArea; |
65 newThresholdIndex = observer().firstThresholdGreaterThan(newVisibleRatio); | 66 newThresholdIndex = observer().firstThresholdGreaterThan(newVisibleRatio); |
(...skipping 21 matching lines...) Expand all Loading... | |
87 target()->ensureIntersectionObserverData().removeObservation(observer()); | 88 target()->ensureIntersectionObserverData().removeObservation(observer()); |
88 m_observer.clear(); | 89 m_observer.clear(); |
89 } | 90 } |
90 | 91 |
91 DEFINE_TRACE(IntersectionObservation) { | 92 DEFINE_TRACE(IntersectionObservation) { |
92 visitor->trace(m_observer); | 93 visitor->trace(m_observer); |
93 visitor->trace(m_target); | 94 visitor->trace(m_target); |
94 } | 95 } |
95 | 96 |
96 } // namespace blink | 97 } // namespace blink |
OLD | NEW |