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

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

Issue 169403006: Screen Orientation API: screen.orientation & orientationchange event (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix nits 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/ScreenOrientation.cpp
diff --git a/Source/modules/screen_orientation/ScreenOrientation.cpp b/Source/modules/screen_orientation/ScreenOrientation.cpp
index 4b147dd809a0f4ee807ee0cd9fb9fe5145c8ce0e..36d6369b9f85c98d27dcff195970b037019c23c2 100644
--- a/Source/modules/screen_orientation/ScreenOrientation.cpp
+++ b/Source/modules/screen_orientation/ScreenOrientation.cpp
@@ -8,9 +8,47 @@
#include "core/frame/DOMWindow.h"
#include "core/frame/Frame.h"
#include "core/frame/Screen.h"
+#include "modules/screen_orientation/ScreenOrientationController.h"
+#include "public/platform/WebScreenOrientation.h"
namespace WebCore {
+struct ScreenOrientationInfo {
+ const AtomicString& name;
+ blink::WebScreenOrientation orientation;
+};
+
+static ScreenOrientationInfo* orientationsMap(unsigned& length)
+{
+ DEFINE_STATIC_LOCAL(const AtomicString, portraitPrimary, ("portrait-primary", AtomicString::ConstructFromLiteral));
+ 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));
+
+ static ScreenOrientationInfo orientationMap[] = {
+ { portraitPrimary, blink::WebScreenOrientationPortraitPrimary },
+ { portraitSecondary, blink::WebScreenOrientationPortraitSecondary },
+ { landscapePrimary, blink::WebScreenOrientationLandscapePrimary },
+ { landscapeSecondary, blink::WebScreenOrientationLandscapeSecondary }
+ };
+ length = WTF_ARRAY_LENGTH(orientationMap);
+ return orientationMap;
+}
+
+static const AtomicString& orientationToString(blink::WebScreenOrientation orientation)
+{
+ unsigned length = 0;
+ ScreenOrientationInfo* orientationMap = orientationsMap(length);
+ for (unsigned i = 0; i < length; ++i) {
+ if (orientationMap[i].orientation == orientation)
+ 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;
+}
+
ScreenOrientation::ScreenOrientation(Screen* screen)
: DOMWindowProperty(screen->frame())
{
@@ -21,6 +59,12 @@ const char* ScreenOrientation::supplementName()
return "ScreenOrientation";
}
+Document* ScreenOrientation::document() const
+{
+ ASSERT(m_associatedDOMWindow);
+ return m_associatedDOMWindow->document();
+}
+
ScreenOrientation* ScreenOrientation::from(Screen* screen)
{
ScreenOrientation* supplement = static_cast<ScreenOrientation*>(Supplement<Screen>::from(screen, supplementName()));
@@ -36,20 +80,12 @@ ScreenOrientation::~ScreenOrientation()
{
}
-Screen* ScreenOrientation::screen() const
-{
- Frame* frame = this->frame();
- ASSERT(frame);
- DOMWindow* window = frame->domWindow();
- ASSERT(window);
- return window->screen();
-}
-
const AtomicString& ScreenOrientation::orientation(Screen* screen)
{
- // FIXME: Implement.
- DEFINE_STATIC_LOCAL(const AtomicString, portraitPrimary, ("portrait-primary", AtomicString::ConstructFromLiteral));
- return portraitPrimary;
+ ScreenOrientation* screenOrientation = ScreenOrientation::from(screen);
+ ScreenOrientationController* controller = ScreenOrientationController::from(screenOrientation->document());
+ ASSERT(controller);
+ return orientationToString(controller->orientation());
}
bool ScreenOrientation::lockOrientation(Screen* screen, const Vector<String>& orientations)
« no previous file with comments | « Source/modules/screen_orientation/ScreenOrientation.h ('k') | Source/modules/screen_orientation/ScreenOrientationController.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698