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

Side by Side Diff: third_party/WebKit/Source/web/FullscreenController.cpp

Issue 2122013003: Wait until after layout when restoring scroll on exiting fullscreen. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests after foolip@'s patch Created 4 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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 FullscreenController* FullscreenController::create(WebViewImpl* webViewImpl) 49 FullscreenController* FullscreenController::create(WebViewImpl* webViewImpl)
50 { 50 {
51 return new FullscreenController(webViewImpl); 51 return new FullscreenController(webViewImpl);
52 } 52 }
53 53
54 FullscreenController::FullscreenController(WebViewImpl* webViewImpl) 54 FullscreenController::FullscreenController(WebViewImpl* webViewImpl)
55 : m_webViewImpl(webViewImpl) 55 : m_webViewImpl(webViewImpl)
56 , m_haveEnteredFullscreen(false) 56 , m_haveEnteredFullscreen(false)
57 , m_exitFullscreenPageScaleFactor(0) 57 , m_exitFullscreenPageScaleFactor(0)
58 , m_needsScrollAndScaleRestore(false)
58 , m_isCancelingFullScreen(false) 59 , m_isCancelingFullScreen(false)
59 { 60 {
60 } 61 }
61 62
62 void FullscreenController::didEnterFullscreen() 63 void FullscreenController::didEnterFullscreen()
63 { 64 {
64 if (!m_provisionalFullScreenElement) 65 if (!m_provisionalFullScreenElement)
65 return; 66 return;
66 67
67 Element* element = m_provisionalFullScreenElement.release(); 68 Element* element = m_provisionalFullScreenElement.release();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // When the client exits from full screen we have to call fullyE xitFullscreen to notify 106 // When the client exits from full screen we have to call fullyE xitFullscreen to notify
106 // the document. While doing that, suppress notifications back t o the client. 107 // the document. While doing that, suppress notifications back t o the client.
107 m_isCancelingFullScreen = true; 108 m_isCancelingFullScreen = true;
108 Fullscreen::fullyExitFullscreen(*document); 109 Fullscreen::fullyExitFullscreen(*document);
109 m_isCancelingFullScreen = false; 110 m_isCancelingFullScreen = false;
110 111
111 // If the video used overlay fullscreen mode, the background was made transparent. Restore the transparency. 112 // If the video used overlay fullscreen mode, the background was made transparent. Restore the transparency.
112 if (isHTMLVideoElement(element) && m_webViewImpl->layerTreeView( )) 113 if (isHTMLVideoElement(element) && m_webViewImpl->layerTreeView( ))
113 m_webViewImpl->layerTreeView()->setHasTransparentBackground( m_webViewImpl->isTransparent()); 114 m_webViewImpl->layerTreeView()->setHasTransparentBackground( m_webViewImpl->isTransparent());
114 115
115 if (m_haveEnteredFullscreen) { 116 // We need to wait until style and layout are updated in order
116 m_webViewImpl->setPageScaleFactor(m_exitFullscreenPageScaleF actor); 117 // to propertly restore scroll offsets since content may not be
117 if (m_webViewImpl->mainFrame()->isWebLocalFrame()) 118 // overflowing in the same way until they do.
118 m_webViewImpl->mainFrame()->setScrollOffset(WebSize(m_ex itFullscreenScrollOffset)); 119 if (m_haveEnteredFullscreen)
119 m_webViewImpl->setVisualViewportOffset(m_exitFullscreenVisua lViewportOffset); 120 m_needsScrollAndScaleRestore = true;
120 }
121 121
122 fullscreen->didExitFullscreen(); 122 fullscreen->didExitFullscreen();
123 } 123 }
124 } 124 }
125 } 125 }
126 126
127 m_haveEnteredFullscreen = false; 127 m_haveEnteredFullscreen = false;
128 m_fullScreenFrame.clear(); 128 m_fullScreenFrame.clear();
129 } 129 }
130 130
(...skipping 14 matching lines...) Expand all
145 145
146 // We are already in fullscreen mode. 146 // We are already in fullscreen mode.
147 if (m_fullScreenFrame) { 147 if (m_fullScreenFrame) {
148 m_provisionalFullScreenElement = element; 148 m_provisionalFullScreenElement = element;
149 didEnterFullscreen(); 149 didEnterFullscreen();
150 return; 150 return;
151 } 151 }
152 152
153 // We need to store these values here rather than didEnterFullscreen since 153 // We need to store these values here rather than didEnterFullscreen since
154 // by the time the latter is called, a Resize has already occured, clamping 154 // by the time the latter is called, a Resize has already occured, clamping
155 // the scroll offset. 155 // the scroll offset. Don't save values if we're still waiting to restore
156 if (!m_haveEnteredFullscreen) { 156 // a previous set. This can happen if we exit and quickly reenter fullscreen
157 // without performing a layout.
158 if (!m_haveEnteredFullscreen && !m_needsScrollAndScaleRestore) {
157 m_exitFullscreenPageScaleFactor = m_webViewImpl->pageScaleFactor(); 159 m_exitFullscreenPageScaleFactor = m_webViewImpl->pageScaleFactor();
158 m_exitFullscreenScrollOffset = m_webViewImpl->mainFrame()->isWebLocalFra me() ? m_webViewImpl->mainFrame()->scrollOffset() : WebSize(); 160 m_exitFullscreenScrollOffset = m_webViewImpl->mainFrame()->isWebLocalFra me() ? m_webViewImpl->mainFrame()->scrollOffset() : WebSize();
159 m_exitFullscreenVisualViewportOffset = m_webViewImpl->visualViewportOffs et(); 161 m_exitFullscreenVisualViewportOffset = m_webViewImpl->visualViewportOffs et();
160 } 162 }
161 163
162 // We need to transition to fullscreen mode. 164 // We need to transition to fullscreen mode.
163 WebLocalFrameImpl* frame = WebLocalFrameImpl::fromFrame(element->document(). frame()); 165 WebLocalFrameImpl* frame = WebLocalFrameImpl::fromFrame(element->document(). frame());
164 if (frame && frame->client()) { 166 if (frame && frame->client()) {
165 if (!Fullscreen::from(element->document()).forCrossProcessDescendant()) 167 if (!Fullscreen::from(element->document()).forCrossProcessDescendant())
166 frame->client()->enterFullscreen(); 168 frame->client()->enterFullscreen();
(...skipping 26 matching lines...) Expand all
193 if (!isFullscreen()) 195 if (!isFullscreen())
194 return; 196 return;
195 197
196 updatePageScaleConstraints(false); 198 updatePageScaleConstraints(false);
197 199
198 Document* document = m_fullScreenFrame->document(); 200 Document* document = m_fullScreenFrame->document();
199 if (Element* fullscreenElement = Fullscreen::currentFullScreenElementFrom(*d ocument)) 201 if (Element* fullscreenElement = Fullscreen::currentFullScreenElementFrom(*d ocument))
200 Fullscreen::from(fullscreenElement->document()).didUpdateSize(*fullscree nElement); 202 Fullscreen::from(fullscreenElement->document()).didUpdateSize(*fullscree nElement);
201 } 203 }
202 204
205 void FullscreenController::didUpdateLayout()
206 {
207 if (!m_needsScrollAndScaleRestore)
208 return;
209
210 // If we re-entered fullscreen before we could restore the scroll and scale
211 // don't try restoring them yet.
212 if (isFullscreen())
213 return;
214
215 m_webViewImpl->setPageScaleFactor(m_exitFullscreenPageScaleFactor);
216 if (m_webViewImpl->mainFrame()->isWebLocalFrame())
217 m_webViewImpl->mainFrame()->setScrollOffset(WebSize(m_exitFullscreenScro llOffset));
218 m_webViewImpl->setVisualViewportOffset(m_exitFullscreenVisualViewportOffset) ;
219 m_needsScrollAndScaleRestore = false;
220 }
221
203 void FullscreenController::updatePageScaleConstraints(bool removeConstraints) 222 void FullscreenController::updatePageScaleConstraints(bool removeConstraints)
204 { 223 {
205 PageScaleConstraints fullscreenConstraints; 224 PageScaleConstraints fullscreenConstraints;
206 if (!removeConstraints) { 225 if (!removeConstraints) {
207 fullscreenConstraints = PageScaleConstraints(1.0, 1.0, 1.0); 226 fullscreenConstraints = PageScaleConstraints(1.0, 1.0, 1.0);
208 fullscreenConstraints.layoutSize = FloatSize(m_webViewImpl->size()); 227 fullscreenConstraints.layoutSize = FloatSize(m_webViewImpl->size());
209 } 228 }
210 m_webViewImpl->pageScaleConstraintsSet().setFullscreenConstraints(fullscreen Constraints); 229 m_webViewImpl->pageScaleConstraintsSet().setFullscreenConstraints(fullscreen Constraints);
211 m_webViewImpl->pageScaleConstraintsSet().computeFinalConstraints(); 230 m_webViewImpl->pageScaleConstraintsSet().computeFinalConstraints();
212 231
213 // Although we called computedFinalConstraints() above, the "final" constrai nts are not 232 // Although we called computedFinalConstraints() above, the "final" constrai nts are not
214 // actually final. They are still subject to scale factor clamping by conten ts size. 233 // actually final. They are still subject to scale factor clamping by conten ts size.
215 // Normally they should be dirtied due to contents size mutation after layou t, however the 234 // Normally they should be dirtied due to contents size mutation after layou t, however the
216 // contents size is not guaranteed to mutate, and the scale factor may remai n unclamped. 235 // contents size is not guaranteed to mutate, and the scale factor may remai n unclamped.
217 // Just fire the event again to ensure the final constraints pick up the lat est contents size. 236 // Just fire the event again to ensure the final constraints pick up the lat est contents size.
218 m_webViewImpl->didChangeContentsSize(); 237 m_webViewImpl->didChangeContentsSize();
219 if (m_webViewImpl->mainFrameImpl() && m_webViewImpl->mainFrameImpl()->frameV iew()) 238 if (m_webViewImpl->mainFrameImpl() && m_webViewImpl->mainFrameImpl()->frameV iew())
220 m_webViewImpl->mainFrameImpl()->frameView()->setNeedsLayout(); 239 m_webViewImpl->mainFrameImpl()->frameView()->setNeedsLayout();
221 240
222 m_webViewImpl->updateMainFrameLayoutSize(); 241 m_webViewImpl->updateMainFrameLayoutSize();
223 } 242 }
224 243
225 DEFINE_TRACE(FullscreenController) 244 DEFINE_TRACE(FullscreenController)
226 { 245 {
227 visitor->trace(m_provisionalFullScreenElement); 246 visitor->trace(m_provisionalFullScreenElement);
228 visitor->trace(m_fullScreenFrame); 247 visitor->trace(m_fullScreenFrame);
229 } 248 }
230 249
231 } // namespace blink 250 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/FullscreenController.h ('k') | third_party/WebKit/Source/web/WebViewImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698