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..03e0b58aac6fa972d89241fcc006ec804195c6f2 |
--- /dev/null |
+++ b/Source/modules/screen_orientation/ScreenOrientationController.cpp |
@@ -0,0 +1,77 @@ |
+// 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 "ScreenOrientationController.h" |
+ |
+#include "modules/screen_orientation/ScreenOrientationClient.h" |
+ |
+namespace WebCore { |
+ |
+ScreenOrientationController::ScreenOrientationController(ScreenOrientationClient* client) |
+ : m_client(client) |
+ // FIXME: This orientation is not necessary the right one until the first orientationchange |
+ // event is fired. |
+ , m_orientation(OrientationPortraitPrimary) |
+ , m_hasClientForTest(false) |
+{ |
+} |
+ |
+ScreenOrientationController::~ScreenOrientationController() |
+{ |
+ if (m_hasClientForTest) |
+ delete m_client; |
+} |
+ |
+PassOwnPtr<ScreenOrientationController> ScreenOrientationController::create(ScreenOrientationClient* client) |
+{ |
+ return adoptPtr(new ScreenOrientationController(client)); |
+} |
+ |
+void ScreenOrientationController::addObserver(ScreenOrientation* observer) |
+{ |
+ m_observers.add(observer); |
+} |
+ |
+void ScreenOrientationController::removeObserver(ScreenOrientation* observer) |
+{ |
+ m_observers.remove(observer); |
+} |
+ |
+const char* ScreenOrientationController::supplementName() |
+{ |
+ return "ScreenOrientationController"; |
+} |
+ |
+ScreenOrientationClient* ScreenOrientationController::clientFrom(Page* page) |
+{ |
+ if (ScreenOrientationController* controller = ScreenOrientationController::from(page)) |
+ return controller->client(); |
+ return 0; |
+} |
+ |
+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(); |
+} |
+ |
+void ScreenOrientationController::setClientForTest(ScreenOrientationClient* client) |
+{ |
+ if (m_hasClientForTest) |
+ delete m_client; |
+ m_client = client; |
+ m_hasClientForTest = true; |
+} |
+ |
+void provideScreenOrientation(Page* page, ScreenOrientationClient* client) |
+{ |
+ ScreenOrientationController::provideTo(page, ScreenOrientationController::supplementName(), ScreenOrientationController::create(client)); |
+} |
+ |
+} // namespace WebCore |