Replace all RenderTheme::popupInternalPadding methods with a single one returning...
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 3 Apr 2016 10:50:11 +0000 (10:50 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 3 Apr 2016 10:50:11 +0000 (10:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=156098

Reviewed by Darin Adler.

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.

* rendering/RenderMenuList.cpp:
(WebCore::RenderMenuList::adjustInnerStyle):
* rendering/RenderTheme.h:
(WebCore::RenderTheme::popupInternalPaddingBox):
(WebCore::RenderTheme::popupInternalPaddingLeft): Deleted.
(WebCore::RenderTheme::popupInternalPaddingRight): Deleted.
(WebCore::RenderTheme::popupInternalPaddingTop): Deleted.
(WebCore::RenderTheme::popupInternalPaddingBottom): Deleted.
* rendering/RenderThemeGtk.cpp:
(WebCore::RenderThemeGtk::popupInternalPaddingBox):
(WebCore::getComboBoxMetrics): Deleted.
(WebCore::RenderThemeGtk::popupInternalPaddingLeft): Deleted.
(WebCore::RenderThemeGtk::popupInternalPaddingRight): Deleted.
(WebCore::RenderThemeGtk::popupInternalPaddingTop): Deleted.
(WebCore::RenderThemeGtk::popupInternalPaddingBottom): Deleted.
* rendering/RenderThemeGtk.h:
* rendering/RenderThemeIOS.h:
* rendering/RenderThemeIOS.mm:
(WebCore::RenderThemeIOS::popupInternalPaddingBox):
(WebCore::RenderThemeIOS::popupInternalPaddingRight): Deleted.
* rendering/RenderThemeMac.h:
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::popupInternalPaddingBox):
(WebCore::RenderThemeMac::popupInternalPaddingLeft): Deleted.
(WebCore::RenderThemeMac::popupInternalPaddingRight): Deleted.
(WebCore::RenderThemeMac::popupInternalPaddingTop): Deleted.
(WebCore::RenderThemeMac::popupInternalPaddingBottom): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@198983 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderMenuList.cpp
Source/WebCore/rendering/RenderTheme.h
Source/WebCore/rendering/RenderThemeGtk.cpp
Source/WebCore/rendering/RenderThemeGtk.h
Source/WebCore/rendering/RenderThemeIOS.h
Source/WebCore/rendering/RenderThemeIOS.mm
Source/WebCore/rendering/RenderThemeMac.h
Source/WebCore/rendering/RenderThemeMac.mm

index 84eaa45..81b7048 100644 (file)
@@ -1,3 +1,42 @@
+2016-04-03  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        Replace all RenderTheme::popupInternalPadding methods with a single one returning a LengthBox
+        https://bugs.webkit.org/show_bug.cgi?id=156098
+
+        Reviewed by Darin Adler.
+
+        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.
+
+        * rendering/RenderMenuList.cpp:
+        (WebCore::RenderMenuList::adjustInnerStyle):
+        * rendering/RenderTheme.h:
+        (WebCore::RenderTheme::popupInternalPaddingBox):
+        (WebCore::RenderTheme::popupInternalPaddingLeft): Deleted.
+        (WebCore::RenderTheme::popupInternalPaddingRight): Deleted.
+        (WebCore::RenderTheme::popupInternalPaddingTop): Deleted.
+        (WebCore::RenderTheme::popupInternalPaddingBottom): Deleted.
+        * rendering/RenderThemeGtk.cpp:
+        (WebCore::RenderThemeGtk::popupInternalPaddingBox):
+        (WebCore::getComboBoxMetrics): Deleted.
+        (WebCore::RenderThemeGtk::popupInternalPaddingLeft): Deleted.
+        (WebCore::RenderThemeGtk::popupInternalPaddingRight): Deleted.
+        (WebCore::RenderThemeGtk::popupInternalPaddingTop): Deleted.
+        (WebCore::RenderThemeGtk::popupInternalPaddingBottom): Deleted.
+        * rendering/RenderThemeGtk.h:
+        * rendering/RenderThemeIOS.h:
+        * rendering/RenderThemeIOS.mm:
+        (WebCore::RenderThemeIOS::popupInternalPaddingBox):
+        (WebCore::RenderThemeIOS::popupInternalPaddingRight): Deleted.
+        * rendering/RenderThemeMac.h:
+        * rendering/RenderThemeMac.mm:
+        (WebCore::RenderThemeMac::popupInternalPaddingBox):
+        (WebCore::RenderThemeMac::popupInternalPaddingLeft): Deleted.
+        (WebCore::RenderThemeMac::popupInternalPaddingRight): Deleted.
+        (WebCore::RenderThemeMac::popupInternalPaddingTop): Deleted.
+        (WebCore::RenderThemeMac::popupInternalPaddingBottom): Deleted.
+
 2016-04-02  Sam Weinig  <sam@webkit.org>
 
         Cleanup DataDetection.mm a little bit
index 478f304..326efe6 100644 (file)
@@ -123,10 +123,7 @@ void RenderMenuList::adjustInnerStyle()
         innerStyle.setAlignSelfPosition(ItemPositionFlexStart);
     }
 
