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

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

Issue 1195793008: [DevTools] Implement screen orientation override. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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 | Annotate | Revision Log
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/FrameHost.h" 9 #include "core/frame/FrameHost.h"
10 #include "core/frame/FrameView.h" 10 #include "core/frame/FrameView.h"
(...skipping 23 matching lines...) Expand all
34 ScreenOrientationController* ScreenOrientationController::from(LocalFrame& frame ) 34 ScreenOrientationController* ScreenOrientationController::from(LocalFrame& frame )
35 { 35 {
36 return static_cast<ScreenOrientationController*>(WillBeHeapSupplement<LocalF rame>::from(frame, supplementName())); 36 return static_cast<ScreenOrientationController*>(WillBeHeapSupplement<LocalF rame>::from(frame, supplementName()));
37 } 37 }
38 38
39 ScreenOrientationController::ScreenOrientationController(LocalFrame& frame, WebS creenOrientationClient* client) 39 ScreenOrientationController::ScreenOrientationController(LocalFrame& frame, WebS creenOrientationClient* client)
40 : LocalFrameLifecycleObserver(&frame) 40 : LocalFrameLifecycleObserver(&frame)
41 , PlatformEventController(frame.page()) 41 , PlatformEventController(frame.page())
42 , m_client(client) 42 , m_client(client)
43 , m_dispatchEventTimer(this, &ScreenOrientationController::dispatchEventTime rFired) 43 , m_dispatchEventTimer(this, &ScreenOrientationController::dispatchEventTime rFired)
44 , m_override(false)
45 , m_overrideType(WebScreenOrientationUndefined)
46 , m_overrideAngle(0)
44 { 47 {
45 } 48 }
46 49
47 const char* ScreenOrientationController::supplementName() 50 const char* ScreenOrientationController::supplementName()
48 { 51 {
49 return "ScreenOrientationController"; 52 return "ScreenOrientationController";
50 } 53 }
51 54
52 // Compute the screen orientation using the orientation angle and the screen wid th / height. 55 // Compute the screen orientation using the orientation angle and the screen wid th / height.
53 WebScreenOrientationType ScreenOrientationController::computeOrientation(ChromeC lient& chromeClient) 56 WebScreenOrientationType ScreenOrientationController::computeOrientation(ChromeC lient& chromeClient)
(...skipping 22 matching lines...) Expand all
76 } 79 }
77 } 80 }
78 81
79 void ScreenOrientationController::updateOrientation() 82 void ScreenOrientationController::updateOrientation()
80 { 83 {
81 ASSERT(m_orientation); 84 ASSERT(m_orientation);
82 ASSERT(frame()); 85 ASSERT(frame());
83 ASSERT(frame()->host()); 86 ASSERT(frame()->host());
84 87
85 ChromeClient& chromeClient = frame()->host()->chromeClient(); 88 ChromeClient& chromeClient = frame()->host()->chromeClient();
86 WebScreenOrientationType orientationType = chromeClient.screenInfo().orienta tionType; 89 unsigned short orientationAngle = m_override ? m_overrideAngle : chromeClien t.screenInfo().orientationAngle;
90 WebScreenOrientationType orientationType = m_override ? m_overrideType : chr omeClient.screenInfo().orientationType;
87 if (orientationType == WebScreenOrientationUndefined) { 91 if (orientationType == WebScreenOrientationUndefined) {
88 // The embedder could not provide us with an orientation, deduce it ours elves. 92 // The embedder could not provide us with an orientation, deduce it ours elves.
89 orientationType = computeOrientation(chromeClient); 93 orientationType = computeOrientation(chromeClient);
90 } 94 }
91 ASSERT(orientationType != WebScreenOrientationUndefined); 95 ASSERT(orientationType != WebScreenOrientationUndefined);
92 96
93 m_orientation->setType(orientationType); 97 m_orientation->setType(orientationType);
94 m_orientation->setAngle(chromeClient.screenInfo().orientationAngle); 98 m_orientation->setAngle(orientationAngle);
95 } 99 }
96 100
97 bool ScreenOrientationController::isActiveAndVisible() const 101 bool ScreenOrientationController::isActiveAndVisible() const
98 { 102 {
99 return m_orientation && frame() && page() && page()->visibilityState() == Pa geVisibilityStateVisible; 103 return m_orientation && frame() && page() && page()->visibilityState() == Pa geVisibilityStateVisible;
100 } 104 }
101 105
102 void ScreenOrientationController::pageVisibilityChanged() 106 void ScreenOrientationController::pageVisibilityChanged()
103 { 107 {
104 notifyDispatcher(); 108 notifyDispatcher();
105 109
106 if (!isActiveAndVisible()) 110 if (!isActiveAndVisible())
107 return; 111 return;
108 112
109 // The orientation type and angle are tied in a way that if the angle has 113 // The orientation type and angle are tied in a way that if the angle has
110 // changed, the type must have changed. 114 // changed, the type must have changed.
111 unsigned short currentAngle = frame()->host()->chromeClient().screenInfo().o rientationAngle; 115 unsigned short currentAngle = m_override ? m_overrideAngle : frame()->host() ->chromeClient().screenInfo().orientationAngle;
mlamouri (slow - plz ping) 2015/06/24 16:51:06 nit: could you have in internal method that does t
dgozman 2015/06/25 12:21:26 Done.
112 116
113 // FIXME: sendOrientationChangeEvent() currently send an event all the 117 // FIXME: sendOrientationChangeEvent() currently send an event all the
114 // children of the frame, so it should only be called on the frame on 118 // children of the frame, so it should only be called on the frame on
115 // top of the tree. We would need the embedder to call 119 // top of the tree. We would need the embedder to call
116 // sendOrientationChangeEvent on every WebFrame part of a WebView to be 120 // sendOrientationChangeEvent on every WebFrame part of a WebView to be
117 // able to remove this. 121 // able to remove this.
118 if (frame() == frame()->localFrameRoot() && m_orientation->angle() != curren tAngle) 122 if (frame() == frame()->localFrameRoot() && m_orientation->angle() != curren tAngle)
119 notifyOrientationChanged(); 123 notifyOrientationChanged();
120 } 124 }
121 125
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 } 169 }
166 170
167 void ScreenOrientationController::unlock() 171 void ScreenOrientationController::unlock()
168 { 172 {
169 // When detached, the client is no longer valid. 173 // When detached, the client is no longer valid.
170 if (!m_client) 174 if (!m_client)
171 return; 175 return;
172 m_client->unlockOrientation(); 176 m_client->unlockOrientation();
173 } 177 }
174 178
179 void ScreenOrientationController::setOverride(WebScreenOrientationType type, uns igned short angle)
180 {
181 m_override = true;
182 m_overrideType = type;
183 m_overrideAngle = angle;
184 notifyOrientationChanged();
185 }
186
187 void ScreenOrientationController::clearOverride()
188 {
189 m_override = false;
190 notifyOrientationChanged();
191 }
192
175 void ScreenOrientationController::dispatchEventTimerFired(Timer<ScreenOrientatio nController>*) 193 void ScreenOrientationController::dispatchEventTimerFired(Timer<ScreenOrientatio nController>*)
176 { 194 {
177 if (!m_orientation) 195 if (!m_orientation)
178 return; 196 return;
179 m_orientation->dispatchEvent(Event::create(EventTypeNames::change)); 197 m_orientation->dispatchEvent(Event::create(EventTypeNames::change));
180 } 198 }
181 199
182 void ScreenOrientationController::didUpdateData() 200 void ScreenOrientationController::didUpdateData()
183 { 201 {
184 // Do nothing. 202 // Do nothing.
(...skipping 29 matching lines...) Expand all
214 232
215 DEFINE_TRACE(ScreenOrientationController) 233 DEFINE_TRACE(ScreenOrientationController)
216 { 234 {
217 visitor->trace(m_orientation); 235 visitor->trace(m_orientation);
218 LocalFrameLifecycleObserver::trace(visitor); 236 LocalFrameLifecycleObserver::trace(visitor);
219 WillBeHeapSupplement<LocalFrame>::trace(visitor); 237 WillBeHeapSupplement<LocalFrame>::trace(visitor);
220 PlatformEventController::trace(visitor); 238 PlatformEventController::trace(visitor);
221 } 239 }
222 240
223 } // namespace blink 241 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698