Title: [139400] trunk/Source/WebCore
Revision
139400
Author
morr...@google.com
Date
2013-01-10 20:00:13 -0800 (Thu, 10 Jan 2013)

Log Message

[Shadow DOM] Refactoring: InsertionPoint could simplify its subclass hooks
https://bugs.webkit.org/show_bug.cgi?id=106614

Reviewed by Dimitri Glazkov.

This change simplifies InsertionPoint overrides and give some flexibility to it.

The change

- Removes InsertionPoint::isSelectValid(). now ContentSelectorQuery parses given selector anyway.
  Invalid select attribute is handled by newly introduced matchTypeFor() method.
- Introduces InsertionPoint::matchTypeFor() to give a chance each InsertionPoint to decide whether it
  accepts the given node as its distribution. Then it lets DetailsSummaryElement adopt it.
- Pulls some HTMLShadowElement overrides up to InsertionPoint so that other upcoming InsertionPoint
  subclasses don't need to override them.

No new tests. Refactoring.

* html/HTMLDetailsElement.cpp:
(WebCore::DetailsSummaryElement::DetailsSummaryElement):
- Implemented matchTypeFor() to get rid of HTMLContentElement machinery which is compiled out in the upcoming change.
(DetailsSummaryElement):
* html/shadow/ContentSelectorQuery.cpp:
(WebCore::ContentSelectorQuery::ContentSelectorQuery):
(WebCore::ContentSelectorQuery::matches):
* html/shadow/HTMLContentElement.cpp:
(WebCore::HTMLContentElement::matchTypeFor): Added.
(WebCore):
* html/shadow/HTMLContentElement.h:
(HTMLContentElement):
(WebCore::isHTMLContentElement):
* html/shadow/HTMLShadowElement.cpp:
* html/shadow/HTMLShadowElement.h:
(HTMLShadowElement):
* html/shadow/InsertionPoint.cpp:
(WebCore::InsertionPoint::emptySelectorList): Moved from HTMLShadowElement.
(WebCore):
* html/shadow/InsertionPoint.h:
(WebCore::InsertionPoint::matchTypeFor): Added.
(WebCore::InsertionPoint::selectorList): Moved from HTMLShadowElement.
(InsertionPoint):
* testing/Internals.cpp:
(WebCore::Internals::isValidContentSelect):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (139399 => 139400)


--- trunk/Source/WebCore/ChangeLog	2013-01-11 03:18:36 UTC (rev 139399)
+++ trunk/Source/WebCore/ChangeLog	2013-01-11 04:00:13 UTC (rev 139400)
@@ -1,3 +1,49 @@
+2013-01-10  Hajime Morrita  <morr...@google.com>
+
+        [Shadow DOM] Refactoring: InsertionPoint could simplify its subclass hooks
+        https://bugs.webkit.org/show_bug.cgi?id=106614
+
+        Reviewed by Dimitri Glazkov.
+
+        This change simplifies InsertionPoint overrides and give some flexibility to it.
+
+        The change
+
+        - Removes InsertionPoint::isSelectValid(). now ContentSelectorQuery parses given selector anyway.
+          Invalid select attribute is handled by newly introduced matchTypeFor() method.
+        - Introduces InsertionPoint::matchTypeFor() to give a chance each InsertionPoint to decide whether it
+          accepts the given node as its distribution. Then it lets DetailsSummaryElement adopt it.
+        - Pulls some HTMLShadowElement overrides up to InsertionPoint so that other upcoming InsertionPoint
+          subclasses don't need to override them.
+
+        No new tests. Refactoring.
+
+        * html/HTMLDetailsElement.cpp:
+        (WebCore::DetailsSummaryElement::DetailsSummaryElement):
+        - Implemented matchTypeFor() to get rid of HTMLContentElement machinery which is compiled out in the upcoming change.
+        (DetailsSummaryElement):
+        * html/shadow/ContentSelectorQuery.cpp:
+        (WebCore::ContentSelectorQuery::ContentSelectorQuery):
+        (WebCore::ContentSelectorQuery::matches):
+        * html/shadow/HTMLContentElement.cpp:
+        (WebCore::HTMLContentElement::matchTypeFor): Added.
+        (WebCore):
+        * html/shadow/HTMLContentElement.h:
+        (HTMLContentElement):
+        (WebCore::isHTMLContentElement):
+        * html/shadow/HTMLShadowElement.cpp:
+        * html/shadow/HTMLShadowElement.h:
+        (HTMLShadowElement):
+        * html/shadow/InsertionPoint.cpp:
+        (WebCore::InsertionPoint::emptySelectorList): Moved from HTMLShadowElement.
+        (WebCore):
+        * html/shadow/InsertionPoint.h:
+        (WebCore::InsertionPoint::matchTypeFor): Added.
+        (WebCore::InsertionPoint::selectorList): Moved from HTMLShadowElement.
+        (InsertionPoint):
+        * testing/Internals.cpp:
+        (WebCore::Internals::isValidContentSelect):
+
 2013-01-10  Dean Jackson  <d...@apple.com>
 
         Plugin snapshot label should take device resolution and inset into account

