1 /* 2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org) 3 * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights 4 * reserved. 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Library General Public License for more details. 15 * 16 * You should have received a copy of the GNU Library General Public License 17 * along with this library; see the file COPYING.LIB. If not, write to 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA. 20 */ 21 22 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_CSS_PARSER_CSS_PARSER_SELECTOR_H_ 23 #define THIRD_PARTY_BLINK_RENDERER_CORE_CSS_PARSER_CSS_PARSER_SELECTOR_H_ 24 25 #include <memory> 26 #include <utility> 27 28 #include "third_party/blink/renderer/core/core_export.h" 29 #include "third_party/blink/renderer/core/css/css_selector.h" 30 31 namespace blink { 32 33 class CSSParserContext; 34 35 class CORE_EXPORT CSSParserSelector { 36 USING_FAST_MALLOC(CSSParserSelector); 37 38 public: 39 CSSParserSelector(); 40 explicit CSSParserSelector(const QualifiedName&, bool is_implicit = false); 41 CSSParserSelector(const CSSParserSelector&) = delete; 42 CSSParserSelector& operator=(const CSSParserSelector&) = delete; 43 ~CSSParserSelector(); 44 ReleaseSelector()45 std::unique_ptr<CSSSelector> ReleaseSelector() { 46 return std::move(selector_); 47 } 48 Relation()49 CSSSelector::RelationType Relation() const { return selector_->Relation(); } 50 void SetValue(const AtomicString& value, bool match_lower_case = false) { 51 selector_->SetValue(value, match_lower_case); 52 } SetAttribute(const QualifiedName & value,CSSSelector::AttributeMatchType match_type)53 void SetAttribute(const QualifiedName& value, 54 CSSSelector::AttributeMatchType match_type) { 55 selector_->SetAttribute(value, match_type); 56 } SetArgument(const AtomicString & value)57 void SetArgument(const AtomicString& value) { selector_->SetArgument(value); } SetPartNames(std::unique_ptr<Vector<AtomicString>> part_names)58 void SetPartNames(std::unique_ptr<Vector<AtomicString>> part_names) { 59 selector_->SetPartNames(std::move(part_names)); 60 } SetNth(int a,int b)61 void SetNth(int a, int b) { selector_->SetNth(a, b); } SetMatch(CSSSelector::MatchType value)62 void SetMatch(CSSSelector::MatchType value) { selector_->SetMatch(value); } SetRelation(CSSSelector::RelationType value)63 void SetRelation(CSSSelector::RelationType value) { 64 selector_->SetRelation(value); 65 } SetForPage()66 void SetForPage() { selector_->SetForPage(); } SetRelationIsAffectedByPseudoContent()67 void SetRelationIsAffectedByPseudoContent() { 68 selector_->SetRelationIsAffectedByPseudoContent(); 69 } RelationIsAffectedByPseudoContent()70 bool RelationIsAffectedByPseudoContent() const { 71 return selector_->RelationIsAffectedByPseudoContent(); 72 } 73 UpdatePseudoType(const AtomicString & value,const CSSParserContext & context,bool has_arguments,CSSParserMode mode)74 void UpdatePseudoType(const AtomicString& value, 75 const CSSParserContext& context, 76 bool has_arguments, 77 CSSParserMode mode) const { 78 selector_->UpdatePseudoType(value, context, has_arguments, mode); 79 } UpdatePseudoPage(const AtomicString & value)80 void UpdatePseudoPage(const AtomicString& value) { 81 selector_->UpdatePseudoPage(value); 82 } 83 84 void AdoptSelectorVector( 85 Vector<std::unique_ptr<CSSParserSelector>>& selector_vector); 86 void SetSelectorList(std::unique_ptr<CSSSelectorList>); 87 void SetAtomics(std::unique_ptr<CSSSelectorList>); 88 89 bool IsHostPseudoSelector() const; 90 Match()91 CSSSelector::MatchType Match() const { return selector_->Match(); } GetPseudoType()92 CSSSelector::PseudoType GetPseudoType() const { 93 return selector_->GetPseudoType(); 94 } IsTreeAbidingPseudoElement()95 bool IsTreeAbidingPseudoElement() const { 96 return selector_->IsTreeAbidingPseudoElement(); 97 } IsAllowedAfterPart()98 bool IsAllowedAfterPart() const { return selector_->IsAllowedAfterPart(); } SelectorList()99 const CSSSelectorList* SelectorList() const { 100 return selector_->SelectorList(); 101 } 102 103 // Some pseudo elements behave as if they have an implicit combinator to their 104 // left even though they are written without one. This method returns the 105 // correct implicit combinator. If no new combinator should be used, it 106 // returns RelationType::kSubSelector. 107 CSSSelector::RelationType GetImplicitShadowCombinatorForMatching() const; 108 bool NeedsImplicitShadowCombinatorForMatching() const; 109 TagHistory()110 CSSParserSelector* TagHistory() const { return tag_history_.get(); } SetTagHistory(std::unique_ptr<CSSParserSelector> selector)111 void SetTagHistory(std::unique_ptr<CSSParserSelector> selector) { 112 tag_history_ = std::move(selector); 113 } ClearTagHistory()114 void ClearTagHistory() { tag_history_.reset(); } 115 void AppendTagHistory(CSSSelector::RelationType, 116 std::unique_ptr<CSSParserSelector>); 117 std::unique_ptr<CSSParserSelector> ReleaseTagHistory(); 118 void PrependTagSelector(const QualifiedName&, bool tag_is_implicit = false); 119 120 private: 121 std::unique_ptr<CSSSelector> selector_; 122 std::unique_ptr<CSSParserSelector> tag_history_; 123 }; 124 125 } // namespace blink 126 127 #endif 128