Changeset 11481 in webkit


Ignore:
Timestamp:
Dec 6, 2005, 5:12:38 PM (20 years ago)
Author:
hyatt
Message:

Add support for more methods for exposing more useful style information.

getMatchedCSSRules can be used to obtain the matched sheet rules for an element. In Obj-C
it will also include user/user agent sheet rules.

Also add support for tracking the original shorthand in which a property was declared, as well
as whether the property was just implicitly set rather than explicitly mentioned (e.g., if it was
an omitted piece of a shorthand). The new methods on CSSStyleDeclaration are getPropertyShorthand
and isPropertyImplicit.

Reviewed by mjs

Test: fast/inspector/style.html

  • khtml/css/css_computedstyle.h: (DOM::CSSComputedStyleDeclarationImpl::getPropertyShorthand): (DOM::CSSComputedStyleDeclarationImpl::isPropertyImplicit):
  • khtml/css/css_valueimpl.cpp: (DOM::CSSStyleDeclarationImpl::getPropertyShorthand): (DOM::CSSStyleDeclarationImpl::isPropertyImplicit): (DOM::CSSMutableStyleDeclarationImpl::getPropertyPriority): (DOM::CSSMutableStyleDeclarationImpl::getPropertyShorthand): (DOM::CSSMutableStyleDeclarationImpl::isPropertyImplicit): (DOM::CSSProperty::cssText): (DOM::operator==):
  • khtml/css/css_valueimpl.h: (DOM::CSSProperty::CSSProperty): (DOM::CSSProperty::operator=): (DOM::CSSProperty::~CSSProperty): (DOM::CSSProperty::setValue): (DOM::CSSProperty::shorthandID): (DOM::CSSProperty::isImportant): (DOM::CSSProperty::isImplicit):
  • khtml/css/cssparser.cpp: (CSSParser::CSSParser): (CSSParser::addProperty): (CSSParser::parseValue): (CSSParser::parseBackgroundShorthand): (CSSParser::parseShorthand): (CSSParser::parse4Values): (CSSParser::parseBackgroundPosition): (CSSParser::parseBackgroundProperty):
  • khtml/css/cssparser.h: (DOM::CSSParser::enterShorthand): (DOM::CSSParser::exitShorthand): (DOM::CSSParser::inShorthand):
  • khtml/css/cssstyleselector.cpp: (khtml::CSSStyleSelector::CSSStyleSelector): (khtml::CSSStyleSelector::matchRules): (khtml::CSSStyleSelector::matchRulesForList): (khtml::CSSStyleSelector::initForStyleResolve): (khtml::CSSStyleSelector::styleRulesForElement): (khtml::CSSStyleSelector::pseudoStyleRulesForElement):
  • khtml/css/cssstyleselector.h:
  • khtml/ecma/kjs_css.cpp: (KJS::DOMCSSStyleDeclarationProtoFunc::callAsFunction):
  • khtml/ecma/kjs_css.h: (KJS::DOMCSSStyleDeclaration::):
  • khtml/ecma/kjs_views.cpp: (KJS::DOMAbstractViewProtoFunc::callAsFunction):
  • khtml/ecma/kjs_views.h: (KJS::DOMAbstractView::):
  • khtml/xml/dom2_viewsimpl.cpp: (DOM::AbstractViewImpl::getComputedStyle): (DOM::AbstractViewImpl::getMatchedCSSRules):
  • khtml/xml/dom2_viewsimpl.h:
  • kwq/DOM-CSS.mm: (-[DOMCSSStyleDeclaration getPropertyShorthand:]): (-[DOMCSSStyleDeclaration isPropertyImplicit:]): (-[DOMDocument getMatchedCSSRules::]):
  • kwq/DOMPrivate.h:
