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

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

Issue 219463003: Screen Orientation API: cleanup, simplify and fix implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 9 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/ScreenOrientation.cpp
diff --git a/Source/modules/screen_orientation/ScreenOrientation.cpp b/Source/modules/screen_orientation/ScreenOrientation.cpp
index 51c609a4e5f5bc9e4251695415cd0473b18db431..e80aa71d92d5a77be94a3df2c407dc038fa208f1 100644
--- a/Source/modules/screen_orientation/ScreenOrientation.cpp
+++ b/Source/modules/screen_orientation/ScreenOrientation.cpp
@@ -10,14 +10,13 @@
#include "core/frame/Screen.h"
#include "modules/screen_orientation/ScreenOrientationController.h"
#include "public/platform/Platform.h"
+#include "public/platform/WebScreenOrientationType.h"
namespace WebCore {
-static const unsigned WebScreenOrientationDefault = 0;
-
struct ScreenOrientationInfo {
const AtomicString& name;
- blink::WebScreenOrientation orientation;
+ char orientation;
Inactive 2014/03/31 18:52:36 Any reason we are not using a WebScreenOrientation
mlamouri (slow - plz ping) 2014/03/31 19:45:35 I could put WebScreenOrientationLockType but it wo
};
static ScreenOrientationInfo* orientationsMap(unsigned& length)
@@ -26,77 +25,74 @@ static ScreenOrientationInfo* orientationsMap(unsigned& length)
DEFINE_STATIC_LOCAL(const AtomicString, portraitSecondary, ("portrait-secondary", AtomicString::ConstructFromLiteral));
DEFINE_STATIC_LOCAL(const AtomicString, landscapePrimary, ("landscape-primary", AtomicString::ConstructFromLiteral));
DEFINE_STATIC_LOCAL(const AtomicString, landscapeSecondary, ("landscape-secondary", AtomicString::ConstructFromLiteral));
+ DEFINE_STATIC_LOCAL(const AtomicString, any, ("any", AtomicString::ConstructFromLiteral));
+ DEFINE_STATIC_LOCAL(const AtomicString, portrait, ("portrait", AtomicString::ConstructFromLiteral));
+ DEFINE_STATIC_LOCAL(const AtomicString, landscape, ("landscape", AtomicString::ConstructFromLiteral));
static ScreenOrientationInfo orientationMap[] = {
- { portraitPrimary, blink::WebScreenOrientationPortraitPrimary },
- { portraitSecondary, blink::WebScreenOrientationPortraitSecondary },
- { landscapePrimary, blink::WebScreenOrientationLandscapePrimary },
- { landscapeSecondary, blink::WebScreenOrientationLandscapeSecondary }
+ { portraitPrimary, blink::WebScreenOrientationLockPortraitPrimary },
+ { portraitSecondary, blink::WebScreenOrientationLockPortraitSecondary },
+ { landscapePrimary, blink::WebScreenOrientationLockLandscapePrimary },
+ { landscapeSecondary, blink::WebScreenOrientationLockLandscapeSecondary },
+ { any, blink::WebScreenOrientationLockAny },
+ { portrait, blink::WebScreenOrientationLockPortrait },
+ { landscape, blink::WebScreenOrientationLockLandscape }
};
length = WTF_ARRAY_LENGTH(orientationMap);
+
return orientationMap;
}
-static const AtomicString& orientationToString(blink::WebScreenOrientation orientation)
+static const AtomicString& orientationTypeToString(blink::WebScreenOrientationType orientation)
{
unsigned length = 0;
ScreenOrientationInfo* orientationMap = orientationsMap(length);
for (unsigned i = 0; i < length; ++i) {
- if (orientationMap[i].orientation == orientation)
+ if (static_cast<blink::WebScreenOrientationType>(orientationMap[i].orientation) == orientation)
Inactive 2014/03/31 18:52:36 So we rely on the values shared by WebScreenOrient
mlamouri (slow - plz ping) 2014/03/31 19:45:35 Argh. I meant to add compile time checks but I for
return orientationMap[i].name;
}
+
// We do no handle OrientationInvalid and OrientationAny but this is fine because screen.orientation
// should never return these and WebScreenOrientation does not define those values.
ASSERT_NOT_REACHED();
return nullAtom;
}
-static blink::WebScreenOrientations stringToOrientations(const AtomicString& orientationString)
+static blink::WebScreenOrientationLockType stringToOrientationLock(const AtomicString& orientationLockString)
{
- DEFINE_STATIC_LOCAL(const AtomicString, any, ("any", AtomicString::ConstructFromLiteral));
- DEFINE_STATIC_LOCAL(const AtomicString, portrait, ("portrait", AtomicString::ConstructFromLiteral));
- DEFINE_STATIC_LOCAL(const AtomicString, landscape, ("landscape", AtomicString::ConstructFromLiteral));
-
- if (orientationString == any) {
- return blink::WebScreenOrientationPortraitPrimary | blink::WebScreenOrientationPortraitSecondary |
- blink::WebScreenOrientationLandscapePrimary | blink::WebScreenOrientationLandscapeSecondary;
- }
- 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;
+ if (orientationMap[i].name == orientationLockString)
+ return static_cast<blink::WebScreenOrientationLockType>(orientationMap[i].orientation);
}
- return 0;
+
+ ASSERT_NOT_REACHED();
+ return blink::WebScreenOrientationLockDefault;
}
ScreenOrientation::ScreenOrientation(Screen& screen)
: DOMWindowProperty(screen.frame())
, m_orientationLockTimer(this, &ScreenOrientation::orientationLockTimerFired)
- , m_lockedOrientations(WebScreenOrientationDefault)
+ , m_prospectiveLock(blink::WebScreenOrientationLockDefault)
{
}
-void ScreenOrientation::lockOrientationAsync(blink::WebScreenOrientations orientations)
+void ScreenOrientation::lockOrientationAsync(blink::WebScreenOrientationLockType orientation)
{
- if (m_lockedOrientations == orientations)
- return;
- m_lockedOrientations = orientations;
- if (!m_orientationLockTimer.isActive())
- m_orientationLockTimer.startOneShot(0, FROM_HERE);
+ if (m_orientationLockTimer.isActive())
+ m_orientationLockTimer.stop();
+
+ m_prospectiveLock = orientation;
+ m_orientationLockTimer.startOneShot(0, FROM_HERE);
Inactive 2014/03/31 18:52:36 So consecutive calls to lockOrientation("portrait"
mlamouri (slow - plz ping) 2014/03/31 19:45:35 If another ScreenOrientation instance lock the scr
Inactive 2014/03/31 19:59:42 What do you mean by another ScreenOrientation inst
}
void ScreenOrientation::orientationLockTimerFired(Timer<ScreenOrientation>*)
{
- if (m_lockedOrientations == WebScreenOrientationDefault)
+ if (m_prospectiveLock == blink::WebScreenOrientationLockDefault)
blink::Platform::current()->unlockOrientation();
else
- blink::Platform::current()->lockOrientation(m_lockedOrientations);
+ blink::Platform::current()->lockOrientation(m_prospectiveLock);
}
const char* ScreenOrientation::supplementName()
@@ -131,24 +127,21 @@ const AtomicString& ScreenOrientation::orientation(Screen& screen)
ScreenOrientation& screenOrientation = ScreenOrientation::from(screen);
if (!screenOrientation.document()) {
// FIXME: we should try to return a better guess, like the latest known value.
- return orientationToString(blink::WebScreenOrientationPortraitPrimary);
+ return orientationTypeToString(blink::WebScreenOrientationPortraitPrimary);
}
ScreenOrientationController& controller = ScreenOrientationController::from(*screenOrientation.document());
- return orientationToString(controller.orientation());
+ return orientationTypeToString(controller.orientation());
}
-bool ScreenOrientation::lockOrientation(Screen& screen, const AtomicString& orientationString)
+bool ScreenOrientation::lockOrientation(Screen& screen, const AtomicString& lockString)
{
- blink::WebScreenOrientations orientations = stringToOrientations(orientationString);
- if (!orientations)
- return false;
- ScreenOrientation::from(screen).lockOrientationAsync(orientations);
+ ScreenOrientation::from(screen).lockOrientationAsync(stringToOrientationLock(lockString));
return true;
}
void ScreenOrientation::unlockOrientation(Screen& screen)
{
- ScreenOrientation::from(screen).lockOrientationAsync(WebScreenOrientationDefault);
+ ScreenOrientation::from(screen).lockOrientationAsync(blink::WebScreenOrientationLockDefault);
}
} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698