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

Unified Diff: Source/modules/screen_orientation/testing/ScreenOrientationClientMock.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/testing/ScreenOrientationClientMock.cpp
diff --git a/Source/modules/screen_orientation/testing/ScreenOrientationClientMock.cpp b/Source/modules/screen_orientation/testing/ScreenOrientationClientMock.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..48a0c1b08113e9d6bf141703ad13759e2a75a697
--- /dev/null
+++ b/Source/modules/screen_orientation/testing/ScreenOrientationClientMock.cpp
@@ -0,0 +1,91 @@
+// 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 "ScreenOrientationClientMock.h"
+
+#include "modules/screen_orientation/ScreenOrientationController.h"
+
+namespace WebCore {
+
+ScreenOrientationClientMock::ScreenOrientationClientMock()
+ : m_controllerTimer(this, &ScreenOrientationClientMock::controllerTimerFired)
+ , m_controller(0)
+ , m_orientation(OrientationPortraitPrimary)
+ , m_lockedOrientations(OrientationAny)
+{
+}
+
+ScreenOrientationClientMock::~ScreenOrientationClientMock()
+{
+}
+
+void ScreenOrientationClientMock::setController(ScreenOrientationController* controller)
+{
+ ASSERT(controller && !m_controller);
+ m_controller = controller;
+}
+
+void ScreenOrientationClientMock::setScreenOrientation(ScreenOrientationValue orientation)
+{
+ if (orientation == m_orientation)
+ return;
+
+ m_orientation = orientation;
+ if (m_lockedOrientations & orientation)
+ asyncUpdateController();
+}
+
+void ScreenOrientationClientMock::asyncUpdateController()
+{
+ ASSERT(m_controller);
+ if (!m_controllerTimer.isActive())
+ m_controllerTimer.startOneShot(0);
+}
+
+void ScreenOrientationClientMock::controllerTimerFired(Timer<ScreenOrientationClientMock>* timer)
+{
+ ASSERT_UNUSED(timer, timer == &m_controllerTimer);
+ ASSERT(m_controller);
+
+ m_controller->orientationChanged(m_orientation);
+}
+
+void ScreenOrientationClientMock::maybeUpdateOrientationAfterLocking()
+{
+ if (m_orientation & m_lockedOrientations)
+ return;
+
+ // We need to change our current screen orientation to meet the locking requirements.
+ ScreenOrientationValue supportedOrientationValues[] = {
+ OrientationPortraitPrimary,
+ OrientationLandscapePrimary,
+ OrientationPortraitSecondary,
+ OrientationLandscapeSecondary
+ };
+
+ for (unsigned i = 0; i < WTF_ARRAY_LENGTH(supportedOrientationValues); ++i) {
+ if (m_lockedOrientations & supportedOrientationValues[i]) {
+ m_orientation = supportedOrientationValues[i];
+ asyncUpdateController();
+ return;
+ }
+ }
+ ASSERT_NOT_REACHED();
+}
+
+void ScreenOrientationClientMock::lockOrientation(ScreenOrientationValues orientations)
+{
+ m_lockedOrientations = orientations;
+ maybeUpdateOrientationAfterLocking();
+}
+
+void ScreenOrientationClientMock::unlockOrientation()
+{
+ m_lockedOrientations = OrientationAny;
+ if (m_orientation != m_controller->orientation())
+ asyncUpdateController();
+}
+
+} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698