Bug 1697529 - Implement visibility: collapse support for ruby text. r=dholbert

Differential Revision: https://phabricator.services.mozilla.com/D107990
This commit is contained in:
Xidorn Quan 2021-03-12 09:28:00 +00:00
Родитель cee32e6733
Коммит 3c6c9eeffc
7 изменённых файлов: 67 добавлений и 18 удалений

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

@ -639,7 +639,7 @@ FRAME_STATE_BIT(Inline, 23, NS_INLINE_FRAME_BIDI_VISUAL_IS_LAST)
FRAME_STATE_GROUP(RubyText, nsRubyTextFrame)
// inherits from nsInlineFrame
FRAME_STATE_BIT(RubyText, 24, NS_RUBY_TEXT_FRAME_AUTOHIDE)
FRAME_STATE_BIT(RubyText, 24, NS_RUBY_TEXT_FRAME_COLLAPSED)
// == Frame state bits that apply to ruby text container frames ===============

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

@ -2814,7 +2814,7 @@ void nsLineLayout::AdvanceAnnotationInlineBounds(PerFrameData* aPFD,
// For ruby text frames, only increase frames
// which are not auto-hidden.
if (frameType != LayoutFrameType::RubyText ||
!static_cast<nsRubyTextFrame*>(frame)->IsAutoHidden()) {
!static_cast<nsRubyTextFrame*>(frame)->IsCollapsed()) {
nscoord reservedISize = RubyUtils::GetReservedISize(frame);
RubyUtils::SetReservedISize(frame, reservedISize + aDeltaISize);
}

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

@ -598,18 +598,23 @@ nscoord nsRubyBaseContainerFrame::ReflowOneColumn(
for (uint32_t i = 0; i < rtcCount; i++) {
nsRubyTextFrame* textFrame = aColumn.mTextFrames[i];
if (textFrame) {
nsAutoString annotationText;
nsLayoutUtils::GetFrameTextContent(textFrame, annotationText);
// Per CSS Ruby spec, the content comparison for auto-hiding
// takes place prior to white spaces collapsing (white-space)
// and text transformation (text-transform), and ignores elements
// (considers only the textContent of the boxes). Which means
// using the content tree text comparison is correct.
if (annotationText.Equals(baseText)) {
textFrame->AddStateBits(NS_RUBY_TEXT_FRAME_AUTOHIDE);
bool isCollapsed = false;
if (textFrame->StyleVisibility()->mVisible == StyleVisibility::Collapse) {
isCollapsed = true;
} else {
textFrame->RemoveStateBits(NS_RUBY_TEXT_FRAME_AUTOHIDE);
// Per CSS Ruby spec, the content comparison for auto-hiding
// takes place prior to white spaces collapsing (white-space)
// and text transformation (text-transform), and ignores elements
// (considers only the textContent of the boxes). Which means
// using the content tree text comparison is correct.
nsAutoString annotationText;
nsLayoutUtils::GetFrameTextContent(textFrame, annotationText);
isCollapsed = annotationText.Equals(baseText);
}
if (isCollapsed) {
textFrame->AddStateBits(NS_RUBY_TEXT_FRAME_COLLAPSED);
} else {
textFrame->RemoveStateBits(NS_RUBY_TEXT_FRAME_COLLAPSED);
}
RubyUtils::ClearReservedISize(textFrame);
@ -682,7 +687,7 @@ nscoord nsRubyBaseContainerFrame::ReflowOneColumn(
nscoord deltaISize = icoord - lineLayout->GetCurrentICoord();
if (deltaISize > 0) {
lineLayout->AdvanceICoord(deltaISize);
if (textFrame && !textFrame->IsAutoHidden()) {
if (textFrame && !textFrame->IsCollapsed()) {
RubyUtils::SetReservedISize(textFrame, deltaISize);
}
}

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

@ -49,7 +49,7 @@ nsresult nsRubyTextFrame::GetFrameName(nsAString& aResult) const {
/* virtual */
void nsRubyTextFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsDisplayListSet& aLists) {
if (IsAutoHidden()) {
if (IsCollapsed()) {
return;
}
@ -69,7 +69,7 @@ void nsRubyTextFrame::Reflow(nsPresContext* aPresContext,
// created. There might be other problems if we don't do that.
nsRubyContentFrame::Reflow(aPresContext, aDesiredSize, aReflowInput, aStatus);
if (IsAutoHidden()) {
if (IsCollapsed()) {
// Reset the ISize. The BSize is not changed so that it won't
// affect vertical positioning in unexpected way.
WritingMode lineWM = aReflowInput.mLineLayout->GetWritingMode();

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

@ -41,8 +41,8 @@ class nsRubyTextFrame final : public nsRubyContentFrame {
const ReflowInput& aReflowInput,
nsReflowStatus& aStatus) override;
bool IsAutoHidden() const {
return HasAnyStateBits(NS_RUBY_TEXT_FRAME_AUTOHIDE);
bool IsCollapsed() const {
return HasAnyStateBits(NS_RUBY_TEXT_FRAME_COLLAPSED);
}
protected:

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

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="ja">
<meta charset="UTF-8">
<title>CSS Reference: visibility: collapse hides ruby annotations</title>
<link rel="author" title="Xidorn Quan" href="https://www.upsuper.org">
<style>
body { line-height: 5; }
rt { font-size: 80%; }
</style>
<ruby>
<rb></rb><rb></rb><rb></rb>
<rt>こん</rt><rt>ちゅう</rt><rt></rt>
</ruby><br>
<ruby>
<rb></rb><rb></rb><rb></rb>
<rt>こん</rt><rt style="opacity: 0">ちゅう</rt><rt></rt>
</ruby><br>
<ruby>
<rb></rb><rb></rb><rb></rb>
<rt>こん</rt><rt></rt><rt></rt>
</ruby>

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

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="ja">
<meta charset="UTF-8">
<title>CSS Test: visibility: collapse hides ruby annotations</title>
<link rel="author" title="Xidorn Quan" href="https://www.upsuper.org">
<link rel="help" href="https://drafts.csswg.org/css-ruby-1/#hiding">
<link rel="match" href="ruby-text-collapse-ref.html">
<style>
body { line-height: 5; }
rt { font-size: 80%; }
</style>
<ruby>
<rb></rb><rb></rb><rb></rb>
<rt>こん</rt><rt>ちゅう</rt><rt></rt>
</ruby><br>
<ruby>
<rb></rb><rb></rb><rb></rb>
<rt>こん</rt><rt style="visibility: hidden">ちゅう</rt><rt></rt>
</ruby><br>
<ruby>
<rb></rb><rb></rb><rb></rb>
<rt>こん</rt><rt style="visibility: collapse">ちゅう</rt><rt></rt>
</ruby>