2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** 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 ***** */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* compact representation of the property-value pairs within a CSS
|
|
|
|
* declaration, and the code for expanding and compacting it
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsCSSDataBlock.h"
|
2010-07-23 11:00:44 -07:00
|
|
|
#include "mozilla/css/Declaration.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsRuleData.h"
|
2007-05-16 14:10:31 -07:00
|
|
|
#include "nsStyleSet.h"
|
2010-04-06 12:42:41 -07:00
|
|
|
#include "nsStyleContext.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-23 11:00:44 -07:00
|
|
|
namespace css = mozilla::css;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
2010-08-19 12:33:44 -07:00
|
|
|
* nsCSSCompressedDataBlock holds property-value pairs corresponding
|
2010-08-19 12:33:44 -07:00
|
|
|
* to CSS declaration blocks. Each pair is stored in a CDBValueStorage
|
|
|
|
* object; these objects form an array at the end of the data block.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct CDBValueStorage {
|
|
|
|
nsCSSProperty property;
|
|
|
|
nsCSSValue value;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2010-08-19 12:33:44 -07:00
|
|
|
CDBValueStorage_advance = sizeof(CDBValueStorage)
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 00:08:04 -07:00
|
|
|
return *reinterpret_cast<nsCSSProperty*>(aCursor);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline nsCSSProperty PropertyAtCursor(const char *aCursor) {
|
2007-07-08 00:08:04 -07:00
|
|
|
return *reinterpret_cast<const nsCSSProperty*>(aCursor);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline nsCSSValue* ValueAtCursor(char *aCursor) {
|
2007-07-08 00:08:04 -07:00
|
|
|
return & reinterpret_cast<CDBValueStorage*>(aCursor)->value;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline const nsCSSValue* ValueAtCursor(const char *aCursor) {
|
2007-07-08 00:08:04 -07:00
|
|
|
return & reinterpret_cast<const CDBValueStorage*>(aCursor)->value;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
/**
|
|
|
|
* Does a fast move of aSource to aDest. The previous value in
|
|
|
|
* aDest is cleanly destroyed, and aSource is cleared. Returns
|
|
|
|
* true if, before the copy, the value at aSource compared unequal
|
|
|
|
* to the value at aDest; false otherwise.
|
|
|
|
*/
|
|
|
|
static PRBool
|
|
|
|
MoveValue(nsCSSValue* aSource, nsCSSValue* aDest)
|
|
|
|
{
|
|
|
|
PRBool changed = (*aSource != *aDest);
|
|
|
|
aDest->~nsCSSValue();
|
|
|
|
memcpy(aDest, aSource, sizeof(nsCSSValue));
|
|
|
|
new (aSource) nsCSSValue();
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
2007-05-16 14:10:31 -07:00
|
|
|
static PRBool
|
|
|
|
ShouldIgnoreColors(nsRuleData *aRuleData)
|
|
|
|
{
|
|
|
|
return aRuleData->mLevel != nsStyleSet::eAgentSheet &&
|
|
|
|
aRuleData->mLevel != nsStyleSet::eUserSheet &&
|
2007-11-15 19:46:42 -08:00
|
|
|
!aRuleData->mPresContext->UseDocumentColors();
|
2007-05-16 14:10:31 -07:00
|
|
|
}
|
|
|
|
|
2009-08-21 13:39:25 -07: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-14 19:16:59 -08:00
|
|
|
TryToStartImageLoadOnValue(const nsCSSValue& aValue, nsIDocument* aDocument)
|
2009-08-21 13:39:25 -07: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-14 19:16:59 -08:00
|
|
|
static void
|
|
|
|
TryToStartImageLoad(const nsCSSValue& aValue, nsIDocument* aDocument,
|
|
|
|
nsCSSProperty aProperty)
|
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
if (aValue.GetUnit() == eCSSUnit_List) {
|
|
|
|
for (const nsCSSValueList* l = aValue.GetListValue(); l; l = l->mNext) {
|
|
|
|
TryToStartImageLoad(l->mValue, aDocument, aProperty);
|
|
|
|
}
|
|
|
|
} else if (nsCSSProps::PropHasFlags(aProperty,
|
|
|
|
CSS_PROPERTY_IMAGE_IS_IN_ARRAY_0)) {
|
2009-11-14 19:16:59 -08:00
|
|
|
if (aValue.GetUnit() == eCSSUnit_Array) {
|
|
|
|
TryToStartImageLoadOnValue(aValue.GetArrayValue()->Item(0), aDocument);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
TryToStartImageLoadOnValue(aValue, aDocument);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-06 12:42:41 -07: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-19 19:28:00 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSCompressedDataBlock::MapRuleInfoInto(nsRuleData *aRuleData) const
|
|
|
|
{
|
2007-10-08 14:58:22 -07:00
|
|
|
// If we have no data for these structs, then return immediately.
|
2007-03-22 10:30:00 -07: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-08 14:58:22 -07:00
|
|
|
if (!(aRuleData->mSIDs & mStyleBits))
|
2010-05-19 19:28:00 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-21 13:39:25 -07:00
|
|
|
nsIDocument* doc = aRuleData->mPresContext->Document();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
const char* cursor = Block();
|
|
|
|
const char* cursor_end = BlockEnd();
|
|
|
|
while (cursor < cursor_end) {
|
|
|
|
nsCSSProperty iProp = PropertyAtCursor(cursor);
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(iProp), "out of range");
|
2007-10-08 14:58:22 -07:00
|
|
|
if (nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[iProp]) &
|
|
|
|
aRuleData->mSIDs) {
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue* target = aRuleData->ValueFor(iProp);
|
|
|
|
if (target->GetUnit() == eCSSUnit_Null) {
|
|
|
|
const nsCSSValue *val = ValueAtCursor(cursor);
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(val->GetUnit() != eCSSUnit_Null, "oops");
|
2010-08-19 12:33:44 -07:00
|
|
|
if (ShouldStartImageLoads(aRuleData, iProp)) {
|
|
|
|
TryToStartImageLoad(*val, doc, iProp);
|
|
|
|
}
|
|
|
|
*target = *val;
|
|
|
|
if (iProp == eCSSProperty_font_family) {
|
|
|
|
// XXX Are there other things like this?
|
|
|
|
aRuleData->mFontData->mFamilyFromHTML = PR_FALSE;
|
|
|
|
}
|
|
|
|
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());
|
2007-05-16 14:10:31 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
} else {
|
|
|
|
// Ignore 'color', 'border-*-color', etc.
|
|
|
|
*target = nsCSSValue();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
cursor += CDBValueStorage_advance;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(cursor == cursor_end, "inconsistent data");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
const nsCSSValue*
|
|
|
|
nsCSSCompressedDataBlock::ValueFor(nsCSSProperty aProperty) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(aProperty),
|
|
|
|
"Don't call for shorthands");
|
2009-07-09 14:50:39 -07:00
|
|
|
|
2007-03-22 10:30:00 -07: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);
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(iProp), "out of range");
|
2007-03-22 10:30:00 -07:00
|
|
|
if (iProp == aProperty) {
|
2010-08-19 12:33:44 -07:00
|
|
|
return ValueAtCursor(cursor);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
cursor += CDBValueStorage_advance;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(cursor == cursor_end, "inconsistent data");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
PRBool
|
|
|
|
nsCSSCompressedDataBlock::TryReplaceValue(nsCSSProperty aProperty,
|
|
|
|
nsCSSExpandedDataBlock& aFromBlock,
|
|
|
|
PRBool *aChanged)
|
|
|
|
{
|
|
|
|
nsCSSValue* newValue = aFromBlock.PropertyAt(aProperty);
|
|
|
|
NS_ABORT_IF_FALSE(newValue && newValue->GetUnit() != eCSSUnit_Null,
|
|
|
|
"cannot replace with empty value");
|
|
|
|
|
|
|
|
const nsCSSValue* oldValue = ValueFor(aProperty);
|
|
|
|
if (!oldValue) {
|
|
|
|
*aChanged = PR_FALSE;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aChanged = MoveValue(newValue, const_cast<nsCSSValue*>(oldValue));
|
|
|
|
aFromBlock.ClearPropertyBit(aProperty);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-07-23 11:00:52 -07:00
|
|
|
nsCSSCompressedDataBlock*
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSCompressedDataBlock::Clone() const
|
|
|
|
{
|
|
|
|
const char *cursor = Block(), *cursor_end = BlockEnd();
|
|
|
|
char *result_cursor;
|
|
|
|
|
2010-07-23 11:00:52 -07:00
|
|
|
nsAutoPtr<nsCSSCompressedDataBlock> result
|
|
|
|
(new(cursor_end - cursor) nsCSSCompressedDataBlock());
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!result)
|
|
|
|
return nsnull;
|
|
|
|
result_cursor = result->Block();
|
|
|
|
|
|
|
|
while (cursor < cursor_end) {
|
|
|
|
nsCSSProperty iProp = PropertyAtCursor(cursor);
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(iProp), "out of range");
|
2007-03-22 10:30:00 -07:00
|
|
|
PropertyAtCursor(result_cursor) = iProp;
|
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
const nsCSSValue* val = ValueAtCursor(cursor);
|
|
|
|
nsCSSValue *result_val = ValueAtCursor(result_cursor);
|
|
|
|
new (result_val) nsCSSValue(*val);
|
|
|
|
cursor += CDBValueStorage_advance;
|
|
|
|
result_cursor += CDBValueStorage_advance;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(cursor == cursor_end, "inconsistent data");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
result->mBlockEnd = result_cursor;
|
|
|
|
result->mStyleBits = mStyleBits;
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(result->DataSize() == DataSize(), "wrong size");
|
2009-12-11 08:13:19 -08:00
|
|
|
|
2010-07-23 11:00:52 -07:00
|
|
|
return result.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-23 11:00:52 -07:00
|
|
|
nsCSSCompressedDataBlock::~nsCSSCompressedDataBlock()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
const char* cursor = Block();
|
|
|
|
const char* cursor_end = BlockEnd();
|
|
|
|
while (cursor < cursor_end) {
|
|
|
|
nsCSSProperty iProp = PropertyAtCursor(cursor);
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(iProp), "out of range");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
const nsCSSValue* val = ValueAtCursor(cursor);
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(val->GetUnit() != eCSSUnit_Null, "oops");
|
2010-08-19 12:33:44 -07:00
|
|
|
val->~nsCSSValue();
|
|
|
|
cursor += CDBValueStorage_advance;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(cursor == cursor_end, "inconsistent data");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-23 11:00:52 -07:00
|
|
|
/* static */ nsCSSCompressedDataBlock*
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSCompressedDataBlock::CreateEmptyBlock()
|
|
|
|
{
|
|
|
|
nsCSSCompressedDataBlock *result = new(0) nsCSSCompressedDataBlock();
|
|
|
|
result->mBlockEnd = result->Block();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
nsCSSExpandedDataBlock::nsCSSExpandedDataBlock()
|
|
|
|
{
|
|
|
|
AssertInitialState();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSExpandedDataBlock::~nsCSSExpandedDataBlock()
|
|
|
|
{
|
|
|
|
AssertInitialState();
|
|
|
|
}
|
|
|
|
|
2010-07-23 11:00:21 -07:00
|
|
|
const size_t
|
|
|
|
nsCSSExpandedDataBlock::kOffsetTable[] = {
|
2010-08-19 12:33:44 -07:00
|
|
|
#define CSS_PROP(name_, id_, method_, flags_, datastruct_, member_, \
|
2009-09-11 03:46:36 -07:00
|
|
|
kwtable_, stylestruct_, stylestructoffset_, animtype_) \
|
2010-07-23 11:00:21 -07:00
|
|
|
offsetof(nsCSSExpandedDataBlock, m##datastruct_.member_),
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCSSPropList.h"
|
|
|
|
#undef CSS_PROP
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2010-07-23 11:00:52 -07:00
|
|
|
nsCSSExpandedDataBlock::DoExpand(nsCSSCompressedDataBlock *aBlock,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool aImportant)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Save needless copying and allocation by copying the memory
|
2010-07-23 11:00:52 -07:00
|
|
|
* corresponding to the stored data in the compressed block.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2010-07-23 11:00:52 -07:00
|
|
|
const char* cursor = aBlock->Block();
|
|
|
|
const char* cursor_end = aBlock->BlockEnd();
|
2007-03-22 10:30:00 -07:00
|
|
|
while (cursor < cursor_end) {
|
|
|
|
nsCSSProperty iProp = PropertyAtCursor(cursor);
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(iProp), "out of range");
|
|
|
|
NS_ABORT_IF_FALSE(!HasPropertyBit(iProp),
|
|
|
|
"compressed block has property multiple times");
|
2007-03-22 10:30:00 -07:00
|
|
|
SetPropertyBit(iProp);
|
|
|
|
if (aImportant)
|
|
|
|
SetImportantBit(iProp);
|
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
const nsCSSValue* val = ValueAtCursor(cursor);
|
|
|
|
nsCSSValue* dest = PropertyAt(iProp);
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(val->GetUnit() != eCSSUnit_Null, "oops");
|
|
|
|
NS_ABORT_IF_FALSE(dest->GetUnit() == eCSSUnit_Null,
|
|
|
|
"expanding into non-empty block");
|
2007-08-27 23:47:32 -07:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
2010-08-19 12:33:44 -07:00
|
|
|
dest->~nsCSSValue();
|
2007-08-27 23:47:32 -07:00
|
|
|
#endif
|
2010-08-19 12:33:44 -07:00
|
|
|
memcpy(dest, val, sizeof(nsCSSValue));
|
|
|
|
cursor += CDBValueStorage_advance;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(cursor == cursor_end, "inconsistent data");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-23 11:00:52 -07:00
|
|
|
// Don't destroy remnants of what we just copied
|
|
|
|
aBlock->mBlockEnd = aBlock->Block();
|
|
|
|
delete aBlock;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-07-23 11:00:52 -07:00
|
|
|
nsCSSExpandedDataBlock::Expand(nsCSSCompressedDataBlock *aNormalBlock,
|
|
|
|
nsCSSCompressedDataBlock *aImportantBlock)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(aNormalBlock, "unexpected null block");
|
2007-03-22 10:30:00 -07:00
|
|
|
AssertInitialState();
|
|
|
|
|
2009-12-11 08:13:19 -08:00
|
|
|
DoExpand(aNormalBlock, PR_FALSE);
|
2010-07-23 11:00:52 -07:00
|
|
|
if (aImportantBlock) {
|
2009-12-11 08:13:19 -08:00
|
|
|
DoExpand(aImportantBlock, PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSExpandedDataBlock::ComputeSizeResult
|
|
|
|
nsCSSExpandedDataBlock::ComputeSize()
|
|
|
|
{
|
|
|
|
ComputeSizeResult result = {0, 0};
|
2010-04-23 12:59:15 -07:00
|
|
|
for (size_t iHigh = 0; iHigh < nsCSSPropertySet::kChunkCount; ++iHigh) {
|
2009-09-11 03:46:36 -07:00
|
|
|
if (!mPropertiesSet.HasPropertyInChunk(iHigh))
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
2010-04-23 12:59:15 -07:00
|
|
|
for (size_t iLow = 0; iLow < nsCSSPropertySet::kBitsInChunk; ++iLow) {
|
2009-09-11 03:46:36 -07:00
|
|
|
if (!mPropertiesSet.HasPropertyAt(iHigh, iLow))
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
2009-09-11 03:46:36 -07:00
|
|
|
nsCSSProperty iProp = nsCSSPropertySet::CSSPropertyAt(iHigh, iLow);
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(iProp), "out of range");
|
|
|
|
NS_ABORT_IF_FALSE(PropertyAt(iProp)->GetUnit() != eCSSUnit_Null,
|
|
|
|
"null value while computing size");
|
2009-09-11 03:46:36 -07:00
|
|
|
if (mPropertiesImportant.HasPropertyAt(iHigh, iLow))
|
2010-08-19 12:33:44 -07:00
|
|
|
result.important += CDBValueStorage_advance;
|
2009-09-11 03:46:36 -07:00
|
|
|
else
|
2010-08-19 12:33:44 -07:00
|
|
|
result.normal += CDBValueStorage_advance;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSExpandedDataBlock::Compress(nsCSSCompressedDataBlock **aNormalBlock,
|
|
|
|
nsCSSCompressedDataBlock **aImportantBlock)
|
|
|
|
{
|
2010-07-23 11:00:52 -07:00
|
|
|
nsAutoPtr<nsCSSCompressedDataBlock> result_normal, result_important;
|
2007-03-22 10:30:00 -07:00
|
|
|
char *cursor_normal, *cursor_important;
|
|
|
|
|
|
|
|
ComputeSizeResult size = ComputeSize();
|
2010-07-23 11:00:52 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
result_normal = new(size.normal) nsCSSCompressedDataBlock();
|
|
|
|
cursor_normal = result_normal->Block();
|
|
|
|
|
|
|
|
if (size.important != 0) {
|
|
|
|
result_important = new(size.important) nsCSSCompressedDataBlock();
|
|
|
|
cursor_important = result_important->Block();
|
|
|
|
} else {
|
|
|
|
result_important = nsnull;
|
2010-08-19 12:33:44 -07:00
|
|
|
cursor_important = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 12:59:15 -07:00
|
|
|
for (size_t iHigh = 0; iHigh < nsCSSPropertySet::kChunkCount; ++iHigh) {
|
2009-09-11 03:46:36 -07:00
|
|
|
if (!mPropertiesSet.HasPropertyInChunk(iHigh))
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
2010-04-23 12:59:15 -07:00
|
|
|
for (size_t iLow = 0; iLow < nsCSSPropertySet::kBitsInChunk; ++iLow) {
|
2009-09-11 03:46:36 -07:00
|
|
|
if (!mPropertiesSet.HasPropertyAt(iHigh, iLow))
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
2009-09-11 03:46:36 -07:00
|
|
|
nsCSSProperty iProp = nsCSSPropertySet::CSSPropertyAt(iHigh, iLow);
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(iProp), "out of range");
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool important =
|
2009-09-11 03:46:36 -07:00
|
|
|
mPropertiesImportant.HasPropertyAt(iHigh, iLow);
|
2007-03-22 10:30:00 -07:00
|
|
|
char *&cursor = important ? cursor_important : cursor_normal;
|
|
|
|
nsCSSCompressedDataBlock *result =
|
|
|
|
important ? result_important : result_normal;
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue* val = PropertyAt(iProp);
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(val->GetUnit() != eCSSUnit_Null,
|
|
|
|
"Null value while compressing");
|
2010-08-19 12:33:44 -07:00
|
|
|
CDBValueStorage *storage =
|
|
|
|
reinterpret_cast<CDBValueStorage*>(cursor);
|
|
|
|
storage->property = iProp;
|
|
|
|
memcpy(&storage->value, val, sizeof(nsCSSValue));
|
|
|
|
new (val) nsCSSValue();
|
|
|
|
cursor += CDBValueStorage_advance;
|
2007-03-22 10:30:00 -07:00
|
|
|
result->mStyleBits |=
|
|
|
|
nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[iProp]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result_normal->mBlockEnd = cursor_normal;
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(result_normal->DataSize() == ptrdiff_t(size.normal),
|
|
|
|
"size miscalculation");
|
2010-08-19 12:33:44 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (result_important) {
|
|
|
|
result_important->mBlockEnd = cursor_important;
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(result_important->DataSize() ==
|
|
|
|
ptrdiff_t(size.important),
|
|
|
|
"size miscalculation");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ClearSets();
|
|
|
|
AssertInitialState();
|
2010-07-23 11:00:52 -07:00
|
|
|
*aNormalBlock = result_normal.forget();
|
|
|
|
*aImportantBlock = result_important.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
void
|
|
|
|
nsCSSExpandedDataBlock::AddLonghandProperty(nsCSSProperty aProperty,
|
|
|
|
const nsCSSValue& aValue)
|
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(aProperty),
|
|
|
|
"property out of range");
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue& storage = *static_cast<nsCSSValue*>(PropertyAt(aProperty));
|
|
|
|
storage = aValue;
|
|
|
|
SetPropertyBit(aProperty);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsCSSExpandedDataBlock::Clear()
|
|
|
|
{
|
2010-04-23 12:59:15 -07:00
|
|
|
for (size_t iHigh = 0; iHigh < nsCSSPropertySet::kChunkCount; ++iHigh) {
|
2009-09-11 03:46:36 -07:00
|
|
|
if (!mPropertiesSet.HasPropertyInChunk(iHigh))
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
2010-04-23 12:59:15 -07:00
|
|
|
for (size_t iLow = 0; iLow < nsCSSPropertySet::kBitsInChunk; ++iLow) {
|
2009-09-11 03:46:36 -07:00
|
|
|
if (!mPropertiesSet.HasPropertyAt(iHigh, iLow))
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
2009-09-11 03:46:36 -07:00
|
|
|
nsCSSProperty iProp = nsCSSPropertySet::CSSPropertyAt(iHigh, iLow);
|
2010-07-23 11:00:42 -07:00
|
|
|
ClearLonghandProperty(iProp);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AssertInitialState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSExpandedDataBlock::ClearProperty(nsCSSProperty aPropID)
|
|
|
|
{
|
2010-07-23 11:00:42 -07:00
|
|
|
if (nsCSSProps::IsShorthand(aPropID)) {
|
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aPropID) {
|
|
|
|
ClearLonghandProperty(*p);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ClearLonghandProperty(aPropID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSExpandedDataBlock::ClearLonghandProperty(nsCSSProperty aPropID)
|
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(aPropID), "out of range");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
ClearPropertyBit(aPropID);
|
|
|
|
ClearImportantBit(aPropID);
|
2010-08-19 12:33:44 -07:00
|
|
|
PropertyAt(aPropID)->Reset();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
PRBool
|
2010-07-23 11:00:44 -07:00
|
|
|
nsCSSExpandedDataBlock::TransferFromBlock(nsCSSExpandedDataBlock& aFromBlock,
|
|
|
|
nsCSSProperty aPropID,
|
|
|
|
PRBool aIsImportant,
|
|
|
|
PRBool aOverrideImportant,
|
|
|
|
PRBool aMustCallValueAppended,
|
2010-08-19 12:33:44 -07:00
|
|
|
css::Declaration* aDeclaration)
|
2010-07-23 11:00:44 -07:00
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
if (!nsCSSProps::IsShorthand(aPropID)) {
|
|
|
|
return DoTransferFromBlock(aFromBlock, aPropID,
|
|
|
|
aIsImportant, aOverrideImportant,
|
|
|
|
aMustCallValueAppended, aDeclaration);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool changed = PR_FALSE;
|
2010-07-23 11:00:44 -07:00
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aPropID) {
|
2010-08-19 12:33:44 -07:00
|
|
|
changed |= DoTransferFromBlock(aFromBlock, *p,
|
|
|
|
aIsImportant, aOverrideImportant,
|
|
|
|
aMustCallValueAppended, aDeclaration);
|
2010-07-23 11:00:44 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
return changed;
|
2010-07-23 11:00:44 -07:00
|
|
|
}
|
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
PRBool
|
2010-07-23 11:00:44 -07:00
|
|
|
nsCSSExpandedDataBlock::DoTransferFromBlock(nsCSSExpandedDataBlock& aFromBlock,
|
|
|
|
nsCSSProperty aPropID,
|
|
|
|
PRBool aIsImportant,
|
|
|
|
PRBool aOverrideImportant,
|
|
|
|
PRBool aMustCallValueAppended,
|
2010-08-19 12:33:44 -07:00
|
|
|
css::Declaration* aDeclaration)
|
2010-07-23 11:00:44 -07:00
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
PRBool changed = PR_FALSE;
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(aFromBlock.HasPropertyBit(aPropID), "oops");
|
2010-07-23 11:00:44 -07:00
|
|
|
if (aIsImportant) {
|
|
|
|
if (!HasImportantBit(aPropID))
|
2010-08-19 12:33:44 -07:00
|
|
|
changed = PR_TRUE;
|
2010-07-23 11:00:44 -07:00
|
|
|
SetImportantBit(aPropID);
|
|
|
|
} else {
|
|
|
|
if (HasImportantBit(aPropID)) {
|
|
|
|
// When parsing a declaration block, an !important declaration
|
|
|
|
// is not overwritten by an ordinary declaration of the same
|
|
|
|
// property later in the block. However, CSSOM manipulations
|
|
|
|
// come through here too, and in that case we do want to
|
|
|
|
// overwrite the property.
|
|
|
|
if (!aOverrideImportant) {
|
|
|
|
aFromBlock.ClearLonghandProperty(aPropID);
|
2010-08-19 12:33:44 -07:00
|
|
|
return PR_FALSE;
|
2010-07-23 11:00:44 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
changed = PR_TRUE;
|
2010-07-23 11:00:44 -07:00
|
|
|
ClearImportantBit(aPropID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aMustCallValueAppended || !HasPropertyBit(aPropID)) {
|
|
|
|
aDeclaration->ValueAppended(aPropID);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetPropertyBit(aPropID);
|
|
|
|
aFromBlock.ClearPropertyBit(aPropID);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save needless copying and allocation by calling the destructor in
|
|
|
|
* the destination, copying memory directly, and then using placement
|
|
|
|
* new.
|
|
|
|
*/
|
2010-08-19 12:33:44 -07:00
|
|
|
changed |= MoveValue(aFromBlock.PropertyAt(aPropID), PropertyAt(aPropID));
|
2010-08-19 12:33:44 -07:00
|
|
|
return changed;
|
2010-07-23 11:00:44 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
nsCSSExpandedDataBlock::DoAssertInitialState()
|
|
|
|
{
|
2009-09-11 03:46:36 -07:00
|
|
|
mPropertiesSet.AssertIsEmpty("not initial state");
|
|
|
|
mPropertiesImportant.AssertIsEmpty("not initial state");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-11 03:46:36 -07:00
|
|
|
for (PRUint32 i = 0; i < eCSSProperty_COUNT_no_shorthands; ++i) {
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(PropertyAt(nsCSSProperty(i))->GetUnit() ==
|
|
|
|
eCSSUnit_Null, "not initial state");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|