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
|
2000-05-15 05:58:26 +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/
|
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.
|
|
|
|
*
|
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.
|
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
|
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 ***** */
|
2000-05-15 05:58:26 +04:00
|
|
|
|
2006-03-25 08:47:31 +03:00
|
|
|
/* DOM object representing values in DOM computed style */
|
|
|
|
|
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"
|
2007-03-23 02:01:14 +03:00
|
|
|
#include "nsUnitConversion.h"
|
2002-01-11 03:15:55 +03:00
|
|
|
#include "nsReadableUtils.h"
|
2003-10-02 02:53:56 +04:00
|
|
|
#include "nsIURI.h"
|
2004-01-18 05:42:27 +03:00
|
|
|
#include "nsIAtom.h"
|
2007-07-22 21:58:37 +04:00
|
|
|
#include "nsCSSKeywords.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
|
2007-02-07 10:46:44 +03:00
|
|
|
nsROCSSPrimitiveValue(PRInt32 aAppUnitsPerInch);
|
2000-05-15 05:58:26 +04:00
|
|
|
virtual ~nsROCSSPrimitiveValue();
|
|
|
|
|
2007-07-22 21:58:37 +04:00
|
|
|
// FIXME Many of these methods should be out-of-line.
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-02-07 10:46:44 +03:00
|
|
|
void SetAppUnits(nscoord aValue)
|
2000-05-15 05:58:26 +04:00
|
|
|
{
|
2002-03-08 22:04:15 +03:00
|
|
|
Reset();
|
2007-02-07 10:46:44 +03:00
|
|
|
mValue.mAppUnits = aValue;
|
2002-03-08 22:04:15 +03:00
|
|
|
mType = CSS_PX;
|
2000-05-15 05:58:26 +04:00
|
|
|
}
|
|
|
|
|
2007-02-07 10:46:44 +03:00
|
|
|
void SetAppUnits(float aValue)
|
2002-04-26 22:10:14 +04:00
|
|
|
{
|
2007-02-07 10:46:44 +03:00
|
|
|
SetAppUnits(NSToCoordRound(aValue));
|
2002-04-26 22:10:14 +04:00
|
|
|
}
|
|
|
|
|
2004-01-18 05:42:27 +03:00
|
|
|
void SetIdent(nsIAtom* aAtom)
|
2002-03-22 23:18:42 +03:00
|
|
|
{
|
2004-01-18 05:42:27 +03:00
|
|
|
NS_PRECONDITION(aAtom, "Don't pass in a null atom");
|
2002-03-22 23:18:42 +03:00
|
|
|
Reset();
|
2004-01-18 05:42:27 +03:00
|
|
|
NS_ADDREF(mValue.mAtom = aAtom);
|
|
|
|
mType = CSS_IDENT;
|
2002-03-22 23:18:42 +03:00
|
|
|
}
|
|
|
|
|
2007-07-22 21:58:37 +04:00
|
|
|
// FIXME More callers should use this variant.
|
|
|
|
void SetIdent(nsCSSKeyword aKeyword)
|
|
|
|
{
|
|
|
|
SetIdent(nsCSSKeywords::GetStringValue(aKeyword));
|
|
|
|
}
|
|
|
|
|
2004-01-18 05:42:27 +03:00
|
|
|
void SetIdent(const nsACString& aString)
|
2002-03-22 23:18:42 +03:00
|
|
|
{
|
|
|
|
Reset();
|
2004-01-18 05:42:27 +03:00
|
|
|
mValue.mAtom = NS_NewAtom(aString);
|
|
|
|
if (mValue.mAtom) {
|
2002-04-26 22:10:14 +04:00
|
|
|
mType = CSS_IDENT;
|
|
|
|
} else {
|
2004-01-18 05:42:27 +03:00
|
|
|
// XXXcaa We should probably let the caller know we are out of memory
|
2002-04-26 22:10:14 +04:00
|
|
|
mType = CSS_UNKNOWN;
|
|
|
|
}
|
2002-03-22 23:18:42 +03:00
|
|
|
}
|
|
|
|
|
2007-07-22 21:58:37 +04:00
|
|
|
// FIXME: CSS_STRING should imply a string with "" and a need for escaping.
|
|
|
|
void SetString(const nsACString& aString, PRUint16 aType = CSS_STRING)
|
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) {
|
2007-07-22 21:58:37 +04:00
|
|
|
mType = aType;
|
2002-04-26 22:10:14 +04:00
|
|
|
} else {
|
2004-01-18 05:42:27 +03:00
|
|
|
// XXXcaa We should probably let the caller know we are out of memory
|
2002-04-26 22:10:14 +04:00
|
|
|
mType = CSS_UNKNOWN;
|
|
|
|
}
|
2000-05-15 05:58:26 +04:00
|
|
|
}
|
|
|
|
|
2007-07-22 21:58:37 +04:00
|
|
|
// FIXME: CSS_STRING should imply a string with "" and a need for escaping.
|
|
|
|
void SetString(const nsAString& aString, PRUint16 aType = CSS_STRING)
|
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) {
|
2007-07-22 21:58:37 +04:00
|
|
|
mType = aType;
|
2002-04-26 22:10:14 +04:00
|
|
|
} else {
|
2004-01-18 05:42:27 +03:00
|
|
|
// XXXcaa We should probably let the caller know we are out of memory
|
2002-04-26 22:10:14 +04:00
|
|
|
mType = CSS_UNKNOWN;
|
|
|
|
}
|
2000-06-14 04:06:36 +04:00
|
|
|
}
|
|
|
|
|
2003-10-02 02:53:56 +04:00
|
|
|
void SetURI(nsIURI *aURI)
|
2002-03-13 00:16:22 +03:00
|
|
|
{
|
|
|
|
Reset();
|
2003-10-02 02:53:56 +04:00
|
|
|
mValue.mURI = aURI;
|
|
|
|
NS_IF_ADDREF(mValue.mURI);
|
|
|
|
mType = CSS_URI;
|
2002-03-22 23:18:42 +03:00
|
|
|
}
|
|
|
|
|
2007-01-25 05:03:02 +03:00
|
|
|
void SetColor(nsDOMCSSRGBColor* aColor)
|
2002-03-22 23:18:42 +03:00
|
|
|
{
|
|
|
|
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:
|
2004-01-18 05:42:27 +03:00
|
|
|
NS_ASSERTION(mValue.mAtom, "Null atom should never happen");
|
|
|
|
NS_RELEASE(mValue.mAtom);
|
|
|
|
break;
|
2002-03-22 23:18:42 +03:00
|
|
|
case CSS_STRING:
|
2007-07-22 21:58:37 +04:00
|
|
|
case CSS_ATTR:
|
|
|
|
case CSS_COUNTER: // FIXME: Counter should use an object
|
2002-03-22 23:18:42 +03:00
|
|
|
NS_ASSERTION(mValue.mString, "Null string should never happen");
|
|
|
|
nsMemory::Free(mValue.mString);
|
|
|
|
mValue.mString = nsnull;
|
|
|
|
break;
|
2003-10-02 02:53:56 +04:00
|
|
|
case CSS_URI:
|
|
|
|
NS_IF_RELEASE(mValue.mURI);
|
|
|
|
break;
|
2002-03-22 23:18:42 +03:00
|
|
|
case CSS_RECT:
|
|
|
|
NS_ASSERTION(mValue.mRect, "Null Rect should never happen");
|
|
|
|
NS_RELEASE(mValue.mRect);
|
|
|
|
break;
|
|
|
|
case CSS_RGBCOLOR:
|
|
|
|
NS_ASSERTION(mValue.mColor, "Null RGBColor should never happen");
|
|
|
|
NS_RELEASE(mValue.mColor);
|
|
|
|
break;
|
2002-03-08 22:04:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-15 05:58:26 +04:00
|
|
|
private:
|
2003-10-02 02:53:56 +04:00
|
|
|
void GetEscapedURI(nsIURI *aURI, PRUnichar **aReturn);
|
2002-03-27 10:39:54 +03:00
|
|
|
|
2000-05-15 05:58:26 +04:00
|
|
|
PRUint16 mType;
|
|
|
|
|
2002-03-08 22:04:15 +03:00
|
|
|
union {
|
2007-02-07 10:46:44 +03:00
|
|
|
nscoord mAppUnits;
|
2002-03-22 23:18:42 +03:00
|
|
|
float mFloat;
|
2007-01-25 05:03:02 +03:00
|
|
|
nsDOMCSSRGBColor* mColor;
|
2002-03-22 23:18:42 +03:00
|
|
|
nsIDOMRect* mRect;
|
|
|
|
PRUnichar* mString;
|
2003-10-02 02:53:56 +04:00
|
|
|
nsIURI* mURI;
|
2007-07-22 21:58:37 +04:00
|
|
|
nsIAtom* mAtom; // FIXME use nsCSSKeyword instead
|
2002-03-08 22:04:15 +03:00
|
|
|
} mValue;
|
|
|
|
|
2007-02-07 10:46:44 +03:00
|
|
|
PRInt32 mAppUnitsPerInch;
|
2000-05-15 05:58:26 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsROCSSPrimitiveValue_h___ */
|
|
|
|
|