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

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

Issue 169403006: Screen Orientation API: screen.orientation & orientationchange event (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Take feedback into consideration 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/ScreenOrientationController.cpp
diff --git a/Source/modules/screen_orientation/ScreenOrientationController.cpp b/Source/modules/screen_orientation/ScreenOrientationController.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..bafdf2d7a4363039642c1092ebd179bd4eb12e5a
--- /dev/null
+++ b/Source/modules/screen_orientation/ScreenOrientationController.cpp
@@ -0,0 +1,64 @@
+// 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 "modules/screen_orientation/ScreenOrientationController.h"
+
+#include "core/dom/Document.h"
+#include "core/events/Event.h"
+#include "core/frame/DOMWindow.h"
+#include "core/frame/Screen.h"
+#include "modules/screen_orientation/ScreenOrientationDispatcher.h"
+
+namespace WebCore {
+
+ScreenOrientationController::~ScreenOrientationController()
+{
+ ScreenOrientationDispatcher::instance().removeController(this);
+}
+
+ScreenOrientationController* ScreenOrientationController::from(Document* document)
+{
+ ScreenOrientationController* controller = static_cast<ScreenOrientationController*>(DocumentSupplement::from(document, supplementName()));
+ if (!controller) {
+ ASSERT(document);
abarth-chromium 2014/02/19 18:51:49 We don't usually have this ASSERT here. The code
Inactive 2014/02/19 19:04:51 Done.
+ controller = new ScreenOrientationController(*document);
+ DocumentSupplement::provideTo(document, supplementName(), adoptPtr(controller));
+ }
+ return controller;
+}
+
+ScreenOrientationController::ScreenOrientationController(Document& document)
+ : m_document(document)
+ // FIXME: This orientation is not necessary the right one until the first orientationchange
+ // event is fired.
abarth-chromium 2014/02/19 18:51:49 I'd skip this FIXME
Inactive 2014/02/19 19:04:51 Done.
+ , m_orientation(blink::WebScreenOrientationPortraitPrimary)
+{
+ // FIXME: We should listen for screen orientation change events only when the page is visible.
+ ScreenOrientationDispatcher::instance().addController(this);
+}
+
+void ScreenOrientationController::dispatchOrientationChangeEvent()
+{
+ if (m_document.domWindow() && m_document.domWindow()->screen()
+ && !m_document.activeDOMObjectsAreSuspended()
+ && !m_document.activeDOMObjectsAreStopped())
+ m_document.domWindow()->screen()->dispatchEvent(Event::create(EventTypeNames::orientationchange));
+}
+
+const char* ScreenOrientationController::supplementName()
+{
+ return "ScreenOrientationController";
+}
+
+void ScreenOrientationController::didChangeScreenOrientation(blink::WebScreenOrientation orientation)
+{
+ if (orientation == m_orientation)
+ return;
+
+ m_orientation = orientation;
+ dispatchOrientationChangeEvent();
+}
+
+} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698