Bug 1123917 part 2 - Make ruby-position only accept [over|under] instead of compound values. r=dholbert

This commit is contained in:
Xidorn Quan 2015-01-22 14:04:55 +11:00
parent f70cc9db66
commit 73b63d0bf9
17 changed files with 68 additions and 131 deletions

View File

@ -13,6 +13,7 @@
#include "RubyUtils.h"
#include "nsRubyBaseContainerFrame.h"
#include "nsRubyTextContainerFrame.h"
#include "mozilla/Maybe.h"
using namespace mozilla;
@ -197,23 +198,6 @@ nsRubyFrame::Reflow(nsPresContext* aPresContext,
borderPadding, lineWM, frameWM);
}
#ifdef DEBUG
static void
SanityCheckRubyPosition(int8_t aRubyPosition)
{
uint8_t horizontalPosition = aRubyPosition &
(NS_STYLE_RUBY_POSITION_LEFT | NS_STYLE_RUBY_POSITION_RIGHT);
MOZ_ASSERT(horizontalPosition == NS_STYLE_RUBY_POSITION_LEFT ||
horizontalPosition == NS_STYLE_RUBY_POSITION_RIGHT);
uint8_t verticalPosition = aRubyPosition &
(NS_STYLE_RUBY_POSITION_OVER | NS_STYLE_RUBY_POSITION_UNDER |
NS_STYLE_RUBY_POSITION_INTER_CHARACTER);
MOZ_ASSERT(verticalPosition == NS_STYLE_RUBY_POSITION_OVER ||
verticalPosition == NS_STYLE_RUBY_POSITION_UNDER ||
verticalPosition == NS_STYLE_RUBY_POSITION_INTER_CHARACTER);
}
#endif
void
nsRubyFrame::ReflowSegment(nsPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
@ -339,39 +323,46 @@ nsRubyFrame::ReflowSegment(nsPresContext* aPresContext,
nscoord reservedISize = RubyUtils::GetReservedISize(textContainer);
segmentISize = std::max(segmentISize, isize + reservedISize);
nscoord x, y;
uint8_t rubyPosition = textContainer->StyleText()->mRubyPosition;
#ifdef DEBUG
SanityCheckRubyPosition(rubyPosition);
#endif
if (lineWM.IsVertical()) {
// writing-mode is vertical, so bsize is the annotation's *width*
if (rubyPosition & NS_STYLE_RUBY_POSITION_LEFT) {
x = offsetRect.X() - bsize;
offsetRect.SetLeftEdge(x);
} else {
x = offsetRect.XMost();
offsetRect.SetRightEdge(x + bsize);
}
y = offsetRect.Y();
MOZ_ASSERT(rubyPosition == NS_STYLE_RUBY_POSITION_OVER ||
rubyPosition == NS_STYLE_RUBY_POSITION_UNDER);
Maybe<Side> side;
if (rubyPosition == NS_STYLE_RUBY_POSITION_OVER) {
side.emplace(lineWM.PhysicalSide(eLineRelativeDirOver));
} else if (rubyPosition == NS_STYLE_RUBY_POSITION_UNDER) {
side.emplace(lineWM.PhysicalSide(eLineRelativeDirUnder));
} else {
// writing-mode is horizontal, so bsize is the annotation's *height*
x = offsetRect.X();
if (rubyPosition & NS_STYLE_RUBY_POSITION_OVER) {
y = offsetRect.Y() - bsize;
offsetRect.SetTopEdge(y);
} else if (rubyPosition & NS_STYLE_RUBY_POSITION_UNDER) {
y = offsetRect.YMost();
offsetRect.SetBottomEdge(y + bsize);
} else {
// XXX inter-character support in bug 1055672
MOZ_ASSERT_UNREACHABLE("Unsupported ruby-position");
y = offsetRect.Y();
// XXX inter-character support in bug 1055672
MOZ_ASSERT_UNREACHABLE("Unsupported ruby-position");
}
nsPoint position;
if (side.isSome()) {
switch (side.value()) {
case eSideLeft:
offsetRect.SetLeftEdge(offsetRect.X() - bsize);
position = offsetRect.TopLeft();
break;
case eSideRight:
position = offsetRect.TopRight();
offsetRect.SetRightEdge(offsetRect.XMost() + bsize);
break;
case eSideTop:
offsetRect.SetTopEdge(offsetRect.Y() - bsize);
position = offsetRect.TopLeft();
break;
case eSideBottom:
position = offsetRect.BottomLeft();
offsetRect.SetBottomEdge(offsetRect.YMost() + bsize);
break;
}
}
FinishReflowChild(textContainer, aPresContext, textMetrics,
&textReflowState, x, y, 0);
&textReflowState, position.x, position.y, 0);
}
MOZ_ASSERT(LogicalSize(lineWM, baseRect.Size()).ISize(lineWM) ==
LogicalSize(lineWM, offsetRect.Size()).ISize(lineWM),
"Annotations should only be placed on the block directions");
nscoord deltaISize = segmentISize - baseMetrics.ISize(lineWM);
if (deltaISize <= 0) {

View File

@ -6,7 +6,7 @@
<link rel="stylesheet" href="common.css">
<style>
div {
ruby-position: under left;
ruby-position: under;
width: 300px; height: 100px;
-moz-text-align-last: justify;
overflow: auto;

View File

@ -6,7 +6,7 @@
<link rel="stylesheet" href="common.css">
<style>
div {
ruby-position: under left;
ruby-position: under;
width: 300px; height: 100px;
-moz-text-align-last: justify;
overflow: auto;

View File

@ -8,7 +8,7 @@
<body style="line-height: 1">
<ruby>
<rb>base</rb>
<rtc style="ruby-position: under left;"><rt style="color: transparent">text</rt></rtc>
<rtc style="ruby-position: under;"><rt style="color: transparent">text</rt></rtc>
</ruby><br>
next line
</body>

View File

@ -8,8 +8,8 @@
<body style="line-height: 1">
<ruby>
<rb>base</rb>
<rtc style="ruby-position: over left; font-size: 80%;"><rt style="color: transparent">text</rt></rtc>
<rtc style="ruby-position: under left; font-size: 50%;"><rt style="color: transparent">text</rt></rtc>
<rtc style="ruby-position: over; font-size: 80%;"><rt style="color: transparent">text</rt></rtc>
<rtc style="ruby-position: under; font-size: 50%;"><rt style="color: transparent">text</rt></rtc>
</ruby><br>
next line
</body>

View File

@ -19,10 +19,10 @@
<body>
<ruby>
<rb>base##</rb>
<rtc style="ruby-position: over left"><rt>over##</rt></rtc>
<rtc style="ruby-position: under left"><rt>under#</rt></rtc>
<rtc style="ruby-position: over left"><rt>over2#</rt></rtc>
<rtc style="ruby-position: under left"><rt>under2</rt></rtc>
<rtc style="ruby-position: over"><rt>over##</rt></rtc>
<rtc style="ruby-position: under"><rt>under#</rt></rtc>
<rtc style="ruby-position: over"><rt>over2#</rt></rtc>
<rtc style="ruby-position: under"><rt>under2</rt></rtc>
</ruby>
</body>
</html>

View File

@ -20,10 +20,10 @@
<body>
<ruby>
<rb>base##</rb>
<rtc style="ruby-position: over left"><rt>left##</rt></rtc>
<rtc style="ruby-position: over right"><rt>right#</rt></rtc>
<rtc style="ruby-position: over left"><rt>left2#</rt></rtc>
<rtc style="ruby-position: over right"><rt>right2</rt></rtc>
<rtc style="ruby-position: under"><rt>left##</rt></rtc>
<rtc style="ruby-position: over"><rt>right#</rt></rtc>
<rtc style="ruby-position: under"><rt>left2#</rt></rtc>
<rtc style="ruby-position: over"><rt>right2</rt></rtc>
</ruby>
</body>
</html>

View File

@ -20,10 +20,10 @@
<body>
<ruby>
<rb>base##</rb>
<rtc style="ruby-position: over left"><rt>left##</rt></rtc>
<rtc style="ruby-position: over right"><rt>right#</rt></rtc>
<rtc style="ruby-position: over left"><rt>left2#</rt></rtc>
<rtc style="ruby-position: over right"><rt>right2</rt></rtc>
<rtc style="ruby-position: under"><rt>left##</rt></rtc>
<rtc style="ruby-position: over"><rt>right#</rt></rtc>
<rtc style="ruby-position: under"><rt>left2#</rt></rtc>
<rtc style="ruby-position: over"><rt>right2</rt></rtc>
</ruby>
</body>
</html>

View File

@ -797,7 +797,6 @@ protected:
bool ParseOverflow();
bool ParsePadding();
bool ParseQuotes();
bool ParseRubyPosition(nsCSSValue& aValue);
bool ParseSize();
bool ParseTextAlign(nsCSSValue& aValue,
const KTableValue aTable[]);
@ -9924,8 +9923,6 @@ CSSParserImpl::ParseSingleValueProperty(nsCSSValue& aValue,
return ParseListStyleType(aValue);
case eCSSProperty_marks:
return ParseMarks(aValue);
case eCSSProperty_ruby_position:
return ParseRubyPosition(aValue);
case eCSSProperty_text_align:
return ParseTextAlign(aValue);
case eCSSProperty_text_align_last:
@ -12932,34 +12929,6 @@ CSSParserImpl::ParseQuotes()
return true;
}
static const int32_t gRubyPositionMask[] = {
// vertical values
NS_STYLE_RUBY_POSITION_OVER |
NS_STYLE_RUBY_POSITION_UNDER |
NS_STYLE_RUBY_POSITION_INTER_CHARACTER,
// horizontal values
NS_STYLE_RUBY_POSITION_RIGHT |
NS_STYLE_RUBY_POSITION_LEFT,
// end
MASK_END_VALUE
};
bool
CSSParserImpl::ParseRubyPosition(nsCSSValue& aValue)
{
if (ParseVariant(aValue, VARIANT_INHERIT, nullptr)) {
return true;
}
if (!ParseBitmaskValues(aValue, nsCSSProps::kRubyPositionKTable,
gRubyPositionMask)) {
return false;
}
auto value = aValue.GetIntValue();
// The specified value must include *both* a vertical keyword *and*
// a horizontal keyword. We reject it here if either is missing.
return (value & gRubyPositionMask[0]) && (value & gRubyPositionMask[1]);
}
bool
CSSParserImpl::ParseSize()
{

View File

@ -3012,13 +3012,12 @@ CSS_PROP_TEXT(
ruby-position,
ruby_position,
RubyPosition,
CSS_PROPERTY_PARSE_VALUE |
CSS_PROPERTY_VALUE_PARSER_FUNCTION,
CSS_PROPERTY_PARSE_VALUE,
"layout.css.ruby.enabled",
0,
VARIANT_HK,
kRubyPositionKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
offsetof(nsStyleText, mRubyPosition),
eStyleAnimType_EnumU8)
CSS_PROP_DISPLAY(
scroll-behavior,
scroll_behavior,

View File

@ -1629,8 +1629,6 @@ const KTableValue nsCSSProps::kRubyPositionKTable[] = {
eCSSKeyword_under, NS_STYLE_RUBY_POSITION_UNDER,
// bug 1055672 for 'inter-character' support
// eCSSKeyword_inter_character, NS_STYLE_RUBY_POSITION_INTER_CHARACTER,
eCSSKeyword_right, NS_STYLE_RUBY_POSITION_RIGHT,
eCSSKeyword_left, NS_STYLE_RUBY_POSITION_LEFT,
eCSSKeyword_UNKNOWN, -1
};

View File

@ -1290,13 +1290,6 @@ nsCSSValue::AppendToString(nsCSSProperty aProperty, nsAString& aResult,
aResult);
break;
case eCSSProperty_ruby_position:
nsStyleUtil::AppendBitmaskCSSValue(aProperty, intValue,
NS_STYLE_RUBY_POSITION_OVER,
NS_STYLE_RUBY_POSITION_LEFT,
aResult);
break;
default:
const nsAFlatCString& name = nsCSSProps::LookupPropertyValue(aProperty, intValue);
AppendASCIItoUTF16(name, aResult);

View File

@ -3079,14 +3079,9 @@ nsComputedDOMStyle::DoGetLineHeight()
CSSValue*
nsComputedDOMStyle::DoGetRubyPosition()
{
nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
int32_t intValue = StyleText()->mRubyPosition;
nsAutoString valueStr;
nsStyleUtil::AppendBitmaskCSSValue(eCSSProperty_ruby_position,
intValue,
NS_STYLE_RUBY_POSITION_OVER,
NS_STYLE_RUBY_POSITION_LEFT, valueStr);
val->SetString(valueStr);
nsROCSSPrimitiveValue *val = new nsROCSSPrimitiveValue;
val->SetIdent(nsCSSProps::ValueToKeywordEnum(
StyleText()->mRubyPosition, nsCSSProps::kRubyPositionKTable));
return val;
}

View File

@ -4311,7 +4311,7 @@ nsRuleNode::ComputeTextData(void* aStartStruct,
text->mRubyPosition, canStoreInRuleTree,
SETDSC_ENUMERATED | SETDSC_UNSET_INHERIT,
parentText->mRubyPosition,
NS_STYLE_RUBY_POSITION_INITIAL, 0, 0, 0, 0);
NS_STYLE_RUBY_POSITION_OVER, 0, 0, 0, 0);
// text-size-adjust: none, auto, inherit, initial
SetDiscrete(*aRuleData->ValueForTextSizeAdjust(), text->mTextSizeAdjust,

View File

@ -841,13 +841,9 @@ static inline mozilla::css::Side operator++(mozilla::css::Side& side, int) {
#define NS_STYLE_HYPHENS_AUTO 2
// ruby-position, see nsStyleText
#define NS_STYLE_RUBY_POSITION_OVER 0x01
#define NS_STYLE_RUBY_POSITION_UNDER 0x02
#define NS_STYLE_RUBY_POSITION_INTER_CHARACTER 0x04 // placeholder, not yet parsed
#define NS_STYLE_RUBY_POSITION_RIGHT 0x08
#define NS_STYLE_RUBY_POSITION_LEFT 0x10
#define NS_STYLE_RUBY_POSITION_INITIAL \
(NS_STYLE_RUBY_POSITION_OVER | NS_STYLE_RUBY_POSITION_RIGHT)
#define NS_STYLE_RUBY_POSITION_OVER 0
#define NS_STYLE_RUBY_POSITION_UNDER 1
#define NS_STYLE_RUBY_POSITION_INTER_CHARACTER 2 /* placeholder, not yet parsed */
// See nsStyleText
#define NS_STYLE_TEXT_SIZE_ADJUST_NONE 0

View File

@ -3351,7 +3351,7 @@ nsStyleText::nsStyleText(void)
mWordBreak = NS_STYLE_WORDBREAK_NORMAL;
mWordWrap = NS_STYLE_WORDWRAP_NORMAL;
mHyphens = NS_STYLE_HYPHENS_MANUAL;
mRubyPosition = NS_STYLE_RUBY_POSITION_INITIAL;
mRubyPosition = NS_STYLE_RUBY_POSITION_OVER;
mTextSizeAdjust = NS_STYLE_TEXT_SIZE_ADJUST_AUTO;
mTextCombineUpright = NS_STYLE_TEXT_COMBINE_UPRIGHT_NONE;
mControlCharacterVisibility = NS_STYLE_CONTROL_CHARACTER_VISIBILITY_HIDDEN;

View File

@ -5706,15 +5706,11 @@ if (SpecialPowers.getBoolPref("layout.css.ruby.enabled")) {
domProp: "rubyPosition",
inherited: true,
type: CSS_TYPE_LONGHAND,
initial_values: [ "over right", "right over" ],
other_values: [
"over left", "under right", "under left",
"left over", "right under", "left under"
],
initial_values: [ "over" ],
other_values: [ "under" ],
invalid_values: [
"over", "under", "left", "right", "auto", "none", "not_a_position",
"over over", "over under", "left left", "left right",
"over left over", "right over left", "0", "100px", "50%"
"left", "right", "auto", "none", "not_a_position",
"over left", "right under", "0", "100px", "50%"
]
};
}