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 "core/layout/LayoutFullScreen.h" |
| 26 |
| 27 #include "core/dom/Fullscreen.h" |
| 28 #include "core/frame/FrameHost.h" |
| 29 #include "core/frame/VisualViewport.h" |
| 30 #include "core/layout/LayoutBlockFlow.h" |
| 31 #include "core/page/Page.h" |
| 32 |
| 33 #include "public/platform/WebScreenInfo.h" |
| 34 |
| 35 using namespace blink; |
| 36 |
| 37 class LayoutFullScreenPlaceholder final : public LayoutBlockFlow { |
| 38 public: |
| 39 LayoutFullScreenPlaceholder(LayoutFullScreen* owner) |
| 40 : LayoutBlockFlow(nullptr) |
| 41 , m_owner(owner) |
| 42 { |
| 43 setDocumentForAnonymous(&owner->document()); |
| 44 } |
| 45 |
| 46 // Must call setStyleWithWritingModeOfParent() instead. |
| 47 void setStyle(PassRefPtr<ComputedStyle>) = delete; |
| 48 |
| 49 private: |
| 50 bool isOfType(LayoutObjectType type) const override { return type == LayoutO
bjectLayoutFullScreenPlaceholder || LayoutBlockFlow::isOfType(type); } |
| 51 bool anonymousHasStylePropagationOverride() override { return true; } |
| 52 |
| 53 void willBeDestroyed() override; |
| 54 LayoutFullScreen* m_owner; |
| 55 }; |
| 56 |
| 57 void LayoutFullScreenPlaceholder::willBeDestroyed() |
| 58 { |
| 59 m_owner->resetPlaceholder(); |
| 60 LayoutBlockFlow::willBeDestroyed(); |
| 61 } |
| 62 |
| 63 LayoutFullScreen::LayoutFullScreen() |
| 64 : LayoutFlexibleBox(nullptr) |
| 65 , m_placeholder(nullptr) |
| 66 { |
| 67 setIsAtomicInlineLevel(false); |
| 68 } |
| 69 |
| 70 LayoutFullScreen* LayoutFullScreen::createAnonymous(Document* document) |
| 71 { |
| 72 LayoutFullScreen* layoutObject = new LayoutFullScreen(); |
| 73 layoutObject->setDocumentForAnonymous(document); |
| 74 return layoutObject; |
| 75 } |
| 76 |
| 77 void LayoutFullScreen::willBeDestroyed() |
| 78 { |
| 79 if (m_placeholder) { |
| 80 remove(); |
| 81 if (!m_placeholder->beingDestroyed()) |
| 82 m_placeholder->destroy(); |
| 83 DCHECK(!m_placeholder); |
| 84 } |
| 85 |
| 86 // LayoutObjects are unretained, so notify the document (which holds a point
er to a LayoutFullScreen) |
| 87 // if its LayoutFullScreen is destroyed. |
| 88 Fullscreen& fullscreen = Fullscreen::from(document()); |
| 89 if (fullscreen.fullScreenLayoutObject() == this) |
| 90 fullscreen.fullScreenLayoutObjectDestroyed(); |
| 91 |
| 92 LayoutFlexibleBox::willBeDestroyed(); |
| 93 } |
| 94 |
| 95 void LayoutFullScreen::updateStyle() |
| 96 { |
| 97 RefPtr<ComputedStyle> fullscreenStyle = ComputedStyle::create(); |
| 98 |
| 99 // Create a stacking context: |
| 100 fullscreenStyle->setZIndex(INT_MAX); |
| 101 fullscreenStyle->setIsStackingContext(true); |
| 102 |
| 103 fullscreenStyle->setFontDescription(FontDescription()); |
| 104 fullscreenStyle->font().update(nullptr); |
| 105 |
| 106 fullscreenStyle->setDisplay(FLEX); |
| 107 fullscreenStyle->setJustifyContentPosition(ContentPositionCenter); |
| 108 fullscreenStyle->setAlignItemsPosition(ItemPositionCenter); |
| 109 fullscreenStyle->setFlexDirection(FlowColumn); |
| 110 |
| 111 fullscreenStyle->setPosition(FixedPosition); |
| 112 fullscreenStyle->setLeft(Length(0, blink::Fixed)); |
| 113 fullscreenStyle->setTop(Length(0, blink::Fixed)); |
| 114 IntSize viewportSize = document().page()->frameHost().visualViewport().size(
); |
| 115 fullscreenStyle->setWidth(Length(viewportSize.width(), blink::Fixed)); |
| 116 fullscreenStyle->setHeight(Length(viewportSize.height(), blink::Fixed)); |
| 117 |
| 118 fullscreenStyle->setBackgroundColor(StyleColor(Color::black)); |
| 119 |
| 120 setStyleWithWritingModeOfParent(fullscreenStyle); |
| 121 } |
| 122 |
| 123 LayoutObject* LayoutFullScreen::wrapLayoutObject(LayoutObject* object, LayoutObj
ect* parent, Document* document) |
| 124 { |
| 125 // FIXME: We should not modify the structure of the layout tree during |
| 126 // layout. crbug.com/370459 |
| 127 DeprecatedDisableModifyLayoutTreeStructureAsserts disabler; |
| 128 |
| 129 LayoutFullScreen* fullscreenLayoutObject = LayoutFullScreen::createAnonymous
(document); |
| 130 fullscreenLayoutObject->updateStyle(); |
| 131 if (parent && !parent->isChildAllowed(fullscreenLayoutObject, fullscreenLayo
utObject->styleRef())) { |
| 132 fullscreenLayoutObject->destroy(); |
| 133 return nullptr; |
| 134 } |
| 135 if (object) { |
| 136 // |object->parent()| can be null if the object is not yet attached |
| 137 // to |parent|. |
| 138 if (LayoutObject* parent = object->parent()) { |
| 139 LayoutBlock* containingBlock = object->containingBlock(); |
| 140 DCHECK(containingBlock); |
| 141 // Since we are moving the |object| to a new parent |fullscreenLayou
tObject|, |
| 142 // the line box tree underneath our |containingBlock| is not longer
valid. |
| 143 if (containingBlock->isLayoutBlockFlow()) |
| 144 toLayoutBlockFlow(containingBlock)->deleteLineBoxTree(); |
| 145 |
| 146 parent->addChildWithWritingModeOfParent(fullscreenLayoutObject, obje
ct); |
| 147 object->remove(); |
| 148 |
| 149 // Always just do a full layout to ensure that line boxes get delete
d properly. |
| 150 // Because objects moved from |parent| to |fullscreenLayoutObject|,
we want to |
| 151 // make new line boxes instead of leaving the old ones around. |
| 152 parent->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(La
youtInvalidationReason::Fullscreen); |
| 153 containingBlock->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvali
dation(LayoutInvalidationReason::Fullscreen); |
| 154 } |
| 155 fullscreenLayoutObject->addChild(object); |
| 156 fullscreenLayoutObject->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInv
alidation(LayoutInvalidationReason::Fullscreen); |
| 157 } |
| 158 |
| 159 DCHECK(document); |
| 160 Fullscreen::from(*document).setFullScreenLayoutObject(fullscreenLayoutObject
); |
| 161 return fullscreenLayoutObject; |
| 162 } |
| 163 |
| 164 void LayoutFullScreen::unwrapLayoutObject() |
| 165 { |
| 166 // FIXME: We should not modify the structure of the layout tree during |
| 167 // layout. crbug.com/370459 |
| 168 DeprecatedDisableModifyLayoutTreeStructureAsserts disabler; |
| 169 |
| 170 if (parent()) { |
| 171 for (LayoutObject* child = firstChild(); child; child = firstChild()) { |
| 172 // We have to clear the override size, because as a flexbox, we |
| 173 // may have set one on the child, and we don't want to leave that |
| 174 // lying around on the child. |
| 175 if (child->isBox()) |
| 176 toLayoutBox(child)->clearOverrideSize(); |
| 177 child->remove(); |
| 178 parent()->addChild(child, this); |
| 179 parent()->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
LayoutInvalidationReason::Fullscreen); |
| 180 } |
| 181 } |
| 182 if (placeholder()) |
| 183 placeholder()->remove(); |
| 184 remove(); |
| 185 destroy(); |
| 186 } |
| 187 |
| 188 void LayoutFullScreen::createPlaceholder(PassRefPtr<ComputedStyle> style, const
LayoutRect& frameRect) |
| 189 { |
| 190 if (style->width().isAuto()) |
| 191 style->setWidth(Length(frameRect.width(), Fixed)); |
| 192 if (style->height().isAuto()) |
| 193 style->setHeight(Length(frameRect.height(), Fixed)); |
| 194 |
| 195 if (!m_placeholder) { |
| 196 m_placeholder = new LayoutFullScreenPlaceholder(this); |
| 197 m_placeholder->setStyleWithWritingModeOfParent(style); |
| 198 if (parent()) { |
| 199 parent()->addChildWithWritingModeOfParent(m_placeholder, this); |
| 200 parent()->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
LayoutInvalidationReason::Fullscreen); |
| 201 } |
| 202 } else { |
| 203 m_placeholder->setStyle(style); |
| 204 m_placeholder->setStyleWithWritingModeOfParent(style); |
| 205 } |
| 206 } |
OLD | NEW |