commit b55def863513a55dff1de8e1992b2f46e15febad
parent 98b169cc6a98e582a9e74e67117ef8c61cfae938
Author: Sajid Anwar <sajidanwar94@gmail.com>
Date: Fri, 2 Jan 2026 09:17:56 +0000
Bug 2008335 - Decouple table cell alignment enum from CSS vertical-align enum. r=layout-reviewers,emilio
Differential Revision: https://phabricator.services.mozilla.com/D277747
Diffstat:
8 files changed, 67 insertions(+), 46 deletions(-)
diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp
@@ -88,6 +88,7 @@
#include "nsRange.h"
#include "nsString.h"
#include "nsStyleUtil.h"
+#include "nsTableCellFrame.h"
#include "nsTextNode.h"
#include "nsThreadUtils.h"
#include "nscore.h"
@@ -1129,10 +1130,10 @@ static constexpr nsAttrValue::EnumTableEntry kScrollingTable[] = {
};
static constexpr nsAttrValue::EnumTableEntry kTableVAlignTable[] = {
- {"top", StyleVerticalAlignKeyword::Top},
- {"middle", StyleVerticalAlignKeyword::Middle},
- {"bottom", StyleVerticalAlignKeyword::Bottom},
- {"baseline", StyleVerticalAlignKeyword::Baseline},
+ {"top", TableCellAlignment::Top},
+ {"middle", TableCellAlignment::Middle},
+ {"bottom", TableCellAlignment::Bottom},
+ {"baseline", TableCellAlignment::Baseline},
};
static constexpr nsAttrValue::EnumTableEntry kAlignTable[] = {
@@ -1435,9 +1436,26 @@ void nsGenericHTMLElement::MapVAlignAttributeInto(
if (!aBuilder.PropertyIsSet(eCSSProperty_vertical_align)) {
// align: enum
const nsAttrValue* value = aBuilder.GetAttr(nsGkAtoms::valign);
- if (value && value->Type() == nsAttrValue::eEnum)
- aBuilder.SetKeywordValue(eCSSProperty_vertical_align,
- value->GetEnumValue());
+ if (value && value->Type() == nsAttrValue::eEnum) {
+ switch (static_cast<TableCellAlignment>(value->GetEnumValue())) {
+ case TableCellAlignment::Top:
+ aBuilder.SetKeywordValue(eCSSProperty_vertical_align,
+ StyleVerticalAlignKeyword::Top);
+ break;
+ case TableCellAlignment::Middle:
+ aBuilder.SetKeywordValue(eCSSProperty_vertical_align,
+ StyleVerticalAlignKeyword::Middle);
+ break;
+ case TableCellAlignment::Bottom:
+ aBuilder.SetKeywordValue(eCSSProperty_vertical_align,
+ StyleVerticalAlignKeyword::Bottom);
+ break;
+ case TableCellAlignment::Baseline:
+ aBuilder.SetKeywordValue(eCSSProperty_vertical_align,
+ StyleVerticalAlignKeyword::Baseline);
+ break;
+ }
+ }
}
}
diff --git a/layout/mathml/nsMathMLmtableFrame.cpp b/layout/mathml/nsMathMLmtableFrame.cpp
@@ -36,15 +36,15 @@ static int8_t ParseStyleValue(nsAtom* aAttribute,
const nsAString& aAttributeValue) {
if (aAttribute == nsGkAtoms::rowalign) {
if (aAttributeValue.EqualsLiteral("top")) {
- return static_cast<int8_t>(StyleVerticalAlignKeyword::Top);
+ return static_cast<int8_t>(TableCellAlignment::Top);
}
if (aAttributeValue.EqualsLiteral("bottom")) {
- return static_cast<int8_t>(StyleVerticalAlignKeyword::Bottom);
+ return static_cast<int8_t>(TableCellAlignment::Bottom);
}
if (aAttributeValue.EqualsLiteral("center")) {
- return static_cast<int8_t>(StyleVerticalAlignKeyword::Middle);
+ return static_cast<int8_t>(TableCellAlignment::Middle);
}
- return static_cast<int8_t>(StyleVerticalAlignKeyword::Baseline);
+ return static_cast<int8_t>(TableCellAlignment::Baseline);
}
if (aAttribute == nsGkAtoms::columnalign) {
@@ -1104,9 +1104,9 @@ nsresult nsMathMLmtdFrame::AttributeChanged(int32_t aNameSpaceID,
return nsContainerFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
}
-StyleVerticalAlignKeyword nsMathMLmtdFrame::GetVerticalAlign() const {
+TableCellAlignment nsMathMLmtdFrame::GetTableCellAlignment() const {
// Set the default alignment in case no alignment was specified
- auto alignment = nsTableCellFrame::GetVerticalAlign();
+ auto alignment = nsTableCellFrame::GetTableCellAlignment();
nsTArray<int8_t>* alignmentList = FindCellProperty(this, RowAlignProperty());
@@ -1115,7 +1115,7 @@ StyleVerticalAlignKeyword nsMathMLmtdFrame::GetVerticalAlign() const {
// If the row number is greater than the number of provided rowalign values,
// we simply repeat the last value.
- return static_cast<StyleVerticalAlignKeyword>(
+ return static_cast<TableCellAlignment>(
(rowIndex < alignmentList->Length())
? alignmentList->ElementAt(rowIndex)
: alignmentList->LastElement());
diff --git a/layout/mathml/nsMathMLmtableFrame.h b/layout/mathml/nsMathMLmtableFrame.h
@@ -216,7 +216,7 @@ class nsMathMLmtdFrame final : public nsTableCellFrame {
nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
AttrModType aModType) override;
- mozilla::StyleVerticalAlignKeyword GetVerticalAlign() const override;
+ TableCellAlignment GetTableCellAlignment() const override;
void ProcessBorders(nsTableFrame* aFrame,
mozilla::nsDisplayListBuilder* aBuilder,
const mozilla::nsDisplayListSet& aLists) override;
diff --git a/layout/tables/nsTableCellFrame.cpp b/layout/tables/nsTableCellFrame.cpp
@@ -395,7 +395,7 @@ void nsTableCellFrame::AlignChildWithinCell(
nscoord aMaxAscent, ForceAlignTopForTableCell aForceAlignTop) {
MOZ_ASSERT(aForceAlignTop != ForceAlignTopForTableCell::Yes ||
PresContext()->IsPaginated(),
- "We shouldn't force table-cells to do 'vertical-align:top' if "
+ "We shouldn't force table-cells to do top alignment if "
"we're not in printing!");
nsIFrame* const inner = Inner();
@@ -413,27 +413,27 @@ void nsTableCellFrame::AlignChildWithinCell(
// Calculate the position for the inner frame, initializing to the origin.
LogicalPoint kidPosition = paddingRect.Origin(innerWM);
- // Apply CSS `vertical-align` to the block coordinate.
- const auto verticalAlign = aForceAlignTop == ForceAlignTopForTableCell::Yes
- ? StyleVerticalAlignKeyword::Top
- : GetVerticalAlign();
- switch (verticalAlign) {
- case StyleVerticalAlignKeyword::Baseline:
+ // Apply table cell alignment to the block coordinate.
+ const auto alignment = aForceAlignTop == ForceAlignTopForTableCell::Yes
+ ? TableCellAlignment::Top
+ : GetTableCellAlignment();
+ switch (alignment) {
+ case TableCellAlignment::Baseline:
if (auto baseline = GetCellBaseline()) {
// Align the baseline of the child frame with the baselines of other
- // children in the same row which have 'vertical-align: baseline'
+ // children in the same row which have baseline alignment
kidPosition.B(innerWM) =
paddingRect.BStart(innerWM) + aMaxAscent - *baseline;
break;
}
// fallback to start alignment
[[fallthrough]];
- case StyleVerticalAlignKeyword::Top:
+ case TableCellAlignment::Top:
// Leave kidPosition at the origin: the child frame will be aligned
// with the padding rect's block-start.
break;
- case StyleVerticalAlignKeyword::Bottom:
+ case TableCellAlignment::Bottom:
// Align the block-end of the child frame with the block-end of the
// padding rect.
kidPosition.B(innerWM) =
@@ -441,7 +441,7 @@ void nsTableCellFrame::AlignChildWithinCell(
break;
default:
- case StyleVerticalAlignKeyword::Middle:
+ case TableCellAlignment::Middle:
// Align the middle of the child frame with the middle of the cell's
// padding rect.
kidPosition.B(innerWM) =
@@ -486,17 +486,22 @@ bool nsTableCellFrame::ComputeCustomOverflow(OverflowAreas& aOverflowAreas) {
// Per CSS 2.1, we map 'sub', 'super', 'text-top', 'text-bottom',
// length, percentage, and calc() values to 'baseline'.
-StyleVerticalAlignKeyword nsTableCellFrame::GetVerticalAlign() const {
+TableCellAlignment nsTableCellFrame::GetTableCellAlignment() 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;
+ switch (value) {
+ case StyleVerticalAlignKeyword::Top:
+ return TableCellAlignment::Top;
+ case StyleVerticalAlignKeyword::Middle:
+ return TableCellAlignment::Middle;
+ case StyleVerticalAlignKeyword::Bottom:
+ return TableCellAlignment::Bottom;
+ default:
+ break;
}
}
- return StyleVerticalAlignKeyword::Baseline;
+ return TableCellAlignment::Baseline;
}
static bool CellHasVisibleContent(nsTableFrame* aTableFrame,
diff --git a/layout/tables/nsTableCellFrame.h b/layout/tables/nsTableCellFrame.h
@@ -20,6 +20,13 @@ class PresShell;
class ScrollContainerFrame;
} // namespace mozilla
+enum class TableCellAlignment : uint8_t {
+ Top,
+ Middle,
+ Bottom,
+ Baseline,
+};
+
/**
* nsTableCellFrame
* data structure to maintain information about a single table cell's frame
@@ -129,14 +136,12 @@ class nsTableCellFrame : public nsContainerFrame,
mozilla::ForceAlignTopForTableCell aForceAlignTop);
/*
- * Get the value of vertical-align adjusted for CSS 2's rules for a
- * table cell, which means the result is always
- * StyleVerticalAlignKeyword::{Top,Middle,Bottom,Baseline}.
+ * Map the CSS vertical-align to the corresponding table cell alignment value.
*/
- virtual mozilla::StyleVerticalAlignKeyword GetVerticalAlign() const;
+ virtual TableCellAlignment GetTableCellAlignment() const;
- bool HasVerticalAlignBaseline() const {
- return GetVerticalAlign() == mozilla::StyleVerticalAlignKeyword::Baseline &&
+ bool HasTableCellAlignmentBaseline() const {
+ return GetTableCellAlignment() == TableCellAlignment::Baseline &&
!GetContentEmpty();
}
diff --git a/layout/tables/nsTableRowFrame.cpp b/layout/tables/nsTableRowFrame.cpp
@@ -443,7 +443,7 @@ void nsTableRowFrame::UpdateBSize(nscoord aBSize, nsTableFrame* aTableFrame,
SetContentBSize(aBSize);
}
- if (aCellFrame->HasVerticalAlignBaseline()) {
+ if (aCellFrame->HasTableCellAlignmentBaseline()) {
if (auto ascent = aCellFrame->GetCellBaseline()) {
// see if this is a long ascender
if (mMaxCellAscent < *ascent) {
diff --git a/layout/tables/nsTableWrapperFrame.cpp b/layout/tables/nsTableWrapperFrame.cpp
@@ -407,11 +407,6 @@ Maybe<StyleCaptionSide> nsTableWrapperFrame::GetCaptionSide() const {
return Some(GetCaption()->StyleTableBorder()->mCaptionSide);
}
-StyleVerticalAlignKeyword nsTableWrapperFrame::GetCaptionVerticalAlign() const {
- const auto& va = GetCaption()->StyleDisplay()->mVerticalAlign;
- return va.IsKeyword() ? va.AsKeyword() : StyleVerticalAlignKeyword::Top;
-}
-
nscoord nsTableWrapperFrame::ComputeFinalBSize(
const LogicalSize& aInnerSize, const LogicalSize& aCaptionSize,
const LogicalMargin& aCaptionMargin, const WritingMode aWM) const {
diff --git a/layout/tables/nsTableWrapperFrame.h b/layout/tables/nsTableWrapperFrame.h
@@ -185,8 +185,6 @@ class nsTableWrapperFrame : public nsContainerFrame {
// having "physical" names.)
MaybeCaptionSide GetCaptionSide() const;
- mozilla::StyleVerticalAlignKeyword GetCaptionVerticalAlign() const;
-
nscoord ComputeFinalBSize(const mozilla::LogicalSize& aInnerSize,
const mozilla::LogicalSize& aCaptionSize,
const mozilla::LogicalMargin& aCaptionMargin,