Bug 156098 - Replace all RenderTheme::popupInternalPadding methods with a single one returning a LengthBox
Summary: Replace all RenderTheme::popupInternalPadding methods with a single one retur...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-31 23:42 PDT by Carlos Garcia Campos
Modified: 2016-04-03 03:50 PDT (History)
2 users (show)

See Also:


Attachments
Patch (12.24 KB, patch)
2016-03-31 23:44 PDT, Carlos Garcia Campos
no flags Details | Formatted Diff | Diff
Try to fix mac builds (13.86 KB, patch)
2016-04-01 00:02 PDT, Carlos Garcia Campos
darin: review+
Details | Formatted Diff | Diff
Patch for landing (13.67 KB, patch)
2016-04-03 02:42 PDT, Carlos Garcia Campos
no flags Details | Formatted Diff | Diff
Try to fix mac builds (13.81 KB, patch)
2016-04-03 03:17 PDT, Carlos Garcia Campos
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos Garcia Campos 2016-03-31 23:42:08 PDT
The caller always wants all padding sides, so we can simplify both the caller and the implementations by using a single method. It's also more efficient for the GTK+ port that creates and destroys the same style contexts on every call.
Comment 1 Carlos Garcia Campos 2016-03-31 23:44:52 PDT
Created attachment 275374 [details]
Patch
Comment 2 Carlos Garcia Campos 2016-04-01 00:02:15 PDT
Created attachment 275375 [details]
Try to fix mac builds
Comment 3 Darin Adler 2016-04-01 09:34:39 PDT
Comment on attachment 275375 [details]
Try to fix mac builds

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

> Source/WebCore/rendering/RenderTheme.h:187
> +    virtual LengthBox popupInternalPaddingBox(const RenderStyle&) const { return LengthBox(0); }

Not sure this function needs the word “Box” in its name. Also could write:

    return { 0 };

Instead of return LengthBox(0);

> Source/WebCore/rendering/RenderThemeGtk.cpp:767
> +        return LengthBox(0);

Again, I prefer:

    return { 0 };

> Source/WebCore/rendering/RenderThemeGtk.cpp:782
> +    return LengthBox(borderWidth.top + focusWidth, borderWidth.right + focusWidth + (style.direction() == LTR ? minArrowSize : 0),
> +        borderWidth.bottom + focusWidth, borderWidth.left + focusWidth + (style.direction() == RTL ? minArrowSize : 0));

I like the syntax where we just write:

    return { a, b, c, d };

Rather than naming the type LengthBox.

> Source/WebCore/rendering/RenderThemeIOS.mm:535
> +        return LengthBox(0, MenuListButtonPaddingRight + style.borderTopWidth(), 0, 0);
> +    return LengthBox(0);

Ditto.

> Source/WebCore/rendering/RenderThemeMac.mm:1374
> +        return LengthBox(popupButtonPadding(controlSizeForFont(style))[topPadding] * style.effectiveZoom(),
> +            popupButtonPadding(controlSizeForFont(style))[rightPadding] * style.effectiveZoom(),
> +            popupButtonPadding(controlSizeForFont(style))[bottomPadding] * style.effectiveZoom(),
> +            popupButtonPadding(controlSizeForFont(style))[leftPadding] * style.effectiveZoom());

Ditto.

> Source/WebCore/rendering/RenderThemeMac.mm:1381
> +        return LengthBox(styledPopupPaddingTop * style.effectiveZoom(),
> +            static_cast<int>(ceilf(arrowWidth + (arrowPaddingLeft + arrowPaddingRight + paddingBeforeSeparator) * style.effectiveZoom())),
> +            styledPopupPaddingBottom * style.effectiveZoom(), styledPopupPaddingLeft * style.effectiveZoom());

Ditto.

> Source/WebCore/rendering/RenderThemeMac.mm:1384
> +    return LengthBox(0);

Ditto.
Comment 4 Carlos Garcia Campos 2016-04-03 02:40:59 PDT
(In reply to comment #3)
> Comment on attachment 275375 [details]
> Try to fix mac builds
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=275375&action=review
> 
> > Source/WebCore/rendering/RenderTheme.h:187
> > +    virtual LengthBox popupInternalPaddingBox(const RenderStyle&) const { return LengthBox(0); }
> 
> Not sure this function needs the word “Box” in its name. 

I thought about it and decided to leave the Box for consistency with RenderStyle::setPaddingBox and because it returns a LengthBox.

> Also could write:
> 
>     return { 0 };
> 
> Instead of return LengthBox(0);

GCC doesn't like that:

error: converting to 'WebCore::LengthBox' from initializer list would use explicit constructor 'WebCore::LengthBox::LengthBox(int)'

I think it's because there are two explicit constructors receiving an integer, using { 0, 0, 0, 0 } works.
Comment 5 Carlos Garcia Campos 2016-04-03 02:42:18 PDT
Created attachment 275491 [details]
Patch for landing
Comment 6 Carlos Garcia Campos 2016-04-03 03:15:27 PDT
It seems brace initializer list requires explicit casts everywhere:

/Volumes/Data/EWS/WebKit/Source/WebCore/rendering/RenderThemeMac.mm:1371:18: error: type 'float' cannot be narrowed to 'int' in initializer list [-Wc++11-narrowing]
        return { popupButtonPadding(controlSizeForFont(style))[topPadding] * style.effectiveZoom(),
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Volumes/Data/EWS/WebKit/Source/WebCore/rendering/RenderThemeMac.mm:1371:18: note: insert an explicit cast to silence this issue
Comment 7 Carlos Garcia Campos 2016-04-03 03:17:00 PDT
Created attachment 275493 [details]
Try to fix mac builds
Comment 8 Carlos Garcia Campos 2016-04-03 03:50:19 PDT
Committed r198983: <http://trac.webkit.org/changeset/198983>