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/ElementVisibilityObserver.h" | 5 #include "core/dom/ElementVisibilityObserver.h" |
6 | 6 |
7 #include "core/dom/Element.h" | 7 #include "core/dom/Element.h" |
8 #include "core/dom/IntersectionObserverEntry.h" | 8 #include "core/dom/IntersectionObserverEntry.h" |
9 #include "core/frame/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
10 #include "wtf/Functional.h" | 10 #include "wtf/Functional.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 &m_element->document(), | 41 &m_element->document(), |
42 WTF::bind(&ElementVisibilityObserver::onVisibilityChanged, | 42 WTF::bind(&ElementVisibilityObserver::onVisibilityChanged, |
43 wrapWeakPersistent(this))); | 43 wrapWeakPersistent(this))); |
44 DCHECK(m_intersectionObserver); | 44 DCHECK(m_intersectionObserver); |
45 m_intersectionObserver->observe(m_element.release()); | 45 m_intersectionObserver->observe(m_element.release()); |
46 } | 46 } |
47 | 47 |
48 void ElementVisibilityObserver::stop() { | 48 void ElementVisibilityObserver::stop() { |
49 // TODO(zqzhang): IntersectionObserver does not work for RemoteFrame, | 49 // TODO(zqzhang): IntersectionObserver does not work for RemoteFrame, |
50 // so |m_intersectionObserver| may be null at this point after start(). | 50 // so |m_intersectionObserver| may be null at this point after start(). |
51 // Replace this early return with DCHECK when this has been fixed. See https:/
/crbug.com/615156 | 51 // Replace this early return with DCHECK when this has been fixed. See |
| 52 // https://crbug.com/615156 |
52 if (!m_intersectionObserver) | 53 if (!m_intersectionObserver) |
53 return; | 54 return; |
54 | 55 |
55 m_intersectionObserver->disconnect(); | 56 m_intersectionObserver->disconnect(); |
56 m_intersectionObserver = nullptr; | 57 m_intersectionObserver = nullptr; |
57 } | 58 } |
58 | 59 |
59 DEFINE_TRACE(ElementVisibilityObserver) { | 60 DEFINE_TRACE(ElementVisibilityObserver) { |
60 visitor->trace(m_element); | 61 visitor->trace(m_element); |
61 visitor->trace(m_intersectionObserver); | 62 visitor->trace(m_intersectionObserver); |
62 } | 63 } |
63 | 64 |
64 void ElementVisibilityObserver::onVisibilityChanged( | 65 void ElementVisibilityObserver::onVisibilityChanged( |
65 const HeapVector<Member<IntersectionObserverEntry>>& entries) { | 66 const HeapVector<Member<IntersectionObserverEntry>>& entries) { |
66 bool isVisible = entries.last()->intersectionRatio() > 0.f; | 67 bool isVisible = entries.last()->intersectionRatio() > 0.f; |
67 (*m_callback.get())(isVisible); | 68 (*m_callback.get())(isVisible); |
68 } | 69 } |
69 | 70 |
70 } // namespace blink | 71 } // namespace blink |
OLD | NEW |