WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
bug-101543-20121108163918.patch (text/plain), 16.21 KB, created by
Shinya Kawanaka
on 2012-11-07 23:41:08 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Shinya Kawanaka
Created:
2012-11-07 23:41:08 PST
Size:
16.21 KB
patch
obsolete
>Subversion Revision: 133839 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 78acb0cad9f6fbf19472d27e59a6b09b294d6ea6..58382d17952445675518593ccbb994890fbe2f69 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,50 @@ >+2012-11-07 Shinya Kawanaka <shinyak@chromium.org> >+ >+ HTMLContentElement should preserve parsed CSSSelectorList >+ https://bugs.webkit.org/show_bug.cgi?id=101543 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ We would like to preserve CSSSelectorList for select attribute of HTMLContentElement. >+ >+ Before, we parsed and validated select attribute every time distribution happens. If we preserve the parsed >+ CSSSelectorList, we can reduce distribution time. >+ >+ This is also a prepration patch for Bug 101180. It also needs the parsed CSSSelectorList. We don't want to >+ parse and validate it again. >+ >+ No new tests, covered by exising tests. >+ >+ * html/shadow/ContentSelectorQuery.cpp: >+ (WebCore::ContentSelectorQuery::ContentSelectorQuery): We don't parse select attribute here anymore. >+ if it's already parsed. >+ (WebCore::ContentSelectorQuery::matches): >+ * html/shadow/ContentSelectorQuery.h: >+ (ContentSelectorQuery): >+ * html/shadow/HTMLContentElement.cpp: >+ (WebCore::HTMLContentElement::HTMLContentElement): >+ (WebCore::HTMLContentElement::isSelectValid): >+ (WebCore::HTMLContentElement::ensureSelectParsed): If we don't have parsed the current select attribute, >+ we parse and validate it. >+ (WebCore::HTMLContentElement::parseAttribute): When select attribute is changed, we have to have a flag enabled >+ to parse select attrite again. >+ (WebCore::validateSubSelector): Moved from ContentSelectorQuery. >+ (WebCore): >+ (WebCore::validateSelector): Moved from ContentSelectorQuery. >+ (WebCore::HTMLContentElement::validateSelect): >+ * html/shadow/HTMLContentElement.h: >+ (HTMLContentElement): >+ (WebCore::HTMLContentElement::setSelect): >+ (WebCore): >+ (WebCore::HTMLContentElement::selectorList): >+ * html/shadow/HTMLShadowElement.cpp: >+ (WebCore): >+ * html/shadow/HTMLShadowElement.h: >+ (HTMLShadowElement): >+ (WebCore::HTMLShadowElement::selectorList): >+ * html/shadow/InsertionPoint.h: >+ (InsertionPoint): >+ > 2012-11-07 Adam Barth <abarth@webkit.org> > > [V8] IntrusiveDOMWrapperMap should be usable for more than just Nodes >diff --git a/Source/WebCore/html/shadow/ContentSelectorQuery.cpp b/Source/WebCore/html/shadow/ContentSelectorQuery.cpp >index 0a6ec32eee5fd00b8e95b433eddf949736b14eea..dbe5a8e9562f68fa6a07f3c33970fa85f3b86bb4 100644 >--- a/Source/WebCore/html/shadow/ContentSelectorQuery.cpp >+++ b/Source/WebCore/html/shadow/ContentSelectorQuery.cpp >@@ -27,7 +27,6 @@ > #include "config.h" > #include "ContentSelectorQuery.h" > >-#include "CSSParser.h" > #include "CSSSelectorList.h" > #include "InsertionPoint.h" > #include "SelectorChecker.h" >@@ -65,26 +64,12 @@ bool ContentSelectorDataList::matches(const ContentSelectorChecker& selectorChec > return false; > } > >-ContentSelectorQuery::ContentSelectorQuery(const InsertionPoint* insertionPoint) >+ContentSelectorQuery::ContentSelectorQuery(InsertionPoint* insertionPoint) > : m_insertionPoint(insertionPoint) > , m_selectorChecker(insertionPoint->document(), !insertionPoint->document()->inQuirksMode()) > { >- if (insertionPoint->select().isNull() || insertionPoint->select().isEmpty()) { >- m_isValidSelector = true; >- return; >- } >- >- CSSParser parser(insertionPoint->document()); >- parser.parseSelector(insertionPoint->select(), m_selectorList); >- >- m_isValidSelector = ContentSelectorQuery::validateSelectorList(); >- if (m_isValidSelector) >- m_selectors.initialize(m_selectorList); >-} >- >-bool ContentSelectorQuery::isValidSelector() const >-{ >- return m_isValidSelector; >+ if (insertionPoint->isSelectValid()) >+ m_selectors.initialize(insertionPoint->selectorList()); > } > > bool ContentSelectorQuery::matches(const Vector<RefPtr<Node> >& siblings, int nth) const >@@ -95,7 +80,7 @@ bool ContentSelectorQuery::matches(const Vector<RefPtr<Node> >& siblings, int nt > if (m_insertionPoint->select().isNull() || m_insertionPoint->select().isEmpty()) > return true; > >- if (!m_isValidSelector) >+ if (!m_insertionPoint->isSelectValid()) > return false; > > if (!node->isElementNode()) >@@ -104,85 +89,4 @@ bool ContentSelectorQuery::matches(const Vector<RefPtr<Node> >& siblings, int nt > return m_selectors.matches(m_selectorChecker, siblings, nth); > } > >-static bool validateSubSelector(CSSSelector* selector) >-{ >- switch (selector->m_match) { >- case CSSSelector::None: >- case CSSSelector::Id: >- case CSSSelector::Class: >- case CSSSelector::Exact: >- case CSSSelector::Set: >- case CSSSelector::List: >- case CSSSelector::Hyphen: >- case CSSSelector::Contain: >- case CSSSelector::Begin: >- case CSSSelector::End: >- return true; >- case CSSSelector::PseudoElement: >- return false; >- case CSSSelector::PagePseudoClass: >- case CSSSelector::PseudoClass: >- break; >- } >- >- switch (selector->pseudoType()) { >- case CSSSelector::PseudoEmpty: >- case CSSSelector::PseudoLink: >- case CSSSelector::PseudoVisited: >- case CSSSelector::PseudoTarget: >- case CSSSelector::PseudoEnabled: >- case CSSSelector::PseudoDisabled: >- case CSSSelector::PseudoChecked: >- case CSSSelector::PseudoIndeterminate: >- case CSSSelector::PseudoNthChild: >- case CSSSelector::PseudoNthLastChild: >- case CSSSelector::PseudoNthOfType: >- case CSSSelector::PseudoNthLastOfType: >- case CSSSelector::PseudoFirstChild: >- case CSSSelector::PseudoLastChild: >- case CSSSelector::PseudoFirstOfType: >- case CSSSelector::PseudoLastOfType: >- case CSSSelector::PseudoOnlyOfType: >- return true; >- default: >- return false; >- } >-} >- >-static bool validateSelector(CSSSelector* selector) >-{ >- ASSERT(selector); >- >- if (!validateSubSelector(selector)) >- return false; >- >- CSSSelector* prevSubSelector = selector; >- CSSSelector* subSelector = selector->tagHistory(); >- >- while (subSelector) { >- if (prevSubSelector->relation() != CSSSelector::SubSelector) >- return false; >- if (!validateSubSelector(subSelector)) >- return false; >- >- prevSubSelector = subSelector; >- subSelector = subSelector->tagHistory(); >- } >- >- return true; >-} >- >-bool ContentSelectorQuery::validateSelectorList() >-{ >- if (!m_selectorList.first()) >- return false; >- >- for (CSSSelector* selector = m_selectorList.first(); selector; selector = m_selectorList.next(selector)) { >- if (!validateSelector(selector)) >- return false; >- } >- >- return true; >-} >- > } >diff --git a/Source/WebCore/html/shadow/ContentSelectorQuery.h b/Source/WebCore/html/shadow/ContentSelectorQuery.h >index 2c710a5852e92d76882c7c20750bfd26da2aa03b..78a082454c9d12f2b0f3c5504a8b90abe9e1ebe6 100644 >--- a/Source/WebCore/html/shadow/ContentSelectorQuery.h >+++ b/Source/WebCore/html/shadow/ContentSelectorQuery.h >@@ -64,18 +64,14 @@ private: > class ContentSelectorQuery { > WTF_MAKE_NONCOPYABLE(ContentSelectorQuery); > public: >- explicit ContentSelectorQuery(const InsertionPoint*); >+ explicit ContentSelectorQuery(InsertionPoint*); > >- bool isValidSelector() const; > bool matches(const Vector<RefPtr<Node> >& siblings, int nthNode) const; > private: >- bool validateSelectorList(); > >- const InsertionPoint* m_insertionPoint; >+ InsertionPoint* m_insertionPoint; > ContentSelectorDataList m_selectors; >- CSSSelectorList m_selectorList; > ContentSelectorChecker m_selectorChecker; >- bool m_isValidSelector; > }; > > } >diff --git a/Source/WebCore/html/shadow/HTMLContentElement.cpp b/Source/WebCore/html/shadow/HTMLContentElement.cpp >index 5040e9eb8d6062756eeaf9be44374d66a5e125e0..27cab5b1f79702225440474f727f0af945eae4a0 100644 >--- a/Source/WebCore/html/shadow/HTMLContentElement.cpp >+++ b/Source/WebCore/html/shadow/HTMLContentElement.cpp >@@ -27,6 +27,7 @@ > #include "config.h" > #include "HTMLContentElement.h" > >+#include "CSSParser.h" > #include "ContentDistributor.h" > #include "ContentSelectorQuery.h" > #include "ContextFeatures.h" >@@ -65,6 +66,8 @@ PassRefPtr<HTMLContentElement> HTMLContentElement::create(const QualifiedName& t > HTMLContentElement::HTMLContentElement(const QualifiedName& name, Document* document) > : InsertionPoint(name, document) > , m_registeredWithShadowRoot(false) >+ , m_shouldParseSelectorList(false) >+ , m_isValidSelector(true) > { > } > >@@ -77,15 +80,23 @@ const AtomicString& HTMLContentElement::select() const > return getAttribute(selectAttr); > } > >-bool HTMLContentElement::isSelectValid() const >+bool HTMLContentElement::isSelectValid() > { >- ContentSelectorQuery query(this); >- return query.isValidSelector(); >+ ensureSelectParsed(); >+ return m_isValidSelector; > } > >-void HTMLContentElement::setSelect(const AtomicString& selectValue) >+inline void HTMLContentElement::ensureSelectParsed() > { >- setAttribute(selectAttr, selectValue); >+ if (!m_shouldParseSelectorList) >+ return; >+ >+ CSSParser parser(document()); >+ parser.parseSelector(select(), m_selectorList); >+ m_shouldParseSelectorList = false; >+ m_isValidSelector = validateSelect(); >+ if (!m_isValidSelector) >+ m_selectorList = CSSSelectorList(); > } > > void HTMLContentElement::parseAttribute(const Attribute& attribute) >@@ -93,6 +104,7 @@ void HTMLContentElement::parseAttribute(const Attribute& attribute) > if (attribute.name() == selectAttr) { > if (ShadowRoot* root = shadowRoot()) > root->owner()->invalidateDistribution(); >+ m_shouldParseSelectorList = true; > } else > InsertionPoint::parseAttribute(attribute); > } >@@ -122,4 +134,91 @@ void HTMLContentElement::removedFrom(ContainerNode* insertionPoint) > InsertionPoint::removedFrom(insertionPoint); > } > >+static bool validateSubSelector(CSSSelector* selector) >+{ >+ switch (selector->m_match) { >+ case CSSSelector::None: >+ case CSSSelector::Id: >+ case CSSSelector::Class: >+ case CSSSelector::Exact: >+ case CSSSelector::Set: >+ case CSSSelector::List: >+ case CSSSelector::Hyphen: >+ case CSSSelector::Contain: >+ case CSSSelector::Begin: >+ case CSSSelector::End: >+ return true; >+ case CSSSelector::PseudoElement: >+ return false; >+ case CSSSelector::PagePseudoClass: >+ case CSSSelector::PseudoClass: >+ break; >+ } >+ >+ switch (selector->pseudoType()) { >+ case CSSSelector::PseudoEmpty: >+ case CSSSelector::PseudoLink: >+ case CSSSelector::PseudoVisited: >+ case CSSSelector::PseudoTarget: >+ case CSSSelector::PseudoEnabled: >+ case CSSSelector::PseudoDisabled: >+ case CSSSelector::PseudoChecked: >+ case CSSSelector::PseudoIndeterminate: >+ case CSSSelector::PseudoNthChild: >+ case CSSSelector::PseudoNthLastChild: >+ case CSSSelector::PseudoNthOfType: >+ case CSSSelector::PseudoNthLastOfType: >+ case CSSSelector::PseudoFirstChild: >+ case CSSSelector::PseudoLastChild: >+ case CSSSelector::PseudoFirstOfType: >+ case CSSSelector::PseudoLastOfType: >+ case CSSSelector::PseudoOnlyOfType: >+ return true; >+ default: >+ return false; >+ } >+} >+ >+static bool validateSelector(CSSSelector* selector) >+{ >+ ASSERT(selector); >+ >+ if (!validateSubSelector(selector)) >+ return false; >+ >+ CSSSelector* prevSubSelector = selector; >+ CSSSelector* subSelector = selector->tagHistory(); >+ >+ while (subSelector) { >+ if (prevSubSelector->relation() != CSSSelector::SubSelector) >+ return false; >+ if (!validateSubSelector(subSelector)) >+ return false; >+ >+ prevSubSelector = subSelector; >+ subSelector = subSelector->tagHistory(); >+ } >+ >+ return true; >+} >+ >+bool HTMLContentElement::validateSelect() const >+{ >+ ASSERT(!m_shouldParseSelectorList); >+ >+ if (select().isNull() || select().isEmpty()) >+ return true; >+ >+ if (!m_selectorList.first()) >+ return false; >+ >+ for (CSSSelector* selector = m_selectorList.first(); selector; selector = m_selectorList.next(selector)) { >+ if (!validateSelector(selector)) >+ return false; >+ } >+ >+ return true; >+} >+ >+ > } >diff --git a/Source/WebCore/html/shadow/HTMLContentElement.h b/Source/WebCore/html/shadow/HTMLContentElement.h >index 2a3a32cea55929e87ce71bac73b7864c790f0ff6..04254e12b223bc03903ed342cbaebf17de9f2016 100644 >--- a/Source/WebCore/html/shadow/HTMLContentElement.h >+++ b/Source/WebCore/html/shadow/HTMLContentElement.h >@@ -31,6 +31,7 @@ > #ifndef HTMLContentElement_h > #define HTMLContentElement_h > >+#include "CSSSelectorList.h" > #include "InsertionPoint.h" > #include <wtf/Forward.h> > >@@ -44,9 +45,10 @@ public: > > virtual ~HTMLContentElement(); > >- const AtomicString& select() const; > void setSelect(const AtomicString&); >- virtual bool isSelectValid() const; >+ virtual const AtomicString& select() const; >+ virtual bool isSelectValid(); >+ virtual const CSSSelectorList& selectorList(); > > protected: > HTMLContentElement(const QualifiedName&, Document*); >@@ -56,10 +58,28 @@ protected: > > private: > virtual void parseAttribute(const Attribute&) OVERRIDE; >+ void ensureSelectParsed(); >+ bool validateSelect() const; > > bool m_registeredWithShadowRoot; >+ >+ bool m_shouldParseSelectorList; >+ bool m_isValidSelector; >+ CSSSelectorList m_selectorList; > }; > >+inline void HTMLContentElement::setSelect(const AtomicString& selectValue) >+{ >+ setAttribute(HTMLNames::selectAttr, selectValue); >+ m_shouldParseSelectorList = true; >+} >+ >+inline const CSSSelectorList& HTMLContentElement::selectorList() >+{ >+ ensureSelectParsed(); >+ return m_selectorList; >+} >+ > inline bool isHTMLContentElement(const Node* node) > { > ASSERT(node); >diff --git a/Source/WebCore/html/shadow/HTMLShadowElement.cpp b/Source/WebCore/html/shadow/HTMLShadowElement.cpp >index 7d7e41529fbdf16f130408ee232f198b82835264..7134f170fc45cab8e8923e5ebe368dbd0c4c9b8a 100644 >--- a/Source/WebCore/html/shadow/HTMLShadowElement.cpp >+++ b/Source/WebCore/html/shadow/HTMLShadowElement.cpp >@@ -39,6 +39,8 @@ namespace WebCore { > > class Document; > >+CSSSelectorList HTMLShadowElement::emptySelectorList = CSSSelectorList(); >+ > inline HTMLShadowElement::HTMLShadowElement(const QualifiedName& tagName, Document* document) > : InsertionPoint(tagName, document) > , m_registeredWithShadowRoot(false) >diff --git a/Source/WebCore/html/shadow/HTMLShadowElement.h b/Source/WebCore/html/shadow/HTMLShadowElement.h >index bac2b92b57961b23dfcc2e32e1f55b2d57e32645..71c94eaecd3e6d33790eadf74be8bda3f8e30ad7 100644 >--- a/Source/WebCore/html/shadow/HTMLShadowElement.h >+++ b/Source/WebCore/html/shadow/HTMLShadowElement.h >@@ -42,8 +42,9 @@ public: > > virtual ~HTMLShadowElement(); > >- const AtomicString& select() const; >- bool isSelectValid() const OVERRIDE { return true; } >+ virtual const AtomicString& select() const; >+ virtual bool isSelectValid() OVERRIDE { return true; } >+ virtual const CSSSelectorList& selectorList() { return emptySelectorList; } > > protected: > virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE; >@@ -52,6 +53,8 @@ protected: > private: > HTMLShadowElement(const QualifiedName&, Document*); > >+ static CSSSelectorList emptySelectorList; >+ > bool m_registeredWithShadowRoot; > }; > >diff --git a/Source/WebCore/html/shadow/InsertionPoint.h b/Source/WebCore/html/shadow/InsertionPoint.h >index 243a08c18a3461030395d9a5ba7d20559b6711a9..23dad8dca7081231821f97d8bf304d77333276f7 100644 >--- a/Source/WebCore/html/shadow/InsertionPoint.h >+++ b/Source/WebCore/html/shadow/InsertionPoint.h >@@ -31,6 +31,7 @@ > #ifndef InsertionPoint_h > #define InsertionPoint_h > >+#include "CSSSelectorList.h" > #include "ContentDistributor.h" > #include "ElementShadow.h" > #include "HTMLElement.h" >@@ -53,7 +54,8 @@ public: > PassRefPtr<NodeList> getDistributedNodes() const; > > virtual const AtomicString& select() const = 0; >- virtual bool isSelectValid() const = 0; >+ virtual bool isSelectValid() = 0; >+ virtual const CSSSelectorList& selectorList() = 0; > > bool resetStyleInheritance() const; > void setResetStyleInheritance(bool);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 101543
:
172939
|
172950
|
172959
|
173168