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

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

Issue 366853008: [screen-orientation] Expose orientation info in OrientationInformation interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: update ctor listing 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/events/Event.h"
8 #include "core/frame/LocalDOMWindow.h" 9 #include "core/frame/LocalDOMWindow.h"
9 #include "core/frame/FrameView.h" 10 #include "core/frame/FrameView.h"
10 #include "core/frame/LocalFrame.h" 11 #include "core/frame/LocalFrame.h"
11 #include "core/frame/Screen.h" 12 #include "core/frame/Screen.h"
12 #include "core/page/Page.h" 13 #include "core/page/Page.h"
14 #include "modules/screen_orientation/OrientationInformation.h"
13 #include "platform/LayoutTestSupport.h" 15 #include "platform/LayoutTestSupport.h"
14 #include "platform/PlatformScreen.h" 16 #include "platform/PlatformScreen.h"
15 #include "public/platform/WebScreenOrientationClient.h" 17 #include "public/platform/WebScreenOrientationClient.h"
16 18
17 namespace WebCore { 19 namespace WebCore {
18 20
19 ScreenOrientationController::~ScreenOrientationController() 21 ScreenOrientationController::~ScreenOrientationController()
20 { 22 {
21 } 23 }
22 24
23 void ScreenOrientationController::persistentHostHasBeenDestroyed() 25 void ScreenOrientationController::persistentHostHasBeenDestroyed()
24 { 26 {
25 // Unregister lifecycle observation once page is being torn down. 27 // Unregister lifecycle observation once page is being torn down.
26 observeContext(0); 28 observeContext(0);
27 } 29 }
28 30
29 void ScreenOrientationController::provideTo(LocalFrame& frame, blink::WebScreenO rientationClient* client) 31 void ScreenOrientationController::provideTo(LocalFrame& frame, blink::WebScreenO rientationClient* client)
30 { 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<Local Frame>::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) 44 , m_orientation(new OrientationInformation)
43 , m_client(client) 45 , m_client(client)
44 , m_frame(frame) 46 , m_frame(frame)
45 { 47 {
46 } 48 }
47 49
48 const char* ScreenOrientationController::supplementName() 50 const char* ScreenOrientationController::supplementName()
49 { 51 {
50 return "ScreenOrientationController"; 52 return "ScreenOrientationController";
51 } 53 }
52 54
(...skipping 17 matching lines...) Expand all
70 case 180: 72 case 180:
71 return isTallDisplay ? blink::WebScreenOrientationPortraitSecondary : bl ink::WebScreenOrientationLandscapeSecondary; 73 return isTallDisplay ? blink::WebScreenOrientationPortraitSecondary : bl ink::WebScreenOrientationLandscapeSecondary;
72 case 270: 74 case 270:
73 return isTallDisplay ? blink::WebScreenOrientationLandscapeSecondary : b link::WebScreenOrientationPortraitPrimary; 75 return isTallDisplay ? blink::WebScreenOrientationLandscapeSecondary : b link::WebScreenOrientationPortraitPrimary;
74 default: 76 default:
75 ASSERT_NOT_REACHED(); 77 ASSERT_NOT_REACHED();
76 return blink::WebScreenOrientationPortraitPrimary; 78 return blink::WebScreenOrientationPortraitPrimary;
77 } 79 }
78 } 80 }
79 81
80 void ScreenOrientationController::pageVisibilityChanged() 82 void ScreenOrientationController::updateOrientation()
81 { 83 {
82 if (page() && page()->visibilityState() == PageVisibilityStateVisible) {
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
108 blink::WebScreenOrientationType orientationType = screenOrientationType(m_fr ame.view()); 84 blink::WebScreenOrientationType orientationType = screenOrientationType(m_fr ame.view());
109 if (orientationType == blink::WebScreenOrientationUndefined) { 85 if (orientationType == blink::WebScreenOrientationUndefined) {
110 // The embedder could not provide us with an orientation, deduce it ours elves. 86 // The embedder could not provide us with an orientation, deduce it ours elves.
111 orientationType = computeOrientation(m_frame.view()); 87 orientationType = computeOrientation(m_frame.view());
112 } 88 }
113 ASSERT(orientationType != blink::WebScreenOrientationUndefined); 89 ASSERT(orientationType != blink::WebScreenOrientationUndefined);
114 return orientationType; 90
91 m_orientation->setType(orientationType);
92 m_orientation->setAngle(screenOrientationAngle(m_frame.view()));
93 }
94
95 void ScreenOrientationController::pageVisibilityChanged()
96 {
97 if (!page() || page()->visibilityState() != PageVisibilityStateVisible)
98 return;
99
100 // The orientation type and angle are tied in a way that if the angle has
101 // changed, the type must have changed.
102 unsigned short currentAngle = screenOrientationAngle(m_frame.view());
103
104 // FIXME: sendOrientationChangeEvent() currently send an event all the
105 // children of the frame, so it should only be called on the frame on
106 // top of the tree. We would need the embedder to call
107 // sendOrientationChangeEvent on every WebFrame part of a WebView to be
108 // able to remove this.
109 if (m_frame == m_frame.localFrameRoot() && m_orientation->angle() != current Angle)
110 notifyOrientationChanged();
111 }
112
113 void ScreenOrientationController::notifyOrientationChanged()
114 {
115 if (!RuntimeEnabledFeatures::orientationEventEnabled() && !RuntimeEnabledFea tures::screenOrientationEnabled())
116 return;
117
118 if (!page() || page()->visibilityState() != PageVisibilityStateVisible)
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 orientationchange
125 // event 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 frame.
133 LocalDOMWindow* window = m_frame.domWindow();
134 if (window)
135 window->dispatchEvent(Event::create(EventTypeNames::orientationchange));
136
137 // Notify subframes.
138 for (size_t i = 0; i < childFrames.size(); ++i)
139 ScreenOrientationController::from(*childFrames[i]).notifyOrientationChan ged();
140 }
141
142 OrientationInformation* ScreenOrientationController::orientation()
143 {
144 if (!m_orientation->initialized())
145 updateOrientation();
146
147 return m_orientation.get();
115 } 148 }
116 149
117 void ScreenOrientationController::lockOrientation(blink::WebScreenOrientationLoc kType orientation, blink::WebLockOrientationCallback* callback) 150 void ScreenOrientationController::lockOrientation(blink::WebScreenOrientationLoc kType orientation, 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::unlockOrientation()
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 void ScreenOrientationController::trace(Visitor* visitor)
169 {
170 WillBeHeapSupplement<LocalFrame>::trace(visitor);
171 visitor->trace(m_orientation);
172 }
173
135 } // namespace WebCore 174 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/screen_orientation/ScreenOrientationController.h ('k') | Source/web/WebLocalFrameImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698