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;
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;

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

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

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

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

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

@ -80,6 +80,7 @@ static GtkShadowType gToolbarShadowType;
static style_prop_t style_prop_func;
static gboolean have_menu_shadow_type;
static gboolean is_initialized;
gint
moz_gtk_enable_style_props(style_prop_t styleGetProp)
@ -440,6 +441,7 @@ moz_gtk_button_paint(GdkDrawable* drawable, GdkRectangle* rect,
gint
moz_gtk_init()
{
is_initialized = TRUE;
have_menu_shadow_type =
(gtk_major_version > 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;
}

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

@ -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 */

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

@ -41,6 +41,8 @@
#include "nsLookAndFeel.h"
#include <gtk/gtkinvisible.h>
#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;

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

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