Source/WebCore: Fix a crash relating to anonymous block merging in
[WebKit-https.git] / Source / WebCore / rendering / RenderFullScreen.cpp
index cc53a6e..fe0f23d 100644 (file)
 
 #include "RenderLayer.h"
 
+#if USE(ACCELERATED_COMPOSITING)
+#include "RenderLayerCompositor.h"
+#endif
+
 using namespace WebCore;
 
-void RenderFullScreen::setAnimating(bool animating)
+class RenderFullScreenPlaceholder : public RenderBlock {
+public:
+    RenderFullScreenPlaceholder(RenderFullScreen* owner) 
+        : RenderBlock(owner->document())
+        , m_owner(owner) 
+    { 
+    }
+private:
+    virtual bool isRenderFullScreenPlaceholder() const { return true; }
+    virtual void willBeDestroyed();
+    RenderFullScreen* m_owner;
+};
+
+void RenderFullScreenPlaceholder::willBeDestroyed()
 {
-    m_isAnimating = animating;
-#if USE(ACCELERATED_COMPOSITING)
-    if (layer())
-        layer()->contentChanged(RenderLayer::FullScreenChanged);
-#endif
+    m_owner->setPlaceholder(0);
+    RenderBlock::willBeDestroyed();
+}
+
+RenderFullScreen::RenderFullScreen(Node* node) 
+    : RenderDeprecatedFlexibleBox(node)
+    , m_placeholder(0)
+{ 
+    setReplaced(false); 
+}
+
+void RenderFullScreen::willBeDestroyed()
+{
+    if (m_placeholder) {
+        remove();
+        if (!m_placeholder->beingDestroyed())
+            m_placeholder->destroy();
+        ASSERT(!m_placeholder);
+    }
+
+    // RenderObjects are unretained, so notify the document (which holds a pointer to a RenderFullScreen)
+    // if it's RenderFullScreen is destroyed.
+    if (document() && document()->fullScreenRenderer() == this)
+        document()->fullScreenRendererDestroyed();
+
+    RenderDeprecatedFlexibleBox::willBeDestroyed();
 }
 
-PassRefPtr<RenderStyle> RenderFullScreen::createFullScreenStyle()
+static PassRefPtr<RenderStyle> createFullScreenStyle()
 {
     RefPtr<RenderStyle> fullscreenStyle = RenderStyle::createDefaultStyle();
 
     // Create a stacking context:
-    fullscreenStyle->setZIndex(0);
+    fullscreenStyle->setZIndex(INT_MAX);
 
     fullscreenStyle->setFontDescription(FontDescription());
     fullscreenStyle->font().update(0);
@@ -54,17 +92,72 @@ PassRefPtr<RenderStyle> RenderFullScreen::createFullScreenStyle()
     fullscreenStyle->setDisplay(BOX);
     fullscreenStyle->setBoxPack(BCENTER);
     fullscreenStyle->setBoxAlign(BCENTER);
-    fullscreenStyle->setBoxOrient(HORIZONTAL);
+    fullscreenStyle->setBoxOrient(VERTICAL);
     
     fullscreenStyle->setPosition(FixedPosition);
     fullscreenStyle->setWidth(Length(100.0, Percent));
     fullscreenStyle->setHeight(Length(100.0, Percent));
-    fullscreenStyle->setLeft(Length(0, Fixed));
-    fullscreenStyle->setTop(Length(0, Fixed));
+    fullscreenStyle->setLeft(Length(0, WebCore::Fixed));
+    fullscreenStyle->setTop(Length(0, WebCore::Fixed));
     
     fullscreenStyle->setBackgroundColor(Color::black);
     
-    return fullscreenStyle;
+    return fullscreenStyle.release();
+}
+
+RenderObject* RenderFullScreen::wrapRenderer(RenderObject* object, Document* document)
+{
+    RenderFullScreen* fullscreenRenderer = new (document->renderArena()) RenderFullScreen(document);
+    fullscreenRenderer->setStyle(createFullScreenStyle());
+    if (object) {
+        if (RenderObject* parent = object->parent()) {
+            parent->addChild(fullscreenRenderer, object);
+            object->remove();
+        }
+        fullscreenRenderer->addChild(object);
+    }
+    document->setFullScreenRenderer(fullscreenRenderer);
+    if (fullscreenRenderer->placeholder())
+        return fullscreenRenderer->placeholder();
+    return fullscreenRenderer;
+}
+
+void RenderFullScreen::unwrapRenderer()
+{
+    RenderObject* holder = placeholder() ? placeholder() : this;
+    if (holder->parent()) {
+        RenderObject* child;
+        while ((child = firstChild())) {
+            child->remove();
+            holder->parent()->addChild(child, holder);
+        }
+    }
+    remove();
+    document()->setFullScreenRenderer(0);
+}
+
+void RenderFullScreen::setPlaceholder(RenderBlock* placeholder)
+{
+    m_placeholder = placeholder;
+}
+
+void RenderFullScreen::createPlaceholder(PassRefPtr<RenderStyle> style, const IntRect& 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 = new (document()->renderArena()) RenderFullScreenPlaceholder(this);
+        m_placeholder->setStyle(style);
+        if (parent()) {
+            parent()->addChild(m_placeholder, this);
+            remove();
+        }
+        m_placeholder->addChild(this);
+    } else
+        m_placeholder->setStyle(style);
 }
 
 #endif