From 8c1da4242457376bb6acc92b1a9b687f055fe6b9 Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Wed, 31 Dec 2014 12:18:13 +1100 Subject: [PATCH] Bug 649142 - Part 2: Convert logical properties to their physical equivalents during the cascade. r=dbaron We will add cases to EnsurePhysicalProperty's switch statement as we convert the existing shorthand-implemented logical properties to the new, CSS_PROPERTY_LOGICAL-bearing properties. --- layout/style/nsCSSDataBlock.cpp | 41 ++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/layout/style/nsCSSDataBlock.cpp b/layout/style/nsCSSDataBlock.cpp index 2191bf513a37..c0fc73854a84 100644 --- a/layout/style/nsCSSDataBlock.cpp +++ b/layout/style/nsCSSDataBlock.cpp @@ -163,6 +163,25 @@ MapSinglePropertyInto(nsCSSProperty aProp, } } +/** + * If aProperty is a logical property, converts it to the equivalent physical + * property based on writing mode information obtained from aRuleData's + * style context. Returns true if aProperty was changed. + */ +static inline void +EnsurePhysicalProperty(nsCSSProperty& aProperty, nsRuleData* aRuleData) +{ + uint8_t direction = aRuleData->mStyleContext->StyleVisibility()->mDirection; + bool ltr = direction == NS_STYLE_DIRECTION_LTR; + + switch (aProperty) { + default: + NS_ABORT_IF_FALSE(nsCSSProps::PropHasFlags(aProperty, + CSS_PROPERTY_LOGICAL), + "unhandled logical property"); + } +} + void nsCSSCompressedDataBlock::MapRuleInfoInto(nsRuleData *aRuleData) const { @@ -173,10 +192,20 @@ nsCSSCompressedDataBlock::MapRuleInfoInto(nsRuleData *aRuleData) const if (!(aRuleData->mSIDs & mStyleBits)) return; - for (uint32_t i = 0; i < mNumProps; i++) { + // 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. + aRuleData->mCanStoreInRuleTree = false; + } nsCSSValue* target = aRuleData->ValueFor(iProp); if (target->GetUnit() == eCSSUnit_Null) { const nsCSSValue *val = ValueAtIndex(i); @@ -605,11 +634,17 @@ nsCSSExpandedDataBlock::MapRuleInfoInto(nsCSSProperty aPropID, const nsCSSValue* src = PropertyAt(aPropID); MOZ_ASSERT(src->GetUnit() != eCSSUnit_Null); - nsCSSValue* dest = aRuleData->ValueFor(aPropID); + nsCSSProperty physicalProp = aPropID; + if (nsCSSProps::PropHasFlags(aPropID, CSS_PROPERTY_LOGICAL)) { + EnsurePhysicalProperty(physicalProp, aRuleData); + aRuleData->mCanStoreInRuleTree = false; + } + + nsCSSValue* dest = aRuleData->ValueFor(physicalProp); MOZ_ASSERT(dest->GetUnit() == eCSSUnit_TokenStream && dest->GetTokenStreamValue()->mPropertyID == aPropID); - MapSinglePropertyInto(aPropID, src, dest, aRuleData); + MapSinglePropertyInto(physicalProp, src, dest, aRuleData); } #ifdef DEBUG