Title: [150464] trunk/Source/WebCore
Revision
150464
Author
[email protected]
Date
2013-05-21 12:09:14 -0700 (Tue, 21 May 2013)

Log Message

Remove ContentDistribution
https://bugs.webkit.org/show_bug.cgi?id=116527

Reviewed by Andreas Kling.

Resolving distribution on traversal is simpler.

* WebCore.exp.in:
* dom/ComposedShadowTreeWalker.cpp:
(WebCore::ComposedShadowTreeWalker::traverseNode):
(WebCore::ComposedShadowTreeWalker::traverseDistributedNodes):
(WebCore::ComposedShadowTreeWalker::traverseSiblingOrBackToInsertionPoint):
* html/HTMLDetailsElement.cpp:
* html/shadow/ContentDistributor.cpp:
(WebCore::ContentDistributor::distributeSelectionsTo):
* html/shadow/ContentDistributor.h:
* html/shadow/HTMLContentElement.idl:
        
    Remove getDistributedNodes().

* html/shadow/InsertionPoint.cpp:
(WebCore::InsertionPoint::InsertionPoint):
(WebCore::InsertionPoint::attach):
(WebCore::InsertionPoint::detach):
(WebCore):
(WebCore::InsertionPoint::firstDistributed):
(WebCore::InsertionPoint::lastDistributed):
(WebCore::InsertionPoint::nextDistributedTo):
(WebCore::InsertionPoint::previousDistributedTo):
        
    Rename for clarity.

* html/shadow/InsertionPoint.h:
(WebCore::InsertionPoint::hasDistribution):
(WebCore::InsertionPoint::setHasDistribution):
(WebCore::InsertionPoint::clearDistribution):
(WebCore::InsertionPoint::matchTypeFor):
(InsertionPoint):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (150463 => 150464)


--- trunk/Source/WebCore/ChangeLog	2013-05-21 19:03:26 UTC (rev 150463)
+++ trunk/Source/WebCore/ChangeLog	2013-05-21 19:09:14 UTC (rev 150464)
@@ -1,3 +1,44 @@
+2013-05-21  Antti Koivisto  <[email protected]>
+
+        Remove ContentDistribution
+        https://bugs.webkit.org/show_bug.cgi?id=116527
+
+        Reviewed by Andreas Kling.
+
+        Resolving distribution on traversal is simpler.
+
+        * WebCore.exp.in:
+        * dom/ComposedShadowTreeWalker.cpp:
+        (WebCore::ComposedShadowTreeWalker::traverseNode):
+        (WebCore::ComposedShadowTreeWalker::traverseDistributedNodes):
+        (WebCore::ComposedShadowTreeWalker::traverseSiblingOrBackToInsertionPoint):
+        * html/HTMLDetailsElement.cpp:
+        * html/shadow/ContentDistributor.cpp:
+        (WebCore::ContentDistributor::distributeSelectionsTo):
+        * html/shadow/ContentDistributor.h:
+        * html/shadow/HTMLContentElement.idl:
+        
+            Remove getDistributedNodes().
+
+        * html/shadow/InsertionPoint.cpp:
+        (WebCore::InsertionPoint::InsertionPoint):
+        (WebCore::InsertionPoint::attach):
+        (WebCore::InsertionPoint::detach):
+        (WebCore):
+        (WebCore::InsertionPoint::firstDistributed):
+        (WebCore::InsertionPoint::lastDistributed):
+        (WebCore::InsertionPoint::nextDistributedTo):
+        (WebCore::InsertionPoint::previousDistributedTo):
+        
+            Rename for clarity.
+
+        * html/shadow/InsertionPoint.h:
+        (WebCore::InsertionPoint::hasDistribution):
+        (WebCore::InsertionPoint::setHasDistribution):
+        (WebCore::InsertionPoint::clearDistribution):
+        (WebCore::InsertionPoint::matchTypeFor):
+        (InsertionPoint):
+
 2013-05-21  Martin Robinson  <[email protected]>
 
         [GTK] [CMake] Add support for building WebKit2

