Commit 0beef8a8 authored by hyatt's avatar hyatt
Browse files

Fix for bug 13802, background colors can't be reset to default

        color.  Fix the value cssText method to do the right thing for background
        and background-position values.

        Reviewed by beth

        fast/dom/background-shorthand-csstext.html

        * css/CSSInitialValue.h:
        (WebCore::CSSInitialValue:::m_implicit):
        (WebCore::CSSInitialValue::isImplicitInitialValue):
        * css/CSSMutableStyleDeclaration.cpp:
        (WebCore::CSSMutableStyleDeclaration::getPropertyValue):
        (WebCore::CSSMutableStyleDeclaration::getLayeredShorthandValue):
        * css/CSSMutableStyleDeclaration.h:
        * css/CSSValue.h:
        (WebCore::CSSValue::isImplicitInitialValue):
        * css/cssparser.cpp:
        (WebCore::CSSParser::parseValue):
        (WebCore::CSSParser::parseBackgroundShorthand):
        (WebCore::CSSParser::parseShorthand):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@21652 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent cc06b695
2007-05-22 David Hyatt <hyatt@apple.com>
Fix for bug 13802, background colors can't be reset to default
color. Fix the value cssText method to do the right thing for background
and background-position values.
Reviewed by beth
fast/dom/background-shorthand-csstext.html
* css/CSSInitialValue.h:
(WebCore::CSSInitialValue:::m_implicit):
(WebCore::CSSInitialValue::isImplicitInitialValue):
* css/CSSMutableStyleDeclaration.cpp:
(WebCore::CSSMutableStyleDeclaration::getPropertyValue):
(WebCore::CSSMutableStyleDeclaration::getLayeredShorthandValue):
* css/CSSMutableStyleDeclaration.h:
* css/CSSValue.h:
(WebCore::CSSValue::isImplicitInitialValue):
* css/cssparser.cpp:
(WebCore::CSSParser::parseValue):
(WebCore::CSSParser::parseBackgroundShorthand):
(WebCore::CSSParser::parseShorthand):
2007-05-22 Darin Adler <darin@apple.com>
 
