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

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

Issue 1727083002: Revert 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)
43 { 46 {
44 } 47 }
45 48
46 const char* ScreenOrientationController::supplementName() 49 const char* ScreenOrientationController::supplementName()
47 { 50 {
48 return "ScreenOrientationController"; 51 return "ScreenOrientationController";
49 } 52 }
50 53
51 // Compute the screen orientation using the orientation angle and the screen wid th / height. 54 // Compute the screen orientation using the orientation angle and the screen wid th / height.
52 WebScreenOrientationType ScreenOrientationController::computeOrientation(const I ntRect& rect, uint16_t rotation) 55 WebScreenOrientationType ScreenOrientationController::computeOrientation(const I ntRect& rect, uint16_t rotation)
(...skipping 13 matching lines...) Expand all
66 case 180: 69 case 180:
67 return isTallDisplay ? WebScreenOrientationPortraitSecondary : WebScreen OrientationLandscapeSecondary; 70 return isTallDisplay ? WebScreenOrientationPortraitSecondary : WebScreen OrientationLandscapeSecondary;
68 case 270: 71 case 270:
69 return isTallDisplay ? WebScreenOrientationLandscapeSecondary : WebScree nOrientationPortraitPrimary; 72 return isTallDisplay ? WebScreenOrientationLandscapeSecondary : WebScree nOrientationPortraitPrimary;
70 default: 73 default:
71 ASSERT_NOT_REACHED(); 74 ASSERT_NOT_REACHED();
72 return WebScreenOrientationPortraitPrimary; 75 return WebScreenOrientationPortraitPrimary;
73 } 76 }
74 } 77 }
75 78
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
76 void ScreenOrientationController::updateOrientation() 89 void ScreenOrientationController::updateOrientation()
77 { 90 {
78 ASSERT(m_orientation); 91 ASSERT(m_orientation);
79 ASSERT(frame()); 92 ASSERT(frame());
80 ASSERT(frame()->host()); 93 ASSERT(frame()->host());
81 94
82 ChromeClient& chromeClient = frame()->host()->chromeClient(); 95 ChromeClient& chromeClient = frame()->host()->chromeClient();
83 WebScreenInfo screenInfo = chromeClient.screenInfo(); 96 WebScreenOrientationType orientationType = effectiveType(chromeClient);
84 WebScreenOrientationType orientationType = screenInfo.orientationType;
85 if (orientationType == WebScreenOrientationUndefined) { 97 if (orientationType == WebScreenOrientationUndefined) {
86 // The embedder could not provide us with an orientation, deduce it ours elves. 98 // The embedder could not provide us with an orientation, deduce it ours elves.
87 orientationType = computeOrientation(chromeClient.screenInfo().rect, scr eenInfo.orientationAngle); 99 orientationType = computeOrientation(chromeClient.screenInfo().rect, eff ectiveAngle(chromeClient));
88 } 100 }
89 ASSERT(orientationType != WebScreenOrientationUndefined); 101 ASSERT(orientationType != WebScreenOrientationUndefined);
90 102
91 m_orientation->setType(orientationType); 103 m_orientation->setType(orientationType);
92 m_orientation->setAngle(screenInfo.orientationAngle); 104 m_orientation->setAngle(effectiveAngle(chromeClient));
93 } 105 }
94 106
95 bool ScreenOrientationController::isActiveAndVisible() const 107 bool ScreenOrientationController::isActiveAndVisible() const
96 { 108 {
97 return m_orientation && frame() && page() && page()->isPageVisible(); 109 return m_orientation && frame() && page() && page()->isPageVisible();
98 } 110 }
99 111
100 void ScreenOrientationController::pageVisibilityChanged() 112 void ScreenOrientationController::pageVisibilityChanged()
101 { 113 {
102 notifyDispatcher(); 114 notifyDispatcher();
103 115
104 if (!isActiveAndVisible()) 116 if (!isActiveAndVisible())
105 return; 117 return;
106 118
107 // The orientation type and angle are tied in a way that if the angle has 119 // The orientation type and angle are tied in a way that if the angle has
108 // changed, the type must have changed. 120 // changed, the type must have changed.
109 unsigned short currentAngle = frame()->host()->chromeClient().screenInfo().o rientationAngle; 121 unsigned short currentAngle = effectiveAngle(frame()->host()->chromeClient() );
110 122
111 // FIXME: sendOrientationChangeEvent() currently send an event all the 123 // FIXME: sendOrientationChangeEvent() currently send an event all the
112 // children of the frame, so it should only be called on the frame on 124 // children of the frame, so it should only be called on the frame on
113 // top of the tree. We would need the embedder to call 125 // top of the tree. We would need the embedder to call
114 // sendOrientationChangeEvent on every WebFrame part of a WebView to be 126 // sendOrientationChangeEvent on every WebFrame part of a WebView to be
115 // able to remove this. 127 // able to remove this.
116 if (frame() == frame()->localFrameRoot() && m_orientation->angle() != curren tAngle) 128 if (frame() == frame()->localFrameRoot() && m_orientation->angle() != curren tAngle)
117 notifyOrientationChanged(); 129 notifyOrientationChanged();
118 } 130 }
119 131
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 } 175 }
164 176
165 void ScreenOrientationController::unlock() 177 void ScreenOrientationController::unlock()
166 { 178 {
167 // When detached, the client is no longer valid. 179 // When detached, the client is no longer valid.
168 if (!m_client) 180 if (!m_client)
169 return; 181 return;
170 m_client->unlockOrientation(); 182 m_client->unlockOrientation();
171 } 183 }
172 184
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
173 void ScreenOrientationController::dispatchEventTimerFired(Timer<ScreenOrientatio nController>*) 199 void ScreenOrientationController::dispatchEventTimerFired(Timer<ScreenOrientatio nController>*)
174 { 200 {
175 if (!m_orientation) 201 if (!m_orientation)
176 return; 202 return;
177 m_orientation->dispatchEvent(Event::create(EventTypeNames::change)); 203 m_orientation->dispatchEvent(Event::create(EventTypeNames::change));
178 } 204 }
179 205
180 void ScreenOrientationController::didUpdateData() 206 void ScreenOrientationController::didUpdateData()
181 { 207 {
182 // Do nothing. 208 // Do nothing.
(...skipping 29 matching lines...) Expand all
212 238
213 DEFINE_TRACE(ScreenOrientationController) 239 DEFINE_TRACE(ScreenOrientationController)
214 { 240 {
215 visitor->trace(m_orientation); 241 visitor->trace(m_orientation);
216 LocalFrameLifecycleObserver::trace(visitor); 242 LocalFrameLifecycleObserver::trace(visitor);
217 WillBeHeapSupplement<LocalFrame>::trace(visitor); 243 WillBeHeapSupplement<LocalFrame>::trace(visitor);
218 PlatformEventController::trace(visitor); 244 PlatformEventController::trace(visitor);
219 } 245 }
220 246
221 } // namespace blink 247 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698