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/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
11 #include "core/dom/ExecutionContext.h" | 11 #include "core/dom/ExecutionContext.h" |
12 #include "core/dom/IntersectionObserverCallback.h" | 12 #include "core/dom/IntersectionObserverCallback.h" |
13 #include "core/dom/IntersectionObserverController.h" | 13 #include "core/dom/IntersectionObserverController.h" |
14 #include "core/dom/IntersectionObserverEntry.h" | 14 #include "core/dom/IntersectionObserverEntry.h" |
15 #include "core/dom/IntersectionObserverInit.h" | 15 #include "core/dom/IntersectionObserverInit.h" |
16 #include "core/dom/NodeIntersectionObserverData.h" | 16 #include "core/dom/NodeIntersectionObserverData.h" |
17 #include "core/html/HTMLFrameOwnerElement.h" | 17 #include "core/html/HTMLFrameOwnerElement.h" |
18 #include "core/layout/LayoutView.h" | 18 #include "core/layout/LayoutView.h" |
| 19 #include "core/timing/DOMWindowPerformance.h" |
| 20 #include "core/timing/Performance.h" |
19 #include "platform/Timer.h" | 21 #include "platform/Timer.h" |
20 #include "wtf/MainThread.h" | 22 #include "wtf/MainThread.h" |
21 #include <algorithm> | 23 #include <algorithm> |
22 | 24 |
23 namespace blink { | 25 namespace blink { |
24 | 26 |
25 static void parseRootMargin(String rootMarginParameter, Vector<Length>& rootMarg
in, ExceptionState& exceptionState) | 27 static void parseRootMargin(String rootMarginParameter, Vector<Length>& rootMarg
in, ExceptionState& exceptionState) |
26 { | 28 { |
27 // TODO(szager): Make sure this exact syntax and behavior is spec-ed somewhe
re. | 29 // TODO(szager): Make sure this exact syntax and behavior is spec-ed somewhe
re. |
28 | 30 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 232 |
231 void IntersectionObserver::unobserve(Element* target, ExceptionState&) | 233 void IntersectionObserver::unobserve(Element* target, ExceptionState&) |
232 { | 234 { |
233 if (!target || !target->intersectionObserverData()) | 235 if (!target || !target->intersectionObserverData()) |
234 return; | 236 return; |
235 // TODO(szager): unobserve callback | 237 // TODO(szager): unobserve callback |
236 if (IntersectionObservation* observation = target->intersectionObserverData(
)->getObservationFor(*this)) | 238 if (IntersectionObservation* observation = target->intersectionObserverData(
)->getObservationFor(*this)) |
237 observation->disconnect(); | 239 observation->disconnect(); |
238 } | 240 } |
239 | 241 |
240 void IntersectionObserver::computeIntersectionObservations(double timestamp) | 242 void IntersectionObserver::computeIntersectionObservations() |
241 { | 243 { |
242 if (!m_root) | 244 if (!m_root) |
243 return; | 245 return; |
| 246 Document* callbackDocument = toDocument(m_callback->executionContext()); |
| 247 if (!callbackDocument) |
| 248 return; |
| 249 LocalDOMWindow* callbackDOMWindow = callbackDocument->domWindow(); |
| 250 if (!callbackDOMWindow) |
| 251 return; |
| 252 DOMHighResTimeStamp timestamp = DOMWindowPerformance::performance(*callbackD
OMWindow)->now(); |
244 for (auto& observation : m_observations) | 253 for (auto& observation : m_observations) |
245 observation->computeIntersectionObservations(timestamp); | 254 observation->computeIntersectionObservations(timestamp); |
246 } | 255 } |
247 | 256 |
248 void IntersectionObserver::disconnect() | 257 void IntersectionObserver::disconnect() |
249 { | 258 { |
250 for (auto& observation : m_observations) | 259 for (auto& observation : m_observations) |
251 observation->clearRootAndRemoveFromTarget(); | 260 observation->clearRootAndRemoveFromTarget(); |
252 m_observations.clear(); | 261 m_observations.clear(); |
253 } | 262 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 { | 339 { |
331 #if ENABLE(OILPAN) | 340 #if ENABLE(OILPAN) |
332 visitor->template registerWeakMembers<IntersectionObserver, &IntersectionObs
erver::clearWeakMembers>(this); | 341 visitor->template registerWeakMembers<IntersectionObserver, &IntersectionObs
erver::clearWeakMembers>(this); |
333 #endif | 342 #endif |
334 visitor->trace(m_callback); | 343 visitor->trace(m_callback); |
335 visitor->trace(m_observations); | 344 visitor->trace(m_observations); |
336 visitor->trace(m_entries); | 345 visitor->trace(m_entries); |
337 } | 346 } |
338 | 347 |
339 } // namespace blink | 348 } // namespace blink |
OLD | NEW |