Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "core/dom/IntersectionObserver.h" | |
| 7 | |
| 8 #include "bindings/core/v8/ExceptionState.h" | |
| 9 #include "core/dom/Document.h" | |
| 10 #include "core/dom/ExceptionCode.h" | |
| 11 #include "core/dom/ExecutionContext.h" | |
| 12 #include "core/dom/IntersectionObserverCallback.h" | |
| 13 #include "core/dom/IntersectionObserverEntry.h" | |
| 14 #include "core/dom/IntersectionObserverInit.h" | |
| 15 #include "platform/Timer.h" | |
| 16 #include "wtf/MainThread.h" | |
| 17 #include <algorithm> | |
| 18 | |
| 19 namespace blink { | |
| 20 | |
| 21 PassRefPtrWillBeRawPtr<IntersectionObserver> IntersectionObserver::create(Docume nt* document, PassOwnPtrWillBeRawPtr<IntersectionObserverCallback> callback) | |
| 22 { | |
| 23 ASSERT(isMainThread()); | |
| 24 return adoptRefWillBeNoop(new IntersectionObserver(document, callback)); | |
| 25 } | |
| 26 | |
| 27 IntersectionObserver::IntersectionObserver(Document* document, PassOwnPtrWillBeR awPtr<IntersectionObserverCallback> callback) | |
| 28 : m_callback(callback) | |
| 29 , m_document(document) | |
| 30 { | |
| 31 } | |
| 32 | |
| 33 IntersectionObserver::~IntersectionObserver() | |
| 34 { | |
| 35 } | |
| 36 | |
| 37 void IntersectionObserver::observe(Element* target, const IntersectionObserverIn it& observerInit, ExceptionState& exceptionState) | |
| 38 { | |
| 39 if (!m_document) { | |
| 40 exceptionState.throwTypeError("Window may be destroyed? Document is inva lid."); | |
| 41 return; | |
| 42 } | |
| 43 if (!target) { | |
| 44 exceptionState.throwTypeError("Invalid observation target (null)."); | |
| 45 return; | |
| 46 } | |
| 47 | |
| 48 target->registerIntersectionObserver(this); | |
| 49 m_targets.append(target); | |
| 50 } | |
| 51 | |
| 52 void IntersectionObserver::disconnect() | |
| 53 { | |
| 54 m_entries.clear(); | |
| 55 for (auto target : m_targets) { | |
| 56 if (target) | |
|
ojan
2015/09/21 03:49:09
How can target be null?
MikeB
2015/09/24 19:04:03
RefPtrWillBeWeakMember will become WeakMember when
| |
| 57 target->unregisterIntersectionObserver(this); | |
| 58 } | |
| 59 m_targets.clear(); | |
| 60 } | |
| 61 | |
| 62 IntersectionObserverEntryVector IntersectionObserver::takeRecords() | |
| 63 { | |
| 64 IntersectionObserverEntryVector entries; | |
| 65 entries.swap(m_entries); | |
| 66 return entries; | |
| 67 } | |
| 68 | |
| 69 void IntersectionObserver::enqueueIntersectionObserverEntry(PassRefPtrWillBeRawP tr<IntersectionObserverEntry> entry) | |
| 70 { | |
| 71 ASSERT(isMainThread()); | |
| 72 m_entries.append(entry); | |
| 73 if (m_document) | |
| 74 m_document->activateIntersectionObserver(*this); | |
| 75 } | |
| 76 | |
| 77 bool IntersectionObserver::shouldBeSuspended() const | |
|
ojan
2015/09/21 03:49:09
I see that MutationObservers are also ActiveDOMObj
| |
| 78 { | |
| 79 return m_callback->executionContext() && m_callback->executionContext()->act iveDOMObjectsAreSuspended(); | |
| 80 } | |
| 81 | |
| 82 void IntersectionObserver::deliver() | |
| 83 { | |
| 84 ASSERT(!shouldBeSuspended()); | |
| 85 | |
| 86 if (m_entries.isEmpty()) | |
| 87 return; | |
| 88 | |
| 89 IntersectionObserverEntryVector entries; | |
| 90 entries.swap(m_entries); | |
| 91 m_callback->handleEvent(entries, this); | |
| 92 } | |
| 93 | |
| 94 DEFINE_TRACE(IntersectionObserver) | |
| 95 { | |
| 96 visitor->trace(m_callback); | |
| 97 visitor->trace(m_document); | |
| 98 visitor->trace(m_entries); | |
| 99 visitor->trace(m_targets); | |
| 100 } | |
| 101 | |
| 102 } // namespace blink | |
| OLD | NEW |