WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
77095
Refactor application of additional style attributes for table elements.
https://bugs.webkit.org/show_bug.cgi?id=77095
Summary
Refactor application of additional style attributes for table elements.
Andreas Kling
Reported
2012-01-26 05:06:24 PST
To reduce use of CSSMappedAttributeDeclaration..
Attachments
Possibly a patch
(30.61 KB, patch)
2012-01-26 05:13 PST
,
Andreas Kling
kling
: review-
Details
Formatted Diff
Diff
Probably a patch
(26.92 KB, patch)
2012-01-26 08:10 PST
,
Andreas Kling
darin
: review+
Details
Formatted Diff
Diff
Show Obsolete
(1)
View All
Add attachment
proposed patch, testcase, etc.
Andreas Kling
Comment 1
2012-01-26 05:13:52 PST
Created
attachment 124107
[details]
Possibly a patch
Andreas Kling
Comment 2
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.
Andreas Kling
Comment 3
2012-01-26 08:10:16 PST
Created
attachment 124119
[details]
Probably a patch
WebKit Review Bot
Comment 4
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.
Darin Adler
Comment 5
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.
Andreas Kling
Comment 6
2012-01-26 11:02:38 PST
Committed
r106015
: <
http://trac.webkit.org/changeset/106015
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug