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

This commit is contained in:
roc+%cs.cmu.edu 2006-05-01 23:23:33 +00:00
Родитель 6b6c883634
Коммит 171e5d95f2
7 изменённых файлов: 96 добавлений и 54 удалений

Просмотреть файл

@ -340,23 +340,23 @@ nsBoxObject::GetLookAndFeelMetric(const PRUnichar* aPropertyName,
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
nsAutoString property(aPropertyName); nsAutoString property(aPropertyName);
if (property.LowerCaseEqualsLiteral("scrollbarstyle")) { if (property.LowerCaseEqualsLiteral("scrollbararrows")) {
PRInt32 metricResult; PRInt32 metricResult;
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ScrollArrowStyle, metricResult); lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ScrollArrowStyle, metricResult);
switch (metricResult) { nsAutoString result;
case nsILookAndFeel::eMetric_ScrollArrowStyleBothAtBottom: if (metricResult & nsILookAndFeel::eMetric_ScrollArrowStartBackward) {
*aResult = ToNewUnicode(NS_LITERAL_STRING("doublebottom")); result.AppendLiteral("start-backward ");
break; }
case nsILookAndFeel::eMetric_ScrollArrowStyleBothAtEachEnd: if (metricResult & nsILookAndFeel::eMetric_ScrollArrowStartForward) {
*aResult = ToNewUnicode(NS_LITERAL_STRING("double")); result.AppendLiteral("start-forward ");
break; }
case nsILookAndFeel::eMetric_ScrollArrowStyleBothAtTop: if (metricResult & nsILookAndFeel::eMetric_ScrollArrowEndBackward) {
*aResult = ToNewUnicode(NS_LITERAL_STRING("doubletop")); result.AppendLiteral("end-backward ");
break; }
default: if (metricResult & nsILookAndFeel::eMetric_ScrollArrowEndForward) {
*aResult = ToNewUnicode(NS_LITERAL_STRING("single")); result.AppendLiteral("end-forward");
break; }
} *aResult = ToNewUnicode(result);
} }
else if (property.LowerCaseEqualsLiteral("thumbstyle")) { else if (property.LowerCaseEqualsLiteral("thumbstyle")) {
PRInt32 metricResult; PRInt32 metricResult;

Просмотреть файл

@ -34,34 +34,29 @@
<implementation> <implementation>
<constructor> <constructor>
if (navigator.platform.indexOf("Mac") != -1) this.initScrollbar();
this.initScrollbar();
</constructor> </constructor>
<method name="initScrollbar"> <method name="initScrollbar">
<body> <body>
<![CDATA[ <![CDATA[
try { try {
var scrollbarStyle = this.boxObject.getLookAndFeelMetric("scrollbarStyle"); var arrows = this.boxObject.getLookAndFeelMetric("scrollbarArrows");
var thumbStyle = this.boxObject.getLookAndFeelMetric("thumbStyle"); var thumbStyle = this.boxObject.getLookAndFeelMetric("thumbStyle");
var downTop; if (!arrows.match(/start-backward/)) {
var upBottom; var upTop = document.getAnonymousElementByAttribute(this, "sbattr", "scrollbar-up-top");
if ( scrollbarStyle == "double" ) { upTop.setAttribute("hidden","true");
downTop = document.getAnonymousElementByAttribute(this, "sbattr", "scrollbar-down-top");
upBottom = document.getAnonymousElementByAttribute(this, "sbattr", "scrollbar-up-bottom");
downTop.removeAttribute("hidden");
upBottom.removeAttribute("hidden");
} }
else if ( scrollbarStyle == "doubletop" ) { if (arrows.match(/start-forward/)) {
downTop = document.getAnonymousElementByAttribute(this, "sbattr", "scrollbar-down-top"); var downTop = document.getAnonymousElementByAttribute(this, "sbattr", "scrollbar-down-top");
var downBottom = document.getAnonymousElementByAttribute(this, "sbattr", "scrollbar-down-bottom");
downTop.removeAttribute("hidden"); downTop.removeAttribute("hidden");
}
if (!arrows.match(/end-forward/)) {
var downBottom = document.getAnonymousElementByAttribute(this, "sbattr", "scrollbar-down-bottom");
downBottom.setAttribute("hidden","true"); downBottom.setAttribute("hidden","true");
} }
else if ( scrollbarStyle == "doublebottom" ) { if (arrows.match(/end-backward/)) {
var upTop = document.getAnonymousElementByAttribute(this, "sbattr", "scrollbar-up-top"); var upBottom = document.getAnonymousElementByAttribute(this, "sbattr", "scrollbar-up-bottom");
upBottom = document.getAnonymousElementByAttribute(this, "sbattr", "scrollbar-up-bottom");
upTop.setAttribute("hidden","true");
upBottom.removeAttribute("hidden"); upBottom.removeAttribute("hidden");
} }
if ( thumbStyle == "fixed" ) { if ( thumbStyle == "fixed" ) {

Просмотреть файл

@ -203,10 +203,19 @@ public:
} nsMetricID; } nsMetricID;
enum { enum {
eMetric_ScrollArrowStyleSingle, // single arrow at each end eMetric_ScrollArrowStartBackward = 0x1000,
eMetric_ScrollArrowStyleBothAtBottom, // both arrows at bottom/right, none at top/left eMetric_ScrollArrowStartForward = 0x0100,
eMetric_ScrollArrowStyleBothAtEachEnd, // both arrows at both ends eMetric_ScrollArrowEndBackward = 0x0010,
eMetric_ScrollArrowStyleBothAtTop // both arrows at top/left, none at bottom/right eMetric_ScrollArrowEndForward = 0x0001,
eMetric_ScrollArrowStyleSingle = // single arrow at each end
eMetric_ScrollArrowStartBackward|eMetric_ScrollArrowEndForward,
eMetric_ScrollArrowStyleBothAtBottom = // both arrows at bottom/right, none at top/left
eMetric_ScrollArrowEndBackward|eMetric_ScrollArrowEndForward,
eMetric_ScrollArrowStyleBothAtEachEnd = // both arrows at both ends
eMetric_ScrollArrowEndBackward|eMetric_ScrollArrowEndForward|
eMetric_ScrollArrowStartBackward|eMetric_ScrollArrowStartForward,
eMetric_ScrollArrowStyleBothAtTop = // both arrows at top/left, none at bottom/right
eMetric_ScrollArrowStartBackward|eMetric_ScrollArrowStartForward
}; };
enum { enum {
eMetric_ScrollThumbStyleNormal, eMetric_ScrollThumbStyleNormal,

Просмотреть файл

@ -80,6 +80,7 @@ static GtkShadowType gToolbarShadowType;
static style_prop_t style_prop_func; static style_prop_t style_prop_func;
static gboolean have_menu_shadow_type; static gboolean have_menu_shadow_type;
static gboolean is_initialized;
gint gint
moz_gtk_enable_style_props(style_prop_t styleGetProp) moz_gtk_enable_style_props(style_prop_t styleGetProp)
@ -440,6 +441,7 @@ moz_gtk_button_paint(GdkDrawable* drawable, GdkRectangle* rect,
gint gint
moz_gtk_init() moz_gtk_init()
{ {
is_initialized = TRUE;
have_menu_shadow_type = have_menu_shadow_type =
(gtk_major_version > 2 || (gtk_major_version > 2 ||
(gtk_major_version == 2 && gtk_minor_version >= 1)); (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; return MOZ_GTK_UNKNOWN_WIDGET;
} }
GtkWidget* moz_gtk_get_scrollbar_widget(void)
{
if (!is_initialized)
return NULL;
ensure_scrollbar_widget();
return gHorizScrollbarWidget;
}
gint gint
moz_gtk_shutdown() moz_gtk_shutdown()
{ {
@ -1706,5 +1716,7 @@ moz_gtk_shutdown()
gMenuItemWidget = NULL; gMenuItemWidget = NULL;
gCheckMenuItemWidget = NULL; gCheckMenuItemWidget = NULL;
is_initialized = FALSE;
return MOZ_GTK_SUCCESS; return MOZ_GTK_SUCCESS;
} }

Просмотреть файл

@ -266,6 +266,12 @@ moz_gtk_get_scrollbar_metrics(MozGtkScrollbarMetrics* metrics);
*/ */
gint moz_gtk_get_dropdown_arrow_size(gint* width, gint* height); 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 #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

Просмотреть файл

@ -41,6 +41,8 @@
#include "nsLookAndFeel.h" #include "nsLookAndFeel.h"
#include <gtk/gtkinvisible.h> #include <gtk/gtkinvisible.h>
#include "gtkdrawing.h"
#define GDK_COLOR_TO_NS_RGB(c) \ #define GDK_COLOR_TO_NS_RGB(c) \
((nscolor) NS_RGB(c.red>>8, c.green>>8, c.blue>>8)) ((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; 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) NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
{ {
nsresult res = NS_OK; nsresult res = NS_OK;
@ -462,7 +486,8 @@ NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
} }
break; break;
case eMetric_ScrollArrowStyle: case eMetric_ScrollArrowStyle:
aMetric = eMetric_ScrollArrowStyleSingle; aMetric =
ConvertGTKStepperStyleToMozillaScrollArrowStyle(moz_gtk_get_scrollbar_widget());
break; break;
case eMetric_ScrollSliderStyle: case eMetric_ScrollSliderStyle:
aMetric = eMetric_ScrollThumbStyleProportional; aMetric = eMetric_ScrollThumbStyleProportional;

Просмотреть файл

@ -34,34 +34,29 @@
<implementation> <implementation>
<constructor> <constructor>
if (navigator.platform.indexOf("Mac") != -1) this.initScrollbar();
this.initScrollbar();
</constructor> </constructor>
<method name="initScrollbar"> <method name="initScrollbar">
<body> <body>
<![CDATA[ <![CDATA[
try { try {
var scrollbarStyle = this.boxObject.getLookAndFeelMetric("scrollbarStyle"); var arrows = this.boxObject.getLookAndFeelMetric("scrollbarArrows");
var thumbStyle = this.boxObject.getLookAndFeelMetric("thumbStyle"); var thumbStyle = this.boxObject.getLookAndFeelMetric("thumbStyle");
var downTop; if (!arrows.match(/start-backward/)) {
var upBottom; var upTop = document.getAnonymousElementByAttribute(this, "sbattr", "scrollbar-up-top");
if ( scrollbarStyle == "double" ) { upTop.setAttribute("hidden","true");
downTop = document.getAnonymousElementByAttribute(this, "sbattr", "scrollbar-down-top");
upBottom = document.getAnonymousElementByAttribute(this, "sbattr", "scrollbar-up-bottom");
downTop.removeAttribute("hidden");
upBottom.removeAttribute("hidden");
} }
else if ( scrollbarStyle == "doubletop" ) { if (arrows.match(/start-forward/)) {
downTop = document.getAnonymousElementByAttribute(this, "sbattr", "scrollbar-down-top"); var downTop = document.getAnonymousElementByAttribute(this, "sbattr", "scrollbar-down-top");
var downBottom = document.getAnonymousElementByAttribute(this, "sbattr", "scrollbar-down-bottom");
downTop.removeAttribute("hidden"); downTop.removeAttribute("hidden");
}
if (!arrows.match(/end-forward/)) {
var downBottom = document.getAnonymousElementByAttribute(this, "sbattr", "scrollbar-down-bottom");
downBottom.setAttribute("hidden","true"); downBottom.setAttribute("hidden","true");
} }
else if ( scrollbarStyle == "doublebottom" ) { if (arrows.match(/end-backward/)) {
var upTop = document.getAnonymousElementByAttribute(this, "sbattr", "scrollbar-up-top"); var upBottom = document.getAnonymousElementByAttribute(this, "sbattr", "scrollbar-up-bottom");
upBottom = document.getAnonymousElementByAttribute(this, "sbattr", "scrollbar-up-bottom");
upTop.setAttribute("hidden","true");
upBottom.removeAttribute("hidden"); upBottom.removeAttribute("hidden");
} }
if ( thumbStyle == "fixed" ) { if ( thumbStyle == "fixed" ) {