Chromium Code Reviews| 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 m_initialState(InitialState::kHidden), |
| 208 m_observeViewportIntersection(thresholds.isEmpty()) { | |
| 208 switch (rootMargin.size()) { | 209 switch (rootMargin.size()) { |
| 209 case 0: | 210 case 0: |
| 210 break; | 211 break; |
| 211 case 1: | 212 case 1: |
| 212 m_topMargin = m_rightMargin = m_bottomMargin = m_leftMargin = | 213 m_topMargin = m_rightMargin = m_bottomMargin = m_leftMargin = |
| 213 rootMargin[0]; | 214 rootMargin[0]; |
| 214 break; | 215 break; |
| 215 case 2: | 216 case 2: |
| 216 m_topMargin = m_bottomMargin = rootMargin[0]; | 217 m_topMargin = m_bottomMargin = rootMargin[0]; |
| 217 m_rightMargin = m_leftMargin = rootMargin[1]; | 218 m_rightMargin = m_leftMargin = rootMargin[1]; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 if (!target || m_root.get() == target) | 263 if (!target || m_root.get() == target) |
| 263 return; | 264 return; |
| 264 | 265 |
| 265 if (target->ensureIntersectionObserverData().getObservationFor(*this)) | 266 if (target->ensureIntersectionObserverData().getObservationFor(*this)) |
| 266 return; | 267 return; |
| 267 bool shouldReportRootBounds = false; | 268 bool shouldReportRootBounds = false; |
| 268 bool isDOMDescendant = false; | 269 bool isDOMDescendant = false; |
| 269 LocalFrame* targetFrame = target->document().frame(); | 270 LocalFrame* targetFrame = target->document().frame(); |
| 270 LocalFrame* rootFrame = m_root->document().frame(); | 271 LocalFrame* rootFrame = m_root->document().frame(); |
| 271 | 272 |
| 272 if (target->document() == rootNode()->document()) { | 273 if (m_observeViewportIntersection) { |
|
szager1
2016/11/16 21:37:55
Hmm... you're using m_observerViewportIntersection
xjz
2016/11/16 22:57:15
Done.
| |
| 274 shouldReportRootBounds = true; | |
| 275 } else if (target->document() == rootNode()->document()) { | |
| 273 shouldReportRootBounds = true; | 276 shouldReportRootBounds = true; |
| 274 isDOMDescendant = rootNode()->isShadowIncludingInclusiveAncestorOf(target); | 277 isDOMDescendant = rootNode()->isShadowIncludingInclusiveAncestorOf(target); |
| 275 } else if (targetFrame && rootFrame) { | 278 } else if (targetFrame && rootFrame) { |
| 276 shouldReportRootBounds = | 279 shouldReportRootBounds = |
| 277 targetFrame->securityContext()->getSecurityOrigin()->canAccess( | 280 targetFrame->securityContext()->getSecurityOrigin()->canAccess( |
| 278 rootFrame->securityContext()->getSecurityOrigin()); | 281 rootFrame->securityContext()->getSecurityOrigin()); |
| 279 isDOMDescendant = (targetFrame->tree().top() == rootFrame); | 282 isDOMDescendant = (targetFrame->tree().top() == rootFrame); |
| 280 } | 283 } |
| 281 | 284 |
| 282 IntersectionObservation* observation = | 285 IntersectionObservation* observation; |
| 283 new IntersectionObservation(*this, *target, shouldReportRootBounds); | 286 if (m_observeViewportIntersection) { |
| 287 observation = new ViewportIntersectionObservation(*this, *target); | |
| 288 } else { | |
| 289 observation = | |
| 290 new IntersectionObservation(*this, *target, shouldReportRootBounds); | |
| 291 } | |
| 284 target->ensureIntersectionObserverData().addObservation(*observation); | 292 target->ensureIntersectionObserverData().addObservation(*observation); |
| 285 m_observations.add(observation); | 293 m_observations.add(observation); |
| 286 | 294 |
| 287 if (!isDOMDescendant) { | 295 if (!isDOMDescendant) { |
| 288 m_root->document().addConsoleMessage( | 296 m_root->document().addConsoleMessage( |
| 289 ConsoleMessage::create(JSMessageSource, WarningMessageLevel, | 297 ConsoleMessage::create(JSMessageSource, WarningMessageLevel, |
| 290 "IntersectionObserver.observe(target): target " | 298 "IntersectionObserver.observe(target): target " |
| 291 "element is not a descendant of root.")); | 299 "element is not a descendant of root.")); |
| 292 return; | 300 return; |
| 293 } | 301 } |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 | 455 |
| 448 DEFINE_TRACE(IntersectionObserver) { | 456 DEFINE_TRACE(IntersectionObserver) { |
| 449 visitor->template registerWeakMembers< | 457 visitor->template registerWeakMembers< |
| 450 IntersectionObserver, &IntersectionObserver::clearWeakMembers>(this); | 458 IntersectionObserver, &IntersectionObserver::clearWeakMembers>(this); |
| 451 visitor->trace(m_callback); | 459 visitor->trace(m_callback); |
| 452 visitor->trace(m_observations); | 460 visitor->trace(m_observations); |
| 453 visitor->trace(m_entries); | 461 visitor->trace(m_entries); |
| 454 } | 462 } |
| 455 | 463 |
| 456 } // namespace blink | 464 } // namespace blink |
| OLD | NEW |