| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2010 Apple Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | |
| 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | |
| 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 23 */ | |
| 24 | |
| 25 #include "config.h" | |
| 26 #include "core/layout/LayoutFullScreen.h" | |
| 27 | |
| 28 #include "core/dom/Fullscreen.h" | |
| 29 #include "core/frame/FrameHost.h" | |
| 30 #include "core/frame/Settings.h" | |
| 31 #include "core/layout/LayoutBlockFlow.h" | |
| 32 #include "core/page/Page.h" | |
| 33 | |
| 34 #include "public/platform/WebScreenInfo.h" | |
| 35 | |
| 36 using namespace blink; | |
| 37 | |
| 38 class LayoutFullScreenPlaceholder final : public LayoutBlockFlow { | |
| 39 public: | |
| 40 LayoutFullScreenPlaceholder(LayoutFullScreen* owner) | |
| 41 : LayoutBlockFlow(nullptr) | |
| 42 , m_owner(owner) | |
| 43 { | |
| 44 setDocumentForAnonymous(&owner->document()); | |
| 45 } | |
| 46 private: | |
| 47 bool isOfType(LayoutObjectType type) const override { return type == LayoutO
bjectLayoutFullScreenPlaceholder || LayoutBlockFlow::isOfType(type); } | |
| 48 void willBeDestroyed() override; | |
| 49 LayoutFullScreen* m_owner; | |
| 50 }; | |
| 51 | |
| 52 void LayoutFullScreenPlaceholder::willBeDestroyed() | |
| 53 { | |
| 54 m_owner->setPlaceholder(nullptr); | |
| 55 LayoutBlockFlow::willBeDestroyed(); | |
| 56 } | |
| 57 | |
| 58 LayoutFullScreen::LayoutFullScreen() | |
| 59 : LayoutFlexibleBox(nullptr) | |
| 60 , m_placeholder(nullptr) | |
| 61 { | |
| 62 setReplaced(false); | |
| 63 } | |
| 64 | |
| 65 LayoutFullScreen* LayoutFullScreen::createAnonymous(Document* document) | |
| 66 { | |
| 67 LayoutFullScreen* layoutObject = new LayoutFullScreen(); | |
| 68 layoutObject->setDocumentForAnonymous(document); | |
| 69 return layoutObject; | |
| 70 } | |
| 71 | |
| 72 void LayoutFullScreen::willBeDestroyed() | |
| 73 { | |
| 74 if (m_placeholder) { | |
| 75 remove(); | |
| 76 if (!m_placeholder->beingDestroyed()) | |
| 77 m_placeholder->destroy(); | |
| 78 ASSERT(!m_placeholder); | |
| 79 } | |
| 80 | |
| 81 // LayoutObjects are unretained, so notify the document (which holds a point
er to a LayoutFullScreen) | |
| 82 // if its LayoutFullScreen is destroyed. | |
| 83 Fullscreen& fullscreen = Fullscreen::from(document()); | |
| 84 if (fullscreen.fullScreenLayoutObject() == this) | |
| 85 fullscreen.fullScreenLayoutObjectDestroyed(); | |
| 86 | |
| 87 LayoutFlexibleBox::willBeDestroyed(); | |
| 88 } | |
| 89 | |
| 90 void LayoutFullScreen::updateStyle() | |
| 91 { | |
| 92 RefPtr<ComputedStyle> fullscreenStyle = ComputedStyle::create(); | |
| 93 | |
| 94 // Create a stacking context: | |
| 95 fullscreenStyle->setZIndex(INT_MAX); | |
| 96 | |
| 97 fullscreenStyle->setFontDescription(FontDescription()); | |
| 98 fullscreenStyle->font().update(nullptr); | |
| 99 | |
| 100 fullscreenStyle->setDisplay(FLEX); | |
| 101 fullscreenStyle->setJustifyContentPosition(ContentPositionCenter); | |
| 102 fullscreenStyle->setAlignItemsPosition(ItemPositionCenter); | |
| 103 fullscreenStyle->setFlexDirection(FlowColumn); | |
| 104 | |
| 105 fullscreenStyle->setPosition(FixedPosition); | |
| 106 fullscreenStyle->setLeft(Length(0, blink::Fixed)); | |
| 107 fullscreenStyle->setTop(Length(0, blink::Fixed)); | |
| 108 IntSize viewportSize = document().page()->frameHost().visualViewport().size(
); | |
| 109 fullscreenStyle->setWidth(Length(viewportSize.width(), blink::Fixed)); | |
| 110 fullscreenStyle->setHeight(Length(viewportSize.height(), blink::Fixed)); | |
| 111 | |
| 112 fullscreenStyle->setBackgroundColor(StyleColor(Color::black)); | |
| 113 | |
| 114 setStyle(fullscreenStyle); | |
| 115 } | |
| 116 | |
| 117 LayoutObject* LayoutFullScreen::wrapLayoutObject(LayoutObject* object, LayoutObj
ect* parent, Document* document) | |
| 118 { | |
| 119 // FIXME: We should not modify the structure of the layout tree during | |
| 120 // layout. crbug.com/370459 | |
| 121 DeprecatedDisableModifyLayoutTreeStructureAsserts disabler; | |
| 122 | |
| 123 LayoutFullScreen* fullscreenLayoutObject = LayoutFullScreen::createAnonymous
(document); | |
| 124 fullscreenLayoutObject->updateStyle(); | |
| 125 if (parent && !parent->isChildAllowed(fullscreenLayoutObject, fullscreenLayo
utObject->styleRef())) { | |
| 126 fullscreenLayoutObject->destroy(); | |
| 127 return nullptr; | |
| 128 } | |
| 129 if (object) { | |
| 130 // |object->parent()| can be null if the object is not yet attached | |
| 131 // to |parent|. | |
| 132 if (LayoutObject* parent = object->parent()) { | |
| 133 LayoutBlock* containingBlock = object->containingBlock(); | |
| 134 ASSERT(containingBlock); | |
| 135 // Since we are moving the |object| to a new parent |fullscreenLayou
tObject|, | |
| 136 // the line box tree underneath our |containingBlock| is not longer
valid. | |
| 137 containingBlock->deleteLineBoxTree(); | |
| 138 | |
| 139 parent->addChild(fullscreenLayoutObject, object); | |
| 140 object->remove(); | |
| 141 | |
| 142 // Always just do a full layout to ensure that line boxes get delete
d properly. | |
| 143 // Because objects moved from |parent| to |fullscreenLayoutObject|,
we want to | |
| 144 // make new line boxes instead of leaving the old ones around. | |
| 145 parent->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(La
youtInvalidationReason::Fullscreen); | |
| 146 containingBlock->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvali
dation(LayoutInvalidationReason::Fullscreen); | |
| 147 } | |
| 148 fullscreenLayoutObject->addChild(object); | |
| 149 fullscreenLayoutObject->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInv
alidation(LayoutInvalidationReason::Fullscreen); | |
| 150 } | |
| 151 | |
| 152 ASSERT(document); | |
| 153 Fullscreen::from(*document).setFullScreenLayoutObject(fullscreenLayoutObject
); | |
| 154 return fullscreenLayoutObject; | |
| 155 } | |
| 156 | |
| 157 void LayoutFullScreen::unwrapLayoutObject() | |
| 158 { | |
| 159 // FIXME: We should not modify the structure of the layout tree during | |
| 160 // layout. crbug.com/370459 | |
| 161 DeprecatedDisableModifyLayoutTreeStructureAsserts disabler; | |
| 162 | |
| 163 if (parent()) { | |
| 164 for (LayoutObject* child = firstChild(); child; child = firstChild()) { | |
| 165 // We have to clear the override size, because as a flexbox, we | |
| 166 // may have set one on the child, and we don't want to leave that | |
| 167 // lying around on the child. | |
| 168 if (child->isBox()) | |
| 169 toLayoutBox(child)->clearOverrideSize(); | |
| 170 child->remove(); | |
| 171 parent()->addChild(child, this); | |
| 172 parent()->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
LayoutInvalidationReason::Fullscreen); | |
| 173 } | |
| 174 } | |
| 175 if (placeholder()) | |
| 176 placeholder()->remove(); | |
| 177 remove(); | |
| 178 destroy(); | |
| 179 } | |
| 180 | |
| 181 void LayoutFullScreen::setPlaceholder(LayoutBlock* placeholder) | |
| 182 { | |
| 183 m_placeholder = placeholder; | |
| 184 } | |
| 185 | |
| 186 void LayoutFullScreen::createPlaceholder(PassRefPtr<ComputedStyle> style, const
LayoutRect& frameRect) | |
| 187 { | |
| 188 if (style->width().isAuto()) | |
| 189 style->setWidth(Length(frameRect.width(), Fixed)); | |
| 190 if (style->height().isAuto()) | |
| 191 style->setHeight(Length(frameRect.height(), Fixed)); | |
| 192 | |
| 193 if (!m_placeholder) { | |
| 194 m_placeholder = new LayoutFullScreenPlaceholder(this); | |
| 195 m_placeholder->setStyle(style); | |
| 196 if (parent()) { | |
| 197 parent()->addChild(m_placeholder, this); | |
| 198 parent()->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
LayoutInvalidationReason::Fullscreen); | |
| 199 } | |
| 200 } else { | |
| 201 m_placeholder->setStyle(style); | |
| 202 } | |
| 203 } | |
| OLD | NEW |