Bug 1547985 - Use rust types for vertical-align. r=mats

The previous commit removed the dependence on the discriminant value, so we
don't need to keep discriminants different from text-align anymore.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2019-05-01 13:08:34 +00:00
Родитель 587c78f065
Коммит edde08a7cb
26 изменённых файлов: 206 добавлений и 313 удалений

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

@ -717,58 +717,37 @@ void TextAttrsMgr::TextPosTextAttr::ExposeValue(
TextAttrsMgr::TextPosValue TextAttrsMgr::TextPosTextAttr::GetTextPosValue(
nsIFrame* aFrame) const {
const nsStyleCoord& styleCoord = aFrame->StyleDisplay()->mVerticalAlign;
switch (styleCoord.GetUnit()) {
case eStyleUnit_Enumerated:
switch (styleCoord.GetIntValue()) {
case NS_STYLE_VERTICAL_ALIGN_BASELINE:
return eTextPosBaseline;
case NS_STYLE_VERTICAL_ALIGN_SUB:
return eTextPosSub;
case NS_STYLE_VERTICAL_ALIGN_SUPER:
return eTextPosSuper;
// No good guess for these:
// NS_STYLE_VERTICAL_ALIGN_TOP
// NS_STYLE_VERTICAL_ALIGN_TEXT_TOP
// NS_STYLE_VERTICAL_ALIGN_MIDDLE
// NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM
// NS_STYLE_VERTICAL_ALIGN_BOTTOM
// NS_STYLE_VERTICAL_ALIGN_MIDDLE_WITH_BASELINE
// Do not expose value of text-position attribute.
default:
break;
}
return eTextPosNone;
case eStyleUnit_Percent: {
float percentValue = styleCoord.GetPercentValue();
return percentValue > 0
? eTextPosSuper
: (percentValue < 0 ? eTextPosSub : eTextPosBaseline);
const auto& verticalAlign = aFrame->StyleDisplay()->mVerticalAlign;
if (verticalAlign.IsKeyword()) {
switch (verticalAlign.AsKeyword()) {
case StyleVerticalAlignKeyword::Baseline:
return eTextPosBaseline;
case StyleVerticalAlignKeyword::Sub:
return eTextPosSub;
case StyleVerticalAlignKeyword::Super:
return eTextPosSuper;
// No good guess for the rest, so do not expose value of text-position
// attribute.
default:
return eTextPosNone;
}
case eStyleUnit_Coord: {
nscoord coordValue = styleCoord.GetCoordValue();
return coordValue > 0 ? eTextPosSuper
: (coordValue < 0 ? eTextPosSub : eTextPosBaseline);
}
case eStyleUnit_Null:
case eStyleUnit_Normal:
case eStyleUnit_Auto:
case eStyleUnit_None:
case eStyleUnit_Factor:
case eStyleUnit_Degree:
case eStyleUnit_FlexFraction:
case eStyleUnit_Integer:
case eStyleUnit_Calc:
break;
}
const nsIContent* content = aFrame->GetContent();
if (content) {
const auto& length = verticalAlign.AsLength();
if (length.ConvertsToPercentage()) {
float percentValue = length.ToPercentage();
return percentValue > 0
? eTextPosSuper
: (percentValue < 0 ? eTextPosSub : eTextPosBaseline);
}
if (length.ConvertsToLength()) {
nscoord coordValue = length.ToLength();
return coordValue > 0 ? eTextPosSuper
: (coordValue < 0 ? eTextPosSub : eTextPosBaseline);
}
if (const nsIContent* content = aFrame->GetContent()) {
if (content->IsHTMLElement(nsGkAtoms::sup)) return eTextPosSuper;
if (content->IsHTMLElement(nsGkAtoms::sub)) return eTextPosSub;
}

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

@ -967,10 +967,10 @@ static const nsAttrValue::EnumTable kScrollingTable[] = {
{"auto", NS_STYLE_FRAME_AUTO}, {nullptr, 0}};
static const nsAttrValue::EnumTable kTableVAlignTable[] = {
{"top", NS_STYLE_VERTICAL_ALIGN_TOP},
{"middle", NS_STYLE_VERTICAL_ALIGN_MIDDLE},
{"bottom", NS_STYLE_VERTICAL_ALIGN_BOTTOM},
{"baseline", NS_STYLE_VERTICAL_ALIGN_BASELINE},
{"top", StyleVerticalAlignKeyword::Top},
{"middle", StyleVerticalAlignKeyword::Middle},
{"bottom", StyleVerticalAlignKeyword::Bottom},
{"baseline", StyleVerticalAlignKeyword::Baseline},
{nullptr, 0}};
bool nsGenericHTMLElement::ParseAlignValue(const nsAString& aString,
@ -979,17 +979,17 @@ bool nsGenericHTMLElement::ParseAlignValue(const nsAString& aString,
{"left", NS_STYLE_TEXT_ALIGN_LEFT},
{"right", NS_STYLE_TEXT_ALIGN_RIGHT},
{"top", NS_STYLE_VERTICAL_ALIGN_TOP},
{"middle", NS_STYLE_VERTICAL_ALIGN_MIDDLE_WITH_BASELINE},
{"bottom", NS_STYLE_VERTICAL_ALIGN_BASELINE},
{"top", StyleVerticalAlignKeyword::Top},
{"middle", StyleVerticalAlignKeyword::MozMiddleWithBaseline},
{"bottom", StyleVerticalAlignKeyword::Bottom},
{"center", NS_STYLE_VERTICAL_ALIGN_MIDDLE_WITH_BASELINE},
{"baseline", NS_STYLE_VERTICAL_ALIGN_BASELINE},
{"center", StyleVerticalAlignKeyword::MozMiddleWithBaseline},
{"baseline", StyleVerticalAlignKeyword::Baseline},
{"texttop", NS_STYLE_VERTICAL_ALIGN_TEXT_TOP},
{"absmiddle", NS_STYLE_VERTICAL_ALIGN_MIDDLE},
{"abscenter", NS_STYLE_VERTICAL_ALIGN_MIDDLE},
{"absbottom", NS_STYLE_VERTICAL_ALIGN_BOTTOM},
{"texttop", StyleVerticalAlignKeyword::TextTop},
{"absmiddle", StyleVerticalAlignKeyword::Middle},
{"abscenter", StyleVerticalAlignKeyword::Middle},
{"absbottom", StyleVerticalAlignKeyword::Bottom},
{nullptr, 0}};
return aResult.ParseEnumValue(aString, kAlignTable, false);

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

@ -9763,37 +9763,37 @@ bool nsIFrame::IsFocusable(int32_t* aTabIndex, bool aWithMouse) {
*/
bool nsIFrame::HasSignificantTerminalNewline() const { return false; }
static uint8_t ConvertSVGDominantBaselineToVerticalAlign(
static StyleVerticalAlignKeyword ConvertSVGDominantBaselineToVerticalAlign(
uint8_t aDominantBaseline) {
// Most of these are approximate mappings.
switch (aDominantBaseline) {
case NS_STYLE_DOMINANT_BASELINE_HANGING:
case NS_STYLE_DOMINANT_BASELINE_TEXT_BEFORE_EDGE:
return NS_STYLE_VERTICAL_ALIGN_TEXT_TOP;
return StyleVerticalAlignKeyword::TextTop;
case NS_STYLE_DOMINANT_BASELINE_TEXT_AFTER_EDGE:
case NS_STYLE_DOMINANT_BASELINE_IDEOGRAPHIC:
return NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM;
return StyleVerticalAlignKeyword::TextBottom;
case NS_STYLE_DOMINANT_BASELINE_CENTRAL:
case NS_STYLE_DOMINANT_BASELINE_MIDDLE:
case NS_STYLE_DOMINANT_BASELINE_MATHEMATICAL:
return NS_STYLE_VERTICAL_ALIGN_MIDDLE;
return StyleVerticalAlignKeyword::Middle;
case NS_STYLE_DOMINANT_BASELINE_AUTO:
case NS_STYLE_DOMINANT_BASELINE_ALPHABETIC:
return NS_STYLE_VERTICAL_ALIGN_BASELINE;
return StyleVerticalAlignKeyword::Baseline;
case NS_STYLE_DOMINANT_BASELINE_USE_SCRIPT:
case NS_STYLE_DOMINANT_BASELINE_NO_CHANGE:
case NS_STYLE_DOMINANT_BASELINE_RESET_SIZE:
// These three should not simply map to 'baseline', but we don't
// support the complex baseline model that SVG 1.1 has and which
// css3-linebox now defines.
return NS_STYLE_VERTICAL_ALIGN_BASELINE;
return StyleVerticalAlignKeyword::Baseline;
default:
MOZ_ASSERT_UNREACHABLE("unexpected aDominantBaseline value");
return NS_STYLE_VERTICAL_ALIGN_BASELINE;
return StyleVerticalAlignKeyword::Baseline;
}
}
uint8_t nsIFrame::VerticalAlignEnum() const {
Maybe<StyleVerticalAlignKeyword> nsIFrame::VerticalAlignEnum() const {
if (nsSVGUtils::IsInSVGTextSubtree(this)) {
uint8_t dominantBaseline;
for (const nsIFrame* frame = this; frame; frame = frame->GetParent()) {
@ -9803,15 +9803,15 @@ uint8_t nsIFrame::VerticalAlignEnum() const {
break;
}
}
return ConvertSVGDominantBaselineToVerticalAlign(dominantBaseline);
return Some(ConvertSVGDominantBaselineToVerticalAlign(dominantBaseline));
}
const nsStyleCoord& verticalAlign = StyleDisplay()->mVerticalAlign;
if (verticalAlign.GetUnit() == eStyleUnit_Enumerated) {
return verticalAlign.GetIntValue();
const auto& verticalAlign = StyleDisplay()->mVerticalAlign;
if (verticalAlign.IsKeyword()) {
return Some(verticalAlign.AsKeyword());
}
return eInvalidVerticalAlign;
return Nothing();
}
NS_IMETHODIMP

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

@ -3939,10 +3939,9 @@ class nsIFrame : public nsQueryFrame {
* of the enumerated values. If this is an SVG text frame, it returns a value
* that corresponds to the value of dominant-baseline. If the
* vertical-align property has length or percentage value, this returns
* eInvalidVerticalAlign.
* Nothing().
*/
uint8_t VerticalAlignEnum() const;
enum { eInvalidVerticalAlign = 0xFF };
Maybe<mozilla::StyleVerticalAlignKeyword> VerticalAlignEnum() const;
void CreateOwnLayerIfNeeded(nsDisplayListBuilder* aBuilder,
nsDisplayList* aList,

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

@ -1959,47 +1959,51 @@ void nsLineLayout::VerticalAlignFrames(PerSpanData* psd) {
// Get vertical-align property ("vertical-align" is the CSS name for
// block-direction align)
const nsStyleCoord& verticalAlign = frame->StyleDisplay()->mVerticalAlign;
uint8_t verticalAlignEnum = frame->VerticalAlignEnum();
const auto& verticalAlign = frame->StyleDisplay()->mVerticalAlign;
Maybe<StyleVerticalAlignKeyword> verticalAlignEnum =
frame->VerticalAlignEnum();
#ifdef NOISY_BLOCKDIR_ALIGN
printf(" [frame]");
frame->ListTag(stdout);
printf(": verticalAlignUnit=%d (enum == %d", verticalAlign.GetUnit(),
((eStyleUnit_Enumerated == verticalAlign.GetUnit())
? verticalAlign.GetIntValue()
: -1));
if (verticalAlignEnum != nsIFrame::eInvalidVerticalAlign) {
printf(": verticalAlignIsKw=%d (enum == %d", verticalAlign.IsKeyword(),
verticalAlign.IsKeyword()
? static_cast<int>(verticalAlign.AsKeyword())
: -1);
if (verticalAlignEnum) {
printf(", after SVG dominant-baseline conversion == %d",
verticalAlignEnum);
static_cast<int>(*verticalAlignEnum));
}
printf(")\n");
#endif
if (verticalAlignEnum != nsIFrame::eInvalidVerticalAlign) {
if (verticalAlignEnum) {
StyleVerticalAlignKeyword keyword = *verticalAlignEnum;
if (lineWM.IsVertical()) {
if (verticalAlignEnum == NS_STYLE_VERTICAL_ALIGN_MIDDLE) {
if (keyword == StyleVerticalAlignKeyword::Middle) {
// For vertical writing mode where the dominant baseline is centered
// (i.e. text-orientation is not sideways-*), we remap 'middle' to
// 'middle-with-baseline' so that images align sensibly with the
// center-baseline-aligned text.
if (!lineWM.IsSideways()) {
verticalAlignEnum = NS_STYLE_VERTICAL_ALIGN_MIDDLE_WITH_BASELINE;
keyword = StyleVerticalAlignKeyword::MozMiddleWithBaseline;
}
} else if (lineWM.IsLineInverted()) {
// Swap the meanings of top and bottom when line is inverted
// relative to block direction.
switch (verticalAlignEnum) {
case NS_STYLE_VERTICAL_ALIGN_TOP:
verticalAlignEnum = NS_STYLE_VERTICAL_ALIGN_BOTTOM;
switch (keyword) {
case StyleVerticalAlignKeyword::Top:
keyword = StyleVerticalAlignKeyword::Bottom;
break;
case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
verticalAlignEnum = NS_STYLE_VERTICAL_ALIGN_TOP;
case StyleVerticalAlignKeyword::Bottom:
keyword = StyleVerticalAlignKeyword::Top;
break;
case NS_STYLE_VERTICAL_ALIGN_TEXT_TOP:
verticalAlignEnum = NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM;
case StyleVerticalAlignKeyword::TextTop:
keyword = StyleVerticalAlignKeyword::TextBottom;
break;
case NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM:
verticalAlignEnum = NS_STYLE_VERTICAL_ALIGN_TEXT_TOP;
case StyleVerticalAlignKeyword::TextBottom:
keyword = StyleVerticalAlignKeyword::TextTop;
break;
default:
break;
}
}
@ -2010,19 +2014,18 @@ void nsLineLayout::VerticalAlignFrames(PerSpanData* psd) {
// For superscript and subscript, raise or lower the baseline of the box
// to the proper offset of the parent's box, then proceed as for BASELINE
if (verticalAlignEnum == NS_STYLE_VERTICAL_ALIGN_SUB ||
verticalAlignEnum == NS_STYLE_VERTICAL_ALIGN_SUPER) {
revisedBaselineBCoord +=
lineWM.FlowRelativeToLineRelativeFactor() *
(verticalAlignEnum == NS_STYLE_VERTICAL_ALIGN_SUB
? fm->SubscriptOffset()
: -fm->SuperscriptOffset());
verticalAlignEnum = NS_STYLE_VERTICAL_ALIGN_BASELINE;
if (keyword == StyleVerticalAlignKeyword::Sub ||
keyword == StyleVerticalAlignKeyword::Super) {
revisedBaselineBCoord += lineWM.FlowRelativeToLineRelativeFactor() *
(keyword == StyleVerticalAlignKeyword::Sub
? fm->SubscriptOffset()
: -fm->SuperscriptOffset());
keyword = StyleVerticalAlignKeyword::Baseline;
}
switch (verticalAlignEnum) {
switch (keyword) {
default:
case NS_STYLE_VERTICAL_ALIGN_BASELINE:
case StyleVerticalAlignKeyword::Baseline:
if (lineWM.IsVertical() && !lineWM.IsSideways()) {
if (frameSpan) {
pfd->mBounds.BStart(lineWM) =
@ -2038,7 +2041,7 @@ void nsLineLayout::VerticalAlignFrames(PerSpanData* psd) {
pfd->mBlockDirAlign = VALIGN_OTHER;
break;
case NS_STYLE_VERTICAL_ALIGN_TOP: {
case StyleVerticalAlignKeyword::Top: {
pfd->mBlockDirAlign = VALIGN_TOP;
nscoord subtreeBSize = logicalBSize;
if (frameSpan) {
@ -2052,7 +2055,7 @@ void nsLineLayout::VerticalAlignFrames(PerSpanData* psd) {
break;
}
case NS_STYLE_VERTICAL_ALIGN_BOTTOM: {
case StyleVerticalAlignKeyword::Bottom: {
pfd->mBlockDirAlign = VALIGN_BOTTOM;
nscoord subtreeBSize = logicalBSize;
if (frameSpan) {
@ -2066,7 +2069,7 @@ void nsLineLayout::VerticalAlignFrames(PerSpanData* psd) {
break;
}
case NS_STYLE_VERTICAL_ALIGN_MIDDLE: {
case StyleVerticalAlignKeyword::Middle: {
// Align the midpoint of the frame with 1/2 the parents
// x-height above the baseline.
nscoord parentXHeight =
@ -2084,7 +2087,7 @@ void nsLineLayout::VerticalAlignFrames(PerSpanData* psd) {
break;
}
case NS_STYLE_VERTICAL_ALIGN_TEXT_TOP: {
case StyleVerticalAlignKeyword::TextTop: {
// The top of the logical box is aligned with the top of
// the parent element's text.
// XXX For vertical text we will need a new API to get the logical
@ -2103,7 +2106,7 @@ void nsLineLayout::VerticalAlignFrames(PerSpanData* psd) {
break;
}
case NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM: {
case StyleVerticalAlignKeyword::TextBottom: {
// The bottom of the logical box is aligned with the
// bottom of the parent elements text.
nscoord parentDescent =
@ -2121,7 +2124,7 @@ void nsLineLayout::VerticalAlignFrames(PerSpanData* psd) {
break;
}
case NS_STYLE_VERTICAL_ALIGN_MIDDLE_WITH_BASELINE: {
case StyleVerticalAlignKeyword::MozMiddleWithBaseline: {
// Align the midpoint of the frame with the baseline of the parent.
if (frameSpan) {
pfd->mBounds.BStart(lineWM) =
@ -2136,17 +2139,16 @@ void nsLineLayout::VerticalAlignFrames(PerSpanData* psd) {
}
} else {
// We have either a coord, a percent, or a calc().
nscoord pctBasis = 0;
if (verticalAlign.HasPercent()) {
nscoord offset = verticalAlign.AsLength().Resolve([&] {
// Percentages are like lengths, except treated as a percentage
// of the elements line block size value.
float inflation =
GetInflationForBlockDirAlignment(frame, mInflationMinFontSize);
pctBasis = ReflowInput::CalcLineHeight(
return ReflowInput::CalcLineHeight(
frame->GetContent(), frame->Style(), frame->PresContext(),
mBlockReflowInput->ComputedBSize(), inflation);
}
nscoord offset = verticalAlign.ComputeCoordPercentCalc(pctBasis);
});
// According to the CSS2 spec (10.8.1), a positive value
// "raises" the box by the given distance while a negative value
// "lowers" the box by the given distance (with zero being the

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

@ -1848,9 +1848,12 @@ bool BuildTextRunsScanner::ContinueTextRunAcrossFrames(nsTextFrame* aFrame1,
}
// 2. vertical-align is not baseline.
const nsStyleCoord& coord = ctx->StyleDisplay()->mVerticalAlign;
if (coord.GetUnit() != eStyleUnit_Enumerated ||
coord.GetIntValue() != NS_STYLE_VERTICAL_ALIGN_BASELINE) {
//
// FIXME: Should this use VerticalAlignEnum()?
const auto& verticalAlign = ctx->StyleDisplay()->mVerticalAlign;
if (!verticalAlign.IsKeyword() ||
verticalAlign.AsKeyword() !=
StyleVerticalAlignKeyword::Baseline) {
return true;
}
@ -5022,7 +5025,9 @@ void nsTextFrame::GetTextDecorations(
// that should be set (see nsLineLayout::VerticalAlignLine).
if (firstBlock) {
// At this point, fChild can't be null since TextFrames can't be blocks
if (fChild->VerticalAlignEnum() != NS_STYLE_VERTICAL_ALIGN_BASELINE) {
Maybe<StyleVerticalAlignKeyword> verticalAlign =
fChild->VerticalAlignEnum();
if (verticalAlign != Some(StyleVerticalAlignKeyword::Baseline)) {
// Since offset is the offset in the child's coordinate space, we have
// to undo the accumulation to bring the transform out of the block's
// coordinate space

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

@ -34,13 +34,13 @@ static int8_t ParseStyleValue(nsAtom* aAttribute,
const nsAString& aAttributeValue) {
if (aAttribute == nsGkAtoms::rowalign_) {
if (aAttributeValue.EqualsLiteral("top"))
return NS_STYLE_VERTICAL_ALIGN_TOP;
return static_cast<int8_t>(StyleVerticalAlignKeyword::Top);
else if (aAttributeValue.EqualsLiteral("bottom"))
return NS_STYLE_VERTICAL_ALIGN_BOTTOM;
return static_cast<int8_t>(StyleVerticalAlignKeyword::Bottom);
else if (aAttributeValue.EqualsLiteral("center"))
return NS_STYLE_VERTICAL_ALIGN_MIDDLE;
return static_cast<int8_t>(StyleVerticalAlignKeyword::Middle);
else
return NS_STYLE_VERTICAL_ALIGN_BASELINE;
return static_cast<int8_t>(StyleVerticalAlignKeyword::Baseline);
} else if (aAttribute == nsGkAtoms::columnalign_) {
if (aAttributeValue.EqualsLiteral("left"))
return NS_STYLE_TEXT_ALIGN_LEFT;
@ -1124,9 +1124,9 @@ nsresult nsMathMLmtdFrame::AttributeChanged(int32_t aNameSpaceID,
return NS_OK;
}
uint8_t nsMathMLmtdFrame::GetVerticalAlign() const {
StyleVerticalAlignKeyword nsMathMLmtdFrame::GetVerticalAlign() const {
// Set the default alignment in case no alignment was specified
uint8_t alignment = nsTableCellFrame::GetVerticalAlign();
auto alignment = nsTableCellFrame::GetVerticalAlign();
nsTArray<int8_t>* alignmentList = FindCellProperty(this, RowAlignProperty());
@ -1135,10 +1135,10 @@ uint8_t nsMathMLmtdFrame::GetVerticalAlign() const {
// If the row number is greater than the number of provided rowalign values,
// we simply repeat the last value.
if (rowIndex < alignmentList->Length())
alignment = alignmentList->ElementAt(rowIndex);
else
alignment = alignmentList->ElementAt(alignmentList->Length() - 1);
return static_cast<StyleVerticalAlignKeyword>(
(rowIndex < alignmentList->Length())
? alignmentList->ElementAt(rowIndex)
: alignmentList->LastElement());
}
return alignment;

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

@ -223,7 +223,7 @@ class nsMathMLmtdFrame final : public nsTableCellFrame {
virtual nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
int32_t aModType) override;
virtual uint8_t GetVerticalAlign() const override;
virtual mozilla::StyleVerticalAlignKeyword GetVerticalAlign() const override;
virtual nsresult ProcessBorders(nsTableFrame* aFrame,
nsDisplayListBuilder* aBuilder,
const nsDisplayListSet& aLists) override;

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

@ -470,6 +470,8 @@ cbindgen-types = [
{ gecko = "StyleRGBA", servo = "cssparser::RGBA" },
{ gecko = "StyleOrigin", servo = "stylesheets::Origin" },
{ gecko = "StyleGenericGradientItem", servo = "values::generics::image::GradientItem" },
{ gecko = "StyleGenericVerticalAlign", servo = "values::generics::box_::VerticalAlign" },
{ gecko = "StyleVerticalAlignKeyword", servo = "values::generics::box_::VerticalAlignKeyword" },
]
mapped-generic-types = [

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

@ -381,19 +381,6 @@ const KTableEntry nsCSSProps::kTextOverflowKTable[] = {
{eCSSKeyword_ellipsis, NS_STYLE_TEXT_OVERFLOW_ELLIPSIS},
{eCSSKeyword_UNKNOWN, -1}};
const KTableEntry nsCSSProps::kVerticalAlignKTable[] = {
{eCSSKeyword_baseline, NS_STYLE_VERTICAL_ALIGN_BASELINE},
{eCSSKeyword_sub, NS_STYLE_VERTICAL_ALIGN_SUB},
{eCSSKeyword_super, NS_STYLE_VERTICAL_ALIGN_SUPER},
{eCSSKeyword_top, NS_STYLE_VERTICAL_ALIGN_TOP},
{eCSSKeyword_text_top, NS_STYLE_VERTICAL_ALIGN_TEXT_TOP},
{eCSSKeyword_middle, NS_STYLE_VERTICAL_ALIGN_MIDDLE},
{eCSSKeyword__moz_middle_with_baseline,
NS_STYLE_VERTICAL_ALIGN_MIDDLE_WITH_BASELINE},
{eCSSKeyword_bottom, NS_STYLE_VERTICAL_ALIGN_BOTTOM},
{eCSSKeyword_text_bottom, NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM},
{eCSSKeyword_UNKNOWN, -1}};
// keyword tables for SVG properties
const KTableEntry nsCSSProps::kShapeRadiusKTable[] = {

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

@ -311,7 +311,6 @@ class nsCSSProps {
static const KTableEntry kTextDecorationStyleKTable[];
static const KTableEntry kTextEmphasisStyleShapeKTable[];
static const KTableEntry kTextOverflowKTable[];
static const KTableEntry kVerticalAlignKTable[];
};
// MOZ_DBG support for nsCSSPropertyID

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

@ -549,9 +549,6 @@ enum class StyleGridTrackBreadth : uint8_t {
#define NS_STYLE_TEXT_ALIGN_MOZ_RIGHT 9
#define NS_STYLE_TEXT_ALIGN_MOZ_LEFT 10
// Note: make sure that the largest NS_STYLE_TEXT_ALIGN_* value is smaller than
// the smallest NS_STYLE_VERTICAL_ALIGN_* value below!
// See nsStyleText
#define NS_STYLE_TEXT_DECORATION_STYLE_NONE \
0 // not in CSS spec, mapped to -moz-none
@ -579,20 +576,6 @@ enum class StyleGridTrackBreadth : uint8_t {
#define NS_STYLE_TOP_LAYER_NONE 0 // not in the top layer
#define NS_STYLE_TOP_LAYER_TOP 1 // in the top layer
// See nsStyleText
// 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 14
#define NS_STYLE_VERTICAL_ALIGN_SUB 15
#define NS_STYLE_VERTICAL_ALIGN_SUPER 16
#define NS_STYLE_VERTICAL_ALIGN_TOP 17
#define NS_STYLE_VERTICAL_ALIGN_TEXT_TOP 18
#define NS_STYLE_VERTICAL_ALIGN_MIDDLE 19
#define NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM 20
#define NS_STYLE_VERTICAL_ALIGN_BOTTOM 21
#define NS_STYLE_VERTICAL_ALIGN_MIDDLE_WITH_BASELINE 22
// See nsStyleVisibility
#define NS_STYLE_VISIBILITY_HIDDEN 0
#define NS_STYLE_VISIBILITY_VISIBLE 1

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

@ -2965,7 +2965,8 @@ nsStyleDisplay::nsStyleDisplay(const Document& aDocument)
{0.}},
mChildPerspective(StylePerspective::None()),
mPerspectiveOrigin(Position::FromPercentage(0.5f)),
mVerticalAlign(NS_STYLE_VERTICAL_ALIGN_BASELINE, eStyleUnit_Enumerated),
mVerticalAlign(
StyleVerticalAlign::Keyword(StyleVerticalAlignKeyword::Baseline)),
mTransitions(
nsStyleAutoArray<StyleTransition>::WITH_SINGLE_INITIAL_ELEMENT),
mTransitionTimingFunctionCount(1),

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

@ -1922,8 +1922,7 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleDisplay {
mozilla::StylePerspective mChildPerspective;
mozilla::Position mPerspectiveOrigin;
nsStyleCoord mVerticalAlign; // coord, percent, calc, enum
// (NS_STYLE_VERTICAL_ALIGN_*)
mozilla::StyleVerticalAlign mVerticalAlign;
nsStyleAutoArray<mozilla::StyleTransition> mTransitions;

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

@ -523,8 +523,6 @@ void nsTableCellFrame::BlockDirAlignChild(WritingMode aWM, nscoord aMaxAscent) {
nscoord bStartInset = borderPadding.BStart(aWM);
nscoord bEndInset = borderPadding.BEnd(aWM);
uint8_t verticalAlignFlags = GetVerticalAlign();
nscoord bSize = BSize(aWM);
nsIFrame* firstKid = mFrames.FirstChild();
nsSize containerSize = mRect.Size();
@ -536,26 +534,26 @@ void nsTableCellFrame::BlockDirAlignChild(WritingMode aWM, nscoord aMaxAscent) {
// Vertically align the child
nscoord kidBStart = 0;
switch (verticalAlignFlags) {
case NS_STYLE_VERTICAL_ALIGN_BASELINE:
switch (GetVerticalAlign()) {
case StyleVerticalAlignKeyword::Baseline:
// Align the baselines of the child frame with the baselines of
// other children in the same row which have 'vertical-align: baseline'
kidBStart = bStartInset + aMaxAscent - GetCellBaseline();
break;
case NS_STYLE_VERTICAL_ALIGN_TOP:
case StyleVerticalAlignKeyword::Top:
// Align the top of the child frame with the top of the content area,
kidBStart = bStartInset;
break;
case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
case StyleVerticalAlignKeyword::Bottom:
// Align the bottom of the child frame with the bottom of the content
// area,
kidBStart = bSize - childBSize - bEndInset;
break;
default:
case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
case StyleVerticalAlignKeyword::Middle:
// Align the middle of the child frame with the middle of the content
// area,
kidBStart = (bSize - childBSize - bEndInset + bStartInset) / 2;
@ -603,17 +601,17 @@ bool nsTableCellFrame::ComputeCustomOverflow(nsOverflowAreas& aOverflowAreas) {
// Per CSS 2.1, we map 'sub', 'super', 'text-top', 'text-bottom',
// length, percentage, and calc() values to 'baseline'.
uint8_t nsTableCellFrame::GetVerticalAlign() const {
const nsStyleCoord& verticalAlign = StyleDisplay()->mVerticalAlign;
if (verticalAlign.GetUnit() == eStyleUnit_Enumerated) {
uint8_t value = verticalAlign.GetIntValue();
if (value == NS_STYLE_VERTICAL_ALIGN_TOP ||
value == NS_STYLE_VERTICAL_ALIGN_MIDDLE ||
value == NS_STYLE_VERTICAL_ALIGN_BOTTOM) {
StyleVerticalAlignKeyword nsTableCellFrame::GetVerticalAlign() const {
const StyleVerticalAlign& verticalAlign = StyleDisplay()->mVerticalAlign;
if (verticalAlign.IsKeyword()) {
auto value = verticalAlign.AsKeyword();
if (value == StyleVerticalAlignKeyword::Top ||
value == StyleVerticalAlignKeyword::Middle ||
value == StyleVerticalAlignKeyword::Bottom) {
return value;
}
}
return NS_STYLE_VERTICAL_ALIGN_BASELINE;
return StyleVerticalAlignKeyword::Baseline;
}
bool nsTableCellFrame::CellHasVisibleContent(nscoord height,

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

@ -124,12 +124,12 @@ class nsTableCellFrame : public nsContainerFrame,
/*
* Get the value of vertical-align adjusted for CSS 2's rules for a
* table cell, which means the result is always
* NS_STYLE_VERTICAL_ALIGN_{TOP,MIDDLE,BOTTOM,BASELINE}.
* StyleVerticalAlignKeyword::{Top,Middle,Bottom,Baseline}.
*/
virtual uint8_t GetVerticalAlign() const;
virtual mozilla::StyleVerticalAlignKeyword GetVerticalAlign() const;
bool HasVerticalAlignBaseline() const {
return GetVerticalAlign() == NS_STYLE_VERTICAL_ALIGN_BASELINE;
return GetVerticalAlign() == mozilla::StyleVerticalAlignKeyword::Baseline;
}
bool CellHasVisibleContent(nscoord aBSize, nsTableFrame* tableFrame,

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

@ -460,12 +460,9 @@ uint8_t nsTableWrapperFrame::GetCaptionSide() {
}
}
uint8_t nsTableWrapperFrame::GetCaptionVerticalAlign() {
const nsStyleCoord& va =
mCaptionFrames.FirstChild()->StyleDisplay()->mVerticalAlign;
return (va.GetUnit() == eStyleUnit_Enumerated) ? va.GetIntValue()
: NS_STYLE_VERTICAL_ALIGN_TOP;
StyleVerticalAlignKeyword nsTableWrapperFrame::GetCaptionVerticalAlign() const {
const auto& va = mCaptionFrames.FirstChild()->StyleDisplay()->mVerticalAlign;
return va.IsKeyword() ? va.AsKeyword() : StyleVerticalAlignKeyword::Top;
}
void nsTableWrapperFrame::SetDesiredSize(uint8_t aCaptionSide,
@ -588,12 +585,12 @@ nsresult nsTableWrapperFrame::GetCaptionOrigin(
case NS_STYLE_CAPTION_SIDE_LEFT:
aOrigin.B(aWM) = aInnerMargin.BStart(aWM);
switch (GetCaptionVerticalAlign()) {
case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
case StyleVerticalAlignKeyword::Middle:
aOrigin.B(aWM) = std::max(
0, aInnerMargin.BStart(aWM) +
((aInnerSize.BSize(aWM) - aCaptionSize.BSize(aWM)) / 2));
break;
case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
case StyleVerticalAlignKeyword::Bottom:
aOrigin.B(aWM) =
std::max(0, aInnerMargin.BStart(aWM) + aInnerSize.BSize(aWM) -
aCaptionSize.BSize(aWM));
@ -677,12 +674,12 @@ nsresult nsTableWrapperFrame::GetInnerOrigin(
case NS_STYLE_CAPTION_SIDE_RIGHT:
aOrigin.B(aWM) = aInnerMargin.BStart(aWM);
switch (GetCaptionVerticalAlign()) {
case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
case StyleVerticalAlignKeyword::Middle:
aOrigin.B(aWM) =
std::max(aInnerMargin.BStart(aWM),
(aCaptionSize.BSize(aWM) - aInnerSize.BSize(aWM)) / 2);
break;
case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
case StyleVerticalAlignKeyword::Bottom:
aOrigin.B(aWM) =
std::max(aInnerMargin.BStart(aWM),
aCaptionSize.BSize(aWM) - aInnerSize.BSize(aWM));

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

@ -200,7 +200,7 @@ class nsTableWrapperFrame : public nsContainerFrame {
captionSide == NS_STYLE_CAPTION_SIDE_RIGHT;
}
uint8_t GetCaptionVerticalAlign();
mozilla::StyleVerticalAlignKeyword GetCaptionVerticalAlign() const;
void SetDesiredSize(uint8_t aCaptionSide,
const mozilla::LogicalSize& aInnerSize,

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

@ -22,7 +22,6 @@ use crate::values::computed::url::ComputedImageUrl;
use crate::values::computed::{Angle, Gradient, Image};
use crate::values::computed::{Integer, LengthPercentage};
use crate::values::computed::{Length, Percentage, TextAlign};
use crate::values::generics::box_::VerticalAlign;
use crate::values::generics::grid::{TrackListValue, TrackSize};
use crate::values::generics::image::{CompatMode, Image as GenericImage};
use crate::values::generics::rect::Rect;
@ -875,26 +874,6 @@ where
}
}
impl<L> VerticalAlign<L> {
/// Converts an enumerated value coming from Gecko to a `VerticalAlign<L>`.
pub fn from_gecko_keyword(value: u32) -> Self {
match value {
structs::NS_STYLE_VERTICAL_ALIGN_BASELINE => VerticalAlign::Baseline,
structs::NS_STYLE_VERTICAL_ALIGN_SUB => VerticalAlign::Sub,
structs::NS_STYLE_VERTICAL_ALIGN_SUPER => VerticalAlign::Super,
structs::NS_STYLE_VERTICAL_ALIGN_TOP => VerticalAlign::Top,
structs::NS_STYLE_VERTICAL_ALIGN_TEXT_TOP => VerticalAlign::TextTop,
structs::NS_STYLE_VERTICAL_ALIGN_MIDDLE => VerticalAlign::Middle,
structs::NS_STYLE_VERTICAL_ALIGN_BOTTOM => VerticalAlign::Bottom,
structs::NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM => VerticalAlign::TextBottom,
structs::NS_STYLE_VERTICAL_ALIGN_MIDDLE_WITH_BASELINE => {
VerticalAlign::MozMiddleWithBaseline
},
_ => panic!("unexpected enumerated value for vertical-align"),
}
}
}
impl TextAlign {
/// Obtain a specified value from a Gecko keyword value
///

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

@ -38,7 +38,7 @@ use crate::gecko_bindings::bindings::{Gecko_ResetFilters, Gecko_CopyFiltersFrom}
use crate::gecko_bindings::structs;
use crate::gecko_bindings::structs::nsCSSPropertyID;
use crate::gecko_bindings::structs::mozilla::PseudoStyleType;
use crate::gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordData, CoordDataMut};
use crate::gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordDataMut};
use crate::gecko_bindings::sugar::refptr::RefPtr;
use crate::gecko::values::GeckoStyleCoordConvertible;
use crate::gecko::values::round_border_to_device_pixels;
@ -2505,7 +2505,7 @@ fn static_assert() {
}
</%def>
<% skip_box_longhands= """display vertical-align
<% skip_box_longhands= """display
animation-name animation-delay animation-duration
animation-direction animation-fill-mode animation-play-state
animation-iteration-count animation-timing-function
@ -2561,47 +2561,6 @@ fn static_assert() {
) %>
${impl_keyword('clear', 'mBreakType', clear_keyword)}
pub fn set_vertical_align(&mut self, v: longhands::vertical_align::computed_value::T) {
use crate::values::generics::box_::VerticalAlign;
let value = match v {
VerticalAlign::Baseline => structs::NS_STYLE_VERTICAL_ALIGN_BASELINE,
VerticalAlign::Sub => structs::NS_STYLE_VERTICAL_ALIGN_SUB,
VerticalAlign::Super => structs::NS_STYLE_VERTICAL_ALIGN_SUPER,
VerticalAlign::Top => structs::NS_STYLE_VERTICAL_ALIGN_TOP,
VerticalAlign::TextTop => structs::NS_STYLE_VERTICAL_ALIGN_TEXT_TOP,
VerticalAlign::Middle => structs::NS_STYLE_VERTICAL_ALIGN_MIDDLE,
VerticalAlign::Bottom => structs::NS_STYLE_VERTICAL_ALIGN_BOTTOM,
VerticalAlign::TextBottom => structs::NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM,
VerticalAlign::MozMiddleWithBaseline => {
structs::NS_STYLE_VERTICAL_ALIGN_MIDDLE_WITH_BASELINE
},
VerticalAlign::Length(length) => {
self.gecko.mVerticalAlign.set(length);
return;
},
};
self.gecko.mVerticalAlign.set_value(CoordDataValue::Enumerated(value));
}
pub fn clone_vertical_align(&self) -> longhands::vertical_align::computed_value::T {
use crate::values::computed::LengthPercentage;
use crate::values::generics::box_::VerticalAlign;
let gecko = &self.gecko.mVerticalAlign;
match gecko.as_value() {
CoordDataValue::Enumerated(value) => VerticalAlign::from_gecko_keyword(value),
_ => {
VerticalAlign::Length(
LengthPercentage::from_gecko_style_coord(gecko).expect(
"expected <length-percentage> for vertical-align",
),
)
},
}
}
<%call expr="impl_coord_copy('vertical_align', 'mVerticalAlign')"></%call>
${impl_style_coord("scroll_snap_points_x", "mScrollSnapPointsX")}
${impl_style_coord("scroll_snap_points_y", "mScrollSnapPointsY")}

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

@ -6,6 +6,37 @@
use crate::values::animated::ToAnimatedZero;
#[derive(
Animate,
Clone,
ComputeSquaredDistance,
Copy,
Debug,
FromPrimitive,
MallocSizeOf,
Parse,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[repr(u8)]
#[allow(missing_docs)]
pub enum VerticalAlignKeyword {
Baseline,
Sub,
Super,
Top,
TextTop,
Middle,
Bottom,
TextBottom,
#[cfg(feature = "gecko")]
MozMiddleWithBaseline,
}
/// A generic value for the `vertical-align` property.
#[derive(
Animate,
@ -21,35 +52,21 @@ use crate::values::animated::ToAnimatedZero;
ToResolvedValue,
ToShmem,
)]
pub enum VerticalAlign<LengthPercentage> {
/// `baseline`
Baseline,
/// `sub`
Sub,
/// `super`
Super,
/// `top`
Top,
/// `text-top`
TextTop,
/// `middle`
Middle,
/// `bottom`
Bottom,
/// `text-bottom`
TextBottom,
/// `-moz-middle-with-baseline`
#[cfg(feature = "gecko")]
MozMiddleWithBaseline,
#[repr(C, u8)]
pub enum GenericVerticalAlign<LengthPercentage> {
/// One of the vertical-align keywords.
Keyword(VerticalAlignKeyword),
/// `<length-percentage>`
Length(LengthPercentage),
}
pub use self::GenericVerticalAlign as VerticalAlign;
impl<L> VerticalAlign<L> {
/// Returns `baseline`.
#[inline]
pub fn baseline() -> Self {
VerticalAlign::Baseline
VerticalAlign::Keyword(VerticalAlignKeyword::Baseline)
}
}

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

@ -10,7 +10,7 @@ use crate::properties::{LonghandId, PropertyDeclarationId, PropertyFlags};
use crate::properties::{PropertyId, ShorthandId};
use crate::values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount;
use crate::values::generics::box_::Perspective as GenericPerspective;
use crate::values::generics::box_::VerticalAlign as GenericVerticalAlign;
use crate::values::generics::box_::{GenericVerticalAlign, VerticalAlignKeyword};
use crate::values::specified::length::{LengthPercentage, NonNegativeLength};
use crate::values::specified::{AllowQuirks, Number};
use crate::values::{CustomIdent, KeyframesName};
@ -280,20 +280,7 @@ impl Parse for VerticalAlign {
return Ok(GenericVerticalAlign::Length(lp));
}
try_match_ident_ignore_ascii_case! { input,
"baseline" => Ok(GenericVerticalAlign::Baseline),
"sub" => Ok(GenericVerticalAlign::Sub),
"super" => Ok(GenericVerticalAlign::Super),
"top" => Ok(GenericVerticalAlign::Top),
"text-top" => Ok(GenericVerticalAlign::TextTop),
"middle" => Ok(GenericVerticalAlign::Middle),
"bottom" => Ok(GenericVerticalAlign::Bottom),
"text-bottom" => Ok(GenericVerticalAlign::TextBottom),
#[cfg(feature = "gecko")]
"-moz-middle-with-baseline" => {
Ok(GenericVerticalAlign::MozMiddleWithBaseline)
},
}
Ok(GenericVerticalAlign::Keyword(VerticalAlignKeyword::parse(input)?))
}
}

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

@ -563,8 +563,7 @@ pub enum TextAlignKeyword {
}
/// Specified value of text-align property.
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[derive(Clone, Copy, Debug, Eq, Hash, Parse, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
pub enum TextAlign {
/// Keyword value of text-align property.
Keyword(TextAlignKeyword),

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

@ -117,6 +117,7 @@ include = [
"Color",
"ColorOrAuto",
"GradientItem",
"VerticalAlign",
]
item_types = ["enums", "structs", "typedefs", "functions"]
renaming_overrides_prefixing = true

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

@ -4329,6 +4329,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetKeywordValue(
use style::properties::longhands;
use style::properties::PropertyDeclaration;
use style::values::generics::font::FontStyle;
use style::values::generics::box_::{VerticalAlign, VerticalAlignKeyword};
use style::values::specified::BorderStyle;
use style::values::specified::Display;
use style::values::specified::{Clear, Float};
@ -4351,7 +4352,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetKeywordValue(
Display => get_from_computed::<Display>(value),
Float => get_from_computed::<Float>(value),
Clear => get_from_computed::<Clear>(value),
VerticalAlign => longhands::vertical_align::SpecifiedValue::from_gecko_keyword(value),
VerticalAlign => VerticalAlign::Keyword(VerticalAlignKeyword::from_u32(value).unwrap()),
TextAlign => longhands::text_align::SpecifiedValue::from_gecko_keyword(value),
TextEmphasisPosition => longhands::text_emphasis_position::SpecifiedValue::from_gecko_keyword(value),
FontSize => {

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

@ -853,23 +853,22 @@ static void RenderWithCoreUI(CGRect aRect, CGContextRef cgContext, NSDictionary*
static float VerticalAlignFactor(nsIFrame* aFrame) {
if (!aFrame) return 0.5f; // default: center
const nsStyleCoord& va = aFrame->StyleDisplay()->mVerticalAlign;
uint8_t intval =
(va.GetUnit() == eStyleUnit_Enumerated) ? va.GetIntValue() : NS_STYLE_VERTICAL_ALIGN_MIDDLE;
switch (intval) {
case NS_STYLE_VERTICAL_ALIGN_TOP:
case NS_STYLE_VERTICAL_ALIGN_TEXT_TOP:
const auto& va = aFrame->StyleDisplay()->mVerticalAlign;
auto kw = va.IsKeyword() ? va.AsKeyword() : StyleVerticalAlignKeyword::Middle;
switch (kw) {
case StyleVerticalAlignKeyword::Top:
case StyleVerticalAlignKeyword::TextTop:
return 0.0f;
case NS_STYLE_VERTICAL_ALIGN_SUB:
case NS_STYLE_VERTICAL_ALIGN_SUPER:
case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
case NS_STYLE_VERTICAL_ALIGN_MIDDLE_WITH_BASELINE:
case StyleVerticalAlignKeyword::Sub:
case StyleVerticalAlignKeyword::Super:
case StyleVerticalAlignKeyword::Middle:
case StyleVerticalAlignKeyword::MozMiddleWithBaseline:
return 0.5f;
case NS_STYLE_VERTICAL_ALIGN_BASELINE:
case NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM:
case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
case StyleVerticalAlignKeyword::Baseline:
case StyleVerticalAlignKeyword::Bottom:
case StyleVerticalAlignKeyword::TextBottom:
return 1.0f;
default: