зеркало из https://github.com/mozilla/pjs.git
use nsAutoTArray for nsCSSDeclaration::mOrder. b=410357, r+sr=dbaron, a=blocking1.9+
This commit is contained in:
Родитель
a51b91421c
Коммит
314e31edd2
|
@ -43,6 +43,7 @@
|
|||
*/
|
||||
|
||||
#include "nscore.h"
|
||||
#include "prlog.h"
|
||||
#include "nsCSSDeclaration.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIAtom.h"
|
||||
|
@ -83,21 +84,23 @@
|
|||
#define B_BORDER 0xfff
|
||||
|
||||
nsCSSDeclaration::nsCSSDeclaration()
|
||||
: mOrder(eCSSProperty_COUNT_no_shorthands, 8),
|
||||
mData(nsnull),
|
||||
: mData(nsnull),
|
||||
mImportantData(nsnull)
|
||||
{
|
||||
// check that we can fit all the CSS properties into a PRUint8
|
||||
// for the mOrder array - if not, might need to use PRUint16!
|
||||
PR_STATIC_ASSERT(eCSSProperty_COUNT_no_shorthands - 1 <= PR_UINT8_MAX);
|
||||
|
||||
MOZ_COUNT_CTOR(nsCSSDeclaration);
|
||||
}
|
||||
|
||||
nsCSSDeclaration::nsCSSDeclaration(const nsCSSDeclaration& aCopy)
|
||||
: mOrder(eCSSProperty_COUNT_no_shorthands, aCopy.mOrder.Count()),
|
||||
: mOrder(aCopy.mOrder),
|
||||
mData(aCopy.mData ? aCopy.mData->Clone() : nsnull),
|
||||
mImportantData(aCopy.mImportantData ? aCopy.mImportantData->Clone()
|
||||
: nsnull)
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsCSSDeclaration);
|
||||
mOrder = aCopy.mOrder;
|
||||
}
|
||||
|
||||
nsCSSDeclaration::~nsCSSDeclaration(void)
|
||||
|
@ -118,12 +121,12 @@ nsCSSDeclaration::ValueAppended(nsCSSProperty aProperty)
|
|||
// order IS important for CSS, so remove and add to the end
|
||||
if (nsCSSProps::IsShorthand(aProperty)) {
|
||||
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty) {
|
||||
mOrder.RemoveValue(*p);
|
||||
mOrder.AppendValue(*p);
|
||||
mOrder.RemoveElement(*p);
|
||||
mOrder.AppendElement(*p);
|
||||
}
|
||||
} else {
|
||||
mOrder.RemoveValue(aProperty);
|
||||
mOrder.AppendValue(aProperty);
|
||||
mOrder.RemoveElement(aProperty);
|
||||
mOrder.AppendElement(aProperty);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -138,11 +141,11 @@ nsCSSDeclaration::RemoveProperty(nsCSSProperty aProperty)
|
|||
if (nsCSSProps::IsShorthand(aProperty)) {
|
||||
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty) {
|
||||
data.ClearProperty(*p);
|
||||
mOrder.RemoveValue(*p);
|
||||
mOrder.RemoveElement(*p);
|
||||
}
|
||||
} else {
|
||||
data.ClearProperty(aProperty);
|
||||
mOrder.RemoveValue(aProperty);
|
||||
mOrder.RemoveElement(aProperty);
|
||||
}
|
||||
|
||||
data.Compress(&mData, &mImportantData);
|
||||
|
@ -1114,7 +1117,7 @@ void nsCSSDeclaration::PropertyIsSet(PRInt32 & aPropertyIndex, PRInt32 aIndex, P
|
|||
nsresult
|
||||
nsCSSDeclaration::ToString(nsAString& aString) const
|
||||
{
|
||||
PRInt32 count = mOrder.Count();
|
||||
PRInt32 count = mOrder.Length();
|
||||
PRInt32 index;
|
||||
// 0 means not in the mOrder array; otherwise it's index+1
|
||||
PRInt32 borderTopWidth = 0, borderTopStyle = 0, borderTopColor = 0;
|
||||
|
@ -1445,17 +1448,11 @@ void nsCSSDeclaration::List(FILE* out, PRInt32 aIndent) const
|
|||
}
|
||||
#endif
|
||||
|
||||
PRUint32
|
||||
nsCSSDeclaration::Count() const
|
||||
{
|
||||
return (PRUint32)mOrder.Count();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsCSSDeclaration::GetNthProperty(PRUint32 aIndex, nsAString& aReturn) const
|
||||
{
|
||||
aReturn.Truncate();
|
||||
if (aIndex < (PRUint32)mOrder.Count()) {
|
||||
if (aIndex < mOrder.Length()) {
|
||||
nsCSSProperty property = OrderValueAt(aIndex);
|
||||
if (0 <= property) {
|
||||
AppendASCIItoUTF16(nsCSSProps::GetStringValue(property), aReturn);
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
#include "nsCoord.h"
|
||||
#include "nsCSSValue.h"
|
||||
#include "nsCSSProps.h"
|
||||
#include "nsValueArray.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsCSSDataBlock.h"
|
||||
#include "nsCSSStruct.h"
|
||||
|
||||
|
@ -83,7 +83,9 @@ public:
|
|||
PRBool GetValueIsImportant(nsCSSProperty aProperty) const;
|
||||
PRBool GetValueIsImportant(const nsAString& aProperty) const;
|
||||
|
||||
PRUint32 Count() const;
|
||||
PRUint32 Count() const {
|
||||
return mOrder.Length();
|
||||
}
|
||||
nsresult GetNthProperty(PRUint32 aIndex, nsAString& aReturn) const;
|
||||
|
||||
nsresult ToString(nsAString& aString) const;
|
||||
|
@ -247,12 +249,12 @@ private:
|
|||
// Block everyone, except us or a derivative, from deleting us.
|
||||
~nsCSSDeclaration(void);
|
||||
|
||||
nsCSSProperty OrderValueAt(nsValueArrayIndex aValue) const {
|
||||
return nsCSSProperty(mOrder.ValueAt(aValue));
|
||||
nsCSSProperty OrderValueAt(PRUint32 aValue) const {
|
||||
return nsCSSProperty(mOrder.ElementAt(aValue));
|
||||
}
|
||||
|
||||
private:
|
||||
nsValueArray mOrder;
|
||||
nsAutoTArray<PRUint8, 8> mOrder;
|
||||
nsAutoRefCnt mRefCnt;
|
||||
nsCSSCompressedDataBlock *mData; // never null, except while expanded
|
||||
nsCSSCompressedDataBlock *mImportantData; // may be null
|
||||
|
|
Загрузка…
Ссылка в новой задаче