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

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

Issue 2051253002: Start autoplay muted videos with autoplay attribute when they are visible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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/IntersectionObserver.h" 5 #include "core/dom/IntersectionObserver.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "core/css/parser/CSSParserTokenRange.h" 8 #include "core/css/parser/CSSParserTokenRange.h"
9 #include "core/css/parser/CSSTokenizer.h" 9 #include "core/css/parser/CSSTokenizer.h"
10 #include "core/dom/Element.h" 10 #include "core/dom/Element.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 return toElement(node)->layoutObject(); 172 return toElement(node)->layoutObject();
173 } 173 }
174 174
175 void IntersectionObserver::observe(Element* target, ExceptionState& exceptionSta te) 175 void IntersectionObserver::observe(Element* target, ExceptionState& exceptionSta te)
176 { 176 {
177 if (!m_root) { 177 if (!m_root) {
178 exceptionState.throwDOMException(InvalidStateError, "observe() called on an IntersectionObserver with an invalid root."); 178 exceptionState.throwDOMException(InvalidStateError, "observe() called on an IntersectionObserver with an invalid root.");
179 return; 179 return;
180 } 180 }
181 181
182 observe(target);
183 }
184
185 void IntersectionObserver::observe(Element* target)
186 {
187 if (!m_root)
188 return;
189
182 if (!target || m_root.get() == target) 190 if (!target || m_root.get() == target)
183 return; 191 return;
184 192
185 if (target->ensureIntersectionObserverData().getObservationFor(*this)) 193 if (target->ensureIntersectionObserverData().getObservationFor(*this))
186 return; 194 return;
187
188 bool shouldReportRootBounds = false; 195 bool shouldReportRootBounds = false;
189 bool isDOMDescendant = false; 196 bool isDOMDescendant = false;
190 LocalFrame* targetFrame = target->document().frame(); 197 LocalFrame* targetFrame = target->document().frame();
191 LocalFrame* rootFrame = m_root->document().frame(); 198 LocalFrame* rootFrame = m_root->document().frame();
192 199
193 if (target->document() == rootNode()->document()) { 200 if (target->document() == rootNode()->document()) {
194 shouldReportRootBounds = true; 201 shouldReportRootBounds = true;
195 isDOMDescendant = target->isDescendantOf(rootNode()); 202 isDOMDescendant = target->isDescendantOf(rootNode());
196 } else if (targetFrame && rootFrame) { 203 } else if (targetFrame && rootFrame) {
197 shouldReportRootBounds = targetFrame->securityContext()->getSecurityOrig in()->canAccess(rootFrame->securityContext()->getSecurityOrigin()); 204 shouldReportRootBounds = targetFrame->securityContext()->getSecurityOrig in()->canAccess(rootFrame->securityContext()->getSecurityOrigin());
(...skipping 17 matching lines...) Expand all
215 rootFrameView->scheduleAnimation(); 222 rootFrameView->scheduleAnimation();
216 } 223 }
217 224
218 void IntersectionObserver::unobserve(Element* target, ExceptionState& exceptionS tate) 225 void IntersectionObserver::unobserve(Element* target, ExceptionState& exceptionS tate)
219 { 226 {
220 if (!m_root) { 227 if (!m_root) {
221 exceptionState.throwDOMException(InvalidStateError, "unobserve() called on an IntersectionObserver with an invalid root."); 228 exceptionState.throwDOMException(InvalidStateError, "unobserve() called on an IntersectionObserver with an invalid root.");
222 return; 229 return;
223 } 230 }
224 231
232 unobserve(target);
233 }
234
235 void IntersectionObserver::unobserve(Element* target)
236 {
237 if (!m_root)
238 return;
239
225 if (!target || !target->intersectionObserverData()) 240 if (!target || !target->intersectionObserverData())
226 return; 241 return;
227 // TODO(szager): unobserve callback 242 // TODO(szager): unobserve callback
228 if (IntersectionObservation* observation = target->intersectionObserverData( )->getObservationFor(*this)) 243 if (IntersectionObservation* observation = target->intersectionObserverData( )->getObservationFor(*this))
229 observation->disconnect(); 244 observation->disconnect();
230 } 245 }
231 246
232 void IntersectionObserver::computeIntersectionObservations() 247 void IntersectionObserver::computeIntersectionObservations()
233 { 248 {
234 Document* callbackDocument = toDocument(m_callback->getExecutionContext()); 249 Document* callbackDocument = toDocument(m_callback->getExecutionContext());
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 unsigned IntersectionObserver::firstThresholdGreaterThan(float ratio) const 348 unsigned IntersectionObserver::firstThresholdGreaterThan(float ratio) const
334 { 349 {
335 unsigned result = 0; 350 unsigned result = 0;
336 while (result < m_thresholds.size() && m_thresholds[result] <= ratio) 351 while (result < m_thresholds.size() && m_thresholds[result] <= ratio)
337 ++result; 352 ++result;
338 return result; 353 return result;
339 } 354 }
340 355
341 void IntersectionObserver::deliver() 356 void IntersectionObserver::deliver()
342 { 357 {
343
344 if (m_entries.isEmpty()) 358 if (m_entries.isEmpty())
345 return; 359 return;
346 360
347 HeapVector<Member<IntersectionObserverEntry>> entries; 361 HeapVector<Member<IntersectionObserverEntry>> entries;
348 entries.swap(m_entries); 362 entries.swap(m_entries);
349 m_callback->handleEvent(entries, *this); 363 m_callback->handleEvent(entries, *this);
350 } 364 }
351 365
352 DEFINE_TRACE(IntersectionObserver) 366 DEFINE_TRACE(IntersectionObserver)
353 { 367 {
354 visitor->template registerWeakMembers<IntersectionObserver, &IntersectionObs erver::clearWeakMembers>(this); 368 visitor->template registerWeakMembers<IntersectionObserver, &IntersectionObs erver::clearWeakMembers>(this);
355 visitor->trace(m_callback); 369 visitor->trace(m_callback);
356 visitor->trace(m_observations); 370 visitor->trace(m_observations);
357 visitor->trace(m_entries); 371 visitor->trace(m_entries);
358 } 372 }
359 373
360 } // namespace blink 374 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698