Bug 1638107 - Scale gtk entry min height by the font-size for smaller-than-default font-sizes. r=karlt

This makes inputs not remain very big at small font sizes, which is
needed for compat both with other browsers and platforms, while keeping
the right native appearance at normal / large font sizes.

Differential Revision: https://phabricator.services.mozilla.com/D76256
This commit is contained in:
Emilio Cobos Álvarez 2020-05-26 01:34:25 +00:00
parent 53d0bd6bbd
commit 8d8d416c63
7 changed files with 48 additions and 11 deletions

View File

@ -2,6 +2,6 @@ include input/reftest.list
include textarea/reftest.list
fuzzy-if(skiaContent,0-1,0-4) == css-restrictions.html css-restrictions-ref.html
fuzzy-if(gtkWidget,255-255,1496-1498) == css-simple-styling.html css-simple-styling-ref.html # gtkWidget, Bug 1600749
fuzzy-if(gtkWidget,255-255,1376-1376) == css-simple-styling.html css-simple-styling-ref.html # gtkWidget, Bug 1600749
!= css-background.html css-background-ref.html
fuzzy-if(skiaContent,0-1,0-180) == ignore-pseudo-class.html ignore-pseudo-class-ref.html

View File

@ -0,0 +1,2 @@
<!doctype html>
<input style="width: 100px; font-size: 10px">

View File

@ -0,0 +1,2 @@
<!doctype html>
<input style="width: 100px; font-size: 16px">

View File

@ -9,3 +9,4 @@ fuzzy-if(skiaContent,0-1,0-500) needs-focus == select.html select-ref.html
== line-height-0.5.html line-height-1.0.html
!= line-height-2.5.html line-height-1.0.html
== shadow-rules.html shadow-rules-ref.html
!= height-small-font.html height-small-font-notref.html

View File

@ -2649,13 +2649,14 @@ gint moz_gtk_get_menu_separator_height(gint* size) {
return MOZ_GTK_SUCCESS;
}
void moz_gtk_get_entry_min_height(gint* height) {
void moz_gtk_get_entry_min_height(gint* min_content_height,
gint* border_padding_height) {
GtkStyleContext* style = GetStyleContext(MOZ_GTK_ENTRY);
if (!gtk_check_version(3, 20, 0)) {
gtk_style_context_get(style, gtk_style_context_get_state(style),
"min-height", height, nullptr);
"min-height", min_content_height, nullptr);
} else {
*height = 0;
*min_content_height = 0;
}
GtkBorder border;
@ -2665,7 +2666,8 @@ void moz_gtk_get_entry_min_height(gint* height) {
gtk_style_context_get_padding(style, gtk_style_context_get_state(style),
&padding);
*height += (border.top + border.bottom + padding.top + padding.bottom);
*border_padding_height =
(border.top + border.bottom + padding.top + padding.bottom);
}
void moz_gtk_get_scale_metrics(GtkOrientation orient, gint* scale_width,

View File

@ -548,10 +548,11 @@ void moz_gtk_get_arrow_size(WidgetNodeType widgetType, gint* width,
/**
* Get the minimum height of a entry widget
* size: [OUT] the minimum height
*
* min_content_height: [OUT] the minimum height of the content box.
* border_padding_height: [OUT] the size of borders and paddings.
*/
void moz_gtk_get_entry_min_height(gint* height);
void moz_gtk_get_entry_min_height(gint* min_content_height,
gint* border_padding_height);
/**
* Get the desired size of a toolbar separator

View File

@ -1663,9 +1663,38 @@ nsNativeThemeGTK::GetMinimumWidgetSize(nsPresContext* aPresContext,
case StyleAppearance::MenulistTextfield:
case StyleAppearance::NumberInput:
case StyleAppearance::Textfield: {
moz_gtk_get_entry_min_height(aFrame->GetWritingMode().IsVertical()
? &aResult->width
: &aResult->height);
gint contentHeight = 0;
gint borderPaddingHeight = 0;
moz_gtk_get_entry_min_height(&contentHeight, &borderPaddingHeight);
// Scale the min content height proportionately with the font-size if it's
// smaller than the default one. This prevents <input type=text
// style="font-size: .5em"> from keeping a ridiculously large size, for
// example.
const gfxFloat fieldFontSizeInCSSPixels = [] {
gfxFontStyle fieldFontStyle;
nsAutoString unusedFontName;
DebugOnly<bool> result = LookAndFeel::GetFont(
LookAndFeel::eFont_Field, unusedFontName, fieldFontStyle);
MOZ_ASSERT(result, "GTK look and feel supports the field font");
// NOTE: GetFont returns font sizes in CSS pixels, and we want just
// that.
return fieldFontStyle.size;
}();
const gfxFloat fontSize =
CSSPixel::FromAppUnits(aFrame->StyleFont()->mFont.size);
if (fieldFontSizeInCSSPixels > fontSize) {
contentHeight =
std::round(contentHeight * fontSize / fieldFontSizeInCSSPixels);
}
gint height = contentHeight + borderPaddingHeight;
if (aFrame->GetWritingMode().IsVertical()) {
aResult->width = height;
} else {
aResult->height = height;
}
} break;
case StyleAppearance::Separator: {
gint separator_width;