Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(573)

Side by Side Diff: third_party/WebKit/Source/core/dom/IntersectionObservationRegistry.cpp

Issue 1449623002: IntersectionObserver: second cut. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Clarify the tear-down path for observers and observations. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/IntersectionObservationRegistry.h"
7
8 #include "core/dom/Document.h"
9
10 namespace blink {
11
12 typedef WillBeHeapVector<RefPtrWillBeMember<IntersectionObserver>> IntersectionO bserverVector;
13
14 IntersectionObservationRegistry::IntersectionObservationRegistry(Timer<Document> & timer)
15 : m_timer(timer)
16 {
17 }
18
19 IntersectionObservationRegistry::~IntersectionObservationRegistry()
20 {
21 resumeSuspendedIntersectionObservers();
22 deliverIntersectionObservations();
23 ASSERT(!m_suspendedIntersectionObservers.size());
24 }
25
26
27 void IntersectionObservationRegistry::activateIntersectionObserver(IntersectionO bserver& observer)
28 {
29 if (m_activeIntersectionObservers.isEmpty())
30 m_timer.startOneShot(0, BLINK_FROM_HERE);
31 m_activeIntersectionObservers.add(&observer);
32 }
33
34 void IntersectionObservationRegistry::resumeSuspendedIntersectionObservers()
35 {
36 ASSERT(isMainThread());
37 if (m_suspendedIntersectionObservers.isEmpty())
38 return;
39
40 IntersectionObserverVector suspended;
41 copyToVector(m_suspendedIntersectionObservers, suspended);
42 for (size_t i = 0; i < suspended.size(); ++i) {
43 if (!suspended[i]->shouldBeSuspended()) {
44 m_suspendedIntersectionObservers.remove(suspended[i]);
45 activateIntersectionObserver(*suspended[i]);
46 }
47 }
48 }
49
50 void IntersectionObservationRegistry::deliverIntersectionObservations()
51 {
52 IntersectionObserverVector observers;
53 copyToVector(m_activeIntersectionObservers, observers);
54 m_activeIntersectionObservers.clear();
55 for (size_t i = 0; i < observers.size(); ++i) {
56 if (observers[i]->shouldBeSuspended())
57 m_suspendedIntersectionObservers.add(observers[i]);
58 else
59 observers[i]->deliver();
60 }
61 }
62
63 void IntersectionObservationRegistry::computeIntersectionObservations()
64 {
65 // TODO: Need to define timestamp.
66 double timestamp = currentTime();
67 for (auto& observation: m_intersectionObservations) {
68 ASSERT(observation->target()->isInTreeScope());
69 observation->computeIntersectionObservations(timestamp);
70 }
71 }
72
73 void IntersectionObservationRegistry::addObservation(IntersectionObservation& ob servation)
74 {
75 m_intersectionObservations.add(adoptRef(&observation));
haraken 2015/11/16 00:41:34 adoptRefWillBeNoop ? Otherwise, it won't compile w
szager1 2015/11/19 19:15:38 Fixed in next patch (either with adoptRefWillBeNoo
76 }
77
78 void IntersectionObservationRegistry::removeObservation(IntersectionObservation& observation)
79 {
80 m_intersectionObservations.remove(adoptRef(&observation));
81 }
82
83 } // namespace blink {
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698