Modified: trunk/Source/WebCore/html/HTMLDetailsElement.cpp (139399 => 139400)


--- trunk/Source/WebCore/html/HTMLDetailsElement.cpp	2013-01-11 03:18:36 UTC (rev 139399)
+++ trunk/Source/WebCore/html/HTMLDetailsElement.cpp	2013-01-11 04:00:13 UTC (rev 139400)
@@ -71,8 +71,13 @@
 private:
     DetailsSummaryElement(Document* document)
         : HTMLContentElement(HTMLNames::webkitShadowContentTag, document)
+    { }
+
+    virtual MatchType matchTypeFor(Node* node) OVERRIDE
     {
-        setSelect(summaryQuerySelector());
+        if (node->isElementNode() && node == node->parentNode()->querySelector(summaryQuerySelector(), ASSERT_NO_EXCEPTION))
+            return AlwaysMatches;
+        return NeverMatches;
     }
 };
 

Modified: trunk/Source/WebCore/html/shadow/ContentSelectorQuery.cpp (139399 => 139400)


--- trunk/Source/WebCore/html/shadow/ContentSelectorQuery.cpp	2013-01-11 03:18:36 UTC (rev 139399)
+++ trunk/Source/WebCore/html/shadow/ContentSelectorQuery.cpp	2013-01-11 04:00:13 UTC (rev 139400)
@@ -68,8 +68,7 @@
     : m_insertionPoint(insertionPoint)
     , m_selectorChecker(insertionPoint->document())
 {
-    if (insertionPoint->isSelectValid())
-        m_selectors.initialize(insertionPoint->selectorList());
+    m_selectors.initialize(insertionPoint->selectorList());
 }
 
 bool ContentSelectorQuery::matches(const Vector<RefPtr<Node> >& siblings, int nth) const
@@ -77,16 +76,17 @@
     Node* node = siblings[nth].get();
     ASSERT(node);
 
-    if (m_insertionPoint->select().isNull() || m_insertionPoint->select().isEmpty())
+    switch (m_insertionPoint->matchTypeFor(node)) {
+    case InsertionPoint::AlwaysMatches:
         return true;
-
-    if (!m_insertionPoint->isSelectValid())
+    case InsertionPoint::NeverMatches:
         return false;
-
-    if (!node->isElementNode())
+    case InsertionPoint::HasToMatchSelector:
+        return node->isElementNode() && m_selectors.matches(m_selectorChecker, siblings, nth);
+    default:
+        ASSERT_NOT_REACHED();
         return false;
-
-    return m_selectors.matches(m_selectorChecker, siblings, nth);
+    }
 }
 
 }

