static void createRendererIfNeeded(Element& element, RenderStyle* resolvedStyle) { ASSERT(!element.renderer()); Document& document = element.document(); ContainerNode* renderingParentNode = NodeRenderingTraversal::parent(&element); RefPtr<RenderStyle> style = resolvedStyle; element.setIsInsideRegion(false); if (!shouldCreateRenderer(element, renderingParentNode) && !elementInsideRegionNeedsRenderer(element, renderingParentNode, style)) return; if (!style) style = element.styleForRenderer(); RenderNamedFlowThread* parentFlowRenderer = 0; #if ENABLE(CSS_REGIONS) parentFlowRenderer = moveToFlowThreadIfNeeded(element, *style); #endif if (!element.rendererIsNeeded(*style)) return; RenderObject* parentRenderer; RenderObject* nextRenderer; if (parentFlowRenderer) { parentRenderer = parentFlowRenderer; nextRenderer = parentFlowRenderer->nextRendererForNode(&element); } else { parentRenderer = renderingParentNode->renderer(); nextRenderer = nextSiblingRenderer(element, renderingParentNode); } RenderObject* newRenderer = element.createRenderer(document.renderArena(), style.get()); if (!newRenderer) return; if (!parentRenderer->isChildAllowed(newRenderer, style.get())) { newRenderer->destroy(); return; } // Make sure the RenderObject already knows it is going to be added to a RenderFlowThread before we set the style // for the first time. Otherwise code using inRenderFlowThread() in the styleWillChange and styleDidChange will fail. newRenderer->setFlowThreadState(parentRenderer->flowThreadState()); element.setRenderer(newRenderer); newRenderer->setAnimatableStyle(style.release()); // setAnimatableStyle() can depend on renderer() already being set. #if ENABLE(FULLSCREEN_API) if (document.webkitIsFullScreen() && document.webkitCurrentFullScreenElement() == &element) { newRenderer = RenderFullScreen::wrapRenderer(newRenderer, parentRenderer, &document); if (!newRenderer) return; } #endif // Note: Adding newRenderer instead of renderer(). renderer() may be a child of newRenderer. parentRenderer->addChild(newRenderer, nextRenderer); }
void NodeRenderingContext::createRendererForElementIfNeeded() { ASSERT(!m_node->renderer()); Element* element = toElement(m_node); element->setIsInsideRegion(false); if (!shouldCreateRenderer() && !elementInsideRegionNeedsRenderer()) return; if (!m_style) m_style = element->styleForRenderer(); ASSERT(m_style); moveToFlowThreadIfNeeded(); if (!element->rendererIsNeeded(*this)) return; RenderObject* newRenderer = element->createRenderer(m_style.get()); if (!newRenderer) return; RenderObject* parentRenderer = this->parentRenderer(); if (!parentRenderer->isChildAllowed(newRenderer, m_style.get())) { newRenderer->destroy(); return; } // Make sure the RenderObject already knows it is going to be added to a RenderFlowThread before we set the style // for the first time. Otherwise code using inRenderFlowThread() in the styleWillChange and styleDidChange will fail. newRenderer->setFlowThreadState(parentRenderer->flowThreadState()); RenderObject* nextRenderer = this->nextRenderer(); element->setRenderer(newRenderer); newRenderer->setAnimatableStyle(m_style.release()); // setAnimatableStyle() can depend on renderer() already being set. if (FullscreenElementStack::isActiveFullScreenElement(element)) { newRenderer = RenderFullScreen::wrapRenderer(newRenderer, parentRenderer, element->document()); if (!newRenderer) return; } // Note: Adding newRenderer instead of renderer(). renderer() may be a child of newRenderer. parentRenderer->addChild(newRenderer, nextRenderer); }