Changeset 95502 in webkit


Ignore:
Timestamp:
Sep 19, 2011 6:20:12 PM (13 years ago)
Author:
macpherson@chromium.org
Message:

Eliminate Length::undefinedLength = -1 and replace with Undefined LengthType.
https://bugs.webkit.org/show_bug.cgi?id=68057

Reviewed by Darin Adler.

There appear to be many cases where -1 is actually a valid Length.
Encoding the validity of Length separately to the value is a natural solution.

No new tests / no behavioral changes.

  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue):

  • css/CSSPrimitiveValue.cpp:

(WebCore::CSSPrimitiveValue::CSSPrimitiveValue):

  • css/CSSStyleApplyProperty.cpp:

(WebCore::ApplyPropertyLength::applyValue):

  • platform/Length.h:

(WebCore::Length::Length):
(WebCore::Length::value):
(WebCore::Length::calcValue):
(WebCore::Length::calcMinValue):
(WebCore::Length::calcFloatValue):
(WebCore::Length::isUndefined):

  • rendering/RenderBlock.cpp:

(WebCore::RenderBlock::computePreferredLogicalWidths):

  • rendering/RenderDeprecatedFlexibleBox.cpp:

(WebCore::RenderDeprecatedFlexibleBox::computePreferredLogicalWidths):

  • rendering/RenderFileUploadControl.cpp:

(WebCore::RenderFileUploadControl::computePreferredLogicalWidths):

  • rendering/RenderImage.cpp:

(WebCore::RenderImage::isLogicalWidthSpecified):
(WebCore::RenderImage::isLogicalHeightSpecified):

  • rendering/RenderListBox.cpp:

(WebCore::RenderListBox::computePreferredLogicalWidths):

  • rendering/RenderMenuList.cpp:

(WebCore::RenderMenuList::computePreferredLogicalWidths):

  • rendering/RenderReplaced.cpp:

(WebCore::RenderReplaced::computePreferredLogicalWidths):

  • rendering/RenderSlider.cpp:

(WebCore::RenderSlider::computePreferredLogicalWidths):

  • rendering/RenderTextControl.cpp:

(WebCore::RenderTextControl::computePreferredLogicalWidths):

  • rendering/style/RenderStyle.h:

(WebCore::InheritedFlags::initialMaxSize):

  • rendering/svg/RenderSVGRoot.cpp:

(WebCore::RenderSVGRoot::computePreferredLogicalWidths):

