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"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCSSProps.h"
|
2000-08-23 21:27:06 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2004-03-09 06:57:51 +03:00
|
|
|
#include "imgIRequest.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsContentUtils.h"
|
2007-05-03 05:15:53 +04:00
|
|
|
#include "nsIPrincipal.h"
|
2009-11-02 22:36:43 +03:00
|
|
|
#include "nsMathUtils.h"
|
2004-03-09 06:57:51 +03:00
|
|
|
|
|
|
|
// Paint forcing
|
|
|
|
#include "prenv.h"
|
1998-10-08 05:29:29 +04:00
|
|
|
|
|
|
|
nsCSSValue::nsCSSValue(PRInt32 aValue, nsCSSUnit aUnit)
|
|
|
|
: mUnit(aUnit)
|
|
|
|
{
|
2008-02-08 22:51:41 +03:00
|
|
|
NS_ASSERTION(aUnit == eCSSUnit_Integer || aUnit == eCSSUnit_Enumerated ||
|
|
|
|
aUnit == eCSSUnit_EnumColor, "not an int value");
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(eCSSUnit_Percent <= aUnit, "not a float value");
|
|
|
|
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
|
|
|
{
|
2008-08-08 03:15:40 +04:00
|
|
|
NS_ASSERTION(UnitHasStringValue(), "not a string value");
|
|
|
|
if (UnitHasStringValue()) {
|
2006-12-13 18:49:36 +03:00
|
|
|
mValue.mString = BufferFromString(aValue);
|
|
|
|
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-05-11 19:49:43 +04:00
|
|
|
NS_ASSERTION(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)
|
|
|
|
{
|
2008-12-29 18:07:38 +03:00
|
|
|
if (mUnit <= eCSSUnit_RectIsAuto) {
|
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();
|
|
|
|
}
|
1998-10-08 05:29:29 +04:00
|
|
|
else {
|
2008-03-13 01:05:27 +03:00
|
|
|
NS_NOTREACHED("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
|
|
|
|
{
|
|
|
|
if (mUnit == aOther.mUnit) {
|
2008-12-29 18:07:38 +03:00
|
|
|
if (mUnit <= eCSSUnit_RectIsAuto) {
|
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;
|
|
|
|
}
|
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:
|
|
|
|
NS_NOTREACHED("unrecognized angular unit");
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-09 06:57:51 +03:00
|
|
|
imgIRequest* nsCSSValue::GetImageValue() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mUnit == eCSSUnit_Image, "not an Image value");
|
|
|
|
return mValue.mImage->mRequest;
|
|
|
|
}
|
|
|
|
|
2006-02-22 01:56:02 +03:00
|
|
|
nscoord nsCSSValue::GetLengthTwips() const
|
2003-12-29 22:07:53 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(IsFixedLengthUnit(), "not a fixed length unit");
|
|
|
|
|
|
|
|
if (IsFixedLengthUnit()) {
|
|
|
|
switch (mUnit) {
|
|
|
|
case eCSSUnit_Inch:
|
2006-02-22 01:56:02 +03:00
|
|
|
return NS_INCHES_TO_TWIPS(mValue.mFloat);
|
2003-12-29 22:07:53 +03:00
|
|
|
|
|
|
|
case eCSSUnit_Millimeter:
|
2006-02-22 01:56:02 +03:00
|
|
|
return NS_MILLIMETERS_TO_TWIPS(mValue.mFloat);
|
2003-12-29 22:07:53 +03:00
|
|
|
case eCSSUnit_Centimeter:
|
2006-02-22 01:56:02 +03:00
|
|
|
return NS_CENTIMETERS_TO_TWIPS(mValue.mFloat);
|
2003-12-29 22:07:53 +03:00
|
|
|
|
|
|
|
case eCSSUnit_Point:
|
2007-02-07 10:46:44 +03:00
|
|
|
return NS_POINTS_TO_TWIPS(mValue.mFloat);
|
2003-12-29 22:07:53 +03:00
|
|
|
case eCSSUnit_Pica:
|
2006-02-22 01:56:02 +03:00
|
|
|
return NS_PICAS_TO_TWIPS(mValue.mFloat);
|
2003-12-29 22:07:53 +03:00
|
|
|
default:
|
|
|
|
NS_ERROR("should never get here");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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();
|
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)
|
|
|
|
{
|
2008-02-08 22:51:41 +03:00
|
|
|
NS_ASSERTION(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)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(eCSSUnit_Number <= aUnit, "not a float value");
|
|
|
|
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;
|
|
|
|
NS_ASSERTION(UnitHasStringValue(), "not a string unit");
|
|
|
|
if (UnitHasStringValue()) {
|
2006-12-13 18:49:36 +03:00
|
|
|
mValue.mString = BufferFromString(aValue);
|
|
|
|
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-05-11 19:49:43 +04:00
|
|
|
NS_ASSERTION(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();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
NS_PRECONDITION(eCSSUnit_URL == mUnit, "Not a URL value!");
|
|
|
|
nsCSSValue::Image* image =
|
|
|
|
new nsCSSValue::Image(mValue.mURL->mURI,
|
|
|
|
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
|
|
|
|
nsStringBuffer*
|
|
|
|
nsCSSValue::BufferFromString(const nsString& aValue)
|
|
|
|
{
|
|
|
|
nsStringBuffer* buffer = nsStringBuffer::FromString(aValue);
|
|
|
|
if (buffer) {
|
|
|
|
buffer->AddRef();
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUnichar length = aValue.Length();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-05-03 05:15:53 +04:00
|
|
|
nsCSSValue::URL::URL(nsIURI* aURI, nsStringBuffer* aString, nsIURI* aReferrer,
|
|
|
|
nsIPrincipal* aOriginPrincipal)
|
|
|
|
: mURI(aURI),
|
|
|
|
mString(aString),
|
|
|
|
mReferrer(aReferrer),
|
2010-04-01 22:05:40 +04:00
|
|
|
mOriginPrincipal(aOriginPrincipal)
|
2007-05-03 05:15:53 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aOriginPrincipal, "Must have an origin principal");
|
|
|
|
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 &&
|
|
|
|
(mURI == aOther.mURI || // handles null == null
|
|
|
|
(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
|
|
|
|
{
|
|
|
|
PRBool eq;
|
|
|
|
// Worth comparing mURI to aOther.mURI and mOriginPrincipal to
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
if (mURI &&
|
2007-07-03 22:45:39 +04:00
|
|
|
nsContentUtils::CanLoadImage(mURI, aDocument, aDocument,
|
|
|
|
aOriginPrincipal)) {
|
|
|
|
nsContentUtils::LoadImage(mURI, aDocument, aOriginPrincipal, aReferrer,
|
|
|
|
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),
|
|
|
|
mBgPosX(eCSSUnit_None),
|
|
|
|
mBgPosY(eCSSUnit_None),
|
|
|
|
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
|
|
|
}
|