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

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

Issue 2645283008: IntersectionObserver: Always send an initial notification. (Closed)
Patch Set: Fix unit test 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/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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 Element* root, 166 Element* root,
167 const Vector<Length>& rootMargin, 167 const Vector<Length>& rootMargin,
168 const Vector<float>& thresholds) 168 const Vector<float>& thresholds)
169 : m_callback(&callback), 169 : m_callback(&callback),
170 m_root(root), 170 m_root(root),
171 m_thresholds(thresholds), 171 m_thresholds(thresholds),
172 m_topMargin(Fixed), 172 m_topMargin(Fixed),
173 m_rightMargin(Fixed), 173 m_rightMargin(Fixed),
174 m_bottomMargin(Fixed), 174 m_bottomMargin(Fixed),
175 m_leftMargin(Fixed), 175 m_leftMargin(Fixed),
176 m_rootIsImplicit(root ? 0 : 1), 176 m_rootIsImplicit(root ? 0 : 1) {
177 m_initialState(InitialState::kHidden) {
178 switch (rootMargin.size()) { 177 switch (rootMargin.size()) {
179 case 0: 178 case 0:
180 break; 179 break;
181 case 1: 180 case 1:
182 m_topMargin = m_rightMargin = m_bottomMargin = m_leftMargin = 181 m_topMargin = m_rightMargin = m_bottomMargin = m_leftMargin =
183 rootMargin[0]; 182 rootMargin[0];
184 break; 183 break;
185 case 2: 184 case 2:
186 m_topMargin = m_bottomMargin = rootMargin[0]; 185 m_topMargin = m_bottomMargin = rootMargin[0];
187 m_rightMargin = m_leftMargin = rootMargin[1]; 186 m_rightMargin = m_leftMargin = rootMargin[1];
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 target->ensureIntersectionObserverData().addObservation(*observation); 264 target->ensureIntersectionObserverData().addObservation(*observation);
266 m_observations.add(observation); 265 m_observations.add(observation);
267 266
268 if (!isDOMDescendant) { 267 if (!isDOMDescendant) {
269 root()->document().addConsoleMessage( 268 root()->document().addConsoleMessage(
270 ConsoleMessage::create(JSMessageSource, WarningMessageLevel, 269 ConsoleMessage::create(JSMessageSource, WarningMessageLevel,
271 "IntersectionObserver.observe(target): target " 270 "IntersectionObserver.observe(target): target "
272 "element is not a descendant of root.")); 271 "element is not a descendant of root."));
273 } 272 }
274 273
275 if (m_initialState == InitialState::kAuto) {
276 for (auto& observation : m_observations)
277 observation->setLastThresholdIndex(std::numeric_limits<unsigned>::max());
278 }
279
280 if (FrameView* frameView = targetFrame->view()) 274 if (FrameView* frameView = targetFrame->view())
281 frameView->scheduleAnimation(); 275 frameView->scheduleAnimation();
282 } 276 }
283 277
284 void IntersectionObserver::unobserve(Element* target, 278 void IntersectionObserver::unobserve(Element* target,
285 ExceptionState& exceptionState) { 279 ExceptionState& exceptionState) {
286 if (!target || !target->intersectionObserverData()) 280 if (!target || !target->intersectionObserverData())
287 return; 281 return;
288 282
289 if (IntersectionObservation* observation = 283 if (IntersectionObservation* observation =
(...skipping 17 matching lines...) Expand all
307 for (auto& observation : m_observations) 301 for (auto& observation : m_observations)
308 observation->computeIntersectionObservations(timestamp); 302 observation->computeIntersectionObservations(timestamp);
309 } 303 }
310 304
311 void IntersectionObserver::disconnect(ExceptionState& exceptionState) { 305 void IntersectionObserver::disconnect(ExceptionState& exceptionState) {
312 for (auto& observation : m_observations) 306 for (auto& observation : m_observations)
313 observation->disconnect(); 307 observation->disconnect();
314 m_observations.clear(); 308 m_observations.clear();
315 } 309 }
316 310
317 void IntersectionObserver::setInitialState(InitialState initialState) {
318 DCHECK(m_observations.isEmpty());
319 m_initialState = initialState;
320 }
321
322 HeapVector<Member<IntersectionObserverEntry>> IntersectionObserver::takeRecords( 311 HeapVector<Member<IntersectionObserverEntry>> IntersectionObserver::takeRecords(
323 ExceptionState& exceptionState) { 312 ExceptionState& exceptionState) {
324 HeapVector<Member<IntersectionObserverEntry>> entries; 313 HeapVector<Member<IntersectionObserverEntry>> entries;
325 entries.swap(m_entries); 314 entries.swap(m_entries);
326 return entries; 315 return entries;
327 } 316 }
328 317
329 static void appendLength(StringBuilder& stringBuilder, const Length& length) { 318 static void appendLength(StringBuilder& stringBuilder, const Length& length) {
330 stringBuilder.appendNumber(length.intValue()); 319 stringBuilder.appendNumber(length.intValue());
331 if (length.type() == Percent) 320 if (length.type() == Percent)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 361
373 DEFINE_TRACE(IntersectionObserver) { 362 DEFINE_TRACE(IntersectionObserver) {
374 visitor->template registerWeakMembers< 363 visitor->template registerWeakMembers<
375 IntersectionObserver, &IntersectionObserver::clearWeakMembers>(this); 364 IntersectionObserver, &IntersectionObserver::clearWeakMembers>(this);
376 visitor->trace(m_callback); 365 visitor->trace(m_callback);
377 visitor->trace(m_observations); 366 visitor->trace(m_observations);
378 visitor->trace(m_entries); 367 visitor->trace(m_entries);
379 } 368 }
380 369
381 } // namespace blink 370 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698