| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Neither the name of Google Inc. nor the names of its | |
| 11 * contributors may be used to endorse or promote products derived from | |
| 12 * this software without specific prior written permission. | |
| 13 * | |
| 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 25 */ | |
| 26 | |
| 27 #include "sky/engine/core/html/HTMLContentElement.h" | |
| 28 | |
| 29 #include "gen/sky/core/HTMLNames.h" | |
| 30 #include "gen/sky/platform/RuntimeEnabledFeatures.h" | |
| 31 #include "sky/engine/core/css/SelectorChecker.h" | |
| 32 #include "sky/engine/core/css/parser/BisonCSSParser.h" | |
| 33 #include "sky/engine/core/dom/QualifiedName.h" | |
| 34 #include "sky/engine/core/dom/shadow/ElementShadow.h" | |
| 35 #include "sky/engine/core/dom/shadow/ShadowRoot.h" | |
| 36 | |
| 37 namespace blink { | |
| 38 | |
| 39 inline HTMLContentElement::HTMLContentElement(Document& document) | |
| 40 : InsertionPoint(HTMLNames::contentTag, document) | |
| 41 , m_shouldParseSelect(false) | |
| 42 , m_isValidSelector(true) | |
| 43 { | |
| 44 } | |
| 45 | |
| 46 DEFINE_NODE_FACTORY(HTMLContentElement) | |
| 47 | |
| 48 HTMLContentElement::~HTMLContentElement() | |
| 49 { | |
| 50 } | |
| 51 | |
| 52 void HTMLContentElement::parseSelect() | |
| 53 { | |
| 54 ASSERT(m_shouldParseSelect); | |
| 55 | |
| 56 CSSParserContext context(document()); | |
| 57 BisonCSSParser parser(context); | |
| 58 parser.parseSelector(m_select, m_selectorList); | |
| 59 m_shouldParseSelect = false; | |
| 60 m_isValidSelector = validateSelect(); | |
| 61 if (!m_isValidSelector) { | |
| 62 CSSSelectorList emptyList; | |
| 63 m_selectorList.adopt(emptyList); | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 void HTMLContentElement::parseAttribute(const QualifiedName& name, const AtomicS
tring& value) | |
| 68 { | |
| 69 if (name == HTMLNames::selectAttr) { | |
| 70 if (ShadowRoot* root = containingShadowRoot()) | |
| 71 root->owner()->willAffectSelector(); | |
| 72 m_shouldParseSelect = true; | |
| 73 m_select = value; | |
| 74 } else { | |
| 75 InsertionPoint::parseAttribute(name, value); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 static inline bool includesDisallowedPseudoClass(const CSSSelector& selector) | |
| 80 { | |
| 81 return selector.match() == CSSSelector::PseudoClass; | |
| 82 } | |
| 83 | |
| 84 bool HTMLContentElement::validateSelect() const | |
| 85 { | |
| 86 ASSERT(!m_shouldParseSelect); | |
| 87 | |
| 88 if (m_select.isNull() || m_select.isEmpty()) | |
| 89 return true; | |
| 90 | |
| 91 if (!m_selectorList.isValid()) | |
| 92 return false; | |
| 93 | |
| 94 // FIXME(sky): Should we allow pseudo classes in select? | |
| 95 bool allowAnyPseudoClasses = false; | |
| 96 | |
| 97 for (const CSSSelector* selector = m_selectorList.first(); selector; selecto
r = m_selectorList.next(*selector)) { | |
| 98 if (!selector->isCompound()) | |
| 99 return false; | |
| 100 if (allowAnyPseudoClasses) | |
| 101 continue; | |
| 102 for (const CSSSelector* subSelector = selector; subSelector; subSelector
= subSelector->tagHistory()) { | |
| 103 if (includesDisallowedPseudoClass(*subSelector)) | |
| 104 return false; | |
| 105 } | |
| 106 } | |
| 107 return true; | |
| 108 } | |
| 109 | |
| 110 bool HTMLContentElement::matchSelector(const Vector<RawPtr<Node>, 32>& siblings,
int nth) const | |
| 111 { | |
| 112 for (const CSSSelector* selector = selectorList().first(); selector; selecto
r = CSSSelectorList::next(*selector)) { | |
| 113 SelectorChecker checker(toElement(*siblings[nth])); | |
| 114 if (checker.match(*selector)) | |
| 115 return true; | |
| 116 } | |
| 117 return false; | |
| 118 } | |
| 119 | |
| 120 } | |
| OLD | NEW |