| 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" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 DEFINE_STATIC_LOCAL(const AtomicString, portraitPrimary, ("portrait-primary"
, AtomicString::ConstructFromLiteral)); | 36 DEFINE_STATIC_LOCAL(const AtomicString, portraitPrimary, ("portrait-primary"
, AtomicString::ConstructFromLiteral)); |
| 37 DEFINE_STATIC_LOCAL(const AtomicString, portraitSecondary, ("portrait-second
ary", AtomicString::ConstructFromLiteral)); | 37 DEFINE_STATIC_LOCAL(const AtomicString, portraitSecondary, ("portrait-second
ary", AtomicString::ConstructFromLiteral)); |
| 38 DEFINE_STATIC_LOCAL(const AtomicString, landscapePrimary, ("landscape-primar
y", AtomicString::ConstructFromLiteral)); | 38 DEFINE_STATIC_LOCAL(const AtomicString, landscapePrimary, ("landscape-primar
y", AtomicString::ConstructFromLiteral)); |
| 39 DEFINE_STATIC_LOCAL(const AtomicString, landscapeSecondary, ("landscape-seco
ndary", AtomicString::ConstructFromLiteral)); | 39 DEFINE_STATIC_LOCAL(const AtomicString, landscapeSecondary, ("landscape-seco
ndary", AtomicString::ConstructFromLiteral)); |
| 40 DEFINE_STATIC_LOCAL(const AtomicString, any, ("any", AtomicString::Construct
FromLiteral)); | 40 DEFINE_STATIC_LOCAL(const AtomicString, any, ("any", AtomicString::Construct
FromLiteral)); |
| 41 DEFINE_STATIC_LOCAL(const AtomicString, portrait, ("portrait", AtomicString:
:ConstructFromLiteral)); | 41 DEFINE_STATIC_LOCAL(const AtomicString, portrait, ("portrait", AtomicString:
:ConstructFromLiteral)); |
| 42 DEFINE_STATIC_LOCAL(const AtomicString, landscape, ("landscape", AtomicStrin
g::ConstructFromLiteral)); | 42 DEFINE_STATIC_LOCAL(const AtomicString, landscape, ("landscape", AtomicStrin
g::ConstructFromLiteral)); |
| 43 DEFINE_STATIC_LOCAL(const AtomicString, natural, ("natural", AtomicString::C
onstructFromLiteral)); | 43 DEFINE_STATIC_LOCAL(const AtomicString, natural, ("natural", AtomicString::C
onstructFromLiteral)); |
| 44 | 44 |
| 45 static ScreenOrientationInfo orientationMap[] = { | 45 static ScreenOrientationInfo orientationMap[] = { |
| 46 { portraitPrimary, blink::WebScreenOrientationLockPortraitPrimary }, | 46 { portraitPrimary, WebScreenOrientationLockPortraitPrimary }, |
| 47 { portraitSecondary, blink::WebScreenOrientationLockPortraitSecondary }, | 47 { portraitSecondary, WebScreenOrientationLockPortraitSecondary }, |
| 48 { landscapePrimary, blink::WebScreenOrientationLockLandscapePrimary }, | 48 { landscapePrimary, WebScreenOrientationLockLandscapePrimary }, |
| 49 { landscapeSecondary, blink::WebScreenOrientationLockLandscapeSecondary
}, | 49 { landscapeSecondary, WebScreenOrientationLockLandscapeSecondary }, |
| 50 { any, blink::WebScreenOrientationLockAny }, | 50 { any, WebScreenOrientationLockAny }, |
| 51 { portrait, blink::WebScreenOrientationLockPortrait }, | 51 { portrait, WebScreenOrientationLockPortrait }, |
| 52 { landscape, blink::WebScreenOrientationLockLandscape }, | 52 { landscape, WebScreenOrientationLockLandscape }, |
| 53 { natural, blink::WebScreenOrientationLockNatural } | 53 { natural, WebScreenOrientationLockNatural } |
| 54 }; | 54 }; |
| 55 length = WTF_ARRAY_LENGTH(orientationMap); | 55 length = WTF_ARRAY_LENGTH(orientationMap); |
| 56 | 56 |
| 57 return orientationMap; | 57 return orientationMap; |
| 58 } | 58 } |
| 59 | 59 |
| 60 const AtomicString& ScreenOrientation::orientationTypeToString(blink::WebScreenO
rientationType orientation) | 60 const AtomicString& ScreenOrientation::orientationTypeToString(WebScreenOrientat
ionType orientation) |
| 61 { | 61 { |
| 62 unsigned length = 0; | 62 unsigned length = 0; |
| 63 ScreenOrientationInfo* orientationMap = orientationsMap(length); | 63 ScreenOrientationInfo* orientationMap = orientationsMap(length); |
| 64 for (unsigned i = 0; i < length; ++i) { | 64 for (unsigned i = 0; i < length; ++i) { |
| 65 if (static_cast<unsigned>(orientation) == orientationMap[i].orientation) | 65 if (static_cast<unsigned>(orientation) == orientationMap[i].orientation) |
| 66 return orientationMap[i].name; | 66 return orientationMap[i].name; |
| 67 } | 67 } |
| 68 | 68 |
| 69 ASSERT_NOT_REACHED(); | 69 ASSERT_NOT_REACHED(); |
| 70 return nullAtom; | 70 return nullAtom; |
| 71 } | 71 } |
| 72 | 72 |
| 73 static blink::WebScreenOrientationLockType stringToOrientationLock(const AtomicS
tring& orientationLockString) | 73 static WebScreenOrientationLockType stringToOrientationLock(const AtomicString&
orientationLockString) |
| 74 { | 74 { |
| 75 unsigned length = 0; | 75 unsigned length = 0; |
| 76 ScreenOrientationInfo* orientationMap = orientationsMap(length); | 76 ScreenOrientationInfo* orientationMap = orientationsMap(length); |
| 77 for (unsigned i = 0; i < length; ++i) { | 77 for (unsigned i = 0; i < length; ++i) { |
| 78 if (orientationMap[i].name == orientationLockString) | 78 if (orientationMap[i].name == orientationLockString) |
| 79 return static_cast<blink::WebScreenOrientationLockType>(orientationM
ap[i].orientation); | 79 return static_cast<WebScreenOrientationLockType>(orientationMap[i].o
rientation); |
| 80 } | 80 } |
| 81 | 81 |
| 82 ASSERT_NOT_REACHED(); | 82 ASSERT_NOT_REACHED(); |
| 83 return blink::WebScreenOrientationLockDefault; | 83 return WebScreenOrientationLockDefault; |
| 84 } | 84 } |
| 85 | 85 |
| 86 // static | 86 // static |
| 87 ScreenOrientation* ScreenOrientation::create(LocalFrame* frame) | 87 ScreenOrientation* ScreenOrientation::create(LocalFrame* frame) |
| 88 { | 88 { |
| 89 ASSERT(frame); | 89 ASSERT(frame); |
| 90 | 90 |
| 91 ScreenOrientation* orientation = adoptRefCountedGarbageCollectedWillBeNoop(n
ew ScreenOrientation(frame)); | 91 ScreenOrientation* orientation = adoptRefCountedGarbageCollectedWillBeNoop(n
ew ScreenOrientation(frame)); |
| 92 ASSERT(orientation->controller()); | 92 ASSERT(orientation->controller()); |
| 93 // FIXME: ideally, we would like to provide the ScreenOrientationController | 93 // FIXME: ideally, we would like to provide the ScreenOrientationController |
| 94 // the case where it is not defined but for the moment, it is eagerly | 94 // the case where it is not defined but for the moment, it is eagerly |
| 95 // created when the LocalFrame is created so we shouldn't be in that | 95 // created when the LocalFrame is created so we shouldn't be in that |
| 96 // situtaion. | 96 // situtaion. |
| 97 // In order to create the ScreenOrientationController lazily, we would need | 97 // In order to create the ScreenOrientationController lazily, we would need |
| 98 // to be able to access WebFrameClient from modules/. | 98 // to be able to access WebFrameClient from modules/. |
| 99 | 99 |
| 100 orientation->controller()->setOrientation(orientation); | 100 orientation->controller()->setOrientation(orientation); |
| 101 return orientation; | 101 return orientation; |
| 102 } | 102 } |
| 103 | 103 |
| 104 ScreenOrientation::ScreenOrientation(LocalFrame* frame) | 104 ScreenOrientation::ScreenOrientation(LocalFrame* frame) |
| 105 : DOMWindowProperty(frame) | 105 : DOMWindowProperty(frame) |
| 106 , m_type(blink::WebScreenOrientationUndefined) | 106 , m_type(WebScreenOrientationUndefined) |
| 107 , m_angle(0) | 107 , m_angle(0) |
| 108 { | 108 { |
| 109 ScriptWrappable::init(this); | 109 ScriptWrappable::init(this); |
| 110 } | 110 } |
| 111 | 111 |
| 112 ScreenOrientation::~ScreenOrientation() | 112 ScreenOrientation::~ScreenOrientation() |
| 113 { | 113 { |
| 114 } | 114 } |
| 115 | 115 |
| 116 const WTF::AtomicString& ScreenOrientation::interfaceName() const | 116 const WTF::AtomicString& ScreenOrientation::interfaceName() const |
| (...skipping 11 matching lines...) Expand all Loading... |
| 128 String ScreenOrientation::type() const | 128 String ScreenOrientation::type() const |
| 129 { | 129 { |
| 130 return orientationTypeToString(m_type); | 130 return orientationTypeToString(m_type); |
| 131 } | 131 } |
| 132 | 132 |
| 133 unsigned short ScreenOrientation::angle() const | 133 unsigned short ScreenOrientation::angle() const |
| 134 { | 134 { |
| 135 return m_angle; | 135 return m_angle; |
| 136 } | 136 } |
| 137 | 137 |
| 138 void ScreenOrientation::setType(blink::WebScreenOrientationType type) | 138 void ScreenOrientation::setType(WebScreenOrientationType type) |
| 139 { | 139 { |
| 140 m_type = type; | 140 m_type = type; |
| 141 } | 141 } |
| 142 | 142 |
| 143 void ScreenOrientation::setAngle(unsigned short angle) | 143 void ScreenOrientation::setAngle(unsigned short angle) |
| 144 { | 144 { |
| 145 m_angle = angle; | 145 m_angle = angle; |
| 146 } | 146 } |
| 147 | 147 |
| 148 ScriptPromise ScreenOrientation::lock(ScriptState* state, const AtomicString& lo
ckString) | 148 ScriptPromise ScreenOrientation::lock(ScriptState* state, const AtomicString& lo
ckString) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 183 |
| 184 return ScreenOrientationController::from(*m_frame); | 184 return ScreenOrientationController::from(*m_frame); |
| 185 } | 185 } |
| 186 | 186 |
| 187 void ScreenOrientation::trace(Visitor* visitor) | 187 void ScreenOrientation::trace(Visitor* visitor) |
| 188 { | 188 { |
| 189 EventTargetWithInlineData::trace(visitor); | 189 EventTargetWithInlineData::trace(visitor); |
| 190 } | 190 } |
| 191 | 191 |
| 192 } // namespace blink | 192 } // namespace blink |
| OLD | NEW |