2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2011-12-22 23:34:45 +00:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2006-03-25 05:47:31 +00:00
|
|
|
|
|
|
|
/* representation of simple property values within CSS declarations */
|
|
|
|
|
1998-10-08 01:29:29 +00:00
|
|
|
#include "nsCSSValue.h"
|
2010-08-19 19:33:43 +00:00
|
|
|
|
2013-12-12 02:09:44 +00:00
|
|
|
#include "mozilla/Likely.h"
|
|
|
|
#include "mozilla/MemoryReporting.h"
|
|
|
|
#include "mozilla/css/ImageLoader.h"
|
|
|
|
#include "CSSCalc.h"
|
|
|
|
#include "gfxFontConstants.h"
|
2004-03-09 03:57:51 +00:00
|
|
|
#include "imgIRequest.h"
|
2013-12-12 02:09:44 +00:00
|
|
|
#include "imgRequestProxy.h"
|
2013-03-17 07:55:15 +00:00
|
|
|
#include "nsIDocument.h"
|
2007-05-03 01:15:53 +00:00
|
|
|
#include "nsIPrincipal.h"
|
2010-08-19 19:33:43 +00:00
|
|
|
#include "nsCSSProps.h"
|
2013-12-12 02:09:44 +00:00
|
|
|
#include "nsCSSStyleSheet.h"
|
2011-05-11 15:28:53 +00:00
|
|
|
#include "nsNetUtil.h"
|
2013-09-16 01:06:52 +00:00
|
|
|
#include "nsPresContext.h"
|
2013-12-12 02:09:44 +00:00
|
|
|
#include "nsStyleUtil.h"
|
2013-09-23 11:55:35 +00:00
|
|
|
#include "nsDeviceContext.h"
|
2004-03-09 03:57:51 +00:00
|
|
|
|
2013-11-15 02:42:57 +00:00
|
|
|
using namespace mozilla;
|
1998-10-08 01:29:29 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
nsCSSValue::nsCSSValue(int32_t aValue, nsCSSUnit aUnit)
|
1998-10-08 01:29:29 +00:00
|
|
|
: mUnit(aUnit)
|
|
|
|
{
|
2010-08-19 19:33:44 +00:00
|
|
|
NS_ABORT_IF_FALSE(aUnit == eCSSUnit_Integer || aUnit == eCSSUnit_Enumerated ||
|
|
|
|
aUnit == eCSSUnit_EnumColor, "not an int value");
|
2008-02-08 19:51:41 +00:00
|
|
|
if (aUnit == eCSSUnit_Integer || aUnit == eCSSUnit_Enumerated ||
|
|
|
|
aUnit == eCSSUnit_EnumColor) {
|
1998-10-08 01:29:29 +00:00
|
|
|
mValue.mInt = aValue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mUnit = eCSSUnit_Null;
|
|
|
|
mValue.mInt = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue::nsCSSValue(float aValue, nsCSSUnit aUnit)
|
|
|
|
: mUnit(aUnit)
|
|
|
|
{
|
2010-08-19 19:33:44 +00:00
|
|
|
NS_ABORT_IF_FALSE(eCSSUnit_Percent <= aUnit, "not a float value");
|
1998-10-08 01:29:29 +00:00
|
|
|
if (eCSSUnit_Percent <= aUnit) {
|
|
|
|
mValue.mFloat = aValue;
|
2013-05-01 20:55:13 +00:00
|
|
|
MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat));
|
1998-10-08 01:29:29 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mUnit = eCSSUnit_Null;
|
|
|
|
mValue.mInt = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-13 15:49:36 +00:00
|
|
|
nsCSSValue::nsCSSValue(const nsString& aValue, nsCSSUnit aUnit)
|
1998-10-26 23:19:59 +00:00
|
|
|
: mUnit(aUnit)
|
1998-10-08 01:29:29 +00:00
|
|
|
{
|
2010-08-19 19:33:44 +00:00
|
|
|
NS_ABORT_IF_FALSE(UnitHasStringValue(), "not a string value");
|
2008-08-07 23:15:40 +00:00
|
|
|
if (UnitHasStringValue()) {
|
2010-12-05 13:17:29 +00:00
|
|
|
mValue.mString = BufferFromString(aValue).get();
|
1998-10-26 23:19:59 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mUnit = eCSSUnit_Null;
|
|
|
|
mValue.mInt = 0;
|
|
|
|
}
|
1998-10-08 01:29:29 +00:00
|
|
|
}
|
|
|
|
|
2005-04-01 23:07:00 +00:00
|
|
|
nsCSSValue::nsCSSValue(nsCSSValue::Array* aValue, nsCSSUnit aUnit)
|
|
|
|
: mUnit(aUnit)
|
|
|
|
{
|
2010-08-19 19:33:44 +00:00
|
|
|
NS_ABORT_IF_FALSE(UnitHasArrayValue(), "bad unit");
|
2005-04-01 23:07:00 +00:00
|
|
|
mValue.mArray = aValue;
|
|
|
|
mValue.mArray->AddRef();
|
|
|
|
}
|
|
|
|
|
2012-08-24 17:50:49 +00:00
|
|
|
nsCSSValue::nsCSSValue(mozilla::css::URLValue* aValue)
|
2003-10-01 22:53:56 +00:00
|
|
|
: mUnit(eCSSUnit_URL)
|
|
|
|
{
|
|
|
|
mValue.mURL = aValue;
|
2003-10-30 01:45:37 +00:00
|
|
|
mValue.mURL->AddRef();
|
2003-10-01 22:53:56 +00:00
|
|
|
}
|
|
|
|
|
2012-08-24 17:50:49 +00:00
|
|
|
nsCSSValue::nsCSSValue(mozilla::css::ImageValue* aValue)
|
2004-03-09 03:57:51 +00:00
|
|
|
: mUnit(eCSSUnit_Image)
|
|
|
|
{
|
|
|
|
mValue.mImage = aValue;
|
|
|
|
mValue.mImage->AddRef();
|
|
|
|
}
|
|
|
|
|
2009-08-01 15:53:40 +00:00
|
|
|
nsCSSValue::nsCSSValue(nsCSSValueGradient* aValue)
|
|
|
|
: mUnit(eCSSUnit_Gradient)
|
|
|
|
{
|
|
|
|
mValue.mGradient = aValue;
|
|
|
|
mValue.mGradient->AddRef();
|
|
|
|
}
|
|
|
|
|
2013-12-12 02:09:42 +00:00
|
|
|
nsCSSValue::nsCSSValue(nsCSSValueTokenStream* aValue)
|
|
|
|
: mUnit(eCSSUnit_TokenStream)
|
|
|
|
{
|
|
|
|
mValue.mTokenStream = aValue;
|
|
|
|
mValue.mTokenStream->AddRef();
|
|
|
|
}
|
|
|
|
|
1998-10-08 01:29:29 +00:00
|
|
|
nsCSSValue::nsCSSValue(const nsCSSValue& aCopy)
|
|
|
|
: mUnit(aCopy.mUnit)
|
|
|
|
{
|
2010-08-19 19:33:44 +00:00
|
|
|
if (mUnit <= eCSSUnit_DummyInherit) {
|
2008-03-12 22:05:27 +00:00
|
|
|
// nothing to do, but put this important case first
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_Percent <= mUnit) {
|
|
|
|
mValue.mFloat = aCopy.mValue.mFloat;
|
2013-05-01 20:55:13 +00:00
|
|
|
MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat));
|
2008-03-12 22:05:27 +00:00
|
|
|
}
|
2008-08-07 23:15:40 +00:00
|
|
|
else if (UnitHasStringValue()) {
|
2006-12-13 15:49:36 +00:00
|
|
|
mValue.mString = aCopy.mValue.mString;
|
|
|
|
mValue.mString->AddRef();
|
1998-10-08 01:29:29 +00:00
|
|
|
}
|
2008-03-12 22:05:27 +00:00
|
|
|
else if (eCSSUnit_Integer <= mUnit && mUnit <= eCSSUnit_EnumColor) {
|
1998-10-08 01:29:29 +00:00
|
|
|
mValue.mInt = aCopy.mValue.mInt;
|
|
|
|
}
|
2013-09-15 23:35:48 +00:00
|
|
|
else if (IsIntegerColorUnit()) {
|
1998-10-08 01:29:29 +00:00
|
|
|
mValue.mColor = aCopy.mValue.mColor;
|
|
|
|
}
|
2013-09-15 23:35:48 +00:00
|
|
|
else if (IsFloatColorUnit()) {
|
|
|
|
mValue.mFloatColor = aCopy.mValue.mFloatColor;
|
|
|
|
mValue.mFloatColor->AddRef();
|
|
|
|
}
|
2010-05-11 15:49:43 +00:00
|
|
|
else if (UnitHasArrayValue()) {
|
2005-04-01 23:07:00 +00:00
|
|
|
mValue.mArray = aCopy.mValue.mArray;
|
|
|
|
mValue.mArray->AddRef();
|
|
|
|
}
|
2008-03-12 22:05:27 +00:00
|
|
|
else if (eCSSUnit_URL == mUnit) {
|
2003-10-01 22:53:56 +00:00
|
|
|
mValue.mURL = aCopy.mValue.mURL;
|
2003-10-30 01:45:37 +00:00
|
|
|
mValue.mURL->AddRef();
|
2003-10-01 22:53:56 +00:00
|
|
|
}
|
2008-03-12 22:05:27 +00:00
|
|
|
else if (eCSSUnit_Image == mUnit) {
|
2004-03-09 03:57:51 +00:00
|
|
|
mValue.mImage = aCopy.mValue.mImage;
|
|
|
|
mValue.mImage->AddRef();
|
|
|
|
}
|
2009-08-01 15:53:40 +00:00
|
|
|
else if (eCSSUnit_Gradient == mUnit) {
|
|
|
|
mValue.mGradient = aCopy.mValue.mGradient;
|
|
|
|
mValue.mGradient->AddRef();
|
|
|
|
}
|
2013-12-12 02:09:42 +00:00
|
|
|
else if (eCSSUnit_TokenStream == mUnit) {
|
|
|
|
mValue.mTokenStream = aCopy.mValue.mTokenStream;
|
|
|
|
mValue.mTokenStream->AddRef();
|
|
|
|
}
|
2010-08-19 19:33:44 +00:00
|
|
|
else if (eCSSUnit_Pair == mUnit) {
|
|
|
|
mValue.mPair = aCopy.mValue.mPair;
|
|
|
|
mValue.mPair->AddRef();
|
|
|
|
}
|
2011-08-03 03:04:23 +00:00
|
|
|
else if (eCSSUnit_Triplet == mUnit) {
|
|
|
|
mValue.mTriplet = aCopy.mValue.mTriplet;
|
|
|
|
mValue.mTriplet->AddRef();
|
|
|
|
}
|
2010-08-19 19:33:44 +00:00
|
|
|
else if (eCSSUnit_Rect == mUnit) {
|
|
|
|
mValue.mRect = aCopy.mValue.mRect;
|
|
|
|
mValue.mRect->AddRef();
|
|
|
|
}
|
2010-08-19 19:33:44 +00:00
|
|
|
else if (eCSSUnit_List == mUnit) {
|
|
|
|
mValue.mList = aCopy.mValue.mList;
|
|
|
|
mValue.mList->AddRef();
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_ListDep == mUnit) {
|
|
|
|
mValue.mListDependent = aCopy.mValue.mListDependent;
|
|
|
|
}
|
2013-12-12 02:09:44 +00:00
|
|
|
else if (eCSSUnit_SharedList == mUnit) {
|
|
|
|
mValue.mSharedList = aCopy.mValue.mSharedList;
|
|
|
|
mValue.mSharedList->AddRef();
|
|
|
|
}
|
2010-08-19 19:33:44 +00:00
|
|
|
else if (eCSSUnit_PairList == mUnit) {
|
|
|
|
mValue.mPairList = aCopy.mValue.mPairList;
|
|
|
|
mValue.mPairList->AddRef();
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_PairListDep == mUnit) {
|
|
|
|
mValue.mPairListDependent = aCopy.mValue.mPairListDependent;
|
|
|
|
}
|
1998-10-08 01:29:29 +00:00
|
|
|
else {
|
2010-08-19 19:33:44 +00:00
|
|
|
NS_ABORT_IF_FALSE(false, "unknown unit");
|
1998-10-08 01:29:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue& nsCSSValue::operator=(const nsCSSValue& aCopy)
|
|
|
|
{
|
2005-04-03 16:47:01 +00:00
|
|
|
if (this != &aCopy) {
|
|
|
|
Reset();
|
|
|
|
new (this) nsCSSValue(aCopy);
|
1998-10-08 01:29:29 +00:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool nsCSSValue::operator==(const nsCSSValue& aOther) const
|
1998-10-08 01:29:29 +00:00
|
|
|
{
|
2010-08-19 19:33:44 +00:00
|
|
|
NS_ABORT_IF_FALSE(mUnit != eCSSUnit_ListDep &&
|
|
|
|
aOther.mUnit != eCSSUnit_ListDep &&
|
|
|
|
mUnit != eCSSUnit_PairListDep &&
|
2010-08-19 19:33:44 +00:00
|
|
|
aOther.mUnit != eCSSUnit_PairListDep,
|
|
|
|
"don't use operator== with dependent lists");
|
|
|
|
|
1998-10-08 01:29:29 +00:00
|
|
|
if (mUnit == aOther.mUnit) {
|
2010-08-19 19:33:44 +00:00
|
|
|
if (mUnit <= eCSSUnit_DummyInherit) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2007-08-28 07:29:03 +00:00
|
|
|
}
|
2008-08-07 23:15:40 +00:00
|
|
|
else if (UnitHasStringValue()) {
|
2006-12-13 15:49:36 +00:00
|
|
|
return (NS_strcmp(GetBufferValue(mValue.mString),
|
|
|
|
GetBufferValue(aOther.mValue.mString)) == 0);
|
1998-10-08 01:29:29 +00:00
|
|
|
}
|
2008-02-08 19:51:41 +00:00
|
|
|
else if ((eCSSUnit_Integer <= mUnit) && (mUnit <= eCSSUnit_EnumColor)) {
|
2003-10-01 22:53:56 +00:00
|
|
|
return mValue.mInt == aOther.mValue.mInt;
|
|
|
|
}
|
2013-09-15 23:35:48 +00:00
|
|
|
else if (IsIntegerColorUnit()) {
|
2003-10-01 22:53:56 +00:00
|
|
|
return mValue.mColor == aOther.mValue.mColor;
|
1998-10-08 01:29:29 +00:00
|
|
|
}
|
2013-09-15 23:35:48 +00:00
|
|
|
else if (IsFloatColorUnit()) {
|
|
|
|
return *mValue.mFloatColor == *aOther.mValue.mFloatColor;
|
|
|
|
}
|
2010-05-11 15:49:43 +00:00
|
|
|
else if (UnitHasArrayValue()) {
|
2005-04-01 23:07:00 +00:00
|
|
|
return *mValue.mArray == *aOther.mValue.mArray;
|
|
|
|
}
|
2003-10-01 22:53:56 +00:00
|
|
|
else if (eCSSUnit_URL == mUnit) {
|
2003-10-30 01:45:37 +00:00
|
|
|
return *mValue.mURL == *aOther.mValue.mURL;
|
1998-10-08 01:29:29 +00:00
|
|
|
}
|
2004-03-09 03:57:51 +00:00
|
|
|
else if (eCSSUnit_Image == mUnit) {
|
|
|
|
return *mValue.mImage == *aOther.mValue.mImage;
|
|
|
|
}
|
2009-08-01 15:53:40 +00:00
|
|
|
else if (eCSSUnit_Gradient == mUnit) {
|
|
|
|
return *mValue.mGradient == *aOther.mValue.mGradient;
|
|
|
|
}
|
2013-12-12 02:09:42 +00:00
|
|
|
else if (eCSSUnit_TokenStream == mUnit) {
|
|
|
|
return *mValue.mTokenStream == *aOther.mValue.mTokenStream;
|
|
|
|
}
|
2010-08-19 19:33:44 +00:00
|
|
|
else if (eCSSUnit_Pair == mUnit) {
|
|
|
|
return *mValue.mPair == *aOther.mValue.mPair;
|
|
|
|
}
|
2011-08-03 03:04:23 +00:00
|
|
|
else if (eCSSUnit_Triplet == mUnit) {
|
|
|
|
return *mValue.mTriplet == *aOther.mValue.mTriplet;
|
|
|
|
}
|
2010-08-19 19:33:44 +00:00
|
|
|
else if (eCSSUnit_Rect == mUnit) {
|
|
|
|
return *mValue.mRect == *aOther.mValue.mRect;
|
|
|
|
}
|
2010-08-19 19:33:44 +00:00
|
|
|
else if (eCSSUnit_List == mUnit) {
|
|
|
|
return *mValue.mList == *aOther.mValue.mList;
|
|
|
|
}
|
2013-12-12 02:09:44 +00:00
|
|
|
else if (eCSSUnit_SharedList == mUnit) {
|
|
|
|
return *mValue.mSharedList == *aOther.mValue.mSharedList;
|
|
|
|
}
|
2010-08-19 19:33:44 +00:00
|
|
|
else if (eCSSUnit_PairList == mUnit) {
|
|
|
|
return *mValue.mPairList == *aOther.mValue.mPairList;
|
|
|
|
}
|
1998-10-08 01:29:29 +00:00
|
|
|
else {
|
2003-10-01 22:53:56 +00:00
|
|
|
return mValue.mFloat == aOther.mValue.mFloat;
|
1998-10-08 01:29:29 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
1998-10-08 01:29:29 +00:00
|
|
|
}
|
|
|
|
|
2009-11-02 19:36:43 +00:00
|
|
|
double nsCSSValue::GetAngleValueInRadians() const
|
|
|
|
{
|
|
|
|
double angle = GetFloatValue();
|
|
|
|
|
|
|
|
switch (GetUnit()) {
|
|
|
|
case eCSSUnit_Radian: return angle;
|
2012-02-04 05:01:23 +00:00
|
|
|
case eCSSUnit_Turn: return angle * 2 * M_PI;
|
2009-11-02 19:36:43 +00:00
|
|
|
case eCSSUnit_Degree: return angle * M_PI / 180.0;
|
|
|
|
case eCSSUnit_Grad: return angle * M_PI / 200.0;
|
|
|
|
|
|
|
|
default:
|
2010-08-19 19:33:44 +00:00
|
|
|
NS_ABORT_IF_FALSE(false, "unrecognized angular unit");
|
2009-11-02 19:36:43 +00:00
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-12 12:43:01 +00:00
|
|
|
imgRequestProxy* nsCSSValue::GetImageValue(nsIDocument* aDocument) const
|
2004-03-09 03:57:51 +00:00
|
|
|
{
|
2010-08-19 19:33:44 +00:00
|
|
|
NS_ABORT_IF_FALSE(mUnit == eCSSUnit_Image, "not an Image value");
|
2012-08-13 22:04:19 +00:00
|
|
|
return mValue.mImage->mRequests.GetWeak(aDocument);
|
2004-03-09 03:57:51 +00:00
|
|
|
}
|
|
|
|
|
2010-08-13 09:58:01 +00:00
|
|
|
nscoord nsCSSValue::GetFixedLength(nsPresContext* aPresContext) const
|
2003-12-29 19:07:53 +00:00
|
|
|
{
|
2010-08-19 19:33:44 +00:00
|
|
|
NS_ABORT_IF_FALSE(mUnit == eCSSUnit_PhysicalMillimeter,
|
|
|
|
"not a fixed length unit");
|
2010-08-13 09:58:01 +00:00
|
|
|
|
2010-08-13 09:58:04 +00:00
|
|
|
float inches = mValue.mFloat / MM_PER_INCH_FLOAT;
|
2011-05-11 16:49:57 +00:00
|
|
|
return NSToCoordFloorClamped(inches *
|
|
|
|
float(aPresContext->DeviceContext()->AppUnitsPerPhysicalInch()));
|
2010-08-13 09:58:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nscoord nsCSSValue::GetPixelLength() const
|
|
|
|
{
|
2010-08-19 19:33:44 +00:00
|
|
|
NS_ABORT_IF_FALSE(IsPixelLengthUnit(), "not a fixed length unit");
|
2010-08-13 09:58:01 +00:00
|
|
|
|
2010-08-13 09:58:02 +00:00
|
|
|
double scaleFactor;
|
2010-08-13 09:58:01 +00:00
|
|
|
switch (mUnit) {
|
2010-08-13 09:58:02 +00:00
|
|
|
case eCSSUnit_Pixel: return nsPresContext::CSSPixelsToAppUnits(mValue.mFloat);
|
|
|
|
case eCSSUnit_Pica: scaleFactor = 16.0; break;
|
|
|
|
case eCSSUnit_Point: scaleFactor = 4/3.0; break;
|
|
|
|
case eCSSUnit_Inch: scaleFactor = 96.0; break;
|
|
|
|
case eCSSUnit_Millimeter: scaleFactor = 96/25.4; break;
|
|
|
|
case eCSSUnit_Centimeter: scaleFactor = 96/2.54; break;
|
2010-08-13 09:58:01 +00:00
|
|
|
default:
|
|
|
|
NS_ERROR("should never get here");
|
|
|
|
return 0;
|
2003-12-29 19:07:53 +00:00
|
|
|
}
|
2010-08-13 09:58:02 +00:00
|
|
|
return nsPresContext::CSSPixelsToAppUnits(float(mValue.mFloat*scaleFactor));
|
2003-12-29 19:07:53 +00:00
|
|
|
}
|
|
|
|
|
2007-08-28 06:47:32 +00:00
|
|
|
void nsCSSValue::DoReset()
|
|
|
|
{
|
2008-08-07 23:15:40 +00:00
|
|
|
if (UnitHasStringValue()) {
|
2007-08-28 06:47:32 +00:00
|
|
|
mValue.mString->Release();
|
2013-09-15 23:35:48 +00:00
|
|
|
} else if (IsFloatColorUnit()) {
|
|
|
|
mValue.mFloatColor->Release();
|
2010-05-11 15:49:43 +00:00
|
|
|
} else if (UnitHasArrayValue()) {
|
2007-08-28 06:47:32 +00:00
|
|
|
mValue.mArray->Release();
|
|
|
|
} else if (eCSSUnit_URL == mUnit) {
|
|
|
|
mValue.mURL->Release();
|
|
|
|
} else if (eCSSUnit_Image == mUnit) {
|
|
|
|
mValue.mImage->Release();
|
2009-08-01 15:53:40 +00:00
|
|
|
} else if (eCSSUnit_Gradient == mUnit) {
|
|
|
|
mValue.mGradient->Release();
|
2013-12-12 02:09:42 +00:00
|
|
|
} else if (eCSSUnit_TokenStream == mUnit) {
|
|
|
|
mValue.mTokenStream->Release();
|
2010-08-19 19:33:44 +00:00
|
|
|
} else if (eCSSUnit_Pair == mUnit) {
|
|
|
|
mValue.mPair->Release();
|
2011-08-03 03:04:23 +00:00
|
|
|
} else if (eCSSUnit_Triplet == mUnit) {
|
|
|
|
mValue.mTriplet->Release();
|
2010-08-19 19:33:44 +00:00
|
|
|
} else if (eCSSUnit_Rect == mUnit) {
|
|
|
|
mValue.mRect->Release();
|
2010-08-19 19:33:44 +00:00
|
|
|
} else if (eCSSUnit_List == mUnit) {
|
|
|
|
mValue.mList->Release();
|
2013-12-12 02:09:44 +00:00
|
|
|
} else if (eCSSUnit_SharedList == mUnit) {
|
|
|
|
mValue.mSharedList->Release();
|
2010-08-19 19:33:44 +00:00
|
|
|
} else if (eCSSUnit_PairList == mUnit) {
|
|
|
|
mValue.mPairList->Release();
|
2007-08-28 06:47:32 +00:00
|
|
|
}
|
|
|
|
mUnit = eCSSUnit_Null;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
void nsCSSValue::SetIntValue(int32_t aValue, nsCSSUnit aUnit)
|
1998-10-08 01:29:29 +00:00
|
|
|
{
|
2010-08-19 19:33:44 +00:00
|
|
|
NS_ABORT_IF_FALSE(aUnit == eCSSUnit_Integer || aUnit == eCSSUnit_Enumerated ||
|
|
|
|
aUnit == eCSSUnit_EnumColor, "not an int value");
|
1998-10-08 01:29:29 +00:00
|
|
|
Reset();
|
2008-02-08 19:51:41 +00:00
|
|
|
if (aUnit == eCSSUnit_Integer || aUnit == eCSSUnit_Enumerated ||
|
|
|
|
aUnit == eCSSUnit_EnumColor) {
|
1998-10-08 01:29:29 +00:00
|
|
|
mUnit = aUnit;
|
|
|
|
mValue.mInt = aValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-29 19:07:53 +00:00
|
|
|
void nsCSSValue::SetPercentValue(float aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Percent;
|
|
|
|
mValue.mFloat = aValue;
|
2013-05-01 20:55:13 +00:00
|
|
|
MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat));
|
2003-12-29 19:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetFloatValue(float aValue, nsCSSUnit aUnit)
|
|
|
|
{
|
2010-08-19 19:33:44 +00:00
|
|
|
NS_ABORT_IF_FALSE(eCSSUnit_Number <= aUnit, "not a float value");
|
2003-12-29 19:07:53 +00:00
|
|
|
Reset();
|
|
|
|
if (eCSSUnit_Number <= aUnit) {
|
|
|
|
mUnit = aUnit;
|
|
|
|
mValue.mFloat = aValue;
|
2013-05-01 20:55:13 +00:00
|
|
|
MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat));
|
2003-12-29 19:07:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-13 15:49:36 +00:00
|
|
|
void nsCSSValue::SetStringValue(const nsString& aValue,
|
2000-08-23 17:27:06 +00:00
|
|
|
nsCSSUnit aUnit)
|
1998-10-08 01:29:29 +00:00
|
|
|
{
|
|
|
|
Reset();
|
2008-08-07 23:15:40 +00:00
|
|
|
mUnit = aUnit;
|
2010-08-19 19:33:44 +00:00
|
|
|
NS_ABORT_IF_FALSE(UnitHasStringValue(), "not a string unit");
|
2008-08-07 23:15:40 +00:00
|
|
|
if (UnitHasStringValue()) {
|
2010-12-05 13:17:29 +00:00
|
|
|
mValue.mString = BufferFromString(aValue).get();
|
2008-08-07 23:15:40 +00:00
|
|
|
} else
|
|
|
|
mUnit = eCSSUnit_Null;
|
1998-10-08 01:29:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetColorValue(nscolor aValue)
|
2013-09-15 23:35:48 +00:00
|
|
|
{
|
|
|
|
SetIntegerColorValue(aValue, eCSSUnit_RGBAColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetIntegerColorValue(nscolor aValue, nsCSSUnit aUnit)
|
1998-10-08 01:29:29 +00:00
|
|
|
{
|
|
|
|
Reset();
|
2013-09-15 23:35:48 +00:00
|
|
|
mUnit = aUnit;
|
|
|
|
NS_ABORT_IF_FALSE(IsIntegerColorUnit(), "bad unit");
|
1998-10-08 01:29:29 +00:00
|
|
|
mValue.mColor = aValue;
|
|
|
|
}
|
|
|
|
|
2013-09-15 23:35:48 +00:00
|
|
|
void nsCSSValue::SetFloatColorValue(float aComponent1,
|
|
|
|
float aComponent2,
|
|
|
|
float aComponent3,
|
|
|
|
float aAlpha,
|
|
|
|
nsCSSUnit aUnit)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = aUnit;
|
|
|
|
NS_ABORT_IF_FALSE(IsFloatColorUnit(), "bad unit");
|
|
|
|
mValue.mFloatColor =
|
|
|
|
new nsCSSValueFloatColor(aComponent1, aComponent2, aComponent3, aAlpha);
|
|
|
|
mValue.mFloatColor->AddRef();
|
|
|
|
}
|
|
|
|
|
2005-04-01 23:07:00 +00:00
|
|
|
void nsCSSValue::SetArrayValue(nsCSSValue::Array* aValue, nsCSSUnit aUnit)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = aUnit;
|
2010-08-19 19:33:44 +00:00
|
|
|
NS_ABORT_IF_FALSE(UnitHasArrayValue(), "bad unit");
|
2005-04-01 23:07:00 +00:00
|
|
|
mValue.mArray = aValue;
|
|
|
|
mValue.mArray->AddRef();
|
|
|
|
}
|
|
|
|
|
2012-08-24 17:50:49 +00:00
|
|
|
void nsCSSValue::SetURLValue(mozilla::css::URLValue* aValue)
|
2003-10-01 22:53:56 +00:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_URL;
|
|
|
|
mValue.mURL = aValue;
|
2003-10-30 01:45:37 +00:00
|
|
|
mValue.mURL->AddRef();
|
2003-10-01 22:53:56 +00:00
|
|
|
}
|
|
|
|
|
2012-08-24 17:50:49 +00:00
|
|
|
void nsCSSValue::SetImageValue(mozilla::css::ImageValue* aValue)
|
2004-03-09 03:57:51 +00:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Image;
|
|
|
|
mValue.mImage = aValue;
|
|
|
|
mValue.mImage->AddRef();
|
|
|
|
}
|
|
|
|
|
2009-08-01 15:53:40 +00:00
|
|
|
void nsCSSValue::SetGradientValue(nsCSSValueGradient* aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Gradient;
|
|
|
|
mValue.mGradient = aValue;
|
|
|
|
mValue.mGradient->AddRef();
|
|
|
|
}
|
|
|
|
|
2013-12-12 02:09:42 +00:00
|
|
|
void nsCSSValue::SetTokenStreamValue(nsCSSValueTokenStream* aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_TokenStream;
|
|
|
|
mValue.mTokenStream = aValue;
|
|
|
|
mValue.mTokenStream->AddRef();
|
|
|
|
}
|
|
|
|
|
2010-08-19 19:33:44 +00:00
|
|
|
void nsCSSValue::SetPairValue(const nsCSSValuePair* aValue)
|
|
|
|
{
|
|
|
|
// pairs should not be used for null/inherit/initial values
|
|
|
|
NS_ABORT_IF_FALSE(aValue &&
|
|
|
|
aValue->mXValue.GetUnit() != eCSSUnit_Null &&
|
|
|
|
aValue->mYValue.GetUnit() != eCSSUnit_Null &&
|
|
|
|
aValue->mXValue.GetUnit() != eCSSUnit_Inherit &&
|
|
|
|
aValue->mYValue.GetUnit() != eCSSUnit_Inherit &&
|
|
|
|
aValue->mXValue.GetUnit() != eCSSUnit_Initial &&
|
2013-10-03 18:49:17 +00:00
|
|
|
aValue->mYValue.GetUnit() != eCSSUnit_Initial &&
|
|
|
|
aValue->mXValue.GetUnit() != eCSSUnit_Unset &&
|
|
|
|
aValue->mYValue.GetUnit() != eCSSUnit_Unset,
|
2010-08-19 19:33:44 +00:00
|
|
|
"missing or inappropriate pair value");
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Pair;
|
|
|
|
mValue.mPair = new nsCSSValuePair_heap(aValue->mXValue, aValue->mYValue);
|
|
|
|
mValue.mPair->AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetPairValue(const nsCSSValue& xValue,
|
|
|
|
const nsCSSValue& yValue)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(xValue.GetUnit() != eCSSUnit_Null &&
|
|
|
|
yValue.GetUnit() != eCSSUnit_Null &&
|
|
|
|
xValue.GetUnit() != eCSSUnit_Inherit &&
|
|
|
|
yValue.GetUnit() != eCSSUnit_Inherit &&
|
|
|
|
xValue.GetUnit() != eCSSUnit_Initial &&
|
2013-10-03 18:49:17 +00:00
|
|
|
yValue.GetUnit() != eCSSUnit_Initial &&
|
|
|
|
xValue.GetUnit() != eCSSUnit_Unset &&
|
|
|
|
yValue.GetUnit() != eCSSUnit_Unset,
|
2010-08-19 19:33:44 +00:00
|
|
|
"inappropriate pair value");
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Pair;
|
|
|
|
mValue.mPair = new nsCSSValuePair_heap(xValue, yValue);
|
|
|
|
mValue.mPair->AddRef();
|
|
|
|
}
|
|
|
|
|
2011-08-03 03:04:23 +00:00
|
|
|
void nsCSSValue::SetTripletValue(const nsCSSValueTriplet* aValue)
|
|
|
|
{
|
|
|
|
// triplet should not be used for null/inherit/initial values
|
|
|
|
NS_ABORT_IF_FALSE(aValue &&
|
|
|
|
aValue->mXValue.GetUnit() != eCSSUnit_Null &&
|
|
|
|
aValue->mYValue.GetUnit() != eCSSUnit_Null &&
|
2012-07-21 23:48:19 +00:00
|
|
|
aValue->mZValue.GetUnit() != eCSSUnit_Null &&
|
2011-08-03 03:04:23 +00:00
|
|
|
aValue->mXValue.GetUnit() != eCSSUnit_Inherit &&
|
|
|
|
aValue->mYValue.GetUnit() != eCSSUnit_Inherit &&
|
|
|
|
aValue->mZValue.GetUnit() != eCSSUnit_Inherit &&
|
|
|
|
aValue->mXValue.GetUnit() != eCSSUnit_Initial &&
|
|
|
|
aValue->mYValue.GetUnit() != eCSSUnit_Initial &&
|
2013-10-03 18:49:17 +00:00
|
|
|
aValue->mZValue.GetUnit() != eCSSUnit_Initial &&
|
|
|
|
aValue->mXValue.GetUnit() != eCSSUnit_Unset &&
|
|
|
|
aValue->mYValue.GetUnit() != eCSSUnit_Unset &&
|
|
|
|
aValue->mZValue.GetUnit() != eCSSUnit_Unset,
|
2011-08-03 03:04:23 +00:00
|
|
|
"missing or inappropriate triplet value");
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Triplet;
|
|
|
|
mValue.mTriplet = new nsCSSValueTriplet_heap(aValue->mXValue, aValue->mYValue, aValue->mZValue);
|
|
|
|
mValue.mTriplet->AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetTripletValue(const nsCSSValue& xValue,
|
|
|
|
const nsCSSValue& yValue,
|
|
|
|
const nsCSSValue& zValue)
|
|
|
|
{
|
|
|
|
// Only allow Null for the z component
|
|
|
|
NS_ABORT_IF_FALSE(xValue.GetUnit() != eCSSUnit_Null &&
|
|
|
|
yValue.GetUnit() != eCSSUnit_Null &&
|
|
|
|
xValue.GetUnit() != eCSSUnit_Inherit &&
|
|
|
|
yValue.GetUnit() != eCSSUnit_Inherit &&
|
|
|
|
zValue.GetUnit() != eCSSUnit_Inherit &&
|
|
|
|
xValue.GetUnit() != eCSSUnit_Initial &&
|
|
|
|
yValue.GetUnit() != eCSSUnit_Initial &&
|
2013-10-03 18:49:17 +00:00
|
|
|
zValue.GetUnit() != eCSSUnit_Initial &&
|
|
|
|
xValue.GetUnit() != eCSSUnit_Unset &&
|
|
|
|
yValue.GetUnit() != eCSSUnit_Unset &&
|
|
|
|
zValue.GetUnit() != eCSSUnit_Unset,
|
2011-08-03 03:04:23 +00:00
|
|
|
"inappropriate triplet value");
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Triplet;
|
|
|
|
mValue.mTriplet = new nsCSSValueTriplet_heap(xValue, yValue, zValue);
|
|
|
|
mValue.mTriplet->AddRef();
|
|
|
|
}
|
|
|
|
|
2010-08-19 19:33:44 +00:00
|
|
|
nsCSSRect& nsCSSValue::SetRectValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Rect;
|
|
|
|
mValue.mRect = new nsCSSRect_heap;
|
|
|
|
mValue.mRect->AddRef();
|
|
|
|
return *mValue.mRect;
|
|
|
|
}
|
|
|
|
|
2010-08-19 19:33:44 +00:00
|
|
|
nsCSSValueList* nsCSSValue::SetListValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_List;
|
|
|
|
mValue.mList = new nsCSSValueList_heap;
|
|
|
|
mValue.mList->AddRef();
|
|
|
|
return mValue.mList;
|
|
|
|
}
|
|
|
|
|
2013-12-12 02:09:44 +00:00
|
|
|
void nsCSSValue::SetSharedListValue(nsCSSValueSharedList* aList)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_SharedList;
|
|
|
|
mValue.mSharedList = aList;
|
|
|
|
mValue.mSharedList->AddRef();
|
|
|
|
}
|
|
|
|
|
2010-08-19 19:33:44 +00:00
|
|
|
void nsCSSValue::SetDependentListValue(nsCSSValueList* aList)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
if (aList) {
|
|
|
|
mUnit = eCSSUnit_ListDep;
|
|
|
|
mValue.mListDependent = aList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-19 19:33:44 +00:00
|
|
|
nsCSSValuePairList* nsCSSValue::SetPairListValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_PairList;
|
|
|
|
mValue.mPairList = new nsCSSValuePairList_heap;
|
|
|
|
mValue.mPairList->AddRef();
|
|
|
|
return mValue.mPairList;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetDependentPairListValue(nsCSSValuePairList* aList)
|
|
|
|
{
|
|
|
|
Reset();
|
2010-08-19 19:33:44 +00:00
|
|
|
if (aList) {
|
|
|
|
mUnit = eCSSUnit_PairListDep;
|
|
|
|
mValue.mPairListDependent = aList;
|
|
|
|
}
|
2010-08-19 19:33:44 +00:00
|
|
|
}
|
|
|
|
|
2003-12-29 19:07:53 +00:00
|
|
|
void nsCSSValue::SetAutoValue()
|
1998-10-08 01:29:29 +00:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Auto;
|
|
|
|
}
|
|
|
|
|
2003-12-29 19:07:53 +00:00
|
|
|
void nsCSSValue::SetInheritValue()
|
1998-10-08 01:29:29 +00:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Inherit;
|
|
|
|
}
|
|
|
|
|
2003-12-29 19:07:53 +00:00
|
|
|
void nsCSSValue::SetInitialValue()
|
2001-05-31 22:19:43 +00:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Initial;
|
|
|
|
}
|
|
|
|
|
2013-10-03 18:49:17 +00:00
|
|
|
void nsCSSValue::SetUnsetValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Unset;
|
|
|
|
}
|
|
|
|
|
2003-12-29 19:07:53 +00:00
|
|
|
void nsCSSValue::SetNoneValue()
|
1998-10-08 01:29:29 +00:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_None;
|
|
|
|
}
|
|
|
|
|
2009-08-20 21:52:47 +00:00
|
|
|
void nsCSSValue::SetAllValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_All;
|
|
|
|
}
|
|
|
|
|
2003-12-29 19:07:53 +00:00
|
|
|
void nsCSSValue::SetNormalValue()
|
1998-10-08 01:29:29 +00:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Normal;
|
|
|
|
}
|
|
|
|
|
2007-06-12 18:28:56 +00:00
|
|
|
void nsCSSValue::SetSystemFontValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_System_Font;
|
|
|
|
}
|
|
|
|
|
2007-10-08 23:11:01 +00:00
|
|
|
void nsCSSValue::SetDummyValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Dummy;
|
|
|
|
}
|
|
|
|
|
2008-10-07 18:53:22 +00:00
|
|
|
void nsCSSValue::SetDummyInheritValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_DummyInherit;
|
|
|
|
}
|
|
|
|
|
2007-07-03 13:59:02 +00:00
|
|
|
void nsCSSValue::StartImageLoad(nsIDocument* aDocument) const
|
2004-03-09 03:57:51 +00:00
|
|
|
{
|
2010-08-19 19:33:44 +00:00
|
|
|
NS_ABORT_IF_FALSE(eCSSUnit_URL == mUnit, "Not a URL value!");
|
2012-08-24 17:50:49 +00:00
|
|
|
mozilla::css::ImageValue* image =
|
|
|
|
new mozilla::css::ImageValue(mValue.mURL->GetURI(),
|
|
|
|
mValue.mURL->mString,
|
|
|
|
mValue.mURL->mReferrer,
|
|
|
|
mValue.mURL->mOriginPrincipal,
|
|
|
|
aDocument);
|
2004-03-09 03:57:51 +00:00
|
|
|
if (image) {
|
2007-07-08 07:08:04 +00:00
|
|
|
nsCSSValue* writable = const_cast<nsCSSValue*>(this);
|
2006-12-13 15:49:36 +00:00
|
|
|
writable->SetImageValue(image);
|
2004-03-09 03:57:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-15 23:35:48 +00:00
|
|
|
nscolor nsCSSValue::GetColorValue() const
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(IsNumericColorUnit(), "not a color value");
|
|
|
|
if (IsFloatColorUnit()) {
|
|
|
|
return mValue.mFloatColor->GetColorValue(mUnit);
|
|
|
|
}
|
|
|
|
return mValue.mColor;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool nsCSSValue::IsNonTransparentColor() const
|
2009-06-16 22:05:12 +00:00
|
|
|
{
|
|
|
|
// We have the value in the form it was specified in at this point, so we
|
|
|
|
// have to look for both the keyword 'transparent' and its equivalent in
|
|
|
|
// rgba notation.
|
|
|
|
nsDependentString buf;
|
|
|
|
return
|
2013-09-15 23:35:48 +00:00
|
|
|
(IsIntegerColorUnit() && NS_GET_A(GetColorValue()) > 0) ||
|
|
|
|
(IsFloatColorUnit() && mValue.mFloatColor->IsNonTransparentColor()) ||
|
2009-06-16 22:05:12 +00:00
|
|
|
(mUnit == eCSSUnit_Ident &&
|
|
|
|
!nsGkAtoms::transparent->Equals(GetStringValue(buf))) ||
|
|
|
|
(mUnit == eCSSUnit_EnumColor);
|
|
|
|
}
|
|
|
|
|
2009-08-21 20:39:25 +00:00
|
|
|
nsCSSValue::Array*
|
2012-08-22 15:56:38 +00:00
|
|
|
nsCSSValue::InitFunction(nsCSSKeyword aFunctionId, uint32_t aNumArgs)
|
2009-08-21 20:39:25 +00:00
|
|
|
{
|
|
|
|
nsRefPtr<nsCSSValue::Array> func = Array::Create(aNumArgs + 1);
|
|
|
|
func->Item(0).SetIntValue(aFunctionId, eCSSUnit_Enumerated);
|
|
|
|
SetArrayValue(func, eCSSUnit_Function);
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2009-08-21 20:39:25 +00:00
|
|
|
nsCSSValue::EqualsFunction(nsCSSKeyword aFunctionId) const
|
|
|
|
{
|
|
|
|
if (mUnit != eCSSUnit_Function) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-08-21 20:39:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue::Array* func = mValue.mArray;
|
|
|
|
NS_ABORT_IF_FALSE(func && func->Count() >= 1 &&
|
|
|
|
func->Item(0).GetUnit() == eCSSUnit_Enumerated,
|
|
|
|
"illegally structured function value");
|
|
|
|
|
2013-05-23 01:08:29 +00:00
|
|
|
nsCSSKeyword thisFunctionId = func->Item(0).GetKeywordValue();
|
2009-08-21 20:39:25 +00:00
|
|
|
return thisFunctionId == aFunctionId;
|
|
|
|
}
|
|
|
|
|
2006-12-13 15:49:36 +00:00
|
|
|
// static
|
2010-12-05 13:17:29 +00:00
|
|
|
already_AddRefed<nsStringBuffer>
|
2006-12-13 15:49:36 +00:00
|
|
|
nsCSSValue::BufferFromString(const nsString& aValue)
|
|
|
|
{
|
2013-04-22 11:13:22 +00:00
|
|
|
nsRefPtr<nsStringBuffer> buffer = nsStringBuffer::FromString(aValue);
|
2006-12-13 15:49:36 +00:00
|
|
|
if (buffer) {
|
2013-04-22 11:13:22 +00:00
|
|
|
return buffer.forget();
|
2006-12-13 15:49:36 +00:00
|
|
|
}
|
2011-05-28 22:38:48 +00:00
|
|
|
|
2012-05-04 00:14:01 +00:00
|
|
|
nsString::size_type length = aValue.Length();
|
2010-12-05 13:17:29 +00:00
|
|
|
|
|
|
|
// NOTE: Alloc prouduces a new, already-addref'd (refcnt = 1) buffer.
|
2011-05-28 22:38:48 +00:00
|
|
|
// NOTE: String buffer allocation is currently fallible.
|
2014-01-04 15:02:17 +00:00
|
|
|
buffer = nsStringBuffer::Alloc((length + 1) * sizeof(char16_t));
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(!buffer)) {
|
2011-05-28 22:38:48 +00:00
|
|
|
NS_RUNTIMEABORT("out of memory");
|
2006-12-13 15:49:36 +00:00
|
|
|
}
|
|
|
|
|
2014-01-04 15:02:17 +00:00
|
|
|
char16_t* data = static_cast<char16_t*>(buffer->Data());
|
|
|
|
nsCharTraits<char16_t>::copy(data, aValue.get(), length);
|
2011-05-28 22:38:48 +00:00
|
|
|
// Null-terminate.
|
|
|
|
data[length] = 0;
|
2013-04-22 11:13:22 +00:00
|
|
|
return buffer.forget();
|
2006-12-13 15:49:36 +00:00
|
|
|
}
|
|
|
|
|
2010-07-23 18:00:27 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct CSSValueSerializeCalcOps {
|
2013-09-15 23:35:49 +00:00
|
|
|
CSSValueSerializeCalcOps(nsCSSProperty aProperty, nsAString& aResult,
|
|
|
|
nsCSSValue::Serialization aSerialization)
|
2010-07-23 18:00:27 +00:00
|
|
|
: mProperty(aProperty),
|
2013-09-15 23:35:49 +00:00
|
|
|
mResult(aResult),
|
|
|
|
mValueSerialization(aSerialization)
|
2010-07-23 18:00:27 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef nsCSSValue input_type;
|
|
|
|
typedef nsCSSValue::Array input_array_type;
|
|
|
|
|
|
|
|
static nsCSSUnit GetUnit(const input_type& aValue) {
|
|
|
|
return aValue.GetUnit();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Append(const char* aString)
|
|
|
|
{
|
|
|
|
mResult.AppendASCII(aString);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppendLeafValue(const input_type& aValue)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aValue.GetUnit() == eCSSUnit_Percent ||
|
|
|
|
aValue.IsLengthUnit(), "unexpected unit");
|
2013-09-15 23:35:49 +00:00
|
|
|
aValue.AppendToString(mProperty, mResult, mValueSerialization);
|
2010-07-23 18:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppendNumber(const input_type& aValue)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aValue.GetUnit() == eCSSUnit_Number, "unexpected unit");
|
2013-09-15 23:35:49 +00:00
|
|
|
aValue.AppendToString(mProperty, mResult, mValueSerialization);
|
2010-07-23 18:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCSSProperty mProperty;
|
|
|
|
nsAString &mResult;
|
2013-09-15 23:35:49 +00:00
|
|
|
nsCSSValue::Serialization mValueSerialization;
|
2010-07-23 18:00:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
void
|
2013-09-15 23:35:49 +00:00
|
|
|
nsCSSValue::AppendToString(nsCSSProperty aProperty, nsAString& aResult,
|
|
|
|
Serialization aSerialization) const
|
2010-07-23 18:00:27 +00:00
|
|
|
{
|
|
|
|
// eCSSProperty_UNKNOWN gets used for some recursive calls below.
|
|
|
|
NS_ABORT_IF_FALSE((0 <= aProperty &&
|
|
|
|
aProperty <= eCSSProperty_COUNT_no_shorthands) ||
|
|
|
|
aProperty == eCSSProperty_UNKNOWN,
|
|
|
|
"property ID out of range");
|
|
|
|
|
|
|
|
nsCSSUnit unit = GetUnit();
|
|
|
|
if (unit == eCSSUnit_Null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eCSSUnit_String <= unit && unit <= eCSSUnit_Attr) {
|
|
|
|
if (unit == eCSSUnit_Attr) {
|
|
|
|
aResult.AppendLiteral("attr(");
|
|
|
|
}
|
|
|
|
nsAutoString buffer;
|
|
|
|
GetStringValue(buffer);
|
|
|
|
if (unit == eCSSUnit_String) {
|
|
|
|
nsStyleUtil::AppendEscapedCSSString(buffer, aResult);
|
|
|
|
} else if (unit == eCSSUnit_Families) {
|
|
|
|
// XXX We really need to do *some* escaping.
|
|
|
|
aResult.Append(buffer);
|
|
|
|
} else {
|
|
|
|
nsStyleUtil::AppendEscapedCSSIdent(buffer, aResult);
|
|
|
|
}
|
|
|
|
}
|
2011-04-12 06:18:42 +00:00
|
|
|
else if (eCSSUnit_Array <= unit && unit <= eCSSUnit_Steps) {
|
2010-07-23 18:00:27 +00:00
|
|
|
switch (unit) {
|
|
|
|
case eCSSUnit_Counter: aResult.AppendLiteral("counter("); break;
|
|
|
|
case eCSSUnit_Counters: aResult.AppendLiteral("counters("); break;
|
|
|
|
case eCSSUnit_Cubic_Bezier: aResult.AppendLiteral("cubic-bezier("); break;
|
2011-04-12 06:18:42 +00:00
|
|
|
case eCSSUnit_Steps: aResult.AppendLiteral("steps("); break;
|
2010-07-23 18:00:27 +00:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue::Array *array = GetArrayValue();
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mark = false;
|
2010-07-23 18:00:27 +00:00
|
|
|
for (size_t i = 0, i_end = array->Count(); i < i_end; ++i) {
|
|
|
|
if (mark && array->Item(i).GetUnit() != eCSSUnit_Null) {
|
|
|
|
if (unit == eCSSUnit_Array &&
|
|
|
|
eCSSProperty_transition_timing_function != aProperty)
|
|
|
|
aResult.AppendLiteral(" ");
|
|
|
|
else
|
|
|
|
aResult.AppendLiteral(", ");
|
|
|
|
}
|
2011-04-12 06:18:42 +00:00
|
|
|
if (unit == eCSSUnit_Steps && i == 1) {
|
|
|
|
NS_ABORT_IF_FALSE(array->Item(i).GetUnit() == eCSSUnit_Enumerated &&
|
|
|
|
(array->Item(i).GetIntValue() ==
|
|
|
|
NS_STYLE_TRANSITION_TIMING_FUNCTION_STEP_START ||
|
|
|
|
array->Item(i).GetIntValue() ==
|
|
|
|
NS_STYLE_TRANSITION_TIMING_FUNCTION_STEP_END),
|
|
|
|
"unexpected value");
|
|
|
|
if (array->Item(i).GetIntValue() ==
|
|
|
|
NS_STYLE_TRANSITION_TIMING_FUNCTION_STEP_START) {
|
|
|
|
aResult.AppendLiteral("start");
|
|
|
|
} else {
|
|
|
|
aResult.AppendLiteral("end");
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2010-07-23 18:00:27 +00:00
|
|
|
nsCSSProperty prop =
|
|
|
|
((eCSSUnit_Counter <= unit && unit <= eCSSUnit_Counters) &&
|
|
|
|
i == array->Count() - 1)
|
|
|
|
? eCSSProperty_list_style_type : aProperty;
|
|
|
|
if (array->Item(i).GetUnit() != eCSSUnit_Null) {
|
2013-09-15 23:35:49 +00:00
|
|
|
array->Item(i).AppendToString(prop, aResult, aSerialization);
|
2011-10-17 14:59:28 +00:00
|
|
|
mark = true;
|
2010-07-23 18:00:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (eCSSUnit_Array == unit &&
|
|
|
|
aProperty == eCSSProperty_transition_timing_function) {
|
|
|
|
aResult.AppendLiteral(")");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Although Function is backed by an Array, we'll handle it separately
|
|
|
|
* because it's a bit quirky.
|
|
|
|
*/
|
|
|
|
else if (eCSSUnit_Function == unit) {
|
|
|
|
const nsCSSValue::Array* array = GetArrayValue();
|
2010-08-19 19:33:44 +00:00
|
|
|
NS_ABORT_IF_FALSE(array->Count() >= 1,
|
|
|
|
"Functions must have at least one element for the name.");
|
2010-07-23 18:00:27 +00:00
|
|
|
|
|
|
|
/* Append the function name. */
|
|
|
|
const nsCSSValue& functionName = array->Item(0);
|
|
|
|
if (functionName.GetUnit() == eCSSUnit_Enumerated) {
|
|
|
|
// We assume that the first argument is always of nsCSSKeyword type.
|
2013-05-23 01:08:29 +00:00
|
|
|
const nsCSSKeyword functionId = functionName.GetKeywordValue();
|
|
|
|
NS_ConvertASCIItoUTF16 ident(nsCSSKeywords::GetStringValue(functionId));
|
|
|
|
// Bug 721136: Normalize the identifier to lowercase, except that things
|
|
|
|
// like scaleX should have the last character capitalized. This matches
|
|
|
|
// what other browsers do.
|
|
|
|
switch (functionId) {
|
|
|
|
case eCSSKeyword_rotatex:
|
|
|
|
case eCSSKeyword_scalex:
|
|
|
|
case eCSSKeyword_skewx:
|
|
|
|
case eCSSKeyword_translatex:
|
2014-01-04 15:02:17 +00:00
|
|
|
ident.Replace(ident.Length() - 1, 1, char16_t('X'));
|
2013-05-23 01:08:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSKeyword_rotatey:
|
|
|
|
case eCSSKeyword_scaley:
|
|
|
|
case eCSSKeyword_skewy:
|
|
|
|
case eCSSKeyword_translatey:
|
2014-01-04 15:02:17 +00:00
|
|
|
ident.Replace(ident.Length() - 1, 1, char16_t('Y'));
|
2013-05-23 01:08:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSKeyword_rotatez:
|
|
|
|
case eCSSKeyword_scalez:
|
|
|
|
case eCSSKeyword_translatez:
|
2014-01-04 15:02:17 +00:00
|
|
|
ident.Replace(ident.Length() - 1, 1, char16_t('Z'));
|
2013-05-23 01:08:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nsStyleUtil::AppendEscapedCSSIdent(ident, aResult);
|
2010-07-23 18:00:27 +00:00
|
|
|
} else {
|
2013-05-23 01:08:29 +00:00
|
|
|
MOZ_ASSERT(false, "should no longer have non-enumerated functions");
|
2010-07-23 18:00:27 +00:00
|
|
|
}
|
|
|
|
aResult.AppendLiteral("(");
|
|
|
|
|
|
|
|
/* Now, step through the function contents, writing each of them as we go. */
|
|
|
|
for (size_t index = 1; index < array->Count(); ++index) {
|
2013-09-15 23:35:49 +00:00
|
|
|
array->Item(index).AppendToString(aProperty, aResult,
|
|
|
|
aSerialization);
|
2010-07-23 18:00:27 +00:00
|
|
|
|
|
|
|
/* If we're not at the final element, append a comma. */
|
|
|
|
if (index + 1 != array->Count())
|
|
|
|
aResult.AppendLiteral(", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Finally, append the closing parenthesis. */
|
|
|
|
aResult.AppendLiteral(")");
|
|
|
|
}
|
|
|
|
else if (IsCalcUnit()) {
|
2010-09-11 16:27:12 +00:00
|
|
|
NS_ABORT_IF_FALSE(GetUnit() == eCSSUnit_Calc, "unexpected unit");
|
2013-09-15 23:35:49 +00:00
|
|
|
CSSValueSerializeCalcOps ops(aProperty, aResult, aSerialization);
|
2010-07-23 18:00:27 +00:00
|
|
|
css::SerializeCalc(*this, ops);
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_Integer == unit) {
|
2010-11-30 18:18:15 +00:00
|
|
|
aResult.AppendInt(GetIntValue(), 10);
|
2010-07-23 18:00:27 +00:00
|
|
|
}
|
|
|
|
else if (eCSSUnit_Enumerated == unit) {
|
2013-05-20 02:59:20 +00:00
|
|
|
int32_t intValue = GetIntValue();
|
|
|
|
switch(aProperty) {
|
|
|
|
|
2013-08-19 10:26:44 +00:00
|
|
|
|
|
|
|
case eCSSProperty_text_combine_horizontal:
|
|
|
|
if (intValue <= NS_STYLE_TEXT_COMBINE_HORIZ_ALL) {
|
|
|
|
AppendASCIItoUTF16(nsCSSProps::LookupPropertyValue(aProperty, intValue),
|
|
|
|
aResult);
|
|
|
|
} else if (intValue == NS_STYLE_TEXT_COMBINE_HORIZ_DIGITS_2) {
|
|
|
|
aResult.AppendLiteral("digits 2");
|
|
|
|
} else if (intValue == NS_STYLE_TEXT_COMBINE_HORIZ_DIGITS_3) {
|
|
|
|
aResult.AppendLiteral("digits 3");
|
|
|
|
} else {
|
|
|
|
aResult.AppendLiteral("digits 4");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-05-20 02:59:20 +00:00
|
|
|
case eCSSProperty_text_decoration_line:
|
2011-04-23 05:16:41 +00:00
|
|
|
if (NS_STYLE_TEXT_DECORATION_LINE_NONE == intValue) {
|
2010-07-23 18:00:27 +00:00
|
|
|
AppendASCIItoUTF16(nsCSSProps::LookupPropertyValue(aProperty, intValue),
|
|
|
|
aResult);
|
|
|
|
} else {
|
|
|
|
// Ignore the "override all" internal value.
|
|
|
|
// (It doesn't have a string representation.)
|
2011-04-23 05:16:41 +00:00
|
|
|
intValue &= ~NS_STYLE_TEXT_DECORATION_LINE_OVERRIDE_ALL;
|
2010-07-23 18:00:27 +00:00
|
|
|
nsStyleUtil::AppendBitmaskCSSValue(
|
|
|
|
aProperty, intValue,
|
2011-04-23 05:16:41 +00:00
|
|
|
NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE,
|
|
|
|
NS_STYLE_TEXT_DECORATION_LINE_PREF_ANCHORS,
|
2010-07-23 18:00:27 +00:00
|
|
|
aResult);
|
|
|
|
}
|
2013-05-20 02:59:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSProperty_marks:
|
2010-07-23 18:00:27 +00:00
|
|
|
if (intValue == NS_STYLE_PAGE_MARKS_NONE) {
|
|
|
|
AppendASCIItoUTF16(nsCSSProps::LookupPropertyValue(aProperty, intValue),
|
|
|
|
aResult);
|
|
|
|
} else {
|
|
|
|
nsStyleUtil::AppendBitmaskCSSValue(aProperty, intValue,
|
|
|
|
NS_STYLE_PAGE_MARKS_CROP,
|
|
|
|
NS_STYLE_PAGE_MARKS_REGISTER,
|
|
|
|
aResult);
|
|
|
|
}
|
2013-05-20 02:59:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSProperty_paint_order:
|
2013-07-18 17:59:53 +00:00
|
|
|
static_assert
|
2013-01-12 23:27:53 +00:00
|
|
|
(NS_STYLE_PAINT_ORDER_BITWIDTH * NS_STYLE_PAINT_ORDER_LAST_VALUE <= 8,
|
|
|
|
"SVGStyleStruct::mPaintOrder and the following cast not big enough");
|
|
|
|
nsStyleUtil::AppendPaintOrderValue(static_cast<uint8_t>(GetIntValue()),
|
|
|
|
aResult);
|
2013-05-20 02:59:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSProperty_font_synthesis:
|
|
|
|
nsStyleUtil::AppendBitmaskCSSValue(aProperty, intValue,
|
|
|
|
NS_FONT_SYNTHESIS_WEIGHT,
|
|
|
|
NS_FONT_SYNTHESIS_STYLE,
|
|
|
|
aResult);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSProperty_font_variant_east_asian:
|
|
|
|
nsStyleUtil::AppendBitmaskCSSValue(aProperty, intValue,
|
|
|
|
NS_FONT_VARIANT_EAST_ASIAN_JIS78,
|
|
|
|
NS_FONT_VARIANT_EAST_ASIAN_RUBY,
|
|
|
|
aResult);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSProperty_font_variant_ligatures:
|
|
|
|
nsStyleUtil::AppendBitmaskCSSValue(aProperty, intValue,
|
2013-11-19 04:30:25 +00:00
|
|
|
NS_FONT_VARIANT_LIGATURES_NONE,
|
2013-05-20 02:59:20 +00:00
|
|
|
NS_FONT_VARIANT_LIGATURES_NO_CONTEXTUAL,
|
|
|
|
aResult);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSProperty_font_variant_numeric:
|
|
|
|
nsStyleUtil::AppendBitmaskCSSValue(aProperty, intValue,
|
|
|
|
NS_FONT_VARIANT_NUMERIC_LINING,
|
|
|
|
NS_FONT_VARIANT_NUMERIC_ORDINAL,
|
|
|
|
aResult);
|
|
|
|
break;
|
|
|
|
|
2014-01-15 15:03:15 +00:00
|
|
|
case eCSSProperty_touch_action:
|
|
|
|
nsStyleUtil::AppendBitmaskCSSValue(aProperty, intValue,
|
|
|
|
NS_STYLE_TOUCH_ACTION_PAN_X,
|
|
|
|
NS_STYLE_TOUCH_ACTION_PAN_Y,
|
|
|
|
aResult);
|
|
|
|
break;
|
|
|
|
|
2013-05-20 02:59:20 +00:00
|
|
|
default:
|
|
|
|
const nsAFlatCString& name = nsCSSProps::LookupPropertyValue(aProperty, intValue);
|
2010-07-23 18:00:27 +00:00
|
|
|
AppendASCIItoUTF16(name, aResult);
|
2013-05-20 02:59:20 +00:00
|
|
|
break;
|
2010-07-23 18:00:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_EnumColor == unit) {
|
|
|
|
// we can lookup the property in the ColorTable and then
|
|
|
|
// get a string mapping the name
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString str;
|
2010-07-23 18:00:27 +00:00
|
|
|
if (nsCSSProps::GetColorName(GetIntValue(), str)){
|
|
|
|
AppendASCIItoUTF16(str, aResult);
|
|
|
|
} else {
|
2010-08-19 19:33:44 +00:00
|
|
|
NS_ABORT_IF_FALSE(false, "bad color value");
|
2010-07-23 18:00:27 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-15 23:35:48 +00:00
|
|
|
else if (IsNumericColorUnit(unit)) {
|
2013-09-15 23:35:49 +00:00
|
|
|
if (aSerialization == eNormalized ||
|
|
|
|
unit == eCSSUnit_RGBColor ||
|
|
|
|
unit == eCSSUnit_RGBAColor) {
|
|
|
|
nscolor color = GetColorValue();
|
|
|
|
if (aSerialization == eNormalized &&
|
|
|
|
color == NS_RGBA(0, 0, 0, 0)) {
|
|
|
|
// Use the strictest match for 'transparent' so we do correct
|
|
|
|
// round-tripping of all other rgba() values.
|
|
|
|
aResult.AppendLiteral("transparent");
|
2010-07-23 18:00:27 +00:00
|
|
|
} else {
|
2013-09-15 23:35:49 +00:00
|
|
|
uint8_t a = NS_GET_A(color);
|
|
|
|
bool showAlpha =
|
|
|
|
(aSerialization == eNormalized && a < 255) ||
|
|
|
|
(aSerialization == eAuthorSpecified &&
|
|
|
|
unit == eCSSUnit_RGBAColor);
|
|
|
|
if (showAlpha) {
|
|
|
|
aResult.AppendLiteral("rgba(");
|
|
|
|
} else {
|
|
|
|
aResult.AppendLiteral("rgb(");
|
|
|
|
}
|
2010-07-23 18:00:27 +00:00
|
|
|
|
2013-09-15 23:35:49 +00:00
|
|
|
NS_NAMED_LITERAL_STRING(comma, ", ");
|
2010-07-23 18:00:27 +00:00
|
|
|
|
2013-09-15 23:35:49 +00:00
|
|
|
aResult.AppendInt(NS_GET_R(color), 10);
|
|
|
|
aResult.Append(comma);
|
|
|
|
aResult.AppendInt(NS_GET_G(color), 10);
|
2010-11-30 18:18:15 +00:00
|
|
|
aResult.Append(comma);
|
2013-09-15 23:35:49 +00:00
|
|
|
aResult.AppendInt(NS_GET_B(color), 10);
|
|
|
|
if (showAlpha) {
|
|
|
|
aResult.Append(comma);
|
|
|
|
aResult.AppendFloat(nsStyleUtil::ColorComponentToFloat(a));
|
|
|
|
}
|
2014-01-04 15:02:17 +00:00
|
|
|
aResult.Append(char16_t(')'));
|
2010-07-23 18:00:27 +00:00
|
|
|
}
|
2013-09-15 23:35:49 +00:00
|
|
|
} else if (eCSSUnit_HexColor == unit) {
|
|
|
|
nscolor color = GetColorValue();
|
|
|
|
aResult.Append('#');
|
|
|
|
aResult.AppendPrintf("%02x", NS_GET_R(color));
|
|
|
|
aResult.AppendPrintf("%02x", NS_GET_G(color));
|
|
|
|
aResult.AppendPrintf("%02x", NS_GET_B(color));
|
|
|
|
} else if (eCSSUnit_ShortHexColor == unit) {
|
|
|
|
nscolor color = GetColorValue();
|
|
|
|
aResult.Append('#');
|
|
|
|
aResult.AppendInt(NS_GET_R(color) / 0x11, 16);
|
|
|
|
aResult.AppendInt(NS_GET_G(color) / 0x11, 16);
|
|
|
|
aResult.AppendInt(NS_GET_B(color) / 0x11, 16);
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(IsFloatColorUnit());
|
|
|
|
mValue.mFloatColor->AppendToString(unit, aResult);
|
2010-07-23 18:00:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_URL == unit || eCSSUnit_Image == unit) {
|
|
|
|
aResult.Append(NS_LITERAL_STRING("url("));
|
|
|
|
nsStyleUtil::AppendEscapedCSSString(
|
|
|
|
nsDependentString(GetOriginalURLValue()), aResult);
|
|
|
|
aResult.Append(NS_LITERAL_STRING(")"));
|
|
|
|
}
|
2010-08-13 13:33:37 +00:00
|
|
|
else if (eCSSUnit_Element == unit) {
|
|
|
|
aResult.Append(NS_LITERAL_STRING("-moz-element(#"));
|
|
|
|
nsAutoString tmpStr;
|
|
|
|
GetStringValue(tmpStr);
|
2011-09-15 07:40:17 +00:00
|
|
|
nsStyleUtil::AppendEscapedCSSIdent(tmpStr, aResult);
|
2010-08-13 13:33:37 +00:00
|
|
|
aResult.Append(NS_LITERAL_STRING(")"));
|
|
|
|
}
|
2010-07-23 18:00:27 +00:00
|
|
|
else if (eCSSUnit_Percent == unit) {
|
2010-11-30 18:18:15 +00:00
|
|
|
aResult.AppendFloat(GetPercentValue() * 100.0f);
|
2010-07-23 18:00:27 +00:00
|
|
|
}
|
|
|
|
else if (eCSSUnit_Percent < unit) { // length unit
|
2010-11-30 18:18:15 +00:00
|
|
|
aResult.AppendFloat(GetFloatValue());
|
2010-07-23 18:00:27 +00:00
|
|
|
}
|
|
|
|
else if (eCSSUnit_Gradient == unit) {
|
|
|
|
nsCSSValueGradient* gradient = GetGradientValue();
|
|
|
|
|
2012-07-07 14:27:09 +00:00
|
|
|
if (gradient->mIsLegacySyntax) {
|
|
|
|
aResult.AppendLiteral("-moz-");
|
|
|
|
}
|
2010-07-23 18:00:27 +00:00
|
|
|
if (gradient->mIsRepeating) {
|
2012-07-07 14:27:09 +00:00
|
|
|
aResult.AppendLiteral("repeating-");
|
|
|
|
}
|
|
|
|
if (gradient->mIsRadial) {
|
|
|
|
aResult.AppendLiteral("radial-gradient(");
|
2010-07-23 18:00:27 +00:00
|
|
|
} else {
|
2012-07-07 14:27:09 +00:00
|
|
|
aResult.AppendLiteral("linear-gradient(");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool needSep = false;
|
|
|
|
if (gradient->mIsRadial && !gradient->mIsLegacySyntax) {
|
|
|
|
if (!gradient->mIsExplicitSize) {
|
|
|
|
if (gradient->GetRadialShape().GetUnit() != eCSSUnit_None) {
|
|
|
|
NS_ABORT_IF_FALSE(gradient->GetRadialShape().GetUnit() ==
|
|
|
|
eCSSUnit_Enumerated,
|
|
|
|
"bad unit for radial gradient shape");
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t intValue = gradient->GetRadialShape().GetIntValue();
|
2012-07-07 14:27:09 +00:00
|
|
|
NS_ABORT_IF_FALSE(intValue != NS_STYLE_GRADIENT_SHAPE_LINEAR,
|
|
|
|
"radial gradient with linear shape?!");
|
|
|
|
AppendASCIItoUTF16(nsCSSProps::ValueToKeyword(intValue,
|
|
|
|
nsCSSProps::kRadialGradientShapeKTable),
|
|
|
|
aResult);
|
|
|
|
needSep = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gradient->GetRadialSize().GetUnit() != eCSSUnit_None) {
|
|
|
|
if (needSep) {
|
|
|
|
aResult.AppendLiteral(" ");
|
|
|
|
}
|
|
|
|
NS_ABORT_IF_FALSE(gradient->GetRadialSize().GetUnit() ==
|
|
|
|
eCSSUnit_Enumerated,
|
|
|
|
"bad unit for radial gradient size");
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t intValue = gradient->GetRadialSize().GetIntValue();
|
2012-07-07 14:27:09 +00:00
|
|
|
AppendASCIItoUTF16(nsCSSProps::ValueToKeyword(intValue,
|
|
|
|
nsCSSProps::kRadialGradientSizeKTable),
|
|
|
|
aResult);
|
|
|
|
needSep = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NS_ABORT_IF_FALSE(gradient->GetRadiusX().GetUnit() != eCSSUnit_None,
|
|
|
|
"bad unit for radial gradient explicit size");
|
2013-09-15 23:35:49 +00:00
|
|
|
gradient->GetRadiusX().AppendToString(aProperty, aResult,
|
|
|
|
aSerialization);
|
2012-07-07 14:27:09 +00:00
|
|
|
if (gradient->GetRadiusY().GetUnit() != eCSSUnit_None) {
|
|
|
|
aResult.AppendLiteral(" ");
|
2013-09-15 23:35:49 +00:00
|
|
|
gradient->GetRadiusY().AppendToString(aProperty, aResult,
|
|
|
|
aSerialization);
|
2012-07-07 14:27:09 +00:00
|
|
|
}
|
|
|
|
needSep = true;
|
2011-10-22 19:41:11 +00:00
|
|
|
}
|
2012-07-07 14:27:09 +00:00
|
|
|
}
|
|
|
|
if (!gradient->mIsRadial && !gradient->mIsLegacySyntax) {
|
|
|
|
if (gradient->mBgPos.mXValue.GetUnit() != eCSSUnit_None ||
|
|
|
|
gradient->mBgPos.mYValue.GetUnit() != eCSSUnit_None) {
|
|
|
|
MOZ_ASSERT(gradient->mAngle.GetUnit() == eCSSUnit_None);
|
|
|
|
NS_ABORT_IF_FALSE(gradient->mBgPos.mXValue.GetUnit() == eCSSUnit_Enumerated &&
|
|
|
|
gradient->mBgPos.mYValue.GetUnit() == eCSSUnit_Enumerated,
|
|
|
|
"unexpected unit");
|
|
|
|
aResult.AppendLiteral("to");
|
|
|
|
if (!(gradient->mBgPos.mXValue.GetIntValue() & NS_STYLE_BG_POSITION_CENTER)) {
|
|
|
|
aResult.AppendLiteral(" ");
|
|
|
|
gradient->mBgPos.mXValue.AppendToString(eCSSProperty_background_position,
|
2013-09-15 23:35:49 +00:00
|
|
|
aResult, aSerialization);
|
2012-07-07 14:27:09 +00:00
|
|
|
}
|
|
|
|
if (!(gradient->mBgPos.mYValue.GetIntValue() & NS_STYLE_BG_POSITION_CENTER)) {
|
|
|
|
aResult.AppendLiteral(" ");
|
|
|
|
gradient->mBgPos.mYValue.AppendToString(eCSSProperty_background_position,
|
2013-09-15 23:35:49 +00:00
|
|
|
aResult, aSerialization);
|
2012-07-07 14:27:09 +00:00
|
|
|
}
|
|
|
|
needSep = true;
|
|
|
|
} else if (gradient->mAngle.GetUnit() != eCSSUnit_None) {
|
2013-09-15 23:35:49 +00:00
|
|
|
gradient->mAngle.AppendToString(aProperty, aResult, aSerialization);
|
2012-07-07 14:27:09 +00:00
|
|
|
needSep = true;
|
2011-10-22 19:41:11 +00:00
|
|
|
}
|
|
|
|
} else if (gradient->mBgPos.mXValue.GetUnit() != eCSSUnit_None ||
|
2010-08-19 19:33:43 +00:00
|
|
|
gradient->mBgPos.mYValue.GetUnit() != eCSSUnit_None ||
|
2010-07-23 18:00:27 +00:00
|
|
|
gradient->mAngle.GetUnit() != eCSSUnit_None) {
|
2012-07-07 14:27:09 +00:00
|
|
|
if (needSep) {
|
|
|
|
aResult.AppendLiteral(" ");
|
|
|
|
}
|
|
|
|
if (gradient->mIsRadial && !gradient->mIsLegacySyntax) {
|
|
|
|
aResult.AppendLiteral("at ");
|
|
|
|
}
|
2010-08-19 19:33:43 +00:00
|
|
|
if (gradient->mBgPos.mXValue.GetUnit() != eCSSUnit_None) {
|
|
|
|
gradient->mBgPos.mXValue.AppendToString(eCSSProperty_background_position,
|
2013-09-15 23:35:49 +00:00
|
|
|
aResult, aSerialization);
|
2010-07-23 18:00:27 +00:00
|
|
|
aResult.AppendLiteral(" ");
|
|
|
|
}
|
2010-08-19 19:33:43 +00:00
|
|
|
if (gradient->mBgPos.mXValue.GetUnit() != eCSSUnit_None) {
|
|
|
|
gradient->mBgPos.mYValue.AppendToString(eCSSProperty_background_position,
|
2013-09-15 23:35:49 +00:00
|
|
|
aResult, aSerialization);
|
2010-07-23 18:00:27 +00:00
|
|
|
aResult.AppendLiteral(" ");
|
|
|
|
}
|
|
|
|
if (gradient->mAngle.GetUnit() != eCSSUnit_None) {
|
2012-07-07 14:27:09 +00:00
|
|
|
NS_ABORT_IF_FALSE(gradient->mIsLegacySyntax,
|
|
|
|
"angle is allowed only for legacy syntax");
|
2013-09-15 23:35:49 +00:00
|
|
|
gradient->mAngle.AppendToString(aProperty, aResult, aSerialization);
|
2010-07-23 18:00:27 +00:00
|
|
|
}
|
2012-07-07 14:27:09 +00:00
|
|
|
needSep = true;
|
2010-07-23 18:00:27 +00:00
|
|
|
}
|
|
|
|
|
2012-07-07 14:27:09 +00:00
|
|
|
if (gradient->mIsRadial && gradient->mIsLegacySyntax &&
|
2012-07-07 14:27:08 +00:00
|
|
|
(gradient->GetRadialShape().GetUnit() != eCSSUnit_None ||
|
|
|
|
gradient->GetRadialSize().GetUnit() != eCSSUnit_None)) {
|
2012-07-07 14:27:09 +00:00
|
|
|
MOZ_ASSERT(!gradient->mIsExplicitSize);
|
|
|
|
if (needSep) {
|
|
|
|
aResult.AppendLiteral(", ");
|
|
|
|
}
|
2012-07-07 14:27:08 +00:00
|
|
|
if (gradient->GetRadialShape().GetUnit() != eCSSUnit_None) {
|
|
|
|
NS_ABORT_IF_FALSE(gradient->GetRadialShape().GetUnit() ==
|
2010-08-19 19:33:44 +00:00
|
|
|
eCSSUnit_Enumerated,
|
|
|
|
"bad unit for radial gradient shape");
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t intValue = gradient->GetRadialShape().GetIntValue();
|
2010-08-19 19:33:44 +00:00
|
|
|
NS_ABORT_IF_FALSE(intValue != NS_STYLE_GRADIENT_SHAPE_LINEAR,
|
|
|
|
"radial gradient with linear shape?!");
|
2010-07-23 18:00:27 +00:00
|
|
|
AppendASCIItoUTF16(nsCSSProps::ValueToKeyword(intValue,
|
|
|
|
nsCSSProps::kRadialGradientShapeKTable),
|
|
|
|
aResult);
|
|
|
|
aResult.AppendLiteral(" ");
|
|
|
|
}
|
|
|
|
|
2012-07-07 14:27:08 +00:00
|
|
|
if (gradient->GetRadialSize().GetUnit() != eCSSUnit_None) {
|
|
|
|
NS_ABORT_IF_FALSE(gradient->GetRadialSize().GetUnit() ==
|
2010-08-19 19:33:44 +00:00
|
|
|
eCSSUnit_Enumerated,
|
|
|
|
"bad unit for radial gradient size");
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t intValue = gradient->GetRadialSize().GetIntValue();
|
2010-07-23 18:00:27 +00:00
|
|
|
AppendASCIItoUTF16(nsCSSProps::ValueToKeyword(intValue,
|
|
|
|
nsCSSProps::kRadialGradientSizeKTable),
|
|
|
|
aResult);
|
|
|
|
}
|
2012-07-07 14:27:09 +00:00
|
|
|
needSep = true;
|
|
|
|
}
|
|
|
|
if (needSep) {
|
2010-07-23 18:00:27 +00:00
|
|
|
aResult.AppendLiteral(", ");
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0 ;;) {
|
2013-09-15 23:35:49 +00:00
|
|
|
gradient->mStops[i].mColor.AppendToString(aProperty, aResult,
|
|
|
|
aSerialization);
|
2010-07-23 18:00:27 +00:00
|
|
|
if (gradient->mStops[i].mLocation.GetUnit() != eCSSUnit_None) {
|
|
|
|
aResult.AppendLiteral(" ");
|
2013-09-15 23:35:49 +00:00
|
|
|
gradient->mStops[i].mLocation.AppendToString(aProperty, aResult,
|
|
|
|
aSerialization);
|
2010-07-23 18:00:27 +00:00
|
|
|
}
|
|
|
|
if (++i == gradient->mStops.Length()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
aResult.AppendLiteral(", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
aResult.AppendLiteral(")");
|
2013-12-12 02:09:42 +00:00
|
|
|
} else if (eCSSUnit_TokenStream == unit) {
|
|
|
|
nsCSSProperty shorthand = mValue.mTokenStream->mShorthandPropertyID;
|
|
|
|
if (shorthand == eCSSProperty_UNKNOWN ||
|
2014-02-15 17:40:38 +00:00
|
|
|
nsCSSProps::PropHasFlags(shorthand, CSS_PROPERTY_IS_ALIAS) ||
|
|
|
|
aProperty == eCSSProperty__x_system_font) {
|
2013-12-12 02:09:42 +00:00
|
|
|
// We treat serialization of aliases like '-moz-transform' as a special
|
|
|
|
// case, since it really wants to be serialized as if it were a longhand
|
|
|
|
// even though it is implemented as a shorthand.
|
|
|
|
aResult.Append(mValue.mTokenStream->mTokenStream);
|
|
|
|
}
|
2010-08-19 19:33:44 +00:00
|
|
|
} else if (eCSSUnit_Pair == unit) {
|
2013-05-20 02:59:20 +00:00
|
|
|
if (eCSSProperty_font_variant_alternates == aProperty) {
|
|
|
|
int32_t intValue = GetPairValue().mXValue.GetIntValue();
|
|
|
|
nsAutoString out;
|
|
|
|
|
|
|
|
// simple, enumerated values
|
|
|
|
nsStyleUtil::AppendBitmaskCSSValue(aProperty,
|
|
|
|
intValue & NS_FONT_VARIANT_ALTERNATES_ENUMERATED_MASK,
|
|
|
|
NS_FONT_VARIANT_ALTERNATES_HISTORICAL,
|
|
|
|
NS_FONT_VARIANT_ALTERNATES_HISTORICAL,
|
|
|
|
out);
|
|
|
|
|
|
|
|
// functional values
|
|
|
|
const nsCSSValueList *list = GetPairValue().mYValue.GetListValue();
|
|
|
|
nsAutoTArray<gfxAlternateValue,8> altValues;
|
|
|
|
|
|
|
|
nsStyleUtil::ComputeFunctionalAlternates(list, altValues);
|
|
|
|
nsStyleUtil::SerializeFunctionalAlternates(altValues, out);
|
|
|
|
aResult.Append(out);
|
|
|
|
} else {
|
2013-09-15 23:35:49 +00:00
|
|
|
GetPairValue().AppendToString(aProperty, aResult, aSerialization);
|
2013-05-20 02:59:20 +00:00
|
|
|
}
|
2011-08-03 03:04:23 +00:00
|
|
|
} else if (eCSSUnit_Triplet == unit) {
|
2013-09-15 23:35:49 +00:00
|
|
|
GetTripletValue().AppendToString(aProperty, aResult, aSerialization);
|
2010-08-19 19:33:44 +00:00
|
|
|
} else if (eCSSUnit_Rect == unit) {
|
2013-09-15 23:35:49 +00:00
|
|
|
GetRectValue().AppendToString(aProperty, aResult, aSerialization);
|
2010-08-19 19:33:44 +00:00
|
|
|
} else if (eCSSUnit_List == unit || eCSSUnit_ListDep == unit) {
|
2013-09-15 23:35:49 +00:00
|
|
|
GetListValue()->AppendToString(aProperty, aResult, aSerialization);
|
2013-12-12 02:09:44 +00:00
|
|
|
} else if (eCSSUnit_SharedList == unit) {
|
2013-09-15 23:35:49 +00:00
|
|
|
GetSharedListValue()->AppendToString(aProperty, aResult, aSerialization);
|
2010-08-19 19:33:44 +00:00
|
|
|
} else if (eCSSUnit_PairList == unit || eCSSUnit_PairListDep == unit) {
|
2012-04-26 06:24:26 +00:00
|
|
|
switch (aProperty) {
|
|
|
|
case eCSSProperty_font_feature_settings:
|
|
|
|
nsStyleUtil::AppendFontFeatureSettings(*this, aResult);
|
|
|
|
break;
|
|
|
|
default:
|
2013-09-15 23:35:49 +00:00
|
|
|
GetPairListValue()->AppendToString(aProperty, aResult, aSerialization);
|
2012-04-26 06:24:26 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-07-23 18:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (unit) {
|
|
|
|
case eCSSUnit_Null: break;
|
|
|
|
case eCSSUnit_Auto: aResult.AppendLiteral("auto"); break;
|
|
|
|
case eCSSUnit_Inherit: aResult.AppendLiteral("inherit"); break;
|
2012-10-30 15:40:33 +00:00
|
|
|
case eCSSUnit_Initial: aResult.AppendLiteral("initial"); break;
|
2013-10-03 18:49:17 +00:00
|
|
|
case eCSSUnit_Unset: aResult.AppendLiteral("unset"); break;
|
2010-07-23 18:00:27 +00:00
|
|
|
case eCSSUnit_None: aResult.AppendLiteral("none"); break;
|
|
|
|
case eCSSUnit_Normal: aResult.AppendLiteral("normal"); break;
|
|
|
|
case eCSSUnit_System_Font: aResult.AppendLiteral("-moz-use-system-font"); break;
|
|
|
|
case eCSSUnit_All: aResult.AppendLiteral("all"); break;
|
|
|
|
case eCSSUnit_Dummy:
|
|
|
|
case eCSSUnit_DummyInherit:
|
2010-08-19 19:33:44 +00:00
|
|
|
NS_ABORT_IF_FALSE(false, "should never serialize");
|
2010-07-23 18:00:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSUnit_String: break;
|
|
|
|
case eCSSUnit_Ident: break;
|
|
|
|
case eCSSUnit_Families: break;
|
|
|
|
case eCSSUnit_URL: break;
|
|
|
|
case eCSSUnit_Image: break;
|
2010-08-13 13:33:37 +00:00
|
|
|
case eCSSUnit_Element: break;
|
2010-07-23 18:00:27 +00:00
|
|
|
case eCSSUnit_Array: break;
|
|
|
|
case eCSSUnit_Attr:
|
|
|
|
case eCSSUnit_Cubic_Bezier:
|
2011-04-12 06:18:42 +00:00
|
|
|
case eCSSUnit_Steps:
|
2010-07-23 18:00:27 +00:00
|
|
|
case eCSSUnit_Counter:
|
2014-01-04 15:02:17 +00:00
|
|
|
case eCSSUnit_Counters: aResult.Append(char16_t(')')); break;
|
2010-07-23 18:00:27 +00:00
|
|
|
case eCSSUnit_Local_Font: break;
|
|
|
|
case eCSSUnit_Font_Format: break;
|
|
|
|
case eCSSUnit_Function: break;
|
|
|
|
case eCSSUnit_Calc: break;
|
|
|
|
case eCSSUnit_Calc_Plus: break;
|
|
|
|
case eCSSUnit_Calc_Minus: break;
|
|
|
|
case eCSSUnit_Calc_Times_L: break;
|
|
|
|
case eCSSUnit_Calc_Times_R: break;
|
|
|
|
case eCSSUnit_Calc_Divided: break;
|
|
|
|
case eCSSUnit_Integer: break;
|
|
|
|
case eCSSUnit_Enumerated: break;
|
2013-09-15 23:35:48 +00:00
|
|
|
case eCSSUnit_EnumColor: break;
|
|
|
|
case eCSSUnit_RGBColor: break;
|
|
|
|
case eCSSUnit_RGBAColor: break;
|
|
|
|
case eCSSUnit_HexColor: break;
|
|
|
|
case eCSSUnit_ShortHexColor: break;
|
|
|
|
case eCSSUnit_PercentageRGBColor: break;
|
|
|
|
case eCSSUnit_PercentageRGBAColor: break;
|
|
|
|
case eCSSUnit_HSLColor: break;
|
|
|
|
case eCSSUnit_HSLAColor: break;
|
2014-01-04 15:02:17 +00:00
|
|
|
case eCSSUnit_Percent: aResult.Append(char16_t('%')); break;
|
2010-07-23 18:00:27 +00:00
|
|
|
case eCSSUnit_Number: break;
|
|
|
|
case eCSSUnit_Gradient: break;
|
2013-12-12 02:09:42 +00:00
|
|
|
case eCSSUnit_TokenStream: break;
|
2010-08-19 19:33:44 +00:00
|
|
|
case eCSSUnit_Pair: break;
|
2011-08-03 03:04:23 +00:00
|
|
|
case eCSSUnit_Triplet: break;
|
2010-08-19 19:33:44 +00:00
|
|
|
case eCSSUnit_Rect: break;
|
2010-08-19 19:33:44 +00:00
|
|
|
case eCSSUnit_List: break;
|
|
|
|
case eCSSUnit_ListDep: break;
|
2013-12-12 02:09:44 +00:00
|
|
|
case eCSSUnit_SharedList: break;
|
2010-08-19 19:33:44 +00:00
|
|
|
case eCSSUnit_PairList: break;
|
|
|
|
case eCSSUnit_PairListDep: break;
|
2010-07-23 18:00:27 +00:00
|
|
|
|
|
|
|
case eCSSUnit_Inch: aResult.AppendLiteral("in"); break;
|
|
|
|
case eCSSUnit_Millimeter: aResult.AppendLiteral("mm"); break;
|
2010-08-13 09:58:02 +00:00
|
|
|
case eCSSUnit_PhysicalMillimeter: aResult.AppendLiteral("mozmm"); break;
|
2010-07-23 18:00:27 +00:00
|
|
|
case eCSSUnit_Centimeter: aResult.AppendLiteral("cm"); break;
|
|
|
|
case eCSSUnit_Point: aResult.AppendLiteral("pt"); break;
|
|
|
|
case eCSSUnit_Pica: aResult.AppendLiteral("pc"); break;
|
|
|
|
|
2012-10-19 23:21:06 +00:00
|
|
|
case eCSSUnit_ViewportWidth: aResult.AppendLiteral("vw"); break;
|
|
|
|
case eCSSUnit_ViewportHeight: aResult.AppendLiteral("vh"); break;
|
|
|
|
case eCSSUnit_ViewportMin: aResult.AppendLiteral("vmin"); break;
|
|
|
|
case eCSSUnit_ViewportMax: aResult.AppendLiteral("vmax"); break;
|
|
|
|
|
2010-07-23 18:00:27 +00:00
|
|
|
case eCSSUnit_EM: aResult.AppendLiteral("em"); break;
|
|
|
|
case eCSSUnit_XHeight: aResult.AppendLiteral("ex"); break;
|
|
|
|
case eCSSUnit_Char: aResult.AppendLiteral("ch"); break;
|
|
|
|
case eCSSUnit_RootEM: aResult.AppendLiteral("rem"); break;
|
|
|
|
|
|
|
|
case eCSSUnit_Pixel: aResult.AppendLiteral("px"); break;
|
|
|
|
|
|
|
|
case eCSSUnit_Degree: aResult.AppendLiteral("deg"); break;
|
|
|
|
case eCSSUnit_Grad: aResult.AppendLiteral("grad"); break;
|
|
|
|
case eCSSUnit_Radian: aResult.AppendLiteral("rad"); break;
|
2012-02-04 05:01:23 +00:00
|
|
|
case eCSSUnit_Turn: aResult.AppendLiteral("turn"); break;
|
2010-07-23 18:00:27 +00:00
|
|
|
|
|
|
|
case eCSSUnit_Hertz: aResult.AppendLiteral("Hz"); break;
|
|
|
|
case eCSSUnit_Kilohertz: aResult.AppendLiteral("kHz"); break;
|
|
|
|
|
2014-01-04 15:02:17 +00:00
|
|
|
case eCSSUnit_Seconds: aResult.Append(char16_t('s')); break;
|
2010-07-23 18:00:27 +00:00
|
|
|
case eCSSUnit_Milliseconds: aResult.AppendLiteral("ms"); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-03 02:19:14 +00:00
|
|
|
size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
nsCSSValue::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 02:19:14 +00:00
|
|
|
{
|
|
|
|
size_t n = 0;
|
|
|
|
|
|
|
|
switch (GetUnit()) {
|
|
|
|
// No value: nothing extra to measure.
|
|
|
|
case eCSSUnit_Null:
|
|
|
|
case eCSSUnit_Auto:
|
|
|
|
case eCSSUnit_Inherit:
|
|
|
|
case eCSSUnit_Initial:
|
2013-10-03 18:49:17 +00:00
|
|
|
case eCSSUnit_Unset:
|
2012-01-03 02:19:14 +00:00
|
|
|
case eCSSUnit_None:
|
|
|
|
case eCSSUnit_Normal:
|
|
|
|
case eCSSUnit_System_Font:
|
|
|
|
case eCSSUnit_All:
|
|
|
|
case eCSSUnit_Dummy:
|
|
|
|
case eCSSUnit_DummyInherit:
|
|
|
|
break;
|
|
|
|
|
|
|
|
// String
|
|
|
|
case eCSSUnit_String:
|
|
|
|
case eCSSUnit_Ident:
|
|
|
|
case eCSSUnit_Families:
|
|
|
|
case eCSSUnit_Attr:
|
|
|
|
case eCSSUnit_Local_Font:
|
|
|
|
case eCSSUnit_Font_Format:
|
|
|
|
case eCSSUnit_Element:
|
|
|
|
n += mValue.mString->SizeOfIncludingThisIfUnshared(aMallocSizeOf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Array
|
|
|
|
case eCSSUnit_Array:
|
|
|
|
case eCSSUnit_Counter:
|
|
|
|
case eCSSUnit_Counters:
|
|
|
|
case eCSSUnit_Cubic_Bezier:
|
|
|
|
case eCSSUnit_Steps:
|
|
|
|
case eCSSUnit_Function:
|
|
|
|
case eCSSUnit_Calc:
|
|
|
|
case eCSSUnit_Calc_Plus:
|
|
|
|
case eCSSUnit_Calc_Minus:
|
|
|
|
case eCSSUnit_Calc_Times_L:
|
|
|
|
case eCSSUnit_Calc_Times_R:
|
|
|
|
case eCSSUnit_Calc_Divided:
|
|
|
|
break;
|
|
|
|
|
|
|
|
// URL
|
|
|
|
case eCSSUnit_URL:
|
|
|
|
n += mValue.mURL->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Image
|
|
|
|
case eCSSUnit_Image:
|
|
|
|
// Not yet measured. Measurement may be added later if DMD finds it
|
|
|
|
// worthwhile.
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Gradient
|
|
|
|
case eCSSUnit_Gradient:
|
|
|
|
n += mValue.mGradient->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
break;
|
|
|
|
|
2013-12-12 02:09:42 +00:00
|
|
|
// TokenStream
|
|
|
|
case eCSSUnit_TokenStream:
|
|
|
|
n += mValue.mTokenStream->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
break;
|
|
|
|
|
2012-01-03 02:19:14 +00:00
|
|
|
// Pair
|
|
|
|
case eCSSUnit_Pair:
|
|
|
|
n += mValue.mPair->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Triplet
|
|
|
|
case eCSSUnit_Triplet:
|
|
|
|
n += mValue.mTriplet->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Rect
|
|
|
|
case eCSSUnit_Rect:
|
|
|
|
n += mValue.mRect->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// List
|
|
|
|
case eCSSUnit_List:
|
|
|
|
n += mValue.mList->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// ListDep: not measured because it's non-owning.
|
|
|
|
case eCSSUnit_ListDep:
|
|
|
|
break;
|
|
|
|
|
2013-12-12 02:09:44 +00:00
|
|
|
// SharedList
|
|
|
|
case eCSSUnit_SharedList:
|
|
|
|
// Makes more sense not to measure, since it most cases the list
|
|
|
|
// will be shared.
|
|
|
|
break;
|
|
|
|
|
2012-01-03 02:19:14 +00:00
|
|
|
// PairList
|
|
|
|
case eCSSUnit_PairList:
|
|
|
|
n += mValue.mPairList->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// PairListDep: not measured because it's non-owning.
|
|
|
|
case eCSSUnit_PairListDep:
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Int: nothing extra to measure.
|
|
|
|
case eCSSUnit_Integer:
|
|
|
|
case eCSSUnit_Enumerated:
|
|
|
|
case eCSSUnit_EnumColor:
|
|
|
|
break;
|
|
|
|
|
2013-09-15 23:35:48 +00:00
|
|
|
// Integer Color: nothing extra to measure.
|
|
|
|
case eCSSUnit_RGBColor:
|
2013-09-15 23:35:48 +00:00
|
|
|
case eCSSUnit_RGBAColor:
|
2013-09-15 23:35:48 +00:00
|
|
|
case eCSSUnit_HexColor:
|
|
|
|
case eCSSUnit_ShortHexColor:
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Float Color
|
|
|
|
case eCSSUnit_PercentageRGBColor:
|
|
|
|
case eCSSUnit_PercentageRGBAColor:
|
|
|
|
case eCSSUnit_HSLColor:
|
|
|
|
case eCSSUnit_HSLAColor:
|
|
|
|
n += mValue.mFloatColor->SizeOfIncludingThis(aMallocSizeOf);
|
2012-01-03 02:19:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Float: nothing extra to measure.
|
|
|
|
case eCSSUnit_Percent:
|
|
|
|
case eCSSUnit_Number:
|
|
|
|
case eCSSUnit_PhysicalMillimeter:
|
2012-10-19 23:21:06 +00:00
|
|
|
case eCSSUnit_ViewportWidth:
|
|
|
|
case eCSSUnit_ViewportHeight:
|
|
|
|
case eCSSUnit_ViewportMin:
|
|
|
|
case eCSSUnit_ViewportMax:
|
2012-01-03 02:19:14 +00:00
|
|
|
case eCSSUnit_EM:
|
|
|
|
case eCSSUnit_XHeight:
|
|
|
|
case eCSSUnit_Char:
|
|
|
|
case eCSSUnit_RootEM:
|
|
|
|
case eCSSUnit_Point:
|
|
|
|
case eCSSUnit_Inch:
|
|
|
|
case eCSSUnit_Millimeter:
|
|
|
|
case eCSSUnit_Centimeter:
|
|
|
|
case eCSSUnit_Pica:
|
|
|
|
case eCSSUnit_Pixel:
|
|
|
|
case eCSSUnit_Degree:
|
|
|
|
case eCSSUnit_Grad:
|
2012-02-13 01:51:58 +00:00
|
|
|
case eCSSUnit_Turn:
|
2012-01-03 02:19:14 +00:00
|
|
|
case eCSSUnit_Radian:
|
|
|
|
case eCSSUnit_Hertz:
|
|
|
|
case eCSSUnit_Kilohertz:
|
|
|
|
case eCSSUnit_Seconds:
|
|
|
|
case eCSSUnit_Milliseconds:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_ABORT_IF_FALSE(false, "bad nsCSSUnit");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2010-08-19 19:33:43 +00:00
|
|
|
// --- nsCSSValueList -----------------
|
|
|
|
|
|
|
|
nsCSSValueList::~nsCSSValueList()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsCSSValueList);
|
|
|
|
NS_CSS_DELETE_LIST_MEMBER(nsCSSValueList, this, mNext);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValueList*
|
|
|
|
nsCSSValueList::Clone() const
|
|
|
|
{
|
|
|
|
nsCSSValueList* result = new nsCSSValueList(*this);
|
|
|
|
nsCSSValueList* dest = result;
|
|
|
|
const nsCSSValueList* src = this->mNext;
|
|
|
|
while (src) {
|
|
|
|
dest->mNext = new nsCSSValueList(*src);
|
|
|
|
dest = dest->mNext;
|
|
|
|
src = src->mNext;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-07-22 22:28:07 +00:00
|
|
|
void
|
|
|
|
nsCSSValueList::CloneInto(nsCSSValueList* aList) const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aList->mNext, "Must be an empty list!");
|
|
|
|
aList->mValue = mValue;
|
2012-07-30 14:20:58 +00:00
|
|
|
aList->mNext = mNext ? mNext->Clone() : nullptr;
|
2011-07-22 22:28:07 +00:00
|
|
|
}
|
|
|
|
|
2010-08-19 19:33:43 +00:00
|
|
|
void
|
2013-09-15 23:35:49 +00:00
|
|
|
nsCSSValueList::AppendToString(nsCSSProperty aProperty, nsAString& aResult,
|
|
|
|
nsCSSValue::Serialization aSerialization) const
|
2010-08-19 19:33:43 +00:00
|
|
|
{
|
|
|
|
const nsCSSValueList* val = this;
|
|
|
|
for (;;) {
|
2013-09-15 23:35:49 +00:00
|
|
|
val->mValue.AppendToString(aProperty, aResult, aSerialization);
|
2010-08-19 19:33:43 +00:00
|
|
|
val = val->mNext;
|
|
|
|
if (!val)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (nsCSSProps::PropHasFlags(aProperty,
|
|
|
|
CSS_PROPERTY_VALUE_LIST_USES_COMMAS))
|
2014-01-04 15:02:17 +00:00
|
|
|
aResult.Append(char16_t(','));
|
|
|
|
aResult.Append(char16_t(' '));
|
2010-08-19 19:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsCSSValueList::operator==(const nsCSSValueList& aOther) const
|
|
|
|
{
|
|
|
|
if (this == &aOther)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
const nsCSSValueList *p1 = this, *p2 = &aOther;
|
|
|
|
for ( ; p1 && p2; p1 = p1->mNext, p2 = p2->mNext) {
|
|
|
|
if (p1->mValue != p2->mValue)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !p1 && !p2; // true if same length, false otherwise
|
|
|
|
}
|
|
|
|
|
2012-01-03 02:19:14 +00:00
|
|
|
size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
nsCSSValueList::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 02:19:14 +00:00
|
|
|
{
|
|
|
|
size_t n = 0;
|
|
|
|
const nsCSSValueList* v = this;
|
|
|
|
while (v) {
|
|
|
|
n += aMallocSizeOf(v);
|
|
|
|
n += v->mValue.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
v = v->mNext;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
nsCSSValueList_heap::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 02:19:14 +00:00
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
n += mValue.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mNext ? mNext->SizeOfIncludingThis(aMallocSizeOf) : 0;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2013-12-12 02:09:44 +00:00
|
|
|
// --- nsCSSValueSharedList -----------------
|
|
|
|
|
|
|
|
nsCSSValueSharedList::~nsCSSValueSharedList()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsCSSValueSharedList);
|
|
|
|
if (mHead) {
|
|
|
|
NS_CSS_DELETE_LIST_MEMBER(nsCSSValueList, mHead, mNext);
|
|
|
|
delete mHead;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-15 23:35:49 +00:00
|
|
|
nsCSSValueSharedList::AppendToString(nsCSSProperty aProperty, nsAString& aResult,
|
|
|
|
nsCSSValue::Serialization aSerialization) const
|
2013-12-12 02:09:44 +00:00
|
|
|
{
|
|
|
|
if (mHead) {
|
2013-09-15 23:35:49 +00:00
|
|
|
mHead->AppendToString(aProperty, aResult, aSerialization);
|
2013-12-12 02:09:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsCSSValueSharedList::operator==(const nsCSSValueSharedList& aOther) const
|
|
|
|
{
|
|
|
|
return !mHead == !aOther.mHead &&
|
|
|
|
(!mHead || *mHead == *aOther.mHead);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
nsCSSValueSharedList::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t n = 0;
|
|
|
|
n += aMallocSizeOf(this);
|
|
|
|
n += mHead->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2010-08-19 19:33:43 +00:00
|
|
|
// --- nsCSSRect -----------------
|
|
|
|
|
|
|
|
nsCSSRect::nsCSSRect(void)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsCSSRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSRect::nsCSSRect(const nsCSSRect& aCopy)
|
|
|
|
: mTop(aCopy.mTop),
|
|
|
|
mRight(aCopy.mRight),
|
|
|
|
mBottom(aCopy.mBottom),
|
|
|
|
mLeft(aCopy.mLeft)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsCSSRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSRect::~nsCSSRect()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsCSSRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-15 23:35:49 +00:00
|
|
|
nsCSSRect::AppendToString(nsCSSProperty aProperty, nsAString& aResult,
|
|
|
|
nsCSSValue::Serialization aSerialization) const
|
2010-08-19 19:33:43 +00:00
|
|
|
{
|
2010-08-19 19:33:44 +00:00
|
|
|
NS_ABORT_IF_FALSE(mTop.GetUnit() != eCSSUnit_Null &&
|
|
|
|
mTop.GetUnit() != eCSSUnit_Inherit &&
|
2013-10-03 18:49:17 +00:00
|
|
|
mTop.GetUnit() != eCSSUnit_Initial &&
|
|
|
|
mTop.GetUnit() != eCSSUnit_Unset,
|
2010-08-19 19:33:44 +00:00
|
|
|
"parser should have used a bare value");
|
|
|
|
|
2011-12-22 23:34:45 +00:00
|
|
|
if (eCSSProperty_border_image_slice == aProperty ||
|
|
|
|
eCSSProperty_border_image_width == aProperty ||
|
|
|
|
eCSSProperty_border_image_outset == aProperty) {
|
|
|
|
NS_NAMED_LITERAL_STRING(space, " ");
|
|
|
|
|
2013-09-15 23:35:49 +00:00
|
|
|
mTop.AppendToString(aProperty, aResult, aSerialization);
|
2011-12-22 23:34:45 +00:00
|
|
|
aResult.Append(space);
|
2013-09-15 23:35:49 +00:00
|
|
|
mRight.AppendToString(aProperty, aResult, aSerialization);
|
2011-12-22 23:34:45 +00:00
|
|
|
aResult.Append(space);
|
2013-09-15 23:35:49 +00:00
|
|
|
mBottom.AppendToString(aProperty, aResult, aSerialization);
|
2011-12-22 23:34:45 +00:00
|
|
|
aResult.Append(space);
|
2013-09-15 23:35:49 +00:00
|
|
|
mLeft.AppendToString(aProperty, aResult, aSerialization);
|
2011-12-22 23:34:45 +00:00
|
|
|
} else {
|
|
|
|
NS_NAMED_LITERAL_STRING(comma, ", ");
|
|
|
|
|
|
|
|
aResult.AppendLiteral("rect(");
|
2013-09-15 23:35:49 +00:00
|
|
|
mTop.AppendToString(aProperty, aResult, aSerialization);
|
2011-12-22 23:34:45 +00:00
|
|
|
aResult.Append(comma);
|
2013-09-15 23:35:49 +00:00
|
|
|
mRight.AppendToString(aProperty, aResult, aSerialization);
|
2011-12-22 23:34:45 +00:00
|
|
|
aResult.Append(comma);
|
2013-09-15 23:35:49 +00:00
|
|
|
mBottom.AppendToString(aProperty, aResult, aSerialization);
|
2011-12-22 23:34:45 +00:00
|
|
|
aResult.Append(comma);
|
2013-09-15 23:35:49 +00:00
|
|
|
mLeft.AppendToString(aProperty, aResult, aSerialization);
|
2014-01-04 15:02:17 +00:00
|
|
|
aResult.Append(char16_t(')'));
|
2011-12-22 23:34:45 +00:00
|
|
|
}
|
2010-08-19 19:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSRect::SetAllSidesTo(const nsCSSValue& aValue)
|
|
|
|
{
|
|
|
|
mTop = aValue;
|
|
|
|
mRight = aValue;
|
|
|
|
mBottom = aValue;
|
|
|
|
mLeft = aValue;
|
|
|
|
}
|
|
|
|
|
2012-01-03 02:19:14 +00:00
|
|
|
size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
nsCSSRect_heap::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 02:19:14 +00:00
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
n += mTop .SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mRight .SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mBottom.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mLeft .SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2013-07-18 17:59:53 +00:00
|
|
|
static_assert(NS_SIDE_TOP == 0 && NS_SIDE_RIGHT == 1 &&
|
|
|
|
NS_SIDE_BOTTOM == 2 && NS_SIDE_LEFT == 3,
|
|
|
|
"box side constants not top/right/bottom/left == 0/1/2/3");
|
2010-08-19 19:33:43 +00:00
|
|
|
|
|
|
|
/* static */ const nsCSSRect::side_type nsCSSRect::sides[4] = {
|
|
|
|
&nsCSSRect::mTop,
|
|
|
|
&nsCSSRect::mRight,
|
|
|
|
&nsCSSRect::mBottom,
|
|
|
|
&nsCSSRect::mLeft,
|
|
|
|
};
|
|
|
|
|
|
|
|
// --- nsCSSValuePair -----------------
|
|
|
|
|
|
|
|
void
|
2010-08-19 19:33:44 +00:00
|
|
|
nsCSSValuePair::AppendToString(nsCSSProperty aProperty,
|
2013-09-15 23:35:49 +00:00
|
|
|
nsAString& aResult,
|
|
|
|
nsCSSValue::Serialization aSerialization) const
|
2010-08-19 19:33:43 +00:00
|
|
|
{
|
2013-09-15 23:35:49 +00:00
|
|
|
mXValue.AppendToString(aProperty, aResult, aSerialization);
|
2010-08-19 19:33:44 +00:00
|
|
|
if (mYValue.GetUnit() != eCSSUnit_Null) {
|
2014-01-04 15:02:17 +00:00
|
|
|
aResult.Append(char16_t(' '));
|
2013-09-15 23:35:49 +00:00
|
|
|
mYValue.AppendToString(aProperty, aResult, aSerialization);
|
2010-08-19 19:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-03 02:19:14 +00:00
|
|
|
size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
nsCSSValuePair::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 02:19:14 +00:00
|
|
|
{
|
|
|
|
size_t n = 0;
|
|
|
|
n += mXValue.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mYValue.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
nsCSSValuePair_heap::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 02:19:14 +00:00
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
n += mXValue.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mYValue.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- nsCSSValueTriplet -----------------
|
2011-08-03 03:04:23 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSValueTriplet::AppendToString(nsCSSProperty aProperty,
|
2013-09-15 23:35:49 +00:00
|
|
|
nsAString& aResult,
|
|
|
|
nsCSSValue::Serialization aSerialization) const
|
2011-08-03 03:04:23 +00:00
|
|
|
{
|
2013-09-15 23:35:49 +00:00
|
|
|
mXValue.AppendToString(aProperty, aResult, aSerialization);
|
2011-08-03 03:04:23 +00:00
|
|
|
if (mYValue.GetUnit() != eCSSUnit_Null) {
|
2014-01-04 15:02:17 +00:00
|
|
|
aResult.Append(char16_t(' '));
|
2013-09-15 23:35:49 +00:00
|
|
|
mYValue.AppendToString(aProperty, aResult, aSerialization);
|
2011-08-03 03:04:23 +00:00
|
|
|
if (mZValue.GetUnit() != eCSSUnit_Null) {
|
2014-01-04 15:02:17 +00:00
|
|
|
aResult.Append(char16_t(' '));
|
2013-09-15 23:35:49 +00:00
|
|
|
mZValue.AppendToString(aProperty, aResult, aSerialization);
|
2011-08-03 03:04:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-03 02:19:14 +00:00
|
|
|
size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
nsCSSValueTriplet_heap::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 02:19:14 +00:00
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
n += mXValue.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mYValue.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mZValue.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2010-08-19 19:33:43 +00:00
|
|
|
// --- nsCSSValuePairList -----------------
|
|
|
|
|
|
|
|
nsCSSValuePairList::~nsCSSValuePairList()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsCSSValuePairList);
|
|
|
|
NS_CSS_DELETE_LIST_MEMBER(nsCSSValuePairList, this, mNext);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValuePairList*
|
|
|
|
nsCSSValuePairList::Clone() const
|
|
|
|
{
|
|
|
|
nsCSSValuePairList* result = new nsCSSValuePairList(*this);
|
|
|
|
nsCSSValuePairList* dest = result;
|
|
|
|
const nsCSSValuePairList* src = this->mNext;
|
|
|
|
while (src) {
|
|
|
|
dest->mNext = new nsCSSValuePairList(*src);
|
|
|
|
dest = dest->mNext;
|
|
|
|
src = src->mNext;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSValuePairList::AppendToString(nsCSSProperty aProperty,
|
2013-09-15 23:35:49 +00:00
|
|
|
nsAString& aResult,
|
|
|
|
nsCSSValue::Serialization aSerialization) const
|
2010-08-19 19:33:43 +00:00
|
|
|
{
|
|
|
|
const nsCSSValuePairList* item = this;
|
|
|
|
for (;;) {
|
|
|
|
NS_ABORT_IF_FALSE(item->mXValue.GetUnit() != eCSSUnit_Null,
|
|
|
|
"unexpected null unit");
|
2013-09-15 23:35:49 +00:00
|
|
|
item->mXValue.AppendToString(aProperty, aResult, aSerialization);
|
2010-08-19 19:33:43 +00:00
|
|
|
if (item->mXValue.GetUnit() != eCSSUnit_Inherit &&
|
|
|
|
item->mXValue.GetUnit() != eCSSUnit_Initial &&
|
2013-10-03 18:49:17 +00:00
|
|
|
item->mXValue.GetUnit() != eCSSUnit_Unset &&
|
2010-08-19 19:33:43 +00:00
|
|
|
item->mYValue.GetUnit() != eCSSUnit_Null) {
|
2014-01-04 15:02:17 +00:00
|
|
|
aResult.Append(char16_t(' '));
|
2013-09-15 23:35:49 +00:00
|
|
|
item->mYValue.AppendToString(aProperty, aResult, aSerialization);
|
2010-08-19 19:33:43 +00:00
|
|
|
}
|
|
|
|
item = item->mNext;
|
|
|
|
if (!item)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (nsCSSProps::PropHasFlags(aProperty,
|
|
|
|
CSS_PROPERTY_VALUE_LIST_USES_COMMAS))
|
2014-01-04 15:02:17 +00:00
|
|
|
aResult.Append(char16_t(','));
|
|
|
|
aResult.Append(char16_t(' '));
|
2010-08-19 19:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsCSSValuePairList::operator==(const nsCSSValuePairList& aOther) const
|
|
|
|
{
|
|
|
|
if (this == &aOther)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
const nsCSSValuePairList *p1 = this, *p2 = &aOther;
|
|
|
|
for ( ; p1 && p2; p1 = p1->mNext, p2 = p2->mNext) {
|
|
|
|
if (p1->mXValue != p2->mXValue ||
|
|
|
|
p1->mYValue != p2->mYValue)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !p1 && !p2; // true if same length, false otherwise
|
|
|
|
}
|
|
|
|
|
2012-01-03 02:19:14 +00:00
|
|
|
size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
nsCSSValuePairList::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 02:19:14 +00:00
|
|
|
{
|
|
|
|
size_t n = 0;
|
|
|
|
const nsCSSValuePairList* v = this;
|
|
|
|
while (v) {
|
|
|
|
n += aMallocSizeOf(v);
|
|
|
|
n += v->mXValue.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += v->mYValue.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
v = v->mNext;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
nsCSSValuePairList_heap::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 02:19:14 +00:00
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
n += mXValue.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mYValue.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mNext ? mNext->SizeOfIncludingThis(aMallocSizeOf) : 0;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
nsCSSValue::Array::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 02:19:14 +00:00
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
for (size_t i = 0; i < mCount; i++) {
|
|
|
|
n += mArray[i].SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2012-08-24 17:50:49 +00:00
|
|
|
css::URLValue::URLValue(nsIURI* aURI, nsStringBuffer* aString,
|
|
|
|
nsIURI* aReferrer, nsIPrincipal* aOriginPrincipal)
|
2007-05-03 01:15:53 +00:00
|
|
|
: mURI(aURI),
|
|
|
|
mString(aString),
|
|
|
|
mReferrer(aReferrer),
|
2011-05-11 15:28:53 +00:00
|
|
|
mOriginPrincipal(aOriginPrincipal),
|
2011-10-17 14:59:28 +00:00
|
|
|
mURIResolved(true)
|
2011-05-11 15:28:53 +00:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aOriginPrincipal, "Must have an origin principal");
|
|
|
|
mString->AddRef();
|
|
|
|
}
|
|
|
|
|
2012-08-24 17:50:49 +00:00
|
|
|
css::URLValue::URLValue(nsStringBuffer* aString, nsIURI* aBaseURI,
|
|
|
|
nsIURI* aReferrer, nsIPrincipal* aOriginPrincipal)
|
2011-05-11 15:28:53 +00:00
|
|
|
: mURI(aBaseURI),
|
|
|
|
mString(aString),
|
|
|
|
mReferrer(aReferrer),
|
|
|
|
mOriginPrincipal(aOriginPrincipal),
|
2011-10-17 14:59:28 +00:00
|
|
|
mURIResolved(false)
|
2007-05-03 01:15:53 +00:00
|
|
|
{
|
2010-08-19 19:33:44 +00:00
|
|
|
NS_ABORT_IF_FALSE(aOriginPrincipal, "Must have an origin principal");
|
2007-05-03 01:15:53 +00:00
|
|
|
mString->AddRef();
|
|
|
|
}
|
|
|
|
|
2012-08-24 17:50:49 +00:00
|
|
|
css::URLValue::~URLValue()
|
2007-05-03 01:15:53 +00:00
|
|
|
{
|
|
|
|
mString->Release();
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-08-24 17:50:49 +00:00
|
|
|
css::URLValue::operator==(const URLValue& aOther) const
|
2007-05-03 01:15:53 +00:00
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool eq;
|
2012-08-24 17:50:49 +00:00
|
|
|
return NS_strcmp(nsCSSValue::GetBufferValue(mString),
|
|
|
|
nsCSSValue::GetBufferValue(aOther.mString)) == 0 &&
|
2011-05-11 15:28:53 +00:00
|
|
|
(GetURI() == aOther.GetURI() || // handles null == null
|
2007-05-03 01:15:53 +00:00
|
|
|
(mURI && aOther.mURI &&
|
|
|
|
NS_SUCCEEDED(mURI->Equals(aOther.mURI, &eq)) &&
|
|
|
|
eq)) &&
|
2007-07-18 22:17:30 +00:00
|
|
|
(mOriginPrincipal == aOther.mOriginPrincipal ||
|
|
|
|
(NS_SUCCEEDED(mOriginPrincipal->Equals(aOther.mOriginPrincipal,
|
|
|
|
&eq)) && eq));
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-08-24 17:50:49 +00:00
|
|
|
css::URLValue::URIEquals(const URLValue& aOther) const
|
2007-07-18 22:17:30 +00:00
|
|
|
{
|
2011-05-11 15:28:53 +00:00
|
|
|
NS_ABORT_IF_FALSE(mURIResolved && aOther.mURIResolved,
|
|
|
|
"How do you know the URIs aren't null?");
|
2011-09-29 06:19:26 +00:00
|
|
|
bool eq;
|
2011-05-11 15:28:53 +00:00
|
|
|
// Worth comparing GetURI() to aOther.GetURI() and mOriginPrincipal to
|
2007-07-18 22:17:30 +00:00
|
|
|
// aOther.mOriginPrincipal, because in the (probably common) case when this
|
|
|
|
// value was one of the ones that in fact did not change this will be our
|
|
|
|
// fast path to equality
|
|
|
|
return (mURI == aOther.mURI ||
|
|
|
|
(NS_SUCCEEDED(mURI->Equals(aOther.mURI, &eq)) && eq)) &&
|
|
|
|
(mOriginPrincipal == aOther.mOriginPrincipal ||
|
|
|
|
(NS_SUCCEEDED(mOriginPrincipal->Equals(aOther.mOriginPrincipal,
|
|
|
|
&eq)) && eq));
|
2007-05-03 01:15:53 +00:00
|
|
|
}
|
|
|
|
|
2011-05-11 15:28:53 +00:00
|
|
|
nsIURI*
|
2012-08-24 17:50:49 +00:00
|
|
|
css::URLValue::GetURI() const
|
2011-05-11 15:28:53 +00:00
|
|
|
{
|
|
|
|
if (!mURIResolved) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mURIResolved = true;
|
2011-05-11 15:28:53 +00:00
|
|
|
// Be careful to not null out mURI before we've passed it as the base URI
|
|
|
|
nsCOMPtr<nsIURI> newURI;
|
|
|
|
NS_NewURI(getter_AddRefs(newURI),
|
2012-08-24 17:50:49 +00:00
|
|
|
NS_ConvertUTF16toUTF8(nsCSSValue::GetBufferValue(mString)),
|
|
|
|
nullptr, mURI);
|
2011-05-11 15:28:53 +00:00
|
|
|
newURI.swap(mURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mURI;
|
|
|
|
}
|
|
|
|
|
2012-01-03 02:19:14 +00:00
|
|
|
size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
css::URLValue::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 02:19:14 +00:00
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
|
|
|
|
// This string is unshared.
|
|
|
|
n += mString->SizeOfIncludingThisMustBeUnshared(aMallocSizeOf);
|
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mURI
|
|
|
|
// - mReferrer
|
|
|
|
// - mOriginPrincipal
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-24 17:50:49 +00:00
|
|
|
css::ImageValue::ImageValue(nsIURI* aURI, nsStringBuffer* aString,
|
|
|
|
nsIURI* aReferrer, nsIPrincipal* aOriginPrincipal,
|
|
|
|
nsIDocument* aDocument)
|
|
|
|
: URLValue(aURI, aString, aReferrer, aOriginPrincipal)
|
2004-03-09 03:57:51 +00:00
|
|
|
{
|
2013-02-23 14:59:43 +00:00
|
|
|
// NB: If aDocument is not the original document, we may not be able to load
|
|
|
|
// images from aDocument. Instead we do the image load from the original doc
|
|
|
|
// and clone it to aDocument.
|
|
|
|
nsIDocument* loadingDoc = aDocument->GetOriginalDocument();
|
|
|
|
if (!loadingDoc) {
|
|
|
|
loadingDoc = aDocument;
|
2010-10-09 10:03:06 +00:00
|
|
|
}
|
2012-08-13 22:04:19 +00:00
|
|
|
|
2013-02-23 14:59:43 +00:00
|
|
|
loadingDoc->StyleImageLoader()->LoadImage(aURI, aOriginPrincipal, aReferrer,
|
|
|
|
this);
|
|
|
|
|
|
|
|
if (loadingDoc != aDocument) {
|
|
|
|
aDocument->StyleImageLoader()->MaybeRegisterCSSImage(this);
|
|
|
|
}
|
2012-08-13 22:04:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PLDHashOperator
|
2012-10-12 12:43:01 +00:00
|
|
|
ClearRequestHashtable(nsISupports* aKey, nsRefPtr<imgRequestProxy>& aValue,
|
2012-08-13 22:04:19 +00:00
|
|
|
void* aClosure)
|
|
|
|
{
|
2012-08-24 17:50:49 +00:00
|
|
|
mozilla::css::ImageValue* image =
|
|
|
|
static_cast<mozilla::css::ImageValue*>(aClosure);
|
2012-08-13 22:04:19 +00:00
|
|
|
nsIDocument* doc = static_cast<nsIDocument*>(aKey);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocument> slowDoc = do_QueryInterface(aKey);
|
|
|
|
MOZ_ASSERT(slowDoc == doc);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (doc) {
|
|
|
|
doc->StyleImageLoader()->DeregisterCSSImage(image);
|
2004-03-09 03:57:51 +00:00
|
|
|
}
|
2012-08-13 22:04:19 +00:00
|
|
|
|
|
|
|
if (aValue) {
|
|
|
|
aValue->CancelAndForgetObserver(NS_BINDING_ABORTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
return PL_DHASH_REMOVE;
|
2004-03-09 03:57:51 +00:00
|
|
|
}
|
|
|
|
|
2012-08-24 17:50:49 +00:00
|
|
|
css::ImageValue::~ImageValue()
|
2004-03-09 03:57:51 +00:00
|
|
|
{
|
2012-08-13 22:04:19 +00:00
|
|
|
mRequests.Enumerate(&ClearRequestHashtable, this);
|
2009-08-01 15:53:40 +00:00
|
|
|
}
|
|
|
|
|
2009-11-02 19:36:43 +00:00
|
|
|
nsCSSValueGradientStop::nsCSSValueGradientStop()
|
|
|
|
: mLocation(eCSSUnit_None),
|
|
|
|
mColor(eCSSUnit_Null)
|
|
|
|
{
|
2009-08-01 15:53:40 +00:00
|
|
|
MOZ_COUNT_CTOR(nsCSSValueGradientStop);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValueGradientStop::nsCSSValueGradientStop(const nsCSSValueGradientStop& aOther)
|
|
|
|
: mLocation(aOther.mLocation),
|
|
|
|
mColor(aOther.mColor)
|
2009-11-02 19:36:43 +00:00
|
|
|
{
|
2009-08-01 15:53:40 +00:00
|
|
|
MOZ_COUNT_CTOR(nsCSSValueGradientStop);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValueGradientStop::~nsCSSValueGradientStop()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsCSSValueGradientStop);
|
|
|
|
}
|
|
|
|
|
2012-01-03 02:19:14 +00:00
|
|
|
size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
nsCSSValueGradientStop::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 02:19:14 +00:00
|
|
|
{
|
|
|
|
size_t n = 0;
|
|
|
|
n += mLocation.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mColor .SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
nsCSSValueGradient::nsCSSValueGradient(bool aIsRadial,
|
|
|
|
bool aIsRepeating)
|
2009-08-01 15:53:40 +00:00
|
|
|
: mIsRadial(aIsRadial),
|
2009-11-02 19:36:43 +00:00
|
|
|
mIsRepeating(aIsRepeating),
|
2012-07-07 14:27:08 +00:00
|
|
|
mIsLegacySyntax(false),
|
2012-07-07 14:27:08 +00:00
|
|
|
mIsExplicitSize(false),
|
2010-08-19 19:33:43 +00:00
|
|
|
mBgPos(eCSSUnit_None),
|
2012-07-07 14:27:08 +00:00
|
|
|
mAngle(eCSSUnit_None)
|
2009-11-02 19:36:43 +00:00
|
|
|
{
|
2012-07-07 14:27:08 +00:00
|
|
|
mRadialValues[0].SetNoneValue();
|
|
|
|
mRadialValues[1].SetNoneValue();
|
2004-03-09 03:57:51 +00:00
|
|
|
}
|
2011-03-28 23:07:26 +00:00
|
|
|
|
2012-01-03 02:19:14 +00:00
|
|
|
size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
nsCSSValueGradient::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 02:19:14 +00:00
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
2012-07-07 14:27:08 +00:00
|
|
|
n += mBgPos.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mAngle.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mRadialValues[0].SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mRadialValues[1].SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mStops.SizeOfExcludingThis(aMallocSizeOf);
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < mStops.Length(); i++) {
|
2012-01-03 02:19:14 +00:00
|
|
|
n += mStops[i].SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2013-12-12 02:09:42 +00:00
|
|
|
// --- nsCSSValueTokenStream ------------
|
|
|
|
|
|
|
|
nsCSSValueTokenStream::nsCSSValueTokenStream()
|
|
|
|
: mPropertyID(eCSSProperty_UNKNOWN)
|
|
|
|
, mShorthandPropertyID(eCSSProperty_UNKNOWN)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsCSSValueTokenStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValueTokenStream::~nsCSSValueTokenStream()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsCSSValueTokenStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
nsCSSValueTokenStream::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
n += mTokenStream.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2013-09-15 23:35:48 +00:00
|
|
|
// --- nsCSSValueFloatColor -------------
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsCSSValueFloatColor::operator==(nsCSSValueFloatColor& aOther) const
|
|
|
|
{
|
|
|
|
return mComponent1 == aOther.mComponent1 &&
|
|
|
|
mComponent2 == aOther.mComponent2 &&
|
|
|
|
mComponent3 == aOther.mComponent3 &&
|
|
|
|
mAlpha == aOther.mAlpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscolor
|
|
|
|
nsCSSValueFloatColor::GetColorValue(nsCSSUnit aUnit) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(nsCSSValue::IsFloatColorUnit(aUnit), "unexpected unit");
|
|
|
|
|
|
|
|
if (aUnit == eCSSUnit_PercentageRGBColor ||
|
|
|
|
aUnit == eCSSUnit_PercentageRGBAColor) {
|
|
|
|
return NS_RGBA(NSToIntRound(mComponent1 * 255.0f),
|
|
|
|
NSToIntRound(mComponent2 * 255.0f),
|
|
|
|
NSToIntRound(mComponent3 * 255.0f),
|
|
|
|
NSToIntRound(mAlpha * 255.0f));
|
|
|
|
}
|
|
|
|
|
|
|
|
// HSL color
|
|
|
|
MOZ_ASSERT(aUnit == eCSSUnit_HSLColor ||
|
|
|
|
aUnit == eCSSUnit_HSLAColor);
|
|
|
|
nscolor hsl = NS_HSL2RGB(mComponent1, mComponent2, mComponent3);
|
|
|
|
return NS_RGBA(NS_GET_R(hsl),
|
|
|
|
NS_GET_G(hsl),
|
|
|
|
NS_GET_B(hsl),
|
|
|
|
NSToIntRound(mAlpha * 255.0f));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsCSSValueFloatColor::IsNonTransparentColor() const
|
|
|
|
{
|
|
|
|
return mAlpha > 0.0f;
|
|
|
|
}
|
|
|
|
|
2013-09-15 23:35:49 +00:00
|
|
|
void
|
|
|
|
nsCSSValueFloatColor::AppendToString(nsCSSUnit aUnit, nsAString& aResult) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(nsCSSValue::IsFloatColorUnit(aUnit), "unexpected unit");
|
|
|
|
|
|
|
|
bool hasAlpha = aUnit == eCSSUnit_PercentageRGBAColor ||
|
|
|
|
aUnit == eCSSUnit_HSLAColor;
|
|
|
|
bool isHSL = aUnit == eCSSUnit_HSLColor ||
|
|
|
|
aUnit == eCSSUnit_HSLAColor;
|
|
|
|
|
|
|
|
if (isHSL) {
|
|
|
|
aResult.AppendLiteral("hsl");
|
|
|
|
} else {
|
|
|
|
aResult.AppendLiteral("rgb");
|
|
|
|
}
|
|
|
|
if (hasAlpha) {
|
|
|
|
aResult.AppendLiteral("a(");
|
|
|
|
} else {
|
|
|
|
aResult.Append('(');
|
|
|
|
}
|
|
|
|
if (isHSL) {
|
|
|
|
aResult.AppendFloat(mComponent1 * 360.0f);
|
|
|
|
aResult.AppendLiteral(", ");
|
|
|
|
} else {
|
|
|
|
aResult.AppendFloat(mComponent1 * 100.0f);
|
|
|
|
aResult.AppendLiteral("%, ");
|
|
|
|
}
|
|
|
|
aResult.AppendFloat(mComponent2 * 100.0f);
|
|
|
|
aResult.AppendLiteral("%, ");
|
|
|
|
aResult.AppendFloat(mComponent3 * 100.0f);
|
|
|
|
if (hasAlpha) {
|
|
|
|
aResult.AppendLiteral("%, ");
|
|
|
|
aResult.AppendFloat(mAlpha);
|
|
|
|
aResult.Append(')');
|
|
|
|
} else {
|
|
|
|
aResult.AppendLiteral("%)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-15 23:35:48 +00:00
|
|
|
size_t
|
|
|
|
nsCSSValueFloatColor::SizeOfIncludingThis(
|
|
|
|
mozilla::MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2011-03-28 23:07:26 +00:00
|
|
|
// --- nsCSSCornerSizes -----------------
|
|
|
|
|
|
|
|
nsCSSCornerSizes::nsCSSCornerSizes(void)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsCSSCornerSizes);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSCornerSizes::nsCSSCornerSizes(const nsCSSCornerSizes& aCopy)
|
|
|
|
: mTopLeft(aCopy.mTopLeft),
|
|
|
|
mTopRight(aCopy.mTopRight),
|
|
|
|
mBottomRight(aCopy.mBottomRight),
|
|
|
|
mBottomLeft(aCopy.mBottomLeft)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsCSSCornerSizes);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSCornerSizes::~nsCSSCornerSizes()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsCSSCornerSizes);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSCornerSizes::Reset()
|
|
|
|
{
|
|
|
|
NS_FOR_CSS_FULL_CORNERS(corner) {
|
|
|
|
this->GetCorner(corner).Reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-18 17:59:53 +00:00
|
|
|
static_assert(NS_CORNER_TOP_LEFT == 0 && NS_CORNER_TOP_RIGHT == 1 &&
|
|
|
|
NS_CORNER_BOTTOM_RIGHT == 2 && NS_CORNER_BOTTOM_LEFT == 3,
|
|
|
|
"box corner constants not tl/tr/br/bl == 0/1/2/3");
|
2011-03-28 23:07:26 +00:00
|
|
|
|
|
|
|
/* static */ const nsCSSCornerSizes::corner_type
|
|
|
|
nsCSSCornerSizes::corners[4] = {
|
|
|
|
&nsCSSCornerSizes::mTopLeft,
|
|
|
|
&nsCSSCornerSizes::mTopRight,
|
|
|
|
&nsCSSCornerSizes::mBottomRight,
|
|
|
|
&nsCSSCornerSizes::mBottomLeft,
|
|
|
|
};
|