2014-07-23 06:08:01 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code is subject to the terms of the Mozilla Public License
|
|
|
|
* version 2.0 (the "License"). You can obtain a copy of the License at
|
|
|
|
* http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
/* rendering object for CSS "display: ruby-base-container" */
|
|
|
|
|
|
|
|
#include "nsRubyBaseContainerFrame.h"
|
2015-04-08 02:22:34 +03:00
|
|
|
#include "nsRubyTextContainerFrame.h"
|
|
|
|
#include "nsRubyBaseFrame.h"
|
|
|
|
#include "nsRubyTextFrame.h"
|
2015-03-26 10:29:31 +03:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
#include "mozilla/Maybe.h"
|
|
|
|
#include "mozilla/WritingModes.h"
|
2015-09-01 02:24:37 +03:00
|
|
|
#include "nsLayoutUtils.h"
|
2014-08-15 21:34:20 +04:00
|
|
|
#include "nsLineLayout.h"
|
2014-07-23 06:08:01 +04:00
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsStyleContext.h"
|
2014-12-22 08:52:30 +03:00
|
|
|
#include "nsStyleStructInlines.h"
|
2015-02-11 02:26:56 +03:00
|
|
|
#include "nsTextFrame.h"
|
2015-03-26 10:29:31 +03:00
|
|
|
#include "RubyUtils.h"
|
2014-08-15 21:34:20 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2016-12-01 01:47:45 +03:00
|
|
|
using namespace mozilla::gfx;
|
2014-07-23 06:08:01 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Frame class boilerplate
|
|
|
|
// =======================
|
|
|
|
|
|
|
|
NS_QUERYFRAME_HEAD(nsRubyBaseContainerFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsRubyBaseContainerFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsRubyBaseContainerFrame)
|
|
|
|
|
|
|
|
nsContainerFrame*
|
|
|
|
NS_NewRubyBaseContainerFrame(nsIPresShell* aPresShell,
|
|
|
|
nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsRubyBaseContainerFrame(aContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// nsRubyBaseContainerFrame Method Implementations
|
|
|
|
// ===============================================
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsRubyBaseContainerFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::rubyBaseContainerFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
|
|
|
nsresult
|
|
|
|
nsRubyBaseContainerFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("RubyBaseContainer"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
2014-08-15 21:34:20 +04:00
|
|
|
|
2015-02-21 14:39:33 +03:00
|
|
|
static gfxBreakPriority
|
2015-02-21 14:39:33 +03:00
|
|
|
LineBreakBefore(nsIFrame* aFrame,
|
2015-12-16 00:56:41 +03:00
|
|
|
DrawTarget* aDrawTarget,
|
2015-02-21 14:39:33 +03:00
|
|
|
nsIFrame* aLineContainerFrame,
|
|
|
|
const nsLineList::iterator* aLine)
|
2015-02-21 14:39:33 +03:00
|
|
|
{
|
|
|
|
for (nsIFrame* child = aFrame; child;
|
2016-01-29 17:42:14 +03:00
|
|
|
child = child->PrincipalChildList().FirstChild()) {
|
2015-02-21 14:39:33 +03:00
|
|
|
if (!child->CanContinueTextRun()) {
|
|
|
|
// It is not an inline element. We can break before it.
|
|
|
|
return gfxBreakPriority::eNormalBreak;
|
|
|
|
}
|
|
|
|
if (child->GetType() != nsGkAtoms::textFrame) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto textFrame = static_cast<nsTextFrame*>(child);
|
|
|
|
gfxSkipCharsIterator iter =
|
2015-12-16 00:56:41 +03:00
|
|
|
textFrame->EnsureTextRun(nsTextFrame::eInflated, aDrawTarget,
|
2015-02-21 14:39:33 +03:00
|
|
|
aLineContainerFrame, aLine);
|
2015-02-21 14:39:33 +03:00
|
|
|
iter.SetOriginalOffset(textFrame->GetContentOffset());
|
|
|
|
uint32_t pos = iter.GetSkippedOffset();
|
|
|
|
gfxTextRun* textRun = textFrame->GetTextRun(nsTextFrame::eInflated);
|
|
|
|
if (pos >= textRun->GetLength()) {
|
|
|
|
// The text frame contains no character at all.
|
|
|
|
return gfxBreakPriority::eNoBreak;
|
|
|
|
}
|
|
|
|
// Return whether we can break before the first character.
|
|
|
|
if (textRun->CanBreakLineBefore(pos)) {
|
|
|
|
return gfxBreakPriority::eNormalBreak;
|
|
|
|
}
|
|
|
|
// Check whether we can wrap word here.
|
|
|
|
const nsStyleText* textStyle = textFrame->StyleText();
|
|
|
|
if (textStyle->WordCanWrap(textFrame) && textRun->IsClusterStart(pos)) {
|
|
|
|
return gfxBreakPriority::eWordWrapBreak;
|
|
|
|
}
|
|
|
|
// We cannot break before.
|
|
|
|
return gfxBreakPriority::eNoBreak;
|
|
|
|
}
|
|
|
|
// Neither block, nor text frame is found as a leaf. We won't break
|
|
|
|
// before this base frame. It is the behavior of empty spans.
|
|
|
|
return gfxBreakPriority::eNoBreak;
|
|
|
|
}
|
|
|
|
|
2015-02-21 14:39:33 +03:00
|
|
|
static void
|
|
|
|
GetIsLineBreakAllowed(nsIFrame* aFrame, bool aIsLineBreakable,
|
|
|
|
bool* aAllowInitialLineBreak, bool* aAllowLineBreak)
|
|
|
|
{
|
|
|
|
nsIFrame* parent = aFrame->GetParent();
|
2015-03-11 02:28:21 +03:00
|
|
|
bool lineBreakSuppressed = parent->StyleContext()->ShouldSuppressLineBreak();
|
2015-02-21 14:39:33 +03:00
|
|
|
// Allow line break between ruby bases when white-space allows,
|
|
|
|
// we are not inside a nested ruby, and there is no span.
|
2015-03-11 02:28:21 +03:00
|
|
|
bool allowLineBreak = !lineBreakSuppressed &&
|
2015-02-21 14:39:33 +03:00
|
|
|
aFrame->StyleText()->WhiteSpaceCanWrap(aFrame);
|
|
|
|
bool allowInitialLineBreak = allowLineBreak;
|
|
|
|
if (!aFrame->GetPrevInFlow()) {
|
2015-03-11 02:28:21 +03:00
|
|
|
allowInitialLineBreak = !lineBreakSuppressed &&
|
2015-02-21 14:39:33 +03:00
|
|
|
parent->StyleText()->WhiteSpaceCanWrap(parent);
|
|
|
|
}
|
|
|
|
if (!aIsLineBreakable) {
|
|
|
|
allowInitialLineBreak = false;
|
|
|
|
}
|
|
|
|
*aAllowInitialLineBreak = allowInitialLineBreak;
|
|
|
|
*aAllowLineBreak = allowLineBreak;
|
|
|
|
}
|
|
|
|
|
2015-07-09 09:05:26 +03:00
|
|
|
/**
|
|
|
|
* @param aBaseISizeData is an in/out param. This method updates the
|
|
|
|
* `skipWhitespace` and `trailingWhitespace` fields of the struct with
|
|
|
|
* the base level frame. Note that we don't need to do the same thing
|
|
|
|
* for ruby text frames, because they are text run container themselves
|
|
|
|
* (see nsTextFrame.cpp:BuildTextRuns), and thus no whitespace collapse
|
|
|
|
* happens across the boundary of those frames.
|
|
|
|
*/
|
2014-11-26 07:52:48 +03:00
|
|
|
static nscoord
|
2014-12-29 06:30:00 +03:00
|
|
|
CalculateColumnPrefISize(nsRenderingContext* aRenderingContext,
|
2015-07-09 09:05:26 +03:00
|
|
|
const RubyColumnEnumerator& aEnumerator,
|
|
|
|
nsIFrame::InlineIntrinsicISizeData* aBaseISizeData)
|
2014-11-26 07:52:48 +03:00
|
|
|
{
|
|
|
|
nscoord max = 0;
|
|
|
|
uint32_t levelCount = aEnumerator.GetLevelCount();
|
|
|
|
for (uint32_t i = 0; i < levelCount; i++) {
|
2015-01-08 10:28:09 +03:00
|
|
|
nsIFrame* frame = aEnumerator.GetFrameAtLevel(i);
|
2014-11-26 07:52:48 +03:00
|
|
|
if (frame) {
|
2015-02-21 14:39:33 +03:00
|
|
|
nsIFrame::InlinePrefISizeData data;
|
2015-07-09 09:05:26 +03:00
|
|
|
if (i == 0) {
|
2015-11-14 11:46:11 +03:00
|
|
|
data.SetLineContainer(aBaseISizeData->LineContainer());
|
2016-04-14 02:32:12 +03:00
|
|
|
data.mSkipWhitespace = aBaseISizeData->mSkipWhitespace;
|
|
|
|
data.mTrailingWhitespace = aBaseISizeData->mTrailingWhitespace;
|
2015-07-09 09:05:26 +03:00
|
|
|
} else {
|
|
|
|
// The line container of ruby text frames is their parent,
|
|
|
|
// ruby text container frame.
|
2015-11-14 11:46:11 +03:00
|
|
|
data.SetLineContainer(frame->GetParent());
|
2015-07-09 09:05:26 +03:00
|
|
|
}
|
2015-02-21 14:39:33 +03:00
|
|
|
frame->AddInlinePrefISize(aRenderingContext, &data);
|
2016-04-14 02:32:12 +03:00
|
|
|
MOZ_ASSERT(data.mPrevLines == 0, "Shouldn't have prev lines");
|
|
|
|
max = std::max(max, data.mCurrentLine);
|
2015-07-09 09:05:26 +03:00
|
|
|
if (i == 0) {
|
2016-04-14 02:32:12 +03:00
|
|
|
aBaseISizeData->mSkipWhitespace = data.mSkipWhitespace;
|
|
|
|
aBaseISizeData->mTrailingWhitespace = data.mTrailingWhitespace;
|
2015-07-09 09:05:26 +03:00
|
|
|
}
|
2014-11-26 07:52:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
2015-02-21 14:39:33 +03:00
|
|
|
// FIXME Currently we use pref isize of ruby content frames for
|
|
|
|
// computing min isize of ruby frame, which may cause problem.
|
|
|
|
// See bug 1134945.
|
2014-11-26 07:52:48 +03:00
|
|
|
/* virtual */ void
|
|
|
|
nsRubyBaseContainerFrame::AddInlineMinISize(
|
2015-02-21 14:39:33 +03:00
|
|
|
nsRenderingContext *aRenderingContext, nsIFrame::InlineMinISizeData *aData)
|
2014-11-26 07:52:48 +03:00
|
|
|
{
|
2015-04-08 02:22:34 +03:00
|
|
|
AutoRubyTextContainerArray textContainers(this);
|
2014-12-30 01:56:34 +03:00
|
|
|
|
|
|
|
for (uint32_t i = 0, iend = textContainers.Length(); i < iend; i++) {
|
|
|
|
if (textContainers[i]->IsSpanContainer()) {
|
2014-12-30 01:44:12 +03:00
|
|
|
// Since spans are not breakable internally, use our pref isize
|
|
|
|
// directly if there is any span.
|
2015-02-21 14:39:33 +03:00
|
|
|
nsIFrame::InlinePrefISizeData data;
|
2015-11-14 11:46:11 +03:00
|
|
|
data.SetLineContainer(aData->LineContainer());
|
2016-04-14 02:32:12 +03:00
|
|
|
data.mSkipWhitespace = aData->mSkipWhitespace;
|
|
|
|
data.mTrailingWhitespace = aData->mTrailingWhitespace;
|
2015-02-21 14:39:33 +03:00
|
|
|
AddInlinePrefISize(aRenderingContext, &data);
|
2016-04-14 02:32:12 +03:00
|
|
|
aData->mCurrentLine += data.mCurrentLine;
|
|
|
|
if (data.mCurrentLine > 0) {
|
|
|
|
aData->mAtStartOfLine = false;
|
2015-02-21 14:39:33 +03:00
|
|
|
}
|
2016-04-14 02:32:12 +03:00
|
|
|
aData->mSkipWhitespace = data.mSkipWhitespace;
|
|
|
|
aData->mTrailingWhitespace = data.mTrailingWhitespace;
|
2014-12-30 01:44:12 +03:00
|
|
|
return;
|
|
|
|
}
|
2014-11-26 07:52:48 +03:00
|
|
|
}
|
|
|
|
|
2015-02-21 14:39:33 +03:00
|
|
|
bool firstFrame = true;
|
|
|
|
bool allowInitialLineBreak, allowLineBreak;
|
2016-04-14 02:32:12 +03:00
|
|
|
GetIsLineBreakAllowed(this, !aData->mAtStartOfLine,
|
2015-02-21 14:39:33 +03:00
|
|
|
&allowInitialLineBreak, &allowLineBreak);
|
2015-02-21 14:39:33 +03:00
|
|
|
for (nsIFrame* frame = this; frame; frame = frame->GetNextInFlow()) {
|
|
|
|
RubyColumnEnumerator enumerator(
|
|
|
|
static_cast<nsRubyBaseContainerFrame*>(frame), textContainers);
|
|
|
|
for (; !enumerator.AtEnd(); enumerator.Next()) {
|
2015-02-21 14:39:33 +03:00
|
|
|
if (firstFrame ? allowInitialLineBreak : allowLineBreak) {
|
|
|
|
nsIFrame* baseFrame = enumerator.GetFrameAtLevel(0);
|
|
|
|
if (baseFrame) {
|
|
|
|
gfxBreakPriority breakPriority =
|
2015-12-16 00:56:41 +03:00
|
|
|
LineBreakBefore(baseFrame, aRenderingContext->GetDrawTarget(),
|
|
|
|
nullptr, nullptr);
|
2015-02-21 14:39:33 +03:00
|
|
|
if (breakPriority != gfxBreakPriority::eNoBreak) {
|
2015-12-07 01:13:57 +03:00
|
|
|
aData->OptionallyBreak();
|
2015-02-21 14:39:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
firstFrame = false;
|
2015-07-09 09:05:26 +03:00
|
|
|
nscoord isize = CalculateColumnPrefISize(aRenderingContext,
|
|
|
|
enumerator, aData);
|
2016-04-14 02:32:12 +03:00
|
|
|
aData->mCurrentLine += isize;
|
2015-02-21 14:39:33 +03:00
|
|
|
if (isize > 0) {
|
2016-04-14 02:32:12 +03:00
|
|
|
aData->mAtStartOfLine = false;
|
2015-02-21 14:39:33 +03:00
|
|
|
}
|
|
|
|
}
|
2014-11-26 07:52:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
nsRubyBaseContainerFrame::AddInlinePrefISize(
|
2015-02-21 14:39:33 +03:00
|
|
|
nsRenderingContext *aRenderingContext, nsIFrame::InlinePrefISizeData *aData)
|
2014-11-26 07:52:48 +03:00
|
|
|
{
|
2015-04-08 02:22:34 +03:00
|
|
|
AutoRubyTextContainerArray textContainers(this);
|
2014-12-30 01:56:34 +03:00
|
|
|
|
2014-11-26 07:52:48 +03:00
|
|
|
nscoord sum = 0;
|
2015-02-21 14:39:33 +03:00
|
|
|
for (nsIFrame* frame = this; frame; frame = frame->GetNextInFlow()) {
|
|
|
|
RubyColumnEnumerator enumerator(
|
|
|
|
static_cast<nsRubyBaseContainerFrame*>(frame), textContainers);
|
|
|
|
for (; !enumerator.AtEnd(); enumerator.Next()) {
|
2015-07-09 09:05:26 +03:00
|
|
|
sum += CalculateColumnPrefISize(aRenderingContext, enumerator, aData);
|
2015-02-21 14:39:33 +03:00
|
|
|
}
|
2014-11-26 07:52:48 +03:00
|
|
|
}
|
2014-12-30 01:56:34 +03:00
|
|
|
for (uint32_t i = 0, iend = textContainers.Length(); i < iend; i++) {
|
|
|
|
if (textContainers[i]->IsSpanContainer()) {
|
2016-01-29 17:42:14 +03:00
|
|
|
nsIFrame* frame = textContainers[i]->PrincipalChildList().FirstChild();
|
2015-02-21 14:39:33 +03:00
|
|
|
nsIFrame::InlinePrefISizeData data;
|
|
|
|
frame->AddInlinePrefISize(aRenderingContext, &data);
|
2016-04-14 02:32:12 +03:00
|
|
|
MOZ_ASSERT(data.mPrevLines == 0, "Shouldn't have prev lines");
|
|
|
|
sum = std::max(sum, data.mCurrentLine);
|
2014-12-30 01:44:12 +03:00
|
|
|
}
|
|
|
|
}
|
2016-04-14 02:32:12 +03:00
|
|
|
aData->mCurrentLine += sum;
|
2014-11-26 07:52:48 +03:00
|
|
|
}
|
|
|
|
|
2014-08-15 21:34:20 +04:00
|
|
|
/* virtual */ bool
|
|
|
|
nsRubyBaseContainerFrame::IsFrameOfType(uint32_t aFlags) const
|
|
|
|
{
|
2015-01-16 02:07:50 +03:00
|
|
|
if (aFlags & eSupportsCSSTransforms) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return nsContainerFrame::IsFrameOfType(aFlags &
|
2014-08-15 21:34:20 +04:00
|
|
|
~(nsIFrame::eLineParticipant));
|
|
|
|
}
|
2014-08-15 21:34:20 +04:00
|
|
|
|
2014-08-15 21:34:20 +04:00
|
|
|
/* virtual */ bool
|
|
|
|
nsRubyBaseContainerFrame::CanContinueTextRun() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-26 07:52:49 +03:00
|
|
|
/* virtual */ LogicalSize
|
|
|
|
nsRubyBaseContainerFrame::ComputeSize(nsRenderingContext *aRenderingContext,
|
|
|
|
WritingMode aWM,
|
|
|
|
const LogicalSize& aCBSize,
|
|
|
|
nscoord aAvailableISize,
|
|
|
|
const LogicalSize& aMargin,
|
|
|
|
const LogicalSize& aBorder,
|
|
|
|
const LogicalSize& aPadding,
|
|
|
|
ComputeSizeFlags aFlags)
|
|
|
|
{
|
|
|
|
// Ruby base container frame is inline,
|
|
|
|
// hence don't compute size before reflow.
|
|
|
|
return LogicalSize(aWM, NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
}
|
|
|
|
|
2014-11-26 07:52:49 +03:00
|
|
|
/* virtual */ nscoord
|
|
|
|
nsRubyBaseContainerFrame::GetLogicalBaseline(WritingMode aWritingMode) const
|
|
|
|
{
|
|
|
|
return mBaseline;
|
|
|
|
}
|
|
|
|
|
2016-07-21 13:36:38 +03:00
|
|
|
struct nsRubyBaseContainerFrame::RubyReflowInput
|
2014-12-29 07:03:38 +03:00
|
|
|
{
|
2015-02-11 02:26:56 +03:00
|
|
|
bool mAllowInitialLineBreak;
|
2014-12-29 07:03:38 +03:00
|
|
|
bool mAllowLineBreak;
|
2015-04-08 02:22:34 +03:00
|
|
|
const AutoRubyTextContainerArray& mTextContainers;
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& mBaseReflowInput;
|
|
|
|
const nsTArray<UniquePtr<ReflowInput>>& mTextReflowInputs;
|
2014-12-29 07:03:38 +03:00
|
|
|
};
|
|
|
|
|
2014-08-15 21:34:20 +04:00
|
|
|
/* virtual */ void
|
|
|
|
nsRubyBaseContainerFrame::Reflow(nsPresContext* aPresContext,
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput& aDesiredSize,
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& aReflowInput,
|
2014-08-15 21:34:20 +04:00
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2015-03-30 01:38:40 +03:00
|
|
|
MarkInReflow();
|
2014-08-15 21:34:20 +04:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsRubyBaseContainerFrame");
|
2016-07-21 13:36:39 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus);
|
2017-02-14 12:55:48 +03:00
|
|
|
aStatus.Reset();
|
2014-08-15 21:34:20 +04:00
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
if (!aReflowInput.mLineLayout) {
|
2014-08-15 21:34:20 +04:00
|
|
|
NS_ASSERTION(
|
2016-07-21 13:36:39 +03:00
|
|
|
aReflowInput.mLineLayout,
|
2014-08-15 21:34:20 +04:00
|
|
|
"No line layout provided to RubyBaseContainerFrame reflow method.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-26 09:40:58 +03:00
|
|
|
mDescendantLeadings.Reset();
|
|
|
|
|
2014-11-26 07:52:50 +03:00
|
|
|
MoveOverflowToChildList();
|
|
|
|
// Ask text containers to drain overflows
|
2015-04-08 02:22:34 +03:00
|
|
|
AutoRubyTextContainerArray textContainers(this);
|
2014-12-30 01:56:34 +03:00
|
|
|
const uint32_t rtcCount = textContainers.Length();
|
2014-11-26 07:52:50 +03:00
|
|
|
for (uint32_t i = 0; i < rtcCount; i++) {
|
2014-12-30 01:56:34 +03:00
|
|
|
textContainers[i]->MoveOverflowToChildList();
|
2014-11-26 07:52:50 +03:00
|
|
|
}
|
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
WritingMode lineWM = aReflowInput.mLineLayout->GetWritingMode();
|
|
|
|
LogicalSize availSize(lineWM, aReflowInput.AvailableISize(),
|
|
|
|
aReflowInput.AvailableBSize());
|
2014-08-15 21:34:20 +04:00
|
|
|
|
2014-11-26 07:52:49 +03:00
|
|
|
// We have a reflow state and a line layout for each RTC.
|
|
|
|
// They are conceptually the state of the RTCs, but we don't actually
|
|
|
|
// reflow those RTCs in this code. These two arrays are holders of
|
|
|
|
// the reflow states and line layouts.
|
2014-12-11 03:24:53 +03:00
|
|
|
// Since there are pointers refer to reflow states and line layouts,
|
|
|
|
// it is necessary to guarantee that they won't be moved. For this
|
|
|
|
// reason, they are wrapped in UniquePtr here.
|
2016-07-21 13:36:39 +03:00
|
|
|
AutoTArray<UniquePtr<ReflowInput>, RTC_ARRAY_SIZE> reflowInputs;
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<UniquePtr<nsLineLayout>, RTC_ARRAY_SIZE> lineLayouts;
|
2016-07-21 13:36:39 +03:00
|
|
|
reflowInputs.SetCapacity(rtcCount);
|
2014-12-30 01:44:12 +03:00
|
|
|
lineLayouts.SetCapacity(rtcCount);
|
2014-11-26 07:52:49 +03:00
|
|
|
|
2014-08-15 21:34:20 +04:00
|
|
|
// Begin the line layout for each ruby text container in advance.
|
2014-12-30 01:44:12 +03:00
|
|
|
bool hasSpan = false;
|
|
|
|
for (uint32_t i = 0; i < rtcCount; i++) {
|
2014-12-30 01:56:34 +03:00
|
|
|
nsRubyTextContainerFrame* textContainer = textContainers[i];
|
2014-12-30 01:44:12 +03:00
|
|
|
if (textContainer->IsSpanContainer()) {
|
|
|
|
hasSpan = true;
|
2014-11-26 07:52:49 +03:00
|
|
|
}
|
2014-12-30 01:44:12 +03:00
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowInput* reflowInput = new ReflowInput(
|
|
|
|
aPresContext, *aReflowInput.mParentReflowInput, textContainer,
|
2015-04-08 02:22:34 +03:00
|
|
|
availSize.ConvertTo(textContainer->GetWritingMode(), lineWM));
|
2016-07-21 13:36:39 +03:00
|
|
|
reflowInputs.AppendElement(reflowInput);
|
2014-12-10 02:04:15 +03:00
|
|
|
nsLineLayout* lineLayout = new nsLineLayout(aPresContext,
|
2016-07-21 13:36:39 +03:00
|
|
|
reflowInput->mFloatManager,
|
|
|
|
reflowInput, nullptr,
|
|
|
|
aReflowInput.mLineLayout);
|
2015-02-18 07:20:02 +03:00
|
|
|
lineLayout->SetSuppressLineWrap(true);
|
2014-11-26 07:52:49 +03:00
|
|
|
lineLayouts.AppendElement(lineLayout);
|
|
|
|
|
|
|
|
// Line number is useless for ruby text
|
|
|
|
// XXX nullptr here may cause problem, see comments for
|
2016-07-21 13:36:39 +03:00
|
|
|
// nsLineLayout::mBlockRI and nsLineLayout::AddFloat
|
2016-07-21 13:36:39 +03:00
|
|
|
lineLayout->Init(nullptr, reflowInput->CalcLineHeight(), -1);
|
|
|
|
reflowInput->mLineLayout = lineLayout;
|
2014-11-26 07:52:49 +03:00
|
|
|
|
2015-01-15 12:02:11 +03:00
|
|
|
// Border and padding are suppressed on ruby text containers.
|
2015-01-13 12:04:41 +03:00
|
|
|
// If the writing mode is vertical-rl, the horizontal position of
|
|
|
|
// rt frames will be updated when reflowing this text container,
|
2015-02-11 12:43:03 +03:00
|
|
|
// hence leave container size 0 here for now.
|
2016-07-21 13:36:39 +03:00
|
|
|
lineLayout->BeginLineReflow(0, 0, reflowInput->ComputedISize(),
|
2014-11-26 07:52:49 +03:00
|
|
|
NS_UNCONSTRAINEDSIZE,
|
2015-02-11 12:43:03 +03:00
|
|
|
false, false, lineWM, nsSize(0, 0));
|
2014-12-10 02:04:15 +03:00
|
|
|
lineLayout->AttachRootFrameToBaseLineLayout();
|
2014-08-15 21:34:20 +04:00
|
|
|
}
|
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
aReflowInput.mLineLayout->BeginSpan(this, &aReflowInput,
|
|
|
|
0, aReflowInput.AvailableISize(),
|
2015-01-15 12:02:11 +03:00
|
|
|
&mBaseline);
|
2014-12-11 07:13:42 +03:00
|
|
|
|
2015-02-21 14:39:33 +03:00
|
|
|
bool allowInitialLineBreak, allowLineBreak;
|
2016-07-21 13:36:39 +03:00
|
|
|
GetIsLineBreakAllowed(this, aReflowInput.mLineLayout->LineIsBreakable(),
|
2015-02-21 14:39:33 +03:00
|
|
|
&allowInitialLineBreak, &allowLineBreak);
|
2014-12-22 08:24:24 +03:00
|
|
|
|
|
|
|
nscoord isize = 0;
|
2015-02-11 02:26:56 +03:00
|
|
|
// Reflow columns excluding any span
|
2016-07-21 13:36:39 +03:00
|
|
|
RubyReflowInput reflowInput = {
|
2015-02-11 02:26:56 +03:00
|
|
|
allowInitialLineBreak, allowLineBreak && !hasSpan,
|
2016-07-21 13:36:39 +03:00
|
|
|
textContainers, aReflowInput, reflowInputs
|
2015-02-11 02:26:56 +03:00
|
|
|
};
|
2016-07-21 13:36:39 +03:00
|
|
|
isize = ReflowColumns(reflowInput, aStatus);
|
|
|
|
DebugOnly<nscoord> lineSpanSize = aReflowInput.mLineLayout->EndSpan(this);
|
2015-01-07 04:47:09 +03:00
|
|
|
aDesiredSize.ISize(lineWM) = isize;
|
|
|
|
// When there are no frames inside the ruby base container, EndSpan
|
|
|
|
// will return 0. However, in this case, the actual width of the
|
|
|
|
// container could be non-zero because of non-empty ruby annotations.
|
2015-03-31 08:30:29 +03:00
|
|
|
// XXX When bug 765861 gets fixed, this warning should be upgraded.
|
2016-09-01 08:01:16 +03:00
|
|
|
NS_WARNING_ASSERTION(
|
2017-02-14 11:33:37 +03:00
|
|
|
aStatus.IsInlineBreak() || isize == lineSpanSize || mFrames.IsEmpty(),
|
2016-09-01 08:01:16 +03:00
|
|
|
"bad isize");
|
2014-11-26 07:52:50 +03:00
|
|
|
|
2014-12-29 06:30:00 +03:00
|
|
|
// If there exists any span, the columns must either be completely
|
2014-11-26 07:52:50 +03:00
|
|
|
// reflowed, or be not reflowed at all.
|
2017-02-14 11:05:24 +03:00
|
|
|
MOZ_ASSERT(aStatus.IsInlineBreakBefore() ||
|
2017-02-11 17:45:07 +03:00
|
|
|
aStatus.IsComplete() || !hasSpan);
|
2017-02-14 11:05:24 +03:00
|
|
|
if (!aStatus.IsInlineBreakBefore() &&
|
2017-02-11 17:45:07 +03:00
|
|
|
aStatus.IsComplete() && hasSpan) {
|
2014-11-26 07:52:50 +03:00
|
|
|
// Reflow spans
|
2016-07-21 13:36:39 +03:00
|
|
|
RubyReflowInput reflowInput = {
|
|
|
|
false, false, textContainers, aReflowInput, reflowInputs
|
2014-12-29 07:03:38 +03:00
|
|
|
};
|
2016-07-21 13:36:39 +03:00
|
|
|
nscoord spanISize = ReflowSpans(reflowInput);
|
2015-02-11 02:26:56 +03:00
|
|
|
isize = std::max(isize, spanISize);
|
2014-12-30 01:24:57 +03:00
|
|
|
}
|
2014-11-26 07:52:50 +03:00
|
|
|
|
2014-12-30 01:44:12 +03:00
|
|
|
for (uint32_t i = 0; i < rtcCount; i++) {
|
2014-11-26 07:52:50 +03:00
|
|
|
// It happens before the ruby text container is reflowed, and that
|
|
|
|
// when it is reflowed, it will just use this size.
|
2014-12-30 01:56:34 +03:00
|
|
|
nsRubyTextContainerFrame* textContainer = textContainers[i];
|
2014-12-09 09:47:26 +03:00
|
|
|
nsLineLayout* lineLayout = lineLayouts[i].get();
|
2014-12-13 03:05:02 +03:00
|
|
|
|
2014-12-09 09:47:26 +03:00
|
|
|
RubyUtils::ClearReservedISize(textContainer);
|
|
|
|
nscoord rtcISize = lineLayout->GetCurrentICoord();
|
2014-12-13 03:05:02 +03:00
|
|
|
// Only span containers and containers with collapsed annotations
|
|
|
|
// need reserving isize. For normal ruby text containers, their
|
|
|
|
// children will be expanded properly. We only need to expand their
|
|
|
|
// own size.
|
2014-12-30 01:44:12 +03:00
|
|
|
if (!textContainer->IsSpanContainer()) {
|
2014-12-13 03:05:02 +03:00
|
|
|
rtcISize = isize;
|
|
|
|
} else if (isize > rtcISize) {
|
|
|
|
RubyUtils::SetReservedISize(textContainer, isize - rtcISize);
|
|
|
|
}
|
2014-12-09 09:47:26 +03:00
|
|
|
|
|
|
|
lineLayout->VerticalAlignLine();
|
2015-02-17 04:25:18 +03:00
|
|
|
textContainer->SetISize(rtcISize);
|
2014-12-09 09:47:26 +03:00
|
|
|
lineLayout->EndLineReflow();
|
2014-11-26 07:52:50 +03:00
|
|
|
}
|
|
|
|
|
2015-01-15 12:02:11 +03:00
|
|
|
// Border and padding are suppressed on ruby base container,
|
|
|
|
// create a fake borderPadding for setting BSize.
|
2016-07-21 13:36:39 +03:00
|
|
|
WritingMode frameWM = aReflowInput.GetWritingMode();
|
2015-01-15 12:02:11 +03:00
|
|
|
LogicalMargin borderPadding(frameWM);
|
2015-01-15 12:02:11 +03:00
|
|
|
nsLayoutUtils::SetBSizeFromFontMetrics(this, aDesiredSize,
|
2014-11-26 07:52:50 +03:00
|
|
|
borderPadding, lineWM, frameWM);
|
|
|
|
}
|
|
|
|
|
2014-11-26 07:52:50 +03:00
|
|
|
/**
|
|
|
|
* This struct stores the continuations after this frame and
|
|
|
|
* corresponding text containers. It is used to speed up looking
|
|
|
|
* ahead for nonempty continuations.
|
|
|
|
*/
|
|
|
|
struct MOZ_STACK_CLASS nsRubyBaseContainerFrame::PullFrameState
|
|
|
|
{
|
|
|
|
ContinuationTraversingState mBase;
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<ContinuationTraversingState, RTC_ARRAY_SIZE> mTexts;
|
2015-04-08 02:22:34 +03:00
|
|
|
const AutoRubyTextContainerArray& mTextContainers;
|
2014-11-26 07:52:50 +03:00
|
|
|
|
2014-12-30 01:56:34 +03:00
|
|
|
PullFrameState(nsRubyBaseContainerFrame* aBaseContainer,
|
2015-04-08 02:22:34 +03:00
|
|
|
const AutoRubyTextContainerArray& aTextContainers);
|
2014-11-26 07:52:50 +03:00
|
|
|
};
|
|
|
|
|
2014-11-26 07:52:50 +03:00
|
|
|
nscoord
|
2016-07-21 13:36:39 +03:00
|
|
|
nsRubyBaseContainerFrame::ReflowColumns(const RubyReflowInput& aReflowInput,
|
2014-12-29 06:30:00 +03:00
|
|
|
nsReflowStatus& aStatus)
|
2014-11-26 07:52:50 +03:00
|
|
|
{
|
2016-07-21 13:36:39 +03:00
|
|
|
nsLineLayout* lineLayout = aReflowInput.mBaseReflowInput.mLineLayout;
|
|
|
|
const uint32_t rtcCount = aReflowInput.mTextContainers.Length();
|
2015-01-15 12:02:11 +03:00
|
|
|
nscoord icoord = lineLayout->GetCurrentICoord();
|
|
|
|
MOZ_ASSERT(icoord == 0, "border/padding of rbc should have been suppressed");
|
2017-02-14 12:55:48 +03:00
|
|
|
nsReflowStatus reflowStatus;
|
|
|
|
aStatus.Reset();
|
2014-11-26 07:52:49 +03:00
|
|
|
|
2014-12-30 02:05:54 +03:00
|
|
|
uint32_t columnIndex = 0;
|
2014-12-29 07:22:19 +03:00
|
|
|
RubyColumn column;
|
|
|
|
column.mTextFrames.SetCapacity(rtcCount);
|
2016-07-21 13:36:39 +03:00
|
|
|
RubyColumnEnumerator e(this, aReflowInput.mTextContainers);
|
2014-11-26 07:52:50 +03:00
|
|
|
for (; !e.AtEnd(); e.Next()) {
|
2014-12-29 07:22:19 +03:00
|
|
|
e.GetColumn(column);
|
2016-07-21 13:36:39 +03:00
|
|
|
icoord += ReflowOneColumn(aReflowInput, columnIndex, column, reflowStatus);
|
2017-02-14 11:05:24 +03:00
|
|
|
if (!reflowStatus.IsInlineBreakBefore()) {
|
2014-12-30 02:05:54 +03:00
|
|
|
columnIndex++;
|
|
|
|
}
|
2017-02-14 11:33:37 +03:00
|
|
|
if (reflowStatus.IsInlineBreak()) {
|
2014-11-26 07:52:50 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// We are not handling overflow here.
|
2017-02-14 12:55:48 +03:00
|
|
|
MOZ_ASSERT(reflowStatus.IsEmpty());
|
2014-11-26 07:52:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isComplete = false;
|
2016-07-21 13:36:39 +03:00
|
|
|
PullFrameState pullFrameState(this, aReflowInput.mTextContainers);
|
2017-02-14 11:33:37 +03:00
|
|
|
while (!reflowStatus.IsInlineBreak()) {
|
2014-11-26 07:52:50 +03:00
|
|
|
// We are not handling overflow here.
|
2017-02-14 12:55:48 +03:00
|
|
|
MOZ_ASSERT(reflowStatus.IsEmpty());
|
2014-11-26 07:52:50 +03:00
|
|
|
|
|
|
|
// Try pull some frames from next continuations. This call replaces
|
2014-12-29 07:22:19 +03:00
|
|
|
// frames in |column| with the frame pulled in each level.
|
|
|
|
PullOneColumn(lineLayout, pullFrameState, column, isComplete);
|
2014-11-26 07:52:50 +03:00
|
|
|
if (isComplete) {
|
|
|
|
// No more frames can be pulled.
|
|
|
|
break;
|
|
|
|
}
|
2016-07-21 13:36:39 +03:00
|
|
|
icoord += ReflowOneColumn(aReflowInput, columnIndex, column, reflowStatus);
|
2017-02-14 11:05:24 +03:00
|
|
|
if (!reflowStatus.IsInlineBreakBefore()) {
|
2014-12-30 02:05:54 +03:00
|
|
|
columnIndex++;
|
|
|
|
}
|
2014-11-26 07:52:50 +03:00
|
|
|
}
|
|
|
|
|
2017-02-14 11:22:04 +03:00
|
|
|
if (!e.AtEnd() && reflowStatus.IsInlineBreakAfter()) {
|
2014-12-29 06:30:00 +03:00
|
|
|
// The current column has been successfully placed.
|
|
|
|
// Skip to the next column and mark break before.
|
2014-11-26 07:52:50 +03:00
|
|
|
e.Next();
|
2014-12-29 07:22:19 +03:00
|
|
|
e.GetColumn(column);
|
2017-02-14 06:52:53 +03:00
|
|
|
reflowStatus.SetInlineLineBreakBeforeAndReset();
|
2014-11-26 07:52:50 +03:00
|
|
|
}
|
|
|
|
if (!e.AtEnd() || (GetNextInFlow() && !isComplete)) {
|
2017-02-11 18:06:17 +03:00
|
|
|
aStatus.SetIncomplete();
|
2014-11-26 07:52:50 +03:00
|
|
|
}
|
|
|
|
|
2017-02-14 11:05:24 +03:00
|
|
|
if (reflowStatus.IsInlineBreakBefore()) {
|
2016-07-21 13:36:39 +03:00
|
|
|
if (!columnIndex || !aReflowInput.mAllowLineBreak) {
|
2014-12-29 06:30:00 +03:00
|
|
|
// If no column has been placed yet, or we have any span,
|
2014-11-26 07:52:50 +03:00
|
|
|
// the whole container should be in the next line.
|
2017-02-14 06:52:53 +03:00
|
|
|
aStatus.SetInlineLineBreakBeforeAndReset();
|
2014-11-26 07:52:50 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2017-02-14 06:52:53 +03:00
|
|
|
aStatus.SetInlineLineBreakAfter();
|
2017-02-11 17:45:07 +03:00
|
|
|
MOZ_ASSERT(aStatus.IsComplete() || aReflowInput.mAllowLineBreak);
|
2014-11-26 07:52:50 +03:00
|
|
|
|
2015-01-08 10:28:09 +03:00
|
|
|
// If we are on an intra-level whitespace column, null values in
|
|
|
|
// column.mBaseFrame and column.mTextFrames don't represent the
|
|
|
|
// end of the frame-sibling-chain at that level -- instead, they
|
|
|
|
// represent an anonymous empty intra-level whitespace box. It is
|
|
|
|
// likely that there are frames in the next column (which can't be
|
|
|
|
// intra-level whitespace). Those frames should be pushed as well.
|
|
|
|
Maybe<RubyColumn> nextColumn;
|
|
|
|
if (column.mIsIntraLevelWhitespace && !e.AtEnd()) {
|
|
|
|
e.Next();
|
|
|
|
nextColumn.emplace();
|
|
|
|
e.GetColumn(nextColumn.ref());
|
|
|
|
}
|
|
|
|
nsIFrame* baseFrame = column.mBaseFrame;
|
|
|
|
if (!baseFrame & nextColumn.isSome()) {
|
|
|
|
baseFrame = nextColumn->mBaseFrame;
|
|
|
|
}
|
|
|
|
if (baseFrame) {
|
|
|
|
PushChildren(baseFrame, baseFrame->GetPrevSibling());
|
2014-11-26 07:52:50 +03:00
|
|
|
}
|
|
|
|
for (uint32_t i = 0; i < rtcCount; i++) {
|
2015-01-08 10:28:09 +03:00
|
|
|
nsRubyTextFrame* textFrame = column.mTextFrames[i];
|
2015-01-08 10:28:09 +03:00
|
|
|
if (!textFrame && nextColumn.isSome()) {
|
|
|
|
textFrame = nextColumn->mTextFrames[i];
|
|
|
|
}
|
2014-11-26 07:52:50 +03:00
|
|
|
if (textFrame) {
|
2016-07-21 13:36:39 +03:00
|
|
|
aReflowInput.mTextContainers[i]->PushChildren(
|
2014-12-30 01:56:34 +03:00
|
|
|
textFrame, textFrame->GetPrevSibling());
|
2014-11-26 07:52:50 +03:00
|
|
|
}
|
|
|
|
}
|
2017-02-14 11:22:04 +03:00
|
|
|
} else if (reflowStatus.IsInlineBreakAfter()) {
|
2014-11-26 07:52:50 +03:00
|
|
|
// |reflowStatus| being break after here may only happen when
|
2014-12-29 06:30:00 +03:00
|
|
|
// there is a break after the column just pulled, or the whole
|
2014-11-26 07:52:50 +03:00
|
|
|
// segment has been completely reflowed. In those cases, we do
|
|
|
|
// not need to push anything.
|
|
|
|
MOZ_ASSERT(e.AtEnd());
|
2017-02-14 06:52:53 +03:00
|
|
|
aStatus.SetInlineLineBreakAfter();
|
2014-11-26 07:52:50 +03:00
|
|
|
}
|
|
|
|
|
2015-01-15 12:02:11 +03:00
|
|
|
return icoord;
|
2014-11-26 07:52:50 +03:00
|
|
|
}
|
|
|
|
|
2014-11-26 07:52:50 +03:00
|
|
|
nscoord
|
2016-07-21 13:36:39 +03:00
|
|
|
nsRubyBaseContainerFrame::ReflowOneColumn(const RubyReflowInput& aReflowInput,
|
2014-12-30 02:05:54 +03:00
|
|
|
uint32_t aColumnIndex,
|
2014-12-29 07:22:19 +03:00
|
|
|
const RubyColumn& aColumn,
|
2014-12-29 06:30:00 +03:00
|
|
|
nsReflowStatus& aStatus)
|
2014-11-26 07:52:50 +03:00
|
|
|
{
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& baseReflowInput = aReflowInput.mBaseReflowInput;
|
|
|
|
const auto& textReflowInputs = aReflowInput.mTextReflowInputs;
|
|
|
|
nscoord istart = baseReflowInput.mLineLayout->GetCurrentICoord();
|
2014-12-29 07:03:38 +03:00
|
|
|
|
2015-02-11 02:26:56 +03:00
|
|
|
if (aColumn.mBaseFrame) {
|
2015-03-11 02:28:21 +03:00
|
|
|
bool allowBreakBefore = aColumnIndex ?
|
2016-07-21 13:36:39 +03:00
|
|
|
aReflowInput.mAllowLineBreak : aReflowInput.mAllowInitialLineBreak;
|
2015-03-11 02:28:21 +03:00
|
|
|
if (allowBreakBefore) {
|
|
|
|
gfxBreakPriority breakPriority = LineBreakBefore(
|
2016-07-21 13:36:39 +03:00
|
|
|
aColumn.mBaseFrame, baseReflowInput.mRenderingContext->GetDrawTarget(),
|
|
|
|
baseReflowInput.mLineLayout->LineContainerFrame(),
|
|
|
|
baseReflowInput.mLineLayout->GetLine());
|
2015-03-11 02:28:21 +03:00
|
|
|
if (breakPriority != gfxBreakPriority::eNoBreak) {
|
2015-03-11 06:14:48 +03:00
|
|
|
gfxBreakPriority lastBreakPriority =
|
2016-07-21 13:36:39 +03:00
|
|
|
baseReflowInput.mLineLayout->LastOptionalBreakPriority();
|
2015-03-11 02:28:21 +03:00
|
|
|
if (breakPriority >= lastBreakPriority) {
|
|
|
|
// Either we have been overflow, or we are forced
|
|
|
|
// to break here, do break before.
|
2016-07-21 13:36:39 +03:00
|
|
|
if (istart > baseReflowInput.AvailableISize() ||
|
|
|
|
baseReflowInput.mLineLayout->NotifyOptionalBreakPosition(
|
2015-03-11 02:28:21 +03:00
|
|
|
aColumn.mBaseFrame, 0, true, breakPriority)) {
|
2017-02-14 06:52:53 +03:00
|
|
|
aStatus.SetInlineLineBreakBeforeAndReset();
|
2015-03-11 02:28:21 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-11 02:26:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
const uint32_t rtcCount = aReflowInput.mTextContainers.Length();
|
2014-12-29 07:22:19 +03:00
|
|
|
MOZ_ASSERT(aColumn.mTextFrames.Length() == rtcCount);
|
2016-07-21 13:36:39 +03:00
|
|
|
MOZ_ASSERT(textReflowInputs.Length() == rtcCount);
|
2014-12-29 06:30:00 +03:00
|
|
|
nscoord columnISize = 0;
|
2014-08-15 21:34:20 +04:00
|
|
|
|
2014-12-15 06:37:15 +03:00
|
|
|
nsAutoString baseText;
|
2014-12-29 07:22:19 +03:00
|
|
|
if (aColumn.mBaseFrame) {
|
2015-09-01 02:24:37 +03:00
|
|
|
nsLayoutUtils::GetFrameTextContent(aColumn.mBaseFrame, baseText);
|
2014-12-15 06:37:15 +03:00
|
|
|
}
|
|
|
|
|
2014-11-26 07:52:50 +03:00
|
|
|
// Reflow text frames
|
2014-11-26 07:52:50 +03:00
|
|
|
for (uint32_t i = 0; i < rtcCount; i++) {
|
2015-01-08 10:28:09 +03:00
|
|
|
nsRubyTextFrame* textFrame = aColumn.mTextFrames[i];
|
2014-12-15 06:37:15 +03:00
|
|
|
if (textFrame) {
|
|
|
|
nsAutoString annotationText;
|
2015-09-01 02:24:37 +03:00
|
|
|
nsLayoutUtils::GetFrameTextContent(textFrame, annotationText);
|
2015-05-22 21:16:20 +03:00
|
|
|
|
2014-12-15 06:37:15 +03:00
|
|
|
// 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);
|
|
|
|
} else {
|
|
|
|
textFrame->RemoveStateBits(NS_RUBY_TEXT_FRAME_AUTOHIDE);
|
|
|
|
}
|
2014-12-13 03:05:02 +03:00
|
|
|
RubyUtils::ClearReservedISize(textFrame);
|
2014-11-26 07:52:48 +03:00
|
|
|
|
|
|
|
bool pushedFrame;
|
2015-01-15 12:02:11 +03:00
|
|
|
nsReflowStatus reflowStatus;
|
2016-07-21 13:36:39 +03:00
|
|
|
nsLineLayout* lineLayout = textReflowInputs[i]->mLineLayout;
|
2015-01-15 12:02:11 +03:00
|
|
|
nscoord textIStart = lineLayout->GetCurrentICoord();
|
|
|
|
lineLayout->ReflowFrame(textFrame, reflowStatus, nullptr, pushedFrame);
|
2017-02-14 11:33:37 +03:00
|
|
|
if (MOZ_UNLIKELY(reflowStatus.IsInlineBreak() || pushedFrame)) {
|
2015-03-14 08:29:06 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE(
|
|
|
|
"Any line break inside ruby box should have been suppressed");
|
|
|
|
// For safety, always drain the overflow list, so that
|
|
|
|
// no frames are left there after reflow.
|
|
|
|
textFrame->DrainSelfOverflowList();
|
|
|
|
}
|
2015-01-15 12:02:11 +03:00
|
|
|
nscoord textISize = lineLayout->GetCurrentICoord() - textIStart;
|
|
|
|
columnISize = std::max(columnISize, textISize);
|
2014-08-15 21:34:20 +04:00
|
|
|
}
|
2014-11-26 07:52:50 +03:00
|
|
|
}
|
2014-08-15 21:34:20 +04:00
|
|
|
|
2014-11-26 07:52:50 +03:00
|
|
|
// Reflow the base frame
|
2014-12-29 07:22:19 +03:00
|
|
|
if (aColumn.mBaseFrame) {
|
|
|
|
RubyUtils::ClearReservedISize(aColumn.mBaseFrame);
|
2014-11-26 07:52:50 +03:00
|
|
|
|
|
|
|
bool pushedFrame;
|
2015-01-15 12:02:11 +03:00
|
|
|
nsReflowStatus reflowStatus;
|
2016-07-21 13:36:39 +03:00
|
|
|
nsLineLayout* lineLayout = baseReflowInput.mLineLayout;
|
2015-01-15 12:02:11 +03:00
|
|
|
nscoord baseIStart = lineLayout->GetCurrentICoord();
|
|
|
|
lineLayout->ReflowFrame(aColumn.mBaseFrame, reflowStatus,
|
|
|
|
nullptr, pushedFrame);
|
2017-02-14 11:33:37 +03:00
|
|
|
if (MOZ_UNLIKELY(reflowStatus.IsInlineBreak() || pushedFrame)) {
|
2015-03-14 08:29:06 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE(
|
|
|
|
"Any line break inside ruby box should have been suppressed");
|
|
|
|
// For safety, always drain the overflow list, so that
|
|
|
|
// no frames are left there after reflow.
|
|
|
|
aColumn.mBaseFrame->DrainSelfOverflowList();
|
|
|
|
}
|
2015-01-15 12:02:11 +03:00
|
|
|
nscoord baseISize = lineLayout->GetCurrentICoord() - baseIStart;
|
|
|
|
columnISize = std::max(columnISize, baseISize);
|
2015-02-11 02:26:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Align all the line layout to the new coordinate.
|
2015-03-11 02:28:21 +03:00
|
|
|
nscoord icoord = istart + columnISize;
|
2016-07-21 13:36:39 +03:00
|
|
|
nscoord deltaISize = icoord - baseReflowInput.mLineLayout->GetCurrentICoord();
|
2014-12-13 03:05:02 +03:00
|
|
|
if (deltaISize > 0) {
|
2016-07-21 13:36:39 +03:00
|
|
|
baseReflowInput.mLineLayout->AdvanceICoord(deltaISize);
|
2014-12-29 07:22:19 +03:00
|
|
|
if (aColumn.mBaseFrame) {
|
|
|
|
RubyUtils::SetReservedISize(aColumn.mBaseFrame, deltaISize);
|
2014-12-13 03:05:02 +03:00
|
|
|
}
|
|
|
|
}
|
2014-11-26 07:52:50 +03:00
|
|
|
for (uint32_t i = 0; i < rtcCount; i++) {
|
2016-07-21 13:36:39 +03:00
|
|
|
if (aReflowInput.mTextContainers[i]->IsSpanContainer()) {
|
2014-12-30 01:44:12 +03:00
|
|
|
continue;
|
|
|
|
}
|
2016-07-21 13:36:39 +03:00
|
|
|
nsLineLayout* lineLayout = textReflowInputs[i]->mLineLayout;
|
2015-01-08 10:28:09 +03:00
|
|
|
nsRubyTextFrame* textFrame = aColumn.mTextFrames[i];
|
2014-12-13 03:05:02 +03:00
|
|
|
nscoord deltaISize = icoord - lineLayout->GetCurrentICoord();
|
|
|
|
if (deltaISize > 0) {
|
|
|
|
lineLayout->AdvanceICoord(deltaISize);
|
2015-03-11 02:28:21 +03:00
|
|
|
if (textFrame && !textFrame->IsAutoHidden()) {
|
2014-12-13 03:05:02 +03:00
|
|
|
RubyUtils::SetReservedISize(textFrame, deltaISize);
|
|
|
|
}
|
|
|
|
}
|
2014-12-29 07:22:19 +03:00
|
|
|
if (aColumn.mBaseFrame && textFrame) {
|
2014-12-10 02:04:15 +03:00
|
|
|
lineLayout->AttachLastFrameToBaseLineLayout();
|
|
|
|
}
|
2014-11-26 07:52:50 +03:00
|
|
|
}
|
|
|
|
|
2014-12-29 06:30:00 +03:00
|
|
|
return columnISize;
|
2014-11-26 07:52:50 +03:00
|
|
|
}
|
|
|
|
|
2014-11-26 07:52:50 +03:00
|
|
|
nsRubyBaseContainerFrame::PullFrameState::PullFrameState(
|
2014-12-30 01:56:34 +03:00
|
|
|
nsRubyBaseContainerFrame* aBaseContainer,
|
2015-04-08 02:22:34 +03:00
|
|
|
const AutoRubyTextContainerArray& aTextContainers)
|
2014-12-30 01:56:34 +03:00
|
|
|
: mBase(aBaseContainer)
|
|
|
|
, mTextContainers(aTextContainers)
|
2014-11-26 07:52:50 +03:00
|
|
|
{
|
2014-12-30 01:56:34 +03:00
|
|
|
const uint32_t rtcCount = aTextContainers.Length();
|
2014-11-26 07:52:50 +03:00
|
|
|
for (uint32_t i = 0; i < rtcCount; i++) {
|
2014-12-30 01:56:34 +03:00
|
|
|
mTexts.AppendElement(aTextContainers[i]);
|
2014-11-26 07:52:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-29 06:30:00 +03:00
|
|
|
nsRubyBaseContainerFrame::PullOneColumn(nsLineLayout* aLineLayout,
|
|
|
|
PullFrameState& aPullFrameState,
|
2014-12-29 07:22:19 +03:00
|
|
|
RubyColumn& aColumn,
|
2014-12-29 06:30:00 +03:00
|
|
|
bool& aIsComplete)
|
2014-11-26 07:52:50 +03:00
|
|
|
{
|
2015-04-08 02:22:34 +03:00
|
|
|
const AutoRubyTextContainerArray& textContainers =
|
|
|
|
aPullFrameState.mTextContainers;
|
2014-12-30 01:56:34 +03:00
|
|
|
const uint32_t rtcCount = textContainers.Length();
|
2014-11-26 07:52:50 +03:00
|
|
|
|
2015-01-08 10:28:09 +03:00
|
|
|
nsIFrame* nextBase = GetNextInFlowChild(aPullFrameState.mBase);
|
2015-01-08 10:28:09 +03:00
|
|
|
MOZ_ASSERT(!nextBase || nextBase->GetType() == nsGkAtoms::rubyBaseFrame);
|
|
|
|
aColumn.mBaseFrame = static_cast<nsRubyBaseFrame*>(nextBase);
|
2016-01-27 08:58:53 +03:00
|
|
|
bool foundFrame = !!aColumn.mBaseFrame;
|
2015-01-08 10:28:09 +03:00
|
|
|
bool pullingIntraLevelWhitespace =
|
|
|
|
aColumn.mBaseFrame && aColumn.mBaseFrame->IsIntraLevelWhitespace();
|
2014-11-26 07:52:50 +03:00
|
|
|
|
2014-12-29 07:22:19 +03:00
|
|
|
aColumn.mTextFrames.ClearAndRetainStorage();
|
2014-11-26 07:52:50 +03:00
|
|
|
for (uint32_t i = 0; i < rtcCount; i++) {
|
|
|
|
nsIFrame* nextText =
|
2015-01-08 10:28:09 +03:00
|
|
|
textContainers[i]->GetNextInFlowChild(aPullFrameState.mTexts[i]);
|
2015-01-08 10:28:09 +03:00
|
|
|
MOZ_ASSERT(!nextText || nextText->GetType() == nsGkAtoms::rubyTextFrame);
|
2015-01-08 10:28:09 +03:00
|
|
|
nsRubyTextFrame* textFrame = static_cast<nsRubyTextFrame*>(nextText);
|
|
|
|
aColumn.mTextFrames.AppendElement(textFrame);
|
2016-01-27 08:58:53 +03:00
|
|
|
foundFrame = foundFrame || nextText;
|
2015-01-08 10:28:09 +03:00
|
|
|
if (nextText && !pullingIntraLevelWhitespace) {
|
|
|
|
pullingIntraLevelWhitespace = textFrame->IsIntraLevelWhitespace();
|
|
|
|
}
|
|
|
|
}
|
2016-01-27 08:58:53 +03:00
|
|
|
// If there exists any frame in continations, we haven't
|
|
|
|
// completed the reflow process.
|
|
|
|
aIsComplete = !foundFrame;
|
|
|
|
if (!foundFrame) {
|
|
|
|
return;
|
|
|
|
}
|
2015-01-08 10:28:09 +03:00
|
|
|
|
|
|
|
aColumn.mIsIntraLevelWhitespace = pullingIntraLevelWhitespace;
|
|
|
|
if (pullingIntraLevelWhitespace) {
|
|
|
|
// We are pulling an intra-level whitespace. Drop all frames which
|
|
|
|
// are not part of this intra-level whitespace column. (Those frames
|
|
|
|
// are really part of the *next* column, after the pulled one.)
|
|
|
|
if (aColumn.mBaseFrame && !aColumn.mBaseFrame->IsIntraLevelWhitespace()) {
|
|
|
|
aColumn.mBaseFrame = nullptr;
|
|
|
|
}
|
|
|
|
for (uint32_t i = 0; i < rtcCount; i++) {
|
|
|
|
nsRubyTextFrame*& textFrame = aColumn.mTextFrames[i];
|
|
|
|
if (textFrame && !textFrame->IsIntraLevelWhitespace()) {
|
|
|
|
textFrame = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2016-01-27 08:58:53 +03:00
|
|
|
} else {
|
|
|
|
// We are not pulling an intra-level whitespace, which means all
|
|
|
|
// elements we are going to pull can have non-whitespace content,
|
|
|
|
// which may contain float which we need to reparent.
|
2016-12-01 05:47:26 +03:00
|
|
|
MOZ_ASSERT(aColumn.begin() != aColumn.end(),
|
|
|
|
"Ruby column shouldn't be empty");
|
|
|
|
nsBlockFrame* oldFloatCB =
|
|
|
|
nsLayoutUtils::GetFloatContainingBlock(*aColumn.begin());
|
2016-01-27 08:58:53 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
MOZ_ASSERT(oldFloatCB, "Must have found a float containing block");
|
|
|
|
for (nsIFrame* frame : aColumn) {
|
|
|
|
MOZ_ASSERT(nsLayoutUtils::GetFloatContainingBlock(frame) == oldFloatCB,
|
|
|
|
"All frames in the same ruby column should share "
|
|
|
|
"the same old float containing block");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
nsBlockFrame* newFloatCB =
|
|
|
|
nsLayoutUtils::GetAsBlock(aLineLayout->LineContainerFrame());
|
|
|
|
MOZ_ASSERT(newFloatCB, "Must have a float containing block");
|
|
|
|
if (oldFloatCB != newFloatCB) {
|
|
|
|
for (nsIFrame* frame : aColumn) {
|
|
|
|
newFloatCB->ReparentFloats(frame, oldFloatCB, false);
|
|
|
|
}
|
|
|
|
}
|
2015-01-08 10:28:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pull the frames of this column.
|
|
|
|
if (aColumn.mBaseFrame) {
|
|
|
|
DebugOnly<nsIFrame*> pulled = PullNextInFlowChild(aPullFrameState.mBase);
|
|
|
|
MOZ_ASSERT(pulled == aColumn.mBaseFrame, "pulled a wrong frame?");
|
|
|
|
}
|
|
|
|
for (uint32_t i = 0; i < rtcCount; i++) {
|
|
|
|
if (aColumn.mTextFrames[i]) {
|
|
|
|
DebugOnly<nsIFrame*> pulled =
|
|
|
|
textContainers[i]->PullNextInFlowChild(aPullFrameState.mTexts[i]);
|
|
|
|
MOZ_ASSERT(pulled == aColumn.mTextFrames[i], "pulled a wrong frame?");
|
|
|
|
}
|
2014-11-26 07:52:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!aIsComplete) {
|
|
|
|
// We pulled frames from the next line, hence mark it dirty.
|
|
|
|
aLineLayout->SetDirtyNextLine();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-26 07:52:50 +03:00
|
|
|
nscoord
|
2016-07-21 13:36:39 +03:00
|
|
|
nsRubyBaseContainerFrame::ReflowSpans(const RubyReflowInput& aReflowInput)
|
2014-11-26 07:52:50 +03:00
|
|
|
{
|
2014-11-26 07:52:49 +03:00
|
|
|
nscoord spanISize = 0;
|
2016-07-21 13:36:39 +03:00
|
|
|
for (uint32_t i = 0, iend = aReflowInput.mTextContainers.Length();
|
2014-12-30 01:56:34 +03:00
|
|
|
i < iend; i++) {
|
2016-07-21 13:36:39 +03:00
|
|
|
nsRubyTextContainerFrame* container = aReflowInput.mTextContainers[i];
|
2014-12-30 01:44:12 +03:00
|
|
|
if (!container->IsSpanContainer()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-01-29 17:42:14 +03:00
|
|
|
nsIFrame* rtFrame = container->PrincipalChildList().FirstChild();
|
2014-11-26 07:52:49 +03:00
|
|
|
nsReflowStatus reflowStatus;
|
|
|
|
bool pushedFrame;
|
2016-07-21 13:36:39 +03:00
|
|
|
nsLineLayout* lineLayout = aReflowInput.mTextReflowInputs[i]->mLineLayout;
|
2015-01-15 12:02:11 +03:00
|
|
|
MOZ_ASSERT(lineLayout->GetCurrentICoord() == 0,
|
|
|
|
"border/padding of rtc should have been suppressed");
|
2015-01-15 12:02:11 +03:00
|
|
|
lineLayout->ReflowFrame(rtFrame, reflowStatus, nullptr, pushedFrame);
|
2017-02-14 11:33:37 +03:00
|
|
|
MOZ_ASSERT(!reflowStatus.IsInlineBreak() && !pushedFrame,
|
2014-12-22 08:16:06 +03:00
|
|
|
"Any line break inside ruby box should has been suppressed");
|
2015-01-15 12:02:11 +03:00
|
|
|
spanISize = std::max(spanISize, lineLayout->GetCurrentICoord());
|
2014-11-26 07:52:49 +03:00
|
|
|
}
|
2014-11-26 07:52:50 +03:00
|
|
|
return spanISize;
|
2014-08-15 21:34:20 +04:00
|
|
|
}
|