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 "modules/screen_orientation/ScreenOrientationDispatcher.h" | 13 #include "modules/screen_orientation/ScreenOrientationDispatcher.h" |
14 #include "platform/LayoutTestSupport.h" | 14 #include "platform/LayoutTestSupport.h" |
15 #include "platform/PlatformScreen.h" | 15 #include "platform/PlatformScreen.h" |
16 #include "public/platform/WebScreenOrientationClient.h" | 16 #include "public/platform/WebScreenOrientationClient.h" |
17 | 17 |
18 namespace blink { | 18 namespace blink { |
19 | 19 |
20 ScreenOrientationController::~ScreenOrientationController() | 20 ScreenOrientationController::~ScreenOrientationController() |
21 { | 21 { |
22 } | 22 } |
23 | 23 |
24 void ScreenOrientationController::persistentHostHasBeenDestroyed() | 24 void ScreenOrientationController::persistentHostHasBeenDestroyed() |
25 { | 25 { |
26 // Unregister lifecycle observation once page is being torn down. | 26 // Unregister lifecycle observation once page is being torn down. |
27 observeContext(0); | 27 observeContext(0); |
28 } | 28 } |
29 | 29 |
30 void ScreenOrientationController::provideTo(LocalFrame& frame, blink::WebScreenO
rientationClient* client) | 30 void ScreenOrientationController::provideTo(LocalFrame& frame, WebScreenOrientat
ionClient* client) |
31 { | 31 { |
32 ASSERT(RuntimeEnabledFeatures::screenOrientationEnabled()); | 32 ASSERT(RuntimeEnabledFeatures::screenOrientationEnabled()); |
33 | 33 |
34 ScreenOrientationController* controller = new ScreenOrientationController(fr
ame, client); | 34 ScreenOrientationController* controller = new ScreenOrientationController(fr
ame, client); |
35 WillBeHeapSupplement<LocalFrame>::provideTo(frame, supplementName(), adoptPt
rWillBeNoop(controller)); | 35 WillBeHeapSupplement<LocalFrame>::provideTo(frame, supplementName(), adoptPt
rWillBeNoop(controller)); |
36 } | 36 } |
37 | 37 |
38 ScreenOrientationController* ScreenOrientationController::from(LocalFrame& frame
) | 38 ScreenOrientationController* ScreenOrientationController::from(LocalFrame& frame
) |
39 { | 39 { |
40 return static_cast<ScreenOrientationController*>(WillBeHeapSupplement<LocalF
rame>::from(frame, supplementName())); | 40 return static_cast<ScreenOrientationController*>(WillBeHeapSupplement<LocalF
rame>::from(frame, supplementName())); |
41 } | 41 } |
42 | 42 |
43 ScreenOrientationController::ScreenOrientationController(LocalFrame& frame, blin
k::WebScreenOrientationClient* client) | 43 ScreenOrientationController::ScreenOrientationController(LocalFrame& frame, WebS
creenOrientationClient* client) |
44 : PlatformEventController(frame.page()) | 44 : PlatformEventController(frame.page()) |
45 , m_client(client) | 45 , m_client(client) |
46 , m_frame(frame) | 46 , m_frame(frame) |
47 , m_dispatchEventTimer(this, &ScreenOrientationController::dispatchEventTime
rFired) | 47 , m_dispatchEventTimer(this, &ScreenOrientationController::dispatchEventTime
rFired) |
48 { | 48 { |
49 } | 49 } |
50 | 50 |
51 const char* ScreenOrientationController::supplementName() | 51 const char* ScreenOrientationController::supplementName() |
52 { | 52 { |
53 return "ScreenOrientationController"; | 53 return "ScreenOrientationController"; |
54 } | 54 } |
55 | 55 |
56 // 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. |
57 blink::WebScreenOrientationType ScreenOrientationController::computeOrientation(
FrameView* view) | 57 WebScreenOrientationType ScreenOrientationController::computeOrientation(FrameVi
ew* view) |
58 { | 58 { |
59 // Bypass orientation detection in layout tests to get consistent results. | 59 // Bypass orientation detection in layout tests to get consistent results. |
60 // FIXME: The screen dimension should be fixed when running the layout tests
to avoid such | 60 // FIXME: The screen dimension should be fixed when running the layout tests
to avoid such |
61 // issues. | 61 // issues. |
62 if (LayoutTestSupport::isRunningLayoutTest()) | 62 if (LayoutTestSupport::isRunningLayoutTest()) |
63 return blink::WebScreenOrientationPortraitPrimary; | 63 return WebScreenOrientationPortraitPrimary; |
64 | 64 |
65 FloatRect rect = screenRect(view); | 65 FloatRect rect = screenRect(view); |
66 uint16_t rotation = screenOrientationAngle(view); | 66 uint16_t rotation = screenOrientationAngle(view); |
67 bool isTallDisplay = rotation % 180 ? rect.height() < rect.width() : rect.he
ight() > rect.width(); | 67 bool isTallDisplay = rotation % 180 ? rect.height() < rect.width() : rect.he
ight() > rect.width(); |
68 switch (rotation) { | 68 switch (rotation) { |
69 case 0: | 69 case 0: |
70 return isTallDisplay ? blink::WebScreenOrientationPortraitPrimary : blin
k::WebScreenOrientationLandscapePrimary; | 70 return isTallDisplay ? WebScreenOrientationPortraitPrimary : WebScreenOr
ientationLandscapePrimary; |
71 case 90: | 71 case 90: |
72 return isTallDisplay ? blink::WebScreenOrientationLandscapePrimary : bli
nk::WebScreenOrientationPortraitSecondary; | 72 return isTallDisplay ? WebScreenOrientationLandscapePrimary : WebScreenO
rientationPortraitSecondary; |
73 case 180: | 73 case 180: |
74 return isTallDisplay ? blink::WebScreenOrientationPortraitSecondary : bl
ink::WebScreenOrientationLandscapeSecondary; | 74 return isTallDisplay ? WebScreenOrientationPortraitSecondary : WebScreen
OrientationLandscapeSecondary; |
75 case 270: | 75 case 270: |
76 return isTallDisplay ? blink::WebScreenOrientationLandscapeSecondary : b
link::WebScreenOrientationPortraitPrimary; | 76 return isTallDisplay ? WebScreenOrientationLandscapeSecondary : WebScree
nOrientationPortraitPrimary; |
77 default: | 77 default: |
78 ASSERT_NOT_REACHED(); | 78 ASSERT_NOT_REACHED(); |
79 return blink::WebScreenOrientationPortraitPrimary; | 79 return WebScreenOrientationPortraitPrimary; |
80 } | 80 } |
81 } | 81 } |
82 | 82 |
83 void ScreenOrientationController::updateOrientation() | 83 void ScreenOrientationController::updateOrientation() |
84 { | 84 { |
85 ASSERT(m_orientation); | 85 ASSERT(m_orientation); |
86 | 86 |
87 blink::WebScreenOrientationType orientationType = screenOrientationType(m_fr
ame.view()); | 87 WebScreenOrientationType orientationType = screenOrientationType(m_frame.vie
w()); |
88 if (orientationType == blink::WebScreenOrientationUndefined) { | 88 if (orientationType == WebScreenOrientationUndefined) { |
89 // The embedder could not provide us with an orientation, deduce it ours
elves. | 89 // The embedder could not provide us with an orientation, deduce it ours
elves. |
90 orientationType = computeOrientation(m_frame.view()); | 90 orientationType = computeOrientation(m_frame.view()); |
91 } | 91 } |
92 ASSERT(orientationType != blink::WebScreenOrientationUndefined); | 92 ASSERT(orientationType != WebScreenOrientationUndefined); |
93 | 93 |
94 m_orientation->setType(orientationType); | 94 m_orientation->setType(orientationType); |
95 m_orientation->setAngle(screenOrientationAngle(m_frame.view())); | 95 m_orientation->setAngle(screenOrientationAngle(m_frame.view())); |
96 } | 96 } |
97 | 97 |
98 void ScreenOrientationController::pageVisibilityChanged() | 98 void ScreenOrientationController::pageVisibilityChanged() |
99 { | 99 { |
100 notifyDispatcher(); | 100 notifyDispatcher(); |
101 | 101 |
102 if (!m_orientation || !page() || page()->visibilityState() != PageVisibility
StateVisible) | 102 if (!m_orientation || !page() || page()->visibilityState() != PageVisibility
StateVisible) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 } | 146 } |
147 | 147 |
148 void ScreenOrientationController::setOrientation(ScreenOrientation* orientation) | 148 void ScreenOrientationController::setOrientation(ScreenOrientation* orientation) |
149 { | 149 { |
150 m_orientation = orientation; | 150 m_orientation = orientation; |
151 if (m_orientation) | 151 if (m_orientation) |
152 updateOrientation(); | 152 updateOrientation(); |
153 notifyDispatcher(); | 153 notifyDispatcher(); |
154 } | 154 } |
155 | 155 |
156 void ScreenOrientationController::lock(blink::WebScreenOrientationLockType orien
tation, blink::WebLockOrientationCallback* callback) | 156 void ScreenOrientationController::lock(WebScreenOrientationLockType orientation,
WebLockOrientationCallback* callback) |
157 { | 157 { |
158 ASSERT(m_client); | 158 ASSERT(m_client); |
159 m_client->lockOrientation(orientation, callback); | 159 m_client->lockOrientation(orientation, callback); |
160 } | 160 } |
161 | 161 |
162 void ScreenOrientationController::unlock() | 162 void ScreenOrientationController::unlock() |
163 { | 163 { |
164 ASSERT(m_client); | 164 ASSERT(m_client); |
165 m_client->unlockOrientation(); | 165 m_client->unlockOrientation(); |
166 } | 166 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 stopUpdating(); | 205 stopUpdating(); |
206 } | 206 } |
207 | 207 |
208 void ScreenOrientationController::trace(Visitor* visitor) | 208 void ScreenOrientationController::trace(Visitor* visitor) |
209 { | 209 { |
210 visitor->trace(m_orientation); | 210 visitor->trace(m_orientation); |
211 WillBeHeapSupplement<LocalFrame>::trace(visitor); | 211 WillBeHeapSupplement<LocalFrame>::trace(visitor); |
212 } | 212 } |
213 | 213 |
214 } // namespace blink | 214 } // namespace blink |
OLD | NEW |