Location:
trunk/Source/WebCore
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r95501 r95502  
     12011-09-19  Luke Macpherson   <macpherson@chromium.org>
     2
     3        Eliminate Length::undefinedLength = -1 and replace with Undefined LengthType.
     4        https://bugs.webkit.org/show_bug.cgi?id=68057
     5
     6        Reviewed by Darin Adler.
     7
     8        There appear to be many cases where -1 is actually a valid Length.
     9        Encoding the validity of Length separately to the value is a natural solution.
     10
     11        No new tests / no behavioral changes.
     12
     13        * css/CSSComputedStyleDeclaration.cpp:
     14        (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue):
     15        * css/CSSPrimitiveValue.cpp:
     16        (WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
     17        * css/CSSStyleApplyProperty.cpp:
     18        (WebCore::ApplyPropertyLength::applyValue):
     19        * platform/Length.h:
     20        (WebCore::Length::Length):
     21        (WebCore::Length::value):
     22        (WebCore::Length::calcValue):
     23        (WebCore::Length::calcMinValue):
     24        (WebCore::Length::calcFloatValue):
     25        (WebCore::Length::isUndefined):
     26        * rendering/RenderBlock.cpp:
     27        (WebCore::RenderBlock::computePreferredLogicalWidths):
     28        * rendering/RenderDeprecatedFlexibleBox.cpp:
     29        (WebCore::RenderDeprecatedFlexibleBox::computePreferredLogicalWidths):
     30        * rendering/RenderFileUploadControl.cpp:
     31        (WebCore::RenderFileUploadControl::computePreferredLogicalWidths):
     32        * rendering/RenderImage.cpp:
     33        (WebCore::RenderImage::isLogicalWidthSpecified):
     34        (WebCore::RenderImage::isLogicalHeightSpecified):
     35        * rendering/RenderListBox.cpp:
     36        (WebCore::RenderListBox::computePreferredLogicalWidths):
     37        * rendering/RenderMenuList.cpp:
     38        (WebCore::RenderMenuList::computePreferredLogicalWidths):
     39        * rendering/RenderReplaced.cpp:
     40        (WebCore::RenderReplaced::computePreferredLogicalWidths):
     41        * rendering/RenderSlider.cpp:
     42        (WebCore::RenderSlider::computePreferredLogicalWidths):
     43        * rendering/RenderTextControl.cpp:
     44        (WebCore::RenderTextControl::computePreferredLogicalWidths):
     45        * rendering/style/RenderStyle.h:
     46        (WebCore::InheritedFlags::initialMaxSize):
     47        * rendering/svg/RenderSVGRoot.cpp:
     48        (WebCore::RenderSVGRoot::computePreferredLogicalWidths):
     49
    1502011-09-19  Adam Barth  <abarth@webkit.org>
    251
  • trunk/Source/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp

    r94427 r95502  
    14241424    }
    14251425
    1426     int indentation = style->textIndent().calcValue(object->size().width());
    1427     if (indentation != undefinedLength) {
     1426    if (!style->textIndent().isUndefined()) {
     1427        int indentation = style->textIndent().calcValue(object->size().width());
    14281428        buffer.set(g_strdup_printf("%i", indentation));
    14291429        result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_INDENT), buffer.get());
  • trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp

    r94989 r95502  
    13961396        case CSSPropertyMaxHeight: {
    13971397            const Length& maxHeight = style->maxHeight();
    1398             if (maxHeight.isFixed() && maxHeight.value() == undefinedLength)
     1398            if (maxHeight.isUndefined())
    13991399                return primitiveValueCache->createIdentifierValue(CSSValueNone);
    14001400            return primitiveValueCache->createValue(maxHeight);
     
    14021402        case CSSPropertyMaxWidth: {
    14031403            const Length& maxWidth = style->maxWidth();
    1404             if (maxWidth.isFixed() && maxWidth.value() == undefinedLength)
     1404            if (maxWidth.isUndefined())
    14051405                return primitiveValueCache->createIdentifierValue(CSSValueNone);
    14061406            return primitiveValueCache->createValue(maxWidth);
  • trunk/Source/WebCore/css/CSSPrimitiveValue.cpp

    r95071 r95502  
    227227            break;
    228228        case Relative:
     229        case Undefined:
    229230            ASSERT_NOT_REACHED();
    230231            break;
     
    401402            break;
    402403        default:
     404            ASSERT_NOT_REACHED();
    403405            return -1.0;
    404406    }
  • trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp

    r94625 r95502  
    329329        if (noneEnabled && primitiveValue->getIdent() == CSSValueNone)
    330330            if (noneUndefined)
    331                 setValue(selector->style(), Length(undefinedLength, Fixed));
     331                setValue(selector->style(), Length(Undefined));
    332332            else
    333333                setValue(selector->style(), Length());
  • trunk/Source/WebCore/platform/Length.h

    r91969 r95502  
    3131namespace WebCore {
    3232
    33 const int undefinedLength = -1;
    3433const int intMaxForLength = 0x7ffffff; // max value for a 28-bit int
    3534const int intMinForLength = (-0x7ffffff - 1); // min value for a 28-bit int
    3635
    37 enum LengthType { Auto, Relative, Percent, Fixed, Intrinsic, MinIntrinsic };
     36enum LengthType { Auto, Relative, Percent, Fixed, Intrinsic, MinIntrinsic, Undefined };
    3837
    3938struct Length {
     
    5756    Length(float v, LengthType t, bool q = false)
    5857    : m_floatValue(v), m_quirk(q), m_type(t), m_isFloat(true)
    59     {           
     58    {
    6059    }
    6160
    6261    Length(double v, LengthType t, bool q = false)
    6362        : m_quirk(q), m_type(t), m_isFloat(true)
    64     {           
     63    {
    6564        m_floatValue = static_cast<float>(v);   
    6665    }
    6766
    68     bool operator==(const Length& o) const { return (getFloatValue() == o.getFloatValue()) && (m_type == o.m_type) && (m_quirk == o.m_quirk); }
    69     bool operator!=(const Length& o) const { return (getFloatValue() != o.getFloatValue()) || (m_type != o.m_type) || (m_quirk != o.m_quirk); }
     67    bool operator==(const Length& o) const { return (m_type == o.m_type) && (m_quirk == o.m_quirk) && (isUndefined() || (getFloatValue() == o.getFloatValue())); }
     68    bool operator!=(const Length& o) const { return !(*this == o); }
    7069
    7170    const Length& operator*=(float v)
     
    7978    }
    8079   
    81     int value() const {
     80    int value() const
     81    {
    8282        return getIntValue();
    8383    }
     
    121121    }
    122122
    123     // note: works only for certain types, returns undefinedLength otherwise
     123    // Note: May only be called for Fixed, Percent and Auto lengths.
     124    // Other types will ASSERT in order to catch invalid length calculations.
    124125    int calcValue(int maxValue, bool roundPercentages = false) const
    125126    {
     
    130131            case Auto:
    131132                return maxValue;
    132             default:
    133                 return undefinedLength;
     133            case Relative:
     134            case Intrinsic:
     135            case MinIntrinsic:
     136            case Undefined:
     137                ASSERT_NOT_REACHED();
     138                return 0;
    134139        }
     140        ASSERT_NOT_REACHED();
     141        return 0;
    135142    }
    136143
     
    146153                return static_cast<int>(static_cast<float>(maxValue * percent() / 100.0f));
    147154            case Auto:
    148             default:
     155                return 0;
     156            case Relative:
     157            case Intrinsic:
     158            case MinIntrinsic:
     159            case Undefined:
     160                ASSERT_NOT_REACHED();
    149161                return 0;
    150162        }
     163        ASSERT_NOT_REACHED();
     164        return 0;
    151165    }
    152166
     
    160174            case Auto:
    161175                return static_cast<float>(maxValue);
    162             default:
    163                 return static_cast<float>(undefinedLength);
     176            case Relative:
     177            case Intrinsic:
     178            case MinIntrinsic:
     179            case Undefined:
     180                ASSERT_NOT_REACHED();
     181                return 0;
    164182        }
    165     }
    166 
    167     bool isUndefined() const { return value() == undefinedLength; }
     183        ASSERT_NOT_REACHED();
     184        return 0;
     185    }
     186
     187    bool isUndefined() const { return type() == Undefined; }
    168188    bool isZero() const
    169     {
     189    {
     190        ASSERT(!isUndefined());
    170191        return m_isFloat ? !m_floatValue : !m_intValue;
    171192    }
    172193   
    173     bool isPositive() const { return getFloatValue() > 0; }
    174     bool isNegative() const { return getFloatValue() < 0; }
     194    bool isPositive() const { return isUndefined() ? false : getFloatValue() > 0; }
     195    bool isNegative() const { return isUndefined() ? false : getFloatValue() < 0; }
    175196
    176197    bool isAuto() const { return type() == Auto; }
     
    208229    int getIntValue() const
    209230    {
     231        ASSERT(!isUndefined());
    210232        return m_isFloat ? static_cast<int>(m_floatValue) : m_intValue;
    211233    }
     
    213235    float getFloatValue() const
    214236    {
     237        ASSERT(!isUndefined());
    215238        return m_isFloat ? m_floatValue : m_intValue;
    216239    }
  • trunk/Source/WebCore/rendering/RenderBlock.cpp

    r95478 r95502  
    47594759    }
    47604760   
    4761     if (style()->logicalMaxWidth().isFixed() && style()->logicalMaxWidth().value() != undefinedLength) {
     4761    if (style()->logicalMaxWidth().isFixed()) {
    47624762        m_maxPreferredLogicalWidth = min(m_maxPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->logicalMaxWidth().value()));
    47634763        m_minPreferredLogicalWidth = min(m_minPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->logicalMaxWidth().value()));
  • trunk/Source/WebCore/rendering/RenderDeprecatedFlexibleBox.cpp

    r94706 r95502  
    203203    }
    204204
    205     if (style()->maxWidth().isFixed() && style()->maxWidth().value() != undefinedLength) {
     205    if (style()->maxWidth().isFixed()) {
    206206        m_maxPreferredLogicalWidth = min(m_maxPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->maxWidth().value()));
    207207        m_minPreferredLogicalWidth = min(m_minPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->maxWidth().value()));
  • trunk/Source/WebCore/rendering/RenderFileUploadControl.cpp

    r94045 r95502  
    189189        m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth;
    190190
    191     if (style->maxWidth().isFixed() && style->maxWidth().value() != undefinedLength) {
     191    if (style->maxWidth().isFixed()) {
    192192        m_maxPreferredLogicalWidth = min(m_maxPreferredLogicalWidth, computeContentBoxLogicalWidth(style->maxWidth().value()));
    193193        m_minPreferredLogicalWidth = min(m_minPreferredLogicalWidth, computeContentBoxLogicalWidth(style->maxWidth().value()));
  • trunk/Source/WebCore/rendering/RenderImage.cpp

    r95103 r95502  
    487487        case MinIntrinsic:
    488488            return false;
    489     }
    490     ASSERT(false);
     489        case Undefined:
     490            ASSERT_NOT_REACHED();
     491            return false;
     492    }
     493    ASSERT_NOT_REACHED();
    491494    return false;
    492495}
     
    503506        case MinIntrinsic:
    504507            return false;
    505     }
    506     ASSERT(false);
     508        case Undefined:
     509            ASSERT_NOT_REACHED();
     510            return false;
     511    }
     512    ASSERT_NOT_REACHED();
    507513    return false;
    508514}
  • trunk/Source/WebCore/rendering/RenderListBox.cpp

    r92998 r95502  
    195195        m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth;
    196196
    197     if (style()->maxWidth().isFixed() && style()->maxWidth().value() != undefinedLength) {
     197    if (style()->maxWidth().isFixed()) {
    198198        m_maxPreferredLogicalWidth = min(m_maxPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->maxWidth().value()));
    199199        m_minPreferredLogicalWidth = min(m_minPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->maxWidth().value()));
  • trunk/Source/WebCore/rendering/RenderMenuList.cpp

    r94427 r95502  
    274274        m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth;
    275275
    276     if (style()->maxWidth().isFixed() && style()->maxWidth().value() != undefinedLength) {
     276    if (style()->maxWidth().isFixed()) {
    277277        m_maxPreferredLogicalWidth = min(m_maxPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->maxWidth().value()));
    278278        m_minPreferredLogicalWidth = min(m_minPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->maxWidth().value()));
  • trunk/Source/WebCore/rendering/RenderReplaced.cpp

    r94912 r95502  
    398398    m_maxPreferredLogicalWidth = computeReplacedLogicalWidth(false) + borderAndPadding;
    399399
    400     if (style()->maxWidth().isFixed() && style()->maxWidth().value() != undefinedLength)
     400    if (style()->maxWidth().isFixed())
    401401        m_maxPreferredLogicalWidth = min(m_maxPreferredLogicalWidth, style()->maxWidth().value() + (style()->boxSizing() == CONTENT_BOX ? borderAndPadding : 0));
    402402
  • trunk/Source/WebCore/rendering/RenderSlider.cpp

    r91574 r95502  
    8484        m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth;
    8585   
    86     if (style()->maxWidth().isFixed() && style()->maxWidth().value() != undefinedLength) {
     86    if (style()->maxWidth().isFixed()) {
    8787        m_maxPreferredLogicalWidth = min(m_maxPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->maxWidth().value()));
    8888        m_minPreferredLogicalWidth = min(m_minPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->maxWidth().value()));
  • trunk/Source/WebCore/rendering/RenderTextControl.cpp

    r94252 r95502  
    289289        m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth;
    290290
    291     if (style()->maxWidth().isFixed() && style()->maxWidth().value() != undefinedLength) {
     291    if (style()->maxWidth().isFixed()) {
    292292        m_maxPreferredLogicalWidth = min(m_maxPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->maxWidth().value()));
    293293        m_minPreferredLogicalWidth = min(m_minPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->maxWidth().value()));
  • trunk/Source/WebCore/rendering/style/RenderStyle.h

    r94912 r95502  
    13581358    static Length initialSize() { return Length(); }
    13591359    static Length initialMinSize() { return Length(0, Fixed); }
    1360     static Length initialMaxSize() { return Length(undefinedLength, Fixed); }
     1360    static Length initialMaxSize() { return Length(Undefined); }
    13611361    static Length initialOffset() { return Length(); }
    13621362    static Length initialMargin() { return Length(Fixed); }
  • trunk/Source/WebCore/rendering/svg/RenderSVGRoot.cpp

    r94372 r95502  
    103103    LayoutUnit width = computeReplacedLogicalWidth(false) + borderAndPadding;
    104104
    105     if (style()->maxWidth().isFixed() && style()->maxWidth().value() != undefinedLength)
     105    if (style()->maxWidth().isFixed())
    106106        width = min(width, style()->maxWidth().value() + (style()->boxSizing() == CONTENT_BOX ? borderAndPadding : 0));
    107107
Note: See TracChangeset for help on using the changeset viewer.