Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(419)

Side by Side Diff: third_party/WebKit/Source/core/dom/IntersectionObservation.cpp

Issue 2645283008: IntersectionObserver: Always send an initial notification. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 geometry.intersectionRect().size().height().toFloat(); 56 geometry.intersectionRect().size().height().toFloat();
57 float targetArea = geometry.targetRect().size().width().toFloat() * 57 float targetArea = geometry.targetRect().size().width().toFloat() *
58 geometry.targetRect().size().height().toFloat(); 58 geometry.targetRect().size().height().toFloat();
59 newVisibleRatio = intersectionArea / targetArea; 59 newVisibleRatio = intersectionArea / targetArea;
60 } 60 }
61 newThresholdIndex = observer()->firstThresholdGreaterThan(newVisibleRatio); 61 newThresholdIndex = observer()->firstThresholdGreaterThan(newVisibleRatio);
62 } else { 62 } else {
63 newVisibleRatio = 0; 63 newVisibleRatio = 0;
64 newThresholdIndex = 0; 64 newThresholdIndex = 0;
65 } 65 }
66
67 // See HACK warning in IntersectionObservation.h
68 newThresholdIndex++;
69 RELEASE_ASSERT(newThresholdIndex < kMaxThresholdIndex);
70
66 if (m_lastThresholdIndex != newThresholdIndex) { 71 if (m_lastThresholdIndex != newThresholdIndex) {
67 IntRect snappedRootBounds = geometry.rootIntRect(); 72 IntRect snappedRootBounds = geometry.rootIntRect();
68 IntRect* rootBoundsPointer = 73 IntRect* rootBoundsPointer =
69 m_shouldReportRootBounds ? &snappedRootBounds : nullptr; 74 m_shouldReportRootBounds ? &snappedRootBounds : nullptr;
70 IntersectionObserverEntry* newEntry = new IntersectionObserverEntry( 75 IntersectionObserverEntry* newEntry = new IntersectionObserverEntry(
71 timestamp, newVisibleRatio, geometry.targetIntRect(), rootBoundsPointer, 76 timestamp, newVisibleRatio, geometry.targetIntRect(), rootBoundsPointer,
72 geometry.intersectionIntRect(), target()); 77 geometry.intersectionIntRect(), target());
73 observer()->enqueueIntersectionObserverEntry(*newEntry); 78 observer()->enqueueIntersectionObserverEntry(*newEntry);
74 setLastThresholdIndex(newThresholdIndex); 79 setLastThresholdIndex(newThresholdIndex);
75 } 80 }
76 } 81 }
77 82
78 void IntersectionObservation::disconnect() { 83 void IntersectionObservation::disconnect() {
79 DCHECK(observer()); 84 DCHECK(observer());
80 if (m_target) 85 if (m_target)
81 target()->ensureIntersectionObserverData().removeObservation(*observer()); 86 target()->ensureIntersectionObserverData().removeObservation(*observer());
82 m_observer.clear(); 87 m_observer.clear();
83 } 88 }
84 89
85 DEFINE_TRACE(IntersectionObservation) { 90 DEFINE_TRACE(IntersectionObservation) {
86 visitor->trace(m_observer); 91 visitor->trace(m_observer);
87 visitor->trace(m_target); 92 visitor->trace(m_target);
88 } 93 }
89 94
90 } // namespace blink 95 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698