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

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

Issue 374623002: [screen-orientation] Update implementation to match recent spec changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 6 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
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/frame/LocalDOMWindow.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/frame/Screen.h"
12 #include "core/page/Page.h" 11 #include "core/page/Page.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/WebScreenOrientationClient.h" 15 #include "public/platform/WebScreenOrientationClient.h"
16 16
17 namespace WebCore { 17 namespace WebCore {
18 18
19 ScreenOrientationController::~ScreenOrientationController() 19 ScreenOrientationController::~ScreenOrientationController()
20 { 20 {
21 } 21 }
22 22
23 void ScreenOrientationController::persistentHostHasBeenDestroyed() 23 void ScreenOrientationController::persistentHostHasBeenDestroyed()
24 { 24 {
25 // Unregister lifecycle observation once page is being torn down. 25 // Unregister lifecycle observation once page is being torn down.
26 observeContext(0); 26 observeContext(0);
27 } 27 }
28 28
29 void ScreenOrientationController::provideTo(LocalFrame& frame, blink::WebScreenO rientationClient* client) 29 void ScreenOrientationController::provideTo(LocalFrame& frame, blink::WebScreenO rientationClient* client)
30 { 30 {
31 ASSERT(RuntimeEnabledFeatures::screenOrientationEnabled());
32
31 ScreenOrientationController* controller = new ScreenOrientationController(fr ame, client); 33 ScreenOrientationController* controller = new ScreenOrientationController(fr ame, client);
32 WillBeHeapSupplement<LocalFrame>::provideTo(frame, supplementName(), adoptPt rWillBeNoop(controller)); 34 WillBeHeapSupplement<LocalFrame>::provideTo(frame, supplementName(), adoptPt rWillBeNoop(controller));
33 } 35 }
34 36
35 ScreenOrientationController& ScreenOrientationController::from(LocalFrame& frame ) 37 ScreenOrientationController* ScreenOrientationController::from(LocalFrame& frame )
36 { 38 {
37 return *static_cast<ScreenOrientationController*>(WillBeHeapSupplement<Local Frame>::from(frame, supplementName())); 39 return static_cast<ScreenOrientationController*>(WillBeHeapSupplement<LocalF rame>::from(frame, supplementName()));
38 } 40 }
39 41
40 ScreenOrientationController::ScreenOrientationController(LocalFrame& frame, blin k::WebScreenOrientationClient* client) 42 ScreenOrientationController::ScreenOrientationController(LocalFrame& frame, blin k::WebScreenOrientationClient* client)
41 : PageLifecycleObserver(frame.page()) 43 : PageLifecycleObserver(frame.page())
42 , m_overrideOrientation(blink::WebScreenOrientationUndefined)
43 , m_client(client) 44 , m_client(client)
44 , m_frame(frame) 45 , m_frame(frame)
45 { 46 {
46 } 47 }
47 48
48 const char* ScreenOrientationController::supplementName() 49 const char* ScreenOrientationController::supplementName()
49 { 50 {
50 return "ScreenOrientationController"; 51 return "ScreenOrientationController";
51 } 52 }
52 53
(...skipping 17 matching lines...) Expand all
70 case 180: 71 case 180:
71 return isTallDisplay ? blink::WebScreenOrientationPortraitSecondary : bl ink::WebScreenOrientationLandscapeSecondary; 72 return isTallDisplay ? blink::WebScreenOrientationPortraitSecondary : bl ink::WebScreenOrientationLandscapeSecondary;
72 case 270: 73 case 270:
73 return isTallDisplay ? blink::WebScreenOrientationLandscapeSecondary : b link::WebScreenOrientationPortraitPrimary; 74 return isTallDisplay ? blink::WebScreenOrientationLandscapeSecondary : b link::WebScreenOrientationPortraitPrimary;
74 default: 75 default:
75 ASSERT_NOT_REACHED(); 76 ASSERT_NOT_REACHED();
76 return blink::WebScreenOrientationPortraitPrimary; 77 return blink::WebScreenOrientationPortraitPrimary;
77 } 78 }
78 } 79 }
79 80
80 void ScreenOrientationController::pageVisibilityChanged() 81 void ScreenOrientationController::updateOrientation()
81 { 82 {
82 if (page() && page()->visibilityState() == PageVisibilityStateVisible) { 83 ASSERT(m_orientation);
83 blink::WebScreenOrientationType oldOrientation = m_overrideOrientation;
84 m_overrideOrientation = blink::WebScreenOrientationUndefined;
85 // FIXME: sendOrientationChangeEvent() currently send an event all the
86 // children of the frame, so it should only be called on the frame on
87 // top of the tree. We would need the embedder to call
88 // sendOrientationChangeEvent on every WebFrame part of a WebView to be
89 // able to remove this.
90 if (m_frame == m_frame.localFrameRoot() && oldOrientation != orientation ())
91 m_frame.sendOrientationChangeEvent();
92 } else if (m_overrideOrientation == blink::WebScreenOrientationUndefined) {
93 // The page is no longer visible, store the last know screen orientation
94 // so that we keep returning this orientation until the page becomes
95 // visible again.
96 m_overrideOrientation = orientation();
97 }
98 }
99
100 blink::WebScreenOrientationType ScreenOrientationController::orientation() const
101 {
102 if (m_overrideOrientation != blink::WebScreenOrientationUndefined) {
103 // The page is not visible, keep returning the last known screen orienta tion.
104 ASSERT(!page() || page()->visibilityState() != PageVisibilityStateVisibl e);
105 return m_overrideOrientation;
106 }
107 84
108 blink::WebScreenOrientationType orientationType = screenOrientationType(m_fr ame.view()); 85 blink::WebScreenOrientationType orientationType = screenOrientationType(m_fr ame.view());
109 if (orientationType == blink::WebScreenOrientationUndefined) { 86 if (orientationType == blink::WebScreenOrientationUndefined) {
110 // The embedder could not provide us with an orientation, deduce it ours elves. 87 // The embedder could not provide us with an orientation, deduce it ours elves.
111 orientationType = computeOrientation(m_frame.view()); 88 orientationType = computeOrientation(m_frame.view());
112 } 89 }
113 ASSERT(orientationType != blink::WebScreenOrientationUndefined); 90 ASSERT(orientationType != blink::WebScreenOrientationUndefined);
114 return orientationType; 91
92 m_orientation->setType(orientationType);
93 m_orientation->setAngle(screenOrientationAngle(m_frame.view()));
115 } 94 }
116 95
117 void ScreenOrientationController::lockOrientation(blink::WebScreenOrientationLoc kType orientation, blink::WebLockOrientationCallback* callback) 96 void ScreenOrientationController::pageVisibilityChanged()
97 {
98 if (!m_orientation || !page() || page()->visibilityState() != PageVisibility StateVisible)
99 return;
100
101 // The orientation type and angle are tied in a way that if the angle has
102 // changed, the type must have changed.
103 unsigned short currentAngle = screenOrientationAngle(m_frame.view());
104
105 // FIXME: sendOrientationChangeEvent() currently send an event all the
106 // 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
108 // sendOrientationChangeEvent on every WebFrame part of a WebView to be
109 // able to remove this.
110 if (m_frame == m_frame.localFrameRoot() && m_orientation->angle() != current Angle)
111 notifyOrientationChanged();
112 }
113
114 void ScreenOrientationController::notifyOrientationChanged()
115 {
116 ASSERT(RuntimeEnabledFeatures::screenOrientationEnabled());
117
118 if (!m_orientation || !page() || page()->visibilityState() != PageVisibility StateVisible)
119 return;
120
121 updateOrientation();
122
123 // Keep track of the frames that need to be notified before notifying the
124 // current frame as it will prevent side effects from the change event
125 // handlers.
126 Vector<RefPtr<LocalFrame> > childFrames;
127 for (Frame* child = m_frame.tree().firstChild(); child; child = child->tree( ).nextSibling()) {
128 if (child->isLocalFrame())
129 childFrames.append(toLocalFrame(child));
130 }
131
132 // Notify current orientation object.
133 m_orientation->dispatchEvent(Event::create(EventTypeNames::change));
134
135 // ... and child frames, if they have a ScreenOrientationController.
136 for (size_t i = 0; i < childFrames.size(); ++i) {
137 ScreenOrientationController* controller = ScreenOrientationController::f rom(*childFrames[i]);
138 if (controller)
139 controller->notifyOrientationChanged();
140 }
141 }
142
143 void ScreenOrientationController::setOrientation(ScreenOrientation* orientation)
144 {
145 m_orientation = orientation;
146 if (m_orientation)
147 updateOrientation();
148 }
149
150 void ScreenOrientationController::lock(blink::WebScreenOrientationLockType orien tation, blink::WebLockOrientationCallback* callback)
118 { 151 {
119 if (!m_client) { 152 if (!m_client) {
120 return; 153 return;
121 } 154 }
122 155
123 m_client->lockOrientation(orientation, callback); 156 m_client->lockOrientation(orientation, callback);
124 } 157 }
125 158
126 void ScreenOrientationController::unlockOrientation() 159 void ScreenOrientationController::unlock()
127 { 160 {
128 if (!m_client) { 161 if (!m_client) {
129 return; 162 return;
130 } 163 }
131 164
132 m_client->unlockOrientation(); 165 m_client->unlockOrientation();
133 } 166 }
134 167
168 const LocalFrame& ScreenOrientationController::frame() const
169 {
170 return m_frame;
171 }
172
173 void ScreenOrientationController::trace(Visitor* visitor)
174 {
175 visitor->trace(m_orientation);
176 WillBeHeapSupplement<LocalFrame>::trace(visitor);
177 }
178
135 } // namespace WebCore 179 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698