Changeset 129579 in webkit


Ignore:
Timestamp:
Sep 25, 2012, 6:17:50 PM (13 years ago)
Author:
macpherson@chromium.org
Message:

Ensure variables are resolved for specialized CSS primitive value types.
https://bugs.webkit.org/show_bug.cgi?id=95930

Reviewed by Tony Chang.

Source/WebCore:

Sometimes CSSPrimitiveValue contains a collection of other CSSPrimitiveValues (eg. 2, 4 or n).
This patch makes sure any variables contained inside those child values are resolved.

Tests: fast/css/variables/root-background-size.html

fast/css/variables/var-inside-pair.html
fast/css/variables/var-inside-quad.html
fast/css/variables/var-inside-shape.html

  • css/CSSBasicShapes.cpp:

(WebCore::buildRectangleString):
(WebCore::CSSBasicShapeRectangle::cssText):
(WebCore):
(WebCore::CSSBasicShapeRectangle::serializeResolvingVariables):
Generates a string representation of this value with variables resolved from the provided HashMap of variables.
(WebCore::CSSBasicShapeRectangle::hasVariableReference):
Returns true if any of the values used to describe the rectange depend on the value of a variable.
(WebCore::buildCircleString):
(WebCore::CSSBasicShapeCircle::cssText):
(WebCore::CSSBasicShapeCircle::serializeResolvingVariables):
(WebCore::CSSBasicShapeCircle::hasVariableReference):
(WebCore::buildEllipseString):
(WebCore::CSSBasicShapeEllipse::cssText):
(WebCore::CSSBasicShapeEllipse::serializeResolvingVariables):
(WebCore::CSSBasicShapeEllipse::hasVariableReference):
(WebCore::CSSBasicShapePolygon::serializeResolvingVariables):
(WebCore::CSSBasicShapePolygon::hasVariableReference):

  • css/CSSBasicShapes.h:

(CSSBasicShapeRectangle):
(CSSBasicShapeCircle):
(CSSBasicShapeEllipse):
(CSSBasicShapePolygon):

  • css/CSSPrimitiveValue.cpp:

(WebCore::CSSPrimitiveValue::customCssText):
Move the logic for generating the strings for Rects, Quads, Pairs and Shapes into their respective classes.
(WebCore::CSSPrimitiveValue::customSerializeResolvingVariables):
Handle Rects, Quads, Pairs and Shapes when they contain variables, by calling their serializeResolvingVariables method.
(WebCore):
(WebCore::CSSPrimitiveValue::hasVariableReference):
Handle Rects, Quads, Pairs and Shapes by calling their respective hasVariableReference methods.

  • css/CSSPrimitiveValue.h:

(CSSPrimitiveValue):

  • css/Pair.h:

(WebCore::Pair::pairString):
(Pair):
(WebCore::Pair::cssText):
(WebCore::Pair::serializeResolvingVariables):
(WebCore::Pair::hasVariableReference):

  • css/Rect.h:

(RectBase):
(WebCore::RectBase::hasVariableReference):
(WebCore::Rect::rectString):
(Rect):
(WebCore::Rect::cssText):
(WebCore::Rect::serializeResolvingVariables):
(WebCore::Quad::quadString):
(Quad):
(WebCore::Quad::cssText):
(WebCore::Quad::serializeResolvingVariables):

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::collectMatchingRulesForList):

LayoutTests:

Add tests that use specialized CSS values (eg. pairs, quads, rectangle, circle, ellipse etc.).

  • fast/css/variables/root-background-size-expected.html: Added.
  • fast/css/variables/root-background-size.html: Added.
  • fast/css/variables/var-inside-pair-expected.html: Added.
  • fast/css/variables/var-inside-pair.html: Added.
  • fast/css/variables/var-inside-quad-expected.html: Added.
  • fast/css/variables/var-inside-quad.html: Added.
  • fast/css/variables/var-inside-shape-expected.html: Added.
  • fast/css/variables/var-inside-shape.html: Added.
