| 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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 if (!target || root() == target) | 235 if (!target || root() == target) |
| 236 return; | 236 return; |
| 237 | 237 |
| 238 LocalFrame* targetFrame = target->document().frame(); | 238 LocalFrame* targetFrame = target->document().frame(); |
| 239 if (!targetFrame) | 239 if (!targetFrame) |
| 240 return; | 240 return; |
| 241 | 241 |
| 242 if (target->ensureIntersectionObserverData().getObservationFor(*this)) | 242 if (target->ensureIntersectionObserverData().getObservationFor(*this)) |
| 243 return; | 243 return; |
| 244 | 244 |
| 245 bool isDOMDescendant = true; | 245 bool shouldReportRootBounds = true; |
| 246 bool shouldReportRootBounds = false; | |
| 247 if (rootIsImplicit()) { | 246 if (rootIsImplicit()) { |
| 248 Frame* rootFrame = targetFrame->tree().top(); | 247 Frame* rootFrame = targetFrame->tree().top(); |
| 249 DCHECK(rootFrame); | 248 DCHECK(rootFrame); |
| 250 if (rootFrame == targetFrame) { | 249 if (rootFrame != targetFrame) { |
| 251 shouldReportRootBounds = true; | |
| 252 } else { | |
| 253 shouldReportRootBounds = | 250 shouldReportRootBounds = |
| 254 targetFrame->securityContext()->getSecurityOrigin()->canAccess( | 251 targetFrame->securityContext()->getSecurityOrigin()->canAccess( |
| 255 rootFrame->securityContext()->getSecurityOrigin()); | 252 rootFrame->securityContext()->getSecurityOrigin()); |
| 256 } | 253 } |
| 257 } else { | |
| 258 shouldReportRootBounds = true; | |
| 259 isDOMDescendant = root()->isShadowIncludingInclusiveAncestorOf(target); | |
| 260 } | 254 } |
| 261 | 255 |
| 262 IntersectionObservation* observation = | 256 IntersectionObservation* observation = |
| 263 new IntersectionObservation(*this, *target, shouldReportRootBounds); | 257 new IntersectionObservation(*this, *target, shouldReportRootBounds); |
| 264 target->ensureIntersectionObserverData().addObservation(*observation); | 258 target->ensureIntersectionObserverData().addObservation(*observation); |
| 265 m_observations.add(observation); | 259 m_observations.add(observation); |
| 266 | |
| 267 if (!isDOMDescendant) { | |
| 268 root()->document().addConsoleMessage( | |
| 269 ConsoleMessage::create(JSMessageSource, WarningMessageLevel, | |
| 270 "IntersectionObserver.observe(target): target " | |
| 271 "element is not a descendant of root.")); | |
| 272 } | |
| 273 | |
| 274 if (FrameView* frameView = targetFrame->view()) | 260 if (FrameView* frameView = targetFrame->view()) |
| 275 frameView->scheduleAnimation(); | 261 frameView->scheduleAnimation(); |
| 276 } | 262 } |
| 277 | 263 |
| 278 void IntersectionObserver::unobserve(Element* target, | 264 void IntersectionObserver::unobserve(Element* target, |
| 279 ExceptionState& exceptionState) { | 265 ExceptionState& exceptionState) { |
| 280 if (!target || !target->intersectionObserverData()) | 266 if (!target || !target->intersectionObserverData()) |
| 281 return; | 267 return; |
| 282 | 268 |
| 283 if (IntersectionObservation* observation = | 269 if (IntersectionObservation* observation = |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 | 348 |
| 363 DEFINE_TRACE(IntersectionObserver) { | 349 DEFINE_TRACE(IntersectionObserver) { |
| 364 visitor->template registerWeakMembers< | 350 visitor->template registerWeakMembers< |
| 365 IntersectionObserver, &IntersectionObserver::clearWeakMembers>(this); | 351 IntersectionObserver, &IntersectionObserver::clearWeakMembers>(this); |
| 366 visitor->trace(m_callback); | 352 visitor->trace(m_callback); |
| 367 visitor->trace(m_observations); | 353 visitor->trace(m_observations); |
| 368 visitor->trace(m_entries); | 354 visitor->trace(m_entries); |
| 369 } | 355 } |
| 370 | 356 |
| 371 } // namespace blink | 357 } // namespace blink |
| OLD | NEW |