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