Changeset 21652 in webkit


Ignore:
Timestamp:
May 22, 2007 5:43:11 PM (17 years ago)
Author:
hyatt
Message:

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):
Location:
trunk/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r21651 r21652  
     12007-05-22  David Hyatt  <hyatt@apple.com>
     2
     3        Fix for bug 13802, background colors can't be reset to default
     4        color.  Fix the value cssText method to do the right thing for background
     5        and background-position values.
     6
     7        Reviewed by beth
     8
     9        fast/dom/background-shorthand-csstext.html
     10
     11        * css/CSSInitialValue.h:
     12        (WebCore::CSSInitialValue:::m_implicit):
     13        (WebCore::CSSInitialValue::isImplicitInitialValue):
     14        * css/CSSMutableStyleDeclaration.cpp:
     15        (WebCore::CSSMutableStyleDeclaration::getPropertyValue):
     16        (WebCore::CSSMutableStyleDeclaration::getLayeredShorthandValue):
     17        * css/CSSMutableStyleDeclaration.h:
     18        * css/CSSValue.h:
     19        (WebCore::CSSValue::isImplicitInitialValue):
     20        * css/cssparser.cpp:
     21        (WebCore::CSSParser::parseValue):
     22        (WebCore::CSSParser::parseBackgroundShorthand):
     23        (WebCore::CSSParser::parseShorthand):
     24
    1252007-05-22  Darin Adler  <darin@apple.com>
    226
  • trunk/WebCore/css/CSSInitialValue.h

    r18850 r21652  
    3030class CSSInitialValue : public CSSValue {
    3131public:
     32    CSSInitialValue(bool implicit)
     33    :m_implicit(implicit)
     34    {}
     35
    3236    virtual unsigned short cssValueType() const;
    3337    virtual String cssText() const;
     38       
     39    virtual bool isImplicitInitialValue() const { return m_implicit; }
     40
     41private:
     42    bool m_implicit;
    3443};
    3544
  • trunk/WebCore/css/CSSMutableStyleDeclaration.cpp

    r21224 r21652  
    2929#include "CSSProperty.h"
    3030#include "CSSStyleSheet.h"
     31#include "CSSValueList.h"
    3132#include "Document.h"
    3233#include "ExceptionCode.h"
    3334#include "StyledElement.h"
     35
     36using namespace std;
    3437
    3538namespace WebCore {
     
    8285            const int properties[2] = { CSS_PROP_BACKGROUND_POSITION_X,
    8386                                        CSS_PROP_BACKGROUND_POSITION_Y };
    84             return getShorthandValue(properties, 2);
     87            return getLayeredShorthandValue(properties, 2);
    8588        }
    8689        case CSS_PROP_BACKGROUND: {
    87             const int properties[5] = { CSS_PROP_BACKGROUND_IMAGE, CSS_PROP_BACKGROUND_REPEAT,
    88                                         CSS_PROP_BACKGROUND_ATTACHMENT, CSS_PROP_BACKGROUND_POSITION,
    89                                         CSS_PROP_BACKGROUND_COLOR };
    90             return getShorthandValue(properties, 5);
     90            const int properties[6] = { CSS_PROP_BACKGROUND_IMAGE, CSS_PROP_BACKGROUND_REPEAT,
     91                                        CSS_PROP_BACKGROUND_ATTACHMENT, CSS_PROP_BACKGROUND_POSITION_X,
     92                                        CSS_PROP_BACKGROUND_POSITION_Y, CSS_PROP_BACKGROUND_COLOR };
     93            return getLayeredShorthandValue(properties, 6);
    9194        }
    9295        case CSS_PROP_BORDER: {
     
    170173        }
    171174    }
     175    return res;
     176}
     177
     178String CSSMutableStyleDeclaration::getLayeredShorthandValue(const int* properties, unsigned number) const
     179{
     180    String res;
     181    unsigned i;
     182    unsigned j;
     183
     184    // Begin by collecting the properties into an array.
     185    Vector< RefPtr<CSSValue> > values(number);
     186    unsigned numLayers = 0;
     187   
     188    for (i = 0; i < number; ++i) {
     189        values[i] = getPropertyCSSValue(properties[i]);
     190        if (values[i]) {
     191            if (values[i]->isValueList()) {
     192                CSSValueList* valueList = static_cast<CSSValueList*>(values[i].get());
     193                numLayers = max(valueList->length(), numLayers);
     194            } else
     195                numLayers = max(1U, numLayers);
     196        }
     197    }
     198   
     199    // Now stitch the properties together.  Implicit initial values are flagged as such and
     200    // can safely be omitted.
     201    for (i = 0; i < numLayers; i++) {
     202        String layerRes;
     203        for (j = 0; j < number; j++) {
     204            RefPtr<CSSValue> value;
     205            if (values[j]) {
     206                if (values[j]->isValueList())
     207                    value = static_cast<CSSValueList*>(values[j].get())->item(i);
     208                else {
     209                    value = values[j];
     210                   
     211                    // Color only belongs in the last layer.
     212                    if (properties[j] == CSS_PROP_BACKGROUND_COLOR) {
     213                        if (i != numLayers - 1)
     214                            value = 0;
     215                    } else if (i != 0) // Other singletons only belong in the first layer.
     216                        value = 0;
     217                }
     218            }
     219           
     220            if (value && !value->isImplicitInitialValue()) {
     221                if (!layerRes.isNull())
     222                    layerRes += " ";
     223                layerRes += value->cssText();
     224            }
     225        }
     226       
     227        if (!layerRes.isNull()) {
     228            if (!res.isNull())
     229                res += ", ";
     230            res += layerRes;
     231        }
     232    }
     233
    172234    return res;
    173235}
  • trunk/WebCore/css/CSSMutableStyleDeclaration.h

    r21224 r21652  
    105105private:
    106106    String getShorthandValue(const int* properties, int number) const;
     107    String getLayeredShorthandValue(const int* properties, unsigned number) const;
    107108    String get4Values(const int* properties) const;
    108109 
  • trunk/WebCore/css/CSSValue.h

    r18874 r21652  
    4747    virtual bool isValue() { return true; }
    4848    virtual bool isFontValue() { return false; }
     49    virtual bool isImplicitInitialValue() const { return false; }
    4950};
    5051
  • trunk/WebCore/css/cssparser.cpp

    r21026 r21652  
    515515        if (num != 1)
    516516            return false;
    517         addProperty(propId, new CSSInitialValue(), important);
     517        addProperty(propId, new CSSInitialValue(false), important);
    518518        return true;
    519519    }
     
    15541554
    15551555                if (!parsedProperty[i] && properties[i] != CSS_PROP_BACKGROUND_COLOR) {
    1556                     addBackgroundValue(values[i], new CSSInitialValue());
     1556                    addBackgroundValue(values[i], new CSSInitialValue(true));
    15571557                    if (properties[i] == CSS_PROP_BACKGROUND_POSITION)
    1558                         addBackgroundValue(positionYValue, new CSSInitialValue());
     1558                        addBackgroundValue(positionYValue, new CSSInitialValue(true));
    15591559                }
    15601560                parsedProperty[i] = false;
     
    15871587    for (i = 0; i < numProperties; ++i) {
    15881588        if (!parsedProperty[i]) {
    1589             addBackgroundValue(values[i], new CSSInitialValue());
     1589            addBackgroundValue(values[i], new CSSInitialValue(true));
    15901590            if (properties[i] == CSS_PROP_BACKGROUND_POSITION)
    1591                 addBackgroundValue(positionYValue, new CSSInitialValue());
     1591                addBackgroundValue(positionYValue, new CSSInitialValue(true));
    15921592        }
    15931593    }
     
    16431643    for (int i = 0; i < numProperties; ++i) {
    16441644        if (!fnd[i])
    1645             addProperty(properties[i], new CSSInitialValue(), important);
     1645            addProperty(properties[i], new CSSInitialValue(true), important);
    16461646    }
    16471647    m_implicitShorthand = false;
Note: See TracChangeset for help on using the changeset viewer.