2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* 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/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* 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"),
|
|
|
|
* 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
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* 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
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
/* representation of simple property values within CSS declarations */
|
|
|
|
|
|
|
|
#ifndef nsCSSValue_h___
|
|
|
|
#define nsCSSValue_h___
|
|
|
|
|
|
|
|
#include "nsColor.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCoord.h"
|
|
|
|
#include "nsCSSProperty.h"
|
2009-08-21 13:39:25 -07:00
|
|
|
#include "nsCSSKeywords.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCRTGlue.h"
|
|
|
|
#include "nsStringBuffer.h"
|
2009-08-01 08:53:40 -07:00
|
|
|
#include "nsTArray.h"
|
2010-04-01 11:05:40 -07:00
|
|
|
#include "nsISupportsImpl.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class imgIRequest;
|
|
|
|
class nsIDocument;
|
2007-05-02 18:15:53 -07:00
|
|
|
class nsIPrincipal;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-10-17 01:13:16 -07: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; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
enum nsCSSUnit {
|
|
|
|
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
|
|
|
|
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 11:28:56 -07:00
|
|
|
eCSSUnit_System_Font = 6, // (n/a) value is -moz-use-system-font
|
2009-08-20 14:52:47 -07:00
|
|
|
eCSSUnit_All = 7, // (n/a) value is all
|
|
|
|
eCSSUnit_Dummy = 8, // (n/a) a fake but specified value, used
|
2007-10-08 16:11:01 -07:00
|
|
|
// only in temporary values
|
2009-08-20 14:52:47 -07:00
|
|
|
eCSSUnit_DummyInherit = 9, // (n/a) a fake but specified value, used
|
2008-10-07 11:53:22 -07:00
|
|
|
// only in temporary values
|
2009-08-20 14:52:47 -07: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
|
2007-03-22 10:30:00 -07: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-20 14:52:47 -07: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 02:42:11 -07:00
|
|
|
// the rest of the values are arguments.
|
|
|
|
|
2010-05-11 08:49:43 -07:00
|
|
|
// The top level of a calc() expression is either -moz-calc()
|
|
|
|
// (eCSSUnit_Calc), -moz-min() (eCSSUnit_Calc_Minimum), or -moz-max()
|
|
|
|
// (eCSSUnit_Calc_Maximum). All remaining eCSSUnit_Calc_* units only
|
|
|
|
// occur inside these toplevel calc values.
|
|
|
|
|
|
|
|
// eCSSUnit_Calc has an array with exactly 1 element. eCSSUnit_Calc
|
|
|
|
// exists so we can distinguish calc(2em) from 2em as specified values
|
|
|
|
// (but we drop this distinction for nsStyleCoord when we store
|
|
|
|
// computed values).
|
|
|
|
eCSSUnit_Calc = 25, // (nsCSSValue::Array*) calc() value
|
|
|
|
// Plus, Minus, Times_* and Divided have arrays with exactly 2
|
|
|
|
// elements. a + b + c + d is grouped as ((a + b) + c) + d
|
|
|
|
eCSSUnit_Calc_Plus = 26, // (nsCSSValue::Array*) + node within calc()
|
|
|
|
eCSSUnit_Calc_Minus = 27, // (nsCSSValue::Array*) - within calc
|
|
|
|
eCSSUnit_Calc_Times_L = 28, // (nsCSSValue::Array*) num * val within calc
|
|
|
|
eCSSUnit_Calc_Times_R = 29, // (nsCSSValue::Array*) val * num within calc
|
|
|
|
eCSSUnit_Calc_Divided = 30, // (nsCSSValue::Array*) / within calc
|
|
|
|
// Minimum and Maximum have arrays with 1 or more elements
|
|
|
|
eCSSUnit_Calc_Minimum = 31, // (nsCSSValue::Array*) min() within calc
|
|
|
|
eCSSUnit_Calc_Maximum = 32, // (nsCSSValue::Array*) max() within calc
|
|
|
|
|
|
|
|
eCSSUnit_URL = 40, // (nsCSSValue::URL*) value
|
|
|
|
eCSSUnit_Image = 41, // (nsCSSValue::Image*) value
|
|
|
|
eCSSUnit_Gradient = 42, // (nsCSSValueGradient*) value
|
2007-03-22 10:30:00 -07:00
|
|
|
eCSSUnit_Integer = 50, // (int) simple value
|
|
|
|
eCSSUnit_Enumerated = 51, // (int) value has enumerated meaning
|
2008-02-08 11:51:41 -08:00
|
|
|
eCSSUnit_EnumColor = 80, // (int) enumerated color (kColorKTable)
|
|
|
|
eCSSUnit_Color = 81, // (nscolor) an RGBA value
|
2007-03-22 10:30:00 -07: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
|
|
|
|
// US English
|
|
|
|
eCSSUnit_Inch = 100, // (float) 0.0254 meters
|
|
|
|
|
|
|
|
// Metric
|
|
|
|
eCSSUnit_Millimeter = 207, // (float) 1/1000 meter
|
|
|
|
eCSSUnit_Centimeter = 208, // (float) 1/100 meter
|
|
|
|
|
|
|
|
// US Typographic
|
|
|
|
eCSSUnit_Point = 300, // (float) 1/72 inch
|
|
|
|
eCSSUnit_Pica = 301, // (float) 12 points == 1/6 inch
|
|
|
|
|
|
|
|
// Length units - relative
|
|
|
|
// Font relative measure
|
|
|
|
eCSSUnit_EM = 800, // (float) == current font size
|
2008-12-04 08:09:53 -08: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-20 13:58:48 -08:00
|
|
|
eCSSUnit_RootEM = 803, // (float) == root element font size
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Screen relative measure
|
|
|
|
eCSSUnit_Pixel = 900, // (float) CSS pixel unit
|
|
|
|
|
|
|
|
// Angular units
|
|
|
|
eCSSUnit_Degree = 1000, // (float) 360 per circle
|
|
|
|
eCSSUnit_Grad = 1001, // (float) 400 per circle
|
|
|
|
eCSSUnit_Radian = 1002, // (float) 2*pi per circle
|
|
|
|
|
|
|
|
// Frequency units
|
|
|
|
eCSSUnit_Hertz = 2000, // (float) 1/seconds
|
|
|
|
eCSSUnit_Kilohertz = 2001, // (float) 1000 Hertz
|
|
|
|
|
|
|
|
// Time units
|
|
|
|
eCSSUnit_Seconds = 3000, // (float) Standard time
|
|
|
|
eCSSUnit_Milliseconds = 3001 // (float) 1/1000 second
|
|
|
|
};
|
|
|
|
|
2009-08-01 08:53:40 -07:00
|
|
|
struct nsCSSValueGradient;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsCSSValue {
|
|
|
|
public:
|
|
|
|
struct Array;
|
|
|
|
friend struct Array;
|
|
|
|
|
|
|
|
struct URL;
|
|
|
|
friend struct URL;
|
|
|
|
|
|
|
|
struct Image;
|
|
|
|
friend struct Image;
|
|
|
|
|
2009-08-20 14:52:47 -07:00
|
|
|
// for valueless units only (null, auto, inherit, none, all, normal)
|
2007-03-22 10:30:00 -07:00
|
|
|
explicit nsCSSValue(nsCSSUnit aUnit = eCSSUnit_Null)
|
|
|
|
: mUnit(aUnit)
|
|
|
|
{
|
2008-12-29 07:07:38 -08:00
|
|
|
NS_ASSERTION(aUnit <= eCSSUnit_RectIsAuto, "not a valueless unit");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-04-06 14:52:17 -07:00
|
|
|
nsCSSValue(PRInt32 aValue, nsCSSUnit aUnit);
|
|
|
|
nsCSSValue(float aValue, nsCSSUnit aUnit);
|
|
|
|
nsCSSValue(const nsString& aValue, nsCSSUnit aUnit);
|
|
|
|
nsCSSValue(Array* aArray, nsCSSUnit aUnit);
|
|
|
|
explicit nsCSSValue(URL* aValue);
|
|
|
|
explicit nsCSSValue(Image* aValue);
|
|
|
|
explicit nsCSSValue(nsCSSValueGradient* aValue);
|
|
|
|
nsCSSValue(const nsCSSValue& aCopy);
|
2007-08-27 23:47:32 -07:00
|
|
|
~nsCSSValue() { Reset(); }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-06 14:52:17 -07:00
|
|
|
nsCSSValue& operator=(const nsCSSValue& aCopy);
|
|
|
|
PRBool operator==(const nsCSSValue& aOther) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PRBool operator!=(const nsCSSValue& aOther) const
|
|
|
|
{
|
|
|
|
return !(*this == aOther);
|
|
|
|
}
|
|
|
|
|
2007-04-23 07:21:53 -07:00
|
|
|
nsCSSUnit GetUnit() const { return mUnit; }
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool IsLengthUnit() const
|
2008-08-07 16:15:40 -07:00
|
|
|
{ return eCSSUnit_Inch <= mUnit && mUnit <= eCSSUnit_Pixel; }
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool IsFixedLengthUnit() const
|
2009-03-09 16:14:34 -07:00
|
|
|
{ return eCSSUnit_Inch <= mUnit && mUnit <= eCSSUnit_Pica; }
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool IsRelativeLengthUnit() const
|
2008-08-07 16:15:40 -07:00
|
|
|
{ return eCSSUnit_EM <= mUnit && mUnit <= eCSSUnit_Pixel; }
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool IsAngularUnit() const
|
2008-08-07 16:15:40 -07:00
|
|
|
{ return eCSSUnit_Degree <= mUnit && mUnit <= eCSSUnit_Radian; }
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool IsFrequencyUnit() const
|
2008-08-07 16:15:40 -07:00
|
|
|
{ return eCSSUnit_Hertz <= mUnit && mUnit <= eCSSUnit_Kilohertz; }
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool IsTimeUnit() const
|
2008-08-07 16:15:40 -07:00
|
|
|
{ return eCSSUnit_Seconds <= mUnit && mUnit <= eCSSUnit_Milliseconds; }
|
2010-05-11 08:49:43 -07:00
|
|
|
PRBool IsCalcUnit() const
|
|
|
|
{ return eCSSUnit_Calc <= mUnit && mUnit <= eCSSUnit_Calc_Maximum; }
|
2008-08-07 16:15:40 -07:00
|
|
|
|
|
|
|
PRBool UnitHasStringValue() const
|
|
|
|
{ return eCSSUnit_String <= mUnit && mUnit <= eCSSUnit_Font_Format; }
|
2010-05-11 08:49:43 -07:00
|
|
|
PRBool UnitHasArrayValue() const
|
|
|
|
{ return eCSSUnit_Array <= mUnit && mUnit <= eCSSUnit_Calc_Maximum; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PRInt32 GetIntValue() const
|
|
|
|
{
|
2008-02-08 11:51:41 -08:00
|
|
|
NS_ASSERTION(mUnit == eCSSUnit_Integer || mUnit == eCSSUnit_Enumerated ||
|
|
|
|
mUnit == eCSSUnit_EnumColor,
|
2007-03-22 10:30:00 -07:00
|
|
|
"not an int value");
|
|
|
|
return mValue.mInt;
|
|
|
|
}
|
|
|
|
|
|
|
|
float GetPercentValue() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mUnit == eCSSUnit_Percent, "not a percent value");
|
|
|
|
return mValue.mFloat;
|
|
|
|
}
|
|
|
|
|
|
|
|
float GetFloatValue() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(eCSSUnit_Number <= mUnit, "not a float value");
|
|
|
|
return mValue.mFloat;
|
|
|
|
}
|
|
|
|
|
2009-11-02 11:36:43 -08:00
|
|
|
float GetAngleValue() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(eCSSUnit_Degree <= mUnit &&
|
2009-11-03 12:17:17 -08:00
|
|
|
mUnit <= eCSSUnit_Radian, "not an angle value");
|
2009-11-02 11:36:43 -08:00
|
|
|
return mValue.mFloat;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Converts any angle to radians.
|
|
|
|
double GetAngleValueInRadians() const;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAString& GetStringValue(nsAString& aBuffer) const
|
|
|
|
{
|
2008-08-07 16:15:40 -07:00
|
|
|
NS_ASSERTION(UnitHasStringValue(), "not a string value");
|
2007-03-22 10:30:00 -07:00
|
|
|
aBuffer.Truncate();
|
|
|
|
PRUint32 len = NS_strlen(GetBufferValue(mValue.mString));
|
|
|
|
mValue.mString->ToString(len, aBuffer);
|
|
|
|
return aBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PRUnichar* GetStringBufferValue() const
|
|
|
|
{
|
2008-08-07 16:15:40 -07:00
|
|
|
NS_ASSERTION(UnitHasStringValue(), "not a string value");
|
2007-03-22 10:30:00 -07:00
|
|
|
return GetBufferValue(mValue.mString);
|
|
|
|
}
|
|
|
|
|
|
|
|
nscolor GetColorValue() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION((mUnit == eCSSUnit_Color), "not a color value");
|
|
|
|
return mValue.mColor;
|
|
|
|
}
|
|
|
|
|
2009-06-16 15:05:12 -07:00
|
|
|
PRBool IsNonTransparentColor() const;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
Array* GetArrayValue() const
|
|
|
|
{
|
2010-05-11 08:49:43 -07:00
|
|
|
NS_ASSERTION(UnitHasArrayValue(), "not an array value");
|
2007-03-22 10:30:00 -07:00
|
|
|
return mValue.mArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIURI* GetURLValue() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mUnit == eCSSUnit_URL || mUnit == eCSSUnit_Image,
|
|
|
|
"not a URL value");
|
|
|
|
return mUnit == eCSSUnit_URL ?
|
|
|
|
mValue.mURL->mURI : mValue.mImage->mURI;
|
|
|
|
}
|
|
|
|
|
2009-08-01 08:53:40 -07:00
|
|
|
nsCSSValueGradient* GetGradientValue() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mUnit == eCSSUnit_Gradient, "not a gradient value");
|
|
|
|
return mValue.mGradient;
|
|
|
|
}
|
|
|
|
|
2007-07-18 14:56:57 -07: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;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
const PRUnichar* GetOriginalURLValue() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mUnit == eCSSUnit_URL || mUnit == eCSSUnit_Image,
|
|
|
|
"not a URL value");
|
|
|
|
return GetBufferValue(mUnit == eCSSUnit_URL ?
|
|
|
|
mValue.mURL->mString :
|
|
|
|
mValue.mImage->mString);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2010-04-06 14:52:17 -07:00
|
|
|
imgIRequest* GetImageValue() const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-06 14:52:17 -07:00
|
|
|
nscoord GetLengthTwips() const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-06 14:52:17 -07:00
|
|
|
void Reset() // sets to null
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-08-27 23:47:32 -07:00
|
|
|
if (mUnit != eCSSUnit_Null)
|
|
|
|
DoReset();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-08-27 23:47:32 -07:00
|
|
|
private:
|
2010-04-06 14:52:17 -07:00
|
|
|
void DoReset();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-27 23:47:32 -07:00
|
|
|
public:
|
2010-04-06 14:52:17 -07:00
|
|
|
void SetIntValue(PRInt32 aValue, nsCSSUnit aUnit);
|
|
|
|
void SetPercentValue(float aValue);
|
|
|
|
void SetFloatValue(float aValue, nsCSSUnit aUnit);
|
|
|
|
void SetStringValue(const nsString& aValue, nsCSSUnit aUnit);
|
|
|
|
void SetColorValue(nscolor aValue);
|
|
|
|
void SetArrayValue(nsCSSValue::Array* aArray, nsCSSUnit aUnit);
|
|
|
|
void SetURLValue(nsCSSValue::URL* aURI);
|
|
|
|
void SetImageValue(nsCSSValue::Image* aImage);
|
|
|
|
void SetGradientValue(nsCSSValueGradient* aGradient);
|
|
|
|
void SetAutoValue();
|
|
|
|
void SetInheritValue();
|
|
|
|
void SetInitialValue();
|
|
|
|
void SetNoneValue();
|
|
|
|
void SetAllValue();
|
|
|
|
void SetNormalValue();
|
|
|
|
void SetSystemFontValue();
|
|
|
|
void SetDummyValue();
|
|
|
|
void SetDummyInheritValue();
|
|
|
|
void StartImageLoad(nsIDocument* aDocument) const; // Only pretend const
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-21 13:39:25 -07:00
|
|
|
// Initializes as a function value with the specified function id.
|
2010-04-06 14:52:17 -07:00
|
|
|
Array* InitFunction(nsCSSKeyword aFunctionId, PRUint32 aNumArgs);
|
2009-08-21 13:39:25 -07:00
|
|
|
// Checks if this is a function value with the specified function id.
|
2010-04-06 14:52:17 -07:00
|
|
|
PRBool EqualsFunction(nsCSSKeyword aFunctionId) const;
|
2009-08-21 13:39:25 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Returns an already addrefed buffer. Can return null on allocation
|
|
|
|
// failure.
|
|
|
|
static nsStringBuffer* BufferFromString(const nsString& aValue);
|
|
|
|
|
|
|
|
struct URL {
|
2007-05-02 18:15:53 -07:00
|
|
|
// Methods are not inline because using an nsIPrincipal means requiring
|
|
|
|
// caps, which leads to REQUIRES hell, since this header is included all
|
|
|
|
// over.
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// aString must not be null.
|
2007-05-02 18:15:53 -07:00
|
|
|
// aOriginPrincipal must not be null.
|
|
|
|
URL(nsIURI* aURI, nsStringBuffer* aString, nsIURI* aReferrer,
|
2010-04-06 14:52:17 -07:00
|
|
|
nsIPrincipal* aOriginPrincipal);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-06 14:52:17 -07:00
|
|
|
~URL();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-06 14:52:17 -07:00
|
|
|
PRBool operator==(const URL& aOther) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-18 14:56:57 -07: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.
|
2010-04-06 14:52:17 -07:00
|
|
|
PRBool URIEquals(const URL& aOther) const;
|
2007-07-18 14:56:57 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIURI> mURI; // null == invalid URL
|
|
|
|
nsStringBuffer* mString; // Could use nsRefPtr, but it'd add useless
|
|
|
|
// null-checks; this is never null.
|
|
|
|
nsCOMPtr<nsIURI> mReferrer;
|
2007-05-02 18:15:53 -07:00
|
|
|
nsCOMPtr<nsIPrincipal> mOriginPrincipal;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-01 11:05:40 -07:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(nsCSSValue::URL)
|
2010-04-01 11:05:40 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
2009-08-01 08:53:40 -07:00
|
|
|
|
|
|
|
// not to be implemented
|
|
|
|
URL(const URL& aOther);
|
|
|
|
URL& operator=(const URL& aOther);
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Image : public URL {
|
|
|
|
// 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.
|
|
|
|
// aString must not be null.
|
|
|
|
Image(nsIURI* aURI, nsStringBuffer* aString, nsIURI* aReferrer,
|
2010-04-06 14:52:17 -07:00
|
|
|
nsIPrincipal* aOriginPrincipal, nsIDocument* aDocument);
|
|
|
|
~Image();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Inherit operator== from nsCSSValue::URL
|
|
|
|
|
|
|
|
nsCOMPtr<imgIRequest> mRequest; // null == image load blocked or somehow failed
|
|
|
|
|
2009-08-01 08:53:40 -07:00
|
|
|
// Override AddRef and Release to not only log ourselves correctly, but
|
|
|
|
// also so that we delete correctly without a virtual destructor
|
2010-04-01 11:05:40 -07:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(nsCSSValue::Image)
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const PRUnichar* GetBufferValue(nsStringBuffer* aBuffer) {
|
2007-07-08 00:08:04 -07:00
|
|
|
return static_cast<PRUnichar*>(aBuffer->Data());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsCSSUnit mUnit;
|
|
|
|
union {
|
|
|
|
PRInt32 mInt;
|
|
|
|
float mFloat;
|
|
|
|
// 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;
|
|
|
|
nscolor mColor;
|
|
|
|
Array* mArray;
|
|
|
|
URL* mURL;
|
|
|
|
Image* mImage;
|
2009-08-01 08:53:40 -07:00
|
|
|
nsCSSValueGradient* mGradient;
|
2007-03-22 10:30:00 -07:00
|
|
|
} mValue;
|
|
|
|
};
|
|
|
|
|
2009-08-01 08:53:40 -07:00
|
|
|
struct nsCSSValueGradientStop {
|
|
|
|
public:
|
2010-04-06 14:52:17 -07:00
|
|
|
nsCSSValueGradientStop();
|
2009-08-01 08:53:40 -07:00
|
|
|
// needed to keep bloat logs happy when we use the nsTArray in nsCSSValueGradient
|
2010-04-06 14:52:17 -07:00
|
|
|
nsCSSValueGradientStop(const nsCSSValueGradientStop& aOther);
|
|
|
|
~nsCSSValueGradientStop();
|
2009-08-01 08:53:40 -07:00
|
|
|
|
|
|
|
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 {
|
2010-04-06 14:52:17 -07:00
|
|
|
nsCSSValueGradient(PRBool aIsRadial, PRBool aIsRepeating);
|
2009-08-01 08:53:40 -07:00
|
|
|
|
|
|
|
// true if gradient is radial, false if it is linear
|
|
|
|
PRPackedBool mIsRadial;
|
2009-11-02 11:36:43 -08:00
|
|
|
PRPackedBool mIsRepeating;
|
|
|
|
// line position and angle
|
|
|
|
nsCSSValue mBgPosX;
|
|
|
|
nsCSSValue mBgPosY;
|
|
|
|
nsCSSValue mAngle;
|
2009-08-01 08:53:40 -07:00
|
|
|
|
|
|
|
// Only meaningful if mIsRadial is true
|
2009-11-02 11:36:43 -08:00
|
|
|
nsCSSValue mRadialShape;
|
|
|
|
nsCSSValue mRadialSize;
|
2009-08-01 08:53:40 -07:00
|
|
|
|
|
|
|
nsTArray<nsCSSValueGradientStop> mStops;
|
|
|
|
|
|
|
|
PRBool operator==(const nsCSSValueGradient& aOther) const
|
|
|
|
{
|
|
|
|
if (mIsRadial != aOther.mIsRadial ||
|
2009-11-02 11:36:43 -08:00
|
|
|
mIsRepeating != aOther.mIsRepeating ||
|
|
|
|
mBgPosX != aOther.mBgPosX ||
|
|
|
|
mBgPosY != aOther.mBgPosY ||
|
|
|
|
mAngle != aOther.mAngle ||
|
|
|
|
mRadialShape != aOther.mRadialShape ||
|
|
|
|
mRadialSize != aOther.mRadialSize)
|
2009-08-01 08:53:40 -07: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);
|
|
|
|
}
|
|
|
|
|
2010-04-01 11:05:40 -07:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(nsCSSValueGradient)
|
2009-08-01 08:53:40 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
// not to be implemented
|
|
|
|
nsCSSValueGradient(const nsCSSValueGradient& aOther);
|
|
|
|
nsCSSValueGradient& operator=(const nsCSSValueGradient& aOther);
|
|
|
|
};
|
|
|
|
|
2009-02-04 21:15:52 -08:00
|
|
|
struct nsCSSValue::Array {
|
|
|
|
|
|
|
|
// return |Array| with reference count of zero
|
2010-06-24 14:53:44 -07:00
|
|
|
static Array* Create(size_t aItemCount) {
|
2009-02-04 21:15:52 -08:00
|
|
|
return new (aItemCount) Array(aItemCount);
|
|
|
|
}
|
|
|
|
|
2010-06-24 14:53:44 -07:00
|
|
|
nsCSSValue& operator[](size_t aIndex) {
|
2009-02-04 21:15:52 -08:00
|
|
|
NS_ASSERTION(aIndex < mCount, "out of range");
|
|
|
|
return mArray[aIndex];
|
|
|
|
}
|
|
|
|
|
2010-06-24 14:53:44 -07:00
|
|
|
const nsCSSValue& operator[](size_t aIndex) const {
|
2009-02-04 21:15:52 -08:00
|
|
|
NS_ASSERTION(aIndex < mCount, "out of range");
|
|
|
|
return mArray[aIndex];
|
|
|
|
}
|
|
|
|
|
2010-06-24 14:53:44 -07:00
|
|
|
nsCSSValue& Item(size_t aIndex) { return (*this)[aIndex]; }
|
|
|
|
const nsCSSValue& Item(size_t aIndex) const { return (*this)[aIndex]; }
|
2009-02-04 21:15:52 -08:00
|
|
|
|
2010-06-24 14:53:44 -07:00
|
|
|
size_t Count() const { return mCount; }
|
2009-02-04 21:15:52 -08:00
|
|
|
|
|
|
|
PRBool operator==(const Array& aOther) const
|
|
|
|
{
|
|
|
|
if (mCount != aOther.mCount)
|
|
|
|
return PR_FALSE;
|
2010-06-24 14:53:44 -07:00
|
|
|
for (size_t i = 0; i < mCount; ++i)
|
2009-02-04 21:15:52 -08:00
|
|
|
if ((*this)[i] != aOther[i])
|
|
|
|
return PR_FALSE;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-06-26 11:58:06 -07:00
|
|
|
// XXXdholbert This uses a size_t ref count. Should we use a variant
|
|
|
|
// of NS_INLINE_DECL_REFCOUNTING that takes a type as an argument?
|
2009-02-04 21:15:52 -08:00
|
|
|
void AddRef() {
|
2010-06-24 14:53:44 -07:00
|
|
|
if (mRefCnt == size_t(-1)) { // really want SIZE_MAX
|
2009-02-04 21:15:52 -08:00
|
|
|
NS_WARNING("refcount overflow, leaking nsCSSValue::Array");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
++mRefCnt;
|
|
|
|
NS_LOG_ADDREF(this, mRefCnt, "nsCSSValue::Array", sizeof(*this));
|
|
|
|
}
|
|
|
|
void Release() {
|
2010-06-24 14:53:44 -07:00
|
|
|
if (mRefCnt == size_t(-1)) { // really want SIZE_MAX
|
2009-02-04 21:15:52 -08:00
|
|
|
NS_WARNING("refcount overflow, leaking nsCSSValue::Array");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
--mRefCnt;
|
|
|
|
NS_LOG_RELEASE(this, mRefCnt, "nsCSSValue::Array");
|
|
|
|
if (mRefCnt == 0)
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2010-06-24 14:53:44 -07:00
|
|
|
size_t mRefCnt;
|
|
|
|
const size_t mCount;
|
2009-02-04 21:15:52 -08:00
|
|
|
// 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];
|
|
|
|
|
2010-06-24 14:53:44 -07:00
|
|
|
void* operator new(size_t aSelfSize, size_t aItemCount) CPP_THROW_NEW {
|
2009-02-04 21:15:52 -08:00
|
|
|
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)
|
|
|
|
|
2010-06-24 14:53:44 -07:00
|
|
|
Array(size_t aItemCount)
|
2009-02-04 21:15:52 -08:00
|
|
|
: 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 08:53:40 -07:00
|
|
|
// not to be implemented
|
|
|
|
Array(const Array& aOther);
|
|
|
|
Array& operator=(const Array& aOther);
|
2009-02-04 21:15:52 -08:00
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif /* nsCSSValue_h___ */
|
|
|
|
|