OLD | NEW |
---|---|
(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/ResizeObserverController.h" | |
6 | |
7 #include "core/observer/ResizeObserver.h" | |
8 | |
9 | |
10 namespace blink { | |
11 | |
12 ResizeObserverController::ResizeObserverController() | |
13 { | |
14 } | |
15 | |
16 void ResizeObserverController::addObserver(ResizeObserver& observer) | |
17 { | |
18 m_observers.add(&observer); | |
19 } | |
20 | |
21 bool ResizeObserverController::gatherObservations() | |
22 { | |
23 bool hasObservations = false; | |
24 for (auto& observer : m_observers) | |
25 hasObservations = hasObservations || observer->gatherObservations(); | |
szager1
2016/07/11 18:33:47
This will skip calling gatherObservations() if has
atotic1
2016/07/11 23:18:58
Good catch. I've reversed the operands, since |= c
| |
26 return hasObservations; | |
27 } | |
28 | |
29 void ResizeObserverController::deliverObservations() | |
30 { | |
31 // Copy is needed because m_observers might get modified during deliverObser vations. | |
32 ObserverSet observers; | |
szager1
2016/07/11 18:33:47
The idiomatic way to do this is:
HeapVector<Membe
atotic1
2016/07/11 23:18:58
Done. A question:
m_observers is a collection of W
szager1
2016/07/11 23:33:34
Correct: a GC can never happen during the executio
| |
33 for (auto it = m_observers.begin(); it != m_observers.end(); ++it) | |
34 observers.add(*it); | |
35 | |
36 for (auto& observer : observers) { | |
37 if (observer) | |
38 observer->deliverObservations(); | |
39 } | |
40 } | |
41 | |
42 void ResizeObserverController::clearObservations() | |
43 { | |
44 for (auto& observer : m_observers) | |
45 observer->clearObservations(); | |
46 } | |
47 | |
48 DEFINE_TRACE(ResizeObserverController) | |
49 { | |
50 visitor->trace(m_observers); | |
51 } | |
52 | |
53 } // namespace blink | |
OLD | NEW |