Changeset 276418 in webkit for trunk/Source/WebCore/css/CSSCounterStyleRule.cpp
- Timestamp:
- Apr 21, 2021, 8:28:03 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/css/CSSCounterStyleRule.cpp
r276380 r276418 27 27 #include "CSSCounterStyleRule.h" 28 28 29 #include "CSSPropertyParser.h"30 #include "CSSStyleSheet.h"31 #include "CSSTokenizer.h"32 #include "Pair.h"33 #include <wtf/text/StringBuilder.h>34 35 29 namespace WebCore { 36 30 … … 45 39 { 46 40 return adoptRef(*new StyleRuleCounterStyle(name, WTFMove(properties))); 47 }48 49 static CounterStyleSystem toCounterStyleSystemEnum(RefPtr<CSSValue> system)50 {51 if (!system || !system->isPrimitiveValue())52 return CounterStyleSystem::Symbolic;53 54 auto& primitiveSystemValue = downcast<CSSPrimitiveValue>(*system);55 ASSERT(primitiveSystemValue.isValueID() || primitiveSystemValue.isPair());56 CSSValueID systemKeyword = CSSValueInvalid;57 if (primitiveSystemValue.isValueID())58 systemKeyword = primitiveSystemValue.valueID();59 else if (auto* pair = primitiveSystemValue.pairValue()) {60 // This value must be `fixed` or `extends`, both of which can or must have an additional component.61 auto firstValue = pair->first();62 ASSERT(firstValue && firstValue->isValueID());63 if (firstValue)64 systemKeyword = firstValue->valueID();65 }66 67 switch (systemKeyword) {68 case CSSValueCyclic:69 return CounterStyleSystem::Cyclic;70 case CSSValueFixed:71 return CounterStyleSystem::Fixed;72 case CSSValueSymbolic:73 return CounterStyleSystem::Symbolic;74 case CSSValueAlphabetic:75 return CounterStyleSystem::Alphabetic;76 case CSSValueNumeric:77 return CounterStyleSystem::Numeric;78 case CSSValueAdditive:79 return CounterStyleSystem::Additive;80 case CSSValueExtends:81 return CounterStyleSystem::Extends;82 default:83 ASSERT_NOT_REACHED();84 return CounterStyleSystem::Symbolic;85 }86 }87 88 static bool symbolsValidForSystem(CounterStyleSystem system, RefPtr<CSSValue> symbols, RefPtr<CSSValue> additiveSymbols)89 {90 switch (system) {91 case CounterStyleSystem::Cyclic:92 case CounterStyleSystem::Fixed:93 case CounterStyleSystem::Symbolic:94 return symbols && symbols->isValueList() && downcast<CSSValueList>(*symbols).length();95 case CounterStyleSystem::Alphabetic:96 case CounterStyleSystem::Numeric:97 return symbols && symbols->isValueList() && downcast<CSSValueList>(*symbols).length() >= 2u;98 case CounterStyleSystem::Additive:99 return additiveSymbols && additiveSymbols->isValueList() && downcast<CSSValueList>(*additiveSymbols).length();100 case CounterStyleSystem::Extends:101 return !symbols && !additiveSymbols;102 default:103 ASSERT_NOT_REACHED();104 return false;105 }106 }107 108 bool StyleRuleCounterStyle::newValueInvalidOrEqual(CSSPropertyID propertyID, const RefPtr<CSSValue> newValue) const109 {110 auto currentValue = m_properties->getPropertyCSSValue(propertyID);111 if (compareCSSValuePtr(currentValue, newValue))112 return true;113 114 RefPtr<CSSValue> symbols;115 RefPtr<CSSValue> additiveSymbols;116 switch (propertyID) {117 case CSSPropertySystem:118 // If the attribute being set is `system`, and the new value would change the algorithm used, do nothing119 // and abort these steps.120 // (It's okay to change an aspect of the algorithm, like the first symbol value of a `fixed` system.)121 return toCounterStyleSystemEnum(currentValue) != toCounterStyleSystemEnum(newValue);122 case CSSPropertySymbols:123 symbols = newValue;124 additiveSymbols = m_properties->getPropertyCSSValue(CSSPropertyAdditiveSymbols);125 break;126 case CSSPropertyAdditiveSymbols:127 symbols = m_properties->getPropertyCSSValue(CSSPropertySymbols);128 additiveSymbols = newValue;129 break;130 default:131 return false;132 }133 auto system = m_properties->getPropertyCSSValue(CSSPropertySystem);134 return symbolsValidForSystem(toCounterStyleSystemEnum(system), symbols, additiveSymbols);135 41 } 136 42 … … 159 65 String CSSCounterStyleRule::cssText() const 160 66 { 161 String systemText = system(); 162 const char* systemPrefix = systemText.isEmpty() ? "" : " system: "; 163 const char* systemSuffix = systemText.isEmpty() ? "" : ";"; 164 165 String symbolsText = symbols(); 166 const char* symbolsPrefix = symbolsText.isEmpty() ? "" : " symbols: "; 167 const char* symbolsSuffix = symbolsText.isEmpty() ? "" : ";"; 168 169 String additiveSymbolsText = additiveSymbols(); 170 const char* additiveSymbolsPrefix = additiveSymbolsText.isEmpty() ? "" : " additive-symbols: "; 171 const char* additiveSymbolsSuffix = additiveSymbolsText.isEmpty() ? "" : ";"; 172 173 String negativeText = negative(); 174 const char* negativePrefix = negativeText.isEmpty() ? "" : " negative: "; 175 const char* negativeSuffix = negativeText.isEmpty() ? "" : ";"; 176 177 String prefixText = prefix(); 178 const char* prefixTextPrefix = prefixText.isEmpty() ? "" : " prefix: "; 179 const char* prefixTextSuffix = prefixText.isEmpty() ? "" : ";"; 180 181 String suffixText = suffix(); 182 const char* suffixTextPrefix = suffixText.isEmpty() ? "" : " suffix: "; 183 const char* suffixTextSuffix = suffixText.isEmpty() ? "" : ";"; 184 185 String padText = pad(); 186 const char* padPrefix = padText.isEmpty() ? "" : " pad: "; 187 const char* padSuffix = padText.isEmpty() ? "" : ";"; 188 189 String rangeText = range(); 190 const char* rangePrefix = rangeText.isEmpty() ? "" : " range: "; 191 const char* rangeSuffix = rangeText.isEmpty() ? "" : ";"; 192 193 String fallbackText = fallback(); 194 const char* fallbackPrefix = fallbackText.isEmpty() ? "" : " fallback: "; 195 const char* fallbackSuffix = fallbackText.isEmpty() ? "" : ";"; 196 197 String speakAsText = speakAs(); 198 const char* speakAsPrefix = speakAsText.isEmpty() ? "" : " speak-as: "; 199 const char* speakAsSuffix = speakAsText.isEmpty() ? "" : ";"; 200 201 return makeString("@counter-style ", name(), " {", systemPrefix, systemText, systemSuffix, symbolsPrefix, symbolsText, symbolsSuffix, additiveSymbolsPrefix, additiveSymbolsText, additiveSymbolsSuffix, negativePrefix, negativeText, negativeSuffix, prefixTextPrefix, prefixText, prefixTextSuffix, suffixTextPrefix, suffixText, suffixTextSuffix, padPrefix, padText, padSuffix, rangePrefix, rangeText, rangeSuffix, fallbackPrefix, fallbackText, fallbackSuffix, speakAsPrefix, speakAsText, speakAsSuffix, " }"); 67 // FIXME: Implement this function when we parse @counter-style descriptors. 68 return emptyString(); 202 69 } 203 70 … … 207 74 } 208 75 209 // https://drafts.csswg.org/css-counter-styles-3/#dom-csscounterstylerule-name210 void CSSCounterStyleRule::setName(const String& text)211 {212 auto tokens = CSSTokenizer(text).tokenRange();213 auto name = CSSPropertyParserHelpers::consumeCounterStyleNameInPrelude(tokens);214 if (name.isNull() || name == m_counterStyleRule->name())215 return;216 217 CSSStyleSheet::RuleMutationScope mutationScope(this);218 m_counterStyleRule->setName(name);219 }220 221 void CSSCounterStyleRule::setterInternal(CSSPropertyID propertyID, const String& valueText)222 {223 auto tokens = CSSTokenizer(valueText).tokenRange();224 auto newValue = CSSPropertyParser::parseCounterStyleDescriptor(propertyID, tokens, parserContext());225 if (m_counterStyleRule->newValueInvalidOrEqual(propertyID, newValue))226 return;227 228 CSSStyleSheet::RuleMutationScope mutationScope(this);229 m_counterStyleRule->mutableProperties().setProperty(propertyID, WTFMove(newValue));230 }231 232 void CSSCounterStyleRule::setSystem(const String& text)233 {234 setterInternal(CSSPropertySystem, text);235 }236 237 void CSSCounterStyleRule::setNegative(const String& text)238 {239 setterInternal(CSSPropertyNegative, text);240 }241 242 void CSSCounterStyleRule::setPrefix(const String& text)243 {244 setterInternal(CSSPropertyPrefix, text);245 }246 247 void CSSCounterStyleRule::setSuffix(const String& text)248 {249 setterInternal(CSSPropertySuffix, text);250 }251 252 void CSSCounterStyleRule::setRange(const String& text)253 {254 setterInternal(CSSPropertyRange, text);255 }256 257 void CSSCounterStyleRule::setPad(const String& text)258 {259 setterInternal(CSSPropertyPad, text);260 }261 262 void CSSCounterStyleRule::setFallback(const String& text)263 {264 setterInternal(CSSPropertyFallback, text);265 }266 267 void CSSCounterStyleRule::setSymbols(const String& text)268 {269 setterInternal(CSSPropertySymbols, text);270 }271 272 void CSSCounterStyleRule::setAdditiveSymbols(const String& text)273 {274 setterInternal(CSSPropertyAdditiveSymbols, text);275 }276 277 void CSSCounterStyleRule::setSpeakAs(const String& text)278 {279 setterInternal(CSSPropertySpeakAs, text);280 }281 282 76 } // namespace WebCore
Note:
See TracChangeset
for help on using the changeset viewer.