Chromium Code Reviews| Index: Source/modules/screen_orientation/ScreenOrientationController.cpp |
| diff --git a/Source/modules/screen_orientation/ScreenOrientationController.cpp b/Source/modules/screen_orientation/ScreenOrientationController.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c0bc087824e06b47bc71560def08563e99164ac6 |
| --- /dev/null |
| +++ b/Source/modules/screen_orientation/ScreenOrientationController.cpp |
| @@ -0,0 +1,63 @@ |
| +// Copyright 2014 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 "config.h" |
| +#include "modules/screen_orientation/ScreenOrientationController.h" |
| + |
| +#include "core/page/Page.h" |
| + |
| +namespace WebCore { |
| + |
| +PassOwnPtr<ScreenOrientationController> ScreenOrientationController::create() |
| +{ |
| + return adoptPtr(new ScreenOrientationController()); |
| +} |
| + |
| +ScreenOrientationController::~ScreenOrientationController() |
| +{ |
| +} |
|
abarth-chromium
2014/02/18 01:34:27
Please ASSERT(m_observers.isEmpty()) here.
Inactive
2014/02/18 20:52:47
observers are now in the Dispatcher class, which i
|
| + |
| +void ScreenOrientationController::addObserver(ScreenOrientation* observer) |
| +{ |
| + m_observers.add(observer); |
| +} |
| + |
| +void ScreenOrientationController::removeObserver(ScreenOrientation* observer) |
| +{ |
| + m_observers.remove(observer); |
| +} |
| + |
| +const char* ScreenOrientationController::supplementName() |
| +{ |
| + return "ScreenOrientationController"; |
| +} |
| + |
| +ScreenOrientationController::ScreenOrientationController() |
| + // FIXME: This orientation is not necessary the right one until the first orientationchange |
| + // event is fired. |
| + : m_orientation(OrientationPortraitPrimary) |
| +{ |
| +} |
| + |
| +ScreenOrientationController* ScreenOrientationController::from(Page* page) |
| +{ |
| + return static_cast<ScreenOrientationController*>(Supplement<Page>::from(page, supplementName())); |
| +} |
| + |
| +void ScreenOrientationController::orientationChanged(ScreenOrientationValue orientation) |
| +{ |
| + if (m_orientation == orientation) |
| + return; |
| + |
| + m_orientation = orientation; |
| + for (ObserversSet::iterator it = m_observers.begin(); it != m_observers.end(); ++it) |
| + (*it)->orientationChanged(); |
|
abarth-chromium
2014/02/18 01:34:27
This is a weak iteration pattern. What if m_obser
Inactive
2014/02/18 20:52:47
Done, used the same code as DeviceOrientation.
|
| +} |
| + |
| +void provideScreenOrientationTo(Page* page) |
| +{ |
| + ScreenOrientationController::provideTo(page, ScreenOrientationController::supplementName(), ScreenOrientationController::create()); |
| +} |
| + |
| +} // namespace WebCore |