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

Unified Diff: Source/modules/screen_orientation/ScreenOrientationController.cpp

Issue 132113006: Add initial Blink-side support for the Screen Orientation API (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Update compile-time assertion for matching enum Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698