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-09-25 04:51:45 +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-09-25 04:51:45 +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-09-25 04:51:45 +04:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client 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-09-25 04:51:45 +04:00
|
|
|
|
1998-10-06 05:39:33 +04:00
|
|
|
#include "nsDOMCSSDeclaration.h"
|
2000-04-20 17:50:56 +04:00
|
|
|
#include "nsIDOMCSSRule.h"
|
1998-09-25 04:51:45 +04:00
|
|
|
#include "nsICSSParser.h"
|
|
|
|
#include "nsIStyleRule.h"
|
2002-01-16 01:43:37 +03:00
|
|
|
#include "nsCSSDeclaration.h"
|
1998-09-25 04:51:45 +04:00
|
|
|
#include "nsCSSProps.h"
|
2000-04-20 17:50:56 +04:00
|
|
|
#include "nsCOMPtr.h"
|
1999-01-15 05:07:46 +03:00
|
|
|
#include "nsIURL.h"
|
1998-09-25 04:51:45 +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
|
|
|
#include "nsContentUtils.h"
|
|
|
|
|
|
|
|
|
1998-10-06 05:39:33 +04:00
|
|
|
nsDOMCSSDeclaration::nsDOMCSSDeclaration()
|
2002-10-03 23:41:42 +04:00
|
|
|
: mInner(nsnull)
|
1998-09-25 04:51:45 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-10-06 05:39:33 +04:00
|
|
|
nsDOMCSSDeclaration::~nsDOMCSSDeclaration()
|
1998-09-25 04:51:45 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-03 23:41:42 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMCSSDeclaration::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (!aInstancePtr) {
|
|
|
|
NS_ERROR("QueryInterface requires a non-NULL destination!");
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsISupports* inst;
|
|
|
|
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsIDOMCSSStyleDeclaration))) {
|
|
|
|
inst = NS_STATIC_CAST(nsIDOMCSSStyleDeclaration*, this);
|
|
|
|
} else if (aIID.Equals(NS_GET_IID(nsIDOMCSS2Properties))) {
|
|
|
|
if (!mInner) {
|
|
|
|
mInner = new CSS2PropertiesTearoff(this);
|
|
|
|
NS_ENSURE_TRUE(mInner, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
}
|
|
|
|
inst = NS_STATIC_CAST(nsIDOMCSS2Properties*,
|
|
|
|
NS_STATIC_CAST(nsISupports*, mInner));
|
|
|
|
} else if (aIID.Equals(NS_GET_IID(nsIDOMNSCSS2Properties))) {
|
|
|
|
if (!mInner) {
|
|
|
|
mInner = new CSS2PropertiesTearoff(this);
|
|
|
|
NS_ENSURE_TRUE(mInner, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
}
|
|
|
|
inst = NS_STATIC_CAST(nsIDOMNSCSS2Properties*,
|
|
|
|
NS_STATIC_CAST(nsISupports*, mInner));
|
|
|
|
} else if (aIID.Equals(NS_GET_IID(nsISupports))) {
|
|
|
|
inst = NS_STATIC_CAST(nsISupports*,
|
|
|
|
NS_STATIC_CAST(nsIDOMCSSStyleDeclaration*, this));
|
|
|
|
} else if (aIID.Equals(NS_GET_IID(nsIClassInfo))) {
|
|
|
|
inst = nsContentUtils::GetClassInfoInstance(eDOMClassInfo_CSSStyleDeclaration_id);
|
|
|
|
NS_ENSURE_TRUE(inst, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
} else {
|
|
|
|
inst = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
if (!inst) {
|
|
|
|
rv = NS_NOINTERFACE;
|
|
|
|
} else {
|
|
|
|
NS_ADDREF(inst);
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aInstancePtr = inst;
|
|
|
|
return rv;
|
|
|
|
}
|
1998-09-25 04:51:45 +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
|
|
|
NS_IMPL_ADDREF(nsDOMCSSDeclaration);
|
|
|
|
NS_IMPL_RELEASE(nsDOMCSSDeclaration);
|
|
|
|
|
1998-09-25 04:51:45 +04:00
|
|
|
|
2000-04-20 17:50:56 +04:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
nsDOMCSSDeclaration::GetCssText(nsAString& aCssText)
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration* decl;
|
2000-04-20 17:50:56 +04:00
|
|
|
aCssText.Truncate();
|
2002-01-16 01:43:37 +03:00
|
|
|
GetCSSDeclaration(&decl, PR_FALSE);
|
2001-05-15 12:25:03 +04:00
|
|
|
NS_ASSERTION(decl, "null CSSDeclaration");
|
|
|
|
|
|
|
|
if (decl) {
|
|
|
|
decl->ToString(aCssText);
|
|
|
|
}
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-04-20 17:50:56 +04:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
nsDOMCSSDeclaration::SetCssText(const nsAString& aCssText)
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
2001-12-15 07:33:11 +03:00
|
|
|
return ParseDeclaration(aCssText, PR_FALSE, PR_TRUE);
|
1998-11-26 04:34:53 +03:00
|
|
|
}
|
|
|
|
|
2000-04-20 17:50:56 +04:00
|
|
|
NS_IMETHODIMP
|
1998-10-06 05:39:33 +04:00
|
|
|
nsDOMCSSDeclaration::GetLength(PRUint32* aLength)
|
1998-09-25 04:51:45 +04:00
|
|
|
{
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration *decl;
|
1998-10-06 05:39:33 +04:00
|
|
|
nsresult result = GetCSSDeclaration(&decl, PR_FALSE);
|
1998-09-25 04:51:45 +04:00
|
|
|
|
|
|
|
*aLength = 0;
|
|
|
|
if ((NS_OK == result) && (nsnull != decl)) {
|
2002-01-16 01:43:37 +03:00
|
|
|
*aLength = decl->Count();
|
1998-09-25 04:51:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-04-20 17:50:56 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMCSSDeclaration::GetParentRule(nsIDOMCSSRule** aParentRule)
|
|
|
|
{
|
2000-07-12 06:15:27 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aParentRule);
|
|
|
|
*aParentRule = nsnull;
|
|
|
|
|
2000-04-20 17:50:56 +04:00
|
|
|
nsCOMPtr<nsISupports> parent;
|
|
|
|
|
|
|
|
GetParent(getter_AddRefs(parent));
|
|
|
|
|
|
|
|
if (parent) {
|
2002-12-11 17:24:49 +03:00
|
|
|
CallQueryInterface(parent, aParentRule);
|
2000-04-20 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
nsDOMCSSDeclaration::GetPropertyCSSValue(const nsAString& aPropertyName,
|
2000-04-20 17:50:56 +04:00
|
|
|
nsIDOMCSSValue** aReturn)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aReturn);
|
|
|
|
|
|
|
|
// We don't support CSSValue yet so we'll just return null...
|
|
|
|
*aReturn = nsnull;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
nsDOMCSSDeclaration::Item(PRUint32 aIndex, nsAString& aReturn)
|
1998-09-25 04:51:45 +04:00
|
|
|
{
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration *decl;
|
1998-10-06 05:39:33 +04:00
|
|
|
nsresult result = GetCSSDeclaration(&decl, PR_FALSE);
|
1998-09-25 04:51:45 +04:00
|
|
|
|
|
|
|
aReturn.SetLength(0);
|
|
|
|
if ((NS_OK == result) && (nsnull != decl)) {
|
|
|
|
result = decl->GetNthProperty(aIndex, aReturn);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
nsDOMCSSDeclaration::GetPropertyValue(const nsAString& aPropertyName,
|
|
|
|
nsAString& aReturn)
|
1998-09-25 04:51:45 +04:00
|
|
|
{
|
|
|
|
nsCSSValue val;
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration *decl;
|
1998-10-06 05:39:33 +04:00
|
|
|
nsresult result = GetCSSDeclaration(&decl, PR_FALSE);
|
1998-09-25 04:51:45 +04:00
|
|
|
|
|
|
|
aReturn.SetLength(0);
|
|
|
|
if ((NS_OK == result) && (nsnull != decl)) {
|
1998-09-30 05:09:19 +04:00
|
|
|
result = decl->GetValue(aPropertyName, aReturn);
|
1998-09-25 04:51:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
nsDOMCSSDeclaration::GetPropertyPriority(const nsAString& aPropertyName,
|
|
|
|
nsAString& aReturn)
|
1998-09-25 04:51:45 +04:00
|
|
|
{
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration *decl;
|
1998-10-06 05:39:33 +04:00
|
|
|
nsresult result = GetCSSDeclaration(&decl, PR_FALSE);
|
1998-09-25 04:51:45 +04:00
|
|
|
PRBool isImportant = PR_FALSE;
|
|
|
|
|
|
|
|
if ((NS_OK == result) && (nsnull != decl)) {
|
2002-01-16 01:43:37 +03:00
|
|
|
isImportant = decl->GetValueIsImportant(aPropertyName);
|
1998-09-25 04:51:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((NS_OK == result) && isImportant) {
|
2002-08-06 07:21:14 +04:00
|
|
|
aReturn.Assign(NS_LITERAL_STRING("important"));
|
1998-09-25 04:51:45 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
aReturn.SetLength(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
nsDOMCSSDeclaration::SetProperty(const nsAString& aPropertyName,
|
|
|
|
const nsAString& aValue,
|
|
|
|
const nsAString& aPriority)
|
1998-09-25 04:51:45 +04:00
|
|
|
{
|
2001-09-28 05:38:36 +04:00
|
|
|
if (aValue.IsEmpty()) {
|
2000-05-02 02:59:54 +04:00
|
|
|
// If the new value of the property is an empty string we remove the
|
|
|
|
// property.
|
|
|
|
nsAutoString tmp;
|
|
|
|
return RemoveProperty(aPropertyName, tmp);
|
|
|
|
}
|
|
|
|
|
2002-08-08 21:40:20 +04:00
|
|
|
if (aPriority.IsEmpty()) {
|
2002-10-03 23:41:42 +04:00
|
|
|
return ParsePropertyValue(aPropertyName, aValue);
|
2002-08-08 21:40:20 +04:00
|
|
|
}
|
2002-10-03 23:41:42 +04:00
|
|
|
|
2002-11-06 05:07:17 +03:00
|
|
|
// ParsePropertyValue does not handle priorities correctly -- it's
|
|
|
|
// optimized for speed. And the priority is not part of the
|
|
|
|
// property value anyway.... So we have to use the full-blown
|
|
|
|
// ParseDeclaration()
|
|
|
|
return ParseDeclaration(aPropertyName + NS_LITERAL_STRING(":") +
|
|
|
|
aValue + NS_LITERAL_STRING("!") + aPriority,
|
|
|
|
PR_TRUE, PR_FALSE);
|
1998-09-25 04:51:45 +04:00
|
|
|
}
|
|
|
|
|
2002-10-03 23:41:42 +04:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
CSS2PropertiesTearoff::CSS2PropertiesTearoff(nsISupports *aOuter)
|
2001-09-17 04:57:46 +04:00
|
|
|
{
|
2002-10-03 23:41:42 +04:00
|
|
|
NS_INIT_AGGREGATED(aOuter);
|
|
|
|
}
|
2001-09-28 05:38:36 +04:00
|
|
|
|
2002-10-03 23:41:42 +04:00
|
|
|
CSS2PropertiesTearoff::~CSS2PropertiesTearoff()
|
|
|
|
{
|
2001-09-17 04:57:46 +04:00
|
|
|
}
|
|
|
|
|
2002-10-03 23:41:42 +04:00
|
|
|
NS_IMPL_AGGREGATED(CSS2PropertiesTearoff);
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_AGGREGATED(CSS2PropertiesTearoff)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSS2Properties)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNSCSS2Properties)
|
|
|
|
NS_INTERFACE_MAP_END_AGGREGATED(fOuter)
|
2002-09-26 07:46:50 +04:00
|
|
|
|
|
|
|
|
2002-10-03 23:41:42 +04:00
|
|
|
// nsIDOMCSS2Properties
|
|
|
|
// nsIDOMNSCSS2Properties
|
|
|
|
|
|
|
|
#define CSS_PROP(name_, id_, method_, hint_) \
|
|
|
|
NS_IMETHODIMP \
|
|
|
|
CSS2PropertiesTearoff::Get##method_(nsAString& aValue) \
|
|
|
|
{ \
|
|
|
|
return NS_STATIC_CAST(nsIDOMCSSStyleDeclaration*, fOuter)-> \
|
|
|
|
GetPropertyValue(NS_LITERAL_STRING(#name_), aValue); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
NS_IMETHODIMP \
|
|
|
|
CSS2PropertiesTearoff::Set##method_(const nsAString& aValue) \
|
|
|
|
{ \
|
|
|
|
return NS_STATIC_CAST(nsIDOMCSSStyleDeclaration*, fOuter)-> \
|
2002-11-06 05:07:17 +03:00
|
|
|
SetProperty(NS_LITERAL_STRING(#name_), aValue, \
|
|
|
|
NS_LITERAL_STRING("")); \
|
2001-09-17 04:57:46 +04:00
|
|
|
}
|
1998-10-28 05:04:27 +03:00
|
|
|
|
2002-10-03 23:41:42 +04:00
|
|
|
#define CSS_PROP_INTERNAL(name_, id_, method_, hint_) /* nothing */
|
|
|
|
#define CSS_PROP_NOTIMPLEMENTED(name_, id_, method_, hint_) \
|
2002-09-26 07:46:50 +04:00
|
|
|
CSS_PROP(name_, id_, method_, hint_)
|
|
|
|
#include "nsCSSPropList.h"
|
|
|
|
#undef CSS_PROP_INTERNAL
|
|
|
|
#undef CSS_PROP
|