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