| OLD | NEW |
| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 // Notify all local frames that we have entered fullscreen. | 81 // Notify all local frames that we have entered fullscreen. |
| 82 for (Frame* frame = m_webViewImpl->page()->mainFrame(); frame; | 82 for (Frame* frame = m_webViewImpl->page()->mainFrame(); frame; |
| 83 frame = frame->tree().traverseNext()) { | 83 frame = frame->tree().traverseNext()) { |
| 84 if (!frame->isLocalFrame()) | 84 if (!frame->isLocalFrame()) |
| 85 continue; | 85 continue; |
| 86 if (Document* document = toLocalFrame(frame)->document()) { | 86 if (Document* document = toLocalFrame(frame)->document()) { |
| 87 if (Fullscreen* fullscreen = Fullscreen::fromIfExists(*document)) | 87 if (Fullscreen* fullscreen = Fullscreen::fromIfExists(*document)) |
| 88 fullscreen->didEnterFullscreen(); | 88 fullscreen->didEnterFullscreen(); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | |
| 92 // TODO(foolip): If the top level browsing context (main frame) ends up with | |
| 93 // no fullscreen element, exit fullscreen again to recover. | |
| 94 } | 91 } |
| 95 | 92 |
| 96 void FullscreenController::didExitFullscreen() { | 93 void FullscreenController::didExitFullscreen() { |
| 97 // The browser process can exit fullscreen at any time, e.g. if the user | 94 // The browser process can exit fullscreen at any time, e.g. if the user |
| 98 // presses Esc. After |Browser::EnterFullscreenModeForTab()|, | 95 // presses Esc. After |Browser::EnterFullscreenModeForTab()|, |
| 99 // |Browser::ExitFullscreenModeForTab()| will make it seem like we exit when | 96 // |Browser::ExitFullscreenModeForTab()| will make it seem like we exit when |
| 100 // not even in fullscreen. Do nothing. | 97 // not even in fullscreen. Do nothing. |
| 101 if (m_state == State::Initial) | 98 if (m_state == State::Initial) |
| 102 return; | 99 return; |
| 103 | 100 |
| 104 updatePageScaleConstraints(true); | 101 updatePageScaleConstraints(true); |
| 105 | 102 |
| 103 // Set |m_state| so that any |exitFullscreen()| calls from within |
| 104 // |Fullscreen::didExitFullscreen()| do not call |
| 105 // |WebFrameClient::exitFullscreen()| again. |
| 106 // TODO(foolip): Remove this when state changes and events are synchronized |
| 107 // with animation frames. https://crbug.com/402376 |
| 108 m_state = State::ExitingFullscreen; |
| 109 |
| 110 // Notify all local frames that we have exited fullscreen. |
| 111 // TODO(foolip): This should only need to notify the topmost local roots. That |
| 112 // doesn't currently work because |Fullscreen::m_currentFullScreenElement| |
| 113 // 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 |
| 115 // fullscreen element stack. https://crbug.com/402421 |
| 116 for (Frame* frame = m_webViewImpl->page()->mainFrame(); frame; |
| 117 frame = frame->tree().traverseNext()) { |
| 118 if (!frame->isLocalFrame()) |
| 119 continue; |
| 120 if (Document* document = toLocalFrame(frame)->document()) { |
| 121 if (Fullscreen* fullscreen = Fullscreen::fromIfExists(*document)) |
| 122 fullscreen->didExitFullscreen(); |
| 123 } |
| 124 } |
| 125 |
| 106 // We need to wait until style and layout are updated in order to properly | 126 // We need to wait until style and layout are updated in order to properly |
| 107 // restore scroll offsets since content may not be overflowing in the same way | 127 // restore scroll offsets since content may not be overflowing in the same way |
| 108 // until they are. | 128 // until they are. |
| 109 m_state = State::NeedsScrollAndScaleRestore; | 129 m_state = State::NeedsScrollAndScaleRestore; |
| 110 | |
| 111 // Notify the topmost local frames that we have exited fullscreen. | |
| 112 // |Fullscreen::didExitFullscreen()| will take care of descendant frames. | |
| 113 for (Frame* frame = m_webViewImpl->page()->mainFrame(); frame;) { | |
| 114 Frame* nextFrame = frame->tree().traverseNext(); | |
| 115 | |
| 116 if (frame->isRemoteFrame()) { | |
| 117 frame = nextFrame; | |
| 118 continue; | |
| 119 } | |
| 120 | |
| 121 DCHECK(frame->isLocalRoot()); | |
| 122 if (Document* document = toLocalFrame(frame)->document()) { | |
| 123 if (Fullscreen* fullscreen = Fullscreen::fromIfExists(*document)) | |
| 124 fullscreen->didExitFullscreen(); | |
| 125 } | |
| 126 | |
| 127 // Skip over all descendant frames. | |
| 128 while (nextFrame && nextFrame->tree().isDescendantOf(frame)) | |
| 129 nextFrame = nextFrame->tree().traverseNext(); | |
| 130 frame = nextFrame; | |
| 131 } | |
| 132 } | 130 } |
| 133 | 131 |
| 134 void FullscreenController::enterFullscreen(LocalFrame& frame) { | 132 void FullscreenController::enterFullscreen(LocalFrame& frame) { |
| 135 // If already fullscreen or exiting fullscreen, synchronously call | 133 // If already fullscreen or exiting fullscreen, synchronously call |
| 136 // |didEnterFullscreen()|. When exiting, the coming |didExitFullscren()| call | 134 // |didEnterFullscreen()|. When exiting, the coming |didExitFullscren()| call |
| 137 // will again notify all frames. | 135 // will again notify all frames. |
| 138 if (m_state == State::Fullscreen || m_state == State::ExitingFullscreen) { | 136 if (m_state == State::Fullscreen || m_state == State::ExitingFullscreen) { |
| 139 State oldState = m_state; | 137 State oldState = m_state; |
| 140 m_state = State::EnteringFullscreen; | 138 m_state = State::EnteringFullscreen; |
| 141 didEnterFullscreen(); | 139 didEnterFullscreen(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 webFrameClient(frame).exitFullscreen(); | 176 webFrameClient(frame).exitFullscreen(); |
| 179 | 177 |
| 180 m_state = State::ExitingFullscreen; | 178 m_state = State::ExitingFullscreen; |
| 181 } | 179 } |
| 182 | 180 |
| 183 void FullscreenController::fullscreenElementChanged(Element* fromElement, | 181 void FullscreenController::fullscreenElementChanged(Element* fromElement, |
| 184 Element* toElement) { | 182 Element* toElement) { |
| 185 DCHECK_NE(fromElement, toElement); | 183 DCHECK_NE(fromElement, toElement); |
| 186 | 184 |
| 187 if (toElement) { | 185 if (toElement) { |
| 188 DCHECK(Fullscreen::isFullscreenElement(*toElement)); | 186 DCHECK(Fullscreen::isCurrentFullScreenElement(*toElement)); |
| 189 | 187 |
| 190 if (isHTMLVideoElement(*toElement)) { | 188 if (isHTMLVideoElement(*toElement)) { |
| 191 HTMLVideoElement& videoElement = toHTMLVideoElement(*toElement); | 189 HTMLVideoElement& videoElement = toHTMLVideoElement(*toElement); |
| 192 videoElement.didEnterFullscreen(); | 190 videoElement.didEnterFullscreen(); |
| 193 | 191 |
| 194 // If the video uses overlay fullscreen mode, make the background | 192 // If the video uses overlay fullscreen mode, make the background |
| 195 // transparent. | 193 // transparent. |
| 196 if (videoElement.usesOverlayFullscreenVideo() && | 194 if (videoElement.usesOverlayFullscreenVideo() && |
| 197 m_webViewImpl->layerTreeView()) { | 195 m_webViewImpl->layerTreeView()) { |
| 198 m_webViewImpl->layerTreeView()->setHasTransparentBackground(true); | 196 m_webViewImpl->layerTreeView()->setHasTransparentBackground(true); |
| 199 } | 197 } |
| 200 } | 198 } |
| 201 } | 199 } |
| 202 | 200 |
| 203 if (fromElement) { | 201 if (fromElement) { |
| 204 DCHECK(!Fullscreen::isFullscreenElement(*fromElement)); | 202 DCHECK(!Fullscreen::isCurrentFullScreenElement(*fromElement)); |
| 205 | 203 |
| 206 if (isHTMLVideoElement(*fromElement)) { | 204 if (isHTMLVideoElement(*fromElement)) { |
| 207 // If the video used overlay fullscreen mode, restore the transparency. | 205 // If the video used overlay fullscreen mode, restore the transparency. |
| 208 if (m_webViewImpl->layerTreeView()) { | 206 if (m_webViewImpl->layerTreeView()) { |
| 209 m_webViewImpl->layerTreeView()->setHasTransparentBackground( | 207 m_webViewImpl->layerTreeView()->setHasTransparentBackground( |
| 210 m_webViewImpl->isTransparent()); | 208 m_webViewImpl->isTransparent()); |
| 211 } | 209 } |
| 212 | 210 |
| 213 HTMLVideoElement& videoElement = toHTMLVideoElement(*fromElement); | 211 HTMLVideoElement& videoElement = toHTMLVideoElement(*fromElement); |
| 214 videoElement.didExitFullscreen(); | 212 videoElement.didExitFullscreen(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 // again to ensure the final constraints pick up the latest contents size. | 267 // again to ensure the final constraints pick up the latest contents size. |
| 270 m_webViewImpl->didChangeContentsSize(); | 268 m_webViewImpl->didChangeContentsSize(); |
| 271 if (m_webViewImpl->mainFrameImpl() && | 269 if (m_webViewImpl->mainFrameImpl() && |
| 272 m_webViewImpl->mainFrameImpl()->frameView()) | 270 m_webViewImpl->mainFrameImpl()->frameView()) |
| 273 m_webViewImpl->mainFrameImpl()->frameView()->setNeedsLayout(); | 271 m_webViewImpl->mainFrameImpl()->frameView()->setNeedsLayout(); |
| 274 | 272 |
| 275 m_webViewImpl->updateMainFrameLayoutSize(); | 273 m_webViewImpl->updateMainFrameLayoutSize(); |
| 276 } | 274 } |
| 277 | 275 |
| 278 } // namespace blink | 276 } // namespace blink |
| OLD | NEW |