- Revision
- 108586
- Author
- [email protected]
- Date
- 2012-02-22 17:40:12 -0800 (Wed, 22 Feb 2012)
Log Message
Make parsing color presentation attributes do less pointless work.
<http://webkit.org/b/79304>
Reviewed by Antti Koivisto.
Let HTMLElement::addHTMLColorToStyle() construct the color CSSValue directly
rather than passing a string that has to go through CSSParser.
* css/StylePropertySet.cpp:
(WebCore::StylePropertySet::setProperty):
* css/StylePropertySet.h:
Added a setProperty(propertyID, CSSValue) overload that expands shorthand
properties if necessary. Also added a little comment about the behavior
differences between setProperty() overloads.
* html/HTMLElement.cpp:
(WebCore::parseColorStringWithCrazyLegacyRules):
Changed this to return an RGBA32.
(WebCore::HTMLElement::addHTMLColorToStyle):
Figure out the RGB value and construct a (pooled) CSSValue directly.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (108585 => 108586)
--- trunk/Source/WebCore/ChangeLog 2012-02-23 01:35:46 UTC (rev 108585)
+++ trunk/Source/WebCore/ChangeLog 2012-02-23 01:40:12 UTC (rev 108586)
@@ -1,3 +1,30 @@
+2012-02-22 Andreas Kling <[email protected]>
+
+ Make parsing color presentation attributes do less pointless work.
+ <http://webkit.org/b/79304>
+
+ Reviewed by Antti Koivisto.
+
+ Let HTMLElement::addHTMLColorToStyle() construct the color CSSValue directly
+ rather than passing a string that has to go through CSSParser.
+
+ * css/StylePropertySet.cpp:
+ (WebCore::StylePropertySet::setProperty):
+ * css/StylePropertySet.h:
+
+ Added a setProperty(propertyID, CSSValue) overload that expands shorthand
+ properties if necessary. Also added a little comment about the behavior
+ differences between setProperty() overloads.
+
+ * html/HTMLElement.cpp:
+ (WebCore::parseColorStringWithCrazyLegacyRules):
+
+ Changed this to return an RGBA32.
+
+ (WebCore::HTMLElement::addHTMLColorToStyle):
+
+ Figure out the RGB value and construct a (pooled) CSSValue directly.
+
2012-02-22 Ian Vollick <[email protected]>
[chromium] Plumb from GraphicsLayer to the cc thread animation code
Modified: trunk/Source/WebCore/css/StylePropertySet.cpp (108585 => 108586)
--- trunk/Source/WebCore/css/StylePropertySet.cpp 2012-02-23 01:35:46 UTC (rev 108585)
+++ trunk/Source/WebCore/css/StylePropertySet.cpp 2012-02-23 01:40:12 UTC (rev 108586)
@@ -582,6 +582,21 @@
return CSSParser::parseValue(this, propertyID, value, important, useStrictParsing(), contextStyleSheet);
}
+void StylePropertySet::setProperty(int propertyID, PassRefPtr<CSSValue> prpValue, bool important)
+{
+ CSSPropertyLonghand longhand = longhandForProperty(propertyID);
+ if (!longhand.length()) {
+ setProperty(CSSProperty(propertyID, prpValue, important));
+ return;
+ }
+
+ removePropertiesInSet(longhand.properties(), longhand.length());
+
+ RefPtr<CSSValue> value = prpValue;
+ for (unsigned i = 0; i < longhand.length(); ++i)
+ m_properties.append(CSSProperty(longhand.properties()[i], value, important));
+}
+
void StylePropertySet::setProperty(const CSSProperty& property, CSSProperty* slot)
{
if (!removeShorthandProperty(property.id())) {
Modified: trunk/Source/WebCore/css/StylePropertySet.h (108585 => 108586)
--- trunk/Source/WebCore/css/StylePropertySet.h 2012-02-23 01:35:46 UTC (rev 108585)
+++ trunk/Source/WebCore/css/StylePropertySet.h 2012-02-23 01:40:12 UTC (rev 108586)
@@ -64,9 +64,13 @@
int getPropertyShorthand(int propertyID) const;
bool isPropertyImplicit(int propertyID) const;
+ // These expand shorthand properties into multiple properties.
+ bool setProperty(int propertyID, const String& value, bool important = false, CSSStyleSheet* contextStyleSheet = 0);
+ void setProperty(int propertyID, PassRefPtr<CSSValue>, bool important = false);
+
+ // These do not. FIXME: This is too messy, we can do better.
bool setProperty(int propertyID, int value, bool important = false, CSSStyleSheet* contextStyleSheet = 0);
bool setProperty(int propertyID, double value, CSSPrimitiveValue::UnitTypes, bool important = false, CSSStyleSheet* contextStyleSheet = 0);
- bool setProperty(int propertyID, const String& value, bool important = false, CSSStyleSheet* contextStyleSheet = 0);
void setProperty(const CSSProperty&, CSSProperty* slot = 0);
bool removeProperty(int propertyID, String* returnText = 0);
Modified: trunk/Source/WebCore/html/HTMLElement.cpp (108585 => 108586)
--- trunk/Source/WebCore/html/HTMLElement.cpp 2012-02-23 01:35:46 UTC (rev 108585)
+++ trunk/Source/WebCore/html/HTMLElement.cpp 2012-02-23 01:40:12 UTC (rev 108586)
@@ -29,6 +29,7 @@
#include "CSSParser.h"
#include "CSSPropertyNames.h"
#include "CSSValueKeywords.h"
+#include "CSSValuePool.h"
#include "ChildListMutationScope.h"
#include "DocumentFragment.h"
#include "Event.h"
@@ -1103,7 +1104,7 @@
addPropertyToAttributeStyle(style, propertyID, value);
}
-static String parseColorStringWithCrazyLegacyRules(const String& colorString)
+static RGBA32 parseColorStringWithCrazyLegacyRules(const String& colorString)
{
// Per spec, only look at the first 128 digits of the string.
const size_t maxColorLength = 128;
@@ -1125,14 +1126,14 @@
}
if (!digitBuffer.size())
- return "#000000";
+ return Color::black;
// Pad the buffer out to at least the next multiple of three in size.
digitBuffer.append('0');
digitBuffer.append('0');
if (digitBuffer.size() < 6)
- return String::format("#0%c0%c0%c", digitBuffer[0], digitBuffer[1], digitBuffer[2]);
+ return makeRGB(toASCIIHexValue(digitBuffer[0]), toASCIIHexValue(digitBuffer[1]), toASCIIHexValue(digitBuffer[2]));
// Split the digits into three components, then search the last 8 digits of each component.
ASSERT(digitBuffer.size() >= 6);
@@ -1152,7 +1153,11 @@
ASSERT(greenIndex + 1 < componentLength * 2);
ASSERT(blueIndex >= componentLength * 2);
ASSERT(blueIndex + 1 < digitBuffer.size());
- return String::format("#%c%c%c%c%c%c", digitBuffer[redIndex], digitBuffer[redIndex + 1], digitBuffer[greenIndex], digitBuffer[greenIndex + 1], digitBuffer[blueIndex], digitBuffer[blueIndex + 1]);
+
+ int redValue = toASCIIHexValue(digitBuffer[redIndex], digitBuffer[redIndex + 1]);
+ int greenValue = toASCIIHexValue(digitBuffer[greenIndex], digitBuffer[greenIndex + 1]);
+ int blueValue = toASCIIHexValue(digitBuffer[blueIndex], digitBuffer[blueIndex + 1]);
+ return makeRGB(redValue, greenValue, blueValue);
}
// Color parsing that matches HTML's "rules for parsing a legacy color value"
@@ -1170,12 +1175,10 @@
// If the string is a named CSS color or a 3/6-digit hex color, use that.
Color parsedColor(colorString);
- if (parsedColor.isValid()) {
- addPropertyToAttributeStyle(style, propertyID, colorString);
- return;
- }
+ if (!parsedColor.isValid())
+ parsedColor.setRGB(parseColorStringWithCrazyLegacyRules(colorString));
- addPropertyToAttributeStyle(style, propertyID, parseColorStringWithCrazyLegacyRules(colorString));
+ style->setProperty(propertyID, document()->cssValuePool()->createColorValue(parsedColor.rgb()));
}
void StyledElement::copyNonAttributeProperties(const Element* sourceElement)