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

Side by Side Diff: third_party/WebKit/Source/core/observer/ResizeObserver.cpp

Issue 2005593002: Initial ResizeObserver implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months 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 2016 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 "core/observer/ResizeObserver.h"
6
7 #include "core/observer/ResizeObservation.h"
8 #include "core/observer/ResizeObserverCallback.h"
9 #include "core/observer/ResizeObserverController.h"
10
11 namespace blink {
12
13 ResizeObserver* ResizeObserver::create(Document& document, ResizeObserverCallbac k* callback)
14 {
15 auto observer = new ResizeObserver(callback);
16 document.ensureResizeObserverController().addObserver(*observer);
17 return observer;
18 }
19
20 ResizeObserver::ResizeObserver(ResizeObserverCallback* callback)
21 : m_callback(callback)
22 {
23 }
24
25 bool compareObservationToElement(Member<blink::ResizeObservation> observation, E lement* el)
szager1 2016/05/23 19:49:11 This isn't used.
atotic1 2016/05/25 00:15:53 Done.
26 {
27 return observation->target() == el;
28 }
szager1 2016/05/23 19:49:11 Add blank line.
atotic1 2016/05/25 00:15:53 Done.
29 bool operator==(Member<blink::ResizeObservation> observation, Element* el)
szager1 2016/05/23 19:49:11 meh, this is obfuscating. Just use (observation->
atotic1 2016/05/25 00:15:53 Leftover from when I was using the std::find algor
30 {
31 return observation->target() == el;
32 }
33
34 void ResizeObserver::observe(Element* target)
35 {
36 if (target && m_observations.find(target) == kNotFound)
szager1 2016/05/23 19:49:11 This is why, for IntersectionObserver, I did this:
atotic1 2016/05/25 00:15:53 Done. I was not optimizing this case because we t
37 m_observations.append(new ResizeObservation(target, this));
38 }
39
40 void ResizeObserver::unobserve(Element* target)
41 {
42 auto pos = m_observations.find(target);
43 if (pos != kNotFound)
44 m_observations.remove(pos);
45 }
46
47 void ResizeObserver::disconnect()
48 {
49 m_observations.clear();
50 m_activeObservations.clear();
szager1 2016/05/23 19:49:11 Also: m_callback.clear();
atotic1 2016/05/25 00:15:53 That'd violate the spec, because no elements could
51 }
52
53 void ResizeObserver::gatherObservations()
54 {
55 m_activeObservations.clear();
szager1 2016/05/23 19:49:11 This should be either ASSERT(m_activeObservations-
atotic1 2016/05/25 00:15:53 ??? m_activeObservations->clear() does not compile
szager1 2016/06/02 20:52:40 It should never happen that gatherObservations() i
56
57 for (auto observation : m_observations) {
szager1 2016/05/23 19:49:11 I'm not sure if it makes a difference, but maybe i
atotic1 2016/05/25 00:15:53 auto& means you can't have a null. Done.
58 if (observation->hasResized())
59 m_activeObservations.append(*observation);
60 }
61 }
62
63 void ResizeObserver::deliverObservations()
64 {
65 if (m_activeObservations.size() == 0)
66 return;
67
68 HeapVector<Member<ResizeObserverEntry>> entries;
69
70 for (size_t i = 0; i < m_activeObservations.size(); i++) {
szager1 2016/05/23 19:49:11 for (auto& observation : m_activeObservations)
atotic1 2016/05/25 00:15:53 Done.
71 auto observation = m_activeObservations.at(i);
72 auto entry = new ResizeObserverEntry(observation->target());
73 entries.append(entry);
74 observation->setBroadcastSize(entry->clientWidth(), entry->clientHeight( ));
75 }
76 m_callback->handleEvent(entries, this);
szager1 2016/05/23 19:49:11 m_activeObservations->clear();
atotic1 2016/05/25 00:15:53 Done.
77 }
78
79 ResizeObserver::ObservationList::iterator ResizeObserver::find(Element* target)
80 {
81 for (ObservationList::iterator it = m_observations.begin(); it != m_observat ions.end(); ++it) {
82 if ((*it)->target() == target)
83 return it;
84 }
85
86 return m_observations.end();
87 }
88
89 DEFINE_TRACE(ResizeObserver)
90 {
91 visitor->trace(m_callback);
92 visitor->trace(m_observations);
93 visitor->trace(m_activeObservations);
94 }
95
96 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698