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

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

Issue 1722643003: Reland of [DevTools] Move screen orientation override to RenderWidgetScreenMetricsEmulator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 "modules/screen_orientation/ScreenOrientationController.h" 5 #include "modules/screen_orientation/ScreenOrientationController.h"
6 6
7 #include "core/events/Event.h" 7 #include "core/events/Event.h"
8 #include "core/frame/FrameHost.h" 8 #include "core/frame/FrameHost.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"
(...skipping 22 matching lines...) Expand all
33 ScreenOrientationController* ScreenOrientationController::from(LocalFrame& frame ) 33 ScreenOrientationController* ScreenOrientationController::from(LocalFrame& frame )
34 { 34 {
35 return static_cast<ScreenOrientationController*>(WillBeHeapSupplement<LocalF rame>::from(frame, supplementName())); 35 return static_cast<ScreenOrientationController*>(WillBeHeapSupplement<LocalF rame>::from(frame, supplementName()));
36 } 36 }
37 37
38 ScreenOrientationController::ScreenOrientationController(LocalFrame& frame, WebS creenOrientationClient* client) 38 ScreenOrientationController::ScreenOrientationController(LocalFrame& frame, WebS creenOrientationClient* client)
39 : LocalFrameLifecycleObserver(&frame) 39 : LocalFrameLifecycleObserver(&frame)
40 , PlatformEventController(frame.page()) 40 , PlatformEventController(frame.page())
41 , m_client(client) 41 , m_client(client)
42 , m_dispatchEventTimer(this, &ScreenOrientationController::dispatchEventTime rFired) 42 , m_dispatchEventTimer(this, &ScreenOrientationController::dispatchEventTime rFired)
43 , m_override(false)
44 , m_overrideType(WebScreenOrientationUndefined)
45 , m_overrideAngle(0)
46 { 43 {
47 } 44 }
48 45
49 const char* ScreenOrientationController::supplementName() 46 const char* ScreenOrientationController::supplementName()
50 { 47 {
51 return "ScreenOrientationController"; 48 return "ScreenOrientationController";
52 } 49 }
53 50
54 // Compute the screen orientation using the orientation angle and the screen wid th / height. 51 // Compute the screen orientation using the orientation angle and the screen wid th / height.
55 WebScreenOrientationType ScreenOrientationController::computeOrientation(const I ntRect& rect, uint16_t rotation) 52 WebScreenOrientationType ScreenOrientationController::computeOrientation(const I ntRect& rect, uint16_t rotation)
(...skipping 13 matching lines...) Expand all
69 case 180: 66 case 180:
70 return isTallDisplay ? WebScreenOrientationPortraitSecondary : WebScreen OrientationLandscapeSecondary; 67 return isTallDisplay ? WebScreenOrientationPortraitSecondary : WebScreen OrientationLandscapeSecondary;
71 case 270: 68 case 270:
72 return isTallDisplay ? WebScreenOrientationLandscapeSecondary : WebScree nOrientationPortraitPrimary; 69 return isTallDisplay ? WebScreenOrientationLandscapeSecondary : WebScree nOrientationPortraitPrimary;
73 default: 70 default:
74 ASSERT_NOT_REACHED(); 71 ASSERT_NOT_REACHED();
75 return WebScreenOrientationPortraitPrimary; 72 return WebScreenOrientationPortraitPrimary;
76 } 73 }
77 } 74 }
78 75
79 unsigned short ScreenOrientationController::effectiveAngle(ChromeClient& chromeC lient)
80 {
81 return m_override ? m_overrideAngle : chromeClient.screenInfo().orientationA ngle;
82 }
83
84 WebScreenOrientationType ScreenOrientationController::effectiveType(ChromeClient & chromeClient)
85 {
86 return m_override ? m_overrideType : chromeClient.screenInfo().orientationTy pe;
87 }
88
89 void ScreenOrientationController::updateOrientation() 76 void ScreenOrientationController::updateOrientation()
90 { 77 {
91 ASSERT(m_orientation); 78 ASSERT(m_orientation);
92 ASSERT(frame()); 79 ASSERT(frame());
93 ASSERT(frame()->host()); 80 ASSERT(frame()->host());
94 81
95 ChromeClient& chromeClient = frame()->host()->chromeClient(); 82 ChromeClient& chromeClient = frame()->host()->chromeClient();
96 WebScreenOrientationType orientationType = effectiveType(chromeClient); 83 WebScreenInfo screenInfo = chromeClient.screenInfo();
84 WebScreenOrientationType orientationType = screenInfo.orientationType;
97 if (orientationType == WebScreenOrientationUndefined) { 85 if (orientationType == WebScreenOrientationUndefined) {
98 // The embedder could not provide us with an orientation, deduce it ours elves. 86 // The embedder could not provide us with an orientation, deduce it ours elves.
99 orientationType = computeOrientation(chromeClient.screenInfo().rect, eff ectiveAngle(chromeClient)); 87 orientationType = computeOrientation(chromeClient.screenInfo().rect, scr eenInfo.orientationAngle);
100 } 88 }
101 ASSERT(orientationType != WebScreenOrientationUndefined); 89 ASSERT(orientationType != WebScreenOrientationUndefined);
102 90
103 m_orientation->setType(orientationType); 91 m_orientation->setType(orientationType);
104 m_orientation->setAngle(effectiveAngle(chromeClient)); 92 m_orientation->setAngle(screenInfo.orientationAngle);
105 } 93 }
106 94
107 bool ScreenOrientationController::isActiveAndVisible() const 95 bool ScreenOrientationController::isActiveAndVisible() const
108 { 96 {
109 return m_orientation && frame() && page() && page()->isPageVisible(); 97 return m_orientation && frame() && page() && page()->isPageVisible();
110 } 98 }
111 99
112 void ScreenOrientationController::pageVisibilityChanged() 100 void ScreenOrientationController::pageVisibilityChanged()
113 { 101 {
114 notifyDispatcher(); 102 notifyDispatcher();
115 103
116 if (!isActiveAndVisible()) 104 if (!isActiveAndVisible())
117 return; 105 return;
118 106
119 // The orientation type and angle are tied in a way that if the angle has 107 // The orientation type and angle are tied in a way that if the angle has
120 // changed, the type must have changed. 108 // changed, the type must have changed.
121 unsigned short currentAngle = effectiveAngle(frame()->host()->chromeClient() ); 109 unsigned short currentAngle = frame()->host()->chromeClient().screenInfo().o rientationAngle;
122 110
123 // FIXME: sendOrientationChangeEvent() currently send an event all the 111 // FIXME: sendOrientationChangeEvent() currently send an event all the
124 // children of the frame, so it should only be called on the frame on 112 // children of the frame, so it should only be called on the frame on
125 // top of the tree. We would need the embedder to call 113 // top of the tree. We would need the embedder to call
126 // sendOrientationChangeEvent on every WebFrame part of a WebView to be 114 // sendOrientationChangeEvent on every WebFrame part of a WebView to be
127 // able to remove this. 115 // able to remove this.
128 if (frame() == frame()->localFrameRoot() && m_orientation->angle() != curren tAngle) 116 if (frame() == frame()->localFrameRoot() && m_orientation->angle() != curren tAngle)
129 notifyOrientationChanged(); 117 notifyOrientationChanged();
130 } 118 }
131 119
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } 163 }
176 164
177 void ScreenOrientationController::unlock() 165 void ScreenOrientationController::unlock()
178 { 166 {
179 // When detached, the client is no longer valid. 167 // When detached, the client is no longer valid.
180 if (!m_client) 168 if (!m_client)
181 return; 169 return;
182 m_client->unlockOrientation(); 170 m_client->unlockOrientation();
183 } 171 }
184 172
185 void ScreenOrientationController::setOverride(WebScreenOrientationType type, uns igned short angle)
186 {
187 m_override = true;
188 m_overrideType = type;
189 m_overrideAngle = angle;
190 notifyOrientationChanged();
191 }
192
193 void ScreenOrientationController::clearOverride()
194 {
195 m_override = false;
196 notifyOrientationChanged();
197 }
198
199 void ScreenOrientationController::dispatchEventTimerFired(Timer<ScreenOrientatio nController>*) 173 void ScreenOrientationController::dispatchEventTimerFired(Timer<ScreenOrientatio nController>*)
200 { 174 {
201 if (!m_orientation) 175 if (!m_orientation)
202 return; 176 return;
203 m_orientation->dispatchEvent(Event::create(EventTypeNames::change)); 177 m_orientation->dispatchEvent(Event::create(EventTypeNames::change));
204 } 178 }
205 179
206 void ScreenOrientationController::didUpdateData() 180 void ScreenOrientationController::didUpdateData()
207 { 181 {
208 // Do nothing. 182 // Do nothing.
(...skipping 29 matching lines...) Expand all
238 212
239 DEFINE_TRACE(ScreenOrientationController) 213 DEFINE_TRACE(ScreenOrientationController)
240 { 214 {
241 visitor->trace(m_orientation); 215 visitor->trace(m_orientation);
242 LocalFrameLifecycleObserver::trace(visitor); 216 LocalFrameLifecycleObserver::trace(visitor);
243 WillBeHeapSupplement<LocalFrame>::trace(visitor); 217 WillBeHeapSupplement<LocalFrame>::trace(visitor);
244 PlatformEventController::trace(visitor); 218 PlatformEventController::trace(visitor);
245 } 219 }
246 220
247 } // namespace blink 221 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698