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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutFullScreen.cpp

Issue 2107233002: Reland "Implement FullScreen using top layer." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
(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 ASSERT(!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
102 fullscreenStyle->setFontDescription(FontDescription());
103 fullscreenStyle->font().update(nullptr);
104
105 fullscreenStyle->setDisplay(FLEX);
106 fullscreenStyle->setJustifyContentPosition(ContentPositionCenter);
107 fullscreenStyle->setAlignItemsPosition(ItemPositionCenter);
108 fullscreenStyle->setFlexDirection(FlowColumn);
109
110 fullscreenStyle->setPosition(FixedPosition);
111 fullscreenStyle->setLeft(Length(0, blink::Fixed));
112 fullscreenStyle->setTop(Length(0, blink::Fixed));
113 IntSize viewportSize = document().page()->frameHost().visualViewport().size( );
114 fullscreenStyle->setWidth(Length(viewportSize.width(), blink::Fixed));
115 fullscreenStyle->setHeight(Length(viewportSize.height(), blink::Fixed));
116
117 fullscreenStyle->setBackgroundColor(StyleColor(Color::black));
118
119 setStyleWithWritingModeOfParent(fullscreenStyle);
120 }
121
122 LayoutObject* LayoutFullScreen::wrapLayoutObject(LayoutObject* object, LayoutObj ect* parent, Document* document)
123 {
124 // FIXME: We should not modify the structure of the layout tree during
125 // layout. crbug.com/370459
126 DeprecatedDisableModifyLayoutTreeStructureAsserts disabler;
127
128 LayoutFullScreen* fullscreenLayoutObject = LayoutFullScreen::createAnonymous (document);
129 fullscreenLayoutObject->updateStyle();
130 if (parent && !parent->isChildAllowed(fullscreenLayoutObject, fullscreenLayo utObject->styleRef())) {
131 fullscreenLayoutObject->destroy();
132 return nullptr;
133 }
134 if (object) {
135 // |object->parent()| can be null if the object is not yet attached
136 // to |parent|.
137 if (LayoutObject* parent = object->parent()) {
138 LayoutBlock* containingBlock = object->containingBlock();
139 ASSERT(containingBlock);
140 // Since we are moving the |object| to a new parent |fullscreenLayou tObject|,
141 // the line box tree underneath our |containingBlock| is not longer valid.
142 if (containingBlock->isLayoutBlockFlow())
143 toLayoutBlockFlow(containingBlock)->deleteLineBoxTree();
144
145 parent->addChildWithWritingModeOfParent(fullscreenLayoutObject, obje ct);
146 object->remove();
147
148 // Always just do a full layout to ensure that line boxes get delete d properly.
149 // Because objects moved from |parent| to |fullscreenLayoutObject|, we want to
150 // make new line boxes instead of leaving the old ones around.
151 parent->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(La youtInvalidationReason::Fullscreen);
152 containingBlock->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvali dation(LayoutInvalidationReason::Fullscreen);
153 }
154 fullscreenLayoutObject->addChild(object);
155 fullscreenLayoutObject->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInv alidation(LayoutInvalidationReason::Fullscreen);
156 }
157
158 ASSERT(document);
159 Fullscreen::from(*document).setFullScreenLayoutObject(fullscreenLayoutObject );
160 return fullscreenLayoutObject;
161 }
162
163 void LayoutFullScreen::unwrapLayoutObject()
164 {
165 // FIXME: We should not modify the structure of the layout tree during
166 // layout. crbug.com/370459
167 DeprecatedDisableModifyLayoutTreeStructureAsserts disabler;
168
169 if (parent()) {
170 for (LayoutObject* child = firstChild(); child; child = firstChild()) {
171 // We have to clear the override size, because as a flexbox, we
172 // may have set one on the child, and we don't want to leave that
173 // lying around on the child.
174 if (child->isBox())
175 toLayoutBox(child)->clearOverrideSize();
176 child->remove();
177 parent()->addChild(child, this);
178 parent()->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation( LayoutInvalidationReason::Fullscreen);
179 }
180 }
181 if (placeholder())
182 placeholder()->remove();
183 remove();
184 destroy();
185 }
186
187 void LayoutFullScreen::createPlaceholder(PassRefPtr<ComputedStyle> style, const LayoutRect& frameRect)
188 {
189 if (style->width().isAuto())
190 style->setWidth(Length(frameRect.width(), Fixed));
191 if (style->height().isAuto())
192 style->setHeight(Length(frameRect.height(), Fixed));
193
194 if (!m_placeholder) {
195 m_placeholder = new LayoutFullScreenPlaceholder(this);
196 m_placeholder->setStyleWithWritingModeOfParent(style);
197 if (parent()) {
198 parent()->addChildWithWritingModeOfParent(m_placeholder, this);
199 parent()->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation( LayoutInvalidationReason::Fullscreen);
200 }
201 } else {
202 m_placeholder->setStyle(style);
203 m_placeholder->setStyleWithWritingModeOfParent(style);
204 }
205 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698