OLD | NEW |
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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 IntersectionObserverCallback& callback, | 196 IntersectionObserverCallback& callback, |
197 Node& root, | 197 Node& root, |
198 const Vector<Length>& rootMargin, | 198 const Vector<Length>& rootMargin, |
199 const Vector<float>& thresholds) | 199 const Vector<float>& thresholds) |
200 : m_callback(&callback), | 200 : m_callback(&callback), |
201 m_root(&root), | 201 m_root(&root), |
202 m_thresholds(thresholds), | 202 m_thresholds(thresholds), |
203 m_topMargin(Fixed), | 203 m_topMargin(Fixed), |
204 m_rightMargin(Fixed), | 204 m_rightMargin(Fixed), |
205 m_bottomMargin(Fixed), | 205 m_bottomMargin(Fixed), |
206 m_leftMargin(Fixed), | 206 m_leftMargin(Fixed) { |
207 m_initialState(InitialState::kHidden) { | |
208 switch (rootMargin.size()) { | 207 switch (rootMargin.size()) { |
209 case 0: | 208 case 0: |
210 break; | 209 break; |
211 case 1: | 210 case 1: |
212 m_topMargin = m_rightMargin = m_bottomMargin = m_leftMargin = | 211 m_topMargin = m_rightMargin = m_bottomMargin = m_leftMargin = |
213 rootMargin[0]; | 212 rootMargin[0]; |
214 break; | 213 break; |
215 case 2: | 214 case 2: |
216 m_topMargin = m_bottomMargin = rootMargin[0]; | 215 m_topMargin = m_bottomMargin = rootMargin[0]; |
217 m_rightMargin = m_leftMargin = rootMargin[1]; | 216 m_rightMargin = m_leftMargin = rootMargin[1]; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 m_observations.add(observation); | 284 m_observations.add(observation); |
286 | 285 |
287 if (!isDOMDescendant) { | 286 if (!isDOMDescendant) { |
288 m_root->document().addConsoleMessage( | 287 m_root->document().addConsoleMessage( |
289 ConsoleMessage::create(JSMessageSource, WarningMessageLevel, | 288 ConsoleMessage::create(JSMessageSource, WarningMessageLevel, |
290 "IntersectionObserver.observe(target): target " | 289 "IntersectionObserver.observe(target): target " |
291 "element is not a descendant of root.")); | 290 "element is not a descendant of root.")); |
292 return; | 291 return; |
293 } | 292 } |
294 | 293 |
295 if (m_initialState == InitialState::kAuto) { | |
296 for (auto& observation : m_observations) | |
297 observation->setLastThresholdIndex(std::numeric_limits<unsigned>::max()); | |
298 } | |
299 | |
300 if (!rootFrame) | 294 if (!rootFrame) |
301 return; | 295 return; |
302 if (FrameView* rootFrameView = rootFrame->view()) | 296 if (FrameView* rootFrameView = rootFrame->view()) |
303 rootFrameView->scheduleAnimation(); | 297 rootFrameView->scheduleAnimation(); |
304 } | 298 } |
305 | 299 |
306 void IntersectionObserver::unobserve(Element* target, | 300 void IntersectionObserver::unobserve(Element* target, |
307 ExceptionState& exceptionState) { | 301 ExceptionState& exceptionState) { |
308 if (!m_root) { | 302 if (!m_root) { |
309 exceptionState.throwDOMException( | 303 exceptionState.throwDOMException( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 for (auto& observation : m_observations) | 338 for (auto& observation : m_observations) |
345 observation->clearRootAndRemoveFromTarget(); | 339 observation->clearRootAndRemoveFromTarget(); |
346 m_observations.clear(); | 340 m_observations.clear(); |
347 } | 341 } |
348 | 342 |
349 void IntersectionObserver::removeObservation( | 343 void IntersectionObserver::removeObservation( |
350 IntersectionObservation& observation) { | 344 IntersectionObservation& observation) { |
351 m_observations.remove(&observation); | 345 m_observations.remove(&observation); |
352 } | 346 } |
353 | 347 |
354 void IntersectionObserver::setInitialState(InitialState initialState) { | |
355 DCHECK(m_observations.isEmpty()); | |
356 m_initialState = initialState; | |
357 } | |
358 | |
359 HeapVector<Member<IntersectionObserverEntry>> IntersectionObserver::takeRecords( | 348 HeapVector<Member<IntersectionObserverEntry>> IntersectionObserver::takeRecords( |
360 ExceptionState& exceptionState) { | 349 ExceptionState& exceptionState) { |
361 HeapVector<Member<IntersectionObserverEntry>> entries; | 350 HeapVector<Member<IntersectionObserverEntry>> entries; |
362 | 351 |
363 if (!m_root) | 352 if (!m_root) |
364 exceptionState.throwDOMException(InvalidStateError, | 353 exceptionState.throwDOMException(InvalidStateError, |
365 "takeRecords() called on an " | 354 "takeRecords() called on an " |
366 "IntersectionObserver with an invalid " | 355 "IntersectionObserver with an invalid " |
367 "root."); | 356 "root."); |
368 else | 357 else |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 | 436 |
448 DEFINE_TRACE(IntersectionObserver) { | 437 DEFINE_TRACE(IntersectionObserver) { |
449 visitor->template registerWeakMembers< | 438 visitor->template registerWeakMembers< |
450 IntersectionObserver, &IntersectionObserver::clearWeakMembers>(this); | 439 IntersectionObserver, &IntersectionObserver::clearWeakMembers>(this); |
451 visitor->trace(m_callback); | 440 visitor->trace(m_callback); |
452 visitor->trace(m_observations); | 441 visitor->trace(m_observations); |
453 visitor->trace(m_entries); | 442 visitor->trace(m_entries); |
454 } | 443 } |
455 | 444 |
456 } // namespace blink | 445 } // namespace blink |
OLD | NEW |