2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 01:52:36 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-10-08 05:29:29 +04:00
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-10-08 05:29:29 +04:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-10-08 05:29:29 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 05:32:19 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 01:52:36 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-25 05:32:19 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 01:52:36 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 05:32:19 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 01:52:36 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-03-25 08:47:31 +03:00
|
|
|
|
|
|
|
/* representation of simple property values within CSS declarations */
|
|
|
|
|
1998-10-08 05:29:29 +04:00
|
|
|
#include "nsCSSValue.h"
|
2010-08-19 23:33:43 +04:00
|
|
|
|
2004-03-09 06:57:51 +03:00
|
|
|
#include "imgIRequest.h"
|
2007-05-03 05:15:53 +04:00
|
|
|
#include "nsIPrincipal.h"
|
2010-08-19 23:33:43 +04:00
|
|
|
#include "nsCSSProps.h"
|
|
|
|
#include "nsContentUtils.h"
|
2010-07-23 22:00:27 +04:00
|
|
|
#include "nsStyleUtil.h"
|
|
|
|
#include "CSSCalc.h"
|
2011-05-11 19:28:53 +04:00
|
|
|
#include "nsNetUtil.h"
|
2004-03-09 06:57:51 +03:00
|
|
|
|
2010-07-23 22:00:27 +04:00
|
|
|
namespace css = mozilla::css;
|
1998-10-08 05:29:29 +04:00
|
|
|
|
|
|
|
nsCSSValue::nsCSSValue(PRInt32 aValue, nsCSSUnit aUnit)
|
|
|
|
: mUnit(aUnit)
|
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(aUnit == eCSSUnit_Integer || aUnit == eCSSUnit_Enumerated ||
|
|
|
|
aUnit == eCSSUnit_EnumColor, "not an int value");
|
2008-02-08 22:51:41 +03:00
|
|
|
if (aUnit == eCSSUnit_Integer || aUnit == eCSSUnit_Enumerated ||
|
|
|
|
aUnit == eCSSUnit_EnumColor) {
|
1998-10-08 05:29:29 +04:00
|
|
|
mValue.mInt = aValue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mUnit = eCSSUnit_Null;
|
|
|
|
mValue.mInt = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue::nsCSSValue(float aValue, nsCSSUnit aUnit)
|
|
|
|
: mUnit(aUnit)
|
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(eCSSUnit_Percent <= aUnit, "not a float value");
|
1998-10-08 05:29:29 +04:00
|
|
|
if (eCSSUnit_Percent <= aUnit) {
|
|
|
|
mValue.mFloat = aValue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mUnit = eCSSUnit_Null;
|
|
|
|
mValue.mInt = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-13 18:49:36 +03:00
|
|
|
nsCSSValue::nsCSSValue(const nsString& aValue, nsCSSUnit aUnit)
|
1998-10-27 02:19:59 +03:00
|
|
|
: mUnit(aUnit)
|
1998-10-08 05:29:29 +04:00
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(UnitHasStringValue(), "not a string value");
|
2008-08-08 03:15:40 +04:00
|
|
|
if (UnitHasStringValue()) {
|
2010-12-05 16:17:29 +03:00
|
|
|
mValue.mString = BufferFromString(aValue).get();
|
2006-12-13 18:49:36 +03:00
|
|
|
if (NS_UNLIKELY(!mValue.mString)) {
|
|
|
|
// XXXbz not much we can do here; just make sure that our promise of a
|
|
|
|
// non-null mValue.mString holds for string units.
|
|
|
|
mUnit = eCSSUnit_Null;
|
|
|
|
}
|
1998-10-27 02:19:59 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mUnit = eCSSUnit_Null;
|
|
|
|
mValue.mInt = 0;
|
|
|
|
}
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
|
2005-04-02 03:07:00 +04:00
|
|
|
nsCSSValue::nsCSSValue(nsCSSValue::Array* aValue, nsCSSUnit aUnit)
|
|
|
|
: mUnit(aUnit)
|
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(UnitHasArrayValue(), "bad unit");
|
2005-04-02 03:07:00 +04:00
|
|
|
mValue.mArray = aValue;
|
|
|
|
mValue.mArray->AddRef();
|
|
|
|
}
|
|
|
|
|
2003-10-30 04:45:37 +03:00
|
|
|
nsCSSValue::nsCSSValue(nsCSSValue::URL* aValue)
|
2003-10-02 02:53:56 +04:00
|
|
|
: mUnit(eCSSUnit_URL)
|
|
|
|
{
|
|
|
|
mValue.mURL = aValue;
|
2003-10-30 04:45:37 +03:00
|
|
|
mValue.mURL->AddRef();
|
2003-10-02 02:53:56 +04:00
|
|
|
}
|
|
|
|
|
2004-03-09 06:57:51 +03:00
|
|
|
nsCSSValue::nsCSSValue(nsCSSValue::Image* aValue)
|
|
|
|
: mUnit(eCSSUnit_Image)
|
|
|
|
{
|
|
|
|
mValue.mImage = aValue;
|
|
|
|
mValue.mImage->AddRef();
|
|
|
|
}
|
|
|
|
|
2009-08-01 19:53:40 +04:00
|
|
|
nsCSSValue::nsCSSValue(nsCSSValueGradient* aValue)
|
|
|
|
: mUnit(eCSSUnit_Gradient)
|
|
|
|
{
|
|
|
|
mValue.mGradient = aValue;
|
|
|
|
mValue.mGradient->AddRef();
|
|
|
|
}
|
|
|
|
|
1998-10-08 05:29:29 +04:00
|
|
|
nsCSSValue::nsCSSValue(const nsCSSValue& aCopy)
|
|
|
|
: mUnit(aCopy.mUnit)
|
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
if (mUnit <= eCSSUnit_DummyInherit) {
|
2008-03-13 01:05:27 +03:00
|
|
|
// nothing to do, but put this important case first
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_Percent <= mUnit) {
|
|
|
|
mValue.mFloat = aCopy.mValue.mFloat;
|
|
|
|
}
|
2008-08-08 03:15:40 +04:00
|
|
|
else if (UnitHasStringValue()) {
|
2006-12-13 18:49:36 +03:00
|
|
|
mValue.mString = aCopy.mValue.mString;
|
|
|
|
mValue.mString->AddRef();
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
2008-03-13 01:05:27 +03:00
|
|
|
else if (eCSSUnit_Integer <= mUnit && mUnit <= eCSSUnit_EnumColor) {
|
1998-10-08 05:29:29 +04:00
|
|
|
mValue.mInt = aCopy.mValue.mInt;
|
|
|
|
}
|
2008-03-13 01:05:27 +03:00
|
|
|
else if (eCSSUnit_Color == mUnit) {
|
1998-10-08 05:29:29 +04:00
|
|
|
mValue.mColor = aCopy.mValue.mColor;
|
|
|
|
}
|
2010-05-11 19:49:43 +04:00
|
|
|
else if (UnitHasArrayValue()) {
|
2005-04-02 03:07:00 +04:00
|
|
|
mValue.mArray = aCopy.mValue.mArray;
|
|
|
|
mValue.mArray->AddRef();
|
|
|
|
}
|
2008-03-13 01:05:27 +03:00
|
|
|
else if (eCSSUnit_URL == mUnit) {
|
2003-10-02 02:53:56 +04:00
|
|
|
mValue.mURL = aCopy.mValue.mURL;
|
2003-10-30 04:45:37 +03:00
|
|
|
mValue.mURL->AddRef();
|
2003-10-02 02:53:56 +04:00
|
|
|
}
|
2008-03-13 01:05:27 +03:00
|
|
|
else if (eCSSUnit_Image == mUnit) {
|
2004-03-09 06:57:51 +03:00
|
|
|
mValue.mImage = aCopy.mValue.mImage;
|
|
|
|
mValue.mImage->AddRef();
|
|
|
|
}
|
2009-08-01 19:53:40 +04:00
|
|
|
else if (eCSSUnit_Gradient == mUnit) {
|
|
|
|
mValue.mGradient = aCopy.mValue.mGradient;
|
|
|
|
mValue.mGradient->AddRef();
|
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
else if (eCSSUnit_Pair == mUnit) {
|
|
|
|
mValue.mPair = aCopy.mValue.mPair;
|
|
|
|
mValue.mPair->AddRef();
|
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
else if (eCSSUnit_Rect == mUnit) {
|
|
|
|
mValue.mRect = aCopy.mValue.mRect;
|
|
|
|
mValue.mRect->AddRef();
|
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
else if (eCSSUnit_List == mUnit) {
|
|
|
|
mValue.mList = aCopy.mValue.mList;
|
|
|
|
mValue.mList->AddRef();
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_ListDep == mUnit) {
|
|
|
|
mValue.mListDependent = aCopy.mValue.mListDependent;
|
|
|
|
}
|
2010-08-19 23:33:44 +04: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 05:29:29 +04:00
|
|
|
else {
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(false, "unknown unit");
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue& nsCSSValue::operator=(const nsCSSValue& aCopy)
|
|
|
|
{
|
2005-04-03 20:47:01 +04:00
|
|
|
if (this != &aCopy) {
|
|
|
|
Reset();
|
|
|
|
new (this) nsCSSValue(aCopy);
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsCSSValue::operator==(const nsCSSValue& aOther) const
|
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(mUnit != eCSSUnit_ListDep &&
|
|
|
|
aOther.mUnit != eCSSUnit_ListDep &&
|
|
|
|
mUnit != eCSSUnit_PairListDep &&
|
2010-08-19 23:33:44 +04:00
|
|
|
aOther.mUnit != eCSSUnit_PairListDep,
|
|
|
|
"don't use operator== with dependent lists");
|
|
|
|
|
1998-10-08 05:29:29 +04:00
|
|
|
if (mUnit == aOther.mUnit) {
|
2010-08-19 23:33:44 +04:00
|
|
|
if (mUnit <= eCSSUnit_DummyInherit) {
|
2007-08-28 11:29:03 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2008-08-08 03:15:40 +04:00
|
|
|
else if (UnitHasStringValue()) {
|
2006-12-13 18:49:36 +03:00
|
|
|
return (NS_strcmp(GetBufferValue(mValue.mString),
|
|
|
|
GetBufferValue(aOther.mValue.mString)) == 0);
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
2008-02-08 22:51:41 +03:00
|
|
|
else if ((eCSSUnit_Integer <= mUnit) && (mUnit <= eCSSUnit_EnumColor)) {
|
2003-10-02 02:53:56 +04:00
|
|
|
return mValue.mInt == aOther.mValue.mInt;
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_Color == mUnit) {
|
|
|
|
return mValue.mColor == aOther.mValue.mColor;
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
2010-05-11 19:49:43 +04:00
|
|
|
else if (UnitHasArrayValue()) {
|
2005-04-02 03:07:00 +04:00
|
|
|
return *mValue.mArray == *aOther.mValue.mArray;
|
|
|
|
}
|
2003-10-02 02:53:56 +04:00
|
|
|
else if (eCSSUnit_URL == mUnit) {
|
2003-10-30 04:45:37 +03:00
|
|
|
return *mValue.mURL == *aOther.mValue.mURL;
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
2004-03-09 06:57:51 +03:00
|
|
|
else if (eCSSUnit_Image == mUnit) {
|
|
|
|
return *mValue.mImage == *aOther.mValue.mImage;
|
|
|
|
}
|
2009-08-01 19:53:40 +04:00
|
|
|
else if (eCSSUnit_Gradient == mUnit) {
|
|
|
|
return *mValue.mGradient == *aOther.mValue.mGradient;
|
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
else if (eCSSUnit_Pair == mUnit) {
|
|
|
|
return *mValue.mPair == *aOther.mValue.mPair;
|
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
else if (eCSSUnit_Rect == mUnit) {
|
|
|
|
return *mValue.mRect == *aOther.mValue.mRect;
|
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
else if (eCSSUnit_List == mUnit) {
|
|
|
|
return *mValue.mList == *aOther.mValue.mList;
|
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
else if (eCSSUnit_PairList == mUnit) {
|
|
|
|
return *mValue.mPairList == *aOther.mValue.mPairList;
|
|
|
|
}
|
1998-10-08 05:29:29 +04:00
|
|
|
else {
|
2003-10-02 02:53:56 +04:00
|
|
|
return mValue.mFloat == aOther.mValue.mFloat;
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-11-02 22:36:43 +03:00
|
|
|
double nsCSSValue::GetAngleValueInRadians() const
|
|
|
|
{
|
|
|
|
double angle = GetFloatValue();
|
|
|
|
|
|
|
|
switch (GetUnit()) {
|
|
|
|
case eCSSUnit_Radian: return angle;
|
|
|
|
case eCSSUnit_Degree: return angle * M_PI / 180.0;
|
|
|
|
case eCSSUnit_Grad: return angle * M_PI / 200.0;
|
|
|
|
|
|
|
|
default:
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(false, "unrecognized angular unit");
|
2009-11-02 22:36:43 +03:00
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-09 06:57:51 +03:00
|
|
|
imgIRequest* nsCSSValue::GetImageValue() const
|
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(mUnit == eCSSUnit_Image, "not an Image value");
|
2004-03-09 06:57:51 +03:00
|
|
|
return mValue.mImage->mRequest;
|
|
|
|
}
|
|
|
|
|
2010-08-13 13:58:01 +04:00
|
|
|
nscoord nsCSSValue::GetFixedLength(nsPresContext* aPresContext) const
|
2003-12-29 22:07:53 +03:00
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(mUnit == eCSSUnit_PhysicalMillimeter,
|
|
|
|
"not a fixed length unit");
|
2010-08-13 13:58:01 +04:00
|
|
|
|
2010-08-13 13:58:04 +04:00
|
|
|
float inches = mValue.mFloat / MM_PER_INCH_FLOAT;
|
2011-05-11 20:49:57 +04:00
|
|
|
return NSToCoordFloorClamped(inches *
|
|
|
|
float(aPresContext->DeviceContext()->AppUnitsPerPhysicalInch()));
|
2010-08-13 13:58:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nscoord nsCSSValue::GetPixelLength() const
|
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(IsPixelLengthUnit(), "not a fixed length unit");
|
2010-08-13 13:58:01 +04:00
|
|
|
|
2010-08-13 13:58:02 +04:00
|
|
|
double scaleFactor;
|
2010-08-13 13:58:01 +04:00
|
|
|
switch (mUnit) {
|
2010-08-13 13:58:02 +04: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 13:58:01 +04:00
|
|
|
default:
|
|
|
|
NS_ERROR("should never get here");
|
|
|
|
return 0;
|
2003-12-29 22:07:53 +03:00
|
|
|
}
|
2010-08-13 13:58:02 +04:00
|
|
|
return nsPresContext::CSSPixelsToAppUnits(float(mValue.mFloat*scaleFactor));
|
2003-12-29 22:07:53 +03:00
|
|
|
}
|
|
|
|
|
2007-08-28 10:47:32 +04:00
|
|
|
void nsCSSValue::DoReset()
|
|
|
|
{
|
2008-08-08 03:15:40 +04:00
|
|
|
if (UnitHasStringValue()) {
|
2007-08-28 10:47:32 +04:00
|
|
|
mValue.mString->Release();
|
2010-05-11 19:49:43 +04:00
|
|
|
} else if (UnitHasArrayValue()) {
|
2007-08-28 10:47:32 +04:00
|
|
|
mValue.mArray->Release();
|
|
|
|
} else if (eCSSUnit_URL == mUnit) {
|
|
|
|
mValue.mURL->Release();
|
|
|
|
} else if (eCSSUnit_Image == mUnit) {
|
|
|
|
mValue.mImage->Release();
|
2009-08-01 19:53:40 +04:00
|
|
|
} else if (eCSSUnit_Gradient == mUnit) {
|
|
|
|
mValue.mGradient->Release();
|
2010-08-19 23:33:44 +04:00
|
|
|
} else if (eCSSUnit_Pair == mUnit) {
|
|
|
|
mValue.mPair->Release();
|
2010-08-19 23:33:44 +04:00
|
|
|
} else if (eCSSUnit_Rect == mUnit) {
|
|
|
|
mValue.mRect->Release();
|
2010-08-19 23:33:44 +04:00
|
|
|
} else if (eCSSUnit_List == mUnit) {
|
|
|
|
mValue.mList->Release();
|
2010-08-19 23:33:44 +04:00
|
|
|
} else if (eCSSUnit_PairList == mUnit) {
|
|
|
|
mValue.mPairList->Release();
|
2007-08-28 10:47:32 +04:00
|
|
|
}
|
|
|
|
mUnit = eCSSUnit_Null;
|
|
|
|
}
|
|
|
|
|
1998-10-08 05:29:29 +04:00
|
|
|
void nsCSSValue::SetIntValue(PRInt32 aValue, nsCSSUnit aUnit)
|
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(aUnit == eCSSUnit_Integer || aUnit == eCSSUnit_Enumerated ||
|
|
|
|
aUnit == eCSSUnit_EnumColor, "not an int value");
|
1998-10-08 05:29:29 +04:00
|
|
|
Reset();
|
2008-02-08 22:51:41 +03:00
|
|
|
if (aUnit == eCSSUnit_Integer || aUnit == eCSSUnit_Enumerated ||
|
|
|
|
aUnit == eCSSUnit_EnumColor) {
|
1998-10-08 05:29:29 +04:00
|
|
|
mUnit = aUnit;
|
|
|
|
mValue.mInt = aValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
void nsCSSValue::SetPercentValue(float aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Percent;
|
|
|
|
mValue.mFloat = aValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetFloatValue(float aValue, nsCSSUnit aUnit)
|
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(eCSSUnit_Number <= aUnit, "not a float value");
|
2003-12-29 22:07:53 +03:00
|
|
|
Reset();
|
|
|
|
if (eCSSUnit_Number <= aUnit) {
|
|
|
|
mUnit = aUnit;
|
|
|
|
mValue.mFloat = aValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-13 18:49:36 +03:00
|
|
|
void nsCSSValue::SetStringValue(const nsString& aValue,
|
2000-08-23 21:27:06 +04:00
|
|
|
nsCSSUnit aUnit)
|
1998-10-08 05:29:29 +04:00
|
|
|
{
|
|
|
|
Reset();
|
2008-08-08 03:15:40 +04:00
|
|
|
mUnit = aUnit;
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(UnitHasStringValue(), "not a string unit");
|
2008-08-08 03:15:40 +04:00
|
|
|
if (UnitHasStringValue()) {
|
2010-12-05 16:17:29 +03:00
|
|
|
mValue.mString = BufferFromString(aValue).get();
|
2006-12-13 18:49:36 +03:00
|
|
|
if (NS_UNLIKELY(!mValue.mString)) {
|
|
|
|
// XXXbz not much we can do here; just make sure that our promise of a
|
|
|
|
// non-null mValue.mString holds for string units.
|
|
|
|
mUnit = eCSSUnit_Null;
|
|
|
|
}
|
2008-08-08 03:15:40 +04:00
|
|
|
} else
|
|
|
|
mUnit = eCSSUnit_Null;
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetColorValue(nscolor aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Color;
|
|
|
|
mValue.mColor = aValue;
|
|
|
|
}
|
|
|
|
|
2005-04-02 03:07:00 +04:00
|
|
|
void nsCSSValue::SetArrayValue(nsCSSValue::Array* aValue, nsCSSUnit aUnit)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = aUnit;
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(UnitHasArrayValue(), "bad unit");
|
2005-04-02 03:07:00 +04:00
|
|
|
mValue.mArray = aValue;
|
|
|
|
mValue.mArray->AddRef();
|
|
|
|
}
|
|
|
|
|
2003-10-30 04:45:37 +03:00
|
|
|
void nsCSSValue::SetURLValue(nsCSSValue::URL* aValue)
|
2003-10-02 02:53:56 +04:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_URL;
|
|
|
|
mValue.mURL = aValue;
|
2003-10-30 04:45:37 +03:00
|
|
|
mValue.mURL->AddRef();
|
2003-10-02 02:53:56 +04:00
|
|
|
}
|
|
|
|
|
2004-03-09 06:57:51 +03:00
|
|
|
void nsCSSValue::SetImageValue(nsCSSValue::Image* aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Image;
|
|
|
|
mValue.mImage = aValue;
|
|
|
|
mValue.mImage->AddRef();
|
|
|
|
}
|
|
|
|
|
2009-08-01 19:53:40 +04:00
|
|
|
void nsCSSValue::SetGradientValue(nsCSSValueGradient* aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Gradient;
|
|
|
|
mValue.mGradient = aValue;
|
|
|
|
mValue.mGradient->AddRef();
|
|
|
|
}
|
|
|
|
|
2010-08-19 23:33:44 +04: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 &&
|
|
|
|
aValue->mYValue.GetUnit() != eCSSUnit_Initial,
|
|
|
|
"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 &&
|
|
|
|
yValue.GetUnit() != eCSSUnit_Initial,
|
|
|
|
"inappropriate pair value");
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Pair;
|
|
|
|
mValue.mPair = new nsCSSValuePair_heap(xValue, yValue);
|
|
|
|
mValue.mPair->AddRef();
|
|
|
|
}
|
|
|
|
|
2010-08-19 23:33:44 +04:00
|
|
|
nsCSSRect& nsCSSValue::SetRectValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Rect;
|
|
|
|
mValue.mRect = new nsCSSRect_heap;
|
|
|
|
mValue.mRect->AddRef();
|
|
|
|
return *mValue.mRect;
|
|
|
|
}
|
|
|
|
|
2010-08-19 23:33:44 +04:00
|
|
|
nsCSSValueList* nsCSSValue::SetListValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_List;
|
|
|
|
mValue.mList = new nsCSSValueList_heap;
|
|
|
|
mValue.mList->AddRef();
|
|
|
|
return mValue.mList;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetDependentListValue(nsCSSValueList* aList)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
if (aList) {
|
|
|
|
mUnit = eCSSUnit_ListDep;
|
|
|
|
mValue.mListDependent = aList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-19 23:33:44 +04: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 23:33:44 +04:00
|
|
|
if (aList) {
|
|
|
|
mUnit = eCSSUnit_PairListDep;
|
|
|
|
mValue.mPairListDependent = aList;
|
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
void nsCSSValue::SetAutoValue()
|
1998-10-08 05:29:29 +04:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Auto;
|
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
void nsCSSValue::SetInheritValue()
|
1998-10-08 05:29:29 +04:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Inherit;
|
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
void nsCSSValue::SetInitialValue()
|
2001-06-01 02:19:43 +04:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Initial;
|
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
void nsCSSValue::SetNoneValue()
|
1998-10-08 05:29:29 +04:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_None;
|
|
|
|
}
|
|
|
|
|
2009-08-21 01:52:47 +04:00
|
|
|
void nsCSSValue::SetAllValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_All;
|
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
void nsCSSValue::SetNormalValue()
|
1998-10-08 05:29:29 +04:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Normal;
|
|
|
|
}
|
|
|
|
|
2007-06-12 22:28:56 +04:00
|
|
|
void nsCSSValue::SetSystemFontValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_System_Font;
|
|
|
|
}
|
|
|
|
|
2007-10-09 03:11:01 +04:00
|
|
|
void nsCSSValue::SetDummyValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Dummy;
|
|
|
|
}
|
|
|
|
|
2008-10-07 22:53:22 +04:00
|
|
|
void nsCSSValue::SetDummyInheritValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_DummyInherit;
|
|
|
|
}
|
|
|
|
|
2007-07-03 17:59:02 +04:00
|
|
|
void nsCSSValue::StartImageLoad(nsIDocument* aDocument) const
|
2004-03-09 06:57:51 +03:00
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(eCSSUnit_URL == mUnit, "Not a URL value!");
|
2004-03-09 06:57:51 +03:00
|
|
|
nsCSSValue::Image* image =
|
2011-05-11 19:28:53 +04:00
|
|
|
new nsCSSValue::Image(mValue.mURL->GetURI(),
|
2004-03-09 06:57:51 +03:00
|
|
|
mValue.mURL->mString,
|
2004-07-15 01:56:23 +04:00
|
|
|
mValue.mURL->mReferrer,
|
2007-05-03 05:15:53 +04:00
|
|
|
mValue.mURL->mOriginPrincipal,
|
2007-07-03 17:59:02 +04:00
|
|
|
aDocument);
|
2004-03-09 06:57:51 +03:00
|
|
|
if (image) {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsCSSValue* writable = const_cast<nsCSSValue*>(this);
|
2006-12-13 18:49:36 +03:00
|
|
|
writable->SetImageValue(image);
|
2004-03-09 06:57:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-17 02:05:12 +04:00
|
|
|
PRBool nsCSSValue::IsNonTransparentColor() const
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
(mUnit == eCSSUnit_Color && NS_GET_A(GetColorValue()) > 0) ||
|
|
|
|
(mUnit == eCSSUnit_Ident &&
|
|
|
|
!nsGkAtoms::transparent->Equals(GetStringValue(buf))) ||
|
|
|
|
(mUnit == eCSSUnit_EnumColor);
|
|
|
|
}
|
|
|
|
|
2009-08-22 00:39:25 +04:00
|
|
|
nsCSSValue::Array*
|
|
|
|
nsCSSValue::InitFunction(nsCSSKeyword aFunctionId, PRUint32 aNumArgs)
|
|
|
|
{
|
|
|
|
nsRefPtr<nsCSSValue::Array> func = Array::Create(aNumArgs + 1);
|
|
|
|
if (!func) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
func->Item(0).SetIntValue(aFunctionId, eCSSUnit_Enumerated);
|
|
|
|
SetArrayValue(func, eCSSUnit_Function);
|
|
|
|
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsCSSValue::EqualsFunction(nsCSSKeyword aFunctionId) const
|
|
|
|
{
|
|
|
|
if (mUnit != eCSSUnit_Function) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue::Array* func = mValue.mArray;
|
|
|
|
NS_ABORT_IF_FALSE(func && func->Count() >= 1 &&
|
|
|
|
func->Item(0).GetUnit() == eCSSUnit_Enumerated,
|
|
|
|
"illegally structured function value");
|
|
|
|
|
|
|
|
nsCSSKeyword thisFunctionId =
|
|
|
|
static_cast<nsCSSKeyword>(func->Item(0).GetIntValue());
|
|
|
|
return thisFunctionId == aFunctionId;
|
|
|
|
}
|
|
|
|
|
2006-12-13 18:49:36 +03:00
|
|
|
// static
|
2010-12-05 16:17:29 +03:00
|
|
|
already_AddRefed<nsStringBuffer>
|
2006-12-13 18:49:36 +03:00
|
|
|
nsCSSValue::BufferFromString(const nsString& aValue)
|
|
|
|
{
|
|
|
|
nsStringBuffer* buffer = nsStringBuffer::FromString(aValue);
|
|
|
|
if (buffer) {
|
|
|
|
buffer->AddRef();
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUnichar length = aValue.Length();
|
2010-12-05 16:17:29 +03:00
|
|
|
|
|
|
|
// NOTE: Alloc prouduces a new, already-addref'd (refcnt = 1) buffer.
|
2006-12-13 18:49:36 +03:00
|
|
|
buffer = nsStringBuffer::Alloc((length + 1) * sizeof(PRUnichar));
|
|
|
|
if (NS_LIKELY(buffer != 0)) {
|
2007-07-08 11:08:04 +04:00
|
|
|
PRUnichar* data = static_cast<PRUnichar*>(buffer->Data());
|
2006-12-13 18:49:36 +03:00
|
|
|
nsCharTraits<PRUnichar>::copy(data, aValue.get(), length);
|
|
|
|
// Null-terminate.
|
|
|
|
data[length] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:27 +04:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct CSSValueSerializeCalcOps {
|
|
|
|
CSSValueSerializeCalcOps(nsCSSProperty aProperty, nsAString& aResult)
|
|
|
|
: mProperty(aProperty),
|
|
|
|
mResult(aResult)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
aValue.AppendToString(mProperty, mResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppendNumber(const input_type& aValue)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aValue.GetUnit() == eCSSUnit_Number, "unexpected unit");
|
|
|
|
aValue.AppendToString(mProperty, mResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCSSProperty mProperty;
|
|
|
|
nsAString &mResult;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSValue::AppendToString(nsCSSProperty aProperty, nsAString& aResult) const
|
|
|
|
{
|
|
|
|
// 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 10:18:42 +04:00
|
|
|
else if (eCSSUnit_Array <= unit && unit <= eCSSUnit_Steps) {
|
2010-07-23 22:00:27 +04: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 10:18:42 +04:00
|
|
|
case eCSSUnit_Steps: aResult.AppendLiteral("steps("); break;
|
2010-07-23 22:00:27 +04:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue::Array *array = GetArrayValue();
|
|
|
|
PRBool mark = PR_FALSE;
|
|
|
|
for (size_t i = 0, i_end = array->Count(); i < i_end; ++i) {
|
|
|
|
if (aProperty == eCSSProperty_border_image && i >= 5) {
|
|
|
|
if (array->Item(i).GetUnit() == eCSSUnit_Null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (i == 5) {
|
|
|
|
aResult.AppendLiteral(" /");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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 10:18:42 +04: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 22:00:27 +04: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) {
|
|
|
|
array->Item(i).AppendToString(prop, aResult);
|
|
|
|
mark = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(array->Count() >= 1,
|
|
|
|
"Functions must have at least one element for the name.");
|
2010-07-23 22:00:27 +04: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.
|
|
|
|
const nsCSSKeyword functionId =
|
|
|
|
static_cast<nsCSSKeyword>(functionName.GetIntValue());
|
|
|
|
nsStyleUtil::AppendEscapedCSSIdent(
|
|
|
|
NS_ConvertASCIItoUTF16(nsCSSKeywords::GetStringValue(functionId)),
|
|
|
|
aResult);
|
|
|
|
} else {
|
|
|
|
functionName.AppendToString(aProperty, aResult);
|
|
|
|
}
|
|
|
|
aResult.AppendLiteral("(");
|
|
|
|
|
|
|
|
/* Now, step through the function contents, writing each of them as we go. */
|
|
|
|
for (size_t index = 1; index < array->Count(); ++index) {
|
|
|
|
array->Item(index).AppendToString(aProperty, aResult);
|
|
|
|
|
|
|
|
/* 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 20:27:12 +04:00
|
|
|
NS_ABORT_IF_FALSE(GetUnit() == eCSSUnit_Calc, "unexpected unit");
|
2010-07-23 22:00:27 +04:00
|
|
|
CSSValueSerializeCalcOps ops(aProperty, aResult);
|
|
|
|
css::SerializeCalc(*this, ops);
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_Integer == unit) {
|
2010-11-30 21:18:15 +03:00
|
|
|
aResult.AppendInt(GetIntValue(), 10);
|
2010-07-23 22:00:27 +04:00
|
|
|
}
|
|
|
|
else if (eCSSUnit_Enumerated == unit) {
|
2011-04-23 09:16:41 +04:00
|
|
|
if (eCSSProperty_text_decoration_line == aProperty) {
|
2010-07-23 22:00:27 +04:00
|
|
|
PRInt32 intValue = GetIntValue();
|
2011-04-23 09:16:41 +04:00
|
|
|
if (NS_STYLE_TEXT_DECORATION_LINE_NONE == intValue) {
|
2010-07-23 22:00:27 +04:00
|
|
|
AppendASCIItoUTF16(nsCSSProps::LookupPropertyValue(aProperty, intValue),
|
|
|
|
aResult);
|
|
|
|
} else {
|
|
|
|
// Ignore the "override all" internal value.
|
|
|
|
// (It doesn't have a string representation.)
|
2011-04-23 09:16:41 +04:00
|
|
|
intValue &= ~NS_STYLE_TEXT_DECORATION_LINE_OVERRIDE_ALL;
|
2010-07-23 22:00:27 +04:00
|
|
|
nsStyleUtil::AppendBitmaskCSSValue(
|
|
|
|
aProperty, intValue,
|
2011-04-23 09:16:41 +04:00
|
|
|
NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE,
|
|
|
|
NS_STYLE_TEXT_DECORATION_LINE_PREF_ANCHORS,
|
2010-07-23 22:00:27 +04:00
|
|
|
aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (eCSSProperty_marks == aProperty) {
|
|
|
|
PRInt32 intValue = GetIntValue();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const nsAFlatCString& name = nsCSSProps::LookupPropertyValue(aProperty, GetIntValue());
|
|
|
|
AppendASCIItoUTF16(name, aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_EnumColor == unit) {
|
|
|
|
// we can lookup the property in the ColorTable and then
|
|
|
|
// get a string mapping the name
|
|
|
|
nsCAutoString str;
|
|
|
|
if (nsCSSProps::GetColorName(GetIntValue(), str)){
|
|
|
|
AppendASCIItoUTF16(str, aResult);
|
|
|
|
} else {
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(false, "bad color value");
|
2010-07-23 22:00:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_Color == unit) {
|
|
|
|
nscolor color = GetColorValue();
|
|
|
|
if (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");
|
|
|
|
} else {
|
|
|
|
PRUint8 a = NS_GET_A(color);
|
|
|
|
if (a < 255) {
|
2010-11-30 21:18:15 +03:00
|
|
|
aResult.AppendLiteral("rgba(");
|
2010-07-23 22:00:27 +04:00
|
|
|
} else {
|
2010-11-30 21:18:15 +03:00
|
|
|
aResult.AppendLiteral("rgb(");
|
2010-07-23 22:00:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_STRING(comma, ", ");
|
|
|
|
|
2010-11-30 21:18:15 +03:00
|
|
|
aResult.AppendInt(NS_GET_R(color), 10);
|
|
|
|
aResult.Append(comma);
|
|
|
|
aResult.AppendInt(NS_GET_G(color), 10);
|
|
|
|
aResult.Append(comma);
|
|
|
|
aResult.AppendInt(NS_GET_B(color), 10);
|
2010-07-23 22:00:27 +04:00
|
|
|
if (a < 255) {
|
2010-11-30 21:18:15 +03:00
|
|
|
aResult.Append(comma);
|
|
|
|
aResult.AppendFloat(nsStyleUtil::ColorComponentToFloat(a));
|
2010-07-23 22:00:27 +04:00
|
|
|
}
|
2010-11-30 21:18:15 +03:00
|
|
|
aResult.Append(PRUnichar(')'));
|
2010-07-23 22:00:27 +04: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 17:33:37 +04:00
|
|
|
else if (eCSSUnit_Element == unit) {
|
|
|
|
aResult.Append(NS_LITERAL_STRING("-moz-element(#"));
|
|
|
|
nsAutoString tmpStr;
|
|
|
|
GetStringValue(tmpStr);
|
|
|
|
nsStyleUtil::AppendEscapedCSSIdent(
|
|
|
|
nsDependentString(tmpStr), aResult);
|
|
|
|
aResult.Append(NS_LITERAL_STRING(")"));
|
|
|
|
}
|
2010-07-23 22:00:27 +04:00
|
|
|
else if (eCSSUnit_Percent == unit) {
|
2010-11-30 21:18:15 +03:00
|
|
|
aResult.AppendFloat(GetPercentValue() * 100.0f);
|
2010-07-23 22:00:27 +04:00
|
|
|
}
|
|
|
|
else if (eCSSUnit_Percent < unit) { // length unit
|
2010-11-30 21:18:15 +03:00
|
|
|
aResult.AppendFloat(GetFloatValue());
|
2010-07-23 22:00:27 +04:00
|
|
|
}
|
|
|
|
else if (eCSSUnit_Gradient == unit) {
|
|
|
|
nsCSSValueGradient* gradient = GetGradientValue();
|
|
|
|
|
|
|
|
if (gradient->mIsRepeating) {
|
|
|
|
if (gradient->mIsRadial)
|
|
|
|
aResult.AppendLiteral("-moz-repeating-radial-gradient(");
|
|
|
|
else
|
|
|
|
aResult.AppendLiteral("-moz-repeating-linear-gradient(");
|
|
|
|
} else {
|
|
|
|
if (gradient->mIsRadial)
|
|
|
|
aResult.AppendLiteral("-moz-radial-gradient(");
|
|
|
|
else
|
|
|
|
aResult.AppendLiteral("-moz-linear-gradient(");
|
|
|
|
}
|
|
|
|
|
2010-08-19 23:33:43 +04:00
|
|
|
if (gradient->mBgPos.mXValue.GetUnit() != eCSSUnit_None ||
|
|
|
|
gradient->mBgPos.mYValue.GetUnit() != eCSSUnit_None ||
|
2010-07-23 22:00:27 +04:00
|
|
|
gradient->mAngle.GetUnit() != eCSSUnit_None) {
|
2010-08-19 23:33:43 +04:00
|
|
|
if (gradient->mBgPos.mXValue.GetUnit() != eCSSUnit_None) {
|
|
|
|
gradient->mBgPos.mXValue.AppendToString(eCSSProperty_background_position,
|
|
|
|
aResult);
|
2010-07-23 22:00:27 +04:00
|
|
|
aResult.AppendLiteral(" ");
|
|
|
|
}
|
2010-08-19 23:33:43 +04:00
|
|
|
if (gradient->mBgPos.mXValue.GetUnit() != eCSSUnit_None) {
|
|
|
|
gradient->mBgPos.mYValue.AppendToString(eCSSProperty_background_position,
|
|
|
|
aResult);
|
2010-07-23 22:00:27 +04:00
|
|
|
aResult.AppendLiteral(" ");
|
|
|
|
}
|
|
|
|
if (gradient->mAngle.GetUnit() != eCSSUnit_None) {
|
|
|
|
gradient->mAngle.AppendToString(aProperty, aResult);
|
|
|
|
}
|
|
|
|
aResult.AppendLiteral(", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gradient->mIsRadial &&
|
|
|
|
(gradient->mRadialShape.GetUnit() != eCSSUnit_None ||
|
|
|
|
gradient->mRadialSize.GetUnit() != eCSSUnit_None)) {
|
|
|
|
if (gradient->mRadialShape.GetUnit() != eCSSUnit_None) {
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(gradient->mRadialShape.GetUnit() ==
|
|
|
|
eCSSUnit_Enumerated,
|
|
|
|
"bad unit for radial gradient shape");
|
2010-07-23 22:00:27 +04:00
|
|
|
PRInt32 intValue = gradient->mRadialShape.GetIntValue();
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(intValue != NS_STYLE_GRADIENT_SHAPE_LINEAR,
|
|
|
|
"radial gradient with linear shape?!");
|
2010-07-23 22:00:27 +04:00
|
|
|
AppendASCIItoUTF16(nsCSSProps::ValueToKeyword(intValue,
|
|
|
|
nsCSSProps::kRadialGradientShapeKTable),
|
|
|
|
aResult);
|
|
|
|
aResult.AppendLiteral(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gradient->mRadialSize.GetUnit() != eCSSUnit_None) {
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(gradient->mRadialSize.GetUnit() ==
|
|
|
|
eCSSUnit_Enumerated,
|
|
|
|
"bad unit for radial gradient size");
|
2010-07-23 22:00:27 +04:00
|
|
|
PRInt32 intValue = gradient->mRadialSize.GetIntValue();
|
|
|
|
AppendASCIItoUTF16(nsCSSProps::ValueToKeyword(intValue,
|
|
|
|
nsCSSProps::kRadialGradientSizeKTable),
|
|
|
|
aResult);
|
|
|
|
}
|
|
|
|
aResult.AppendLiteral(", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (PRUint32 i = 0 ;;) {
|
|
|
|
gradient->mStops[i].mColor.AppendToString(aProperty, aResult);
|
|
|
|
if (gradient->mStops[i].mLocation.GetUnit() != eCSSUnit_None) {
|
|
|
|
aResult.AppendLiteral(" ");
|
|
|
|
gradient->mStops[i].mLocation.AppendToString(aProperty, aResult);
|
|
|
|
}
|
|
|
|
if (++i == gradient->mStops.Length()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
aResult.AppendLiteral(", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
aResult.AppendLiteral(")");
|
2010-08-19 23:33:44 +04:00
|
|
|
} else if (eCSSUnit_Pair == unit) {
|
|
|
|
GetPairValue().AppendToString(aProperty, aResult);
|
2010-08-19 23:33:44 +04:00
|
|
|
} else if (eCSSUnit_Rect == unit) {
|
|
|
|
GetRectValue().AppendToString(aProperty, aResult);
|
2010-08-19 23:33:44 +04:00
|
|
|
} else if (eCSSUnit_List == unit || eCSSUnit_ListDep == unit) {
|
|
|
|
GetListValue()->AppendToString(aProperty, aResult);
|
2010-08-19 23:33:44 +04:00
|
|
|
} else if (eCSSUnit_PairList == unit || eCSSUnit_PairListDep == unit) {
|
|
|
|
GetPairListValue()->AppendToString(aProperty, aResult);
|
2010-07-23 22:00:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (unit) {
|
|
|
|
case eCSSUnit_Null: break;
|
|
|
|
case eCSSUnit_Auto: aResult.AppendLiteral("auto"); break;
|
|
|
|
case eCSSUnit_Inherit: aResult.AppendLiteral("inherit"); break;
|
|
|
|
case eCSSUnit_Initial: aResult.AppendLiteral("-moz-initial"); break;
|
|
|
|
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 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(false, "should never serialize");
|
2010-07-23 22:00:27 +04: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 17:33:37 +04:00
|
|
|
case eCSSUnit_Element: break;
|
2010-07-23 22:00:27 +04:00
|
|
|
case eCSSUnit_Array: break;
|
|
|
|
case eCSSUnit_Attr:
|
|
|
|
case eCSSUnit_Cubic_Bezier:
|
2011-04-12 10:18:42 +04:00
|
|
|
case eCSSUnit_Steps:
|
2010-07-23 22:00:27 +04:00
|
|
|
case eCSSUnit_Counter:
|
|
|
|
case eCSSUnit_Counters: aResult.Append(PRUnichar(')')); break;
|
|
|
|
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;
|
|
|
|
case eCSSUnit_EnumColor: break;
|
|
|
|
case eCSSUnit_Color: break;
|
|
|
|
case eCSSUnit_Percent: aResult.Append(PRUnichar('%')); break;
|
|
|
|
case eCSSUnit_Number: break;
|
|
|
|
case eCSSUnit_Gradient: break;
|
2010-08-19 23:33:44 +04:00
|
|
|
case eCSSUnit_Pair: break;
|
2010-08-19 23:33:44 +04:00
|
|
|
case eCSSUnit_Rect: break;
|
2010-08-19 23:33:44 +04:00
|
|
|
case eCSSUnit_List: break;
|
|
|
|
case eCSSUnit_ListDep: break;
|
2010-08-19 23:33:44 +04:00
|
|
|
case eCSSUnit_PairList: break;
|
|
|
|
case eCSSUnit_PairListDep: break;
|
2010-07-23 22:00:27 +04:00
|
|
|
|
|
|
|
case eCSSUnit_Inch: aResult.AppendLiteral("in"); break;
|
|
|
|
case eCSSUnit_Millimeter: aResult.AppendLiteral("mm"); break;
|
2010-08-13 13:58:02 +04:00
|
|
|
case eCSSUnit_PhysicalMillimeter: aResult.AppendLiteral("mozmm"); break;
|
2010-07-23 22:00:27 +04:00
|
|
|
case eCSSUnit_Centimeter: aResult.AppendLiteral("cm"); break;
|
|
|
|
case eCSSUnit_Point: aResult.AppendLiteral("pt"); break;
|
|
|
|
case eCSSUnit_Pica: aResult.AppendLiteral("pc"); break;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
case eCSSUnit_Hertz: aResult.AppendLiteral("Hz"); break;
|
|
|
|
case eCSSUnit_Kilohertz: aResult.AppendLiteral("kHz"); break;
|
|
|
|
|
|
|
|
case eCSSUnit_Seconds: aResult.Append(PRUnichar('s')); break;
|
|
|
|
case eCSSUnit_Milliseconds: aResult.AppendLiteral("ms"); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-19 23:33:43 +04: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSValueList::AppendToString(nsCSSProperty aProperty, nsAString& aResult) const
|
|
|
|
{
|
|
|
|
const nsCSSValueList* val = this;
|
|
|
|
for (;;) {
|
|
|
|
val->mValue.AppendToString(aProperty, aResult);
|
|
|
|
val = val->mNext;
|
|
|
|
if (!val)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (nsCSSProps::PropHasFlags(aProperty,
|
|
|
|
CSS_PROPERTY_VALUE_LIST_USES_COMMAS))
|
|
|
|
aResult.Append(PRUnichar(','));
|
|
|
|
aResult.Append(PRUnichar(' '));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- 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
|
|
|
|
nsCSSRect::AppendToString(nsCSSProperty aProperty, nsAString& aResult) const
|
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(mTop.GetUnit() != eCSSUnit_Null &&
|
|
|
|
mTop.GetUnit() != eCSSUnit_Inherit &&
|
|
|
|
mTop.GetUnit() != eCSSUnit_Initial,
|
|
|
|
"parser should have used a bare value");
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_STRING(comma, ", ");
|
|
|
|
|
|
|
|
aResult.AppendLiteral("rect(");
|
|
|
|
mTop.AppendToString(aProperty, aResult);
|
|
|
|
aResult.Append(comma);
|
|
|
|
mRight.AppendToString(aProperty, aResult);
|
|
|
|
aResult.Append(comma);
|
|
|
|
mBottom.AppendToString(aProperty, aResult);
|
|
|
|
aResult.Append(comma);
|
|
|
|
mLeft.AppendToString(aProperty, aResult);
|
|
|
|
aResult.Append(PRUnichar(')'));
|
2010-08-19 23:33:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSRect::SetAllSidesTo(const nsCSSValue& aValue)
|
|
|
|
{
|
|
|
|
mTop = aValue;
|
|
|
|
mRight = aValue;
|
|
|
|
mBottom = aValue;
|
|
|
|
mLeft = aValue;
|
|
|
|
}
|
|
|
|
|
2010-08-19 23:33:44 +04:00
|
|
|
PR_STATIC_ASSERT(NS_SIDE_TOP == 0 && NS_SIDE_RIGHT == 1 &&
|
|
|
|
NS_SIDE_BOTTOM == 2 && NS_SIDE_LEFT == 3);
|
2010-08-19 23:33:43 +04:00
|
|
|
|
|
|
|
/* static */ const nsCSSRect::side_type nsCSSRect::sides[4] = {
|
|
|
|
&nsCSSRect::mTop,
|
|
|
|
&nsCSSRect::mRight,
|
|
|
|
&nsCSSRect::mBottom,
|
|
|
|
&nsCSSRect::mLeft,
|
|
|
|
};
|
|
|
|
|
|
|
|
// --- nsCSSValuePair -----------------
|
|
|
|
|
|
|
|
void
|
2010-08-19 23:33:44 +04:00
|
|
|
nsCSSValuePair::AppendToString(nsCSSProperty aProperty,
|
|
|
|
nsAString& aResult) const
|
2010-08-19 23:33:43 +04:00
|
|
|
{
|
|
|
|
mXValue.AppendToString(aProperty, aResult);
|
2010-08-19 23:33:44 +04:00
|
|
|
if (mYValue.GetUnit() != eCSSUnit_Null) {
|
2010-08-19 23:33:43 +04:00
|
|
|
aResult.Append(PRUnichar(' '));
|
|
|
|
mYValue.AppendToString(aProperty, aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- 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,
|
|
|
|
nsAString& aResult) const
|
|
|
|
{
|
|
|
|
const nsCSSValuePairList* item = this;
|
|
|
|
for (;;) {
|
|
|
|
NS_ABORT_IF_FALSE(item->mXValue.GetUnit() != eCSSUnit_Null,
|
|
|
|
"unexpected null unit");
|
|
|
|
item->mXValue.AppendToString(aProperty, aResult);
|
|
|
|
if (item->mXValue.GetUnit() != eCSSUnit_Inherit &&
|
|
|
|
item->mXValue.GetUnit() != eCSSUnit_Initial &&
|
|
|
|
item->mYValue.GetUnit() != eCSSUnit_Null) {
|
|
|
|
aResult.Append(PRUnichar(' '));
|
|
|
|
item->mYValue.AppendToString(aProperty, aResult);
|
|
|
|
}
|
|
|
|
item = item->mNext;
|
|
|
|
if (!item)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (nsCSSProps::PropHasFlags(aProperty,
|
|
|
|
CSS_PROPERTY_VALUE_LIST_USES_COMMAS))
|
|
|
|
aResult.Append(PRUnichar(','));
|
|
|
|
aResult.Append(PRUnichar(' '));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2011-05-11 19:28:53 +04:00
|
|
|
nsCSSValue::URL::URL(nsIURI* aURI, nsStringBuffer* aString,
|
|
|
|
nsIURI* aReferrer, nsIPrincipal* aOriginPrincipal)
|
2007-05-03 05:15:53 +04:00
|
|
|
: mURI(aURI),
|
|
|
|
mString(aString),
|
|
|
|
mReferrer(aReferrer),
|
2011-05-11 19:28:53 +04:00
|
|
|
mOriginPrincipal(aOriginPrincipal),
|
|
|
|
mURIResolved(PR_TRUE)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aOriginPrincipal, "Must have an origin principal");
|
|
|
|
mString->AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue::URL::URL(nsStringBuffer* aString, nsIURI* aBaseURI,
|
|
|
|
nsIURI* aReferrer, nsIPrincipal* aOriginPrincipal)
|
|
|
|
: mURI(aBaseURI),
|
|
|
|
mString(aString),
|
|
|
|
mReferrer(aReferrer),
|
|
|
|
mOriginPrincipal(aOriginPrincipal),
|
|
|
|
mURIResolved(PR_FALSE)
|
2007-05-03 05:15:53 +04:00
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(aOriginPrincipal, "Must have an origin principal");
|
2007-05-03 05:15:53 +04:00
|
|
|
mString->AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue::URL::~URL()
|
|
|
|
{
|
|
|
|
mString->Release();
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsCSSValue::URL::operator==(const URL& aOther) const
|
|
|
|
{
|
|
|
|
PRBool eq;
|
|
|
|
return NS_strcmp(GetBufferValue(mString),
|
|
|
|
GetBufferValue(aOther.mString)) == 0 &&
|
2011-05-11 19:28:53 +04:00
|
|
|
(GetURI() == aOther.GetURI() || // handles null == null
|
2007-05-03 05:15:53 +04:00
|
|
|
(mURI && aOther.mURI &&
|
|
|
|
NS_SUCCEEDED(mURI->Equals(aOther.mURI, &eq)) &&
|
|
|
|
eq)) &&
|
2007-07-19 02:17:30 +04:00
|
|
|
(mOriginPrincipal == aOther.mOriginPrincipal ||
|
|
|
|
(NS_SUCCEEDED(mOriginPrincipal->Equals(aOther.mOriginPrincipal,
|
|
|
|
&eq)) && eq));
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsCSSValue::URL::URIEquals(const URL& aOther) const
|
|
|
|
{
|
2011-05-11 19:28:53 +04:00
|
|
|
NS_ABORT_IF_FALSE(mURIResolved && aOther.mURIResolved,
|
|
|
|
"How do you know the URIs aren't null?");
|
2007-07-19 02:17:30 +04:00
|
|
|
PRBool eq;
|
2011-05-11 19:28:53 +04:00
|
|
|
// Worth comparing GetURI() to aOther.GetURI() and mOriginPrincipal to
|
2007-07-19 02:17:30 +04: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 05:15:53 +04:00
|
|
|
}
|
|
|
|
|
2011-05-11 19:28:53 +04:00
|
|
|
nsIURI*
|
|
|
|
nsCSSValue::URL::GetURI() const
|
|
|
|
{
|
|
|
|
if (!mURIResolved) {
|
|
|
|
mURIResolved = PR_TRUE;
|
|
|
|
// Be careful to not null out mURI before we've passed it as the base URI
|
|
|
|
nsCOMPtr<nsIURI> newURI;
|
|
|
|
NS_NewURI(getter_AddRefs(newURI),
|
|
|
|
NS_ConvertUTF16toUTF8(GetBufferValue(mString)), nsnull, mURI);
|
|
|
|
newURI.swap(mURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mURI;
|
|
|
|
}
|
|
|
|
|
2006-12-13 18:49:36 +03:00
|
|
|
nsCSSValue::Image::Image(nsIURI* aURI, nsStringBuffer* aString,
|
2007-05-03 05:15:53 +04:00
|
|
|
nsIURI* aReferrer, nsIPrincipal* aOriginPrincipal,
|
2007-07-03 17:59:02 +04:00
|
|
|
nsIDocument* aDocument)
|
2007-05-03 05:15:53 +04:00
|
|
|
: URL(aURI, aString, aReferrer, aOriginPrincipal)
|
2004-03-09 06:57:51 +03:00
|
|
|
{
|
2010-10-09 14:03:06 +04:00
|
|
|
if (aDocument->GetOriginalDocument()) {
|
|
|
|
aDocument = aDocument->GetOriginalDocument();
|
|
|
|
}
|
2011-05-11 19:28:53 +04:00
|
|
|
if (aURI &&
|
|
|
|
nsContentUtils::CanLoadImage(aURI, aDocument, aDocument,
|
2007-07-03 22:45:39 +04:00
|
|
|
aOriginPrincipal)) {
|
2011-05-11 19:28:53 +04:00
|
|
|
nsContentUtils::LoadImage(aURI, aDocument, aOriginPrincipal, aReferrer,
|
2007-07-03 22:45:39 +04:00
|
|
|
nsnull, nsIRequest::LOAD_NORMAL,
|
2004-03-09 06:57:51 +03:00
|
|
|
getter_AddRefs(mRequest));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue::Image::~Image()
|
|
|
|
{
|
2009-08-01 19:53:40 +04:00
|
|
|
}
|
|
|
|
|
2009-11-02 22:36:43 +03:00
|
|
|
nsCSSValueGradientStop::nsCSSValueGradientStop()
|
|
|
|
: mLocation(eCSSUnit_None),
|
|
|
|
mColor(eCSSUnit_Null)
|
|
|
|
{
|
2009-08-01 19:53:40 +04:00
|
|
|
MOZ_COUNT_CTOR(nsCSSValueGradientStop);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValueGradientStop::nsCSSValueGradientStop(const nsCSSValueGradientStop& aOther)
|
|
|
|
: mLocation(aOther.mLocation),
|
|
|
|
mColor(aOther.mColor)
|
2009-11-02 22:36:43 +03:00
|
|
|
{
|
2009-08-01 19:53:40 +04:00
|
|
|
MOZ_COUNT_CTOR(nsCSSValueGradientStop);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValueGradientStop::~nsCSSValueGradientStop()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsCSSValueGradientStop);
|
|
|
|
}
|
|
|
|
|
2009-11-02 22:36:43 +03:00
|
|
|
nsCSSValueGradient::nsCSSValueGradient(PRBool aIsRadial,
|
|
|
|
PRBool aIsRepeating)
|
2009-08-01 19:53:40 +04:00
|
|
|
: mIsRadial(aIsRadial),
|
2009-11-02 22:36:43 +03:00
|
|
|
mIsRepeating(aIsRepeating),
|
2010-08-19 23:33:43 +04:00
|
|
|
mBgPos(eCSSUnit_None),
|
2009-11-02 22:36:43 +03:00
|
|
|
mAngle(eCSSUnit_None),
|
|
|
|
mRadialShape(eCSSUnit_None),
|
2010-04-01 22:05:40 +04:00
|
|
|
mRadialSize(eCSSUnit_None)
|
2009-11-02 22:36:43 +03:00
|
|
|
{
|
2004-03-09 06:57:51 +03:00
|
|
|
}
|
2011-03-29 03:07:26 +04: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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_STATIC_ASSERT(NS_CORNER_TOP_LEFT == 0 && NS_CORNER_TOP_RIGHT == 1 && \
|
|
|
|
NS_CORNER_BOTTOM_RIGHT == 2 && NS_CORNER_BOTTOM_LEFT == 3);
|
|
|
|
|
|
|
|
/* static */ const nsCSSCornerSizes::corner_type
|
|
|
|
nsCSSCornerSizes::corners[4] = {
|
|
|
|
&nsCSSCornerSizes::mTopLeft,
|
|
|
|
&nsCSSCornerSizes::mTopRight,
|
|
|
|
&nsCSSCornerSizes::mBottomRight,
|
|
|
|
&nsCSSCornerSizes::mBottomLeft,
|
|
|
|
};
|
|
|
|
|