2014-12-12 13:30:43 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_RubyUtils_h_
|
|
|
|
#define mozilla_RubyUtils_h_
|
|
|
|
|
2016-01-26 12:31:45 +03:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
2016-12-01 01:51:51 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2016-12-01 01:52:26 +03:00
|
|
|
#include "nsIFrame.h"
|
2016-12-01 01:51:51 +03:00
|
|
|
#include "nsTArray.h"
|
2015-04-07 23:40:31 +03:00
|
|
|
|
2015-04-08 02:22:34 +03:00
|
|
|
#define RTC_ARRAY_SIZE 1
|
|
|
|
|
|
|
|
class nsRubyFrame;
|
|
|
|
class nsRubyBaseFrame;
|
|
|
|
class nsRubyTextFrame;
|
|
|
|
class nsRubyContentFrame;
|
2015-04-08 02:22:34 +03:00
|
|
|
class nsRubyBaseContainerFrame;
|
2015-04-08 02:22:34 +03:00
|
|
|
class nsRubyTextContainerFrame;
|
2015-04-08 02:22:34 +03:00
|
|
|
|
2014-12-12 13:30:43 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reserved ISize
|
|
|
|
*
|
|
|
|
* With some exceptions, each ruby internal box has two isizes, which
|
|
|
|
* are the reflowed isize and the final isize. The reflowed isize is
|
|
|
|
* what a box itself needs. It is determined when the box gets reflowed.
|
|
|
|
*
|
|
|
|
* The final isize is what a box should be as the final result. For a
|
|
|
|
* ruby base/text box, the final isize is the size of its ruby column.
|
|
|
|
* For a ruby base/text container, the final isize is the size of its
|
|
|
|
* ruby segment. The final isize is never smaller than the reflowed
|
|
|
|
* isize. It is initially determined when a ruby column/segment gets
|
|
|
|
* fully reflowed, and may be advanced when a box is expanded, e.g.
|
|
|
|
* for justification.
|
|
|
|
*
|
|
|
|
* The difference between the reflowed isize and the final isize is
|
|
|
|
* reserved in the line layout after reflowing a box, hence it is called
|
|
|
|
* "Reserved ISize" here. It is used to expand the ruby boxes from their
|
|
|
|
* reflowed isize to the final isize during alignment of the line.
|
|
|
|
*
|
|
|
|
* There are three exceptions for the final isize:
|
|
|
|
* 1. A ruby text container has a larger final isize only if it is for
|
|
|
|
* a span or collapsed annotations.
|
|
|
|
* 2. A ruby base container has a larger final isize only if at least
|
|
|
|
* one of its ruby text containers does.
|
|
|
|
* 3. If a ruby text container has a larger final isize, its children
|
|
|
|
* must not have.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class RubyUtils
|
|
|
|
{
|
|
|
|
public:
|
2015-04-23 04:32:53 +03:00
|
|
|
static inline bool IsRubyContentBox(nsIAtom* aFrameType)
|
|
|
|
{
|
|
|
|
return aFrameType == nsGkAtoms::rubyBaseFrame ||
|
|
|
|
aFrameType == nsGkAtoms::rubyTextFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool IsRubyContainerBox(nsIAtom* aFrameType)
|
|
|
|
{
|
|
|
|
return aFrameType == nsGkAtoms::rubyBaseContainerFrame ||
|
|
|
|
aFrameType == nsGkAtoms::rubyTextContainerFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool IsRubyBox(nsIAtom* aFrameType)
|
|
|
|
{
|
|
|
|
return aFrameType == nsGkAtoms::rubyFrame ||
|
|
|
|
IsRubyContentBox(aFrameType) || IsRubyContainerBox(aFrameType);
|
|
|
|
}
|
|
|
|
|
2014-12-12 13:30:43 +03:00
|
|
|
static inline bool IsExpandableRubyBox(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIAtom* type = aFrame->GetType();
|
2015-04-23 04:32:53 +03:00
|
|
|
return IsRubyContentBox(type) || IsRubyContainerBox(type);
|
2014-12-12 13:30:43 +03:00
|
|
|
}
|
|
|
|
|
2016-01-26 12:31:45 +03:00
|
|
|
static inline bool IsRubyPseudo(nsIAtom* aPseudo)
|
|
|
|
{
|
|
|
|
return aPseudo == nsCSSAnonBoxes::ruby ||
|
|
|
|
aPseudo == nsCSSAnonBoxes::rubyBase ||
|
|
|
|
aPseudo == nsCSSAnonBoxes::rubyText ||
|
|
|
|
aPseudo == nsCSSAnonBoxes::rubyBaseContainer ||
|
|
|
|
aPseudo == nsCSSAnonBoxes::rubyTextContainer;
|
|
|
|
}
|
|
|
|
|
2014-12-12 13:30:43 +03:00
|
|
|
static void SetReservedISize(nsIFrame* aFrame, nscoord aISize);
|
|
|
|
static void ClearReservedISize(nsIFrame* aFrame);
|
|
|
|
static nscoord GetReservedISize(nsIFrame* aFrame);
|
|
|
|
};
|
|
|
|
|
2014-12-29 03:14:53 +03:00
|
|
|
/**
|
2015-04-08 02:22:34 +03:00
|
|
|
* This array stores all ruby text containers of the ruby segment
|
|
|
|
* of the given ruby base container.
|
2014-12-29 03:14:53 +03:00
|
|
|
*/
|
2016-03-28 15:34:26 +03:00
|
|
|
class MOZ_RAII AutoRubyTextContainerArray final
|
2016-02-02 18:36:30 +03:00
|
|
|
: public AutoTArray<nsRubyTextContainerFrame*, RTC_ARRAY_SIZE>
|
2014-12-29 03:14:53 +03:00
|
|
|
{
|
|
|
|
public:
|
2015-04-08 02:22:34 +03:00
|
|
|
explicit AutoRubyTextContainerArray(nsRubyBaseContainerFrame* aBaseContainer);
|
2015-04-07 23:40:31 +03:00
|
|
|
};
|
|
|
|
|
2015-04-08 02:22:34 +03:00
|
|
|
/**
|
|
|
|
* This enumerator enumerates each ruby segment.
|
|
|
|
*/
|
|
|
|
class MOZ_STACK_CLASS RubySegmentEnumerator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit RubySegmentEnumerator(nsRubyFrame* aRubyFrame);
|
|
|
|
|
|
|
|
void Next();
|
|
|
|
bool AtEnd() const { return !mBaseContainer; }
|
|
|
|
|
|
|
|
nsRubyBaseContainerFrame* GetBaseContainer() const
|
|
|
|
{
|
|
|
|
return mBaseContainer;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsRubyBaseContainerFrame* mBaseContainer;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ruby column is a unit consists of one ruby base and all ruby
|
|
|
|
* annotations paired with it.
|
|
|
|
* See http://dev.w3.org/csswg/css-ruby/#ruby-pairing
|
|
|
|
*/
|
|
|
|
struct MOZ_STACK_CLASS RubyColumn
|
|
|
|
{
|
|
|
|
nsRubyBaseFrame* mBaseFrame;
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<nsRubyTextFrame*, RTC_ARRAY_SIZE> mTextFrames;
|
2015-04-08 02:22:34 +03:00
|
|
|
bool mIsIntraLevelWhitespace;
|
2016-01-27 08:58:53 +03:00
|
|
|
|
2015-04-08 02:22:34 +03:00
|
|
|
RubyColumn() : mBaseFrame(nullptr), mIsIntraLevelWhitespace(false) { }
|
2016-01-27 08:58:53 +03:00
|
|
|
|
|
|
|
// 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 ||
|
2016-01-27 09:30:04 +03:00
|
|
|
(aIndex >= 0 &&
|
|
|
|
aIndex <= int32_t(aColumn.mTextFrames.Length())));
|
2016-01-27 08:58:53 +03:00
|
|
|
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(); }
|
2015-04-08 02:22:34 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This enumerator enumerates ruby columns in a segment.
|
|
|
|
*/
|
|
|
|
class MOZ_STACK_CLASS RubyColumnEnumerator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RubyColumnEnumerator(nsRubyBaseContainerFrame* aRBCFrame,
|
2015-04-08 02:22:34 +03:00
|
|
|
const AutoRubyTextContainerArray& aRTCFrames);
|
2015-04-08 02:22:34 +03:00
|
|
|
|
|
|
|
void Next();
|
|
|
|
bool AtEnd() const;
|
|
|
|
|
|
|
|
uint32_t GetLevelCount() const { return mFrames.Length(); }
|
|
|
|
nsRubyContentFrame* GetFrameAtLevel(uint32_t aIndex) const;
|
|
|
|
void GetColumn(RubyColumn& aColumn) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Frames in this array are NOT necessary part of the current column.
|
|
|
|
// When in doubt, use GetFrameAtLevel to access it.
|
|
|
|
// See GetFrameAtLevel() and Next() for more info.
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<nsRubyContentFrame*, RTC_ARRAY_SIZE + 1> mFrames;
|
2015-04-08 02:22:34 +03:00
|
|
|
// Whether we are on a column for intra-level whitespaces
|
|
|
|
bool mAtIntraLevelWhitespace;
|
|
|
|
};
|
|
|
|
|
2016-11-10 03:10:42 +03:00
|
|
|
/**
|
|
|
|
* Stores block-axis leadings produced from ruby annotations.
|
|
|
|
*/
|
|
|
|
struct RubyBlockLeadings
|
|
|
|
{
|
|
|
|
nscoord mStart = 0;
|
|
|
|
nscoord mEnd = 0;
|
|
|
|
|
|
|
|
void Reset() {
|
|
|
|
mStart = mEnd = 0;
|
|
|
|
}
|
|
|
|
void Update(nscoord aStart, nscoord aEnd) {
|
|
|
|
mStart = std::max(mStart, aStart);
|
|
|
|
mEnd = std::max(mEnd, aEnd);
|
|
|
|
}
|
|
|
|
void Update(const RubyBlockLeadings& aOther) {
|
|
|
|
Update(aOther.mStart, aOther.mEnd);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|
2014-12-12 13:30:43 +03:00
|
|
|
|
|
|
|
#endif /* !defined(mozilla_RubyUtils_h_) */
|