| 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 "modules/screen_orientation/ScreenOrientationControllerImpl.h" | 5 #include "modules/screen_orientation/ScreenOrientationControllerImpl.h" |
| 6 | 6 |
| 7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/dom/TaskRunnerHelper.h" | 8 #include "core/dom/TaskRunnerHelper.h" |
| 9 #include "core/events/Event.h" | 9 #include "core/events/Event.h" |
| 10 #include "core/frame/FrameHost.h" | 10 #include "core/frame/FrameHost.h" |
| 11 #include "core/frame/FrameView.h" | 11 #include "core/frame/FrameView.h" |
| 12 #include "core/frame/LocalFrame.h" | 12 #include "core/frame/LocalFrame.h" |
| 13 #include "core/page/ChromeClient.h" | 13 #include "core/page/ChromeClient.h" |
| 14 #include "core/page/Page.h" | 14 #include "core/page/Page.h" |
| 15 #include "modules/screen_orientation/ScreenOrientation.h" | 15 #include "modules/screen_orientation/ScreenOrientation.h" |
| 16 #include "modules/screen_orientation/ScreenOrientationDispatcher.h" | |
| 17 #include "platform/LayoutTestSupport.h" | 16 #include "platform/LayoutTestSupport.h" |
| 18 #include "platform/ScopedOrientationChangeIndicator.h" | 17 #include "platform/ScopedOrientationChangeIndicator.h" |
| 19 #include "public/platform/WebScreenInfo.h" | 18 #include "public/platform/WebScreenInfo.h" |
| 20 #include "public/platform/modules/screen_orientation/WebScreenOrientationClient.
h" | 19 #include "public/platform/modules/screen_orientation/WebScreenOrientationClient.
h" |
| 21 #include <memory> | 20 #include <memory> |
| 22 #include <utility> | 21 #include <utility> |
| 23 | 22 |
| 24 namespace blink { | 23 namespace blink { |
| 25 | 24 |
| 26 ScreenOrientationControllerImpl::~ScreenOrientationControllerImpl() = default; | 25 ScreenOrientationControllerImpl::~ScreenOrientationControllerImpl() = default; |
| 27 | 26 |
| 28 void ScreenOrientationControllerImpl::provideTo( | 27 void ScreenOrientationControllerImpl::provideTo( |
| 29 LocalFrame& frame, | 28 LocalFrame& frame, |
| 30 WebScreenOrientationClient* client) { | 29 WebScreenOrientationClient* client) { |
| 31 ScreenOrientationController::provideTo( | 30 ScreenOrientationController::provideTo( |
| 32 frame, new ScreenOrientationControllerImpl(frame, client)); | 31 frame, new ScreenOrientationControllerImpl(frame, client)); |
| 33 } | 32 } |
| 34 | 33 |
| 35 ScreenOrientationControllerImpl* ScreenOrientationControllerImpl::from( | 34 ScreenOrientationControllerImpl* ScreenOrientationControllerImpl::from( |
| 36 LocalFrame& frame) { | 35 LocalFrame& frame) { |
| 37 return static_cast<ScreenOrientationControllerImpl*>( | 36 return static_cast<ScreenOrientationControllerImpl*>( |
| 38 ScreenOrientationController::from(frame)); | 37 ScreenOrientationController::from(frame)); |
| 39 } | 38 } |
| 40 | 39 |
| 41 ScreenOrientationControllerImpl::ScreenOrientationControllerImpl( | 40 ScreenOrientationControllerImpl::ScreenOrientationControllerImpl( |
| 42 LocalFrame& frame, | 41 LocalFrame& frame, |
| 43 WebScreenOrientationClient* client) | 42 WebScreenOrientationClient* client) |
| 44 : ScreenOrientationController(frame), | 43 : ScreenOrientationController(frame), |
| 45 ContextLifecycleObserver(frame.document()), | 44 ContextLifecycleObserver(frame.document()), |
| 46 PlatformEventController(&frame), | 45 PageVisibilityObserver(frame.page()), |
| 47 m_client(client), | 46 m_client(client), |
| 48 m_dispatchEventTimer( | 47 m_dispatchEventTimer( |
| 49 TaskRunnerHelper::get(TaskType::MiscPlatformAPI, &frame), | 48 TaskRunnerHelper::get(TaskType::MiscPlatformAPI, &frame), |
| 50 this, | 49 this, |
| 51 &ScreenOrientationControllerImpl::dispatchEventTimerFired) {} | 50 &ScreenOrientationControllerImpl::dispatchEventTimerFired) {} |
| 52 | 51 |
| 53 // Compute the screen orientation using the orientation angle and the screen | 52 // Compute the screen orientation using the orientation angle and the screen |
| 54 // width / height. | 53 // width / height. |
| 55 WebScreenOrientationType ScreenOrientationControllerImpl::computeOrientation( | 54 WebScreenOrientationType ScreenOrientationControllerImpl::computeOrientation( |
| 56 const IntRect& rect, | 55 const IntRect& rect, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 106 |
| 108 bool ScreenOrientationControllerImpl::isVisible() const { | 107 bool ScreenOrientationControllerImpl::isVisible() const { |
| 109 return page() && page()->isPageVisible(); | 108 return page() && page()->isPageVisible(); |
| 110 } | 109 } |
| 111 | 110 |
| 112 bool ScreenOrientationControllerImpl::isActiveAndVisible() const { | 111 bool ScreenOrientationControllerImpl::isActiveAndVisible() const { |
| 113 return isActive() && isVisible(); | 112 return isActive() && isVisible(); |
| 114 } | 113 } |
| 115 | 114 |
| 116 void ScreenOrientationControllerImpl::pageVisibilityChanged() { | 115 void ScreenOrientationControllerImpl::pageVisibilityChanged() { |
| 117 notifyDispatcher(); | 116 notifyAccurateListen(); |
| 118 | 117 |
| 119 if (!isActiveAndVisible()) | 118 if (!isActiveAndVisible()) |
| 120 return; | 119 return; |
| 121 | 120 |
| 122 DCHECK(frame()); | 121 DCHECK(frame()); |
| 123 DCHECK(frame()->host()); | 122 DCHECK(frame()->host()); |
| 124 | 123 |
| 125 // The orientation type and angle are tied in a way that if the angle has | 124 // The orientation type and angle are tied in a way that if the angle has |
| 126 // changed, the type must have changed. | 125 // changed, the type must have changed. |
| 127 unsigned short currentAngle = | 126 unsigned short currentAngle = |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 controller->notifyOrientationChanged(); | 164 controller->notifyOrientationChanged(); |
| 166 } | 165 } |
| 167 } | 166 } |
| 168 } | 167 } |
| 169 | 168 |
| 170 void ScreenOrientationControllerImpl::setOrientation( | 169 void ScreenOrientationControllerImpl::setOrientation( |
| 171 ScreenOrientation* orientation) { | 170 ScreenOrientation* orientation) { |
| 172 m_orientation = orientation; | 171 m_orientation = orientation; |
| 173 if (m_orientation) | 172 if (m_orientation) |
| 174 updateOrientation(); | 173 updateOrientation(); |
| 175 notifyDispatcher(); | 174 notifyAccurateListen(); |
| 176 } | 175 } |
| 177 | 176 |
| 178 void ScreenOrientationControllerImpl::lock( | 177 void ScreenOrientationControllerImpl::lock( |
| 179 WebScreenOrientationLockType orientation, | 178 WebScreenOrientationLockType orientation, |
| 180 std::unique_ptr<WebLockOrientationCallback> callback) { | 179 std::unique_ptr<WebLockOrientationCallback> callback) { |
| 181 // When detached, the client is no longer valid. | 180 // When detached, the client is no longer valid. |
| 182 if (!m_client) | 181 if (!m_client) |
| 183 return; | 182 return; |
| 184 m_client->lockOrientation(orientation, std::move(callback)); | 183 m_client->lockOrientation(orientation, std::move(callback)); |
| 185 m_activeLock = true; | 184 m_activeLock = true; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 198 } | 197 } |
| 199 | 198 |
| 200 void ScreenOrientationControllerImpl::dispatchEventTimerFired(TimerBase*) { | 199 void ScreenOrientationControllerImpl::dispatchEventTimerFired(TimerBase*) { |
| 201 if (!m_orientation) | 200 if (!m_orientation) |
| 202 return; | 201 return; |
| 203 | 202 |
| 204 ScopedOrientationChangeIndicator orientationChangeIndicator; | 203 ScopedOrientationChangeIndicator orientationChangeIndicator; |
| 205 m_orientation->dispatchEvent(Event::create(EventTypeNames::change)); | 204 m_orientation->dispatchEvent(Event::create(EventTypeNames::change)); |
| 206 } | 205 } |
| 207 | 206 |
| 208 void ScreenOrientationControllerImpl::didUpdateData() { | |
| 209 // Do nothing. | |
| 210 } | |
| 211 | |
| 212 void ScreenOrientationControllerImpl::registerWithDispatcher() { | |
| 213 ScreenOrientationDispatcher::instance().addController(this); | |
| 214 } | |
| 215 | |
| 216 void ScreenOrientationControllerImpl::unregisterWithDispatcher() { | |
| 217 ScreenOrientationDispatcher::instance().removeController(this); | |
| 218 } | |
| 219 | |
| 220 bool ScreenOrientationControllerImpl::hasLastData() { | |
| 221 return true; | |
| 222 } | |
| 223 | |
| 224 void ScreenOrientationControllerImpl::contextDestroyed(ExecutionContext*) { | 207 void ScreenOrientationControllerImpl::contextDestroyed(ExecutionContext*) { |
| 225 stopUpdating(); | 208 if (m_startedAccurateListen) { |
| 209 m_client->stopAccurateListen(); |
| 210 m_startedAccurateListen = false; |
| 211 } |
| 226 m_client = nullptr; | 212 m_client = nullptr; |
| 227 m_activeLock = false; | 213 m_activeLock = false; |
| 228 } | 214 } |
| 229 | 215 |
| 230 void ScreenOrientationControllerImpl::notifyDispatcher() { | 216 void ScreenOrientationControllerImpl::notifyAccurateListen() { |
| 231 if (m_orientation && page()->isPageVisible()) | 217 if (m_orientation && page()->isPageVisible()) { |
| 232 startUpdating(); | 218 // Timing to start accurate listening. |
| 233 else | 219 if (!m_startedAccurateListen) { |
| 234 stopUpdating(); | 220 m_client->startAccurateListen(); |
| 221 m_startedAccurateListen = true; |
| 222 } |
| 223 } else { |
| 224 // Timing to stop accurate listening. |
| 225 if (m_startedAccurateListen) { |
| 226 m_client->stopAccurateListen(); |
| 227 m_startedAccurateListen = false; |
| 228 } |
| 229 } |
| 235 } | 230 } |
| 236 | 231 |
| 237 DEFINE_TRACE(ScreenOrientationControllerImpl) { | 232 DEFINE_TRACE(ScreenOrientationControllerImpl) { |
| 238 visitor->trace(m_orientation); | 233 visitor->trace(m_orientation); |
| 239 ContextLifecycleObserver::trace(visitor); | 234 ContextLifecycleObserver::trace(visitor); |
| 240 Supplement<LocalFrame>::trace(visitor); | 235 Supplement<LocalFrame>::trace(visitor); |
| 241 PlatformEventController::trace(visitor); | 236 PageVisibilityObserver::trace(visitor); |
| 242 } | 237 } |
| 243 | 238 |
| 244 } // namespace blink | 239 } // namespace blink |
| OLD | NEW |