Bug 1312379 part 3 - [css-align][css-tables] Add methods for CSS Alignment first/last baseline of the table container. r=dholbert

This commit is contained in:
Mats Palmgren 2016-12-20 23:56:35 +01:00
Родитель deb52d2e03
Коммит 562b840a02
5 изменённых файлов: 77 добавлений и 22 удалений

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

@ -3805,35 +3805,54 @@ nsTableFrame::GetRowSpacing(int32_t aStartRowIndex,
}
/* virtual */ nscoord
nsTableFrame::GetLogicalBaseline(WritingMode aWritingMode) const
nsTableFrame::GetLogicalBaseline(WritingMode aWM) const
{
nscoord baseline;
if (!GetNaturalBaselineBOffset(aWM, BaselineSharingGroup::eFirst, &baseline)) {
baseline = BSize(aWM);
}
return baseline;
}
/* virtual */ bool
nsTableFrame::GetNaturalBaselineBOffset(WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const
{
nscoord ascent = 0;
RowGroupArray orderedRowGroups;
OrderRowGroups(orderedRowGroups);
nsTableRowFrame* firstRow = nullptr;
// XXX not sure if this should be the size of the containing block instead.
nsSize containerSize = mRect.Size();
for (uint32_t rgIndex = 0; rgIndex < orderedRowGroups.Length(); rgIndex++) {
nsTableRowGroupFrame* rgFrame = orderedRowGroups[rgIndex];
if (rgFrame->GetRowCount()) {
firstRow = rgFrame->GetFirstRow();
nscoord rgNormalBStart =
LogicalRect(aWritingMode, rgFrame->GetNormalRect(), containerSize)
.Origin(aWritingMode).B(aWritingMode);
nscoord firstRowNormalBStart =
LogicalRect(aWritingMode, firstRow->GetNormalRect(), containerSize)
.Origin(aWritingMode).B(aWritingMode);
ascent = rgNormalBStart + firstRowNormalBStart +
firstRow->GetRowBaseline(aWritingMode);
break;
auto TableBaseline = [aWM, containerSize] (nsTableRowGroupFrame* aRowGroup,
nsTableRowFrame* aRow) {
nscoord rgBStart = LogicalRect(aWM, aRowGroup->GetNormalRect(),
containerSize).BStart(aWM);
nscoord rowBStart = LogicalRect(aWM, aRow->GetNormalRect(),
containerSize).BStart(aWM);
return rgBStart + rowBStart + aRow->GetRowBaseline(aWM);
};
if (aBaselineGroup == BaselineSharingGroup::eFirst) {
for (uint32_t rgIndex = 0; rgIndex < orderedRowGroups.Length(); rgIndex++) {
nsTableRowGroupFrame* rgFrame = orderedRowGroups[rgIndex];
nsTableRowFrame* row = rgFrame->GetFirstRow();
if (row) {
*aBaseline = TableBaseline(rgFrame, row);
return true;
}
}
} else {
for (uint32_t rgIndex = orderedRowGroups.Length(); rgIndex-- > 0;) {
nsTableRowGroupFrame* rgFrame = orderedRowGroups[rgIndex];
nsTableRowFrame* row = rgFrame->GetLastRow();
if (row) {
*aBaseline = BSize(aWM) - TableBaseline(rgFrame, row);
return true;
}
}
}
if (!firstRow)
ascent = BSize(aWritingMode);
return ascent;
return false;
}
/* ----- global methods ----- */
nsTableFrame*

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

@ -465,6 +465,10 @@ private:
public:
virtual nscoord GetLogicalBaseline(mozilla::WritingMode aWritingMode) const override;
bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const override;
/** return the row span of a cell, taking into account row span magic at the bottom
* of a table. The row span equals the number of rows spanned by aCell starting at
* aStartRowIndex, and can be smaller if aStartRowIndex is greater than the row

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

@ -507,7 +507,19 @@ nsTableRowFrame*
nsTableRowGroupFrame::GetFirstRow()
{
for (nsIFrame* childFrame : mFrames) {
nsTableRowFrame *rowFrame = do_QueryFrame(childFrame);
nsTableRowFrame* rowFrame = do_QueryFrame(childFrame);
if (rowFrame) {
return rowFrame;
}
}
return nullptr;
}
nsTableRowFrame*
nsTableRowGroupFrame::GetLastRow()
{
for (auto iter = mFrames.rbegin(), end = mFrames.rend(); iter != end; ++iter) {
nsTableRowFrame* rowFrame = do_QueryFrame(*iter);
if (rowFrame) {
return rowFrame;
}

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

@ -103,6 +103,7 @@ public:
virtual nsIAtom* GetType() const override;
nsTableRowFrame* GetFirstRow();
nsTableRowFrame* GetLastRow();
#ifdef DEBUG_FRAME_DUMP
virtual nsresult GetFrameName(nsAString& aResult) const override;

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

@ -68,6 +68,25 @@ public:
virtual nscoord GetLogicalBaseline(mozilla::WritingMode aWritingMode) const override;
bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const override
{
auto innerTable = InnerTableFrame();
nscoord offset;
if (innerTable->GetNaturalBaselineBOffset(aWM, aBaselineGroup, &offset)) {
auto bStart = innerTable->BStart(aWM, mRect.Size());
if (aBaselineGroup == BaselineSharingGroup::eFirst) {
*aBaseline = offset + bStart;
} else {
auto bEnd = bStart + innerTable->BSize(aWM);
*aBaseline = BSize(aWM) - (bEnd - offset);
}
return true;
}
return false;
}
virtual nscoord GetMinISize(nsRenderingContext *aRenderingContext) override;
virtual nscoord GetPrefISize(nsRenderingContext *aRenderingContext) override;