2002-01-16 01:43:37 +03: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
|
2002-01-16 01:43:37 +03: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/
|
2002-01-16 01:43:37 +03: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.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2002-01-16 01:43:37 +03:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2002-05-21 12:16:42 +04:00
|
|
|
* Daniel Glazman <glazman@netscape.com>
|
2002-01-16 01:43:37 +03:00
|
|
|
*
|
|
|
|
* 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"),
|
2002-01-16 01:43:37 +03: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
|
2002-01-16 01:43:37 +03: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.
|
2002-01-16 01:43:37 +03:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-03-25 08:47:31 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* representation of a declaration block (or style attribute) in a CSS
|
|
|
|
* stylesheet
|
|
|
|
*/
|
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
#ifndef nsCSSDeclaration_h___
|
|
|
|
#define nsCSSDeclaration_h___
|
|
|
|
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsColor.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCoord.h"
|
|
|
|
#include "nsCSSValue.h"
|
|
|
|
#include "nsCSSProps.h"
|
2007-03-23 02:01:14 +03:00
|
|
|
#include "nsValueArray.h"
|
2003-06-08 02:14:42 +04:00
|
|
|
#include "nsCSSDataBlock.h"
|
2003-04-15 07:07:34 +04:00
|
|
|
#include "nsCSSStruct.h"
|
2002-01-16 01:43:37 +03:00
|
|
|
|
|
|
|
class nsCSSDeclaration {
|
|
|
|
public:
|
2003-06-08 02:14:42 +04:00
|
|
|
/**
|
|
|
|
* Construct an |nsCSSDeclaration| that is in an invalid state (null
|
|
|
|
* |mData|) and cannot be used until its |CompressFrom| method or
|
|
|
|
* |InitializeEmpty| method is called.
|
|
|
|
*/
|
|
|
|
nsCSSDeclaration();
|
2002-01-16 01:43:37 +03:00
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
nsCSSDeclaration(const nsCSSDeclaration& aCopy);
|
2002-01-16 01:43:37 +03:00
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
/**
|
|
|
|
* |ValueAppended| must be called to maintain this declaration's
|
|
|
|
* |mOrder| whenever a property is parsed into an expanded data block
|
|
|
|
* for this declaration.
|
|
|
|
*/
|
|
|
|
nsresult ValueAppended(nsCSSProperty aProperty);
|
2002-01-16 01:43:37 +03:00
|
|
|
|
2002-03-24 01:56:05 +03:00
|
|
|
nsresult AppendComment(const nsAString& aComment);
|
2003-06-08 02:14:42 +04:00
|
|
|
nsresult RemoveProperty(nsCSSProperty aProperty);
|
|
|
|
|
|
|
|
nsresult GetValue(nsCSSProperty aProperty, nsAString& aValue) const;
|
|
|
|
nsresult GetValue(const nsAString& aProperty, nsAString& aValue) const;
|
2002-01-16 01:43:37 +03:00
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
PRBool HasImportantData() const { return mImportantData != nsnull; }
|
|
|
|
PRBool GetValueIsImportant(nsCSSProperty aProperty) const;
|
|
|
|
PRBool GetValueIsImportant(const nsAString& aProperty) const;
|
2002-01-16 01:43:37 +03:00
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
PRUint32 Count() const;
|
2003-06-08 02:14:42 +04:00
|
|
|
nsresult GetNthProperty(PRUint32 aIndex, nsAString& aReturn) const;
|
2002-01-16 01:43:37 +03:00
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
nsresult ToString(nsAString& aString) const;
|
2002-01-16 01:43:37 +03:00
|
|
|
|
|
|
|
nsCSSDeclaration* Clone() const;
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
nsresult MapRuleInfoInto(nsRuleData *aRuleData) const {
|
|
|
|
return mData->MapRuleInfoInto(aRuleData);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult MapImportantRuleInfoInto(nsRuleData *aRuleData) const {
|
|
|
|
return mImportantData->MapRuleInfoInto(aRuleData);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize this declaration as holding no data. Return false on
|
|
|
|
* out-of-memory.
|
|
|
|
*/
|
|
|
|
PRBool InitializeEmpty();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transfer all of the state from |aExpandedData| into this declaration.
|
|
|
|
* After calling, |aExpandedData| should be in its initial state.
|
|
|
|
*/
|
|
|
|
void CompressFrom(nsCSSExpandedDataBlock *aExpandedData) {
|
|
|
|
NS_ASSERTION(!mData, "oops");
|
|
|
|
NS_ASSERTION(!mImportantData, "oops");
|
|
|
|
aExpandedData->Compress(&mData, &mImportantData);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transfer all of the state from this declaration into
|
|
|
|
* |aExpandedData| and put this declaration temporarily into an
|
|
|
|
* invalid state (ended by |CompressFrom| or |InitializeEmpty|) that
|
|
|
|
* should last only during parsing. During this time only
|
|
|
|
* |ValueAppended| should be called.
|
|
|
|
*/
|
|
|
|
void ExpandTo(nsCSSExpandedDataBlock *aExpandedData) {
|
|
|
|
aExpandedData->AssertInitialState();
|
|
|
|
|
|
|
|
NS_ASSERTION(mData, "oops");
|
|
|
|
aExpandedData->Expand(&mData, &mImportantData);
|
|
|
|
NS_ASSERTION(!mData && !mImportantData,
|
|
|
|
"Expand didn't null things out");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the data, in preparation for its replacement with entirely
|
|
|
|
* new data by a call to |CompressFrom|.
|
|
|
|
*/
|
|
|
|
void ClearData() {
|
|
|
|
mData->Destroy();
|
|
|
|
mData = nsnull;
|
|
|
|
if (mImportantData) {
|
|
|
|
mImportantData->Destroy();
|
|
|
|
mImportantData = nsnull;
|
|
|
|
}
|
2005-04-29 00:19:24 +04:00
|
|
|
mOrder.Clear();
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
private:
|
2003-06-08 02:14:42 +04:00
|
|
|
// Not implemented, and not supported.
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration& operator=(const nsCSSDeclaration& aCopy);
|
|
|
|
PRBool operator==(const nsCSSDeclaration& aCopy) const;
|
|
|
|
|
2006-05-03 03:36:17 +04:00
|
|
|
static void AppendImportanceToString(PRBool aIsImportant, nsAString& aString);
|
2003-06-08 02:14:42 +04:00
|
|
|
// return whether there was a value in |aValue| (i.e., it had a non-null unit)
|
|
|
|
PRBool AppendValueToString(nsCSSProperty aProperty, nsAString& aResult) const;
|
|
|
|
// return whether there was a value in |aValue| (i.e., it had a non-null unit)
|
2006-05-03 03:36:17 +04:00
|
|
|
static PRBool AppendCSSValueToString(nsCSSProperty aProperty,
|
|
|
|
const nsCSSValue& aValue,
|
|
|
|
nsAString& aResult);
|
2003-06-08 02:14:42 +04:00
|
|
|
|
2003-12-29 22:17:22 +03:00
|
|
|
// May be called only for properties whose type is eCSSType_Value.
|
|
|
|
nsresult GetValueOrImportantValue(nsCSSProperty aProperty, nsCSSValue& aValue) const;
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
void PropertyIsSet(PRInt32 & aPropertyIndex, PRInt32 aIndex, PRUint32 & aSet, PRUint32 aValue) const;
|
2002-05-21 12:16:42 +04:00
|
|
|
PRBool TryBorderShorthand(nsAString & aString, PRUint32 aPropertiesSet,
|
|
|
|
PRInt32 aBorderTopWidth,
|
|
|
|
PRInt32 aBorderTopStyle,
|
|
|
|
PRInt32 aBorderTopColor,
|
|
|
|
PRInt32 aBorderBottomWidth,
|
|
|
|
PRInt32 aBorderBottomStyle,
|
|
|
|
PRInt32 aBorderBottomColor,
|
|
|
|
PRInt32 aBorderLeftWidth,
|
|
|
|
PRInt32 aBorderLeftStyle,
|
|
|
|
PRInt32 aBorderLeftColor,
|
|
|
|
PRInt32 aBorderRightWidth,
|
|
|
|
PRInt32 aBorderRightStyle,
|
2003-06-08 02:14:42 +04:00
|
|
|
PRInt32 aBorderRightColor) const;
|
2002-05-21 12:16:42 +04:00
|
|
|
PRBool TryBorderSideShorthand(nsAString & aString,
|
|
|
|
nsCSSProperty aShorthand,
|
|
|
|
PRInt32 aBorderWidth,
|
|
|
|
PRInt32 aBorderStyle,
|
2003-06-08 02:14:42 +04:00
|
|
|
PRInt32 aBorderColor) const;
|
2002-05-21 12:16:42 +04:00
|
|
|
PRBool TryFourSidesShorthand(nsAString & aString,
|
|
|
|
nsCSSProperty aShorthand,
|
|
|
|
PRInt32 & aTop,
|
|
|
|
PRInt32 & aBottom,
|
|
|
|
PRInt32 & aLeft,
|
|
|
|
PRInt32 & aRight,
|
2003-06-08 02:14:42 +04:00
|
|
|
PRBool aClearIndexes) const;
|
2002-03-24 01:56:05 +03:00
|
|
|
void TryBackgroundShorthand(nsAString & aString,
|
2002-01-16 01:43:37 +03:00
|
|
|
PRInt32 & aBgColor, PRInt32 & aBgImage,
|
|
|
|
PRInt32 & aBgRepeat, PRInt32 & aBgAttachment,
|
2007-04-16 02:25:20 +04:00
|
|
|
PRInt32 & aBgPosition) const;
|
2004-09-05 04:04:04 +04:00
|
|
|
void TryOverflowShorthand(nsAString & aString,
|
|
|
|
PRInt32 & aOverflowX, PRInt32 & aOverflowY) const;
|
2004-12-09 06:16:15 +03:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
void TryMarkerShorthand(nsAString & aString,
|
|
|
|
PRInt32 & aMarkerEnd,
|
|
|
|
PRInt32 & aMarkerMid,
|
|
|
|
PRInt32 & aMarkerStart) const;
|
|
|
|
#endif
|
2002-01-16 01:43:37 +03:00
|
|
|
|
2002-05-21 12:16:42 +04:00
|
|
|
PRBool AllPropertiesSameImportance(PRInt32 aFirst, PRInt32 aSecond,
|
|
|
|
PRInt32 aThird, PRInt32 aFourth,
|
2007-04-16 02:25:20 +04:00
|
|
|
PRInt32 aFifth,
|
2003-06-08 02:14:42 +04:00
|
|
|
PRBool & aImportance) const;
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool AllPropertiesSameValue(PRInt32 aFirst, PRInt32 aSecond,
|
2003-06-08 02:14:42 +04:00
|
|
|
PRInt32 aThird, PRInt32 aFourth) const;
|
2002-01-16 01:43:37 +03:00
|
|
|
void AppendPropertyAndValueToString(nsCSSProperty aProperty,
|
2004-02-05 03:19:19 +03:00
|
|
|
nsAString& aResult) const
|
|
|
|
{
|
|
|
|
AppendPropertyAndValueToString(aProperty, aProperty, aResult);
|
|
|
|
}
|
|
|
|
void AppendPropertyAndValueToString(nsCSSProperty aProperty,
|
|
|
|
nsCSSProperty aPropertyName,
|
2003-06-08 02:14:42 +04:00
|
|
|
nsAString& aResult) const;
|
2002-01-16 01:43:37 +03:00
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
private:
|
2002-01-16 01:43:37 +03:00
|
|
|
//
|
|
|
|
// Specialized ref counting.
|
|
|
|
// We do not want everyone to ref count us, only the rules which hold
|
|
|
|
// onto us (our well defined lifetime is when the last rule releases
|
|
|
|
// us).
|
|
|
|
// It's worth a comment here that the main nsCSSDeclaration is refcounted,
|
|
|
|
// but it's |mImportant| is not refcounted, but just owned by the
|
|
|
|
// non-important declaration.
|
|
|
|
//
|
|
|
|
friend class CSSStyleRuleImpl;
|
|
|
|
void AddRef(void) {
|
2003-06-08 02:14:42 +04:00
|
|
|
++mRefCnt;
|
2002-01-16 01:43:37 +03:00
|
|
|
}
|
|
|
|
void Release(void) {
|
2003-06-08 02:14:42 +04:00
|
|
|
NS_ASSERTION(0 < mRefCnt, "bad Release");
|
|
|
|
if (0 == --mRefCnt) {
|
2002-01-16 01:43:37 +03:00
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
void RuleAbort(void) {
|
2003-06-08 02:14:42 +04:00
|
|
|
NS_ASSERTION(0 == mRefCnt, "bad RuleAbort");
|
2002-01-16 01:43:37 +03:00
|
|
|
delete this;
|
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
private:
|
|
|
|
// Block everyone, except us or a derivative, from deleting us.
|
2002-01-16 01:43:37 +03:00
|
|
|
~nsCSSDeclaration(void);
|
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
nsCSSProperty OrderValueAt(nsValueArrayIndex aValue) const {
|
|
|
|
return nsCSSProperty(mOrder.ValueAt(aValue));
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
2002-01-16 01:43:37 +03:00
|
|
|
|
|
|
|
private:
|
2007-03-23 02:01:14 +03:00
|
|
|
nsValueArray mOrder;
|
2003-06-08 02:14:42 +04:00
|
|
|
nsAutoRefCnt mRefCnt;
|
|
|
|
nsCSSCompressedDataBlock *mData; // never null, except while expanded
|
|
|
|
nsCSSCompressedDataBlock *mImportantData; // may be null
|
2002-01-16 01:43:37 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsCSSDeclaration_h___ */
|