Modified: trunk/Source/WebCore/html/shadow/HTMLContentElement.cpp (139399 => 139400)


--- trunk/Source/WebCore/html/shadow/HTMLContentElement.cpp	2013-01-11 03:18:36 UTC (rev 139399)
+++ trunk/Source/WebCore/html/shadow/HTMLContentElement.cpp	2013-01-11 04:00:13 UTC (rev 139400)
@@ -72,6 +72,15 @@
 {
 }
 
+InsertionPoint::MatchType HTMLContentElement::matchTypeFor(Node*)
+{
+    if (select().isNull() || select().isEmpty())
+        return AlwaysMatches;
+    if (!isSelectValid())
+        return NeverMatches;
+    return HasToMatchSelector;
+}
+
 const AtomicString& HTMLContentElement::select() const
 {
     return getAttribute(selectAttr);

Modified: trunk/Source/WebCore/html/shadow/HTMLContentElement.h (139399 => 139400)


--- trunk/Source/WebCore/html/shadow/HTMLContentElement.h	2013-01-11 03:18:36 UTC (rev 139399)
+++ trunk/Source/WebCore/html/shadow/HTMLContentElement.h	2013-01-11 04:00:13 UTC (rev 139400)
@@ -46,11 +46,13 @@
     virtual ~HTMLContentElement();
 
     void setSelect(const AtomicString&);
-    virtual const AtomicString& select() const;
-    virtual bool isSelectValid();
-    virtual const CSSSelectorList& selectorList();
+    const AtomicString& select() const;
+
+    virtual MatchType matchTypeFor(Node*) OVERRIDE;
+    virtual const CSSSelectorList& selectorList() OVERRIDE;
     virtual Type insertionPointType() const OVERRIDE { return ContentInsertionPoint; }
     virtual bool canAffectSelector() const OVERRIDE { return true; }
+    virtual bool isSelectValid();
 
 protected:
     HTMLContentElement(const QualifiedName&, Document*);
@@ -80,7 +82,7 @@
 inline bool isHTMLContentElement(const Node* node)
 {
     ASSERT(node);
-    return node->hasTagName(HTMLContentElement::contentTagName(node->document()));
+    return node->isInsertionPoint() && toInsertionPoint(node)->insertionPointType() == InsertionPoint::ContentInsertionPoint;
 }
 
 inline HTMLContentElement* toHTMLContentElement(Node* node)

Modified: trunk/Source/WebCore/html/shadow/HTMLShadowElement.cpp (139399 => 139400)


--- trunk/Source/WebCore/html/shadow/HTMLShadowElement.cpp	2013-01-11 03:18:36 UTC (rev 139399)
+++ trunk/Source/WebCore/html/shadow/HTMLShadowElement.cpp	2013-01-11 04:00:13 UTC (rev 139400)
@@ -54,17 +54,6 @@
 {
 }
 
-const AtomicString& HTMLShadowElement::select() const
-{
-     return nullAtom;
-}
-
-const CSSSelectorList& HTMLShadowElement::emptySelectorList()
-{
-    DEFINE_STATIC_LOCAL(CSSSelectorList, selectorList, (CSSSelectorList()));
-    return selectorList;
-}
-
 ShadowRoot* HTMLShadowElement::olderShadowRoot()
 {
     if (!treeScope()->rootNode()->isShadowRoot())

Modified: trunk/Source/WebCore/html/shadow/HTMLShadowElement.h (139399 => 139400)


--- trunk/Source/WebCore/html/shadow/HTMLShadowElement.h	2013-01-11 03:18:36 UTC (rev 139399)
+++ trunk/Source/WebCore/html/shadow/HTMLShadowElement.h	2013-01-11 04:00:13 UTC (rev 139400)
@@ -42,17 +42,12 @@
 
     virtual ~HTMLShadowElement();
 
-    virtual const AtomicString& select() const;
-    virtual bool isSelectValid() OVERRIDE { return true; }
-    virtual const CSSSelectorList& selectorList() { return emptySelectorList(); }
     virtual Type insertionPointType() const OVERRIDE { return ShadowInsertionPoint; }
 
     ShadowRoot* olderShadowRoot();
 
 private:
     HTMLShadowElement(const QualifiedName&, Document*);
-
-    static const CSSSelectorList& emptySelectorList();
 };
 
 inline bool isHTMLShadowElement(const Node* node)

Modified: trunk/Source/WebCore/html/shadow/InsertionPoint.cpp (139399 => 139400)


--- trunk/Source/WebCore/html/shadow/InsertionPoint.cpp	2013-01-11 03:18:36 UTC (rev 139399)
+++ trunk/Source/WebCore/html/shadow/InsertionPoint.cpp	2013-01-11 04:00:13 UTC (rev 139400)
@@ -191,6 +191,12 @@
     return m_distribution.contains(const_cast<Node*>(node)) || (node->isShadowRoot() && ScopeContentDistribution::assignedTo(toShadowRoot(node)) == this);
 }
 
