From 04bccbd8fa0d28f90584a25ffba2f16e5a7e9a52 Mon Sep 17 00:00:00 2001 From: "jst%netscape.com" Date: Mon, 15 May 2000 01:58:26 +0000 Subject: [PATCH] Adding a very primitive readonly implementation of CSSPrimitiveValue. Not part of the build yet. git-svn-id: svn://10.0.0.236/trunk@69717 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/style/src/nsROCSSPrimitiveValue.cpp | 217 ++++++++++++++++++ .../html/style/src/nsROCSSPrimitiveValue.h | 80 +++++++ .../html/style/src/nsROCSSPrimitiveValue.cpp | 217 ++++++++++++++++++ .../html/style/src/nsROCSSPrimitiveValue.h | 80 +++++++ .../layout/style/nsROCSSPrimitiveValue.cpp | 217 ++++++++++++++++++ mozilla/layout/style/nsROCSSPrimitiveValue.h | 80 +++++++ 6 files changed, 891 insertions(+) create mode 100644 mozilla/content/html/style/src/nsROCSSPrimitiveValue.cpp create mode 100644 mozilla/content/html/style/src/nsROCSSPrimitiveValue.h create mode 100644 mozilla/layout/html/style/src/nsROCSSPrimitiveValue.cpp create mode 100644 mozilla/layout/html/style/src/nsROCSSPrimitiveValue.h create mode 100644 mozilla/layout/style/nsROCSSPrimitiveValue.cpp create mode 100644 mozilla/layout/style/nsROCSSPrimitiveValue.h diff --git a/mozilla/content/html/style/src/nsROCSSPrimitiveValue.cpp b/mozilla/content/html/style/src/nsROCSSPrimitiveValue.cpp new file mode 100644 index 00000000000..0a5c56a75be --- /dev/null +++ b/mozilla/content/html/style/src/nsROCSSPrimitiveValue.cpp @@ -0,0 +1,217 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/ + * + * 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 Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsROCSSPrimitiveValue.h" + +#include "nsCOMPtr.h" +#include "nsDOMError.h" + + +nsROCSSPrimitiveValue::nsROCSSPrimitiveValue(nsISupports *aOwner, float aT2P) + : mType(0), mTwips(0), mString(), mOwner(aOwner), mT2P(aT2P) +{ + NS_INIT_REFCNT(); +} + + +nsROCSSPrimitiveValue::~nsROCSSPrimitiveValue() +{ +} + + +NS_IMPL_ADDREF(nsROCSSPrimitiveValue); +NS_IMPL_RELEASE(nsROCSSPrimitiveValue); + + +NS_INTERFACE_MAP_BEGIN(nsROCSSPrimitiveValue) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSPrimitiveValue) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValue) + NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMCSSPrimitiveValue) +NS_INTERFACE_MAP_END + + +// nsIScriptObjectOwner + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetScriptObject(nsIScriptContext *aContext, + void** aScriptObject) +{ + nsresult res = NS_OK; + + if (!mScriptObject) { + nsISupports *supports = NS_STATIC_CAST(nsIDOMCSSPrimitiveValue *, this); + + // XXX Should be done through factory + res = NS_NewScriptCSSPrimitiveValue(aContext, supports, mOwner, + &mScriptObject); + } + + *aScriptObject = mScriptObject; + + return res; +} + + +// nsIDOMCSSValue + +NS_IMETHODIMP +nsROCSSPrimitiveValue::SetScriptObject(void* aScriptObject) +{ + mScriptObject = aScriptObject; + return NS_OK; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetCssText(nsString& aCssText) +{ + aCssText.Truncate(); + return NS_ERROR_DOM_NOT_SUPPORTED_ERR; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::SetCssText(const nsString& aCssText) +{ + return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetValueType(PRUint16* aValueType) +{ + NS_ENSURE_ARG_POINTER(aValueType); + *aValueType = nsIDOMCSSValue::CSS_PRIMITIVE_VALUE; + return NS_OK; +} + + +// nsIDOMCSSPrimitiveValue + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetPrimitiveType(PRUint16* aPrimitiveType) +{ + NS_ENSURE_ARG_POINTER(aPrimitiveType); + *aPrimitiveType = mType; + + return NS_OK; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::SetFloatValue(PRUint16 aUnitType, float aFloatValue) +{ + return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetFloatValue(PRUint16 aUnitType, float* aReturn) +{ + NS_ENSURE_ARG_POINTER(aReturn); + *aReturn = 0; + + if (mType == CSS_STRING) { + return NS_ERROR_DOM_INVALID_ACCESS_ERR; + } + + switch(aUnitType) { + case CSS_PX : + *aReturn = NSTwipsToFloatPixels(mTwips, mT2P); + break; + case CSS_CM : + *aReturn = NS_TWIPS_TO_CENTIMETERS(mTwips); + break; + case CSS_MM : + *aReturn = NS_TWIPS_TO_MILLIMETERS(mTwips); + break; + case CSS_IN : + *aReturn = NS_TWIPS_TO_INCHES(mTwips); + break; + case CSS_PT : + *aReturn = NSTwipsToFloatPoints(mTwips); + break; + case CSS_PC : + case CSS_UNKNOWN : + case CSS_NUMBER : + case CSS_PERCENTAGE : + case CSS_EMS : + case CSS_EXS : + case CSS_DEG : + case CSS_RAD : + case CSS_GRAD : + case CSS_MS : + case CSS_S : + case CSS_HZ : + case CSS_KHZ : + case CSS_DIMENSION : + case CSS_STRING : + case CSS_URI : + case CSS_IDENT : + case CSS_ATTR : + case CSS_COUNTER : + case CSS_RECT : + case CSS_RGBCOLOR : + return NS_ERROR_DOM_INVALID_ACCESS_ERR; + } + + return NS_OK; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::SetStringValue(PRUint16 aStringType, + const nsString& aStringValue) +{ + return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetStringValue(nsString& aReturn) +{ + aReturn = mString; + return NS_OK; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetCounterValue(nsIDOMCounter** aReturn) +{ + return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetRectValue(nsIDOMRect** aReturn) +{ + return NS_ERROR_DOM_NOT_SUPPORTED_ERR; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetRGBColorValue(nsIDOMRGBColor** aReturn) +{ + return NS_ERROR_DOM_NOT_SUPPORTED_ERR; +} + diff --git a/mozilla/content/html/style/src/nsROCSSPrimitiveValue.h b/mozilla/content/html/style/src/nsROCSSPrimitiveValue.h new file mode 100644 index 00000000000..b82d677725f --- /dev/null +++ b/mozilla/content/html/style/src/nsROCSSPrimitiveValue.h @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/ + * + * 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 Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#ifndef nsROCSSPrimitiveValue_h___ +#define nsROCSSPrimitiveValue_h___ + +#include "nsIDOMCSSPrimitiveValue.h" +#include "nsCoord.h" +#include "nsUnitConversion.h" +#include "nsIScriptObjectOwner.h" + +#include "nsCOMPtr.h" +#include "nsDOMError.h" + + +class nsROCSSPrimitiveValue : public nsIDOMCSSPrimitiveValue, + public nsIScriptObjectOwner +{ +public: + NS_DECL_ISUPPORTS + + // nsIDOMCSSPrimitiveValue + NS_DECL_IDOMCSSPRIMITIVEVALUE + + // nsIDOMCSSValue + NS_DECL_IDOMCSSVALUE + + // nsIScriptObjectOwner + NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); + NS_IMETHOD SetScriptObject(void* aScriptObject); + + // nsROCSSPrimitiveValue + nsROCSSPrimitiveValue(nsISupports *aOwner, float aP2T); + virtual ~nsROCSSPrimitiveValue(); + + void SetTwips(nscoord aValue) + { + mTwips = aValue; + } + + void SetString(const char *aString) + { + mString.AssignWithConversion(aString); + mType = CSS_STRING; + } + +private: + PRUint16 mType; + + nscoord mTwips; + nsString mString; + + nsISupports *mOwner; + + float mT2P; + + void* mScriptObject; +}; + +#endif /* nsROCSSPrimitiveValue_h___ */ + diff --git a/mozilla/layout/html/style/src/nsROCSSPrimitiveValue.cpp b/mozilla/layout/html/style/src/nsROCSSPrimitiveValue.cpp new file mode 100644 index 00000000000..0a5c56a75be --- /dev/null +++ b/mozilla/layout/html/style/src/nsROCSSPrimitiveValue.cpp @@ -0,0 +1,217 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/ + * + * 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 Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsROCSSPrimitiveValue.h" + +#include "nsCOMPtr.h" +#include "nsDOMError.h" + + +nsROCSSPrimitiveValue::nsROCSSPrimitiveValue(nsISupports *aOwner, float aT2P) + : mType(0), mTwips(0), mString(), mOwner(aOwner), mT2P(aT2P) +{ + NS_INIT_REFCNT(); +} + + +nsROCSSPrimitiveValue::~nsROCSSPrimitiveValue() +{ +} + + +NS_IMPL_ADDREF(nsROCSSPrimitiveValue); +NS_IMPL_RELEASE(nsROCSSPrimitiveValue); + + +NS_INTERFACE_MAP_BEGIN(nsROCSSPrimitiveValue) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSPrimitiveValue) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValue) + NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMCSSPrimitiveValue) +NS_INTERFACE_MAP_END + + +// nsIScriptObjectOwner + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetScriptObject(nsIScriptContext *aContext, + void** aScriptObject) +{ + nsresult res = NS_OK; + + if (!mScriptObject) { + nsISupports *supports = NS_STATIC_CAST(nsIDOMCSSPrimitiveValue *, this); + + // XXX Should be done through factory + res = NS_NewScriptCSSPrimitiveValue(aContext, supports, mOwner, + &mScriptObject); + } + + *aScriptObject = mScriptObject; + + return res; +} + + +// nsIDOMCSSValue + +NS_IMETHODIMP +nsROCSSPrimitiveValue::SetScriptObject(void* aScriptObject) +{ + mScriptObject = aScriptObject; + return NS_OK; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetCssText(nsString& aCssText) +{ + aCssText.Truncate(); + return NS_ERROR_DOM_NOT_SUPPORTED_ERR; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::SetCssText(const nsString& aCssText) +{ + return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetValueType(PRUint16* aValueType) +{ + NS_ENSURE_ARG_POINTER(aValueType); + *aValueType = nsIDOMCSSValue::CSS_PRIMITIVE_VALUE; + return NS_OK; +} + + +// nsIDOMCSSPrimitiveValue + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetPrimitiveType(PRUint16* aPrimitiveType) +{ + NS_ENSURE_ARG_POINTER(aPrimitiveType); + *aPrimitiveType = mType; + + return NS_OK; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::SetFloatValue(PRUint16 aUnitType, float aFloatValue) +{ + return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetFloatValue(PRUint16 aUnitType, float* aReturn) +{ + NS_ENSURE_ARG_POINTER(aReturn); + *aReturn = 0; + + if (mType == CSS_STRING) { + return NS_ERROR_DOM_INVALID_ACCESS_ERR; + } + + switch(aUnitType) { + case CSS_PX : + *aReturn = NSTwipsToFloatPixels(mTwips, mT2P); + break; + case CSS_CM : + *aReturn = NS_TWIPS_TO_CENTIMETERS(mTwips); + break; + case CSS_MM : + *aReturn = NS_TWIPS_TO_MILLIMETERS(mTwips); + break; + case CSS_IN : + *aReturn = NS_TWIPS_TO_INCHES(mTwips); + break; + case CSS_PT : + *aReturn = NSTwipsToFloatPoints(mTwips); + break; + case CSS_PC : + case CSS_UNKNOWN : + case CSS_NUMBER : + case CSS_PERCENTAGE : + case CSS_EMS : + case CSS_EXS : + case CSS_DEG : + case CSS_RAD : + case CSS_GRAD : + case CSS_MS : + case CSS_S : + case CSS_HZ : + case CSS_KHZ : + case CSS_DIMENSION : + case CSS_STRING : + case CSS_URI : + case CSS_IDENT : + case CSS_ATTR : + case CSS_COUNTER : + case CSS_RECT : + case CSS_RGBCOLOR : + return NS_ERROR_DOM_INVALID_ACCESS_ERR; + } + + return NS_OK; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::SetStringValue(PRUint16 aStringType, + const nsString& aStringValue) +{ + return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetStringValue(nsString& aReturn) +{ + aReturn = mString; + return NS_OK; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetCounterValue(nsIDOMCounter** aReturn) +{ + return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetRectValue(nsIDOMRect** aReturn) +{ + return NS_ERROR_DOM_NOT_SUPPORTED_ERR; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetRGBColorValue(nsIDOMRGBColor** aReturn) +{ + return NS_ERROR_DOM_NOT_SUPPORTED_ERR; +} + diff --git a/mozilla/layout/html/style/src/nsROCSSPrimitiveValue.h b/mozilla/layout/html/style/src/nsROCSSPrimitiveValue.h new file mode 100644 index 00000000000..b82d677725f --- /dev/null +++ b/mozilla/layout/html/style/src/nsROCSSPrimitiveValue.h @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/ + * + * 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 Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#ifndef nsROCSSPrimitiveValue_h___ +#define nsROCSSPrimitiveValue_h___ + +#include "nsIDOMCSSPrimitiveValue.h" +#include "nsCoord.h" +#include "nsUnitConversion.h" +#include "nsIScriptObjectOwner.h" + +#include "nsCOMPtr.h" +#include "nsDOMError.h" + + +class nsROCSSPrimitiveValue : public nsIDOMCSSPrimitiveValue, + public nsIScriptObjectOwner +{ +public: + NS_DECL_ISUPPORTS + + // nsIDOMCSSPrimitiveValue + NS_DECL_IDOMCSSPRIMITIVEVALUE + + // nsIDOMCSSValue + NS_DECL_IDOMCSSVALUE + + // nsIScriptObjectOwner + NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); + NS_IMETHOD SetScriptObject(void* aScriptObject); + + // nsROCSSPrimitiveValue + nsROCSSPrimitiveValue(nsISupports *aOwner, float aP2T); + virtual ~nsROCSSPrimitiveValue(); + + void SetTwips(nscoord aValue) + { + mTwips = aValue; + } + + void SetString(const char *aString) + { + mString.AssignWithConversion(aString); + mType = CSS_STRING; + } + +private: + PRUint16 mType; + + nscoord mTwips; + nsString mString; + + nsISupports *mOwner; + + float mT2P; + + void* mScriptObject; +}; + +#endif /* nsROCSSPrimitiveValue_h___ */ + diff --git a/mozilla/layout/style/nsROCSSPrimitiveValue.cpp b/mozilla/layout/style/nsROCSSPrimitiveValue.cpp new file mode 100644 index 00000000000..0a5c56a75be --- /dev/null +++ b/mozilla/layout/style/nsROCSSPrimitiveValue.cpp @@ -0,0 +1,217 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/ + * + * 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 Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsROCSSPrimitiveValue.h" + +#include "nsCOMPtr.h" +#include "nsDOMError.h" + + +nsROCSSPrimitiveValue::nsROCSSPrimitiveValue(nsISupports *aOwner, float aT2P) + : mType(0), mTwips(0), mString(), mOwner(aOwner), mT2P(aT2P) +{ + NS_INIT_REFCNT(); +} + + +nsROCSSPrimitiveValue::~nsROCSSPrimitiveValue() +{ +} + + +NS_IMPL_ADDREF(nsROCSSPrimitiveValue); +NS_IMPL_RELEASE(nsROCSSPrimitiveValue); + + +NS_INTERFACE_MAP_BEGIN(nsROCSSPrimitiveValue) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSPrimitiveValue) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValue) + NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMCSSPrimitiveValue) +NS_INTERFACE_MAP_END + + +// nsIScriptObjectOwner + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetScriptObject(nsIScriptContext *aContext, + void** aScriptObject) +{ + nsresult res = NS_OK; + + if (!mScriptObject) { + nsISupports *supports = NS_STATIC_CAST(nsIDOMCSSPrimitiveValue *, this); + + // XXX Should be done through factory + res = NS_NewScriptCSSPrimitiveValue(aContext, supports, mOwner, + &mScriptObject); + } + + *aScriptObject = mScriptObject; + + return res; +} + + +// nsIDOMCSSValue + +NS_IMETHODIMP +nsROCSSPrimitiveValue::SetScriptObject(void* aScriptObject) +{ + mScriptObject = aScriptObject; + return NS_OK; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetCssText(nsString& aCssText) +{ + aCssText.Truncate(); + return NS_ERROR_DOM_NOT_SUPPORTED_ERR; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::SetCssText(const nsString& aCssText) +{ + return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetValueType(PRUint16* aValueType) +{ + NS_ENSURE_ARG_POINTER(aValueType); + *aValueType = nsIDOMCSSValue::CSS_PRIMITIVE_VALUE; + return NS_OK; +} + + +// nsIDOMCSSPrimitiveValue + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetPrimitiveType(PRUint16* aPrimitiveType) +{ + NS_ENSURE_ARG_POINTER(aPrimitiveType); + *aPrimitiveType = mType; + + return NS_OK; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::SetFloatValue(PRUint16 aUnitType, float aFloatValue) +{ + return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetFloatValue(PRUint16 aUnitType, float* aReturn) +{ + NS_ENSURE_ARG_POINTER(aReturn); + *aReturn = 0; + + if (mType == CSS_STRING) { + return NS_ERROR_DOM_INVALID_ACCESS_ERR; + } + + switch(aUnitType) { + case CSS_PX : + *aReturn = NSTwipsToFloatPixels(mTwips, mT2P); + break; + case CSS_CM : + *aReturn = NS_TWIPS_TO_CENTIMETERS(mTwips); + break; + case CSS_MM : + *aReturn = NS_TWIPS_TO_MILLIMETERS(mTwips); + break; + case CSS_IN : + *aReturn = NS_TWIPS_TO_INCHES(mTwips); + break; + case CSS_PT : + *aReturn = NSTwipsToFloatPoints(mTwips); + break; + case CSS_PC : + case CSS_UNKNOWN : + case CSS_NUMBER : + case CSS_PERCENTAGE : + case CSS_EMS : + case CSS_EXS : + case CSS_DEG : + case CSS_RAD : + case CSS_GRAD : + case CSS_MS : + case CSS_S : + case CSS_HZ : + case CSS_KHZ : + case CSS_DIMENSION : + case CSS_STRING : + case CSS_URI : + case CSS_IDENT : + case CSS_ATTR : + case CSS_COUNTER : + case CSS_RECT : + case CSS_RGBCOLOR : + return NS_ERROR_DOM_INVALID_ACCESS_ERR; + } + + return NS_OK; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::SetStringValue(PRUint16 aStringType, + const nsString& aStringValue) +{ + return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetStringValue(nsString& aReturn) +{ + aReturn = mString; + return NS_OK; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetCounterValue(nsIDOMCounter** aReturn) +{ + return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetRectValue(nsIDOMRect** aReturn) +{ + return NS_ERROR_DOM_NOT_SUPPORTED_ERR; +} + + +NS_IMETHODIMP +nsROCSSPrimitiveValue::GetRGBColorValue(nsIDOMRGBColor** aReturn) +{ + return NS_ERROR_DOM_NOT_SUPPORTED_ERR; +} + diff --git a/mozilla/layout/style/nsROCSSPrimitiveValue.h b/mozilla/layout/style/nsROCSSPrimitiveValue.h new file mode 100644 index 00000000000..b82d677725f --- /dev/null +++ b/mozilla/layout/style/nsROCSSPrimitiveValue.h @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/ + * + * 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 Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#ifndef nsROCSSPrimitiveValue_h___ +#define nsROCSSPrimitiveValue_h___ + +#include "nsIDOMCSSPrimitiveValue.h" +#include "nsCoord.h" +#include "nsUnitConversion.h" +#include "nsIScriptObjectOwner.h" + +#include "nsCOMPtr.h" +#include "nsDOMError.h" + + +class nsROCSSPrimitiveValue : public nsIDOMCSSPrimitiveValue, + public nsIScriptObjectOwner +{ +public: + NS_DECL_ISUPPORTS + + // nsIDOMCSSPrimitiveValue + NS_DECL_IDOMCSSPRIMITIVEVALUE + + // nsIDOMCSSValue + NS_DECL_IDOMCSSVALUE + + // nsIScriptObjectOwner + NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); + NS_IMETHOD SetScriptObject(void* aScriptObject); + + // nsROCSSPrimitiveValue + nsROCSSPrimitiveValue(nsISupports *aOwner, float aP2T); + virtual ~nsROCSSPrimitiveValue(); + + void SetTwips(nscoord aValue) + { + mTwips = aValue; + } + + void SetString(const char *aString) + { + mString.AssignWithConversion(aString); + mType = CSS_STRING; + } + +private: + PRUint16 mType; + + nscoord mTwips; + nsString mString; + + nsISupports *mOwner; + + float mT2P; + + void* mScriptObject; +}; + +#endif /* nsROCSSPrimitiveValue_h___ */ +