2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
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 ANY
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 ON
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.
27 #if ENABLE(FULLSCREEN_API)
29 #include "RenderFullScreen.h"
31 #include "RenderBlockFlow.h"
32 #include "RenderLayer.h"
34 #if USE(ACCELERATED_COMPOSITING)
35 #include "RenderLayerCompositor.h"
38 using namespace WebCore;
40 class RenderFullScreenPlaceholder FINAL : public RenderBlockFlow {
42 RenderFullScreenPlaceholder(RenderFullScreen* owner)
46 setDocumentForAnonymous(owner->document());
49 virtual bool isRenderFullScreenPlaceholder() const { return true; }
50 virtual void willBeDestroyed();
51 RenderFullScreen* m_owner;
54 void RenderFullScreenPlaceholder::willBeDestroyed()
56 m_owner->setPlaceholder(0);
57 RenderBlock::willBeDestroyed();
60 RenderFullScreen::RenderFullScreen()
61 : RenderFlexibleBox(0)
67 RenderFullScreen* RenderFullScreen::createAnonymous(Document& document)
69 RenderFullScreen* renderer = new (document.renderArena()) RenderFullScreen();
70 renderer->setDocumentForAnonymous(document);
74 void RenderFullScreen::willBeDestroyed()
78 if (!m_placeholder->beingDestroyed())
79 m_placeholder->destroy();
80 ASSERT(!m_placeholder);
83 // RenderObjects are unretained, so notify the document (which holds a pointer to a RenderFullScreen)
84 // if it's RenderFullScreen is destroyed.
85 if (document().fullScreenRenderer() == this)
86 document().fullScreenRendererDestroyed();
88 RenderFlexibleBox::willBeDestroyed();
91 static PassRefPtr<RenderStyle> createFullScreenStyle()
93 RefPtr<RenderStyle> fullscreenStyle = RenderStyle::createDefaultStyle();
95 // Create a stacking context:
96 fullscreenStyle->setZIndex(INT_MAX);
98 fullscreenStyle->setFontDescription(FontDescription());
99 fullscreenStyle->font().update(0);
101 fullscreenStyle->setDisplay(FLEX);
102 fullscreenStyle->setJustifyContent(JustifyCenter);
103 fullscreenStyle->setAlignItems(AlignCenter);
104 fullscreenStyle->setFlexDirection(FlowColumn);
106 fullscreenStyle->setPosition(FixedPosition);
107 fullscreenStyle->setWidth(Length(100.0, Percent));
108 fullscreenStyle->setHeight(Length(100.0, Percent));
109 fullscreenStyle->setLeft(Length(0, WebCore::Fixed));
110 fullscreenStyle->setTop(Length(0, WebCore::Fixed));
112 fullscreenStyle->setBackgroundColor(Color::black);
114 return fullscreenStyle.release();
117 RenderObject* RenderFullScreen::wrapRenderer(RenderObject* object, RenderObject* parent, Document* document)
119 RenderFullScreen* fullscreenRenderer = RenderFullScreen::createAnonymous(*document);
120 fullscreenRenderer->setStyle(createFullScreenStyle());
121 if (parent && !parent->isChildAllowed(fullscreenRenderer, fullscreenRenderer->style())) {
122 fullscreenRenderer->destroy();
126 // |object->parent()| can be null if the object is not yet attached
128 if (RenderObject* parent = object->parent()) {
129 RenderBlock* containingBlock = object->containingBlock();
130 ASSERT(containingBlock);
131 // Since we are moving the |object| to a new parent |fullscreenRenderer|,
132 // the line box tree underneath our |containingBlock| is not longer valid.
133 containingBlock->deleteLineBoxTree();
135 parent->addChild(fullscreenRenderer, object);
138 // Always just do a full layout to ensure that line boxes get deleted properly.
139 // Because objects moved from |parent| to |fullscreenRenderer|, we want to
140 // make new line boxes instead of leaving the old ones around.
141 parent->setNeedsLayoutAndPrefWidthsRecalc();
142 containingBlock->setNeedsLayoutAndPrefWidthsRecalc();
144 fullscreenRenderer->addChild(object);
145 fullscreenRenderer->setNeedsLayoutAndPrefWidthsRecalc();
147 document->setFullScreenRenderer(fullscreenRenderer);
148 return fullscreenRenderer;
151 void RenderFullScreen::unwrapRenderer()
155 while ((child = firstChild())) {
156 // We have to clear the override size, because as a flexbox, we
157 // may have set one on the child, and we don't want to leave that
158 // lying around on the child.
160 toRenderBox(child)->clearOverrideSize();
162 parent()->addChild(child, this);
163 parent()->setNeedsLayoutAndPrefWidthsRecalc();
167 placeholder()->remove();
169 document().setFullScreenRenderer(0);
172 void RenderFullScreen::setPlaceholder(RenderBlock* placeholder)
174 m_placeholder = placeholder;
177 void RenderFullScreen::createPlaceholder(PassRefPtr<RenderStyle> style, const LayoutRect& frameRect)
179 if (style->width().isAuto())
180 style->setWidth(Length(frameRect.width(), Fixed));
181 if (style->height().isAuto())
182 style->setHeight(Length(frameRect.height(), Fixed));
184 if (!m_placeholder) {
185 m_placeholder = new (renderArena()) RenderFullScreenPlaceholder(this);
186 m_placeholder->setStyle(style);
188 parent()->addChild(m_placeholder, this);
189 parent()->setNeedsLayoutAndPrefWidthsRecalc();
192 m_placeholder->setStyle(style);