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
|
|
|
#ifndef nsCSSValue_h___
|
|
|
|
#define nsCSSValue_h___
|
|
|
|
|
|
|
|
#include "nsColor.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCoord.h"
|
2003-06-08 02:14:42 +04:00
|
|
|
#include "nsCSSProperty.h"
|
2009-08-22 00:39:25 +04:00
|
|
|
#include "nsCSSKeywords.h"
|
2003-10-02 02:53:56 +04:00
|
|
|
#include "nsIURI.h"
|
2003-10-30 04:45:37 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2004-03-09 06:57:51 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2006-08-25 07:27:47 +04:00
|
|
|
#include "nsCRTGlue.h"
|
2006-12-13 18:49:36 +03:00
|
|
|
#include "nsStringBuffer.h"
|
2009-08-01 19:53:40 +04:00
|
|
|
#include "nsTArray.h"
|
2004-03-09 06:57:51 +03:00
|
|
|
|
|
|
|
class imgIRequest;
|
|
|
|
class nsIDocument;
|
2007-05-03 05:15:53 +04:00
|
|
|
class nsIPrincipal;
|
1998-10-08 05:29:29 +04:00
|
|
|
|
2008-10-17 12:13:16 +04:00
|
|
|
// Deletes a linked list iteratively to avoid blowing up the stack (bug 456196).
|
|
|
|
#define NS_CSS_DELETE_LIST_MEMBER(type_, ptr_, member_) \
|
|
|
|
{ \
|
|
|
|
type_ *cur = (ptr_)->member_; \
|
|
|
|
(ptr_)->member_ = nsnull; \
|
|
|
|
while (cur) { \
|
|
|
|
type_ *next = cur->member_; \
|
|
|
|
cur->member_ = nsnull; \
|
|
|
|
delete cur; \
|
|
|
|
cur = next; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clones a linked list iteratively to avoid blowing up the stack.
|
|
|
|
// If it fails to clone the entire list then 'to_' is deleted and
|
|
|
|
// we return null.
|
|
|
|
#define NS_CSS_CLONE_LIST_MEMBER(type_, from_, member_, to_, args_) \
|
|
|
|
{ \
|
|
|
|
type_ *dest = (to_); \
|
|
|
|
(to_)->member_ = nsnull; \
|
|
|
|
for (const type_ *src = (from_)->member_; src; src = src->member_) { \
|
|
|
|
type_ *clone = src->Clone args_; \
|
|
|
|
if (!clone) { \
|
|
|
|
delete (to_); \
|
|
|
|
return nsnull; \
|
|
|
|
} \
|
|
|
|
dest->member_ = clone; \
|
|
|
|
dest = clone; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
1998-10-08 05:29:29 +04:00
|
|
|
enum nsCSSUnit {
|
1998-10-27 02:19:59 +03:00
|
|
|
eCSSUnit_Null = 0, // (n/a) null unit, value is not specified
|
|
|
|
eCSSUnit_Auto = 1, // (n/a) value is algorithmic
|
|
|
|
eCSSUnit_Inherit = 2, // (n/a) value is inherited
|
2001-06-01 02:19:43 +04:00
|
|
|
eCSSUnit_Initial = 3, // (n/a) value is default UA value
|
|
|
|
eCSSUnit_None = 4, // (n/a) value is none
|
|
|
|
eCSSUnit_Normal = 5, // (n/a) value is normal (algorithmic, different than auto)
|
2007-06-12 22:28:56 +04:00
|
|
|
eCSSUnit_System_Font = 6, // (n/a) value is -moz-use-system-font
|
2009-08-21 01:52:47 +04:00
|
|
|
eCSSUnit_All = 7, // (n/a) value is all
|
|
|
|
eCSSUnit_Dummy = 8, // (n/a) a fake but specified value, used
|
2007-10-09 03:11:01 +04:00
|
|
|
// only in temporary values
|
2009-08-21 01:52:47 +04:00
|
|
|
eCSSUnit_DummyInherit = 9, // (n/a) a fake but specified value, used
|
2008-10-07 22:53:22 +04:00
|
|
|
// only in temporary values
|
2009-08-21 01:52:47 +04:00
|
|
|
eCSSUnit_RectIsAuto = 10, // (n/a) 'auto' for an entire rect()
|
|
|
|
eCSSUnit_String = 11, // (PRUnichar*) a string value
|
|
|
|
eCSSUnit_Ident = 12, // (PRUnichar*) a string value
|
|
|
|
eCSSUnit_Families = 13, // (PRUnichar*) a string value
|
|
|
|
eCSSUnit_Attr = 14, // (PRUnichar*) a attr(string) value
|
|
|
|
eCSSUnit_Local_Font = 15, // (PRUnichar*) a local font name
|
|
|
|
eCSSUnit_Font_Format = 16, // (PRUnichar*) a font format name
|
2005-04-02 03:07:00 +04:00
|
|
|
eCSSUnit_Array = 20, // (nsCSSValue::Array*) a list of values
|
|
|
|
eCSSUnit_Counter = 21, // (nsCSSValue::Array*) a counter(string,[string]) value
|
|
|
|
eCSSUnit_Counters = 22, // (nsCSSValue::Array*) a counters(string,string[,string]) value
|
2009-08-21 01:52:47 +04:00
|
|
|
eCSSUnit_Cubic_Bezier = 23, // (nsCSSValue::Array*) a list of float values
|
|
|
|
eCSSUnit_Function = 24, // (nsCSSValue::Array*) a function with parameters. First elem of array is name,
|
2008-09-13 13:42:11 +04:00
|
|
|
// the rest of the values are arguments.
|
|
|
|
|
2005-04-02 03:07:00 +04:00
|
|
|
eCSSUnit_URL = 30, // (nsCSSValue::URL*) value
|
|
|
|
eCSSUnit_Image = 31, // (nsCSSValue::Image*) value
|
2009-08-01 19:53:40 +04:00
|
|
|
eCSSUnit_Gradient = 32, // (nsCSSValueGradient*) value
|
1998-10-27 02:19:59 +03:00
|
|
|
eCSSUnit_Integer = 50, // (int) simple value
|
|
|
|
eCSSUnit_Enumerated = 51, // (int) value has enumerated meaning
|
2008-02-08 22:51:41 +03:00
|
|
|
eCSSUnit_EnumColor = 80, // (int) enumerated color (kColorKTable)
|
|
|
|
eCSSUnit_Color = 81, // (nscolor) an RGBA value
|
1998-10-27 02:19:59 +03:00
|
|
|
eCSSUnit_Percent = 90, // (float) 1.0 == 100%) value is percentage of something
|
|
|
|
eCSSUnit_Number = 91, // (float) value is numeric (usually multiplier, different behavior that percent)
|
|
|
|
|
|
|
|
// Length units - fixed
|
1998-10-08 05:29:29 +04:00
|
|
|
// US English
|
2005-04-02 03:07:00 +04:00
|
|
|
eCSSUnit_Inch = 100, // (float) 0.0254 meters
|
1998-10-08 05:29:29 +04:00
|
|
|
|
|
|
|
// Metric
|
1998-10-27 02:19:59 +03:00
|
|
|
eCSSUnit_Millimeter = 207, // (float) 1/1000 meter
|
|
|
|
eCSSUnit_Centimeter = 208, // (float) 1/100 meter
|
1998-10-08 05:29:29 +04:00
|
|
|
|
|
|
|
// US Typographic
|
1998-10-27 02:19:59 +03:00
|
|
|
eCSSUnit_Point = 300, // (float) 1/72 inch
|
|
|
|
eCSSUnit_Pica = 301, // (float) 12 points == 1/6 inch
|
1998-10-08 05:29:29 +04:00
|
|
|
|
1998-10-27 02:19:59 +03:00
|
|
|
// Length units - relative
|
1998-10-08 05:29:29 +04:00
|
|
|
// Font relative measure
|
1998-10-27 02:19:59 +03:00
|
|
|
eCSSUnit_EM = 800, // (float) == current font size
|
2008-12-04 19:09:53 +03:00
|
|
|
eCSSUnit_XHeight = 801, // (float) distance from top of lower case x to baseline
|
|
|
|
eCSSUnit_Char = 802, // (float) number of characters, used for width with monospace font
|
2009-01-21 00:58:48 +03:00
|
|
|
eCSSUnit_RootEM = 803, // (float) == root element font size
|
1998-10-08 05:29:29 +04:00
|
|
|
|
|
|
|
// Screen relative measure
|
2005-04-02 03:07:00 +04:00
|
|
|
eCSSUnit_Pixel = 900, // (float) CSS pixel unit
|
1998-10-27 02:19:59 +03:00
|
|
|
|
|
|
|
// Angular units
|
|
|
|
eCSSUnit_Degree = 1000, // (float) 360 per circle
|
|
|
|
eCSSUnit_Grad = 1001, // (float) 400 per circle
|
2005-04-02 03:07:00 +04:00
|
|
|
eCSSUnit_Radian = 1002, // (float) 2*pi per circle
|
1998-10-27 02:19:59 +03:00
|
|
|
|
|
|
|
// Frequency units
|
2005-04-02 03:07:00 +04:00
|
|
|
eCSSUnit_Hertz = 2000, // (float) 1/seconds
|
|
|
|
eCSSUnit_Kilohertz = 2001, // (float) 1000 Hertz
|
1998-10-27 02:19:59 +03:00
|
|
|
|
|
|
|
// Time units
|
2005-04-02 03:07:00 +04:00
|
|
|
eCSSUnit_Seconds = 3000, // (float) Standard time
|
|
|
|
eCSSUnit_Milliseconds = 3001 // (float) 1/1000 second
|
1998-10-08 05:29:29 +04:00
|
|
|
};
|
|
|
|
|
2009-08-01 19:53:40 +04:00
|
|
|
struct nsCSSValueGradient;
|
|
|
|
|
1998-10-08 05:29:29 +04:00
|
|
|
class nsCSSValue {
|
|
|
|
public:
|
2005-04-02 03:07:00 +04:00
|
|
|
struct Array;
|
|
|
|
friend struct Array;
|
|
|
|
|
2003-10-30 04:45:37 +03:00
|
|
|
struct URL;
|
|
|
|
friend struct URL;
|
|
|
|
|
2004-03-09 06:57:51 +03:00
|
|
|
struct Image;
|
|
|
|
friend struct Image;
|
|
|
|
|
2009-08-21 01:52:47 +04:00
|
|
|
// for valueless units only (null, auto, inherit, none, all, normal)
|
2004-08-21 00:55:17 +04:00
|
|
|
explicit nsCSSValue(nsCSSUnit aUnit = eCSSUnit_Null)
|
2001-02-19 15:55:42 +03:00
|
|
|
: mUnit(aUnit)
|
|
|
|
{
|
2008-12-29 18:07:38 +03:00
|
|
|
NS_ASSERTION(aUnit <= eCSSUnit_RectIsAuto, "not a valueless unit");
|
2001-02-19 15:55:42 +03:00
|
|
|
}
|
|
|
|
|
2004-05-13 01:20:09 +04:00
|
|
|
nsCSSValue(PRInt32 aValue, nsCSSUnit aUnit) NS_HIDDEN;
|
|
|
|
nsCSSValue(float aValue, nsCSSUnit aUnit) NS_HIDDEN;
|
2006-12-13 18:49:36 +03:00
|
|
|
nsCSSValue(const nsString& aValue, nsCSSUnit aUnit) NS_HIDDEN;
|
2005-04-02 03:07:00 +04:00
|
|
|
nsCSSValue(Array* aArray, nsCSSUnit aUnit) NS_HIDDEN;
|
2004-08-21 00:55:17 +04:00
|
|
|
explicit nsCSSValue(URL* aValue) NS_HIDDEN;
|
|
|
|
explicit nsCSSValue(Image* aValue) NS_HIDDEN;
|
2009-08-01 19:53:40 +04:00
|
|
|
explicit nsCSSValue(nsCSSValueGradient* aValue) NS_HIDDEN;
|
2004-05-13 01:20:09 +04:00
|
|
|
nsCSSValue(const nsCSSValue& aCopy) NS_HIDDEN;
|
2007-08-28 10:47:32 +04:00
|
|
|
~nsCSSValue() { Reset(); }
|
2004-05-13 01:20:09 +04:00
|
|
|
|
|
|
|
NS_HIDDEN_(nsCSSValue&) operator=(const nsCSSValue& aCopy);
|
|
|
|
NS_HIDDEN_(PRBool) operator==(const nsCSSValue& aOther) const;
|
2003-10-02 02:53:56 +04:00
|
|
|
|
|
|
|
PRBool operator!=(const nsCSSValue& aOther) const
|
|
|
|
{
|
|
|
|
return !(*this == aOther);
|
|
|
|
}
|
1998-10-08 05:29:29 +04:00
|
|
|
|
2007-04-23 18:21:53 +04:00
|
|
|
nsCSSUnit GetUnit() const { return mUnit; }
|
2003-12-29 22:07:53 +03:00
|
|
|
PRBool IsLengthUnit() const
|
2008-08-08 03:15:40 +04:00
|
|
|
{ return eCSSUnit_Inch <= mUnit && mUnit <= eCSSUnit_Pixel; }
|
2003-12-29 22:07:53 +03:00
|
|
|
PRBool IsFixedLengthUnit() const
|
2009-03-10 02:14:34 +03:00
|
|
|
{ return eCSSUnit_Inch <= mUnit && mUnit <= eCSSUnit_Pica; }
|
2003-12-29 22:07:53 +03:00
|
|
|
PRBool IsRelativeLengthUnit() const
|
2008-08-08 03:15:40 +04:00
|
|
|
{ return eCSSUnit_EM <= mUnit && mUnit <= eCSSUnit_Pixel; }
|
2003-12-29 22:07:53 +03:00
|
|
|
PRBool IsAngularUnit() const
|
2008-08-08 03:15:40 +04:00
|
|
|
{ return eCSSUnit_Degree <= mUnit && mUnit <= eCSSUnit_Radian; }
|
2003-12-29 22:07:53 +03:00
|
|
|
PRBool IsFrequencyUnit() const
|
2008-08-08 03:15:40 +04:00
|
|
|
{ return eCSSUnit_Hertz <= mUnit && mUnit <= eCSSUnit_Kilohertz; }
|
2003-12-29 22:07:53 +03:00
|
|
|
PRBool IsTimeUnit() const
|
2008-08-08 03:15:40 +04:00
|
|
|
{ return eCSSUnit_Seconds <= mUnit && mUnit <= eCSSUnit_Milliseconds; }
|
|
|
|
|
|
|
|
PRBool UnitHasStringValue() const
|
|
|
|
{ return eCSSUnit_String <= mUnit && mUnit <= eCSSUnit_Font_Format; }
|
1998-10-08 05:29:29 +04:00
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
PRInt32 GetIntValue() const
|
2003-10-02 02:53:56 +04:00
|
|
|
{
|
2008-02-08 22:51:41 +03:00
|
|
|
NS_ASSERTION(mUnit == eCSSUnit_Integer || mUnit == eCSSUnit_Enumerated ||
|
|
|
|
mUnit == eCSSUnit_EnumColor,
|
2003-10-02 02:53:56 +04:00
|
|
|
"not an int value");
|
|
|
|
return mValue.mInt;
|
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
float GetPercentValue() const
|
2003-10-02 02:53:56 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mUnit == eCSSUnit_Percent, "not a percent value");
|
|
|
|
return mValue.mFloat;
|
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
float GetFloatValue() const
|
2003-10-02 02:53:56 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(eCSSUnit_Number <= mUnit, "not a float value");
|
|
|
|
return mValue.mFloat;
|
|
|
|
}
|
|
|
|
|
2009-11-02 22:36:43 +03:00
|
|
|
float GetAngleValue() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(eCSSUnit_Degree <= mUnit &&
|
2009-11-03 23:17:17 +03:00
|
|
|
mUnit <= eCSSUnit_Radian, "not an angle value");
|
2009-11-02 22:36:43 +03:00
|
|
|
return mValue.mFloat;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Converts any angle to radians.
|
|
|
|
double GetAngleValueInRadians() const;
|
|
|
|
|
2003-10-02 02:53:56 +04:00
|
|
|
nsAString& GetStringValue(nsAString& aBuffer) const
|
|
|
|
{
|
2008-08-08 03:15:40 +04:00
|
|
|
NS_ASSERTION(UnitHasStringValue(), "not a string value");
|
2003-10-02 02:53:56 +04:00
|
|
|
aBuffer.Truncate();
|
2006-12-13 18:49:36 +03:00
|
|
|
PRUint32 len = NS_strlen(GetBufferValue(mValue.mString));
|
|
|
|
mValue.mString->ToString(len, aBuffer);
|
2003-10-02 02:53:56 +04:00
|
|
|
return aBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PRUnichar* GetStringBufferValue() const
|
|
|
|
{
|
2008-08-08 03:15:40 +04:00
|
|
|
NS_ASSERTION(UnitHasStringValue(), "not a string value");
|
2006-12-13 18:49:36 +03:00
|
|
|
return GetBufferValue(mValue.mString);
|
2003-10-02 02:53:56 +04:00
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
nscolor GetColorValue() const
|
2003-10-02 02:53:56 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION((mUnit == eCSSUnit_Color), "not a color value");
|
|
|
|
return mValue.mColor;
|
|
|
|
}
|
|
|
|
|
2009-06-17 02:05:12 +04:00
|
|
|
PRBool IsNonTransparentColor() const;
|
|
|
|
|
2005-04-02 03:07:00 +04:00
|
|
|
Array* GetArrayValue() const
|
|
|
|
{
|
2008-09-13 13:42:11 +04:00
|
|
|
NS_ASSERTION(eCSSUnit_Array <= mUnit && mUnit <= eCSSUnit_Function,
|
2005-04-02 03:07:00 +04:00
|
|
|
"not an array value");
|
|
|
|
return mValue.mArray;
|
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
nsIURI* GetURLValue() const
|
2003-10-02 02:53:56 +04:00
|
|
|
{
|
2004-03-09 06:57:51 +03:00
|
|
|
NS_ASSERTION(mUnit == eCSSUnit_URL || mUnit == eCSSUnit_Image,
|
|
|
|
"not a URL value");
|
|
|
|
return mUnit == eCSSUnit_URL ?
|
|
|
|
mValue.mURL->mURI : mValue.mImage->mURI;
|
2003-10-30 04:45:37 +03:00
|
|
|
}
|
|
|
|
|
2009-08-01 19:53:40 +04:00
|
|
|
nsCSSValueGradient* GetGradientValue() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mUnit == eCSSUnit_Gradient, "not a gradient value");
|
|
|
|
return mValue.mGradient;
|
|
|
|
}
|
|
|
|
|
2007-07-19 01:56:57 +04:00
|
|
|
URL* GetURLStructValue() const
|
|
|
|
{
|
|
|
|
// Not allowing this for Image values, because if the caller takes
|
|
|
|
// a ref to them they won't be able to delete them properly.
|
|
|
|
NS_ASSERTION(mUnit == eCSSUnit_URL, "not a URL value");
|
|
|
|
return mValue.mURL;
|
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
const PRUnichar* GetOriginalURLValue() const
|
2003-10-30 04:45:37 +03:00
|
|
|
{
|
2004-03-09 06:57:51 +03:00
|
|
|
NS_ASSERTION(mUnit == eCSSUnit_URL || mUnit == eCSSUnit_Image,
|
|
|
|
"not a URL value");
|
2006-12-13 18:49:36 +03:00
|
|
|
return GetBufferValue(mUnit == eCSSUnit_URL ?
|
|
|
|
mValue.mURL->mString :
|
|
|
|
mValue.mImage->mString);
|
2003-10-02 02:53:56 +04:00
|
|
|
}
|
|
|
|
|
2004-03-09 06:57:51 +03:00
|
|
|
// Not making this inline because that would force us to include
|
|
|
|
// imgIRequest.h, which leads to REQUIRES hell, since this header is included
|
|
|
|
// all over.
|
2004-05-13 01:20:09 +04:00
|
|
|
NS_HIDDEN_(imgIRequest*) GetImageValue() const;
|
2005-04-02 03:07:00 +04:00
|
|
|
|
2006-02-22 01:56:02 +03:00
|
|
|
NS_HIDDEN_(nscoord) GetLengthTwips() const;
|
2003-10-02 02:53:56 +04:00
|
|
|
|
2004-05-13 21:09:20 +04:00
|
|
|
NS_HIDDEN_(void) Reset() // sets to null
|
2001-02-19 15:55:42 +03:00
|
|
|
{
|
2007-08-28 10:47:32 +04:00
|
|
|
if (mUnit != eCSSUnit_Null)
|
|
|
|
DoReset();
|
2001-02-19 15:55:42 +03:00
|
|
|
}
|
2007-08-28 10:47:32 +04:00
|
|
|
private:
|
|
|
|
NS_HIDDEN_(void) DoReset();
|
1998-10-08 05:29:29 +04:00
|
|
|
|
2007-08-28 10:47:32 +04:00
|
|
|
public:
|
2004-05-13 01:20:09 +04:00
|
|
|
NS_HIDDEN_(void) SetIntValue(PRInt32 aValue, nsCSSUnit aUnit);
|
|
|
|
NS_HIDDEN_(void) SetPercentValue(float aValue);
|
|
|
|
NS_HIDDEN_(void) SetFloatValue(float aValue, nsCSSUnit aUnit);
|
2006-12-13 18:49:36 +03:00
|
|
|
NS_HIDDEN_(void) SetStringValue(const nsString& aValue, nsCSSUnit aUnit);
|
2004-05-13 01:20:09 +04:00
|
|
|
NS_HIDDEN_(void) SetColorValue(nscolor aValue);
|
2005-04-02 03:07:00 +04:00
|
|
|
NS_HIDDEN_(void) SetArrayValue(nsCSSValue::Array* aArray, nsCSSUnit aUnit);
|
2004-05-13 01:20:09 +04:00
|
|
|
NS_HIDDEN_(void) SetURLValue(nsCSSValue::URL* aURI);
|
|
|
|
NS_HIDDEN_(void) SetImageValue(nsCSSValue::Image* aImage);
|
2009-08-01 19:53:40 +04:00
|
|
|
NS_HIDDEN_(void) SetGradientValue(nsCSSValueGradient* aGradient);
|
2004-05-13 01:20:09 +04:00
|
|
|
NS_HIDDEN_(void) SetAutoValue();
|
|
|
|
NS_HIDDEN_(void) SetInheritValue();
|
|
|
|
NS_HIDDEN_(void) SetInitialValue();
|
|
|
|
NS_HIDDEN_(void) SetNoneValue();
|
2009-08-21 01:52:47 +04:00
|
|
|
NS_HIDDEN_(void) SetAllValue();
|
2004-05-13 01:20:09 +04:00
|
|
|
NS_HIDDEN_(void) SetNormalValue();
|
2007-06-12 22:28:56 +04:00
|
|
|
NS_HIDDEN_(void) SetSystemFontValue();
|
2007-10-09 03:11:01 +04:00
|
|
|
NS_HIDDEN_(void) SetDummyValue();
|
2008-10-07 22:53:22 +04:00
|
|
|
NS_HIDDEN_(void) SetDummyInheritValue();
|
2008-12-29 18:07:38 +03:00
|
|
|
NS_HIDDEN_(void) SetRectIsAutoValue();
|
2007-07-03 17:59:02 +04:00
|
|
|
NS_HIDDEN_(void) StartImageLoad(nsIDocument* aDocument)
|
2004-08-04 07:23:37 +04:00
|
|
|
const; // Not really const, but pretending
|
2003-12-29 22:07:53 +03:00
|
|
|
|
2009-08-22 00:39:25 +04:00
|
|
|
// Initializes as a function value with the specified function id.
|
|
|
|
NS_HIDDEN_(Array*) InitFunction(nsCSSKeyword aFunctionId, PRUint32 aNumArgs);
|
|
|
|
// Checks if this is a function value with the specified function id.
|
|
|
|
NS_HIDDEN_(PRBool) EqualsFunction(nsCSSKeyword aFunctionId) const;
|
|
|
|
|
2006-12-13 18:49:36 +03:00
|
|
|
// Returns an already addrefed buffer. Can return null on allocation
|
|
|
|
// failure.
|
|
|
|
static nsStringBuffer* BufferFromString(const nsString& aValue);
|
|
|
|
|
2003-10-30 04:45:37 +03:00
|
|
|
struct URL {
|
2007-05-03 05:15:53 +04:00
|
|
|
// Methods are not inline because using an nsIPrincipal means requiring
|
|
|
|
// caps, which leads to REQUIRES hell, since this header is included all
|
|
|
|
// over.
|
|
|
|
|
2006-12-13 18:49:36 +03:00
|
|
|
// aString must not be null.
|
2007-05-03 05:15:53 +04:00
|
|
|
// aOriginPrincipal must not be null.
|
|
|
|
URL(nsIURI* aURI, nsStringBuffer* aString, nsIURI* aReferrer,
|
|
|
|
nsIPrincipal* aOriginPrincipal) NS_HIDDEN;
|
2003-10-30 04:45:37 +03:00
|
|
|
|
2007-05-03 05:15:53 +04:00
|
|
|
~URL() NS_HIDDEN;
|
2003-10-30 04:45:37 +03:00
|
|
|
|
2007-05-03 05:15:53 +04:00
|
|
|
NS_HIDDEN_(PRBool) operator==(const URL& aOther) const;
|
2003-10-30 04:45:37 +03:00
|
|
|
|
2007-07-19 01:56:57 +04:00
|
|
|
// URIEquals only compares URIs and principals (unlike operator==, which
|
|
|
|
// also compares the original strings). URIEquals also assumes that the
|
|
|
|
// mURI member of both URL objects is non-null. Do NOT call this method
|
|
|
|
// unless you're sure this is the case.
|
|
|
|
NS_HIDDEN_(PRBool) URIEquals(const URL& aOther) const;
|
|
|
|
|
2003-10-30 04:45:37 +03:00
|
|
|
nsCOMPtr<nsIURI> mURI; // null == invalid URL
|
2006-12-13 18:49:36 +03:00
|
|
|
nsStringBuffer* mString; // Could use nsRefPtr, but it'd add useless
|
|
|
|
// null-checks; this is never null.
|
2004-07-15 01:56:23 +04:00
|
|
|
nsCOMPtr<nsIURI> mReferrer;
|
2007-05-03 05:15:53 +04:00
|
|
|
nsCOMPtr<nsIPrincipal> mOriginPrincipal;
|
2003-10-30 04:45:37 +03:00
|
|
|
|
2008-12-28 04:58:14 +03:00
|
|
|
void AddRef() {
|
|
|
|
if (mRefCnt == PR_UINT32_MAX) {
|
|
|
|
NS_WARNING("refcount overflow, leaking nsCSSValue::URL");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
++mRefCnt;
|
2009-08-01 19:53:40 +04:00
|
|
|
NS_LOG_ADDREF(this, mRefCnt, "nsCSSValue::URL", sizeof(*this));
|
2008-12-28 04:58:14 +03:00
|
|
|
}
|
|
|
|
void Release() {
|
|
|
|
if (mRefCnt == PR_UINT32_MAX) {
|
|
|
|
NS_WARNING("refcount overflow, leaking nsCSSValue::URL");
|
|
|
|
return;
|
|
|
|
}
|
2009-08-01 19:53:40 +04:00
|
|
|
--mRefCnt;
|
|
|
|
NS_LOG_RELEASE(this, mRefCnt, "nsCSSValue::URL");
|
|
|
|
if (mRefCnt == 0)
|
2008-12-28 04:58:14 +03:00
|
|
|
delete this;
|
|
|
|
}
|
2004-03-09 06:57:51 +03:00
|
|
|
protected:
|
2003-10-30 04:45:37 +03:00
|
|
|
nsrefcnt mRefCnt;
|
2009-08-01 19:53:40 +04:00
|
|
|
|
|
|
|
// not to be implemented
|
|
|
|
URL(const URL& aOther);
|
|
|
|
URL& operator=(const URL& aOther);
|
2003-10-30 04:45:37 +03:00
|
|
|
};
|
|
|
|
|
2004-03-09 07:28:14 +03:00
|
|
|
struct Image : public URL {
|
2004-03-09 06:57:51 +03:00
|
|
|
// Not making the constructor and destructor inline because that would
|
|
|
|
// force us to include imgIRequest.h, which leads to REQUIRES hell, since
|
|
|
|
// this header is included all over.
|
2006-12-13 18:49:36 +03:00
|
|
|
// aString must not be null.
|
|
|
|
Image(nsIURI* aURI, nsStringBuffer* aString, nsIURI* aReferrer,
|
2007-07-03 17:59:02 +04:00
|
|
|
nsIPrincipal* aOriginPrincipal, nsIDocument* aDocument) NS_HIDDEN;
|
2004-05-13 01:20:09 +04:00
|
|
|
~Image() NS_HIDDEN;
|
2004-03-09 06:57:51 +03:00
|
|
|
|
|
|
|
// Inherit operator== from nsCSSValue::URL
|
|
|
|
|
|
|
|
nsCOMPtr<imgIRequest> mRequest; // null == image load blocked or somehow failed
|
|
|
|
|
2009-08-01 19:53:40 +04:00
|
|
|
// Override AddRef and Release to not only log ourselves correctly, but
|
|
|
|
// also so that we delete correctly without a virtual destructor
|
|
|
|
void AddRef() {
|
|
|
|
if (mRefCnt == PR_UINT32_MAX) {
|
|
|
|
NS_WARNING("refcount overflow, leaking nsCSSValue::Image");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
++mRefCnt;
|
|
|
|
NS_LOG_ADDREF(this, mRefCnt, "nsCSSValue::Image", sizeof(*this));
|
|
|
|
}
|
|
|
|
|
2008-12-28 04:58:14 +03:00
|
|
|
void Release() {
|
|
|
|
if (mRefCnt == PR_UINT32_MAX) {
|
|
|
|
NS_WARNING("refcount overflow, leaking nsCSSValue::Image");
|
|
|
|
return;
|
|
|
|
}
|
2009-08-01 19:53:40 +04:00
|
|
|
--mRefCnt;
|
|
|
|
NS_LOG_RELEASE(this, mRefCnt, "nsCSSValue::Image");
|
|
|
|
if (mRefCnt == 0)
|
2008-12-28 04:58:14 +03:00
|
|
|
delete this;
|
|
|
|
}
|
2004-03-09 06:57:51 +03:00
|
|
|
};
|
|
|
|
|
2006-12-13 18:49:36 +03:00
|
|
|
private:
|
|
|
|
static const PRUnichar* GetBufferValue(nsStringBuffer* aBuffer) {
|
2007-07-08 11:08:04 +04:00
|
|
|
return static_cast<PRUnichar*>(aBuffer->Data());
|
2006-12-13 18:49:36 +03:00
|
|
|
}
|
|
|
|
|
1998-10-08 05:29:29 +04:00
|
|
|
protected:
|
|
|
|
nsCSSUnit mUnit;
|
|
|
|
union {
|
2000-06-06 13:36:12 +04:00
|
|
|
PRInt32 mInt;
|
|
|
|
float mFloat;
|
2006-12-13 18:49:36 +03:00
|
|
|
// Note: the capacity of the buffer may exceed the length of the string.
|
|
|
|
// If we're of a string type, mString is not null.
|
|
|
|
nsStringBuffer* mString;
|
2000-06-06 13:36:12 +04:00
|
|
|
nscolor mColor;
|
2005-04-02 03:07:00 +04:00
|
|
|
Array* mArray;
|
2003-10-30 04:45:37 +03:00
|
|
|
URL* mURL;
|
2004-03-09 06:57:51 +03:00
|
|
|
Image* mImage;
|
2009-08-01 19:53:40 +04:00
|
|
|
nsCSSValueGradient* mGradient;
|
1998-10-08 05:29:29 +04:00
|
|
|
} mValue;
|
|
|
|
};
|
|
|
|
|
2009-08-01 19:53:40 +04:00
|
|
|
struct nsCSSValueGradientStop {
|
|
|
|
public:
|
2009-11-02 22:36:43 +03:00
|
|
|
nsCSSValueGradientStop() NS_HIDDEN;
|
2009-08-01 19:53:40 +04:00
|
|
|
// needed to keep bloat logs happy when we use the nsTArray in nsCSSValueGradient
|
|
|
|
nsCSSValueGradientStop(const nsCSSValueGradientStop& aOther) NS_HIDDEN;
|
|
|
|
~nsCSSValueGradientStop() NS_HIDDEN;
|
|
|
|
|
|
|
|
nsCSSValue mLocation;
|
|
|
|
nsCSSValue mColor;
|
|
|
|
|
|
|
|
PRBool operator==(const nsCSSValueGradientStop& aOther) const
|
|
|
|
{
|
|
|
|
return (mLocation == aOther.mLocation &&
|
|
|
|
mColor == aOther.mColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool operator!=(const nsCSSValueGradientStop& aOther) const
|
|
|
|
{
|
|
|
|
return !(*this == aOther);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nsCSSValueGradient {
|
2009-11-02 22:36:43 +03:00
|
|
|
nsCSSValueGradient(PRBool aIsRadial,
|
|
|
|
PRBool aIsRepeating) NS_HIDDEN;
|
2009-08-01 19:53:40 +04:00
|
|
|
|
|
|
|
// true if gradient is radial, false if it is linear
|
|
|
|
PRPackedBool mIsRadial;
|
2009-11-02 22:36:43 +03:00
|
|
|
PRPackedBool mIsRepeating;
|
|
|
|
// line position and angle
|
|
|
|
nsCSSValue mBgPosX;
|
|
|
|
nsCSSValue mBgPosY;
|
|
|
|
nsCSSValue mAngle;
|
2009-08-01 19:53:40 +04:00
|
|
|
|
|
|
|
// Only meaningful if mIsRadial is true
|
2009-11-02 22:36:43 +03:00
|
|
|
nsCSSValue mRadialShape;
|
|
|
|
nsCSSValue mRadialSize;
|
2009-08-01 19:53:40 +04:00
|
|
|
|
|
|
|
nsTArray<nsCSSValueGradientStop> mStops;
|
|
|
|
|
|
|
|
PRBool operator==(const nsCSSValueGradient& aOther) const
|
|
|
|
{
|
|
|
|
if (mIsRadial != aOther.mIsRadial ||
|
2009-11-02 22:36:43 +03:00
|
|
|
mIsRepeating != aOther.mIsRepeating ||
|
|
|
|
mBgPosX != aOther.mBgPosX ||
|
|
|
|
mBgPosY != aOther.mBgPosY ||
|
|
|
|
mAngle != aOther.mAngle ||
|
|
|
|
mRadialShape != aOther.mRadialShape ||
|
|
|
|
mRadialSize != aOther.mRadialSize)
|
2009-08-01 19:53:40 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (mStops.Length() != aOther.mStops.Length())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < mStops.Length(); i++) {
|
|
|
|
if (mStops[i] != aOther.mStops[i])
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool operator!=(const nsCSSValueGradient& aOther) const
|
|
|
|
{
|
|
|
|
return !(*this == aOther);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddRef() {
|
|
|
|
if (mRefCnt == PR_UINT32_MAX) {
|
|
|
|
NS_WARNING("refcount overflow, leaking nsCSSValue::Gradient");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
++mRefCnt;
|
|
|
|
NS_LOG_ADDREF(this, mRefCnt, "nsCSSValue::Gradient", sizeof(*this));
|
|
|
|
}
|
|
|
|
void Release() {
|
|
|
|
if (mRefCnt == PR_UINT32_MAX) {
|
|
|
|
NS_WARNING("refcount overflow, leaking nsCSSValue::Gradient");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
--mRefCnt;
|
|
|
|
NS_LOG_RELEASE(this, mRefCnt, "nsCSSValue::Gradient");
|
|
|
|
if (mRefCnt == 0)
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsrefcnt mRefCnt;
|
|
|
|
|
|
|
|
// not to be implemented
|
|
|
|
nsCSSValueGradient(const nsCSSValueGradient& aOther);
|
|
|
|
nsCSSValueGradient& operator=(const nsCSSValueGradient& aOther);
|
|
|
|
};
|
|
|
|
|
2009-02-05 08:15:52 +03:00
|
|
|
struct nsCSSValue::Array {
|
|
|
|
|
|
|
|
// return |Array| with reference count of zero
|
|
|
|
static Array* Create(PRUint16 aItemCount) {
|
|
|
|
return new (aItemCount) Array(aItemCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue& operator[](PRUint16 aIndex) {
|
|
|
|
NS_ASSERTION(aIndex < mCount, "out of range");
|
|
|
|
return mArray[aIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsCSSValue& operator[](PRUint16 aIndex) const {
|
|
|
|
NS_ASSERTION(aIndex < mCount, "out of range");
|
|
|
|
return mArray[aIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue& Item(PRUint16 aIndex) { return (*this)[aIndex]; }
|
|
|
|
const nsCSSValue& Item(PRUint16 aIndex) const { return (*this)[aIndex]; }
|
|
|
|
|
|
|
|
PRUint16 Count() const { return mCount; }
|
|
|
|
|
|
|
|
PRBool operator==(const Array& aOther) const
|
|
|
|
{
|
|
|
|
if (mCount != aOther.mCount)
|
|
|
|
return PR_FALSE;
|
|
|
|
for (PRUint16 i = 0; i < mCount; ++i)
|
|
|
|
if ((*this)[i] != aOther[i])
|
|
|
|
return PR_FALSE;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddRef() {
|
|
|
|
if (mRefCnt == PR_UINT16_MAX) {
|
|
|
|
NS_WARNING("refcount overflow, leaking nsCSSValue::Array");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
++mRefCnt;
|
|
|
|
NS_LOG_ADDREF(this, mRefCnt, "nsCSSValue::Array", sizeof(*this));
|
|
|
|
}
|
|
|
|
void Release() {
|
|
|
|
if (mRefCnt == PR_UINT16_MAX) {
|
|
|
|
NS_WARNING("refcount overflow, leaking nsCSSValue::Array");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
--mRefCnt;
|
|
|
|
NS_LOG_RELEASE(this, mRefCnt, "nsCSSValue::Array");
|
|
|
|
if (mRefCnt == 0)
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
PRUint16 mRefCnt;
|
|
|
|
const PRUint16 mCount;
|
|
|
|
// This must be the last sub-object, since we extend this array to
|
|
|
|
// be of size mCount; it needs to be a sub-object so it gets proper
|
|
|
|
// alignment.
|
|
|
|
nsCSSValue mArray[1];
|
|
|
|
|
|
|
|
void* operator new(size_t aSelfSize, PRUint16 aItemCount) CPP_THROW_NEW {
|
|
|
|
NS_ABORT_IF_FALSE(aItemCount > 0, "cannot have a 0 item count");
|
|
|
|
return ::operator new(aSelfSize + sizeof(nsCSSValue) * (aItemCount - 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator delete(void* aPtr) { ::operator delete(aPtr); }
|
|
|
|
|
|
|
|
nsCSSValue* First() { return mArray; }
|
|
|
|
|
|
|
|
const nsCSSValue* First() const { return mArray; }
|
|
|
|
|
|
|
|
#define CSSVALUE_LIST_FOR_EXTRA_VALUES(var) \
|
|
|
|
for (nsCSSValue *var = First() + 1, *var##_end = First() + mCount; \
|
|
|
|
var != var##_end; ++var)
|
|
|
|
|
|
|
|
Array(PRUint16 aItemCount)
|
|
|
|
: mRefCnt(0)
|
|
|
|
, mCount(aItemCount)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsCSSValue::Array);
|
|
|
|
CSSVALUE_LIST_FOR_EXTRA_VALUES(val) {
|
|
|
|
new (val) nsCSSValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~Array()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsCSSValue::Array);
|
|
|
|
CSSVALUE_LIST_FOR_EXTRA_VALUES(val) {
|
|
|
|
val->~nsCSSValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef CSSVALUE_LIST_FOR_EXTRA_VALUES
|
|
|
|
|
|
|
|
private:
|
2009-08-01 19:53:40 +04:00
|
|
|
// not to be implemented
|
|
|
|
Array(const Array& aOther);
|
|
|
|
Array& operator=(const Array& aOther);
|
2009-02-05 08:15:52 +03:00
|
|
|
};
|
|
|
|
|
1998-10-08 05:29:29 +04:00
|
|
|
#endif /* nsCSSValue_h___ */
|
|
|
|
|