Files
palemoon27/layout/style/nsCSSDataBlock.cpp
T
roytam1 5499b4356b import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1155371 - Include DOMMediaStream and MediaSource object URLs in memory reports. r=khuey (b62513f5c6)
- Bug 1187782 (part 1) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey. (aa14b536c4)
- Bug 1187782 (part 2) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey. (1645a9b910)
- Bug 1187782 (part 3) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey. (67a83f37d5)
- Bug 1187782 (part 4) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey. (bf1f7a8dfe)
- Bug 1187782 (part 5) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey. (b76f1f34c8)
- Bug 1187782 (part 6) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey. (f44312f3a9)
- Bug 1187782 (part 7) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey. (33bb281955)
- Bug 1187782 (part 8) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey. (52f7bc040e)
- Bug 1187782 (part 9) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey. (7e797025a3)
- Bug 1207355 (Part 1) - Stop requesting decodes in nsDocument. r=tn (b2e6eb49c0)
- Bug 1202085 - Part 1: Remove imgICache::RemoveEntry(); r=seth (b5e4e2242f)
- Bug 1202085 - Part 2: Add an optional document argument to imgICache::FindEntryProperties(); r=seth (3f3138e5ba)
- Bug 1202085 - Part 3: Relax the assertion in ServiceWorkerManager::IsControlled to only happen when we think the document is controlled; r=jdm (6a829a6985)
- Bug 1202085 - Part 4: Add an ID for controlled document to the image cache key; r=seth (525ca69231)
- Bug 1202085 - Part 5: Add an automated test for the interaction of image cache with controlled documents; r=jdm (627e28d58d)
- Bug 1202085 - Part 6: Clear the entries in the image cache belonging to a controlled document when it gets destroyed; r=seth (935b858eac)
- Bug 1221279 Don't crash while clearing imgLoader cache when disconnected document is destroyed. r=smaug (040d3fa2be)
- Bug 1207084 - keep sheet level on tokenstream for use in ruledata when resolving variables, to fix hcm issues with CSS variables, r=heycam (2d8f5af005)
- Bug 1207084 - addendum: fix operator== for nsCSSValueTokenStream, implied-r=heycam (ee66d21638)
- Bug 1209124 - Bail out of nsStyleSet::GatherRuleProcessors and PresShell::Observe if we're called during/after shutdown. r=dbaron (7043eb3ee7)
- Bug 1216043 - Rename nsStyleSheet::sheetType and make it an enum class. r=dbaron (f03c5328e6)
- Bug 1168158 - Make URLValue::mString a smart pointer. r=heycam (06e37619be)
- Bug 1216038 - Deduce underlying integer type for MakeEnumeratedRange starting at 0. r=froydnj (883c74fb6b)
- Bug 1216040 - Make ArrayLength support mozilla::EnumeratedArray. r=froydnj (d1fc4aa43c)
- Bug 1216041 - Add ranged iterator support to mozilla::{Array,RangedArray,EnumerationArray}. r=froydnj (bf71f0ea1f)
- Bug 1128787 part.1 Add test r=ehsan (97016bbd85)
- Bug 1128787 part.2 nsHTMLDocument should clear focus before making itself editable when designMode is enabled and it makes the focused content non-focusable r=smaug+enndeakin (eccab99994)
- Bug 1171342 - Store contenteditable.css and designmode.css in the style sheet cache. r=jwatt (7e6aa290d2)
- Bug 1164279 - Disable font-variant-east-asian: ruby for <rt> on Windows. r=jfkthame (04117062d7)
- Bug 1126230 part 9 - Remove fullscreen override and related test. r=dbaron (18818d67fa)
- Bug 1126230 part 1 - Use delegated constructor to simplify constructor of nsFrameConstructorState. r=bz (5c1193f9f5)
- Bug 1126230 part 2 - Refactor part of nsFrameConstructorState::AddChild. r=bz (3c02f9e8c2)
- Bug 1126230 part 3 - Add :-moz-browser-frame pseudo class for HTML browser frame elements. r=dbaron (6a7b01f092)
- Bug 1211040 - Restrict -moz-window-{dragging,shadow} to be chrome-only. r=dbaron (005f02f673)
- Bug 1126230 part 4 - Add -moz-top-layer internal CSS property and set it for fullscreen elements. r=dbaron (02d841cab7)
- Bug 1203405 - Ignore order of abs/fixed-pos frames in the frame list. r=roc (d67696d0ea)
- Bug 1126230 part 5 - Give proper geometric parent for top layer frames. r=bz,dbaron (19504f223e)
- Bug 1126230 part 6 - Add nsIDocument::GetFullscreenStack() method. r=smaug (d401d534d1)
- Bug 1126230 part 7 - Add static method nsDisplayListBuilder::GetOutOfFlowData(). r=roc (3bdafef9b2)
- Bug 1126230 part 8 - Implement painting part for the top layer. r=roc (8875115dc1)
- Bug 1126230 part 10 - Add test for fullscreen top layer. r=dbaron (d095d85cd0)
- Bug 1069192 part 1 - Force users of nsCSSProps::IsEnabled() to pass in the enabled state. r=dbaron (38e40ebf1d)
- Bug 1195978 - set line number when re-parsing sheet. r=heycam (41cdf15319)
- Bug 1202095 - re-use @imported style sheets from inIDOMUtils.parseStyleSheet. r=heycam (2f54fdacf0)
- Bug 1099557 followup - Put the default setting for control-character visibility behind a runtime pref, and keep it off-by-default on release builds for now. r=dbaron (3ada076d9b)
- Bug 1069192 part 2 - Add a flag for chrome-only properties and change semantics of enabling flags. r=dbaron (2e887397ac)
- Bug 1220496 - Create PresHint/StyleAttr rule processors in nsStyleSet::Init and make DirtyRuleProcessors private. r=bzbarsky (0b538fe7cc)
- No bug - Cleanup the layout/style mochitest manifest. (e26676496f)
- Bug 1183461 part 1 - Move InitialAdvance to CSSAnimation; r=heycam (dac91a759a)
- Bug 1183461 part 2 - Reorder the parameters to EventInfo constructors; r=heycam (29fc1b2096)
- Bug 1183461 part 3 - Add Animation::AnimationTimeToTimeStamp; r=heycam (d3410ccc01)
- Bug 1183461 part 4 - Add CSSAnimation::ElapsedTimeToTimeStamp; r=heycam (10bac42e8e)
- Bug 1183461 part 5 - Store event TimeStamp along with event info; r=heycam (0250a63ee8)
- Bug 1220599 - Fix erroneous nsHTMLDocument::Open comment to note that we reuse the document rather than creating a new one. r=baku (5d492865d3)
- Bug 1220827 - Replace question comment in nsHTMLDocument::Open with an explanatory comment to explain why we create a new Window. r=smaug (69f16ef5dc)
- missing bits of  Bug 1170911 - Add pref for switching off execCommand("cut"/"copy"). r=ehsan (613644fa39)
- Bug 1183461 part 6 - Store the generating animation on the event; r=heycam (c490af70cc)
- Bug 1194037 part 4 - Remove ticking from FlushAnimations; r=dholbert (8df1f3eec4)
- Bug 1200568 - Don't create animations for elements that are not part of the document tree; r=dbaron (3027949d8b)
- Bug 1183461 part 7 - Add EventInfoComparator and sort events; r=heycam (550aad09bc)
- Bug 1183461 part 8 - Add tests for event order dispatch; r=heycam (964ee5fe23)
- Bug 978833 patch 1 - Add mochitest for bug 978833. r=heycam (4b4579d3f7)
- Bug 1208951 - Part 1: Split half of KeyframeValueEntry into a base class. r=birtles (32d7cbd477)
- Bug 1208951 - Part 2: Use a comparator object instead of operator< onKeyframeValueEntry. r=birtles (3b83723ef0)
- Bug 1209603 patch 1 - Add comments to RuleNodeCacheConditions.h . r=heycam (444eabdddc)
- Bug 1209603 patch 2 - Reduce calls to StyleVisibility() in WritingMode constructor. r=heycam (f079fb5765)
- Bug 1209603 patch 3 - Don't call SetFontSizeDependency for 0em. r=heycam (7a87fe5229)
- Bug 1209603 patch 4 - Add reftest for bug 1209603. r=heycam (1680144fc2)
- Bug 1209603 patch 5 - Move inline method nsStyleContext::GetCachedStyleData into header file, and make it public. r=heycam (32c38f790e)
- Bug 1209603 patch 6 - Prepare to use a different meaning of mBits when cached style data pointer is null. r=heycam (15e6471e58)
- Bug 1209603 patch 7 - Add assertions that we don't ask the rule node for data when we have cached data on the style context. r=heycam (0f27687446)
- Bug 1209603 patch 8 - Record in mBits when we have gotten a reset style struct that is cached on the rule node. r=heycam (b5e693a986)
- Bug 1209603 patch 9 - Cache inherited style structs on the style context when we found already-cached data in the rule tree. r=heycam (bfa6a169cb)
- Bug 1209603 patch 10 - Make PeekStyle* exact, i.e., guaranteed to return null if we haven't computed the data for this context. r=heycam (6ffdf7f0bf)
- Bug 1209603 patch 11 - Assert that PeekStyle* results don't change during difference computation. r=heycam (a3d7336dce)
- Bug 1193518 - Ensure that when we update a WritingMode after resolving dir=auto, we set the inline-dir bit appropriately as well as the inline-bidi bit. r=dholbert (072c062ddc)
- Bug 1216431 patch 1 - Give WritingMode an nsStyleVisibility* constructor. r=heycam (b7efb1204c)
- Bug 1216431 patch 2 - Pass nsStyleVisibility to nsStylePosition::CalcDifference to avoid computing new nsStyleVisibility during nsStyleContext::CalcStyleDifference. r=heycam (b842123d9b)
- Bug 1216431 patch 3 - Cache structs that are stored with conditions on the rule node all the time, rather than only when freshly computed. r=heycam (d4ea9adc19)
- Bug 1216431 patch 4 - Don't trigger computation of new structs via testing of conditions for conditionally-stored structs on the rule node. r=heycam (95cc7e8a52)
- Bug 1216431 patch 5 - Back out half of bug 1209603 patch 10. r=heycam (5949a2e9d0)
- Bug 1216431 patch 6 - Back out bug 1209603 patch 8. r=heycam (45a05ad60e)
- Bug 1209603 patch 6b - Rename nsStyleContext::HasCachedInheritedStyleData to HasCachedDependentStyleData. r=heycam (c4f52f00d0)
- Bug 1216431 patch 7 - Back out bug 1209603 patch 6. r=heycam (6eb8677af2)
- Bug 1216431 patch 8 - Fix whitespace error I made when addressing review comments. (19abf29215)
- Bug 1214958 - Add operators &=, |=, and ^= to mozilla::DebugOnly. r=froydnj (c76229e817)
- Bug 1208951 - Part 3: Expose nsCSSValue -> nsTimingFunction computation function. r=birtles (f0124bbbf2)
- Bug 1208951 - Part 4: Add an nsCSSParser entry point to parse a single longhand property and return an nsCSSValue. r=birtles (a317aa3255)
- Bug 1208951 - Part 5: Add nsCSSProps method to look a property by its IDL name. r=bzbarsky (1d0b78374d)
- Bug 1208951 - Part 6: Add method to compare nsCSSPropertySets for equality. r=birtles (9039197290)
- Bug 1208951 - Part 7: Add a StyleAnimationValue::ComputeValues method to compute components of a shorthand. r=birtles (36149d8c82)
- Bug 1208951 - Part 8: Don't warn if StyleAnimationValue::ComputeValue fails to parse a CSS property. r=birtles (12e06d0356)
- Bug 1208385 part 1 - Store a pointer to the owning animation on each KeyframeEffect; r=heycam (8f48533047)
- Bug 1208385 part 2 - Remove stored parent time from KeyframeEffectReadOnly and get the time directly from the owning animation; r=heycam (7bd25845be)
- Bug 1208951 - Part 9: Implement KeyframeEffectReadOnly constructor. r=bzbarsky r=birtles (49049edfac)
- Bug 1208951 - Part 10: Make GetFrames aware of initial/final zero-length segments and discontinuities between segments. r=birtles (71066c4941)
- Bug 1208951 - Part 11: Tests. r=birtles (308ad9ba9f)
- Bug 1210575 part 1: Rename CSS parser function "ParseWebkitPrefixedGradient()" to be more specific, now that we'll have several ways of parsing these expressions. r=heycam (060a01b43a)
- Bug 1210575 part 2: Refactor out the body of a long compound "if" expression into a helper function, IsFunctionTokenValidForBackgroundImage. r=heycam (ed784fb98d)
- Bug 1210575 part 3: Refactor CSS gradient-parsing code to use a flags bitfield instead of multiple bool args for customizing behavior. r=heycam (5c9df6466c)
- Bug 1210575 part 4: Prevent CSS parser from invoking CSSUnprefixingService if native webkit prefix support is enabled. r=heycam (d4c7997c94)
- Bug 1210575 part 5: Allow CSS -webkit-{linear|radial}-gradient expressions (& 'repeating' variants) to make it to our gradient-parsing code, if webkit prefix support is preffed on. r=heycam (4113bb47c4)
- Bug 1207002 - Use CSS property flag to restrict MathML-related internal properties. r=dbaron (9b021c7819)
- Bug 1199610 - Correctly handle parsing failures inside CSS functions. r=dbaron (5255fe445d)
- Bug 1210575 part 6: Implement -webkit-radial-gradient parse quirks with contain/cover keywords, sized shapes, "at" keyword, & angles. r=heycam (ba1002fbae)
- Bug 1210575 part 7: Refactor linear-gradient parsing code slightly & add/extend comments. r=heycam (1bd144ff04)
- Bug 1210575 part 8: Implement -webkit-linear-gradient parse quirks with "to", angles, and "center". r=heycam (97587d49ea)
- Bug 1210575 part 9: Remove some obsolete XXXdholbert comments from property_database.js. (no review, comment-only so DONTBUILD) (961a2c43e9)
- Bug 978833 patch 2 - Make css::Declaration reference-counted. r=heycam (4aab911856)
2022-11-10 09:36:53 +08:00

