From 171e5d95f2a97f4ed3bfbeab4b9a2d3070111a61 Mon Sep 17 00:00:00 2001 From: "roc+%cs.cmu.edu" Date: Mon, 1 May 2006 23:23:33 +0000 Subject: [PATCH] Bug 263444. Allow nsILookAndFeel to request any combination of scrollbar arrows (up and/or down (or neither) at each end of the scrollbar) on all platforms. Get the arrow settings from the GTK2 style in GTK2 builds. r+sr=bryner --- layout/xul/base/src/nsBoxObject.cpp | 30 +++++++++---------- toolkit/content/widgets/scrollbar.xml | 29 ++++++++---------- widget/public/nsILookAndFeel.h | 17 ++++++++--- widget/src/gtk2/gtk2drawing.c | 12 ++++++++ widget/src/gtk2/gtkdrawing.h | 6 ++++ widget/src/gtk2/nsLookAndFeel.cpp | 27 ++++++++++++++++- .../resources/content/bindings/scrollbar.xml | 29 ++++++++---------- 7 files changed, 96 insertions(+), 54 deletions(-) diff --git a/layout/xul/base/src/nsBoxObject.cpp b/layout/xul/base/src/nsBoxObject.cpp index cfb1a07274e..1435fb036ab 100644 --- a/layout/xul/base/src/nsBoxObject.cpp +++ b/layout/xul/base/src/nsBoxObject.cpp @@ -340,23 +340,23 @@ nsBoxObject::GetLookAndFeelMetric(const PRUnichar* aPropertyName, return NS_ERROR_FAILURE; nsAutoString property(aPropertyName); - if (property.LowerCaseEqualsLiteral("scrollbarstyle")) { + if (property.LowerCaseEqualsLiteral("scrollbararrows")) { PRInt32 metricResult; lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ScrollArrowStyle, metricResult); - switch (metricResult) { - case nsILookAndFeel::eMetric_ScrollArrowStyleBothAtBottom: - *aResult = ToNewUnicode(NS_LITERAL_STRING("doublebottom")); - break; - case nsILookAndFeel::eMetric_ScrollArrowStyleBothAtEachEnd: - *aResult = ToNewUnicode(NS_LITERAL_STRING("double")); - break; - case nsILookAndFeel::eMetric_ScrollArrowStyleBothAtTop: - *aResult = ToNewUnicode(NS_LITERAL_STRING("doubletop")); - break; - default: - *aResult = ToNewUnicode(NS_LITERAL_STRING("single")); - break; - } + nsAutoString result; + if (metricResult & nsILookAndFeel::eMetric_ScrollArrowStartBackward) { + result.AppendLiteral("start-backward "); + } + if (metricResult & nsILookAndFeel::eMetric_ScrollArrowStartForward) { + result.AppendLiteral("start-forward "); + } + if (metricResult & nsILookAndFeel::eMetric_ScrollArrowEndBackward) { + result.AppendLiteral("end-backward "); + } + if (metricResult & nsILookAndFeel::eMetric_ScrollArrowEndForward) { + result.AppendLiteral("end-forward"); + } + *aResult = ToNewUnicode(result); } else if (property.LowerCaseEqualsLiteral("thumbstyle")) { PRInt32 metricResult; diff --git a/toolkit/content/widgets/scrollbar.xml b/toolkit/content/widgets/scrollbar.xml index a5b5eccee84..6e79f3ece78 100644 --- a/toolkit/content/widgets/scrollbar.xml +++ b/toolkit/content/widgets/scrollbar.xml @@ -34,34 +34,29 @@ - if (navigator.platform.indexOf("Mac") != -1) - this.initScrollbar(); + this.initScrollbar(); 2 || (gtk_major_version == 2 && gtk_minor_version >= 1)); @@ -1676,6 +1678,14 @@ moz_gtk_widget_paint(GtkThemeWidgetType widget, GdkDrawable* drawable, return MOZ_GTK_UNKNOWN_WIDGET; } +GtkWidget* moz_gtk_get_scrollbar_widget(void) +{ + if (!is_initialized) + return NULL; + ensure_scrollbar_widget(); + return gHorizScrollbarWidget; +} + gint moz_gtk_shutdown() { @@ -1706,5 +1716,7 @@ moz_gtk_shutdown() gMenuItemWidget = NULL; gCheckMenuItemWidget = NULL; + is_initialized = FALSE; + return MOZ_GTK_SUCCESS; } diff --git a/widget/src/gtk2/gtkdrawing.h b/widget/src/gtk2/gtkdrawing.h index f1a7f5fc78d..c91a53fc7b4 100644 --- a/widget/src/gtk2/gtkdrawing.h +++ b/widget/src/gtk2/gtkdrawing.h @@ -266,6 +266,12 @@ moz_gtk_get_scrollbar_metrics(MozGtkScrollbarMetrics* metrics); */ gint moz_gtk_get_dropdown_arrow_size(gint* width, gint* height); +/** + * Retrieve an actual GTK scrollbar widget for style analysis. It will not + * be modified. + */ +GtkWidget* moz_gtk_get_scrollbar_widget(void); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/widget/src/gtk2/nsLookAndFeel.cpp b/widget/src/gtk2/nsLookAndFeel.cpp index 2dadf6c0702..428842e85e7 100644 --- a/widget/src/gtk2/nsLookAndFeel.cpp +++ b/widget/src/gtk2/nsLookAndFeel.cpp @@ -41,6 +41,8 @@ #include "nsLookAndFeel.h" #include +#include "gtkdrawing.h" + #define GDK_COLOR_TO_NS_RGB(c) \ ((nscolor) NS_RGB(c.red>>8, c.green>>8, c.blue>>8)) @@ -304,6 +306,28 @@ nsresult nsLookAndFeel::NativeGetColor(const nsColorID aID, nscolor& aColor) return res; } +static PRInt32 CheckWidgetStyle(GtkWidget* aWidget, const char* aStyle, PRInt32 aMetric) { + gboolean value = PR_FALSE; + gtk_widget_style_get(aWidget, aStyle, &value, NULL); + return value ? aMetric : 0; +} + +static PRInt32 ConvertGTKStepperStyleToMozillaScrollArrowStyle(GtkWidget* aWidget) +{ + if (!aWidget) + return nsILookAndFeel::eMetric_ScrollArrowStyleSingle; + + return + CheckWidgetStyle(aWidget, "has-backward-stepper", + nsILookAndFeel::eMetric_ScrollArrowStartBackward) | + CheckWidgetStyle(aWidget, "has-forward-stepper", + nsILookAndFeel::eMetric_ScrollArrowEndForward) | + CheckWidgetStyle(aWidget, "has-secondary-backward-stepper", + nsILookAndFeel::eMetric_ScrollArrowEndBackward) | + CheckWidgetStyle(aWidget, "has-secondary-forward-stepper", + nsILookAndFeel::eMetric_ScrollArrowStartForward); +} + NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric) { nsresult res = NS_OK; @@ -462,7 +486,8 @@ NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric) } break; case eMetric_ScrollArrowStyle: - aMetric = eMetric_ScrollArrowStyleSingle; + aMetric = + ConvertGTKStepperStyleToMozillaScrollArrowStyle(moz_gtk_get_scrollbar_widget()); break; case eMetric_ScrollSliderStyle: aMetric = eMetric_ScrollThumbStyleProportional; diff --git a/xpfe/global/resources/content/bindings/scrollbar.xml b/xpfe/global/resources/content/bindings/scrollbar.xml index a5b5eccee84..6e79f3ece78 100644 --- a/xpfe/global/resources/content/bindings/scrollbar.xml +++ b/xpfe/global/resources/content/bindings/scrollbar.xml @@ -34,34 +34,29 @@ - if (navigator.platform.indexOf("Mac") != -1) - this.initScrollbar(); + this.initScrollbar();