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

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

Issue 261983005: Stop firing orientationchange events at pages that are not visible (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Simplify test case Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « Source/modules/screen_orientation/ScreenOrientation.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ScreenOrientation.h" 6 #include "modules/screen_orientation/ScreenOrientation.h"
7 7
8 #include "core/dom/FullscreenElementStack.h"
8 #include "core/frame/DOMWindow.h" 9 #include "core/frame/DOMWindow.h"
9 #include "core/frame/LocalFrame.h" 10 #include "core/frame/LocalFrame.h"
10 #include "core/frame/Screen.h" 11 #include "core/frame/Screen.h"
11 #include "modules/screen_orientation/ScreenOrientationController.h" 12 #include "modules/screen_orientation/ScreenOrientationController.h"
12 #include "public/platform/Platform.h" 13 #include "public/platform/Platform.h"
13 #include "public/platform/WebScreenOrientationType.h" 14 #include "public/platform/WebScreenOrientationType.h"
14 15
15 // This code assumes that WebScreenOrientationType values are included in WebScr eenOrientationLockType. 16 // This code assumes that WebScreenOrientationType values are included in WebScr eenOrientationLockType.
16 #define COMPILE_ASSERT_MATCHING_ENUM(enum1, enum2) \ 17 #define COMPILE_ASSERT_MATCHING_ENUM(enum1, enum2) \
17 COMPILE_ASSERT(static_cast<unsigned>(blink::enum1) == static_cast<unsigned>( blink::enum2), mismatching_types) 18 COMPILE_ASSERT(static_cast<unsigned>(blink::enum1) == static_cast<unsigned>( blink::enum2), mismatching_types)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 95 }
95 96
96 void ScreenOrientation::orientationLockTimerFired(Timer<ScreenOrientation>*) 97 void ScreenOrientation::orientationLockTimerFired(Timer<ScreenOrientation>*)
97 { 98 {
98 if (m_prospectiveLock == blink::WebScreenOrientationLockDefault) 99 if (m_prospectiveLock == blink::WebScreenOrientationLockDefault)
99 blink::Platform::current()->unlockOrientation(); 100 blink::Platform::current()->unlockOrientation();
100 else 101 else
101 blink::Platform::current()->lockOrientation(m_prospectiveLock); 102 blink::Platform::current()->lockOrientation(m_prospectiveLock);
102 } 103 }
103 104
105 void ScreenOrientation::startListeningForFullscreenExit()
106 {
107 Document* document = this->document();
108 ASSERT(document);
109 FullscreenElementStack* fullscreen = FullscreenElementStack::fromIfExists(*d ocument);
110 ASSERT(fullscreen);
111 fullscreen->addObserver(this);
112 }
113
114 void ScreenOrientation::stopListeningForFullscreenExit()
115 {
116 Document* document = this->document();
117 if (!document)
118 return;
119 FullscreenElementStack* fullscreen = FullscreenElementStack::fromIfExists(*d ocument);
120 if (!fullscreen)
121 return;
122 fullscreen->removeObserver(this);
123 }
124
125 // We need to set the screen orientation lock back to the default when
126 // the document fully exists fullscreen.
127 void ScreenOrientation::didFullyExitFullscreen()
128 {
129 stopListeningForFullscreenExit();
130
131 m_prospectiveLock = blink::WebScreenOrientationLockDefault;
132 if (m_orientationLockTimer.isActive())
133 m_orientationLockTimer.stop();
134
135 blink::Platform::current()->unlockOrientation();
136 }
137
104 const char* ScreenOrientation::supplementName() 138 const char* ScreenOrientation::supplementName()
105 { 139 {
106 return "ScreenOrientation"; 140 return "ScreenOrientation";
107 } 141 }
108 142
109 Document* ScreenOrientation::document() const 143 Document* ScreenOrientation::document() const
110 { 144 {
111 if (!m_associatedDOMWindow || !m_associatedDOMWindow->isCurrentlyDisplayedIn Frame()) 145 if (!m_associatedDOMWindow || !m_associatedDOMWindow->isCurrentlyDisplayedIn Frame())
112 return 0; 146 return 0;
113 ASSERT(m_associatedDOMWindow->document()); 147 ASSERT(m_associatedDOMWindow->document());
114 return m_associatedDOMWindow->document(); 148 return m_associatedDOMWindow->document();
115 } 149 }
116 150
117 ScreenOrientation& ScreenOrientation::from(Screen& screen) 151 ScreenOrientation& ScreenOrientation::from(Screen& screen)
118 { 152 {
119 ScreenOrientation* supplement = static_cast<ScreenOrientation*>(WillBeHeapSu pplement<Screen>::from(screen, supplementName())); 153 ScreenOrientation* supplement = static_cast<ScreenOrientation*>(WillBeHeapSu pplement<Screen>::from(screen, supplementName()));
120 if (!supplement) { 154 if (!supplement) {
121 supplement = new ScreenOrientation(screen); 155 supplement = new ScreenOrientation(screen);
122 provideTo(screen, supplementName(), adoptPtrWillBeNoop(supplement)); 156 provideTo(screen, supplementName(), adoptPtrWillBeNoop(supplement));
123 } 157 }
124 return *supplement; 158 return *supplement;
125 } 159 }
126 160
127 ScreenOrientation::~ScreenOrientation() 161 ScreenOrientation::~ScreenOrientation()
128 { 162 {
163 stopListeningForFullscreenExit();
sof 2014/05/08 21:41:17 With Oilpan, this is a somewhat problematic cleanu
129 } 164 }
130 165
131 const AtomicString& ScreenOrientation::orientation(Screen& screen) 166 const AtomicString& ScreenOrientation::orientation(Screen& screen)
132 { 167 {
133 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); 168 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen);
134 if (!screenOrientation.document()) { 169 if (!screenOrientation.document()) {
135 // FIXME: we should try to return a better guess, like the latest known value. 170 // FIXME: we should try to return a better guess, like the latest known value.
136 return orientationTypeToString(blink::WebScreenOrientationPortraitPrimar y); 171 return orientationTypeToString(blink::WebScreenOrientationPortraitPrimar y);
137 } 172 }
138 ScreenOrientationController& controller = ScreenOrientationController::from( *screenOrientation.document()); 173 ScreenOrientationController& controller = ScreenOrientationController::from( *screenOrientation.document());
139 return orientationTypeToString(controller.orientation()); 174 return orientationTypeToString(controller.orientation());
140 } 175 }
141 176
177 bool ScreenOrientation::isOrientationLockingAllowed(Document& document) const
178 {
179 // We only allow locking the orientation while in fullscreen, for consistenc y with other browsers.
180 return FullscreenElementStack::isFullScreen(document);
181 }
182
142 bool ScreenOrientation::lockOrientation(Screen& screen, const AtomicString& lock String) 183 bool ScreenOrientation::lockOrientation(Screen& screen, const AtomicString& lock String)
143 { 184 {
144 ScreenOrientation::from(screen).lockOrientationAsync(stringToOrientationLock (lockString)); 185 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen);
186 Document* document = screenOrientation.document();
187 if (!document)
188 return false;
189 if (!screenOrientation.isOrientationLockingAllowed(*document))
190 return false;
191
192 screenOrientation.lockOrientationAsync(stringToOrientationLock(lockString));
193 screenOrientation.startListeningForFullscreenExit();
145 return true; 194 return true;
146 } 195 }
147 196
148 void ScreenOrientation::unlockOrientation(Screen& screen) 197 void ScreenOrientation::unlockOrientation(Screen& screen)
149 { 198 {
150 ScreenOrientation::from(screen).lockOrientationAsync(blink::WebScreenOrienta tionLockDefault); 199 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen);
200 screenOrientation.stopListeningForFullscreenExit();
201 screenOrientation.lockOrientationAsync(blink::WebScreenOrientationLockDefaul t);
151 } 202 }
152 203
153 } // namespace WebCore 204 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/screen_orientation/ScreenOrientation.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698