742 lines
26 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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/. */
/*
* compact representation of the property-value pairs within a CSS
* declaration, and the code for expanding and compacting it
*/
#include "nsCSSDataBlock.h"
#include "mozilla/css/Declaration.h"
#include "mozilla/css/ImageLoader.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/WritingModes.h"
#include "nsIDocument.h"
#include "nsRuleData.h"
#include "nsStyleContext.h"
#include "nsStyleSet.h"
using namespace mozilla;
/**
* 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 bool
MoveValue(nsCSSValue* aSource, nsCSSValue* aDest)
{
bool changed = (*aSource != *aDest);
aDest->~nsCSSValue();
memcpy(aDest, aSource, sizeof(nsCSSValue));
new (aSource) nsCSSValue();
return changed;
}
static bool
ShouldIgnoreColors(nsRuleData *aRuleData)
{
return aRuleData->mLevel != SheetType::Agent &&
aRuleData->mLevel != SheetType::User &&
!aRuleData->mPresContext->UseDocumentColors();
}
/**
* Tries to call |nsCSSValue::StartImageLoad()| on an image source.
* Image sources are specified by |url()| or |-moz-image-rect()| function.
*/
static void
TryToStartImageLoadOnValue(const nsCSSValue& aValue, nsIDocument* aDocument,
nsCSSValueTokenStream* aTokenStream)
{
MOZ_ASSERT(aDocument);
if (aValue.GetUnit() == eCSSUnit_URL) {
aValue.StartImageLoad(aDocument);
if (aTokenStream) {
aTokenStream->mImageValues.PutEntry(aValue.GetImageStructValue());
}
}
else if (aValue.GetUnit() == eCSSUnit_Image) {
// If we already have a request, see if this document needs to clone it.
imgIRequest* request = aValue.GetImageValue(nullptr);
if (request) {
mozilla::css::ImageValue* imageValue = aValue.GetImageStructValue();
aDocument->StyleImageLoader()->MaybeRegisterCSSImage(imageValue);
if (aTokenStream) {
aTokenStream->mImageValues.PutEntry(imageValue);
}
}
}
else if (aValue.EqualsFunction(eCSSKeyword__moz_image_rect)) {
nsCSSValue::Array* arguments = aValue.GetArrayValue();
MOZ_ASSERT(arguments->Count() == 6, "unexpected num of arguments");
const nsCSSValue& image = arguments->Item(1);
TryToStartImageLoadOnValue(image, aDocument, aTokenStream);
}
}
static void
TryToStartImageLoad(const nsCSSValue& aValue, nsIDocument* aDocument,
nsCSSProperty aProperty,
nsCSSValueTokenStream* aTokenStream)
{
if (aValue.GetUnit() == eCSSUnit_List) {
for (const nsCSSValueList* l = aValue.GetListValue(); l; l = l->mNext) {
TryToStartImageLoad(l->mValue, aDocument, aProperty, aTokenStream);
}
} else if (nsCSSProps::PropHasFlags(aProperty,
CSS_PROPERTY_IMAGE_IS_IN_ARRAY_0)) {
if (aValue.GetUnit() == eCSSUnit_Array) {
TryToStartImageLoadOnValue(aValue.GetArrayValue()->Item(0), aDocument,
aTokenStream);
}
} else {
TryToStartImageLoadOnValue(aValue, aDocument, aTokenStream);
}
}
static inline bool
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);
}
static void
MapSinglePropertyInto(nsCSSProperty aProp,
const nsCSSValue* aValue,
nsCSSValue* aTarget,
nsRuleData* aRuleData)
{
MOZ_ASSERT(aValue->GetUnit() != eCSSUnit_Null, "oops");
// Although aTarget is the nsCSSValue we are going to write into,
// we also look at its value before writing into it. This is done
// when aTarget is a token stream value, which is the case when we
// have just re-parsed a property that had a variable reference (in
// nsCSSParser::ParsePropertyWithVariableReferences). TryToStartImageLoad
// then records any resulting ImageValue objects on the
// nsCSSValueTokenStream object we found on aTarget. See the comment
// above nsCSSValueTokenStream::mImageValues for why.
MOZ_ASSERT(aTarget->GetUnit() == eCSSUnit_TokenStream ||
aTarget->GetUnit() == eCSSUnit_Null,
"aTarget must only be a token stream (when re-parsing "
"properties with variable references) or null");
nsCSSValueTokenStream* tokenStream =
aTarget->GetUnit() == eCSSUnit_TokenStream ?
aTarget->GetTokenStreamValue() :
nullptr;
if (ShouldStartImageLoads(aRuleData, aProp)) {
nsIDocument* doc = aRuleData->mPresContext->Document();
TryToStartImageLoad(*aValue, doc, aProp, tokenStream);
}
*aTarget = *aValue;
if (nsCSSProps::PropHasFlags(aProp,
CSS_PROPERTY_IGNORED_WHEN_COLORS_DISABLED) &&
ShouldIgnoreColors(aRuleData))
{
if (aProp == eCSSProperty_background_color) {
// Force non-'transparent' background
// colors to the user's default.
if (aTarget->IsNonTransparentColor()) {
aTarget->SetColorValue(aRuleData->mPresContext->
DefaultBackgroundColor());
}
} else {
// Ignore 'color', 'border-*-color', etc.
*aTarget = nsCSSValue();
}
}
}
/**
* If aProperty is a logical property, converts it to the equivalent physical
* property based on writing mode information obtained from aRuleData's
* style context.
*/
static inline void
EnsurePhysicalProperty(nsCSSProperty& aProperty, nsRuleData* aRuleData)
{
bool isAxisProperty =
nsCSSProps::PropHasFlags(aProperty, CSS_PROPERTY_LOGICAL_AXIS);
bool isBlock =
nsCSSProps::PropHasFlags(aProperty, CSS_PROPERTY_LOGICAL_BLOCK_AXIS);
int index;
if (isAxisProperty) {
LogicalAxis logicalAxis = isBlock ? eLogicalAxisBlock : eLogicalAxisInline;
uint8_t wm = aRuleData->mStyleContext->StyleVisibility()->mWritingMode;
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;
} else {
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;
}
const nsCSSProperty* props = nsCSSProps::LogicalGroup(aProperty);
#ifdef DEBUG
{
size_t len = isAxisProperty ? 2 : 4;
for (size_t i = 0; i < len; i++) {
MOZ_ASSERT(props[i] != eCSSProperty_UNKNOWN,
"unexpected logical group length");
}
MOZ_ASSERT(props[len] == eCSSProperty_UNKNOWN,
"unexpected logical group length");
}
#endif
aProperty = props[index];
}
void
nsCSSCompressedDataBlock::MapRuleInfoInto(nsRuleData *aRuleData) const
{
// 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; ) {
nsCSSProperty iProp = PropertyAtIndex(i);
if (nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[iProp]) &
aRuleData->mSIDs) {
if (nsCSSProps::PropHasFlags(iProp, CSS_PROPERTY_LOGICAL)) {
EnsurePhysicalProperty(iProp, aRuleData);
// We can't cache anything on the rule tree if we use any data from
// the style context, since data cached in the rule tree could be
// used with a style context with a different value.
uint8_t wm = WritingMode(aRuleData->mStyleContext).GetBits();
aRuleData->mConditions.SetWritingModeDependency(wm);
}
nsCSSValue* target = aRuleData->ValueFor(iProp);
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;
}
MapSinglePropertyInto(iProp, val, target, aRuleData);
}
}
}
}
const nsCSSValue*
nsCSSCompressedDataBlock::ValueFor(nsCSSProperty aProperty) const
{
MOZ_ASSERT(!nsCSSProps::IsShorthand(aProperty),
"Don't call for shorthands");
// 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;
for (uint32_t i = 0; i < mNumProps; i++) {
if (PropertyAtIndex(i) == aProperty) {
return ValueAtIndex(i);
}
}
return nullptr;
}
bool
nsCSSCompressedDataBlock::TryReplaceValue(nsCSSProperty aProperty,
nsCSSExpandedDataBlock& aFromBlock,
bool *aChanged)
{
nsCSSValue* newValue = aFromBlock.PropertyAt(aProperty);
MOZ_ASSERT(newValue && newValue->GetUnit() != eCSSUnit_Null,
"cannot replace with empty value");
const nsCSSValue* oldValue = ValueFor(aProperty);
if (!oldValue) {
*aChanged = false;
return false;
}
*aChanged = MoveValue(newValue, const_cast<nsCSSValue*>(oldValue));
aFromBlock.ClearPropertyBit(aProperty);
return true;
}
nsCSSCompressedDataBlock*
nsCSSCompressedDataBlock::Clone() const
{
nsAutoPtr<nsCSSCompressedDataBlock>
result(new(mNumProps) nsCSSCompressedDataBlock(mNumProps));
result->mStyleBits = mStyleBits;
for (uint32_t i = 0; i < mNumProps; i++) {
result->SetPropertyAtIndex(i, PropertyAtIndex(i));
result->CopyValueToIndex(i, ValueAtIndex(i));
}
return result.forget();
}
nsCSSCompressedDataBlock::~nsCSSCompressedDataBlock()
{
for (uint32_t i = 0; i < mNumProps; i++) {
#ifdef DEBUG
(void)PropertyAtIndex(i); // this checks the property is in range
#endif
const nsCSSValue* val = ValueAtIndex(i);
MOZ_ASSERT(val->GetUnit() != eCSSUnit_Null, "oops");
val->~nsCSSValue();
}
}
/* static */ nsCSSCompressedDataBlock*
nsCSSCompressedDataBlock::CreateEmptyBlock()
{
nsCSSCompressedDataBlock *result = new(0) nsCSSCompressedDataBlock(0);
return result;
}
size_t
nsCSSCompressedDataBlock::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
{
size_t n = aMallocSizeOf(this);
for (uint32_t i = 0; i < mNumProps; i++) {
n += ValueAtIndex(i)->SizeOfExcludingThis(aMallocSizeOf);
}
return n;
}
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));
}
/*****************************************************************************/
nsCSSExpandedDataBlock::nsCSSExpandedDataBlock()
{
AssertInitialState();
}
nsCSSExpandedDataBlock::~nsCSSExpandedDataBlock()
{
AssertInitialState();
}
void
nsCSSExpandedDataBlock::DoExpand(nsCSSCompressedDataBlock *aBlock,
bool aImportant)
{
/*
* 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++) {
nsCSSProperty iProp = aBlock->PropertyAtIndex(i);
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");
#ifdef NS_BUILD_REFCNT_LOGGING
dest->~nsCSSValue();
#endif
memcpy(dest, val, sizeof(nsCSSValue));
}
// Set the number of properties to zero so that we don't destroy the
// remnants of what we just copied.
aBlock->SetNumPropsToZero();
delete aBlock;
}
void
nsCSSExpandedDataBlock::Expand(nsCSSCompressedDataBlock *aNormalBlock,
nsCSSCompressedDataBlock *aImportantBlock)
{
MOZ_ASSERT(aNormalBlock, "unexpected null block");
AssertInitialState();
DoExpand(aNormalBlock, false);
if (aImportantBlock) {
DoExpand(aImportantBlock, true);
}
}
void
nsCSSExpandedDataBlock::ComputeNumProps(uint32_t* aNumPropsNormal,
uint32_t* aNumPropsImportant)
{
*aNumPropsNormal = *aNumPropsImportant = 0;
for (size_t iHigh = 0; iHigh < nsCSSPropertySet::kChunkCount; ++iHigh) {
if (!mPropertiesSet.HasPropertyInChunk(iHigh))
continue;
for (size_t iLow = 0; iLow < nsCSSPropertySet::kBitsInChunk; ++iLow) {
if (!mPropertiesSet.HasPropertyAt(iHigh, iLow))
continue;
#ifdef DEBUG
nsCSSProperty iProp = nsCSSPropertySet::CSSPropertyAt(iHigh, iLow);
#endif
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)++;
}
}
}
void
nsCSSExpandedDataBlock::Compress(nsCSSCompressedDataBlock **aNormalBlock,
nsCSSCompressedDataBlock **aImportantBlock,
const nsTArray<uint32_t>& aOrder)
{
nsAutoPtr<nsCSSCompressedDataBlock> result_normal, result_important;
uint32_t i_normal = 0, i_important = 0;
uint32_t numPropsNormal, numPropsImportant;
ComputeNumProps(&numPropsNormal, &numPropsImportant);
result_normal =
new(numPropsNormal) nsCSSCompressedDataBlock(numPropsNormal);
if (numPropsImportant != 0) {
result_important =
new(numPropsImportant) nsCSSCompressedDataBlock(numPropsImportant);
} else {
result_important = nullptr;
}
/*
* 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++) {
nsCSSProperty iProp = static_cast<nsCSSProperty>(aOrder[i]);
if (iProp >= eCSSProperty_COUNT) {
// a custom property
continue;
}
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]);
}
MOZ_ASSERT(numPropsNormal == i_normal, "bad numProps");
if (result_important) {
MOZ_ASSERT(numPropsImportant == i_important, "bad numProps");
}
#ifdef DEBUG
{
// 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;
for (size_t iHigh = 0; iHigh < nsCSSPropertySet::kChunkCount; iHigh++) {
if (!mPropertiesSet.HasPropertyInChunk(iHigh)) {
continue;
}
for (size_t iLow = 0; iLow < nsCSSPropertySet::kBitsInChunk; iLow++) {
if (mPropertiesSet.HasPropertyAt(iHigh, iLow)) {
numPropsInSet++;
}
}
}
MOZ_ASSERT(numPropsNormal + numPropsImportant == numPropsInSet,
"aOrder missing properties from the expanded data block");
}
#endif
ClearSets();
AssertInitialState();
*aNormalBlock = result_normal.forget();
*aImportantBlock = result_important.forget();
}
void
nsCSSExpandedDataBlock::AddLonghandProperty(nsCSSProperty aProperty,
const nsCSSValue& aValue)
{
MOZ_ASSERT(!nsCSSProps::IsShorthand(aProperty),
"property out of range");
nsCSSValue& storage = *static_cast<nsCSSValue*>(PropertyAt(aProperty));
storage = aValue;
SetPropertyBit(aProperty);
}
void
nsCSSExpandedDataBlock::Clear()
{
for (size_t iHigh = 0; iHigh < nsCSSPropertySet::kChunkCount; ++iHigh) {
if (!mPropertiesSet.HasPropertyInChunk(iHigh))
continue;
for (size_t iLow = 0; iLow < nsCSSPropertySet::kBitsInChunk; ++iLow) {
if (!mPropertiesSet.HasPropertyAt(iHigh, iLow))
continue;
nsCSSProperty iProp = nsCSSPropertySet::CSSPropertyAt(iHigh, iLow);
ClearLonghandProperty(iProp);
}
}
AssertInitialState();
}
void
nsCSSExpandedDataBlock::ClearProperty(nsCSSProperty aPropID)
{
if (nsCSSProps::IsShorthand(aPropID)) {
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aPropID,
nsCSSProps::eIgnoreEnabledState) {
ClearLonghandProperty(*p);
}
} else {
ClearLonghandProperty(aPropID);
}
}
void
nsCSSExpandedDataBlock::ClearLonghandProperty(nsCSSProperty aPropID)
{
MOZ_ASSERT(!nsCSSProps::IsShorthand(aPropID), "out of range");
ClearPropertyBit(aPropID);
ClearImportantBit(aPropID);
PropertyAt(aPropID)->Reset();
}
bool
nsCSSExpandedDataBlock::TransferFromBlock(nsCSSExpandedDataBlock& aFromBlock,
nsCSSProperty aPropID,
nsCSSProps::EnabledState aEnabledState,
bool aIsImportant,
bool aOverrideImportant,
bool aMustCallValueAppended,
css::Declaration* aDeclaration,
nsIDocument* aSheetDocument)
{
if (!nsCSSProps::IsShorthand(aPropID)) {
return DoTransferFromBlock(aFromBlock, aPropID,
aIsImportant, aOverrideImportant,
aMustCallValueAppended, aDeclaration,
aSheetDocument);
}
// We can pass eIgnoreEnabledState (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.
bool changed = false;
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aPropID, aEnabledState) {
changed |= DoTransferFromBlock(aFromBlock, *p,
aIsImportant, aOverrideImportant,
aMustCallValueAppended, aDeclaration,
aSheetDocument);
}
return changed;
}
bool
nsCSSExpandedDataBlock::DoTransferFromBlock(nsCSSExpandedDataBlock& aFromBlock,
nsCSSProperty aPropID,
bool aIsImportant,
bool aOverrideImportant,
bool aMustCallValueAppended,
css::Declaration* aDeclaration,
nsIDocument* aSheetDocument)
{
bool changed = false;
MOZ_ASSERT(aFromBlock.HasPropertyBit(aPropID), "oops");
if (aIsImportant) {
if (!HasImportantBit(aPropID))
changed = true;
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);
return false;
}
changed = true;
ClearImportantBit(aPropID);
}
}
if (aMustCallValueAppended || !HasPropertyBit(aPropID)) {
aDeclaration->ValueAppended(aPropID);
}
if (aSheetDocument) {
UseCounter useCounter = nsCSSProps::UseCounterFor(aPropID);
if (useCounter != eUseCounter_UNKNOWN) {
aSheetDocument->SetDocumentAndPageUseCounter(useCounter);
}
}
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.
*/
changed |= MoveValue(aFromBlock.PropertyAt(aPropID), PropertyAt(aPropID));
return changed;
}
void
nsCSSExpandedDataBlock::MapRuleInfoInto(nsCSSProperty aPropID,
nsRuleData* aRuleData) const
{
MOZ_ASSERT(!nsCSSProps::IsShorthand(aPropID));
const nsCSSValue* src = PropertyAt(aPropID);
MOZ_ASSERT(src->GetUnit() != eCSSUnit_Null);
nsCSSProperty physicalProp = aPropID;
if (nsCSSProps::PropHasFlags(aPropID, CSS_PROPERTY_LOGICAL)) {
EnsurePhysicalProperty(physicalProp, aRuleData);
uint8_t wm = WritingMode(aRuleData->mStyleContext).GetBits();
aRuleData->mConditions.SetWritingModeDependency(wm);
}
nsCSSValue* dest = aRuleData->ValueFor(physicalProp);
MOZ_ASSERT(dest->GetUnit() == eCSSUnit_TokenStream &&
dest->GetTokenStreamValue()->mPropertyID == aPropID);
MapSinglePropertyInto(physicalProp, src, dest, aRuleData);
}
#ifdef DEBUG
void
nsCSSExpandedDataBlock::DoAssertInitialState()
{
mPropertiesSet.AssertIsEmpty("not initial state");
mPropertiesImportant.AssertIsEmpty("not initial state");
for (uint32_t i = 0; i < eCSSProperty_COUNT_no_shorthands; ++i) {
nsCSSProperty prop = nsCSSProperty(i);
MOZ_ASSERT(PropertyAt(prop)->GetUnit() == eCSSUnit_Null,
"not initial state");
}
}
#endif