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

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

Issue 216803002: Implement all shorthand property. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixed ASSERT_NOT_REACH in linux_blink_dbg Created 6 years, 7 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 3b6e94a02945f839fb2b6ff8d9171411c32dfe18..b2fceed300a1e44ed8d1fd8ae8d8c995ca1f5ff3 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,159 @@ static bool isInitialOrInherit(const String& value)
return value.length() == 7 && (value == initial || value == inherit);
}
+static bool isAffectedByAllProperty(CSSPropertyID propertyID)
+{
+ return propertyID != CSSPropertyUnicodeBidi && propertyID != CSSPropertyDirection;
+}
+
+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 (isAffectedByAllProperty(property.id()) && property.id() != CSSPropertyAll)
+ return true;
+ }
+ return false;
+}
+
+static bool canAllOverwriteProperty(StylePropertySet::PropertyReference all, unsigned allIndex, StylePropertySet::PropertyReference property, unsigned propertyIndex)
esprehn 2014/05/30 00:59:22 const StylePropertySet::PropertyReference&
tasak 2014/06/04 09:37:41 Done.
+{
+ if (allIndex == propertyIndex)
+ return true;
+ if (!isAffectedByAllProperty(property.id()))
+ return false;
+ if (all.isImportant() != property.isImportant())
+ return all.isImportant();
+ return propertyIndex < allIndex;
+}
+
StylePropertySerializer::StylePropertySerializer(const StylePropertySet& properties)
: m_propertySet(properties)
{
+ if (!shouldExpandAll(properties))
+ return;
+
+ unsigned allIndex = properties.findPropertyIndex(CSSPropertyAll);
+ StylePropertySet::PropertyReference all = properties.propertyAt(allIndex);
+ BitArray<numCSSProperties> shorthandPropertyAppeared;
+
+ m_propertyVector = adoptPtr(new Vector<CSSPropertyInternal>());
esprehn 2014/05/30 00:59:22 Why heap allocate this if the constructor is alway
tasak 2014/06/04 09:37:40 I changed m_propertyVector, from OwnPtr<Vector..>
+
+ unsigned position = 0;
+ for (unsigned i = 0; i < properties.propertyCount(); ++i) {
esprehn 2014/05/30 00:59:22 All of this needs to be in a method. the early re
tasak 2014/06/04 09:37:40 Done.
+ StylePropertySet::PropertyReference property = properties.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 (propertyId == CSSPropertyAll || !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()));
+ }
+}
+
+unsigned StylePropertySerializer::propertyCount() const
+{
+ if (!m_propertyVector)
+ return m_propertySet.propertyCount();
+
+ return m_propertyVector->size();
+}
+
+StylePropertySerializer::CSSPropertyInternal StylePropertySerializer::propertyAt(unsigned index) const
esprehn 2014/05/30 00:59:22 Is this private? PropertyInternal doesn't seem lik
tasak 2014/06/04 09:37:41 Yes, this is private.
+{
+ if (!m_propertyVector)
+ return CSSPropertyInternal(m_propertySet.propertyAt(index));
+
+ return m_propertyVector->at(index);
+}
+
+String StylePropertySerializer::getPropertyValueInternal(CSSPropertyID propertyId) const
esprehn 2014/05/30 00:59:22 these are all named wrong. propertyValue() and suc
tasak 2014/06/04 09:37:40 Done. Now propertyValue().
+{
+ if (!m_propertyVector)
+ return m_propertySet.getPropertyValue(propertyId);
+
+ int index = findPropertyIndex(propertyId);
+ if (index == -1)
+ return String();
+ if (CSSValue* value = m_propertyVector->at(index).value())
+ return value->cssText();
+ return String();
+}
+
+CSSValue* StylePropertySerializer::getPropertyCSSValue(CSSPropertyID propertyId) const
+{
+ if (!m_propertyVector)
+ return m_propertySet.getPropertyCSSValue(propertyId).get();
+
+ int index = findPropertyIndex(propertyId);
+ if (index == -1)
+ return 0;
+ return m_propertyVector->at(index).value();
+}
+
+int StylePropertySerializer::findPropertyIndex(CSSPropertyID propertyId) const
+{
+ if (!m_propertyVector)
+ return m_propertySet.findPropertyIndex(propertyId);
+
+ for (unsigned i = 0; i < m_propertyVector->size(); ++i) {
+ if (m_propertyVector->at(i).id() == propertyId)
+ return i;
+ }
+ return -1;
+}
+
+bool StylePropertySerializer::isPropertyImplicit(CSSPropertyID propertyId) const
+{
+ if (!m_propertyVector)
+ 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)
+ 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 +214,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 +364,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 +376,7 @@ String StylePropertySerializer::asText() const
if (shorthandPropertyUsed.get(shortPropertyIndex))
continue;
if (!shorthandPropertyAppeared.get(shortPropertyIndex) && value.isNull())
- value = m_propertySet.getPropertyValue(shorthandPropertyID);
+ value = getPropertyValueInternal(shorthandPropertyID);
shorthandPropertyAppeared.set(shortPropertyIndex);
}
@@ -321,7 +479,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 +493,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 +511,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 +538,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 +546,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);
esprehn 2014/05/30 00:59:22 This needs a different name. Internal usually mean
tasak 2014/06/04 09:37:40 Yes, I would like to make CSSPropertyInternal priv
+ CSSPropertyInternal fontFamilyProperty = propertyAt(fontFamilyPropertyIndex);
if (fontSizeProperty.isImplicit() || fontFamilyProperty.isImplicit())
return emptyString();
@@ -418,18 +576,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 +637,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 +680,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 +782,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 +812,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 +824,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;
@@ -704,13 +862,13 @@ String StylePropertySerializer::borderPropertyValue(CommonValueMode valueMode) c
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 (repeatX->cssValueType() != repeatY->cssValueType())
return String();
- if (m_propertySet.propertyIsImportant(CSSPropertyBackgroundRepeatX) != m_propertySet.propertyIsImportant(CSSPropertyBackgroundRepeatY))
+ if (propertyIsImportant(CSSPropertyBackgroundRepeatX) != propertyIsImportant(CSSPropertyBackgroundRepeatY))
return String();
StringBuilder builder;
@@ -751,13 +909,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;
}
@@ -774,10 +932,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.
@@ -785,45 +943,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 = getPropertyValueInternal(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 = getPropertyValueInternal(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;
@@ -832,21 +990,70 @@ 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
+{
+ if (!propertyCount())
+ return false;
+
+ bool isImportant = propertyAt(0).isImportant();
esprehn 2014/05/30 00:59:22 why is it okay to only check 0?
tasak 2014/06/04 09:37:40 I'm trying to see if all properties' isImportant a
+ 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 (isImportant != property.isImportant())
+ return false;
+ }
+ if (!isInitialValue && !isInheritedValue && !isUnsetValue)
+ return false;
+
+ for (int i = firstCSSProperty; i <= lastCSSProperty; ++i) {
esprehn 2014/05/30 00:59:22 I think you can just loop over CSSPropertyID and c
tasak 2014/06/04 09:37:40 Because I have the following error: "error: cannot
+ CSSPropertyID propertyId = static_cast<CSSPropertyID>(i);
+
+ if (isExpandedShorthandForAll(propertyId))
+ continue;
+ if (propertyId == CSSPropertyAll || !isAffectedByAllProperty(propertyId))
+ continue;
+
+ unsigned shorthandIndex = i - firstCSSProperty;
+ if (!shorthandPropertyAppeared.get(shorthandIndex))
+ return false;
+ }
+
+ String value = isInitialValue ? "initial" : (isInheritedValue ? "inherit" : "unset");
esprehn 2014/05/30 00:59:22 don't nest ternaries
tasak 2014/06/04 09:37:40 Done.
+ result = getPropertyText(CSSPropertyAll, value, isImportant, false);
+ return true;
+}
+
}

Powered by Google App Engine
This is Rietveld 408576698