Reviewed by Geoff.
......@@ -29,8 +29,17 @@ namespace WebCore {
class CSSInitialValue : public CSSValue {
public:
CSSInitialValue(bool implicit)
:m_implicit(implicit)
{}
virtual unsigned short cssValueType() const;
virtual String cssText() const;
virtual bool isImplicitInitialValue() const { return m_implicit; }
private:
bool m_implicit;
};
} // namespace WebCore
......
......@@ -28,10 +28,13 @@
#include "CSSPropertyNames.h"
#include "CSSProperty.h"
#include "CSSStyleSheet.h"
#include "CSSValueList.h"
#include "Document.h"
#include "ExceptionCode.h"
#include "StyledElement.h"
using namespace std;
namespace WebCore {
CSSMutableStyleDeclaration::CSSMutableStyleDeclaration()
......@@ -81,13 +84,13 @@ String CSSMutableStyleDeclaration::getPropertyValue(int propertyID) const
// FIXME: Is this correct? The code in cssparser.cpp is confusing
const int properties[2] = { CSS_PROP_BACKGROUND_POSITION_X,
CSS_PROP_BACKGROUND_POSITION_Y };
return getShorthandValue(properties, 2);
return getLayeredShorthandValue(properties, 2);
}
case CSS_PROP_BACKGROUND: {
const int properties[5] = { CSS_PROP_BACKGROUND_IMAGE, CSS_PROP_BACKGROUND_REPEAT,
CSS_PROP_BACKGROUND_ATTACHMENT, CSS_PROP_BACKGROUND_POSITION,
CSS_PROP_BACKGROUND_COLOR };
return getShorthandValue(properties, 5);
const int properties[6] = { CSS_PROP_BACKGROUND_IMAGE, CSS_PROP_BACKGROUND_REPEAT,
CSS_PROP_BACKGROUND_ATTACHMENT, CSS_PROP_BACKGROUND_POSITION_X,
CSS_PROP_BACKGROUND_POSITION_Y, CSS_PROP_BACKGROUND_COLOR };
return getLayeredShorthandValue(properties, 6);
}
case CSS_PROP_BORDER: {
const int properties[3] = { CSS_PROP_BORDER_WIDTH, CSS_PROP_BORDER_STYLE,
......@@ -172,6 +175,65 @@ String CSSMutableStyleDeclaration::get4Values( const int* properties ) const
return res;
}
String CSSMutableStyleDeclaration::getLayeredShorthandValue(const int* properties, unsigned number) const
{
String res;
unsigned i;
unsigned j;
// Begin by collecting the properties into an array.
Vector< RefPtr<CSSValue> > values(number);
unsigned numLayers = 0;
for (i = 0; i < number; ++i) {
values[i] = getPropertyCSSValue(properties[i]);
if (values[i]) {
if (values[i]->isValueList()) {
CSSValueList* valueList = static_cast<CSSValueList*>(values[i].get());
numLayers = max(valueList->length(), numLayers);
} else
numLayers = max(1U, numLayers);
}
}
// Now stitch the properties together. Implicit initial values are flagged as such and
// can safely be omitted.
for (i = 0; i < numLayers; i++) {
String layerRes;
for (j = 0; j < number; j++) {
RefPtr<CSSValue> value;
if (values[j]) {
if (values[j]->isValueList())
value = static_cast<CSSValueList*>(values[j].get())->item(i);
else {
value = values[j];
// Color only belongs in the last layer.
if (properties[j] == CSS_PROP_BACKGROUND_COLOR) {
if (i != numLayers - 1)
value = 0;
} else if (i != 0) // Other singletons only belong in the first layer.
value = 0;
}
}
if (value && !value->isImplicitInitialValue()) {
if (!layerRes.isNull())
layerRes += " ";
layerRes += value->cssText();
}
}
if (!layerRes.isNull()) {
if (!res.isNull())
res += ", ";
res += layerRes;
}
}
return res;
}
String CSSMutableStyleDeclaration::getShorthandValue(const int* properties, int number) const
{
String res;
......
......@@ -104,6 +104,7 @@ public:
private:
String getShorthandValue(const int* properties, int number) const;
String getLayeredShorthandValue(const int* properties, unsigned number) const;
String get4Values(const int* properties) const;
DeprecatedValueList<CSSProperty> m_values;
......
......@@ -46,6 +46,7 @@ public:
virtual bool isValue() { return true; }
virtual bool isFontValue() { return false; }
virtual bool isImplicitInitialValue() const { return false; }
};
} // namespace
......
......@@ -514,7 +514,7 @@ bool CSSParser::parseValue(int propId, bool important)
else if (id == CSS_VAL_INITIAL) {
if (num != 1)
return false;
addProperty(propId, new CSSInitialValue(), important);
addProperty(propId, new CSSInitialValue(false), important);
return true;
}
......@@ -1553,9 +1553,9 @@ bool CSSParser::parseBackgroundShorthand(bool important)
goto fail;
if (!parsedProperty[i] && properties[i] != CSS_PROP_BACKGROUND_COLOR) {
addBackgroundValue(values[i], new CSSInitialValue());
addBackgroundValue(values[i], new CSSInitialValue(true));
if (properties[i] == CSS_PROP_BACKGROUND_POSITION)
addBackgroundValue(positionYValue, new CSSInitialValue());
addBackgroundValue(positionYValue, new CSSInitialValue(true));
}
parsedProperty[i] = false;
}
......@@ -1586,9 +1586,9 @@ bool CSSParser::parseBackgroundShorthand(bool important)
// Fill in any remaining properties with the initial value.
for (i = 0; i < numProperties; ++i) {
if (!parsedProperty[i]) {
addBackgroundValue(values[i], new CSSInitialValue());
addBackgroundValue(values[i], new CSSInitialValue(true));
if (properties[i] == CSS_PROP_BACKGROUND_POSITION)
addBackgroundValue(positionYValue, new CSSInitialValue());
addBackgroundValue(positionYValue, new CSSInitialValue(true));
}
}
......@@ -1642,7 +1642,7 @@ bool CSSParser::parseShorthand(int propId, const int *properties, int numPropert
m_implicitShorthand = true;
for (int i = 0; i < numProperties; ++i) {
if (!fnd[i])
addProperty(properties[i], new CSSInitialValue(), important);
addProperty(properties[i], new CSSInitialValue(true), important);
}
m_implicitShorthand = false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment