#include "config.h"
#include "core/css/StylePropertySerializer.h"
-#include "CSSValueKeywords.h"
-#include "StylePropertyShorthand.h"
+#include "core/CSSValueKeywords.h"
+#include "core/StylePropertyShorthand.h"
#include "core/css/RuntimeCSSEnabled.h"
#include "wtf/BitArray.h"
#include "wtf/text/StringBuilder.h"
-using namespace std;
-
-namespace WebCore {
+namespace blink {
static bool isInitialOrInherit(const String& value)
{
case CSSPropertyFontFamily:
case CSSPropertyLineHeight:
case CSSPropertyFontSize:
+ case CSSPropertyFontStretch:
case CSSPropertyFontStyle:
case CSSPropertyFontVariant:
case CSSPropertyFontWeight:
} else
value = property.value()->cssText();
- if (value == "initial" && !CSSProperty::isInheritedProperty(propertyID))
+ if (value == "initial" && !CSSPropertyMetadata::isInheritedProperty(propertyID))
continue;
result.append(getPropertyText(propertyID, value, property.isImportant(), numDecls++));
return getShorthandValue(webkitTextEmphasisShorthand());
case CSSPropertyWebkitTextStroke:
return getShorthandValue(webkitTextStrokeShorthand());
+ case CSSPropertyTransformOrigin:
case CSSPropertyWebkitTransformOrigin:
return getShorthandValue(webkitTransformOriginShorthand());
case CSSPropertyWebkitTransition:
case CSSPropertyFontStyle:
break; // No prefix.
case CSSPropertyFontFamily:
+ case CSSPropertyFontStretch:
case CSSPropertyFontVariant:
case CSSPropertyFontWeight:
prefix = ' ';
appendFontLonghandValueIfExplicit(CSSPropertyFontStyle, result, commonValue);
appendFontLonghandValueIfExplicit(CSSPropertyFontVariant, result, commonValue);
appendFontLonghandValueIfExplicit(CSSPropertyFontWeight, result, commonValue);
+ appendFontLonghandValueIfExplicit(CSSPropertyFontStretch, result, commonValue);
if (!result.isEmpty())
result.append(' ');
result.append(fontSizeProperty.value()->cssText());
if (values[i]) {
if (values[i]->isBaseValueList()) {
CSSValueList* valueList = toCSSValueList(values[i].get());
- numLayers = max(valueList->length(), numLayers);
- } else
- numLayers = max<size_t>(1U, numLayers);
+ numLayers = std::max(valueList->length(), numLayers);
+ } else {
+ numLayers = std::max<size_t>(1U, numLayers);
+ }
}
}
for (unsigned j = 0; j < size; j++) {
RefPtrWillBeRawPtr<CSSValue> value = nullptr;
if (values[j]) {
- if (values[j]->isBaseValueList())
- value = toCSSValueList(values[j].get())->item(i);
- else {
+ if (values[j]->isBaseValueList()) {
+ value = toCSSValueList(values[j].get())->itemWithBoundsCheck(i);
+ } else {
value = values[j];
// Color only belongs in the last layer.
RefPtrWillBeRawPtr<CSSValue> yValue = nullptr;
RefPtrWillBeRawPtr<CSSValue> nextValue = values[j + 1];
if (nextValue->isValueList())
- yValue = toCSSValueList(nextValue.get())->itemWithoutBoundsCheck(i);
+ yValue = toCSSValueList(nextValue.get())->item(i);
else
yValue = nextValue;
return result.isEmpty() ? String() : result.toString();
}
+static void appendBackgroundRepeatValue(StringBuilder& builder, const CSSValue& repeatXCSSValue, const CSSValue& repeatYCSSValue)
+{
+ // FIXME: Ensure initial values do not appear in CSS_VALUE_LISTS.
+ DEFINE_STATIC_REF_WILL_BE_PERSISTENT(CSSPrimitiveValue, initialRepeatValue, (CSSPrimitiveValue::create(CSSValueRepeat)));
+ const CSSPrimitiveValue& repeatX = repeatXCSSValue.isInitialValue() ? *initialRepeatValue : toCSSPrimitiveValue(repeatXCSSValue);
+ const CSSPrimitiveValue& repeatY = repeatYCSSValue.isInitialValue() ? *initialRepeatValue : toCSSPrimitiveValue(repeatYCSSValue);
+ CSSValueID repeatXValueId = repeatX.getValueID();
+ CSSValueID repeatYValueId = repeatY.getValueID();
+ if (repeatXValueId == repeatYValueId) {
+ builder.append(repeatX.cssText());
+ } else if (repeatXValueId == CSSValueNoRepeat && repeatYValueId == CSSValueRepeat) {
+ builder.append("repeat-y");
+ } else if (repeatXValueId == CSSValueRepeat && repeatYValueId == CSSValueNoRepeat) {
+ builder.append("repeat-x");
+ } else {
+ builder.append(repeatX.cssText());
+ builder.append(" ");
+ builder.append(repeatY.cssText());
+ }
+}
+
String StylePropertySerializer::backgroundRepeatPropertyValue() const
{
RefPtrWillBeRawPtr<CSSValue> repeatX = m_propertySet.getPropertyCSSValue(CSSPropertyBackgroundRepeatX);
RefPtrWillBeRawPtr<CSSValue> repeatY = m_propertySet.getPropertyCSSValue(CSSPropertyBackgroundRepeatY);
if (!repeatX || !repeatY)
return String();
- if (repeatX->cssValueType() != repeatY->cssValueType())
- return String();
if (m_propertySet.propertyIsImportant(CSSPropertyBackgroundRepeatX) != m_propertySet.propertyIsImportant(CSSPropertyBackgroundRepeatY))
return String();
-
- StringBuilder builder;
- switch (repeatX->cssValueType()) {
- case CSSValue::CSS_INHERIT:
- case CSSValue::CSS_INITIAL:
+ if (repeatX->cssValueType() == repeatY->cssValueType()
+ && (repeatX->cssValueType() == CSSValue::CSS_INITIAL || repeatX->cssValueType() == CSSValue::CSS_INHERIT)) {
return repeatX->cssText();
+ }
- case CSSValue::CSS_PRIMITIVE_VALUE:
- {
- CSSValueID repeatXValueId = toCSSPrimitiveValue(repeatX.get())->getValueID();
- CSSValueID repeatYValueId = toCSSPrimitiveValue(repeatY.get())->getValueID();
- if (repeatXValueId == repeatYValueId)
- return repeatX->cssText();
+ RefPtrWillBeRawPtr<CSSValueList> repeatXList;
+ if (repeatX->cssValueType() == CSSValue::CSS_PRIMITIVE_VALUE) {
+ repeatXList = CSSValueList::createCommaSeparated();
+ repeatXList->append(repeatX);
+ } else if (repeatX->cssValueType() == CSSValue::CSS_VALUE_LIST) {
+ repeatXList = toCSSValueList(repeatX.get());
+ } else {
+ return String();
+ }
- if (repeatXValueId == CSSValueNoRepeat && repeatYValueId == CSSValueRepeat) {
- builder.append("repeat-y");
- break;
- }
- if (repeatXValueId == CSSValueRepeat && repeatYValueId == CSSValueNoRepeat) {
- builder.append("repeat-x");
- break;
- }
- // Fall through intentional.
- }
- case CSSValue::CSS_CUSTOM:
- case CSSValue::CSS_VALUE_LIST:
- default:
- builder.append(repeatX->cssText());
- builder.append(' ');
- builder.append(repeatY->cssText());
- break;
+ RefPtrWillBeRawPtr<CSSValueList> repeatYList;
+ if (repeatY->cssValueType() == CSSValue::CSS_PRIMITIVE_VALUE) {
+ repeatYList = CSSValueList::createCommaSeparated();
+ repeatYList->append(repeatY);
+ } else if (repeatY->cssValueType() == CSSValue::CSS_VALUE_LIST) {
+ repeatYList = toCSSValueList(repeatY.get());
+ } else {
+ return String();
+ }
+
+ size_t shorthandLength = lowestCommonMultiple(repeatXList->length(), repeatYList->length());
+ StringBuilder builder;
+ for (size_t i = 0; i < shorthandLength; ++i) {
+ if (i)
+ builder.append(", ");
+ appendBackgroundRepeatValue(builder,
+ *repeatXList->item(i % repeatXList->length()),
+ *repeatYList->item(i % repeatYList->length()));
}
return builder.toString();
}