Title: [195122] releases/WebKitGTK/webkit-2.10/Source/WebCore
Revision
195122
Author
[email protected]
Date
2016-01-15 04:37:54 -0800 (Fri, 15 Jan 2016)

Log Message

Merge r194844 - [GTK] Cleanup ScrollbarThemeGtk
https://bugs.webkit.org/show_bug.cgi?id=152830

Reviewed by Michael Catanzaro.

Use a common path for GTK+ 3.19 and previous versions, simplifying
the code and removing a lot of ifdefs. Use always a new
GtkStyleContext, but when painting cache the newly created one so
all paint methods use that one. We were also caching some theme
properties assuming they don't change unless the theme changes,
but some of them can have different values depending on the state,
for example, when hovered or pressed. Those properties are now
only cached when we create a new GtkStyleContext.
The method updateScrollbarsFrameThickness() has also been removed,
since the Scrollbar constructor already initializes the frame rect
using the scrollbarThickness(). This method was not doing anything
anyway, since that was called on the constructor of the theme,
when there were no scrollbars registered. This also means we no
longer need to track registered/unregistered scrollbars.

* platform/gtk/ScrollbarThemeGtk.cpp:
(WebCore::ScrollbarThemeGtk::backButtonRect): Use the cached
GtkStyleContext and properties or create a new.
(WebCore::ScrollbarThemeGtk::forwardButtonRect): Ditto.
(WebCore::ScrollbarThemeGtk::trackRect): Ditto.
(WebCore::orientationStyleClass):
(WebCore::ScrollbarThemeGtk::getOrCreateStyleContext): Create a
new GtkStyleContext for the scrollbar if there isn't a cached
one. Also initialize the properties that depend on the state.
(WebCore::createChildStyleContext): Create a new GtkStyleContext
from a parent one.
(WebCore::ScrollbarThemeGtk::updateThemeProperties): Get the
properties that can only change when the theme changes.
(WebCore::ScrollbarThemeGtk::thumbRect): Use the cached
GtkStyleContext and properties or create a new.
(WebCore::adjustRectAccordingToMargin): Use always the
GtkStyleContext state instead of receiving it and setting it again.
(WebCore::ScrollbarThemeGtk::paintTrackBackground): Get or create
a GtkStyleContext for the scrollbar and create a child one for the trough.
(WebCore::ScrollbarThemeGtk::paintScrollbarBackground): Use the
cached GtkStyleContext or create a new one.
(WebCore::ScrollbarThemeGtk::paintThumb): Get or create a
GtkStyleContext for the scrollbar and create a child ones for
trough and slider.
(WebCore::ScrollbarThemeGtk::paintButton): Get or create a
GtkStyleContext for the scrollbar and create a child one for the button.
(WebCore::ScrollbarThemeGtk::paint): Create a GtkStyleContext and
cache it temporarily using TemporaryChange until the method finishes.
(WebCore::ScrollbarThemeGtk::scrollbarThickness): Use the cached
GtkStyleContext and properties or create a new.
(WebCore::ScrollbarThemeGtk::buttonSize): Ditto.
* platform/gtk/ScrollbarThemeGtk.h:

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/ChangeLog (195121 => 195122)


