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" | |
8 #include "core/events/Event.h" | 10 #include "core/events/Event.h" |
9 #include "core/frame/FrameView.h" | 11 #include "core/frame/FrameView.h" |
10 #include "core/frame/LocalFrame.h" | 12 #include "core/frame/LocalFrame.h" |
11 #include "core/page/Page.h" | 13 #include "core/page/Page.h" |
12 #include "modules/screen_orientation/ScreenOrientation.h" | 14 #include "modules/screen_orientation/ScreenOrientation.h" |
13 #include "modules/screen_orientation/ScreenOrientationDispatcher.h" | 15 #include "modules/screen_orientation/ScreenOrientationDispatcher.h" |
14 #include "platform/LayoutTestSupport.h" | 16 #include "platform/LayoutTestSupport.h" |
15 #include "platform/PlatformScreen.h" | 17 #include "platform/PlatformScreen.h" |
16 #include "public/platform/WebScreenOrientationClient.h" | 18 #include "public/platform/WebScreenOrientationClient.h" |
17 | 19 |
(...skipping 13 matching lines...) Expand all Loading... | |
31 | 33 |
32 ScreenOrientationController* ScreenOrientationController::from(LocalFrame& frame ) | 34 ScreenOrientationController* ScreenOrientationController::from(LocalFrame& frame ) |
33 { | 35 { |
34 return static_cast<ScreenOrientationController*>(WillBeHeapSupplement<LocalF rame>::from(frame, supplementName())); | 36 return static_cast<ScreenOrientationController*>(WillBeHeapSupplement<LocalF rame>::from(frame, supplementName())); |
35 } | 37 } |
36 | 38 |
37 ScreenOrientationController::ScreenOrientationController(LocalFrame& frame, WebS creenOrientationClient* client) | 39 ScreenOrientationController::ScreenOrientationController(LocalFrame& frame, WebS creenOrientationClient* client) |
38 : LocalFrameLifecycleObserver(&frame) | 40 : LocalFrameLifecycleObserver(&frame) |
39 , PlatformEventController(frame.page()) | 41 , PlatformEventController(frame.page()) |
40 , m_client(client) | 42 , m_client(client) |
41 , m_dispatchEventTimer(this, &ScreenOrientationController::dispatchEventTime rFired) | 43 , m_isDispatchingEvent(false) |
42 { | 44 { |
43 } | 45 } |
44 | 46 |
45 const char* ScreenOrientationController::supplementName() | 47 const char* ScreenOrientationController::supplementName() |
46 { | 48 { |
47 return "ScreenOrientationController"; | 49 return "ScreenOrientationController"; |
48 } | 50 } |
49 | 51 |
50 // 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. |
51 WebScreenOrientationType ScreenOrientationController::computeOrientation(FrameVi ew* view) | 53 WebScreenOrientationType ScreenOrientationController::computeOrientation(FrameVi ew* view) |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 // Keep track of the frames that need to be notified before notifying the | 130 // Keep track of the frames that need to be notified before notifying the |
129 // current frame as it will prevent side effects from the change event | 131 // current frame as it will prevent side effects from the change event |
130 // handlers. | 132 // handlers. |
131 WillBeHeapVector<RefPtrWillBeMember<LocalFrame>> childFrames; | 133 WillBeHeapVector<RefPtrWillBeMember<LocalFrame>> childFrames; |
132 for (Frame* child = frame()->tree().firstChild(); child; child = child->tree ().nextSibling()) { | 134 for (Frame* child = frame()->tree().firstChild(); child; child = child->tree ().nextSibling()) { |
133 if (child->isLocalFrame()) | 135 if (child->isLocalFrame()) |
134 childFrames.append(toLocalFrame(child)); | 136 childFrames.append(toLocalFrame(child)); |
135 } | 137 } |
136 | 138 |
137 // Notify current orientation object. | 139 // Notify current orientation object. |
138 if (!m_dispatchEventTimer.isActive()) | 140 if (!m_isDispatchingEvent) { |
139 m_dispatchEventTimer.startOneShot(0, FROM_HERE); | 141 if (Document* document = frame()->document()) { |
142 document->postTask(FROM_HERE, createSameThreadTask(&ScreenOrientatio nController::dispatchChangeEvent, this)); | |
alex clarke (OOO till 29th)
2015/04/15 09:27:32
FYI the blink scheduler team are thinking of addin
| |
143 m_isDispatchingEvent = true; | |
144 } | |
145 } | |
140 | 146 |
141 // ... and child frames, if they have a ScreenOrientationController. | 147 // ... and child frames, if they have a ScreenOrientationController. |
142 for (size_t i = 0; i < childFrames.size(); ++i) { | 148 for (size_t i = 0; i < childFrames.size(); ++i) { |
143 if (ScreenOrientationController* controller = ScreenOrientationControlle r::from(*childFrames[i])) | 149 if (ScreenOrientationController* controller = ScreenOrientationControlle r::from(*childFrames[i])) |
144 controller->notifyOrientationChanged(); | 150 controller->notifyOrientationChanged(); |
145 } | 151 } |
146 } | 152 } |
147 | 153 |
148 void ScreenOrientationController::setOrientation(ScreenOrientation* orientation) | 154 void ScreenOrientationController::setOrientation(ScreenOrientation* orientation) |
149 { | 155 { |
(...skipping 12 matching lines...) Expand all Loading... | |
162 } | 168 } |
163 | 169 |
164 void ScreenOrientationController::unlock() | 170 void ScreenOrientationController::unlock() |
165 { | 171 { |
166 // When detached, the client is no longer valid. | 172 // When detached, the client is no longer valid. |
167 if (!m_client) | 173 if (!m_client) |
168 return; | 174 return; |
169 m_client->unlockOrientation(); | 175 m_client->unlockOrientation(); |
170 } | 176 } |
171 | 177 |
172 void ScreenOrientationController::dispatchEventTimerFired(Timer<ScreenOrientatio nController>*) | 178 void ScreenOrientationController::dispatchChangeEvent() |
173 { | 179 { |
180 m_isDispatchingEvent = false; | |
174 if (!m_orientation) | 181 if (!m_orientation) |
175 return; | 182 return; |
176 m_orientation->dispatchEvent(Event::create(EventTypeNames::change)); | 183 m_orientation->dispatchEvent(Event::create(EventTypeNames::change)); |
177 } | 184 } |
178 | 185 |
179 void ScreenOrientationController::didUpdateData() | 186 void ScreenOrientationController::didUpdateData() |
180 { | 187 { |
181 // Do nothing. | 188 // Do nothing. |
182 } | 189 } |
183 | 190 |
(...skipping 27 matching lines...) Expand all Loading... | |
211 | 218 |
212 DEFINE_TRACE(ScreenOrientationController) | 219 DEFINE_TRACE(ScreenOrientationController) |
213 { | 220 { |
214 visitor->trace(m_orientation); | 221 visitor->trace(m_orientation); |
215 LocalFrameLifecycleObserver::trace(visitor); | 222 LocalFrameLifecycleObserver::trace(visitor); |
216 WillBeHeapSupplement<LocalFrame>::trace(visitor); | 223 WillBeHeapSupplement<LocalFrame>::trace(visitor); |
217 PlatformEventController::trace(visitor); | 224 PlatformEventController::trace(visitor); |
218 } | 225 } |
219 | 226 |
220 } // namespace blink | 227 } // namespace blink |
OLD | NEW |