| 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" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 // ourselves. | 94 // ourselves. |
| 95 orientationType = computeOrientation(chromeClient.screenInfo().rect, | 95 orientationType = computeOrientation(chromeClient.screenInfo().rect, |
| 96 screenInfo.orientationAngle); | 96 screenInfo.orientationAngle); |
| 97 } | 97 } |
| 98 DCHECK(orientationType != WebScreenOrientationUndefined); | 98 DCHECK(orientationType != WebScreenOrientationUndefined); |
| 99 | 99 |
| 100 m_orientation->setType(orientationType); | 100 m_orientation->setType(orientationType); |
| 101 m_orientation->setAngle(screenInfo.orientationAngle); | 101 m_orientation->setAngle(screenInfo.orientationAngle); |
| 102 } | 102 } |
| 103 | 103 |
| 104 bool ScreenOrientationControllerImpl::isActive() const { |
| 105 return m_orientation && m_client; |
| 106 } |
| 107 |
| 108 bool ScreenOrientationControllerImpl::isVisible() const { |
| 109 return page() && page()->isPageVisible(); |
| 110 } |
| 111 |
| 104 bool ScreenOrientationControllerImpl::isActiveAndVisible() const { | 112 bool ScreenOrientationControllerImpl::isActiveAndVisible() const { |
| 105 return m_orientation && m_client && page() && page()->isPageVisible(); | 113 return isActive() && isVisible(); |
| 106 } | 114 } |
| 107 | 115 |
| 108 void ScreenOrientationControllerImpl::pageVisibilityChanged() { | 116 void ScreenOrientationControllerImpl::pageVisibilityChanged() { |
| 109 notifyDispatcher(); | 117 notifyDispatcher(); |
| 110 | 118 |
| 111 if (!isActiveAndVisible()) | 119 if (!isActiveAndVisible()) |
| 112 return; | 120 return; |
| 113 | 121 |
| 114 DCHECK(frame()); | 122 DCHECK(frame()); |
| 115 DCHECK(frame()->host()); | 123 DCHECK(frame()->host()); |
| 116 | 124 |
| 117 // The orientation type and angle are tied in a way that if the angle has | 125 // The orientation type and angle are tied in a way that if the angle has |
| 118 // changed, the type must have changed. | 126 // changed, the type must have changed. |
| 119 unsigned short currentAngle = | 127 unsigned short currentAngle = |
| 120 frame()->host()->chromeClient().screenInfo().orientationAngle; | 128 frame()->host()->chromeClient().screenInfo().orientationAngle; |
| 121 | 129 |
| 122 // FIXME: sendOrientationChangeEvent() currently send an event all the | 130 // FIXME: sendOrientationChangeEvent() currently send an event all the |
| 123 // children of the frame, so it should only be called on the frame on | 131 // children of the frame, so it should only be called on the frame on |
| 124 // top of the tree. We would need the embedder to call | 132 // top of the tree. We would need the embedder to call |
| 125 // sendOrientationChangeEvent on every WebFrame part of a WebView to be | 133 // sendOrientationChangeEvent on every WebFrame part of a WebView to be |
| 126 // able to remove this. | 134 // able to remove this. |
| 127 if (frame() == frame()->localFrameRoot() && | 135 if (frame() == frame()->localFrameRoot() && |
| 128 m_orientation->angle() != currentAngle) | 136 m_orientation->angle() != currentAngle) |
| 129 notifyOrientationChanged(); | 137 notifyOrientationChanged(); |
| 130 } | 138 } |
| 131 | 139 |
| 132 void ScreenOrientationControllerImpl::notifyOrientationChanged() { | 140 void ScreenOrientationControllerImpl::notifyOrientationChanged() { |
| 133 if (!isActiveAndVisible()) | 141 if (!isVisible()) |
| 134 return; | 142 return; |
| 135 | 143 |
| 136 updateOrientation(); | 144 if (isActive()) |
| 145 updateOrientation(); |
| 137 | 146 |
| 138 // Keep track of the frames that need to be notified before notifying the | 147 // Keep track of the frames that need to be notified before notifying the |
| 139 // current frame as it will prevent side effects from the change event | 148 // current frame as it will prevent side effects from the change event |
| 140 // handlers. | 149 // handlers. |
| 141 HeapVector<Member<LocalFrame>> childFrames; | 150 HeapVector<Member<LocalFrame>> childFrames; |
| 142 for (Frame* child = frame()->tree().firstChild(); child; | 151 for (Frame* child = frame()->tree().firstChild(); child; |
| 143 child = child->tree().nextSibling()) { | 152 child = child->tree().nextSibling()) { |
| 144 if (child->isLocalFrame()) | 153 if (child->isLocalFrame()) |
| 145 childFrames.push_back(toLocalFrame(child)); | 154 childFrames.push_back(toLocalFrame(child)); |
| 146 } | 155 } |
| 147 | 156 |
| 148 // Notify current orientation object. | 157 // Notify current orientation object. |
| 149 if (!m_dispatchEventTimer.isActive()) | 158 if (isActive() && !m_dispatchEventTimer.isActive()) |
| 150 m_dispatchEventTimer.startOneShot(0, BLINK_FROM_HERE); | 159 m_dispatchEventTimer.startOneShot(0, BLINK_FROM_HERE); |
| 151 | 160 |
| 152 // ... and child frames, if they have a ScreenOrientationControllerImpl. | 161 // ... and child frames, if they have a ScreenOrientationControllerImpl. |
| 153 for (size_t i = 0; i < childFrames.size(); ++i) { | 162 for (size_t i = 0; i < childFrames.size(); ++i) { |
| 154 if (ScreenOrientationControllerImpl* controller = | 163 if (ScreenOrientationControllerImpl* controller = |
| 155 ScreenOrientationControllerImpl::from(*childFrames[i])) | 164 ScreenOrientationControllerImpl::from(*childFrames[i])) { |
| 156 controller->notifyOrientationChanged(); | 165 controller->notifyOrientationChanged(); |
| 166 } |
| 157 } | 167 } |
| 158 } | 168 } |
| 159 | 169 |
| 160 void ScreenOrientationControllerImpl::setOrientation( | 170 void ScreenOrientationControllerImpl::setOrientation( |
| 161 ScreenOrientation* orientation) { | 171 ScreenOrientation* orientation) { |
| 162 m_orientation = orientation; | 172 m_orientation = orientation; |
| 163 if (m_orientation) | 173 if (m_orientation) |
| 164 updateOrientation(); | 174 updateOrientation(); |
| 165 notifyDispatcher(); | 175 notifyDispatcher(); |
| 166 } | 176 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 } | 235 } |
| 226 | 236 |
| 227 DEFINE_TRACE(ScreenOrientationControllerImpl) { | 237 DEFINE_TRACE(ScreenOrientationControllerImpl) { |
| 228 visitor->trace(m_orientation); | 238 visitor->trace(m_orientation); |
| 229 ContextLifecycleObserver::trace(visitor); | 239 ContextLifecycleObserver::trace(visitor); |
| 230 Supplement<LocalFrame>::trace(visitor); | 240 Supplement<LocalFrame>::trace(visitor); |
| 231 PlatformEventController::trace(visitor); | 241 PlatformEventController::trace(visitor); |
| 232 } | 242 } |
| 233 | 243 |
| 234 } // namespace blink | 244 } // namespace blink |
| OLD | NEW |