2016-01-11 02:28:35 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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"
|
2015-03-26 10:29:31 +03:00
|
|
|
|
2015-08-27 04:19:38 +03:00
|
|
|
#include "CSSVariableImageTable.h"
|
2010-07-23 22:00:44 +04:00
|
|
|
#include "mozilla/css/Declaration.h"
|
2012-08-14 02:04:19 +04:00
|
|
|
#include "mozilla/css/ImageLoader.h"
|
2015-03-26 10:29:31 +03:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
|
|
|
#include "mozilla/WritingModes.h"
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2015-03-26 10:29:31 +03:00
|
|
|
#include "nsIDocument.h"
|
2004-07-20 10:11:27 +04:00
|
|
|
#include "nsRuleData.h"
|
2010-04-06 23:42:41 +04:00
|
|
|
#include "nsStyleContext.h"
|
2015-03-26 10:29:31 +03:00
|
|
|
#include "nsStyleSet.h"
|
2003-06-08 02:14:42 +04:00
|
|
|
|
2013-11-15 06:42:57 +04:00
|
|
|
using namespace mozilla;
|
2015-08-27 04:19:38 +03:00
|
|
|
using namespace mozilla::css;
|
2010-07-23 22:00:44 +04:00
|
|
|
|
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)
|
|
|
|
{
|
2016-01-11 02:28:35 +03:00
|
|
|
bool changed = (*aSource != *aDest);
|
|
|
|
aDest->~nsCSSValue();
|
|
|
|
memcpy(aDest, aSource, sizeof(nsCSSValue));
|
|
|
|
new (aSource) nsCSSValue();
|
|
|
|
return changed;
|
2010-08-19 23:33:44 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2007-05-17 01:10:31 +04:00
|
|
|
ShouldIgnoreColors(nsRuleData *aRuleData)
|
|
|
|
{
|
2016-01-11 02:28:35 +03:00
|
|
|
return aRuleData->mLevel != SheetType::Agent &&
|
|
|
|
aRuleData->mLevel != SheetType::User &&
|
|
|
|
!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
|
2014-03-18 13:11:14 +04:00
|
|
|
TryToStartImageLoadOnValue(const nsCSSValue& aValue, nsIDocument* aDocument,
|
2016-08-17 04:37:48 +03:00
|
|
|
nsStyleContext* aContext, nsCSSPropertyID aProperty,
|
2015-08-27 04:19:38 +03:00
|
|
|
bool aForTokenStream)
|
2009-08-22 00:39:25 +04:00
|
|
|
{
|
2012-08-14 02:04:19 +04:00
|
|
|
MOZ_ASSERT(aDocument);
|
|
|
|
|
2009-08-22 00:39:25 +04:00
|
|
|
if (aValue.GetUnit() == eCSSUnit_URL) {
|
2016-05-26 08:49:54 +03:00
|
|
|
#ifdef MOZ_ENABLE_MASK_AS_SHORTHAND
|
|
|
|
// The 'mask-image' property accepts local reference URIs.
|
|
|
|
// For example,
|
|
|
|
// mask-image: url(#mask_id); // refer to a SVG mask element, whose id is
|
|
|
|
// // "mask_id", in the current document.
|
|
|
|
// For such 'mask-image' values (pointing to an in-document element),
|
|
|
|
// there is no need to trigger image download.
|
|
|
|
if (aProperty == eCSSProperty_mask_image) {
|
2016-08-04 18:50:22 +03:00
|
|
|
// Filter out all fragment URLs.
|
|
|
|
// Since nsCSSValue::GetURLStructValue runs much faster than
|
|
|
|
// nsIURI::EqualsExceptRef bellow, we get performance gain by this
|
|
|
|
// early return.
|
|
|
|
URLValue* urlValue = aValue.GetURLStructValue();
|
2016-10-11 09:56:11 +03:00
|
|
|
if (urlValue->IsLocalRef()) {
|
2016-08-04 18:50:22 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Even though urlValue is not a fragment URL, it might still refer to
|
|
|
|
// an internal resource.
|
|
|
|
// For example, aDocument base URL is "http://foo/index.html" and
|
|
|
|
// intentionally references a mask-image at
|
|
|
|
// url(http://foo/index.html#mask) which still refers to a resource in
|
|
|
|
// aDocument.
|
2016-05-26 08:49:54 +03:00
|
|
|
nsIURI* imageURI = aValue.GetURLValue();
|
2016-06-24 19:52:20 +03:00
|
|
|
if (imageURI) {
|
2016-08-04 18:50:22 +03:00
|
|
|
nsIURI* docURI = aDocument->GetDocumentURI();
|
2016-06-24 19:52:20 +03:00
|
|
|
bool isEqualExceptRef = false;
|
|
|
|
nsresult rv = imageURI->EqualsExceptRef(docURI, &isEqualExceptRef);
|
|
|
|
if (NS_SUCCEEDED(rv) && isEqualExceptRef) {
|
|
|
|
return;
|
|
|
|
}
|
2016-05-26 08:49:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2009-08-22 00:39:25 +04:00
|
|
|
aValue.StartImageLoad(aDocument);
|
2015-08-27 04:19:38 +03:00
|
|
|
if (aForTokenStream && aContext) {
|
|
|
|
CSSVariableImageTable::Add(aContext, aProperty,
|
|
|
|
aValue.GetImageStructValue());
|
2014-03-18 13:11:14 +04:00
|
|
|
}
|
2009-08-22 00:39:25 +04:00
|
|
|
}
|
2012-08-14 02:04:19 +04:00
|
|
|
else if (aValue.GetUnit() == eCSSUnit_Image) {
|
|
|
|
// If we already have a request, see if this document needs to clone it.
|
2012-08-15 00:34:20 +04:00
|
|
|
imgIRequest* request = aValue.GetImageValue(nullptr);
|
2012-08-14 02:04:19 +04:00
|
|
|
|
|
|
|
if (request) {
|
2015-08-27 04:19:38 +03:00
|
|
|
ImageValue* imageValue = aValue.GetImageStructValue();
|
2014-03-18 13:11:14 +04:00
|
|
|
aDocument->StyleImageLoader()->MaybeRegisterCSSImage(imageValue);
|
2015-08-27 04:19:38 +03:00
|
|
|
if (aForTokenStream && aContext) {
|
|
|
|
CSSVariableImageTable::Add(aContext, aProperty, imageValue);
|
2014-03-18 13:11:14 +04:00
|
|
|
}
|
2012-08-14 02:04:19 +04:00
|
|
|
}
|
|
|
|
}
|
2009-08-22 00:39:25 +04:00
|
|
|
else if (aValue.EqualsFunction(eCSSKeyword__moz_image_rect)) {
|
|
|
|
nsCSSValue::Array* arguments = aValue.GetArrayValue();
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(arguments->Count() == 6, "unexpected num of arguments");
|
2009-08-22 00:39:25 +04:00
|
|
|
|
|
|
|
const nsCSSValue& image = arguments->Item(1);
|
2015-08-27 04:19:38 +03:00
|
|
|
TryToStartImageLoadOnValue(image, aDocument, aContext, aProperty,
|
|
|
|
aForTokenStream);
|
2009-08-22 00:39:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-15 06:16:59 +03:00
|
|
|
static void
|
|
|
|
TryToStartImageLoad(const nsCSSValue& aValue, nsIDocument* aDocument,
|
2016-08-17 04:37:48 +03:00
|
|
|
nsStyleContext* aContext, nsCSSPropertyID aProperty,
|
2015-08-27 04:19:38 +03:00
|
|
|
bool aForTokenStream)
|
2009-11-15 06:16:59 +03:00
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
if (aValue.GetUnit() == eCSSUnit_List) {
|
|
|
|
for (const nsCSSValueList* l = aValue.GetListValue(); l; l = l->mNext) {
|
2015-08-27 04:19:38 +03:00
|
|
|
TryToStartImageLoad(l->mValue, aDocument, aContext, aProperty,
|
|
|
|
aForTokenStream);
|
2010-08-19 23:33:44 +04:00
|
|
|
}
|
|
|
|
} 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) {
|
2014-03-18 13:11:14 +04:00
|
|
|
TryToStartImageLoadOnValue(aValue.GetArrayValue()->Item(0), aDocument,
|
2015-08-27 04:19:38 +03:00
|
|
|
aContext, aProperty, aForTokenStream);
|
2009-11-15 06:16:59 +03:00
|
|
|
}
|
|
|
|
} else {
|
2015-08-27 04:19:38 +03:00
|
|
|
TryToStartImageLoadOnValue(aValue, aDocument, aContext, aProperty,
|
|
|
|
aForTokenStream);
|
2009-11-15 06:16:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static inline bool
|
2016-08-17 04:37:48 +03:00
|
|
|
ShouldStartImageLoads(nsRuleData *aRuleData, nsCSSPropertyID aProperty)
|
2010-04-06 23:42:41 +04:00
|
|
|
{
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2013-12-12 06:09:43 +04:00
|
|
|
static void
|
2016-08-17 04:37:48 +03:00
|
|
|
MapSinglePropertyInto(nsCSSPropertyID aTargetProp,
|
2016-04-21 21:43:24 +03:00
|
|
|
const nsCSSValue* aSrcValue,
|
|
|
|
nsCSSValue* aTargetValue,
|
2013-12-12 06:09:43 +04:00
|
|
|
nsRuleData* aRuleData)
|
|
|
|
{
|
2016-04-21 21:43:26 +03:00
|
|
|
MOZ_ASSERT(!nsCSSProps::PropHasFlags(aTargetProp, CSS_PROPERTY_LOGICAL),
|
|
|
|
"Can't map into a logical property");
|
2016-04-21 21:43:24 +03:00
|
|
|
MOZ_ASSERT(aSrcValue->GetUnit() != eCSSUnit_Null, "oops");
|
2015-12-31 10:36:31 +03:00
|
|
|
|
2016-04-21 21:43:24 +03:00
|
|
|
// Although aTargetValue is the nsCSSValue we are going to write into,
|
2016-01-11 02:28:35 +03:00
|
|
|
// we also look at its value before writing into it. This is done
|
2016-04-21 21:43:24 +03:00
|
|
|
// when aTargetValue is a token stream value, which is the case when we
|
2016-01-11 02:28:35 +03:00
|
|
|
// have just re-parsed a property that had a variable reference (in
|
|
|
|
// nsCSSParser::ParsePropertyWithVariableReferences). TryToStartImageLoad
|
|
|
|
// then records any resulting ImageValue objects in the
|
|
|
|
// CSSVariableImageTable, to give them the appropriate lifetime.
|
2016-04-21 21:43:24 +03:00
|
|
|
MOZ_ASSERT(aTargetValue->GetUnit() == eCSSUnit_TokenStream ||
|
|
|
|
aTargetValue->GetUnit() == eCSSUnit_Null,
|
|
|
|
"aTargetValue must only be a token stream (when re-parsing "
|
2016-01-11 02:28:35 +03:00
|
|
|
"properties with variable references) or null");
|
|
|
|
|
2016-04-21 21:43:24 +03:00
|
|
|
if (ShouldStartImageLoads(aRuleData, aTargetProp)) {
|
2016-01-11 02:28:35 +03:00
|
|
|
nsIDocument* doc = aRuleData->mPresContext->Document();
|
2016-04-21 21:43:24 +03:00
|
|
|
TryToStartImageLoad(*aSrcValue, doc, aRuleData->mStyleContext,
|
|
|
|
aTargetProp,
|
|
|
|
aTargetValue->GetUnit() == eCSSUnit_TokenStream);
|
2016-01-11 02:28:35 +03:00
|
|
|
}
|
2016-04-21 21:43:24 +03:00
|
|
|
*aTargetValue = *aSrcValue;
|
|
|
|
if (nsCSSProps::PropHasFlags(aTargetProp,
|
2016-01-11 02:28:35 +03:00
|
|
|
CSS_PROPERTY_IGNORED_WHEN_COLORS_DISABLED) &&
|
|
|
|
ShouldIgnoreColors(aRuleData))
|
|
|
|
{
|
2016-04-21 21:43:24 +03:00
|
|
|
if (aTargetProp == eCSSProperty_background_color) {
|
2016-01-11 02:28:35 +03:00
|
|
|
// Force non-'transparent' background
|
|
|
|
// colors to the user's default.
|
2016-04-21 21:43:24 +03:00
|
|
|
if (aTargetValue->IsNonTransparentColor()) {
|
|
|
|
aTargetValue->SetColorValue(aRuleData->mPresContext->
|
|
|
|
DefaultBackgroundColor());
|
2016-01-11 02:28:35 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Ignore 'color', 'border-*-color', etc.
|
2016-04-21 21:43:24 +03:00
|
|
|
*aTargetValue = nsCSSValue();
|
2013-12-12 06:09:43 +04:00
|
|
|
}
|
2016-01-11 02:28:35 +03:00
|
|
|
}
|
2013-12-12 06:09:43 +04:00
|
|
|
}
|
|
|
|
|
2015-01-17 07:16:01 +03:00
|
|
|
/**
|
2016-04-21 02:43:24 +03:00
|
|
|
* If aProperty is a logical property, converts it to the equivalent physical
|
2015-01-17 07:16:01 +03:00
|
|
|
* property based on writing mode information obtained from aRuleData's
|
|
|
|
* style context.
|
|
|
|
*/
|
2016-04-21 02:43:24 +03:00
|
|
|
static inline void
|
2016-08-17 04:37:48 +03:00
|
|
|
EnsurePhysicalProperty(nsCSSPropertyID& aProperty, nsRuleData* aRuleData)
|
2015-01-17 07:16:01 +03:00
|
|
|
{
|
2015-01-17 07:43:20 +03:00
|
|
|
bool isAxisProperty =
|
|
|
|
nsCSSProps::PropHasFlags(aProperty, CSS_PROPERTY_LOGICAL_AXIS);
|
2015-01-17 07:22:51 +03:00
|
|
|
bool isBlock =
|
|
|
|
nsCSSProps::PropHasFlags(aProperty, CSS_PROPERTY_LOGICAL_BLOCK_AXIS);
|
|
|
|
|
2015-01-17 07:43:20 +03:00
|
|
|
int index;
|
2015-01-17 07:22:51 +03:00
|
|
|
|
2016-04-21 02:43:24 +03:00
|
|
|
if (isAxisProperty) {
|
2015-01-17 07:43:20 +03:00
|
|
|
LogicalAxis logicalAxis = isBlock ? eLogicalAxisBlock : eLogicalAxisInline;
|
2015-01-17 07:22:51 +03:00
|
|
|
uint8_t wm = aRuleData->mStyleContext->StyleVisibility()->mWritingMode;
|
2015-01-17 07:43:20 +03:00
|
|
|
PhysicalAxis axis =
|
|
|
|
WritingMode::PhysicalAxisForLogicalAxis(wm, logicalAxis);
|
|
|
|
|
|
|
|
// We rely on physical axis constants values matching the order of the
|
|
|
|
// physical properties in the logical group array.
|
|
|
|
static_assert(eAxisVertical == 0 && eAxisHorizontal == 1,
|
|
|
|
"unexpected axis constant values");
|
|
|
|
index = axis;
|
2015-01-17 07:22:51 +03:00
|
|
|
} else {
|
2015-01-17 07:43:20 +03:00
|
|
|
bool isEnd =
|
|
|
|
nsCSSProps::PropHasFlags(aProperty, CSS_PROPERTY_LOGICAL_END_EDGE);
|
|
|
|
|
|
|
|
LogicalEdge edge = isEnd ? eLogicalEdgeEnd : eLogicalEdgeStart;
|
|
|
|
|
|
|
|
// We handle block axis logical properties separately to save a bit of
|
|
|
|
// work that the WritingMode constructor does that is unnecessary
|
|
|
|
// unless we have an inline axis property.
|
|
|
|
mozilla::css::Side side;
|
|
|
|
if (isBlock) {
|
|
|
|
uint8_t wm = aRuleData->mStyleContext->StyleVisibility()->mWritingMode;
|
|
|
|
side = WritingMode::PhysicalSideForBlockAxis(wm, edge);
|
|
|
|
} else {
|
|
|
|
WritingMode wm(aRuleData->mStyleContext);
|
|
|
|
side = wm.PhysicalSideForInlineAxis(edge);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We rely on the physical side constant values matching the order of
|
|
|
|
// the physical properties in the logical group array.
|
|
|
|
static_assert(NS_SIDE_TOP == 0 && NS_SIDE_RIGHT == 1 &&
|
|
|
|
NS_SIDE_BOTTOM == 2 && NS_SIDE_LEFT == 3,
|
|
|
|
"unexpected side constant values");
|
|
|
|
index = side;
|
2015-01-17 07:16:01 +03:00
|
|
|
}
|
2015-01-17 07:22:51 +03:00
|
|
|
|
2016-08-17 04:37:48 +03:00
|
|
|
const nsCSSPropertyID* props = nsCSSProps::LogicalGroup(aProperty);
|
2016-04-21 02:43:24 +03:00
|
|
|
size_t len = isAxisProperty ? 2 : 4;
|
2015-01-17 07:43:20 +03:00
|
|
|
#ifdef DEBUG
|
2016-04-21 02:43:24 +03:00
|
|
|
for (size_t i = 0; i < len; i++) {
|
2016-03-14 20:27:05 +03:00
|
|
|
MOZ_ASSERT(props[i] != eCSSProperty_UNKNOWN,
|
2015-01-17 07:43:20 +03:00
|
|
|
"unexpected logical group length");
|
|
|
|
}
|
2016-03-14 20:27:05 +03:00
|
|
|
MOZ_ASSERT(props[len] == eCSSProperty_UNKNOWN,
|
|
|
|
"unexpected logical group length");
|
2015-01-17 07:43:20 +03:00
|
|
|
#endif
|
2016-03-14 20:27:05 +03:00
|
|
|
|
|
|
|
for (size_t i = 0; i < len; i++) {
|
|
|
|
if (aRuleData->ValueFor(props[i])->GetUnit() == eCSSUnit_Null) {
|
|
|
|
// A declaration of one of the logical properties in this logical
|
|
|
|
// group (but maybe not aProperty) would be the winning
|
|
|
|
// declaration in the cascade. This means that it's reasonably
|
|
|
|
// likely that this logical property could be the winning
|
|
|
|
// declaration in the cascade for some values of writing-mode,
|
|
|
|
// direction, and text-orientation. (It doesn't mean that for
|
|
|
|
// sure, though. For example, if this is a block-start logical
|
|
|
|
// property, and all but the bottom physical property were set.
|
|
|
|
// But the common case we want to hit here is logical declarations
|
|
|
|
// that are completely overridden by a shorthand.)
|
|
|
|
//
|
|
|
|
// If this logical property could be the winning declaration in
|
|
|
|
// the cascade for some values of writing-mode, direction, and
|
|
|
|
// text-orientation, then we have to fault the resulting style
|
|
|
|
// struct out of the rule tree. We can't cache anything on the
|
|
|
|
// rule tree if it depends on data from the style context, since
|
|
|
|
// data cached in the rule tree could be used with a style context
|
|
|
|
// with a different value of the depended-upon data.
|
|
|
|
uint8_t wm = WritingMode(aRuleData->mStyleContext).GetBits();
|
|
|
|
aRuleData->mConditions.SetWritingModeDependency(wm);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-21 02:43:24 +03:00
|
|
|
aProperty = props[index];
|
2015-01-17 07:16:01 +03:00
|
|
|
}
|
|
|
|
|
2010-05-20 06:28:00 +04:00
|
|
|
void
|
2003-06-08 02:14:42 +04:00
|
|
|
nsCSSCompressedDataBlock::MapRuleInfoInto(nsRuleData *aRuleData) const
|
|
|
|
{
|
2016-01-11 02:28:35 +03:00
|
|
|
// If we have no data for these structs, 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 (!(aRuleData->mSIDs & mStyleBits))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// We process these in reverse order so that we end up mapping the
|
|
|
|
// right property when one can be expressed using both logical and
|
|
|
|
// physical property names.
|
|
|
|
for (uint32_t i = mNumProps; i-- > 0; ) {
|
2016-08-17 04:37:48 +03:00
|
|
|
nsCSSPropertyID iProp = PropertyAtIndex(i);
|
2016-01-11 02:28:35 +03:00
|
|
|
if (nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[iProp]) &
|
|
|
|
aRuleData->mSIDs) {
|
2016-04-21 02:43:24 +03:00
|
|
|
if (nsCSSProps::PropHasFlags(iProp, CSS_PROPERTY_LOGICAL)) {
|
|
|
|
EnsurePhysicalProperty(iProp, aRuleData);
|
|
|
|
}
|
|
|
|
nsCSSValue* target = aRuleData->ValueFor(iProp);
|
2016-01-11 02:28:35 +03:00
|
|
|
if (target->GetUnit() == eCSSUnit_Null) {
|
|
|
|
const nsCSSValue *val = ValueAtIndex(i);
|
|
|
|
// In order for variable resolution to have the right information
|
|
|
|
// about the stylesheet level of a value, that level needs to be
|
|
|
|
// stored on the token stream. We can't do that at creation time
|
|
|
|
// because the CSS parser (which creates the object) has no idea
|
|
|
|
// about the stylesheet level, so we do it here instead, where
|
|
|
|
// the rule walking will have just updated aRuleData.
|
|
|
|
if (val->GetUnit() == eCSSUnit_TokenStream) {
|
|
|
|
val->GetTokenStreamValue()->mLevel = aRuleData->mLevel;
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
2016-04-21 02:43:24 +03:00
|
|
|
MapSinglePropertyInto(iProp, val, target, aRuleData);
|
2016-01-11 02:28:35 +03:00
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
2016-01-11 02:28:35 +03:00
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
2010-08-19 23:33:44 +04:00
|
|
|
const nsCSSValue*
|
2016-08-17 04:37:48 +03:00
|
|
|
nsCSSCompressedDataBlock::ValueFor(nsCSSPropertyID aProperty) const
|
2003-06-08 02:14:42 +04:00
|
|
|
{
|
2016-01-11 02:28:35 +03:00
|
|
|
MOZ_ASSERT(!nsCSSProps::IsShorthand(aProperty),
|
|
|
|
"Don't call for shorthands");
|
2009-07-10 01:50:39 +04:00
|
|
|
|
2016-01-11 02:28:35 +03: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 nullptr;
|
2003-06-08 02:14:42 +04:00
|
|
|
|
2016-01-11 02:28:35 +03:00
|
|
|
for (uint32_t i = 0; i < mNumProps; i++) {
|
|
|
|
if (PropertyAtIndex(i) == aProperty) {
|
|
|
|
return ValueAtIndex(i);
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
2016-01-11 02:28:35 +03:00
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
|
2016-01-11 02:28:35 +03:00
|
|
|
return nullptr;
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2016-08-17 04:37:48 +03:00
|
|
|
nsCSSCompressedDataBlock::TryReplaceValue(nsCSSPropertyID aProperty,
|
2010-08-19 23:33:44 +04:00
|
|
|
nsCSSExpandedDataBlock& aFromBlock,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *aChanged)
|
2010-08-19 23:33:44 +04:00
|
|
|
{
|
2016-01-11 02:28:35 +03:00
|
|
|
nsCSSValue* newValue = aFromBlock.PropertyAt(aProperty);
|
|
|
|
MOZ_ASSERT(newValue && newValue->GetUnit() != eCSSUnit_Null,
|
|
|
|
"cannot replace with empty value");
|
2010-08-19 23:33:44 +04:00
|
|
|
|
2016-01-11 02:28:35 +03:00
|
|
|
const nsCSSValue* oldValue = ValueFor(aProperty);
|
|
|
|
if (!oldValue) {
|
|
|
|
*aChanged = false;
|
|
|
|
return false;
|
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
|
2016-01-11 02:28:35 +03:00
|
|
|
*aChanged = MoveValue(newValue, const_cast<nsCSSValue*>(oldValue));
|
|
|
|
aFromBlock.ClearPropertyBit(aProperty);
|
|
|
|
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
|
|
|
|
{
|
2016-01-11 02:28:35 +03:00
|
|
|
nsAutoPtr<nsCSSCompressedDataBlock>
|
|
|
|
result(new(mNumProps) nsCSSCompressedDataBlock(mNumProps));
|
2003-06-08 02:14:42 +04:00
|
|
|
|
2016-01-11 02:28:35 +03:00
|
|
|
result->mStyleBits = mStyleBits;
|
2012-03-19 09:53:20 +04:00
|
|
|
|
2016-01-11 02:28:35 +03:00
|
|
|
for (uint32_t i = 0; i < mNumProps; i++) {
|
|
|
|
result->SetPropertyAtIndex(i, PropertyAtIndex(i));
|
|
|
|
result->CopyValueToIndex(i, ValueAtIndex(i));
|
|
|
|
}
|
2009-12-11 19:13:19 +03:00
|
|
|
|
2016-01-11 02:28:35 +03: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
|
|
|
{
|
2016-01-11 02:28:35 +03:00
|
|
|
for (uint32_t i = 0; i < mNumProps; i++) {
|
2012-03-19 12:39:15 +04:00
|
|
|
#ifdef DEBUG
|
2016-01-11 02:28:35 +03:00
|
|
|
(void)PropertyAtIndex(i); // this checks the property is in range
|
2012-03-19 12:39:15 +04:00
|
|
|
#endif
|
2016-01-11 02:28:35 +03:00
|
|
|
const nsCSSValue* val = ValueAtIndex(i);
|
|
|
|
MOZ_ASSERT(val->GetUnit() != eCSSUnit_Null, "oops");
|
|
|
|
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()
|
|
|
|
{
|
2016-01-11 02:28:35 +03:00
|
|
|
nsCSSCompressedDataBlock *result = new(0) nsCSSCompressedDataBlock(0);
|
|
|
|
return result;
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
2012-01-03 06:19:14 +04:00
|
|
|
size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
nsCSSCompressedDataBlock::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 06:19:14 +04:00
|
|
|
{
|
2016-01-11 02:28:35 +03:00
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
for (uint32_t i = 0; i < mNumProps; i++) {
|
|
|
|
n += ValueAtIndex(i)->SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
return n;
|
2012-01-03 06:19:14 +04:00
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2016-01-11 02:28:35 +03:00
|
|
|
AssertInitialState();
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSExpandedDataBlock::~nsCSSExpandedDataBlock()
|
|
|
|
{
|
2016-01-11 02:28:35 +03:00
|
|
|
AssertInitialState();
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2016-01-11 02:28:35 +03:00
|
|
|
/*
|
|
|
|
* Save needless copying and allocation by copying the memory
|
|
|
|
* corresponding to the stored data in the compressed block.
|
|
|
|
*/
|
|
|
|
for (uint32_t i = 0; i < aBlock->mNumProps; i++) {
|
2016-08-17 04:37:48 +03:00
|
|
|
nsCSSPropertyID iProp = aBlock->PropertyAtIndex(i);
|
2016-01-11 02:28:35 +03:00
|
|
|
MOZ_ASSERT(!nsCSSProps::IsShorthand(iProp), "out of range");
|
|
|
|
MOZ_ASSERT(!HasPropertyBit(iProp),
|
|
|
|
"compressed block has property multiple times");
|
|
|
|
SetPropertyBit(iProp);
|
|
|
|
if (aImportant)
|
|
|
|
SetImportantBit(iProp);
|
|
|
|
|
|
|
|
const nsCSSValue* val = aBlock->ValueAtIndex(i);
|
|
|
|
nsCSSValue* dest = PropertyAt(iProp);
|
|
|
|
MOZ_ASSERT(val->GetUnit() != eCSSUnit_Null, "oops");
|
|
|
|
MOZ_ASSERT(dest->GetUnit() == eCSSUnit_Null,
|
|
|
|
"expanding into non-empty block");
|
2007-08-28 10:47:32 +04:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
2016-01-11 02:28:35 +03:00
|
|
|
dest->~nsCSSValue();
|
2007-08-28 10:47:32 +04:00
|
|
|
#endif
|
2016-01-11 02:28:35 +03:00
|
|
|
memcpy(dest, val, sizeof(nsCSSValue));
|
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
|
2016-01-11 02:28:35 +03:00
|
|
|
// Set the number of properties to zero so that we don't destroy the
|
|
|
|
// remnants of what we just copied.
|
|
|
|
aBlock->SetNumPropsToZero();
|
|
|
|
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
|
|
|
{
|
2016-01-11 02:28:35 +03:00
|
|
|
MOZ_ASSERT(aNormalBlock, "unexpected null block");
|
|
|
|
AssertInitialState();
|
2003-06-08 02:14:42 +04:00
|
|
|
|
2016-01-11 02:28:35 +03:00
|
|
|
DoExpand(aNormalBlock, false);
|
|
|
|
if (aImportantBlock) {
|
|
|
|
DoExpand(aImportantBlock, true);
|
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
2012-03-19 12:39:15 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsCSSExpandedDataBlock::ComputeNumProps(uint32_t* aNumPropsNormal,
|
|
|
|
uint32_t* aNumPropsImportant)
|
2003-06-08 02:14:42 +04:00
|
|
|
{
|
2016-01-11 02:28:35 +03:00
|
|
|
*aNumPropsNormal = *aNumPropsImportant = 0;
|
2016-08-17 04:46:58 +03:00
|
|
|
for (size_t iHigh = 0; iHigh < nsCSSPropertyIDSet::kChunkCount; ++iHigh) {
|
2016-01-11 02:28:35 +03:00
|
|
|
if (!mPropertiesSet.HasPropertyInChunk(iHigh))
|
|
|
|
continue;
|
2016-08-17 04:46:58 +03:00
|
|
|
for (size_t iLow = 0; iLow < nsCSSPropertyIDSet::kBitsInChunk; ++iLow) {
|
2016-01-11 02:28:35 +03:00
|
|
|
if (!mPropertiesSet.HasPropertyAt(iHigh, iLow))
|
|
|
|
continue;
|
2011-06-22 20:00:56 +04:00
|
|
|
#ifdef DEBUG
|
2016-08-17 04:46:58 +03:00
|
|
|
nsCSSPropertyID iProp = nsCSSPropertyIDSet::CSSPropertyAt(iHigh, iLow);
|
2011-06-22 20:00:56 +04:00
|
|
|
#endif
|
2016-01-11 02:28:35 +03:00
|
|
|
MOZ_ASSERT(!nsCSSProps::IsShorthand(iProp), "out of range");
|
|
|
|
MOZ_ASSERT(PropertyAt(iProp)->GetUnit() != eCSSUnit_Null,
|
|
|
|
"null value while computing size");
|
|
|
|
if (mPropertiesImportant.HasPropertyAt(iHigh, iLow))
|
|
|
|
(*aNumPropsImportant)++;
|
|
|
|
else
|
|
|
|
(*aNumPropsNormal)++;
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
2016-01-11 02:28:35 +03:00
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSExpandedDataBlock::Compress(nsCSSCompressedDataBlock **aNormalBlock,
|
2014-12-19 06:32:34 +03:00
|
|
|
nsCSSCompressedDataBlock **aImportantBlock,
|
|
|
|
const nsTArray<uint32_t>& aOrder)
|
2003-06-08 02:14:42 +04:00
|
|
|
{
|
2016-01-11 02:28:35 +03:00
|
|
|
nsAutoPtr<nsCSSCompressedDataBlock> result_normal, result_important;
|
|
|
|
uint32_t i_normal = 0, i_important = 0;
|
2003-06-08 02:14:42 +04:00
|
|
|
|
2016-01-11 02:28:35 +03:00
|
|
|
uint32_t numPropsNormal, numPropsImportant;
|
|
|
|
ComputeNumProps(&numPropsNormal, &numPropsImportant);
|
2010-07-23 22:00:52 +04:00
|
|
|
|
2016-01-11 02:28:35 +03:00
|
|
|
result_normal =
|
|
|
|
new(numPropsNormal) nsCSSCompressedDataBlock(numPropsNormal);
|
2003-06-08 02:14:42 +04:00
|
|
|
|
2016-01-11 02:28:35 +03:00
|
|
|
if (numPropsImportant != 0) {
|
|
|
|
result_important =
|
|
|
|
new(numPropsImportant) nsCSSCompressedDataBlock(numPropsImportant);
|
|
|
|
} else {
|
|
|
|
result_important = nullptr;
|
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
|
2016-01-11 02:28:35 +03: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.
|
|
|
|
*/
|
|
|
|
for (size_t i = 0; i < aOrder.Length(); i++) {
|
2016-08-17 04:37:48 +03:00
|
|
|
nsCSSPropertyID iProp = static_cast<nsCSSPropertyID>(aOrder[i]);
|
2016-01-11 02:28:35 +03:00
|
|
|
if (iProp >= eCSSProperty_COUNT) {
|
|
|
|
// a custom property
|
|
|
|
continue;
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
2016-01-11 02:28:35 +03:00
|
|
|
MOZ_ASSERT(mPropertiesSet.HasProperty(iProp),
|
|
|
|
"aOrder identifies a property not in the expanded "
|
|
|
|
"data block");
|
|
|
|
MOZ_ASSERT(!nsCSSProps::IsShorthand(iProp), "out of range");
|
|
|
|
bool important = mPropertiesImportant.HasProperty(iProp);
|
|
|
|
nsCSSCompressedDataBlock *result =
|
|
|
|
important ? result_important : result_normal;
|
|
|
|
uint32_t* ip = important ? &i_important : &i_normal;
|
|
|
|
nsCSSValue* val = PropertyAt(iProp);
|
|
|
|
MOZ_ASSERT(val->GetUnit() != eCSSUnit_Null,
|
|
|
|
"Null value while compressing");
|
|
|
|
result->SetPropertyAtIndex(*ip, iProp);
|
|
|
|
result->RawCopyValueToIndex(*ip, val);
|
|
|
|
new (val) nsCSSValue();
|
|
|
|
(*ip)++;
|
|
|
|
result->mStyleBits |=
|
|
|
|
nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[iProp]);
|
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
|
2016-01-11 02:28:35 +03:00
|
|
|
MOZ_ASSERT(numPropsNormal == i_normal, "bad numProps");
|
2010-08-19 23:33:44 +04:00
|
|
|
|
2016-01-11 02:28:35 +03:00
|
|
|
if (result_important) {
|
|
|
|
MOZ_ASSERT(numPropsImportant == i_important, "bad numProps");
|
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
|
2014-12-19 06:32:34 +03:00
|
|
|
#ifdef DEBUG
|
2016-01-11 02:28:35 +03:00
|
|
|
{
|
|
|
|
// assert that we didn't have any other properties on this expanded data
|
|
|
|
// block that we didn't find in aOrder
|
|
|
|
uint32_t numPropsInSet = 0;
|
2016-08-17 04:46:58 +03:00
|
|
|
for (size_t iHigh = 0; iHigh < nsCSSPropertyIDSet::kChunkCount; iHigh++) {
|
2016-01-11 02:28:35 +03:00
|
|
|
if (!mPropertiesSet.HasPropertyInChunk(iHigh)) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-08-17 04:46:58 +03:00
|
|
|
for (size_t iLow = 0; iLow < nsCSSPropertyIDSet::kBitsInChunk; iLow++) {
|
2016-01-11 02:28:35 +03:00
|
|
|
if (mPropertiesSet.HasPropertyAt(iHigh, iLow)) {
|
|
|
|
numPropsInSet++;
|
|
|
|
}
|
2014-12-19 06:32:34 +03:00
|
|
|
}
|
|
|
|
}
|
2016-01-11 02:28:35 +03:00
|
|
|
MOZ_ASSERT(numPropsNormal + numPropsImportant == numPropsInSet,
|
|
|
|
"aOrder missing properties from the expanded data block");
|
|
|
|
}
|
2014-12-19 06:32:34 +03:00
|
|
|
#endif
|
|
|
|
|
2016-01-11 02:28:35 +03:00
|
|
|
ClearSets();
|
|
|
|
AssertInitialState();
|
|
|
|
*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
|
2016-08-17 04:37:48 +03:00
|
|
|
nsCSSExpandedDataBlock::AddLonghandProperty(nsCSSPropertyID aProperty,
|
2010-08-19 23:33:44 +04:00
|
|
|
const nsCSSValue& aValue)
|
|
|
|
{
|
2016-01-11 02:28:35 +03:00
|
|
|
MOZ_ASSERT(!nsCSSProps::IsShorthand(aProperty),
|
|
|
|
"property out of range");
|
|
|
|
nsCSSValue& storage = *static_cast<nsCSSValue*>(PropertyAt(aProperty));
|
|
|
|
storage = aValue;
|
|
|
|
SetPropertyBit(aProperty);
|
2010-08-19 23:33:44 +04:00
|
|
|
}
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
void
|
|
|
|
nsCSSExpandedDataBlock::Clear()
|
|
|
|
{
|
2016-08-17 04:46:58 +03:00
|
|
|
for (size_t iHigh = 0; iHigh < nsCSSPropertyIDSet::kChunkCount; ++iHigh) {
|
2016-01-11 02:28:35 +03:00
|
|
|
if (!mPropertiesSet.HasPropertyInChunk(iHigh))
|
|
|
|
continue;
|
2016-08-17 04:46:58 +03:00
|
|
|
for (size_t iLow = 0; iLow < nsCSSPropertyIDSet::kBitsInChunk; ++iLow) {
|
2016-01-11 02:28:35 +03:00
|
|
|
if (!mPropertiesSet.HasPropertyAt(iHigh, iLow))
|
|
|
|
continue;
|
2016-08-17 04:46:58 +03:00
|
|
|
nsCSSPropertyID iProp = nsCSSPropertyIDSet::CSSPropertyAt(iHigh, iLow);
|
2016-01-11 02:28:35 +03:00
|
|
|
ClearLonghandProperty(iProp);
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
2016-01-11 02:28:35 +03:00
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
|
2016-01-11 02:28:35 +03:00
|
|
|
AssertInitialState();
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-17 04:37:48 +03:00
|
|
|
nsCSSExpandedDataBlock::ClearProperty(nsCSSPropertyID aPropID)
|
2003-06-08 02:14:42 +04:00
|
|
|
{
|
2010-07-23 22:00:42 +04:00
|
|
|
if (nsCSSProps::IsShorthand(aPropID)) {
|
2016-05-10 11:44:05 +03:00
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(
|
|
|
|
p, aPropID, CSSEnabledState::eIgnoreEnabledState) {
|
2010-07-23 22:00:42 +04:00
|
|
|
ClearLonghandProperty(*p);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ClearLonghandProperty(aPropID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-17 04:37:48 +03:00
|
|
|
nsCSSExpandedDataBlock::ClearLonghandProperty(nsCSSPropertyID aPropID)
|
2010-07-23 22:00:42 +04:00
|
|
|
{
|
2016-01-11 02:28:35 +03:00
|
|
|
MOZ_ASSERT(!nsCSSProps::IsShorthand(aPropID), "out of range");
|
2003-06-08 02:14:42 +04:00
|
|
|
|
2016-01-11 02:28:35 +03:00
|
|
|
ClearPropertyBit(aPropID);
|
|
|
|
ClearImportantBit(aPropID);
|
|
|
|
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,
|
2016-08-17 04:37:48 +03:00
|
|
|
nsCSSPropertyID aPropID,
|
2016-05-10 11:44:05 +03:00
|
|
|
CSSEnabledState aEnabledState,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsImportant,
|
|
|
|
bool aOverrideImportant,
|
|
|
|
bool aMustCallValueAppended,
|
2015-06-03 22:21:24 +03:00
|
|
|
css::Declaration* aDeclaration,
|
|
|
|
nsIDocument* aSheetDocument)
|
2010-07-23 22:00:44 +04:00
|
|
|
{
|
2016-01-11 02:28:35 +03:00
|
|
|
if (!nsCSSProps::IsShorthand(aPropID)) {
|
|
|
|
return DoTransferFromBlock(aFromBlock, aPropID,
|
|
|
|
aIsImportant, aOverrideImportant,
|
|
|
|
aMustCallValueAppended, aDeclaration,
|
|
|
|
aSheetDocument);
|
|
|
|
}
|
|
|
|
|
2016-05-10 11:44:05 +03:00
|
|
|
// We can pass CSSEnabledState::eIgnore (here, and in ClearProperty
|
|
|
|
// above) rather than a value corresponding to whether we're parsing
|
|
|
|
// a UA style sheet or certified app because we assert in nsCSSProps::
|
|
|
|
// AddRefTable that shorthand properties available in these contexts
|
|
|
|
// also have all of their subproperties available in these contexts.
|
2016-01-11 02:28:35 +03:00
|
|
|
bool changed = false;
|
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aPropID, aEnabledState) {
|
|
|
|
changed |= DoTransferFromBlock(aFromBlock, *p,
|
2010-08-19 23:33:44 +04:00
|
|
|
aIsImportant, aOverrideImportant,
|
2015-06-03 22:21:24 +03:00
|
|
|
aMustCallValueAppended, aDeclaration,
|
|
|
|
aSheetDocument);
|
2016-01-11 02:28:35 +03: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,
|
2016-08-17 04:37:48 +03:00
|
|
|
nsCSSPropertyID aPropID,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsImportant,
|
|
|
|
bool aOverrideImportant,
|
|
|
|
bool aMustCallValueAppended,
|
2015-06-03 22:21:24 +03:00
|
|
|
css::Declaration* aDeclaration,
|
|
|
|
nsIDocument* aSheetDocument)
|
2010-07-23 22:00:44 +04:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool changed = false;
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(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);
|
|
|
|
}
|
|
|
|
|
2015-06-03 22:21:24 +03:00
|
|
|
if (aSheetDocument) {
|
|
|
|
UseCounter useCounter = nsCSSProps::UseCounterFor(aPropID);
|
|
|
|
if (useCounter != eUseCounter_UNKNOWN) {
|
|
|
|
aSheetDocument->SetDocumentAndPageUseCounter(useCounter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:44 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-12-12 06:09:44 +04:00
|
|
|
void
|
2016-08-17 04:37:48 +03:00
|
|
|
nsCSSExpandedDataBlock::MapRuleInfoInto(nsCSSPropertyID aPropID,
|
2013-12-12 06:09:44 +04:00
|
|
|
nsRuleData* aRuleData) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!nsCSSProps::IsShorthand(aPropID));
|
|
|
|
|
|
|
|
const nsCSSValue* src = PropertyAt(aPropID);
|
|
|
|
MOZ_ASSERT(src->GetUnit() != eCSSUnit_Null);
|
|
|
|
|
2016-08-17 04:37:48 +03:00
|
|
|
nsCSSPropertyID physicalProp = aPropID;
|
2016-04-21 02:43:24 +03:00
|
|
|
if (nsCSSProps::PropHasFlags(aPropID, CSS_PROPERTY_LOGICAL)) {
|
|
|
|
EnsurePhysicalProperty(physicalProp, aRuleData);
|
|
|
|
}
|
2015-01-17 07:16:01 +03:00
|
|
|
|
|
|
|
nsCSSValue* dest = aRuleData->ValueFor(physicalProp);
|
2013-12-12 06:09:44 +04:00
|
|
|
MOZ_ASSERT(dest->GetUnit() == eCSSUnit_TokenStream &&
|
|
|
|
dest->GetTokenStreamValue()->mPropertyID == aPropID);
|
|
|
|
|
2015-08-27 04:19:38 +03:00
|
|
|
CSSVariableImageTable::ReplaceAll(aRuleData->mStyleContext, aPropID, [=] {
|
2016-04-21 02:43:24 +03:00
|
|
|
MapSinglePropertyInto(physicalProp, src, dest, aRuleData);
|
2015-08-27 04:19:38 +03:00
|
|
|
});
|
2013-12-12 06:09:44 +04:00
|
|
|
}
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
nsCSSExpandedDataBlock::DoAssertInitialState()
|
|
|
|
{
|
2016-01-11 02:28:35 +03:00
|
|
|
mPropertiesSet.AssertIsEmpty("not initial state");
|
|
|
|
mPropertiesImportant.AssertIsEmpty("not initial state");
|
2003-06-08 02:14:42 +04:00
|
|
|
|
2016-01-11 02:28:35 +03:00
|
|
|
for (uint32_t i = 0; i < eCSSProperty_COUNT_no_shorthands; ++i) {
|
2016-08-17 04:37:48 +03:00
|
|
|
nsCSSPropertyID prop = nsCSSPropertyID(i);
|
2016-01-11 02:28:35 +03:00
|
|
|
MOZ_ASSERT(PropertyAt(prop)->GetUnit() == eCSSUnit_Null,
|
|
|
|
"not initial state");
|
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
#endif
|