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

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: Add Kenneth as OWNER 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..b56f183975a99bdce9d48cd948b11eb95b3d9509
--- /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())
kenneth.r.christiansen 2014/02/12 13:42:37 maybe for the mock this doesnt have to be async?
Inactive 2014/02/12 16:03:11 Hmm, I did this because calling setScreenOrientati
+ 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.
+ DEFINE_STATIC_LOCAL(Vector<ScreenOrientationValue>, supportedOrientationValues, ());
+ if (supportedOrientationValues.isEmpty()) {
+ supportedOrientationValues.append(OrientationPortraitPrimary);
+ supportedOrientationValues.append(OrientationLandscapePrimary);
+ supportedOrientationValues.append(OrientationPortraitSecondary);
+ supportedOrientationValues.append(OrientationLandscapeSecondary);
+ }
+ for (unsigned i = 0; i < supportedOrientationValues.size(); ++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