diff --git a/layout/generic/RubyUtils.cpp b/layout/generic/RubyUtils.cpp index 74a0b126b6a..e99e79f01d8 100644 --- a/layout/generic/RubyUtils.cpp +++ b/layout/generic/RubyUtils.cpp @@ -9,6 +9,7 @@ #include "nsRubyBaseFrame.h" #include "nsRubyTextFrame.h" #include "nsRubyBaseContainerFrame.h" +#include "nsRubyTextContainerFrame.h" using namespace mozilla; @@ -46,20 +47,13 @@ RubyUtils::GetReservedISize(nsIFrame* aFrame) return value.mCoord; } -RubyTextContainerIterator::RubyTextContainerIterator( +AutoRubyTextContainerArray::AutoRubyTextContainerArray( nsRubyBaseContainerFrame* aBaseContainer) { - mFrame = aBaseContainer; - Next(); -} - -void -RubyTextContainerIterator::Next() -{ - MOZ_ASSERT(mFrame, "Should have checked AtEnd()"); - mFrame = mFrame->GetNextSibling(); - if (mFrame && mFrame->GetType() != nsGkAtoms::rubyTextContainerFrame) { - mFrame = nullptr; + for (nsIFrame* frame = aBaseContainer->GetNextSibling(); + frame && frame->GetType() == nsGkAtoms::rubyTextContainerFrame; + frame = frame->GetNextSibling()) { + AppendElement(static_cast(frame)); } } @@ -84,7 +78,7 @@ RubySegmentEnumerator::Next() RubyColumnEnumerator::RubyColumnEnumerator( nsRubyBaseContainerFrame* aBaseContainer, - const nsTArray& aTextContainers) + const AutoRubyTextContainerArray& aTextContainers) : mAtIntraLevelWhitespace(false) { const uint32_t rtcCount = aTextContainers.Length(); diff --git a/layout/generic/RubyUtils.h b/layout/generic/RubyUtils.h index d4ec33e2b18..26fbf8ea2fb 100644 --- a/layout/generic/RubyUtils.h +++ b/layout/generic/RubyUtils.h @@ -9,7 +9,6 @@ #include "nsTArray.h" #include "nsGkAtoms.h" -#include "nsRubyTextContainerFrame.h" #define RTC_ARRAY_SIZE 1 @@ -18,6 +17,7 @@ class nsRubyBaseFrame; class nsRubyTextFrame; class nsRubyContentFrame; class nsRubyBaseContainerFrame; +class nsRubyTextContainerFrame; namespace mozilla { @@ -68,23 +68,14 @@ public: }; /** - * This class iterates all ruby text containers paired with - * the given ruby base container. + * This array stores all ruby text containers of the ruby segment + * of the given ruby base container. */ -class MOZ_STACK_CLASS RubyTextContainerIterator +class MOZ_STACK_CLASS AutoRubyTextContainerArray final + : public nsAutoTArray { public: - explicit RubyTextContainerIterator(nsRubyBaseContainerFrame* aBaseContainer); - - void Next(); - bool AtEnd() const { return !mFrame; } - nsRubyTextContainerFrame* GetTextContainer() const - { - return static_cast(mFrame); - } - -private: - nsIFrame* mFrame; + explicit AutoRubyTextContainerArray(nsRubyBaseContainerFrame* aBaseContainer); }; /** @@ -127,7 +118,7 @@ class MOZ_STACK_CLASS RubyColumnEnumerator { public: RubyColumnEnumerator(nsRubyBaseContainerFrame* aRBCFrame, - const nsTArray& aRTCFrames); + const AutoRubyTextContainerArray& aRTCFrames); void Next(); bool AtEnd() const; diff --git a/layout/generic/nsRubyBaseContainerFrame.cpp b/layout/generic/nsRubyBaseContainerFrame.cpp index 572c85a7890..1dfad7c0545 100644 --- a/layout/generic/nsRubyBaseContainerFrame.cpp +++ b/layout/generic/nsRubyBaseContainerFrame.cpp @@ -153,8 +153,7 @@ CalculateColumnPrefISize(nsRenderingContext* aRenderingContext, nsRubyBaseContainerFrame::AddInlineMinISize( nsRenderingContext *aRenderingContext, nsIFrame::InlineMinISizeData *aData) { - AutoTextContainerArray textContainers; - GetTextContainers(textContainers); + AutoRubyTextContainerArray textContainers(this); for (uint32_t i = 0, iend = textContainers.Length(); i < iend; i++) { if (textContainers[i]->IsSpanContainer()) { @@ -202,8 +201,7 @@ nsRubyBaseContainerFrame::AddInlineMinISize( nsRubyBaseContainerFrame::AddInlinePrefISize( nsRenderingContext *aRenderingContext, nsIFrame::InlinePrefISizeData *aData) { - AutoTextContainerArray textContainers; - GetTextContainers(textContainers); + AutoRubyTextContainerArray textContainers(this); nscoord sum = 0; for (nsIFrame* frame = this; frame; frame = frame->GetNextInFlow()) { @@ -235,15 +233,6 @@ nsRubyBaseContainerFrame::IsFrameOfType(uint32_t aFlags) const ~(nsIFrame::eLineParticipant)); } -void -nsRubyBaseContainerFrame::GetTextContainers(TextContainerArray& aTextContainers) -{ - MOZ_ASSERT(aTextContainers.IsEmpty()); - for (RubyTextContainerIterator iter(this); !iter.AtEnd(); iter.Next()) { - aTextContainers.AppendElement(iter.GetTextContainer()); - } -} - /* virtual */ bool nsRubyBaseContainerFrame::CanContinueTextRun() const { @@ -275,7 +264,7 @@ struct nsRubyBaseContainerFrame::ReflowState { bool mAllowInitialLineBreak; bool mAllowLineBreak; - const TextContainerArray& mTextContainers; + const AutoRubyTextContainerArray& mTextContainers; const nsHTMLReflowState& mBaseReflowState; const nsTArray>& mTextReflowStates; }; @@ -298,11 +287,9 @@ nsRubyBaseContainerFrame::Reflow(nsPresContext* aPresContext, return; } - AutoTextContainerArray textContainers; - GetTextContainers(textContainers); - MoveOverflowToChildList(); // Ask text containers to drain overflows + AutoRubyTextContainerArray textContainers(this); const uint32_t rtcCount = textContainers.Length(); for (uint32_t i = 0; i < rtcCount; i++) { textContainers[i]->MoveOverflowToChildList(); @@ -441,10 +428,10 @@ struct MOZ_STACK_CLASS nsRubyBaseContainerFrame::PullFrameState { ContinuationTraversingState mBase; nsAutoTArray mTexts; - const TextContainerArray& mTextContainers; + const AutoRubyTextContainerArray& mTextContainers; PullFrameState(nsRubyBaseContainerFrame* aBaseContainer, - const TextContainerArray& aTextContainers); + const AutoRubyTextContainerArray& aTextContainers); }; nscoord @@ -695,7 +682,7 @@ nsRubyBaseContainerFrame::ReflowOneColumn(const ReflowState& aReflowState, nsRubyBaseContainerFrame::PullFrameState::PullFrameState( nsRubyBaseContainerFrame* aBaseContainer, - const TextContainerArray& aTextContainers) + const AutoRubyTextContainerArray& aTextContainers) : mBase(aBaseContainer) , mTextContainers(aTextContainers) { @@ -711,7 +698,8 @@ nsRubyBaseContainerFrame::PullOneColumn(nsLineLayout* aLineLayout, RubyColumn& aColumn, bool& aIsComplete) { - const TextContainerArray& textContainers = aPullFrameState.mTextContainers; + const AutoRubyTextContainerArray& textContainers = + aPullFrameState.mTextContainers; const uint32_t rtcCount = textContainers.Length(); nsIFrame* nextBase = GetNextInFlowChild(aPullFrameState.mBase); diff --git a/layout/generic/nsRubyBaseContainerFrame.h b/layout/generic/nsRubyBaseContainerFrame.h index 10b4c22e65e..3b7b1af2cea 100644 --- a/layout/generic/nsRubyBaseContainerFrame.h +++ b/layout/generic/nsRubyBaseContainerFrame.h @@ -9,7 +9,6 @@ #ifndef nsRubyBaseContainerFrame_h___ #define nsRubyBaseContainerFrame_h___ -#include "RubyUtils.h" #include "nsContainerFrame.h" /** @@ -19,6 +18,10 @@ nsContainerFrame* NS_NewRubyBaseContainerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); +namespace mozilla { +struct RubyColumn; +} + class nsRubyBaseContainerFrame final : public nsContainerFrame { public: @@ -61,10 +64,6 @@ protected: nsStyleContext* aContext); explicit nsRubyBaseContainerFrame(nsStyleContext* aContext) : nsContainerFrame(aContext) {} - typedef nsTArray TextContainerArray; - typedef nsAutoTArray AutoTextContainerArray; - void GetTextContainers(TextContainerArray& aTextContainers); - struct ReflowState; nscoord ReflowColumns(const ReflowState& aReflowState, nsReflowStatus& aStatus); diff --git a/layout/generic/nsRubyFrame.cpp b/layout/generic/nsRubyFrame.cpp index a31e14d1c00..5029d8bab18 100644 --- a/layout/generic/nsRubyFrame.cpp +++ b/layout/generic/nsRubyFrame.cpp @@ -177,10 +177,7 @@ nsRubyFrame::ReflowSegment(nsPresContext* aPresContext, NS_ASSERTION(!rubyWM.IsOrthogonalTo(lineWM), "Ruby frame writing-mode shouldn't be orthogonal to its line"); - nsAutoTArray textContainers; - for (RubyTextContainerIterator iter(aBaseContainer); !iter.AtEnd(); iter.Next()) { - textContainers.AppendElement(iter.GetTextContainer()); - } + AutoRubyTextContainerArray textContainers(aBaseContainer); const uint32_t rtcCount = textContainers.Length(); nsHTMLReflowMetrics baseMetrics(aReflowState);