Bug 1120284 - Part 5: Support logical axis properties. r=dbaron

This commit is contained in:
Cameron McCormack 2015-01-17 15:43:20 +11:00
parent b3408d2302
commit 48c07b7b02
5 changed files with 85 additions and 29 deletions

View File

@ -172,33 +172,63 @@ MapSinglePropertyInto(nsCSSProperty aProp,
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);
bool isEnd =
nsCSSProps::PropHasFlags(aProperty, CSS_PROPERTY_LOGICAL_END_EDGE);
LogicalEdge edge = isEnd ? eLogicalEdgeEnd : eLogicalEdgeStart;
int index;
// 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) {
if (isAxisProperty) {
LogicalAxis logicalAxis = isBlock ? eLogicalAxisBlock : eLogicalAxisInline;
uint8_t wm = aRuleData->mStyleContext->StyleVisibility()->mWritingMode;
side = WritingMode::PhysicalSideForBlockAxis(wm, edge);
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 {
WritingMode wm(aRuleData->mStyleContext);
side = wm.PhysicalSideForInlineAxis(edge);
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);
MOZ_ASSERT(props[0] != eCSSProperty_UNKNOWN &&
props[1] != eCSSProperty_UNKNOWN &&
props[2] != eCSSProperty_UNKNOWN &&
props[3] != eCSSProperty_UNKNOWN &&
props[4] == eCSSProperty_UNKNOWN,
"expected four-element subproperty table");
aProperty = props[side];
#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

View File

@ -13,7 +13,9 @@
// margin-top, margin-right, margin-bottom and margin-left.
//
// Logical property groups are defined below using one of the following
// macros:
// macros, where the name_ argument must be capitalized LikeThis and
// must not collide with the name of a property's DOM method (its
// method_ in nsCSSPropList.h):
//
// CSS_PROP_LOGICAL_GROUP_SHORTHAND(name_)
// Defines a logical property group whose corresponding physical
@ -30,12 +32,18 @@
// example, the logical property group for
// offset-{block,inline}-{start,end} contains the top, right,
// bottom and left physical properties, but there is no shorthand
// that sets those four properties. The name_ argument must be
// capitalized LikeSo and must not collide with the name of a
// property's DOM method (its method_ in nsCSSPropList.h). A
// table must be defined in nsCSSProps.cpp named
// g<name_>LogicalGroupTable containing the four physical properties
// in top/right/bottom/left order.
// that sets those four properties. A table must be defined in
// nsCSSProps.cpp named g<name_>LogicalGroupTable containing the
// four physical properties in top/right/bottom/left order.
//
// CSS_PROP_LOGICAL_GROUP_AXIS(name_)
// Defines a logical property group whose corresponding physical
// properties are a set of two axis-related properties. For
// example, the logical property group for {block,inline}-size
// contains the width and height properties. A table must be
// defined in nCSSProps.cpp named g<name_>LogicalGroupTable
// containing the two physical properties in vertical/horizontal
// order, followed by an nsCSSProperty_UNKNOWN entry.
CSS_PROP_LOGICAL_GROUP_SHORTHAND(BorderColor)
CSS_PROP_LOGICAL_GROUP_SHORTHAND(BorderStyle)

View File

@ -86,6 +86,8 @@ enum nsCSSCounterDesc {
enum nsCSSPropertyLogicalGroup {
eCSSPropertyLogicalGroup_UNKNOWN = -1,
#define CSS_PROP_LOGICAL_GROUP_AXIS(name_) \
eCSSPropertyLogicalGroup_##name_,
#define CSS_PROP_LOGICAL_GROUP_BOX(name_) \
eCSSPropertyLogicalGroup_##name_,
#define CSS_PROP_LOGICAL_GROUP_SHORTHAND(name_) \
@ -93,6 +95,7 @@ enum nsCSSPropertyLogicalGroup {
#include "nsCSSPropLogicalGroupList.h"
#undef CSS_PROP_LOGICAL_GROUP_SHORTHAND
#undef CSS_PROP_LOGICAL_GROUP_BOX
#undef CSS_PROP_LOGICAL_GROUP_AXIS
eCSSPropertyLogicalGroup_COUNT
};

View File

@ -2559,9 +2559,11 @@ nsCSSProps::kSubpropertyTable[eCSSProperty_COUNT - eCSSProperty_COUNT_no_shortha
const nsCSSProperty* const
nsCSSProps::kLogicalGroupTable[eCSSPropertyLogicalGroup_COUNT] = {
#define CSS_PROP_LOGICAL_GROUP_SHORTHAND(id_) g##id_##SubpropTable,
#define CSS_PROP_LOGICAL_GROUP_AXIS(name_) g##name_##LogicalGroupTable,
#define CSS_PROP_LOGICAL_GROUP_BOX(name_) g##name_##LogicalGroupTable,
#include "nsCSSPropLogicalGroupList.h"
#undef CSS_PROP_LOGICAL_GROUP_BOX
#undef CSS_PROP_LOGICAL_GROUP_AXIS
#undef CSS_PROP_LOGICAL_GROUP_SHORTHAND
};
@ -2826,13 +2828,15 @@ nsCSSProps::gPropertyEnabled[eCSSProperty_COUNT_with_aliases] = {
#undef CSS_PROP_ALIAS
};
// Check that all properties defined using CSS_PROP_*_LOGICAL macros use
// the CSS_PROPERTY_LOGICAL flag.
// Check that all logical property flags are used appropriately.
#define CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, \
kwtable_, stylestruct_, stylestructoffset_, animtype_) \
static_assert(!((flags_) & CSS_PROPERTY_LOGICAL), \
"only properties defined with CSS_PROP_LOGICAL can use " \
"the CSS_PROPERTY_LOGICAL flag"); \
static_assert(!((flags_) & CSS_PROPERTY_LOGICAL_AXIS), \
"only properties defined with CSS_PROP_LOGICAL can use " \
"the CSS_PROPERTY_LOGICAL_AXIS flag"); \
static_assert(!((flags_) & CSS_PROPERTY_LOGICAL_BLOCK_AXIS), \
"only properties defined with CSS_PROP_LOGICAL can use " \
"the CSS_PROPERTY_LOGICAL_BLOCK_AXIS flag"); \
@ -2847,7 +2851,11 @@ nsCSSProps::gPropertyEnabled[eCSSProperty_COUNT_with_aliases] = {
"the CSS_PROPERTY_LOGICAL flag"); \
static_assert(!((flags_) & CSS_PROPERTY_IGNORED_WHEN_COLORS_DISABLED), \
"CSS_PROPERTY_IGNORED_WHEN_COLORS_DISABLED has no effect " \
"on logical properties");
"on logical properties"); \
static_assert(!(((flags_) & CSS_PROPERTY_LOGICAL_AXIS) && \
((flags_) & CSS_PROPERTY_LOGICAL_END_EDGE)), \
"CSS_PROPERTY_LOGICAL_END_EDGE makes no sense when used " \
"with CSS_PROPERTY_LOGICAL_AXIS");
#include "nsCSSPropList.h"
#undef CSS_PROP_LOGICAL
#undef CSS_PROP

View File

@ -130,7 +130,14 @@
// list.
#define CSS_PROPERTY_IMAGE_IS_IN_ARRAY_0 (1<<6)
// Flag (1<<7) is currently free.
// This is a logical property that represents some value associated with
// a logical axis rather than a logical box side, and thus has two
// corresponding physical properties it could set rather than four. For
// example, the block-size logical property has this flag set, as it
// represents the size in either the block or inline axis dimensions, and
// has two corresponding physical properties, width and height. Must not
// be used in conjunction with CSS_PROPERTY_LOGICAL_END_EDGE.
#define CSS_PROPERTY_LOGICAL_AXIS (1<<7)
// This property allows calc() between lengths and percentages and
// stores such calc() expressions in its style structs (typically in an