| 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 IgnorableExceptionState exceptionState; | 213 IgnorableExceptionState exceptionState; |
| 214 disconnect(exceptionState); | 214 disconnect(exceptionState); |
| 215 m_root = nullptr; | 215 m_root = nullptr; |
| 216 } | 216 } |
| 217 | 217 |
| 218 bool IntersectionObserver::rootIsValid() const { | 218 bool IntersectionObserver::rootIsValid() const { |
| 219 return rootIsImplicit() || root(); | 219 return rootIsImplicit() || root(); |
| 220 } | 220 } |
| 221 | 221 |
| 222 Document& IntersectionObserver::trackingDocument() const { | 222 Document& IntersectionObserver::trackingDocument() const { |
| 223 Document* document = nullptr; | |
| 224 if (rootIsImplicit()) { | 223 if (rootIsImplicit()) { |
| 225 DCHECK(m_callback->getExecutionContext()); | 224 DCHECK(m_callback->getExecutionContext()); |
| 226 document = toDocument(m_callback->getExecutionContext()); | 225 return *toDocument(m_callback->getExecutionContext()); |
| 227 } else { | |
| 228 DCHECK(root()); | |
| 229 document = &root()->document(); | |
| 230 } | 226 } |
| 231 DCHECK(document); | 227 DCHECK(root()); |
| 232 DCHECK(document->frame()); | 228 return root()->document(); |
| 233 return *document->frame()->localFrameRoot()->document(); | |
| 234 } | 229 } |
| 235 | 230 |
| 236 void IntersectionObserver::observe(Element* target, | 231 void IntersectionObserver::observe(Element* target, |
| 237 ExceptionState& exceptionState) { | 232 ExceptionState& exceptionState) { |
| 238 if (!rootIsValid()) { | 233 if (!rootIsValid()) { |
| 239 exceptionState.throwDOMException( | 234 exceptionState.throwDOMException( |
| 240 InvalidStateError, | 235 InvalidStateError, |
| 241 "observe() called on an IntersectionObserver with an invalid root."); | 236 "observe() called on an IntersectionObserver with an invalid root."); |
| 242 return; | 237 return; |
| 243 } | 238 } |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 | 402 |
| 408 DEFINE_TRACE(IntersectionObserver) { | 403 DEFINE_TRACE(IntersectionObserver) { |
| 409 visitor->template registerWeakMembers< | 404 visitor->template registerWeakMembers< |
| 410 IntersectionObserver, &IntersectionObserver::clearWeakMembers>(this); | 405 IntersectionObserver, &IntersectionObserver::clearWeakMembers>(this); |
| 411 visitor->trace(m_callback); | 406 visitor->trace(m_callback); |
| 412 visitor->trace(m_observations); | 407 visitor->trace(m_observations); |
| 413 visitor->trace(m_entries); | 408 visitor->trace(m_entries); |
| 414 } | 409 } |
| 415 | 410 |
| 416 } // namespace blink | 411 } // namespace blink |
| OLD | NEW |