2004-09-10 07:26:58 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2003-06-08 02:14:42 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* 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/
|
|
|
|
*
|
|
|
|
* 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 nsCSSDataBlock.cpp.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is L. David Baron.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2003
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* L. David Baron <dbaron@dbaron.org> (original author)
|
|
|
|
*
|
|
|
|
* 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 MPL, 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 MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2006-03-25 08:47:31 +03:00
|
|
|
/*
|
|
|
|
* compact representation of the property-value pairs within a CSS
|
|
|
|
* declaration, and the code for expanding and compacting it
|
|
|
|
*/
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
#include "nsCSSDataBlock.h"
|
|
|
|
#include "nsCSSProps.h"
|
2004-07-20 10:11:27 +04:00
|
|
|
#include "nsRuleData.h"
|
2007-04-28 20:01:24 +04:00
|
|
|
#include "nsRuleNode.h"
|
2007-05-17 01:10:31 +04:00
|
|
|
#include "nsStyleSet.h"
|
2010-04-06 23:42:41 +04:00
|
|
|
#include "nsStyleContext.h"
|
2003-06-08 02:14:42 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* nsCSSCompressedDataBlock holds property-value pairs corresponding to
|
2008-08-05 02:15:11 +04:00
|
|
|
* CSS declaration blocks. The value is stored in one of the five CSS
|
|
|
|
* data types: nsCSSValue, nsCSSRect, nsCSSValueList, nsCSSValuePair,
|
|
|
|
* and nsCSSValuePairList, which each correspond to a value of the
|
|
|
|
* nsCSSType enumeration.
|
2003-06-08 02:14:42 +04:00
|
|
|
*
|
|
|
|
* The storage strategy uses the CDB*Storage structs below to help
|
|
|
|
* ensure that all the types remain properly aligned. nsCSSValue's
|
|
|
|
* alignment requirements cannot be weaker than any others, since it
|
|
|
|
* contains a pointer and an enumeration.
|
|
|
|
*
|
|
|
|
* The simple types, nsCSSValue and nsCSSRect have the nsCSSValue or
|
|
|
|
* nsCSSRect objects stored in the block. The list types have only a
|
|
|
|
* pointer to the first element in the list stored in the block.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct CDBValueStorage {
|
|
|
|
nsCSSProperty property;
|
|
|
|
nsCSSValue value;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CDBRectStorage {
|
|
|
|
nsCSSProperty property;
|
|
|
|
nsCSSRect value;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2004-09-10 07:26:58 +04:00
|
|
|
struct CDBValuePairStorage {
|
|
|
|
nsCSSProperty property;
|
|
|
|
nsCSSValuePair value;
|
|
|
|
};
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
struct CDBPointerStorage {
|
|
|
|
nsCSSProperty property;
|
|
|
|
void *value;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
CDBValueStorage_advance = sizeof(CDBValueStorage),
|
|
|
|
CDBRectStorage_advance = sizeof(CDBRectStorage),
|
2004-09-10 07:26:58 +04:00
|
|
|
CDBValuePairStorage_advance = sizeof(CDBValuePairStorage),
|
2003-06-08 02:14:42 +04:00
|
|
|
// round up using the closest estimate we can get of the alignment
|
|
|
|
// requirements of nsCSSValue:
|
|
|
|
CDBPointerStorage_advance = PR_ROUNDUP(sizeof(CDBPointerStorage),
|
|
|
|
sizeof(CDBValueStorage) - sizeof(nsCSSValue))
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define a bunch of utility functions for getting the property or any
|
|
|
|
* of the value types when the cursor is at the beginning of the storage
|
|
|
|
* for the property-value pair. The versions taking a non-const cursor
|
|
|
|
* argument return a reference so that the caller can assign into the
|
|
|
|
* result.
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline nsCSSProperty& PropertyAtCursor(char *aCursor) {
|
2007-07-08 11:08:04 +04:00
|
|
|
return *reinterpret_cast<nsCSSProperty*>(aCursor);
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline nsCSSProperty PropertyAtCursor(const char *aCursor) {
|
2007-07-08 11:08:04 +04:00
|
|
|
return *reinterpret_cast<const nsCSSProperty*>(aCursor);
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline nsCSSValue* ValueAtCursor(char *aCursor) {
|
2007-07-08 11:08:04 +04:00
|
|
|
return & reinterpret_cast<CDBValueStorage*>(aCursor)->value;
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline const nsCSSValue* ValueAtCursor(const char *aCursor) {
|
2007-07-08 11:08:04 +04:00
|
|
|
return & reinterpret_cast<const CDBValueStorage*>(aCursor)->value;
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline nsCSSRect* RectAtCursor(char *aCursor) {
|
2007-07-08 11:08:04 +04:00
|
|
|
return & reinterpret_cast<CDBRectStorage*>(aCursor)->value;
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline const nsCSSRect* RectAtCursor(const char *aCursor) {
|
2007-07-08 11:08:04 +04:00
|
|
|
return & reinterpret_cast<const CDBRectStorage*>(aCursor)->value;
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
2004-09-10 07:26:58 +04:00
|
|
|
inline nsCSSValuePair* ValuePairAtCursor(char *aCursor) {
|
2007-07-08 11:08:04 +04:00
|
|
|
return & reinterpret_cast<CDBValuePairStorage*>(aCursor)->value;
|
2004-09-10 07:26:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline const nsCSSValuePair* ValuePairAtCursor(const char *aCursor) {
|
2007-07-08 11:08:04 +04:00
|
|
|
return & reinterpret_cast<const CDBValuePairStorage*>(aCursor)->value;
|
2004-09-10 07:26:58 +04:00
|
|
|
}
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
inline void*& PointerAtCursor(char *aCursor) {
|
2007-07-08 11:08:04 +04:00
|
|
|
return reinterpret_cast<CDBPointerStorage*>(aCursor)->value;
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void* PointerAtCursor(const char *aCursor) {
|
2007-07-08 11:08:04 +04:00
|
|
|
return reinterpret_cast<const CDBPointerStorage*>(aCursor)->value;
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline nsCSSValueList*& ValueListAtCursor(char *aCursor) {
|
2007-07-08 11:08:04 +04:00
|
|
|
return * reinterpret_cast<nsCSSValueList**>
|
|
|
|
(& reinterpret_cast<CDBPointerStorage*>(aCursor)->value);
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline nsCSSValueList* ValueListAtCursor(const char *aCursor) {
|
2007-07-08 11:08:04 +04:00
|
|
|
return static_cast<nsCSSValueList*>
|
|
|
|
(reinterpret_cast<const CDBPointerStorage*>(aCursor)->value);
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
2008-08-05 02:15:11 +04:00
|
|
|
inline nsCSSValuePairList*& ValuePairListAtCursor(char *aCursor) {
|
|
|
|
return * reinterpret_cast<nsCSSValuePairList**>
|
2007-07-08 11:08:04 +04:00
|
|
|
(& reinterpret_cast<CDBPointerStorage*>(aCursor)->value);
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
2008-08-05 02:15:11 +04:00
|
|
|
inline nsCSSValuePairList* ValuePairListAtCursor(const char *aCursor) {
|
|
|
|
return static_cast<nsCSSValuePairList*>
|
2007-07-08 11:08:04 +04:00
|
|
|
(reinterpret_cast<const CDBPointerStorage*>(aCursor)->value);
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
2007-05-17 01:10:31 +04:00
|
|
|
static PRBool
|
|
|
|
ShouldIgnoreColors(nsRuleData *aRuleData)
|
|
|
|
{
|
|
|
|
return aRuleData->mLevel != nsStyleSet::eAgentSheet &&
|
|
|
|
aRuleData->mLevel != nsStyleSet::eUserSheet &&
|
2007-11-16 06:46:42 +03:00
|
|
|
!aRuleData->mPresContext->UseDocumentColors();
|
2007-05-17 01:10:31 +04:00
|
|
|
}
|
|
|
|
|
2009-08-22 00:39:25 +04:00
|
|
|
/**
|
|
|
|
* Tries to call |nsCSSValue::StartImageLoad()| on an image source.
|
|
|
|
* Image sources are specified by |url()| or |-moz-image-rect()| function.
|
|
|
|
*/
|
|
|
|
static void
|
2009-11-15 06:16:59 +03:00
|
|
|
TryToStartImageLoadOnValue(const nsCSSValue& aValue, nsIDocument* aDocument)
|
2009-08-22 00:39:25 +04:00
|
|
|
{
|
|
|
|
if (aValue.GetUnit() == eCSSUnit_URL) {
|
|
|
|
aValue.StartImageLoad(aDocument);
|
|
|
|
}
|
|
|
|
else if (aValue.EqualsFunction(eCSSKeyword__moz_image_rect)) {
|
|
|
|
nsCSSValue::Array* arguments = aValue.GetArrayValue();
|
|
|
|
NS_ABORT_IF_FALSE(arguments->Count() == 6, "unexpected num of arguments");
|
|
|
|
|
|
|
|
const nsCSSValue& image = arguments->Item(1);
|
|
|
|
if (image.GetUnit() == eCSSUnit_URL)
|
|
|
|
image.StartImageLoad(aDocument);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-15 06:16:59 +03:00
|
|
|
static void
|
|
|
|
TryToStartImageLoad(const nsCSSValue& aValue, nsIDocument* aDocument,
|
|
|
|
nsCSSProperty aProperty)
|
|
|
|
{
|
|
|
|
if (nsCSSProps::PropHasFlags(aProperty, CSS_PROPERTY_IMAGE_IS_IN_ARRAY_0)) {
|
|
|
|
if (aValue.GetUnit() == eCSSUnit_Array) {
|
|
|
|
TryToStartImageLoadOnValue(aValue.GetArrayValue()->Item(0), aDocument);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
TryToStartImageLoadOnValue(aValue, aDocument);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-06 23:42:41 +04:00
|
|
|
static inline PRBool
|
|
|
|
ShouldStartImageLoads(nsRuleData *aRuleData, nsCSSProperty aProperty)
|
|
|
|
{
|
|
|
|
// Don't initiate image loads for if-visited styles. This is
|
|
|
|
// important because:
|
|
|
|
// (1) it's a waste of CPU and bandwidth
|
|
|
|
// (2) in some cases we'd start the image load on a style change
|
|
|
|
// where we wouldn't have started the load initially, which makes
|
|
|
|
// which links are visited detectable to Web pages (see bug
|
|
|
|
// 557287)
|
|
|
|
return !aRuleData->mStyleContext->IsStyleIfVisited() &&
|
|
|
|
nsCSSProps::PropHasFlags(aProperty, CSS_PROPERTY_START_IMAGE_LOADS);
|
|
|
|
}
|
|
|
|
|
2010-05-20 06:28:00 +04:00
|
|
|
void
|
2003-06-08 02:14:42 +04:00
|
|
|
nsCSSCompressedDataBlock::MapRuleInfoInto(nsRuleData *aRuleData) const
|
|
|
|
{
|
2007-10-09 01:58:22 +04:00
|
|
|
// If we have no data for these structs, then return immediately.
|
2003-06-08 02:14:42 +04:00
|
|
|
// This optimization should make us return most of the time, so we
|
|
|
|
// have to worry much less (although still some) about the speed of
|
|
|
|
// the rest of the function.
|
2007-10-09 01:58:22 +04:00
|
|
|
if (!(aRuleData->mSIDs & mStyleBits))
|
2010-05-20 06:28:00 +04:00
|
|
|
return;
|
2003-06-08 02:14:42 +04:00
|
|
|
|
2009-08-22 00:39:25 +04:00
|
|
|
nsIDocument* doc = aRuleData->mPresContext->Document();
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
const char* cursor = Block();
|
|
|
|
const char* cursor_end = BlockEnd();
|
|
|
|
while (cursor < cursor_end) {
|
|
|
|
nsCSSProperty iProp = PropertyAtCursor(cursor);
|
|
|
|
NS_ASSERTION(0 <= iProp && iProp < eCSSProperty_COUNT_no_shorthands,
|
|
|
|
"out of range");
|
2007-10-09 01:58:22 +04:00
|
|
|
if (nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[iProp]) &
|
|
|
|
aRuleData->mSIDs) {
|
2003-06-08 02:14:42 +04:00
|
|
|
void *prop =
|
|
|
|
nsCSSExpandedDataBlock::RuleDataPropertyAt(aRuleData, iProp);
|
|
|
|
switch (nsCSSProps::kTypeTable[iProp]) {
|
|
|
|
case eCSSType_Value: {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsCSSValue* target = static_cast<nsCSSValue*>(prop);
|
2003-06-08 02:14:42 +04:00
|
|
|
if (target->GetUnit() == eCSSUnit_Null) {
|
|
|
|
const nsCSSValue *val = ValueAtCursor(cursor);
|
|
|
|
NS_ASSERTION(val->GetUnit() != eCSSUnit_Null, "oops");
|
2010-04-06 23:42:41 +04:00
|
|
|
if (ShouldStartImageLoads(aRuleData, iProp)) {
|
2009-11-15 06:16:59 +03:00
|
|
|
TryToStartImageLoad(*val, doc, iProp);
|
2004-03-09 06:57:51 +03:00
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
*target = *val;
|
|
|
|
if (iProp == eCSSProperty_font_family) {
|
|
|
|
// XXX Are there other things like this?
|
|
|
|
aRuleData->mFontData->mFamilyFromHTML = PR_FALSE;
|
|
|
|
}
|
2009-07-16 04:24:24 +04:00
|
|
|
if (nsCSSProps::PropHasFlags(iProp,
|
|
|
|
CSS_PROPERTY_IGNORED_WHEN_COLORS_DISABLED) &&
|
|
|
|
ShouldIgnoreColors(aRuleData))
|
|
|
|
{
|
|
|
|
if (iProp == eCSSProperty_background_color) {
|
|
|
|
// Force non-'transparent' background
|
|
|
|
// colors to the user's default.
|
|
|
|
if (target->IsNonTransparentColor()) {
|
|
|
|
target->SetColorValue(aRuleData->
|
|
|
|
mPresContext->
|
|
|
|
DefaultBackgroundColor());
|
2009-06-16 19:00:20 +04:00
|
|
|
}
|
2009-07-16 04:24:24 +04:00
|
|
|
} else {
|
|
|
|
// Ignore 'color', 'border-*-color', etc.
|
|
|
|
*target = nsCSSValue();
|
2007-05-17 01:10:31 +04:00
|
|
|
}
|
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
cursor += CDBValueStorage_advance;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case eCSSType_Rect: {
|
2009-07-16 04:24:24 +04:00
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::PropHasFlags(iProp,
|
|
|
|
CSS_PROPERTY_IGNORED_WHEN_COLORS_DISABLED),
|
|
|
|
"this case needs to handle color properties");
|
2003-06-08 02:14:42 +04:00
|
|
|
const nsCSSRect* val = RectAtCursor(cursor);
|
2004-05-05 04:43:50 +04:00
|
|
|
NS_ASSERTION(val->HasValue(), "oops");
|
2007-07-08 11:08:04 +04:00
|
|
|
nsCSSRect* target = static_cast<nsCSSRect*>(prop);
|
2003-06-08 02:14:42 +04:00
|
|
|
if (target->mTop.GetUnit() == eCSSUnit_Null)
|
|
|
|
target->mTop = val->mTop;
|
|
|
|
if (target->mRight.GetUnit() == eCSSUnit_Null)
|
|
|
|
target->mRight = val->mRight;
|
|
|
|
if (target->mBottom.GetUnit() == eCSSUnit_Null)
|
|
|
|
target->mBottom = val->mBottom;
|
|
|
|
if (target->mLeft.GetUnit() == eCSSUnit_Null)
|
|
|
|
target->mLeft = val->mLeft;
|
|
|
|
cursor += CDBRectStorage_advance;
|
|
|
|
} break;
|
|
|
|
|
2004-09-10 07:26:58 +04:00
|
|
|
case eCSSType_ValuePair: {
|
2009-07-16 04:24:24 +04:00
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::PropHasFlags(iProp,
|
|
|
|
CSS_PROPERTY_IGNORED_WHEN_COLORS_DISABLED),
|
|
|
|
"this case needs to handle color properties");
|
2004-09-10 07:26:58 +04:00
|
|
|
const nsCSSValuePair* val = ValuePairAtCursor(cursor);
|
|
|
|
NS_ASSERTION(val->mXValue.GetUnit() != eCSSUnit_Null ||
|
|
|
|
val->mYValue.GetUnit() != eCSSUnit_Null, "oops");
|
2007-07-08 11:08:04 +04:00
|
|
|
nsCSSValuePair* target = static_cast<nsCSSValuePair*>(prop);
|
2009-02-20 08:29:21 +03:00
|
|
|
NS_ASSERTION((target->mXValue.GetUnit() == eCSSUnit_Null)
|
|
|
|
== (target->mYValue.GetUnit() == eCSSUnit_Null),
|
|
|
|
"half a property?");
|
|
|
|
if (target->mXValue.GetUnit() == eCSSUnit_Null) {
|
2004-09-10 07:26:58 +04:00
|
|
|
target->mXValue = val->mXValue;
|
|
|
|
target->mYValue = val->mYValue;
|
2009-02-20 08:29:21 +03:00
|
|
|
}
|
2004-09-10 07:26:58 +04:00
|
|
|
cursor += CDBValuePairStorage_advance;
|
|
|
|
} break;
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
case eCSSType_ValueList:
|
2008-08-05 02:15:11 +04:00
|
|
|
case eCSSType_ValuePairList: {
|
2007-07-08 11:08:04 +04:00
|
|
|
void** target = static_cast<void**>(prop);
|
2003-06-08 02:14:42 +04:00
|
|
|
if (!*target) {
|
2010-04-06 23:42:41 +04:00
|
|
|
if (ShouldStartImageLoads(aRuleData, iProp)) {
|
2009-11-15 06:16:59 +03:00
|
|
|
for (nsCSSValueList* l = ValueListAtCursor(cursor);
|
|
|
|
l; l = l->mNext) {
|
2009-11-15 06:16:59 +03:00
|
|
|
TryToStartImageLoad(l->mValue, doc, iProp);
|
2009-11-15 06:16:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
void* val = PointerAtCursor(cursor);
|
|
|
|
NS_ASSERTION(val, "oops");
|
|
|
|
*target = val;
|
2007-05-17 01:10:31 +04:00
|
|
|
|
2009-07-16 04:24:24 +04:00
|
|
|
if (nsCSSProps::PropHasFlags(iProp,
|
|
|
|
CSS_PROPERTY_IGNORED_WHEN_COLORS_DISABLED) &&
|
|
|
|
ShouldIgnoreColors(aRuleData))
|
|
|
|
{
|
|
|
|
*target = nsnull;
|
2007-05-17 01:10:31 +04:00
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
cursor += CDBPointerStorage_advance;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (nsCSSProps::kTypeTable[iProp]) {
|
|
|
|
case eCSSType_Value: {
|
|
|
|
cursor += CDBValueStorage_advance;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case eCSSType_Rect: {
|
|
|
|
cursor += CDBRectStorage_advance;
|
|
|
|
} break;
|
|
|
|
|
2004-09-10 07:26:58 +04:00
|
|
|
case eCSSType_ValuePair: {
|
|
|
|
cursor += CDBValuePairStorage_advance;
|
|
|
|
} break;
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
case eCSSType_ValueList:
|
2008-08-05 02:15:11 +04:00
|
|
|
case eCSSType_ValuePairList: {
|
2003-06-08 02:14:42 +04:00
|
|
|
cursor += CDBPointerStorage_advance;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(cursor == cursor_end, "inconsistent data");
|
|
|
|
}
|
|
|
|
|
|
|
|
const void*
|
|
|
|
nsCSSCompressedDataBlock::StorageFor(nsCSSProperty aProperty) const
|
|
|
|
{
|
2009-07-10 01:50:39 +04:00
|
|
|
NS_PRECONDITION(!nsCSSProps::IsShorthand(aProperty),
|
|
|
|
"Don't call for shorthands");
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
// If we have no data for this struct, then return immediately.
|
|
|
|
// This optimization should make us return most of the time, so we
|
|
|
|
// have to worry much less (although still some) about the speed of
|
|
|
|
// the rest of the function.
|
|
|
|
if (!(nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[aProperty]) &
|
|
|
|
mStyleBits))
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
const char* cursor = Block();
|
|
|
|
const char* cursor_end = BlockEnd();
|
|
|
|
while (cursor < cursor_end) {
|
|
|
|
nsCSSProperty iProp = PropertyAtCursor(cursor);
|
|
|
|
NS_ASSERTION(0 <= iProp && iProp < eCSSProperty_COUNT_no_shorthands,
|
|
|
|
"out of range");
|
|
|
|
if (iProp == aProperty) {
|
|
|
|
switch (nsCSSProps::kTypeTable[iProp]) {
|
|
|
|
case eCSSType_Value: {
|
|
|
|
return ValueAtCursor(cursor);
|
|
|
|
}
|
|
|
|
case eCSSType_Rect: {
|
|
|
|
return RectAtCursor(cursor);
|
|
|
|
}
|
2004-09-10 07:26:58 +04:00
|
|
|
case eCSSType_ValuePair: {
|
|
|
|
return ValuePairAtCursor(cursor);
|
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
case eCSSType_ValueList:
|
2008-08-05 02:15:11 +04:00
|
|
|
case eCSSType_ValuePairList: {
|
2007-07-08 11:08:04 +04:00
|
|
|
return &PointerAtCursor(const_cast<char*>(cursor));
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (nsCSSProps::kTypeTable[iProp]) {
|
|
|
|
case eCSSType_Value: {
|
|
|
|
cursor += CDBValueStorage_advance;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case eCSSType_Rect: {
|
|
|
|
cursor += CDBRectStorage_advance;
|
|
|
|
} break;
|
|
|
|
|
2004-09-10 07:26:58 +04:00
|
|
|
case eCSSType_ValuePair: {
|
|
|
|
cursor += CDBValuePairStorage_advance;
|
|
|
|
} break;
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
case eCSSType_ValueList:
|
2008-08-05 02:15:11 +04:00
|
|
|
case eCSSType_ValuePairList: {
|
2003-06-08 02:14:42 +04:00
|
|
|
cursor += CDBPointerStorage_advance;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(cursor == cursor_end, "inconsistent data");
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2009-12-11 19:13:19 +03:00
|
|
|
already_AddRefed<nsCSSCompressedDataBlock>
|
2003-06-08 02:14:42 +04:00
|
|
|
nsCSSCompressedDataBlock::Clone() const
|
|
|
|
{
|
|
|
|
const char *cursor = Block(), *cursor_end = BlockEnd();
|
|
|
|
char *result_cursor;
|
|
|
|
|
|
|
|
nsCSSCompressedDataBlock *result =
|
|
|
|
new(cursor_end - cursor) nsCSSCompressedDataBlock();
|
|
|
|
if (!result)
|
|
|
|
return nsnull;
|
|
|
|
result_cursor = result->Block();
|
|
|
|
|
|
|
|
while (cursor < cursor_end) {
|
|
|
|
nsCSSProperty iProp = PropertyAtCursor(cursor);
|
|
|
|
NS_ASSERTION(0 <= iProp && iProp < eCSSProperty_COUNT_no_shorthands,
|
|
|
|
"out of range");
|
|
|
|
PropertyAtCursor(result_cursor) = iProp;
|
|
|
|
|
|
|
|
switch (nsCSSProps::kTypeTable[iProp]) {
|
|
|
|
case eCSSType_Value: {
|
|
|
|
const nsCSSValue* val = ValueAtCursor(cursor);
|
|
|
|
NS_ASSERTION(val->GetUnit() != eCSSUnit_Null, "oops");
|
2003-06-11 02:08:40 +04:00
|
|
|
nsCSSValue *result_val = ValueAtCursor(result_cursor);
|
|
|
|
new (result_val) nsCSSValue(*val);
|
2003-06-08 02:14:42 +04:00
|
|
|
cursor += CDBValueStorage_advance;
|
|
|
|
result_cursor += CDBValueStorage_advance;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case eCSSType_Rect: {
|
|
|
|
const nsCSSRect* val = RectAtCursor(cursor);
|
2004-05-05 04:43:50 +04:00
|
|
|
NS_ASSERTION(val->HasValue(), "oops");
|
2003-06-11 02:08:40 +04:00
|
|
|
nsCSSRect* result_val = RectAtCursor(result_cursor);
|
|
|
|
new (result_val) nsCSSRect(*val);
|
2003-06-08 02:14:42 +04:00
|
|
|
cursor += CDBRectStorage_advance;
|
|
|
|
result_cursor += CDBRectStorage_advance;
|
|
|
|
} break;
|
|
|
|
|
2004-09-10 07:26:58 +04:00
|
|
|
case eCSSType_ValuePair: {
|
|
|
|
const nsCSSValuePair* val = ValuePairAtCursor(cursor);
|
|
|
|
NS_ASSERTION(val->mXValue.GetUnit() != eCSSUnit_Null ||
|
|
|
|
val->mYValue.GetUnit() != eCSSUnit_Null, "oops");
|
|
|
|
nsCSSValuePair* result_val = ValuePairAtCursor(result_cursor);
|
|
|
|
new (result_val) nsCSSValuePair(*val);
|
|
|
|
cursor += CDBValuePairStorage_advance;
|
|
|
|
result_cursor += CDBValuePairStorage_advance;
|
|
|
|
} break;
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
case eCSSType_ValueList:
|
2008-08-05 02:15:11 +04:00
|
|
|
case eCSSType_ValuePairList: {
|
2003-06-08 02:14:42 +04:00
|
|
|
void *copy;
|
|
|
|
NS_ASSERTION(PointerAtCursor(cursor), "oops");
|
|
|
|
switch (nsCSSProps::kTypeTable[iProp]) {
|
2003-06-11 02:08:40 +04:00
|
|
|
default:
|
|
|
|
NS_NOTREACHED("unreachable");
|
|
|
|
// fall through to keep gcc's uninitialized
|
|
|
|
// variable warning quiet
|
2003-06-08 02:14:42 +04:00
|
|
|
case eCSSType_ValueList:
|
2008-10-17 12:13:16 +04:00
|
|
|
copy = ValueListAtCursor(cursor)->Clone();
|
2003-06-08 02:14:42 +04:00
|
|
|
break;
|
2008-08-05 02:15:11 +04:00
|
|
|
case eCSSType_ValuePairList:
|
2008-10-17 12:13:16 +04:00
|
|
|
copy = ValuePairListAtCursor(cursor)->Clone();
|
2003-06-08 02:14:42 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!copy) {
|
|
|
|
result->mBlockEnd = result_cursor;
|
|
|
|
result->Destroy();
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
PointerAtCursor(result_cursor) = copy;
|
|
|
|
cursor += CDBPointerStorage_advance;
|
|
|
|
result_cursor += CDBPointerStorage_advance;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(cursor == cursor_end, "inconsistent data");
|
|
|
|
|
|
|
|
result->mBlockEnd = result_cursor;
|
2003-06-11 02:08:40 +04:00
|
|
|
result->mStyleBits = mStyleBits;
|
|
|
|
NS_ASSERTION(result->DataSize() == DataSize(), "wrong size");
|
2009-12-11 19:13:19 +03:00
|
|
|
|
|
|
|
result->AddRef();
|
2003-06-08 02:14:42 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSCompressedDataBlock::Destroy()
|
|
|
|
{
|
|
|
|
const char* cursor = Block();
|
|
|
|
const char* cursor_end = BlockEnd();
|
|
|
|
while (cursor < cursor_end) {
|
|
|
|
nsCSSProperty iProp = PropertyAtCursor(cursor);
|
|
|
|
NS_ASSERTION(0 <= iProp && iProp < eCSSProperty_COUNT_no_shorthands,
|
|
|
|
"out of range");
|
|
|
|
|
|
|
|
switch (nsCSSProps::kTypeTable[iProp]) {
|
|
|
|
case eCSSType_Value: {
|
|
|
|
const nsCSSValue* val = ValueAtCursor(cursor);
|
|
|
|
NS_ASSERTION(val->GetUnit() != eCSSUnit_Null, "oops");
|
|
|
|
val->~nsCSSValue();
|
|
|
|
cursor += CDBValueStorage_advance;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case eCSSType_Rect: {
|
|
|
|
const nsCSSRect* val = RectAtCursor(cursor);
|
2004-05-05 04:43:50 +04:00
|
|
|
NS_ASSERTION(val->HasValue(), "oops");
|
2003-06-08 02:14:42 +04:00
|
|
|
val->~nsCSSRect();
|
|
|
|
cursor += CDBRectStorage_advance;
|
|
|
|
} break;
|
|
|
|
|
2004-09-10 07:26:58 +04:00
|
|
|
case eCSSType_ValuePair: {
|
|
|
|
const nsCSSValuePair* val = ValuePairAtCursor(cursor);
|
|
|
|
NS_ASSERTION(val->mXValue.GetUnit() != eCSSUnit_Null ||
|
|
|
|
val->mYValue.GetUnit() != eCSSUnit_Null, "oops");
|
|
|
|
val->~nsCSSValuePair();
|
|
|
|
cursor += CDBValuePairStorage_advance;
|
|
|
|
} break;
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
case eCSSType_ValueList: {
|
|
|
|
nsCSSValueList* val = ValueListAtCursor(cursor);
|
|
|
|
NS_ASSERTION(val, "oops");
|
|
|
|
delete val;
|
|
|
|
cursor += CDBPointerStorage_advance;
|
|
|
|
} break;
|
|
|
|
|
2008-08-05 02:15:11 +04:00
|
|
|
case eCSSType_ValuePairList: {
|
|
|
|
nsCSSValuePairList* val = ValuePairListAtCursor(cursor);
|
2003-06-08 02:14:42 +04:00
|
|
|
NS_ASSERTION(val, "oops");
|
|
|
|
delete val;
|
|
|
|
cursor += CDBPointerStorage_advance;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(cursor == cursor_end, "inconsistent data");
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2009-12-11 19:13:19 +03:00
|
|
|
/* static */ already_AddRefed<nsCSSCompressedDataBlock>
|
2003-06-08 02:14:42 +04:00
|
|
|
nsCSSCompressedDataBlock::CreateEmptyBlock()
|
|
|
|
{
|
|
|
|
nsCSSCompressedDataBlock *result = new(0) nsCSSCompressedDataBlock();
|
|
|
|
if (!result)
|
|
|
|
return nsnull;
|
|
|
|
result->mBlockEnd = result->Block();
|
2009-12-11 19:13:19 +03:00
|
|
|
|
|
|
|
result->AddRef();
|
2003-06-08 02:14:42 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
nsCSSExpandedDataBlock::nsCSSExpandedDataBlock()
|
|
|
|
{
|
|
|
|
AssertInitialState();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSExpandedDataBlock::~nsCSSExpandedDataBlock()
|
|
|
|
{
|
|
|
|
AssertInitialState();
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsCSSExpandedDataBlock::PropertyOffsetInfo
|
|
|
|
nsCSSExpandedDataBlock::kOffsetTable[eCSSProperty_COUNT_no_shorthands] = {
|
2009-09-11 14:46:36 +04:00
|
|
|
#define CSS_PROP_BACKENDONLY(name_, id_, method_, flags_, datastruct_, \
|
|
|
|
member_, type_, kwtable_) \
|
|
|
|
{ offsetof(nsCSSExpandedDataBlock, m##datastruct_.member_), \
|
|
|
|
size_t(-1), \
|
2003-06-08 02:14:42 +04:00
|
|
|
size_t(-1) },
|
2009-09-11 14:46:36 +04:00
|
|
|
#define CSS_PROP(name_, id_, method_, flags_, datastruct_, member_, type_, \
|
|
|
|
kwtable_, stylestruct_, stylestructoffset_, animtype_) \
|
|
|
|
{ offsetof(nsCSSExpandedDataBlock, m##datastruct_.member_), \
|
|
|
|
offsetof(nsRuleData, m##datastruct_##Data), \
|
2003-06-08 02:14:42 +04:00
|
|
|
offsetof(nsRuleData##datastruct_, member_) },
|
|
|
|
#include "nsCSSPropList.h"
|
|
|
|
#undef CSS_PROP
|
|
|
|
#undef CSS_PROP_BACKENDONLY
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2009-12-11 19:13:19 +03:00
|
|
|
nsCSSExpandedDataBlock::DoExpand(nsRefPtr<nsCSSCompressedDataBlock> *aBlock,
|
2003-06-08 02:14:42 +04:00
|
|
|
PRBool aImportant)
|
|
|
|
{
|
2009-12-11 19:13:19 +03:00
|
|
|
NS_PRECONDITION(*aBlock, "unexpected null block");
|
|
|
|
|
|
|
|
if (!(*aBlock)->IsMutable()) {
|
|
|
|
// FIXME (maybe): We really don't need to clone the block
|
|
|
|
// itself, just all the data inside it.
|
|
|
|
*aBlock = (*aBlock)->Clone();
|
2010-03-29 17:43:00 +04:00
|
|
|
if (!*aBlock) {
|
2009-12-11 19:13:19 +03:00
|
|
|
// Not much we can do; just lose the properties.
|
|
|
|
NS_WARNING("out of memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NS_ABORT_IF_FALSE((*aBlock)->IsMutable(), "we just cloned it");
|
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Save needless copying and allocation by copying the memory
|
|
|
|
* corresponding to the stored data in the compressed block, and
|
|
|
|
* then, to avoid destructors, deleting the compressed block by
|
|
|
|
* calling |delete| instead of using its |Destroy| method.
|
|
|
|
*/
|
2009-12-11 19:13:19 +03:00
|
|
|
const char* cursor = (*aBlock)->Block();
|
|
|
|
const char* cursor_end = (*aBlock)->BlockEnd();
|
2003-06-08 02:14:42 +04:00
|
|
|
while (cursor < cursor_end) {
|
|
|
|
nsCSSProperty iProp = PropertyAtCursor(cursor);
|
|
|
|
NS_ASSERTION(0 <= iProp && iProp < eCSSProperty_COUNT_no_shorthands,
|
|
|
|
"out of range");
|
|
|
|
NS_ASSERTION(!HasPropertyBit(iProp),
|
|
|
|
"compressed block has property multiple times");
|
|
|
|
SetPropertyBit(iProp);
|
|
|
|
if (aImportant)
|
|
|
|
SetImportantBit(iProp);
|
|
|
|
void *prop = PropertyAt(iProp);
|
|
|
|
|
|
|
|
switch (nsCSSProps::kTypeTable[iProp]) {
|
|
|
|
case eCSSType_Value: {
|
|
|
|
const nsCSSValue* val = ValueAtCursor(cursor);
|
2007-08-28 10:47:32 +04:00
|
|
|
nsCSSValue* dest = static_cast<nsCSSValue*>(prop);
|
2003-06-08 02:14:42 +04:00
|
|
|
NS_ASSERTION(val->GetUnit() != eCSSUnit_Null, "oops");
|
2007-08-28 10:47:32 +04:00
|
|
|
NS_ASSERTION(dest->GetUnit() == eCSSUnit_Null,
|
|
|
|
"expanding into non-empty block");
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
dest->~nsCSSValue();
|
|
|
|
#endif
|
|
|
|
memcpy(dest, val, sizeof(nsCSSValue));
|
2003-06-08 02:14:42 +04:00
|
|
|
cursor += CDBValueStorage_advance;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case eCSSType_Rect: {
|
|
|
|
const nsCSSRect* val = RectAtCursor(cursor);
|
2007-08-28 10:47:32 +04:00
|
|
|
nsCSSRect* dest = static_cast<nsCSSRect*>(prop);
|
2004-05-05 04:43:50 +04:00
|
|
|
NS_ASSERTION(val->HasValue(), "oops");
|
2007-08-28 10:47:32 +04:00
|
|
|
NS_ASSERTION(!dest->HasValue(),
|
|
|
|
"expanding into non-empty block");
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
dest->~nsCSSRect();
|
|
|
|
#endif
|
|
|
|
memcpy(dest, val, sizeof(nsCSSRect));
|
2003-06-08 02:14:42 +04:00
|
|
|
cursor += CDBRectStorage_advance;
|
|
|
|
} break;
|
|
|
|
|
2004-09-10 07:26:58 +04:00
|
|
|
case eCSSType_ValuePair: {
|
|
|
|
const nsCSSValuePair* val = ValuePairAtCursor(cursor);
|
2007-08-28 10:47:32 +04:00
|
|
|
nsCSSValuePair* dest = static_cast<nsCSSValuePair*>(prop);
|
2004-09-10 07:26:58 +04:00
|
|
|
NS_ASSERTION(val->mXValue.GetUnit() != eCSSUnit_Null ||
|
|
|
|
val->mYValue.GetUnit() != eCSSUnit_Null, "oops");
|
2007-08-28 10:47:32 +04:00
|
|
|
NS_ASSERTION(dest->mXValue.GetUnit() == eCSSUnit_Null &&
|
|
|
|
dest->mYValue.GetUnit() == eCSSUnit_Null,
|
|
|
|
"expanding into non-empty block");
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
dest->~nsCSSValuePair();
|
|
|
|
#endif
|
|
|
|
memcpy(dest, val, sizeof(nsCSSValuePair));
|
2004-09-10 07:26:58 +04:00
|
|
|
cursor += CDBValuePairStorage_advance;
|
|
|
|
} break;
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
case eCSSType_ValueList:
|
2008-08-05 02:15:11 +04:00
|
|
|
case eCSSType_ValuePairList: {
|
2003-06-08 02:14:42 +04:00
|
|
|
void* val = PointerAtCursor(cursor);
|
2007-08-28 10:47:32 +04:00
|
|
|
void** dest = static_cast<void**>(prop);
|
2003-06-08 02:14:42 +04:00
|
|
|
NS_ASSERTION(val, "oops");
|
2007-08-28 10:47:32 +04:00
|
|
|
NS_ASSERTION(!*dest, "expanding into non-empty block");
|
|
|
|
*dest = val;
|
2003-06-08 02:14:42 +04:00
|
|
|
cursor += CDBPointerStorage_advance;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(cursor == cursor_end, "inconsistent data");
|
|
|
|
|
2009-12-11 19:13:19 +03:00
|
|
|
NS_ASSERTION((*aBlock)->mRefCnt == 1, "unexpected reference count");
|
|
|
|
delete aBlock->forget().get();
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-11 19:13:19 +03:00
|
|
|
nsCSSExpandedDataBlock::Expand(
|
|
|
|
nsRefPtr<nsCSSCompressedDataBlock> *aNormalBlock,
|
|
|
|
nsRefPtr<nsCSSCompressedDataBlock> *aImportantBlock)
|
2003-06-08 02:14:42 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(*aNormalBlock, "unexpected null block");
|
|
|
|
AssertInitialState();
|
|
|
|
|
2009-12-11 19:13:19 +03:00
|
|
|
DoExpand(aNormalBlock, PR_FALSE);
|
2003-06-08 02:14:42 +04:00
|
|
|
if (*aImportantBlock) {
|
2009-12-11 19:13:19 +03:00
|
|
|
DoExpand(aImportantBlock, PR_TRUE);
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSExpandedDataBlock::ComputeSizeResult
|
|
|
|
nsCSSExpandedDataBlock::ComputeSize()
|
|
|
|
{
|
|
|
|
ComputeSizeResult result = {0, 0};
|
2010-04-23 23:59:15 +04:00
|
|
|
for (size_t iHigh = 0; iHigh < nsCSSPropertySet::kChunkCount; ++iHigh) {
|
2009-09-11 14:46:36 +04:00
|
|
|
if (!mPropertiesSet.HasPropertyInChunk(iHigh))
|
2003-06-08 02:14:42 +04:00
|
|
|
continue;
|
2010-04-23 23:59:15 +04:00
|
|
|
for (size_t iLow = 0; iLow < nsCSSPropertySet::kBitsInChunk; ++iLow) {
|
2009-09-11 14:46:36 +04:00
|
|
|
if (!mPropertiesSet.HasPropertyAt(iHigh, iLow))
|
2003-06-08 02:14:42 +04:00
|
|
|
continue;
|
2009-09-11 14:46:36 +04:00
|
|
|
nsCSSProperty iProp = nsCSSPropertySet::CSSPropertyAt(iHigh, iLow);
|
2003-06-08 02:14:42 +04:00
|
|
|
NS_ASSERTION(0 <= iProp && iProp < eCSSProperty_COUNT_no_shorthands,
|
|
|
|
"out of range");
|
2008-09-20 17:42:03 +04:00
|
|
|
#ifdef DEBUG
|
2003-06-08 02:14:42 +04:00
|
|
|
void *prop = PropertyAt(iProp);
|
2008-09-20 17:42:03 +04:00
|
|
|
#endif
|
2003-06-08 02:14:42 +04:00
|
|
|
PRUint32 increment = 0;
|
|
|
|
switch (nsCSSProps::kTypeTable[iProp]) {
|
|
|
|
case eCSSType_Value: {
|
2005-04-29 00:19:24 +04:00
|
|
|
#ifdef DEBUG
|
2007-07-08 11:08:04 +04:00
|
|
|
nsCSSValue* val = static_cast<nsCSSValue*>(prop);
|
2005-04-29 00:19:24 +04:00
|
|
|
NS_ASSERTION(val->GetUnit() != eCSSUnit_Null,
|
|
|
|
"null value while computing size");
|
|
|
|
#endif
|
|
|
|
increment = CDBValueStorage_advance;
|
2003-06-08 02:14:42 +04:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case eCSSType_Rect: {
|
2005-04-29 00:19:24 +04:00
|
|
|
#ifdef DEBUG
|
2007-07-08 11:08:04 +04:00
|
|
|
nsCSSRect* val = static_cast<nsCSSRect*>(prop);
|
2005-04-29 00:19:24 +04:00
|
|
|
NS_ASSERTION(val->HasValue(),
|
|
|
|
"Valueless rect while computing size");
|
|
|
|
#endif
|
|
|
|
increment = CDBRectStorage_advance;
|
2003-06-08 02:14:42 +04:00
|
|
|
} break;
|
|
|
|
|
2004-09-10 07:26:58 +04:00
|
|
|
case eCSSType_ValuePair: {
|
2005-04-29 00:19:24 +04:00
|
|
|
#ifdef DEBUG
|
2007-07-08 11:08:04 +04:00
|
|
|
nsCSSValuePair* val = static_cast<nsCSSValuePair*>(prop);
|
2005-04-29 00:19:24 +04:00
|
|
|
NS_ASSERTION(val->mXValue.GetUnit() != eCSSUnit_Null ||
|
|
|
|
val->mYValue.GetUnit() != eCSSUnit_Null,
|
|
|
|
"Valueless pair while computing size");
|
|
|
|
#endif
|
|
|
|
increment = CDBValuePairStorage_advance;
|
2004-09-10 07:26:58 +04:00
|
|
|
} break;
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
case eCSSType_ValueList:
|
2008-08-05 02:15:11 +04:00
|
|
|
case eCSSType_ValuePairList: {
|
2005-04-29 00:19:24 +04:00
|
|
|
#ifdef DEBUG
|
2007-07-08 11:08:04 +04:00
|
|
|
void* val = *static_cast<void**>(prop);
|
2005-04-29 00:19:24 +04:00
|
|
|
NS_ASSERTION(val, "Null pointer while computing size");
|
|
|
|
#endif
|
|
|
|
increment = CDBPointerStorage_advance;
|
2003-06-08 02:14:42 +04:00
|
|
|
} break;
|
|
|
|
}
|
2009-09-11 14:46:36 +04:00
|
|
|
if (mPropertiesImportant.HasPropertyAt(iHigh, iLow))
|
2003-06-08 02:14:42 +04:00
|
|
|
result.important += increment;
|
2009-09-11 14:46:36 +04:00
|
|
|
else
|
|
|
|
result.normal += increment;
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSExpandedDataBlock::Compress(nsCSSCompressedDataBlock **aNormalBlock,
|
|
|
|
nsCSSCompressedDataBlock **aImportantBlock)
|
|
|
|
{
|
2009-12-11 19:13:19 +03:00
|
|
|
nsRefPtr<nsCSSCompressedDataBlock> result_normal, result_important;
|
2003-06-08 02:14:42 +04:00
|
|
|
char *cursor_normal, *cursor_important;
|
|
|
|
|
|
|
|
ComputeSizeResult size = ComputeSize();
|
|
|
|
|
|
|
|
result_normal = new(size.normal) nsCSSCompressedDataBlock();
|
|
|
|
if (!result_normal) {
|
|
|
|
*aNormalBlock = nsnull;
|
|
|
|
*aImportantBlock = nsnull;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cursor_normal = result_normal->Block();
|
|
|
|
|
|
|
|
if (size.important != 0) {
|
|
|
|
result_important = new(size.important) nsCSSCompressedDataBlock();
|
|
|
|
if (!result_important) {
|
|
|
|
*aNormalBlock = nsnull;
|
|
|
|
*aImportantBlock = nsnull;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cursor_important = result_important->Block();
|
|
|
|
} else {
|
|
|
|
result_important = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save needless copying and allocation by copying the memory
|
|
|
|
* corresponding to the stored data in the expanded block, and then
|
|
|
|
* clearing the data in the expanded block.
|
|
|
|
*/
|
2010-04-23 23:59:15 +04:00
|
|
|
for (size_t iHigh = 0; iHigh < nsCSSPropertySet::kChunkCount; ++iHigh) {
|
2009-09-11 14:46:36 +04:00
|
|
|
if (!mPropertiesSet.HasPropertyInChunk(iHigh))
|
2003-06-08 02:14:42 +04:00
|
|
|
continue;
|
2010-04-23 23:59:15 +04:00
|
|
|
for (size_t iLow = 0; iLow < nsCSSPropertySet::kBitsInChunk; ++iLow) {
|
2009-09-11 14:46:36 +04:00
|
|
|
if (!mPropertiesSet.HasPropertyAt(iHigh, iLow))
|
2003-06-08 02:14:42 +04:00
|
|
|
continue;
|
2009-09-11 14:46:36 +04:00
|
|
|
nsCSSProperty iProp = nsCSSPropertySet::CSSPropertyAt(iHigh, iLow);
|
2003-06-08 02:14:42 +04:00
|
|
|
NS_ASSERTION(0 <= iProp && iProp < eCSSProperty_COUNT_no_shorthands,
|
|
|
|
"out of range");
|
|
|
|
void *prop = PropertyAt(iProp);
|
|
|
|
PRBool important =
|
2009-09-11 14:46:36 +04:00
|
|
|
mPropertiesImportant.HasPropertyAt(iHigh, iLow);
|
2003-06-08 02:14:42 +04:00
|
|
|
char *&cursor = important ? cursor_important : cursor_normal;
|
|
|
|
nsCSSCompressedDataBlock *result =
|
|
|
|
important ? result_important : result_normal;
|
|
|
|
switch (nsCSSProps::kTypeTable[iProp]) {
|
|
|
|
case eCSSType_Value: {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsCSSValue* val = static_cast<nsCSSValue*>(prop);
|
2005-04-29 00:19:24 +04:00
|
|
|
NS_ASSERTION(val->GetUnit() != eCSSUnit_Null,
|
|
|
|
"Null value while compressing");
|
|
|
|
CDBValueStorage *storage =
|
2007-07-08 11:08:04 +04:00
|
|
|
reinterpret_cast<CDBValueStorage*>(cursor);
|
2005-04-29 00:19:24 +04:00
|
|
|
storage->property = iProp;
|
|
|
|
memcpy(&storage->value, val, sizeof(nsCSSValue));
|
|
|
|
new (val) nsCSSValue();
|
|
|
|
cursor += CDBValueStorage_advance;
|
2003-06-08 02:14:42 +04:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case eCSSType_Rect: {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsCSSRect* val = static_cast<nsCSSRect*>(prop);
|
2005-04-29 00:19:24 +04:00
|
|
|
NS_ASSERTION(val->HasValue(),
|
|
|
|
"Valueless rect while compressing");
|
|
|
|
CDBRectStorage *storage =
|
2007-07-08 11:08:04 +04:00
|
|
|
reinterpret_cast<CDBRectStorage*>(cursor);
|
2005-04-29 00:19:24 +04:00
|
|
|
storage->property = iProp;
|
|
|
|
memcpy(&storage->value, val, sizeof(nsCSSRect));
|
|
|
|
new (val) nsCSSRect();
|
|
|
|
cursor += CDBRectStorage_advance;
|
2003-06-08 02:14:42 +04:00
|
|
|
} break;
|
|
|
|
|
2004-09-10 07:26:58 +04:00
|
|
|
case eCSSType_ValuePair: {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsCSSValuePair* val = static_cast<nsCSSValuePair*>(prop);
|
2005-04-29 00:19:24 +04:00
|
|
|
NS_ASSERTION(val->mXValue.GetUnit() != eCSSUnit_Null ||
|
|
|
|
val->mYValue.GetUnit() != eCSSUnit_Null,
|
|
|
|
"Valueless pair while compressing");
|
|
|
|
CDBValuePairStorage *storage =
|
2007-07-08 11:08:04 +04:00
|
|
|
reinterpret_cast<CDBValuePairStorage*>(cursor);
|
2005-04-29 00:19:24 +04:00
|
|
|
storage->property = iProp;
|
|
|
|
memcpy(&storage->value, val, sizeof(nsCSSValuePair));
|
|
|
|
new (val) nsCSSValuePair();
|
|
|
|
cursor += CDBValuePairStorage_advance;
|
2004-09-10 07:26:58 +04:00
|
|
|
} break;
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
case eCSSType_ValueList:
|
2008-08-05 02:15:11 +04:00
|
|
|
case eCSSType_ValuePairList: {
|
2007-07-08 11:08:04 +04:00
|
|
|
void*& val = *static_cast<void**>(prop);
|
2005-04-29 00:19:24 +04:00
|
|
|
NS_ASSERTION(val, "Null pointer while compressing");
|
|
|
|
CDBPointerStorage *storage =
|
2007-07-08 11:08:04 +04:00
|
|
|
reinterpret_cast<CDBPointerStorage*>(cursor);
|
2005-04-29 00:19:24 +04:00
|
|
|
storage->property = iProp;
|
|
|
|
storage->value = val;
|
|
|
|
val = nsnull;
|
|
|
|
cursor += CDBPointerStorage_advance;
|
2003-06-08 02:14:42 +04:00
|
|
|
} break;
|
|
|
|
}
|
2005-04-29 00:19:24 +04:00
|
|
|
result->mStyleBits |=
|
|
|
|
nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[iProp]);
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result_normal->mBlockEnd = cursor_normal;
|
|
|
|
NS_ASSERTION(result_normal->DataSize() == ptrdiff_t(size.normal),
|
|
|
|
"size miscalculation");
|
|
|
|
if (result_important) {
|
|
|
|
result_important->mBlockEnd = cursor_important;
|
|
|
|
NS_ASSERTION(result_important->DataSize() == ptrdiff_t(size.important),
|
|
|
|
"size miscalculation");
|
|
|
|
}
|
|
|
|
|
|
|
|
ClearSets();
|
|
|
|
AssertInitialState();
|
2009-12-11 19:13:19 +03:00
|
|
|
result_normal.forget(aNormalBlock);
|
|
|
|
result_important.forget(aImportantBlock);
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSExpandedDataBlock::Clear()
|
|
|
|
{
|
2010-04-23 23:59:15 +04:00
|
|
|
for (size_t iHigh = 0; iHigh < nsCSSPropertySet::kChunkCount; ++iHigh) {
|
2009-09-11 14:46:36 +04:00
|
|
|
if (!mPropertiesSet.HasPropertyInChunk(iHigh))
|
2003-06-08 02:14:42 +04:00
|
|
|
continue;
|
2010-04-23 23:59:15 +04:00
|
|
|
for (size_t iLow = 0; iLow < nsCSSPropertySet::kBitsInChunk; ++iLow) {
|
2009-09-11 14:46:36 +04:00
|
|
|
if (!mPropertiesSet.HasPropertyAt(iHigh, iLow))
|
2003-06-08 02:14:42 +04:00
|
|
|
continue;
|
2009-09-11 14:46:36 +04:00
|
|
|
nsCSSProperty iProp = nsCSSPropertySet::CSSPropertyAt(iHigh, iLow);
|
2003-06-08 02:14:42 +04:00
|
|
|
ClearProperty(iProp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AssertInitialState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSExpandedDataBlock::ClearProperty(nsCSSProperty aPropID)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(0 <= aPropID && aPropID < eCSSProperty_COUNT_no_shorthands,
|
|
|
|
"out of range");
|
|
|
|
|
|
|
|
ClearPropertyBit(aPropID);
|
|
|
|
ClearImportantBit(aPropID);
|
|
|
|
|
|
|
|
void *prop = PropertyAt(aPropID);
|
|
|
|
switch (nsCSSProps::kTypeTable[aPropID]) {
|
|
|
|
case eCSSType_Value: {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsCSSValue* val = static_cast<nsCSSValue*>(prop);
|
2003-06-08 02:14:42 +04:00
|
|
|
val->Reset();
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case eCSSType_Rect: {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsCSSRect* val = static_cast<nsCSSRect*>(prop);
|
2004-05-05 04:43:50 +04:00
|
|
|
val->Reset();
|
2003-06-08 02:14:42 +04:00
|
|
|
} break;
|
|
|
|
|
2004-09-10 07:26:58 +04:00
|
|
|
case eCSSType_ValuePair: {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsCSSValuePair* val = static_cast<nsCSSValuePair*>(prop);
|
2004-09-10 07:26:58 +04:00
|
|
|
val->mXValue.Reset();
|
|
|
|
val->mYValue.Reset();
|
|
|
|
} break;
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
case eCSSType_ValueList: {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsCSSValueList*& val = *static_cast<nsCSSValueList**>(prop);
|
2003-06-08 02:14:42 +04:00
|
|
|
if (val) {
|
|
|
|
delete val;
|
|
|
|
val = nsnull;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
2008-08-05 02:15:11 +04:00
|
|
|
case eCSSType_ValuePairList: {
|
|
|
|
nsCSSValuePairList*& val =
|
|
|
|
*static_cast<nsCSSValuePairList**>(prop);
|
2003-06-08 02:14:42 +04:00
|
|
|
if (val) {
|
|
|
|
delete val;
|
|
|
|
val = nsnull;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
nsCSSExpandedDataBlock::DoAssertInitialState()
|
|
|
|
{
|
2009-09-11 14:46:36 +04:00
|
|
|
mPropertiesSet.AssertIsEmpty("not initial state");
|
|
|
|
mPropertiesImportant.AssertIsEmpty("not initial state");
|
2003-06-08 02:14:42 +04:00
|
|
|
|
2009-09-11 14:46:36 +04:00
|
|
|
for (PRUint32 i = 0; i < eCSSProperty_COUNT_no_shorthands; ++i) {
|
2003-06-08 02:14:42 +04:00
|
|
|
void *prop = PropertyAt(nsCSSProperty(i));
|
|
|
|
switch (nsCSSProps::kTypeTable[i]) {
|
|
|
|
case eCSSType_Value: {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsCSSValue* val = static_cast<nsCSSValue*>(prop);
|
2003-06-08 02:14:42 +04:00
|
|
|
NS_ASSERTION(val->GetUnit() == eCSSUnit_Null,
|
|
|
|
"not initial state");
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case eCSSType_Rect: {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsCSSRect* val = static_cast<nsCSSRect*>(prop);
|
2003-06-08 02:14:42 +04:00
|
|
|
NS_ASSERTION(val->mTop.GetUnit() == eCSSUnit_Null,
|
|
|
|
"not initial state");
|
|
|
|
NS_ASSERTION(val->mRight.GetUnit() == eCSSUnit_Null,
|
|
|
|
"not initial state");
|
|
|
|
NS_ASSERTION(val->mBottom.GetUnit() == eCSSUnit_Null,
|
|
|
|
"not initial state");
|
|
|
|
NS_ASSERTION(val->mLeft.GetUnit() == eCSSUnit_Null,
|
|
|
|
"not initial state");
|
|
|
|
} break;
|
|
|
|
|
2004-09-10 07:26:58 +04:00
|
|
|
case eCSSType_ValuePair: {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsCSSValuePair* val = static_cast<nsCSSValuePair*>(prop);
|
2004-09-10 07:26:58 +04:00
|
|
|
NS_ASSERTION(val->mXValue.GetUnit() == eCSSUnit_Null,
|
|
|
|
"not initial state");
|
|
|
|
NS_ASSERTION(val->mYValue.GetUnit() == eCSSUnit_Null,
|
|
|
|
"not initial state");
|
|
|
|
} break;
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
case eCSSType_ValueList: {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsCSSValueList* val = *static_cast<nsCSSValueList**>(prop);
|
2003-06-08 02:14:42 +04:00
|
|
|
NS_ASSERTION(val == nsnull, "not initial state");
|
|
|
|
} break;
|
|
|
|
|
2008-08-05 02:15:11 +04:00
|
|
|
case eCSSType_ValuePairList: {
|
|
|
|
nsCSSValuePairList* val =
|
|
|
|
*static_cast<nsCSSValuePairList**>(prop);
|
2003-06-08 02:14:42 +04:00
|
|
|
NS_ASSERTION(val == nsnull, "not initial state");
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|