-    innerStyle.setPaddingLeft(Length(theme().popupInternalPaddingLeft(style()), Fixed));
-    innerStyle.setPaddingRight(Length(theme().popupInternalPaddingRight(style()), Fixed));
-    innerStyle.setPaddingTop(Length(theme().popupInternalPaddingTop(style()), Fixed));
-    innerStyle.setPaddingBottom(Length(theme().popupInternalPaddingBottom(style()), Fixed));
+    innerStyle.setPaddingBox(theme().popupInternalPaddingBox(style()));
 
     if (document().page()->chrome().selectItemWritingDirectionIsNatural()) {
         // Items in the popup will not respect the CSS text-align and direction properties,
index 7ba4112..5d3acc2 100644 (file)
@@ -184,10 +184,7 @@ public:
 
     virtual void adjustSliderThumbSize(RenderStyle&, Element*) const;
 
-    virtual int popupInternalPaddingLeft(const RenderStyle&) const { return 0; }
-    virtual int popupInternalPaddingRight(const RenderStyle&) const { return 0; }
-    virtual int popupInternalPaddingTop(const RenderStyle&) const { return 0; }
-    virtual int popupInternalPaddingBottom(const RenderStyle&) const { return 0; }
+    virtual LengthBox popupInternalPaddingBox(const RenderStyle&) const { return { 0, 0, 0, 0 }; }
     virtual bool popupOptionSupportsTextIndent() const { return false; }
     virtual PopupMenuStyle::PopupMenuSize popupMenuSize(const RenderStyle&, IntRect&) const { return PopupMenuStyle::PopupMenuSizeNormal; }
 
index 949d997..7d19ff4 100644 (file)
@@ -761,61 +761,25 @@ void RenderThemeGtk::adjustMenuListButtonStyle(StyleResolver& styleResolver, Ren
     adjustMenuListStyle(styleResolver, style, e);
 }
 
-static void getComboBoxMetrics(const RenderStyle& style, GtkBorder& border, int& focus)
+LengthBox RenderThemeGtk::popupInternalPaddingBox(const RenderStyle& style) const
 {
-    // If this menu list button isn't drawn using the native theme, we
-    // don't add any extra padding beyond what WebCore already uses.
     if (style.appearance() == NoControlPart)
-        return;
+        return { 0, 0, 0, 0 };
 
     GRefPtr<GtkStyleContext> parentContext = createStyleContext(ComboBox);
     GRefPtr<GtkStyleContext> context = createStyleContext(ComboBoxButton, parentContext.get());
     gtk_style_context_set_direction(context.get(), static_cast<GtkTextDirection>(gtkTextDirection(style.direction())));
     gtk_style_context_set_state(context.get(), static_cast<GtkStateFlags>(0));
-    gtk_style_context_get_border(context.get(), gtk_style_context_get_state(context.get()), &border);
+    GtkBorder borderWidth = { 0, 0, 0, 0 };
+    gtk_style_context_get_border(context.get(), gtk_style_context_get_state(context.get()), &borderWidth);
 
     gboolean interiorFocus;
     gint focusWidth, focusPad;
     gtk_style_context_get_style(context.get(), "interior-focus", &interiorFocus, "focus-line-width", &focusWidth, "focus-padding", &focusPad, nullptr);
-    focus = interiorFocus ? focusWidth + focusPad : 0;
-}
+    focusWidth = interiorFocus ? focusWidth + focusPad : 0;
 
-int RenderThemeGtk::popupInternalPaddingLeft(const RenderStyle& style) const
-{
-    GtkBorder borderWidth = { 0, 0, 0, 0 };
-    int focusWidth = 0;
-    getComboBoxMetrics(style, borderWidth, focusWidth);
-    int left = borderWidth.left + focusWidth;
-    if (style.direction() == RTL)
-        left += minArrowSize;
-    return left;
-}
-
-int RenderThemeGtk::popupInternalPaddingRight(const RenderStyle& style) const
-{
-    GtkBorder borderWidth = { 0, 0, 0, 0 };
-    int focusWidth = 0;
-    getComboBoxMetrics(style, borderWidth, focusWidth);
-    int right = borderWidth.right + focusWidth;
-    if (style.direction() == LTR)
-        right += minArrowSize;
-    return right;
-}
-
-int RenderThemeGtk::popupInternalPaddingTop(const RenderStyle& style) const
-{
-    GtkBorder borderWidth = { 0, 0, 0, 0 };
-    int focusWidth = 0;
-    getComboBoxMetrics(style, borderWidth, focusWidth);
-    return borderWidth.top + focusWidth;
-}
-
-int RenderThemeGtk::popupInternalPaddingBottom(const RenderStyle& style) const
-{
-    GtkBorder borderWidth = { 0, 0, 0, 0 };
-    int focusWidth = 0;
-    getComboBoxMetrics(style, borderWidth, focusWidth);
-    return borderWidth.bottom + focusWidth;
+    return { borderWidth.top + focusWidth, borderWidth.right + focusWidth + (style.direction() == LTR ? minArrowSize : 0),
+        borderWidth.bottom + focusWidth, borderWidth.left + focusWidth + (style.direction() == RTL ? minArrowSize : 0) };
 }
 
 bool RenderThemeGtk::paintMenuList(const RenderObject& renderObject, const PaintInfo& paintInfo, const FloatRect& r)
index 34715bf..4197c76 100644 (file)
@@ -119,10 +119,7 @@ private:
     bool paintTextField(const RenderObject&, const PaintInfo&, const FloatRect&) override;
     bool paintTextArea(const RenderObject&, const PaintInfo&, const FloatRect&) override;
 
-    int popupInternalPaddingLeft(const RenderStyle&) const override;
-    int popupInternalPaddingRight(const RenderStyle&) const override;
-    int popupInternalPaddingTop(const RenderStyle&) const override;
-    int popupInternalPaddingBottom(const RenderStyle&) const override;
+    LengthBox popupInternalPaddingBox(const RenderStyle&) const override;
 
     // The Mac port differentiates between the "menu list" and the "menu list button."
     // The former is used when a menu list button has been styled. This is used to ensure
index 062bc2b..d6c860c 100644 (file)
@@ -40,7 +40,7 @@ class RenderThemeIOS final : public RenderTheme {
 public:
     static Ref<RenderTheme> create();
 
-    int popupInternalPaddingRight(const RenderStyle&) const override;
+    LengthBox popupInternalPaddingBox(const RenderStyle&) const override;
 
     static void adjustRoundBorderRadius(RenderStyle&, RenderBox&);
 
index fa677c0..348498d 100644 (file)
@@ -528,11 +528,11 @@ const float MenuListArrowWidth = 7;
 const float MenuListArrowHeight = 6;
 const float MenuListButtonPaddingRight = 19;
 
-int RenderThemeIOS::popupInternalPaddingRight(const RenderStyle& style) const
+LengthBox RenderThemeIOS::popupInternalPaddingBox(const RenderStyle& style) const
 {
     if (style.appearance() == MenulistButtonPart)
-        return MenuListButtonPaddingRight + style.borderTopWidth();
-    return 0;
+        return { 0, static_cast<int>(MenuListButtonPaddingRight + style.borderTopWidth()), 0, 0 };
+    return { 0, 0, 0, 0 };
 }
 
 void RenderThemeIOS::adjustRoundBorderRadius(RenderStyle& style, RenderBox& box)
index 704330d..0f41333 100644 (file)
@@ -75,10 +75,7 @@ public:
     int sliderTickOffsetFromTrackCenter() const override;
 #endif
 
-    int popupInternalPaddingLeft(const RenderStyle&) const override;
-    int popupInternalPaddingRight(const RenderStyle&) const override;
-    int popupInternalPaddingTop(const RenderStyle&) const override;
-    int popupInternalPaddingBottom(const RenderStyle&) const override;
+    LengthBox popupInternalPaddingBox(const RenderStyle&) const override;
     PopupMenuStyle::PopupMenuSize popupMenuSize(const RenderStyle&, IntRect&) const override;
 
     bool popsMenuByArrowKeys() const override { return true; }
index 67c3a0f..1451eaa 100644 (file)
@@ -1365,43 +1365,23 @@ void RenderThemeMac::adjustMenuListStyle(StyleResolver& styleResolver, RenderSty
     style.setBoxShadow(nullptr);
 }
 
-int RenderThemeMac::popupInternalPaddingLeft(const RenderStyle& style) const
+LengthBox RenderThemeMac::popupInternalPaddingBox(const RenderStyle& style) const
 {
-    if (style.appearance() == MenulistPart)
-        return popupButtonPadding(controlSizeForFont(style))[leftPadding] * style.effectiveZoom();
-    if (style.appearance() == MenulistButtonPart)
-        return styledPopupPaddingLeft * style.effectiveZoom();
-    return 0;
-}
+    if (style.appearance() == MenulistPart) {
+        return { static_cast<int>(popupButtonPadding(controlSizeForFont(style))[topPadding] * style.effectiveZoom()),
+            static_cast<int>(popupButtonPadding(controlSizeForFont(style))[rightPadding] * style.effectiveZoom()),
+            static_cast<int>(popupButtonPadding(controlSizeForFont(style))[bottomPadding] * style.effectiveZoom()),
+            static_cast<int>(popupButtonPadding(controlSizeForFont(style))[leftPadding] * style.effectiveZoom()) };
+    }
 
-int RenderThemeMac::popupInternalPaddingRight(const RenderStyle& style) const
-{
-    if (style.appearance() == MenulistPart)
-        return popupButtonPadding(controlSizeForFont(style))[rightPadding] * style.effectiveZoom();
     if (style.appearance() == MenulistButtonPart) {
-        float fontScale = style.fontSize() / baseFontSize;
-        float arrowWidth = baseArrowWidth * fontScale;
-        return static_cast<int>(ceilf(arrowWidth + (arrowPaddingLeft + arrowPaddingRight + paddingBeforeSeparator) * style.effectiveZoom()));
+        float arrowWidth = baseArrowWidth * (style.fontSize() / baseFontSize);
+        return { static_cast<int>(styledPopupPaddingTop * style.effectiveZoom()),
+            static_cast<int>(ceilf(arrowWidth + (arrowPaddingLeft + arrowPaddingRight + paddingBeforeSeparator) * style.effectiveZoom())),
+            static_cast<int>(styledPopupPaddingBottom * style.effectiveZoom()), static_cast<int>(styledPopupPaddingLeft * style.effectiveZoom()) };
     }
-    return 0;
-}
 
-int RenderThemeMac::popupInternalPaddingTop(const RenderStyle& style) const
-{
-    if (style.appearance() == MenulistPart)
-        return popupButtonPadding(controlSizeForFont(style))[topPadding] * style.effectiveZoom();
-    if (style.appearance() == MenulistButtonPart)
-        return styledPopupPaddingTop * style.effectiveZoom();
-    return 0;
-}
-
-int RenderThemeMac::popupInternalPaddingBottom(const RenderStyle& style) const
-{
-    if (style.appearance() == MenulistPart)
-        return popupButtonPadding(controlSizeForFont(style))[bottomPadding] * style.effectiveZoom();
-    if (style.appearance() == MenulistButtonPart)
-        return styledPopupPaddingBottom * style.effectiveZoom();
-    return 0;
+    return { 0, 0, 0, 0 };
 }
 
 PopupMenuStyle::PopupMenuSize RenderThemeMac::popupMenuSize(const RenderStyle& style, IntRect& rect) const