#include "StylePropertyShorthand.h"
#include "core/css/parser/BisonCSSParser.h"
#include "core/css/CSSValuePool.h"
-#include "core/css/CSSVariableValue.h"
#include "core/css/RuntimeCSSEnabled.h"
#include "core/css/StylePropertySerializer.h"
#include "core/css/StyleSheetContents.h"
-#include "core/css/VariablesIterator.h"
#include "core/frame/UseCounter.h"
#include "wtf/text/StringBuilder.h"
return StylePropertySerializer(*this).getPropertyValue(propertyID);
}
-PassRefPtr<CSSVariablesIterator> MutableStylePropertySet::variablesIterator()
-{
- return VariablesIterator::create(this);
-}
-
PassRefPtr<CSSValue> StylePropertySet::getPropertyCSSValue(CSSPropertyID propertyID) const
{
int foundPropertyIndex = findPropertyIndex(propertyID);
return propertyAt(foundPropertyIndex).value();
}
-unsigned StylePropertySet::variableCount() const
-{
- ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
- unsigned count = 0;
- for (unsigned i = 0; i < propertyCount(); ++i) {
- if (propertyAt(i).id() == CSSPropertyVariable)
- count++;
- }
- return count;
-}
-
-String StylePropertySet::variableValue(const AtomicString& name) const
-{
- ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
- size_t index = findVariableIndex(name);
- if (index == kNotFound)
- return String();
- return toCSSVariableValue(propertyAt(index).value())->value();
-}
-
bool MutableStylePropertySet::removeShorthandProperty(CSSPropertyID propertyID)
{
StylePropertyShorthand shorthand = shorthandForProperty(propertyID);
return indexOfShorthandForLonghand(prefixedShorthand, shorthands);
}
-bool MutableStylePropertySet::setVariableValue(const AtomicString& name, const String& value, bool important)
-{
- ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
- if (value.isEmpty())
- return removeVariable(name);
-
- size_t index = findVariableIndex(name);
- if (index != kNotFound) {
- const CSSValue* cssValue = m_propertyVector.at(index).value();
- if (toCSSVariableValue(cssValue)->value() == value)
- return false;
- }
-
- CSSProperty property(CSSPropertyVariable, CSSVariableValue::create(name, value), important);
- if (index == kNotFound) {
- m_propertyVector.append(property);
- return true;
- }
- m_propertyVector.at(index) = property;
- return false;
-}
-
void MutableStylePropertySet::appendPrefixingVariantProperty(const CSSProperty& property)
{
m_propertyVector.append(property);
{
m_propertyVector.clear();
- CSSParserContext context(cssParserMode());
+ CSSParserContext context(cssParserMode(), UseCounter::getFrom(contextStyleSheet));
if (contextStyleSheet) {
context = contextStyleSheet->parserContext();
context.setMode(cssParserMode());
}
- BisonCSSParser parser(context, UseCounter::getFrom(contextStyleSheet));
+ BisonCSSParser parser(context);
parser.parseDeclaration(this, styleDeclaration, 0, contextStyleSheet);
}
CSSPropertyPageBreakAfter,
CSSPropertyPageBreakBefore,
CSSPropertyPageBreakInside,
- CSSPropertyWebkitRegionBreakAfter,
- CSSPropertyWebkitRegionBreakBefore,
- CSSPropertyWebkitRegionBreakInside,
CSSPropertyTextAlign,
CSSPropertyTextAlignLast,
CSSPropertyTextIndent,
return -1;
}
-size_t StylePropertySet::findVariableIndex(const AtomicString& name) const
-{
- ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
- for (int i = propertyCount() - 1; i >= 0; --i) {
- const PropertyReference& property = propertyAt(i);
- if (property.id() == CSSPropertyVariable && toCSSVariableValue(property.value())->name() == name)
- return i;
- }
- return kNotFound;
-}
-
CSSProperty* MutableStylePropertySet::findCSSPropertyWithID(CSSPropertyID propertyID)
{
int foundPropertyIndex = findPropertyIndex(propertyID);
removeProperty(propertiesToRemove[i]);
}
-bool MutableStylePropertySet::removeVariable(const AtomicString& name)
-{
- ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
- size_t index = findVariableIndex(name);
- if (index == kNotFound)
- return false;
- m_propertyVector.remove(index);
- return true;
-}
-
-bool MutableStylePropertySet::clearVariables()
-{
- ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
- CSSPropertyID variablesId = CSSPropertyVariable;
- return removePropertiesInSet(&variablesId, 1);
-}
-
PassRefPtr<MutableStylePropertySet> StylePropertySet::mutableCopy() const
{
return adoptRef(new MutableStylePropertySet(*this));
String StylePropertySet::PropertyReference::cssName() const
{
- if (id() == CSSPropertyVariable) {
- if (!propertyValue()->isVariableValue())
- return emptyString(); // Should not happen, but if it does, avoid a bad cast.
- return "var-" + toCSSVariableValue(propertyValue())->name();
- }
return getPropertyNameString(id());
}