Location:
trunk
Files:
8 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r129572 r129579  
     12012-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
    1192012-09-25  Mike West  <mkwst@chromium.org>
    220
  • trunk/Source/WebCore/ChangeLog

    r129574 r129579  
     12012-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
    1692012-09-25  Filip Pizlo  <fpizlo@apple.com>
    270
  • trunk/Source/WebCore/css/CSSBasicShapes.cpp

    r127155 r129579  
    3838namespace WebCore {
    3939
    40 String CSSBasicShapeRectangle::cssText() const
     40static String buildRectangleString(const String& x, const String& y, const String& width, const String& height, const String& radiusX, const String& radiusY)
    4141{
    4242    StringBuilder result;
    43     result.reserveCapacity(32);
    44 
    4543    result.appendLiteral("rectangle(");
    46 
    47     result.append(m_x->cssText());
     44    result.append(x);
    4845    result.appendLiteral(", ");
    49 
    50     result.append(m_y->cssText());
     46    result.append(y);
    5147    result.appendLiteral(", ");
    52 
    53     result.append(m_width->cssText());
     48    result.append(width);
    5449    result.appendLiteral(", ");
    55 
    56     result.append(m_height->cssText());
    57 
    58     if (m_radiusX.get()) {
     50    result.append(height);
     51    if (!radiusX.isNull()) {
    5952        result.appendLiteral(", ");
    60         result.append(m_radiusX->cssText());
    61 
    62         if (m_radiusY.get()) {
     53        result.append(radiusX);
     54        if (!radiusY.isNull()) {
    6355            result.appendLiteral(", ");
    64             result.append(m_radiusY->cssText());
     56            result.append(radiusY);
    6557        }
    6658    }
    67 
    6859    result.append(')');
    69 
    7060    return result.toString();
    7161}
    7262
     63String 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)
     74String 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
     84bool 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
     95static String buildCircleString(const String& x, const String& y, const String& radius)
     96{
     97    return "circle(" + x + ", " + y + ", " + radius + ')';
     98}
     99
    73100String CSSBasicShapeCircle::cssText() const
    74101{
     102    return buildCircleString(m_centerX->cssText(), m_centerY->cssText(), m_radius->cssText());
     103}
     104
     105#if ENABLE(CSS_VARIABLES)
     106String 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
     113bool CSSBasicShapeCircle::hasVariableReference() const
     114{
     115    return m_centerX->hasVariableReference()
     116        || m_centerY->hasVariableReference()
     117        || m_radius->hasVariableReference();
     118}
     119#endif
     120
     121static String buildEllipseString(const String& x, const String& y, const String& radiusX, const String& radiusY)
     122{
     123    return "ellipse(" + x + ", " + y + ", " + radiusX + ", " + radiusY + ')';
     124}
     125
     126String 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)
     132String 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
     140bool 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
     149static String buildPolygonString(const WindRule& windRule, const Vector<String>& points)
     150{
    75151    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)
    119154        result.appendLiteral("polygon(evenodd, ");
    120155    else
    121156        result.appendLiteral("polygon(nonzero, ");
    122157
    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) {
    126161        if (i)
    127162            result.appendLiteral(", ");
    128         result.append(m_values.at(i)->cssText());
     163        result.append(points[i]);
    129164        result.append(' ');
    130         result.append(m_values.at(i + 1)->cssText());
     165        result.append(points[i + 1]);
    131166    }
    132167
     
    136171}
    137172
     173String 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)
     185String 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
     196bool 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
    138206} // namespace WebCore
    139207
  • trunk/Source/WebCore/css/CSSBasicShapes.h

    r127757 r129579  
    5151    virtual String cssText() const = 0;
    5252
     53#if ENABLE(CSS_VARIABLES)
     54    virtual String serializeResolvingVariables(const HashMap<AtomicString, String>&) const = 0;
     55    virtual bool hasVariableReference() const = 0;
     56#endif
     57
    5358public:
    5459    virtual ~CSSBasicShape() { }
     
    7984    virtual String cssText() const;
    8085
     86#if ENABLE(CSS_VARIABLES)
     87    virtual String serializeResolvingVariables(const HashMap<AtomicString, String>&) const;
     88    virtual bool hasVariableReference() const;
     89#endif
     90
    8191private:
    8292    CSSBasicShapeRectangle() { }
     
    105115    virtual String cssText() const;
    106116
     117#if ENABLE(CSS_VARIABLES)
     118    virtual String serializeResolvingVariables(const HashMap<AtomicString, String>&) const;
     119    virtual bool hasVariableReference() const;
     120#endif
     121
    107122private:
    108123    CSSBasicShapeCircle() { }
     
    129144    virtual Type type() const { return CSS_BASIC_SHAPE_ELLIPSE; }
    130145    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
    131151
    132152private:
     
    159179    virtual String cssText() const;
    160180
     181#if ENABLE(CSS_VARIABLES)
     182    virtual String serializeResolvingVariables(const HashMap<AtomicString, String>&) const;
     183    virtual bool hasVariableReference() const;
     184#endif
     185
    161186private:
    162187    CSSBasicShapePolygon()
  • trunk/Source/WebCore/css/CSSPrimitiveValue.cpp

    r128762 r129579  
    989989            break;
    990990        }
    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;
    1016997        case CSS_RGBCOLOR:
    1017998        case CSS_PARSER_HEXCOLOR: {
     
    10481029            break;
    10491030        }
    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;
    10601034#if ENABLE(DASHBOARD_SUPPORT) || ENABLE(WIDGET_REGION)
    10611035        case CSS_DASHBOARD_REGION: {
     
    11421116    if (isVariableName() && variables.contains(m_value.string))
    11431117        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);
    11461128    return customCssText();
     1129}
     1130
     1131bool 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();
    11471144}
    11481145#endif
  • trunk/Source/WebCore/css/CSSPrimitiveValue.h

    r127838 r129579  
    300300#if ENABLE(CSS_VARIABLES)
    301301    String customSerializeResolvingVariables(const HashMap<AtomicString, String>&) const;
     302    bool hasVariableReference() const;
    302303#endif
    303304
  • trunk/Source/WebCore/css/Pair.h

    r97854 r129579  
    2525#include "CSSPrimitiveValue.h"
    2626#include <wtf/PassRefPtr.h>
     27#include <wtf/text/StringBuilder.h>
    2728
    2829namespace WebCore {
     
    5051    void setSecond(PassRefPtr<CSSPrimitiveValue> second) { m_second = second; }
    5152
     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
    5269private:
    5370    Pair() : m_first(0), m_second(0) { }
    5471    Pair(PassRefPtr<CSSPrimitiveValue> first, PassRefPtr<CSSPrimitiveValue> second)
    5572        : 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    }
    5680
    5781    RefPtr<CSSPrimitiveValue> m_first;
  • trunk/Source/WebCore/css/Rect.h

    r113588 r129579  
    2424#include "CSSPrimitiveValue.h"
    2525#include <wtf/RefPtr.h>
     26#include <wtf/text/StringBuilder.h>
    2627
    2728namespace WebCore {
     
    3839    void setBottom(PassRefPtr<CSSPrimitiveValue> bottom) { m_bottom = bottom; }
    3940    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
    4051
    4152protected:
     
    6475    PassRefPtr<Rect> cloneForCSSOM() const { return adoptRef(new Rect(*this)); }
    6576
     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
    6692private:
    6793    Rect() { }
    6894    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    }
    6999};
    70100
     
    75105    PassRefPtr<Quad> cloneForCSSOM() const { return adoptRef(new Quad(*this)); }
    76106
     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
    77122private:
    78123    Quad() { }
    79124    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    }
    80143};
    81144
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r129466 r129579  
    33603360    if (value->isPrimitiveValue()) {
    33613361        CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
    3362         if (CSSCalcValue* calcValue = primitiveValue->cssCalcValue())
    3363             return calcValue->hasVariableReference();
    3364         return primitiveValue->isVariableName();
     3362        return primitiveValue->hasVariableReference();
    33653363    }
    33663364
Note: See TracChangeset for help on using the changeset viewer.