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

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

Issue 2202493002: NOT FOR REVIEW: Fullscreen WIP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 1 month 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
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
23 * DAMAGE.
24 */
25
26 #include "core/layout/LayoutFullScreen.h"
27
28 #include "core/dom/Fullscreen.h"
29 #include "core/frame/FrameHost.h"
30 #include "core/frame/VisualViewport.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), m_owner(owner) {
42 setDocumentForAnonymous(&owner->document());
43 }
44
45 // Must call setStyleWithWritingModeOfParent() instead.
46 void setStyle(PassRefPtr<ComputedStyle>) = delete;
47
48 private:
49 bool isOfType(LayoutObjectType type) const override {
50 return type == LayoutObjectLayoutFullScreenPlaceholder ||
51 LayoutBlockFlow::isOfType(type);
52 }
53 bool anonymousHasStylePropagationOverride() override { return true; }
54
55 void willBeDestroyed() override;
56 LayoutFullScreen* m_owner;
57 };
58
59 void LayoutFullScreenPlaceholder::willBeDestroyed() {
60 m_owner->resetPlaceholder();
61 LayoutBlockFlow::willBeDestroyed();
62 }
63
64 LayoutFullScreen::LayoutFullScreen()
65 : LayoutFlexibleBox(nullptr), m_placeholder(nullptr) {
66 setIsAtomicInlineLevel(false);
67 }
68
69 LayoutFullScreen* LayoutFullScreen::createAnonymous(Document* document) {
70 LayoutFullScreen* layoutObject = new LayoutFullScreen();
71 layoutObject->setDocumentForAnonymous(document);
72 return layoutObject;
73 }
74
75 void LayoutFullScreen::willBeDestroyed() {
76 if (m_placeholder) {
77 remove();
78 if (!m_placeholder->beingDestroyed())
79 m_placeholder->destroy();
80 DCHECK(!m_placeholder);
81 }
82
83 // LayoutObjects are unretained, so notify the document (which holds a pointer
84 // to a LayoutFullScreen) if its LayoutFullScreen is destroyed.
85 Fullscreen& fullscreen = Fullscreen::from(document());
86 if (fullscreen.fullScreenLayoutObject() == this)
87 fullscreen.fullScreenLayoutObjectDestroyed();
88
89 LayoutFlexibleBox::willBeDestroyed();
90 }
91
92 void LayoutFullScreen::updateStyle(LayoutObject* parent) {
93 RefPtr<ComputedStyle> fullscreenStyle = ComputedStyle::create();
94
95 // Create a stacking context:
96 fullscreenStyle->setZIndex(INT_MAX);
97 fullscreenStyle->setIsStackingContext(true);
98
99 fullscreenStyle->setFontDescription(FontDescription());
100 fullscreenStyle->font().update(nullptr);
101
102 fullscreenStyle->setDisplay(EDisplay::Flex);
103 fullscreenStyle->setJustifyContentPosition(ContentPositionCenter);
104 // TODO (lajava): Since the FullScrenn layout object is anonymous, its Default
105 // Alignment (align-items) value can't be used to resolve its children Self
106 // Alignment 'auto' values.
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 setStyleWithWritingModeOf(fullscreenStyle, parent);
120 }
121
122 void LayoutFullScreen::updateStyle() {
123 updateStyle(parent());
124 }
125
126 LayoutObject* LayoutFullScreen::wrapLayoutObject(LayoutObject* object,
127 LayoutObject* parent,
128 Document* document) {
129 // FIXME: We should not modify the structure of the layout tree during
130 // layout. crbug.com/370459
131 DeprecatedDisableModifyLayoutTreeStructureAsserts disabler;
132
133 LayoutFullScreen* fullscreenLayoutObject =
134 LayoutFullScreen::createAnonymous(document);
135 fullscreenLayoutObject->updateStyle(parent);
136 if (parent &&
137 !parent->isChildAllowed(fullscreenLayoutObject,
138 fullscreenLayoutObject->styleRef())) {
139 fullscreenLayoutObject->destroy();
140 return nullptr;
141 }
142 if (object) {
143 // |object->parent()| can be null if the object is not yet attached
144 // to |parent|.
145 if (LayoutObject* parent = object->parent()) {
146 LayoutBlock* containingBlock = object->containingBlock();
147 DCHECK(containingBlock);
148 // Since we are moving the |object| to a new parent
149 // |fullscreenLayoutObject|, the line box tree underneath our
150 // |containingBlock| is not longer valid.
151 if (containingBlock->isLayoutBlockFlow())
152 toLayoutBlockFlow(containingBlock)->deleteLineBoxTree();
153
154 parent->addChildWithWritingModeOfParent(fullscreenLayoutObject, object);
155 object->remove();
156
157 // Always just do a full layout to ensure that line boxes get deleted
158 // properly.
159 // Because objects moved from |parent| to |fullscreenLayoutObject|, we
160 // want to make new line boxes instead of leaving the old ones around.
161 parent->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
162 LayoutInvalidationReason::Fullscreen);
163 containingBlock
164 ->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
165 LayoutInvalidationReason::Fullscreen);
166 }
167 fullscreenLayoutObject->addChild(object);
168 fullscreenLayoutObject
169 ->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
170 LayoutInvalidationReason::Fullscreen);
171 }
172
173 DCHECK(document);
174 Fullscreen::from(*document).setFullScreenLayoutObject(fullscreenLayoutObject);
175 return fullscreenLayoutObject;
176 }
177
178 void LayoutFullScreen::unwrapLayoutObject() {
179 // FIXME: We should not modify the structure of the layout tree during
180 // layout. crbug.com/370459
181 DeprecatedDisableModifyLayoutTreeStructureAsserts disabler;
182
183 if (parent()) {
184 for (LayoutObject* child = firstChild(); child; child = firstChild()) {
185 // We have to clear the override size, because as a flexbox, we
186 // may have set one on the child, and we don't want to leave that
187 // lying around on the child.
188 if (child->isBox())
189 toLayoutBox(child)->clearOverrideSize();
190 child->remove();
191 parent()->addChild(child, this);
192 parent()->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
193 LayoutInvalidationReason::Fullscreen);
194 }
195 }
196 if (placeholder())
197 placeholder()->remove();
198 remove();
199 destroy();
200 }
201
202 void LayoutFullScreen::createPlaceholder(PassRefPtr<ComputedStyle> style,
203 const LayoutRect& frameRect) {
204 if (style->width().isAuto())
205 style->setWidth(Length(frameRect.width(), Fixed));
206 if (style->height().isAuto())
207 style->setHeight(Length(frameRect.height(), Fixed));
208
209 if (!m_placeholder) {
210 m_placeholder = new LayoutFullScreenPlaceholder(this);
211 m_placeholder->setStyleWithWritingModeOfParent(std::move(style));
212 if (parent()) {
213 parent()->addChildWithWritingModeOfParent(m_placeholder, this);
214 parent()->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
215 LayoutInvalidationReason::Fullscreen);
216 }
217 } else {
218 m_placeholder->setStyle(std::move(style));
219 m_placeholder->setStyleWithWritingModeOfParent(std::move(style));
220 }
221 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutFullScreen.h ('k') | third_party/WebKit/Source/core/layout/LayoutInline.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698