Chromium Code Reviews| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 // since by the time the latter is called, a Resize has already occured, | 145 // 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 | 146 // 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 | 147 // restore a previous set. This can happen if we exit and quickly reenter |
| 148 // fullscreen without performing a layout. | 148 // fullscreen without performing a layout. |
| 149 if (m_state == State::Initial) { | 149 if (m_state == State::Initial) { |
| 150 m_initialPageScaleFactor = m_webViewImpl->pageScaleFactor(); | 150 m_initialPageScaleFactor = m_webViewImpl->pageScaleFactor(); |
| 151 m_initialScrollOffset = m_webViewImpl->mainFrame()->isWebLocalFrame() | 151 m_initialScrollOffset = m_webViewImpl->mainFrame()->isWebLocalFrame() |
| 152 ? m_webViewImpl->mainFrame()->getScrollOffset() | 152 ? m_webViewImpl->mainFrame()->getScrollOffset() |
| 153 : WebSize(); | 153 : WebSize(); |
| 154 m_initialVisualViewportOffset = m_webViewImpl->visualViewportOffset(); | 154 m_initialVisualViewportOffset = m_webViewImpl->visualViewportOffset(); |
| 155 m_initialBackgroundColorOverrideEnabled = | |
| 156 m_webViewImpl->backgroundColorOverrideEnabled(); | |
| 157 m_initialBackgroundColorOverride = m_webViewImpl->backgroundColorOverride(); | |
| 155 } | 158 } |
| 156 | 159 |
| 157 // If already entering fullscreen, just wait. | 160 // If already entering fullscreen, just wait. |
| 158 if (m_state == State::EnteringFullscreen) | 161 if (m_state == State::EnteringFullscreen) |
| 159 return; | 162 return; |
| 160 | 163 |
| 161 DCHECK(m_state == State::Initial || | 164 DCHECK(m_state == State::Initial || |
| 162 m_state == State::NeedsScrollAndScaleRestore); | 165 m_state == State::NeedsScrollAndScaleRestore); |
| 163 webFrameClient(frame).enterFullscreen(); | 166 webFrameClient(frame).enterFullscreen(); |
| 164 | 167 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 175 | 178 |
| 176 webFrameClient(frame).exitFullscreen(); | 179 webFrameClient(frame).exitFullscreen(); |
| 177 | 180 |
| 178 m_state = State::ExitingFullscreen; | 181 m_state = State::ExitingFullscreen; |
| 179 } | 182 } |
| 180 | 183 |
| 181 void FullscreenController::fullscreenElementChanged(Element* fromElement, | 184 void FullscreenController::fullscreenElementChanged(Element* fromElement, |
| 182 Element* toElement) { | 185 Element* toElement) { |
| 183 DCHECK_NE(fromElement, toElement); | 186 DCHECK_NE(fromElement, toElement); |
| 184 | 187 |
| 188 // We only override the WebView's background color for overlay fullscreen | |
| 189 // video elements, so have to restore the override when the element changes. | |
| 190 restoreBackgroundColorOverride(); | |
|
chrishtr
2017/03/28 19:45:56
Are the code changes in this file tested by a layo
Eric Seckler
2017/03/29 10:50:18
Yeah, there's a unit test [1], which fails if we d
| |
| 191 | |
| 185 if (toElement) { | 192 if (toElement) { |
| 186 DCHECK(Fullscreen::isCurrentFullScreenElement(*toElement)); | 193 DCHECK(Fullscreen::isCurrentFullScreenElement(*toElement)); |
| 187 | 194 |
| 188 if (isHTMLVideoElement(*toElement)) { | 195 if (isHTMLVideoElement(*toElement)) { |
| 189 HTMLVideoElement& videoElement = toHTMLVideoElement(*toElement); | 196 HTMLVideoElement& videoElement = toHTMLVideoElement(*toElement); |
| 190 videoElement.didEnterFullscreen(); | 197 videoElement.didEnterFullscreen(); |
| 191 | 198 |
| 192 // If the video uses overlay fullscreen mode, make the background | 199 // If the video uses overlay fullscreen mode, make the background |
| 193 // transparent. | 200 // transparent. |
| 194 if (videoElement.usesOverlayFullscreenVideo() && | 201 if (videoElement.usesOverlayFullscreenVideo()) |
| 195 m_webViewImpl->layerTreeView()) { | 202 m_webViewImpl->setBackgroundColorOverride(Color::transparent); |
| 196 m_webViewImpl->layerTreeView()->setHasTransparentBackground(true); | |
| 197 } | |
| 198 } | 203 } |
| 199 } | 204 } |
| 200 | 205 |
| 201 if (fromElement) { | 206 if (fromElement) { |
| 202 DCHECK(!Fullscreen::isCurrentFullScreenElement(*fromElement)); | 207 DCHECK(!Fullscreen::isCurrentFullScreenElement(*fromElement)); |
| 203 | 208 |
| 204 if (isHTMLVideoElement(*fromElement)) { | 209 if (isHTMLVideoElement(*fromElement)) { |
| 205 // If the video used overlay fullscreen mode, restore the transparency. | |
| 206 if (m_webViewImpl->layerTreeView()) { | |
| 207 m_webViewImpl->layerTreeView()->setHasTransparentBackground( | |
| 208 m_webViewImpl->isTransparent()); | |
| 209 } | |
| 210 | |
| 211 HTMLVideoElement& videoElement = toHTMLVideoElement(*fromElement); | 210 HTMLVideoElement& videoElement = toHTMLVideoElement(*fromElement); |
| 212 videoElement.didExitFullscreen(); | 211 videoElement.didExitFullscreen(); |
| 213 } | 212 } |
| 214 } | 213 } |
| 215 } | 214 } |
| 216 | 215 |
| 216 void FullscreenController::restoreBackgroundColorOverride() { | |
| 217 if (m_webViewImpl->backgroundColorOverrideEnabled() != | |
| 218 m_initialBackgroundColorOverrideEnabled || | |
| 219 m_webViewImpl->backgroundColorOverride() != | |
| 220 m_initialBackgroundColorOverride) { | |
| 221 if (m_initialBackgroundColorOverrideEnabled) { | |
| 222 m_webViewImpl->setBackgroundColorOverride( | |
| 223 m_initialBackgroundColorOverride); | |
| 224 } else { | |
| 225 m_webViewImpl->clearBackgroundColorOverride(); | |
| 226 } | |
| 227 } | |
| 228 } | |
| 229 | |
| 217 void FullscreenController::updateSize() { | 230 void FullscreenController::updateSize() { |
| 218 DCHECK(m_webViewImpl->page()); | 231 DCHECK(m_webViewImpl->page()); |
| 219 | 232 |
| 220 if (m_state != State::Fullscreen && m_state != State::ExitingFullscreen) | 233 if (m_state != State::Fullscreen && m_state != State::ExitingFullscreen) |
| 221 return; | 234 return; |
| 222 | 235 |
| 223 updatePageScaleConstraints(false); | 236 updatePageScaleConstraints(false); |
| 224 | 237 |
| 225 // Traverse all local frames and notify the LayoutFullScreen object, if any. | 238 // Traverse all local frames and notify the LayoutFullScreen object, if any. |
| 226 for (Frame* frame = m_webViewImpl->page()->mainFrame(); frame; | 239 for (Frame* frame = m_webViewImpl->page()->mainFrame(); frame; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 238 } | 251 } |
| 239 | 252 |
| 240 void FullscreenController::didUpdateLayout() { | 253 void FullscreenController::didUpdateLayout() { |
| 241 if (m_state != State::NeedsScrollAndScaleRestore) | 254 if (m_state != State::NeedsScrollAndScaleRestore) |
| 242 return; | 255 return; |
| 243 | 256 |
| 244 m_webViewImpl->setPageScaleFactor(m_initialPageScaleFactor); | 257 m_webViewImpl->setPageScaleFactor(m_initialPageScaleFactor); |
| 245 if (m_webViewImpl->mainFrame()->isWebLocalFrame()) | 258 if (m_webViewImpl->mainFrame()->isWebLocalFrame()) |
| 246 m_webViewImpl->mainFrame()->setScrollOffset(WebSize(m_initialScrollOffset)); | 259 m_webViewImpl->mainFrame()->setScrollOffset(WebSize(m_initialScrollOffset)); |
| 247 m_webViewImpl->setVisualViewportOffset(m_initialVisualViewportOffset); | 260 m_webViewImpl->setVisualViewportOffset(m_initialVisualViewportOffset); |
| 261 // Background color override was already restored when | |
| 262 // fullscreenElementChanged([..], nullptr) was called while exiting. | |
| 248 | 263 |
| 249 m_state = State::Initial; | 264 m_state = State::Initial; |
| 250 } | 265 } |
| 251 | 266 |
| 252 void FullscreenController::updatePageScaleConstraints(bool removeConstraints) { | 267 void FullscreenController::updatePageScaleConstraints(bool removeConstraints) { |
| 253 PageScaleConstraints fullscreenConstraints; | 268 PageScaleConstraints fullscreenConstraints; |
| 254 if (!removeConstraints) { | 269 if (!removeConstraints) { |
| 255 fullscreenConstraints = PageScaleConstraints(1.0, 1.0, 1.0); | 270 fullscreenConstraints = PageScaleConstraints(1.0, 1.0, 1.0); |
| 256 fullscreenConstraints.layoutSize = FloatSize(m_webViewImpl->size()); | 271 fullscreenConstraints.layoutSize = FloatSize(m_webViewImpl->size()); |
| 257 } | 272 } |
| 258 m_webViewImpl->pageScaleConstraintsSet().setFullscreenConstraints( | 273 m_webViewImpl->pageScaleConstraintsSet().setFullscreenConstraints( |
| 259 fullscreenConstraints); | 274 fullscreenConstraints); |
| 260 m_webViewImpl->pageScaleConstraintsSet().computeFinalConstraints(); | 275 m_webViewImpl->pageScaleConstraintsSet().computeFinalConstraints(); |
| 261 | 276 |
| 262 // Although we called |computedFinalConstraints()| above, the "final" | 277 // Although we called |computedFinalConstraints()| above, the "final" |
| 263 // constraints are not actually final. They are still subject to scale factor | 278 // constraints are not actually final. They are still subject to scale factor |
| 264 // clamping by contents size. Normally they should be dirtied due to contents | 279 // clamping by contents size. Normally they should be dirtied due to contents |
| 265 // size mutation after layout, however the contents size is not guaranteed to | 280 // size mutation after layout, however the contents size is not guaranteed to |
| 266 // mutate, and the scale factor may remain unclamped. Just fire the event | 281 // mutate, and the scale factor may remain unclamped. Just fire the event |
| 267 // again to ensure the final constraints pick up the latest contents size. | 282 // again to ensure the final constraints pick up the latest contents size. |
| 268 m_webViewImpl->didChangeContentsSize(); | 283 m_webViewImpl->didChangeContentsSize(); |
| 269 if (m_webViewImpl->mainFrameImpl() && | 284 if (m_webViewImpl->mainFrameImpl() && |
| 270 m_webViewImpl->mainFrameImpl()->frameView()) | 285 m_webViewImpl->mainFrameImpl()->frameView()) |
| 271 m_webViewImpl->mainFrameImpl()->frameView()->setNeedsLayout(); | 286 m_webViewImpl->mainFrameImpl()->frameView()->setNeedsLayout(); |
| 272 | 287 |
| 273 m_webViewImpl->updateMainFrameLayoutSize(); | 288 m_webViewImpl->updateMainFrameLayoutSize(); |
| 274 } | 289 } |
| 275 | 290 |
| 276 } // namespace blink | 291 } // namespace blink |
| OLD | NEW |