Bug 1171696 - Require room for scrollbar sliders and draw troughs only when there is room for a slider or buttons on GTK. r=karlt

This commit is contained in:
Andrew Comminos 2015-06-17 07:27:00 -04:00
parent 402bfa77ba
commit b7bf2737b5
4 changed files with 46 additions and 19 deletions

View File

@ -3409,6 +3409,20 @@ GtkWidget* moz_gtk_get_scrollbar_widget(void)
return gHorizScrollbarWidget;
}
gboolean moz_gtk_has_scrollbar_buttons(void)
{
gboolean backward, forward, secondary_backward, secondary_forward;
MOZ_ASSERT(is_initialized, "Forgot to call moz_gtk_init()");
ensure_scrollbar_widget();
gtk_widget_style_get (gHorizScrollbarWidget,
"has-backward-stepper", &backward,
"has-forward-stepper", &forward,
"has-secondary-backward-stepper", &secondary_backward,
"has-secondary-forward-stepper", &secondary_forward,
NULL);
return backward | forward | secondary_forward | secondary_forward;
}
gint
moz_gtk_shutdown()
{

View File

@ -3265,6 +3265,20 @@ GtkWidget* moz_gtk_get_scrollbar_widget(void)
return gHorizScrollbarWidget;
}
gboolean moz_gtk_has_scrollbar_buttons(void)
{
gboolean backward, forward, secondary_backward, secondary_forward;
MOZ_ASSERT(is_initialized, "Forgot to call moz_gtk_init()");
ensure_scrollbar_widget();
gtk_widget_style_get (gHorizScrollbarWidget,
"has-backward-stepper", &backward,
"has-forward-stepper", &forward,
"has-secondary-backward-stepper", &secondary_backward,
"has-secondary-forward-stepper", &secondary_forward,
NULL);
return backward | forward | secondary_forward | secondary_forward;
}
gint
moz_gtk_shutdown()
{

View File

@ -440,6 +440,12 @@ gboolean moz_gtk_images_in_menus(void);
*/
gboolean moz_gtk_images_in_buttons(void);
/**
* Get a boolean which indicates whether the theme draws scrollbar buttons.
* If TRUE, draw scrollbar buttons.
*/
gboolean moz_gtk_has_scrollbar_buttons(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -1400,10 +1400,18 @@ nsNativeThemeGTK::GetMinimumWidgetSize(nsPresContext* aPresContext,
MozGtkScrollbarMetrics metrics;
moz_gtk_get_scrollbar_metrics(&metrics);
if (aWidgetType == NS_THEME_SCROLLBAR_TRACK_VERTICAL)
// Require room for the slider in the track if we don't have buttons.
bool hasScrollbarButtons = moz_gtk_has_scrollbar_buttons();
if (aWidgetType == NS_THEME_SCROLLBAR_TRACK_VERTICAL) {
aResult->width = metrics.slider_width + 2 * metrics.trough_border;
else
if (!hasScrollbarButtons)
aResult->height = metrics.min_slider_size + 2 * metrics.trough_border;
} else {
aResult->height = metrics.slider_width + 2 * metrics.trough_border;
if (!hasScrollbarButtons)
aResult->width = metrics.min_slider_size + 2 * metrics.trough_border;
}
*aIsOverridable = false;
}
@ -1414,27 +1422,12 @@ nsNativeThemeGTK::GetMinimumWidgetSize(nsPresContext* aPresContext,
MozGtkScrollbarMetrics metrics;
moz_gtk_get_scrollbar_metrics(&metrics);
nsRect rect = aFrame->GetParent()->GetRect();
int32_t p2a = aFrame->PresContext()->DeviceContext()->
AppUnitsPerDevPixel();
nsMargin margin;
/* Get the available space, if that is smaller then the minimum size,
* adjust the mininum size to fit into it.
* Setting aIsOverridable to true has no effect for thumbs. */
aFrame->GetMargin(margin);
rect.Deflate(margin);
aFrame->GetParent()->GetBorderAndPadding(margin);
rect.Deflate(margin);
if (aWidgetType == NS_THEME_SCROLLBAR_THUMB_VERTICAL) {
aResult->width = metrics.slider_width;
aResult->height = std::min(NSAppUnitsToIntPixels(rect.height, p2a),
metrics.min_slider_size);
aResult->height = metrics.min_slider_size;
} else {
aResult->height = metrics.slider_width;
aResult->width = std::min(NSAppUnitsToIntPixels(rect.width, p2a),
metrics.min_slider_size);
aResult->width = metrics.min_slider_size;
}
*aIsOverridable = false;