| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "modules/screen_orientation/ScreenOrientation.h" | 6 #include "modules/screen_orientation/ScreenOrientation.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
| 9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| 11 #include "core/dom/Document.h" | 11 #include "core/dom/Document.h" |
| 12 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
| 13 #include "core/frame/LocalDOMWindow.h" | 13 #include "core/frame/LocalDOMWindow.h" |
| 14 #include "core/frame/LocalFrame.h" | 14 #include "core/frame/LocalFrame.h" |
| 15 #include "core/frame/Screen.h" | 15 #include "core/frame/Screen.h" |
| 16 #include "modules/screen_orientation/LockOrientationCallback.h" | 16 #include "modules/screen_orientation/LockOrientationCallback.h" |
| 17 #include "modules/screen_orientation/OrientationInformation.h" |
| 17 #include "modules/screen_orientation/ScreenOrientationController.h" | 18 #include "modules/screen_orientation/ScreenOrientationController.h" |
| 18 #include "public/platform/WebScreenOrientationType.h" | 19 #include "public/platform/WebScreenOrientationType.h" |
| 19 | 20 |
| 20 // This code assumes that WebScreenOrientationType values are included in WebScr
eenOrientationLockType. | 21 // This code assumes that WebScreenOrientationType values are included in WebScr
eenOrientationLockType. |
| 21 #define COMPILE_ASSERT_MATCHING_ENUM(enum1, enum2) \ | 22 #define COMPILE_ASSERT_MATCHING_ENUM(enum1, enum2) \ |
| 22 COMPILE_ASSERT(static_cast<unsigned>(blink::enum1) == static_cast<unsigned>(
blink::enum2), mismatching_types) | 23 COMPILE_ASSERT(static_cast<unsigned>(blink::enum1) == static_cast<unsigned>(
blink::enum2), mismatching_types) |
| 23 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationPortraitPrimary, WebScreenOrien
tationLockPortraitPrimary); | 24 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationPortraitPrimary, WebScreenOrien
tationLockPortraitPrimary); |
| 24 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationPortraitSecondary, WebScreenOri
entationLockPortraitSecondary); | 25 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationPortraitSecondary, WebScreenOri
entationLockPortraitSecondary); |
| 25 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationLandscapePrimary, WebScreenOrie
ntationLockLandscapePrimary); | 26 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationLandscapePrimary, WebScreenOrie
ntationLockLandscapePrimary); |
| 26 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationLandscapeSecondary, WebScreenOr
ientationLockLandscapeSecondary); | 27 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationLandscapeSecondary, WebScreenOr
ientationLockLandscapeSecondary); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 supplement = new ScreenOrientation(screen); | 110 supplement = new ScreenOrientation(screen); |
| 110 provideTo(screen, supplementName(), adoptPtrWillBeNoop(supplement)); | 111 provideTo(screen, supplementName(), adoptPtrWillBeNoop(supplement)); |
| 111 } | 112 } |
| 112 return *supplement; | 113 return *supplement; |
| 113 } | 114 } |
| 114 | 115 |
| 115 ScreenOrientation::~ScreenOrientation() | 116 ScreenOrientation::~ScreenOrientation() |
| 116 { | 117 { |
| 117 } | 118 } |
| 118 | 119 |
| 119 const AtomicString& ScreenOrientation::orientation(Screen& screen) | 120 OrientationInformation* ScreenOrientation::orientation(Screen& screen) |
| 120 { | 121 { |
| 121 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); | 122 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); |
| 122 if (!screenOrientation.frame()) { | 123 if (!screenOrientation.frame()) { |
| 123 // FIXME: we should try to return a better guess, like the latest known
value. | 124 return OrientationInformation::createFake(); |
| 124 return orientationTypeToString(blink::WebScreenOrientationPortraitPrimar
y); | |
| 125 } | 125 } |
| 126 ScreenOrientationController& controller = ScreenOrientationController::from(
*screenOrientation.frame()); | 126 return ScreenOrientationController::from(*screenOrientation.frame()).orienta
tion(); |
| 127 return orientationTypeToString(controller.orientation()); | |
| 128 } | 127 } |
| 129 | 128 |
| 130 ScriptPromise ScreenOrientation::lockOrientation(ScriptState* state, Screen& scr
een, const AtomicString& lockString) | 129 ScriptPromise ScreenOrientation::lockOrientation(ScriptState* state, Screen& scr
een, const AtomicString& lockString) |
| 131 { | 130 { |
| 132 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(state
); | 131 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(state
); |
| 133 ScriptPromise promise = resolver->promise(); | 132 ScriptPromise promise = resolver->promise(); |
| 134 | 133 |
| 135 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); | 134 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); |
| 136 Document* document = screenOrientation.document(); | 135 Document* document = screenOrientation.document(); |
| 137 | 136 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 154 void ScreenOrientation::unlockOrientation(Screen& screen) | 153 void ScreenOrientation::unlockOrientation(Screen& screen) |
| 155 { | 154 { |
| 156 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); | 155 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); |
| 157 if (!screenOrientation.frame()) | 156 if (!screenOrientation.frame()) |
| 158 return; | 157 return; |
| 159 | 158 |
| 160 ScreenOrientationController::from(*screenOrientation.frame()).unlockOrientat
ion(); | 159 ScreenOrientationController::from(*screenOrientation.frame()).unlockOrientat
ion(); |
| 161 } | 160 } |
| 162 | 161 |
| 163 } // namespace WebCore | 162 } // namespace WebCore |
| OLD | NEW |