Bug 1299741 part 4 - Add StyleComplexColor type for storing color combining numeric color and currentcolor. r=dbaron

MozReview-Commit-ID: I6DaSaMCgtH

--HG--
extra : rebase_source : 0ad610a40431e74a540714491be35ad444fd4372
This commit is contained in:
Xidorn Quan 2016-09-02 14:58:10 +10:00
Родитель 6cedec7667
Коммит 8b3d5beac6
3 изменённых файлов: 58 добавлений и 0 удалений

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

@ -0,0 +1,51 @@
/* -*- 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"
namespace mozilla {
/**
* This struct represents a combined color from a numeric color and
* the current foreground color (currentcolor keyword).
* Conceptually, the formula is "color * (1 - p) + currentcolor * p"
* where p is mForegroundRatio. See mozilla::LinearBlendColors for
* the actual algorithm.
*/
struct StyleComplexColor
{
nscolor mColor;
uint8_t mForegroundRatio;
StyleComplexColor() {}
StyleComplexColor(nscolor aColor, uint_fast8_t aForegroundRatio)
: mColor(aColor), mForegroundRatio(aForegroundRatio) {}
static StyleComplexColor FromColor(nscolor aColor)
{ return StyleComplexColor(aColor, 0); }
static StyleComplexColor CurrentColor()
{ return StyleComplexColor(NS_RGBA(0, 0, 0, 0), 255); }
bool IsNumericColor() const { return mForegroundRatio == 0; }
bool IsCurrentColor() const { return mForegroundRatio == 255; }
bool operator==(const StyleComplexColor& aOther) const {
return mForegroundRatio == aOther.mForegroundRatio &&
(IsCurrentColor() || mColor == aOther.mColor);
}
bool operator!=(const StyleComplexColor& aOther) const {
return !(*this == aOther);
}
};
}
#endif // mozilla_StyleComplexColor_h_

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

@ -100,6 +100,7 @@ EXPORTS.mozilla += [
'SheetType.h',
'StyleAnimationValue.h',
'StyleBackendType.h',
'StyleComplexColor.h',
'StyleContextSource.h',
'StyleSetHandle.h',
'StyleSetHandleInlines.h',

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

@ -18,6 +18,7 @@
#include "mozilla/Maybe.h"
#include "mozilla/SheetType.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/StyleComplexColor.h"
#include "mozilla/StyleStructContext.h"
#include "mozilla/UniquePtr.h"
#include "nsColor.h"
@ -480,6 +481,11 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleColor
MOZ_COUNT_DTOR(nsStyleColor);
}
nscolor CalcComplexColor(const mozilla::StyleComplexColor& aColor) const {
return mozilla::LinearBlendColors(aColor.mColor, mColor,
aColor.mForegroundRatio);
}
nsChangeHint CalcDifference(const nsStyleColor& aNewData) const;
static nsChangeHint MaxDifference() {
return nsChangeHint_RepaintFrame;