2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-10-08 05:29:29 +04:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
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.
|
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* 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.
|
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
|
|
|
|
* either 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 NPL, 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 NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-10-08 05:29:29 +04:00
|
|
|
#ifndef nsCSSValue_h___
|
|
|
|
#define nsCSSValue_h___
|
|
|
|
|
|
|
|
#include "nsColor.h"
|
|
|
|
#include "nsString.h"
|
2002-05-15 22:55:21 +04:00
|
|
|
#include "nsCRT.h"
|
1998-10-08 05:29:29 +04:00
|
|
|
#include "nsCoord.h"
|
2003-06-08 02:14:42 +04:00
|
|
|
#include "nsCSSProperty.h"
|
2001-02-19 15:55:42 +03:00
|
|
|
#include "nsUnitConversion.h"
|
2003-10-02 02:53:56 +04:00
|
|
|
#include "nsIURI.h"
|
2003-10-30 04:45:37 +03:00
|
|
|
#include "nsCOMPtr.h"
|
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)
|
2003-10-02 02:53:56 +04:00
|
|
|
eCSSUnit_String = 10, // (PRUnichar*) a string value
|
|
|
|
eCSSUnit_Attr = 11, // (PRUnichar*) a attr(string) value
|
|
|
|
eCSSUnit_Counter = 12, // (PRUnichar*) a counter(string,[string]) value
|
|
|
|
eCSSUnit_Counters = 13, // (PRUnichar*) a counters(string,string[,string]) value
|
2003-10-30 04:45:37 +03:00
|
|
|
eCSSUnit_URL = 14, // (nsCSSValue::URL*) value
|
1998-10-27 02:19:59 +03:00
|
|
|
eCSSUnit_Integer = 50, // (int) simple value
|
|
|
|
eCSSUnit_Enumerated = 51, // (int) value has enumerated meaning
|
|
|
|
eCSSUnit_Color = 80, // (color) an RGBA value
|
|
|
|
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
|
1998-10-27 02:19:59 +03:00
|
|
|
eCSSUnit_Inch = 100, // (float) Standard length
|
|
|
|
eCSSUnit_Foot = 101, // (float) 12 inches
|
|
|
|
eCSSUnit_Mile = 102, // (float) 5280 feet
|
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
|
|
|
|
eCSSUnit_Meter = 210, // (float) Standard length
|
|
|
|
eCSSUnit_Kilometer = 213, // (float) 1000 meters
|
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
|
|
|
|
|
|
|
// European Typographic
|
1998-10-27 02:19:59 +03:00
|
|
|
eCSSUnit_Didot = 400, // (float) 15 didots == 16 points
|
|
|
|
eCSSUnit_Cicero = 401, // (float) 12 didots
|
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
|
|
|
|
eCSSUnit_EN = 801, // (float) .5 em
|
|
|
|
eCSSUnit_XHeight = 802, // (float) distance from top of lower case x to baseline
|
|
|
|
eCSSUnit_CapHeight = 803, // (float) distance from top of uppercase case H to baseline
|
1999-07-18 04:28:43 +04:00
|
|
|
eCSSUnit_Char = 804, // (float) number of characters, used for width with monospace font
|
1998-10-08 05:29:29 +04:00
|
|
|
|
|
|
|
// Screen relative measure
|
1998-10-27 02:19:59 +03:00
|
|
|
eCSSUnit_Pixel = 900, // (float)
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
// Proportional Unit (for columns in tables)
|
|
|
|
eCSSUnit_Proportional = 950,
|
|
|
|
|
1998-10-27 02:19:59 +03:00
|
|
|
// Angular units
|
|
|
|
eCSSUnit_Degree = 1000, // (float) 360 per circle
|
|
|
|
eCSSUnit_Grad = 1001, // (float) 400 per circle
|
|
|
|
eCSSUnit_Radian = 1002, // (float) 2pi per circle
|
|
|
|
|
|
|
|
// Frequency units
|
|
|
|
eCSSUnit_Hertz = 2000, // (float)
|
|
|
|
eCSSUnit_Kilohertz = 2001, // (float)
|
|
|
|
|
|
|
|
// Time units
|
|
|
|
eCSSUnit_Seconds = 3000, // (float)
|
|
|
|
eCSSUnit_Milliseconds = 3001 // (float)
|
1998-10-08 05:29:29 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class nsCSSValue {
|
|
|
|
public:
|
2003-10-30 04:45:37 +03:00
|
|
|
struct URL;
|
|
|
|
friend struct URL;
|
|
|
|
|
2001-02-19 15:55:42 +03:00
|
|
|
// for valueless units only (null, auto, inherit, none, normal)
|
|
|
|
nsCSSValue(nsCSSUnit aUnit = eCSSUnit_Null)
|
|
|
|
: mUnit(aUnit)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aUnit <= eCSSUnit_Normal, "not a valueless unit");
|
|
|
|
if (aUnit > eCSSUnit_Normal) {
|
|
|
|
mUnit = eCSSUnit_Null;
|
|
|
|
}
|
|
|
|
mValue.mInt = 0;
|
|
|
|
}
|
|
|
|
|
1998-10-08 05:29:29 +04:00
|
|
|
nsCSSValue(PRInt32 aValue, nsCSSUnit aUnit);
|
|
|
|
nsCSSValue(float aValue, nsCSSUnit aUnit);
|
2002-03-24 01:56:05 +03:00
|
|
|
nsCSSValue(const nsAString& aValue, nsCSSUnit aUnit);
|
1998-10-08 05:29:29 +04:00
|
|
|
nsCSSValue(nscolor aValue);
|
2003-10-30 06:34:58 +03:00
|
|
|
nsCSSValue(URL* aValue);
|
1998-10-08 05:29:29 +04:00
|
|
|
nsCSSValue(const nsCSSValue& aCopy);
|
2003-12-29 22:07:53 +03:00
|
|
|
~nsCSSValue();
|
1998-10-08 05:29:29 +04:00
|
|
|
|
|
|
|
nsCSSValue& operator=(const nsCSSValue& aCopy);
|
|
|
|
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
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
nsCSSUnit GetUnit() const { return mUnit; };
|
|
|
|
PRBool IsLengthUnit() const
|
2001-06-01 02:19:43 +04:00
|
|
|
{ return PRBool((eCSSUnit_Inch <= mUnit) && (mUnit <= eCSSUnit_Proportional)); }
|
2003-12-29 22:07:53 +03:00
|
|
|
PRBool IsFixedLengthUnit() const
|
1998-10-27 02:19:59 +03:00
|
|
|
{ return PRBool((eCSSUnit_Inch <= mUnit) && (mUnit <= eCSSUnit_Cicero)); }
|
2003-12-29 22:07:53 +03:00
|
|
|
PRBool IsRelativeLengthUnit() const
|
2001-06-01 02:19:43 +04:00
|
|
|
{ return PRBool((eCSSUnit_EM <= mUnit) && (mUnit <= eCSSUnit_Proportional)); }
|
2003-12-29 22:07:53 +03:00
|
|
|
PRBool IsAngularUnit() const
|
1998-10-27 02:19:59 +03:00
|
|
|
{ return PRBool((eCSSUnit_Degree <= mUnit) && (mUnit <= eCSSUnit_Radian)); }
|
2003-12-29 22:07:53 +03:00
|
|
|
PRBool IsFrequencyUnit() const
|
1998-10-27 02:19:59 +03:00
|
|
|
{ return PRBool((eCSSUnit_Hertz <= mUnit) && (mUnit <= eCSSUnit_Kilohertz)); }
|
2003-12-29 22:07:53 +03:00
|
|
|
PRBool IsTimeUnit() const
|
1998-10-27 02:19:59 +03:00
|
|
|
{ return PRBool((eCSSUnit_Seconds <= mUnit) && (mUnit <= eCSSUnit_Milliseconds)); }
|
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
|
|
|
{
|
|
|
|
NS_ASSERTION(mUnit == eCSSUnit_Integer || mUnit == eCSSUnit_Enumerated,
|
|
|
|
"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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAString& GetStringValue(nsAString& aBuffer) const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(eCSSUnit_String <= mUnit && mUnit <= eCSSUnit_Counters,
|
|
|
|
"not a string value");
|
|
|
|
aBuffer.Truncate();
|
|
|
|
if (nsnull != mValue.mString) {
|
|
|
|
aBuffer.Append(mValue.mString);
|
|
|
|
}
|
|
|
|
return aBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PRUnichar* GetStringBufferValue() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(eCSSUnit_String <= mUnit && mUnit <= eCSSUnit_Counters,
|
|
|
|
"not a string value");
|
|
|
|
return mValue.mString;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
nsIURI* GetURLValue() const
|
2003-10-02 02:53:56 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mUnit == eCSSUnit_URL, "not a URL value");
|
2003-10-30 04:45:37 +03:00
|
|
|
return mValue.mURL->mURI;
|
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
const PRUnichar* GetOriginalURLValue() const
|
2003-10-30 04:45:37 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mUnit == eCSSUnit_URL, "not a URL value");
|
|
|
|
return mValue.mURL->mString;
|
2003-10-02 02:53:56 +04:00
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
nscoord GetLengthTwips() const;
|
2003-10-02 02:53:56 +04:00
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
void Reset() // sets to null
|
2001-02-19 15:55:42 +03:00
|
|
|
{
|
|
|
|
if ((eCSSUnit_String <= mUnit) && (mUnit <= eCSSUnit_Counters) &&
|
|
|
|
(nsnull != mValue.mString)) {
|
|
|
|
nsCRT::free(mValue.mString);
|
2003-10-02 02:53:56 +04:00
|
|
|
} else if (eCSSUnit_URL == mUnit) {
|
2003-10-30 04:45:37 +03:00
|
|
|
mValue.mURL->Release();
|
2001-02-19 15:55:42 +03:00
|
|
|
}
|
|
|
|
mUnit = eCSSUnit_Null;
|
|
|
|
mValue.mInt = 0;
|
|
|
|
}
|
1998-10-08 05:29:29 +04:00
|
|
|
|
|
|
|
void SetIntValue(PRInt32 aValue, nsCSSUnit aUnit);
|
2003-12-29 22:07:53 +03:00
|
|
|
void SetPercentValue(float aValue);
|
|
|
|
void SetFloatValue(float aValue, nsCSSUnit aUnit);
|
2002-03-24 01:56:05 +03:00
|
|
|
void SetStringValue(const nsAString& aValue, nsCSSUnit aUnit);
|
1998-10-08 05:29:29 +04:00
|
|
|
void SetColorValue(nscolor aValue);
|
2003-10-30 04:45:37 +03:00
|
|
|
void SetURLValue(nsCSSValue::URL* aURI);
|
2003-12-29 22:07:53 +03:00
|
|
|
void SetAutoValue();
|
|
|
|
void SetInheritValue();
|
|
|
|
void SetInitialValue();
|
|
|
|
void SetNoneValue();
|
|
|
|
void SetNormalValue();
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2002-03-24 01:56:05 +03:00
|
|
|
void AppendToString(nsAString& aBuffer, nsCSSProperty aPropID = eCSSProperty_UNKNOWN) const;
|
|
|
|
void ToString(nsAString& aBuffer, nsCSSProperty aPropID = eCSSProperty_UNKNOWN) const;
|
2003-12-29 22:07:53 +03:00
|
|
|
#endif
|
1998-10-08 05:29:29 +04:00
|
|
|
|
2003-10-30 04:45:37 +03:00
|
|
|
MOZ_DECL_CTOR_COUNTER(nsCSSValue::URL)
|
|
|
|
|
|
|
|
struct URL {
|
|
|
|
// Caller must delete this object immediately if the allocation of
|
|
|
|
// |mString| fails.
|
|
|
|
URL(nsIURI* aURI, const PRUnichar* aString)
|
|
|
|
: mURI(aURI),
|
|
|
|
mString(nsCRT::strdup(aString)),
|
|
|
|
mRefCnt(0)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsCSSValue::URL);
|
|
|
|
}
|
|
|
|
|
|
|
|
~URL()
|
|
|
|
{
|
|
|
|
// null |mString| isn't valid normally, but is checked by callers
|
|
|
|
// of the constructor
|
|
|
|
if (mString)
|
|
|
|
nsCRT::free(mString);
|
|
|
|
MOZ_COUNT_DTOR(nsCSSValue::URL);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool operator==(const URL& aOther)
|
|
|
|
{
|
|
|
|
PRBool eq;
|
|
|
|
return nsCRT::strcmp(mString, aOther.mString) == 0 &&
|
|
|
|
(mURI == aOther.mURI || // handles null == null
|
|
|
|
(mURI && aOther.mURI &&
|
|
|
|
NS_SUCCEEDED(mURI->Equals(aOther.mURI, &eq)) &&
|
|
|
|
eq));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> mURI; // null == invalid URL
|
|
|
|
PRUnichar* mString;
|
|
|
|
|
|
|
|
void AddRef() { ++mRefCnt; }
|
|
|
|
void Release() { if (--mRefCnt == 0) delete this; }
|
|
|
|
private:
|
|
|
|
nsrefcnt mRefCnt;
|
|
|
|
};
|
|
|
|
|
1998-10-08 05:29:29 +04:00
|
|
|
protected:
|
|
|
|
nsCSSUnit mUnit;
|
|
|
|
union {
|
2000-06-06 13:36:12 +04:00
|
|
|
PRInt32 mInt;
|
|
|
|
float mFloat;
|
|
|
|
PRUnichar* mString;
|
|
|
|
nscolor mColor;
|
2003-10-30 04:45:37 +03:00
|
|
|
URL* mURL;
|
1998-10-08 05:29:29 +04:00
|
|
|
} mValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsCSSValue_h___ */
|
|
|
|
|