| 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/ScreenOrientationController.h" | 6 #include "modules/screen_orientation/ScreenOrientationController.h" |
| 7 | 7 |
| 8 #include "core/events/Event.h" | 8 #include "core/events/Event.h" |
| 9 #include "core/frame/FrameView.h" | 9 #include "core/frame/FrameView.h" |
| 10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
| 11 #include "core/page/Page.h" | 11 #include "core/page/Page.h" |
| 12 #include "modules/screen_orientation/ScreenOrientation.h" | 12 #include "modules/screen_orientation/ScreenOrientation.h" |
| 13 #include "modules/screen_orientation/ScreenOrientationDispatcher.h" | 13 #include "modules/screen_orientation/ScreenOrientationDispatcher.h" |
| 14 #include "platform/LayoutTestSupport.h" | 14 #include "platform/LayoutTestSupport.h" |
| 15 #include "platform/PlatformScreen.h" | 15 #include "platform/PlatformScreen.h" |
| 16 #include "public/platform/WebScreenOrientationClient.h" | 16 #include "public/platform/WebScreenOrientationClient.h" |
| 17 | 17 |
| 18 namespace blink { | 18 namespace blink { |
| 19 | 19 |
| 20 ScreenOrientationController::~ScreenOrientationController() | 20 ScreenOrientationController::~ScreenOrientationController() |
| 21 { | 21 { |
| 22 } | 22 } |
| 23 | 23 |
| 24 void ScreenOrientationController::persistentHostHasBeenDestroyed() | |
| 25 { | |
| 26 // Unregister lifecycle observation once page is being torn down. | |
| 27 observeContext(0); | |
| 28 } | |
| 29 | |
| 30 void ScreenOrientationController::provideTo(LocalFrame& frame, WebScreenOrientat
ionClient* client) | 24 void ScreenOrientationController::provideTo(LocalFrame& frame, WebScreenOrientat
ionClient* client) |
| 31 { | 25 { |
| 32 ASSERT(RuntimeEnabledFeatures::screenOrientationEnabled()); | 26 ASSERT(RuntimeEnabledFeatures::screenOrientationEnabled()); |
| 33 | 27 |
| 34 ScreenOrientationController* controller = new ScreenOrientationController(fr
ame, client); | 28 ScreenOrientationController* controller = new ScreenOrientationController(fr
ame, client); |
| 35 WillBeHeapSupplement<LocalFrame>::provideTo(frame, supplementName(), adoptPt
rWillBeNoop(controller)); | 29 WillBeHeapSupplement<LocalFrame>::provideTo(frame, supplementName(), adoptPt
rWillBeNoop(controller)); |
| 36 } | 30 } |
| 37 | 31 |
| 38 ScreenOrientationController* ScreenOrientationController::from(LocalFrame& frame
) | 32 ScreenOrientationController* ScreenOrientationController::from(LocalFrame& frame
) |
| 39 { | 33 { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 ASSERT(RuntimeEnabledFeatures::screenOrientationEnabled()); | 114 ASSERT(RuntimeEnabledFeatures::screenOrientationEnabled()); |
| 121 | 115 |
| 122 if (!m_orientation || !page() || page()->visibilityState() != PageVisibility
StateVisible) | 116 if (!m_orientation || !page() || page()->visibilityState() != PageVisibility
StateVisible) |
| 123 return; | 117 return; |
| 124 | 118 |
| 125 updateOrientation(); | 119 updateOrientation(); |
| 126 | 120 |
| 127 // Keep track of the frames that need to be notified before notifying the | 121 // Keep track of the frames that need to be notified before notifying the |
| 128 // current frame as it will prevent side effects from the change event | 122 // current frame as it will prevent side effects from the change event |
| 129 // handlers. | 123 // handlers. |
| 130 Vector<RefPtr<LocalFrame> > childFrames; | 124 WillBeHeapVector<RefPtrWillBeMember<LocalFrame> > childFrames; |
| 131 for (Frame* child = m_frame.tree().firstChild(); child; child = child->tree(
).nextSibling()) { | 125 for (Frame* child = m_frame.tree().firstChild(); child; child = child->tree(
).nextSibling()) { |
| 132 if (child->isLocalFrame()) | 126 if (child->isLocalFrame()) |
| 133 childFrames.append(toLocalFrame(child)); | 127 childFrames.append(toLocalFrame(child)); |
| 134 } | 128 } |
| 135 | 129 |
| 136 // Notify current orientation object. | 130 // Notify current orientation object. |
| 137 if (!m_dispatchEventTimer.isActive()) | 131 if (!m_dispatchEventTimer.isActive()) |
| 138 m_dispatchEventTimer.startOneShot(0, FROM_HERE); | 132 m_dispatchEventTimer.startOneShot(0, FROM_HERE); |
| 139 | 133 |
| 140 // ... and child frames, if they have a ScreenOrientationController. | 134 // ... and child frames, if they have a ScreenOrientationController. |
| 141 for (size_t i = 0; i < childFrames.size(); ++i) { | 135 for (size_t i = 0; i < childFrames.size(); ++i) { |
| 142 ScreenOrientationController* controller = ScreenOrientationController::f
rom(*childFrames[i]); | 136 if (ScreenOrientationController* controller = ScreenOrientationControlle
r::from(*childFrames[i])) |
| 143 if (controller) | |
| 144 controller->notifyOrientationChanged(); | 137 controller->notifyOrientationChanged(); |
| 145 } | 138 } |
| 146 } | 139 } |
| 147 | 140 |
| 148 void ScreenOrientationController::setOrientation(ScreenOrientation* orientation) | 141 void ScreenOrientationController::setOrientation(ScreenOrientation* orientation) |
| 149 { | 142 { |
| 150 m_orientation = orientation; | 143 m_orientation = orientation; |
| 151 if (m_orientation) | 144 if (m_orientation) |
| 152 updateOrientation(); | 145 updateOrientation(); |
| 153 notifyDispatcher(); | 146 notifyDispatcher(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 stopUpdating(); | 198 stopUpdating(); |
| 206 } | 199 } |
| 207 | 200 |
| 208 void ScreenOrientationController::trace(Visitor* visitor) | 201 void ScreenOrientationController::trace(Visitor* visitor) |
| 209 { | 202 { |
| 210 visitor->trace(m_orientation); | 203 visitor->trace(m_orientation); |
| 211 WillBeHeapSupplement<LocalFrame>::trace(visitor); | 204 WillBeHeapSupplement<LocalFrame>::trace(visitor); |
| 212 } | 205 } |
| 213 | 206 |
| 214 } // namespace blink | 207 } // namespace blink |
| OLD | NEW |