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

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

Issue 2495423004: Convert FullscreenController to use WebCallbacks (Closed)
Patch Set: just in case Created 4 years 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 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "web/FullscreenController.h" 31 #include "web/FullscreenController.h"
32 32
33 #include "core/dom/Document.h" 33 #include "core/dom/Document.h"
34 #include "core/dom/Fullscreen.h" 34 #include "core/dom/Fullscreen.h"
35 #include "core/dom/FullscreenCallbacks.h"
35 #include "core/frame/FrameView.h" 36 #include "core/frame/FrameView.h"
36 #include "core/frame/LocalFrame.h" 37 #include "core/frame/LocalFrame.h"
37 #include "core/frame/PageScaleConstraintsSet.h" 38 #include "core/frame/PageScaleConstraintsSet.h"
38 #include "core/html/HTMLVideoElement.h" 39 #include "core/html/HTMLVideoElement.h"
39 #include "core/layout/LayoutFullScreen.h" 40 #include "core/layout/LayoutFullScreen.h"
40 #include "public/platform/WebLayerTreeView.h" 41 #include "public/platform/WebLayerTreeView.h"
41 #include "public/web/WebFrameClient.h" 42 #include "public/web/WebFrameClient.h"
42 #include "web/WebLocalFrameImpl.h" 43 #include "web/WebLocalFrameImpl.h"
43 #include "web/WebViewImpl.h" 44 #include "web/WebViewImpl.h"
44 45
(...skipping 26 matching lines...) Expand all
71 return; 72 return;
72 73
73 updatePageScaleConstraints(false); 74 updatePageScaleConstraints(false);
74 m_webViewImpl->setPageScaleFactor(1.0f); 75 m_webViewImpl->setPageScaleFactor(1.0f);
75 if (m_webViewImpl->mainFrame()->isWebLocalFrame()) 76 if (m_webViewImpl->mainFrame()->isWebLocalFrame())
76 m_webViewImpl->mainFrame()->setScrollOffset(WebSize()); 77 m_webViewImpl->mainFrame()->setScrollOffset(WebSize());
77 m_webViewImpl->setVisualViewportOffset(FloatPoint()); 78 m_webViewImpl->setVisualViewportOffset(FloatPoint());
78 79
79 m_state = State::Fullscreen; 80 m_state = State::Fullscreen;
80 81
81 // Notify all local frames that we have entered fullscreen. 82 DCHECK(!m_callbacksList.isEmpty());
82 for (Frame* frame = m_webViewImpl->page()->mainFrame(); frame; 83 CallbacksList callbacksList;
83 frame = frame->tree().traverseNext()) { 84 callbacksList.swap(m_callbacksList);
84 if (!frame->isLocalFrame()) 85 for (auto& callbacks : callbacksList)
85 continue; 86 callbacks->onSuccess();
86 if (Document* document = toLocalFrame(frame)->document()) {
87 if (Fullscreen* fullscreen = Fullscreen::fromIfExists(*document))
88 fullscreen->didEnterFullscreen();
89 }
90 }
91 } 87 }
92 88
93 void FullscreenController::didExitFullscreen() { 89 void FullscreenController::didExitFullscreen() {
94 // The browser process can exit fullscreen at any time, e.g. if the user 90 // The browser process can exit fullscreen at any time, e.g. if the user
95 // presses Esc. After |Browser::EnterFullscreenModeForTab()|, 91 // presses Esc. After |Browser::EnterFullscreenModeForTab()|,
96 // |Browser::ExitFullscreenModeForTab()| will make it seem like we exit when 92 // |Browser::ExitFullscreenModeForTab()| will make it seem like we exit when
97 // not even in fullscreen. Do nothing. 93 // not even in fullscreen. Do nothing.
98 if (m_state == State::Initial) 94 if (m_state == State::Initial)
99 return; 95 return;
100 96
101 updatePageScaleConstraints(true); 97 updatePageScaleConstraints(true);
102 98
103 // Set |m_state| so that any |exitFullscreen()| calls from within 99 // Set |m_state| so that any |exitFullscreen()| calls from within
104 // |Fullscreen::didExitFullscreen()| do not call 100 // |Fullscreen::didExitFullscreen()| do not call
105 // |WebFrameClient::exitFullscreen()| again. 101 // |WebFrameClient::exitFullscreen()| again.
106 // TODO(foolip): Remove this when state changes and events are synchronized 102 // TODO(foolip): Remove this when state changes and events are synchronized
107 // with animation frames. https://crbug.com/402376 103 // with animation frames. https://crbug.com/402376
108 m_state = State::ExitingFullscreen; 104 m_state = State::ExitingFullscreen;
109 105
106 // If we were transitioning into fullscreen, invoke the error callbacks.
107 if (m_state == State::EnteringFullscreen) {
108 DCHECK(!m_callbacksList.isEmpty());
109 CallbacksList callbacksList;
110 callbacksList.swap(m_callbacksList);
111 for (auto& callbacks : callbacksList)
112 callbacks->onError();
113 } else {
114 DCHECK(m_callbacksList.isEmpty());
115 }
116
110 // Notify all local frames that we have exited fullscreen. 117 // Notify all local frames that we have exited fullscreen.
111 // TODO(foolip): This should only need to notify the topmost local roots. That 118 // TODO(foolip): This should only need to notify the topmost local roots. That
112 // doesn't currently work because |Fullscreen::m_currentFullScreenElement| 119 // doesn't currently work because |Fullscreen::m_currentFullScreenElement|
113 // isn't set for the topmost document when an iframe goes fullscreen, but can 120 // isn't set for the topmost document when an iframe goes fullscreen, but can
114 // be done once |m_currentFullScreenElement| is gone and all state is in the 121 // be done once |m_currentFullScreenElement| is gone and all state is in the
115 // fullscreen element stack. https://crbug.com/402421 122 // fullscreen element stack. https://crbug.com/402421
116 for (Frame* frame = m_webViewImpl->page()->mainFrame(); frame; 123 for (Frame* frame = m_webViewImpl->page()->mainFrame(); frame;
117 frame = frame->tree().traverseNext()) { 124 frame = frame->tree().traverseNext()) {
118 if (!frame->isLocalFrame()) 125 if (!frame->isLocalFrame())
119 continue; 126 continue;
120 if (Document* document = toLocalFrame(frame)->document()) { 127 if (Document* document = toLocalFrame(frame)->document()) {
121 if (Fullscreen* fullscreen = Fullscreen::fromIfExists(*document)) 128 if (Fullscreen* fullscreen = Fullscreen::fromIfExists(*document))
122 fullscreen->didExitFullscreen(); 129 fullscreen->didExitFullscreen();
123 } 130 }
124 } 131 }
125 132
126 // We need to wait until style and layout are updated in order to properly 133 // We need to wait until style and layout are updated in order to properly
127 // restore scroll offsets since content may not be overflowing in the same way 134 // restore scroll offsets since content may not be overflowing in the same way
128 // until they are. 135 // until they are.
129 m_state = State::NeedsScrollAndScaleRestore; 136 m_state = State::NeedsScrollAndScaleRestore;
130 } 137 }
131 138
132 void FullscreenController::enterFullscreen(LocalFrame& frame) { 139 void FullscreenController::enterFullscreen(
133 // If already fullscreen or exiting fullscreen, synchronously call 140 LocalFrame& frame,
134 // |didEnterFullscreen()|. When exiting, the coming |didExitFullscren()| call 141 std::unique_ptr<FullscreenCallbacks> callbacks) {
135 // will again notify all frames. 142 // If already fullscreen or exiting fullscreen, synchronously invoke the
143 // success callback. When exiting, the coming |didExitFullscren()| call will
144 // again notify all frames.
136 if (m_state == State::Fullscreen || m_state == State::ExitingFullscreen) { 145 if (m_state == State::Fullscreen || m_state == State::ExitingFullscreen) {
137 State oldState = m_state; 146 State oldState = m_state;
138 m_state = State::EnteringFullscreen; 147 m_state = State::EnteringFullscreen;
139 didEnterFullscreen(); 148 callbacks->onSuccess();
140 m_state = oldState; 149 m_state = oldState;
141 return; 150 return;
142 } 151 }
143 152
144 // We need to store these values here rather than in |didEnterFullscreen()| 153 // We need to store these values here rather than in |didEnterFullscreen()|
145 // since by the time the latter is called, a Resize has already occured, 154 // since by the time the latter is called, a Resize has already occured,
146 // clamping the scroll offset. Don't save values if we're still waiting to 155 // clamping the scroll offset. Don't save values if we're still waiting to
147 // restore a previous set. This can happen if we exit and quickly reenter 156 // restore a previous set. This can happen if we exit and quickly reenter
148 // fullscreen without performing a layout. 157 // fullscreen without performing a layout.
149 if (m_state == State::Initial) { 158 if (m_state == State::Initial) {
150 m_initialPageScaleFactor = m_webViewImpl->pageScaleFactor(); 159 m_initialPageScaleFactor = m_webViewImpl->pageScaleFactor();
151 m_initialScrollOffset = m_webViewImpl->mainFrame()->isWebLocalFrame() 160 m_initialScrollOffset = m_webViewImpl->mainFrame()->isWebLocalFrame()
152 ? m_webViewImpl->mainFrame()->getScrollOffset() 161 ? m_webViewImpl->mainFrame()->getScrollOffset()
153 : WebSize(); 162 : WebSize();
154 m_initialVisualViewportOffset = m_webViewImpl->visualViewportOffset(); 163 m_initialVisualViewportOffset = m_webViewImpl->visualViewportOffset();
155 } 164 }
156 165
166 m_callbacksList.append(std::move(callbacks));
167
157 // If already entering fullscreen, just wait. 168 // If already entering fullscreen, just wait.
158 if (m_state == State::EnteringFullscreen) 169 if (m_state == State::EnteringFullscreen)
159 return; 170 return;
160 171
161 DCHECK(m_state == State::Initial || 172 DCHECK(m_state == State::Initial ||
162 m_state == State::NeedsScrollAndScaleRestore); 173 m_state == State::NeedsScrollAndScaleRestore);
163 webFrameClient(frame).enterFullscreen(); 174 webFrameClient(frame).enterFullscreen();
164 175
165 m_state = State::EnteringFullscreen; 176 m_state = State::EnteringFullscreen;
166 } 177 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 // again to ensure the final constraints pick up the latest contents size. 278 // again to ensure the final constraints pick up the latest contents size.
268 m_webViewImpl->didChangeContentsSize(); 279 m_webViewImpl->didChangeContentsSize();
269 if (m_webViewImpl->mainFrameImpl() && 280 if (m_webViewImpl->mainFrameImpl() &&
270 m_webViewImpl->mainFrameImpl()->frameView()) 281 m_webViewImpl->mainFrameImpl()->frameView())
271 m_webViewImpl->mainFrameImpl()->frameView()->setNeedsLayout(); 282 m_webViewImpl->mainFrameImpl()->frameView()->setNeedsLayout();
272 283
273 m_webViewImpl->updateMainFrameLayoutSize(); 284 m_webViewImpl->updateMainFrameLayoutSize();
274 } 285 }
275 286
276 } // namespace blink 287 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/FullscreenController.h ('k') | third_party/WebKit/Source/web/WebViewImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698