Changeset 129579 in webkit
- Timestamp:
- Sep 25, 2012, 6:17:50 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 8 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r129572 r129579 1 2012-09-25 Luke Macpherson <macpherson@chromium.org> 2 3 Ensure variables are resolved for specialized CSS primitive value types. 4 https://bugs.webkit.org/show_bug.cgi?id=95930 5 6 Reviewed by Tony Chang. 7 8 Add tests that use specialized CSS values (eg. pairs, quads, rectangle, circle, ellipse etc.). 9 10 * fast/css/variables/root-background-size-expected.html: Added. 11 * fast/css/variables/root-background-size.html: Added. 12 * fast/css/variables/var-inside-pair-expected.html: Added. 13 * fast/css/variables/var-inside-pair.html: Added. 14 * fast/css/variables/var-inside-quad-expected.html: Added. 15 * fast/css/variables/var-inside-quad.html: Added. 16 * fast/css/variables/var-inside-shape-expected.html: Added. 17 * fast/css/variables/var-inside-shape.html: Added. 18 1 19 2012-09-25 Mike West <mkwst@chromium.org> 2 20 -
trunk/Source/WebCore/ChangeLog
r129574 r129579 1 2012-09-25 Luke Macpherson <macpherson@chromium.org> 2 3 Ensure variables are resolved for specialized CSS primitive value types. 4 https://bugs.webkit.org/show_bug.cgi?id=95930 5 6 Reviewed by Tony Chang. 7 8 Sometimes CSSPrimitiveValue contains a collection of other CSSPrimitiveValues (eg. 2, 4 or n). 9 This patch makes sure any variables contained inside those child values are resolved. 10 11 Tests: fast/css/variables/root-background-size.html 12 fast/css/variables/var-inside-pair.html 13 fast/css/variables/var-inside-quad.html 14 fast/css/variables/var-inside-shape.html 15 16 * css/CSSBasicShapes.cpp: 17 (WebCore::buildRectangleString): 18 (WebCore::CSSBasicShapeRectangle::cssText): 19 (WebCore): 20 (WebCore::CSSBasicShapeRectangle::serializeResolvingVariables): 21 Generates a string representation of this value with variables resolved from the provided HashMap of variables. 22 (WebCore::CSSBasicShapeRectangle::hasVariableReference): 23 Returns true if any of the values used to describe the rectange depend on the value of a variable. 24 (WebCore::buildCircleString): 25 (WebCore::CSSBasicShapeCircle::cssText): 26 (WebCore::CSSBasicShapeCircle::serializeResolvingVariables): 27 (WebCore::CSSBasicShapeCircle::hasVariableReference): 28 (WebCore::buildEllipseString): 29 (WebCore::CSSBasicShapeEllipse::cssText): 30 (WebCore::CSSBasicShapeEllipse::serializeResolvingVariables): 31 (WebCore::CSSBasicShapeEllipse::hasVariableReference): 32 (WebCore::CSSBasicShapePolygon::serializeResolvingVariables): 33 (WebCore::CSSBasicShapePolygon::hasVariableReference): 34 * css/CSSBasicShapes.h: 35 (CSSBasicShapeRectangle): 36 (CSSBasicShapeCircle): 37 (CSSBasicShapeEllipse): 38 (CSSBasicShapePolygon): 39 * css/CSSPrimitiveValue.cpp: 40 (WebCore::CSSPrimitiveValue::customCssText): 41 Move the logic for generating the strings for Rects, Quads, Pairs and Shapes into their respective classes. 42 (WebCore::CSSPrimitiveValue::customSerializeResolvingVariables): 43 Handle Rects, Quads, Pairs and Shapes when they contain variables, by calling their serializeResolvingVariables method. 44 (WebCore): 45 (WebCore::CSSPrimitiveValue::hasVariableReference): 46 Handle Rects, Quads, Pairs and Shapes by calling their respective hasVariableReference methods. 47 * css/CSSPrimitiveValue.h: 48 (CSSPrimitiveValue): 49 * css/Pair.h: 50 (WebCore::Pair::pairString): 51 (Pair): 52 (WebCore::Pair::cssText): 53 (WebCore::Pair::serializeResolvingVariables): 54 (WebCore::Pair::hasVariableReference): 55 * css/Rect.h: 56 (RectBase): 57 (WebCore::RectBase::hasVariableReference): 58 (WebCore::Rect::rectString): 59 (Rect): 60 (WebCore::Rect::cssText): 61 (WebCore::Rect::serializeResolvingVariables): 62 (WebCore::Quad::quadString): 63 (Quad): 64 (WebCore::Quad::cssText): 65 (WebCore::Quad::serializeResolvingVariables): 66 * css/StyleResolver.cpp: 67 (WebCore::StyleResolver::collectMatchingRulesForList): 68 1 69 2012-09-25 Filip Pizlo <fpizlo@apple.com> 2 70 -
trunk/Source/WebCore/css/CSSBasicShapes.cpp
r127155 r129579 38 38 namespace WebCore { 39 39 40 String CSSBasicShapeRectangle::cssText() const 40 static String buildRectangleString(const String& x, const String& y, const String& width, const String& height, const String& radiusX, const String& radiusY) 41 41 { 42 42 StringBuilder result; 43 result.reserveCapacity(32);44 45 43 result.appendLiteral("rectangle("); 46 47 result.append(m_x->cssText()); 44 result.append(x); 48 45 result.appendLiteral(", "); 49 50 result.append(m_y->cssText()); 46 result.append(y); 51 47 result.appendLiteral(", "); 52 53 result.append(m_width->cssText()); 48 result.append(width); 54 49 result.appendLiteral(", "); 55 56 result.append(m_height->cssText()); 57 58 if (m_radiusX.get()) { 50 result.append(height); 51 if (!radiusX.isNull()) { 59 52 result.appendLiteral(", "); 60 result.append(m_radiusX->cssText()); 61 62 if (m_radiusY.get()) { 53 result.append(radiusX); 54 if (!radiusY.isNull()) { 63 55 result.appendLiteral(", "); 64 result.append( m_radiusY->cssText());56 result.append(radiusY); 65 57 } 66 58 } 67 68 59 result.append(')'); 69 70 60 return result.toString(); 71 61 } 72 62 63 String CSSBasicShapeRectangle::cssText() const 64 { 65 return buildRectangleString(m_x->cssText(), 66 m_y->cssText(), 67 m_width->cssText(), 68 m_height->cssText(), 69 m_radiusX.get() ? m_radiusX->cssText() : String(), 70 m_radiusY.get() ? m_radiusY->cssText() : String()); 71 } 72 73 #if ENABLE(CSS_VARIABLES) 74 String CSSBasicShapeRectangle::serializeResolvingVariables(const HashMap<AtomicString, String>& variables) const 75 { 76 return buildRectangleString(m_x->serializeResolvingVariables(variables), 77 m_y->serializeResolvingVariables(variables), 78 m_width->serializeResolvingVariables(variables), 79 m_height->serializeResolvingVariables(variables), 80 m_radiusX.get() ? m_radiusX->serializeResolvingVariables(variables) : String(), 81 m_radiusY.get() ? m_radiusY->serializeResolvingVariables(variables) : String()); 82 } 83 84 bool CSSBasicShapeRectangle::hasVariableReference() const 85 { 86 return m_x->hasVariableReference() 87 || m_y->hasVariableReference() 88 || m_width->hasVariableReference() 89 || m_height->hasVariableReference() 90 || (m_radiusX.get() && m_radiusX->hasVariableReference()) 91 || (m_radiusY.get() && m_radiusY->hasVariableReference()); 92 } 93 #endif 94 95 static String buildCircleString(const String& x, const String& y, const String& radius) 96 { 97 return "circle(" + x + ", " + y + ", " + radius + ')'; 98 } 99 73 100 String CSSBasicShapeCircle::cssText() const 74 101 { 102 return buildCircleString(m_centerX->cssText(), m_centerY->cssText(), m_radius->cssText()); 103 } 104 105 #if ENABLE(CSS_VARIABLES) 106 String CSSBasicShapeCircle::serializeResolvingVariables(const HashMap<AtomicString, String>& variables) const 107 { 108 return buildCircleString(m_centerX->serializeResolvingVariables(variables), 109 m_centerY->serializeResolvingVariables(variables), 110 m_radius->serializeResolvingVariables(variables)); 111 } 112 113 bool CSSBasicShapeCircle::hasVariableReference() const 114 { 115 return m_centerX->hasVariableReference() 116 || m_centerY->hasVariableReference() 117 || m_radius->hasVariableReference(); 118 } 119 #endif 120 121 static String buildEllipseString(const String& x, const String& y, const String& radiusX, const String& radiusY) 122 { 123 return "ellipse(" + x + ", " + y + ", " + radiusX + ", " + radiusY + ')'; 124 } 125 126 String CSSBasicShapeEllipse::cssText() const 127 { 128 return buildEllipseString(m_centerX->cssText(), m_centerY->cssText(), m_radiusX->cssText(), m_radiusY->cssText()); 129 } 130 131 #if ENABLE(CSS_VARIABLES) 132 String CSSBasicShapeEllipse::serializeResolvingVariables(const HashMap<AtomicString, String>& variables) const 133 { 134 return buildEllipseString(m_centerX->serializeResolvingVariables(variables), 135 m_centerY->serializeResolvingVariables(variables), 136 m_radiusX->serializeResolvingVariables(variables), 137 m_radiusY->serializeResolvingVariables(variables)); 138 } 139 140 bool CSSBasicShapeEllipse::hasVariableReference() const 141 { 142 return m_centerX->hasVariableReference() 143 || m_centerY->hasVariableReference() 144 || m_radiusX->hasVariableReference() 145 || m_radiusY->hasVariableReference(); 146 } 147 #endif 148 149 static String buildPolygonString(const WindRule& windRule, const Vector<String>& points) 150 { 75 151 StringBuilder result; 76 result.reserveCapacity(32); 77 78 result.appendLiteral("circle("); 79 80 result.append(m_centerX->cssText()); 81 result.appendLiteral(", "); 82 83 result.append(m_centerY->cssText()); 84 result.appendLiteral(", "); 85 86 result.append(m_radius->cssText()); 87 result.append(')'); 88 89 return result.toString(); 90 } 91 92 String CSSBasicShapeEllipse::cssText() const 93 { 94 StringBuilder result; 95 result.reserveCapacity(32); 96 result.appendLiteral("ellipse("); 97 98 result.append(m_centerX->cssText()); 99 result.appendLiteral(", "); 100 101 result.append(m_centerY->cssText()); 102 result.appendLiteral(", "); 103 104 result.append(m_radiusX->cssText()); 105 result.appendLiteral(", "); 106 107 result.append(m_radiusY->cssText()); 108 result.append(')'); 109 110 return result.toString(); 111 } 112 113 String CSSBasicShapePolygon::cssText() const 114 { 115 StringBuilder result; 116 result.reserveCapacity(32); 117 118 if (m_windRule == RULE_EVENODD) 152 153 if (windRule == RULE_EVENODD) 119 154 result.appendLiteral("polygon(evenodd, "); 120 155 else 121 156 result.appendLiteral("polygon(nonzero, "); 122 157 123 ASSERT(!( m_values.size() % 2));124 125 for ( unsigned i = 0; i < m_values.size(); i += 2) {158 ASSERT(!(points.size() % 2)); 159 160 for (size_t i = 0; i < points.size(); i += 2) { 126 161 if (i) 127 162 result.appendLiteral(", "); 128 result.append( m_values.at(i)->cssText());163 result.append(points[i]); 129 164 result.append(' '); 130 result.append( m_values.at(i + 1)->cssText());165 result.append(points[i + 1]); 131 166 } 132 167 … … 136 171 } 137 172 173 String CSSBasicShapePolygon::cssText() const 174 { 175 Vector<String> points; 176 points.reserveInitialCapacity(m_values.size()); 177 178 for (size_t i = 0; i < m_values.size(); ++i) 179 points.append(m_values.at(i)->cssText()); 180 181 return buildPolygonString(m_windRule, points); 182 } 183 184 #if ENABLE(CSS_VARIABLES) 185 String CSSBasicShapePolygon::serializeResolvingVariables(const HashMap<AtomicString, String>& variables) const 186 { 187 Vector<String> points; 188 points.reserveInitialCapacity(m_values.size()); 189 190 for (size_t i = 0; i < m_values.size(); ++i) 191 points.append(m_values.at(i)->serializeResolvingVariables(variables)); 192 193 return buildPolygonString(m_windRule, points); 194 } 195 196 bool CSSBasicShapePolygon::hasVariableReference() const 197 { 198 for (size_t i = 0; i < m_values.size(); ++i) { 199 if (m_values.at(i)->hasVariableReference()) 200 return true; 201 } 202 return false; 203 } 204 #endif 205 138 206 } // namespace WebCore 139 207 -
trunk/Source/WebCore/css/CSSBasicShapes.h
r127757 r129579 51 51 virtual String cssText() const = 0; 52 52 53 #if ENABLE(CSS_VARIABLES) 54 virtual String serializeResolvingVariables(const HashMap<AtomicString, String>&) const = 0; 55 virtual bool hasVariableReference() const = 0; 56 #endif 57 53 58 public: 54 59 virtual ~CSSBasicShape() { } … … 79 84 virtual String cssText() const; 80 85 86 #if ENABLE(CSS_VARIABLES) 87 virtual String serializeResolvingVariables(const HashMap<AtomicString, String>&) const; 88 virtual bool hasVariableReference() const; 89 #endif 90 81 91 private: 82 92 CSSBasicShapeRectangle() { } … … 105 115 virtual String cssText() const; 106 116 117 #if ENABLE(CSS_VARIABLES) 118 virtual String serializeResolvingVariables(const HashMap<AtomicString, String>&) const; 119 virtual bool hasVariableReference() const; 120 #endif 121 107 122 private: 108 123 CSSBasicShapeCircle() { } … … 129 144 virtual Type type() const { return CSS_BASIC_SHAPE_ELLIPSE; } 130 145 virtual String cssText() const; 146 147 #if ENABLE(CSS_VARIABLES) 148 virtual String serializeResolvingVariables(const HashMap<AtomicString, String>&) const; 149 virtual bool hasVariableReference() const; 150 #endif 131 151 132 152 private: … … 159 179 virtual String cssText() const; 160 180 181 #if ENABLE(CSS_VARIABLES) 182 virtual String serializeResolvingVariables(const HashMap<AtomicString, String>&) const; 183 virtual bool hasVariableReference() const; 184 #endif 185 161 186 private: 162 187 CSSBasicShapePolygon() -
trunk/Source/WebCore/css/CSSPrimitiveValue.cpp
r128762 r129579 989 989 break; 990 990 } 991 case CSS_RECT: { 992 Rect* rectVal = getRectValue(); 993 text = "rect(" + rectVal->top()->cssText() + ' ' + rectVal->right()->cssText() + ' ' + rectVal->bottom()->cssText() + ' ' + rectVal->left()->cssText() + ')'; 994 break; 995 } 996 case CSS_QUAD: { 997 Quad* quadVal = getQuadValue(); 998 Vector<UChar> result; 999 result.reserveInitialCapacity(32); 1000 append(result, quadVal->top()->cssText()); 1001 if (quadVal->right() != quadVal->top() || quadVal->bottom() != quadVal->top() || quadVal->left() != quadVal->top()) { 1002 result.append(' '); 1003 append(result, quadVal->right()->cssText()); 1004 if (quadVal->bottom() != quadVal->top() || quadVal->right() != quadVal->left()) { 1005 result.append(' '); 1006 append(result, quadVal->bottom()->cssText()); 1007 if (quadVal->left() != quadVal->right()) { 1008 result.append(' '); 1009 append(result, quadVal->left()->cssText()); 1010 } 1011 } 1012 } 1013 text = String::adopt(result); 1014 break; 1015 } 991 case CSS_RECT: 992 text = getRectValue()->cssText(); 993 break; 994 case CSS_QUAD: 995 text = getQuadValue()->cssText(); 996 break; 1016 997 case CSS_RGBCOLOR: 1017 998 case CSS_PARSER_HEXCOLOR: { … … 1048 1029 break; 1049 1030 } 1050 case CSS_PAIR: { 1051 StringBuilder result; 1052 result.append(m_value.pair->first()->cssText()); 1053 if (m_value.pair->second() != m_value.pair->first()) { 1054 result.append(' '); 1055 result.append(m_value.pair->second()->cssText()); 1056 } 1057 text = result.toString(); 1058 break; 1059 } 1031 case CSS_PAIR: 1032 text = getPairValue()->cssText(); 1033 break; 1060 1034 #if ENABLE(DASHBOARD_SUPPORT) || ENABLE(WIDGET_REGION) 1061 1035 case CSS_DASHBOARD_REGION: { … … 1142 1116 if (isVariableName() && variables.contains(m_value.string)) 1143 1117 return variables.get(m_value.string); 1144 if (isCalculated()) 1145 return cssCalcValue()->customSerializeResolvingVariables(variables); 1118 if (CSSCalcValue* calcValue = cssCalcValue()) 1119 return calcValue->customSerializeResolvingVariables(variables); 1120 if (Pair* pairValue = getPairValue()) 1121 return pairValue->serializeResolvingVariables(variables); 1122 if (Rect* rectVal = getRectValue()) 1123 return rectVal->serializeResolvingVariables(variables); 1124 if (Quad* quadVal = getQuadValue()) 1125 return quadVal->serializeResolvingVariables(variables); 1126 if (CSSBasicShape* shapeValue = getShapeValue()) 1127 return shapeValue->serializeResolvingVariables(variables); 1146 1128 return customCssText(); 1129 } 1130 1131 bool CSSPrimitiveValue::hasVariableReference() const 1132 { 1133 if (CSSCalcValue* calcValue = cssCalcValue()) 1134 return calcValue->hasVariableReference(); 1135 if (Pair* pairValue = getPairValue()) 1136 return pairValue->hasVariableReference(); 1137 if (Quad* quadValue = getQuadValue()) 1138 return quadValue->hasVariableReference(); 1139 if (Rect* rectValue = getRectValue()) 1140 return rectValue->hasVariableReference(); 1141 if (CSSBasicShape* shapeValue = getShapeValue()) 1142 return shapeValue->hasVariableReference(); 1143 return isVariableName(); 1147 1144 } 1148 1145 #endif -
trunk/Source/WebCore/css/CSSPrimitiveValue.h
r127838 r129579 300 300 #if ENABLE(CSS_VARIABLES) 301 301 String customSerializeResolvingVariables(const HashMap<AtomicString, String>&) const; 302 bool hasVariableReference() const; 302 303 #endif 303 304 -
trunk/Source/WebCore/css/Pair.h
r97854 r129579 25 25 #include "CSSPrimitiveValue.h" 26 26 #include <wtf/PassRefPtr.h> 27 #include <wtf/text/StringBuilder.h> 27 28 28 29 namespace WebCore { … … 50 51 void setSecond(PassRefPtr<CSSPrimitiveValue> second) { m_second = second; } 51 52 53 String cssText() const 54 { 55 56 return generateCSSString(first()->cssText(), second()->cssText()); 57 } 58 59 #if ENABLE(CSS_VARIABLES) 60 String serializeResolvingVariables(const HashMap<AtomicString, String>& variables) const 61 { 62 return generateCSSString(first()->customSerializeResolvingVariables(variables), 63 second()->customSerializeResolvingVariables(variables)); 64 } 65 66 bool hasVariableReference() const { return first()->hasVariableReference() || second()->hasVariableReference(); } 67 #endif 68 52 69 private: 53 70 Pair() : m_first(0), m_second(0) { } 54 71 Pair(PassRefPtr<CSSPrimitiveValue> first, PassRefPtr<CSSPrimitiveValue> second) 55 72 : m_first(first), m_second(second) { } 73 74 static String generateCSSString(const String& first, const String& second) 75 { 76 if (first == second) 77 return first; 78 return first + ' ' + second; 79 } 56 80 57 81 RefPtr<CSSPrimitiveValue> m_first; -
trunk/Source/WebCore/css/Rect.h
r113588 r129579 24 24 #include "CSSPrimitiveValue.h" 25 25 #include <wtf/RefPtr.h> 26 #include <wtf/text/StringBuilder.h> 26 27 27 28 namespace WebCore { … … 38 39 void setBottom(PassRefPtr<CSSPrimitiveValue> bottom) { m_bottom = bottom; } 39 40 void setLeft(PassRefPtr<CSSPrimitiveValue> left) { m_left = left; } 41 42 #if ENABLE(CSS_VARIABLES) 43 bool hasVariableReference() const 44 { 45 return m_top->hasVariableReference() 46 || m_right->hasVariableReference() 47 || m_bottom->hasVariableReference() 48 || m_left->hasVariableReference(); 49 } 50 #endif 40 51 41 52 protected: … … 64 75 PassRefPtr<Rect> cloneForCSSOM() const { return adoptRef(new Rect(*this)); } 65 76 77 String cssText() const 78 { 79 return generateCSSString(top()->cssText(), right()->cssText(), bottom()->cssText(), left()->cssText()); 80 } 81 82 #if ENABLE(CSS_VARIABLES) 83 String serializeResolvingVariables(const HashMap<AtomicString, String>& variables) const 84 { 85 return generateCSSString(top()->customSerializeResolvingVariables(variables), 86 right()->customSerializeResolvingVariables(variables), 87 bottom()->customSerializeResolvingVariables(variables), 88 left()->customSerializeResolvingVariables(variables)); 89 } 90 #endif 91 66 92 private: 67 93 Rect() { } 68 94 Rect(const Rect& cloneFrom) : RectBase(cloneFrom), RefCounted<Rect>() { } 95 static String generateCSSString(const String& top, const String& right, const String& bottom, const String& left) 96 { 97 return "rect(" + top + ' ' + right + ' ' + bottom + ' ' + left + ')'; 98 } 69 99 }; 70 100 … … 75 105 PassRefPtr<Quad> cloneForCSSOM() const { return adoptRef(new Quad(*this)); } 76 106 107 String cssText() const 108 { 109 return generateCSSString(top()->cssText(), right()->cssText(), bottom()->cssText(), left()->cssText()); 110 } 111 112 #if ENABLE(CSS_VARIABLES) 113 String serializeResolvingVariables(const HashMap<AtomicString, String>& variables) const 114 { 115 return generateCSSString(top()->customSerializeResolvingVariables(variables), 116 right()->customSerializeResolvingVariables(variables), 117 bottom()->customSerializeResolvingVariables(variables), 118 left()->customSerializeResolvingVariables(variables)); 119 } 120 #endif 121 77 122 private: 78 123 Quad() { } 79 124 Quad(const Quad& cloneFrom) : RectBase(cloneFrom), RefCounted<Quad>() { } 125 static String generateCSSString(const String& top, const String& right, const String& bottom, const String& left) 126 { 127 StringBuilder result; 128 result.append(top); 129 if (right != top || bottom != top || left != top) { 130 result.append(' '); 131 result.append(right); 132 if (bottom != top || right != left) { 133 result.append(' '); 134 result.append(bottom); 135 if (left != right) { 136 result.append(' '); 137 result.append(left); 138 } 139 } 140 } 141 return result.toString(); 142 } 80 143 }; 81 144 -
trunk/Source/WebCore/css/StyleResolver.cpp
r129466 r129579 3360 3360 if (value->isPrimitiveValue()) { 3361 3361 CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value); 3362 if (CSSCalcValue* calcValue = primitiveValue->cssCalcValue()) 3363 return calcValue->hasVariableReference(); 3364 return primitiveValue->isVariableName(); 3362 return primitiveValue->hasVariableReference(); 3365 3363 } 3366 3364
Note:
See TracChangeset
for help on using the changeset viewer.