Location:
trunk/WebCore
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog-2005-12-19

    r11472 r11481  
     1<<<<<<< ChangeLog
     22005-12-05  David Hyatt  <hyatt@apple.com>
     3
     4        Add support for more methods for exposing more useful style information.
     5
     6        getMatchedCSSRules can be used to obtain the matched sheet rules for an element.  In Obj-C
     7        it will also include user/user agent sheet rules.
     8
     9        Also add support for tracking the original shorthand in which a property was declared, as well
     10        as whether the property was just implicitly set rather than explicitly mentioned (e.g., if it was
     11        an omitted piece of a shorthand).  The new methods on CSSStyleDeclaration are getPropertyShorthand
     12        and isPropertyImplicit.
     13       
     14        Reviewed by mjs
     15
     16        Test: fast/inspector/style.html
     17
     18        * khtml/css/css_computedstyle.h:
     19        (DOM::CSSComputedStyleDeclarationImpl::getPropertyShorthand):
     20        (DOM::CSSComputedStyleDeclarationImpl::isPropertyImplicit):
     21        * khtml/css/css_valueimpl.cpp:
     22        (DOM::CSSStyleDeclarationImpl::getPropertyShorthand):
     23        (DOM::CSSStyleDeclarationImpl::isPropertyImplicit):
     24        (DOM::CSSMutableStyleDeclarationImpl::getPropertyPriority):
     25        (DOM::CSSMutableStyleDeclarationImpl::getPropertyShorthand):
     26        (DOM::CSSMutableStyleDeclarationImpl::isPropertyImplicit):
     27        (DOM::CSSProperty::cssText):
     28        (DOM::operator==):
     29        * khtml/css/css_valueimpl.h:
     30        (DOM::CSSProperty::CSSProperty):
     31        (DOM::CSSProperty::operator=):
     32        (DOM::CSSProperty::~CSSProperty):
     33        (DOM::CSSProperty::setValue):
     34        (DOM::CSSProperty::shorthandID):
     35        (DOM::CSSProperty::isImportant):
     36        (DOM::CSSProperty::isImplicit):
     37        * khtml/css/cssparser.cpp:
     38        (CSSParser::CSSParser):
     39        (CSSParser::addProperty):
     40        (CSSParser::parseValue):
     41        (CSSParser::parseBackgroundShorthand):
     42        (CSSParser::parseShorthand):
     43        (CSSParser::parse4Values):
     44        (CSSParser::parseBackgroundPosition):
     45        (CSSParser::parseBackgroundProperty):
     46        * khtml/css/cssparser.h:
     47        (DOM::CSSParser::enterShorthand):
     48        (DOM::CSSParser::exitShorthand):
     49        (DOM::CSSParser::inShorthand):
     50        * khtml/css/cssstyleselector.cpp:
     51        (khtml::CSSStyleSelector::CSSStyleSelector):
     52        (khtml::CSSStyleSelector::matchRules):
     53        (khtml::CSSStyleSelector::matchRulesForList):
     54        (khtml::CSSStyleSelector::initForStyleResolve):
     55        (khtml::CSSStyleSelector::styleRulesForElement):
     56        (khtml::CSSStyleSelector::pseudoStyleRulesForElement):
     57        * khtml/css/cssstyleselector.h:
     58        * khtml/ecma/kjs_css.cpp:
     59        (KJS::DOMCSSStyleDeclarationProtoFunc::callAsFunction):
     60        * khtml/ecma/kjs_css.h:
     61        (KJS::DOMCSSStyleDeclaration::):
     62        * khtml/ecma/kjs_views.cpp:
     63        (KJS::DOMAbstractViewProtoFunc::callAsFunction):
     64        * khtml/ecma/kjs_views.h:
     65        (KJS::DOMAbstractView::):
     66        * khtml/xml/dom2_viewsimpl.cpp:
     67        (DOM::AbstractViewImpl::getComputedStyle):
     68        (DOM::AbstractViewImpl::getMatchedCSSRules):
     69        * khtml/xml/dom2_viewsimpl.h:
     70        * kwq/DOM-CSS.mm:
     71        (-[DOMCSSStyleDeclaration getPropertyShorthand:]):
     72        (-[DOMCSSStyleDeclaration isPropertyImplicit:]):
     73        (-[DOMDocument getMatchedCSSRules::]):
     74        * kwq/DOMPrivate.h:
     75
     76=======
    1772005-12-04  Maciej Stachowiak  <mjs@apple.com>
    278
     
    253329        logic for the "oldUnder" variable as for the "targetNode" variable.
    254330
     331>>>>>>> 1.482
    2553322005-12-05  John Sullivan  <sullivan@apple.com>
    256333
  • trunk/WebCore/khtml/css/css_computedstyle.h

    r11375 r11481  
    5151    virtual DOMString getPropertyValue(int propertyID) const;
    5252    virtual bool getPropertyPriority(int propertyID) const;
     53    virtual int getPropertyShorthand(int propertyID) const { return -1; }
     54    virtual bool isPropertyImplicit(int propertyID) const { return true; }
    5355
    5456    virtual CSSMutableStyleDeclarationImpl *copy() const;
  • trunk/WebCore/khtml/css/css_valueimpl.cpp

    r11333 r11481  
    132132}
    133133
     134DOMString CSSStyleDeclarationImpl::getPropertyShorthand(const DOMString &propertyName)
     135{
     136    int propID = propertyID(propertyName);
     137    if (!propID)
     138        return DOMString();
     139    int shorthandID = getPropertyShorthand(propID);
     140    if (!shorthandID)
     141        return DOMString();
     142    return getPropertyName(shorthandID);
     143}
     144
     145bool CSSStyleDeclarationImpl::isPropertyImplicit(const DOMString &propertyName)
     146{
     147    int propID = propertyID(propertyName);
     148    if (!propID)
     149        return false;
     150    return isPropertyImplicit(propID);
     151}
     152
    134153void CSSStyleDeclarationImpl::setProperty(const DOMString &propertyName, const DOMString &value, const DOMString &priority, int &exception)
    135154{
     
    386405    QValueListConstIterator<CSSProperty> end;
    387406    for (QValueListConstIterator<CSSProperty> it = m_values.begin(); it != end; ++it)
    388         if (propertyID == (*it).m_id)
    389             return (*it).m_bImportant;
     407        if (propertyID == (*it).id())
     408            return (*it).isImportant();
     409    return false;
     410}
     411
     412int CSSMutableStyleDeclarationImpl::getPropertyShorthand(int propertyID) const
     413{
     414    QValueListConstIterator<CSSProperty> end;
     415    for (QValueListConstIterator<CSSProperty> it = m_values.begin(); it != end; ++it)
     416        if (propertyID == (*it).id())
     417            return (*it).shorthandID();
     418    return false;
     419}
     420
     421bool CSSMutableStyleDeclarationImpl::isPropertyImplicit(int propertyID) const
     422{
     423    QValueListConstIterator<CSSProperty> end;
     424    for (QValueListConstIterator<CSSProperty> it = m_values.begin(); it != end; ++it)
     425        if (propertyID == (*it).id())
     426            return (*it).isImplicit();
    390427    return false;
    391428}
     
    13381375DOMString CSSProperty::cssText() const
    13391376{
    1340     return getPropertyName(m_id) + DOMString(": ") + m_value->cssText() + (m_bImportant ? DOMString(" !important") : DOMString()) + DOMString("; ");
     1377    return getPropertyName(id()) + DOMString(": ") + m_value->cssText() + (isImportant() ? DOMString(" !important") : DOMString()) + DOMString("; ");
    13411378}
    13421379
    13431380bool operator==(const CSSProperty &a, const CSSProperty &b)
    13441381{
    1345     return a.m_id == b.m_id && a.m_bImportant == b.m_bImportant && a.m_value == b.m_value;
    1346 }
    1347 
    1348 }
     1382    return a.m_id == b.m_id && a.m_important == b.m_important && a.m_value == b.m_value;
     1383}
     1384
     1385}
  • trunk/WebCore/khtml/css/css_valueimpl.h

    r11272 r11481  
    6464    DOMString getPropertyValue(const DOMString &propertyName);
    6565    DOMString getPropertyPriority(const DOMString &propertyName);
     66    DOMString getPropertyShorthand(const DOMString& propertyName);
     67    bool isPropertyImplicit(const DOMString& propertyName);
     68   
    6669    virtual CSSValueImpl *getPropertyCSSValue(int propertyID) const = 0;
    6770    virtual DOMString getPropertyValue(int propertyID) const = 0;
    6871    virtual bool getPropertyPriority(int propertyID) const = 0;
     72    virtual int getPropertyShorthand(int propertyID) const = 0;
     73    virtual bool isPropertyImplicit(int propertyID) const = 0;
    6974
    7075    void setProperty(const DOMString &propertyName, const DOMString &value, const DOMString &priority, int &exception);
     
    407412{
    408413public:
    409     CSSProperty() : m_id(-1), m_bImportant(false), m_value(0)
     414    CSSProperty(int propID, CSSValueImpl *value, bool important = false, int shorthandID = 0, bool implicit = false)
     415        : m_id(propID), m_shorthandID(shorthandID), m_important(important), m_implicit(implicit), m_value(value)
    410416    {
    411     }
    412     CSSProperty(int propID, CSSValueImpl *value, bool important = false)
    413         : m_id(propID), m_bImportant(important), m_value(value)
    414     {
    415         if (value) value->ref();
    416     }
     417        if (value)
     418            value->ref();
     419    }
     420   
    417421    CSSProperty(const CSSProperty& o)
    418422    {
    419423        m_id = o.m_id;
    420         m_bImportant = o.m_bImportant;
     424        m_shorthandID = o.m_shorthandID;
     425        m_important = o.m_important;
     426        m_implicit = o.m_implicit;
    421427        m_value = o.m_value;
    422         if (m_value) m_value->ref();
    423     }
     428        if (m_value)
     429            m_value->ref();
     430    }
     431   
    424432    CSSProperty &operator=(const CSSProperty& o)
    425433    {
    426         if (o.m_value) o.m_value->ref();
    427         if (m_value) m_value->deref();
     434        if (o.m_value)
     435            o.m_value->ref();
     436        if (m_value)
     437            m_value->deref();
    428438        m_id = o.m_id;
    429         m_bImportant = o.m_bImportant;
     439        m_shorthandID = o.m_shorthandID;
     440        m_important = o.m_important;
    430441        m_value = o.m_value;
    431442        return *this;
    432443    }
     444   
    433445    ~CSSProperty() {
    434         if(m_value) m_value->deref();
     446        if (m_value)
     447            m_value->deref();
    435448    }
    436449
    437450    void setValue(CSSValueImpl *val) {
    438         if (val) val->ref();
    439         if (m_value) m_value->deref();
     451        if (val)
     452            val->ref();
     453        if (m_value)
     454            m_value->deref();
    440455        m_value = val;
    441456    }
    442457
    443458    int id() const { return m_id; }
    444     bool isImportant() const { return m_bImportant; }
     459    int shorthandID() const { return m_shorthandID; }
     460   
     461    bool isImportant() const { return m_important; }
     462    bool isImplicit() const { return m_implicit; }
     463
    445464    CSSValueImpl *value() const { return m_value; }
    446465   
     
    448467
    449468    // make sure the following fits in 4 bytes.
    450     int  m_id;
    451     bool m_bImportant;
     469    int m_id;
     470    int m_shorthandID;  // If this property was set as part of a shorthand, gives the shorthand.
     471    bool m_important : 1;
     472    bool m_implicit  : 1; // Whether or not the property was set implicitly as the result of a shorthand.
    452473
    453474    friend bool operator==(const CSSProperty &, const CSSProperty &);
     
    479500    virtual DOMString getPropertyValue(int propertyID) const;
    480501    virtual bool getPropertyPriority(int propertyID) const;
     502    virtual int getPropertyShorthand(int propertyID) const;
     503    virtual bool isPropertyImplicit(int propertyID) const;
    481504
    482505    virtual void setProperty(int propertyId, const DOMString &value, bool important, int &exceptionCode);
  • trunk/WebCore/khtml/css/cssparser.cpp

    r11272 r11481  
    33 *
    44 * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
    5  * Copyright (C) 2004 Apple Computer, Inc.
     5 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
     6 * Copyright (C) 2004, 2005 Apple Computer, Inc.
    67 *
    78 * This library is free software; you can redistribute it and/or
     
    103104    id = 0;
    104105    important = false;
    105     inParseShortHand = false;
    106    
     106    m_inParseShorthand = 0;
     107    m_currentShorthand = 0;
     108    m_implicitShorthand = false;
     109
    107110    defaultNamespace = starAtom;
    108111   
     
    313316
    314317
    315 void CSSParser::addProperty( int propId, CSSValueImpl *value, bool important )
    316 {
    317     CSSProperty *prop = new CSSProperty;
    318     prop->m_id = propId;
    319     prop->setValue( value );
    320     prop->m_bImportant = important;
    321 
    322     if ( numParsedProperties >= maxParsedProperties ) {
     318void CSSParser::addProperty(int propId, CSSValueImpl *value, bool important)
     319{
     320    CSSProperty *prop = new CSSProperty(propId, value, important, m_currentShorthand, m_implicitShorthand);
     321    if (numParsedProperties >= maxParsedProperties) {
    323322        maxParsedProperties += 32;
    324323        parsedProperties = (CSSProperty **)fastRealloc(parsedProperties,
     
    425424        return false;
    426425
    427     int id = 0;
    428     id = value->id;
     426    int id = value->id;
    429427
    430428    if (id == CSS_VAL_INHERIT) {
     
    520518        break;
    521519
    522     /* Start of supported CSS properties with validation. This is needed for parseShortHand to work
     520    /* Start of supported CSS properties with validation. This is needed for parseShorthand to work
    523521     * correctly and allows optimization in khtml::applyRule(..)
    524522     */
     
    10441042                                    CSS_PROP__KHTML_MARQUEE_REPETITION,
    10451043                                    CSS_PROP__KHTML_MARQUEE_STYLE, CSS_PROP__KHTML_MARQUEE_SPEED };
    1046         return parseShortHand(properties, 5, important);
     1044        return parseShorthand(propId, properties, 5, important);
    10471045    }
    10481046    case CSS_PROP__KHTML_MARQUEE_DIRECTION:
     
    11591157        const int properties[3] = { CSS_PROP_BORDER_WIDTH, CSS_PROP_BORDER_STYLE,
    11601158                                    CSS_PROP_BORDER_COLOR };
    1161         return parseShortHand(properties, 3, important);
     1159        return parseShorthand(propId, properties, 3, important);
    11621160    }
    11631161    case CSS_PROP_BORDER_TOP:
     
    11661164        const int properties[3] = { CSS_PROP_BORDER_TOP_WIDTH, CSS_PROP_BORDER_TOP_STYLE,
    11671165                                    CSS_PROP_BORDER_TOP_COLOR};
    1168         return parseShortHand(properties, 3, important);
     1166        return parseShorthand(propId, properties, 3, important);
    11691167    }
    11701168    case CSS_PROP_BORDER_RIGHT:
     
    11731171        const int properties[3] = { CSS_PROP_BORDER_RIGHT_WIDTH, CSS_PROP_BORDER_RIGHT_STYLE,
    11741172                                    CSS_PROP_BORDER_RIGHT_COLOR };
    1175         return parseShortHand(properties, 3, important);
     1173        return parseShorthand(propId, properties, 3, important);
    11761174    }
    11771175    case CSS_PROP_BORDER_BOTTOM:
     
    11801178        const int properties[3] = { CSS_PROP_BORDER_BOTTOM_WIDTH, CSS_PROP_BORDER_BOTTOM_STYLE,
    11811179                                    CSS_PROP_BORDER_BOTTOM_COLOR };
    1182         return parseShortHand(properties, 3, important);
     1180        return parseShorthand(propId, properties, 3, important);
    11831181    }
    11841182    case CSS_PROP_BORDER_LEFT:
     
    11871185        const int properties[3] = { CSS_PROP_BORDER_LEFT_WIDTH, CSS_PROP_BORDER_LEFT_STYLE,
    11881186                                    CSS_PROP_BORDER_LEFT_COLOR };
    1189         return parseShortHand(properties, 3, important);
     1187        return parseShorthand(propId, properties, 3, important);
    11901188    }
    11911189    case CSS_PROP_OUTLINE:
     
    11941192        const int properties[3] = { CSS_PROP_OUTLINE_WIDTH, CSS_PROP_OUTLINE_STYLE,
    11951193                                    CSS_PROP_OUTLINE_COLOR };
    1196         return parseShortHand(properties, 3, important);
     1194        return parseShorthand(propId, properties, 3, important);
    11971195    }
    11981196    case CSS_PROP_BORDER_COLOR:
     
    12011199        const int properties[4] = { CSS_PROP_BORDER_TOP_COLOR, CSS_PROP_BORDER_RIGHT_COLOR,
    12021200                                    CSS_PROP_BORDER_BOTTOM_COLOR, CSS_PROP_BORDER_LEFT_COLOR };
    1203         return parse4Values(properties, important);
     1201        return parse4Values(propId, properties, important);
    12041202    }
    12051203    case CSS_PROP_BORDER_WIDTH:
     
    12081206        const int properties[4] = { CSS_PROP_BORDER_TOP_WIDTH, CSS_PROP_BORDER_RIGHT_WIDTH,
    12091207                                    CSS_PROP_BORDER_BOTTOM_WIDTH, CSS_PROP_BORDER_LEFT_WIDTH };
    1210         return parse4Values(properties, important);
     1208        return parse4Values(propId, properties, important);
    12111209    }
    12121210    case CSS_PROP_BORDER_STYLE:
     
    12151213        const int properties[4] = { CSS_PROP_BORDER_TOP_STYLE, CSS_PROP_BORDER_RIGHT_STYLE,
    12161214                                    CSS_PROP_BORDER_BOTTOM_STYLE, CSS_PROP_BORDER_LEFT_STYLE };
    1217         return parse4Values(properties, important);
     1215        return parse4Values(propId, properties, important);
    12181216    }
    12191217    case CSS_PROP_MARGIN:
     
    12221220        const int properties[4] = { CSS_PROP_MARGIN_TOP, CSS_PROP_MARGIN_RIGHT,
    12231221                                    CSS_PROP_MARGIN_BOTTOM, CSS_PROP_MARGIN_LEFT };
    1224         return parse4Values(properties, important);
     1222        return parse4Values(propId, properties, important);
    12251223    }
    12261224    case CSS_PROP_PADDING:
     
    12291227        const int properties[4] = { CSS_PROP_PADDING_TOP, CSS_PROP_PADDING_RIGHT,
    12301228                                    CSS_PROP_PADDING_BOTTOM, CSS_PROP_PADDING_LEFT };
    1231         return parse4Values(properties, important);
     1229        return parse4Values(propId, properties, important);
    12321230    }
    12331231    case CSS_PROP_FONT:
    12341232        // [ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]?
    12351233        // 'font-family' ] | caption | icon | menu | message-box | small-caption | status-bar | inherit
    1236         if ( id >= CSS_VAL_CAPTION && id <= CSS_VAL_STATUS_BAR )
     1234        if (id >= CSS_VAL_CAPTION && id <= CSS_VAL_STATUS_BAR)
    12371235            valid_primitive = true;
    12381236        else
     
    12431241        const int properties[3] = { CSS_PROP_LIST_STYLE_TYPE, CSS_PROP_LIST_STYLE_POSITION,
    12441242                                    CSS_PROP_LIST_STYLE_IMAGE };
    1245         return parseShortHand(properties, 3, important);
     1243        return parseShorthand(propId, properties, 3, important);
    12461244    }
    12471245    default:
     
    13071305        CSS_PROP_BACKGROUND_ORIGIN, CSS_PROP_BACKGROUND_COLOR };
    13081306   
    1309     inParseShortHand = true;
    1310    
     1307    enterShorthand(CSS_PROP_BACKGROUND);
     1308
    13111309    bool parsedProperty[numProperties] = { false }; // compiler will repeat false as necessary
    13121310    CSSValueImpl* values[numProperties] = { 0 }; // compiler will repeat 0 as necessary
     
    13751373    }
    13761374   
    1377     inParseShortHand = false;
     1375    exitShorthand();
    13781376    return true;
    13791377
    13801378fail:
    1381     inParseShortHand = false;
     1379    exitShorthand();
    13821380    for (int k = 0; k < numProperties; k++)
    13831381        delete values[k];
     
    13861384}
    13871385
    1388 bool CSSParser::parseShortHand( const int *properties, int numProperties, bool important )
    1389 {
    1390     /* We try to match as many properties as possible
    1391      * We setup an array of booleans to mark which property has been found,
    1392      * and we try to search for properties until it makes no longer any sense
    1393      */
    1394     inParseShortHand = true;
     1386bool CSSParser::parseShorthand(int propId, const int *properties, int numProperties, bool important)
     1387{
     1388    // We try to match as many properties as possible
     1389    // We set up an array of booleans to mark which property has been found,
     1390    // and we try to search for properties until it makes no longer any sense.
     1391    enterShorthand(propId);
    13951392
    13961393    bool found = false;
    1397     bool fnd[6]; //Trust me ;)
    1398     for( int i = 0; i < numProperties; i++ )
     1394    bool fnd[6]; // Trust me ;)
     1395    for (int i = 0; i < numProperties; i++)
    13991396        fnd[i] = false;
    14001397
    1401 #ifdef CSS_DEBUG
    1402     kdDebug(6080) << "PSH: numProperties=" << numProperties << endl;
    1403 #endif
    1404 
    1405     while ( valueList->current() ) {
     1398    while (valueList->current()) {
    14061399        found = false;
    1407         // qDebug("outer loop" );
    1408         for (int propIndex = 0; !found && propIndex < numProperties; ++propIndex) {
     1400        for (int propIndex = 0; !found && propIndex < numProperties; ++propIndex) {
    14091401            if (!fnd[propIndex]) {
    1410 #ifdef CSS_DEBUG
    1411                 kdDebug(6080) << "LOOKING FOR: " << getPropertyName(properties[propIndex]).qstring() << endl;
    1412 #endif
    1413                 if ( parseValue( properties[propIndex], important ) ) {
     1402                if (parseValue( properties[propIndex], important))
    14141403                    fnd[propIndex] = found = true;
    1415 #ifdef CSS_DEBUG
    1416                     kdDebug(6080) << "FOUND: " << getPropertyName(properties[propIndex]).qstring() << endl;
    1417 #endif
    1418                 }
    14191404            }
    14201405        }
     1406
    14211407        // if we didn't find at least one match, this is an
    14221408        // invalid shorthand and we have to ignore it
    14231409        if (!found) {
    1424 #ifdef CSS_DEBUG
    1425             qDebug("didn't find anything" );
    1426 #endif
    1427             inParseShortHand = false;
     1410            exitShorthand();
    14281411            return false;
    14291412        }
     
    14311414   
    14321415    // Fill in any remaining properties with the initial value.
     1416    m_implicitShorthand = true;
    14331417    for (int i = 0; i < numProperties; ++i) {
    14341418        if (!fnd[i])
    14351419            addProperty(properties[i], new CSSInitialValueImpl(), important);
    14361420    }
    1437    
    1438     inParseShortHand = false;
    1439 #ifdef CSS_DEBUG
    1440     kdDebug( 6080 ) << "parsed shorthand" << endl;
    1441 #endif
     1421    m_implicitShorthand = false;
     1422
     1423    exitShorthand();
    14421424    return true;
    14431425}
    14441426
    1445 bool CSSParser::parse4Values( const int *properties,  bool important )
     1427bool CSSParser::parse4Values(int propId, const int *properties,  bool important)
    14461428{
    14471429    /* From the CSS 2 specs, 8.3
     
    14521434     * right, bottom, and left, respectively.
    14531435     */
    1454 
    1455     int num = inParseShortHand ? 1 : valueList->numValues;
    1456     // qDebug("parse4Values: num=%d", num );
     1436   
     1437    int num = inShorthand() ? 1 : valueList->numValues;
     1438   
     1439    enterShorthand(propId);
    14571440
    14581441    // the order is top, right, bottom, left
    1459     switch( num ) {
    1460     case 1: {
    1461         if( !parseValue( properties[0], important ) ) return false;
    1462         CSSValueImpl *value = parsedProperties[numParsedProperties-1]->value();
    1463         addProperty( properties[1], value, important );
    1464         addProperty( properties[2], value, important );
    1465         addProperty( properties[3], value, important );
    1466         return true;
    1467     }
    1468     case 2: {
    1469 
    1470         if( !parseValue( properties[0], important ) ) return false;
    1471         if( !parseValue( properties[1], important ) ) return false;
    1472         CSSValueImpl *value = parsedProperties[numParsedProperties-2]->value();
    1473         addProperty( properties[2], value, important );
    1474         value = parsedProperties[numParsedProperties-2]->value();
    1475         addProperty( properties[3], value, important );
    1476         return true;
    1477     }
    1478     case 3: {
    1479         if( !parseValue( properties[0], important ) ) return false;
    1480         if( !parseValue( properties[1], important ) ) return false;
    1481         if( !parseValue( properties[2], important ) ) return false;
    1482         CSSValueImpl *value = parsedProperties[numParsedProperties-2]->value();
    1483         addProperty( properties[3], value, important );
    1484         return true;
    1485     }
    1486     case 4: {
    1487         if( !parseValue( properties[0], important ) ) return false;
    1488         if( !parseValue( properties[1], important ) ) return false;
    1489         if( !parseValue( properties[2], important ) ) return false;
    1490         if( !parseValue( properties[3], important ) ) return false;
    1491         return true;
    1492     }
    1493     default:
    1494         return false;
    1495     }
     1442    switch (num) {
     1443        case 1: {
     1444            if (!parseValue(properties[0], important)) {
     1445                exitShorthand();
     1446                return false;
     1447            }
     1448            CSSValueImpl *value = parsedProperties[numParsedProperties-1]->value();
     1449            m_implicitShorthand = true;
     1450            addProperty(properties[1], value, important);
     1451            addProperty(properties[2], value, important);
     1452            addProperty(properties[3], value, important);
     1453            m_implicitShorthand = false;
     1454            break;
     1455        }
     1456        case 2: {
     1457            if (!parseValue(properties[0], important) || !parseValue(properties[1], important)) {
     1458                exitShorthand();
     1459                return false;
     1460            }
     1461            CSSValueImpl *value = parsedProperties[numParsedProperties-2]->value();
     1462            m_implicitShorthand = true;
     1463            addProperty(properties[2], value, important);
     1464            value = parsedProperties[numParsedProperties-2]->value();
     1465            addProperty(properties[3], value, important);
     1466            m_implicitShorthand = false;
     1467            break;
     1468        }
     1469        case 3: {
     1470            if (!parseValue(properties[0], important) || !parseValue(properties[1], important) ||
     1471                !parseValue(properties[2], important)) {
     1472                exitShorthand();
     1473                return false;
     1474            }
     1475            CSSValueImpl *value = parsedProperties[numParsedProperties-2]->value();
     1476            m_implicitShorthand = true;
     1477            addProperty(properties[3], value, important);
     1478            m_implicitShorthand = false;
     1479            break;
     1480        }
     1481        case 4: {
     1482            if (!parseValue(properties[0], important) || !parseValue(properties[1], important) ||
     1483                !parseValue(properties[2], important) || !parseValue(properties[3], important)) {
     1484                exitShorthand();
     1485                return false;
     1486            }
     1487            break;
     1488        }
     1489        default: {
     1490            exitShorthand();
     1491            return false;
     1492        }
     1493    }
     1494   
     1495    exitShorthand();
     1496    return true;
    14961497}
    14971498
     
    16291630            valueList->next();
    16301631        else {
    1631             if (!inParseShortHand) {
     1632            if (!inShorthand()) {
    16321633                delete value1;
    16331634                value1 = 0;
     
    17571758        // When parsing the 'background' shorthand property, we let it handle building up the lists for all
    17581759        // properties.
    1759         if (inParseShortHand)
     1760        if (inShorthand())
    17601761            break;
    17611762    }
  • trunk/WebCore/khtml/css/cssparser.h

    r11272 r11481  
    120120        DOM::DocumentImpl *document() const;
    121121
    122         void addProperty( int propId, CSSValueImpl *value, bool important );
     122        void addProperty(int propId, CSSValueImpl *value, bool important);
    123123        bool hasProperties() const { return numParsedProperties > 0; }
    124124        CSSMutableStyleDeclarationImpl *createStyleDeclaration( CSSStyleRuleImpl *rule );
    125125        void clearProperties();
    126126
    127         bool parseValue( int propId, bool important );
    128         bool parseShortHand( const int *properties, int numProperties, bool important );
    129         bool parse4Values( const int *properties, bool important );
    130         bool parseContent( int propId, bool important );
     127        bool parseValue(int propId, bool important);
     128        bool parseShorthand(int propId, const int *properties, int numProperties, bool important);
     129        bool parse4Values(int propId, const int *properties, bool important);
     130        bool parseContent(int propId, bool important);
    131131
    132132        CSSValueImpl* parseBackgroundColor();
     
    171171        int numParsedProperties;
    172172        int maxParsedProperties;
    173         bool inParseShortHand;
     173       
     174        int m_inParseShorthand;
     175        int m_currentShorthand;
     176        bool m_implicitShorthand;
    174177
    175178        AtomicString defaultNamespace;
     
    186189    private:
    187190        void setupParser(const char *prefix, const DOMString &string, const char *suffix);
    188        
     191        void enterShorthand(int propId)
     192        {
     193            if (!(m_inParseShorthand++))
     194                m_currentShorthand = propId;
     195        }
     196        void exitShorthand()
     197        {
     198            if (!(--m_inParseShorthand))
     199                m_currentShorthand = 0;
     200        }
     201        bool inShorthand() const { return m_inParseShorthand; }
     202
    189203        unsigned short *data;
    190204        unsigned short *yytext;
  • trunk/WebCore/khtml/css/cssstyleselector.cpp

    r11333 r11481  
    33 *
    44 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
    5  * Copyright (C) 2004 Apple Computer, Inc.
     5 *           (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
     6 * Copyright (C) 2005 Apple Computer, Inc.
    67 *
    78 * This library is free software; you can redistribute it and/or
     
    255256            m_authorStyle->addRulesFromSheet(static_cast<CSSStyleSheetImpl*>(it.current()), m_medium);
    256257
     258    m_ruleList = 0;
     259    m_collectRulesOnly = false;
     260
    257261    //kdDebug( 6080 ) << "number of style sheets in document " << authorStyleSheets.count() << endl;
    258262    //kdDebug( 6080 ) << "CSSStyleSelector: author style has " << authorStyle->count() << " elements"<< endl;
     
    387391   
    388392    // Now transfer the set of matched rules over to our list of decls.
    389     for (unsigned i = 0; i < m_matchedRuleCount; i++)
    390         addMatchedDeclaration(m_matchedRules[i]->rule()->declaration());
     393    if (!m_collectRulesOnly) {
     394        for (unsigned i = 0; i < m_matchedRuleCount; i++)
     395            addMatchedDeclaration(m_matchedRules[i]->rule()->declaration());
     396    } else {
     397        for (unsigned i = 0; i < m_matchedRuleCount; i++) {
     398            if (!m_ruleList)
     399                m_ruleList = new CSSRuleListImpl();
     400            m_ruleList->append(m_matchedRules[i]->rule());
     401        }
     402    }
    391403}
    392404
     
    406418            // If we're matching normal rules, set a pseudo bit if
    407419            // we really just matched a pseudo-element.
    408             if (dynamicPseudo != RenderStyle::NOPSEUDO && pseudoStyle == RenderStyle::NOPSEUDO)
     420            if (!m_collectRulesOnly && dynamicPseudo != RenderStyle::NOPSEUDO && pseudoStyle == RenderStyle::NOPSEUDO)
    409421                style->setHasPseudoStyle(dynamicPseudo);
    410422            else {
     
    530542    m_matchedDeclCount = 0;
    531543    m_tmpRuleCount = 0;
    532    
     544    m_ruleList = 0;
     545
    533546    fontDirty = false;
    534547}
     
    10431056    if (style->hasFixedBackgroundImage() && view)
    10441057        view->useSlowRepaints();
     1058}
     1059
     1060RefPtr<CSSRuleListImpl> CSSStyleSelector::styleRulesForElement(ElementImpl* e, bool authorOnly)
     1061{
     1062    if (!e->getDocument()->haveStylesheetsLoaded())
     1063        return 0;
     1064
     1065    m_collectRulesOnly = true;
     1066   
     1067    initElementAndPseudoState(e);
     1068    initForStyleResolve(e, 0);
     1069   
     1070    if (!authorOnly) {
     1071        // First we match rules from the user agent sheet.
     1072        int firstUARule = -1, lastUARule = -1;
     1073        matchRules(defaultStyle, firstUARule, lastUARule);
     1074       
     1075        // In quirks mode, we match rules from the quirks user agent sheet.
     1076        if (!strictParsing)
     1077            matchRules(defaultQuirksStyle, firstUARule, lastUARule);
     1078       
     1079        // If our medium is print, then we match rules from the print sheet.
     1080        if (m_medium == "print")
     1081            matchRules(defaultPrintStyle, firstUARule, lastUARule);
     1082
     1083        // Now we check user sheet rules.
     1084        int firstUserRule = -1, lastUserRule = -1;
     1085        matchRules(m_userStyle, firstUserRule, lastUserRule);
     1086    }
     1087
     1088    // Check the rules in author sheets.
     1089    int firstAuthorRule = -1, lastAuthorRule = -1;
     1090    matchRules(m_authorStyle, firstAuthorRule, lastAuthorRule);
     1091   
     1092    m_collectRulesOnly = false;
     1093   
     1094    return m_ruleList;
     1095}
     1096
     1097RefPtr<CSSRuleListImpl> CSSStyleSelector::pseudoStyleRulesForElement(ElementImpl* e, DOMStringImpl* pseudoStyle, bool authorOnly)
     1098{
     1099    // FIXME: Implement this.
     1100    return 0;
    10451101}
    10461102
  • trunk/WebCore/khtml/css/cssstyleselector.h

    r11272 r11481  
    115115        bool canShareStyleWithElement(DOM::NodeImpl* n);
    116116       
     117        // These methods will give back the set of rules that matched for a given element (or a pseudo-element).
     118        RefPtr<DOM::CSSRuleListImpl> styleRulesForElement(DOM::ElementImpl* e, bool authorOnly);
     119        RefPtr<DOM::CSSRuleListImpl> pseudoStyleRulesForElement(DOM::ElementImpl* e, DOM::DOMStringImpl* pseudoStyle, bool authorOnly);
     120
    117121        bool strictParsing;
    118122       
     
    211215        QMemArray<CSSRuleData*> m_tmpRules;
    212216        unsigned m_tmpRuleCount;
    213        
     217        DOM::CSSRuleListImpl* m_ruleList;
     218        bool m_collectRulesOnly;
     219
    214220        QString m_medium;
    215221
  • trunk/WebCore/khtml/ecma/kjs_css.cpp

    r11271 r11481  
    111111  removeProperty        DOMCSSStyleDeclaration::RemoveProperty          DontDelete|Function 1
    112112  getPropertyPriority   DOMCSSStyleDeclaration::GetPropertyPriority     DontDelete|Function 1
     113  getPropertyShorthand  DOMCSSStyleDeclaration::GetPropertyShorthand    DontDelete|Function 1
     114  isPropertyImplicit    DOMCSSStyleDeclaration::IsPropertyImplicit      DontDelete|Function 1
    113115  setProperty           DOMCSSStyleDeclaration::SetProperty             DontDelete|Function 3
    114116  item                  DOMCSSStyleDeclaration::Item                    DontDelete|Function 1
     
    258260    case DOMCSSStyleDeclaration::GetPropertyPriority:
    259261      return getStringOrNull(styleDecl.getPropertyPriority(s));
     262    case DOMCSSStyleDeclaration::GetPropertyShorthand:
     263      return getStringOrNull(styleDecl.getPropertyShorthand(s));
     264    case DOMCSSStyleDeclaration::IsPropertyImplicit:
     265      return Boolean(styleDecl.isPropertyImplicit(s));
    260266    case DOMCSSStyleDeclaration::SetProperty:
    261267      styleDecl.setProperty(s, args[1]->toString(exec).domString(), args[2]->toString(exec).domString(), exception);
  • trunk/WebCore/khtml/ecma/kjs_css.h

    r11375 r11481  
    5858    enum { CssText, Length, ParentRule };
    5959    enum { GetPropertyValue, GetPropertyCSSValue, RemoveProperty,
    60            GetPropertyPriority, SetProperty, Item };
     60           GetPropertyPriority, GetPropertyShorthand, IsPropertyImplicit, SetProperty, Item };
    6161    DOM::CSSStyleDeclarationImpl *impl() const { return m_impl.get(); }
    6262  private:
  • trunk/WebCore/khtml/ecma/kjs_views.cpp

    r11270 r11481  
    3333using DOM::ElementImpl;
    3434using DOM::NodeImpl;
    35 
     35using DOM::CSSRuleListImpl;
    3636
    3737#include "kjs_views.lut.h"
     
    4848@begin DOMAbstractViewProtoTable 1
    4949  getComputedStyle      DOMAbstractView::GetComputedStyle       DontDelete|Function 2
     50  getMatchedCSSRules    DOMAbstractView::GetMatchedCSSRules     DontDelete|Function 2
    5051@end
    5152*/
     
    9394        }
    9495      }
     96    case DOMAbstractView::GetMatchedCSSRules: {
     97        ElementImpl *arg0 = toElement(args[0]);
     98        if (!arg0)
     99            return Undefined(); // throw exception?
     100        else {
     101            // No need to update layout, since we just want the back-end rules.
     102            return getDOMCSSRuleList(exec, abstractView.getMatchedCSSRules(arg0,
     103                                     args[1]->toString(exec).domString().impl()).get());
     104        }
     105    }
    95106  }
    96107  return Undefined();
  • trunk/WebCore/khtml/ecma/kjs_views.h

    r11375 r11481  
    4040    static const ClassInfo info;
    4141    DOM::AbstractViewImpl *impl() const { return m_impl.get(); }
    42     enum { Document, GetComputedStyle };
     42    enum { Document, GetComputedStyle, GetMatchedCSSRules };
    4343  private:
    4444    RefPtr<DOM::AbstractViewImpl> m_impl;
  • trunk/WebCore/khtml/xml/dom2_viewsimpl.cpp

    r11270 r11481  
    2727#include "css/css_computedstyle.h"
    2828#include "dom_elementimpl.h"
     29#include "dom_docimpl.h"
     30#include "cssstyleselector.h"
    2931
    3032namespace DOM {
     
    4244{
    4345    // FIXME: This should work even if we do not have a renderer.
    44    
     46    // FIXME: This needs to work with pseudo elements.
    4547    if (!elt || !elt->renderer())
    4648        return 0;
     
    4951}
    5052
     53RefPtr<CSSRuleListImpl> AbstractViewImpl::getMatchedCSSRules(ElementImpl* elt, DOMStringImpl* pseudoElt, bool authorOnly)
     54{
     55    if (pseudoElt && pseudoElt->l)
     56        return m_document->styleSelector()->pseudoStyleRulesForElement(elt, pseudoElt, authorOnly);
     57    return m_document->styleSelector()->styleRulesForElement(elt, authorOnly);
    5158}
     59
     60}
  • trunk/WebCore/khtml/xml/dom2_viewsimpl.h

    r11270 r11481  
    3131class DocumentImpl;
    3232class CSSStyleDeclarationImpl;
     33class CSSRuleListImpl;
    3334class ElementImpl;
    3435class DOMStringImpl;
     
    4344    DocumentImpl *document() const { return m_document; }
    4445    CSSStyleDeclarationImpl *getComputedStyle(ElementImpl *elt, DOMStringImpl *pseudoElt);
     46    RefPtr<CSSRuleListImpl> getMatchedCSSRules(ElementImpl *elt, DOMStringImpl *pseudoElt, bool authorOnly = true);
     47
    4548protected:
    4649    DocumentImpl *m_document;
  • trunk/WebCore/kwq/DOM-CSS.mm

    r11341 r11481  
    758758}
    759759
     760- (NSString *)getPropertyShorthand:(NSString *)propertyName
     761{
     762    return [self _styleDeclarationImpl]->getPropertyShorthand(propertyName);
     763}
     764
     765- (BOOL)isPropertyImplicit:(NSString *)propertyName
     766{
     767    return [self _styleDeclarationImpl]->isPropertyImplicit(propertyName);
     768}
     769
    760770- (void)setProperty:(NSString *)propertyName :(NSString *)value :(NSString *)priority
    761771{
     
    25172527}
    25182528
    2519 @end
     2529- (DOMCSSRuleList *)getMatchedCSSRules:(DOMElement *)elt :(NSString *)pseudoElt
     2530{
     2531    // The parameter of "false" is handy for the DOM inspector and lets us see user agent and user rules.
     2532    return [DOMCSSRuleList _ruleListWithImpl: AbstractViewImpl([self _documentImpl]).getMatchedCSSRules([elt _elementImpl], DOMString(pseudoElt).impl(), false).get()];
     2533}
     2534
     2535@end
  • trunk/WebCore/kwq/DOMPrivate.h

    r11285 r11481  
    8686@end
    8787
     88@interface DOMCSSStyleDeclaration (DOMCSSStyleDeclarationExtensions)
     89- (NSString *)getPropertyShorthand:(NSString *)propertyName;
     90- (BOOL)isPropertyImplicit:(NSString *)propertyName;
     91@end
    8892// END
    8993
Note: See TracChangeset for help on using the changeset viewer.