Bug 1141931 part 7 - Move [Auto]RubyTextContainerArray to RubyUtils and merge RubyTextContainerIterator into AutoRubyTextContainerArray. r=dholbert

This commit is contained in:
Xidorn Quan 2015-04-08 11:22:34 +12:00
parent 67079982ec
commit a89732e92c
5 changed files with 28 additions and 59 deletions

View File

@ -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<nsRubyTextContainerFrame*>(frame));
}
}
@ -84,7 +78,7 @@ RubySegmentEnumerator::Next()
RubyColumnEnumerator::RubyColumnEnumerator(
nsRubyBaseContainerFrame* aBaseContainer,
const nsTArray<nsRubyTextContainerFrame*>& aTextContainers)
const AutoRubyTextContainerArray& aTextContainers)
: mAtIntraLevelWhitespace(false)
{
const uint32_t rtcCount = aTextContainers.Length();

View File

@ -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<nsRubyTextContainerFrame*, RTC_ARRAY_SIZE>
{
public:
explicit RubyTextContainerIterator(nsRubyBaseContainerFrame* aBaseContainer);
void Next();
bool AtEnd() const { return !mFrame; }
nsRubyTextContainerFrame* GetTextContainer() const
{
return static_cast<nsRubyTextContainerFrame*>(mFrame);
}
private:
nsIFrame* mFrame;
explicit AutoRubyTextContainerArray(nsRubyBaseContainerFrame* aBaseContainer);
};
/**
@ -127,7 +118,7 @@ class MOZ_STACK_CLASS RubyColumnEnumerator
{
public:
RubyColumnEnumerator(nsRubyBaseContainerFrame* aRBCFrame,
const nsTArray<nsRubyTextContainerFrame*>& aRTCFrames);
const AutoRubyTextContainerArray& aRTCFrames);
void Next();
bool AtEnd() const;

View File

@ -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<UniquePtr<nsHTMLReflowState>>& 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<ContinuationTraversingState, RTC_ARRAY_SIZE> 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);

View File

@ -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<nsRubyTextContainerFrame*> TextContainerArray;
typedef nsAutoTArray<nsRubyTextContainerFrame*, RTC_ARRAY_SIZE> AutoTextContainerArray;
void GetTextContainers(TextContainerArray& aTextContainers);
struct ReflowState;
nscoord ReflowColumns(const ReflowState& aReflowState,
nsReflowStatus& aStatus);

View File

@ -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<nsRubyTextContainerFrame*, RTC_ARRAY_SIZE> 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);