Bug 1120284 - Part 1: Define logical property groups more explicitly. r=dbaron

This commit is contained in:
Cameron McCormack 2015-01-17 15:43:20 +11:00
Родитель b080003370
Коммит e213d872b9
7 изменённых файлов: 120 добавлений и 57 удалений

Просмотреть файл

@ -23,6 +23,7 @@ EXPORTS += [
'nsCSSProperty.h',
'nsCSSPropertySet.h',
'nsCSSPropList.h',
'nsCSSPropLogicalGroupList.h',
'nsCSSProps.h',
'nsCSSPseudoClasses.h',
'nsCSSPseudoClassList.h',

Просмотреть файл

@ -191,15 +191,14 @@ EnsurePhysicalProperty(nsCSSProperty& aProperty, nsRuleData* aRuleData)
side = wm.PhysicalSideForInlineAxis(edge);
}
nsCSSProperty shorthand = nsCSSProps::BoxShorthandFor(aProperty);
const nsCSSProperty* subprops = nsCSSProps::SubpropertyEntryFor(shorthand);
MOZ_ASSERT(subprops[0] != eCSSProperty_UNKNOWN &&
subprops[1] != eCSSProperty_UNKNOWN &&
subprops[2] != eCSSProperty_UNKNOWN &&
subprops[3] != eCSSProperty_UNKNOWN &&
subprops[4] == eCSSProperty_UNKNOWN,
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 = subprops[side];
aProperty = props[side];
}
void

Просмотреть файл