+const CSSSelectorList& InsertionPoint::emptySelectorList()
+{
+    DEFINE_STATIC_LOCAL(CSSSelectorList, selectorList, (CSSSelectorList()));
+    return selectorList;
+}
+
 InsertionPoint* resolveReprojection(const Node* projectedNode)
 {
     InsertionPoint* insertionPoint = 0;

Modified: trunk/Source/WebCore/html/shadow/InsertionPoint.h (139399 => 139400)


--- trunk/Source/WebCore/html/shadow/InsertionPoint.h	2013-01-11 03:18:36 UTC (rev 139399)
+++ trunk/Source/WebCore/html/shadow/InsertionPoint.h	2013-01-11 04:00:13 UTC (rev 139400)
@@ -48,6 +48,12 @@
         ContentInsertionPoint
     };
 
+    enum MatchType {
+        AlwaysMatches,
+        NeverMatches,
+        HasToMatchSelector
+    };
+
     virtual ~InsertionPoint();
 
     bool hasDistribution() const { return !m_distribution.isEmpty(); }
@@ -58,9 +64,8 @@
 
     PassRefPtr<NodeList> getDistributedNodes() const;
 
-    virtual const AtomicString& select() const = 0;
-    virtual bool isSelectValid() = 0;
-    virtual const CSSSelectorList& selectorList() = 0;
+    virtual MatchType matchTypeFor(Node*) { return AlwaysMatches; }
+    virtual const CSSSelectorList& selectorList() { return emptySelectorList(); }
     virtual Type insertionPointType() const = 0;
     virtual bool canAffectSelector() const { return false; }
 
@@ -81,6 +86,8 @@
     Node* nextTo(const Node* node) const { return m_distribution.nextTo(node); }
     Node* previousTo(const Node* node) const { return m_distribution.previousTo(node); }
 
+    static const CSSSelectorList& emptySelectorList();
+
 protected:
     InsertionPoint(const QualifiedName&, Document*);
     virtual bool rendererIsNeeded(const NodeRenderingContext&) OVERRIDE;

Modified: trunk/Source/WebCore/testing/Internals.cpp (139399 => 139400)


--- trunk/Source/WebCore/testing/Internals.cpp	2013-01-11 03:18:36 UTC (rev 139399)
+++ trunk/Source/WebCore/testing/Internals.cpp	2013-01-11 04:00:13 UTC (rev 139400)
@@ -310,7 +310,7 @@
         return false;
     }
 
-    return toInsertionPoint(insertionPoint)->isSelectValid();
+    return isHTMLContentElement(insertionPoint) && toHTMLContentElement(insertionPoint)->isSelectValid();
 }
 
 Node* Internals::treeScopeRootNode(Node* node, ExceptionCode& ec)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to