зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1229437 part 3 - Support iterating frames of RubyColumn. r=dholbert
--HG-- extra : source : 33d18b0760b2b4e6ae8c1357226f7bace1a75519
This commit is contained in:
Родитель
dd663b590f
Коммит
488c3f7ca2
|
@ -57,6 +57,35 @@ AutoRubyTextContainerArray::AutoRubyTextContainerArray(
|
|||
}
|
||||
}
|
||||
|
||||
nsIFrame*
|
||||
RubyColumn::Iterator::operator*() const
|
||||
{
|
||||
nsIFrame* frame;
|
||||
if (mIndex == -1) {
|
||||
frame = mColumn.mBaseFrame;
|
||||
} else {
|
||||
frame = mColumn.mTextFrames[mIndex];
|
||||
}
|
||||
MOZ_ASSERT(frame, "Frame here cannot be null");
|
||||
return frame;
|
||||
}
|
||||
|
||||
void
|
||||
RubyColumn::Iterator::SkipUntilExistingFrame()
|
||||
{
|
||||
if (mIndex == -1) {
|
||||
if (!mColumn.mBaseFrame) {
|
||||
++mIndex;
|
||||
}
|
||||
}
|
||||
auto numTextFrames = mColumn.mTextFrames.Length();
|
||||
for (; mIndex < numTextFrames; ++mIndex) {
|
||||
if (mColumn.mTextFrames[mIndex]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RubySegmentEnumerator::RubySegmentEnumerator(nsRubyFrame* aRubyFrame)
|
||||
{
|
||||
nsIFrame* frame = aRubyFrame->GetFirstPrincipalChild();
|
||||
|
|
|
@ -133,7 +133,54 @@ struct MOZ_STACK_CLASS RubyColumn
|
|||
nsRubyBaseFrame* mBaseFrame;
|
||||
nsAutoTArray<nsRubyTextFrame*, RTC_ARRAY_SIZE> mTextFrames;
|
||||
bool mIsIntraLevelWhitespace;
|
||||
|
||||
RubyColumn() : mBaseFrame(nullptr), mIsIntraLevelWhitespace(false) { }
|
||||
|
||||
// Helper class to support iteration across the frames within a single
|
||||
// RubyColumn (the column's ruby base and its annotations).
|
||||
class MOZ_STACK_CLASS Iterator
|
||||
{
|
||||
public:
|
||||
nsIFrame* operator*() const;
|
||||
|
||||
Iterator& operator++() { ++mIndex; SkipUntilExistingFrame(); return *this; }
|
||||
Iterator operator++(int) { auto ret = *this; ++*this; return ret; }
|
||||
|
||||
friend bool operator==(const Iterator& aIter1, const Iterator& aIter2)
|
||||
{
|
||||
MOZ_ASSERT(&aIter1.mColumn == &aIter2.mColumn,
|
||||
"Should only compare iterators of the same ruby column");
|
||||
return aIter1.mIndex == aIter2.mIndex;
|
||||
}
|
||||
friend bool operator!=(const Iterator& aIter1, const Iterator& aIter2)
|
||||
{
|
||||
return !(aIter1 == aIter2);
|
||||
}
|
||||
|
||||
private:
|
||||
Iterator(const RubyColumn& aColumn, int32_t aIndex)
|
||||
: mColumn(aColumn)
|
||||
, mIndex(aIndex)
|
||||
{
|
||||
MOZ_ASSERT(aIndex == -1 ||
|
||||
(aIndex >= 0 && aIndex <= aColumn.mTextFrames.Length()));
|
||||
SkipUntilExistingFrame();
|
||||
}
|
||||
friend struct RubyColumn; // for the constructor
|
||||
|
||||
void SkipUntilExistingFrame();
|
||||
|
||||
const RubyColumn& mColumn;
|
||||
// -1 means the ruby base frame,
|
||||
// non-negative means the index of ruby text frame
|
||||
// a value of mTextFrames.Length() means we're done iterating
|
||||
int32_t mIndex = -1;
|
||||
};
|
||||
|
||||
Iterator begin() const { return Iterator(*this, -1); }
|
||||
Iterator end() const { return Iterator(*this, mTextFrames.Length()); }
|
||||
Iterator cbegin() const { return begin(); }
|
||||
Iterator cend() const { return end(); }
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче