| 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 "core/frame/DOMWindow.h" | 8 #include "core/frame/DOMWindow.h" |
| 9 #include "core/frame/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
| 10 #include "core/frame/Screen.h" | 10 #include "core/frame/Screen.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 blink::Platform::current()->unlockOrientation(); | 92 blink::Platform::current()->unlockOrientation(); |
| 93 else | 93 else |
| 94 blink::Platform::current()->lockOrientation(m_lockedOrientations); | 94 blink::Platform::current()->lockOrientation(m_lockedOrientations); |
| 95 } | 95 } |
| 96 | 96 |
| 97 const char* ScreenOrientation::supplementName() | 97 const char* ScreenOrientation::supplementName() |
| 98 { | 98 { |
| 99 return "ScreenOrientation"; | 99 return "ScreenOrientation"; |
| 100 } | 100 } |
| 101 | 101 |
| 102 Document& ScreenOrientation::document() const | 102 Document* ScreenOrientation::document() const |
| 103 { | 103 { |
| 104 ASSERT(m_associatedDOMWindow); | 104 if (!m_associatedDOMWindow || !m_associatedDOMWindow->isCurrentlyDisplayedIn
Frame()) |
| 105 return 0; |
| 105 ASSERT(m_associatedDOMWindow->document()); | 106 ASSERT(m_associatedDOMWindow->document()); |
| 106 return *m_associatedDOMWindow->document(); | 107 return m_associatedDOMWindow->document(); |
| 107 } | 108 } |
| 108 | 109 |
| 109 ScreenOrientation& ScreenOrientation::from(Screen& screen) | 110 ScreenOrientation& ScreenOrientation::from(Screen& screen) |
| 110 { | 111 { |
| 111 ScreenOrientation* supplement = static_cast<ScreenOrientation*>(Supplement<S
creen>::from(screen, supplementName())); | 112 ScreenOrientation* supplement = static_cast<ScreenOrientation*>(Supplement<S
creen>::from(screen, supplementName())); |
| 112 if (!supplement) { | 113 if (!supplement) { |
| 113 supplement = new ScreenOrientation(screen); | 114 supplement = new ScreenOrientation(screen); |
| 114 provideTo(screen, supplementName(), adoptPtr(supplement)); | 115 provideTo(screen, supplementName(), adoptPtr(supplement)); |
| 115 } | 116 } |
| 116 return *supplement; | 117 return *supplement; |
| 117 } | 118 } |
| 118 | 119 |
| 119 ScreenOrientation::~ScreenOrientation() | 120 ScreenOrientation::~ScreenOrientation() |
| 120 { | 121 { |
| 121 } | 122 } |
| 122 | 123 |
| 123 const AtomicString& ScreenOrientation::orientation(Screen& screen) | 124 const AtomicString& ScreenOrientation::orientation(Screen& screen) |
| 124 { | 125 { |
| 125 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); | 126 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); |
| 126 ScreenOrientationController& controller = ScreenOrientationController::from(
screenOrientation.document()); | 127 if (!screenOrientation.document()) |
| 128 return emptyAtom; |
| 129 ScreenOrientationController& controller = ScreenOrientationController::from(
*screenOrientation.document()); |
| 127 return orientationToString(controller.orientation()); | 130 return orientationToString(controller.orientation()); |
| 128 } | 131 } |
| 129 | 132 |
| 130 bool ScreenOrientation::lockOrientation(Screen& screen, const Vector<String>& or
ientationsVector) | 133 bool ScreenOrientation::lockOrientation(Screen& screen, const Vector<String>& or
ientationsVector) |
| 131 { | 134 { |
| 132 blink::WebScreenOrientations orientations = 0; | 135 blink::WebScreenOrientations orientations = 0; |
| 133 for (size_t i = 0; i < orientationsVector.size(); ++i) { | 136 for (size_t i = 0; i < orientationsVector.size(); ++i) { |
| 134 blink::WebScreenOrientations currentOrientation = stringToOrientations(A
tomicString(orientationsVector[i])); | 137 blink::WebScreenOrientations currentOrientation = stringToOrientations(A
tomicString(orientationsVector[i])); |
| 135 if (!currentOrientation) | 138 if (!currentOrientation) |
| 136 return false; | 139 return false; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 150 ScreenOrientation::from(screen).lockOrientationAsync(orientations); | 153 ScreenOrientation::from(screen).lockOrientationAsync(orientations); |
| 151 return true; | 154 return true; |
| 152 } | 155 } |
| 153 | 156 |
| 154 void ScreenOrientation::unlockOrientation(Screen& screen) | 157 void ScreenOrientation::unlockOrientation(Screen& screen) |
| 155 { | 158 { |
| 156 ScreenOrientation::from(screen).lockOrientationAsync(WebScreenOrientationDef
ault); | 159 ScreenOrientation::from(screen).lockOrientationAsync(WebScreenOrientationDef
ault); |
| 157 } | 160 } |
| 158 | 161 |
| 159 } // namespace WebCore | 162 } // namespace WebCore |
| OLD | NEW |