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/FrameView.h" | 9 #include "core/frame/FrameView.h" |
10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
11 #include "core/page/Page.h" | 11 #include "core/page/Page.h" |
12 #include "modules/screen_orientation/ScreenOrientation.h" | 12 #include "modules/screen_orientation/ScreenOrientation.h" |
13 #include "platform/LayoutTestSupport.h" | 13 #include "platform/LayoutTestSupport.h" |
14 #include "platform/PlatformScreen.h" | 14 #include "platform/PlatformScreen.h" |
| 15 #include "public/platform/Platform.h" |
15 #include "public/platform/WebScreenOrientationClient.h" | 16 #include "public/platform/WebScreenOrientationClient.h" |
16 | 17 |
17 namespace WebCore { | 18 namespace WebCore { |
18 | 19 |
19 ScreenOrientationController::~ScreenOrientationController() | 20 ScreenOrientationController::~ScreenOrientationController() |
20 { | 21 { |
21 } | 22 } |
22 | 23 |
23 void ScreenOrientationController::persistentHostHasBeenDestroyed() | 24 void ScreenOrientationController::persistentHostHasBeenDestroyed() |
24 { | 25 { |
(...skipping 11 matching lines...) Expand all Loading... |
36 | 37 |
37 ScreenOrientationController* ScreenOrientationController::from(LocalFrame& frame
) | 38 ScreenOrientationController* ScreenOrientationController::from(LocalFrame& frame
) |
38 { | 39 { |
39 return static_cast<ScreenOrientationController*>(WillBeHeapSupplement<LocalF
rame>::from(frame, supplementName())); | 40 return static_cast<ScreenOrientationController*>(WillBeHeapSupplement<LocalF
rame>::from(frame, supplementName())); |
40 } | 41 } |
41 | 42 |
42 ScreenOrientationController::ScreenOrientationController(LocalFrame& frame, blin
k::WebScreenOrientationClient* client) | 43 ScreenOrientationController::ScreenOrientationController(LocalFrame& frame, blin
k::WebScreenOrientationClient* client) |
43 : PageLifecycleObserver(frame.page()) | 44 : PageLifecycleObserver(frame.page()) |
44 , m_client(client) | 45 , m_client(client) |
45 , m_frame(frame) | 46 , m_frame(frame) |
| 47 , m_platformListening(false) |
46 { | 48 { |
47 } | 49 } |
48 | 50 |
49 const char* ScreenOrientationController::supplementName() | 51 const char* ScreenOrientationController::supplementName() |
50 { | 52 { |
51 return "ScreenOrientationController"; | 53 return "ScreenOrientationController"; |
52 } | 54 } |
53 | 55 |
54 // Compute the screen orientation using the orientation angle and the screen wid
th / height. | 56 // Compute the screen orientation using the orientation angle and the screen wid
th / height. |
55 blink::WebScreenOrientationType ScreenOrientationController::computeOrientation(
FrameView* view) | 57 blink::WebScreenOrientationType ScreenOrientationController::computeOrientation(
FrameView* view) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 orientationType = computeOrientation(m_frame.view()); | 90 orientationType = computeOrientation(m_frame.view()); |
89 } | 91 } |
90 ASSERT(orientationType != blink::WebScreenOrientationUndefined); | 92 ASSERT(orientationType != blink::WebScreenOrientationUndefined); |
91 | 93 |
92 m_orientation->setType(orientationType); | 94 m_orientation->setType(orientationType); |
93 m_orientation->setAngle(screenOrientationAngle(m_frame.view())); | 95 m_orientation->setAngle(screenOrientationAngle(m_frame.view())); |
94 } | 96 } |
95 | 97 |
96 void ScreenOrientationController::pageVisibilityChanged() | 98 void ScreenOrientationController::pageVisibilityChanged() |
97 { | 99 { |
| 100 notifyPlatform(); |
| 101 |
98 if (!m_orientation || !page() || page()->visibilityState() != PageVisibility
StateVisible) | 102 if (!m_orientation || !page() || page()->visibilityState() != PageVisibility
StateVisible) |
99 return; | 103 return; |
100 | 104 |
101 // The orientation type and angle are tied in a way that if the angle has | 105 // The orientation type and angle are tied in a way that if the angle has |
102 // changed, the type must have changed. | 106 // changed, the type must have changed. |
103 unsigned short currentAngle = screenOrientationAngle(m_frame.view()); | 107 unsigned short currentAngle = screenOrientationAngle(m_frame.view()); |
104 | 108 |
105 // FIXME: sendOrientationChangeEvent() currently send an event all the | 109 // FIXME: sendOrientationChangeEvent() currently send an event all the |
106 // children of the frame, so it should only be called on the frame on | 110 // children of the frame, so it should only be called on the frame on |
107 // top of the tree. We would need the embedder to call | 111 // top of the tree. We would need the embedder to call |
(...skipping 30 matching lines...) Expand all Loading... |
138 if (controller) | 142 if (controller) |
139 controller->notifyOrientationChanged(); | 143 controller->notifyOrientationChanged(); |
140 } | 144 } |
141 } | 145 } |
142 | 146 |
143 void ScreenOrientationController::setOrientation(ScreenOrientation* orientation) | 147 void ScreenOrientationController::setOrientation(ScreenOrientation* orientation) |
144 { | 148 { |
145 m_orientation = orientation; | 149 m_orientation = orientation; |
146 if (m_orientation) | 150 if (m_orientation) |
147 updateOrientation(); | 151 updateOrientation(); |
| 152 |
| 153 notifyPlatform(); |
148 } | 154 } |
149 | 155 |
150 void ScreenOrientationController::lock(blink::WebScreenOrientationLockType orien
tation, blink::WebLockOrientationCallback* callback) | 156 void ScreenOrientationController::lock(blink::WebScreenOrientationLockType orien
tation, blink::WebLockOrientationCallback* callback) |
151 { | 157 { |
152 if (!m_client) { | 158 if (!m_client) { |
153 return; | 159 return; |
154 } | 160 } |
155 | 161 |
156 m_client->lockOrientation(orientation, callback); | 162 m_client->lockOrientation(orientation, callback); |
157 } | 163 } |
158 | 164 |
159 void ScreenOrientationController::unlock() | 165 void ScreenOrientationController::unlock() |
160 { | 166 { |
161 if (!m_client) { | 167 if (!m_client) { |
162 return; | 168 return; |
163 } | 169 } |
164 | 170 |
165 m_client->unlockOrientation(); | 171 m_client->unlockOrientation(); |
166 } | 172 } |
167 | 173 |
168 const LocalFrame& ScreenOrientationController::frame() const | 174 const LocalFrame& ScreenOrientationController::frame() const |
169 { | 175 { |
170 return m_frame; | 176 return m_frame; |
171 } | 177 } |
172 | 178 |
| 179 void ScreenOrientationController::notifyPlatform() |
| 180 { |
| 181 bool shouldListen = !!m_orientation && page() && page()->visibilityState() =
= PageVisibilityStateVisible; |
| 182 |
| 183 if (m_platformListening == shouldListen) |
| 184 return; |
| 185 |
| 186 shouldListen ? blink::Platform::current()->startScreenOrientationListening() |
| 187 : blink::Platform::current()->stopScreenOrientationListening(); |
| 188 m_platformListening = shouldListen; |
| 189 } |
| 190 |
173 void ScreenOrientationController::trace(Visitor* visitor) | 191 void ScreenOrientationController::trace(Visitor* visitor) |
174 { | 192 { |
175 visitor->trace(m_orientation); | 193 visitor->trace(m_orientation); |
176 WillBeHeapSupplement<LocalFrame>::trace(visitor); | 194 WillBeHeapSupplement<LocalFrame>::trace(visitor); |
177 } | 195 } |
178 | 196 |
179 } // namespace WebCore | 197 } // namespace WebCore |
OLD | NEW |