Bug 1463687 - Apply scrollbar style of root element to scrollbars of viewport. r=heycam

MozReview-Commit-ID: GWmhehtqO1U

--HG--
extra : rebase_source : 76e460a6f57a4caa852ee1ada1c8e213c598bbd1
This commit is contained in:
Xidorn Quan 2018-05-24 16:34:58 +10:00
Родитель 0d7519b550
Коммит f34d64c3c5
4 изменённых файлов: 47 добавлений и 9 удалений

Просмотреть файл

@ -20,6 +20,7 @@
#include "mozilla/Maybe.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/ServoStyleSetInlines.h"
#include "mozilla/StaticPrefs.h"
#include "mozilla/Unused.h"
#include "nsCharTraits.h"
@ -10186,3 +10187,27 @@ nsLayoutUtils::ParseFontLanguageOverride(const nsAString& aLangTag)
}
return result;
}
/* static */ ComputedStyle*
nsLayoutUtils::StyleForScrollbar(nsIFrame* aScrollbarPart)
{
nsIFrame* scrollFrame =
GetClosestFrameOfType(aScrollbarPart, LayoutFrameType::Scroll);
MOZ_ASSERT(scrollFrame, "Scrollbar part frame "
"should have a scroll frame ancestor");
if (scrollFrame->GetParent()->IsViewportFrame()) {
nsPresContext* pc = scrollFrame->PresContext();
if (Element* root = pc->Document()->GetRootElement()) {
if (nsIFrame* frameOfRoot = root->GetPrimaryFrame()) {
return frameOfRoot->Style();
}
// If the root doesn't have primary frame, get the computed style
// from the element. Dropping the strong reference is fine because
// the style should be held strongly by the element.
RefPtr<ComputedStyle> style = pc->StyleSet()->ResolveServoStyle(root);
return style.get();
}
}
return scrollFrame->Style();
}

Просмотреть файл

@ -3111,6 +3111,15 @@ public:
return ResolveToLength<true>(aGap, aPercentageBasis);
}
/**
* Get the computed style for the given scrollbar part frame.
*
* Generally it returns the computed style of the scroll frame which
* contains the given part frame. If the scroll frame is for the
* viewport, the computed style of the document element is returned.
*/
static ComputedStyle* StyleForScrollbar(nsIFrame* aScrollbarPart);
private:
static uint32_t sFontSizeInflationEmPerLine;
static uint32_t sFontSizeInflationMinTwips;

Просмотреть файл

@ -19,6 +19,7 @@
#include "nsIContent.h"
#include "nsIContentInlines.h"
#include "nsIFrame.h"
#include "nsLayoutUtils.h"
#include "nsNameSpaceManager.h"
#include "nsLookAndFeel.h"
#include "nsMenuFrame.h"
@ -1551,10 +1552,12 @@ nsNativeThemeWin::DrawWidgetBackground(gfxContext* aContext,
const nsRect& aRect,
const nsRect& aDirtyRect)
{
if (aFrame->StyleUserInterface()->HasCustomScrollbars() &&
IsWidgetScrollbarPart(aWidgetType)) {
return DrawCustomScrollbarPart(aContext, aFrame, aWidgetType,
aRect, aDirtyRect);
if (IsWidgetScrollbarPart(aWidgetType)) {
ComputedStyle* style = nsLayoutUtils::StyleForScrollbar(aFrame);
if (style->StyleUserInterface()->HasCustomScrollbars()) {
return DrawCustomScrollbarPart(aContext, aFrame, style,
aWidgetType, aRect, aDirtyRect);
}
}
HANDLE theme = GetTheme(aWidgetType);
@ -4263,19 +4266,19 @@ GetScrollbarArrowColor(nscolor aTrackColor)
nsresult
nsNativeThemeWin::DrawCustomScrollbarPart(gfxContext* aContext,
nsIFrame* aFrame,
ComputedStyle* aStyle,
uint8_t aWidgetType,
const nsRect& aRect,
const nsRect& aClipRect)
{
ComputedStyle* style = aFrame->Style();
MOZ_ASSERT(!style->StyleUserInterface()->mScrollbarFaceColor.mIsAuto ||
!style->StyleUserInterface()->mScrollbarTrackColor.mIsAuto);
MOZ_ASSERT(!aStyle->StyleUserInterface()->mScrollbarFaceColor.mIsAuto ||
!aStyle->StyleUserInterface()->mScrollbarTrackColor.mIsAuto);
gfxRect tr(aRect.X(), aRect.Y(), aRect.Width(), aRect.Height()),
dr(aClipRect.X(), aClipRect.Y(),
aClipRect.Width(), aClipRect.Height());
nscolor trackColor = GetScrollbarTrackColor(style);
nscolor trackColor = GetScrollbarTrackColor(aStyle);
HBRUSH dcBrush = (HBRUSH) GetStockObject(DC_BRUSH);
gfxFloat p2a = gfxFloat(aFrame->PresContext()->AppUnitsPerDevPixel());
@ -4311,7 +4314,7 @@ nsNativeThemeWin::DrawCustomScrollbarPart(gfxContext* aContext,
tr2.Deflate(0, dev2css);
}
nativeDrawing.TransformToNativeRect(tr2, widgetRect);
nscolor faceColor = GetScrollbarFaceColor(style);
nscolor faceColor = GetScrollbarFaceColor(aStyle);
::SetDCBrushColor(hdc, ToColorRef(faceColor));
::FillRect(hdc, &widgetRect, dcBrush);
break;

Просмотреть файл

@ -116,6 +116,7 @@ protected:
HBRUSH defaultBack);
nsresult DrawCustomScrollbarPart(gfxContext* aContext,
nsIFrame* aFrame,
mozilla::ComputedStyle* aStyle,
uint8_t aWidgetType,
const nsRect& aRect,
const nsRect& aClipRect);