Changeset 77960 in webkit


Ignore:
Timestamp:
Feb 8, 2011 11:15:32 AM (13 years ago)
Author:
Martin Robinson
Message:

2011-02-08 Martin Robinson <mrobinson@igalia.com>

Reviewed by Gustavo Noronha Silva.

[GTK] Move scrollbar rendering out of gtk2drawing.c
https://bugs.webkit.org/show_bug.cgi?id=52836

Replace gtk2drawing.c scrollbar rendering with our own version. This
is the last use of the Mozilla theme drawing code.

No new tests. This should not change the rendering of the default
theme.

  • platform/gtk/GtkVersioning.h: Add some more backported allocation setters.
  • platform/gtk/RenderThemeGtk.h: Add a getter for the scrollbar widgets.
  • platform/gtk/RenderThemeGtk2.cpp: Initialize and add getters for scrollbar widgets. (WebCore::RenderThemeGtk::platformInit): Ditto. (WebCore::RenderThemeGtk::gtkHScrollbar): Ditto. (WebCore::RenderThemeGtk::gtkVScrollbar): Ditto.
  • platform/gtk/ScrollbarThemeGtk.cpp: (WebCore::ScrollbarThemeGtk::paint): We only repaint the scrolled window background if we are repainting a button or the thumb. In that case also repaint the track rect.
  • platform/gtk/ScrollbarThemeGtk2.cpp: Port to WidgetRenderingContext. (WebCore::ScrollbarThemeGtk::ScrollbarThemeGtk): Ditto. (WebCore::ScrollbarThemeGtk::updateThemeProperties): Ditto. (WebCore::getWidgetForScrollbar): Ditto. (WebCore::ScrollbarThemeGtk::paintTrackBackground): Ditto. (WebCore::ScrollbarThemeGtk::paintScrollbarBackground): Ditto. (WebCore::ScrollbarThemeGtk::paintThumb): Ditto. (WebCore::ScrollbarThemeGtk::paintButton): Ditto.
  • platform/gtk/WidgetRenderingContext.cpp: Ditto. (WebCore::WidgetRenderingContext::gtkPaintBox): Added an option which also adjusts a widget allocation according to the paint rect. This is necessary to properly draw scrollbar buttons.
  • platform/gtk/WidgetRenderingContext.h: Ditto.
Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r77958 r77960  
     12011-02-08  Martin Robinson  <mrobinson@igalia.com>
     2
     3        Reviewed by Gustavo Noronha Silva.
     4
     5        [GTK] Move scrollbar rendering out of gtk2drawing.c
     6        https://bugs.webkit.org/show_bug.cgi?id=52836
     7
     8        Replace gtk2drawing.c scrollbar rendering with our own version. This
     9        is the last use of the Mozilla theme drawing code.
     10
     11        No new tests. This should not change the rendering of the default
     12        theme.
     13
     14        * platform/gtk/GtkVersioning.h: Add some more backported allocation setters.
     15        * platform/gtk/RenderThemeGtk.h: Add a getter for the scrollbar widgets.
     16        * platform/gtk/RenderThemeGtk2.cpp:  Initialize and add getters for scrollbar widgets.
     17        (WebCore::RenderThemeGtk::platformInit): Ditto.
     18        (WebCore::RenderThemeGtk::gtkHScrollbar): Ditto.
     19        (WebCore::RenderThemeGtk::gtkVScrollbar): Ditto.
     20        * platform/gtk/ScrollbarThemeGtk.cpp:
     21        (WebCore::ScrollbarThemeGtk::paint): We only repaint the scrolled
     22        window background if we are repainting a button or the thumb. In that
     23        case also repaint the track rect.
     24        * platform/gtk/ScrollbarThemeGtk2.cpp: Port to WidgetRenderingContext.
     25        (WebCore::ScrollbarThemeGtk::ScrollbarThemeGtk): Ditto.
     26        (WebCore::ScrollbarThemeGtk::updateThemeProperties): Ditto.
     27        (WebCore::getWidgetForScrollbar): Ditto.
     28        (WebCore::ScrollbarThemeGtk::paintTrackBackground): Ditto.
     29        (WebCore::ScrollbarThemeGtk::paintScrollbarBackground): Ditto.
     30        (WebCore::ScrollbarThemeGtk::paintThumb): Ditto.
     31        (WebCore::ScrollbarThemeGtk::paintButton): Ditto.
     32        * platform/gtk/WidgetRenderingContext.cpp: Ditto.
     33        (WebCore::WidgetRenderingContext::gtkPaintBox): Added an option which
     34        also adjusts a widget allocation according to the paint rect. This is
     35        necessary to properly draw scrollbar buttons.
     36        * platform/gtk/WidgetRenderingContext.h: Ditto.
     37
    1382011-02-08  Simon Fraser  <simon.fraser@apple.com>
    239
  • trunk/Source/WebCore/platform/gtk/GtkVersioning.h

    r75397 r77960  
    9595#define gtk_selection_data_get_data(data) (data)->data
    9696#define gtk_selection_data_get_target(data) (data)->target
    97 #define gtk_adjustment_set_page_size(adj, value) (adj)->page_size = value
     97#define gtk_adjustment_set_page_size(adj, newValue) ((adj)->page_size = newValue)
     98#define gtk_adjustment_set_value(adj, newValue) ((adj)->value = newValue)
     99#define gtk_adjustment_set_lower(adj, newValue) ((adj)->lower = newValue)
     100#define gtk_adjustment_set_upper(adj, newValue) ((adj)->upper = newValue)
    98101
    99102void gtk_adjustment_configure(GtkAdjustment* adjustment, gdouble value, gdouble lower, gdouble upper,
  • trunk/Source/WebCore/platform/gtk/RenderThemeGtk.h

    r76577 r77960  
    9393
    9494#ifdef GTK_API_VERSION_2
    95     GtkWidget* gtkScrollbar();
     95    GtkWidget* gtkVScrollbar() const;
     96    GtkWidget* gtkHScrollbar() const;
    9697    static void getIndicatorMetrics(ControlPart, int& indicatorSize, int& indicatorSpacing);
    9798#else
     
    234235    mutable GtkWidget* m_gtkComboBoxArrow;
    235236    mutable GtkWidget* m_gtkComboBoxSeparator;
     237    mutable GtkWidget* m_gtkVScrollbar;
     238    mutable GtkWidget* m_gtkHScrollbar;
    236239    bool m_themePartsHaveRGBAColormap;
    237240    friend class WidgetRenderingContext;
  • trunk/Source/WebCore/platform/gtk/RenderThemeGtk2.cpp

    r76577 r77960  
    6969    m_gtkComboBoxArrow = 0;
    7070    m_gtkComboBoxSeparator = 0;
     71    m_gtkVScrollbar = 0;
     72    m_gtkHScrollbar = 0;
    7173
    7274    memset(&m_themeParts, 0, sizeof(GtkThemeParts));
     
    892894}
    893895
    894 GtkWidget* RenderThemeGtk::gtkScrollbar()
    895 {
    896     return moz_gtk_get_scrollbar_widget();
     896GtkWidget* RenderThemeGtk::gtkHScrollbar() const
     897{
     898    if (m_gtkHScrollbar)
     899        return m_gtkHScrollbar;
     900    m_gtkHScrollbar = gtk_hscrollbar_new(0);
     901    setupWidgetAndAddToContainer(m_gtkHScrollbar, gtkContainer());
     902    return m_gtkHScrollbar;
     903}
     904
     905GtkWidget* RenderThemeGtk::gtkVScrollbar() const
     906{
     907    if (m_gtkVScrollbar)
     908        return m_gtkVScrollbar;
     909    m_gtkVScrollbar = gtk_vscrollbar_new(0);
     910    setupWidgetAndAddToContainer(m_gtkVScrollbar, gtkContainer());
     911    return m_gtkVScrollbar;
    897912}
    898913
  • trunk/Source/WebCore/platform/gtk/ScrollbarThemeGtk.cpp

    r75259 r77960  
    229229    }
    230230
    231     paintScrollbarBackground(graphicsContext, scrollbar);
    232 
    233     if (scrollMask & TrackBGPart)
     231    ScrollbarControlPartMask allButtons = BackButtonStartPart | BackButtonEndPart
     232                                         | ForwardButtonStartPart | ForwardButtonEndPart;
     233    if (scrollMask & TrackBGPart || scrollMask & ThumbPart || scrollMask & allButtons)
     234        paintScrollbarBackground(graphicsContext, scrollbar);
    234235        paintTrackBackground(graphicsContext, scrollbar, trackPaintRect);
    235236
  • trunk/Source/WebCore/platform/gtk/ScrollbarThemeGtk2.cpp

    r75259 r77960  
    4747{
    4848    updateThemeProperties();
    49     g_signal_connect(static_cast<RenderThemeGtk*>(RenderTheme::defaultTheme().get())->gtkScrollbar(),
     49    g_signal_connect(static_cast<RenderThemeGtk*>(RenderTheme::defaultTheme().get())->gtkHScrollbar(),
    5050         "style-set", G_CALLBACK(gtkStyleSetCallback), this);
    5151}
     
    5353void ScrollbarThemeGtk::updateThemeProperties()
    5454{
    55     MozGtkScrollbarMetrics metrics;
    56     moz_gtk_get_scrollbar_metrics(&metrics);
    57 
    58     m_thumbFatness = metrics.slider_width;
    59     m_troughBorderWidth = metrics.trough_border;
    60     m_stepperSize = metrics.stepper_size;
    61     m_stepperSpacing = metrics.stepper_spacing;
    62     m_minThumbLength = metrics.min_slider_size;
    63     m_troughUnderSteppers = metrics.trough_under_steppers;
    64     m_hasForwardButtonStartPart = metrics.has_secondary_forward_stepper;
    65     m_hasBackButtonEndPart = metrics.has_secondary_backward_stepper;
    66 
     55    GtkWidget* scrollbar = static_cast<RenderThemeGtk*>(RenderTheme::defaultTheme().get())->gtkHScrollbar();
     56    gtk_widget_style_get(scrollbar,
     57                         "slider_width", &m_thumbFatness,
     58                         "trough_border", &m_troughBorderWidth,
     59                         "stepper-size", &m_stepperSize,
     60                         "trough-under-steppers", &m_troughUnderSteppers,
     61                         "has-secondary-forward-stepper", &m_hasForwardButtonStartPart,
     62                         "has-secondary-backward-stepper", &m_hasBackButtonEndPart, NULL);
     63    m_minThumbLength = gtk_range_get_min_slider_size(GTK_RANGE(scrollbar));
    6764    updateScrollbarsFrameThickness();
    6865}
    6966
     67static GtkWidget* getWidgetForScrollbar(Scrollbar* scrollbar)
     68{
     69    RenderThemeGtk* theme = static_cast<RenderThemeGtk*>(RenderTheme::defaultTheme().get());
     70    return scrollbar->orientation() == VerticalScrollbar ? theme->gtkVScrollbar() : theme->gtkHScrollbar();
     71}
     72
    7073void ScrollbarThemeGtk::paintTrackBackground(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect)
    7174{
    72     GtkWidgetState state;
    73     state.focused = FALSE;
    74     state.isDefault = FALSE;
    75     state.canDefault = FALSE;
    76     state.disabled = FALSE;
    77     state.active = FALSE;
    78     state.inHover = FALSE;
    79 
    8075    // Paint the track background. If the trough-under-steppers property is true, this
    8176    // should be the full size of the scrollbar, but if is false, it should only be the
    8277    // track rect.
    83     IntRect fullScrollbarRect = rect;
     78    IntRect fullScrollbarRect(rect);
    8479    if (m_troughUnderSteppers)
    8580        fullScrollbarRect = IntRect(scrollbar->x(), scrollbar->y(), scrollbar->width(), scrollbar->height());
    8681
    87     GtkThemeWidgetType type = scrollbar->orientation() == VerticalScrollbar ? MOZ_GTK_SCROLLBAR_TRACK_VERTICAL : MOZ_GTK_SCROLLBAR_TRACK_HORIZONTAL;
    8882    WidgetRenderingContext widgetContext(context, fullScrollbarRect);
    89     widgetContext.paintMozillaWidget(type, &state, 0);
     83    IntRect paintRect(IntPoint(), fullScrollbarRect.size());
     84    widgetContext.gtkPaintBox(paintRect, getWidgetForScrollbar(scrollbar),
     85                              GTK_STATE_ACTIVE, GTK_SHADOW_IN, "trough");
    9086}
    9187
    9288void ScrollbarThemeGtk::paintScrollbarBackground(GraphicsContext* context, Scrollbar* scrollbar)
    9389{
    94     // This is unused by the moz_gtk_scrollecd_window_paint.
    95     GtkWidgetState state;
    9690    IntRect fullScrollbarRect = IntRect(scrollbar->x(), scrollbar->y(), scrollbar->width(), scrollbar->height());
     91
    9792    WidgetRenderingContext widgetContext(context, fullScrollbarRect);
    98     widgetContext.paintMozillaWidget(MOZ_GTK_SCROLLED_WINDOW, &state, 0);
     93    widgetContext.gtkPaintBox(fullScrollbarRect, getWidgetForScrollbar(scrollbar),
     94                              GTK_STATE_NORMAL, GTK_SHADOW_IN, "scrolled_window");
    9995}
    10096
    10197void ScrollbarThemeGtk::paintThumb(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect)
    10298{
    103     GtkWidgetState state;
    104     state.focused = FALSE;
    105     state.isDefault = FALSE;
    106     state.canDefault = FALSE;
    107     state.disabled = FALSE;
    108     state.active = scrollbar->pressedPart() == ThumbPart;
    109     state.inHover = scrollbar->hoveredPart() == ThumbPart;
    110     state.maxpos = scrollbar->maximum();
    111     state.curpos = scrollbar->currentPos();
    112 
    113     GtkThemeWidgetType type = scrollbar->orientation() == VerticalScrollbar ? MOZ_GTK_SCROLLBAR_THUMB_VERTICAL : MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL;
     99    GtkWidget* widget = getWidgetForScrollbar(scrollbar);
     100    gboolean activateSlider;
     101    gtk_widget_style_get(widget, "activate-slider", &activateSlider, NULL);
     102
     103    GtkStateType stateType = GTK_STATE_NORMAL;
     104    GtkShadowType shadowType = GTK_SHADOW_OUT;
     105    if (activateSlider && scrollbar->pressedPart() == ThumbPart) {
     106        stateType = GTK_STATE_ACTIVE;
     107        shadowType = GTK_SHADOW_IN;
     108    } else if (scrollbar->pressedPart() == ThumbPart || scrollbar->hoveredPart() == ThumbPart)
     109        stateType = GTK_STATE_PRELIGHT;
     110
     111    // The adjustment controls the rendering of the scrollbar thumb. If it's not set
     112    // properly the theme may not draw the thumb borders properly.
     113    GtkAdjustment* adjustment = gtk_range_get_adjustment(GTK_RANGE(widget));
     114    gtk_adjustment_set_value(adjustment, scrollbar->currentPos());
     115    gtk_adjustment_set_lower(adjustment, 0);
     116    gtk_adjustment_set_upper(adjustment, scrollbar->maximum());
     117
     118    GtkOrientation orientation = GTK_ORIENTATION_HORIZONTAL;
     119    if (scrollbar->orientation() == VerticalScrollbar) {
     120        gtk_adjustment_set_page_size(adjustment, rect.height());
     121        orientation = GTK_ORIENTATION_VERTICAL;
     122    } else
     123        gtk_adjustment_set_page_size(adjustment, rect.width());
     124
    114125    WidgetRenderingContext widgetContext(context, rect);
    115     widgetContext.paintMozillaWidget(type, &state, 0);
     126    IntRect sliderRect(IntPoint(), rect.size());
     127    widgetContext.gtkPaintSlider(sliderRect, widget, stateType, shadowType, "slider", orientation);
    116128}
    117129
    118130void ScrollbarThemeGtk::paintButton(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart part)
    119131{
    120     int flags = 0;
    121     if (scrollbar->orientation() == VerticalScrollbar)
    122         flags |= MOZ_GTK_STEPPER_VERTICAL;
    123 
    124     if (part == ForwardButtonEndPart)
    125         flags |= (MOZ_GTK_STEPPER_DOWN | MOZ_GTK_STEPPER_BOTTOM);
    126     if (part == ForwardButtonStartPart)
    127         flags |= MOZ_GTK_STEPPER_DOWN;
    128 
    129     GtkWidgetState state;
    130     state.focused = TRUE;
    131     state.isDefault = TRUE;
    132     state.canDefault = TRUE;
    133     state.depressed = FALSE;
     132    // The buttons will be disabled if the thumb is as the appropriate extreme.
     133    GtkShadowType shadowType = GTK_SHADOW_OUT;
     134    GtkStateType stateType = GTK_STATE_INSENSITIVE;
     135    bool pressed = (part == scrollbar->pressedPart());
    134136
    135137    if ((BackButtonStartPart == part && scrollbar->currentPos())
     
    137139        || (ForwardButtonEndPart == part && scrollbar->currentPos() != scrollbar->maximum())
    138140        || (ForwardButtonStartPart == part && scrollbar->currentPos() != scrollbar->maximum())) {
    139         state.disabled = FALSE;
    140         state.active = part == scrollbar->pressedPart();
    141         state.inHover = part == scrollbar->hoveredPart();
     141        stateType = GTK_STATE_NORMAL;
     142        if (pressed) {
     143            stateType = GTK_STATE_ACTIVE;
     144            shadowType = GTK_SHADOW_IN;
     145        } else if (part == scrollbar->hoveredPart())
     146            stateType = GTK_STATE_PRELIGHT;
     147    }
     148
     149    // Themes determine how to draw the button (which button to draw) based on the allocation
     150    // of the widget. Where the target rect is in relation to the total widget allocation
     151    // determines the button.
     152    ScrollbarOrientation orientation = scrollbar->orientation();
     153    int buttonSize = (orientation == VerticalScrollbar) ? rect.height() : rect.width();
     154    int totalAllocation = buttonSize * 5; // One space for each button and one extra.
     155    int buttonOffset = 0;
     156    if (ForwardButtonStartPart == part)
     157        buttonOffset = buttonSize;
     158    else if (BackButtonEndPart == part)
     159        buttonOffset = 3 * buttonSize;
     160    else if (ForwardButtonEndPart == part)
     161        buttonOffset = 4 * buttonSize;
     162
     163    // Now we want the allocation to be relative to the origin of the painted rect.
     164    GtkWidget* widget = getWidgetForScrollbar(scrollbar);
     165    GtkAllocation allocation;
     166    gtk_widget_get_allocation(widget, &allocation);
     167    allocation.x = allocation.y = 0;
     168    allocation.width = rect.width();
     169    allocation.height = rect.height();
     170
     171    if (orientation == VerticalScrollbar) {
     172        allocation.height = totalAllocation;
     173        allocation.y -= buttonOffset;
    142174    } else {
    143         state.disabled = TRUE;
    144         state.active = FALSE;
    145         state.inHover = FALSE;
    146     }
    147 
     175        allocation.width = totalAllocation;
     176        allocation.x -= buttonOffset;
     177    }
     178    gtk_widget_set_allocation(widget, &allocation);
     179
     180    const char* detail = orientation == VerticalScrollbar ? "vscrollbar" : "hscrollbar";
    148181    WidgetRenderingContext widgetContext(context, rect);
    149     widgetContext.paintMozillaWidget(MOZ_GTK_SCROLLBAR_BUTTON, &state, flags);
     182
     183    IntRect buttonRect(IntPoint(), rect.size());
     184    widgetContext.gtkPaintBox(buttonRect, widget, stateType, shadowType, detail);
     185
     186    float arrowScaling;
     187    gtk_widget_style_get(widget, "arrow-scaling", &arrowScaling, NULL);
     188    IntSize arrowSize = rect.size();
     189    arrowSize.scale(arrowScaling);
     190    IntRect arrowRect(IntPoint(buttonRect.x() + (buttonRect.width() - arrowSize.width()) / 2,
     191                               buttonRect.y() + (buttonRect.height() - arrowSize.height()) / 2),
     192                      arrowSize);
     193    if (pressed) {
     194        int arrowDisplacementX, arrowDisplacementY;
     195        gtk_widget_style_get(widget,
     196                             "arrow-displacement-x", &arrowDisplacementX,
     197                             "arrow-displacement-y", &arrowDisplacementY,
     198                             NULL);
     199        arrowRect.move(arrowDisplacementX, arrowDisplacementY);
     200    }
     201
     202    GtkArrowType arrowType = GTK_ARROW_DOWN;
     203    if (orientation == VerticalScrollbar) {
     204        if (part == BackButtonEndPart || part == BackButtonStartPart)
     205            arrowType = GTK_ARROW_UP;
     206    } else if (orientation == HorizontalScrollbar) {
     207        arrowType = GTK_ARROW_RIGHT;
     208        if (part == BackButtonEndPart || part == BackButtonStartPart)
     209            arrowType = GTK_ARROW_LEFT;
     210    }
     211    widgetContext.gtkPaintArrow(arrowRect, widget, stateType, shadowType, arrowType, detail);
    150212}
    151213
  • trunk/Source/WebCore/platform/gtk/WidgetRenderingContext.cpp

    r76388 r77960  
    156156{
    157157    GdkRectangle paintRect = { m_paintRect.x + rect.x(), m_paintRect.y + rect.y(), rect.width(), rect.height() };
    158     gtk_paint_box(gtk_widget_get_style(widget), m_target, stateType, shadowType, &m_paintRect,
     158
     159    // Some widgets also need their allocation adjusted to account for extra space.
     160    // Right now only scrollbar buttons have significant allocations.
     161    GtkAllocation allocation;
     162    gtk_widget_get_allocation(widget, &allocation);
     163    allocation.x += m_paintRect.x;
     164    allocation.y += m_paintRect.y;
     165    gtk_widget_set_allocation(widget, &allocation);
     166
     167    gtk_paint_box(gtk_widget_get_style(widget), m_target, stateType, shadowType, &paintRect,
    159168                  widget, detail, paintRect.x, paintRect.y, paintRect.width, paintRect.height);
    160169}
Note: See TracChangeset for help on using the changeset viewer.