| OLD | NEW |
| 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 Loading... |
| 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_forCrossProcessAncestor(false) | 200 , m_forCrossProcessAncestor(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 forCrossProcessAncestor) | 223 void Fullscreen::requestFullscreen(Element& element, RequestType requestType, bo
ol forCrossProcessAncestor) |
| 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 (!forCrossProcessAncestor) { | 227 if (!forCrossProcessAncestor) { |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_forCrossProcessAncestor| 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 if (m_forCrossProcessAncestor) { | 492 if (m_forCrossProcessAncestor) { |
| 515 DCHECK(m_fullScreenElement->isFrameOwnerElement()); | 493 DCHECK(m_fullScreenElement->isFrameOwnerElement()); |
| 516 DCHECK(toHTMLFrameOwnerElement(m_fullScreenElement)->contentFrame()->isR
emoteFrame()); | 494 DCHECK(toHTMLFrameOwnerElement(m_fullScreenElement)->contentFrame()->isR
emoteFrame()); |
| 517 m_fullScreenElement->setContainsFullScreenElement(true); | 495 m_fullScreenElement->setContainsFullScreenElement(true); |
| 518 } | 496 } |
| 519 | 497 |
| 520 m_fullScreenElement->setContainsFullScreenElementOnAncestorsCrossingFrameBou
ndaries(true); | 498 m_fullScreenElement->setContainsFullScreenElementOnAncestorsCrossingFrameBou
ndaries(true); |
| 521 | 499 |
| 522 document()->styleEngine().ensureFullscreenUAStyle(); | 500 document()->styleEngine().ensureFullscreenUAStyle(); |
| 523 m_fullScreenElement->pseudoStateChanged(CSSSelector::PseudoFullScreen); | 501 m_fullScreenElement->pseudoStateChanged(CSSSelector::PseudoFullScreen); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 534 } | 512 } |
| 535 | 513 |
| 536 void Fullscreen::didExitFullScreenForElement() | 514 void Fullscreen::didExitFullScreenForElement() |
| 537 { | 515 { |
| 538 if (!m_fullScreenElement) | 516 if (!m_fullScreenElement) |
| 539 return; | 517 return; |
| 540 | 518 |
| 541 if (!document()->isActive()) | 519 if (!document()->isActive()) |
| 542 return; | 520 return; |
| 543 | 521 |
| 522 document()->removeFromTopLayer(m_fullScreenElement.get()); |
| 544 m_fullScreenElement->willStopBeingFullscreenElement(); | 523 m_fullScreenElement->willStopBeingFullscreenElement(); |
| 545 | 524 |
| 546 if (m_forCrossProcessAncestor) | 525 if (m_forCrossProcessAncestor) |
| 547 m_fullScreenElement->setContainsFullScreenElement(false); | 526 m_fullScreenElement->setContainsFullScreenElement(false); |
| 548 | 527 |
| 549 m_fullScreenElement->setContainsFullScreenElementOnAncestorsCrossingFrameBou
ndaries(false); | 528 m_fullScreenElement->setContainsFullScreenElementOnAncestorsCrossingFrameBou
ndaries(false); |
| 550 | 529 |
| 551 if (m_fullScreenLayoutObject) | 530 // TODO(foolip): redundant with something the top layer machinery does? |
| 552 LayoutFullScreenItem(m_fullScreenLayoutObject).unwrapLayoutObject(); | |
| 553 | |
| 554 document()->styleEngine().ensureFullscreenUAStyle(); | 531 document()->styleEngine().ensureFullscreenUAStyle(); |
| 555 m_fullScreenElement->pseudoStateChanged(CSSSelector::PseudoFullScreen); | 532 m_fullScreenElement->pseudoStateChanged(CSSSelector::PseudoFullScreen); |
| 556 m_fullScreenElement = nullptr; | 533 m_fullScreenElement = nullptr; |
| 557 | 534 |
| 558 if (document()->frame()) | 535 if (document()->frame()) |
| 559 document()->frame()->eventHandler().scheduleHoverStateUpdate(); | 536 document()->frame()->eventHandler().scheduleHoverStateUpdate(); |
| 560 | 537 |
| 561 // When fullyExitFullscreen is called, we call exitFullscreen on the topDocu
ment(). That means | 538 // When fullyExitFullscreen is called, we call exitFullscreen on the topDocu
ment(). That means |
| 562 // that the events will be queued there. So if we have no events here, start
the timer on the | 539 // that the events will be queued there. So if we have no events here, start
the timer on the |
| 563 // exiting document. | 540 // exiting document. |
| 564 Document* exitingDocument = document(); | 541 Document* exitingDocument = document(); |
| 565 if (m_eventQueue.isEmpty()) | 542 if (m_eventQueue.isEmpty()) |
| 566 exitingDocument = &topmostLocalAncestor(*document()); | 543 exitingDocument = &topmostLocalAncestor(*document()); |
| 567 DCHECK(exitingDocument); | 544 DCHECK(exitingDocument); |
| 568 from(*exitingDocument).m_eventQueueTimer.startOneShot(0, BLINK_FROM_HERE); | 545 from(*exitingDocument).m_eventQueueTimer.startOneShot(0, BLINK_FROM_HERE); |
| 569 | 546 |
| 570 m_forCrossProcessAncestor = false; | 547 m_forCrossProcessAncestor = false; |
| 571 } | 548 } |
| 572 | 549 |
| 573 void Fullscreen::setFullScreenLayoutObject(LayoutFullScreen* layoutObject) | 550 void Fullscreen::didUpdateSize(Element& element) |
| 574 { | 551 { |
| 575 if (layoutObject == m_fullScreenLayoutObject) | 552 // StyleAdjuster will set the size so we need to do a style recalc. |
| 576 return; | 553 // Normally changing size means layout so just doing a style recalc is a |
| 577 | 554 // bit surprising. |
| 578 if (layoutObject && m_savedPlaceholderComputedStyle) { | 555 element.setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::c
reate(StyleChangeReason::FullScreen)); |
| 579 layoutObject->createPlaceholder(m_savedPlaceholderComputedStyle.release(
), m_savedPlaceholderFrameRect); | |
| 580 } else if (layoutObject && m_fullScreenLayoutObject && m_fullScreenLayoutObj
ect->placeholder()) { | |
| 581 LayoutBlockFlow* placeholder = m_fullScreenLayoutObject->placeholder(); | |
| 582 layoutObject->createPlaceholder(ComputedStyle::clone(placeholder->styleR
ef()), placeholder->frameRect()); | |
| 583 } | |
| 584 | |
| 585 if (m_fullScreenLayoutObject) | |
| 586 m_fullScreenLayoutObject->unwrapLayoutObject(); | |
| 587 DCHECK(!m_fullScreenLayoutObject); | |
| 588 | |
| 589 m_fullScreenLayoutObject = layoutObject; | |
| 590 } | |
| 591 | |
| 592 void Fullscreen::fullScreenLayoutObjectDestroyed() | |
| 593 { | |
| 594 m_fullScreenLayoutObject = nullptr; | |
| 595 } | 556 } |
| 596 | 557 |
| 597 void Fullscreen::enqueueChangeEvent(Document& document, RequestType requestType) | 558 void Fullscreen::enqueueChangeEvent(Document& document, RequestType requestType) |
| 598 { | 559 { |
| 599 Event* event; | 560 Event* event; |
| 600 if (requestType == UnprefixedRequest) { | 561 if (requestType == UnprefixedRequest) { |
| 601 event = createEvent(EventTypeNames::fullscreenchange, document); | 562 event = createEvent(EventTypeNames::fullscreenchange, document); |
| 602 } else { | 563 } else { |
| 603 DCHECK(document.hasFullscreenSupplement()); | 564 DCHECK(document.hasFullscreenSupplement()); |
| 604 Fullscreen& fullscreen = from(document); | 565 Fullscreen& fullscreen = from(document); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 void Fullscreen::clearFullscreenElementStack() | 630 void Fullscreen::clearFullscreenElementStack() |
| 670 { | 631 { |
| 671 m_fullScreenElementStack.clear(); | 632 m_fullScreenElementStack.clear(); |
| 672 } | 633 } |
| 673 | 634 |
| 674 void Fullscreen::popFullscreenElementStack() | 635 void Fullscreen::popFullscreenElementStack() |
| 675 { | 636 { |
| 676 if (m_fullScreenElementStack.isEmpty()) | 637 if (m_fullScreenElementStack.isEmpty()) |
| 677 return; | 638 return; |
| 678 | 639 |
| 640 document()->removeFromTopLayer(m_fullScreenElementStack.last().first.get()); |
| 679 m_fullScreenElementStack.removeLast(); | 641 m_fullScreenElementStack.removeLast(); |
| 680 } | 642 } |
| 681 | 643 |
| 682 void Fullscreen::pushFullscreenElementStack(Element& element, RequestType reques
tType) | 644 void Fullscreen::pushFullscreenElementStack(Element& element, RequestType reques
tType) |
| 683 { | 645 { |
| 684 m_fullScreenElementStack.append(std::make_pair(&element, requestType)); | 646 m_fullScreenElementStack.append(std::make_pair(&element, requestType)); |
| 647 document()->addToTopLayer(&element); |
| 685 } | 648 } |
| 686 | 649 |
| 687 DEFINE_TRACE(Fullscreen) | 650 DEFINE_TRACE(Fullscreen) |
| 688 { | 651 { |
| 689 visitor->trace(m_fullScreenElement); | 652 visitor->trace(m_fullScreenElement); |
| 690 visitor->trace(m_fullScreenElementStack); | 653 visitor->trace(m_fullScreenElementStack); |
| 691 visitor->trace(m_eventQueue); | 654 visitor->trace(m_eventQueue); |
| 692 Supplement<Document>::trace(visitor); | 655 Supplement<Document>::trace(visitor); |
| 693 ContextLifecycleObserver::trace(visitor); | 656 ContextLifecycleObserver::trace(visitor); |
| 694 } | 657 } |
| 695 | 658 |
| 696 } // namespace blink | 659 } // namespace blink |
| OLD | NEW |