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

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

Issue 171683015: Screen Orientation API: Add support for lockOrientation() / unlockOrientation() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase 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
« no previous file with comments | « Source/modules/screen_orientation/ScreenOrientation.h ('k') | public/platform/Platform.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/screen_orientation/ScreenOrientation.cpp
diff --git a/Source/modules/screen_orientation/ScreenOrientation.cpp b/Source/modules/screen_orientation/ScreenOrientation.cpp
index df4563a66cba3d71bd42dfde204ff9ef6bf59954..6aecb49853b2d6dcc3df87d9840f6194e7f8664f 100644
--- a/Source/modules/screen_orientation/ScreenOrientation.cpp
+++ b/Source/modules/screen_orientation/ScreenOrientation.cpp
@@ -9,10 +9,12 @@
#include "core/frame/Frame.h"
#include "core/frame/Screen.h"
#include "modules/screen_orientation/ScreenOrientationController.h"
-#include "public/platform/WebScreenOrientation.h"
+#include "public/platform/Platform.h"
namespace WebCore {
+static const unsigned WebScreenOrientationDefault = 0;
+
struct ScreenOrientationInfo {
const AtomicString& name;
blink::WebScreenOrientation orientation;
@@ -49,9 +51,47 @@ static const AtomicString& orientationToString(blink::WebScreenOrientation orien
return nullAtom;
}
+static blink::WebScreenOrientations stringToOrientations(const AtomicString& orientationString)
+{
+ DEFINE_STATIC_LOCAL(const AtomicString, portrait, ("portrait", AtomicString::ConstructFromLiteral));
+ DEFINE_STATIC_LOCAL(const AtomicString, landscape, ("landscape", AtomicString::ConstructFromLiteral));
+
+ if (orientationString == portrait)
+ return blink::WebScreenOrientationPortraitPrimary | blink::WebScreenOrientationPortraitSecondary;
+ if (orientationString == landscape)
+ return blink::WebScreenOrientationLandscapePrimary | blink::WebScreenOrientationLandscapeSecondary;
+
+ unsigned length = 0;
+ ScreenOrientationInfo* orientationMap = orientationsMap(length);
+ for (unsigned i = 0; i < length; ++i) {
+ if (orientationMap[i].name == orientationString)
+ return orientationMap[i].orientation;
+ }
+ return 0;
+}
+
ScreenOrientation::ScreenOrientation(Screen& screen)
: DOMWindowProperty(screen.frame())
+ , m_orientationLockTimer(this, &ScreenOrientation::orientationLockTimerFired)
+ , m_lockedOrientations(WebScreenOrientationDefault)
+{
+}
+
+void ScreenOrientation::lockOrientationAsync(blink::WebScreenOrientations orientations)
{
+ if (m_lockedOrientations == orientations)
+ return;
+ m_lockedOrientations = orientations;
+ if (!m_orientationLockTimer.isActive())
+ m_orientationLockTimer.startOneShot(0);
+}
+
+void ScreenOrientation::orientationLockTimerFired(Timer<ScreenOrientation>*)
+{
+ if (m_lockedOrientations == WebScreenOrientationDefault)
+ blink::Platform::current()->unlockOrientation();
+ else
+ blink::Platform::current()->lockOrientation(m_lockedOrientations);
}
const char* ScreenOrientation::supplementName()
@@ -87,21 +127,33 @@ const AtomicString& ScreenOrientation::orientation(Screen& screen)
return orientationToString(controller.orientation());
}
-bool ScreenOrientation::lockOrientation(Screen& screen, const Vector<String>& orientations)
+bool ScreenOrientation::lockOrientation(Screen& screen, const Vector<String>& orientationsVector)
{
- // FIXME: Implement.
- return false;
+ blink::WebScreenOrientations orientations = 0;
+ for (size_t i = 0; i < orientationsVector.size(); ++i) {
+ blink::WebScreenOrientations currentOrientation = stringToOrientations(AtomicString(orientationsVector[i]));
+ if (!currentOrientation)
+ return false;
+ orientations |= currentOrientation;
+ }
+ if (!orientations)
+ return false;
+ ScreenOrientation::from(screen).lockOrientationAsync(orientations);
+ return true;
}
-bool ScreenOrientation::lockOrientation(Screen& screen, const AtomicString& orientation)
+bool ScreenOrientation::lockOrientation(Screen& screen, const AtomicString& orientationString)
{
- // FIXME: Implement.
- return false;
+ blink::WebScreenOrientations orientations = stringToOrientations(orientationString);
+ if (!orientations)
+ return false;
+ ScreenOrientation::from(screen).lockOrientationAsync(orientations);
+ return true;
}
void ScreenOrientation::unlockOrientation(Screen& screen)
{
- // FIXME: Implement.
+ ScreenOrientation::from(screen).lockOrientationAsync(WebScreenOrientationDefault);
}
} // namespace WebCore
« no previous file with comments | « Source/modules/screen_orientation/ScreenOrientation.h ('k') | public/platform/Platform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698