From ee8b85324b98fbe12627eb29a8a08004d583fcee Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Mon, 20 Aug 2018 01:33:54 +0000 Subject: [PATCH] Bug 1469741 part 1 - Apply scrollbar colors to background of some scrollbar parts when theme doesn't support them. r=mattwoodrow Differential Revision: https://phabricator.services.mozilla.com/D3578 --HG-- extra : moz-landing-system : lando --- layout/painting/nsCSSRendering.cpp | 40 ++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/layout/painting/nsCSSRendering.cpp b/layout/painting/nsCSSRendering.cpp index 4fe6db006fa6..76c358027676 100644 --- a/layout/painting/nsCSSRendering.cpp +++ b/layout/painting/nsCSSRendering.cpp @@ -2530,6 +2530,43 @@ DrawBackgroundColor(nsCSSRendering::ImageLayerClipState& aClipState, aCtx->Restore(); } +static Maybe +CalcScrollbarColor(nsIFrame* aFrame, StyleComplexColor nsStyleUI::* aColor) +{ + ComputedStyle* scrollbarStyle = nsLayoutUtils::StyleForScrollbar(aFrame); + auto color = scrollbarStyle->StyleUI()->*aColor; + if (color.IsAuto()) { + return Nothing(); + } + return Some(color.CalcColor(scrollbarStyle)); +} + +static nscolor +GetBackgroundColor(nsIFrame* aFrame, ComputedStyle* aComputedStyle) +{ + Maybe overrideColor = Nothing(); + switch (aComputedStyle->StyleDisplay()->mAppearance) { + case StyleAppearance::ScrollbarthumbVertical: + case StyleAppearance::ScrollbarthumbHorizontal: + overrideColor = + CalcScrollbarColor(aFrame, &nsStyleUI::mScrollbarFaceColor); + break; + case StyleAppearance::ScrollbarVertical: + case StyleAppearance::ScrollbarHorizontal: + case StyleAppearance::Scrollcorner: + overrideColor = + CalcScrollbarColor(aFrame, &nsStyleUI::mScrollbarTrackColor); + break; + default: + break; + } + if (overrideColor.isSome()) { + return *overrideColor; + } + return aComputedStyle-> + GetVisitedDependentColor(&nsStyleBackground::mBackgroundColor); +} + nscolor nsCSSRendering::DetermineBackgroundColor(nsPresContext* aPresContext, ComputedStyle* aComputedStyle, @@ -2551,8 +2588,7 @@ nsCSSRendering::DetermineBackgroundColor(nsPresContext* aPresContext, const nsStyleBackground *bg = aComputedStyle->StyleBackground(); nscolor bgColor; if (aDrawBackgroundColor) { - bgColor = aComputedStyle-> - GetVisitedDependentColor(&nsStyleBackground::mBackgroundColor); + bgColor = GetBackgroundColor(aFrame, aComputedStyle); if (NS_GET_A(bgColor) == 0) { aDrawBackgroundColor = false; }