Changeset 19164 in webkit


Ignore:
Timestamp:
Jan 26, 2007 2:45:42 PM (17 years ago)
Author:
hyatt
Message:

Fix for style regression caused by strictness checking of the number of properties. This caused code like:
"width: 20 px" to fail, because we interpreted it as two values and rejected it. Our old code allowed 20 to be
used like a pixel value and then ignored the orphaned unit.

This patch actually scans the list of values looking for orphaned units and reattaches them to the numeric
values that they should correspond to. This means rules like "width: 5 em" will now work in quirks mdoe and
the "em" unit type will be honored.

Reviewed by beth

  • WebCore.xcodeproj/project.pbxproj:
  • css/cssparser.cpp: (WebCore::unitFromString): (WebCore::CSSParser::checkForOrphanedUnits): (WebCore::CSSParser::parseValue):
  • css/cssparser.h: (WebCore::ValueList::valueAt): (WebCore::ValueList::deleteValueAt):
Location:
trunk/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r19163 r19164  
     12007-01-26  David Hyatt  <hyatt@apple.com>
     2
     3        Fix for style regression caused by strictness checking of the number of properties.  This caused code like:
     4        "width: 20 px" to fail, because we interpreted it as two values and rejected it.  Our old code allowed 20 to be
     5        used like a pixel value and then ignored the orphaned unit.
     6
     7        This patch actually scans the list of values looking for orphaned units and reattaches them to the numeric
     8        values that they should correspond to.  This means rules like "width: 5 em" will now work in quirks mdoe and
     9        the "em" unit type will be honored.
     10
     11        Reviewed by beth
     12
     13        * WebCore.xcodeproj/project.pbxproj:
     14        * css/cssparser.cpp:
     15        (WebCore::unitFromString):
     16        (WebCore::CSSParser::checkForOrphanedUnits):
     17        (WebCore::CSSParser::parseValue):
     18        * css/cssparser.h:
     19        (WebCore::ValueList::valueAt):
     20        (WebCore::ValueList::deleteValueAt):
     21
    1222007-01-26  George Staikos  <staikos@kde.org>
    223
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r19160 r19164  
    1109611096                        isa = PBXProject;
    1109711097                        buildConfigurationList = 149C284308902B11008A9EFC /* Build configuration list for PBXProject "WebCore" */;
    11098                         compatibilityVersion = "Xcode 2.4";
    1109911098                        hasScannedForEncodings = 1;
    1110011099                        knownRegions = (
     
    1111111110                        projectDirPath = "";
    1111211111                        projectRoot = "";
    11113                         shouldCheckCompatibility = 1;
    1111411112                        targets = (
    1111511113                                93F198A508245E59001E9ABC /* WebCore */,
  • trunk/WebCore/css/cssparser.cpp

    r18838 r19164  
    422422}
    423423
     424static int unitFromString(Value* value)
     425{
     426    if (value->unit != CSSPrimitiveValue::CSS_IDENT || value->id)
     427        return 0;
     428
     429    String str = domString(value->string);
     430    if (str == "em")
     431        return CSSPrimitiveValue::CSS_EMS;
     432    if (str == "ex")
     433        return CSSPrimitiveValue::CSS_EXS;
     434    if (str == "px")
     435        return CSSPrimitiveValue::CSS_PX;
     436    if (str == "cm")
     437        return CSSPrimitiveValue::CSS_CM;
     438    if (str == "mm")
     439        return CSSPrimitiveValue::CSS_MM;
     440    if (str == "in")
     441        return CSSPrimitiveValue::CSS_IN;
     442    if (str == "pt")
     443        return CSSPrimitiveValue::CSS_PT;
     444    if (str == "pc")
     445        return CSSPrimitiveValue::CSS_PC;
     446    if (str == "deg")
     447        return CSSPrimitiveValue::CSS_DEG;
     448    if (str == "rad")
     449        return CSSPrimitiveValue::CSS_RAD;
     450    if (str == "grad")
     451        return CSSPrimitiveValue::CSS_GRAD;
     452    if (str == "ms")
     453        return CSSPrimitiveValue::CSS_MS;
     454    if (str == "s")
     455        return CSSPrimitiveValue::CSS_S;
     456    if (str == "Hz")
     457        return CSSPrimitiveValue::CSS_HZ;
     458    if (str == "kHz")
     459        return CSSPrimitiveValue::CSS_KHZ;
     460   
     461    return 0;
     462}
     463
     464void CSSParser::checkForOrphanedUnits()
     465{
     466    if (strict || inShorthand())
     467        return;
     468       
     469    // The purpose of this code is to implement the WinIE quirk that allows unit types to be separated from their numeric values
     470    // by whitespace, so e.g., width: 20 px instead of width:20px.  This is invalid CSS, so we don't do this in strict mode.
     471    Value* numericVal = 0;
     472    unsigned size = valueList->size();
     473    for (unsigned i = 0; i < size; i++) {
     474        Value* value = valueList->valueAt(i);
     475        if (numericVal) {
     476            // Change the unit type of the numeric val to match.
     477            int unit = unitFromString(value);
     478            if (unit) {
     479                numericVal->unit = unit;
     480                numericVal = 0;
     481
     482                // Now delete the bogus unit value.
     483                valueList->deleteValueAt(i);
     484                i--; // We're safe even though |i| is unsigned, since we only hit this code if we had a previous numeric value (so |i| is always > 0 here).
     485                size--;
     486                continue;
     487            }
     488        }
     489       
     490        numericVal = (value->unit == CSSPrimitiveValue::CSS_NUMBER) ? value : 0;
     491    }
     492}
     493
    424494bool CSSParser::parseValue(int propId, bool important)
    425495{
     
    451521    bool valid_primitive = false;
    452522    CSSValue *parsedValue = 0;
     523
     524    // In quirks mode, we will look for units that have been incorrectly separated from the number they belong to
     525    // by a space.  We go ahead and associate the unit with the number even though it is invalid CSS.
     526    checkForOrphanedUnits();
    453527
    454528    switch(propId) {
  • trunk/WebCore/css/cssparser.h

    r18850 r19164  
    9595        Value* next() { ++m_current; return current(); }
    9696
     97        Value* valueAt(unsigned i) { return i < m_values.size() ? &m_values[i] : 0; }
     98        void deleteValueAt(unsigned i) { m_values.remove(i); }
     99
    97100    private:
    98101        Vector<Value, 16> m_values;
     
    235238        bool inShorthand() const { return m_inParseShorthand; }
    236239
     240        void checkForOrphanedUnits();
     241       
    237242        UChar* data;
    238243        UChar* yytext;
Note: See TracChangeset for help on using the changeset viewer.