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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 } | 47 } |
| 48 | 48 |
| 49 ExecutionContext* getExecutionContext() const override { return m_context; } | 49 ExecutionContext* getExecutionContext() const override { return m_context; } |
| 50 | 50 |
| 51 DEFINE_INLINE_TRACE() { | 51 DEFINE_INLINE_TRACE() { |
| 52 IntersectionObserverCallback::trace(visitor); | 52 IntersectionObserverCallback::trace(visitor); |
| 53 visitor->trace(m_context); | 53 visitor->trace(m_context); |
| 54 } | 54 } |
| 55 | 55 |
| 56 private: | 56 private: |
| 57 WeakMember<ExecutionContext> m_context; | 57 Member<ExecutionContext> m_context; |
|
sof
2016/12/26 07:28:04
The use of WeakMember<> comes from
https://coder
| |
| 58 std::unique_ptr<IntersectionObserver::EventCallback> m_callback; | 58 std::unique_ptr<IntersectionObserver::EventCallback> m_callback; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 void parseRootMargin(String rootMarginParameter, | 61 void parseRootMargin(String rootMarginParameter, |
| 62 Vector<Length>& rootMargin, | 62 Vector<Length>& rootMargin, |
| 63 ExceptionState& exceptionState) { | 63 ExceptionState& exceptionState) { |
| 64 // TODO(szager): Make sure this exact syntax and behavior is spec-ed | 64 // TODO(szager): Make sure this exact syntax and behavior is spec-ed |
| 65 // somewhere. | 65 // somewhere. |
| 66 | 66 |
| 67 // The root margin argument accepts syntax similar to that for CSS margin: | 67 // The root margin argument accepts syntax similar to that for CSS margin: |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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; | 223 Document* document = nullptr; |
| 224 if (rootIsImplicit()) { | 224 if (rootIsImplicit()) { |
| 225 DCHECK(m_callback->getExecutionContext()); | |
| 226 document = toDocument(m_callback->getExecutionContext()); | 225 document = toDocument(m_callback->getExecutionContext()); |
| 227 } else { | 226 } else { |
| 228 DCHECK(root()); | 227 DCHECK(root()); |
| 229 document = &root()->document(); | 228 document = &root()->document(); |
| 230 } | 229 } |
| 231 DCHECK(document); | 230 DCHECK(document); |
| 232 DCHECK(document->frame()); | 231 DCHECK(document->frame()); |
| 233 return *document->frame()->localFrameRoot()->document(); | 232 return *document->frame()->localFrameRoot()->document(); |
| 234 } | 233 } |
| 235 | 234 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 return; | 302 return; |
| 304 | 303 |
| 305 if (IntersectionObservation* observation = | 304 if (IntersectionObservation* observation = |
| 306 target->intersectionObserverData()->getObservationFor(*this)) | 305 target->intersectionObserverData()->getObservationFor(*this)) |
| 307 observation->disconnect(); | 306 observation->disconnect(); |
| 308 } | 307 } |
| 309 | 308 |
| 310 void IntersectionObserver::computeIntersectionObservations() { | 309 void IntersectionObserver::computeIntersectionObservations() { |
| 311 if (!rootIsValid()) | 310 if (!rootIsValid()) |
| 312 return; | 311 return; |
| 313 Document* callbackDocument = toDocument(m_callback->getExecutionContext()); | 312 LocalDOMWindow* callbackDOMWindow = |
| 314 if (!callbackDocument) | 313 toDocument(m_callback->getExecutionContext())->domWindow(); |
| 315 return; | |
| 316 LocalDOMWindow* callbackDOMWindow = callbackDocument->domWindow(); | |
| 317 if (!callbackDOMWindow) | 314 if (!callbackDOMWindow) |
| 318 return; | 315 return; |
| 319 DOMHighResTimeStamp timestamp = | 316 DOMHighResTimeStamp timestamp = |
| 320 DOMWindowPerformance::performance(*callbackDOMWindow)->now(); | 317 DOMWindowPerformance::performance(*callbackDOMWindow)->now(); |
| 321 for (auto& observation : m_observations) | 318 for (auto& observation : m_observations) |
| 322 observation->computeIntersectionObservations(timestamp); | 319 observation->computeIntersectionObservations(timestamp); |
| 323 } | 320 } |
| 324 | 321 |
| 325 void IntersectionObserver::disconnect(ExceptionState& exceptionState) { | 322 void IntersectionObserver::disconnect(ExceptionState& exceptionState) { |
| 326 if (!rootIsValid()) { | 323 if (!rootIsValid()) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 | 404 |
| 408 DEFINE_TRACE(IntersectionObserver) { | 405 DEFINE_TRACE(IntersectionObserver) { |
| 409 visitor->template registerWeakMembers< | 406 visitor->template registerWeakMembers< |
| 410 IntersectionObserver, &IntersectionObserver::clearWeakMembers>(this); | 407 IntersectionObserver, &IntersectionObserver::clearWeakMembers>(this); |
| 411 visitor->trace(m_callback); | 408 visitor->trace(m_callback); |
| 412 visitor->trace(m_observations); | 409 visitor->trace(m_observations); |
| 413 visitor->trace(m_entries); | 410 visitor->trace(m_entries); |
| 414 } | 411 } |
| 415 | 412 |
| 416 } // namespace blink | 413 } // namespace blink |
| OLD | NEW |