Bug 929991 - Style system implementation of 'text-align: true X'. r=heycam

This commit is contained in:
Mats Palmgren 2013-10-27 20:56:32 +00:00
parent e8b7a09b19
commit 241ee3a30d
10 changed files with 143 additions and 25 deletions

View File

@ -529,6 +529,7 @@ CSS_KEY(translatey, translatey)
CSS_KEY(translatez, translatez)
CSS_KEY(transparent, transparent) // for nsComputedDOMStyle only
CSS_KEY(tri-state, tri_state)
CSS_KEY(true, true)
CSS_KEY(ultra-condensed, ultra_condensed)
CSS_KEY(ultra-expanded, ultra_expanded)
CSS_KEY(underline, underline)

View File

@ -506,6 +506,9 @@ protected:
bool ParsePadding();
bool ParseQuotes();
bool ParseSize();
bool ParseTextAlign(nsCSSValue& aValue, const int32_t aTable[]);
bool ParseTextAlign(nsCSSValue& aValue);
bool ParseTextAlignLast(nsCSSValue& aValue);
bool ParseTextDecoration();
bool ParseTextDecorationLine(nsCSSValue& aValue);
bool ParseTextCombineHorizontal(nsCSSValue& aValue);
@ -6669,6 +6672,10 @@ CSSParserImpl::ParseSingleValueProperty(nsCSSValue& aValue,
return ParseImageOrientation(aValue);
case eCSSProperty_marks:
return ParseMarks(aValue);
case eCSSProperty_text_align:
return ParseTextAlign(aValue);
case eCSSProperty_text_align_last:
return ParseTextAlignLast(aValue);
case eCSSProperty_text_decoration_line:
return ParseTextDecorationLine(aValue);
case eCSSProperty_text_combine_horizontal:
@ -9714,6 +9721,49 @@ CSSParserImpl::ParseTextDecoration()
return true;
}
bool
CSSParserImpl::ParseTextAlign(nsCSSValue& aValue, const int32_t aTable[])
{
if (ParseVariant(aValue, VARIANT_INHERIT, nullptr)) {
// 'inherit', 'initial' and 'unset' must be alone
return true;
}
nsCSSValue left;
if (!ParseVariant(left, VARIANT_KEYWORD, aTable)) {
return false;
}
nsCSSValue right;
if (ParseVariant(right, VARIANT_KEYWORD, aTable)) {
// 'true' must be combined with some other value than 'true'.
if (left.GetIntValue() == NS_STYLE_TEXT_ALIGN_TRUE &&
right.GetIntValue() == NS_STYLE_TEXT_ALIGN_TRUE) {
return false;
}
aValue.SetPairValue(left, right);
} else {
// Single value 'true' is not allowed.
if (left.GetIntValue() == NS_STYLE_TEXT_ALIGN_TRUE) {
return false;
}
aValue = left;
}
return true;
}
bool
CSSParserImpl::ParseTextAlign(nsCSSValue& aValue)
{
return ParseTextAlign(aValue, nsCSSProps::kTextAlignKTable);
}
bool
CSSParserImpl::ParseTextAlignLast(nsCSSValue& aValue)
{
return ParseTextAlign(aValue, nsCSSProps::kTextAlignLastKTable);
}
bool
CSSParserImpl::ParseTextDecorationLine(nsCSSValue& aValue)
{

View File

@ -2768,7 +2768,8 @@ CSS_PROP_TEXT(
text-align,
text_align,
TextAlign,
CSS_PROPERTY_PARSE_VALUE | CSS_PROPERTY_APPLIES_TO_PLACEHOLDER,
CSS_PROPERTY_PARSE_VALUE | CSS_PROPERTY_VALUE_PARSER_FUNCTION |
CSS_PROPERTY_APPLIES_TO_PLACEHOLDER,
"",
// When we support aligning on a string, we can parse text-align
// as a string....
@ -2780,7 +2781,7 @@ CSS_PROP_TEXT(
-moz-text-align-last,
text_align_last,
CSS_PROP_DOMPROP_PREFIXED(TextAlignLast),
CSS_PROPERTY_PARSE_VALUE,
CSS_PROPERTY_PARSE_VALUE | CSS_PROPERTY_VALUE_PARSER_FUNCTION,
"",
VARIANT_HK,
kTextAlignLastKTable,

View File

@ -1438,6 +1438,7 @@ const int32_t nsCSSProps::kTextAlignKTable[] = {
eCSSKeyword__moz_left, NS_STYLE_TEXT_ALIGN_MOZ_LEFT,
eCSSKeyword_start, NS_STYLE_TEXT_ALIGN_DEFAULT,
eCSSKeyword_end, NS_STYLE_TEXT_ALIGN_END,
eCSSKeyword_true, NS_STYLE_TEXT_ALIGN_TRUE,
eCSSKeyword_UNKNOWN,-1
};
@ -1449,6 +1450,7 @@ const int32_t nsCSSProps::kTextAlignLastKTable[] = {
eCSSKeyword_justify, NS_STYLE_TEXT_ALIGN_JUSTIFY,
eCSSKeyword_start, NS_STYLE_TEXT_ALIGN_DEFAULT,
eCSSKeyword_end, NS_STYLE_TEXT_ALIGN_END,
eCSSKeyword_true, NS_STYLE_TEXT_ALIGN_TRUE,
eCSSKeyword_UNKNOWN,-1
};

View File

@ -2760,23 +2760,38 @@ nsComputedDOMStyle::DoGetVerticalAlign()
}
CSSValue*
nsComputedDOMStyle::DoGetTextAlign()
nsComputedDOMStyle::CreateTextAlignValue(uint8_t aAlign, bool aAlignTrue,
const int32_t aTable[])
{
nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
val->SetIdent(
nsCSSProps::ValueToKeywordEnum(StyleText()->mTextAlign,
nsCSSProps::kTextAlignKTable));
return val;
val->SetIdent(nsCSSProps::ValueToKeywordEnum(aAlign, aTable));
if (!aAlignTrue) {
return val;
}
nsROCSSPrimitiveValue* first = new nsROCSSPrimitiveValue;
first->SetIdent(eCSSKeyword_true);
nsDOMCSSValueList* valueList = GetROCSSValueList(false);
valueList->AppendCSSValue(first);
valueList->AppendCSSValue(val);
return valueList;
}
CSSValue*
nsComputedDOMStyle::DoGetTextAlign()
{
const nsStyleText* style = StyleText();
return CreateTextAlignValue(style->mTextAlign, style->mTextAlignTrue,
nsCSSProps::kTextAlignKTable);
}
CSSValue*
nsComputedDOMStyle::DoGetTextAlignLast()
{
nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
val->SetIdent(
nsCSSProps::ValueToKeywordEnum(StyleText()->mTextAlignLast,
nsCSSProps::kTextAlignLastKTable));
return val;
const nsStyleText* style = StyleText();
return CreateTextAlignValue(style->mTextAlignLast, style->mTextAlignLastTrue,
nsCSSProps::kTextAlignLastKTable);
}
CSSValue*

View File

@ -140,6 +140,11 @@ private:
nsMargin GetAdjustedValuesForBoxSizing();
// Helper method for DoGetTextAlign[Last].
mozilla::dom::CSSValue* CreateTextAlignValue(uint8_t aAlign,
bool aAlignTrue,
const int32_t aTable[]);
#define STYLE_STRUCT(name_, checkdata_cb_) \
const nsStyle##name_ * Style##name_() { \
return mStyleContextHolder->Style##name_(); \

View File

@ -3968,8 +3968,10 @@ nsRuleNode::ComputeTextData(void* aStartStruct,
}
// text-align: enum, string, inherit, initial
// text-align: enum, string, pair(enum|string), inherit, initial
// NOTE: string is not implemented yet.
const nsCSSValue* textAlignValue = aRuleData->ValueForTextAlign();
text->mTextAlignTrue = false;
if (eCSSUnit_String == textAlignValue->GetUnit()) {
NS_NOTYETIMPLEMENTED("align string");
} else if (eCSSUnit_Enumerated == textAlignValue->GetUnit() &&
@ -3979,14 +3981,47 @@ nsRuleNode::ComputeTextData(void* aStartStruct,
uint8_t parentAlign = parentText->mTextAlign;
text->mTextAlign = (NS_STYLE_TEXT_ALIGN_DEFAULT == parentAlign) ?
NS_STYLE_TEXT_ALIGN_CENTER : parentAlign;
} else
} else {
if (eCSSUnit_Pair == textAlignValue->GetUnit()) {
// Two values were specified, one must be 'true'.
text->mTextAlignTrue = true;
const nsCSSValuePair& textAlignValuePair = textAlignValue->GetPairValue();
textAlignValue = &textAlignValuePair.mXValue;
if (eCSSUnit_Enumerated == textAlignValue->GetUnit()) {
if (textAlignValue->GetIntValue() == NS_STYLE_TEXT_ALIGN_TRUE) {
textAlignValue = &textAlignValuePair.mYValue;
}
} else if (eCSSUnit_String == textAlignValue->GetUnit()) {
NS_NOTYETIMPLEMENTED("align string");
}
} else if (eCSSUnit_Inherit == textAlignValue->GetUnit() ||
eCSSUnit_Unset == textAlignValue->GetUnit()) {
text->mTextAlignTrue = parentText->mTextAlignTrue;
}
SetDiscrete(*textAlignValue, text->mTextAlign, canStoreInRuleTree,
SETDSC_ENUMERATED | SETDSC_UNSET_INHERIT,
parentText->mTextAlign,
NS_STYLE_TEXT_ALIGN_DEFAULT, 0, 0, 0, 0);
}
// text-align-last: enum, inherit, initial
SetDiscrete(*aRuleData->ValueForTextAlignLast(), text->mTextAlignLast,
// text-align-last: enum, pair(enum), inherit, initial
const nsCSSValue* textAlignLastValue = aRuleData->ValueForTextAlignLast();
text->mTextAlignLastTrue = false;
if (eCSSUnit_Pair == textAlignLastValue->GetUnit()) {
// Two values were specified, one must be 'true'.
text->mTextAlignLastTrue = true;
const nsCSSValuePair& textAlignLastValuePair = textAlignLastValue->GetPairValue();
textAlignLastValue = &textAlignLastValuePair.mXValue;
if (eCSSUnit_Enumerated == textAlignLastValue->GetUnit()) {
if (textAlignLastValue->GetIntValue() == NS_STYLE_TEXT_ALIGN_TRUE) {
textAlignLastValue = &textAlignLastValuePair.mYValue;
}
}
} else if (eCSSUnit_Inherit == textAlignLastValue->GetUnit() ||
eCSSUnit_Unset == textAlignLastValue->GetUnit()) {
text->mTextAlignLastTrue = parentText->mTextAlignLastTrue;
}
SetDiscrete(*textAlignLastValue, text->mTextAlignLast,
canStoreInRuleTree,
SETDSC_ENUMERATED | SETDSC_UNSET_INHERIT,
parentText->mTextAlignLast,

View File

@ -661,6 +661,7 @@ static inline mozilla::css::Side operator++(mozilla::css::Side& side, int) {
// NS_STYLE_TEXT_ALIGN_MOZ_CENTER_OR_INHERIT is only used in data structs; it
// is never present in stylesheets or computed data.
#define NS_STYLE_TEXT_ALIGN_MOZ_CENTER_OR_INHERIT 11
#define NS_STYLE_TEXT_ALIGN_TRUE 12
// Note: make sure that the largest NS_STYLE_TEXT_ALIGN_* value is smaller than
// the smallest NS_STYLE_VERTICAL_ALIGN_* value below!
@ -710,15 +711,15 @@ static inline mozilla::css::Side operator++(mozilla::css::Side& side, int) {
// Note: these values pickup after the text-align values because there
// are a few html cases where an object can have both types of
// alignment applied with a single attribute
#define NS_STYLE_VERTICAL_ALIGN_BASELINE 12
#define NS_STYLE_VERTICAL_ALIGN_SUB 13
#define NS_STYLE_VERTICAL_ALIGN_SUPER 14
#define NS_STYLE_VERTICAL_ALIGN_TOP 15
#define NS_STYLE_VERTICAL_ALIGN_TEXT_TOP 16
#define NS_STYLE_VERTICAL_ALIGN_MIDDLE 17
#define NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM 18
#define NS_STYLE_VERTICAL_ALIGN_BOTTOM 19
#define NS_STYLE_VERTICAL_ALIGN_MIDDLE_WITH_BASELINE 20
#define NS_STYLE_VERTICAL_ALIGN_BASELINE 13
#define NS_STYLE_VERTICAL_ALIGN_SUB 14
#define NS_STYLE_VERTICAL_ALIGN_SUPER 15
#define NS_STYLE_VERTICAL_ALIGN_TOP 16
#define NS_STYLE_VERTICAL_ALIGN_TEXT_TOP 17
#define NS_STYLE_VERTICAL_ALIGN_MIDDLE 18
#define NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM 19
#define NS_STYLE_VERTICAL_ALIGN_BOTTOM 20
#define NS_STYLE_VERTICAL_ALIGN_MIDDLE_WITH_BASELINE 21
// See nsStyleVisibility
#define NS_STYLE_VISIBILITY_HIDDEN 0

View File

@ -2924,6 +2924,8 @@ nsStyleText::nsStyleText(void)
MOZ_COUNT_CTOR(nsStyleText);
mTextAlign = NS_STYLE_TEXT_ALIGN_DEFAULT;
mTextAlignLast = NS_STYLE_TEXT_ALIGN_AUTO;
mTextAlignTrue = false;
mTextAlignLastTrue = false;
mTextTransform = NS_STYLE_TEXT_TRANSFORM_NONE;
mWhiteSpace = NS_STYLE_WHITESPACE_NORMAL;
mWordBreak = NS_STYLE_WORDBREAK_NORMAL;
@ -2945,6 +2947,8 @@ nsStyleText::nsStyleText(void)
nsStyleText::nsStyleText(const nsStyleText& aSource)
: mTextAlign(aSource.mTextAlign),
mTextAlignLast(aSource.mTextAlignLast),
mTextAlignTrue(false),
mTextAlignLastTrue(false),
mTextTransform(aSource.mTextTransform),
mWhiteSpace(aSource.mWhiteSpace),
mWordBreak(aSource.mWordBreak),
@ -2982,6 +2986,8 @@ nsChangeHint nsStyleText::CalcDifference(const nsStyleText& aOther) const
if ((mTextAlign != aOther.mTextAlign) ||
(mTextAlignLast != aOther.mTextAlignLast) ||
(mTextAlignTrue != aOther.mTextAlignTrue) ||
(mTextAlignLastTrue != aOther.mTextAlignLastTrue) ||
(mTextTransform != aOther.mTextTransform) ||
(mWhiteSpace != aOther.mWhiteSpace) ||
(mWordBreak != aOther.mWordBreak) ||

View File

@ -1310,6 +1310,8 @@ struct nsStyleText {
uint8_t mTextAlign; // [inherited] see nsStyleConsts.h
uint8_t mTextAlignLast; // [inherited] see nsStyleConsts.h
bool mTextAlignTrue : 1; // [inherited] see nsStyleConsts.h
bool mTextAlignLastTrue : 1; // [inherited] see nsStyleConsts.h
uint8_t mTextTransform; // [inherited] see nsStyleConsts.h
uint8_t mWhiteSpace; // [inherited] see nsStyleConsts.h
uint8_t mWordBreak; // [inherited] see nsStyleConsts.h