Changeset 75259 in webkit


Ignore:
Timestamp:
Jan 7, 2011 11:32:53 AM (13 years ago)
Author:
Carlos Garcia Campos
Message:

2011-01-07 Carlos Garcia Campos <cgarcia@igalia.com>

Reviewed by Martin Robinson.

[GTK] Port scrollbar painting to GtkStyleContext
https://bugs.webkit.org/show_bug.cgi?id=52051

  • wtf/gobject/GTypedefs.h: Add GtkStyleContext forward declaration.

2011-01-07 Carlos Garcia Campos <cgarcia@igalia.com>

Reviewed by Martin Robinson.

[GTK] Port scrollbar painting to GtkStyleContext
https://bugs.webkit.org/show_bug.cgi?id=52051

Use GtkStyleContext API to paint scrollbars when building with
GTK+ 3.x.

No new tests. This should not change functionality.

  • platform/gtk/RenderThemeGtk.h:
  • platform/gtk/RenderThemeGtk3.cpp: (WebCore::RenderThemeGtk::gtkScrollbarStyle):
  • platform/gtk/ScrollbarThemeGtk.cpp:
  • platform/gtk/ScrollbarThemeGtk.h:
  • platform/gtk/ScrollbarThemeGtk2.cpp: (WebCore::gtkStyleSetCallback): (WebCore::ScrollbarThemeGtk::ScrollbarThemeGtk):
  • platform/gtk/ScrollbarThemeGtk3.cpp: (WebCore::gtkStyleChangedCallback): (WebCore::ScrollbarThemeGtk::ScrollbarThemeGtk): (WebCore::ScrollbarThemeGtk::updateThemeProperties): (WebCore::ScrollbarThemeGtk::paintTrackBackground): (WebCore::ScrollbarThemeGtk::paintScrollbarBackground): (WebCore::ScrollbarThemeGtk::paintThumb): (WebCore::ScrollbarThemeGtk::paintButton):
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r75247 r75259  
     12011-01-07  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [GTK] Port scrollbar painting to GtkStyleContext
     6        https://bugs.webkit.org/show_bug.cgi?id=52051
     7
     8        * wtf/gobject/GTypedefs.h: Add GtkStyleContext forward
     9        declaration.
     10
    1112011-01-07  Daniel Bates  <dbates@rim.com>
    212
  • trunk/Source/JavaScriptCore/wtf/gobject/GTypedefs.h

    r73330 r75259  
    9090typedef struct _cairo_rectangle_int cairo_rectangle_int_t;
    9191typedef cairo_rectangle_int_t GdkRectangle;
     92typedef struct _GtkStyleContext GtkStyleContext;
    9293#endif
    9394
  • trunk/WebCore/ChangeLog

    r75257 r75259  
     12011-01-07  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [GTK] Port scrollbar painting to GtkStyleContext
     6        https://bugs.webkit.org/show_bug.cgi?id=52051
     7
     8        Use GtkStyleContext API to paint scrollbars when building with
     9        GTK+ 3.x.
     10
     11        No new tests. This should not change functionality.
     12
     13        * platform/gtk/RenderThemeGtk.h:
     14        * platform/gtk/RenderThemeGtk3.cpp:
     15        (WebCore::RenderThemeGtk::gtkScrollbarStyle):
     16        * platform/gtk/ScrollbarThemeGtk.cpp:
     17        * platform/gtk/ScrollbarThemeGtk.h:
     18        * platform/gtk/ScrollbarThemeGtk2.cpp:
     19        (WebCore::gtkStyleSetCallback):
     20        (WebCore::ScrollbarThemeGtk::ScrollbarThemeGtk):
     21        * platform/gtk/ScrollbarThemeGtk3.cpp:
     22        (WebCore::gtkStyleChangedCallback):
     23        (WebCore::ScrollbarThemeGtk::ScrollbarThemeGtk):
     24        (WebCore::ScrollbarThemeGtk::updateThemeProperties):
     25        (WebCore::ScrollbarThemeGtk::paintTrackBackground):
     26        (WebCore::ScrollbarThemeGtk::paintScrollbarBackground):
     27        (WebCore::ScrollbarThemeGtk::paintThumb):
     28        (WebCore::ScrollbarThemeGtk::paintButton):
     29
    1302011-01-07  Dan Bernstein  <mitz@apple.com>
    231
  • trunk/WebCore/platform/gtk/RenderThemeGtk.h

    r75241 r75259  
    8989    void getIndicatorMetrics(ControlPart, int& indicatorSize, int& indicatorSpacing) const;
    9090
     91#ifdef GTK_API_VERSION_2
    9192    GtkWidget* gtkScrollbar();
     93#else
     94    GtkStyleContext* gtkScrollbarStyle();
     95#endif
    9296
    9397protected:
  • trunk/WebCore/platform/gtk/RenderThemeGtk3.cpp

    r75255 r75259  
    634634}
    635635
    636 GtkWidget* RenderThemeGtk::gtkScrollbar()
    637 {
    638     return moz_gtk_get_scrollbar_widget();
     636GtkStyleContext* RenderThemeGtk::gtkScrollbarStyle()
     637{
     638    return getStyleContext(GTK_TYPE_SCROLLBAR);
    639639}
    640640
  • trunk/WebCore/platform/gtk/ScrollbarThemeGtk.cpp

    r75070 r75259  
    3535
    3636static HashSet<Scrollbar*>* gScrollbars;
    37 static void gtkStyleSetCallback(GtkWidget*, GtkStyle*, ScrollbarThemeGtk*);
    3837
    3938ScrollbarTheme* ScrollbarTheme::nativeTheme()
     
    4140    static ScrollbarThemeGtk theme;
    4241    return &theme;
    43 }
    44 
    45 ScrollbarThemeGtk::ScrollbarThemeGtk()
    46 {
    47     updateThemeProperties();
    48     g_signal_connect(static_cast<RenderThemeGtk*>(RenderTheme::defaultTheme().get())->gtkScrollbar(),
    49          "style-set", G_CALLBACK(gtkStyleSetCallback), this);
    5042}
    5143
     
    9385            scrollbar->setFrameRect(IntRect(scrollbar->parent()->width() - thickness, 0, thickness, scrollbar->height()));
    9486    }
    95 }
    96 
    97 static void gtkStyleSetCallback(GtkWidget* widget, GtkStyle* previous, ScrollbarThemeGtk* scrollbarTheme)
    98 {
    99     scrollbarTheme->updateThemeProperties();
    10087}
    10188
  • trunk/WebCore/platform/gtk/ScrollbarThemeGtk.h

    r75070 r75259  
    6464
    6565protected:
     66#ifndef GTK_API_VERSION_2
     67    GtkStyleContext* m_context;
     68#endif
    6669    int m_thumbFatness;
    6770    int m_troughBorderWidth;
     
    6972    int m_stepperSpacing;
    7073    int m_minThumbLength;
    71     bool m_troughUnderSteppers;
    72     bool m_hasForwardButtonStartPart;
    73     bool m_hasBackButtonEndPart;
     74    gboolean m_troughUnderSteppers;
     75    gboolean m_hasForwardButtonStartPart;
     76    gboolean m_hasBackButtonEndPart;
    7477};
    7578
  • trunk/WebCore/platform/gtk/ScrollbarThemeGtk2.cpp

    r75070 r75259  
    3838
    3939namespace WebCore {
     40
     41static void gtkStyleSetCallback(GtkWidget* widget, GtkStyle* previous, ScrollbarThemeGtk* scrollbarTheme)
     42{
     43    scrollbarTheme->updateThemeProperties();
     44}
     45
     46ScrollbarThemeGtk::ScrollbarThemeGtk()
     47{
     48    updateThemeProperties();
     49    g_signal_connect(static_cast<RenderThemeGtk*>(RenderTheme::defaultTheme().get())->gtkScrollbar(),
     50         "style-set", G_CALLBACK(gtkStyleSetCallback), this);
     51}
    4052
    4153void ScrollbarThemeGtk::updateThemeProperties()
  • trunk/WebCore/platform/gtk/ScrollbarThemeGtk3.cpp

    r75070 r75259  
    3333#include "ScrollView.h"
    3434#include "Scrollbar.h"
    35 #include "WidgetRenderingContext.h"
    36 #include "gtkdrawing.h"
    3735#include <gtk/gtk.h>
    3836
    3937namespace WebCore {
    4038
     39static void gtkStyleChangedCallback(GtkWidget*, ScrollbarThemeGtk* scrollbarTheme)
     40{
     41    scrollbarTheme->updateThemeProperties();
     42}
     43
     44ScrollbarThemeGtk::ScrollbarThemeGtk()
     45    : m_context(static_cast<RenderThemeGtk*>(RenderTheme::defaultTheme().get())->gtkScrollbarStyle())
     46{
     47    updateThemeProperties();
     48    g_signal_connect(m_context, "changed", G_CALLBACK(gtkStyleChangedCallback), this);
     49}
     50
    4151void ScrollbarThemeGtk::updateThemeProperties()
    4252{
    43     MozGtkScrollbarMetrics metrics;
    44     moz_gtk_get_scrollbar_metrics(&metrics);
    45 
    46     m_thumbFatness = metrics.slider_width;
    47     m_troughBorderWidth = metrics.trough_border;
    48     m_stepperSize = metrics.stepper_size;
    49     m_stepperSpacing = metrics.stepper_spacing;
    50     m_minThumbLength = metrics.min_slider_size;
    51     m_troughUnderSteppers = metrics.trough_under_steppers;
    52     m_hasForwardButtonStartPart = metrics.has_secondary_forward_stepper;
    53     m_hasBackButtonEndPart = metrics.has_secondary_backward_stepper;
    54 
     53    gtk_style_context_get_style(m_context,
     54                                "min-slider-length", &m_minThumbLength,
     55                                "slider-width", &m_thumbFatness,
     56                                "trough-border", &m_troughBorderWidth,
     57                                "stepper-size", &m_stepperSize,
     58                                "stepper-spacing", &m_stepperSpacing,
     59                                "trough-under-steppers", &m_troughUnderSteppers,
     60                                "has-secondary-backward-stepper", &m_hasBackButtonEndPart,
     61                                "has-secondary-forward-stepper", &m_hasForwardButtonStartPart,
     62                                NULL);
    5563    updateScrollbarsFrameThickness();
    5664}
     
    5866void ScrollbarThemeGtk::paintTrackBackground(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect)
    5967{
    60     GtkWidgetState state;
    61     state.focused = FALSE;
    62     state.isDefault = FALSE;
    63     state.canDefault = FALSE;
    64     state.disabled = FALSE;
    65     state.active = FALSE;
    66     state.inHover = FALSE;
    67 
    6868    // Paint the track background. If the trough-under-steppers property is true, this
    6969    // should be the full size of the scrollbar, but if is false, it should only be the
    7070    // track rect.
    71     IntRect fullScrollbarRect = rect;
     71    IntRect fullScrollbarRect(rect);
    7272    if (m_troughUnderSteppers)
    7373        fullScrollbarRect = IntRect(scrollbar->x(), scrollbar->y(), scrollbar->width(), scrollbar->height());
    7474
    75     GtkThemeWidgetType type = scrollbar->orientation() == VerticalScrollbar ? MOZ_GTK_SCROLLBAR_TRACK_VERTICAL : MOZ_GTK_SCROLLBAR_TRACK_HORIZONTAL;
    76     WidgetRenderingContext widgetContext(context, fullScrollbarRect);
    77     widgetContext.paintMozillaWidget(type, &state, 0);
     75    gtk_style_context_save(m_context);
     76
     77    gtk_style_context_add_class(m_context, GTK_STYLE_CLASS_SCROLLBAR);
     78    gtk_style_context_add_class(m_context, GTK_STYLE_CLASS_TROUGH);
     79
     80    gtk_render_background(m_context, context->platformContext(),
     81                          fullScrollbarRect.x(), fullScrollbarRect.y(), fullScrollbarRect.width(), fullScrollbarRect.height());
     82    gtk_render_frame(m_context, context->platformContext(),
     83                     fullScrollbarRect.x(), fullScrollbarRect.y(), fullScrollbarRect.width(), fullScrollbarRect.height());
     84
     85    gtk_style_context_restore(m_context);
    7886}
    7987
    8088void ScrollbarThemeGtk::paintScrollbarBackground(GraphicsContext* context, Scrollbar* scrollbar)
    8189{
    82     // This is unused by the moz_gtk_scrollecd_window_paint.
    83     GtkWidgetState state;
    84     IntRect fullScrollbarRect = IntRect(scrollbar->x(), scrollbar->y(), scrollbar->width(), scrollbar->height());
    85     WidgetRenderingContext widgetContext(context, fullScrollbarRect);
    86     widgetContext.paintMozillaWidget(MOZ_GTK_SCROLLED_WINDOW, &state, 0);
     90    gtk_style_context_save(m_context);
     91
     92    gtk_style_context_add_class(m_context, GTK_STYLE_CLASS_SCROLLBAR);
     93    gtk_style_context_add_class(m_context, "scrolled-window");
     94    gtk_render_frame(m_context, context->platformContext(), scrollbar->x(), scrollbar->y(), scrollbar->width(), scrollbar->height());
     95
     96    gtk_style_context_restore(m_context);
    8797}
    8898
    8999void ScrollbarThemeGtk::paintThumb(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect)
    90100{
    91     GtkWidgetState state;
    92     state.focused = FALSE;
    93     state.isDefault = FALSE;
    94     state.canDefault = FALSE;
    95     state.disabled = FALSE;
    96     state.active = scrollbar->pressedPart() == ThumbPart;
    97     state.inHover = scrollbar->hoveredPart() == ThumbPart;
    98     state.maxpos = scrollbar->maximum();
    99     state.curpos = scrollbar->currentPos();
     101    gtk_style_context_save(m_context);
    100102
    101     GtkThemeWidgetType type = scrollbar->orientation() == VerticalScrollbar ? MOZ_GTK_SCROLLBAR_THUMB_VERTICAL : MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL;
    102     WidgetRenderingContext widgetContext(context, rect);
    103     widgetContext.paintMozillaWidget(type, &state, 0);
     103    gtk_style_context_add_class(m_context, GTK_STYLE_CLASS_SCROLLBAR);
     104    gtk_style_context_add_class(m_context, GTK_STYLE_CLASS_SLIDER);
     105
     106    guint flags = 0;
     107    if (scrollbar->pressedPart() == ThumbPart)
     108        flags |= GTK_STATE_FLAG_ACTIVE;
     109    if (scrollbar->hoveredPart() == ThumbPart)
     110        flags |= GTK_STATE_FLAG_PRELIGHT;
     111    gtk_style_context_set_state(m_context, static_cast<GtkStateFlags>(flags));
     112
     113    gtk_render_slider(m_context, context->platformContext(), rect.x(), rect.y(), rect.width(), rect.height(),
     114                      scrollbar->orientation() == VerticalScrollbar ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL);
     115
     116    gtk_style_context_restore(m_context);
    104117}
    105118
    106119void ScrollbarThemeGtk::paintButton(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart part)
    107120{
    108     int flags = 0;
    109     if (scrollbar->orientation() == VerticalScrollbar)
    110         flags |= MOZ_GTK_STEPPER_VERTICAL;
     121    gtk_style_context_save(m_context);
    111122
    112     if (part == ForwardButtonEndPart)
    113         flags |= (MOZ_GTK_STEPPER_DOWN | MOZ_GTK_STEPPER_BOTTOM);
    114     if (part == ForwardButtonStartPart)
    115         flags |= MOZ_GTK_STEPPER_DOWN;
     123    gtk_style_context_add_class(m_context, GTK_STYLE_CLASS_SCROLLBAR);
    116124
    117     GtkWidgetState state;
    118     state.focused = TRUE;
    119     state.isDefault = TRUE;
    120     state.canDefault = TRUE;
    121     state.depressed = FALSE;
    122 
     125    guint flags = 0;
    123126    if ((BackButtonStartPart == part && scrollbar->currentPos())
    124127        || (BackButtonEndPart == part && scrollbar->currentPos())
    125128        || (ForwardButtonEndPart == part && scrollbar->currentPos() != scrollbar->maximum())
    126129        || (ForwardButtonStartPart == part && scrollbar->currentPos() != scrollbar->maximum())) {
    127         state.disabled = FALSE;
    128         state.active = part == scrollbar->pressedPart();
    129         state.inHover = part == scrollbar->hoveredPart();
    130     } else {
    131         state.disabled = TRUE;
    132         state.active = FALSE;
    133         state.inHover = FALSE;
     130        if (part == scrollbar->pressedPart())
     131            flags |= GTK_STATE_FLAG_ACTIVE;
     132        if (part == scrollbar->hoveredPart())
     133            flags |= GTK_STATE_FLAG_PRELIGHT;
     134    } else
     135        flags |= GTK_STATE_FLAG_INSENSITIVE;
     136    gtk_style_context_set_state(m_context, static_cast<GtkStateFlags>(flags));
     137
     138    guint sides = gtk_style_context_get_junction_sides(m_context);
     139    if (scrollbar->orientation() == VerticalScrollbar)
     140        sides &= ~(GTK_JUNCTION_TOP | GTK_JUNCTION_BOTTOM);
     141    else
     142        sides &= ~(GTK_JUNCTION_LEFT | GTK_JUNCTION_RIGHT);
     143
     144    switch (part) {
     145    case BackButtonStartPart:
     146        sides |= (scrollbar->orientation() == VerticalScrollbar) ? GTK_JUNCTION_BOTTOM : GTK_JUNCTION_RIGHT;
     147        break;
     148    case BackButtonEndPart:
     149    case ForwardButtonEndPart:
     150        sides |= (scrollbar->orientation() == VerticalScrollbar) ?
     151                GTK_JUNCTION_TOP | GTK_JUNCTION_BOTTOM : GTK_JUNCTION_RIGHT | GTK_JUNCTION_LEFT;
     152        break;
     153    case ForwardButtonStartPart:
     154        sides |= (scrollbar->orientation() == VerticalScrollbar) ? GTK_JUNCTION_TOP : GTK_JUNCTION_LEFT;
     155        break;
     156    default:
     157        ASSERT_NOT_REACHED();
     158    }
     159    gtk_style_context_set_junction_sides(m_context, static_cast<GtkJunctionSides>(sides));
     160    gtk_style_context_add_class(m_context, GTK_STYLE_CLASS_BUTTON);
     161
     162    gtk_render_background(m_context, context->platformContext(), rect.x(), rect.y(), rect.width(), rect.height());
     163    gtk_render_frame(m_context, context->platformContext(), rect.x(), rect.y(), rect.width(), rect.height());
     164
     165    gfloat arrowScaling;
     166    gtk_style_context_get_style(m_context, "arrow-scaling", &arrowScaling, NULL);
     167
     168    IntSize arrowSize = rect.size();
     169    arrowSize.scale(arrowScaling);
     170    IntPoint arrowPoint(rect.x() + (rect.width() - arrowSize.width()) / 2,
     171                        rect.y() + (rect.height() - arrowSize.height()) / 2);
     172
     173    if (flags & GTK_STATE_FLAG_ACTIVE) {
     174        gint arrowDisplacementX, arrowDisplacementY;
     175        gtk_style_context_get_style(m_context,
     176                                    "arrow-displacement-x", &arrowDisplacementX,
     177                                    "arrow-displacement-y", &arrowDisplacementY,
     178                                    NULL);
     179        arrowPoint.move(arrowDisplacementX, arrowDisplacementY);
    134180    }
    135181
    136     WidgetRenderingContext widgetContext(context, rect);
    137     widgetContext.paintMozillaWidget(MOZ_GTK_SCROLLBAR_BUTTON, &state, flags);
     182    gdouble angle, size;
     183    if (scrollbar->orientation() == VerticalScrollbar) {
     184        size = arrowSize.width();
     185        angle = (part == ForwardButtonEndPart || part == ForwardButtonStartPart) ? G_PI : 0;
     186    } else {
     187        size = arrowSize.height();
     188        angle = (part == ForwardButtonEndPart || part == ForwardButtonStartPart) ? G_PI / 2 : 3 * (G_PI / 2);
     189    }
     190
     191    gtk_render_arrow(m_context, context->platformContext(), angle, arrowPoint.x(), arrowPoint.y(), size);
     192
     193    gtk_style_context_restore(m_context);
    138194}
    139195
Note: See TracChangeset for help on using the changeset viewer.