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

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

Issue 1889053002: IntersectionObserver: notify when root or target is removed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Created 4 years, 8 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 if (ancestorFrame != descendantFrame) 133 if (ancestorFrame != descendantFrame)
134 return false; 134 return false;
135 135
136 while (descendant && descendant != ancestor) 136 while (descendant && descendant != ancestor)
137 descendant = descendant->containingBlock(); 137 descendant = descendant->containingBlock();
138 return descendant; 138 return descendant;
139 } 139 }
140 140
141 bool IntersectionObservation::computeGeometry(IntersectionGeometry& geometry) co nst 141 bool IntersectionObservation::computeGeometry(IntersectionGeometry& geometry) co nst
142 { 142 {
143 // Pre-oilpan, there will be a delay between the time when the target Elemen t gets deleted 143 // In the first few lines here, before initializeGeometry is called, "return true"
144 // (because its ref count dropped to zero) and when this IntersectionObserva tion gets 144 // effectively means "if the previous observed state was that root and targe t were
145 // deleted (during the next gc run, because the target Element is the only t hing keeping 145 // intersecting, then generate a notification indicating that they are no lo nger
146 // the IntersectionObservation alive). During that interval, we need to che ck that m_target 146 // intersecting." This happens, for example, when root or target is removed from the
147 // hasn't been cleared. 147 // DOM tree and not reinserted before the next frame is generated.
148 Element* targetElement = target(); 148 Element* targetElement = target();
149 if (!targetElement || !targetElement->inShadowIncludingDocument()) 149 if (!targetElement)
150 return false; 150 return false;
151 if (!targetElement->inShadowIncludingDocument())
152 return true;
ojan 2016/04/15 18:19:08 Nit: I think this code would be more self-document
szager1 2016/04/15 19:47:23 The return value means "should we *ever* send a no
ojan 2016/04/15 22:40:52 All the more reason to use an out param with a cle
153 DCHECK(m_observer);
154 Element* rootElement = m_observer->root();
155 if (rootElement && !rootElement->inShadowIncludingDocument())
156 return true;
157
158 LayoutObject* rootLayoutObject = m_observer->rootLayoutObject();
159 if (!rootLayoutObject || !rootLayoutObject->isBoxModelObject())
160 return false;
161 // TODO(szager): Support SVG
151 LayoutObject* targetLayoutObject = targetElement->layoutObject(); 162 LayoutObject* targetLayoutObject = targetElement->layoutObject();
152 DCHECK(m_observer);
153 LayoutObject* rootLayoutObject = m_observer->rootLayoutObject();
154 // TODO(szager): Support SVG
155 if (!targetLayoutObject) 163 if (!targetLayoutObject)
156 return false; 164 return false;
157 if (!targetLayoutObject->isBoxModelObject() && !targetLayoutObject->isText() ) 165 if (!targetLayoutObject->isBoxModelObject() && !targetLayoutObject->isText() )
158 return false; 166 return false;
159 if (!rootLayoutObject || !rootLayoutObject->isBoxModelObject())
160 return false;
161 if (!isContainingBlockChainDescendant(targetLayoutObject, rootLayoutObject)) 167 if (!isContainingBlockChainDescendant(targetLayoutObject, rootLayoutObject))
162 return false; 168 return true;
163 169
164 initializeGeometry(geometry); 170 initializeGeometry(geometry);
165 171
166 clipToRoot(geometry); 172 clipToRoot(geometry);
167 173
168 mapTargetRectToTargetFrameCoordinates(geometry.targetRect); 174 mapTargetRectToTargetFrameCoordinates(geometry.targetRect);
169 175
170 if (geometry.doesIntersect) 176 if (geometry.doesIntersect)
171 mapRootRectToTargetFrameCoordinates(geometry.intersectionRect); 177 mapRootRectToTargetFrameCoordinates(geometry.intersectionRect);
172 else 178 else
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 IntRect snappedRootBounds = pixelSnappedIntRect(geometry.rootRect); 219 IntRect snappedRootBounds = pixelSnappedIntRect(geometry.rootRect);
214 IntRect* rootBoundsPointer = m_shouldReportRootBounds ? &snappedRootBoun ds : nullptr; 220 IntRect* rootBoundsPointer = m_shouldReportRootBounds ? &snappedRootBoun ds : nullptr;
215 IntersectionObserverEntry* newEntry = new IntersectionObserverEntry( 221 IntersectionObserverEntry* newEntry = new IntersectionObserverEntry(
216 timestamp, 222 timestamp,
217 newVisibleRatio, 223 newVisibleRatio,
218 pixelSnappedIntRect(geometry.targetRect), 224 pixelSnappedIntRect(geometry.targetRect),
219 rootBoundsPointer, 225 rootBoundsPointer,
220 pixelSnappedIntRect(geometry.intersectionRect), 226 pixelSnappedIntRect(geometry.intersectionRect),
221 target()); 227 target());
222 observer().enqueueIntersectionObserverEntry(*newEntry); 228 observer().enqueueIntersectionObserverEntry(*newEntry);
229 setLastThresholdIndex(newThresholdIndex);
223 } 230 }
224 setLastThresholdIndex(newThresholdIndex);
225 } 231 }
226 232
227 void IntersectionObservation::disconnect() 233 void IntersectionObservation::disconnect()
228 { 234 {
229 IntersectionObserver* observer = m_observer; 235 IntersectionObserver* observer = m_observer;
230 clearRootAndRemoveFromTarget(); 236 clearRootAndRemoveFromTarget();
231 observer->removeObservation(*this); 237 observer->removeObservation(*this);
232 } 238 }
233 239
234 void IntersectionObservation::clearRootAndRemoveFromTarget() 240 void IntersectionObservation::clearRootAndRemoveFromTarget()
235 { 241 {
236 if (m_target) 242 if (m_target)
237 target()->ensureIntersectionObserverData().removeObservation(observer()) ; 243 target()->ensureIntersectionObserverData().removeObservation(observer()) ;
238 m_observer.clear(); 244 m_observer.clear();
239 } 245 }
240 246
241 DEFINE_TRACE(IntersectionObservation) 247 DEFINE_TRACE(IntersectionObservation)
242 { 248 {
243 visitor->trace(m_observer); 249 visitor->trace(m_observer);
244 visitor->trace(m_target); 250 visitor->trace(m_target);
245 } 251 }
246 252
247 } // namespace blink 253 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698