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
|
2000-05-15 05:58:26 +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/
|
2000-05-15 05:58:26 +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.
|
2000-05-15 05:58:26 +04: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.
|
2000-05-15 05:58:26 +04: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 ***** */
|
2000-05-15 05:58:26 +04:00
|
|
|
|
|
|
|
#ifndef nsROCSSPrimitiveValue_h___
|
|
|
|
#define nsROCSSPrimitiveValue_h___
|
|
|
|
|
|
|
|
#include "nsIDOMCSSPrimitiveValue.h"
|
2001-05-21 07:14:39 +04:00
|
|
|
#include "nsString.h"
|
2000-05-15 05:58:26 +04:00
|
|
|
#include "nsCoord.h"
|
|
|
|
#include "nsUnitConversion.h"
|
2002-01-11 03:15:55 +03:00
|
|
|
#include "nsReadableUtils.h"
|
2000-05-15 05:58:26 +04:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDOMError.h"
|
2002-01-11 03:15:55 +03:00
|
|
|
#include "nsDOMCSSRect.h"
|
2002-03-22 23:18:42 +03:00
|
|
|
#include "nsDOMCSSRGBColor.h"
|
2000-05-15 05:58:26 +04:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
class nsROCSSPrimitiveValue : public nsIDOMCSSPrimitiveValue
|
2000-05-15 05:58:26 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIDOMCSSPrimitiveValue
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_DECL_NSIDOMCSSPRIMITIVEVALUE
|
2000-05-15 05:58:26 +04:00
|
|
|
|
|
|
|
// nsIDOMCSSValue
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_DECL_NSIDOMCSSVALUE
|
2000-05-15 05:58:26 +04:00
|
|
|
|
|
|
|
// nsROCSSPrimitiveValue
|
2002-07-08 11:11:59 +04:00
|
|
|
nsROCSSPrimitiveValue(float aP2T);
|
2000-05-15 05:58:26 +04:00
|
|
|
virtual ~nsROCSSPrimitiveValue();
|
|
|
|
|
2002-03-08 22:04:15 +03:00
|
|
|
void SetNumber(float aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mValue.mFloat = aValue;
|
|
|
|
mType = CSS_NUMBER;
|
|
|
|
}
|
2002-04-26 22:10:14 +04:00
|
|
|
|
|
|
|
void SetNumber(PRInt32 aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mValue.mFloat = float(aValue);
|
|
|
|
mType = CSS_NUMBER;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetNumber(PRUint32 aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mValue.mFloat = float(aValue);
|
|
|
|
mType = CSS_NUMBER;
|
|
|
|
}
|
|
|
|
|
2001-12-07 00:15:54 +03:00
|
|
|
void SetPercent(float aValue)
|
|
|
|
{
|
2002-03-08 22:04:15 +03:00
|
|
|
Reset();
|
|
|
|
mValue.mFloat = aValue;
|
2001-12-07 00:15:54 +03:00
|
|
|
mType = CSS_PERCENTAGE;
|
|
|
|
}
|
|
|
|
|
2000-05-15 05:58:26 +04:00
|
|
|
void SetTwips(nscoord aValue)
|
|
|
|
{
|
2002-03-08 22:04:15 +03:00
|
|
|
Reset();
|
|
|
|
mValue.mTwips = aValue;
|
|
|
|
mType = CSS_PX;
|
2000-05-15 05:58:26 +04:00
|
|
|
}
|
|
|
|
|
2002-04-26 22:10:14 +04:00
|
|
|
void SetTwips(float aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mValue.mTwips = nscoord(aValue);
|
|
|
|
mType = CSS_PX;
|
|
|
|
}
|
|
|
|
|
2002-03-22 23:18:42 +03:00
|
|
|
void SetIdent(const nsACString& aString)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mValue.mString = ToNewUnicode(aString);
|
2002-04-26 22:10:14 +04:00
|
|
|
if (mValue.mString) {
|
|
|
|
mType = CSS_IDENT;
|
|
|
|
} else {
|
|
|
|
mType = CSS_UNKNOWN;
|
|
|
|
}
|
2002-03-22 23:18:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetIdent(const nsAString& aString)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mValue.mString = ToNewUnicode(aString);
|
2002-04-26 22:10:14 +04:00
|
|
|
if (mValue.mString) {
|
|
|
|
mType = CSS_IDENT;
|
|
|
|
} else {
|
|
|
|
mType = CSS_UNKNOWN;
|
|
|
|
}
|
2002-03-22 23:18:42 +03:00
|
|
|
}
|
|
|
|
|
2002-01-11 03:15:55 +03:00
|
|
|
void SetString(const nsACString& aString)
|
2000-05-15 05:58:26 +04:00
|
|
|
{
|
2002-03-08 22:04:15 +03:00
|
|
|
Reset();
|
|
|
|
mValue.mString = ToNewUnicode(aString);
|
2002-04-26 22:10:14 +04:00
|
|
|
if (mValue.mString) {
|
|
|
|
mType = CSS_STRING;
|
|
|
|
} else {
|
|
|
|
mType = CSS_UNKNOWN;
|
|
|
|
}
|
2000-05-15 05:58:26 +04:00
|
|
|
}
|
|
|
|
|
2001-09-07 06:28:10 +04:00
|
|
|
void SetString(const nsAString& aString)
|
2000-06-14 04:06:36 +04:00
|
|
|
{
|
2002-03-08 22:04:15 +03:00
|
|
|
Reset();
|
|
|
|
mValue.mString = ToNewUnicode(aString);
|
2002-04-26 22:10:14 +04:00
|
|
|
if (mValue.mString) {
|
|
|
|
mType = CSS_STRING;
|
|
|
|
} else {
|
|
|
|
mType = CSS_UNKNOWN;
|
|
|
|
}
|
2000-06-14 04:06:36 +04:00
|
|
|
}
|
|
|
|
|
2002-03-13 00:16:22 +03:00
|
|
|
void SetURI(const nsACString& aString)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mValue.mString = ToNewUnicode(aString);
|
2002-04-26 22:10:14 +04:00
|
|
|
if (mValue.mString) {
|
|
|
|
mType = CSS_URI;
|
|
|
|
} else {
|
|
|
|
mType = CSS_UNKNOWN;
|
|
|
|
}
|
2002-03-13 00:16:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetURI(const nsAString& aString)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mValue.mString = ToNewUnicode(aString);
|
2002-04-26 22:10:14 +04:00
|
|
|
if (mValue.mString) {
|
|
|
|
mType = CSS_URI;
|
|
|
|
} else {
|
|
|
|
mType = CSS_UNKNOWN;
|
|
|
|
}
|
2002-03-22 23:18:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetColor(nsIDOMRGBColor* aColor)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aColor, "Null RGBColor being set!");
|
|
|
|
Reset();
|
|
|
|
mValue.mColor = aColor;
|
|
|
|
if (mValue.mColor) {
|
|
|
|
NS_ADDREF(mValue.mColor);
|
|
|
|
mType = CSS_RGBCOLOR;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mType = CSS_UNKNOWN;
|
|
|
|
}
|
2002-03-13 00:16:22 +03:00
|
|
|
}
|
|
|
|
|
2002-01-11 03:15:55 +03:00
|
|
|
void SetRect(nsIDOMRect* aRect)
|
|
|
|
{
|
2002-03-08 22:04:15 +03:00
|
|
|
NS_PRECONDITION(aRect, "Null rect being set!");
|
|
|
|
Reset();
|
|
|
|
mValue.mRect = aRect;
|
2002-03-22 23:18:42 +03:00
|
|
|
if (mValue.mRect) {
|
|
|
|
NS_ADDREF(mValue.mRect);
|
|
|
|
mType = CSS_RECT;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mType = CSS_UNKNOWN;
|
|
|
|
}
|
2002-01-11 03:15:55 +03:00
|
|
|
}
|
|
|
|
|
2002-03-08 22:04:15 +03:00
|
|
|
void Reset(void)
|
|
|
|
{
|
2002-03-22 23:18:42 +03:00
|
|
|
switch (mType) {
|
|
|
|
case CSS_IDENT:
|
|
|
|
case CSS_STRING:
|
|
|
|
case CSS_URI:
|
|
|
|
NS_ASSERTION(mValue.mString, "Null string should never happen");
|
|
|
|
nsMemory::Free(mValue.mString);
|
|
|
|
mValue.mString = nsnull;
|
|
|
|
break;
|
|
|
|
case CSS_RECT:
|
|
|
|
NS_ASSERTION(mValue.mRect, "Null Rect should never happen");
|
|
|
|
NS_RELEASE(mValue.mRect);
|
|
|
|
mValue.mRect = nsnull;
|
|
|
|
break;
|
|
|
|
case CSS_RGBCOLOR:
|
|
|
|
NS_ASSERTION(mValue.mColor, "Null RGBColor should never happen");
|
|
|
|
NS_RELEASE(mValue.mColor);
|
|
|
|
mValue.mColor = nsnull;
|
|
|
|
break;
|
2002-03-08 22:04:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-15 05:58:26 +04:00
|
|
|
private:
|
2002-03-27 10:39:54 +03:00
|
|
|
void GetEscapedURI(PRUnichar *aURI, PRUnichar **aReturn);
|
|
|
|
|
2000-05-15 05:58:26 +04:00
|
|
|
PRUint16 mType;
|
|
|
|
|
2002-03-08 22:04:15 +03:00
|
|
|
union {
|
2002-03-22 23:18:42 +03:00
|
|
|
nscoord mTwips;
|
|
|
|
float mFloat;
|
|
|
|
nsIDOMRGBColor* mColor;
|
|
|
|
nsIDOMRect* mRect;
|
|
|
|
PRUnichar* mString;
|
2002-03-08 22:04:15 +03:00
|
|
|
} mValue;
|
|
|
|
|
2000-05-15 05:58:26 +04:00
|
|
|
float mT2P;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsROCSSPrimitiveValue_h___ */
|
|
|
|
|