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

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

Issue 374623002: [screen-orientation] Update implementation to match recent spec changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 6 years, 5 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 8114c51173ea3ec852d08703d41b2dfd5692afb9..d8e40ed08b5a21b4b8042667a1b58c3352577fe7 100644
--- a/Source/modules/screen_orientation/ScreenOrientation.cpp
+++ b/Source/modules/screen_orientation/ScreenOrientation.cpp
@@ -10,9 +10,8 @@
#include "core/dom/DOMException.h"
#include "core/dom/Document.h"
#include "core/dom/ExceptionCode.h"
-#include "core/frame/LocalDOMWindow.h"
#include "core/frame/LocalFrame.h"
-#include "core/frame/Screen.h"
+#include "modules/EventTargetModules.h"
#include "modules/screen_orientation/LockOrientationCallback.h"
#include "modules/screen_orientation/ScreenOrientationController.h"
#include "public/platform/WebScreenOrientationType.h"
@@ -84,58 +83,76 @@ static blink::WebScreenOrientationLockType stringToOrientationLock(const AtomicS
return blink::WebScreenOrientationLockDefault;
}
-ScreenOrientation::ScreenOrientation(Screen& screen)
- : DOMWindowProperty(screen.frame())
+// static
+ScreenOrientation* ScreenOrientation::create(LocalFrame* frame)
{
+ ASSERT(frame);
+
+ ScreenOrientation* orientation = adoptRefCountedGarbageCollectedWillBeNoop(new ScreenOrientation(frame));
+ ASSERT(orientation->controller());
+ // FIXME: ideally, we would like to provide the ScreenOrientationController
+ // the case where it is not defined but for the moment, it is eagerly
+ // created when the LocalFrame is created so we shouldn't be in that
+ // situtaion.
+ // In order to create the ScreenOrientationController lazily, we would need
+ // to be able to access WebFrameClient from modules/.
+
+ orientation->controller()->setOrientation(orientation);
+ return orientation;
}
-const char* ScreenOrientation::supplementName()
+ScreenOrientation::ScreenOrientation(LocalFrame* frame)
+ : DOMWindowProperty(frame)
+ , m_type(blink::WebScreenOrientationUndefined)
+ , m_angle(0)
{
- return "ScreenOrientation";
+ ScriptWrappable::init(this);
}
-Document* ScreenOrientation::document() const
+ScreenOrientation::~ScreenOrientation()
+{
+}
+
+const WTF::AtomicString& ScreenOrientation::interfaceName() const
{
- if (!m_associatedDOMWindow || !m_associatedDOMWindow->isCurrentlyDisplayedInFrame())
+ return EventTargetNames::ScreenOrientation;
+}
+
+ExecutionContext* ScreenOrientation::executionContext() const
+{
+ if (!m_frame)
return 0;
- ASSERT(m_associatedDOMWindow->document());
- return m_associatedDOMWindow->document();
+ return m_frame->document();
}
-ScreenOrientation& ScreenOrientation::from(Screen& screen)
+String ScreenOrientation::type() const
{
- ScreenOrientation* supplement = static_cast<ScreenOrientation*>(WillBeHeapSupplement<Screen>::from(screen, supplementName()));
- if (!supplement) {
- supplement = new ScreenOrientation(screen);
- provideTo(screen, supplementName(), adoptPtrWillBeNoop(supplement));
- }
- return *supplement;
+ return orientationTypeToString(m_type);
}
-ScreenOrientation::~ScreenOrientation()
+unsigned short ScreenOrientation::angle() const
{
+ return m_angle;
}
-const AtomicString& ScreenOrientation::orientation(Screen& screen)
+void ScreenOrientation::setType(blink::WebScreenOrientationType type)
{
- ScreenOrientation& screenOrientation = ScreenOrientation::from(screen);
- if (!screenOrientation.frame()) {
- // FIXME: we should try to return a better guess, like the latest known value.
- return orientationTypeToString(blink::WebScreenOrientationPortraitPrimary);
- }
- ScreenOrientationController& controller = ScreenOrientationController::from(*screenOrientation.frame());
- return orientationTypeToString(controller.orientation());
+ m_type = type;
}
-ScriptPromise ScreenOrientation::lockOrientation(ScriptState* state, Screen& screen, const AtomicString& lockString)
+void ScreenOrientation::setAngle(unsigned short angle)
+{
+ m_angle = angle;
+}
+
+ScriptPromise ScreenOrientation::lock(ScriptState* state, const AtomicString& lockString)
{
RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(state);
ScriptPromise promise = resolver->promise();
- ScreenOrientation& screenOrientation = ScreenOrientation::from(screen);
- Document* document = screenOrientation.document();
+ Document* document = m_frame ? m_frame->document() : 0;
- if (!document || !screenOrientation.frame()) {
+ if (!document || !controller()) {
RefPtrWillBeRawPtr<DOMException> exception = DOMException::create(InvalidStateError, "The object is no longer associated to a document.");
resolver->reject(exception);
return promise;
@@ -147,17 +164,29 @@ ScriptPromise ScreenOrientation::lockOrientation(ScriptState* state, Screen& scr
return promise;
}
- ScreenOrientationController::from(*screenOrientation.frame()).lockOrientation(stringToOrientationLock(lockString), new LockOrientationCallback(resolver));
+ controller()->lock(stringToOrientationLock(lockString), new LockOrientationCallback(resolver));
return promise;
}
-void ScreenOrientation::unlockOrientation(Screen& screen)
+void ScreenOrientation::unlock()
{
- ScreenOrientation& screenOrientation = ScreenOrientation::from(screen);
- if (!screenOrientation.frame())
+ if (!controller())
return;
- ScreenOrientationController::from(*screenOrientation.frame()).unlockOrientation();
+ controller()->unlock();
+}
+
+ScreenOrientationController* ScreenOrientation::controller()
+{
+ if (!m_frame)
+ return 0;
+
+ return ScreenOrientationController::from(*m_frame);
+}
+
+void ScreenOrientation::trace(Visitor* visitor)
+{
+ EventTargetWithInlineData::trace(visitor);
}
} // namespace WebCore
« no previous file with comments | « Source/modules/screen_orientation/ScreenOrientation.h ('k') | Source/modules/screen_orientation/ScreenOrientation.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698