Chromium Code Reviews| 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/dom/Document.h" | |
| 9 #include "core/dom/ExecutionContextTask.h" | |
| 10 #include "core/events/Event.h" | 8 #include "core/events/Event.h" |
| 11 #include "core/frame/FrameHost.h" | 9 #include "core/frame/FrameHost.h" |
| 12 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
| 13 #include "core/frame/LocalFrame.h" | 11 #include "core/frame/LocalFrame.h" |
| 14 #include "core/page/ChromeClient.h" | 12 #include "core/page/ChromeClient.h" |
| 15 #include "core/page/Page.h" | 13 #include "core/page/Page.h" |
| 16 #include "modules/screen_orientation/ScreenOrientation.h" | 14 #include "modules/screen_orientation/ScreenOrientation.h" |
| 17 #include "modules/screen_orientation/ScreenOrientationDispatcher.h" | 15 #include "modules/screen_orientation/ScreenOrientationDispatcher.h" |
| 18 #include "platform/LayoutTestSupport.h" | 16 #include "platform/LayoutTestSupport.h" |
| 19 #include "public/platform/WebScreenInfo.h" | 17 #include "public/platform/WebScreenInfo.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 35 | 33 |
| 36 ScreenOrientationController* ScreenOrientationController::from(LocalFrame& frame ) | 34 ScreenOrientationController* ScreenOrientationController::from(LocalFrame& frame ) |
| 37 { | 35 { |
| 38 return static_cast<ScreenOrientationController*>(WillBeHeapSupplement<LocalF rame>::from(frame, supplementName())); | 36 return static_cast<ScreenOrientationController*>(WillBeHeapSupplement<LocalF rame>::from(frame, supplementName())); |
| 39 } | 37 } |
| 40 | 38 |
| 41 ScreenOrientationController::ScreenOrientationController(LocalFrame& frame, WebS creenOrientationClient* client) | 39 ScreenOrientationController::ScreenOrientationController(LocalFrame& frame, WebS creenOrientationClient* client) |
| 42 : LocalFrameLifecycleObserver(&frame) | 40 : LocalFrameLifecycleObserver(&frame) |
| 43 , PlatformEventController(frame.page()) | 41 , PlatformEventController(frame.page()) |
| 44 , m_client(client) | 42 , m_client(client) |
| 45 , m_isDispatchingEvent(false) | 43 , m_dispatchEventTimer(this, &ScreenOrientationController::dispatchEventTime rFired) |
| 46 { | 44 { |
| 47 } | 45 } |
| 48 | 46 |
| 49 const char* ScreenOrientationController::supplementName() | 47 const char* ScreenOrientationController::supplementName() |
| 50 { | 48 { |
| 51 return "ScreenOrientationController"; | 49 return "ScreenOrientationController"; |
| 52 } | 50 } |
| 53 | 51 |
| 54 // Compute the screen orientation using the orientation angle and the screen wid th / height. | 52 // Compute the screen orientation using the orientation angle and the screen wid th / height. |
| 55 WebScreenOrientationType ScreenOrientationController::computeOrientation(ChromeC lient& chromeClient) | 53 WebScreenOrientationType ScreenOrientationController::computeOrientation(ChromeC lient& chromeClient) |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 // Keep track of the frames that need to be notified before notifying the | 131 // Keep track of the frames that need to be notified before notifying the |
| 134 // current frame as it will prevent side effects from the change event | 132 // current frame as it will prevent side effects from the change event |
| 135 // handlers. | 133 // handlers. |
| 136 WillBeHeapVector<RefPtrWillBeMember<LocalFrame>> childFrames; | 134 WillBeHeapVector<RefPtrWillBeMember<LocalFrame>> childFrames; |
| 137 for (Frame* child = frame()->tree().firstChild(); child; child = child->tree ().nextSibling()) { | 135 for (Frame* child = frame()->tree().firstChild(); child; child = child->tree ().nextSibling()) { |
| 138 if (child->isLocalFrame()) | 136 if (child->isLocalFrame()) |
| 139 childFrames.append(toLocalFrame(child)); | 137 childFrames.append(toLocalFrame(child)); |
| 140 } | 138 } |
| 141 | 139 |
| 142 // Notify current orientation object. | 140 // Notify current orientation object. |
| 143 if (!m_isDispatchingEvent) { | 141 if (!m_dispatchEventTimer.isActive()) |
| 144 if (Document* document = frame()->document()) { | 142 m_dispatchEventTimer.startOneShot(0, FROM_HERE); |
|
haraken
2015/06/19 11:04:15
Would you help me understand why the new code is s
sof
2015/06/19 11:08:27
This controller owns the timer, so it'll be finali
haraken
2015/06/19 11:11:40
Ah, makes sense. LGTM.
| |
| 145 document->postTask(FROM_HERE, createSameThreadTask(&ScreenOrientatio nController::dispatchChangeEvent, this)); | |
| 146 m_isDispatchingEvent = true; | |
| 147 } | |
| 148 } | |
| 149 | 143 |
| 150 // ... and child frames, if they have a ScreenOrientationController. | 144 // ... and child frames, if they have a ScreenOrientationController. |
| 151 for (size_t i = 0; i < childFrames.size(); ++i) { | 145 for (size_t i = 0; i < childFrames.size(); ++i) { |
| 152 if (ScreenOrientationController* controller = ScreenOrientationControlle r::from(*childFrames[i])) | 146 if (ScreenOrientationController* controller = ScreenOrientationControlle r::from(*childFrames[i])) |
| 153 controller->notifyOrientationChanged(); | 147 controller->notifyOrientationChanged(); |
| 154 } | 148 } |
| 155 } | 149 } |
| 156 | 150 |
| 157 void ScreenOrientationController::setOrientation(ScreenOrientation* orientation) | 151 void ScreenOrientationController::setOrientation(ScreenOrientation* orientation) |
| 158 { | 152 { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 171 } | 165 } |
| 172 | 166 |
| 173 void ScreenOrientationController::unlock() | 167 void ScreenOrientationController::unlock() |
| 174 { | 168 { |
| 175 // When detached, the client is no longer valid. | 169 // When detached, the client is no longer valid. |
| 176 if (!m_client) | 170 if (!m_client) |
| 177 return; | 171 return; |
| 178 m_client->unlockOrientation(); | 172 m_client->unlockOrientation(); |
| 179 } | 173 } |
| 180 | 174 |
| 181 void ScreenOrientationController::dispatchChangeEvent() | 175 void ScreenOrientationController::dispatchEventTimerFired(Timer<ScreenOrientatio nController>*) |
| 182 { | 176 { |
| 183 m_isDispatchingEvent = false; | |
| 184 if (!m_orientation) | 177 if (!m_orientation) |
| 185 return; | 178 return; |
| 186 m_orientation->dispatchEvent(Event::create(EventTypeNames::change)); | 179 m_orientation->dispatchEvent(Event::create(EventTypeNames::change)); |
| 187 } | 180 } |
| 188 | 181 |
| 189 void ScreenOrientationController::didUpdateData() | 182 void ScreenOrientationController::didUpdateData() |
| 190 { | 183 { |
| 191 // Do nothing. | 184 // Do nothing. |
| 192 } | 185 } |
| 193 | 186 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 221 | 214 |
| 222 DEFINE_TRACE(ScreenOrientationController) | 215 DEFINE_TRACE(ScreenOrientationController) |
| 223 { | 216 { |
| 224 visitor->trace(m_orientation); | 217 visitor->trace(m_orientation); |
| 225 LocalFrameLifecycleObserver::trace(visitor); | 218 LocalFrameLifecycleObserver::trace(visitor); |
| 226 WillBeHeapSupplement<LocalFrame>::trace(visitor); | 219 WillBeHeapSupplement<LocalFrame>::trace(visitor); |
| 227 PlatformEventController::trace(visitor); | 220 PlatformEventController::trace(visitor); |
| 228 } | 221 } |
| 229 | 222 |
| 230 } // namespace blink | 223 } // namespace blink |
| OLD | NEW |