RenderFullScreen.cpp [plain text]
#include "config.h"
#if ENABLE(FULLSCREEN_API)
#include "RenderFullScreen.h"
#include "RenderBlockFlow.h"
#include "RenderLayer.h"
#include "RenderLayerCompositor.h"
namespace WebCore {
class RenderFullScreenPlaceholder final : public RenderBlockFlow {
public:
RenderFullScreenPlaceholder(RenderFullScreen& owner, RenderStyle&& style)
: RenderBlockFlow(owner.document(), WTFMove(style))
, m_owner(owner)
{
}
private:
virtual bool isRenderFullScreenPlaceholder() const { return true; }
virtual void willBeDestroyed();
RenderFullScreen& m_owner;
};
void RenderFullScreenPlaceholder::willBeDestroyed()
{
m_owner.setPlaceholder(0);
RenderBlockFlow::willBeDestroyed();
}
RenderFullScreen::RenderFullScreen(Document& document, RenderStyle&& style)
: RenderFlexibleBox(document, WTFMove(style))
, m_placeholder(0)
{
setReplaced(false);
}
void RenderFullScreen::willBeDestroyed()
{
if (m_placeholder) {
removeFromParent();
if (!m_placeholder->beingDestroyed())
m_placeholder->destroy();
ASSERT(!m_placeholder);
}
if (document().fullScreenRenderer() == this)
document().fullScreenRendererDestroyed();
RenderFlexibleBox::willBeDestroyed();
}
static RenderStyle createFullScreenStyle()
{
auto fullscreenStyle = RenderStyle::create();
fullscreenStyle.setZIndex(INT_MAX);
fullscreenStyle.setFontDescription({ });
fullscreenStyle.fontCascade().update(nullptr);
fullscreenStyle.setDisplay(FLEX);
fullscreenStyle.setJustifyContentPosition(ContentPositionCenter);
fullscreenStyle.setAlignItemsPosition(ItemPositionCenter);
fullscreenStyle.setFlexDirection(FlowColumn);
fullscreenStyle.setPosition(FixedPosition);
fullscreenStyle.setWidth(Length(100.0, Percent));
fullscreenStyle.setHeight(Length(100.0, Percent));
fullscreenStyle.setLeft(Length(0, WebCore::Fixed));
fullscreenStyle.setTop(Length(0, WebCore::Fixed));
fullscreenStyle.setBackgroundColor(Color::black);
return fullscreenStyle;
}
RenderFullScreen* RenderFullScreen::wrapRenderer(RenderObject* object, RenderElement* parent, Document& document)
{
RenderFullScreen* fullscreenRenderer = new RenderFullScreen(document, createFullScreenStyle());
fullscreenRenderer->initializeStyle();
if (parent && !parent->isChildAllowed(*fullscreenRenderer, fullscreenRenderer->style())) {
fullscreenRenderer->destroy();
return 0;
}
if (object) {
if (RenderElement* parent = object->parent()) {
RenderBlock* containingBlock = object->containingBlock();
ASSERT(containingBlock);
containingBlock->deleteLines();
parent->addChild(fullscreenRenderer, object);
object->removeFromParent();
parent->setNeedsLayoutAndPrefWidthsRecalc();
containingBlock->setNeedsLayoutAndPrefWidthsRecalc();
}
fullscreenRenderer->addChild(object);
fullscreenRenderer->setNeedsLayoutAndPrefWidthsRecalc();
}
document.setFullScreenRenderer(fullscreenRenderer);
return fullscreenRenderer;
}
void RenderFullScreen::unwrapRenderer(bool& requiresRenderTreeRebuild)
{
requiresRenderTreeRebuild = false;
if (parent()) {
auto* child = firstChild();
if (child != lastChild())
requiresRenderTreeRebuild = true;
else if (child && child->isAnonymousBlock()) {
auto& anonymousBlock = downcast<RenderBlock>(*child);
if (anonymousBlock.firstChild() != anonymousBlock.lastChild())
requiresRenderTreeRebuild = true;
}
while ((child = firstChild())) {
if (child->isAnonymousBlock() && !requiresRenderTreeRebuild) {
if (auto* nonAnonymousChild = downcast<RenderBlock>(*child).firstChild())
child = nonAnonymousChild;
else {
child->removeFromParent();
child->destroy();
continue;
}
}
if (is<RenderBox>(*child))
downcast<RenderBox>(*child).clearOverrideSize();
child->removeFromParent();
parent()->addChild(child, this);
parent()->setNeedsLayoutAndPrefWidthsRecalc();
}
}
if (placeholder())
placeholder()->removeFromParent();
removeFromParent();
document().setFullScreenRenderer(0);
}
void RenderFullScreen::setPlaceholder(RenderBlock* placeholder)
{
m_placeholder = placeholder;
}
void RenderFullScreen::createPlaceholder(std::unique_ptr<RenderStyle> style, const LayoutRect& frameRect)
{
if (style->width().isAuto())
style->setWidth(Length(frameRect.width(), Fixed));
if (style->height().isAuto())
style->setHeight(Length(frameRect.height(), Fixed));
if (m_placeholder) {
m_placeholder->setStyle(WTFMove(*style));
return;
}
m_placeholder = new RenderFullScreenPlaceholder(*this, WTFMove(*style));
m_placeholder->initializeStyle();
if (parent()) {
parent()->addChild(m_placeholder, this);
parent()->setNeedsLayoutAndPrefWidthsRecalc();
}
}
}
#endif