Bug 1617472 - Use enums for text-align / text-align-last. r=jfkthame

This also fixes some backwards logic in nsBlockFrame::ReflowDirtyLines, and adds
some static assertions to nsGenericHTMLElement that almost cause a very subtle
bug.

Depends on D63792

Differential Revision: https://phabricator.services.mozilla.com/D63793

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2020-02-24 13:32:57 +00:00
Родитель 844051acc0
Коммит 5e65211744
27 изменённых файлов: 246 добавлений и 220 удалений

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

@ -7,7 +7,8 @@
#include "mozilla/dom/HTMLHRElement.h"
#include "mozilla/dom/HTMLHRElementBinding.h"
#include "nsCSSProps.h"
#include "nsStyleConsts.h"
#include "mozilla/MappedDeclarations.h"
NS_IMPL_NS_NEW_HTML_ELEMENT(HR)
@ -27,9 +28,9 @@ bool HTMLHRElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
nsIPrincipal* aMaybeScriptedPrincipal,
nsAttrValue& aResult) {
static const nsAttrValue::EnumTable kAlignTable[] = {
{"left", NS_STYLE_TEXT_ALIGN_LEFT},
{"right", NS_STYLE_TEXT_ALIGN_RIGHT},
{"center", NS_STYLE_TEXT_ALIGN_CENTER},
{"left", StyleTextAlign::Left},
{"right", StyleTextAlign::Right},
{"center", StyleTextAlign::Center},
{nullptr, 0}};
if (aNamespaceID == kNameSpaceID_None) {
@ -69,19 +70,22 @@ void HTMLHRElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::align);
if (value && value->Type() == nsAttrValue::eEnum) {
// Map align attribute into auto side margins
switch (value->GetEnumValue()) {
case NS_STYLE_TEXT_ALIGN_LEFT:
switch (StyleTextAlign(value->GetEnumValue())) {
case StyleTextAlign::Left:
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_left, 0.0f);
aDecls.SetAutoValueIfUnset(eCSSProperty_margin_right);
break;
case NS_STYLE_TEXT_ALIGN_RIGHT:
case StyleTextAlign::Right:
aDecls.SetAutoValueIfUnset(eCSSProperty_margin_left);
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_right, 0.0f);
break;
case NS_STYLE_TEXT_ALIGN_CENTER:
case StyleTextAlign::Center:
aDecls.SetAutoValueIfUnset(eCSSProperty_margin_left);
aDecls.SetAutoValueIfUnset(eCSSProperty_margin_right);
break;
default:
MOZ_ASSERT_UNREACHABLE("Unknown <hr align> value");
break;
}
}
if (!aDecls.PropertyIsSet(eCSSProperty_height)) {

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

@ -863,8 +863,8 @@ void HTMLTableElement::MapAttributesIntoRule(
// illegal)
value = aAttributes->GetAttr(nsGkAtoms::align);
if (value && value->Type() == nsAttrValue::eEnum) {
if (value->GetEnumValue() == NS_STYLE_TEXT_ALIGN_CENTER ||
value->GetEnumValue() == NS_STYLE_TEXT_ALIGN_MOZ_CENTER) {
if (value->GetEnumValue() == uint8_t(StyleTextAlign::Center) ||
value->GetEnumValue() == uint8_t(StyleTextAlign::MozCenter)) {
aDecls.SetAutoValueIfUnset(eCSSProperty_margin_left);
aDecls.SetAutoValueIfUnset(eCSSProperty_margin_right);
}

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

@ -874,11 +874,11 @@ nsPresContext* nsGenericHTMLElement::GetPresContext(PresContextFor aFor) {
}
static const nsAttrValue::EnumTable kDivAlignTable[] = {
{"left", NS_STYLE_TEXT_ALIGN_MOZ_LEFT},
{"right", NS_STYLE_TEXT_ALIGN_MOZ_RIGHT},
{"center", NS_STYLE_TEXT_ALIGN_MOZ_CENTER},
{"middle", NS_STYLE_TEXT_ALIGN_MOZ_CENTER},
{"justify", NS_STYLE_TEXT_ALIGN_JUSTIFY},
{"left", StyleTextAlign::MozLeft},
{"right", StyleTextAlign::MozRight},
{"center", StyleTextAlign::MozCenter},
{"middle", StyleTextAlign::MozCenter},
{"justify", StyleTextAlign::Justify},
{nullptr, 0}};
static const nsAttrValue::EnumTable kFrameborderTable[] = {
@ -905,8 +905,8 @@ static const nsAttrValue::EnumTable kTableVAlignTable[] = {
bool nsGenericHTMLElement::ParseAlignValue(const nsAString& aString,
nsAttrValue& aResult) {
static const nsAttrValue::EnumTable kAlignTable[] = {
{"left", NS_STYLE_TEXT_ALIGN_LEFT},
{"right", NS_STYLE_TEXT_ALIGN_RIGHT},
{"left", StyleTextAlign::Left},
{"right", StyleTextAlign::Right},
{"top", StyleVerticalAlignKeyword::Top},
{"middle", StyleVerticalAlignKeyword::MozMiddleWithBaseline},
@ -923,18 +923,41 @@ bool nsGenericHTMLElement::ParseAlignValue(const nsAString& aString,
{"absbottom", StyleVerticalAlignKeyword::Bottom},
{nullptr, 0}};
static_assert(uint8_t(StyleTextAlign::Left) !=
uint8_t(StyleVerticalAlignKeyword::Top) &&
uint8_t(StyleTextAlign::Left) !=
uint8_t(StyleVerticalAlignKeyword::MozMiddleWithBaseline) &&
uint8_t(StyleTextAlign::Left) !=
uint8_t(StyleVerticalAlignKeyword::Baseline) &&
uint8_t(StyleTextAlign::Left) !=
uint8_t(StyleVerticalAlignKeyword::TextTop) &&
uint8_t(StyleTextAlign::Left) !=
uint8_t(StyleVerticalAlignKeyword::Middle) &&
uint8_t(StyleTextAlign::Left) !=
uint8_t(StyleVerticalAlignKeyword::Bottom));
static_assert(uint8_t(StyleTextAlign::Right) !=
uint8_t(StyleVerticalAlignKeyword::Top) &&
uint8_t(StyleTextAlign::Right) !=
uint8_t(StyleVerticalAlignKeyword::MozMiddleWithBaseline) &&
uint8_t(StyleTextAlign::Right) !=
uint8_t(StyleVerticalAlignKeyword::Baseline) &&
uint8_t(StyleTextAlign::Right) !=
uint8_t(StyleVerticalAlignKeyword::TextTop) &&
uint8_t(StyleTextAlign::Right) !=
uint8_t(StyleVerticalAlignKeyword::Middle) &&
uint8_t(StyleTextAlign::Right) !=
uint8_t(StyleVerticalAlignKeyword::Bottom));
return aResult.ParseEnumValue(aString, kAlignTable, false);
}
//----------------------------------------
static const nsAttrValue::EnumTable kTableHAlignTable[] = {
{"left", NS_STYLE_TEXT_ALIGN_LEFT},
{"right", NS_STYLE_TEXT_ALIGN_RIGHT},
{"center", NS_STYLE_TEXT_ALIGN_CENTER},
{"char", NS_STYLE_TEXT_ALIGN_CHAR},
{"justify", NS_STYLE_TEXT_ALIGN_JUSTIFY},
{nullptr, 0}};
{"left", StyleTextAlign::Left}, {"right", StyleTextAlign::Right},
{"center", StyleTextAlign::Center}, {"char", StyleTextAlign::Char},
{"justify", StyleTextAlign::Justify}, {nullptr, 0}};
bool nsGenericHTMLElement::ParseTableHAlignValue(const nsAString& aString,
nsAttrValue& aResult) {
@ -945,13 +968,13 @@ bool nsGenericHTMLElement::ParseTableHAlignValue(const nsAString& aString,
// This table is used for td, th, tr, col, thead, tbody and tfoot.
static const nsAttrValue::EnumTable kTableCellHAlignTable[] = {
{"left", NS_STYLE_TEXT_ALIGN_MOZ_LEFT},
{"right", NS_STYLE_TEXT_ALIGN_MOZ_RIGHT},
{"center", NS_STYLE_TEXT_ALIGN_MOZ_CENTER},
{"char", NS_STYLE_TEXT_ALIGN_CHAR},
{"justify", NS_STYLE_TEXT_ALIGN_JUSTIFY},
{"middle", NS_STYLE_TEXT_ALIGN_MOZ_CENTER},
{"absmiddle", NS_STYLE_TEXT_ALIGN_CENTER},
{"left", StyleTextAlign::MozLeft},
{"right", StyleTextAlign::MozRight},
{"center", StyleTextAlign::MozCenter},
{"char", StyleTextAlign::Char},
{"justify", StyleTextAlign::Justify},
{"middle", StyleTextAlign::MozCenter},
{"absmiddle", StyleTextAlign::Center},
{nullptr, 0}};
bool nsGenericHTMLElement::ParseTableCellHAlignValue(const nsAString& aString,
@ -1124,16 +1147,16 @@ void nsGenericHTMLElement::MapImageAlignAttributeInto(
if (value && value->Type() == nsAttrValue::eEnum) {
int32_t align = value->GetEnumValue();
if (!aDecls.PropertyIsSet(eCSSProperty_float)) {
if (align == NS_STYLE_TEXT_ALIGN_LEFT) {
if (align == uint8_t(StyleTextAlign::Left)) {
aDecls.SetKeywordValue(eCSSProperty_float, StyleFloat::Left);
} else if (align == NS_STYLE_TEXT_ALIGN_RIGHT) {
} else if (align == uint8_t(StyleTextAlign::Right)) {
aDecls.SetKeywordValue(eCSSProperty_float, StyleFloat::Right);
}
}
if (!aDecls.PropertyIsSet(eCSSProperty_vertical_align)) {
switch (align) {
case NS_STYLE_TEXT_ALIGN_LEFT:
case NS_STYLE_TEXT_ALIGN_RIGHT:
case uint8_t(StyleTextAlign::Left):
case uint8_t(StyleTextAlign::Right):
break;
default:
aDecls.SetKeywordValue(eCSSProperty_vertical_align, align);

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

@ -2722,19 +2722,19 @@ void ReflowInput::CalculateBlockSideMargins(LayoutFrameType aFrameType) {
// of the table wrapper's parent.
pri = pri->mParentReflowInput;
}
if (pri && (pri->mStyleText->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_LEFT ||
pri->mStyleText->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_CENTER ||
pri->mStyleText->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_RIGHT)) {
if (pri && (pri->mStyleText->mTextAlign == StyleTextAlign::MozLeft ||
pri->mStyleText->mTextAlign == StyleTextAlign::MozCenter ||
pri->mStyleText->mTextAlign == StyleTextAlign::MozRight)) {
if (pri->mWritingMode.IsBidiLTR()) {
isAutoStartMargin =
pri->mStyleText->mTextAlign != NS_STYLE_TEXT_ALIGN_MOZ_LEFT;
pri->mStyleText->mTextAlign != StyleTextAlign::MozLeft;
isAutoEndMargin =
pri->mStyleText->mTextAlign != NS_STYLE_TEXT_ALIGN_MOZ_RIGHT;
pri->mStyleText->mTextAlign != StyleTextAlign::MozRight;
} else {
isAutoStartMargin =
pri->mStyleText->mTextAlign != NS_STYLE_TEXT_ALIGN_MOZ_RIGHT;
pri->mStyleText->mTextAlign != StyleTextAlign::MozRight;
isAutoEndMargin =
pri->mStyleText->mTextAlign != NS_STYLE_TEXT_ALIGN_MOZ_LEFT;
pri->mStyleText->mTextAlign != StyleTextAlign::MozLeft;
}
}
// Otherwise apply the CSS rules, and ignore one margin by forcing

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

@ -2234,13 +2234,14 @@ void nsBlockFrame::MarkLineDirty(LineIterator aLine,
* Test whether lines are certain to be aligned left so that we can make
* resizing optimizations
*/
static inline bool IsAlignedLeft(uint8_t aAlignment, StyleDirection aDirection,
static inline bool IsAlignedLeft(StyleTextAlign aAlignment,
StyleDirection aDirection,
uint8_t aUnicodeBidi, nsIFrame* aFrame) {
return nsSVGUtils::IsInSVGTextSubtree(aFrame) ||
NS_STYLE_TEXT_ALIGN_LEFT == aAlignment ||
(((NS_STYLE_TEXT_ALIGN_START == aAlignment &&
StyleTextAlign::Left == aAlignment ||
(((StyleTextAlign::Start == aAlignment &&
StyleDirection::Ltr == aDirection) ||
(NS_STYLE_TEXT_ALIGN_END == aAlignment &&
(StyleTextAlign::End == aAlignment &&
StyleDirection::Rtl == aDirection)) &&
!(NS_STYLE_UNICODE_BIDI_PLAINTEXT & aUnicodeBidi));
}
@ -2621,11 +2622,9 @@ void nsBlockFrame::ReflowDirtyLines(BlockReflowInput& aState) {
if (aState.ContainerSize() != line->mContainerSize) {
line->mContainerSize = aState.ContainerSize();
bool isLastLine = line == mLines.back() && !GetNextInFlow() &&
NS_STYLE_TEXT_ALIGN_AUTO == StyleText()->mTextAlignLast;
uint8_t align =
isLastLine ? StyleText()->mTextAlign : StyleText()->mTextAlignLast;
const bool isLastLine = line == mLines.back() && !GetNextInFlow();
const auto align = isLastLine ? StyleText()->TextAlignForLastLine()
: StyleText()->mTextAlign;
if (line->mWritingMode.IsVertical() || line->mWritingMode.IsBidiRTL() ||
!IsAlignedLeft(align,
aState.mReflowInput.mStyleVisibility->mDirection,
@ -4903,17 +4902,15 @@ bool nsBlockFrame::PlaceLine(BlockReflowInput& aState,
const nsStyleText* styleText = StyleText();
/**
* text-align-last defaults to the same value as text-align when
* text-align-last is set to auto (except when text-align is set to justify),
* so in that case we don't need to set isLastLine.
* We don't care checking for IsLastLine properly if we don't care (if it
* can't change the used text-align value for the line).
*
* In other words, isLastLine really means isLastLineAndWeCare.
*/
bool isLastLine =
const bool isLastLine =
!nsSVGUtils::IsInSVGTextSubtree(this) &&
((NS_STYLE_TEXT_ALIGN_AUTO != styleText->mTextAlignLast ||
NS_STYLE_TEXT_ALIGN_JUSTIFY == styleText->mTextAlign) &&
(aLineLayout.GetLineEndsInBR() || IsLastLine(aState, aLine)));
styleText->TextAlignForLastLine() != styleText->mTextAlign &&
(aLineLayout.GetLineEndsInBR() || IsLastLine(aState, aLine));
aLineLayout.TextAlignLine(aLine, isLastLine);

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

@ -3077,30 +3077,16 @@ void nsLineLayout::TextAlignLine(nsLineBox* aLine, bool aIsLastLine) {
availISize, aLine->IStart(), aLine->ISize(), remainingISize);
#endif
// 'text-align-last: auto' is equivalent to the value of the 'text-align'
// property except when 'text-align' is set to 'justify', in which case it
// is 'justify' when 'text-justify' is 'distribute' and 'start' otherwise.
//
// XXX: the code below will have to change when we implement text-justify
//
nscoord dx = 0;
uint8_t textAlign = mStyleText->mTextAlign;
if (aIsLastLine) {
if (mStyleText->mTextAlignLast == NS_STYLE_TEXT_ALIGN_AUTO) {
if (textAlign == NS_STYLE_TEXT_ALIGN_JUSTIFY) {
textAlign = NS_STYLE_TEXT_ALIGN_START;
}
} else {
textAlign = mStyleText->mTextAlignLast;
}
}
StyleTextAlign textAlign =
aIsLastLine ? mStyleText->TextAlignForLastLine() : mStyleText->mTextAlign;
bool isSVG = nsSVGUtils::IsInSVGTextSubtree(mBlockReflowInput->mFrame);
bool doTextAlign = remainingISize > 0;
int32_t additionalGaps = 0;
if (!isSVG &&
(mHasRuby || (doTextAlign && textAlign == NS_STYLE_TEXT_ALIGN_JUSTIFY))) {
(mHasRuby || (doTextAlign && textAlign == StyleTextAlign::Justify))) {
JustificationComputationState computeState;
ComputeFrameJustification(psd, computeState);
if (mHasRuby && computeState.mFirstParticipant) {
@ -3127,7 +3113,7 @@ void nsLineLayout::TextAlignLine(nsLineBox* aLine, bool aIsLastLine) {
if (!isSVG && doTextAlign) {
switch (textAlign) {
case NS_STYLE_TEXT_ALIGN_JUSTIFY: {
case StyleTextAlign::Justify: {
int32_t opportunities =
psd->mFrame->mJustificationInfo.mInnerOpportunities;
if (opportunities > 0) {
@ -3151,30 +3137,32 @@ void nsLineLayout::TextAlignLine(nsLineBox* aLine, bool aIsLastLine) {
[[fallthrough]];
}
case NS_STYLE_TEXT_ALIGN_START:
// default alignment is to start edge so do nothing
case StyleTextAlign::Start:
case StyleTextAlign::Char:
// default alignment is to start edge so do nothing.
// Char is for tables so treat as start if we find it in block layout.
break;
case NS_STYLE_TEXT_ALIGN_LEFT:
case NS_STYLE_TEXT_ALIGN_MOZ_LEFT:
case StyleTextAlign::Left:
case StyleTextAlign::MozLeft:
if (lineWM.IsBidiRTL()) {
dx = remainingISize;
}
break;
case NS_STYLE_TEXT_ALIGN_RIGHT:
case NS_STYLE_TEXT_ALIGN_MOZ_RIGHT:
case StyleTextAlign::Right:
case StyleTextAlign::MozRight:
if (lineWM.IsBidiLTR()) {
dx = remainingISize;
}
break;
case NS_STYLE_TEXT_ALIGN_END:
case StyleTextAlign::End:
dx = remainingISize;
break;
case NS_STYLE_TEXT_ALIGN_CENTER:
case NS_STYLE_TEXT_ALIGN_MOZ_CENTER:
case StyleTextAlign::Center:
case StyleTextAlign::MozCenter:
dx = remainingISize / 2;
break;
}

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

@ -2181,9 +2181,9 @@ already_AddRefed<gfxTextRun> BuildTextRunsScanner::BuildTextRunForFrames(
nsTextFrame* nextBreakBeforeFrame = GetNextBreakBeforeFrame(&nextBreakIndex);
bool isSVG = nsSVGUtils::IsInSVGTextSubtree(mLineContainer);
bool enabledJustification =
(mLineContainer->StyleText()->mTextAlign == NS_STYLE_TEXT_ALIGN_JUSTIFY ||
(mLineContainer->StyleText()->mTextAlign == StyleTextAlign::Justify ||
mLineContainer->StyleText()->mTextAlignLast ==
NS_STYLE_TEXT_ALIGN_JUSTIFY);
StyleTextAlignLast::Justify);
const nsStyleText* textStyle = nullptr;
const nsStyleFont* fontStyle = nullptr;
@ -9544,9 +9544,9 @@ void nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth,
// Compute space and letter counts for justification, if required
if (!textStyle->WhiteSpaceIsSignificant() &&
(lineContainer->StyleText()->mTextAlign == NS_STYLE_TEXT_ALIGN_JUSTIFY ||
(lineContainer->StyleText()->mTextAlign == StyleTextAlign::Justify ||
lineContainer->StyleText()->mTextAlignLast ==
NS_STYLE_TEXT_ALIGN_JUSTIFY ||
StyleTextAlignLast::Justify ||
shouldSuppressLineBreak) &&
!nsSVGUtils::IsInSVGTextSubtree(lineContainer)) {
AddStateBits(TEXT_JUSTIFICATION_ENABLED);

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

@ -34,33 +34,40 @@ using mozilla::dom::Element;
static int8_t ParseStyleValue(nsAtom* aAttribute,
const nsAString& aAttributeValue) {
if (aAttribute == nsGkAtoms::rowalign_) {
if (aAttributeValue.EqualsLiteral("top"))
if (aAttributeValue.EqualsLiteral("top")) {
return static_cast<int8_t>(StyleVerticalAlignKeyword::Top);
else if (aAttributeValue.EqualsLiteral("bottom"))
}
if (aAttributeValue.EqualsLiteral("bottom")) {
return static_cast<int8_t>(StyleVerticalAlignKeyword::Bottom);
else if (aAttributeValue.EqualsLiteral("center"))
}
if (aAttributeValue.EqualsLiteral("center")) {
return static_cast<int8_t>(StyleVerticalAlignKeyword::Middle);
else
return static_cast<int8_t>(StyleVerticalAlignKeyword::Baseline);
} else if (aAttribute == nsGkAtoms::columnalign_) {
if (aAttributeValue.EqualsLiteral("left"))
return NS_STYLE_TEXT_ALIGN_LEFT;
else if (aAttributeValue.EqualsLiteral("right"))
return NS_STYLE_TEXT_ALIGN_RIGHT;
else
return NS_STYLE_TEXT_ALIGN_CENTER;
} else if (aAttribute == nsGkAtoms::rowlines_ ||
aAttribute == nsGkAtoms::columnlines_) {
if (aAttributeValue.EqualsLiteral("solid"))
return static_cast<int8_t>(StyleBorderStyle::Solid);
else if (aAttributeValue.EqualsLiteral("dashed"))
return static_cast<int8_t>(StyleBorderStyle::Dashed);
else
return static_cast<int8_t>(StyleBorderStyle::None);
} else {
MOZ_CRASH("Unrecognized attribute.");
}
return static_cast<int8_t>(StyleVerticalAlignKeyword::Baseline);
}
if (aAttribute == nsGkAtoms::columnalign_) {
if (aAttributeValue.EqualsLiteral("left")) {
return int8_t(StyleTextAlign::Left);
}
if (aAttributeValue.EqualsLiteral("right")) {
return int8_t(StyleTextAlign::Right);
}
return int8_t(StyleTextAlign::Center);
}
if (aAttribute == nsGkAtoms::rowlines_ ||
aAttribute == nsGkAtoms::columnlines_) {
if (aAttributeValue.EqualsLiteral("solid")) {
return static_cast<int8_t>(StyleBorderStyle::Solid);
}
if (aAttributeValue.EqualsLiteral("dashed")) {
return static_cast<int8_t>(StyleBorderStyle::Dashed);
}
return static_cast<int8_t>(StyleBorderStyle::None);
}
MOZ_CRASH("Unrecognized attribute.");
return -1;
}
@ -1202,7 +1209,7 @@ void nsMathMLmtdInnerFrame::Reflow(nsPresContext* aPresContext,
const nsStyleText* nsMathMLmtdInnerFrame::StyleTextForLineLayout() {
// Set the default alignment in case nothing was specified
uint8_t alignment = StyleText()->mTextAlign;
auto alignment = uint8_t(StyleText()->mTextAlign);
nsTArray<int8_t>* alignmentList =
FindCellProperty(this, ColumnAlignProperty());
@ -1219,7 +1226,7 @@ const nsStyleText* nsMathMLmtdInnerFrame::StyleTextForLineLayout() {
alignment = alignmentList->ElementAt(alignmentList->Length() - 1);
}
mUniqueStyleText->mTextAlign = alignment;
mUniqueStyleText->mTextAlign = StyleTextAlign(alignment);
return mUniqueStyleText.get();
}

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

@ -447,6 +447,7 @@ cbindgen-types = [
{ gecko = "StyleFloat", servo = "values::computed::Float" },
{ gecko = "StyleOverscrollBehavior", servo = "values::computed::OverscrollBehavior" },
{ gecko = "StyleTextAlign", servo = "values::computed::TextAlign" },
{ gecko = "StyleTextAlignLast", servo = "values::computed::text::TextAlignLast" },
{ gecko = "StyleTextOverflow", servo = "values::computed::TextOverflow" },
{ gecko = "StyleOverflow", servo = "values::computed::Overflow" },
{ gecko = "StyleOverflowAnchor", servo = "values::computed::OverflowAnchor" },

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

@ -167,15 +167,15 @@ const nsCString& nsCSSProps::GetStringValue(nsCSSCounterDesc aCounterDesc) {
/***************************************************************************/
const KTableEntry nsCSSProps::kTextAlignKTable[] = {
{eCSSKeyword_left, NS_STYLE_TEXT_ALIGN_LEFT},
{eCSSKeyword_right, NS_STYLE_TEXT_ALIGN_RIGHT},
{eCSSKeyword_center, NS_STYLE_TEXT_ALIGN_CENTER},
{eCSSKeyword_justify, NS_STYLE_TEXT_ALIGN_JUSTIFY},
{eCSSKeyword__moz_center, NS_STYLE_TEXT_ALIGN_MOZ_CENTER},
{eCSSKeyword__moz_right, NS_STYLE_TEXT_ALIGN_MOZ_RIGHT},
{eCSSKeyword__moz_left, NS_STYLE_TEXT_ALIGN_MOZ_LEFT},
{eCSSKeyword_start, NS_STYLE_TEXT_ALIGN_START},
{eCSSKeyword_end, NS_STYLE_TEXT_ALIGN_END},
{eCSSKeyword_left, StyleTextAlign::Left},
{eCSSKeyword_right, StyleTextAlign::Right},
{eCSSKeyword_center, StyleTextAlign::Center},
{eCSSKeyword_justify, StyleTextAlign::Justify},
{eCSSKeyword__moz_center, StyleTextAlign::MozCenter},
{eCSSKeyword__moz_right, StyleTextAlign::MozRight},
{eCSSKeyword__moz_left, StyleTextAlign::MozLeft},
{eCSSKeyword_start, StyleTextAlign::Start},
{eCSSKeyword_end, StyleTextAlign::End},
{eCSSKeyword_UNKNOWN, nsCSSKTableEntry::SENTINEL_VALUE},
};

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

@ -518,20 +518,6 @@ enum class StyleObjectFit : uint8_t {
ScaleDown,
};
// See nsStyleText
#define NS_STYLE_TEXT_ALIGN_START 0
#define NS_STYLE_TEXT_ALIGN_LEFT 1
#define NS_STYLE_TEXT_ALIGN_RIGHT 2
#define NS_STYLE_TEXT_ALIGN_CENTER 3
#define NS_STYLE_TEXT_ALIGN_JUSTIFY 4
#define NS_STYLE_TEXT_ALIGN_CHAR \
5 // align based on a certain character, for table cell
#define NS_STYLE_TEXT_ALIGN_END 6
#define NS_STYLE_TEXT_ALIGN_AUTO 7
#define NS_STYLE_TEXT_ALIGN_MOZ_CENTER 8
#define NS_STYLE_TEXT_ALIGN_MOZ_RIGHT 9
#define NS_STYLE_TEXT_ALIGN_MOZ_LEFT 10
// See nsStyleText
#define NS_STYLE_TEXT_DECORATION_STYLE_NONE \
0 // not in CSS spec, mapped to -moz-none

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

@ -2913,8 +2913,8 @@ static StyleRGBA DefaultColor(const Document& aDocument) {
nsStyleText::nsStyleText(const Document& aDocument)
: mColor(DefaultColor(aDocument)),
mTextTransform(StyleTextTransform::None()),
mTextAlign(NS_STYLE_TEXT_ALIGN_START),
mTextAlignLast(NS_STYLE_TEXT_ALIGN_AUTO),
mTextAlign(StyleTextAlign::Start),
mTextAlignLast(StyleTextAlignLast::Auto),
mTextJustify(StyleTextJustify::Auto),
mWhiteSpace(StyleWhiteSpace::Normal),
mHyphens(StyleHyphens::Manual),

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

@ -867,8 +867,8 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleText {
mozilla::StyleRGBA mColor;
mozilla::StyleTextTransform mTextTransform;
uint8_t mTextAlign; // NS_STYLE_TEXT_ALIGN_*
uint8_t mTextAlignLast; // NS_STYLE_TEXT_ALIGN_*
mozilla::StyleTextAlign mTextAlign;
mozilla::StyleTextAlignLast mTextAlignLast;
mozilla::StyleTextJustify mTextJustify;
mozilla::StyleWhiteSpace mWhiteSpace;
mozilla::StyleLineBreak mLineBreak = mozilla::StyleLineBreak::Auto;
@ -975,6 +975,36 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleText {
return true;
}
mozilla::StyleTextAlign TextAlignForLastLine() const {
switch (mTextAlignLast) {
case mozilla::StyleTextAlignLast::Auto:
// 'text-align-last: auto' is equivalent to the value of the
// 'text-align' property except when 'text-align' is set to 'justify',
// in which case it is 'justify' when 'text-justify' is 'distribute' and
// 'start' otherwise.
//
// XXX: the code below will have to change when we implement
// text-justify
if (mTextAlign == mozilla::StyleTextAlign::Justify) {
return mozilla::StyleTextAlign::Start;
}
return mTextAlign;
case mozilla::StyleTextAlignLast::Center:
return mozilla::StyleTextAlign::Center;
case mozilla::StyleTextAlignLast::Start:
return mozilla::StyleTextAlign::Start;
case mozilla::StyleTextAlignLast::End:
return mozilla::StyleTextAlign::End;
case mozilla::StyleTextAlignLast::Left:
return mozilla::StyleTextAlign::Left;
case mozilla::StyleTextAlignLast::Right:
return mozilla::StyleTextAlign::Right;
case mozilla::StyleTextAlignLast::Justify:
return mozilla::StyleTextAlign::Justify;
}
return mozilla::StyleTextAlign::Start;
}
bool HasWebkitTextStroke() const { return mWebkitTextStrokeWidth > 0; }
bool HasTextShadow() const { return !mTextShadow.IsEmpty(); }

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

@ -1031,12 +1031,12 @@ void nsTextBoxFrame::CalcDrawRect(gfxContext& aRenderingContext) {
// Align our text within the overall rect by checking our text-align property.
const nsStyleText* textStyle = StyleText();
if (textStyle->mTextAlign == NS_STYLE_TEXT_ALIGN_CENTER) {
if (textStyle->mTextAlign == StyleTextAlign::Center) {
textRect.IStart(wm) += (outerISize - textRect.ISize(wm)) / 2;
} else if (textStyle->mTextAlign == NS_STYLE_TEXT_ALIGN_END ||
(textStyle->mTextAlign == NS_STYLE_TEXT_ALIGN_LEFT &&
} else if (textStyle->mTextAlign == StyleTextAlign::End ||
(textStyle->mTextAlign == StyleTextAlign::Left &&
wm.IsBidiRTL()) ||
(textStyle->mTextAlign == NS_STYLE_TEXT_ALIGN_RIGHT &&
(textStyle->mTextAlign == StyleTextAlign::Right &&
wm.IsBidiLTR())) {
textRect.IStart(wm) += (outerISize - textRect.ISize(wm));
}

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

@ -1263,12 +1263,14 @@ void nsTreeBodyFrame::AdjustForCellText(nsAutoString& aText, int32_t aRowIndex,
aRenderingContext);
switch (aColumn->GetTextAlignment()) {
case NS_STYLE_TEXT_ALIGN_RIGHT: {
case mozilla::StyleTextAlign::Right:
aTextRect.x += aTextRect.width - width;
} break;
case NS_STYLE_TEXT_ALIGN_CENTER: {
break;
case mozilla::StyleTextAlign::Center:
aTextRect.x += (aTextRect.width - width) / 2;
} break;
break;
default:
break;
}
aTextRect.width = width;

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

@ -148,14 +148,14 @@ void nsTreeColumn::Invalidate(ErrorResult& aRv) {
mTextAlignment = textStyle->mTextAlign;
// START or END alignment sometimes means RIGHT
if ((mTextAlignment == NS_STYLE_TEXT_ALIGN_START &&
if ((mTextAlignment == StyleTextAlign::Start &&
vis->mDirection == StyleDirection::Rtl) ||
(mTextAlignment == NS_STYLE_TEXT_ALIGN_END &&
(mTextAlignment == StyleTextAlign::End &&
vis->mDirection == StyleDirection::Ltr)) {
mTextAlignment = NS_STYLE_TEXT_ALIGN_RIGHT;
} else if (mTextAlignment == NS_STYLE_TEXT_ALIGN_START ||
mTextAlignment == NS_STYLE_TEXT_ALIGN_END) {
mTextAlignment = NS_STYLE_TEXT_ALIGN_LEFT;
mTextAlignment = StyleTextAlign::Right;
} else if (mTextAlignment == StyleTextAlign::Start ||
mTextAlignment == StyleTextAlign::End) {
mTextAlignment = StyleTextAlign::Left;
}
// Figure out if we're the primary column (that has to have indentation

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

@ -23,6 +23,8 @@ class nsIContent;
struct nsRect;
namespace mozilla {
enum class StyleTextAlignKeyword : uint8_t;
using StyleTextAlign = StyleTextAlignKeyword;
class ErrorResult;
namespace dom {
class Element;
@ -111,7 +113,7 @@ class nsTreeColumn final : public nsISupports, public nsWrapperCache {
int16_t GetType() { return mType; }
int8_t GetCropStyle() { return mCropStyle; }
int32_t GetTextAlignment() { return mTextAlignment; }
mozilla::StyleTextAlign GetTextAlignment() { return mTextAlignment; }
void SetNext(nsTreeColumn* aNext) {
NS_ASSERTION(!mNext, "already have a next sibling");
@ -140,7 +142,7 @@ class nsTreeColumn final : public nsISupports, public nsWrapperCache {
int16_t mType;
int8_t mCropStyle;
int8_t mTextAlignment;
mozilla::StyleTextAlign mTextAlignment;
RefPtr<nsTreeColumn> mNext;
nsTreeColumn* mPrevious;

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

@ -10,10 +10,9 @@
#![allow(unsafe_code)]
use crate::gecko_bindings::structs::{self, Matrix4x4Components, nsresult};
use crate::gecko_bindings::structs::{Matrix4x4Components, nsresult};
use crate::stylesheets::RulesMutateError;
use crate::values::computed::transform::Matrix3D;
use crate::values::computed::TextAlign;
impl From<RulesMutateError> for nsresult {
fn from(other: RulesMutateError) -> Self {
@ -26,39 +25,6 @@ impl From<RulesMutateError> for nsresult {
}
}
impl TextAlign {
/// Obtain a specified value from a Gecko keyword value
///
/// Intended for use with presentation attributes, not style structs
pub fn from_gecko_keyword(kw: u32) -> Self {
match kw {
structs::NS_STYLE_TEXT_ALIGN_LEFT => TextAlign::Left,
structs::NS_STYLE_TEXT_ALIGN_RIGHT => TextAlign::Right,
structs::NS_STYLE_TEXT_ALIGN_CENTER => TextAlign::Center,
structs::NS_STYLE_TEXT_ALIGN_JUSTIFY => TextAlign::Justify,
structs::NS_STYLE_TEXT_ALIGN_MOZ_LEFT => TextAlign::MozLeft,
structs::NS_STYLE_TEXT_ALIGN_MOZ_RIGHT => TextAlign::MozRight,
structs::NS_STYLE_TEXT_ALIGN_MOZ_CENTER => TextAlign::MozCenter,
structs::NS_STYLE_TEXT_ALIGN_CHAR => TextAlign::Char,
structs::NS_STYLE_TEXT_ALIGN_END => TextAlign::End,
_ => panic!("Found unexpected value in style struct for text-align property"),
}
}
}
/// Convert to String from given chars pointer.
pub unsafe fn string_from_chars_pointer(p: *const u16) -> String {
use std::slice;
let mut length = 0;
let mut iter = p;
while *iter != 0 {
length += 1;
iter = iter.offset(1);
}
let char_vec = slice::from_raw_parts(p, length as usize);
String::from_utf16_lossy(char_vec)
}
impl<'a> From<&'a Matrix4x4Components> for Matrix3D {
fn from(m: &'a Matrix4x4Components) -> Matrix3D {
Matrix3D {

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

@ -382,6 +382,7 @@ class Longhand(object):
"ScrollSnapStrictness",
"ScrollSnapType",
"TextAlign",
"TextAlignLast",
"TextDecorationLine",
"TextEmphasisPosition",
"TextTransform",

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

@ -2016,16 +2016,9 @@ fn static_assert() {
<%self:impl_trait style_struct_name="InheritedText"
skip_longhands="text-align -webkit-text-stroke-width">
<% text_align_keyword = Keyword("text-align",
"start end left right center justify -moz-center -moz-left -moz-right char",
gecko_strip_moz_prefix=False) %>
${impl_keyword('text_align', 'mTextAlign', text_align_keyword)}
skip_longhands="-webkit-text-stroke-width">
${impl_non_negative_length('_webkit_text_stroke_width',
'mWebkitTextStrokeWidth')}
</%self:impl_trait>
<%self:impl_trait style_struct_name="Text" skip_longhands="initial-letter">

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

@ -141,11 +141,12 @@ ${helpers.predefined_type(
% endif
</%helpers:single_keyword>
${helpers.single_keyword(
${helpers.predefined_type(
"text-align-last",
"auto start end left right center justify",
"TextAlignLast",
"computed::text::TextAlignLast::Auto",
needs_context=False,
engines="gecko",
gecko_constant_prefix="NS_STYLE_TEXT_ALIGN",
animation_value_type="discrete",
spec="https://drafts.csswg.org/css-text/#propdef-text-align-last",
)}

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

@ -78,7 +78,7 @@ pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth};
pub use self::text::TextUnderlinePosition;
pub use self::text::{InitialLetter, LetterSpacing, LineBreak, LineHeight};
pub use self::text::{OverflowWrap, TextOverflow, WordBreak, WordSpacing};
pub use self::text::{TextAlign, TextEmphasisPosition, TextEmphasisStyle};
pub use self::text::{TextAlign, TextAlignLast, TextEmphasisPosition, TextEmphasisStyle};
pub use self::text::{TextDecorationLength, TextDecorationSkipInk};
pub use self::time::Time;
pub use self::transform::{Rotate, Scale, Transform, TransformOperation};

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

@ -18,8 +18,7 @@ use crate::Zero;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss};
pub use crate::values::specified::TextAlignKeyword as TextAlign;
pub use crate::values::specified::TextUnderlinePosition;
pub use crate::values::specified::text::{TextAlignLast, TextUnderlinePosition};
pub use crate::values::specified::{LineBreak, OverflowWrap, WordBreak};
pub use crate::values::specified::{TextDecorationLine, TextEmphasisPosition};
pub use crate::values::specified::{TextDecorationSkipInk, TextTransform};
@ -30,6 +29,9 @@ pub type InitialLetter = GenericInitialLetter<CSSFloat, CSSInteger>;
/// Implements type for `text-decoration-thickness` property.
pub type TextDecorationLength = GenericTextDecorationLength<LengthPercentage>;
/// The computed value of `text-align`.
pub type TextAlign = specified::TextAlignKeyword;
/// A computed value for the `letter-spacing` property.
#[repr(transparent)]
#[derive(

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

@ -85,6 +85,7 @@ pub use self::text::{InitialLetter, LetterSpacing, LineBreak, LineHeight, TextAl
pub use self::text::{OverflowWrap, TextEmphasisPosition, TextEmphasisStyle, WordBreak};
pub use self::text::{TextAlignKeyword, TextDecorationLine, TextOverflow, WordSpacing};
pub use self::text::{TextDecorationLength, TextDecorationSkipInk, TextTransform};
pub use self::text::TextAlignLast;
pub use self::time::Time;
pub use self::transform::{Rotate, Scale, Transform};
pub use self::transform::{TransformOrigin, TransformStyle, Translate};

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

@ -511,6 +511,35 @@ impl ToCss for TextTransformOther {
}
}
/// Specified and computed value of text-align-last.
#[derive(
Clone,
Copy,
Debug,
Eq,
FromPrimitive,
Hash,
MallocSizeOf,
Parse,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[allow(missing_docs)]
#[repr(u8)]
pub enum TextAlignLast {
Auto,
Start,
End,
Left,
Right,
Center,
Justify,
}
/// Specified value of text-align keyword value.
#[derive(
Clone,
@ -529,14 +558,18 @@ impl ToCss for TextTransformOther {
ToShmem,
)]
#[allow(missing_docs)]
#[repr(u8)]
pub enum TextAlignKeyword {
Start,
End,
Left,
Right,
Center,
#[cfg(any(feature = "gecko", feature = "servo-layout-2013"))]
Justify,
#[css(skip)]
#[cfg(feature = "gecko")]
Char,
End,
#[cfg(feature = "gecko")]
MozCenter,
#[cfg(feature = "gecko")]
@ -549,9 +582,6 @@ pub enum TextAlignKeyword {
ServoLeft,
#[cfg(feature = "servo-layout-2013")]
ServoRight,
#[css(skip)]
#[cfg(feature = "gecko")]
Char,
}
/// Specified value of text-align property.
@ -573,14 +603,6 @@ pub enum TextAlign {
MozCenterOrInherit,
}
impl TextAlign {
/// Convert an enumerated value coming from Gecko to a `TextAlign`.
#[cfg(feature = "gecko")]
pub fn from_gecko_keyword(kw: u32) -> Self {
TextAlign::Keyword(TextAlignKeyword::from_gecko_keyword(kw))
}
}
impl ToComputedValue for TextAlign {
type ComputedValue = TextAlignKeyword;

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

@ -213,6 +213,8 @@ include = [
"SVGLength",
"SVGOpacity",
"SVGWidth",
"TextAlign",
"TextAlignLast",
]
item_types = ["enums", "structs", "unions", "typedefs", "functions", "constants"]
renaming_overrides_prefixing = true

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

@ -4790,9 +4790,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetKeywordValue(
use style::properties::PropertyDeclaration;
use style::values::generics::box_::{VerticalAlign, VerticalAlignKeyword};
use style::values::generics::font::FontStyle;
use style::values::specified::BorderStyle;
use style::values::specified::Display;
use style::values::specified::{Clear, Float};
use style::values::specified::{BorderStyle, Clear, Display, Float, TextAlign};
fn get_from_computed<T>(value: u32) -> T
where
@ -4812,7 +4810,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetKeywordValue(
Float => get_from_computed::<Float>(value),
Clear => get_from_computed::<Clear>(value),
VerticalAlign => VerticalAlign::Keyword(VerticalAlignKeyword::from_u32(value).unwrap()),
TextAlign => longhands::text_align::SpecifiedValue::from_gecko_keyword(value),
TextAlign => get_from_computed::<TextAlign>(value),
TextEmphasisPosition => longhands::text_emphasis_position::SpecifiedValue::from_gecko_keyword(value),
FontSize => {
// We rely on Gecko passing in font-size values (0...7) here.