Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: Source/modules/screen_orientation/ScreenOrientationController.cpp

Issue 419643008: Make Screen Orientation use Platform Events in order to handle polling. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@platform_events
Patch Set: rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "platform/LayoutTestSupport.h" 14 #include "platform/LayoutTestSupport.h"
14 #include "platform/PlatformScreen.h" 15 #include "platform/PlatformScreen.h"
15 #include "public/platform/WebScreenOrientationClient.h" 16 #include "public/platform/WebScreenOrientationClient.h"
16 17
17 namespace blink { 18 namespace blink {
18 19
19 ScreenOrientationController::~ScreenOrientationController() 20 ScreenOrientationController::~ScreenOrientationController()
20 { 21 {
21 } 22 }
22 23
(...skipping 10 matching lines...) Expand all
33 ScreenOrientationController* controller = new ScreenOrientationController(fr ame, client); 34 ScreenOrientationController* controller = new ScreenOrientationController(fr ame, client);
34 WillBeHeapSupplement<LocalFrame>::provideTo(frame, supplementName(), adoptPt rWillBeNoop(controller)); 35 WillBeHeapSupplement<LocalFrame>::provideTo(frame, supplementName(), adoptPt rWillBeNoop(controller));
35 } 36 }
36 37
37 ScreenOrientationController* ScreenOrientationController::from(LocalFrame& frame ) 38 ScreenOrientationController* ScreenOrientationController::from(LocalFrame& frame )
38 { 39 {
39 return static_cast<ScreenOrientationController*>(WillBeHeapSupplement<LocalF rame>::from(frame, supplementName())); 40 return static_cast<ScreenOrientationController*>(WillBeHeapSupplement<LocalF rame>::from(frame, supplementName()));
40 } 41 }
41 42
42 ScreenOrientationController::ScreenOrientationController(LocalFrame& frame, blin k::WebScreenOrientationClient* client) 43 ScreenOrientationController::ScreenOrientationController(LocalFrame& frame, blin k::WebScreenOrientationClient* client)
43 : PageLifecycleObserver(frame.page()) 44 : PlatformEventController(frame.page())
44 , m_client(client) 45 , m_client(client)
45 , m_frame(frame) 46 , m_frame(frame)
46 , m_dispatchEventTimer(this, &ScreenOrientationController::dispatchEventTime rFired) 47 , m_dispatchEventTimer(this, &ScreenOrientationController::dispatchEventTime rFired)
47 { 48 {
48 } 49 }
49 50
50 const char* ScreenOrientationController::supplementName() 51 const char* ScreenOrientationController::supplementName()
51 { 52 {
52 return "ScreenOrientationController"; 53 return "ScreenOrientationController";
53 } 54 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 orientationType = computeOrientation(m_frame.view()); 90 orientationType = computeOrientation(m_frame.view());
90 } 91 }
91 ASSERT(orientationType != blink::WebScreenOrientationUndefined); 92 ASSERT(orientationType != blink::WebScreenOrientationUndefined);
92 93
93 m_orientation->setType(orientationType); 94 m_orientation->setType(orientationType);
94 m_orientation->setAngle(screenOrientationAngle(m_frame.view())); 95 m_orientation->setAngle(screenOrientationAngle(m_frame.view()));
95 } 96 }
96 97
97 void ScreenOrientationController::pageVisibilityChanged() 98 void ScreenOrientationController::pageVisibilityChanged()
98 { 99 {
100 notifyDispatcher();
101
99 if (!m_orientation || !page() || page()->visibilityState() != PageVisibility StateVisible) 102 if (!m_orientation || !page() || page()->visibilityState() != PageVisibility StateVisible)
100 return; 103 return;
101 104
102 // The orientation type and angle are tied in a way that if the angle has 105 // The orientation type and angle are tied in a way that if the angle has
103 // changed, the type must have changed. 106 // changed, the type must have changed.
104 unsigned short currentAngle = screenOrientationAngle(m_frame.view()); 107 unsigned short currentAngle = screenOrientationAngle(m_frame.view());
105 108
106 // FIXME: sendOrientationChangeEvent() currently send an event all the 109 // FIXME: sendOrientationChangeEvent() currently send an event all the
107 // children of the frame, so it should only be called on the frame on 110 // children of the frame, so it should only be called on the frame on
108 // top of the tree. We would need the embedder to call 111 // top of the tree. We would need the embedder to call
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 if (controller) 143 if (controller)
141 controller->notifyOrientationChanged(); 144 controller->notifyOrientationChanged();
142 } 145 }
143 } 146 }
144 147
145 void ScreenOrientationController::setOrientation(ScreenOrientation* orientation) 148 void ScreenOrientationController::setOrientation(ScreenOrientation* orientation)
146 { 149 {
147 m_orientation = orientation; 150 m_orientation = orientation;
148 if (m_orientation) 151 if (m_orientation)
149 updateOrientation(); 152 updateOrientation();
153 notifyDispatcher();
150 } 154 }
151 155
152 void ScreenOrientationController::lock(blink::WebScreenOrientationLockType orien tation, blink::WebLockOrientationCallback* callback) 156 void ScreenOrientationController::lock(blink::WebScreenOrientationLockType orien tation, blink::WebLockOrientationCallback* callback)
153 { 157 {
154 ASSERT(m_client); 158 ASSERT(m_client);
155 m_client->lockOrientation(orientation, callback); 159 m_client->lockOrientation(orientation, callback);
156 } 160 }
157 161
158 void ScreenOrientationController::unlock() 162 void ScreenOrientationController::unlock()
159 { 163 {
160 ASSERT(m_client); 164 ASSERT(m_client);
161 m_client->unlockOrientation(); 165 m_client->unlockOrientation();
162 } 166 }
163 167
164 const LocalFrame& ScreenOrientationController::frame() const 168 const LocalFrame& ScreenOrientationController::frame() const
165 { 169 {
166 return m_frame; 170 return m_frame;
167 } 171 }
168 172
169 void ScreenOrientationController::dispatchEventTimerFired(Timer<ScreenOrientatio nController>*) 173 void ScreenOrientationController::dispatchEventTimerFired(Timer<ScreenOrientatio nController>*)
170 { 174 {
171 if (!m_orientation) 175 if (!m_orientation)
172 return; 176 return;
173 m_orientation->dispatchEvent(Event::create(EventTypeNames::change)); 177 m_orientation->dispatchEvent(Event::create(EventTypeNames::change));
174 } 178 }
175 179
180 void ScreenOrientationController::didUpdateData()
181 {
182 // Do nothing.
183 }
184
185 void ScreenOrientationController::registerWithDispatcher()
186 {
187 ScreenOrientationDispatcher::instance().addController(this);
188 }
189
190 void ScreenOrientationController::unregisterWithDispatcher()
191 {
192 ScreenOrientationDispatcher::instance().removeController(this);
193 }
194
195 bool ScreenOrientationController::hasLastData()
196 {
197 return true;
198 }
199
200 void ScreenOrientationController::notifyDispatcher()
201 {
202 if (m_orientation && page()->visibilityState() == PageVisibilityStateVisible )
203 startUpdating();
204 else
205 stopUpdating();
206 }
207
176 void ScreenOrientationController::trace(Visitor* visitor) 208 void ScreenOrientationController::trace(Visitor* visitor)
177 { 209 {
178 visitor->trace(m_orientation); 210 visitor->trace(m_orientation);
179 WillBeHeapSupplement<LocalFrame>::trace(visitor); 211 WillBeHeapSupplement<LocalFrame>::trace(visitor);
180 } 212 }
181 213
182 } // namespace blink 214 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698