2004-09-10 07:26:58 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2003-06-08 02:14:42 +04:00
|
|
|
|
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"
|
2010-07-23 22:00:44 +04:00
|
|
|
#include "mozilla/css/Declaration.h"
|
2004-07-20 10:11:27 +04:00
|
|
|
#include "nsRuleData.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
|
|
|
|
2010-07-23 22:00:44 +04:00
|
|
|
namespace css = mozilla::css;
|
|
|
|
|
2010-08-19 23:33:44 +04: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.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2010-08-19 23:33:44 +04:00
|
|
|
MoveValue(nsCSSValue* aSource, nsCSSValue* aDest)
|
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool changed = (*aSource != *aDest);
|
2010-08-19 23:33:44 +04:00
|
|
|
aDest->~nsCSSValue();
|
|
|
|
memcpy(aDest, aSource, sizeof(nsCSSValue));
|
|
|
|
new (aSource) nsCSSValue();
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2007-05-17 01:10:31 +04:00
|
|
|
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);
|
2012-04-07 21:36:49 +04:00
|
|
|
if (image.GetUnit() == eCSSUnit_URL)
|
|
|
|
image.StartImageLoad(aDocument);
|
2009-08-22 00:39:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-15 06:16:59 +03:00
|
|
|
static void
|
|
|
|
TryToStartImageLoad(const nsCSSValue& aValue, nsIDocument* aDocument,
|
|
|
|
nsCSSProperty aProperty)
|
|
|
|
{
|
2010-08-19 23:33:44 +04: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-15 06:16:59 +03:00
|
|
|
if (aValue.GetUnit() == eCSSUnit_Array) {
|
|
|
|
TryToStartImageLoadOnValue(aValue.GetArrayValue()->Item(0), aDocument);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
TryToStartImageLoadOnValue(aValue, aDocument);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static inline bool
|
2010-04-06 23:42:41 +04:00
|
|
|
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();
|
|
|
|
|
2012-03-19 12:39:15 +04:00
|
|
|
for (PRUint32 i = 0; i < mNumProps; i++) {
|
|
|
|
nsCSSProperty iProp = PropertyAtIndex(i);
|
2007-10-09 01:58:22 +04:00
|
|
|
if (nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[iProp]) &
|
|
|
|
aRuleData->mSIDs) {
|
2010-08-19 23:33:44 +04:00
|
|
|
nsCSSValue* target = aRuleData->ValueFor(iProp);
|
|
|
|
if (target->GetUnit() == eCSSUnit_Null) {
|
2012-03-19 12:39:15 +04:00
|
|
|
const nsCSSValue *val = ValueAtIndex(i);
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(val->GetUnit() != eCSSUnit_Null, "oops");
|
2010-08-19 23:33:44 +04:00
|
|
|
if (ShouldStartImageLoads(aRuleData, iProp)) {
|
|
|
|
TryToStartImageLoad(*val, doc, iProp);
|
|
|
|
}
|
|
|
|
*target = *val;
|
|
|
|
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-17 01:10:31 +04:00
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
} else {
|
|
|
|
// Ignore 'color', 'border-*-color', etc.
|
|
|
|
*target = nsCSSValue();
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-19 23:33:44 +04:00
|
|
|
const nsCSSValue*
|
|
|
|
nsCSSCompressedDataBlock::ValueFor(nsCSSProperty aProperty) const
|
2003-06-08 02:14:42 +04:00
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(aProperty),
|
|
|
|
"Don't call for shorthands");
|
2009-07-10 01:50:39 +04:00
|
|
|
|
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))
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2003-06-08 02:14:42 +04:00
|
|
|
|
2012-03-19 12:39:15 +04:00
|
|
|
for (PRUint32 i = 0; i < mNumProps; i++) {
|
|
|
|
if (PropertyAtIndex(i) == aProperty) {
|
|
|
|
return ValueAtIndex(i);
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-08-19 23:33:44 +04:00
|
|
|
nsCSSCompressedDataBlock::TryReplaceValue(nsCSSProperty aProperty,
|
|
|
|
nsCSSExpandedDataBlock& aFromBlock,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *aChanged)
|
2010-08-19 23:33:44 +04:00
|
|
|
{
|
|
|
|
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) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aChanged = false;
|
|
|
|
return false;
|
2010-08-19 23:33:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
*aChanged = MoveValue(newValue, const_cast<nsCSSValue*>(oldValue));
|
|
|
|
aFromBlock.ClearPropertyBit(aProperty);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-08-19 23:33:44 +04:00
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:52 +04:00
|
|
|
nsCSSCompressedDataBlock*
|
2003-06-08 02:14:42 +04:00
|
|
|
nsCSSCompressedDataBlock::Clone() const
|
|
|
|
{
|
2012-03-19 12:39:15 +04:00
|
|
|
nsAutoPtr<nsCSSCompressedDataBlock>
|
|
|
|
result(new(mNumProps) nsCSSCompressedDataBlock(mNumProps));
|
2003-06-08 02:14:42 +04:00
|
|
|
|
2012-03-19 12:39:15 +04:00
|
|
|
result->mStyleBits = mStyleBits;
|
2012-03-19 09:53:20 +04:00
|
|
|
|
2012-03-19 12:39:15 +04:00
|
|
|
for (PRUint32 i = 0; i < mNumProps; i++) {
|
|
|
|
result->SetPropertyAtIndex(i, PropertyAtIndex(i));
|
|
|
|
result->CopyValueToIndex(i, ValueAtIndex(i));
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
2009-12-11 19:13:19 +03:00
|
|
|
|
2010-07-23 22:00:52 +04:00
|
|
|
return result.forget();
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:52 +04:00
|
|
|
nsCSSCompressedDataBlock::~nsCSSCompressedDataBlock()
|
2003-06-08 02:14:42 +04:00
|
|
|
{
|
2012-03-19 12:39:15 +04:00
|
|
|
for (PRUint32 i = 0; i < mNumProps; i++) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
(void)PropertyAtIndex(i); // this checks the property is in range
|
|
|
|
#endif
|
|
|
|
const nsCSSValue* val = ValueAtIndex(i);
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(val->GetUnit() != eCSSUnit_Null, "oops");
|
2010-08-19 23:33:44 +04:00
|
|
|
val->~nsCSSValue();
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:52 +04:00
|
|
|
/* static */ nsCSSCompressedDataBlock*
|
2003-06-08 02:14:42 +04:00
|
|
|
nsCSSCompressedDataBlock::CreateEmptyBlock()
|
|
|
|
{
|
2012-03-19 12:39:15 +04:00
|
|
|
nsCSSCompressedDataBlock *result = new(0) nsCSSCompressedDataBlock(0);
|
2003-06-08 02:14:42 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-01-03 06:19:14 +04:00
|
|
|
size_t
|
|
|
|
nsCSSCompressedDataBlock::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
2012-03-19 12:39:15 +04:00
|
|
|
for (PRUint32 i = 0; i < mNumProps; i++) {
|
|
|
|
n += ValueAtIndex(i)->SizeOfExcludingThis(aMallocSizeOf);
|
2012-01-03 06:19:14 +04:00
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2012-05-31 09:19:49 +04:00
|
|
|
bool
|
|
|
|
nsCSSCompressedDataBlock::HasDefaultBorderImageSlice() const
|
|
|
|
{
|
|
|
|
const nsCSSValueList *slice =
|
|
|
|
ValueFor(eCSSProperty_border_image_slice)->GetListValue();
|
|
|
|
return !slice->mNext &&
|
|
|
|
slice->mValue.GetRectValue().AllSidesEqualTo(
|
|
|
|
nsCSSValue(1.0f, eCSSUnit_Percent));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsCSSCompressedDataBlock::HasDefaultBorderImageWidth() const
|
|
|
|
{
|
|
|
|
const nsCSSRect &width =
|
|
|
|
ValueFor(eCSSProperty_border_image_width)->GetRectValue();
|
|
|
|
return width.AllSidesEqualTo(nsCSSValue(1.0f, eCSSUnit_Number));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsCSSCompressedDataBlock::HasDefaultBorderImageOutset() const
|
|
|
|
{
|
|
|
|
const nsCSSRect &outset =
|
|
|
|
ValueFor(eCSSProperty_border_image_outset)->GetRectValue();
|
|
|
|
return outset.AllSidesEqualTo(nsCSSValue(0.0f, eCSSUnit_Number));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsCSSCompressedDataBlock::HasDefaultBorderImageRepeat() const
|
|
|
|
{
|
|
|
|
const nsCSSValuePair &repeat =
|
|
|
|
ValueFor(eCSSProperty_border_image_repeat)->GetPairValue();
|
|
|
|
return repeat.BothValuesEqualTo(
|
|
|
|
nsCSSValue(NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH, eCSSUnit_Enumerated));
|
|
|
|
}
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
nsCSSExpandedDataBlock::nsCSSExpandedDataBlock()
|
|
|
|
{
|
|
|
|
AssertInitialState();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSExpandedDataBlock::~nsCSSExpandedDataBlock()
|
|
|
|
{
|
|
|
|
AssertInitialState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-07-23 22:00:52 +04:00
|
|
|
nsCSSExpandedDataBlock::DoExpand(nsCSSCompressedDataBlock *aBlock,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aImportant)
|
2003-06-08 02:14:42 +04:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Save needless copying and allocation by copying the memory
|
2010-07-23 22:00:52 +04:00
|
|
|
* corresponding to the stored data in the compressed block.
|
2003-06-08 02:14:42 +04:00
|
|
|
*/
|
2012-03-19 12:39:15 +04:00
|
|
|
for (PRUint32 i = 0; i < aBlock->mNumProps; i++) {
|
|
|
|
nsCSSProperty iProp = aBlock->PropertyAtIndex(i);
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(iProp), "out of range");
|
|
|
|
NS_ABORT_IF_FALSE(!HasPropertyBit(iProp),
|
|
|
|
"compressed block has property multiple times");
|
2003-06-08 02:14:42 +04:00
|
|
|
SetPropertyBit(iProp);
|
|
|
|
if (aImportant)
|
|
|
|
SetImportantBit(iProp);
|
|
|
|
|
2012-03-19 12:39:15 +04:00
|
|
|
const nsCSSValue* val = aBlock->ValueAtIndex(i);
|
2010-08-19 23:33:44 +04:00
|
|
|
nsCSSValue* dest = PropertyAt(iProp);
|
2010-08-19 23:33:44 +04: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-28 10:47:32 +04:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
2010-08-19 23:33:44 +04:00
|
|
|
dest->~nsCSSValue();
|
2007-08-28 10:47:32 +04:00
|
|
|
#endif
|
2010-08-19 23:33:44 +04:00
|
|
|
memcpy(dest, val, sizeof(nsCSSValue));
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
2012-03-19 12:39:15 +04:00
|
|
|
// Set the number of properties to zero so that we don't destroy the
|
|
|
|
// remnants of what we just copied.
|
|
|
|
aBlock->SetNumPropsToZero();
|
2010-07-23 22:00:52 +04:00
|
|
|
delete aBlock;
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-07-23 22:00:52 +04:00
|
|
|
nsCSSExpandedDataBlock::Expand(nsCSSCompressedDataBlock *aNormalBlock,
|
|
|
|
nsCSSCompressedDataBlock *aImportantBlock)
|
2003-06-08 02:14:42 +04:00
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(aNormalBlock, "unexpected null block");
|
2003-06-08 02:14:42 +04:00
|
|
|
AssertInitialState();
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
DoExpand(aNormalBlock, false);
|
2010-07-23 22:00:52 +04:00
|
|
|
if (aImportantBlock) {
|
2011-10-17 18:59:28 +04:00
|
|
|
DoExpand(aImportantBlock, true);
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-19 12:39:15 +04:00
|
|
|
void
|
|
|
|
nsCSSExpandedDataBlock::ComputeNumProps(PRUint32* aNumPropsNormal,
|
|
|
|
PRUint32* aNumPropsImportant)
|
2003-06-08 02:14:42 +04:00
|
|
|
{
|
2012-03-19 12:39:15 +04:00
|
|
|
*aNumPropsNormal = *aNumPropsImportant = 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;
|
2011-06-22 20:00:56 +04:00
|
|
|
#ifdef DEBUG
|
2009-09-11 14:46:36 +04:00
|
|
|
nsCSSProperty iProp = nsCSSPropertySet::CSSPropertyAt(iHigh, iLow);
|
2011-06-22 20:00:56 +04:00
|
|
|
#endif
|
2010-08-19 23:33:44 +04: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 14:46:36 +04:00
|
|
|
if (mPropertiesImportant.HasPropertyAt(iHigh, iLow))
|
2012-03-19 12:39:15 +04:00
|
|
|
(*aNumPropsImportant)++;
|
2009-09-11 14:46:36 +04:00
|
|
|
else
|
2012-03-19 12:39:15 +04:00
|
|
|
(*aNumPropsNormal)++;
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSExpandedDataBlock::Compress(nsCSSCompressedDataBlock **aNormalBlock,
|
|
|
|
nsCSSCompressedDataBlock **aImportantBlock)
|
|
|
|
{
|
2010-07-23 22:00:52 +04:00
|
|
|
nsAutoPtr<nsCSSCompressedDataBlock> result_normal, result_important;
|
2012-03-19 12:39:15 +04:00
|
|
|
PRUint32 i_normal = 0, i_important = 0;
|
2003-06-08 02:14:42 +04:00
|
|
|
|
2012-03-19 12:39:15 +04:00
|
|
|
PRUint32 numPropsNormal, numPropsImportant;
|
|
|
|
ComputeNumProps(&numPropsNormal, &numPropsImportant);
|
2010-07-23 22:00:52 +04:00
|
|
|
|
2012-03-19 12:39:15 +04:00
|
|
|
result_normal =
|
|
|
|
new(numPropsNormal) nsCSSCompressedDataBlock(numPropsNormal);
|
2003-06-08 02:14:42 +04:00
|
|
|
|
2012-03-19 12:39:15 +04:00
|
|
|
if (numPropsImportant != 0) {
|
|
|
|
result_important =
|
|
|
|
new(numPropsImportant) nsCSSCompressedDataBlock(numPropsImportant);
|
2003-06-08 02:14:42 +04:00
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
result_important = nullptr;
|
2003-06-08 02:14:42 +04: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 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);
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(iProp), "out of range");
|
2011-09-29 10:19:26 +04:00
|
|
|
bool important =
|
2009-09-11 14:46:36 +04:00
|
|
|
mPropertiesImportant.HasPropertyAt(iHigh, iLow);
|
2003-06-08 02:14:42 +04:00
|
|
|
nsCSSCompressedDataBlock *result =
|
|
|
|
important ? result_important : result_normal;
|
2012-03-19 12:39:15 +04:00
|
|
|
PRUint32* ip = important ? &i_important : &i_normal;
|
2010-08-19 23:33:44 +04:00
|
|
|
nsCSSValue* val = PropertyAt(iProp);
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(val->GetUnit() != eCSSUnit_Null,
|
|
|
|
"Null value while compressing");
|
2012-03-19 12:39:15 +04:00
|
|
|
result->SetPropertyAtIndex(*ip, iProp);
|
|
|
|
result->RawCopyValueToIndex(*ip, val);
|
2010-08-19 23:33:44 +04:00
|
|
|
new (val) nsCSSValue();
|
2012-03-19 12:39:15 +04:00
|
|
|
(*ip)++;
|
2005-04-29 00:19:24 +04:00
|
|
|
result->mStyleBits |=
|
|
|
|
nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[iProp]);
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-19 12:39:15 +04:00
|
|
|
NS_ABORT_IF_FALSE(numPropsNormal == i_normal, "bad numProps");
|
2010-08-19 23:33:44 +04:00
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
if (result_important) {
|
2012-03-19 12:39:15 +04:00
|
|
|
NS_ABORT_IF_FALSE(numPropsImportant == i_important, "bad numProps");
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ClearSets();
|
|
|
|
AssertInitialState();
|
2010-07-23 22:00:52 +04:00
|
|
|
*aNormalBlock = result_normal.forget();
|
|
|
|
*aImportantBlock = result_important.forget();
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
2010-08-19 23:33:44 +04:00
|
|
|
void
|
|
|
|
nsCSSExpandedDataBlock::AddLonghandProperty(nsCSSProperty aProperty,
|
|
|
|
const nsCSSValue& aValue)
|
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(aProperty),
|
|
|
|
"property out of range");
|
2010-08-19 23:33:44 +04:00
|
|
|
nsCSSValue& storage = *static_cast<nsCSSValue*>(PropertyAt(aProperty));
|
|
|
|
storage = aValue;
|
|
|
|
SetPropertyBit(aProperty);
|
|
|
|
}
|
|
|
|
|
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);
|
2010-07-23 22:00:42 +04:00
|
|
|
ClearLonghandProperty(iProp);
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AssertInitialState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSExpandedDataBlock::ClearProperty(nsCSSProperty aPropID)
|
|
|
|
{
|
2010-07-23 22:00:42 +04:00
|
|
|
if (nsCSSProps::IsShorthand(aPropID)) {
|
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aPropID) {
|
|
|
|
ClearLonghandProperty(*p);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ClearLonghandProperty(aPropID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSExpandedDataBlock::ClearLonghandProperty(nsCSSProperty aPropID)
|
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(aPropID), "out of range");
|
2003-06-08 02:14:42 +04:00
|
|
|
|
|
|
|
ClearPropertyBit(aPropID);
|
|
|
|
ClearImportantBit(aPropID);
|
2010-08-19 23:33:44 +04:00
|
|
|
PropertyAt(aPropID)->Reset();
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-07-23 22:00:44 +04:00
|
|
|
nsCSSExpandedDataBlock::TransferFromBlock(nsCSSExpandedDataBlock& aFromBlock,
|
|
|
|
nsCSSProperty aPropID,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsImportant,
|
|
|
|
bool aOverrideImportant,
|
|
|
|
bool aMustCallValueAppended,
|
2010-08-19 23:33:44 +04:00
|
|
|
css::Declaration* aDeclaration)
|
2010-07-23 22:00:44 +04:00
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
if (!nsCSSProps::IsShorthand(aPropID)) {
|
|
|
|
return DoTransferFromBlock(aFromBlock, aPropID,
|
|
|
|
aIsImportant, aOverrideImportant,
|
|
|
|
aMustCallValueAppended, aDeclaration);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool changed = false;
|
2010-07-23 22:00:44 +04:00
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aPropID) {
|
2010-08-19 23:33:44 +04:00
|
|
|
changed |= DoTransferFromBlock(aFromBlock, *p,
|
|
|
|
aIsImportant, aOverrideImportant,
|
|
|
|
aMustCallValueAppended, aDeclaration);
|
2010-07-23 22:00:44 +04:00
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
return changed;
|
2010-07-23 22:00:44 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-07-23 22:00:44 +04:00
|
|
|
nsCSSExpandedDataBlock::DoTransferFromBlock(nsCSSExpandedDataBlock& aFromBlock,
|
|
|
|
nsCSSProperty aPropID,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsImportant,
|
|
|
|
bool aOverrideImportant,
|
|
|
|
bool aMustCallValueAppended,
|
2010-08-19 23:33:44 +04:00
|
|
|
css::Declaration* aDeclaration)
|
2010-07-23 22:00:44 +04:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool changed = false;
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(aFromBlock.HasPropertyBit(aPropID), "oops");
|
2010-07-23 22:00:44 +04:00
|
|
|
if (aIsImportant) {
|
|
|
|
if (!HasImportantBit(aPropID))
|
2011-10-17 18:59:28 +04:00
|
|
|
changed = true;
|
2010-07-23 22:00:44 +04: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);
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-07-23 22:00:44 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
changed = true;
|
2010-07-23 22:00:44 +04: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 23:33:44 +04:00
|
|
|
changed |= MoveValue(aFromBlock.PropertyAt(aPropID), PropertyAt(aPropID));
|
2010-08-19 23:33:44 +04:00
|
|
|
return changed;
|
2010-07-23 22:00:44 +04:00
|
|
|
}
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
#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) {
|
2011-03-18 07:58:26 +03:00
|
|
|
nsCSSProperty prop = nsCSSProperty(i);
|
2011-03-29 03:07:26 +04:00
|
|
|
NS_ABORT_IF_FALSE(PropertyAt(prop)->GetUnit() == eCSSUnit_Null,
|
2011-03-18 07:58:26 +03:00
|
|
|
"not initial state");
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|