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

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

Issue 1220643002: Revert of [DevTools] Implement screen orientation override. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 5 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)
47 { 44 {
48 } 45 }
49 46
50 const char* ScreenOrientationController::supplementName() 47 const char* ScreenOrientationController::supplementName()
51 { 48 {
52 return "ScreenOrientationController"; 49 return "ScreenOrientationController";
53 } 50 }
54 51
55 // 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.
56 WebScreenOrientationType ScreenOrientationController::computeOrientation(const I ntRect& rect, uint16_t rotation) 53 WebScreenOrientationType ScreenOrientationController::computeOrientation(ChromeC lient& chromeClient)
57 { 54 {
58 // Bypass orientation detection in layout tests to get consistent results. 55 // Bypass orientation detection in layout tests to get consistent results.
59 // FIXME: The screen dimension should be fixed when running the layout tests to avoid such 56 // FIXME: The screen dimension should be fixed when running the layout tests to avoid such
60 // issues. 57 // issues.
61 if (LayoutTestSupport::isRunningLayoutTest()) 58 if (LayoutTestSupport::isRunningLayoutTest())
62 return WebScreenOrientationPortraitPrimary; 59 return WebScreenOrientationPortraitPrimary;
63 60
61 IntRect rect = chromeClient.screenInfo().rect;
62 uint16_t rotation = chromeClient.screenInfo().orientationAngle;
64 bool isTallDisplay = rotation % 180 ? rect.height() < rect.width() : rect.he ight() > rect.width(); 63 bool isTallDisplay = rotation % 180 ? rect.height() < rect.width() : rect.he ight() > rect.width();
65 switch (rotation) { 64 switch (rotation) {
66 case 0: 65 case 0:
67 return isTallDisplay ? WebScreenOrientationPortraitPrimary : WebScreenOr ientationLandscapePrimary; 66 return isTallDisplay ? WebScreenOrientationPortraitPrimary : WebScreenOr ientationLandscapePrimary;
68 case 90: 67 case 90:
69 return isTallDisplay ? WebScreenOrientationLandscapePrimary : WebScreenO rientationPortraitSecondary; 68 return isTallDisplay ? WebScreenOrientationLandscapePrimary : WebScreenO rientationPortraitSecondary;
70 case 180: 69 case 180:
71 return isTallDisplay ? WebScreenOrientationPortraitSecondary : WebScreen OrientationLandscapeSecondary; 70 return isTallDisplay ? WebScreenOrientationPortraitSecondary : WebScreen OrientationLandscapeSecondary;
72 case 270: 71 case 270:
73 return isTallDisplay ? WebScreenOrientationLandscapeSecondary : WebScree nOrientationPortraitPrimary; 72 return isTallDisplay ? WebScreenOrientationLandscapeSecondary : WebScree nOrientationPortraitPrimary;
74 default: 73 default:
75 ASSERT_NOT_REACHED(); 74 ASSERT_NOT_REACHED();
76 return WebScreenOrientationPortraitPrimary; 75 return WebScreenOrientationPortraitPrimary;
77 } 76 }
78 } 77 }
79 78
80 unsigned short ScreenOrientationController::effectiveAngle(ChromeClient& chromeC lient)
81 {
82 return m_override ? m_overrideAngle : chromeClient.screenInfo().orientationA ngle;
83 }
84
85 WebScreenOrientationType ScreenOrientationController::effectiveType(ChromeClient & chromeClient)
86 {
87 return m_override ? m_overrideType : chromeClient.screenInfo().orientationTy pe;
88 }
89
90 void ScreenOrientationController::updateOrientation() 79 void ScreenOrientationController::updateOrientation()
91 { 80 {
92 ASSERT(m_orientation); 81 ASSERT(m_orientation);
93 ASSERT(frame()); 82 ASSERT(frame());
94 ASSERT(frame()->host()); 83 ASSERT(frame()->host());
95 84
96 ChromeClient& chromeClient = frame()->host()->chromeClient(); 85 ChromeClient& chromeClient = frame()->host()->chromeClient();
97 WebScreenOrientationType orientationType = effectiveType(chromeClient); 86 WebScreenOrientationType orientationType = chromeClient.screenInfo().orienta tionType;
98 if (orientationType == WebScreenOrientationUndefined) { 87 if (orientationType == WebScreenOrientationUndefined) {
99 // The embedder could not provide us with an orientation, deduce it ours elves. 88 // The embedder could not provide us with an orientation, deduce it ours elves.
100 orientationType = computeOrientation(chromeClient.screenInfo().rect, eff ectiveAngle(chromeClient)); 89 orientationType = computeOrientation(chromeClient);
101 } 90 }
102 ASSERT(orientationType != WebScreenOrientationUndefined); 91 ASSERT(orientationType != WebScreenOrientationUndefined);
103 92
104 m_orientation->setType(orientationType); 93 m_orientation->setType(orientationType);
105 m_orientation->setAngle(effectiveAngle(chromeClient)); 94 m_orientation->setAngle(chromeClient.screenInfo().orientationAngle);
106 } 95 }
107 96
108 bool ScreenOrientationController::isActiveAndVisible() const 97 bool ScreenOrientationController::isActiveAndVisible() const
109 { 98 {
110 return m_orientation && frame() && page() && page()->visibilityState() == Pa geVisibilityStateVisible; 99 return m_orientation && frame() && page() && page()->visibilityState() == Pa geVisibilityStateVisible;
111 } 100 }
112 101
113 void ScreenOrientationController::pageVisibilityChanged() 102 void ScreenOrientationController::pageVisibilityChanged()
114 { 103 {
115 notifyDispatcher(); 104 notifyDispatcher();
116 105
117 if (!isActiveAndVisible()) 106 if (!isActiveAndVisible())
118 return; 107 return;
119 108
120 // The orientation type and angle are tied in a way that if the angle has 109 // The orientation type and angle are tied in a way that if the angle has
121 // changed, the type must have changed. 110 // changed, the type must have changed.
122 unsigned short currentAngle = effectiveAngle(frame()->host()->chromeClient() ); 111 unsigned short currentAngle = frame()->host()->chromeClient().screenInfo().o rientationAngle;
123 112
124 // FIXME: sendOrientationChangeEvent() currently send an event all the 113 // FIXME: sendOrientationChangeEvent() currently send an event all the
125 // children of the frame, so it should only be called on the frame on 114 // children of the frame, so it should only be called on the frame on
126 // top of the tree. We would need the embedder to call 115 // top of the tree. We would need the embedder to call
127 // sendOrientationChangeEvent on every WebFrame part of a WebView to be 116 // sendOrientationChangeEvent on every WebFrame part of a WebView to be
128 // able to remove this. 117 // able to remove this.
129 if (frame() == frame()->localFrameRoot() && m_orientation->angle() != curren tAngle) 118 if (frame() == frame()->localFrameRoot() && m_orientation->angle() != curren tAngle)
130 notifyOrientationChanged(); 119 notifyOrientationChanged();
131 } 120 }
132 121
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 165 }
177 166
178 void ScreenOrientationController::unlock() 167 void ScreenOrientationController::unlock()
179 { 168 {
180 // When detached, the client is no longer valid. 169 // When detached, the client is no longer valid.
181 if (!m_client) 170 if (!m_client)
182 return; 171 return;
183 m_client->unlockOrientation(); 172 m_client->unlockOrientation();
184 } 173 }
185 174
186 void ScreenOrientationController::setOverride(WebScreenOrientationType type, uns igned short angle)
187 {
188 m_override = true;
189 m_overrideType = type;
190 m_overrideAngle = angle;
191 notifyOrientationChanged();
192 }
193
194 void ScreenOrientationController::clearOverride()
195 {
196 m_override = false;
197 notifyOrientationChanged();
198 }
199
200 void ScreenOrientationController::dispatchEventTimerFired(Timer<ScreenOrientatio nController>*) 175 void ScreenOrientationController::dispatchEventTimerFired(Timer<ScreenOrientatio nController>*)
201 { 176 {
202 if (!m_orientation) 177 if (!m_orientation)
203 return; 178 return;
204 m_orientation->dispatchEvent(Event::create(EventTypeNames::change)); 179 m_orientation->dispatchEvent(Event::create(EventTypeNames::change));
205 } 180 }
206 181
207 void ScreenOrientationController::didUpdateData() 182 void ScreenOrientationController::didUpdateData()
208 { 183 {
209 // Do nothing. 184 // Do nothing.
(...skipping 29 matching lines...) Expand all
239 214
240 DEFINE_TRACE(ScreenOrientationController) 215 DEFINE_TRACE(ScreenOrientationController)
241 { 216 {
242 visitor->trace(m_orientation); 217 visitor->trace(m_orientation);
243 LocalFrameLifecycleObserver::trace(visitor); 218 LocalFrameLifecycleObserver::trace(visitor);
244 WillBeHeapSupplement<LocalFrame>::trace(visitor); 219 WillBeHeapSupplement<LocalFrame>::trace(visitor);
245 PlatformEventController::trace(visitor); 220 PlatformEventController::trace(visitor);
246 } 221 }
247 222
248 } // namespace blink 223 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698