зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1578377 - Render dark scrollbars for element with dark background on Windows. r=jmathies
Differential Revision: https://phabricator.services.mozilla.com/D48289 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
af392c3e5b
Коммит
82cc547ab8
|
@ -362,6 +362,8 @@ class RefTest(object):
|
|||
prefs['reftest.logLevel'] = options.log_tbpl_level or 'info'
|
||||
prefs['reftest.suite'] = options.suite
|
||||
prefs['gfx.font_rendering.ahem_antialias_none'] = True
|
||||
# Disable dark scrollbars because it's semi-transparent.
|
||||
prefs['widget.disable-dark-scrollbar'] = True
|
||||
|
||||
# Set tests to run or manifests to parse.
|
||||
if tests:
|
||||
|
|
|
@ -7496,6 +7496,16 @@
|
|||
value: false
|
||||
mirror: always
|
||||
|
||||
# Preference to disable dark scrollbar implementation.
|
||||
# This is mainly for testing because dark scrollbars have to be semi-
|
||||
# transparent, but many reftests expect scrollbars to look identical
|
||||
# among different backgrounds.
|
||||
# However, some users may want to disable this as well.
|
||||
- name: widget.disable-dark-scrollbar
|
||||
type: bool
|
||||
value: false
|
||||
mirror: always
|
||||
|
||||
- name: widget.window-transforms.disabled
|
||||
type: RelaxedAtomicBool
|
||||
value: false
|
||||
|
|
|
@ -40,6 +40,9 @@ user_pref("dom.animations-api.implicit-keyframes.enabled", true);
|
|||
// sometime wpt runs test even before the document becomes visible, which would
|
||||
// delay video.play() and cause play() running in wrong order.
|
||||
user_pref("media.block-autoplay-until-in-foreground", false);
|
||||
// Disable dark scrollbars as it can be semi-transparent that many reftests
|
||||
// don't expect.
|
||||
user_pref("widget.disable-dark-scrollbar", true);
|
||||
user_pref("media.block-autoplay-until-in-foreground", false);
|
||||
// Enable AppCache globally for now whilst it's being removed in Bug 1584984
|
||||
user_pref("browser.cache.offline.storage.enable", true);
|
||||
|
|
|
@ -652,6 +652,7 @@ static nsIFrame* GetBodyFrame(nsIFrame* aCanvasFrame) {
|
|||
return body->GetPrimaryFrame();
|
||||
}
|
||||
|
||||
/* static */
|
||||
bool nsNativeTheme::IsDarkBackground(nsIFrame* aFrame) {
|
||||
nsIScrollableFrame* scrollFrame = nullptr;
|
||||
while (!scrollFrame && aFrame) {
|
||||
|
|
|
@ -185,7 +185,7 @@ class nsNativeTheme : public nsITimerCallback, public nsINamed {
|
|||
bool IsRangeHorizontal(nsIFrame* aFrame);
|
||||
|
||||
// scrollbar
|
||||
bool IsDarkBackground(nsIFrame* aFrame);
|
||||
static bool IsDarkBackground(nsIFrame* aFrame);
|
||||
// custom scrollbar
|
||||
typedef nscolor (*AutoColorGetter)(mozilla::ComputedStyle*);
|
||||
bool IsWidgetScrollbarPart(mozilla::StyleAppearance aAppearance);
|
||||
|
|
|
@ -1514,9 +1514,26 @@ static bool IsScrollbarWidthThin(nsIFrame* aFrame) {
|
|||
return IsScrollbarWidthThin(style);
|
||||
}
|
||||
|
||||
static bool ShouldDrawCustomScrollbar(ComputedStyle* aStyle) {
|
||||
return aStyle->StyleUI()->HasCustomScrollbars() ||
|
||||
IsScrollbarWidthThin(aStyle);
|
||||
// Returns the style for custom scrollbar if the scrollbar part frame should
|
||||
// use the custom drawing path, nullptr otherwise.
|
||||
//
|
||||
// Optionally the caller can pass a pointer to aForDarkBg for whether custom
|
||||
// scrollbar may be drawn due to dark background.
|
||||
static ComputedStyle* GetCustomScrollbarStyle(nsIFrame* aFrame,
|
||||
bool* aDarkScrollbar = nullptr) {
|
||||
ComputedStyle* style = nsLayoutUtils::StyleForScrollbar(aFrame);
|
||||
if (style->StyleUI()->HasCustomScrollbars()) {
|
||||
return style;
|
||||
}
|
||||
bool useDarkScrollbar = !StaticPrefs::widget_disable_dark_scrollbar() &&
|
||||
nsNativeTheme::IsDarkBackground(aFrame);
|
||||
if (useDarkScrollbar || IsScrollbarWidthThin(style)) {
|
||||
if (aDarkScrollbar) {
|
||||
*aDarkScrollbar = useDarkScrollbar;
|
||||
}
|
||||
return style;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -1530,10 +1547,9 @@ nsNativeThemeWin::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
|
|||
}
|
||||
|
||||
if (IsWidgetScrollbarPart(aAppearance)) {
|
||||
ComputedStyle* style = nsLayoutUtils::StyleForScrollbar(aFrame);
|
||||
if (ShouldDrawCustomScrollbar(style)) {
|
||||
return DrawCustomScrollbarPart(aContext, aFrame, style, aAppearance,
|
||||
aRect, aDirtyRect);
|
||||
if (MayDrawCustomScrollbarPart(aContext, aFrame, aAppearance, aRect,
|
||||
aDirtyRect)) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2659,8 +2675,7 @@ nsITheme::ThemeGeometryType nsNativeThemeWin::ThemeGeometryTypeForWidget(
|
|||
nsITheme::Transparency nsNativeThemeWin::GetWidgetTransparency(
|
||||
nsIFrame* aFrame, StyleAppearance aAppearance) {
|
||||
if (IsWidgetScrollbarPart(aAppearance)) {
|
||||
ComputedStyle* style = nsLayoutUtils::StyleForScrollbar(aFrame);
|
||||
if (ShouldDrawCustomScrollbar(style)) {
|
||||
if (ComputedStyle* style = GetCustomScrollbarStyle(aFrame)) {
|
||||
auto* ui = style->StyleUI();
|
||||
if (ui->mScrollbarColor.IsAuto() ||
|
||||
ui->mScrollbarColor.AsColors().track.MaybeTransparent()) {
|
||||
|
@ -4158,9 +4173,17 @@ static nscolor AdjustScrollbarFaceColor(nscolor aFaceColor,
|
|||
}
|
||||
|
||||
// This tries to draw a Windows 10 style scrollbar with given colors.
|
||||
nsresult nsNativeThemeWin::DrawCustomScrollbarPart(
|
||||
gfxContext* aContext, nsIFrame* aFrame, ComputedStyle* aStyle,
|
||||
StyleAppearance aAppearance, const nsRect& aRect, const nsRect& aClipRect) {
|
||||
bool nsNativeThemeWin::MayDrawCustomScrollbarPart(gfxContext* aContext,
|
||||
nsIFrame* aFrame,
|
||||
StyleAppearance aAppearance,
|
||||
const nsRect& aRect,
|
||||
const nsRect& aClipRect) {
|
||||
bool darkScrollbar = false;
|
||||
ComputedStyle* style = GetCustomScrollbarStyle(aFrame, &darkScrollbar);
|
||||
if (!style) {
|
||||
return false;
|
||||
}
|
||||
|
||||
EventStates eventStates = GetContentState(aFrame, aAppearance);
|
||||
|
||||
gfxContextAutoSaveRestore autoSave(aContext);
|
||||
|
@ -4172,11 +4195,12 @@ nsresult nsNativeThemeWin::DrawCustomScrollbarPart(
|
|||
gfxRect rect =
|
||||
ThebesRect(LayoutDevicePixel::FromAppUnits(aRect, p2a).ToUnknownRect());
|
||||
|
||||
const nsStyleUI* ui = aStyle->StyleUI();
|
||||
const nsStyleUI* ui = style->StyleUI();
|
||||
auto* customColors =
|
||||
ui->mScrollbarColor.IsAuto() ? nullptr : &ui->mScrollbarColor.AsColors();
|
||||
nscolor trackColor = customColors ? customColors->track.CalcColor(*aStyle)
|
||||
: NS_RGB(240, 240, 240);
|
||||
nscolor trackColor = customColors ? customColors->track.CalcColor(*style)
|
||||
: (darkScrollbar ? NS_RGBA(20, 20, 25, 77)
|
||||
: NS_RGB(240, 240, 240));
|
||||
switch (aAppearance) {
|
||||
case StyleAppearance::ScrollbarHorizontal:
|
||||
case StyleAppearance::ScrollbarVertical:
|
||||
|
@ -4184,7 +4208,7 @@ nsresult nsNativeThemeWin::DrawCustomScrollbarPart(
|
|||
ctx->SetColor(Color::FromABGR(trackColor));
|
||||
ctx->Rectangle(rect);
|
||||
ctx->Fill();
|
||||
return NS_OK;
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
|
@ -4211,8 +4235,10 @@ nsresult nsNativeThemeWin::DrawCustomScrollbarPart(
|
|||
switch (aAppearance) {
|
||||
case StyleAppearance::ScrollbarthumbVertical:
|
||||
case StyleAppearance::ScrollbarthumbHorizontal: {
|
||||
nscolor faceColor = customColors ? customColors->thumb.CalcColor(*aStyle)
|
||||
: NS_RGB(205, 205, 205);
|
||||
nscolor faceColor = customColors
|
||||
? customColors->thumb.CalcColor(*style)
|
||||
: (darkScrollbar ? NS_RGBA(249, 249, 250, 102)
|
||||
: NS_RGB(205, 205, 205));
|
||||
faceColor = AdjustScrollbarFaceColor(faceColor, eventStates);
|
||||
ctx->SetColor(Color::FromABGR(faceColor));
|
||||
ctx->Rectangle(bgRect);
|
||||
|
@ -4276,7 +4302,7 @@ nsresult nsNativeThemeWin::DrawCustomScrollbarPart(
|
|||
default:
|
||||
MOZ_ASSERT_UNREACHABLE("Unknown widget type");
|
||||
}
|
||||
return NS_OK;
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////
|
||||
|
|
|
@ -105,11 +105,9 @@ class nsNativeThemeWin : private nsNativeTheme, public nsITheme {
|
|||
StyleAppearance aAppearance);
|
||||
void DrawCheckedRect(HDC hdc, const RECT& rc, int32_t fore, int32_t back,
|
||||
HBRUSH defaultBack);
|
||||
nsresult DrawCustomScrollbarPart(gfxContext* aContext, nsIFrame* aFrame,
|
||||
mozilla::ComputedStyle* aStyle,
|
||||
bool MayDrawCustomScrollbarPart(gfxContext* aContext, nsIFrame* aFrame,
|
||||
StyleAppearance aAppearance,
|
||||
const nsRect& aRect,
|
||||
const nsRect& aClipRect);
|
||||
const nsRect& aRect, const nsRect& aClipRect);
|
||||
uint32_t GetWidgetNativeDrawingFlags(StyleAppearance aAppearance);
|
||||
int32_t StandardGetState(nsIFrame* aFrame, StyleAppearance aAppearance,
|
||||
bool wantFocused);
|
||||
|
|
Загрузка…
Ссылка в новой задаче