Merge remote-tracking branch 'origin/master' into custom

This commit is contained in:
roytam1 2021-01-14 22:41:39 +08:00
commit a324d0a18c
52 changed files with 459 additions and 241 deletions

View file

@ -2279,6 +2279,12 @@ IsHiDPIContext(nsPresContext* aContext)
2 * aContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom();
}
static bool
IsScrollbarWidthThin(nsIFrame* aFrame)
{
return aFrame->StyleUserInterface()->mScrollbarWidth == StyleScrollbarWidth::Thin;
}
NS_IMETHODIMP
nsNativeThemeCocoa::DrawWidgetBackground(nsRenderingContext* aContext,
nsIFrame* aFrame,
@ -3392,9 +3398,10 @@ nsNativeThemeCocoa::GetMinimumWidgetSize(nsPresContext* aPresContext,
// Find our parent scrollbar frame in order to find out whether we're in
// a small or a large scrollbar.
nsIFrame *scrollbarFrame = GetParentScrollbarFrame(aFrame);
if (!scrollbarFrame)
if (!scrollbarFrame) {
return NS_ERROR_FAILURE;
}
bool isSmall = (scrollbarFrame->StyleDisplay()->mAppearance == NS_THEME_SCROLLBAR_SMALL);
bool isHorizontal = (aWidgetType == NS_THEME_SCROLLBARTHUMB_HORIZONTAL);
int32_t& minSize = isHorizontal ? aResult->width : aResult->height;
@ -3419,6 +3426,9 @@ nsNativeThemeCocoa::GetMinimumWidgetSize(nsPresContext* aPresContext,
else {
aResult->SizeTo(16, 16);
}
if (IsScrollbarWidthThin(aFrame)) {
aResult->SizeTo(8, 8);
}
break;
}
@ -3435,6 +3445,9 @@ nsNativeThemeCocoa::GetMinimumWidgetSize(nsPresContext* aPresContext,
kThemeMetricScrollBarWidth;
SInt32 scrollbarWidth = 0;
::GetThemeMetric(themeMetric, &scrollbarWidth);
if (IsScrollbarWidthThin(aFrame)) {
scrollbarWidth /= 2;
}
aResult->SizeTo(scrollbarWidth, scrollbarWidth);
break;
}
@ -3467,22 +3480,26 @@ nsNativeThemeCocoa::GetMinimumWidgetSize(nsPresContext* aPresContext,
case NS_THEME_SCROLLBARBUTTON_LEFT:
case NS_THEME_SCROLLBARBUTTON_RIGHT:
{
nsIFrame *scrollbarFrame = GetParentScrollbarFrame(aFrame);
if (!scrollbarFrame) return NS_ERROR_FAILURE;
if (!IsScrollbarWidthThin(aFrame)) {
// Get scrollbar button metrics from the system, except in the case of
// thin scrollbars, where we leave them at 0 (collapse)
// Since there is no NS_THEME_SCROLLBARBUTTON_UP_SMALL we need to ask the parent what appearance style it has.
int32_t themeMetric = (scrollbarFrame->StyleDisplay()->mAppearance == NS_THEME_SCROLLBAR_SMALL) ?
kThemeMetricSmallScrollBarWidth :
kThemeMetricScrollBarWidth;
SInt32 scrollbarWidth = 0;
::GetThemeMetric(themeMetric, &scrollbarWidth);
nsIFrame *scrollbarFrame = GetParentScrollbarFrame(aFrame);
if (!scrollbarFrame) return NS_ERROR_FAILURE;
// It seems that for both sizes of scrollbar, the buttons are one pixel "longer".
if (aWidgetType == NS_THEME_SCROLLBARBUTTON_LEFT || aWidgetType == NS_THEME_SCROLLBARBUTTON_RIGHT)
aResult->SizeTo(scrollbarWidth+1, scrollbarWidth);
else
aResult->SizeTo(scrollbarWidth, scrollbarWidth+1);
// Since there is no NS_THEME_SCROLLBARBUTTON_UP_SMALL we need to ask the parent what appearance style it has.
int32_t themeMetric = (scrollbarFrame->StyleDisplay()->mAppearance == NS_THEME_SCROLLBAR_SMALL) ?
kThemeMetricSmallScrollBarWidth :
kThemeMetricScrollBarWidth;
SInt32 scrollbarWidth = 0;
::GetThemeMetric(themeMetric, &scrollbarWidth);
// It seems that for both sizes of scrollbar, the buttons are one pixel "longer".
if (aWidgetType == NS_THEME_SCROLLBARBUTTON_LEFT || aWidgetType == NS_THEME_SCROLLBARBUTTON_RIGHT)
aResult->SizeTo(scrollbarWidth+1, scrollbarWidth);
else
aResult->SizeTo(scrollbarWidth, scrollbarWidth+1);
}
*aIsOverridable = false;
break;
}

View file

@ -1098,6 +1098,12 @@ nsNativeThemeGTK::GetExtraSizeForWidget(nsIFrame* aFrame, uint8_t aWidgetType,
return true;
}
static bool
IsScrollbarWidthThin(nsIFrame* aFrame)
{
return aFrame->StyleUserInterface()->mScrollbarWidth == StyleScrollbarWidth::Thin;
}
NS_IMETHODIMP
nsNativeThemeGTK::DrawWidgetBackground(nsRenderingContext* aContext,
nsIFrame* aFrame,
@ -1419,32 +1425,39 @@ nsNativeThemeGTK::GetMinimumWidgetSize(nsPresContext* aPresContext,
case NS_THEME_SCROLLBARBUTTON_UP:
case NS_THEME_SCROLLBARBUTTON_DOWN:
{
if (gtk_check_version(3,20,0) == nullptr) {
moz_gtk_get_widget_min_size(MOZ_GTK_SCROLLBAR_BUTTON,
&(aResult->width), &(aResult->height));
} else {
MozGtkScrollbarMetrics metrics;
moz_gtk_get_scrollbar_metrics(&metrics);
if (!IsScrollbarWidthThin(aFrame)) {
// Get scrollbar button metrics from the system, except in the case of
// thin scrollbars, where we leave them at 0 (collapse)
if (gtk_check_version(3,20,0) == nullptr) {
moz_gtk_get_widget_min_size(MOZ_GTK_SCROLLBAR_BUTTON,
&(aResult->width), &(aResult->height));
} else {
MozGtkScrollbarMetrics metrics;
moz_gtk_get_scrollbar_metrics(&metrics);
aResult->width = metrics.slider_width;
aResult->height = metrics.stepper_size;
aResult->width = metrics.slider_width;
aResult->height = metrics.stepper_size;
}
}
*aIsOverridable = false;
}
break;
case NS_THEME_SCROLLBARBUTTON_LEFT:
case NS_THEME_SCROLLBARBUTTON_RIGHT:
{
if (gtk_check_version(3,20,0) == nullptr) {
moz_gtk_get_widget_min_size(MOZ_GTK_SCROLLBAR_BUTTON,
&(aResult->width), &(aResult->height));
} else {
MozGtkScrollbarMetrics metrics;
moz_gtk_get_scrollbar_metrics(&metrics);
if (!IsScrollbarWidthThin(aFrame)) {
// Get scrollbar button metrics from the system, except in the case of
// thin scrollbars, where we leave them at 0 (collapse)
if (gtk_check_version(3,20,0) == nullptr) {
moz_gtk_get_widget_min_size(MOZ_GTK_SCROLLBAR_BUTTON,
&(aResult->width), &(aResult->height));
} else {
MozGtkScrollbarMetrics metrics;
moz_gtk_get_scrollbar_metrics(&metrics);
aResult->width = metrics.stepper_size;
aResult->height = metrics.slider_width;
aResult->width = metrics.stepper_size;
aResult->height = metrics.slider_width;
}
}
*aIsOverridable = false;
}
@ -1514,6 +1527,24 @@ nsNativeThemeGTK::GetMinimumWidgetSize(nsPresContext* aPresContext,
}
break;
case NS_THEME_SCROLLBARTHUMB_VERTICAL:
{
if (gtk_check_version(3,20,0) == nullptr) {
moz_gtk_get_widget_min_size(NativeThemeToGtkTheme(aWidgetType, aFrame),
&(aResult->width), &(aResult->height));
} else {
MozGtkScrollbarMetrics metrics;
moz_gtk_get_scrollbar_metrics(&metrics);
aResult->width = metrics.slider_width;
aResult->height = metrics.min_slider_size;
}
if (IsScrollbarWidthThin(aFrame)) {
// If thin scrollbars, divide the thickness by 3
aResult->width /= 3;
}
*aIsOverridable = false;
}
break;
case NS_THEME_SCROLLBARTHUMB_HORIZONTAL:
{
if (gtk_check_version(3,20,0) == nullptr) {
@ -1523,13 +1554,12 @@ nsNativeThemeGTK::GetMinimumWidgetSize(nsPresContext* aPresContext,
MozGtkScrollbarMetrics metrics;
moz_gtk_get_scrollbar_metrics(&metrics);
if (aWidgetType == NS_THEME_SCROLLBARTHUMB_VERTICAL) {
aResult->width = metrics.slider_width;
aResult->height = metrics.min_slider_size;
} else {
aResult->height = metrics.slider_width;
aResult->width = metrics.min_slider_size;
}
aResult->height = metrics.slider_width;
aResult->width = metrics.min_slider_size;
}
if (IsScrollbarWidthThin(aFrame)) {
// If thin scrollbars, divide the thickness by 3
aResult->height /= 3;
}
*aIsOverridable = false;
}

View file

@ -1569,6 +1569,12 @@ GetThemeDpiScaleFactor(nsIFrame* aFrame)
return 1.0;
}
static bool
IsScrollbarWidthThin(nsIFrame* aFrame)
{
return aFrame->StyleUserInterface()->mScrollbarWidth == StyleScrollbarWidth::Thin;
}
NS_IMETHODIMP
nsNativeThemeWin::DrawWidgetBackground(nsRenderingContext* aContext,
nsIFrame* aFrame,
@ -2999,14 +3005,21 @@ nsNativeThemeWin::ClassicGetMinimumWidgetSize(nsIFrame* aFrame,
break;
case NS_THEME_SCROLLBARBUTTON_UP:
case NS_THEME_SCROLLBARBUTTON_DOWN:
(*aResult).width = ::GetSystemMetrics(SM_CXVSCROLL);
(*aResult).height = ::GetSystemMetrics(SM_CYVSCROLL);
// Get scrollbar button metrics from the system, except in the case of
// thin scrollbars, where we leave them at 0 (collapsing them to invisible)
if (!IsScrollbarWidthThin(aFrame)) {
(*aResult).width = ::GetSystemMetrics(SM_CXVSCROLL);
(*aResult).height = ::GetSystemMetrics(SM_CYVSCROLL);
}
*aIsOverridable = false;
break;
case NS_THEME_SCROLLBARBUTTON_LEFT:
case NS_THEME_SCROLLBARBUTTON_RIGHT:
(*aResult).width = ::GetSystemMetrics(SM_CXHSCROLL);
(*aResult).height = ::GetSystemMetrics(SM_CYHSCROLL);
// See comment above.
if (!IsScrollbarWidthThin(aFrame)) {
(*aResult).width = ::GetSystemMetrics(SM_CXHSCROLL);
(*aResult).height = ::GetSystemMetrics(SM_CYHSCROLL);
}
*aIsOverridable = false;
break;
case NS_THEME_SCROLLBAR_VERTICAL:
@ -3082,8 +3095,14 @@ nsNativeThemeWin::ClassicGetMinimumWidgetSize(nsIFrame* aFrame,
(*aResult).height = ::GetSystemMetrics(SM_CYVTHUMB);
// Without theming, divide the thumb size by two in order to look more
// native
if (!GetTheme(aWidgetType))
(*aResult).height >>= 1;
if (!GetTheme(aWidgetType)) {
(*aResult).height /= 2;
}
// If scrollbar-width is thin, divide the thickness by three to make
// it more compact.
if (IsScrollbarWidthThin(aFrame)) {
(*aResult).width /= 3;
}
*aIsOverridable = false;
break;
case NS_THEME_SCROLLBARTHUMB_HORIZONTAL:
@ -3091,8 +3110,14 @@ nsNativeThemeWin::ClassicGetMinimumWidgetSize(nsIFrame* aFrame,
(*aResult).height = ::GetSystemMetrics(SM_CYHSCROLL);
// Without theming, divide the thumb size by two in order to look more
// native
if (!GetTheme(aWidgetType))
(*aResult).width >>= 1;
if (!GetTheme(aWidgetType)) {
(*aResult).width /= 2;
}
// If scrollbar-width is thin, divide the thickness by three to make
// it more compact.
if (IsScrollbarWidthThin(aFrame)) {
(*aResult).height /= 3;
}
*aIsOverridable = false;
break;
case NS_THEME_SCROLLBAR_HORIZONTAL: