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

Side by Side Diff: third_party/WebKit/Source/core/dom/Fullscreen.cpp

Issue 2107233002: Reland "Implement FullScreen using top layer." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: new untested DCHECK 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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 8 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
9 * Copyright (C) 2013 Google Inc. All rights reserved. 9 * Copyright (C) 2013 Google Inc. All rights reserved.
10 * 10 *
11 * This library is free software; you can redistribute it and/or 11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public 12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either 13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version. 14 * version 2 of the License, or (at your option) any later version.
15 * 15 *
16 * This library is distributed in the hope that it will be useful, 16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details. 19 * Library General Public License for more details.
20 * 20 *
21 * You should have received a copy of the GNU Library General Public License 21 * You should have received a copy of the GNU Library General Public License
22 * along with this library; see the file COPYING.LIB. If not, write to 22 * along with this library; see the file COPYING.LIB. If not, write to
23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA. 24 * Boston, MA 02110-1301, USA.
25 * 25 *
26 */ 26 */
27 27
28 #include "core/dom/Fullscreen.h" 28 #include "core/dom/Fullscreen.h"
29 29
30 #include "bindings/core/v8/ExceptionMessages.h"
30 #include "core/HTMLNames.h" 31 #include "core/HTMLNames.h"
31 #include "core/dom/Document.h" 32 #include "core/dom/Document.h"
32 #include "core/dom/ElementTraversal.h" 33 #include "core/dom/ElementTraversal.h"
33 #include "core/dom/StyleChangeReason.h" 34 #include "core/dom/StyleChangeReason.h"
34 #include "core/dom/StyleEngine.h" 35 #include "core/dom/StyleEngine.h"
35 #include "core/events/Event.h" 36 #include "core/events/Event.h"
36 #include "core/frame/FrameHost.h" 37 #include "core/frame/FrameHost.h"
37 #include "core/frame/HostsUsingFeatures.h" 38 #include "core/frame/HostsUsingFeatures.h"
38 #include "core/frame/LocalFrame.h" 39 #include "core/frame/LocalFrame.h"
39 #include "core/frame/Settings.h" 40 #include "core/frame/Settings.h"
40 #include "core/frame/UseCounter.h" 41 #include "core/frame/UseCounter.h"
41 #include "core/html/HTMLIFrameElement.h" 42 #include "core/html/HTMLIFrameElement.h"
42 #include "core/html/HTMLMediaElement.h" 43 #include "core/html/HTMLMediaElement.h"
43 #include "core/input/EventHandler.h" 44 #include "core/input/EventHandler.h"
44 #include "core/inspector/ConsoleMessage.h" 45 #include "core/inspector/ConsoleMessage.h"
45 #include "core/layout/LayoutBlockFlow.h"
46 #include "core/layout/LayoutFullScreen.h"
47 #include "core/layout/api/LayoutFullScreenItem.h"
48 #include "core/page/ChromeClient.h" 46 #include "core/page/ChromeClient.h"
47 #include "core/page/Page.h"
48 #include "core/style/ComputedStyle.h"
49 #include "platform/UserGestureIndicator.h" 49 #include "platform/UserGestureIndicator.h"
50 50
51 namespace blink { 51 namespace blink {
52 52
53 using namespace HTMLNames; 53 using namespace HTMLNames;
54 54
55 namespace { 55 namespace {
56 56
57 bool fullscreenIsAllowedForAllOwners(const Document& document) 57 bool fullscreenIsAllowedForAllOwners(const Document& document)
58 { 58 {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 return 0; 189 return 0;
190 } 190 }
191 191
192 bool Fullscreen::isFullScreen(Document& document) 192 bool Fullscreen::isFullScreen(Document& document)
193 { 193 {
194 return currentFullScreenElementFrom(document); 194 return currentFullScreenElementFrom(document);
195 } 195 }
196 196
197 Fullscreen::Fullscreen(Document& document) 197 Fullscreen::Fullscreen(Document& document)
198 : ContextLifecycleObserver(&document) 198 : ContextLifecycleObserver(&document)
199 , m_fullScreenLayoutObject(nullptr)
200 , m_eventQueueTimer(this, &Fullscreen::eventQueueTimerFired) 199 , m_eventQueueTimer(this, &Fullscreen::eventQueueTimerFired)
201 , m_forCrossProcessDescendant(false) 200 , m_forCrossProcessDescendant(false)
202 { 201 {
203 document.setHasFullscreenSupplement(); 202 document.setHasFullscreenSupplement();
204 } 203 }
205 204
206 Fullscreen::~Fullscreen() 205 Fullscreen::~Fullscreen()
207 { 206 {
208 } 207 }
209 208
210 inline Document* Fullscreen::document() 209 inline Document* Fullscreen::document()
211 { 210 {
212 return toDocument(lifecycleContext()); 211 return toDocument(lifecycleContext());
213 } 212 }
214 213
215 void Fullscreen::contextDestroyed() 214 void Fullscreen::contextDestroyed()
216 { 215 {
217 m_eventQueue.clear(); 216 m_eventQueue.clear();
218 217
219 if (m_fullScreenLayoutObject)
220 m_fullScreenLayoutObject->destroy();
221
222 m_fullScreenElement = nullptr; 218 m_fullScreenElement = nullptr;
223 m_fullScreenElementStack.clear(); 219 m_fullScreenElementStack.clear();
224 220
225 } 221 }
226 222
227 void Fullscreen::requestFullscreen(Element& element, RequestType requestType, bo ol forCrossProcessDescendant) 223 void Fullscreen::requestFullscreen(Element& element, RequestType requestType, bo ol forCrossProcessDescendant)
228 { 224 {
229 // Use counters only need to be incremented in the process of the actual 225 // Use counters only need to be incremented in the process of the actual
230 // fullscreen element. 226 // fullscreen element.
231 if (!forCrossProcessDescendant) { 227 if (!forCrossProcessDescendant) {
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 // 4. The fullscreenEnabled attribute must return true if the context object has its 475 // 4. The fullscreenEnabled attribute must return true if the context object has its
480 // fullscreen enabled flag set and fullscreen is supported, and false oth erwise. 476 // fullscreen enabled flag set and fullscreen is supported, and false oth erwise.
481 477
482 // Top-level browsing contexts are implied to have their allowFullScreen att ribute set. 478 // Top-level browsing contexts are implied to have their allowFullScreen att ribute set.
483 return fullscreenIsAllowedForAllOwners(document) && fullscreenIsSupported(do cument); 479 return fullscreenIsAllowedForAllOwners(document) && fullscreenIsSupported(do cument);
484 } 480 }
485 481
486 void Fullscreen::didEnterFullscreenForElement(Element* element) 482 void Fullscreen::didEnterFullscreenForElement(Element* element)
487 { 483 {
488 DCHECK(element); 484 DCHECK(element);
485 DCHECK(element->isInTopLayer());
486
489 if (!document()->isActive()) 487 if (!document()->isActive())
490 return; 488 return;
491 489
492 if (m_fullScreenLayoutObject)
493 m_fullScreenLayoutObject->unwrapLayoutObject();
494
495 m_fullScreenElement = element; 490 m_fullScreenElement = element;
496 491
497 // Create a placeholder block for a the full-screen element, to keep the pag e from reflowing
498 // when the element is removed from the normal flow. Only do this for a Layo utBox, as only
499 // a box will have a frameRect. The placeholder will be created in setFullSc reenLayoutObject()
500 // during layout.
501 LayoutObject* layoutObject = m_fullScreenElement->layoutObject();
502 bool shouldCreatePlaceholder = layoutObject && layoutObject->isBox();
503 if (shouldCreatePlaceholder) {
504 m_savedPlaceholderFrameRect = toLayoutBox(layoutObject)->frameRect();
505 m_savedPlaceholderComputedStyle = ComputedStyle::clone(layoutObject->sty leRef());
506 }
507
508 // TODO(alexmos): When |m_forCrossProcessDescendant| is true, some of
509 // this layout work has already been done in another process, so it should
510 // not be necessary to repeat it here.
511 if (m_fullScreenElement != document()->documentElement())
512 LayoutFullScreen::wrapLayoutObject(layoutObject, layoutObject ? layoutOb ject->parent() : 0, document());
513
514 // When |m_forCrossProcessDescendant| is true, m_fullScreenElement 492 // When |m_forCrossProcessDescendant| is true, m_fullScreenElement
515 // corresponds to the HTMLFrameOwnerElement for the out-of-process iframe 493 // corresponds to the HTMLFrameOwnerElement for the out-of-process iframe
516 // that contains the actual fullscreen element. Hence, it must also set 494 // that contains the actual fullscreen element. Hence, it must also set
517 // the ContainsFullScreenElement flag (so that it gains the 495 // the ContainsFullScreenElement flag (so that it gains the
518 // -webkit-full-screen-ancestor style). 496 // -webkit-full-screen-ancestor style).
519 if (m_forCrossProcessDescendant) { 497 if (m_forCrossProcessDescendant) {
520 DCHECK(m_fullScreenElement->isFrameOwnerElement()); 498 DCHECK(m_fullScreenElement->isFrameOwnerElement());
521 DCHECK(toHTMLFrameOwnerElement(m_fullScreenElement)->contentFrame()->isR emoteFrame()); 499 DCHECK(toHTMLFrameOwnerElement(m_fullScreenElement)->contentFrame()->isR emoteFrame());
522 m_fullScreenElement->setContainsFullScreenElement(true); 500 m_fullScreenElement->setContainsFullScreenElement(true);
523 } 501 }
(...skipping 15 matching lines...) Expand all
539 } 517 }
540 518
541 void Fullscreen::didExitFullscreen() 519 void Fullscreen::didExitFullscreen()
542 { 520 {
543 if (!m_fullScreenElement) 521 if (!m_fullScreenElement)
544 return; 522 return;
545 523
546 if (!document()->isActive()) 524 if (!document()->isActive())
547 return; 525 return;
548 526
527 document()->removeFromTopLayer(m_fullScreenElement.get());
549 m_fullScreenElement->willStopBeingFullscreenElement(); 528 m_fullScreenElement->willStopBeingFullscreenElement();
550 529
551 if (m_forCrossProcessDescendant) 530 if (m_forCrossProcessDescendant)
552 m_fullScreenElement->setContainsFullScreenElement(false); 531 m_fullScreenElement->setContainsFullScreenElement(false);
553 532
554 m_fullScreenElement->setContainsFullScreenElementOnAncestorsCrossingFrameBou ndaries(false); 533 m_fullScreenElement->setContainsFullScreenElementOnAncestorsCrossingFrameBou ndaries(false);
555 534
556 if (m_fullScreenLayoutObject)
557 LayoutFullScreenItem(m_fullScreenLayoutObject).unwrapLayoutObject();
558
559 document()->styleEngine().ensureFullscreenUAStyle(); 535 document()->styleEngine().ensureFullscreenUAStyle();
560 m_fullScreenElement->pseudoStateChanged(CSSSelector::PseudoFullScreen); 536 m_fullScreenElement->pseudoStateChanged(CSSSelector::PseudoFullScreen);
561 m_fullScreenElement = nullptr; 537 m_fullScreenElement = nullptr;
562 538
563 if (document()->frame()) 539 if (document()->frame())
564 document()->frame()->eventHandler().scheduleHoverStateUpdate(); 540 document()->frame()->eventHandler().scheduleHoverStateUpdate();
565 541
566 // When fullyExitFullscreen is called, we call exitFullscreen on the topDocu ment(). That means 542 // When fullyExitFullscreen is called, we call exitFullscreen on the topDocu ment(). That means
567 // that the events will be queued there. So if we have no events here, start the timer on the 543 // that the events will be queued there. So if we have no events here, start the timer on the
568 // exiting document. 544 // exiting document.
569 Document* exitingDocument = document(); 545 Document* exitingDocument = document();
570 if (m_eventQueue.isEmpty()) 546 if (m_eventQueue.isEmpty())
571 exitingDocument = &topmostLocalAncestor(*document()); 547 exitingDocument = &topmostLocalAncestor(*document());
572 DCHECK(exitingDocument); 548 DCHECK(exitingDocument);
573 from(*exitingDocument).m_eventQueueTimer.startOneShot(0, BLINK_FROM_HERE); 549 from(*exitingDocument).m_eventQueueTimer.startOneShot(0, BLINK_FROM_HERE);
574 550
575 m_forCrossProcessDescendant = false; 551 m_forCrossProcessDescendant = false;
576 } 552 }
577 553
578 void Fullscreen::setFullScreenLayoutObject(LayoutFullScreen* layoutObject) 554 void Fullscreen::didUpdateSize(Element& element)
579 { 555 {
580 if (layoutObject == m_fullScreenLayoutObject) 556 // StyleAdjuster will set the size so we need to do a style recalc.
581 return; 557 // Normally changing size means layout so just doing a style recalc is a
582 558 // bit surprising.
583 if (layoutObject && m_savedPlaceholderComputedStyle) { 559 element.setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::c reate(StyleChangeReason::FullScreen));
584 layoutObject->createPlaceholder(m_savedPlaceholderComputedStyle.release( ), m_savedPlaceholderFrameRect);
585 } else if (layoutObject && m_fullScreenLayoutObject && m_fullScreenLayoutObj ect->placeholder()) {
586 LayoutBlockFlow* placeholder = m_fullScreenLayoutObject->placeholder();
587 layoutObject->createPlaceholder(ComputedStyle::clone(placeholder->styleR ef()), placeholder->frameRect());
588 }
589
590 if (m_fullScreenLayoutObject)
591 m_fullScreenLayoutObject->unwrapLayoutObject();
592 DCHECK(!m_fullScreenLayoutObject);
593
594 m_fullScreenLayoutObject = layoutObject;
595 }
596
597 void Fullscreen::fullScreenLayoutObjectDestroyed()
598 {
599 m_fullScreenLayoutObject = nullptr;
600 } 560 }
601 561
602 void Fullscreen::enqueueChangeEvent(Document& document, RequestType requestType) 562 void Fullscreen::enqueueChangeEvent(Document& document, RequestType requestType)
603 { 563 {
604 Event* event; 564 Event* event;
605 if (requestType == UnprefixedRequest) { 565 if (requestType == UnprefixedRequest) {
606 event = createEvent(EventTypeNames::fullscreenchange, document); 566 event = createEvent(EventTypeNames::fullscreenchange, document);
607 } else { 567 } else {
608 DCHECK(document.hasFullscreenSupplement()); 568 DCHECK(document.hasFullscreenSupplement());
609 Fullscreen& fullscreen = from(document); 569 Fullscreen& fullscreen = from(document);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 void Fullscreen::clearFullscreenElementStack() 634 void Fullscreen::clearFullscreenElementStack()
675 { 635 {
676 m_fullScreenElementStack.clear(); 636 m_fullScreenElementStack.clear();
677 } 637 }
678 638
679 void Fullscreen::popFullscreenElementStack() 639 void Fullscreen::popFullscreenElementStack()
680 { 640 {
681 if (m_fullScreenElementStack.isEmpty()) 641 if (m_fullScreenElementStack.isEmpty())
682 return; 642 return;
683 643
644 document()->removeFromTopLayer(m_fullScreenElementStack.last().first.get());
684 m_fullScreenElementStack.removeLast(); 645 m_fullScreenElementStack.removeLast();
685 } 646 }
686 647
687 void Fullscreen::pushFullscreenElementStack(Element& element, RequestType reques tType) 648 void Fullscreen::pushFullscreenElementStack(Element& element, RequestType reques tType)
688 { 649 {
689 m_fullScreenElementStack.append(std::make_pair(&element, requestType)); 650 m_fullScreenElementStack.append(std::make_pair(&element, requestType));
651 document()->addToTopLayer(&element);
690 } 652 }
691 653
692 DEFINE_TRACE(Fullscreen) 654 DEFINE_TRACE(Fullscreen)
693 { 655 {
694 visitor->trace(m_fullScreenElement); 656 visitor->trace(m_fullScreenElement);
695 visitor->trace(m_fullScreenElementStack); 657 visitor->trace(m_fullScreenElementStack);
696 visitor->trace(m_eventQueue); 658 visitor->trace(m_eventQueue);
697 Supplement<Document>::trace(visitor); 659 Supplement<Document>::trace(visitor);
698 ContextLifecycleObserver::trace(visitor); 660 ContextLifecycleObserver::trace(visitor);
699 } 661 }
700 662
701 } // namespace blink 663 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/Fullscreen.h ('k') | third_party/WebKit/Source/core/dom/LayoutTreeBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698