Modified: trunk/Source/WebCore/WebCore.exp.in (150463 => 150464)


--- trunk/Source/WebCore/WebCore.exp.in	2013-05-21 19:03:26 UTC (rev 150463)
+++ trunk/Source/WebCore/WebCore.exp.in	2013-05-21 19:09:14 UTC (rev 150464)
@@ -1403,7 +1403,6 @@
 __ZNK7WebCore14FrameSelection31getClippedVisibleTextRectanglesERN3WTF6VectorINS_9FloatRectELm0ENS1_15CrashOnOverflowEEE
 __ZNK7WebCore14FrameSelection36rootEditableElementOrDocumentElementEv
 __ZNK7WebCore14FrameSelection6boundsEb
-__ZNK7WebCore14InsertionPoint19getDistributedNodesEv
 __ZNK7WebCore14InsertionPoint8isActiveEv
 __ZNK7WebCore14RenderListItem10markerTextEv
 __ZNK7WebCore14ResourceBuffer4dataEv

Modified: trunk/Source/WebCore/dom/ComposedShadowTreeWalker.cpp (150463 => 150464)


--- trunk/Source/WebCore/dom/ComposedShadowTreeWalker.cpp	2013-05-21 19:03:26 UTC (rev 150463)
+++ trunk/Source/WebCore/dom/ComposedShadowTreeWalker.cpp	2013-05-21 19:09:14 UTC (rev 150464)
@@ -127,7 +127,7 @@
     if (!isActiveInsertionPoint(node))
         return const_cast<Node*>(node);
     const InsertionPoint* insertionPoint = toInsertionPoint(node);
-    if (Node* found = traverseDistributedNodes(direction == TraversalDirectionForward ? insertionPoint->first() : insertionPoint->last(), insertionPoint, direction))
+    if (Node* found = traverseDistributedNodes(direction == TraversalDirectionForward ? insertionPoint->firstDistributed() : insertionPoint->lastDistributed(), insertionPoint, direction))
         return found;
     return traverseLightChildren(node, direction);
 }