@ -51,10 +51,11 @@
keyword table member of class nsCSSProps, for use in
nsCSSProps::LookupPropertyValue.
-. 'boxshorthand_' [used only for CSS_PROP_LOGICAL] is the id of
the shorthand property that sets the four sides of the box for which
this is a logical property. For example, this would be 'border_color'
for 'border-block-start-color'.
-. 'group_' [used only for CSS_PROP_LOGICAL] is the name of
the logical property group that contains the physical properties
that can be set by this logical property. The name must be one
from nsCSSPropLogicalGroupList.h. For example, this would be
'BorderColor' for 'border-block-start-color'.
-. 'stylestruct_' [used only for CSS_PROP and CSS_PROP_LOGICAL, not
CSS_PROP_*] gives the name of the style struct. Can be used to make
@ -174,12 +175,12 @@
#ifndef CSS_PROP_LOGICAL
#ifdef CSS_PROP_LIST_INCLUDE_LOGICAL
#define CSS_PROP_LOGICAL(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, boxshorthand_, struct_, stylestructoffset_, animtype_) CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, struct_, stylestructoffset_, animtype_)
#define CSS_PROP_LOGICAL(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, group_, struct_, stylestructoffset_, animtype_) CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, struct_, stylestructoffset_, animtype_)
#else
#ifndef CSS_PROP_LIST_EXCLUDE_LOGICAL
#error Must define exactly one of CSS_PROP_LOGICAL, CSS_PROP_LIST_EXCLUDE_LOGICAL and CSS_PROP_LIST_INCLUDE_LOGICAL when capturing properties using CSS_PROP.
#endif
#define CSS_PROP_LOGICAL(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, boxshorthand_, struct_, stylestructoffset_, animtype_) /* nothing */
#define CSS_PROP_LOGICAL(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, group_, struct_, stylestructoffset_, animtype_) /* nothing */
#endif
#define DEFINED_CSS_PROP_LOGICAL
#endif
@ -296,7 +297,7 @@
#define DEFINED_CSS_PROP_BACKENDONLY
#endif
#ifndef CSS_PROP_LOGICAL
#define CSS_PROP_LOGICAL(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, boxshorthand_, struct_, stylestructoffset_, animtype_) /* nothing */
#define CSS_PROP_LOGICAL(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, group_, struct_, stylestructoffset_, animtype_) /* nothing */
#define DEFINED_CSS_PROP_LOGICAL
#endif
@ -700,7 +701,7 @@ CSS_PROP_LOGICAL(
"layout.css.vertical-text.enabled",
VARIANT_HCK,
kBorderColorKTable,
border_color,
BorderColor,
Border,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
@ -716,7 +717,7 @@ CSS_PROP_LOGICAL(
"layout.css.vertical-text.enabled",
VARIANT_HK,
kBorderStyleKTable,
border_style,
BorderStyle,
Border,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
@ -734,7 +735,7 @@ CSS_PROP_LOGICAL(
"layout.css.vertical-text.enabled",
VARIANT_HKL | VARIANT_CALC,
kBorderWidthKTable,
border_width,
BorderWidth,
Border,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
@ -749,7 +750,7 @@ CSS_PROP_LOGICAL(
"layout.css.vertical-text.enabled",
VARIANT_HCK,
kBorderColorKTable,
border_color,
BorderColor,
Border,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
@ -764,7 +765,7 @@ CSS_PROP_LOGICAL(
"layout.css.vertical-text.enabled",
VARIANT_HK,
kBorderStyleKTable,
border_style,
BorderStyle,
Border,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
@ -781,7 +782,7 @@ CSS_PROP_LOGICAL(
"layout.css.vertical-text.enabled",
VARIANT_HKL | VARIANT_CALC,
kBorderWidthKTable,
border_width,
BorderWidth,
Border,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
@ -937,7 +938,7 @@ CSS_PROP_LOGICAL(
"",
VARIANT_HCK,
kBorderColorKTable,
border_color,
BorderColor,
Border,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
@ -952,7 +953,7 @@ CSS_PROP_LOGICAL(
"",
VARIANT_HK,
kBorderStyleKTable,
border_style,
BorderStyle,
Border,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
@ -969,7 +970,7 @@ CSS_PROP_LOGICAL(
"",
VARIANT_HKL | VARIANT_CALC,
kBorderWidthKTable,
border_width,
BorderWidth,
Border,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
@ -989,7 +990,7 @@ CSS_PROP_LOGICAL(
"",
VARIANT_HCK,
kBorderColorKTable,
border_color,
BorderColor,
Border,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
@ -1003,7 +1004,7 @@ CSS_PROP_LOGICAL(
"",
VARIANT_HK,
kBorderStyleKTable,
border_style,
BorderStyle,
Border,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
@ -1019,7 +1020,7 @@ CSS_PROP_LOGICAL(
"",
VARIANT_HKL | VARIANT_CALC,
kBorderWidthKTable,
border_width,
BorderWidth,
Border,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
@ -2220,7 +2221,7 @@ CSS_PROP_LOGICAL(
"layout.css.vertical-text.enabled",
VARIANT_AHLP | VARIANT_CALC,
nullptr,
margin,
Margin,
Margin,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
@ -2238,7 +2239,7 @@ CSS_PROP_LOGICAL(
"layout.css.vertical-text.enabled",
VARIANT_AHLP | VARIANT_CALC,
nullptr,
margin,
Margin,
Margin,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
@ -2270,7 +2271,7 @@ CSS_PROP_LOGICAL(
"",
VARIANT_AHLP | VARIANT_CALC,
nullptr,
margin,
Margin,
Margin,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
@ -2286,7 +2287,7 @@ CSS_PROP_LOGICAL(
"",
VARIANT_AHLP | VARIANT_CALC,
nullptr,
margin,
Margin,
Margin,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
@ -2599,7 +2600,7 @@ CSS_PROP_LOGICAL(
"layout.css.vertical-text.enabled",
VARIANT_HLP | VARIANT_CALC,
nullptr,
padding,
Padding,
Padding,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
@ -2619,7 +2620,7 @@ CSS_PROP_LOGICAL(
"layout.css.vertical-text.enabled",
VARIANT_HLP | VARIANT_CALC,
nullptr,
padding,
Padding,
Padding,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
@ -2656,7 +2657,7 @@ CSS_PROP_LOGICAL(
"",
VARIANT_HLP | VARIANT_CALC,
nullptr,
padding,
Padding,
Padding,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
@ -2675,7 +2676,7 @@ CSS_PROP_LOGICAL(
"",
VARIANT_HLP | VARIANT_CALC,
nullptr,
padding,
Padding,
Padding,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)

Просмотреть файл

@ -0,0 +1,30 @@
/* 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/. */
/*
* a list of groups of logical properties, for preprocessing
*/
// A logical property group is one that defines the corresponding physical
// longhand properties that could be set by a given set of logical longhand
// properties. For example, the logical property group for margin-block-start
// (and the other three logical margin properties) is one that contains
// margin-top, margin-right, margin-bottom and margin-left.
//
// Logical property groups are defined below using one of the following
// macros:
//
// CSS_PROP_LOGICAL_GROUP_SHORTHAND(name_)
// Defines a logical property group whose corresponding physical
// properties are those in a given shorthand. For example, the
// logical property group for margin-{block,inline}-{start,end}
// is defined by the margin shorthand. The name_ argument must
// be the method_ name of the shorthand (so Margin rather than
// margin).
CSS_PROP_LOGICAL_GROUP_SHORTHAND(BorderColor)
CSS_PROP_LOGICAL_GROUP_SHORTHAND(BorderStyle)
CSS_PROP_LOGICAL_GROUP_SHORTHAND(BorderWidth)
CSS_PROP_LOGICAL_GROUP_SHORTHAND(Margin)
CSS_PROP_LOGICAL_GROUP_SHORTHAND(Padding)

Просмотреть файл

@ -84,4 +84,13 @@ enum nsCSSCounterDesc {
eCSSCounterDesc_COUNT
};
enum nsCSSPropertyLogicalGroup {
eCSSPropertyLogicalGroup_UNKNOWN = -1,
#define CSS_PROP_LOGICAL_GROUP_SHORTHAND(name_) \
eCSSPropertyLogicalGroup_##name_,
#include "nsCSSPropLogicalGroupList.h"
#undef CSS_PROP_LOGICAL_GROUP_SHORTHAND
eCSSPropertyLogicalGroup_COUNT
};
#endif /* nsCSSProperty_h___ */

Просмотреть файл

@ -2556,21 +2556,30 @@ nsCSSProps::kSubpropertyTable[eCSSProperty_COUNT - eCSSProperty_COUNT_no_shortha
};
// Mapping of logical longhand properties to the shorthand that sets the four
// corresponding physical properties. The format is pairs of values,
// where the first is the logical longhand property and the second is the
// shorthand, stored in a flat array (like KTableValue arrays).
static const nsCSSProperty gBoxShorthandTable[] = {
const nsCSSProperty* const
nsCSSProps::kLogicalGroupTable[eCSSPropertyLogicalGroup_COUNT] = {
#define CSS_PROP_LOGICAL_GROUP_SHORTHAND(id_) g##id_##SubpropTable,
#include "nsCSSPropLogicalGroupList.h"
#undef CSS_PROP_LOGICAL_GROUP_SHORTHAND
};
// Mapping of logical longhand properties to their logical group (which
// represents the physical longhands the logical properties an correspond
// to). The format is pairs of values, where the first is the logical
// longhand property (an nsCSSProperty) and the second is the logical group
// (an nsCSSPropertyLogicalGroup), stored in a flat array (like KTableValue
// arrays).
static const int gLogicalGroupMappingTable[] = {
#define CSS_PROP_LOGICAL(name_, id_, method_, flags_, pref_, parsevariant_, \
kwtable_, boxshorthand_, stylestruct_, \
kwtable_, group_, stylestruct_, \
stylestructoffset_, animtype_) \
eCSSProperty_##id_, eCSSProperty_##boxshorthand_,
eCSSProperty_##id_, eCSSPropertyLogicalGroup_##group_,
#include "nsCSSPropList.h"
#undef CSS_PROP_LOGICAL
};
/* static */ nsCSSProperty
nsCSSProps::BoxShorthandFor(nsCSSProperty aProperty)
/* static */ const nsCSSProperty*
nsCSSProps::LogicalGroup(nsCSSProperty aProperty)
{
NS_ABORT_IF_FALSE(0 <= aProperty &&
aProperty < eCSSProperty_COUNT_no_shorthands,
@ -2578,14 +2587,14 @@ nsCSSProps::BoxShorthandFor(nsCSSProperty aProperty)
NS_ABORT_IF_FALSE(nsCSSProps::PropHasFlags(aProperty, CSS_PROPERTY_LOGICAL),
"aProperty must be a logical longhand property");
for (size_t i = 0; i < ArrayLength(gBoxShorthandTable); i += 2) {
if (gBoxShorthandTable[i] == aProperty) {
return gBoxShorthandTable[i + 1];
for (size_t i = 0; i < ArrayLength(gLogicalGroupMappingTable); i += 2) {
if (gLogicalGroupMappingTable[i] == aProperty) {
return kLogicalGroupTable[gLogicalGroupMappingTable[i + 1]];
}
}
NS_ABORT_IF_FALSE(false, "missing gBoxShorthandTable entry");
return eCSSProperty_UNKNOWN;
NS_ABORT_IF_FALSE(false, "missing gLogicalGroupMappingTable entry");
return nullptr;
}
@ -2781,7 +2790,7 @@ nsCSSProps::gPropertyIndexInStruct[eCSSProperty_COUNT_no_shorthands] = {
parsevariant_, kwtable_) \
size_t(-1),
#define CSS_PROP_LOGICAL(name_, id_, method_, flags_, pref_, parsevariant_, \
kwtable_, boxshorthand_, stylestruct_, \
kwtable_, group_, stylestruct_, \
stylestructoffset_, animtype_) \
size_t(-1),
#define CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, \
@ -2829,7 +2838,7 @@ nsCSSProps::gPropertyEnabled[eCSSProperty_COUNT_with_aliases] = {
"only properties defined with CSS_PROP_LOGICAL can use " \
"the CSS_PROPERTY_LOGICAL_END_EDGE flag");
#define CSS_PROP_LOGICAL(name_, id_, method_, flags_, pref_, parsevariant_, \
kwtable_, boxshorthand_, stylestruct_, \
kwtable_, group_, stylestruct_, \
stylestructoffset_, animtype_) \
static_assert((flags_) & CSS_PROPERTY_LOGICAL, \
"properties defined with CSS_PROP_LOGICAL must also use " \

Просмотреть файл

@ -471,18 +471,32 @@ public:
return gPropertyIndexInStruct[aProperty];
}
private:
// A table for logical property groups. Indexes are
// nsCSSPropertyLogicalGroup values.
static const nsCSSProperty* const
kLogicalGroupTable[eCSSPropertyLogicalGroup_COUNT];
public:
/**
* Returns the shorthand property which sets the four physical box side
* properties for which the argument is one of the corresponding logical
* box properties. For example, given eCSSProperty_margin_block_start,
* returns eCSSProperty_margin.
* Returns an array of longhand physical properties which can be set by
* the argument, which must be a logical longhand property. The returned
* array is terminated by an eCSSProperty_UNKNOWN value. For example,
* given eCSSProperty_margin_block_start, returns an array of the four
* properties eCSSProperty_margin_top, eCSSProperty_margin_right,
* eCSSProperty_margin_bottom and eCSSProperty_margin_left, followed
* by the sentinel.
*
* When called with a property that has the CSS_PROPERTY_LOGICAL_AXIS
* flag, the returned array will have two values preceding the sentinel;
* otherwise it will have four.
*
* (Note that the running time of this function is proportional to the
* number of logical longhand properties that exist. If we start
* getting too many of these properties, we should make gBoxShorthandTable
* getting too many of these properties, we should make kLogicalGroupTable
* be a simple array of eCSSProperty_COUNT length.)
*/
static nsCSSProperty BoxShorthandFor(nsCSSProperty aProperty);
static const nsCSSProperty* LogicalGroup(nsCSSProperty aProperty);
private:
static bool gPropertyEnabled[eCSSProperty_COUNT_with_aliases];