Bug 77095

Summary: Refactor application of additional style attributes for table elements.
Product: WebKit Reporter: Andreas Kling <kling>
Component: CSSAssignee: Andreas Kling <kling>
Status: RESOLVED FIXED    
Severity: Normal CC: koivisto, macpherson, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Possibly a patch
kling: review-
Probably a patch darin: review+

Description Andreas Kling 2012-01-26 05:06:24 PST
To reduce use of CSSMappedAttributeDeclaration..
Comment 1 Andreas Kling 2012-01-26 05:13:52 PST
Created attachment 124107 [details]
Possibly a patch
Comment 2 Andreas Kling 2012-01-26 05:38:48 PST
Comment on attachment 124107 [details]
Possibly a patch

We can do a lot better than this, Mr. Kling. Srsly.
Comment 3 Andreas Kling 2012-01-26 08:10:16 PST
Created attachment 124119 [details]
Probably a patch
Comment 4 WebKit Review Bot 2012-01-26 08:11:54 PST
Attachment 124119 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WebCore/ChangeLog', u'Source/WebCor..." exit_code: 1

Source/WebCore/html/HTMLTableElement.cpp:453:  An else statement can be removed when the prior "if" concludes with a return, break, continue or goto statement.  [readability/control_flow] [4]
Source/WebCore/html/HTMLTableElement.cpp:558:  An else statement can be removed when the prior "if" concludes with a return, break, continue or goto statement.  [readability/control_flow] [4]
Total errors found: 2 in 12 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 5 Darin Adler 2012-01-26 09:40:50 PST
Comment on attachment 124119 [details]
Probably a patch

View in context: https://bugs.webkit.org/attachment.cgi?id=124119&action=review

> Source/WebCore/html/HTMLTableElement.cpp:472
> +    if (m_borderColorAttr) {
> +        DEFINE_STATIC_LOCAL(RefPtr<CSSMutableStyleDeclaration>, style, ());
> +        if (!style) {
> +            style = CSSMutableStyleDeclaration::create();
> +            style->setProperty(CSSPropertyBorderTopStyle, CSSValueSolid);
> +            style->setProperty(CSSPropertyBorderBottomStyle, CSSValueSolid);
> +            style->setProperty(CSSPropertyBorderLeftStyle, CSSValueSolid);
> +            style->setProperty(CSSPropertyBorderRightStyle, CSSValueSolid);
> +        }
> +        return style;
> +    } else {
> +        DEFINE_STATIC_LOCAL(RefPtr<CSSMutableStyleDeclaration>, style, ());
> +        if (!style) {
> +            style = CSSMutableStyleDeclaration::create();
> +            style->setProperty(CSSPropertyBorderTopStyle, CSSValueOutset);
> +            style->setProperty(CSSPropertyBorderBottomStyle, CSSValueOutset);
> +            style->setProperty(CSSPropertyBorderLeftStyle, CSSValueOutset);
> +            style->setProperty(CSSPropertyBorderRightStyle, CSSValueOutset);
> +        }
> +        return style;

We can make this a lot cleaner with a helper function:

    static CSSMutableStyleDeclaration* leakBorderStyle(int value)
    {
        RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
        style->setProperty(CSSPropertyBorderTopStyle, CSSValueOutset);
        style->setProperty(CSSPropertyBorderBottomStyle, CSSValueOutset);
        style->setProperty(CSSPropertyBorderLeftStyle, CSSValueOutset);
        style->setProperty(CSSPropertyBorderRightStyle, CSSValueOutset);
        return style.release().leakRef();
    }

    if (m_borderColorAttr) {
        static CSSMutableStyleDeclaration* solidBorderStyle = leakBorderStyle(CSSValueSolid);
        return solidBorderStyle;
    }
    static CSSMutableStyleDeclaration* outsetBorderStyle = leakBorderStyle(CSSValueOutset);
    return outsetBorderStyle;

> Source/WebCore/html/HTMLTableElement.cpp:504
> +PassRefPtr<CSSMutableStyleDeclaration> HTMLTableElement::additionalCellStyle()
> +{
> +    if (m_sharedCellStyle)
> +        return m_sharedCellStyle;
> +
> +    m_sharedCellStyle = CSSMutableStyleDeclaration::create();

I think it’s better to put the management of the data member into a separate function from the one with the case statement that creates the style. The function could even be inlined; the out of line part would be the “create the declaration” bit.

> Source/WebCore/html/HTMLTableElement.cpp:548
> +    if (m_padding) {
> +        String value = String::number(m_padding);
> +        m_sharedCellStyle->setProperty(CSSPropertyPaddingTop, value);
> +        m_sharedCellStyle->setProperty(CSSPropertyPaddingBottom, value);
> +        m_sharedCellStyle->setProperty(CSSPropertyPaddingLeft, value);
> +        m_sharedCellStyle->setProperty(CSSPropertyPaddingRight, value);
>      }

I notice we’re not adding “px” here. Is that OK?

> Source/WebCore/html/HTMLTableElement.cpp:578
> +    if (rows) {
> +        DEFINE_STATIC_LOCAL(RefPtr<CSSMutableStyleDeclaration>, style, ());
> +        if (!style) {
> +            style = CSSMutableStyleDeclaration::create();
> +            style->setProperty(CSSPropertyBorderTopWidth, CSSValueThin);
> +            style->setProperty(CSSPropertyBorderBottomWidth, CSSValueThin);
> +            style->setProperty(CSSPropertyBorderTopStyle, CSSValueSolid);
> +            style->setProperty(CSSPropertyBorderBottomStyle, CSSValueSolid);
>          }
> -
> -        setMappedAttributeDecl(ePersistent, rulesAttr, rulesValue, decl);
> -        decl->setMappedState(ePersistent, rulesAttr, rulesValue);
> +        return style;
> +    } else {
> +        DEFINE_STATIC_LOCAL(RefPtr<CSSMutableStyleDeclaration>, style, ());
> +        if (!style) {
> +            style = CSSMutableStyleDeclaration::create();
> +            style->setProperty(CSSPropertyBorderLeftWidth, CSSValueThin);
> +            style->setProperty(CSSPropertyBorderRightWidth, CSSValueThin);
> +            style->setProperty(CSSPropertyBorderLeftStyle, CSSValueSolid);
> +            style->setProperty(CSSPropertyBorderRightStyle, CSSValueSolid);
> +        }
> +        return style;
>      }

Again, I suggest using helper functions so we don’t need the “if (!style)” here.
Comment 6 Andreas Kling 2012-01-26 11:02:38 PST
Committed r106015: <http://trac.webkit.org/changeset/106015>