mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-30 18:31:08 +00:00
Bug 1457810: Move CalcComplexColor to StyleComplexColor. r=xidorn
Move from nsStyleColor::CalcComplexColor to StyleComplexColor::CalcColor. MozReview-Commit-ID: FkYovvPZLc8 --HG-- extra : rebase_source : 54f1966e0ef9258f20e954cd6250774008eca04c
This commit is contained in:
parent
788be8ad4e
commit
ee3d63760a
@ -702,8 +702,7 @@ TextAttrsMgr::TextDecorValue::
|
||||
{
|
||||
const nsStyleTextReset* textReset = aFrame->StyleTextReset();
|
||||
mStyle = textReset->mTextDecorationStyle;
|
||||
mColor = aFrame->StyleColor()->
|
||||
CalcComplexColor(textReset->mTextDecorationColor);
|
||||
mColor = textReset->mTextDecorationColor.CalcColor(aFrame);
|
||||
mLine = textReset->mTextDecorationLine &
|
||||
(NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE |
|
||||
NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH);
|
||||
|
@ -258,59 +258,6 @@ NS_ComposeColors(nscolor aBG, nscolor aFG)
|
||||
return NS_RGBA(r, g, b, a);
|
||||
}
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
static uint32_t
|
||||
BlendColorComponent(uint32_t aBg, uint32_t aFg, uint32_t aFgAlpha)
|
||||
{
|
||||
return RoundingDivideBy255(aBg * (255 - aFgAlpha) + aFg * aFgAlpha);
|
||||
}
|
||||
|
||||
nscolor
|
||||
LinearBlendColors(nscolor aBg, nscolor aFg, uint_fast8_t aFgRatio)
|
||||
{
|
||||
// Common case that either pure background or pure foreground
|
||||
if (aFgRatio == 0) {
|
||||
return aBg;
|
||||
}
|
||||
if (aFgRatio == 255) {
|
||||
return aFg;
|
||||
}
|
||||
// Common case that alpha channel is equal (usually both are opaque)
|
||||
if (NS_GET_A(aBg) == NS_GET_A(aFg)) {
|
||||
auto r = BlendColorComponent(NS_GET_R(aBg), NS_GET_R(aFg), aFgRatio);
|
||||
auto g = BlendColorComponent(NS_GET_G(aBg), NS_GET_G(aFg), aFgRatio);
|
||||
auto b = BlendColorComponent(NS_GET_B(aBg), NS_GET_B(aFg), aFgRatio);
|
||||
return NS_RGBA(r, g, b, NS_GET_A(aFg));
|
||||
}
|
||||
|
||||
constexpr float kFactor = 1.0f / 255.0f;
|
||||
|
||||
float p1 = kFactor * (255 - aFgRatio);
|
||||
float a1 = kFactor * NS_GET_A(aBg);
|
||||
float r1 = a1 * NS_GET_R(aBg);
|
||||
float g1 = a1 * NS_GET_G(aBg);
|
||||
float b1 = a1 * NS_GET_B(aBg);
|
||||
|
||||
float p2 = 1.0f - p1;
|
||||
float a2 = kFactor * NS_GET_A(aFg);
|
||||
float r2 = a2 * NS_GET_R(aFg);
|
||||
float g2 = a2 * NS_GET_G(aFg);
|
||||
float b2 = a2 * NS_GET_B(aFg);
|
||||
|
||||
float a = p1 * a1 + p2 * a2;
|
||||
if (a == 0.0) {
|
||||
return NS_RGBA(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
auto r = ClampColor((p1 * r1 + p2 * r2) / a);
|
||||
auto g = ClampColor((p1 * g1 + p2 * g2) / a);
|
||||
auto b = ClampColor((p1 * b1 + p2 * b2) / a);
|
||||
return NS_RGBA(r, g, b, NSToIntRound(a * 255));
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
// Functions to convert from HSL color space to RGB color space.
|
||||
// This is the algorithm described in the CSS3 specification
|
||||
|
||||
|
@ -86,10 +86,6 @@ inline uint32_t RoundingDivideBy255(uint32_t n)
|
||||
return (n + 127) / 255;
|
||||
}
|
||||
|
||||
// Blend one RGBA color with another based on a given ratio.
|
||||
// It is a linear interpolation on each channel with alpha premultipled.
|
||||
nscolor LinearBlendColors(nscolor aBg, nscolor aFg, uint_fast8_t aFgRatio);
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
// Translate a hex string to a color. Return true if it parses ok,
|
||||
|
@ -344,8 +344,7 @@ public:
|
||||
if (nsSVGUtils::IsInSVGTextSubtree(mFrame)) {
|
||||
return 0;
|
||||
}
|
||||
return mFrame->StyleColor()->
|
||||
CalcComplexColor(mFrame->StyleText()->mWebkitTextStrokeColor);
|
||||
return mFrame->StyleText()->mWebkitTextStrokeColor.CalcColor(mFrame);
|
||||
}
|
||||
float GetWebkitTextStrokeWidth() {
|
||||
if (nsSVGUtils::IsInSVGTextSubtree(mFrame)) {
|
||||
@ -5195,11 +5194,10 @@ nsTextFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
||||
|
||||
DO_GLOBAL_REFLOW_COUNT_DSP("nsTextFrame");
|
||||
|
||||
const nsStyleColor* sc = StyleColor();
|
||||
const nsStyleText* st = StyleText();
|
||||
bool isTextTransparent =
|
||||
NS_GET_A(sc->CalcComplexColor(st->mWebkitTextFillColor)) == 0 &&
|
||||
NS_GET_A(sc->CalcComplexColor(st->mWebkitTextStrokeColor)) == 0;
|
||||
NS_GET_A(st->mWebkitTextFillColor.CalcColor(this)) == 0 &&
|
||||
NS_GET_A(st->mWebkitTextStrokeColor.CalcColor(this)) == 0;
|
||||
Maybe<bool> isSelected;
|
||||
if (((GetStateBits() & TEXT_NO_RENDERED_GLYPHS) ||
|
||||
(isTextTransparent && !StyleText()->HasTextShadow())) &&
|
||||
|
@ -800,9 +800,6 @@ ConstructBorderRenderer(nsPresContext* aPresContext,
|
||||
{
|
||||
nsMargin border = aStyleBorder.GetComputedBorder();
|
||||
|
||||
// Get our ComputedStyle's color struct.
|
||||
const nsStyleColor* ourColor = aComputedStyle->StyleColor();
|
||||
|
||||
// In NavQuirks mode we want to use the parent's context as a starting point
|
||||
// for determining the background color.
|
||||
bool quirks = aPresContext->CompatibilityMode() == eCompatibility_NavQuirks;
|
||||
@ -861,7 +858,7 @@ ConstructBorderRenderer(nsPresContext* aPresContext,
|
||||
// pull out styles, colors
|
||||
NS_FOR_CSS_SIDES (i) {
|
||||
borderStyles[i] = aStyleBorder.GetBorderStyle(i);
|
||||
borderColors[i] = ourColor->CalcComplexColor(aStyleBorder.mBorderColor[i]);
|
||||
borderColors[i] = aStyleBorder.mBorderColor[i].CalcColor(aComputedStyle);
|
||||
}
|
||||
|
||||
PrintAsFormatString(" borderStyles: %d %d %d %d\n", borderStyles[0], borderStyles[1], borderStyles[2], borderStyles[3]);
|
||||
|
@ -341,7 +341,7 @@ ExtractColor(ComputedStyle* aStyle, const nscolor& aColor)
|
||||
static nscolor
|
||||
ExtractColor(ComputedStyle* aStyle, const StyleComplexColor& aColor)
|
||||
{
|
||||
return aStyle->StyleColor()->CalcComplexColor(aColor);
|
||||
return aColor.CalcColor(aStyle);
|
||||
}
|
||||
|
||||
static nscolor
|
||||
|
77
layout/style/StyleComplexColor.cpp
Normal file
77
layout/style/StyleComplexColor.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "mozilla/StyleComplexColor.h"
|
||||
|
||||
#include "mozilla/ComputedStyle.h"
|
||||
#include "mozilla/ComputedStyleInlines.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsStyleStruct.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
static uint32_t
|
||||
BlendColorComponent(uint32_t aBg, uint32_t aFg, uint32_t aFgAlpha)
|
||||
{
|
||||
return RoundingDivideBy255(aBg * (255 - aFgAlpha) + aFg * aFgAlpha);
|
||||
}
|
||||
|
||||
// Blend one RGBA color with another based on a given ratio.
|
||||
// It is a linear interpolation on each channel with alpha premultipled.
|
||||
static nscolor
|
||||
LinearBlendColors(nscolor aBg, nscolor aFg, uint_fast8_t aFgRatio)
|
||||
{
|
||||
// Common case that either pure background or pure foreground
|
||||
if (aFgRatio == 0) {
|
||||
return aBg;
|
||||
}
|
||||
if (aFgRatio == 255) {
|
||||
return aFg;
|
||||
}
|
||||
// Common case that alpha channel is equal (usually both are opaque)
|
||||
if (NS_GET_A(aBg) == NS_GET_A(aFg)) {
|
||||
auto r = BlendColorComponent(NS_GET_R(aBg), NS_GET_R(aFg), aFgRatio);
|
||||
auto g = BlendColorComponent(NS_GET_G(aBg), NS_GET_G(aFg), aFgRatio);
|
||||
auto b = BlendColorComponent(NS_GET_B(aBg), NS_GET_B(aFg), aFgRatio);
|
||||
return NS_RGBA(r, g, b, NS_GET_A(aFg));
|
||||
}
|
||||
|
||||
constexpr float kFactor = 1.0f / 255.0f;
|
||||
|
||||
float p1 = kFactor * (255 - aFgRatio);
|
||||
float a1 = kFactor * NS_GET_A(aBg);
|
||||
float r1 = a1 * NS_GET_R(aBg);
|
||||
float g1 = a1 * NS_GET_G(aBg);
|
||||
float b1 = a1 * NS_GET_B(aBg);
|
||||
|
||||
float p2 = 1.0f - p1;
|
||||
float a2 = kFactor * NS_GET_A(aFg);
|
||||
float r2 = a2 * NS_GET_R(aFg);
|
||||
float g2 = a2 * NS_GET_G(aFg);
|
||||
float b2 = a2 * NS_GET_B(aFg);
|
||||
|
||||
float a = p1 * a1 + p2 * a2;
|
||||
if (a == 0.0) {
|
||||
return NS_RGBA(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
auto r = ClampColor((p1 * r1 + p2 * r2) / a);
|
||||
auto g = ClampColor((p1 * g1 + p2 * g2) / a);
|
||||
auto b = ClampColor((p1 * b1 + p2 * b2) / a);
|
||||
return NS_RGBA(r, g, b, NSToIntRound(a * 255));
|
||||
}
|
||||
|
||||
nscolor
|
||||
StyleComplexColor::CalcColor(mozilla::ComputedStyle* aStyle) const {
|
||||
MOZ_ASSERT(aStyle);
|
||||
auto foregroundColor = aStyle->StyleColor()->mColor;
|
||||
return LinearBlendColors(mColor, foregroundColor, mForegroundRatio);
|
||||
}
|
||||
|
||||
nscolor
|
||||
StyleComplexColor::CalcColor(const nsIFrame* aFrame) const {
|
||||
return CalcColor(aFrame->Style());
|
||||
}
|
@ -11,8 +11,12 @@
|
||||
|
||||
#include "nsColor.h"
|
||||
|
||||
class nsIFrame;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class ComputedStyle;
|
||||
|
||||
/**
|
||||
* This struct represents a combined color from a numeric color and
|
||||
* the current foreground color (currentcolor keyword).
|
||||
@ -51,6 +55,18 @@ struct StyleComplexColor
|
||||
bool operator!=(const StyleComplexColor& aOther) const {
|
||||
return !(*this == aOther);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -221,6 +221,7 @@ UNIFIED_SOURCES += [
|
||||
'ServoSupportsRule.cpp',
|
||||
'StreamLoader.cpp',
|
||||
'StyleAnimationValue.cpp',
|
||||
'StyleComplexColor.cpp',
|
||||
'StyleSheet.cpp',
|
||||
'URLExtraData.cpp',
|
||||
]
|
||||
|
@ -1188,7 +1188,7 @@ void
|
||||
nsComputedDOMStyle::SetValueFromComplexColor(nsROCSSPrimitiveValue* aValue,
|
||||
const StyleComplexColor& aColor)
|
||||
{
|
||||
SetToRGBAColor(aValue, StyleColor()->CalcComplexColor(aColor));
|
||||
SetToRGBAColor(aValue, aColor.CalcColor(mComputedStyle));
|
||||
}
|
||||
|
||||
already_AddRefed<CSSValue>
|
||||
|
@ -3372,7 +3372,7 @@ nsStyleBackground::BackgroundColor(mozilla::ComputedStyle* aStyle) const
|
||||
// In that case, we can skip resolving StyleColor().
|
||||
return mBackgroundColor.IsNumericColor()
|
||||
? mBackgroundColor.mColor
|
||||
: aStyle->StyleColor()->CalcComplexColor(mBackgroundColor);
|
||||
: mBackgroundColor.CalcColor(aStyle);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -522,11 +522,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleColor
|
||||
void FinishStyle(nsPresContext*, const nsStyleColor*) {}
|
||||
const static bool kHasFinishStyle = false;
|
||||
|
||||
nscolor CalcComplexColor(const mozilla::StyleComplexColor& aColor) const {
|
||||
return mozilla::LinearBlendColors(aColor.mColor, mColor,
|
||||
aColor.mForegroundRatio);
|
||||
}
|
||||
|
||||
nsChangeHint CalcDifference(const nsStyleColor& aNewData) const;
|
||||
|
||||
// Don't add ANY members to this struct! We can achieve caching in the rule
|
||||
|
@ -427,8 +427,7 @@ nsTextBoxFrame::DrawText(gfxContext& aRenderingContext,
|
||||
if (aOverrideColor) {
|
||||
color = *aOverrideColor;
|
||||
} else {
|
||||
color = context->StyleColor()->
|
||||
CalcComplexColor(styleText->mTextDecorationColor);
|
||||
color = styleText->mTextDecorationColor.CalcColor(context);
|
||||
}
|
||||
uint8_t style = styleText->mTextDecorationStyle;
|
||||
|
||||
|
@ -3307,8 +3307,7 @@ nsTreeBodyFrame::PaintCell(int32_t aRowIndex,
|
||||
|
||||
const nsStyleBorder* borderStyle = lineContext->StyleBorder();
|
||||
// Resolve currentcolor values against the treeline context
|
||||
nscolor color = lineContext->StyleColor()->
|
||||
CalcComplexColor(borderStyle->mBorderLeftColor);
|
||||
nscolor color = borderStyle->mBorderLeftColor.CalcColor(lineContext);
|
||||
ColorPattern colorPatt(ToDeviceColor(color));
|
||||
|
||||
uint8_t style = borderStyle->GetBorderStyle(eSideLeft);
|
||||
|
Loading…
x
Reference in New Issue
Block a user