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..c5cfd6213879870c8535b710b4877f8ca9a07d37 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,68 @@ static blink::WebScreenOrientationLockType stringToOrientationLock(const AtomicS |
return blink::WebScreenOrientationLockDefault; |
} |
-ScreenOrientation::ScreenOrientation(Screen& screen) |
- : DOMWindowProperty(screen.frame()) |
+// static |
+ScreenOrientation* ScreenOrientation::create(ScreenOrientationController* controller, ExecutionContext* executionContext) |
{ |
+ ScreenOrientation* orientation = adoptRefCountedGarbageCollectedWillBeNoop(new ScreenOrientation(controller, executionContext)); |
+ orientation->suspendIfNeeded(); |
+ controller->setOrientation(orientation); |
+ |
+ return orientation; |
} |
-const char* ScreenOrientation::supplementName() |
+ScreenOrientation::ScreenOrientation(ScreenOrientationController* controller, ExecutionContext* executionContext) |
+ : ActiveDOMObject(executionContext) |
+ , m_controller(controller) |
+ , m_type(blink::WebScreenOrientationUndefined) |
+ , m_angle(0) |
{ |
- return "ScreenOrientation"; |
+ ScriptWrappable::init(this); |
} |
-Document* ScreenOrientation::document() const |
+ScreenOrientation::~ScreenOrientation() |
{ |
- if (!m_associatedDOMWindow || !m_associatedDOMWindow->isCurrentlyDisplayedInFrame()) |
- return 0; |
- ASSERT(m_associatedDOMWindow->document()); |
- return m_associatedDOMWindow->document(); |
+ m_controller->setOrientation(0); |
} |
-ScreenOrientation& ScreenOrientation::from(Screen& screen) |
+const WTF::AtomicString& ScreenOrientation::interfaceName() 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 EventTargetNames::ScreenOrientation; |
} |
-ScreenOrientation::~ScreenOrientation() |
+ExecutionContext* ScreenOrientation::executionContext() const |
{ |
+ return ActiveDOMObject::executionContext(); |
} |
-const AtomicString& ScreenOrientation::orientation(Screen& screen) |
+String ScreenOrientation::type() const |
{ |
- 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()); |
+ return orientationTypeToString(m_type); |
} |
-ScriptPromise ScreenOrientation::lockOrientation(ScriptState* state, Screen& screen, const AtomicString& lockString) |
+unsigned short ScreenOrientation::angle() const |
+{ |
+ return m_angle; |
+} |
+ |
+void ScreenOrientation::setType(blink::WebScreenOrientationType type) |
+{ |
+ m_type = type; |
+} |
+ |
+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_controller->frame().document(); |
- if (!document || !screenOrientation.frame()) { |
+ if (!document) { |
RefPtrWillBeRawPtr<DOMException> exception = DOMException::create(InvalidStateError, "The object is no longer associated to a document."); |
resolver->reject(exception); |
return promise; |
@@ -147,17 +156,23 @@ ScriptPromise ScreenOrientation::lockOrientation(ScriptState* state, Screen& scr |
return promise; |
} |
- ScreenOrientationController::from(*screenOrientation.frame()).lockOrientation(stringToOrientationLock(lockString), new LockOrientationCallback(resolver)); |
+ m_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()) |
- return; |
+ m_controller->unlock(); |
+} |
- ScreenOrientationController::from(*screenOrientation.frame()).unlockOrientation(); |
+bool ScreenOrientation::hasPendingActivity() const |
+{ |
+ return hasEventListeners(); |
+} |
abarth-chromium
2014/07/07 17:29:33
You don't need this code because this object is ke
mlamouri (slow - plz ping)
2014/07/08 14:07:59
Done.
|
+ |
+void ScreenOrientation::trace(Visitor* visitor) |
+{ |
+ EventTargetWithInlineData::trace(visitor); |
} |
} // namespace WebCore |