Chromium Code Reviews| Index: third_party/WebKit/Source/core/observer/ResizeObserverController.cpp |
| diff --git a/third_party/WebKit/Source/core/observer/ResizeObserverController.cpp b/third_party/WebKit/Source/core/observer/ResizeObserverController.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b7bccedc07f4a0d9dc5a5c6bfd27d24827bacf72 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/observer/ResizeObserverController.cpp |
| @@ -0,0 +1,53 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "core/observer/ResizeObserverController.h" |
| + |
| +#include "core/observer/ResizeObserver.h" |
| + |
| + |
| +namespace blink { |
| + |
| +ResizeObserverController::ResizeObserverController() |
| +{ |
| +} |
| + |
| +void ResizeObserverController::addObserver(ResizeObserver& observer) |
| +{ |
| + m_observers.add(&observer); |
| +} |
| + |
| +bool ResizeObserverController::gatherObservations() |
| +{ |
| + bool hasObservations = false; |
| + for (auto& observer : m_observers) |
| + 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
|
| + return hasObservations; |
| +} |
| + |
| +void ResizeObserverController::deliverObservations() |
| +{ |
| + // Copy is needed because m_observers might get modified during deliverObservations. |
| + 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
|
| + for (auto it = m_observers.begin(); it != m_observers.end(); ++it) |
| + observers.add(*it); |
| + |
| + for (auto& observer : observers) { |
| + if (observer) |
| + observer->deliverObservations(); |
| + } |
| +} |
| + |
| +void ResizeObserverController::clearObservations() |
| +{ |
| + for (auto& observer : m_observers) |
| + observer->clearObservations(); |
| +} |
| + |
| +DEFINE_TRACE(ResizeObserverController) |
| +{ |
| + visitor->trace(m_observers); |
| +} |
| + |
| +} // namespace blink |