зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1541546 - Use the rust color representation. r=heycam
Differential Revision: https://phabricator.services.mozilla.com/D25976
This commit is contained in:
Родитель
06e8936b5d
Коммит
3a1e1a41c4
|
@ -27,6 +27,11 @@
|
|||
# undef Always
|
||||
#endif
|
||||
|
||||
// And Complex...
|
||||
#ifdef Complex
|
||||
# undef Complex
|
||||
#endif
|
||||
|
||||
// X11/Xlib.h also defines True and False, get rid of those too for
|
||||
// the same reasons as above...
|
||||
#ifdef True
|
||||
|
|
|
@ -806,7 +806,7 @@ static nsCSSBorderRenderer ConstructBorderRenderer(
|
|||
// pull out styles, colors
|
||||
NS_FOR_CSS_SIDES(i) {
|
||||
borderStyles[i] = aStyleBorder.GetBorderStyle(i);
|
||||
borderColors[i] = aStyleBorder.BorderColorFor(i).CalcColor(aComputedStyle);
|
||||
borderColors[i] = aStyleBorder.BorderColorFor(i).CalcColor(*aComputedStyle);
|
||||
}
|
||||
|
||||
PrintAsFormatString(
|
||||
|
@ -2290,37 +2290,47 @@ static void DrawBackgroundColor(nsCSSRendering::ImageLayerClipState& aClipState,
|
|||
aCtx->Restore();
|
||||
}
|
||||
|
||||
enum class ScrollbarColorKind {
|
||||
Thumb,
|
||||
Track,
|
||||
};
|
||||
|
||||
static Maybe<nscolor> CalcScrollbarColor(nsIFrame* aFrame,
|
||||
StyleComplexColor nsStyleUI::*aColor) {
|
||||
ScrollbarColorKind aKind) {
|
||||
ComputedStyle* scrollbarStyle = nsLayoutUtils::StyleForScrollbar(aFrame);
|
||||
auto color = scrollbarStyle->StyleUI()->*aColor;
|
||||
if (color.IsAuto()) {
|
||||
const auto& colors = scrollbarStyle->StyleUI()->mScrollbarColor;
|
||||
if (colors.IsAuto()) {
|
||||
return Nothing();
|
||||
}
|
||||
return Some(color.CalcColor(scrollbarStyle));
|
||||
const auto& color = aKind == ScrollbarColorKind::Thumb
|
||||
? colors.AsColors().thumb
|
||||
: colors.AsColors().track;
|
||||
return Some(color.CalcColor(*scrollbarStyle));
|
||||
}
|
||||
|
||||
static nscolor GetBackgroundColor(nsIFrame* aFrame,
|
||||
ComputedStyle* aComputedStyle) {
|
||||
Maybe<nscolor> overrideColor = Nothing();
|
||||
switch (aComputedStyle->StyleDisplay()->mAppearance) {
|
||||
case StyleAppearance::ScrollbarthumbVertical:
|
||||
case StyleAppearance::ScrollbarthumbHorizontal:
|
||||
overrideColor =
|
||||
CalcScrollbarColor(aFrame, &nsStyleUI::mScrollbarFaceColor);
|
||||
case StyleAppearance::ScrollbarthumbHorizontal: {
|
||||
if (Maybe<nscolor> overrideColor =
|
||||
CalcScrollbarColor(aFrame, ScrollbarColorKind::Thumb)) {
|
||||
return *overrideColor;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case StyleAppearance::ScrollbarVertical:
|
||||
case StyleAppearance::ScrollbarHorizontal:
|
||||
case StyleAppearance::Scrollcorner:
|
||||
overrideColor =
|
||||
CalcScrollbarColor(aFrame, &nsStyleUI::mScrollbarTrackColor);
|
||||
case StyleAppearance::Scrollcorner: {
|
||||
if (Maybe<nscolor> overrideColor =
|
||||
CalcScrollbarColor(aFrame, ScrollbarColorKind::Track)) {
|
||||
return *overrideColor;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (overrideColor.isSome()) {
|
||||
return *overrideColor;
|
||||
}
|
||||
return aComputedStyle->GetVisitedDependentColor(
|
||||
&nsStyleBackground::mBackgroundColor);
|
||||
}
|
||||
|
|
|
@ -581,7 +581,7 @@ static nsTArray<ColorStop> ComputeColorStops(ComputedStyle* aComputedStyle,
|
|||
if (firstUnsetPosition < 0) {
|
||||
firstUnsetPosition = i;
|
||||
}
|
||||
auto stopColor = stop.mColor.CalcColor(aComputedStyle);
|
||||
auto stopColor = stop.mColor.CalcColor(*aComputedStyle);
|
||||
stops.AppendElement(
|
||||
ColorStop(0, stop.mIsInterpolationHint, Color::FromABGR(stopColor)));
|
||||
continue;
|
||||
|
@ -595,7 +595,7 @@ static nsTArray<ColorStop> ComputeColorStops(ComputedStyle* aComputedStyle,
|
|||
: stops[i - 1].mPosition;
|
||||
position = std::max(position, previousPosition);
|
||||
}
|
||||
auto stopColor = stop.mColor.CalcColor(aComputedStyle);
|
||||
auto stopColor = stop.mColor.CalcColor(*aComputedStyle);
|
||||
stops.AppendElement(ColorStop(position, stop.mIsInterpolationHint,
|
||||
Color::FromABGR(stopColor)));
|
||||
if (firstUnsetPosition > 0) {
|
||||
|
|
|
@ -277,19 +277,30 @@ static nscolor GetVisitedDependentColorInternal(ComputedStyle* aSc,
|
|||
return colors[0];
|
||||
}
|
||||
|
||||
static nscolor ExtractColor(ComputedStyle* aStyle, const nscolor& aColor) {
|
||||
static nscolor ExtractColor(const ComputedStyle& aStyle,
|
||||
const nscolor& aColor) {
|
||||
return aColor;
|
||||
}
|
||||
|
||||
static nscolor ExtractColor(ComputedStyle* aStyle,
|
||||
static nscolor ExtractColor(const ComputedStyle& aStyle,
|
||||
const StyleComplexColor& aColor) {
|
||||
return aColor.CalcColor(aStyle);
|
||||
}
|
||||
|
||||
static nscolor ExtractColor(ComputedStyle* aStyle,
|
||||
// Currently caret-color, the only property in the list which is a ColorOrAuto,
|
||||
// always maps auto to currentcolor.
|
||||
static nscolor ExtractColor(const ComputedStyle& aStyle,
|
||||
const StyleColorOrAuto& aColor) {
|
||||
if (aColor.IsAuto()) {
|
||||
return ExtractColor(aStyle, StyleColor::CurrentColor());
|
||||
}
|
||||
return ExtractColor(aStyle, aColor.AsColor());
|
||||
}
|
||||
|
||||
static nscolor ExtractColor(ComputedStyle& aStyle,
|
||||
const nsStyleSVGPaint& aPaintServer) {
|
||||
return aPaintServer.Type() == eStyleSVGPaintType_Color
|
||||
? aPaintServer.GetColor(aStyle)
|
||||
? aPaintServer.GetColor(&aStyle)
|
||||
: NS_RGBA(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
|
@ -303,7 +314,7 @@ static nscolor ExtractColor(ComputedStyle* aStyle,
|
|||
" which is not listed in nsCSSVisitedDependentPropList.h"); \
|
||||
return GetVisitedDependentColorInternal( \
|
||||
this, [aField](ComputedStyle* sc) { \
|
||||
return ExtractColor(sc, sc->Style##name_()->*aField); \
|
||||
return ExtractColor(*sc, sc->Style##name_()->*aField); \
|
||||
}); \
|
||||
}
|
||||
#include "nsCSSVisitedDependentPropList.h"
|
||||
|
|
|
@ -95,7 +95,6 @@ rusty-enums = [
|
|||
"mozilla::StyleClear",
|
||||
"mozilla::StyleColumnFill",
|
||||
"mozilla::StyleColumnSpan",
|
||||
"mozilla::StyleComplexColor_Tag",
|
||||
"mozilla::StyleFloat",
|
||||
"mozilla::StyleImageOrientation",
|
||||
"mozilla::StyleUserModify",
|
||||
|
@ -459,6 +458,10 @@ cbindgen-types = [
|
|||
{ gecko = "StyleStrong", servo = "gecko_bindings::sugar::ownership::Strong" },
|
||||
{ gecko = "StyleGenericFontFamily", servo = "values::computed::font::GenericFontFamily" },
|
||||
{ gecko = "StyleFontFamilyNameSyntax", servo = "values::computed::font::FontFamilyNameSyntax" },
|
||||
{ gecko = "StyleGenericColor", servo = "values::generics::color::Color" },
|
||||
{ gecko = "StyleGenericColorOrAuto", servo = "values::generics::color::ColorOrAuto" },
|
||||
{ gecko = "StyleGenericScrollbarColor", servo = "values::generics::ui::ScrollbarColor" },
|
||||
{ gecko = "StyleRGBA", servo = "cssparser::RGBA" },
|
||||
]
|
||||
|
||||
mapped-generic-types = [
|
||||
|
|
|
@ -30,6 +30,7 @@ struct RawServoAnimationValueTable;
|
|||
struct RawServoAnimationValueMap;
|
||||
|
||||
class nsAtom;
|
||||
class nsIFrame;
|
||||
class nsINode;
|
||||
class nsCSSPropertyIDSet;
|
||||
class nsPresContext;
|
||||
|
@ -58,6 +59,8 @@ class nsMainThreadPtrHolder;
|
|||
|
||||
namespace mozilla {
|
||||
|
||||
class ComputedStyle;
|
||||
|
||||
using Matrix4x4Components = float[16];
|
||||
using StyleMatrix4x4Components = Matrix4x4Components;
|
||||
|
||||
|
|
|
@ -46,42 +46,47 @@ static nscolor LinearBlendColors(nscolor aBg, float aBgRatio, nscolor aFg,
|
|||
return NS_RGBA(r, g, b, NSToIntRound(a * 255));
|
||||
}
|
||||
|
||||
template<>
|
||||
bool StyleComplexColor::MaybeTransparent() const {
|
||||
// We know that the color is opaque when it's a numeric color with
|
||||
// alpha == 255.
|
||||
// TODO(djg): Should we extend this to check Complex with bgRatio =
|
||||
// 0, and fgRatio * alpha >= 255?
|
||||
return mTag != eNumeric || NS_GET_A(mColor) != 255;
|
||||
return !IsNumeric() || AsNumeric().alpha != 255;
|
||||
}
|
||||
|
||||
static nscolor RGBAToNSColor(const StyleRGBA& aRGBA) {
|
||||
return NS_RGBA(aRGBA.red, aRGBA.green, aRGBA.blue, aRGBA.alpha);
|
||||
}
|
||||
|
||||
template<>
|
||||
nscolor StyleComplexColor::CalcColor(nscolor aForegroundColor) const {
|
||||
switch (mTag) {
|
||||
case eNumeric:
|
||||
return mColor;
|
||||
case eForeground:
|
||||
case eAuto:
|
||||
return aForegroundColor;
|
||||
case eComplex:
|
||||
return LinearBlendColors(mColor, mBgRatio, aForegroundColor, mFgRatio);
|
||||
default:
|
||||
MOZ_ASSERT_UNREACHABLE("StyleComplexColor has invalid mTag");
|
||||
return mColor;
|
||||
if (IsNumeric()) {
|
||||
return RGBAToNSColor(AsNumeric());
|
||||
}
|
||||
if (IsCurrentColor()) {
|
||||
return aForegroundColor;
|
||||
}
|
||||
MOZ_ASSERT(IsComplex());
|
||||
const auto& complex = AsComplex();
|
||||
return LinearBlendColors(RGBAToNSColor(complex.color), complex.ratios.bg,
|
||||
aForegroundColor, complex.ratios.fg);
|
||||
}
|
||||
|
||||
nscolor StyleComplexColor::CalcColor(mozilla::ComputedStyle* aStyle) const {
|
||||
template<>
|
||||
nscolor StyleComplexColor::CalcColor(const ComputedStyle& aStyle) const {
|
||||
// Common case that is numeric color, which is pure background, we
|
||||
// can skip resolving StyleColor().
|
||||
// TODO(djg): Is this optimization worth it?
|
||||
if (mTag == eNumeric) {
|
||||
return mColor;
|
||||
if (IsNumeric()) {
|
||||
return RGBAToNSColor(AsNumeric());
|
||||
}
|
||||
|
||||
MOZ_ASSERT(aStyle);
|
||||
auto fgColor = aStyle->StyleColor()->mColor;
|
||||
auto fgColor = aStyle.StyleColor()->mColor;
|
||||
return CalcColor(fgColor);
|
||||
}
|
||||
|
||||
template<>
|
||||
nscolor StyleComplexColor::CalcColor(const nsIFrame* aFrame) const {
|
||||
return CalcColor(aFrame->Style());
|
||||
return CalcColor(*aFrame->Style());
|
||||
}
|
||||
|
|
|
@ -10,124 +10,41 @@
|
|||
#define mozilla_StyleComplexColor_h_
|
||||
|
||||
#include "nsColor.h"
|
||||
|
||||
class nsIFrame;
|
||||
#include "mozilla/ServoStyleConsts.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class ComputedStyle;
|
||||
using StyleComplexColor = StyleColor;
|
||||
|
||||
/**
|
||||
* This struct represents a combined color from a numeric color and
|
||||
* the current foreground color (currentcolor keyword).
|
||||
* Conceptually, the formula is "color * q + currentcolor * p"
|
||||
* where p is mFgRatio and q is mBgRatio.
|
||||
*
|
||||
* It can also represent an "auto" value, which is valid for some
|
||||
* properties. See comment of `Tag::eAuto`.
|
||||
*/
|
||||
class StyleComplexColor final {
|
||||
public:
|
||||
static StyleComplexColor FromColor(nscolor aColor) {
|
||||
return {aColor, 0, eNumeric};
|
||||
}
|
||||
static StyleComplexColor CurrentColor() {
|
||||
return {NS_RGBA(0, 0, 0, 0), 1, eForeground};
|
||||
}
|
||||
static StyleComplexColor Auto() { return {NS_RGBA(0, 0, 0, 0), 1, eAuto}; }
|
||||
template<>
|
||||
inline StyleColor StyleColor::FromColor(nscolor aColor) {
|
||||
return StyleColor::Numeric({NS_GET_R(aColor), NS_GET_G(aColor),
|
||||
NS_GET_B(aColor), NS_GET_A(aColor)});
|
||||
}
|
||||
|
||||
static StyleComplexColor Black() {
|
||||
return StyleComplexColor::FromColor(NS_RGB(0, 0, 0));
|
||||
}
|
||||
static StyleComplexColor White() {
|
||||
return StyleComplexColor::FromColor(NS_RGB(255, 255, 255));
|
||||
}
|
||||
static StyleComplexColor Transparent() {
|
||||
return StyleComplexColor::FromColor(NS_RGBA(0, 0, 0, 0));
|
||||
}
|
||||
template<>
|
||||
inline StyleColor StyleColor::Black() {
|
||||
return FromColor(NS_RGB(0, 0, 0));
|
||||
}
|
||||
|
||||
bool IsAuto() const { return mTag == eAuto; }
|
||||
bool IsCurrentColor() const { return mTag == eForeground; }
|
||||
template<>
|
||||
inline StyleColor StyleColor::White() {
|
||||
return FromColor(NS_RGB(255, 255, 255));
|
||||
}
|
||||
|
||||
bool operator==(const StyleComplexColor& aOther) const {
|
||||
if (mTag != aOther.mTag) {
|
||||
return false;
|
||||
}
|
||||
template<>
|
||||
inline StyleColor StyleColor::Transparent() {
|
||||
return FromColor(NS_RGBA(0, 0, 0, 0));
|
||||
}
|
||||
|
||||
switch (mTag) {
|
||||
case eAuto:
|
||||
case eForeground:
|
||||
return true;
|
||||
case eNumeric:
|
||||
return mColor == aOther.mColor;
|
||||
case eComplex:
|
||||
return (mBgRatio == aOther.mBgRatio && mFgRatio == aOther.mFgRatio &&
|
||||
mColor == aOther.mColor);
|
||||
default:
|
||||
MOZ_ASSERT_UNREACHABLE("Unexpected StyleComplexColor type.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
template<>
|
||||
nscolor StyleComplexColor::CalcColor(nscolor aForegroundColor) const;
|
||||
|
||||
bool operator!=(const StyleComplexColor& aOther) const {
|
||||
return !(*this == aOther);
|
||||
}
|
||||
template<>
|
||||
nscolor StyleComplexColor::CalcColor(const ComputedStyle&) const;
|
||||
|
||||
/**
|
||||
* Is it possible that this StyleComplexColor is transparent?
|
||||
*/
|
||||
bool MaybeTransparent() const;
|
||||
|
||||
/**
|
||||
* Compute the color for this StyleComplexColor, taking into account
|
||||
* the foreground color, aForegroundColor.
|
||||
*/
|
||||
nscolor CalcColor(nscolor aForegroundColor) const;
|
||||
|
||||
/**
|
||||
* Compute the color for this StyleComplexColor, taking into account
|
||||
* the foreground color from aStyle.
|
||||
*/
|
||||
nscolor CalcColor(mozilla::ComputedStyle* aStyle) const;
|
||||
|
||||
/**
|
||||
* Compute the color for this StyleComplexColor, taking into account
|
||||
* the foreground color from aFrame's ComputedStyle.
|
||||
*/
|
||||
nscolor CalcColor(const nsIFrame* aFrame) const;
|
||||
|
||||
private:
|
||||
enum Tag : uint8_t {
|
||||
// This represents a computed-value time auto value. This
|
||||
// indicates that this value should not be interpolatable with
|
||||
// other colors. Other fields represent a currentcolor and
|
||||
// properties can decide whether that should be used.
|
||||
eAuto,
|
||||
// This represents a numeric color; no currentcolor component.
|
||||
eNumeric,
|
||||
// This represents the current foreground color, currentcolor; no
|
||||
// numeric color component.
|
||||
eForeground,
|
||||
// This represents a linear combination of numeric color and the
|
||||
// foreground color: "mColor * mBgRatio + currentcolor *
|
||||
// mFgRatio".
|
||||
eComplex,
|
||||
};
|
||||
|
||||
StyleComplexColor(nscolor aColor, float aFgRatio, Tag aTag)
|
||||
: mColor(aColor),
|
||||
mBgRatio(1.f - aFgRatio),
|
||||
mFgRatio(aFgRatio),
|
||||
mTag(aTag) {
|
||||
MOZ_ASSERT(mTag != eNumeric || aFgRatio == 0.);
|
||||
MOZ_ASSERT(!(mTag == eAuto || mTag == eForeground) || aFgRatio == 1.);
|
||||
}
|
||||
|
||||
nscolor mColor;
|
||||
float mBgRatio;
|
||||
float mFgRatio;
|
||||
Tag mTag;
|
||||
};
|
||||
template<>
|
||||
nscolor StyleComplexColor::CalcColor(const nsIFrame*) const;
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
|
|
|
@ -1042,7 +1042,7 @@ void nsComputedDOMStyle::SetToRGBAColor(nsROCSSPrimitiveValue* aValue,
|
|||
|
||||
void nsComputedDOMStyle::SetValueFromComplexColor(
|
||||
nsROCSSPrimitiveValue* aValue, const StyleComplexColor& aColor) {
|
||||
SetToRGBAColor(aValue, aColor.CalcColor(mComputedStyle));
|
||||
SetToRGBAColor(aValue, aColor.CalcColor(*mComputedStyle));
|
||||
}
|
||||
|
||||
already_AddRefed<CSSValue> nsComputedDOMStyle::DoGetColor() {
|
||||
|
@ -1858,11 +1858,7 @@ already_AddRefed<CSSValue> nsComputedDOMStyle::DoGetScrollSnapPointsY() {
|
|||
|
||||
already_AddRefed<CSSValue> nsComputedDOMStyle::DoGetScrollbarColor() {
|
||||
const nsStyleUI* ui = StyleUI();
|
||||
MOZ_ASSERT(
|
||||
ui->mScrollbarFaceColor.IsAuto() == ui->mScrollbarTrackColor.IsAuto(),
|
||||
"Whether the two colors are auto should be identical");
|
||||
|
||||
if (ui->mScrollbarFaceColor.IsAuto()) {
|
||||
if (ui->mScrollbarColor.IsAuto()) {
|
||||
RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
|
||||
val->SetIdent(eCSSKeyword_auto);
|
||||
return val.forget();
|
||||
|
@ -1874,8 +1870,9 @@ already_AddRefed<CSSValue> nsComputedDOMStyle::DoGetScrollbarColor() {
|
|||
SetValueFromComplexColor(val, color);
|
||||
list->AppendCSSValue(val.forget());
|
||||
};
|
||||
put(ui->mScrollbarFaceColor);
|
||||
put(ui->mScrollbarTrackColor);
|
||||
auto& colors = ui->mScrollbarColor.AsColors();
|
||||
put(colors.thumb);
|
||||
put(colors.track);
|
||||
return list.forget();
|
||||
}
|
||||
|
||||
|
@ -2153,7 +2150,11 @@ static_assert(NS_STYLE_UNICODE_BIDI_NORMAL == 0,
|
|||
|
||||
already_AddRefed<CSSValue> nsComputedDOMStyle::DoGetCaretColor() {
|
||||
RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
|
||||
SetValueFromComplexColor(val, StyleUI()->mCaretColor);
|
||||
if (StyleUI()->mCaretColor.IsAuto()) {
|
||||
SetToRGBAColor(val, StyleColor()->mColor);
|
||||
} else {
|
||||
SetValueFromComplexColor(val, StyleUI()->mCaretColor.AsColor());
|
||||
}
|
||||
return val.forget();
|
||||
}
|
||||
|
||||
|
|
|
@ -2846,9 +2846,8 @@ nscolor nsStyleBackground::BackgroundColor(const nsIFrame* aFrame) const {
|
|||
return mBackgroundColor.CalcColor(aFrame);
|
||||
}
|
||||
|
||||
nscolor nsStyleBackground::BackgroundColor(
|
||||
mozilla::ComputedStyle* aStyle) const {
|
||||
return mBackgroundColor.CalcColor(aStyle);
|
||||
nscolor nsStyleBackground::BackgroundColor(ComputedStyle* aStyle) const {
|
||||
return mBackgroundColor.CalcColor(*aStyle);
|
||||
}
|
||||
|
||||
bool nsStyleBackground::IsTransparent(const nsIFrame* aFrame) const {
|
||||
|
@ -3918,9 +3917,8 @@ nsStyleUI::nsStyleUI(const Document& aDocument)
|
|||
mUserFocus(StyleUserFocus::None),
|
||||
mPointerEvents(NS_STYLE_POINTER_EVENTS_AUTO),
|
||||
mCursor(StyleCursorKind::Auto),
|
||||
mCaretColor(StyleComplexColor::Auto()),
|
||||
mScrollbarFaceColor(StyleComplexColor::Auto()),
|
||||
mScrollbarTrackColor(StyleComplexColor::Auto()) {
|
||||
mCaretColor(StyleColorOrAuto::Auto()),
|
||||
mScrollbarColor(StyleScrollbarColor::Auto()) {
|
||||
MOZ_COUNT_CTOR(nsStyleUI);
|
||||
}
|
||||
|
||||
|
@ -3932,8 +3930,7 @@ nsStyleUI::nsStyleUI(const nsStyleUI& aSource)
|
|||
mCursor(aSource.mCursor),
|
||||
mCursorImages(aSource.mCursorImages),
|
||||
mCaretColor(aSource.mCaretColor),
|
||||
mScrollbarFaceColor(aSource.mScrollbarFaceColor),
|
||||
mScrollbarTrackColor(aSource.mScrollbarTrackColor) {
|
||||
mScrollbarColor(aSource.mScrollbarColor) {
|
||||
MOZ_COUNT_CTOR(nsStyleUI);
|
||||
}
|
||||
|
||||
|
@ -3995,8 +3992,7 @@ nsChangeHint nsStyleUI::CalcDifference(const nsStyleUI& aNewData) const {
|
|||
}
|
||||
|
||||
if (mCaretColor != aNewData.mCaretColor ||
|
||||
mScrollbarFaceColor != aNewData.mScrollbarFaceColor ||
|
||||
mScrollbarTrackColor != aNewData.mScrollbarTrackColor) {
|
||||
mScrollbarColor != aNewData.mScrollbarColor) {
|
||||
hint |= nsChangeHint_RepaintFrame;
|
||||
}
|
||||
|
||||
|
|
|
@ -2564,16 +2564,13 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleUI {
|
|||
|
||||
mozilla::StyleCursorKind mCursor;
|
||||
nsTArray<nsCursorImage> mCursorImages; // images and coords
|
||||
mozilla::StyleComplexColor mCaretColor;
|
||||
|
||||
mozilla::StyleComplexColor mScrollbarFaceColor;
|
||||
mozilla::StyleComplexColor mScrollbarTrackColor;
|
||||
mozilla::StyleColorOrAuto mCaretColor;
|
||||
mozilla::StyleScrollbarColor mScrollbarColor;
|
||||
|
||||
inline uint8_t GetEffectivePointerEvents(nsIFrame* aFrame) const;
|
||||
|
||||
bool HasCustomScrollbars() const {
|
||||
return !mScrollbarFaceColor.IsAuto() || !mScrollbarTrackColor.IsAuto();
|
||||
}
|
||||
bool HasCustomScrollbars() const { return !mScrollbarColor.IsAuto(); }
|
||||
};
|
||||
|
||||
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleXUL {
|
||||
|
@ -2685,7 +2682,7 @@ class nsStyleSVGPaint {
|
|||
|
||||
nscolor GetColor(mozilla::ComputedStyle* aComputedStyle) const {
|
||||
MOZ_ASSERT(mType == eStyleSVGPaintType_Color);
|
||||
return mPaint.mColor.CalcColor(aComputedStyle);
|
||||
return mPaint.mColor.CalcColor(*aComputedStyle);
|
||||
}
|
||||
|
||||
mozilla::css::URLValue* GetPaintServer() const {
|
||||
|
@ -2699,7 +2696,7 @@ class nsStyleSVGPaint {
|
|||
MOZ_ASSERT(mType == eStyleSVGPaintType_Server ||
|
||||
mType == eStyleSVGPaintType_ContextFill ||
|
||||
mType == eStyleSVGPaintType_ContextStroke);
|
||||
return mFallbackColor.CalcColor(aComputedStyle);
|
||||
return mFallbackColor.CalcColor(*aComputedStyle);
|
||||
}
|
||||
|
||||
bool operator==(const nsStyleSVGPaint& aOther) const;
|
||||
|
|
|
@ -393,7 +393,7 @@ void nsTextBoxFrame::DrawText(gfxContext& aRenderingContext,
|
|||
if (aOverrideColor) {
|
||||
color = *aOverrideColor;
|
||||
} else {
|
||||
color = styleText->mTextDecorationColor.CalcColor(context);
|
||||
color = styleText->mTextDecorationColor.CalcColor(*context);
|
||||
}
|
||||
uint8_t style = styleText->mTextDecorationStyle;
|
||||
|
||||
|
|
|
@ -2997,7 +2997,7 @@ ImgDrawResult nsTreeBodyFrame::PaintCell(
|
|||
|
||||
const nsStyleBorder* borderStyle = lineContext->StyleBorder();
|
||||
// Resolve currentcolor values against the treeline context
|
||||
nscolor color = borderStyle->mBorderLeftColor.CalcColor(lineContext);
|
||||
nscolor color = borderStyle->mBorderLeftColor.CalcColor(*lineContext);
|
||||
ColorPattern colorPatt(ToDeviceColor(color));
|
||||
|
||||
StyleBorderStyle style = borderStyle->GetBorderStyle(eSideLeft);
|
||||
|
|
|
@ -15,4 +15,3 @@ mod ns_t_array;
|
|||
pub mod origin_flags;
|
||||
pub mod ownership;
|
||||
pub mod refptr;
|
||||
mod style_complex_color;
|
||||
|
|
|
@ -1,111 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
//! Rust helpers to interact with Gecko's StyleComplexColor.
|
||||
|
||||
use crate::gecko::values::{convert_nscolor_to_rgba, convert_rgba_to_nscolor};
|
||||
use crate::gecko_bindings::structs::StyleComplexColor;
|
||||
use crate::gecko_bindings::structs::StyleComplexColor_Tag as Tag;
|
||||
use crate::values::computed::{Color as ComputedColor, ColorOrAuto, RGBAColor as ComputedRGBA};
|
||||
use crate::values::generics::color::{
|
||||
Color as GenericColor, ColorOrAuto as GenericColorOrAuto, ComplexColorRatios,
|
||||
};
|
||||
|
||||
impl StyleComplexColor {
|
||||
/// Create a `StyleComplexColor` value that represents `currentColor`.
|
||||
pub fn current_color() -> Self {
|
||||
StyleComplexColor {
|
||||
mColor: 0,
|
||||
mBgRatio: 0.,
|
||||
mFgRatio: 1.,
|
||||
mTag: Tag::eForeground,
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a `StyleComplexColor` value that represents `auto`.
|
||||
pub fn auto() -> Self {
|
||||
StyleComplexColor {
|
||||
mColor: 0,
|
||||
mBgRatio: 0.,
|
||||
mFgRatio: 1.,
|
||||
mTag: Tag::eAuto,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ComputedRGBA> for StyleComplexColor {
|
||||
fn from(other: ComputedRGBA) -> Self {
|
||||
StyleComplexColor {
|
||||
mColor: convert_rgba_to_nscolor(&other),
|
||||
mBgRatio: 1.,
|
||||
mFgRatio: 0.,
|
||||
mTag: Tag::eNumeric,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ComputedColor> for StyleComplexColor {
|
||||
fn from(other: ComputedColor) -> Self {
|
||||
match other {
|
||||
GenericColor::Numeric(color) => color.into(),
|
||||
GenericColor::CurrentColor => Self::current_color(),
|
||||
GenericColor::Complex { color, ratios } => {
|
||||
debug_assert!(ratios != ComplexColorRatios::NUMERIC);
|
||||
debug_assert!(ratios != ComplexColorRatios::FOREGROUND);
|
||||
StyleComplexColor {
|
||||
mColor: convert_rgba_to_nscolor(&color).into(),
|
||||
mBgRatio: ratios.bg,
|
||||
mFgRatio: ratios.fg,
|
||||
mTag: Tag::eComplex,
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<StyleComplexColor> for ComputedColor {
|
||||
fn from(other: StyleComplexColor) -> Self {
|
||||
match other.mTag {
|
||||
Tag::eNumeric => {
|
||||
debug_assert!(other.mBgRatio == 1. && other.mFgRatio == 0.);
|
||||
GenericColor::Numeric(convert_nscolor_to_rgba(other.mColor))
|
||||
},
|
||||
Tag::eForeground => {
|
||||
debug_assert!(other.mBgRatio == 0. && other.mFgRatio == 1.);
|
||||
GenericColor::CurrentColor
|
||||
},
|
||||
Tag::eComplex => {
|
||||
debug_assert!(other.mBgRatio != 1. || other.mFgRatio != 0.);
|
||||
debug_assert!(other.mBgRatio != 0. || other.mFgRatio != 1.);
|
||||
GenericColor::Complex {
|
||||
color: convert_nscolor_to_rgba(other.mColor),
|
||||
ratios: ComplexColorRatios {
|
||||
bg: other.mBgRatio,
|
||||
fg: other.mFgRatio,
|
||||
},
|
||||
}
|
||||
},
|
||||
Tag::eAuto => unreachable!("Unsupport StyleComplexColor with tag eAuto"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ColorOrAuto> for StyleComplexColor {
|
||||
fn from(other: ColorOrAuto) -> Self {
|
||||
match other {
|
||||
GenericColorOrAuto::Color(color) => color.into(),
|
||||
GenericColorOrAuto::Auto => StyleComplexColor::auto(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<StyleComplexColor> for ColorOrAuto {
|
||||
fn from(other: StyleComplexColor) -> Self {
|
||||
if other.mTag != Tag::eAuto {
|
||||
GenericColorOrAuto::Color(other.into())
|
||||
} else {
|
||||
GenericColorOrAuto::Auto
|
||||
}
|
||||
}
|
||||
}
|
|
@ -397,34 +397,6 @@ def set_gecko_property(ffi_name, expr):
|
|||
}
|
||||
</%def>
|
||||
|
||||
<%def name="impl_color_setter(ident, gecko_ffi_name)">
|
||||
#[allow(unreachable_code)]
|
||||
#[allow(non_snake_case)]
|
||||
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
|
||||
${set_gecko_property(gecko_ffi_name, "v.into()")}
|
||||
}
|
||||
</%def>
|
||||
|
||||
<%def name="impl_color_copy(ident, gecko_ffi_name)">
|
||||
#[allow(non_snake_case)]
|
||||
pub fn copy_${ident}_from(&mut self, other: &Self) {
|
||||
let color = ${get_gecko_property(gecko_ffi_name, self_param = "other")};
|
||||
${set_gecko_property(gecko_ffi_name, "color")};
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn reset_${ident}(&mut self, other: &Self) {
|
||||
self.copy_${ident}_from(other)
|
||||
}
|
||||
</%def>
|
||||
|
||||
<%def name="impl_color_clone(ident, gecko_ffi_name)">
|
||||
#[allow(non_snake_case)]
|
||||
pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
|
||||
${get_gecko_property(gecko_ffi_name)}.into()
|
||||
}
|
||||
</%def>
|
||||
|
||||
<%def name="impl_keyword(ident, gecko_ffi_name, keyword, cast_type='u8', **kwargs)">
|
||||
<%call expr="impl_keyword_setter(ident, gecko_ffi_name, keyword, cast_type, **kwargs)"></%call>
|
||||
<%call expr="impl_simple_copy(ident, gecko_ffi_name, **kwargs)"></%call>
|
||||
|
@ -449,12 +421,6 @@ def set_gecko_property(ffi_name, expr):
|
|||
}
|
||||
</%def>
|
||||
|
||||
<%def name="impl_color(ident, gecko_ffi_name)">
|
||||
<%call expr="impl_color_setter(ident, gecko_ffi_name)"></%call>
|
||||
<%call expr="impl_color_copy(ident, gecko_ffi_name)"></%call>
|
||||
<%call expr="impl_color_clone(ident, gecko_ffi_name)"></%call>
|
||||
</%def>
|
||||
|
||||
<%def name="impl_rgba_color(ident, gecko_ffi_name)">
|
||||
#[allow(non_snake_case)]
|
||||
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
|
||||
|
@ -1238,8 +1204,6 @@ impl Clone for ${style_struct.gecko_struct_name} {
|
|||
|
||||
# Types used with predefined_type()-defined properties that we can auto-generate.
|
||||
predefined_types = {
|
||||
"Color": impl_color,
|
||||
"ColorOrAuto": impl_color,
|
||||
"length::LengthOrAuto": impl_style_coord,
|
||||
"length::LengthOrNormal": impl_style_coord,
|
||||
"length::NonNegativeLengthOrAuto": impl_style_coord,
|
||||
|
@ -1247,7 +1211,6 @@ impl Clone for ${style_struct.gecko_struct_name} {
|
|||
"Length": impl_absolute_length,
|
||||
"LengthOrNormal": impl_style_coord,
|
||||
"LengthPercentageOrAuto": impl_style_coord,
|
||||
"MozListReversed": impl_simple,
|
||||
"MozScriptMinSize": impl_absolute_length,
|
||||
"RGBAColor": impl_rgba_color,
|
||||
"SVGLength": impl_svg_length,
|
||||
|
@ -1379,7 +1342,7 @@ fn static_assert() {
|
|||
self.gecko.mBorderStyle[${side.index}]
|
||||
}
|
||||
|
||||
<% impl_color("border_%s_color" % side.ident, "mBorder%sColor" % side.name) %>
|
||||
<% impl_simple("border_%s_color" % side.ident, "mBorder%sColor" % side.name) %>
|
||||
|
||||
<% impl_non_negative_length("border_%s_width" % side.ident,
|
||||
"mComputedBorder.%s" % side.ident,
|
||||
|
@ -4386,23 +4349,11 @@ clip-path
|
|||
}
|
||||
</%self:impl_trait>
|
||||
|
||||
<%self:impl_trait style_struct_name="Color"
|
||||
skip_longhands="*">
|
||||
pub fn set_color(&mut self, v: longhands::color::computed_value::T) {
|
||||
let result = convert_rgba_to_nscolor(&v);
|
||||
${set_gecko_property("mColor", "result")}
|
||||
}
|
||||
|
||||
<%call expr="impl_simple_copy('color', 'mColor')"></%call>
|
||||
|
||||
pub fn clone_color(&self) -> longhands::color::computed_value::T {
|
||||
let color = ${get_gecko_property("mColor")} as u32;
|
||||
convert_nscolor_to_rgba(color)
|
||||
}
|
||||
<%self:impl_trait style_struct_name="Color" skip_longhands="color">
|
||||
${impl_rgba_color("color", "mColor")}
|
||||
</%self:impl_trait>
|
||||
|
||||
<%self:impl_trait style_struct_name="InheritedUI"
|
||||
skip_longhands="cursor scrollbar-color">
|
||||
<%self:impl_trait style_struct_name="InheritedUI" skip_longhands="cursor">
|
||||
pub fn set_cursor(&mut self, v: longhands::cursor::computed_value::T) {
|
||||
self.gecko.mCursor = v.keyword;
|
||||
unsafe {
|
||||
|
@ -4464,48 +4415,6 @@ clip-path
|
|||
|
||||
longhands::cursor::computed_value::T { images, keyword }
|
||||
}
|
||||
|
||||
pub fn set_scrollbar_color(&mut self, v: longhands::scrollbar_color::computed_value::T) {
|
||||
use crate::gecko_bindings::structs::StyleComplexColor;
|
||||
use crate::values::generics::ui::ScrollbarColor;
|
||||
match v {
|
||||
ScrollbarColor::Auto => {
|
||||
self.gecko.mScrollbarFaceColor = StyleComplexColor::auto();
|
||||
self.gecko.mScrollbarTrackColor = StyleComplexColor::auto();
|
||||
}
|
||||
ScrollbarColor::Colors { thumb, track } => {
|
||||
self.gecko.mScrollbarFaceColor = thumb.into();
|
||||
self.gecko.mScrollbarTrackColor = track.into();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn copy_scrollbar_color_from(&mut self, other: &Self) {
|
||||
self.gecko.mScrollbarFaceColor = other.gecko.mScrollbarFaceColor;
|
||||
self.gecko.mScrollbarTrackColor = other.gecko.mScrollbarTrackColor;
|
||||
}
|
||||
|
||||
pub fn reset_scrollbar_color(&mut self, other: &Self) {
|
||||
self.copy_scrollbar_color_from(other);
|
||||
}
|
||||
|
||||
pub fn clone_scrollbar_color(&self) -> longhands::scrollbar_color::computed_value::T {
|
||||
use crate::gecko_bindings::structs::StyleComplexColor_Tag as Tag;
|
||||
use crate::values::generics::ui::ScrollbarColor;
|
||||
debug_assert!(
|
||||
(self.gecko.mScrollbarFaceColor.mTag == Tag::eAuto) ==
|
||||
(self.gecko.mScrollbarTrackColor.mTag == Tag::eAuto),
|
||||
"Whether the two colors are `auto` should match",
|
||||
);
|
||||
if self.gecko.mScrollbarFaceColor.mTag == Tag::eAuto {
|
||||
ScrollbarColor::Auto
|
||||
} else {
|
||||
ScrollbarColor::Colors {
|
||||
thumb: self.gecko.mScrollbarFaceColor.into(),
|
||||
track: self.gecko.mScrollbarTrackColor.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
</%self:impl_trait>
|
||||
|
||||
<%self:impl_trait style_struct_name="Column"
|
||||
|
|
|
@ -19,4 +19,4 @@ pub type Cursor = generics::Cursor<CursorImage>;
|
|||
pub type CursorImage = generics::CursorImage<ComputedImageUrl, Number>;
|
||||
|
||||
/// A computed value for `scrollbar-color` property.
|
||||
pub type ScrollbarColor = generics::ScrollbarColor<Color>;
|
||||
pub type ScrollbarColor = generics::GenericScrollbarColor<Color>;
|
||||
|
|
|
@ -86,7 +86,8 @@ impl<ImageUrl: ToCss, Number: ToCss> ToCss for CursorImage<ImageUrl, Number> {
|
|||
ToCss,
|
||||
ToShmem,
|
||||
)]
|
||||
pub enum ScrollbarColor<Color> {
|
||||
#[repr(C, u8)]
|
||||
pub enum GenericScrollbarColor<Color> {
|
||||
/// `auto`
|
||||
Auto,
|
||||
/// `<color>{2}`
|
||||
|
@ -98,6 +99,8 @@ pub enum ScrollbarColor<Color> {
|
|||
},
|
||||
}
|
||||
|
||||
pub use self::GenericScrollbarColor as ScrollbarColor;
|
||||
|
||||
impl<Color> Default for ScrollbarColor<Color> {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
|
|
|
@ -106,6 +106,7 @@ include = [
|
|||
"Owned",
|
||||
"OwnedOrNull",
|
||||
"Strong",
|
||||
"ScrollbarColor",
|
||||
"Color",
|
||||
"ColorOrAuto",
|
||||
]
|
||||
|
@ -282,3 +283,25 @@ renaming_overrides_prefixing = true
|
|||
return ret;
|
||||
}
|
||||
"""
|
||||
|
||||
"GenericColor" = """
|
||||
static inline StyleGenericColor FromColor(nscolor);
|
||||
static inline StyleGenericColor Black();
|
||||
static inline StyleGenericColor White();
|
||||
static inline StyleGenericColor Transparent();
|
||||
bool MaybeTransparent() const;
|
||||
/**
|
||||
* Compute the color for this StyleComplexColor, taking into
|
||||
* account the foreground color from the frame's ComputedStyle.
|
||||
*/
|
||||
nscolor CalcColor(const nsIFrame*) const;
|
||||
/**
|
||||
* Compute the color for this StyleComplexColor, taking into
|
||||
* account the foreground color the style.
|
||||
*/
|
||||
nscolor CalcColor(const ComputedStyle&) const;
|
||||
/**
|
||||
* Compute the color for this StyleComplexColor, making the argument the foreground color.
|
||||
*/
|
||||
nscolor CalcColor(nscolor) const;
|
||||
"""
|
||||
|
|
|
@ -2453,9 +2453,10 @@ nsNativeThemeCocoa::ScrollbarParams nsNativeThemeCocoa::ComputeScrollbarParams(n
|
|||
ComputedStyle* style = nsLayoutUtils::StyleForScrollbar(aFrame);
|
||||
const nsStyleUI* ui = style->StyleUI();
|
||||
if (ui->HasCustomScrollbars()) {
|
||||
const auto& colors = ui->mScrollbarColor.AsColors();
|
||||
params.custom = true;
|
||||
params.trackColor = ui->mScrollbarTrackColor.CalcColor(style);
|
||||
params.faceColor = ui->mScrollbarFaceColor.CalcColor(style);
|
||||
params.trackColor = colors.track.CalcColor(*style);
|
||||
params.faceColor = colors.thumb.CalcColor(*style);
|
||||
}
|
||||
}
|
||||
return params;
|
||||
|
@ -4468,8 +4469,8 @@ nsITheme::Transparency nsNativeThemeCocoa::GetWidgetTransparency(nsIFrame* aFram
|
|||
return eTransparent;
|
||||
}
|
||||
const nsStyleUI* ui = nsLayoutUtils::StyleForScrollbar(aFrame)->StyleUI();
|
||||
StyleComplexColor trackColor = ui->mScrollbarTrackColor;
|
||||
if (!trackColor.IsAuto() && trackColor.MaybeTransparent()) {
|
||||
if (!ui->mScrollbarColor.IsAuto() &&
|
||||
ui->mScrollbarColor.AsColors().track.MaybeTransparent()) {
|
||||
return eTransparent;
|
||||
}
|
||||
return eOpaque;
|
||||
|
|
|
@ -2660,7 +2660,9 @@ nsITheme::Transparency nsNativeThemeWin::GetWidgetTransparency(
|
|||
if (IsWidgetScrollbarPart(aAppearance)) {
|
||||
ComputedStyle* style = nsLayoutUtils::StyleForScrollbar(aFrame);
|
||||
if (ShouldDrawCustomScrollbar(style)) {
|
||||
if (style->StyleUI()->mScrollbarTrackColor.MaybeTransparent()) {
|
||||
auto* ui = style->StyleUI();
|
||||
if (ui->mScrollbarColor.IsAuto() ||
|
||||
ui->mScrollbarColor.AsColors().track.MaybeTransparent()) {
|
||||
return eTransparent;
|
||||
}
|
||||
// DrawCustomScrollbarPart doesn't draw the track background for
|
||||
|
@ -4170,9 +4172,10 @@ nsresult nsNativeThemeWin::DrawCustomScrollbarPart(
|
|||
ThebesRect(LayoutDevicePixel::FromAppUnits(aRect, p2a).ToUnknownRect());
|
||||
|
||||
const nsStyleUI* ui = aStyle->StyleUI();
|
||||
nscolor trackColor = ui->mScrollbarTrackColor.IsAuto()
|
||||
? NS_RGB(240, 240, 240)
|
||||
: ui->mScrollbarTrackColor.CalcColor(aStyle);
|
||||
auto* customColors =
|
||||
ui->mScrollbarColor.IsAuto() ? nullptr : &ui->mScrollbarColor.AsColors();
|
||||
nscolor trackColor = customColors ? customColors->track.CalcColor(*aStyle)
|
||||
: NS_RGB(240, 240, 240);
|
||||
switch (aAppearance) {
|
||||
case StyleAppearance::ScrollbarHorizontal:
|
||||
case StyleAppearance::ScrollbarVertical:
|
||||
|
@ -4207,9 +4210,8 @@ nsresult nsNativeThemeWin::DrawCustomScrollbarPart(
|
|||
switch (aAppearance) {
|
||||
case StyleAppearance::ScrollbarthumbVertical:
|
||||
case StyleAppearance::ScrollbarthumbHorizontal: {
|
||||
nscolor faceColor = ui->mScrollbarFaceColor.IsAuto()
|
||||
? NS_RGB(205, 205, 205)
|
||||
: ui->mScrollbarFaceColor.CalcColor(aStyle);
|
||||
nscolor faceColor = customColors ? customColors->thumb.CalcColor(*aStyle)
|
||||
: NS_RGB(205, 205, 205);
|
||||
faceColor = AdjustScrollbarFaceColor(faceColor, eventStates);
|
||||
ctx->SetColor(Color::FromABGR(faceColor));
|
||||
ctx->Rectangle(bgRect);
|
||||
|
|
Загрузка…
Ссылка в новой задаче