[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

mrobinson at webkit.org mrobinson at webkit.org
Wed Dec 22 12:40:10 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 60e3aa2fe6447f8646067bd036c6dc5fa404f6a4
Author: mrobinson at webkit.org <mrobinson at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Aug 26 23:06:06 2010 +0000

    2010-08-23  Martin Robinson  <mrobinson at igalia.com>
    
            Reviewed by Gustavo Noronha Silva.
    
            [GTK] ScrollbarThemeGtk is incomplete
            https://bugs.webkit.org/show_bug.cgi?id=44471
    
            Add theme drawing code for GTK+ scrollbars. Turn RenderThemeGtk::paintMozillaWidget
            into a public method so that ScrollbarThemeGtk can access Mozilla theme API properly.
    
            Tests for this issue will be activated in the form of pixel tests, but
            only after fully-fake scrollbars are activated.
    
            * platform/gtk/RenderThemeGtk.cpp:
            (WebCore::RenderThemeGtk::paintMozillaGtkWidget): Added this public method which takes
            the proper widget state, widget type, graphics context and rectangle and renders a
            widget using the Mozilla theming API.
            (WebCore::RenderThemeGtk::paintRenderObject): Added this method which first calculates
            the widget state before passing the information on to paintMozillaGtkWidget.
            (WebCore::RenderThemeGtk::paintCheckbox): Switch to use paintRenderObject.
            (WebCore::RenderThemeGtk::paintRadio): Switch to use paintRenderObject.
            (WebCore::RenderThemeGtk::paintButton): Switch to use paintRenderObject.
            (WebCore::RenderThemeGtk::paintMenuList): Switch to use paintRenderObject.
            (WebCore::RenderThemeGtk::paintTextField): Switch to use paintRenderObject.
            (WebCore::RenderThemeGtk::paintSliderTrack): Switch to use paintRenderObject.
            (WebCore::RenderThemeGtk::paintSliderThumb): Switch to use paintRenderObject.
            (WebCore::RenderThemeGtk::paintProgressBar): Switch to use paintRenderObject.
            * platform/gtk/RenderThemeGtk.h: Added new method declarations.
            * platform/gtk/ScrollbarThemeGtk.cpp: Added code which can render GTK+ scrollbars.
            (WebCore::ScrollbarThemeGtk::hasThumb): Added.
            (WebCore::ScrollbarThemeGtk::backButtonRect): Added.
            (WebCore::ScrollbarThemeGtk::forwardButtonRect): Added.
            (WebCore::ScrollbarThemeGtk::trackRect): Added.
            (WebCore::ScrollbarThemeGtk::paintTrackBackground): Added.
            (WebCore::ScrollbarThemeGtk::paintScrollbarBackground): Added.
            (WebCore::ScrollbarThemeGtk::paintThumb): Added.
            (WebCore::ScrollbarThemeGtk::thumbRect): Added.
            (WebCore::ScrollbarThemeGtk::paint): Added.
            (WebCore::ScrollbarThemeGtk::paintButton): Added.
            (WebCore::ScrollbarThemeGtk::paintScrollCorner): Added.
            (WebCore::ScrollbarThemeGtk::shouldCenterOnThumb): Added.
            (WebCore::ScrollbarThemeGtk::scrollbarThickness): Always get the metrics from the
            theme drawing API so that it stays up to date with theme changes.
            (WebCore::ScrollbarThemeGtk::buttonSize): Added.
            (WebCore::ScrollbarThemeGtk::minimumThumbLength): Added.
            * platform/gtk/ScrollbarThemeGtk.h:
            (WebCore::ScrollbarThemeGtk::hasButtons): Added.
            (WebCore::ScrollbarThemeGtk::initialAutoscrollTimerDelay): Added.
            (WebCore::ScrollbarThemeGtk::autoscrollTimerDelay): Added.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@66148 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index ef4c128..c9ab235 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,53 @@
+2010-08-23  Martin Robinson  <mrobinson at igalia.com>
+
+        Reviewed by Gustavo Noronha Silva.
+
+        [GTK] ScrollbarThemeGtk is incomplete
+        https://bugs.webkit.org/show_bug.cgi?id=44471
+
+        Add theme drawing code for GTK+ scrollbars. Turn RenderThemeGtk::paintMozillaWidget
+        into a public method so that ScrollbarThemeGtk can access Mozilla theme API properly.
+
+        Tests for this issue will be activated in the form of pixel tests, but
+        only after fully-fake scrollbars are activated.
+
+        * platform/gtk/RenderThemeGtk.cpp:
+        (WebCore::RenderThemeGtk::paintMozillaGtkWidget): Added this public method which takes
+        the proper widget state, widget type, graphics context and rectangle and renders a
+        widget using the Mozilla theming API.
+        (WebCore::RenderThemeGtk::paintRenderObject): Added this method which first calculates
+        the widget state before passing the information on to paintMozillaGtkWidget.
+        (WebCore::RenderThemeGtk::paintCheckbox): Switch to use paintRenderObject.
+        (WebCore::RenderThemeGtk::paintRadio): Switch to use paintRenderObject.
+        (WebCore::RenderThemeGtk::paintButton): Switch to use paintRenderObject.
+        (WebCore::RenderThemeGtk::paintMenuList): Switch to use paintRenderObject.
+        (WebCore::RenderThemeGtk::paintTextField): Switch to use paintRenderObject.
+        (WebCore::RenderThemeGtk::paintSliderTrack): Switch to use paintRenderObject.
+        (WebCore::RenderThemeGtk::paintSliderThumb): Switch to use paintRenderObject.
+        (WebCore::RenderThemeGtk::paintProgressBar): Switch to use paintRenderObject.
+        * platform/gtk/RenderThemeGtk.h: Added new method declarations.
+        * platform/gtk/ScrollbarThemeGtk.cpp: Added code which can render GTK+ scrollbars.
+        (WebCore::ScrollbarThemeGtk::hasThumb): Added.
+        (WebCore::ScrollbarThemeGtk::backButtonRect): Added.
+        (WebCore::ScrollbarThemeGtk::forwardButtonRect): Added.
+        (WebCore::ScrollbarThemeGtk::trackRect): Added.
+        (WebCore::ScrollbarThemeGtk::paintTrackBackground): Added.
+        (WebCore::ScrollbarThemeGtk::paintScrollbarBackground): Added.
+        (WebCore::ScrollbarThemeGtk::paintThumb): Added.
+        (WebCore::ScrollbarThemeGtk::thumbRect): Added.
+        (WebCore::ScrollbarThemeGtk::paint): Added.
+        (WebCore::ScrollbarThemeGtk::paintButton): Added.
+        (WebCore::ScrollbarThemeGtk::paintScrollCorner): Added.
+        (WebCore::ScrollbarThemeGtk::shouldCenterOnThumb): Added.
+        (WebCore::ScrollbarThemeGtk::scrollbarThickness): Always get the metrics from the
+        theme drawing API so that it stays up to date with theme changes.
+        (WebCore::ScrollbarThemeGtk::buttonSize): Added.
+        (WebCore::ScrollbarThemeGtk::minimumThumbLength): Added.
+        * platform/gtk/ScrollbarThemeGtk.h:
+        (WebCore::ScrollbarThemeGtk::hasButtons): Added.
+        (WebCore::ScrollbarThemeGtk::initialAutoscrollTimerDelay): Added.
+        (WebCore::ScrollbarThemeGtk::autoscrollTimerDelay): Added.
+
 2010-08-26  Alexey Proskuryakov  <ap at apple.com>
 
         Reviewed by Sam Weinig.
diff --git a/WebCore/platform/gtk/RenderThemeGtk.cpp b/WebCore/platform/gtk/RenderThemeGtk.cpp
index 5019f35..f11e082 100644
--- a/WebCore/platform/gtk/RenderThemeGtk.cpp
+++ b/WebCore/platform/gtk/RenderThemeGtk.cpp
@@ -34,8 +34,10 @@
 #include "HTMLNames.h"
 #include "MediaControlElements.h"
 #include "NotImplemented.h"
+#include "PlatformMouseEvent.h"
 #include "RenderBox.h"
 #include "RenderObject.h"
+#include "Scrollbar.h"
 #include "UserAgentStyleSheets.h"
 #include "gtkdrawing.h"
 #include <gdk/gdk.h>
@@ -281,30 +283,10 @@ static void adjustMozillaStyle(const RenderThemeGtk* theme, RenderStyle* style,
     style->setPaddingBottom(Length(ypadding + bottom, Fixed));
 }
 
-static void setMozillaState(const RenderTheme* theme, GtkThemeWidgetType type, RenderObject* o, GtkWidgetState* state)
-{
-    state->active = theme->isPressed(o);
-    state->focused = theme->isFocused(o);
-    state->inHover = theme->isHovered(o);
-    // FIXME: Disabled does not always give the correct appearance for ReadOnly
-    state->disabled = !theme->isEnabled(o) || theme->isReadOnlyControl(o);
-    state->isDefault = false;
-    state->canDefault = false;
-
-
-    // FIXME: The depressed value should probably apply for other theme parts too.
-    // It must be used for range thumbs, because otherwise when the thumb is pressed,
-    // the rendering is incorrect.
-    if (type == MOZ_GTK_SCALE_THUMB_HORIZONTAL || type == MOZ_GTK_SCALE_THUMB_VERTICAL)
-        state->depressed = theme->isPressed(o);
-    else
-        state->depressed = false;
-}
-
-static bool paintMozillaGtkWidget(const RenderThemeGtk* theme, GtkThemeWidgetType type, RenderObject* o, const PaintInfo& i, const IntRect& rect)
+bool RenderThemeGtk::paintMozillaGtkWidget(GtkThemeWidgetType type, GraphicsContext* context, const IntRect& rect, GtkWidgetState* widgetState, int flags, GtkTextDirection textDirection)
 {
     // Painting is disabled so just claim to have succeeded
-    if (i.context->paintingDisabled())
+    if (context->paintingDisabled())
         return false;
 
     GtkWidgetState widgetState;
@@ -320,16 +302,15 @@ static bool paintMozillaGtkWidget(const RenderThemeGtk* theme, GtkThemeWidgetTyp
     PlatformRefPtr<GdkDrawable> drawable(i.context->gdkDrawable());
     GdkRectangle paintRect, clipRect;
     if (drawable) {
-        AffineTransform ctm = i.context->getCTM();
+        AffineTransform ctm = context->getCTM();
         IntPoint pos = ctm.mapPoint(rect.location());
         paintRect = IntRect(pos.x(), pos.y(), rect.width(), rect.height());
 
         // Intersect the cairo rectangle with the target widget region. This  will
         // prevent the theme drawing code from drawing into regions that cairo will
         // clip anyway.
-        cairo_t* cr = i.context->platformContext();
         double clipX1, clipX2, clipY1, clipY2;
-        cairo_clip_extents(cr, &clipX1, &clipY1, &clipX2, &clipY2);
+        cairo_clip_extents(context->platformContext(), &clipX1, &clipY1, &clipX2, &clipY2);
         IntPoint clipPos = ctm.mapPoint(IntPoint(clipX1, clipY1));
 
         clipRect.width = clipX2 - clipX1;
@@ -346,13 +327,13 @@ static bool paintMozillaGtkWidget(const RenderThemeGtk* theme, GtkThemeWidgetTyp
         paintRect = clipRect = IntRect(0, 0, rect.width(), rect.height());
     }
 
-    moz_gtk_use_theme_parts(theme->partsForDrawable(drawable.get()));
-    bool success = moz_gtk_widget_paint(type, drawable.get(), &paintRect, &clipRect, &widgetState, flags, gtkTextDirection(o->style()->direction())) == MOZ_GTK_SUCCESS;
+    moz_gtk_use_theme_parts(partsForDrawable(drawable.get()));
+    bool success = moz_gtk_widget_paint(type, drawable.get(), &paintRect, &clipRect, widgetState, flags, textDirection) == MOZ_GTK_SUCCESS;
 
     // If the drawing was successful and we rendered onto a pixmap, copy the
     // results back to the original GraphicsContext.
-    if (success && !i.context->gdkDrawable()) {
-        cairo_t* cairoContext = i.context->platformContext();
+    if (success && !context->gdkDrawable()) {
+        cairo_t* cairoContext = context->platformContext();
         cairo_save(cairoContext);
         gdk_cairo_set_source_pixmap(cairoContext, drawable.get(), rect.x(), rect.y());
         cairo_paint(cairoContext);
@@ -362,6 +343,34 @@ static bool paintMozillaGtkWidget(const RenderThemeGtk* theme, GtkThemeWidgetTyp
     return !success;
 }
 
+bool RenderThemeGtk::paintRenderObject(GtkThemeWidgetType type, RenderObject* renderObject, GraphicsContext* context, const IntRect& rect, int flags)
+{
+    // Painting is disabled so just claim to have succeeded
+    if (context->paintingDisabled())
+        return false;
+
+    GtkWidgetState widgetState;
+    widgetState.active = isPressed(renderObject);
+    widgetState.focused = isFocused(renderObject);
+    widgetState.inHover = isHovered(renderObject);
+
+    // FIXME: Disabled does not always give the correct appearance for ReadOnly
+    widgetState.disabled = !isEnabled(renderObject) || isReadOnlyControl(renderObject);
+    widgetState.isDefault = false;
+    widgetState.canDefault = false;
+
+    // FIXME: The depressed value should probably apply for other theme parts too.
+    // It must be used for range thumbs, because otherwise when the thumb is pressed,
+    // the rendering is incorrect.
+    if (type == MOZ_GTK_SCALE_THUMB_HORIZONTAL || type == MOZ_GTK_SCALE_THUMB_VERTICAL)
+        widgetState.depressed = isPressed(renderObject);
+    else
+        widgetState.depressed = false;
+
+    GtkTextDirection textDirection = gtkTextDirection(renderObject->style()->direction());
+    return paintMozillaGtkWidget(type, context, rect, &widgetState, flags, textDirection);
+}
+
 static void setButtonPadding(RenderStyle* style)
 {
     // FIXME: This looks incorrect.
@@ -411,7 +420,7 @@ void RenderThemeGtk::setCheckboxSize(RenderStyle* style) const
 
 bool RenderThemeGtk::paintCheckbox(RenderObject* o, const PaintInfo& i, const IntRect& rect)
 {
-    return paintMozillaGtkWidget(this, MOZ_GTK_CHECKBUTTON, o, i, rect);
+    return paintRenderObject(MOZ_GTK_CHECKBUTTON, o, i.context, rect, isChecked(o));
 }
 
 void RenderThemeGtk::setRadioSize(RenderStyle* style) const
@@ -421,7 +430,7 @@ void RenderThemeGtk::setRadioSize(RenderStyle* style) const
 
 bool RenderThemeGtk::paintRadio(RenderObject* o, const PaintInfo& i, const IntRect& rect)
 {
-    return paintMozillaGtkWidget(this, MOZ_GTK_RADIOBUTTON, o, i, rect);
+    return paintRenderObject(MOZ_GTK_RADIOBUTTON, o, i.context, rect, isChecked(o));
 }
 
 void RenderThemeGtk::adjustButtonStyle(CSSStyleSelector* selector, RenderStyle* style, WebCore::Element* e) const
@@ -442,7 +451,7 @@ void RenderThemeGtk::adjustButtonStyle(CSSStyleSelector* selector, RenderStyle*
 
 bool RenderThemeGtk::paintButton(RenderObject* o, const PaintInfo& i, const IntRect& rect)
 {
-    return paintMozillaGtkWidget(this, MOZ_GTK_BUTTON, o, i, rect);
+    return paintRenderObject(MOZ_GTK_BUTTON, o, i.context, rect, GTK_RELIEF_NORMAL);
 }
 
 void RenderThemeGtk::adjustMenuListStyle(CSSStyleSelector* selector, RenderStyle* style, WebCore::Element* e) const
@@ -456,7 +465,7 @@ void RenderThemeGtk::adjustMenuListStyle(CSSStyleSelector* selector, RenderStyle
 
 bool RenderThemeGtk::paintMenuList(RenderObject* o, const PaintInfo& i, const IntRect& rect)
 {
-    return paintMozillaGtkWidget(this, MOZ_GTK_DROPDOWN, o, i, rect);
+    return paintRenderObject(MOZ_GTK_DROPDOWN, o, i.context, rect);
 }
 
 void RenderThemeGtk::adjustTextFieldStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
@@ -470,7 +479,7 @@ void RenderThemeGtk::adjustTextFieldStyle(CSSStyleSelector* selector, RenderStyl
 
 bool RenderThemeGtk::paintTextField(RenderObject* o, const PaintInfo& i, const IntRect& rect)
 {
-    return paintMozillaGtkWidget(this, MOZ_GTK_ENTRY, o, i, rect);
+    return paintRenderObject(MOZ_GTK_ENTRY, o, i.context, rect);
 }
 
 bool RenderThemeGtk::paintTextArea(RenderObject* o, const PaintInfo& i, const IntRect& r)
@@ -550,7 +559,7 @@ bool RenderThemeGtk::paintSliderTrack(RenderObject* object, const PaintInfo& inf
     if (part == SliderVerticalPart)
         gtkPart = MOZ_GTK_SCALE_VERTICAL;
 
-    return paintMozillaGtkWidget(this, gtkPart, object, info, rect);
+    return paintRenderObject(gtkPart, object, info.context, rect);
 }
 
 void RenderThemeGtk::adjustSliderTrackStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
@@ -567,7 +576,7 @@ bool RenderThemeGtk::paintSliderThumb(RenderObject* object, const PaintInfo& inf
     if (part == SliderThumbVerticalPart)
         gtkPart = MOZ_GTK_SCALE_THUMB_VERTICAL;
 
-    return paintMozillaGtkWidget(this, gtkPart, object, info, rect);
+    return paintRenderObject(gtkPart, object, info.context, rect);
 }
 
 void RenderThemeGtk::adjustSliderThumbStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
@@ -873,7 +882,7 @@ bool RenderThemeGtk::paintProgressBar(RenderObject* renderObject, const PaintInf
     if (!progressBarWidget)
         return true;
 
-    if (paintMozillaGtkWidget(this, MOZ_GTK_PROGRESSBAR, renderObject, paintInfo, rect))
+    if (paintRenderObject(MOZ_GTK_PROGRESSBAR, renderObject, paintInfo.context, rect))
         return true;
 
     IntRect chunkRect(rect);
@@ -888,7 +897,7 @@ bool RenderThemeGtk::paintProgressBar(RenderObject* renderObject, const PaintInf
     else
         chunkRect.setX(chunkRect.x() + style->xthickness);
 
-    return paintMozillaGtkWidget(this, MOZ_GTK_PROGRESS_CHUNK, renderObject, paintInfo, chunkRect);
+    return paintRenderObject(MOZ_GTK_PROGRESS_CHUNK, renderObject, paintInfo.context, chunkRect);
 }
 #endif
 
diff --git a/WebCore/platform/gtk/RenderThemeGtk.h b/WebCore/platform/gtk/RenderThemeGtk.h
index b9c076d..d2e0d70 100644
--- a/WebCore/platform/gtk/RenderThemeGtk.h
+++ b/WebCore/platform/gtk/RenderThemeGtk.h
@@ -29,6 +29,7 @@
 #define RenderThemeGtk_h
 
 #include "GRefPtr.h"
+#include "gtkdrawing.h"
 #include "RenderTheme.h"
 
 typedef struct _GtkWidget GtkWidget;
@@ -95,7 +96,7 @@ public:
     virtual String extraMediaControlsStyleSheet();
 #endif
 
-    GtkThemeParts* partsForDrawable(GdkDrawable*) const;
+    bool paintMozillaGtkWidget(GtkThemeWidgetType, GraphicsContext*, const IntRect&, GtkWidgetState*, int flags, GtkTextDirection = GTK_TEXT_DIR_NONE);
 
 protected:
     virtual bool paintCheckbox(RenderObject* o, const PaintInfo& i, const IntRect& r);
@@ -167,6 +168,9 @@ private:
      */
     GtkContainer* gtkContainer() const;
 
+    bool paintRenderObject(GtkThemeWidgetType, RenderObject*, GraphicsContext*, const IntRect& rect, int flags = 0);
+    GtkThemeParts* partsForDrawable(GdkDrawable*) const;
+
     mutable GtkWidget* m_gtkWindow;
     mutable GtkContainer* m_gtkContainer;
     mutable GtkWidget* m_gtkButton;
diff --git a/WebCore/platform/gtk/ScrollbarThemeGtk.cpp b/WebCore/platform/gtk/ScrollbarThemeGtk.cpp
index fee2c70..ab100a9 100644
--- a/WebCore/platform/gtk/ScrollbarThemeGtk.cpp
+++ b/WebCore/platform/gtk/ScrollbarThemeGtk.cpp
@@ -26,6 +26,9 @@
 #include "config.h"
 #include "ScrollbarThemeGtk.h"
 
+#include "PlatformMouseEvent.h"
+#include "RenderThemeGtk.h"
+#include "Scrollbar.h"
 #include "gtkdrawing.h"
 #include <gtk/gtk.h>
 
@@ -41,15 +44,262 @@ ScrollbarThemeGtk::~ScrollbarThemeGtk()
 {
 }
 
-int ScrollbarThemeGtk::scrollbarThickness(ScrollbarControlSize controlSize)
+bool ScrollbarThemeGtk::hasThumb(Scrollbar* scrollbar)
 {
-    static int size;
-    if (!size) {
-        MozGtkScrollbarMetrics metrics;
-        moz_gtk_get_scrollbar_metrics(&metrics);
-        size = metrics.slider_width;
+    // This method is just called as a paint-time optimization to see if
+    // painting the thumb can be skipped.  We don't have to be exact here.
+    return thumbLength(scrollbar) > 0;
+}
+
+IntRect ScrollbarThemeGtk::backButtonRect(Scrollbar* scrollbar, ScrollbarPart part, bool)
+{
+    // We do not support multiple steppers per end yet.
+    if (part == BackButtonEndPart)
+        return IntRect();
+
+    MozGtkScrollbarMetrics metrics;
+    moz_gtk_get_scrollbar_metrics(&metrics);
+    IntSize size = buttonSize(scrollbar);
+    return IntRect(scrollbar->x() + metrics.trough_border, scrollbar->y() + metrics.trough_border, size.width(), size.height());
+}
+
+IntRect ScrollbarThemeGtk::forwardButtonRect(Scrollbar* scrollbar, ScrollbarPart part, bool)
+{
+    // We do not support multiple steppers per end yet.
+    if (part == ForwardButtonStartPart)
+        return IntRect();
+
+    MozGtkScrollbarMetrics metrics;
+    moz_gtk_get_scrollbar_metrics(&metrics);
+
+    IntSize size = buttonSize(scrollbar);
+    int x, y;
+    if (scrollbar->orientation() == HorizontalScrollbar) {
+        x = scrollbar->x() + scrollbar->width() - size.width() - metrics.trough_border;
+        y = scrollbar->y() + metrics.trough_border;
+    } else {
+        x = scrollbar->x() + metrics.trough_border;
+        y = scrollbar->y() + scrollbar->height() - size.height() - metrics.trough_border;
+    }
+    return IntRect(x, y, size.width(), size.height());
+}
+
+IntRect ScrollbarThemeGtk::trackRect(Scrollbar* scrollbar, bool)
+{
+    // The padding along the thumb movement axis (from outside to in)
+    // is the size of trough border plus the size of the stepper (button)
+    // plus the size of stepper spacing (the space between the stepper and
+    // the place where the thumb stops). There is often no stepper spacing.
+    MozGtkScrollbarMetrics metrics;
+    moz_gtk_get_scrollbar_metrics(&metrics);
+    int movementAxisPadding = metrics.trough_border + metrics.stepper_size + metrics.stepper_spacing;
+
+    // The thickness (of the long part) of the scrollbar. We could also
+    // use scrollbarThickness here, but that would mean one more call to
+    // moz_gtk_get_scrollbar_metrics.
+    int thickness = metrics.slider_width + (metrics.trough_border * 2);
+
+    if (scrollbar->orientation() == HorizontalScrollbar) {
+        // Once the scrollbar becomes smaller than the natural size of the
+        // two buttons, the track disappears.
+        if (scrollbar->width() < 2 * thickness)
+            return IntRect();
+        return IntRect(scrollbar->x() + movementAxisPadding, scrollbar->y(), scrollbar->width() - (2 * movementAxisPadding), thickness);
+    }
+
+    if (scrollbar->height() < 2 * thickness)
+        return IntRect();
+    return IntRect(scrollbar->x(), scrollbar->y() + movementAxisPadding, thickness, scrollbar->height() - (2 * movementAxisPadding));
+}
+
+void ScrollbarThemeGtk::paintTrackBackground(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect)
+{
+    GtkWidgetState state;
+    state.focused = FALSE;
+    state.isDefault = FALSE;
+    state.canDefault = FALSE;
+    state.disabled = FALSE;
+    state.active = FALSE;
+    state.inHover = FALSE;
+
+    IntRect fullScrollbarRect(scrollbar->x(), scrollbar->y(), scrollbar->width(), scrollbar->height());
+    GtkThemeWidgetType type = scrollbar->orientation() == VerticalScrollbar ? MOZ_GTK_SCROLLBAR_TRACK_VERTICAL : MOZ_GTK_SCROLLBAR_TRACK_HORIZONTAL;
+    static_cast<RenderThemeGtk*>(RenderTheme::defaultTheme().get())->paintMozillaGtkWidget(type, context, fullScrollbarRect, &state, 0);
+}
+
+void ScrollbarThemeGtk::paintScrollbarBackground(GraphicsContext* context, Scrollbar* scrollbar)
+{
+    GtkWidgetState state;
+    state.focused = FALSE;
+    state.isDefault = FALSE;
+    state.canDefault = FALSE;
+    state.disabled = FALSE;
+    state.active = TRUE;
+    state.inHover = FALSE;
+
+    IntRect fullScrollbarRect = IntRect(scrollbar->x(), scrollbar->y(), scrollbar->width(), scrollbar->height());
+    static_cast<RenderThemeGtk*>(RenderTheme::defaultTheme().get())->paintMozillaGtkWidget(MOZ_GTK_SCROLLED_WINDOW, context, fullScrollbarRect, &state, 0);
+}
+
+void ScrollbarThemeGtk::paintThumb(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect)
+{
+    GtkWidgetState state;
+    state.focused = FALSE;
+    state.isDefault = FALSE;
+    state.canDefault = FALSE;
+    state.disabled = FALSE;
+    state.active = scrollbar->pressedPart() == ThumbPart;
+    state.inHover = scrollbar->hoveredPart() == ThumbPart;
+    state.maxpos = scrollbar->maximum();
+    state.curpos = scrollbar->currentPos();
+
+    GtkThemeWidgetType type = scrollbar->orientation() == VerticalScrollbar ? MOZ_GTK_SCROLLBAR_THUMB_VERTICAL : MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL;
+    static_cast<RenderThemeGtk*>(RenderTheme::defaultTheme().get())->paintMozillaGtkWidget(type, context, rect, &state, 0);
+}
+
+IntRect ScrollbarThemeGtk::thumbRect(Scrollbar* scrollbar, const IntRect& unconstrainedTrackRect)
+{
+    MozGtkScrollbarMetrics metrics;
+    moz_gtk_get_scrollbar_metrics(&metrics);
+
+    IntRect trackRect = constrainTrackRectToTrackPieces(scrollbar, unconstrainedTrackRect);
+    int thickness = metrics.slider_width;
+    int thumbPos = thumbPosition(scrollbar);
+    if (scrollbar->orientation() == HorizontalScrollbar)
+        return IntRect(trackRect.x() + thumbPos, trackRect.y() + (trackRect.height() - thickness) / 2, thumbLength(scrollbar), thickness); 
+
+    // VerticalScrollbar
+    return IntRect(trackRect.x() + (trackRect.width() - thickness) / 2, trackRect.y() + thumbPos, thickness, thumbLength(scrollbar));
+}
+
+bool ScrollbarThemeGtk::paint(Scrollbar* scrollbar, GraphicsContext* graphicsContext, const IntRect& damageRect)
+{
+    // Create the ScrollbarControlPartMask based on the damageRect
+    ScrollbarControlPartMask scrollMask = NoPart;
+
+    IntRect backButtonStartPaintRect;
+    IntRect backButtonEndPaintRect;
+    IntRect forwardButtonStartPaintRect;
+    IntRect forwardButtonEndPaintRect;
+    if (hasButtons(scrollbar)) {
+        backButtonStartPaintRect = backButtonRect(scrollbar, BackButtonStartPart, true);
+        if (damageRect.intersects(backButtonStartPaintRect))
+            scrollMask |= BackButtonStartPart;
+        backButtonEndPaintRect = backButtonRect(scrollbar, BackButtonEndPart, true);
+        if (damageRect.intersects(backButtonEndPaintRect))
+            scrollMask |= BackButtonEndPart;
+        forwardButtonStartPaintRect = forwardButtonRect(scrollbar, ForwardButtonStartPart, true);
+        if (damageRect.intersects(forwardButtonStartPaintRect))
+            scrollMask |= ForwardButtonStartPart;
+        forwardButtonEndPaintRect = forwardButtonRect(scrollbar, ForwardButtonEndPart, true);
+        if (damageRect.intersects(forwardButtonEndPaintRect))
+            scrollMask |= ForwardButtonEndPart;
+    }
+
+    IntRect trackPaintRect = trackRect(scrollbar, true);
+    if (damageRect.intersects(trackPaintRect))
+        scrollMask |= TrackBGPart;
+
+    bool thumbPresent = hasThumb(scrollbar);
+    IntRect currentThumbRect;
+    if (thumbPresent) {
+        IntRect track = trackRect(scrollbar, false);
+        currentThumbRect = thumbRect(scrollbar, track);
+        if (damageRect.intersects(currentThumbRect))
+            scrollMask |= ThumbPart;
+    }
+
+    // Paint the scrollbar background (only used by custom CSS scrollbars).
+    paintScrollbarBackground(graphicsContext, scrollbar);
+
+    if (scrollMask & TrackBGPart)
+        paintTrackBackground(graphicsContext, scrollbar, trackPaintRect);
+
+    // Paint the back and forward buttons.
+    if (scrollMask & BackButtonStartPart)
+        paintButton(graphicsContext, scrollbar, backButtonStartPaintRect, BackButtonStartPart);
+    if (scrollMask & BackButtonEndPart)
+        paintButton(graphicsContext, scrollbar, backButtonEndPaintRect, BackButtonEndPart);
+    if (scrollMask & ForwardButtonStartPart)
+        paintButton(graphicsContext, scrollbar, forwardButtonStartPaintRect, ForwardButtonStartPart);
+    if (scrollMask & ForwardButtonEndPart)
+        paintButton(graphicsContext, scrollbar, forwardButtonEndPaintRect, ForwardButtonEndPart);
+
+    // Paint the thumb.
+    if (scrollMask & ThumbPart)
+        paintThumb(graphicsContext, scrollbar, currentThumbRect);
+
+    return true;
+}
+
+void ScrollbarThemeGtk::paintButton(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart part)
+{
+    int flags = 0;
+    if (scrollbar->orientation() == VerticalScrollbar)
+        flags |= MOZ_GTK_STEPPER_VERTICAL;
+
+    if (part == ForwardButtonEndPart) {
+        flags |= MOZ_GTK_STEPPER_DOWN;
+        flags |= MOZ_GTK_STEPPER_BOTTOM;
+    }
+
+    GtkWidgetState state;
+    state.focused = TRUE;
+    state.isDefault = TRUE;
+    state.canDefault = TRUE;
+
+    if ((BackButtonStartPart == part && scrollbar->currentPos())
+        || (ForwardButtonEndPart == part && scrollbar->currentPos() != scrollbar->maximum())) {
+        state.disabled = FALSE;
+        state.active = part == scrollbar->pressedPart();
+        state.inHover = part == scrollbar->hoveredPart();
+    } else {
+        state.disabled = TRUE;
+        state.active = FALSE;
+        state.inHover = FALSE;
     }
-    return size;
+
+    static_cast<RenderThemeGtk*>(RenderTheme::defaultTheme().get())->paintMozillaGtkWidget(MOZ_GTK_SCROLLBAR_BUTTON, context, rect, &state, flags);
+}
+
+void ScrollbarThemeGtk::paintScrollCorner(ScrollView* view, GraphicsContext* context, const IntRect& cornerRect)
+{
+    // ScrollbarThemeComposite::paintScrollCorner incorrectly assumes that the
+    // ScrollView is a FrameView (see FramelessScrollView), so we cannot let
+    // that code run.  For FrameView's this is correct since we don't do custom
+    // scrollbar corner rendering, which ScrollbarThemeComposite supports.
+    ScrollbarTheme::paintScrollCorner(view, context, cornerRect);
+}
+
+bool ScrollbarThemeGtk::shouldCenterOnThumb(Scrollbar*, const PlatformMouseEvent& event)
+{
+    return (event.shiftKey() && event.button() == LeftButton) || (event.button() == MiddleButton);
+}
+
+int ScrollbarThemeGtk::scrollbarThickness(ScrollbarControlSize)
+{
+    MozGtkScrollbarMetrics metrics;
+    moz_gtk_get_scrollbar_metrics(&metrics);
+    return metrics.slider_width + (metrics.trough_border * 2);
+}
+
+IntSize ScrollbarThemeGtk::buttonSize(Scrollbar* scrollbar)
+{
+    MozGtkScrollbarMetrics metrics;
+    moz_gtk_get_scrollbar_metrics(&metrics);
+
+    if (scrollbar->orientation() == VerticalScrollbar)
+        return IntSize(metrics.slider_width, metrics.stepper_size);
+
+    // HorizontalScrollbar
+    return IntSize(metrics.stepper_size, metrics.slider_width);
+}
+
+int ScrollbarThemeGtk::minimumThumbLength(Scrollbar* scrollbar)
+{
+    MozGtkScrollbarMetrics metrics;
+    moz_gtk_get_scrollbar_metrics(&metrics);
+    return metrics.min_slider_size;
 }
 
 }
diff --git a/WebCore/platform/gtk/ScrollbarThemeGtk.h b/WebCore/platform/gtk/ScrollbarThemeGtk.h
index 618da35..4080b77 100644
--- a/WebCore/platform/gtk/ScrollbarThemeGtk.h
+++ b/WebCore/platform/gtk/ScrollbarThemeGtk.h
@@ -26,20 +26,37 @@
 #ifndef ScrollbarThemeGtk_h
 #define ScrollbarThemeGtk_h
 
-#include "ScrollbarTheme.h"
-
-typedef struct _GtkWidget GtkWidget;
-typedef struct _GtkStyle GtkStyle;
-typedef struct _GtkContainer GtkContainer;
-typedef struct _GtkBorder GtkBorder;
+#include "ScrollbarThemeComposite.h"
 
 namespace WebCore {
 
-class ScrollbarThemeGtk : public ScrollbarTheme {
+class Scrollbar;
+
+class ScrollbarThemeGtk : public ScrollbarThemeComposite {
 public:
     virtual ~ScrollbarThemeGtk();
 
-    virtual int scrollbarThickness(ScrollbarControlSize = RegularScrollbar);
+    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);
+    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 void paintScrollCorner(ScrollView*, GraphicsContext*, const IntRect&);
+    virtual bool shouldCenterOnThumb(Scrollbar*, const PlatformMouseEvent&);
+    virtual int scrollbarThickness(ScrollbarControlSize);
+    virtual IntSize buttonSize(Scrollbar*);
+    virtual int minimumThumbLength(Scrollbar*);
+
+    // 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; }
+
 };
 
 }

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list