summaryrefslogtreecommitdiff
path: root/Source/WebCore/dom/NodeRenderingContext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/dom/NodeRenderingContext.cpp')
-rw-r--r--Source/WebCore/dom/NodeRenderingContext.cpp165
1 files changed, 79 insertions, 86 deletions
diff --git a/Source/WebCore/dom/NodeRenderingContext.cpp b/Source/WebCore/dom/NodeRenderingContext.cpp
index 4a9709a0d..cdcb102d8 100644
--- a/Source/WebCore/dom/NodeRenderingContext.cpp
+++ b/Source/WebCore/dom/NodeRenderingContext.cpp
@@ -27,14 +27,15 @@
#include "NodeRenderingContext.h"
#include "ContainerNode.h"
-#include "ContentInclusionSelector.h"
#include "HTMLContentElement.h"
+#include "HTMLContentSelector.h"
#include "Node.h"
#include "RenderFlowThread.h"
#include "RenderFullScreen.h"
#include "RenderObject.h"
#include "RenderView.h"
#include "ShadowRoot.h"
+#include "ShadowRootList.h"
#if ENABLE(SVG)
#include "SVGNames.h"
@@ -43,12 +44,11 @@
namespace WebCore {
NodeRenderingContext::NodeRenderingContext(Node* node)
- : m_location(LocationNotInTree)
- , m_phase(AttachStraight)
+ : m_phase(AttachingNotInTree)
, m_node(node)
, m_parentNodeForRenderingAndStyle(0)
- , m_visualParentShadowRoot(0)
- , m_includer(0)
+ , m_visualParentShadowRootList(0)
+ , m_insertionPoint(0)
, m_style(0)
, m_parentFlowRenderer(0)
{
@@ -57,49 +57,46 @@ NodeRenderingContext::NodeRenderingContext(Node* node)
return;
if (parent->isShadowRoot()) {
- m_location = LocationShadowChild;
+ m_phase = AttachingShadowChild;
m_parentNodeForRenderingAndStyle = parent->shadowHost();
return;
}
- m_location = LocationLightChild;
-
if (parent->isElementNode()) {
- m_visualParentShadowRoot = toElement(parent)->shadowRoot();
-
- if (m_visualParentShadowRoot) {
- if ((m_includer = m_visualParentShadowRoot->includerFor(m_node))
- && m_visualParentShadowRoot->isInclusionSelectorActive()) {
- m_phase = AttachContentForwarded;
- m_parentNodeForRenderingAndStyle = NodeRenderingContext(m_includer).parentNodeForRenderingAndStyle();
+ if (toElement(parent)->hasShadowRoot()) {
+ m_visualParentShadowRootList = toElement(parent)->shadowRootList();
+ if ((m_insertionPoint = m_visualParentShadowRootList->insertionPointFor(m_node))
+ && m_visualParentShadowRootList->isSelectorActive()) {
+ m_phase = AttachingDistributed;
+ m_parentNodeForRenderingAndStyle = NodeRenderingContext(m_insertionPoint).parentNodeForRenderingAndStyle();
return;
}
- m_phase = AttachContentLight;
+ m_phase = AttachingNotDistributed;
m_parentNodeForRenderingAndStyle = parent;
return;
}
- if (parent->isContentElement()) {
- HTMLContentElement* shadowContentElement = toHTMLContentElement(parent);
- if (!shadowContentElement->hasInclusion()) {
- m_phase = AttachContentFallback;
- m_parentNodeForRenderingAndStyle = NodeRenderingContext(parent).parentNodeForRenderingAndStyle();
- return;
- }
+ if (isInsertionPoint(parent)) {
+ if (toInsertionPoint(parent)->hasSelection())
+ m_phase = AttachingNotFallbacked;
+ else
+ m_phase = AttachingFallbacked;
+ m_parentNodeForRenderingAndStyle = NodeRenderingContext(parent).parentNodeForRenderingAndStyle();
+ return;
}
}
+ m_phase = AttachingStraight;
m_parentNodeForRenderingAndStyle = parent;
}
NodeRenderingContext::NodeRenderingContext(Node* node, RenderStyle* style)
- : m_location(LocationUndetermined)
- , m_phase(AttachStraight)
+ : m_phase(Calculating)
, m_node(node)
, m_parentNodeForRenderingAndStyle(0)
- , m_visualParentShadowRoot(0)
- , m_includer(0)
+ , m_visualParentShadowRootList(0)
+ , m_insertionPoint(0)
, m_style(style)
, m_parentFlowRenderer(0)
{
@@ -120,72 +117,80 @@ PassRefPtr<RenderStyle> NodeRenderingContext::releaseStyle()
return m_style.release();
}
-static RenderObject* nextRendererOf(HTMLContentElement* parent, Node* current)
+static RenderObject* nextRendererOf(InsertionPoint* parent, Node* current)
{
- ShadowInclusion* currentInclusion = parent->inclusions()->find(current);
- if (!currentInclusion)
+ HTMLContentSelection* currentSelection = parent->selections()->find(current);
+ if (!currentSelection)
return 0;
- for (ShadowInclusion* inclusion = currentInclusion->next(); inclusion; inclusion = inclusion->next()) {
- if (RenderObject* renderer = inclusion->content()->renderer())
+ for (HTMLContentSelection* selection = currentSelection->next(); selection; selection = selection->next()) {
+ if (RenderObject* renderer = selection->node()->renderer())
return renderer;
}
return 0;
}
-static RenderObject* previousRendererOf(HTMLContentElement* parent, Node* current)
+static RenderObject* previousRendererOf(InsertionPoint* parent, Node* current)
{
RenderObject* lastRenderer = 0;
- for (ShadowInclusion* inclusion = parent->inclusions()->first(); inclusion; inclusion = inclusion->next()) {
- if (inclusion->content() == current)
+ for (HTMLContentSelection* selection = parent->selections()->first(); selection; selection = selection->next()) {
+ if (selection->node() == current)
break;
- if (RenderObject* renderer = inclusion->content()->renderer())
+ if (RenderObject* renderer = selection->node()->renderer())
lastRenderer = renderer;
}
return lastRenderer;
}
-static RenderObject* firstRendererOf(HTMLContentElement* parent)
+static RenderObject* firstRendererOf(InsertionPoint* parent)
{
- for (ShadowInclusion* inclusion = parent->inclusions()->first(); inclusion; inclusion = inclusion->next()) {
- if (RenderObject* renderer = inclusion->content()->renderer())
- return renderer;
+ if (parent->hasSelection()) {
+ for (HTMLContentSelection* selection = parent->selections()->first(); selection; selection = selection->next()) {
+ if (RenderObject* renderer = selection->node()->renderer())
+ return renderer;
+ }
+
+ return 0;
}
- return 0;
+ return NodeRenderingContext(parent).nextRenderer();
}
-static RenderObject* lastRendererOf(HTMLContentElement* parent)
+static RenderObject* lastRendererOf(InsertionPoint* parent)
{
- for (ShadowInclusion* inclusion = parent->inclusions()->last(); inclusion; inclusion = inclusion->previous()) {
- if (RenderObject* renderer = inclusion->content()->renderer())
- return renderer;
+ if (parent->hasSelection()) {
+ for (HTMLContentSelection* selection = parent->selections()->last(); selection; selection = selection->previous()) {
+ if (RenderObject* renderer = selection->node()->renderer())
+ return renderer;
+ }
+
+ return 0;
}
- return 0;
+ return NodeRenderingContext(parent).previousRenderer();
}
RenderObject* NodeRenderingContext::nextRenderer() const
{
- ASSERT(m_node->renderer() || m_location != LocationUndetermined);
+ ASSERT(m_node->renderer() || m_phase != Calculating);
if (RenderObject* renderer = m_node->renderer())
return renderer->nextSibling();
if (m_parentFlowRenderer)
return m_parentFlowRenderer->nextRendererForNode(m_node);
- if (m_phase == AttachContentForwarded) {
- if (RenderObject* found = nextRendererOf(m_includer, m_node))
+ if (m_phase == AttachingDistributed) {
+ if (RenderObject* found = nextRendererOf(m_insertionPoint, m_node))
return found;
- return NodeRenderingContext(m_includer).nextRenderer();
+ return NodeRenderingContext(m_insertionPoint).nextRenderer();
}
- // Avoid an O(n^2) problem with this function by not checking for
+ // Avoid an O(N^2) problem with this function by not checking for
// nextRenderer() when the parent element hasn't attached yet.
- if (m_node->parentOrHostNode() && !m_node->parentOrHostNode()->attached() && m_phase != AttachContentFallback)
+ if (m_node->parentOrHostNode() && !m_node->parentOrHostNode()->attached())
return 0;
for (Node* node = m_node->nextSibling(); node; node = node->nextSibling()) {
@@ -195,31 +200,30 @@ RenderObject* NodeRenderingContext::nextRenderer() const
continue;
return node->renderer();
}
- if (node->isContentElement()) {
- if (RenderObject* first = firstRendererOf(toHTMLContentElement(node)))
+
+ if (isInsertionPoint(node)) {
+ if (RenderObject* first = firstRendererOf(toInsertionPoint(node)))
return first;
}
}
- if (m_phase == AttachContentFallback)
- return NodeRenderingContext(m_node->parentNode()).nextRenderer();
-
return 0;
}
RenderObject* NodeRenderingContext::previousRenderer() const
{
- ASSERT(m_node->renderer() || m_location != LocationUndetermined);
+ ASSERT(m_node->renderer() || m_phase != Calculating);
+
if (RenderObject* renderer = m_node->renderer())
return renderer->previousSibling();
if (m_parentFlowRenderer)
return m_parentFlowRenderer->previousRendererForNode(m_node);
- if (m_phase == AttachContentForwarded) {
- if (RenderObject* found = previousRendererOf(m_includer, m_node))
+ if (m_phase == AttachingDistributed) {
+ if (RenderObject* found = previousRendererOf(m_insertionPoint, m_node))
return found;
- return NodeRenderingContext(m_includer).previousRenderer();
+ return NodeRenderingContext(m_insertionPoint).previousRenderer();
}
// FIXME: We should have the same O(N^2) avoidance as nextRenderer does
@@ -231,68 +235,57 @@ RenderObject* NodeRenderingContext::previousRenderer() const
continue;
return node->renderer();
}
- if (node->isContentElement()) {
- if (RenderObject* last = lastRendererOf(toHTMLContentElement(node)))
+ if (isInsertionPoint(node)) {
+ if (RenderObject* last = lastRendererOf(toInsertionPoint(node)))
return last;
}
}
- if (m_phase == AttachContentFallback)
- return NodeRenderingContext(m_node->parentNode()).previousRenderer();
-
return 0;
}
RenderObject* NodeRenderingContext::parentRenderer() const
{
if (RenderObject* renderer = m_node->renderer()) {
- ASSERT(m_location == LocationUndetermined);
+ ASSERT(m_phase == Calculating);
return renderer->parent();
}
if (m_parentFlowRenderer)
return m_parentFlowRenderer;
- ASSERT(m_location != LocationUndetermined);
+ ASSERT(m_phase != Calculating);
return m_parentNodeForRenderingAndStyle ? m_parentNodeForRenderingAndStyle->renderer() : 0;
}
void NodeRenderingContext::hostChildrenChanged()
{
- if (m_phase == AttachContentLight)
- m_visualParentShadowRoot->hostChildrenChanged();
+ if (m_phase == AttachingNotDistributed)
+ m_visualParentShadowRootList->hostChildrenChanged();
}
bool NodeRenderingContext::shouldCreateRenderer() const
{
- ASSERT(m_location != LocationUndetermined);
+ ASSERT(m_phase != Calculating);
ASSERT(parentNodeForRenderingAndStyle());
- if (m_location == LocationNotInTree || m_phase == AttachContentLight)
+ if (m_phase == AttachingNotInTree || m_phase == AttachingNotDistributed || m_phase == AttachingNotFallbacked)
return false;
-
RenderObject* parentRenderer = this->parentRenderer();
if (!parentRenderer)
return false;
-
- if (m_location == LocationLightChild && m_phase == AttachStraight) {
- // FIXME: Ignoring canHaveChildren() in a case of shadow children might be wrong.
- // See https://bugs.webkit.org/show_bug.cgi?id=52423
- if (!parentRenderer->canHaveChildren())
- return false;
-
- if (m_visualParentShadowRoot)
- return false;
- }
-
- if (!m_parentNodeForRenderingAndStyle->childShouldCreateRenderer(m_node))
+ if (!parentRenderer->canHaveChildren())
+ return false;
+ if (!m_parentNodeForRenderingAndStyle->childShouldCreateRenderer(*this))
return false;
-
return true;
}
void NodeRenderingContext::moveToFlowThreadIfNeeded()
{
+ if (!m_node->document()->cssRegionsEnabled())
+ return;
+
if (!m_node->isElementNode() || !m_style || m_style->flowThread().isEmpty())
return;