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