2016-09-02 07:58:10 +03:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
|
|
|
/* represent a color combines a numeric color and currentcolor */
|
|
|
|
|
|
|
|
#ifndef mozilla_StyleComplexColor_h_
|
|
|
|
#define mozilla_StyleComplexColor_h_
|
|
|
|
|
|
|
|
#include "nsColor.h"
|
|
|
|
|
2018-05-09 10:03:02 +03:00
|
|
|
class nsIFrame;
|
|
|
|
|
2016-09-02 07:58:10 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2018-05-09 10:03:02 +03:00
|
|
|
class ComputedStyle;
|
|
|
|
|
2016-09-02 07:58:10 +03:00
|
|
|
/**
|
|
|
|
* This struct represents a combined color from a numeric color and
|
|
|
|
* the current foreground color (currentcolor keyword).
|
2018-05-23 08:23:26 +03:00
|
|
|
* Conceptually, the formula is "color * q + currentcolor * p"
|
|
|
|
* where p is mFgRatio and q is mBgRatio.
|
2018-05-10 02:05:08 +03:00
|
|
|
*
|
|
|
|
* It can also represent an "auto" value, which is valid for some
|
2018-05-23 08:23:26 +03:00
|
|
|
* properties. See comment of `Tag::eAuto`.
|
2016-09-02 07:58:10 +03:00
|
|
|
*/
|
2018-05-23 08:23:26 +03:00
|
|
|
class StyleComplexColor final
|
2016-09-02 07:58:10 +03:00
|
|
|
{
|
2018-05-23 08:23:26 +03:00
|
|
|
public:
|
2016-12-22 03:03:37 +03:00
|
|
|
static StyleComplexColor FromColor(nscolor aColor) {
|
2018-05-23 08:23:26 +03:00
|
|
|
return {aColor, 0, eNumeric};
|
2016-12-22 03:03:37 +03:00
|
|
|
}
|
|
|
|
static StyleComplexColor CurrentColor() {
|
2018-05-23 08:23:26 +03:00
|
|
|
return {NS_RGBA(0, 0, 0, 0), 1, eForeground};
|
2016-12-22 03:03:37 +03:00
|
|
|
}
|
|
|
|
static StyleComplexColor Auto() {
|
2018-05-23 08:23:26 +03:00
|
|
|
return {NS_RGBA(0, 0, 0, 0), 1, eAuto};
|
2016-12-22 03:03:37 +03:00
|
|
|
}
|
2016-09-02 07:58:10 +03:00
|
|
|
|
2018-06-27 10:07:37 +03:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2018-05-23 08:23:26 +03:00
|
|
|
bool IsAuto() const { return mTag == eAuto; }
|
|
|
|
bool IsCurrentColor() const { return mTag == eForeground; }
|
2016-09-02 07:58:10 +03:00
|
|
|
|
|
|
|
bool operator==(const StyleComplexColor& aOther) const {
|
2018-05-23 08:23:26 +03:00
|
|
|
if (mTag != aOther.mTag) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2016-09-02 07:58:10 +03:00
|
|
|
}
|
2018-05-23 08:23:26 +03:00
|
|
|
|
2016-09-02 07:58:10 +03:00
|
|
|
bool operator!=(const StyleComplexColor& aOther) const {
|
|
|
|
return !(*this == aOther);
|
|
|
|
}
|
2018-05-09 10:03:02 +03:00
|
|
|
|
2018-05-23 08:23:26 +03:00
|
|
|
/**
|
|
|
|
* Is it possible that this StyleComplexColor is transparent?
|
|
|
|
*/
|
|
|
|
bool MaybeTransparent() const;
|
|
|
|
|
2018-06-19 07:18:33 +03:00
|
|
|
/**
|
|
|
|
* Compute the color for this StyleComplexColor, taking into account
|
|
|
|
* the foreground color, aForegroundColor.
|
|
|
|
*/
|
|
|
|
nscolor CalcColor(nscolor aForegroundColor) const;
|
|
|
|
|
2018-05-09 10:03:02 +03:00
|
|
|
/**
|
|
|
|
* 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;
|
2018-05-23 08:23:26 +03:00
|
|
|
|
|
|
|
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;
|
2016-09-02 07:58:10 +03:00
|
|
|
};
|
|
|
|
|
2018-05-23 08:23:26 +03:00
|
|
|
} // namespace mozilla
|
2016-09-02 07:58:10 +03:00
|
|
|
|
|
|
|
#endif // mozilla_StyleComplexColor_h_
|