@@ -148,7 +148,7 @@
 
 Node* ComposedShadowTreeWalker::traverseDistributedNodes(const Node* node, const InsertionPoint* insertionPoint, TraversalDirection direction)
 {
-    for (const Node* next = node; next; next = (direction == TraversalDirectionForward ? insertionPoint->nextTo(next) : insertionPoint->previousTo(next))) {
+    for (const Node* next = node; next; next = (direction == TraversalDirectionForward ? insertionPoint->nextDistributedTo(next) : insertionPoint->previousDistributedTo(next))) {
         if (Node* found = traverseNode(next, direction))
             return found;
     }
@@ -166,7 +166,7 @@
     if (!insertionPoint)
         return traverseSiblingInCurrentTree(node, direction);
 
-    if (Node* found = traverseDistributedNodes(direction == TraversalDirectionForward ? insertionPoint->nextTo(node) : insertionPoint->previousTo(node), insertionPoint, direction))
+    if (Node* found = traverseDistributedNodes(direction == TraversalDirectionForward ? insertionPoint->nextDistributedTo(node) : insertionPoint->previousDistributedTo(node), insertionPoint, direction))
         return found;
     return traverseSiblingOrBackToInsertionPoint(insertionPoint, direction);
 }

Modified: trunk/Source/WebCore/html/HTMLDetailsElement.cpp (150463 => 150464)


--- trunk/Source/WebCore/html/HTMLDetailsElement.cpp	2013-05-21 19:03:26 UTC (rev 150463)
+++ trunk/Source/WebCore/html/HTMLDetailsElement.cpp	2013-05-21 19:09:14 UTC (rev 150464)
@@ -52,7 +52,7 @@
     {
     }
 
-    virtual MatchType matchTypeFor(Node* node) OVERRIDE
+    virtual MatchType matchTypeFor(Node* node) const OVERRIDE
     {
         if (node->isElementNode() && node == node->parentNode()->querySelector(summaryQuerySelector(), ASSERT_NO_EXCEPTION))
             return NeverMatches;
@@ -80,7 +80,7 @@
         : HTMLContentElement(HTMLNames::webkitShadowContentTag, document)
     { }
 
-    virtual MatchType matchTypeFor(Node* node) OVERRIDE
+    virtual MatchType matchTypeFor(Node* node) const OVERRIDE
     {
         if (node->isElementNode() && node == node->parentNode()->querySelector(summaryQuerySelector(), ASSERT_NO_EXCEPTION))
             return AlwaysMatches;

Modified: trunk/Source/WebCore/html/shadow/ContentDistributor.cpp (150463 => 150464)


--- trunk/Source/WebCore/html/shadow/ContentDistributor.cpp	2013-05-21 19:03:26 UTC (rev 150463)
+++ trunk/Source/WebCore/html/shadow/ContentDistributor.cpp	2013-05-21 19:09:14 UTC (rev 150464)
@@ -35,45 +35,6 @@
 
 namespace WebCore {
 
-void ContentDistribution::swap(ContentDistribution& other)
-{
-    m_nodes.swap(other.m_nodes);
-    m_indices.swap(other.m_indices);
-}
-
-void ContentDistribution::append(PassRefPtr<Node> node)
-{
-    size_t size = m_nodes.size();
-    m_indices.set(node.get(), size);
-    m_nodes.append(node);
-}
-
-size_t ContentDistribution::find(const Node* node) const
-{
-    HashMap<const Node*, size_t>::const_iterator it = m_indices.find(node);
-    if (it == m_indices.end())
-        return notFound;
-
-    return it.get()->value;
-}
-
-Node* ContentDistribution::nextTo(const Node* node) const
-{
-    size_t index = find(node);
-    if (index == notFound || index + 1 == size())
-        return 0;
-    return at(index + 1).get();
-}
-
-Node* ContentDistribution::previousTo(const Node* node) const
-{
-    size_t index = find(node);
-    if (index == notFound || !index)
-        return 0;
-    return at(index - 1).get();
-}
-
-
 ScopeContentDistribution::ScopeContentDistribution()
     : m_insertionPointListIsValid(true)
 {
@@ -169,19 +130,18 @@
 
 void ContentDistributor::distributeSelectionsTo(InsertionPoint* insertionPoint, Element* host)
 {
-    ContentDistribution distribution;
-
     for (Node* child = host->firstChild(); child; child = child->nextSibling()) {
         ASSERT(!child->isInsertionPoint());
 
         if (insertionPoint->matchTypeFor(child) != InsertionPoint::AlwaysMatches)
             continue;
 
-        distribution.append(child);
         m_nodeToInsertionPoint.add(child, insertionPoint);
     }
 
-    insertionPoint->setDistribution(distribution);
+    if (m_nodeToInsertionPoint.isEmpty())
+        return;
+    insertionPoint->setHasDistribution();
 }
 
 void ContentDistributor::ensureDistribution(ShadowRoot* shadowRoot)

Modified: trunk/Source/WebCore/html/shadow/ContentDistributor.h (150463 => 150464)


--- trunk/Source/WebCore/html/shadow/ContentDistributor.h	2013-05-21 19:03:26 UTC (rev 150463)
+++ trunk/Source/WebCore/html/shadow/ContentDistributor.h	2013-05-21 19:09:14 UTC (rev 150464)
@@ -44,32 +44,6 @@
 class Node;
 class ShadowRoot;
 
-class ContentDistribution {
-public:
-    PassRefPtr<Node> first() const { return m_nodes.first(); }
-    PassRefPtr<Node> last() const { return m_nodes.last(); }
-    PassRefPtr<Node> at(size_t index) const { return m_nodes.at(index); }
-
-    size_t size() const { return m_nodes.size(); }
-    bool isEmpty() const { return m_nodes.isEmpty(); }
-
-    void append(PassRefPtr<Node>);
-    void clear() { m_nodes.clear(); m_indices.clear(); }
-
-    bool contains(const Node* node) const { return m_indices.contains(node); }
-    size_t find(const Node*) const;
-    Node* nextTo(const Node*) const;
-    Node* previousTo(const Node*) const;
-
-    void swap(ContentDistribution& other);
-
-    const Vector<RefPtr<Node> >& nodes() const { return m_nodes; }
-
-private:
-    Vector<RefPtr<Node> > m_nodes;
-    HashMap<const Node*, size_t> m_indices;
-};
-
 class ScopeContentDistribution {
 public:
     ScopeContentDistribution();

Modified: trunk/Source/WebCore/html/shadow/HTMLContentElement.idl (150463 => 150464)


--- trunk/Source/WebCore/html/shadow/HTMLContentElement.idl	2013-05-21 19:03:26 UTC (rev 150463)
+++ trunk/Source/WebCore/html/shadow/HTMLContentElement.idl	2013-05-21 19:09:14 UTC (rev 150464)
@@ -29,5 +29,4 @@
 ] interface HTMLContentElement : HTMLElement {
     [Reflect] attribute DOMString select;
     attribute boolean resetStyleInheritance;
-    NodeList getDistributedNodes();
 };

Modified: trunk/Source/WebCore/html/shadow/InsertionPoint.cpp (150463 => 150464)


--- trunk/Source/WebCore/html/shadow/InsertionPoint.cpp	2013-05-21 19:03:26 UTC (rev 150463)
+++ trunk/Source/WebCore/html/shadow/InsertionPoint.cpp	2013-05-21 19:09:14 UTC (rev 150464)
@@ -44,6 +44,7 @@
 InsertionPoint::InsertionPoint(const QualifiedName& tagName, Document* document)
     : HTMLElement(tagName, document, CreateInsertionPoint)
     , m_registeredWithShadowRoot(false)
+    , m_hasDistribution(false)
 {
 }
 
@@ -55,9 +56,9 @@
 {
     if (ShadowRoot* shadowRoot = containingShadowRoot())
         ContentDistributor::ensureDistribution(shadowRoot);
-    for (size_t i = 0; i < m_distribution.size(); ++i) {
-        if (!m_distribution.at(i)->attached())
-            m_distribution.at(i)->attach();
+    for (Node* current = firstDistributed(); current; current = nextDistributedTo(current)) {
+        if (!current->attached())
+            current->attach();
     }
 
     HTMLElement::attach();
@@ -68,8 +69,8 @@
     if (ShadowRoot* shadowRoot = containingShadowRoot())
         ContentDistributor::ensureDistribution(shadowRoot);
 
-    for (size_t i = 0; i < m_distribution.size(); ++i)
-        m_distribution.at(i)->detach();
+    for (Node* current = firstDistributed(); current; current = nextDistributedTo(current))
+        current->detach();
 
     HTMLElement::detach();
 }
@@ -98,19 +99,6 @@
     return true;
 }
 
-PassRefPtr<NodeList> InsertionPoint::getDistributedNodes() const
-{
-    if (ShadowRoot* shadowRoot = containingShadowRoot())
-        ContentDistributor::ensureDistribution(shadowRoot);
-
-    Vector<RefPtr<Node> > nodes;
-
-    for (size_t i = 0; i < m_distribution.size(); ++i)
-        nodes.append(m_distribution.at(i));
-
-    return StaticNodeList::adopt(nodes);
-}
-
 bool InsertionPoint::rendererIsNeeded(const NodeRenderingContext& context)
 {
     return !isShadowBoundary() && HTMLElement::rendererIsNeeded(context);
@@ -184,17 +172,52 @@
     setBooleanAttribute(reset_style_inheritanceAttr, value);
 }
 
-bool InsertionPoint::contains(const Node* node) const
-{
-    return m_distribution.contains(const_cast<Node*>(node));
-}
-
 const CSSSelectorList& InsertionPoint::emptySelectorList()
 {
     DEFINE_STATIC_LOCAL(CSSSelectorList, selectorList, (CSSSelectorList()));
     return selectorList;
 }
+    
+Node* InsertionPoint::firstDistributed() const
+{
+    if (!m_hasDistribution)
+        return 0;
+    for (Node* current = shadowHost()->firstChild(); current; current = current->nextSibling()) {
+        if (matchTypeFor(current) == InsertionPoint::AlwaysMatches)
+            return current;
+    }
+    return 0;
+}
 
+Node* InsertionPoint::lastDistributed() const
+{
+    if (!m_hasDistribution)
+        return 0;
+    for (Node* current = shadowHost()->lastChild(); current; current = current->previousSibling()) {
+        if (matchTypeFor(current) == InsertionPoint::AlwaysMatches)
+            return current;
+    }
+    return 0;
+}
+
+Node* InsertionPoint::nextDistributedTo(const Node* node) const
+{
+    for (Node* current = node->nextSibling(); current; current = current->nextSibling()) {
+        if (matchTypeFor(current) == InsertionPoint::AlwaysMatches)
+            return current;
+    }
+    return 0;
+}
+
+Node* InsertionPoint::previousDistributedTo(const Node* node) const
+{
+    for (Node* current = node->previousSibling(); current; current = current->previousSibling()) {
+        if (matchTypeFor(current) == InsertionPoint::AlwaysMatches)
+            return current;
+    }
+    return 0;
+}
+
 InsertionPoint* resolveReprojection(const Node* projectedNode)
 {
     if (ElementShadow* shadow = shadowOfParentForDistribution(projectedNode)) {

Modified: trunk/Source/WebCore/html/shadow/InsertionPoint.h (150463 => 150464)


--- trunk/Source/WebCore/html/shadow/InsertionPoint.h	2013-05-21 19:03:26 UTC (rev 150463)
+++ trunk/Source/WebCore/html/shadow/InsertionPoint.h	2013-05-21 19:09:14 UTC (rev 150464)
@@ -50,20 +50,17 @@
     enum MatchType {
         AlwaysMatches,
         NeverMatches,
-        HasToMatchSelector
     };
 
     virtual ~InsertionPoint();
 
-    bool hasDistribution() const { return !m_distribution.isEmpty(); }
-    void setDistribution(ContentDistribution& distribution) { m_distribution.swap(distribution); }
-    void clearDistribution() { m_distribution.clear(); }
+    bool hasDistribution() const { return m_hasDistribution; }
+    void setHasDistribution() { m_hasDistribution = true; }
+    void clearDistribution() { m_hasDistribution = false; }
     bool isShadowBoundary() const;
     bool isActive() const;
 
-    PassRefPtr<NodeList> getDistributedNodes() const;
-
-    virtual MatchType matchTypeFor(Node*) { return AlwaysMatches; }
+    virtual MatchType matchTypeFor(Node*) const { return AlwaysMatches; }
     virtual const CSSSelectorList& selectorList() { return emptySelectorList(); }
     virtual Type insertionPointType() const = 0;
 
@@ -75,14 +72,10 @@
 
     bool shouldUseFallbackElements() const;
 
-    size_t indexOf(Node* node) const { return m_distribution.find(node); }
-    bool contains(const Node*) const;
-    size_t size() const { return m_distribution.size(); }
-    Node* at(size_t index)  const { return m_distribution.at(index).get(); }
-    Node* first() const { return m_distribution.isEmpty() ? 0 : m_distribution.first().get(); }
-    Node* last() const { return m_distribution.isEmpty() ? 0 : m_distribution.last().get(); }
-    Node* nextTo(const Node* node) const { return m_distribution.nextTo(node); }
-    Node* previousTo(const Node* node) const { return m_distribution.previousTo(node); }
+    Node* firstDistributed() const;
+    Node* lastDistributed() const;
+    Node* nextDistributedTo(const Node*) const;
+    Node* previousDistributedTo(const Node*) const;
 
     static const CSSSelectorList& emptySelectorList();
 
@@ -97,8 +90,8 @@
 
 private:
 
-    ContentDistribution m_distribution;
     bool m_registeredWithShadowRoot;
+    bool m_hasDistribution;
 };
 
 inline InsertionPoint* toInsertionPoint(Node* node)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to