--- releases/WebKitGTK/webkit-2.10/Source/WebCore/ChangeLog	2016-01-15 12:37:36 UTC (rev 195121)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/ChangeLog	2016-01-15 12:37:54 UTC (rev 195122)
@@ -1,3 +1,58 @@
+2016-01-11  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Cleanup ScrollbarThemeGtk
+        https://bugs.webkit.org/show_bug.cgi?id=152830
+
+        Reviewed by Michael Catanzaro.
+
+        Use a common path for GTK+ 3.19 and previous versions, simplifying
+        the code and removing a lot of ifdefs. Use always a new
+        GtkStyleContext, but when painting cache the newly created one so
+        all paint methods use that one. We were also caching some theme
+        properties assuming they don't change unless the theme changes,
+        but some of them can have different values depending on the state,
+        for example, when hovered or pressed. Those properties are now
+        only cached when we create a new GtkStyleContext.
+        The method updateScrollbarsFrameThickness() has also been removed,
+        since the Scrollbar constructor already initializes the frame rect
+        using the scrollbarThickness(). This method was not doing anything
+        anyway, since that was called on the constructor of the theme,
+        when there were no scrollbars registered. This also means we no
+        longer need to track registered/unregistered scrollbars.
+
+        * platform/gtk/ScrollbarThemeGtk.cpp:
+        (WebCore::ScrollbarThemeGtk::backButtonRect): Use the cached
+        GtkStyleContext and properties or create a new.
+        (WebCore::ScrollbarThemeGtk::forwardButtonRect): Ditto.
+        (WebCore::ScrollbarThemeGtk::trackRect): Ditto.
+        (WebCore::orientationStyleClass):
+        (WebCore::ScrollbarThemeGtk::getOrCreateStyleContext): Create a
+        new GtkStyleContext for the scrollbar if there isn't a cached
+        one. Also initialize the properties that depend on the state.
+        (WebCore::createChildStyleContext): Create a new GtkStyleContext
+        from a parent one.
+        (WebCore::ScrollbarThemeGtk::updateThemeProperties): Get the
+        properties that can only change when the theme changes.
+        (WebCore::ScrollbarThemeGtk::thumbRect): Use the cached
+        GtkStyleContext and properties or create a new.
+        (WebCore::adjustRectAccordingToMargin): Use always the
+        GtkStyleContext state instead of receiving it and setting it again.
+        (WebCore::ScrollbarThemeGtk::paintTrackBackground): Get or create
+        a GtkStyleContext for the scrollbar and create a child one for the trough.
+        (WebCore::ScrollbarThemeGtk::paintScrollbarBackground): Use the
+        cached GtkStyleContext or create a new one.
+        (WebCore::ScrollbarThemeGtk::paintThumb): Get or create a
+        GtkStyleContext for the scrollbar and create a child ones for
+        trough and slider.
+        (WebCore::ScrollbarThemeGtk::paintButton): Get or create a
+        GtkStyleContext for the scrollbar and create a child one for the button.
+        (WebCore::ScrollbarThemeGtk::paint): Create a GtkStyleContext and
+        cache it temporarily using TemporaryChange until the method finishes.
+        (WebCore::ScrollbarThemeGtk::scrollbarThickness): Use the cached
+        GtkStyleContext and properties or create a new.
+        (WebCore::ScrollbarThemeGtk::buttonSize): Ditto.
+        * platform/gtk/ScrollbarThemeGtk.h:
+
 2016-01-08  Zalan Bujtas  <[email protected]>
 
         Absolute positioning -webkit-search-cancel-button crashes Safari.

Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/platform/gtk/ScrollbarThemeGtk.cpp (195121 => 195122)


--- releases/WebKitGTK/webkit-2.10/Source/WebCore/platform/gtk/ScrollbarThemeGtk.cpp	2016-01-15 12:37:36 UTC (rev 195121)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/platform/gtk/ScrollbarThemeGtk.cpp	2016-01-15 12:37:54 UTC (rev 195122)
@@ -33,7 +33,7 @@
 #include "Scrollbar.h"
 #include <gtk/gtk.h>
 #include <wtf/NeverDestroyed.h>
