Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(460)

Unified Diff: Source/core/css/StylePropertySerializer.cpp

Issue 216803002: Implement all shorthand property. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/css/StylePropertySerializer.cpp
diff --git a/Source/core/css/StylePropertySerializer.cpp b/Source/core/css/StylePropertySerializer.cpp
index 717bd84f0c7fa86e7a7204c990b219961bb02805..137923180e273f4c31f8dc3ca10ce099a9c5062e 100644
--- a/Source/core/css/StylePropertySerializer.cpp
+++ b/Source/core/css/StylePropertySerializer.cpp
@@ -25,6 +25,7 @@
#include "CSSValueKeywords.h"
#include "StylePropertyShorthand.h"
+#include "core/css/CSSValuePool.h"
#include "core/css/RuntimeCSSEnabled.h"
#include "wtf/BitArray.h"
#include "wtf/text/StringBuilder.h"
@@ -40,9 +41,155 @@ static bool isInitialOrInherit(const String& value)
return value.length() == 7 && (value == initial || value == inherit);
}
+static bool shouldExpandAll(const StylePropertySet& properties)
+{
+ int allIndex = properties.findPropertyIndex(CSSPropertyAll);
+ if (allIndex == -1)
+ return false;
+
+ for (unsigned i = 0; i < properties.propertyCount(); ++i) {
+ StylePropertySet::PropertyReference property = properties.propertyAt(i);
+ if (CSSProperty::isAffectedByAllProperty(property.id()))
+ return true;
+ }
+ return false;
+}
+
+static bool canAllOverwriteProperty(const StylePropertySet::PropertyReference& all, unsigned allIndex, const StylePropertySet::PropertyReference& property, unsigned propertyIndex)
esprehn 2014/06/12 00:36:45 Can you explain the purpose of this?
+{
+ if (allIndex == propertyIndex)
+ return true;
+ if (!CSSProperty::isAffectedByAllProperty(property.id()))
+ return false;
+ if (all.isImportant() != property.isImportant())
+ return all.isImportant();
+ return propertyIndex < allIndex;
+}
+
+void StylePropertySerializer::expandAll()
+{
+ unsigned allIndex = m_propertySet.findPropertyIndex(CSSPropertyAll);
+ StylePropertySet::PropertyReference all = m_propertySet.propertyAt(allIndex);
+ BitArray<numCSSProperties> shorthandPropertyAppeared;
+
+ unsigned position = 0;
+ for (unsigned i = 0; i < m_propertySet.propertyCount(); ++i) {
+ StylePropertySet::PropertyReference property = m_propertySet.propertyAt(i);
+ CSSPropertyID propertyId = property.id();
+
+ if (propertyId == CSSPropertyAll)
+ position = m_propertyVector.size();
+
+ if (!canAllOverwriteProperty(all, allIndex, property, i)) {
+ m_propertyVector.append(CSSPropertyInternal(property));
+
+ unsigned shortPropertyIndex = property.id() - firstCSSProperty;
+ shorthandPropertyAppeared.set(shortPropertyIndex);
+ }
+ }
+
+ bool allIsUnset = !all.value()->isInitialValue() && !all.value()->isInheritedValue();
+ CSSValue* value = all.value();
+
+ for (int i = firstCSSProperty; i <= lastCSSProperty; ++i) {
+ CSSPropertyID propertyId = static_cast<CSSPropertyID>(i);
+
+ if (isExpandedShorthandForAll(propertyId))
+ continue;
+ if (!CSSProperty::isAffectedByAllProperty(propertyId))
+ continue;
+ if (shorthandPropertyAppeared.get(i - firstCSSProperty))
+ continue;
+
+ if (allIsUnset) {
+ if (CSSProperty::isInheritedProperty(propertyId))
+ value = cssValuePool().createInheritedValue().get();
+ else
+ value = cssValuePool().createExplicitInitialValue().get();
+ }
+ m_propertyVector.insert(position++, CSSPropertyInternal(propertyId, value, all.isImportant(), value->isInheritedValue(), all.isImplicit()));
esprehn 2014/06/12 00:36:44 All these vector inserts are going to be really ex
+ }
+}
+
StylePropertySerializer::StylePropertySerializer(const StylePropertySet& properties)
: m_propertySet(properties)
{
+ if (shouldExpandAll(properties))
+ expandAll();
+}
+
+unsigned StylePropertySerializer::propertyCount() const
+{
+ if (m_propertyVector.isEmpty())
+ return m_propertySet.propertyCount();
+
+ return m_propertyVector.size();
+}
+
+StylePropertySerializer::CSSPropertyInternal StylePropertySerializer::propertyAt(unsigned index) const
+{
+ if (m_propertyVector.isEmpty())
+ return CSSPropertyInternal(m_propertySet.propertyAt(index));
+
+ return m_propertyVector.at(index);
esprehn 2014/06/12 00:36:45 m_propertyVector[index] ?
+}
+
+String StylePropertySerializer::propertyValue(CSSPropertyID propertyId) const
+{
+ if (m_propertyVector.isEmpty())
+ return m_propertySet.getPropertyValue(propertyId);
+
+ int index = findPropertyIndex(propertyId);
+ if (index == -1)
+ return String();
+ if (CSSValue* value = m_propertyVector.at(index).value())
esprehn 2014/06/12 00:36:45 ditto
+ return value->cssText();
+ return String();
+}
+
+CSSValue* StylePropertySerializer::getPropertyCSSValue(CSSPropertyID propertyId) const
+{
+ if (m_propertyVector.isEmpty())
+ return m_propertySet.getPropertyCSSValue(propertyId).get();
+
+ int index = findPropertyIndex(propertyId);
+ if (index == -1)
+ return 0;
+ return m_propertyVector.at(index).value();
esprehn 2014/06/12 00:36:45 ditto
+}
+
+int StylePropertySerializer::findPropertyIndex(CSSPropertyID propertyId) const
+{
+ if (m_propertyVector.isEmpty())
+ return m_propertySet.findPropertyIndex(propertyId);
+
+ for (unsigned i = 0; i < m_propertyVector.size(); ++i) {
+ if (m_propertyVector.at(i).id() == propertyId)
esprehn 2014/06/12 00:36:45 m_propertyVector[i].id()
+ return i;
+ }
+ return -1;
+}
+
+bool StylePropertySerializer::isPropertyImplicit(CSSPropertyID propertyId) const
+{
+ if (m_propertyVector.isEmpty())
+ return m_propertySet.isPropertyImplicit(propertyId);
+
+ int index = findPropertyIndex(propertyId);
+ if (index == -1)
+ return false;
+ return m_propertyVector.at(index).isImplicit();
+}
+
+bool StylePropertySerializer::propertyIsImportant(CSSPropertyID propertyId) const
+{
+ if (m_propertyVector.isEmpty())
+ return m_propertySet.propertyIsImportant(propertyId);
+
+ int index = findPropertyIndex(propertyId);
+ if (index == -1)
+ return false;
+ return m_propertyVector.at(index).isImportant();
}
String StylePropertySerializer::getPropertyText(CSSPropertyID propertyID, const String& value, bool isImportant, bool isNotFirstDecl) const
@@ -63,13 +210,17 @@ String StylePropertySerializer::asText() const
{
StringBuilder result;
+ String allValue;
+ if (hasAllShorthand(allValue))
+ return allValue;
+
BitArray<numCSSProperties> shorthandPropertyUsed;
BitArray<numCSSProperties> shorthandPropertyAppeared;
- unsigned size = m_propertySet.propertyCount();
+ unsigned size = propertyCount();
unsigned numDecls = 0;
for (unsigned n = 0; n < size; ++n) {
- StylePropertySet::PropertyReference property = m_propertySet.propertyAt(n);
+ CSSPropertyInternal property = propertyAt(n);
CSSPropertyID propertyID = property.id();
// Only enabled or internal properties should be part of the style.
ASSERT(RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID) || isInternalProperty(propertyID));
@@ -209,6 +360,9 @@ String StylePropertySerializer::asText() const
case CSSPropertyWebkitTransitionDelay:
shorthandPropertyID = CSSPropertyWebkitTransition;
break;
+ case CSSPropertyAll:
+ result.append(getPropertyText(propertyID, property.value()->cssText(), property.isImportant(), numDecls++));
+ continue;
default:
break;
}
@@ -218,7 +372,7 @@ String StylePropertySerializer::asText() const
if (shorthandPropertyUsed.get(shortPropertyIndex))
continue;
if (!shorthandPropertyAppeared.get(shortPropertyIndex) && value.isNull())
- value = m_propertySet.getPropertyValue(shorthandPropertyID);
+ value = propertyValue(shorthandPropertyID);
shorthandPropertyAppeared.set(shortPropertyIndex);
}
@@ -227,11 +381,13 @@ String StylePropertySerializer::asText() const
propertyID = shorthandPropertyID;
shorthandPropertyUsed.set(shortPropertyIndex);
}
- } else
+ } else {
+ // We should not show "initial" when the "initial" is implicit.
+ // If explicit "initial", we need to show.
+ if (property.value()->isImplicitInitialValue())
+ continue;
value = property.value()->cssText();
-
- if (value == "initial" && !CSSProperty::isInheritedProperty(propertyID))
- continue;
+ }
result.append(getPropertyText(propertyID, value, property.isImportant(), numDecls++));
}
@@ -321,7 +477,7 @@ String StylePropertySerializer::getPropertyValue(CSSPropertyID propertyID) const
case CSSPropertyWebkitAnimation:
return getLayeredShorthandValue(webkitAnimationShorthand());
case CSSPropertyMarker: {
- RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(CSSPropertyMarkerStart);
+ RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(CSSPropertyMarkerStart);
if (value)
return value->cssText();
return String();
@@ -335,8 +491,8 @@ String StylePropertySerializer::getPropertyValue(CSSPropertyID propertyID) const
String StylePropertySerializer::borderSpacingValue(const StylePropertyShorthand& shorthand) const
{
- RefPtrWillBeRawPtr<CSSValue> horizontalValue = m_propertySet.getPropertyCSSValue(shorthand.properties()[0]);
- RefPtrWillBeRawPtr<CSSValue> verticalValue = m_propertySet.getPropertyCSSValue(shorthand.properties()[1]);
+ RefPtrWillBeRawPtr<CSSValue> horizontalValue = getPropertyCSSValue(shorthand.properties()[0]);
+ RefPtrWillBeRawPtr<CSSValue> verticalValue = getPropertyCSSValue(shorthand.properties()[1]);
// While standard border-spacing property does not allow specifying border-spacing-vertical without
// specifying border-spacing-horizontal <http://www.w3.org/TR/CSS21/tables.html#separated-borders>,
@@ -353,11 +509,11 @@ String StylePropertySerializer::borderSpacingValue(const StylePropertyShorthand&
void StylePropertySerializer::appendFontLonghandValueIfExplicit(CSSPropertyID propertyID, StringBuilder& result, String& commonValue) const
{
- int foundPropertyIndex = m_propertySet.findPropertyIndex(propertyID);
+ int foundPropertyIndex = findPropertyIndex(propertyID);
if (foundPropertyIndex == -1)
return; // All longhands must have at least implicit values if "font" is specified.
- if (m_propertySet.propertyAt(foundPropertyIndex).isImplicit()) {
+ if (propertyAt(foundPropertyIndex).isImplicit()) {
commonValue = String();
return;
}
@@ -380,7 +536,7 @@ void StylePropertySerializer::appendFontLonghandValueIfExplicit(CSSPropertyID pr
if (prefix && !result.isEmpty())
result.append(prefix);
- String value = m_propertySet.propertyAt(foundPropertyIndex).value()->cssText();
+ String value = propertyAt(foundPropertyIndex).value()->cssText();
result.append(value);
if (!commonValue.isNull() && commonValue != value)
commonValue = String();
@@ -388,13 +544,13 @@ void StylePropertySerializer::appendFontLonghandValueIfExplicit(CSSPropertyID pr
String StylePropertySerializer::fontValue() const
{
- int fontSizePropertyIndex = m_propertySet.findPropertyIndex(CSSPropertyFontSize);
- int fontFamilyPropertyIndex = m_propertySet.findPropertyIndex(CSSPropertyFontFamily);
+ int fontSizePropertyIndex = findPropertyIndex(CSSPropertyFontSize);
+ int fontFamilyPropertyIndex = findPropertyIndex(CSSPropertyFontFamily);
if (fontSizePropertyIndex == -1 || fontFamilyPropertyIndex == -1)
return emptyString();
- StylePropertySet::PropertyReference fontSizeProperty = m_propertySet.propertyAt(fontSizePropertyIndex);
- StylePropertySet::PropertyReference fontFamilyProperty = m_propertySet.propertyAt(fontFamilyPropertyIndex);
+ CSSPropertyInternal fontSizeProperty = propertyAt(fontSizePropertyIndex);
+ CSSPropertyInternal fontFamilyProperty = propertyAt(fontFamilyPropertyIndex);
if (fontSizeProperty.isImplicit() || fontFamilyProperty.isImplicit())
return emptyString();
@@ -418,18 +574,18 @@ String StylePropertySerializer::fontValue() const
String StylePropertySerializer::get4Values(const StylePropertyShorthand& shorthand) const
{
// Assume the properties are in the usual order top, right, bottom, left.
- int topValueIndex = m_propertySet.findPropertyIndex(shorthand.properties()[0]);
- int rightValueIndex = m_propertySet.findPropertyIndex(shorthand.properties()[1]);
- int bottomValueIndex = m_propertySet.findPropertyIndex(shorthand.properties()[2]);
- int leftValueIndex = m_propertySet.findPropertyIndex(shorthand.properties()[3]);
+ int topValueIndex = findPropertyIndex(shorthand.properties()[0]);
+ int rightValueIndex = findPropertyIndex(shorthand.properties()[1]);
+ int bottomValueIndex = findPropertyIndex(shorthand.properties()[2]);
+ int leftValueIndex = findPropertyIndex(shorthand.properties()[3]);
if (topValueIndex == -1 || rightValueIndex == -1 || bottomValueIndex == -1 || leftValueIndex == -1)
return String();
- StylePropertySet::PropertyReference top = m_propertySet.propertyAt(topValueIndex);
- StylePropertySet::PropertyReference right = m_propertySet.propertyAt(rightValueIndex);
- StylePropertySet::PropertyReference bottom = m_propertySet.propertyAt(bottomValueIndex);
- StylePropertySet::PropertyReference left = m_propertySet.propertyAt(leftValueIndex);
+ CSSPropertyInternal top = propertyAt(topValueIndex);
+ CSSPropertyInternal right = propertyAt(rightValueIndex);
+ CSSPropertyInternal bottom = propertyAt(bottomValueIndex);
+ CSSPropertyInternal left = propertyAt(leftValueIndex);
// All 4 properties must be specified.
if (!top.value() || !right.value() || !bottom.value() || !left.value())
@@ -479,7 +635,7 @@ String StylePropertySerializer::getLayeredShorthandValue(const StylePropertyShor
size_t numLayers = 0;
for (unsigned i = 0; i < size; ++i) {
- values[i] = m_propertySet.getPropertyCSSValue(shorthand.properties()[i]);
+ values[i] = getPropertyCSSValue(shorthand.properties()[i]);
if (values[i]) {
if (values[i]->isBaseValueList()) {
CSSValueList* valueList = toCSSValueList(values[i].get());
@@ -522,8 +678,8 @@ String StylePropertySerializer::getLayeredShorthandValue(const StylePropertyShor
// We need to report background-repeat as it was written in the CSS. If the property is implicit,
// then it was written with only one value. Here we figure out which value that was so we can
// report back correctly.
- if ((shorthand.properties()[j] == CSSPropertyBackgroundRepeatX && m_propertySet.isPropertyImplicit(shorthand.properties()[j]))
- || (shorthand.properties()[j] == CSSPropertyWebkitMaskRepeatX && m_propertySet.isPropertyImplicit(shorthand.properties()[j]))) {
+ if ((shorthand.properties()[j] == CSSPropertyBackgroundRepeatX && isPropertyImplicit(shorthand.properties()[j]))
+ || (shorthand.properties()[j] == CSSPropertyWebkitMaskRepeatX && isPropertyImplicit(shorthand.properties()[j]))) {
// BUG 49055: make sure the value was not reset in the layer check just above.
if ((j < size - 1 && shorthand.properties()[j + 1] == CSSPropertyBackgroundRepeatY && value)
@@ -624,8 +780,8 @@ String StylePropertySerializer::getShorthandValue(const StylePropertyShorthand&
String commonValue;
StringBuilder result;
for (unsigned i = 0; i < shorthand.length(); ++i) {
- if (!m_propertySet.isPropertyImplicit(shorthand.properties()[i])) {
- RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(shorthand.properties()[i]);
+ if (!isPropertyImplicit(shorthand.properties()[i])) {
+ RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(shorthand.properties()[i]);
if (!value)
return String();
String valueText = value->cssText();
@@ -654,7 +810,7 @@ String StylePropertySerializer::getCommonValue(const StylePropertyShorthand& sho
String res;
bool lastPropertyWasImportant = false;
for (unsigned i = 0; i < shorthand.length(); ++i) {
- RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(shorthand.properties()[i]);
+ RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(shorthand.properties()[i]);
// FIXME: CSSInitialValue::cssText should generate the right value.
if (!value)
return String();
@@ -666,7 +822,7 @@ String StylePropertySerializer::getCommonValue(const StylePropertyShorthand& sho
else if (res != text)
return String();
- bool currentPropertyIsImportant = m_propertySet.propertyIsImportant(shorthand.properties()[i]);
+ bool currentPropertyIsImportant = propertyIsImportant(shorthand.properties()[i]);
if (i && lastPropertyWasImportant != currentPropertyIsImportant)
return String();
lastPropertyWasImportant = currentPropertyIsImportant;
@@ -725,11 +881,11 @@ static void appendBackgroundRepeatValue(StringBuilder& builder, const CSSValue&
String StylePropertySerializer::backgroundRepeatPropertyValue() const
{
- RefPtrWillBeRawPtr<CSSValue> repeatX = m_propertySet.getPropertyCSSValue(CSSPropertyBackgroundRepeatX);
- RefPtrWillBeRawPtr<CSSValue> repeatY = m_propertySet.getPropertyCSSValue(CSSPropertyBackgroundRepeatY);
+ RefPtrWillBeRawPtr<CSSValue> repeatX = getPropertyCSSValue(CSSPropertyBackgroundRepeatX);
+ RefPtrWillBeRawPtr<CSSValue> repeatY = getPropertyCSSValue(CSSPropertyBackgroundRepeatY);
if (!repeatX || !repeatY)
return String();
- if (m_propertySet.propertyIsImportant(CSSPropertyBackgroundRepeatX) != m_propertySet.propertyIsImportant(CSSPropertyBackgroundRepeatY))
+ if (propertyIsImportant(CSSPropertyBackgroundRepeatX) != propertyIsImportant(CSSPropertyBackgroundRepeatY))
return String();
if (repeatX->cssValueType() == repeatY->cssValueType()
&& (repeatX->cssValueType() == CSSValue::CSS_INITIAL || repeatX->cssValueType() == CSSValue::CSS_INHERIT)) {
@@ -772,13 +928,13 @@ void StylePropertySerializer::appendBackgroundPropertyAsText(StringBuilder& resu
{
if (isPropertyShorthandAvailable(backgroundShorthand())) {
String backgroundValue = getPropertyValue(CSSPropertyBackground);
- bool isImportant = m_propertySet.propertyIsImportant(CSSPropertyBackgroundImage);
+ bool isImportant = propertyIsImportant(CSSPropertyBackgroundImage);
result.append(getPropertyText(CSSPropertyBackground, backgroundValue, isImportant, numDecls++));
return;
}
if (shorthandHasOnlyInitialOrInheritedValue(backgroundShorthand())) {
- RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(CSSPropertyBackgroundImage);
- bool isImportant = m_propertySet.propertyIsImportant(CSSPropertyBackgroundImage);
+ RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(CSSPropertyBackgroundImage);
+ bool isImportant = propertyIsImportant(CSSPropertyBackgroundImage);
result.append(getPropertyText(CSSPropertyBackground, value->cssText(), isImportant, numDecls++));
return;
}
@@ -795,10 +951,10 @@ void StylePropertySerializer::appendBackgroundPropertyAsText(StringBuilder& resu
for (unsigned i = 0; i < WTF_ARRAY_LENGTH(backgroundPropertyIds); ++i) {
CSSPropertyID propertyID = backgroundPropertyIds[i];
- RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(propertyID);
+ RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(propertyID);
if (!value)
continue;
- result.append(getPropertyText(propertyID, value->cssText(), m_propertySet.propertyIsImportant(propertyID), numDecls++));
+ result.append(getPropertyText(propertyID, value->cssText(), propertyIsImportant(propertyID), numDecls++));
}
// FIXME: This is a not-so-nice way to turn x/y positions into single background-position in output.
@@ -806,45 +962,45 @@ void StylePropertySerializer::appendBackgroundPropertyAsText(StringBuilder& resu
// would not work in Firefox (<rdar://problem/5143183>)
// It would be a better solution if background-position was CSS_PAIR.
if (shorthandHasOnlyInitialOrInheritedValue(backgroundPositionShorthand())) {
- RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(CSSPropertyBackgroundPositionX);
- bool isImportant = m_propertySet.propertyIsImportant(CSSPropertyBackgroundPositionX);
+ RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(CSSPropertyBackgroundPositionX);
+ bool isImportant = propertyIsImportant(CSSPropertyBackgroundPositionX);
result.append(getPropertyText(CSSPropertyBackgroundPosition, value->cssText(), isImportant, numDecls++));
} else if (isPropertyShorthandAvailable(backgroundPositionShorthand())) {
- String positionValue = m_propertySet.getPropertyValue(CSSPropertyBackgroundPosition);
- bool isImportant = m_propertySet.propertyIsImportant(CSSPropertyBackgroundPositionX);
+ String positionValue = propertyValue(CSSPropertyBackgroundPosition);
+ bool isImportant = propertyIsImportant(CSSPropertyBackgroundPositionX);
if (!positionValue.isNull())
result.append(getPropertyText(CSSPropertyBackgroundPosition, positionValue, isImportant, numDecls++));
} else {
// should check background-position-x or background-position-y.
- if (RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(CSSPropertyBackgroundPositionX)) {
+ if (RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(CSSPropertyBackgroundPositionX)) {
if (!value->isImplicitInitialValue()) {
- bool isImportant = m_propertySet.propertyIsImportant(CSSPropertyBackgroundPositionX);
+ bool isImportant = propertyIsImportant(CSSPropertyBackgroundPositionX);
result.append(getPropertyText(CSSPropertyBackgroundPositionX, value->cssText(), isImportant, numDecls++));
}
}
- if (RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(CSSPropertyBackgroundPositionY)) {
+ if (RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(CSSPropertyBackgroundPositionY)) {
if (!value->isImplicitInitialValue()) {
- bool isImportant = m_propertySet.propertyIsImportant(CSSPropertyBackgroundPositionY);
+ bool isImportant = propertyIsImportant(CSSPropertyBackgroundPositionY);
result.append(getPropertyText(CSSPropertyBackgroundPositionY, value->cssText(), isImportant, numDecls++));
}
}
}
- String repeatValue = m_propertySet.getPropertyValue(CSSPropertyBackgroundRepeat);
+ String repeatValue = propertyValue(CSSPropertyBackgroundRepeat);
if (!repeatValue.isNull())
- result.append(getPropertyText(CSSPropertyBackgroundRepeat, repeatValue, m_propertySet.propertyIsImportant(CSSPropertyBackgroundRepeatX), numDecls++));
+ result.append(getPropertyText(CSSPropertyBackgroundRepeat, repeatValue, propertyIsImportant(CSSPropertyBackgroundRepeatX), numDecls++));
}
bool StylePropertySerializer::isPropertyShorthandAvailable(const StylePropertyShorthand& shorthand) const
{
ASSERT(shorthand.length() > 0);
- bool isImportant = m_propertySet.propertyIsImportant(shorthand.properties()[0]);
+ bool isImportant = propertyIsImportant(shorthand.properties()[0]);
for (unsigned i = 0; i < shorthand.length(); ++i) {
- RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(shorthand.properties()[i]);
+ RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(shorthand.properties()[i]);
if (!value || (value->isInitialValue() && !value->isImplicitInitialValue()) || value->isInheritedValue())
return false;
- if (isImportant != m_propertySet.propertyIsImportant(shorthand.properties()[i]))
+ if (isImportant != propertyIsImportant(shorthand.properties()[i]))
return false;
}
return true;
@@ -853,21 +1009,76 @@ bool StylePropertySerializer::isPropertyShorthandAvailable(const StylePropertySh
bool StylePropertySerializer::shorthandHasOnlyInitialOrInheritedValue(const StylePropertyShorthand& shorthand) const
{
ASSERT(shorthand.length() > 0);
- bool isImportant = m_propertySet.propertyIsImportant(shorthand.properties()[0]);
+ bool isImportant = propertyIsImportant(shorthand.properties()[0]);
bool isInitialValue = true;
bool isInheritedValue = true;
for (unsigned i = 0; i < shorthand.length(); ++i) {
- RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(shorthand.properties()[i]);
+ RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(shorthand.properties()[i]);
if (!value)
return false;
if (!value->isInitialValue())
isInitialValue = false;
if (!value->isInheritedValue())
isInheritedValue = false;
- if (isImportant != m_propertySet.propertyIsImportant(shorthand.properties()[i]))
+ if (isImportant != propertyIsImportant(shorthand.properties()[i]))
return false;
}
return isInitialValue || isInheritedValue;
}
+bool StylePropertySerializer::hasAllShorthand(String& result) const
esprehn 2014/06/12 00:36:44 has*() methods shouldn't really reaturn stuff like
+{
+ if (!propertyCount())
+ return false;
+
+ bool firstPropertyIsImportant = propertyAt(0).isImportant();
+ bool isInitialValue = true;
+ bool isInheritedValue = true;
+ bool isUnsetValue = true;
+
+ BitArray<numCSSProperties> shorthandPropertyAppeared;
+
+ for (unsigned i = 0; i < propertyCount(); ++i) {
+ CSSPropertyInternal property = propertyAt(i);
+
+ unsigned shorthandIndex = property.id() - firstCSSProperty;
+ shorthandPropertyAppeared.set(shorthandIndex);
+
+ if (!property.value()->isInitialValue())
+ isInitialValue = false;
+ if (!property.value()->isInheritedValue())
+ isInheritedValue = false;
+ if ((CSSProperty::isInheritedProperty(property.id()) && !property.value()->isInheritedValue()) || (!CSSProperty::isInheritedProperty(property.id()) && !property.value()->isInitialValue()))
+ isUnsetValue = false;
+
+ if (firstPropertyIsImportant != property.isImportant())
+ return false;
+ }
+ if (!isInitialValue && !isInheritedValue && !isUnsetValue)
+ return false;
+
+ for (int i = firstCSSProperty; i <= lastCSSProperty; ++i) {
+ CSSPropertyID propertyId = static_cast<CSSPropertyID>(i);
+
+ if (isExpandedShorthandForAll(propertyId))
+ continue;
+ if (!CSSProperty::isAffectedByAllProperty(propertyId))
+ continue;
+
+ unsigned shorthandIndex = i - firstCSSProperty;
+ if (!shorthandPropertyAppeared.get(shorthandIndex))
+ return false;
+ }
+
+ String value;
+ if (isInitialValue)
+ value = "initial";
+ else if (isInheritedValue)
+ value = "inherit";
+ else
+ value = "unset";
+ result = getPropertyText(CSSPropertyAll, value, firstPropertyIsImportant, false);
+ return true;
+}
+
}

Powered by Google App Engine
This is Rietveld 408576698