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

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

Issue 1615573002: Set rootBounds to null for cross-origin observations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Get rid of js-test.js monkey patching Created 4 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/frame/FrameView.h" 9 #include "core/frame/FrameView.h"
10 #include "core/layout/LayoutBox.h" 10 #include "core/layout/LayoutBox.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 mapRectToDocumentCoordinates(*targetLayoutObject, geometry.targetRect); 109 mapRectToDocumentCoordinates(*targetLayoutObject, geometry.targetRect);
110 110
111 // Map intersectionRect into document coordinates. 111 // Map intersectionRect into document coordinates.
112 mapRectToDocumentCoordinates(*rootLayoutObject, geometry.intersectionRect); 112 mapRectToDocumentCoordinates(*rootLayoutObject, geometry.intersectionRect);
113 113
114 // Clip intersectionRect to FrameView visible area if necessary, and map all geometry to frame coordinates. 114 // Clip intersectionRect to FrameView visible area if necessary, and map all geometry to frame coordinates.
115 clipToFrameView(geometry); 115 clipToFrameView(geometry);
116 116
117 if (geometry.intersectionRect.size().isZero()) 117 if (geometry.intersectionRect.size().isZero())
118 geometry.intersectionRect = LayoutRect(); 118 geometry.intersectionRect = LayoutRect();
119 if (!m_shouldReportRootBounds)
120 geometry.rootRect = LayoutRect();
121 119
122 return true; 120 return true;
123 } 121 }
124 122
125 void IntersectionObservation::computeIntersectionObservations(double timestamp) 123 void IntersectionObservation::computeIntersectionObservations(double timestamp)
126 { 124 {
127 // Pre-oilpan, there will be a delay between the time when the target Elemen t gets deleted 125 // Pre-oilpan, there will be a delay between the time when the target Elemen t gets deleted
128 // (because its ref count dropped to zero) and when this IntersectionObserva tion gets 126 // (because its ref count dropped to zero) and when this IntersectionObserva tion gets
129 // deleted (during the next gc run, because the target Element is the only t hing keeping 127 // deleted (during the next gc run, because the target Element is the only t hing keeping
130 // the IntersectionObservation alive). During that interval, we need to che ck that m_target 128 // the IntersectionObservation alive). During that interval, we need to che ck that m_target
131 // hasn't been cleared. 129 // hasn't been cleared.
132 Element* targetElement = target(); 130 Element* targetElement = target();
133 if (!targetElement || !isActive()) 131 if (!targetElement || !isActive())
134 return; 132 return;
135 LayoutObject* targetLayoutObject = targetElement->layoutObject(); 133 LayoutObject* targetLayoutObject = targetElement->layoutObject();
136 // TODO(szager): Support SVG 134 // TODO(szager): Support SVG
137 if (!targetLayoutObject || (!targetLayoutObject->isBox() && !targetLayoutObj ect->isInline())) 135 if (!targetLayoutObject || (!targetLayoutObject->isBox() && !targetLayoutObj ect->isInline()))
138 return; 136 return;
139 137
140 IntersectionGeometry geometry; 138 IntersectionGeometry geometry;
141 if (!computeGeometry(geometry)) 139 if (!computeGeometry(geometry))
142 return; 140 return;
143 141
144 float intersectionArea = geometry.intersectionRect.size().width().toFloat() * geometry.intersectionRect.size().height().toFloat(); 142 float intersectionArea = geometry.intersectionRect.size().width().toFloat() * geometry.intersectionRect.size().height().toFloat();
145 float targetArea = geometry.targetRect.size().width().toFloat() * geometry.t argetRect.size().height().toFloat(); 143 float targetArea = geometry.targetRect.size().width().toFloat() * geometry.t argetRect.size().height().toFloat();
146 if (!targetArea) 144 if (!targetArea)
147 return; 145 return;
148 float newVisibleRatio = intersectionArea / targetArea; 146 float newVisibleRatio = intersectionArea / targetArea;
149 unsigned newThresholdIndex = observer().firstThresholdGreaterThan(newVisible Ratio); 147 unsigned newThresholdIndex = observer().firstThresholdGreaterThan(newVisible Ratio);
148 IntRect snappedRootBounds = pixelSnappedIntRect(geometry.rootRect);
149 IntRect* rootBoundsPointer = m_shouldReportRootBounds ? &snappedRootBounds : nullptr;
150 if (m_lastThresholdIndex != newThresholdIndex) { 150 if (m_lastThresholdIndex != newThresholdIndex) {
151 IntersectionObserverEntry* newEntry = new IntersectionObserverEntry( 151 IntersectionObserverEntry* newEntry = new IntersectionObserverEntry(
152 timestamp / 1000.0, 152 timestamp / 1000.0,
153 pixelSnappedIntRect(geometry.targetRect), 153 pixelSnappedIntRect(geometry.targetRect),
154 pixelSnappedIntRect(geometry.rootRect), 154 rootBoundsPointer,
155 pixelSnappedIntRect(geometry.intersectionRect), 155 pixelSnappedIntRect(geometry.intersectionRect),
156 targetElement); 156 targetElement);
157 observer().enqueueIntersectionObserverEntry(*newEntry); 157 observer().enqueueIntersectionObserverEntry(*newEntry);
158 } 158 }
159 setLastThresholdIndex(newThresholdIndex); 159 setLastThresholdIndex(newThresholdIndex);
160 } 160 }
161 161
162 void IntersectionObservation::disconnect() 162 void IntersectionObservation::disconnect()
163 { 163 {
164 IntersectionObserver* observer = m_observer; 164 IntersectionObserver* observer = m_observer;
165 clearRootAndRemoveFromTarget(); 165 clearRootAndRemoveFromTarget();
166 observer->removeObservation(*this); 166 observer->removeObservation(*this);
167 } 167 }
168 168
169 void IntersectionObservation::clearRootAndRemoveFromTarget() 169 void IntersectionObservation::clearRootAndRemoveFromTarget()
170 { 170 {
171 if (m_target) 171 if (m_target)
172 target()->ensureIntersectionObserverData().removeObservation(observer()) ; 172 target()->ensureIntersectionObserverData().removeObservation(observer()) ;
173 m_observer.clear(); 173 m_observer.clear();
174 } 174 }
175 175
176 DEFINE_TRACE(IntersectionObservation) 176 DEFINE_TRACE(IntersectionObservation)
177 { 177 {
178 visitor->trace(m_observer); 178 visitor->trace(m_observer);
179 visitor->trace(m_target); 179 visitor->trace(m_target);
180 } 180 }
181 181
182 } // namespace blink 182 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698