-#include <wtf/glib/GRefPtr.h>
+#include <wtf/TemporaryChange.h>
 
 namespace WebCore {
 
@@ -67,18 +67,19 @@
     if (part == BackButtonStartPart && !m_hasBackButtonStartPart)
         return IntRect();
 
-    int x = scrollbar.x() + m_troughBorderWidth;
-    int y = scrollbar.y() + m_troughBorderWidth;
+    GRefPtr<GtkStyleContext> styleContext = getOrCreateStyleContext();
+    int x = scrollbar.x() + m_cachedProperties.troughBorderWidth;
+    int y = scrollbar.y() + m_cachedProperties.troughBorderWidth;
     IntSize size = buttonSize(scrollbar);
     if (part == BackButtonStartPart)
         return IntRect(x, y, size.width(), size.height());
 
     // BackButtonEndPart (alternate button)
     if (scrollbar.orientation() == HorizontalScrollbar)
-        return IntRect(scrollbar.x() + scrollbar.width() - m_troughBorderWidth - (2 * size.width()), y, size.width(), size.height());
+        return IntRect(scrollbar.x() + scrollbar.width() - m_cachedProperties.troughBorderWidth - (2 * size.width()), y, size.width(), size.height());
 
     // VerticalScrollbar alternate button
-    return IntRect(x, scrollbar.y() + scrollbar.height() - m_troughBorderWidth - (2 * size.height()), size.width(), size.height());
+    return IntRect(x, scrollbar.y() + scrollbar.height() - m_cachedProperties.troughBorderWidth - (2 * size.height()), size.width(), size.height());
 #else
     UNUSED_PARAM(scrollbar);
     UNUSED_PARAM(part);
@@ -94,23 +95,24 @@
     if (part == ForwardButtonEndPart && !m_hasForwardButtonEndPart)
         return IntRect();
 
+    GRefPtr<GtkStyleContext> styleContext = getOrCreateStyleContext();
     IntSize size = buttonSize(scrollbar);
     if (scrollbar.orientation() == HorizontalScrollbar) {
-        int y = scrollbar.y() + m_troughBorderWidth;
+        int y = scrollbar.y() + m_cachedProperties.troughBorderWidth;
         if (part == ForwardButtonEndPart)
-            return IntRect(scrollbar.x() + scrollbar.width() - size.width() - m_troughBorderWidth, y, size.width(), size.height());
+            return IntRect(scrollbar.x() + scrollbar.width() - size.width() - m_cachedProperties.troughBorderWidth, y, size.width(), size.height());
 
         // ForwardButtonStartPart (alternate button)
-        return IntRect(scrollbar.x() + m_troughBorderWidth + size.width(), y, size.width(), size.height());
+        return IntRect(scrollbar.x() + m_cachedProperties.troughBorderWidth + size.width(), y, size.width(), size.height());
     }
 
     // VerticalScrollbar
-    int x = scrollbar.x() + m_troughBorderWidth;
+    int x = scrollbar.x() + m_cachedProperties.troughBorderWidth;
     if (part == ForwardButtonEndPart)
-        return IntRect(x, scrollbar.y() + scrollbar.height() - size.height() - m_troughBorderWidth, size.width(), size.height());
+        return IntRect(x, scrollbar.y() + scrollbar.height() - size.height() - m_cachedProperties.troughBorderWidth, size.width(), size.height());
 
     // ForwardButtonStartPart (alternate button)
-    return IntRect(x, scrollbar.y() + m_troughBorderWidth + size.height(), size.width(), size.height());
+    return IntRect(x, scrollbar.y() + m_cachedProperties.troughBorderWidth + size.height(), size.width(), size.height());
 #else
     UNUSED_PARAM(scrollbar);
     UNUSED_PARAM(part);
@@ -121,10 +123,11 @@
 IntRect ScrollbarThemeGtk::trackRect(Scrollbar& scrollbar, bool)
 {
 #ifndef GTK_API_VERSION_2
+    GRefPtr<GtkStyleContext> styleContext = getOrCreateStyleContext();
     // The padding along the thumb movement axis includes the trough border
     // plus the size of stepper spacing (the space between the stepper and
     // the place where the thumb stops). There is often no stepper spacing.
-    int movementAxisPadding = m_troughBorderWidth + m_stepperSpacing;
+    int movementAxisPadding = m_cachedProperties.troughBorderWidth + m_cachedProperties.stepperSpacing;
 
     // The fatness of the scrollbar on the non-movement axis.
     int thickness = scrollbarThickness(scrollbar.controlSize());
@@ -132,17 +135,17 @@
     int startButtonsOffset = 0;
     int buttonsWidth = 0;
     if (m_hasForwardButtonStartPart) {
-        startButtonsOffset += m_stepperSize;
-        buttonsWidth += m_stepperSize;
+        startButtonsOffset += m_cachedProperties.stepperSize;
+        buttonsWidth += m_cachedProperties.stepperSize;
     }
     if (m_hasBackButtonStartPart) {
-        startButtonsOffset += m_stepperSize;
-        buttonsWidth += m_stepperSize;
+        startButtonsOffset += m_cachedProperties.stepperSize;
+        buttonsWidth += m_cachedProperties.stepperSize;
     }
     if (m_hasBackButtonEndPart)
-        buttonsWidth += m_stepperSize;
+        buttonsWidth += m_cachedProperties.stepperSize;
     if (m_hasForwardButtonEndPart)
-        buttonsWidth += m_stepperSize;
+        buttonsWidth += m_cachedProperties.stepperSize;
 
     if (scrollbar.orientation() == HorizontalScrollbar) {
         // Once the scrollbar becomes smaller than the natural size of the
@@ -164,42 +167,56 @@
 }
 
 #ifndef GTK_API_VERSION_2
+static inline const char* orientationStyleClass(ScrollbarOrientation orientation)
+{
+    return orientation == VerticalScrollbar ? "vertical" : "horizontal";
+}
 
-#if !GTK_CHECK_VERSION(3, 19, 2)
-// Currently we use a static GtkStyleContext for GTK+ < 3.19, and a bunch of unique
-// GtkStyleContexts for GTK+ >= 3.19. This is crazy and definitely should not be necessary, but I
-// couldn't find any other way to not break one version or the other. Ideally one of the two
-// people on the planet who really understand GTK+ styles would fix this.
-class ScrollbarStyleContext {
-    WTF_MAKE_NONCOPYABLE(ScrollbarStyleContext); WTF_MAKE_FAST_ALLOCATED;
-public:
-    ScrollbarStyleContext()
-        : m_context(adoptGRef(gtk_style_context_new()))
-    {
-        GtkWidgetPath* path = gtk_widget_path_new();
-        gtk_widget_path_append_type(path, GTK_TYPE_SCROLLBAR);
-        gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_SCROLLBAR);
-        gtk_style_context_set_path(m_context.get(), path);
-        gtk_widget_path_free(path);
-    }
+GRefPtr<GtkStyleContext> ScrollbarThemeGtk::getOrCreateStyleContext(ScrollbarOrientation orientation)
+{
+    if (m_cachedStyleContext)
+        return m_cachedStyleContext;
 
-    ~ScrollbarStyleContext()
-    {
-    }
+    GRefPtr<GtkStyleContext> styleContext = adoptGRef(gtk_style_context_new());
+    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
+#if GTK_CHECK_VERSION(3, 19, 2)
+    gtk_widget_path_iter_set_object_name(path.get(), -1, "scrollbar");
+#else
+    gtk_widget_path_iter_add_class(path.get(), -1, "scrollbar");
+#endif
+    gtk_widget_path_iter_add_class(path.get(), -1, orientationStyleClass(orientation));
+    gtk_style_context_set_path(styleContext.get(), path.get());
 
-    GtkStyleContext* context() const { return m_context.get(); }
+    gtk_style_context_get_style(
+        styleContext.get(),
+        "slider-width", &m_cachedProperties.thumbFatness,
+        "trough-border", &m_cachedProperties.troughBorderWidth,
+        "stepper-size", &m_cachedProperties.stepperSize,
+        "stepper-spacing", &m_cachedProperties.stepperSpacing,
+        "trough-under-steppers", &m_cachedProperties.troughUnderSteppers,
+        nullptr);
 
-private:
-    GRefPtr<GtkStyleContext> m_context;
-};
+    return styleContext;
+}
 
-static GtkStyleContext* gtkScrollbarStyleContext()
+static GRefPtr<GtkStyleContext> createChildStyleContext(GtkStyleContext* parent, const char* name)
 {
-    static NeverDestroyed<ScrollbarStyleContext> styleContext;
-    return styleContext.get().context();
-}
+    ASSERT(parent);
+    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_copy(gtk_style_context_get_path(parent)));
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
+#if GTK_CHECK_VERSION(3, 19, 2)
+    gtk_widget_path_iter_set_object_name(path.get(), -1, name);
+#else
+    gtk_widget_path_iter_add_class(path.get(), -1, name);
 #endif
 
