| 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 14 matching lines...) Expand all Loading... |
| 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/exported/WebViewBase.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" |
| 41 #include "core/page/Page.h" |
| 40 #include "public/platform/WebLayerTreeView.h" | 42 #include "public/platform/WebLayerTreeView.h" |
| 41 #include "public/web/WebFrameClient.h" | 43 #include "public/web/WebFrameClient.h" |
| 42 #include "web/WebLocalFrameImpl.h" | 44 #include "web/WebLocalFrameImpl.h" |
| 43 #include "web/WebViewImpl.h" | |
| 44 | 45 |
| 45 namespace blink { | 46 namespace blink { |
| 46 | 47 |
| 47 namespace { | 48 namespace { |
| 48 | 49 |
| 49 WebFrameClient& GetWebFrameClient(LocalFrame& frame) { | 50 WebFrameClient& GetWebFrameClient(LocalFrame& frame) { |
| 50 WebLocalFrameImpl* web_frame = WebLocalFrameImpl::FromFrame(frame); | 51 WebLocalFrameImpl* web_frame = WebLocalFrameImpl::FromFrame(frame); |
| 51 DCHECK(web_frame); | 52 DCHECK(web_frame); |
| 52 DCHECK(web_frame->Client()); | 53 DCHECK(web_frame->Client()); |
| 53 return *web_frame->Client(); | 54 return *web_frame->Client(); |
| 54 } | 55 } |
| 55 | 56 |
| 56 } // anonymous namespace | 57 } // anonymous namespace |
| 57 | 58 |
| 58 std::unique_ptr<FullscreenController> FullscreenController::Create( | 59 std::unique_ptr<FullscreenController> FullscreenController::Create( |
| 59 WebViewImpl* web_view_impl) { | 60 WebViewBase* web_view_base) { |
| 60 return WTF::WrapUnique(new FullscreenController(web_view_impl)); | 61 return WTF::WrapUnique(new FullscreenController(web_view_base)); |
| 61 } | 62 } |
| 62 | 63 |
| 63 FullscreenController::FullscreenController(WebViewImpl* web_view_impl) | 64 FullscreenController::FullscreenController(WebViewBase* web_view_base) |
| 64 : web_view_impl_(web_view_impl) {} | 65 : web_view_base_(web_view_base) {} |
| 65 | 66 |
| 66 void FullscreenController::DidEnterFullscreen() { | 67 void FullscreenController::DidEnterFullscreen() { |
| 67 // |Browser::EnterFullscreenModeForTab()| can enter fullscreen without going | 68 // |Browser::EnterFullscreenModeForTab()| can enter fullscreen without going |
| 68 // through |Fullscreen::requestFullscreen()|, in which case there will be no | 69 // through |Fullscreen::requestFullscreen()|, in which case there will be no |
| 69 // fullscreen element. Do nothing. | 70 // fullscreen element. Do nothing. |
| 70 if (state_ != State::kEnteringFullscreen) | 71 if (state_ != State::kEnteringFullscreen) |
| 71 return; | 72 return; |
| 72 | 73 |
| 73 UpdatePageScaleConstraints(false); | 74 UpdatePageScaleConstraints(false); |
| 74 web_view_impl_->SetPageScaleFactor(1.0f); | 75 web_view_base_->SetPageScaleFactor(1.0f); |
| 75 if (web_view_impl_->MainFrame()->IsWebLocalFrame()) | 76 if (web_view_base_->MainFrame()->IsWebLocalFrame()) |
| 76 web_view_impl_->MainFrame()->SetScrollOffset(WebSize()); | 77 web_view_base_->MainFrame()->SetScrollOffset(WebSize()); |
| 77 web_view_impl_->SetVisualViewportOffset(FloatPoint()); | 78 web_view_base_->SetVisualViewportOffset(FloatPoint()); |
| 78 | 79 |
| 79 state_ = State::kFullscreen; | 80 state_ = State::kFullscreen; |
| 80 | 81 |
| 81 // Notify all local frames that we have entered fullscreen. | 82 // Notify all local frames that we have entered fullscreen. |
| 82 for (Frame* frame = web_view_impl_->GetPage()->MainFrame(); frame; | 83 for (Frame* frame = web_view_base_->GetPage()->MainFrame(); frame; |
| 83 frame = frame->Tree().TraverseNext()) { | 84 frame = frame->Tree().TraverseNext()) { |
| 84 if (!frame->IsLocalFrame()) | 85 if (!frame->IsLocalFrame()) |
| 85 continue; | 86 continue; |
| 86 if (Document* document = ToLocalFrame(frame)->GetDocument()) { | 87 if (Document* document = ToLocalFrame(frame)->GetDocument()) { |
| 87 if (Fullscreen* fullscreen = Fullscreen::FromIfExists(*document)) | 88 if (Fullscreen* fullscreen = Fullscreen::FromIfExists(*document)) |
| 88 fullscreen->DidEnterFullscreen(); | 89 fullscreen->DidEnterFullscreen(); |
| 89 } | 90 } |
| 90 } | 91 } |
| 91 } | 92 } |
| 92 | 93 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 106 // TODO(foolip): Remove this when state changes and events are synchronized | 107 // TODO(foolip): Remove this when state changes and events are synchronized |
| 107 // with animation frames. https://crbug.com/402376 | 108 // with animation frames. https://crbug.com/402376 |
| 108 state_ = State::kExitingFullscreen; | 109 state_ = State::kExitingFullscreen; |
| 109 | 110 |
| 110 // Notify all local frames that we have exited fullscreen. | 111 // Notify all local frames that we have exited fullscreen. |
| 111 // TODO(foolip): This should only need to notify the topmost local roots. That | 112 // TODO(foolip): This should only need to notify the topmost local roots. That |
| 112 // doesn't currently work because |Fullscreen::m_currentFullScreenElement| | 113 // doesn't currently work because |Fullscreen::m_currentFullScreenElement| |
| 113 // isn't set for the topmost document when an iframe goes fullscreen, but can | 114 // 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 // be done once |m_currentFullScreenElement| is gone and all state is in the |
| 115 // fullscreen element stack. https://crbug.com/402421 | 116 // fullscreen element stack. https://crbug.com/402421 |
| 116 for (Frame* frame = web_view_impl_->GetPage()->MainFrame(); frame; | 117 for (Frame* frame = web_view_base_->GetPage()->MainFrame(); frame; |
| 117 frame = frame->Tree().TraverseNext()) { | 118 frame = frame->Tree().TraverseNext()) { |
| 118 if (!frame->IsLocalFrame()) | 119 if (!frame->IsLocalFrame()) |
| 119 continue; | 120 continue; |
| 120 if (Document* document = ToLocalFrame(frame)->GetDocument()) { | 121 if (Document* document = ToLocalFrame(frame)->GetDocument()) { |
| 121 if (Fullscreen* fullscreen = Fullscreen::FromIfExists(*document)) | 122 if (Fullscreen* fullscreen = Fullscreen::FromIfExists(*document)) |
| 122 fullscreen->DidExitFullscreen(); | 123 fullscreen->DidExitFullscreen(); |
| 123 } | 124 } |
| 124 } | 125 } |
| 125 | 126 |
| 126 // We need to wait until style and layout are updated in order to properly | 127 // We need to wait until style and layout are updated in order to properly |
| (...skipping 13 matching lines...) Expand all Loading... |
| 140 state_ = old_state; | 141 state_ = old_state; |
| 141 return; | 142 return; |
| 142 } | 143 } |
| 143 | 144 |
| 144 // We need to store these values here rather than in |didEnterFullscreen()| | 145 // 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, | 146 // 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 | 147 // 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 | 148 // restore a previous set. This can happen if we exit and quickly reenter |
| 148 // fullscreen without performing a layout. | 149 // fullscreen without performing a layout. |
| 149 if (state_ == State::kInitial) { | 150 if (state_ == State::kInitial) { |
| 150 initial_page_scale_factor_ = web_view_impl_->PageScaleFactor(); | 151 initial_page_scale_factor_ = web_view_base_->PageScaleFactor(); |
| 151 initial_scroll_offset_ = | 152 initial_scroll_offset_ = |
| 152 web_view_impl_->MainFrame()->IsWebLocalFrame() | 153 web_view_base_->MainFrame()->IsWebLocalFrame() |
| 153 ? web_view_impl_->MainFrame()->GetScrollOffset() | 154 ? web_view_base_->MainFrame()->GetScrollOffset() |
| 154 : WebSize(); | 155 : WebSize(); |
| 155 initial_visual_viewport_offset_ = web_view_impl_->VisualViewportOffset(); | 156 initial_visual_viewport_offset_ = web_view_base_->VisualViewportOffset(); |
| 156 initial_background_color_override_enabled_ = | 157 initial_background_color_override_enabled_ = |
| 157 web_view_impl_->BackgroundColorOverrideEnabled(); | 158 web_view_base_->BackgroundColorOverrideEnabled(); |
| 158 initial_background_color_override_ = | 159 initial_background_color_override_ = |
| 159 web_view_impl_->BackgroundColorOverride(); | 160 web_view_base_->BackgroundColorOverride(); |
| 160 } | 161 } |
| 161 | 162 |
| 162 // If already entering fullscreen, just wait. | 163 // If already entering fullscreen, just wait. |
| 163 if (state_ == State::kEnteringFullscreen) | 164 if (state_ == State::kEnteringFullscreen) |
| 164 return; | 165 return; |
| 165 | 166 |
| 166 DCHECK(state_ == State::kInitial || | 167 DCHECK(state_ == State::kInitial || |
| 167 state_ == State::kNeedsScrollAndScaleRestore); | 168 state_ == State::kNeedsScrollAndScaleRestore); |
| 168 GetWebFrameClient(frame).EnterFullscreen(); | 169 GetWebFrameClient(frame).EnterFullscreen(); |
| 169 | 170 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 194 if (to_element) { | 195 if (to_element) { |
| 195 DCHECK(Fullscreen::IsCurrentFullScreenElement(*to_element)); | 196 DCHECK(Fullscreen::IsCurrentFullScreenElement(*to_element)); |
| 196 | 197 |
| 197 if (isHTMLVideoElement(*to_element)) { | 198 if (isHTMLVideoElement(*to_element)) { |
| 198 HTMLVideoElement& video_element = toHTMLVideoElement(*to_element); | 199 HTMLVideoElement& video_element = toHTMLVideoElement(*to_element); |
| 199 video_element.DidEnterFullscreen(); | 200 video_element.DidEnterFullscreen(); |
| 200 | 201 |
| 201 // If the video uses overlay fullscreen mode, make the background | 202 // If the video uses overlay fullscreen mode, make the background |
| 202 // transparent. | 203 // transparent. |
| 203 if (video_element.UsesOverlayFullscreenVideo()) | 204 if (video_element.UsesOverlayFullscreenVideo()) |
| 204 web_view_impl_->SetBackgroundColorOverride(Color::kTransparent); | 205 web_view_base_->SetBackgroundColorOverride(Color::kTransparent); |
| 205 } | 206 } |
| 206 } | 207 } |
| 207 | 208 |
| 208 if (from_element) { | 209 if (from_element) { |
| 209 DCHECK(!Fullscreen::IsCurrentFullScreenElement(*from_element)); | 210 DCHECK(!Fullscreen::IsCurrentFullScreenElement(*from_element)); |
| 210 | 211 |
| 211 if (isHTMLVideoElement(*from_element)) { | 212 if (isHTMLVideoElement(*from_element)) { |
| 212 HTMLVideoElement& video_element = toHTMLVideoElement(*from_element); | 213 HTMLVideoElement& video_element = toHTMLVideoElement(*from_element); |
| 213 video_element.DidExitFullscreen(); | 214 video_element.DidExitFullscreen(); |
| 214 } | 215 } |
| 215 } | 216 } |
| 216 } | 217 } |
| 217 | 218 |
| 218 void FullscreenController::RestoreBackgroundColorOverride() { | 219 void FullscreenController::RestoreBackgroundColorOverride() { |
| 219 if (web_view_impl_->BackgroundColorOverrideEnabled() != | 220 if (web_view_base_->BackgroundColorOverrideEnabled() != |
| 220 initial_background_color_override_enabled_ || | 221 initial_background_color_override_enabled_ || |
| 221 web_view_impl_->BackgroundColorOverride() != | 222 web_view_base_->BackgroundColorOverride() != |
| 222 initial_background_color_override_) { | 223 initial_background_color_override_) { |
| 223 if (initial_background_color_override_enabled_) { | 224 if (initial_background_color_override_enabled_) { |
| 224 web_view_impl_->SetBackgroundColorOverride( | 225 web_view_base_->SetBackgroundColorOverride( |
| 225 initial_background_color_override_); | 226 initial_background_color_override_); |
| 226 } else { | 227 } else { |
| 227 web_view_impl_->ClearBackgroundColorOverride(); | 228 web_view_base_->ClearBackgroundColorOverride(); |
| 228 } | 229 } |
| 229 } | 230 } |
| 230 } | 231 } |
| 231 | 232 |
| 232 void FullscreenController::UpdateSize() { | 233 void FullscreenController::UpdateSize() { |
| 233 DCHECK(web_view_impl_->GetPage()); | 234 DCHECK(web_view_base_->GetPage()); |
| 234 | 235 |
| 235 if (state_ != State::kFullscreen && state_ != State::kExitingFullscreen) | 236 if (state_ != State::kFullscreen && state_ != State::kExitingFullscreen) |
| 236 return; | 237 return; |
| 237 | 238 |
| 238 UpdatePageScaleConstraints(false); | 239 UpdatePageScaleConstraints(false); |
| 239 | 240 |
| 240 // Traverse all local frames and notify the LayoutFullScreen object, if any. | 241 // Traverse all local frames and notify the LayoutFullScreen object, if any. |
| 241 for (Frame* frame = web_view_impl_->GetPage()->MainFrame(); frame; | 242 for (Frame* frame = web_view_base_->GetPage()->MainFrame(); frame; |
| 242 frame = frame->Tree().TraverseNext()) { | 243 frame = frame->Tree().TraverseNext()) { |
| 243 if (!frame->IsLocalFrame()) | 244 if (!frame->IsLocalFrame()) |
| 244 continue; | 245 continue; |
| 245 if (Document* document = ToLocalFrame(frame)->GetDocument()) { | 246 if (Document* document = ToLocalFrame(frame)->GetDocument()) { |
| 246 if (Fullscreen* fullscreen = Fullscreen::FromIfExists(*document)) { | 247 if (Fullscreen* fullscreen = Fullscreen::FromIfExists(*document)) { |
| 247 if (LayoutFullScreen* layout_object = | 248 if (LayoutFullScreen* layout_object = |
| 248 fullscreen->FullScreenLayoutObject()) | 249 fullscreen->FullScreenLayoutObject()) |
| 249 layout_object->UpdateStyle(); | 250 layout_object->UpdateStyle(); |
| 250 } | 251 } |
| 251 } | 252 } |
| 252 } | 253 } |
| 253 } | 254 } |
| 254 | 255 |
| 255 void FullscreenController::DidUpdateLayout() { | 256 void FullscreenController::DidUpdateLayout() { |
| 256 if (state_ != State::kNeedsScrollAndScaleRestore) | 257 if (state_ != State::kNeedsScrollAndScaleRestore) |
| 257 return; | 258 return; |
| 258 | 259 |
| 259 web_view_impl_->SetPageScaleFactor(initial_page_scale_factor_); | 260 web_view_base_->SetPageScaleFactor(initial_page_scale_factor_); |
| 260 if (web_view_impl_->MainFrame()->IsWebLocalFrame()) | 261 if (web_view_base_->MainFrame()->IsWebLocalFrame()) |
| 261 web_view_impl_->MainFrame()->SetScrollOffset( | 262 web_view_base_->MainFrame()->SetScrollOffset( |
| 262 WebSize(initial_scroll_offset_)); | 263 WebSize(initial_scroll_offset_)); |
| 263 web_view_impl_->SetVisualViewportOffset(initial_visual_viewport_offset_); | 264 web_view_base_->SetVisualViewportOffset(initial_visual_viewport_offset_); |
| 264 // Background color override was already restored when | 265 // Background color override was already restored when |
| 265 // fullscreenElementChanged([..], nullptr) was called while exiting. | 266 // fullscreenElementChanged([..], nullptr) was called while exiting. |
| 266 | 267 |
| 267 state_ = State::kInitial; | 268 state_ = State::kInitial; |
| 268 } | 269 } |
| 269 | 270 |
| 270 void FullscreenController::UpdatePageScaleConstraints(bool remove_constraints) { | 271 void FullscreenController::UpdatePageScaleConstraints(bool remove_constraints) { |
| 271 PageScaleConstraints fullscreen_constraints; | 272 PageScaleConstraints fullscreen_constraints; |
| 272 if (!remove_constraints) { | 273 if (!remove_constraints) { |
| 273 fullscreen_constraints = PageScaleConstraints(1.0, 1.0, 1.0); | 274 fullscreen_constraints = PageScaleConstraints(1.0, 1.0, 1.0); |
| 274 fullscreen_constraints.layout_size = FloatSize(web_view_impl_->Size()); | 275 fullscreen_constraints.layout_size = FloatSize(web_view_base_->Size()); |
| 275 } | 276 } |
| 276 web_view_impl_->GetPageScaleConstraintsSet().SetFullscreenConstraints( | 277 web_view_base_->GetPageScaleConstraintsSet().SetFullscreenConstraints( |
| 277 fullscreen_constraints); | 278 fullscreen_constraints); |
| 278 web_view_impl_->GetPageScaleConstraintsSet().ComputeFinalConstraints(); | 279 web_view_base_->GetPageScaleConstraintsSet().ComputeFinalConstraints(); |
| 279 | 280 |
| 280 // Although we called |computedFinalConstraints()| above, the "final" | 281 // Although we called |computedFinalConstraints()| above, the "final" |
| 281 // constraints are not actually final. They are still subject to scale factor | 282 // constraints are not actually final. They are still subject to scale factor |
| 282 // clamping by contents size. Normally they should be dirtied due to contents | 283 // clamping by contents size. Normally they should be dirtied due to contents |
| 283 // size mutation after layout, however the contents size is not guaranteed to | 284 // size mutation after layout, however the contents size is not guaranteed to |
| 284 // mutate, and the scale factor may remain unclamped. Just fire the event | 285 // mutate, and the scale factor may remain unclamped. Just fire the event |
| 285 // again to ensure the final constraints pick up the latest contents size. | 286 // again to ensure the final constraints pick up the latest contents size. |
| 286 web_view_impl_->DidChangeContentsSize(); | 287 web_view_base_->DidChangeContentsSize(); |
| 287 if (web_view_impl_->MainFrameImpl() && | 288 if (web_view_base_->MainFrameImpl() && |
| 288 web_view_impl_->MainFrameImpl()->GetFrameView()) | 289 web_view_base_->MainFrameImpl()->GetFrameView()) |
| 289 web_view_impl_->MainFrameImpl()->GetFrameView()->SetNeedsLayout(); | 290 web_view_base_->MainFrameImpl()->GetFrameView()->SetNeedsLayout(); |
| 290 | 291 |
| 291 web_view_impl_->UpdateMainFrameLayoutSize(); | 292 web_view_base_->UpdateMainFrameLayoutSize(); |
| 292 } | 293 } |
| 293 | 294 |
| 294 } // namespace blink | 295 } // namespace blink |
| OLD | NEW |