+    GRefPtr<GtkStyleContext> styleContext = adoptGRef(gtk_style_context_new());
+    gtk_style_context_set_path(styleContext.get(), path.get());
+    gtk_style_context_set_parent(styleContext.get(), parent);
+    return styleContext;
+}
+
 ScrollbarThemeGtk::ScrollbarThemeGtk()
 {
     updateThemeProperties();
@@ -207,111 +224,37 @@
 
 void ScrollbarThemeGtk::themeChanged()
 {
-#if !GTK_CHECK_VERSION(3, 19, 2)
-    gtk_style_context_invalidate(gtkScrollbarStyleContext());
-#endif
     updateThemeProperties();
 }
 
 void ScrollbarThemeGtk::updateThemeProperties()
 {
-#if GTK_CHECK_VERSION(3, 19, 2)
-    GRefPtr<GtkStyleContext> styleContext = adoptGRef(gtk_style_context_new());
-    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
-
-    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
-    gtk_widget_path_iter_set_object_name(path.get(), 0, "scrollbar");
-
-    gtk_style_context_set_path(styleContext.get(), path.get());
-#else
-    GRefPtr<GtkStyleContext> styleContext = gtkScrollbarStyleContext();
-#endif
-
+    GRefPtr<GtkStyleContext> styleContext = getOrCreateStyleContext();
     gtk_style_context_get_style(
         styleContext.get(),
         "min-slider-length", &m_minThumbLength,
-        "slider-width", &m_thumbFatness,
-        "trough-border", &m_troughBorderWidth,
-        "stepper-size", &m_stepperSize,
-        "stepper-spacing", &m_stepperSpacing,
-        "trough-under-steppers", &m_troughUnderSteppers,
         "has-backward-stepper", &m_hasBackButtonStartPart,
         "has-forward-stepper", &m_hasForwardButtonEndPart,
         "has-secondary-backward-stepper", &m_hasBackButtonEndPart,
         "has-secondary-forward-stepper", &m_hasForwardButtonStartPart,
         nullptr);
-    updateScrollbarsFrameThickness();
 }
 
-typedef HashSet<Scrollbar*> ScrollbarMap;
-
-static ScrollbarMap& scrollbarMap()
-{
-    static NeverDestroyed<ScrollbarMap> map;
-    return map;
-}
-
-void ScrollbarThemeGtk::registerScrollbar(Scrollbar& scrollbar)
-{
-    scrollbarMap().add(&scrollbar);
-}
-
-void ScrollbarThemeGtk::unregisterScrollbar(Scrollbar& scrollbar)
-{
-    scrollbarMap().remove(&scrollbar);
-}
-
-void ScrollbarThemeGtk::updateScrollbarsFrameThickness()
-{
-    if (scrollbarMap().isEmpty())
-        return;
-
-    // Update the thickness of every interior frame scrollbar widget. The
-    // platform-independent scrollbar them code isn't yet smart enough to get
-    // this information when it paints.
-    for (const auto& scrollbar : scrollbarMap()) {
-        // Top-level scrollbar i.e. scrollbars who have a parent ScrollView
-        // with no parent are native, and thus do not need to be resized.
-        if (!scrollbar->parent() || !scrollbar->parent()->parent())
-            return;
-
-        int thickness = scrollbarThickness(scrollbar->controlSize());
-        if (scrollbar->orientation() == HorizontalScrollbar)
-            scrollbar->setFrameRect(IntRect(0, scrollbar->parent()->height() - thickness, scrollbar->width(), thickness));
-        else
-            scrollbar->setFrameRect(IntRect(scrollbar->parent()->width() - thickness, 0, thickness, scrollbar->height()));
-    }
-}
-
 IntRect ScrollbarThemeGtk::thumbRect(Scrollbar& scrollbar, const IntRect& unconstrainedTrackRect)
 {
+    GRefPtr<GtkStyleContext> styleContext = getOrCreateStyleContext(scrollbar.orientation());
     IntRect trackRect = constrainTrackRectToTrackPieces(scrollbar, unconstrainedTrackRect);
     int thumbPos = thumbPosition(scrollbar);
     if (scrollbar.orientation() == HorizontalScrollbar)
-        return IntRect(trackRect.x() + thumbPos, trackRect.y() + (trackRect.height() - m_thumbFatness) / 2, thumbLength(scrollbar), m_thumbFatness); 
+        return IntRect(trackRect.x() + thumbPos, trackRect.y() + (trackRect.height() - m_cachedProperties.thumbFatness) / 2, thumbLength(scrollbar), m_cachedProperties.thumbFatness);
 
     // VerticalScrollbar
-    return IntRect(trackRect.x() + (trackRect.width() - m_thumbFatness) / 2, trackRect.y() + thumbPos, m_thumbFatness, thumbLength(scrollbar));
+    return IntRect(trackRect.x() + (trackRect.width() - m_cachedProperties.thumbFatness) / 2, trackRect.y() + thumbPos, m_cachedProperties.thumbFatness, thumbLength(scrollbar));
 }
 
-
-static const char* orientationStyleClass(ScrollbarOrientation orientation)
+static void adjustRectAccordingToMargin(GtkStyleContext* context, IntRect& rect)
 {
-    return orientation == VerticalScrollbar ? "vertical" : "horizontal";
-}
-
-#if !GTK_CHECK_VERSION(3, 19, 2)
-static void applyScrollbarStyleContextClasses(GtkStyleContext* context, ScrollbarOrientation orientation)
-{
-    gtk_style_context_add_class(context, GTK_STYLE_CLASS_SCROLLBAR);
-    gtk_style_context_add_class(context, orientationStyleClass(orientation));
-}
-#endif
-
-static void adjustRectAccordingToMargin(GtkStyleContext* context, GtkStateFlags state, IntRect& rect)
-{
     GtkBorder margin;
-    gtk_style_context_set_state(context, state);
     gtk_style_context_get_margin(context, gtk_style_context_get_state(context), &margin);
     rect.move(margin.left, margin.right);
     rect.contract(margin.left + margin.right, margin.top + margin.bottom);
@@ -319,97 +262,34 @@
 
 void ScrollbarThemeGtk::paintTrackBackground(GraphicsContext& context, Scrollbar& scrollbar, const IntRect& rect)
 {
+    GRefPtr<GtkStyleContext> parentStyleContext = getOrCreateStyleContext(scrollbar.orientation());
     // Paint the track background. If the trough-under-steppers property is true, this
     // should be the full size of the scrollbar, but if is false, it should only be the
     // track rect.
     IntRect fullScrollbarRect(rect);
-    if (m_troughUnderSteppers)
+    if (m_cachedProperties.troughUnderSteppers)
         fullScrollbarRect = IntRect(scrollbar.x(), scrollbar.y(), scrollbar.width(), scrollbar.height());
 
-#if GTK_CHECK_VERSION(3, 19, 2)
-    GRefPtr<GtkStyleContext> styleContext = adoptGRef(gtk_style_context_new());
-    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
-
-    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
-    gtk_widget_path_iter_set_object_name(path.get(), 0, "scrollbar");
-    gtk_widget_path_iter_add_class(path.get(), 0, orientationStyleClass(scrollbar.orientation()));
-
-    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
-    gtk_widget_path_iter_set_object_name(path.get(), 1, "trough");
-
-    gtk_style_context_set_path(styleContext.get(), path.get());
-#else
-    GRefPtr<GtkStyleContext> styleContext = gtkScrollbarStyleContext();
-    gtk_style_context_save(styleContext.get());
-
-    applyScrollbarStyleContextClasses(styleContext.get(), scrollbar.orientation());
-    gtk_style_context_add_class(styleContext.get(), GTK_STYLE_CLASS_TROUGH);
-#endif
-
-    adjustRectAccordingToMargin(styleContext.get(), static_cast<GtkStateFlags>(0), fullScrollbarRect);
+    GRefPtr<GtkStyleContext> styleContext = createChildStyleContext(parentStyleContext.get(), "trough");
+    adjustRectAccordingToMargin(styleContext.get(), fullScrollbarRect);
     gtk_render_background(styleContext.get(), context.platformContext()->cr(), fullScrollbarRect.x(), fullScrollbarRect.y(), fullScrollbarRect.width(), fullScrollbarRect.height());
     gtk_render_frame(styleContext.get(), context.platformContext()->cr(), fullScrollbarRect.x(), fullScrollbarRect.y(), fullScrollbarRect.width(), fullScrollbarRect.height());
-
-#if !GTK_CHECK_VERSION(3, 19, 2)
-    gtk_style_context_restore(styleContext.get());
-#endif
 }
 
 void ScrollbarThemeGtk::paintScrollbarBackground(GraphicsContext& context, Scrollbar& scrollbar)
 {
-#if GTK_CHECK_VERSION(3, 19, 2)
-    GRefPtr<GtkStyleContext> styleContext = adoptGRef(gtk_style_context_new());
-    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
-
-    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
-    gtk_widget_path_iter_set_object_name(path.get(), 0, "scrollbar");
-    gtk_widget_path_iter_add_class(path.get(), 0, orientationStyleClass(scrollbar.orientation()));
-
-    gtk_style_context_set_path(styleContext.get(), path.get());
-#else
-    GRefPtr<GtkStyleContext> styleContext = gtkScrollbarStyleContext();
-    gtk_style_context_save(styleContext.get());
-
-    applyScrollbarStyleContextClasses(styleContext.get(), scrollbar.orientation());
-    gtk_style_context_add_class(styleContext.get(), "scrolled-window");
-#endif
-
+    GRefPtr<GtkStyleContext> styleContext = getOrCreateStyleContext(scrollbar.orientation());
     gtk_render_frame(styleContext.get(), context.platformContext()->cr(), scrollbar.x(), scrollbar.y(), scrollbar.width(), scrollbar.height());
-
-#if !GTK_CHECK_VERSION(3, 19, 2)
-    gtk_style_context_restore(styleContext.get());
-#endif
 }
 
 void ScrollbarThemeGtk::paintThumb(GraphicsContext& context, Scrollbar& scrollbar, const IntRect& rect)
 {
-#if GTK_CHECK_VERSION(3, 19, 2)
-    GRefPtr<GtkStyleContext> styleContext = adoptGRef(gtk_style_context_new());
-    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
-
-    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
-    gtk_widget_path_iter_set_object_name(path.get(), 0, "scrollbar");
-    gtk_widget_path_iter_add_class(path.get(), 0, orientationStyleClass(scrollbar.orientation()));
-
-    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
-    gtk_widget_path_iter_set_object_name(path.get(), 1, "trough");
-
-    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
-    gtk_widget_path_iter_set_object_name(path.get(), 2, "slider");
-
-    gtk_style_context_set_path(styleContext.get(), path.get());
-#else
-    GRefPtr<GtkStyleContext> styleContext = gtkScrollbarStyleContext();
-    gtk_style_context_save(styleContext.get());
-#endif
-
     ScrollbarOrientation orientation = scrollbar.orientation();
-#if !GTK_CHECK_VERSION(3, 19, 2)
-    applyScrollbarStyleContextClasses(styleContext.get(), orientation);
-    gtk_style_context_add_class(styleContext.get(), GTK_STYLE_CLASS_SLIDER);
-#endif
+    GRefPtr<GtkStyleContext> parentStyleContext = getOrCreateStyleContext(orientation);
+    GRefPtr<GtkStyleContext> troughStyleContext = createChildStyleContext(parentStyleContext.get(), "trough");
+    GRefPtr<GtkStyleContext> styleContext = createChildStyleContext(troughStyleContext.get(), "slider");
 
-    guint flags = 0;
+    unsigned flags = 0;
     if (scrollbar.pressedPart() == ThumbPart)
         flags |= GTK_STATE_FLAG_ACTIVE;
     if (scrollbar.hoveredPart() == ThumbPart)
@@ -417,40 +297,18 @@
     gtk_style_context_set_state(styleContext.get(), static_cast<GtkStateFlags>(flags));
 
     IntRect thumbRect(rect);
-    adjustRectAccordingToMargin(styleContext.get(), static_cast<GtkStateFlags>(flags), thumbRect);
+    adjustRectAccordingToMargin(styleContext.get(), thumbRect);
     gtk_render_slider(styleContext.get(), context.platformContext()->cr(), thumbRect.x(), thumbRect.y(), thumbRect.width(), thumbRect.height(),
         orientation == VerticalScrollbar ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL);
-
-#if !GTK_CHECK_VERSION(3, 19, 2)
-    gtk_style_context_restore(styleContext.get());
-#endif
 }
 
 void ScrollbarThemeGtk::paintButton(GraphicsContext& context, Scrollbar& scrollbar, const IntRect& rect, ScrollbarPart part)
 {
-#if GTK_CHECK_VERSION(3, 19, 2)
-    GRefPtr<GtkStyleContext> styleContext = adoptGRef(gtk_style_context_new());
-    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
-
-    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
-    gtk_widget_path_iter_set_object_name(path.get(), 0, "scrollbar");
-    gtk_widget_path_iter_add_class(path.get(), 0, orientationStyleClass(scrollbar.orientation()));
-
-    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
-    gtk_widget_path_iter_set_object_name(path.get(), 1, "button");
-
-    gtk_style_context_set_path(styleContext.get(), path.get());
-#else
-    GRefPtr<GtkStyleContext> styleContext = gtkScrollbarStyleContext();
-    gtk_style_context_save(styleContext.get());
-#endif
-
     ScrollbarOrientation orientation = scrollbar.orientation();
-#if !GTK_CHECK_VERSION(3, 19, 2)
-    applyScrollbarStyleContextClasses(styleContext.get(), orientation);
-#endif
+    GRefPtr<GtkStyleContext> parentStyleContext = getOrCreateStyleContext(orientation);
+    GRefPtr<GtkStyleContext> styleContext = createChildStyleContext(parentStyleContext.get(), "button");
 
-    guint flags = 0;
+    unsigned flags = 0;
     if ((BackButtonStartPart == part && scrollbar.currentPos())
         || (BackButtonEndPart == part && scrollbar.currentPos())
         || (ForwardButtonEndPart == part && scrollbar.currentPos() != scrollbar.maximum())
@@ -463,10 +321,6 @@
         flags |= GTK_STATE_FLAG_INSENSITIVE;
     gtk_style_context_set_state(styleContext.get(), static_cast<GtkStateFlags>(flags));
 
-#if !GTK_CHECK_VERSION(3, 19, 2)
-    gtk_style_context_add_class(styleContext.get(), GTK_STYLE_CLASS_BUTTON);
-#endif
-
     gtk_render_background(styleContext.get(), context.platformContext()->cr(), rect.x(), rect.y(), rect.width(), rect.height());
     gtk_render_frame(styleContext.get(), context.platformContext()->cr(), rect.x(), rect.y(), rect.width(), rect.height());
 
@@ -491,10 +345,6 @@
         angle = (part == ForwardButtonEndPart || part == ForwardButtonStartPart) ? G_PI / 2 : 3 * (G_PI / 2);
 
     gtk_render_arrow(styleContext.get(), context.platformContext()->cr(), angle, arrowPoint.x(), arrowPoint.y(), arrowSize);
-
-#if !GTK_CHECK_VERSION(3, 19, 2)
-    gtk_style_context_restore(styleContext.get());
-#endif
 }
 
 bool ScrollbarThemeGtk::paint(Scrollbar& scrollbar, GraphicsContext& graphicsContext, const IntRect& damageRect)
@@ -502,6 +352,8 @@
     if (graphicsContext.paintingDisabled())
         return false;
 
+    TemporaryChange<GRefPtr<GtkStyleContext>> tempStyleContext(m_cachedStyleContext, getOrCreateStyleContext(scrollbar.orientation()));
+
     // Create the ScrollbarControlPartMask based on the damageRect
     ScrollbarControlPartMask scrollMask = NoPart;
 
@@ -528,7 +380,7 @@
     if (damageRect.intersects(trackPaintRect))
         scrollMask |= TrackBGPart;
 
-    if (m_troughUnderSteppers && (scrollMask & BackButtonStartPart
+    if (m_cachedProperties.troughUnderSteppers && (scrollMask & BackButtonStartPart
             || scrollMask & BackButtonEndPart
             || scrollMask & ForwardButtonStartPart
             || scrollMask & ForwardButtonEndPart))
@@ -572,16 +424,18 @@
 
 int ScrollbarThemeGtk::scrollbarThickness(ScrollbarControlSize)
 {
-    return m_thumbFatness + (m_troughBorderWidth * 2);
+    GRefPtr<GtkStyleContext> styleContext = getOrCreateStyleContext();
+    return m_cachedProperties.thumbFatness + (m_cachedProperties.troughBorderWidth * 2);
 }
 
 IntSize ScrollbarThemeGtk::buttonSize(Scrollbar& scrollbar)
 {
+    GRefPtr<GtkStyleContext> styleContext = getOrCreateStyleContext(scrollbar.orientation());
     if (scrollbar.orientation() == VerticalScrollbar)
-        return IntSize(m_thumbFatness, m_stepperSize);
+        return IntSize(m_cachedProperties.thumbFatness, m_cachedProperties.stepperSize);
 
     // HorizontalScrollbar
-    return IntSize(m_stepperSize, m_thumbFatness);
+    return IntSize(m_cachedProperties.stepperSize, m_cachedProperties.thumbFatness);
 }
 
 int ScrollbarThemeGtk::minimumThumbLength(Scrollbar&)

Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/platform/gtk/ScrollbarThemeGtk.h (195121 => 195122)


--- releases/WebKitGTK/webkit-2.10/Source/WebCore/platform/gtk/ScrollbarThemeGtk.h	2016-01-15 12:37:36 UTC (rev 195121)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/platform/gtk/ScrollbarThemeGtk.h	2016-01-15 12:37:54 UTC (rev 195122)
@@ -27,53 +27,58 @@
 #define ScrollbarThemeGtk_h
 
 #include "ScrollbarThemeComposite.h"
+#include <wtf/glib/GRefPtr.h>
 
 namespace WebCore {
 
 class Scrollbar;
 
-class ScrollbarThemeGtk : public ScrollbarThemeComposite {
+class ScrollbarThemeGtk final : public ScrollbarThemeComposite {
 public:
     virtual ~ScrollbarThemeGtk();
 
-    virtual bool hasButtons(Scrollbar&) { return true; }
-    virtual bool hasThumb(Scrollbar&);
-    virtual IntRect backButtonRect(Scrollbar&, ScrollbarPart, bool);
-    virtual IntRect forwardButtonRect(Scrollbar&, ScrollbarPart, bool);
-    virtual IntRect trackRect(Scrollbar&, bool);
+    virtual bool hasButtons(Scrollbar&) override { return true; }
+    virtual bool hasThumb(Scrollbar&) override;
+    virtual IntRect backButtonRect(Scrollbar&, ScrollbarPart, bool) override;
+    virtual IntRect forwardButtonRect(Scrollbar&, ScrollbarPart, bool) override;
+    virtual IntRect trackRect(Scrollbar&, bool) override;
 
 #ifndef GTK_API_VERSION_2
     ScrollbarThemeGtk();
 
     using ScrollbarThemeComposite::thumbRect;
     IntRect thumbRect(Scrollbar&, const IntRect& unconstrainedTrackRect);
-    bool paint(Scrollbar&, GraphicsContext&, const IntRect& damageRect);
-    void paintScrollbarBackground(GraphicsContext&, Scrollbar&);
-    void paintTrackBackground(GraphicsContext&, Scrollbar&, const IntRect&);
-    void paintThumb(GraphicsContext&, Scrollbar&, const IntRect&);
-    virtual void paintButton(GraphicsContext&, Scrollbar&, const IntRect&, ScrollbarPart);
-    virtual bool shouldCenterOnThumb(Scrollbar&, const PlatformMouseEvent&);
-    virtual int scrollbarThickness(ScrollbarControlSize);
-    virtual IntSize buttonSize(Scrollbar&);
-    virtual int minimumThumbLength(Scrollbar&);
+    bool paint(Scrollbar&, GraphicsContext&, const IntRect& damageRect) override;
+    void paintScrollbarBackground(GraphicsContext&, Scrollbar&) override;
+    void paintTrackBackground(GraphicsContext&, Scrollbar&, const IntRect&) override;
+    void paintThumb(GraphicsContext&, Scrollbar&, const IntRect&) override;
+    virtual void paintButton(GraphicsContext&, Scrollbar&, const IntRect&, ScrollbarPart) override;
+    virtual bool shouldCenterOnThumb(Scrollbar&, const PlatformMouseEvent&) override;
+    virtual int scrollbarThickness(ScrollbarControlSize) override;
+    virtual int minimumThumbLength(Scrollbar&) override;
 
     // TODO: These are the default GTK+ values. At some point we should pull these from the theme itself.
-    virtual double initialAutoscrollTimerDelay() { return 0.20; }
-    virtual double autoscrollTimerDelay() { return 0.02; }
+    virtual double initialAutoscrollTimerDelay() override { return 0.20; }
+    virtual double autoscrollTimerDelay() override { return 0.02; }
     void themeChanged();
-    void updateScrollbarsFrameThickness();
-    void registerScrollbar(Scrollbar&);
-    void unregisterScrollbar(Scrollbar&);
 
-protected:
+private:
     void updateThemeProperties();
+    GRefPtr<GtkStyleContext> getOrCreateStyleContext(ScrollbarOrientation = VerticalScrollbar);
 
-    int m_thumbFatness;
-    int m_troughBorderWidth;
-    int m_stepperSize;
-    int m_stepperSpacing;
+    IntSize buttonSize(Scrollbar&);
+
+    struct Properties {
+        int thumbFatness;
+        int troughBorderWidth;
+        int stepperSize;
+        int stepperSpacing;
+        gboolean troughUnderSteppers;
+    };
+
+    GRefPtr<GtkStyleContext> m_cachedStyleContext;
+    Properties m_cachedProperties;
     int m_minThumbLength;
-    gboolean m_troughUnderSteppers;
     gboolean m_hasForwardButtonStartPart;
     gboolean m_hasForwardButtonEndPart;
     gboolean m_hasBackButtonStartPart;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to