2014-07-22 19:08:01 -07: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-07 16:22:34 -07:00
|
|
|
#include "nsRubyTextContainerFrame.h"
|
|
|
|
#include "nsRubyBaseFrame.h"
|
|
|
|
#include "nsRubyTextFrame.h"
|
2015-03-26 00:29:31 -07:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
#include "mozilla/Maybe.h"
|
|
|
|
#include "mozilla/WritingModes.h"
|
2014-12-14 19:37:15 -08:00
|
|
|
#include "nsContentUtils.h"
|
2014-08-15 10:34:20 -07:00
|
|
|
#include "nsLineLayout.h"
|
2014-07-22 19:08:01 -07:00
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsStyleContext.h"
|
2014-12-21 21:52:30 -08:00
|
|
|
#include "nsStyleStructInlines.h"
|
2015-02-10 15:26:56 -08:00
|
|
|
#include "nsTextFrame.h"
|
2015-03-26 00:29:31 -07:00
|
|
|
#include "RubyUtils.h"
|
2014-08-15 10:34:20 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2014-07-22 19:08:01 -07: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 10:34:20 -07:00
|
|
|
|
2015-02-21 03:39:33 -08:00
|
|
|
static gfxBreakPriority
|
2015-02-21 03:39:33 -08:00
|
|
|
LineBreakBefore(nsIFrame* aFrame,
|
|
|
|
nsRenderingContext* aRenderingContext,
|
|
|
|
nsIFrame* aLineContainerFrame,
|
|
|
|
const nsLineList::iterator* aLine)
|
2015-02-21 03:39:33 -08:00
|
|
|
{
|
|
|
|
for (nsIFrame* child = aFrame; child;
|
|
|
|
child = child->GetFirstPrincipalChild()) {
|
|
|
|
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 =
|
|
|
|
textFrame->EnsureTextRun(nsTextFrame::eInflated,
|
2015-02-21 03:39:33 -08:00
|
|
|
aRenderingContext->ThebesContext(),
|
|
|
|
aLineContainerFrame, aLine);
|
2015-02-21 03:39:33 -08: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 03:39:33 -08:00
|
|
|
static void
|
|
|
|
GetIsLineBreakAllowed(nsIFrame* aFrame, bool aIsLineBreakable,
|
|
|
|
bool* aAllowInitialLineBreak, bool* aAllowLineBreak)
|
|
|
|
{
|
|
|
|
nsIFrame* parent = aFrame->GetParent();
|
2015-03-10 16:28:21 -07:00
|
|
|
bool lineBreakSuppressed = parent->StyleContext()->ShouldSuppressLineBreak();
|
2015-02-21 03:39:33 -08: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-10 16:28:21 -07:00
|
|
|
bool allowLineBreak = !lineBreakSuppressed &&
|
2015-02-21 03:39:33 -08:00
|
|
|
aFrame->StyleText()->WhiteSpaceCanWrap(aFrame);
|
|
|
|
bool allowInitialLineBreak = allowLineBreak;
|
|
|
|
if (!aFrame->GetPrevInFlow()) {
|
2015-03-10 16:28:21 -07:00
|
|
|
allowInitialLineBreak = !lineBreakSuppressed &&
|
2015-02-21 03:39:33 -08:00
|
|
|
parent->StyleText()->WhiteSpaceCanWrap(parent);
|
|
|
|
}
|
|
|
|
if (!aIsLineBreakable) {
|
|
|
|
allowInitialLineBreak = false;
|
|
|
|
}
|
|
|
|
*aAllowInitialLineBreak = allowInitialLineBreak;
|
|
|
|
*aAllowLineBreak = allowLineBreak;
|
|
|
|
}
|
|
|
|
|
2015-07-08 23:05:26 -07: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-25 20:52:48 -08:00
|
|
|
static nscoord
|
2014-12-28 19:30:00 -08:00
|
|
|
CalculateColumnPrefISize(nsRenderingContext* aRenderingContext,
|
2015-07-08 23:05:26 -07:00
|
|
|
const RubyColumnEnumerator& aEnumerator,
|
|
|
|
nsIFrame::InlineIntrinsicISizeData* aBaseISizeData)
|
2014-11-25 20:52:48 -08:00
|
|
|
{
|
|
|
|
nscoord max = 0;
|
|
|
|
uint32_t levelCount = aEnumerator.GetLevelCount();
|
|
|
|
for (uint32_t i = 0; i < levelCount; i++) {
|
2015-01-07 23:28:09 -08:00
|
|
|
nsIFrame* frame = aEnumerator.GetFrameAtLevel(i);
|
2014-11-25 20:52:48 -08:00
|
|
|
if (frame) {
|
2015-02-21 03:39:33 -08:00
|
|
|
nsIFrame::InlinePrefISizeData data;
|
2015-07-08 23:05:26 -07:00
|
|
|
if (i == 0) {
|
|
|
|
data.lineContainer = aBaseISizeData->lineContainer;
|
|
|
|
data.skipWhitespace = aBaseISizeData->skipWhitespace;
|
|
|
|
data.trailingWhitespace = aBaseISizeData->trailingWhitespace;
|
|
|
|
} else {
|
|
|
|
// The line container of ruby text frames is their parent,
|
|
|
|
// ruby text container frame.
|
|
|
|
data.lineContainer = frame->GetParent();
|
|
|
|
}
|
2015-02-21 03:39:33 -08:00
|
|
|
frame->AddInlinePrefISize(aRenderingContext, &data);
|
|
|
|
MOZ_ASSERT(data.prevLines == 0, "Shouldn't have prev lines");
|
|
|
|
max = std::max(max, data.currentLine);
|
2015-07-08 23:05:26 -07:00
|
|
|
if (i == 0) {
|
|
|
|
aBaseISizeData->skipWhitespace = data.skipWhitespace;
|
|
|
|
aBaseISizeData->trailingWhitespace = data.trailingWhitespace;
|
|
|
|
}
|
2014-11-25 20:52:48 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
2015-02-21 03:39:33 -08: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-25 20:52:48 -08:00
|
|
|
/* virtual */ void
|
|
|
|
nsRubyBaseContainerFrame::AddInlineMinISize(
|
2015-02-21 03:39:33 -08:00
|
|
|
nsRenderingContext *aRenderingContext, nsIFrame::InlineMinISizeData *aData)
|
2014-11-25 20:52:48 -08:00
|
|
|
{
|
2015-04-07 16:22:34 -07:00
|
|
|
AutoRubyTextContainerArray textContainers(this);
|
2014-12-29 14:56:34 -08:00
|
|
|
|
|
|
|
for (uint32_t i = 0, iend = textContainers.Length(); i < iend; i++) {
|
|
|
|
if (textContainers[i]->IsSpanContainer()) {
|
2014-12-29 14:44:12 -08:00
|
|
|
// Since spans are not breakable internally, use our pref isize
|
|
|
|
// directly if there is any span.
|
2015-02-21 03:39:33 -08:00
|
|
|
nsIFrame::InlinePrefISizeData data;
|
2015-07-08 23:05:26 -07:00
|
|
|
data.lineContainer = aData->lineContainer;
|
|
|
|
data.skipWhitespace = aData->skipWhitespace;
|
|
|
|
data.trailingWhitespace = aData->trailingWhitespace;
|
2015-02-21 03:39:33 -08:00
|
|
|
AddInlinePrefISize(aRenderingContext, &data);
|
|
|
|
aData->currentLine += data.currentLine;
|
|
|
|
if (data.currentLine > 0) {
|
|
|
|
aData->atStartOfLine = false;
|
|
|
|
}
|
2015-07-08 23:05:26 -07:00
|
|
|
aData->skipWhitespace = data.skipWhitespace;
|
|
|
|
aData->trailingWhitespace = data.trailingWhitespace;
|
2014-12-29 14:44:12 -08:00
|
|
|
return;
|
|
|
|
}
|
2014-11-25 20:52:48 -08:00
|
|
|
}
|
|
|
|
|
2015-02-21 03:39:33 -08:00
|
|
|
bool firstFrame = true;
|
|
|
|
bool allowInitialLineBreak, allowLineBreak;
|
|
|
|
GetIsLineBreakAllowed(this, !aData->atStartOfLine,
|
|
|
|
&allowInitialLineBreak, &allowLineBreak);
|
2015-02-21 03:39:33 -08:00
|
|
|
for (nsIFrame* frame = this; frame; frame = frame->GetNextInFlow()) {
|
|
|
|
RubyColumnEnumerator enumerator(
|
|
|
|
static_cast<nsRubyBaseContainerFrame*>(frame), textContainers);
|
|
|
|
for (; !enumerator.AtEnd(); enumerator.Next()) {
|
2015-02-21 03:39:33 -08:00
|
|
|
if (firstFrame ? allowInitialLineBreak : allowLineBreak) {
|
|
|
|
nsIFrame* baseFrame = enumerator.GetFrameAtLevel(0);
|
|
|
|
if (baseFrame) {
|
|
|
|
gfxBreakPriority breakPriority =
|
|
|
|
LineBreakBefore(baseFrame, aRenderingContext, nullptr, nullptr);
|
|
|
|
if (breakPriority != gfxBreakPriority::eNoBreak) {
|
|
|
|
aData->OptionallyBreak(aRenderingContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
firstFrame = false;
|
2015-07-08 23:05:26 -07:00
|
|
|
nscoord isize = CalculateColumnPrefISize(aRenderingContext,
|
|
|
|
enumerator, aData);
|
2015-02-21 03:39:33 -08:00
|
|
|
aData->currentLine += isize;
|
|
|
|
if (isize > 0) {
|
|
|
|
aData->atStartOfLine = false;
|
|
|
|
}
|
|
|
|
}
|
2014-11-25 20:52:48 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
nsRubyBaseContainerFrame::AddInlinePrefISize(
|
2015-02-21 03:39:33 -08:00
|
|
|
nsRenderingContext *aRenderingContext, nsIFrame::InlinePrefISizeData *aData)
|
2014-11-25 20:52:48 -08:00
|
|
|
{
|
2015-04-07 16:22:34 -07:00
|
|
|
AutoRubyTextContainerArray textContainers(this);
|
2014-12-29 14:56:34 -08:00
|
|
|
|
2014-11-25 20:52:48 -08:00
|
|
|
nscoord sum = 0;
|
2015-02-21 03:39:33 -08:00
|
|
|
for (nsIFrame* frame = this; frame; frame = frame->GetNextInFlow()) {
|
|
|
|
RubyColumnEnumerator enumerator(
|
|
|
|
static_cast<nsRubyBaseContainerFrame*>(frame), textContainers);
|
|
|
|
for (; !enumerator.AtEnd(); enumerator.Next()) {
|
2015-07-08 23:05:26 -07:00
|
|
|
sum += CalculateColumnPrefISize(aRenderingContext, enumerator, aData);
|
2015-02-21 03:39:33 -08:00
|
|
|
}
|
2014-11-25 20:52:48 -08:00
|
|
|
}
|
2014-12-29 14:56:34 -08:00
|
|
|
for (uint32_t i = 0, iend = textContainers.Length(); i < iend; i++) {
|
|
|
|
if (textContainers[i]->IsSpanContainer()) {
|
|
|
|
nsIFrame* frame = textContainers[i]->GetFirstPrincipalChild();
|
2015-02-21 03:39:33 -08:00
|
|
|
nsIFrame::InlinePrefISizeData data;
|
|
|
|
frame->AddInlinePrefISize(aRenderingContext, &data);
|
|
|
|
MOZ_ASSERT(data.prevLines == 0, "Shouldn't have prev lines");
|
|
|
|
sum = std::max(sum, data.currentLine);
|
2014-12-29 14:44:12 -08:00
|
|
|
}
|
|
|
|
}
|
2014-11-25 20:52:48 -08:00
|
|
|
aData->currentLine += sum;
|
|
|
|
}
|
|
|
|
|
2014-08-15 10:34:20 -07:00
|
|
|
/* virtual */ bool
|
|
|
|
nsRubyBaseContainerFrame::IsFrameOfType(uint32_t aFlags) const
|
|
|
|
{
|
2015-01-15 15:07:50 -08:00
|
|
|
if (aFlags & eSupportsCSSTransforms) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return nsContainerFrame::IsFrameOfType(aFlags &
|
2014-08-15 10:34:20 -07:00
|
|
|
~(nsIFrame::eLineParticipant));
|
|
|
|
}
|
2014-08-15 10:34:20 -07:00
|
|
|
|
2014-08-15 10:34:20 -07:00
|
|
|
/* virtual */ bool
|
|
|
|
nsRubyBaseContainerFrame::CanContinueTextRun() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-25 20:52:49 -08: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-25 20:52:49 -08:00
|
|
|
/* virtual */ nscoord
|
|
|
|
nsRubyBaseContainerFrame::GetLogicalBaseline(WritingMode aWritingMode) const
|
|
|
|
{
|
|
|
|
return mBaseline;
|
|
|
|
}
|
|
|
|
|
2014-12-28 20:03:38 -08:00
|
|
|
struct nsRubyBaseContainerFrame::ReflowState
|
|
|
|
{
|
2015-02-10 15:26:56 -08:00
|
|
|
bool mAllowInitialLineBreak;
|
2014-12-28 20:03:38 -08:00
|
|
|
bool mAllowLineBreak;
|
2015-04-07 16:22:34 -07:00
|
|
|
const AutoRubyTextContainerArray& mTextContainers;
|
2014-12-28 20:03:38 -08:00
|
|
|
const nsHTMLReflowState& mBaseReflowState;
|
2014-12-29 14:44:12 -08:00
|
|
|
const nsTArray<UniquePtr<nsHTMLReflowState>>& mTextReflowStates;
|
2014-12-28 20:03:38 -08:00
|
|
|
};
|
|
|
|
|
2014-08-15 10:34:20 -07:00
|
|
|
/* virtual */ void
|
|
|
|
nsRubyBaseContainerFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2015-03-29 15:38:40 -07:00
|
|
|
MarkInReflow();
|
2014-08-15 10:34:20 -07:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsRubyBaseContainerFrame");
|
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
2014-12-21 21:24:24 -08:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
2014-08-15 10:34:20 -07:00
|
|
|
|
|
|
|
if (!aReflowState.mLineLayout) {
|
|
|
|
NS_ASSERTION(
|
|
|
|
aReflowState.mLineLayout,
|
|
|
|
"No line layout provided to RubyBaseContainerFrame reflow method.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-25 20:52:50 -08:00
|
|
|
MoveOverflowToChildList();
|
|
|
|
// Ask text containers to drain overflows
|
2015-04-07 16:22:34 -07:00
|
|
|
AutoRubyTextContainerArray textContainers(this);
|
2014-12-29 14:56:34 -08:00
|
|
|
const uint32_t rtcCount = textContainers.Length();
|
2014-11-25 20:52:50 -08:00
|
|
|
for (uint32_t i = 0; i < rtcCount; i++) {
|
2014-12-29 14:56:34 -08:00
|
|
|
textContainers[i]->MoveOverflowToChildList();
|
2014-11-25 20:52:50 -08:00
|
|
|
}
|
|
|
|
|
2014-08-15 10:34:20 -07:00
|
|
|
WritingMode lineWM = aReflowState.mLineLayout->GetWritingMode();
|
2015-02-16 14:07:55 -08:00
|
|
|
LogicalSize availSize(lineWM, aReflowState.AvailableISize(),
|
|
|
|
aReflowState.AvailableBSize());
|
2014-08-15 10:34:20 -07:00
|
|
|
|
2014-11-25 20:52:49 -08: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-10 16:24:53 -08: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.
|
2014-11-25 20:52:49 -08:00
|
|
|
nsAutoTArray<UniquePtr<nsHTMLReflowState>, RTC_ARRAY_SIZE> reflowStates;
|
|
|
|
nsAutoTArray<UniquePtr<nsLineLayout>, RTC_ARRAY_SIZE> lineLayouts;
|
2014-12-29 14:44:12 -08:00
|
|
|
reflowStates.SetCapacity(rtcCount);
|
|
|
|
lineLayouts.SetCapacity(rtcCount);
|
2014-11-25 20:52:49 -08:00
|
|
|
|
2014-08-15 10:34:20 -07:00
|
|
|
// Begin the line layout for each ruby text container in advance.
|
2014-12-29 14:44:12 -08:00
|
|
|
bool hasSpan = false;
|
|
|
|
for (uint32_t i = 0; i < rtcCount; i++) {
|
2014-12-29 14:56:34 -08:00
|
|
|
nsRubyTextContainerFrame* textContainer = textContainers[i];
|
2014-12-29 14:44:12 -08:00
|
|
|
if (textContainer->IsSpanContainer()) {
|
|
|
|
hasSpan = true;
|
2014-11-25 20:52:49 -08:00
|
|
|
}
|
2014-12-29 14:44:12 -08:00
|
|
|
|
2014-11-25 20:52:49 -08:00
|
|
|
nsHTMLReflowState* reflowState = new nsHTMLReflowState(
|
2015-04-07 16:22:34 -07:00
|
|
|
aPresContext, *aReflowState.parentReflowState, textContainer,
|
|
|
|
availSize.ConvertTo(textContainer->GetWritingMode(), lineWM));
|
2014-11-25 20:52:49 -08:00
|
|
|
reflowStates.AppendElement(reflowState);
|
2014-12-09 15:04:15 -08:00
|
|
|
nsLineLayout* lineLayout = new nsLineLayout(aPresContext,
|
|
|
|
reflowState->mFloatManager,
|
|
|
|
reflowState, nullptr,
|
|
|
|
aReflowState.mLineLayout);
|
2015-02-17 20:20:02 -08:00
|
|
|
lineLayout->SetSuppressLineWrap(true);
|
2014-11-25 20:52:49 -08:00
|
|
|
lineLayouts.AppendElement(lineLayout);
|
|
|
|
|
|
|
|
// Line number is useless for ruby text
|
|
|
|
// XXX nullptr here may cause problem, see comments for
|
|
|
|
// nsLineLayout::mBlockRS and nsLineLayout::AddFloat
|
|
|
|
lineLayout->Init(nullptr, reflowState->CalcLineHeight(), -1);
|
|
|
|
reflowState->mLineLayout = lineLayout;
|
|
|
|
|
2015-01-15 01:02:11 -08:00
|
|
|
// Border and padding are suppressed on ruby text containers.
|
2015-01-13 01:04:41 -08: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 01:43:03 -08:00
|
|
|
// hence leave container size 0 here for now.
|
2015-01-15 01:02:11 -08:00
|
|
|
lineLayout->BeginLineReflow(0, 0, reflowState->ComputedISize(),
|
2014-11-25 20:52:49 -08:00
|
|
|
NS_UNCONSTRAINEDSIZE,
|
2015-02-11 01:43:03 -08:00
|
|
|
false, false, lineWM, nsSize(0, 0));
|
2014-12-09 15:04:15 -08:00
|
|
|
lineLayout->AttachRootFrameToBaseLineLayout();
|
2014-08-15 10:34:20 -07:00
|
|
|
}
|
|
|
|
|
2014-12-10 20:13:42 -08:00
|
|
|
aReflowState.mLineLayout->BeginSpan(this, &aReflowState,
|
2015-01-15 01:02:11 -08:00
|
|
|
0, aReflowState.AvailableISize(),
|
|
|
|
&mBaseline);
|
2014-12-10 20:13:42 -08:00
|
|
|
|
2015-02-21 03:39:33 -08:00
|
|
|
bool allowInitialLineBreak, allowLineBreak;
|
|
|
|
GetIsLineBreakAllowed(this, aReflowState.mLineLayout->LineIsBreakable(),
|
|
|
|
&allowInitialLineBreak, &allowLineBreak);
|
2014-12-21 21:24:24 -08:00
|
|
|
|
|
|
|
nscoord isize = 0;
|
2015-02-10 15:26:56 -08:00
|
|
|
// Reflow columns excluding any span
|
|
|
|
ReflowState reflowState = {
|
|
|
|
allowInitialLineBreak, allowLineBreak && !hasSpan,
|
|
|
|
textContainers, aReflowState, reflowStates
|
|
|
|
};
|
|
|
|
isize = ReflowColumns(reflowState, aStatus);
|
2015-01-06 17:47:09 -08:00
|
|
|
DebugOnly<nscoord> lineSpanSize = aReflowState.mLineLayout->EndSpan(this);
|
|
|
|
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-30 22:30:29 -07:00
|
|
|
// XXX When bug 765861 gets fixed, this warning should be upgraded.
|
|
|
|
NS_WARN_IF_FALSE(NS_INLINE_IS_BREAK(aStatus) ||
|
|
|
|
isize == lineSpanSize || mFrames.IsEmpty(), "bad isize");
|
2014-11-25 20:52:50 -08:00
|
|
|
|
2014-12-28 19:30:00 -08:00
|
|
|
// If there exists any span, the columns must either be completely
|
2014-11-25 20:52:50 -08:00
|
|
|
// reflowed, or be not reflowed at all.
|
|
|
|
MOZ_ASSERT(NS_INLINE_IS_BREAK_BEFORE(aStatus) ||
|
2014-12-29 14:44:12 -08:00
|
|
|
NS_FRAME_IS_COMPLETE(aStatus) || !hasSpan);
|
2014-11-25 20:52:50 -08:00
|
|
|
if (!NS_INLINE_IS_BREAK_BEFORE(aStatus) &&
|
2014-12-29 14:44:12 -08:00
|
|
|
NS_FRAME_IS_COMPLETE(aStatus) && hasSpan) {
|
2014-11-25 20:52:50 -08:00
|
|
|
// Reflow spans
|
2014-12-28 20:03:38 -08:00
|
|
|
ReflowState reflowState = {
|
2015-02-10 15:26:56 -08:00
|
|
|
false, false, textContainers, aReflowState, reflowStates
|
2014-12-28 20:03:38 -08:00
|
|
|
};
|
|
|
|
nscoord spanISize = ReflowSpans(reflowState);
|
2015-02-10 15:26:56 -08:00
|
|
|
isize = std::max(isize, spanISize);
|
2014-12-29 14:24:57 -08:00
|
|
|
}
|
2014-11-25 20:52:50 -08:00
|
|
|
|
2014-12-29 14:44:12 -08:00
|
|
|
for (uint32_t i = 0; i < rtcCount; i++) {
|
2014-11-25 20:52:50 -08:00
|
|
|
// It happens before the ruby text container is reflowed, and that
|
|
|
|
// when it is reflowed, it will just use this size.
|
2014-12-29 14:56:34 -08:00
|
|
|
nsRubyTextContainerFrame* textContainer = textContainers[i];
|
2014-12-08 22:47:26 -08:00
|
|
|
nsLineLayout* lineLayout = lineLayouts[i].get();
|
2014-12-12 16:05:02 -08:00
|
|
|
|
2014-12-08 22:47:26 -08:00
|
|
|
RubyUtils::ClearReservedISize(textContainer);
|
|
|
|
nscoord rtcISize = lineLayout->GetCurrentICoord();
|
2014-12-12 16:05:02 -08: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-29 14:44:12 -08:00
|
|
|
if (!textContainer->IsSpanContainer()) {
|
2014-12-12 16:05:02 -08:00
|
|
|
rtcISize = isize;
|
|
|
|
} else if (isize > rtcISize) {
|
|
|
|
RubyUtils::SetReservedISize(textContainer, isize - rtcISize);
|
|
|
|
}
|
2014-12-08 22:47:26 -08:00
|
|
|
|
|
|
|
lineLayout->VerticalAlignLine();
|
2015-02-16 17:25:18 -08:00
|
|
|
textContainer->SetISize(rtcISize);
|
2014-12-08 22:47:26 -08:00
|
|
|
lineLayout->EndLineReflow();
|
2014-11-25 20:52:50 -08:00
|
|
|
}
|
|
|
|
|
2015-01-15 01:02:11 -08:00
|
|
|
// Border and padding are suppressed on ruby base container,
|
|
|
|
// create a fake borderPadding for setting BSize.
|
|
|
|
WritingMode frameWM = aReflowState.GetWritingMode();
|
|
|
|
LogicalMargin borderPadding(frameWM);
|
2015-01-15 01:02:11 -08:00
|
|
|
nsLayoutUtils::SetBSizeFromFontMetrics(this, aDesiredSize,
|
2014-11-25 20:52:50 -08:00
|
|
|
borderPadding, lineWM, frameWM);
|
|
|
|
}
|
|
|
|
|
2014-11-25 20:52:50 -08: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;
|
|
|
|
nsAutoTArray<ContinuationTraversingState, RTC_ARRAY_SIZE> mTexts;
|
2015-04-07 16:22:34 -07:00
|
|
|
const AutoRubyTextContainerArray& mTextContainers;
|
2014-11-25 20:52:50 -08:00
|
|
|
|
2014-12-29 14:56:34 -08:00
|
|
|
PullFrameState(nsRubyBaseContainerFrame* aBaseContainer,
|
2015-04-07 16:22:34 -07:00
|
|
|
const AutoRubyTextContainerArray& aTextContainers);
|
2014-11-25 20:52:50 -08:00
|
|
|
};
|
|
|
|
|
2014-11-25 20:52:50 -08:00
|
|
|
nscoord
|
2014-12-28 20:03:38 -08:00
|
|
|
nsRubyBaseContainerFrame::ReflowColumns(const ReflowState& aReflowState,
|
2014-12-28 19:30:00 -08:00
|
|
|
nsReflowStatus& aStatus)
|
2014-11-25 20:52:50 -08:00
|
|
|
{
|
2014-12-28 20:03:38 -08:00
|
|
|
nsLineLayout* lineLayout = aReflowState.mBaseReflowState.mLineLayout;
|
2014-12-29 14:56:34 -08:00
|
|
|
const uint32_t rtcCount = aReflowState.mTextContainers.Length();
|
2015-01-15 01:02:11 -08:00
|
|
|
nscoord icoord = lineLayout->GetCurrentICoord();
|
|
|
|
MOZ_ASSERT(icoord == 0, "border/padding of rbc should have been suppressed");
|
2014-11-25 20:52:50 -08:00
|
|
|
nsReflowStatus reflowStatus = NS_FRAME_COMPLETE;
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
2014-11-25 20:52:49 -08:00
|
|
|
|
2014-12-29 15:05:54 -08:00
|
|
|
uint32_t columnIndex = 0;
|
2014-12-28 20:22:19 -08:00
|
|
|
RubyColumn column;
|
|
|
|
column.mTextFrames.SetCapacity(rtcCount);
|
2014-12-29 14:56:34 -08:00
|
|
|
RubyColumnEnumerator e(this, aReflowState.mTextContainers);
|
2014-11-25 20:52:50 -08:00
|
|
|
for (; !e.AtEnd(); e.Next()) {
|
2014-12-28 20:22:19 -08:00
|
|
|
e.GetColumn(column);
|
2014-12-29 15:05:54 -08:00
|
|
|
icoord += ReflowOneColumn(aReflowState, columnIndex, column, reflowStatus);
|
|
|
|
if (!NS_INLINE_IS_BREAK_BEFORE(reflowStatus)) {
|
|
|
|
columnIndex++;
|
|
|
|
}
|
2014-11-25 20:52:50 -08:00
|
|
|
if (NS_INLINE_IS_BREAK(reflowStatus)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// We are not handling overflow here.
|
|
|
|
MOZ_ASSERT(reflowStatus == NS_FRAME_COMPLETE);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isComplete = false;
|
2014-12-29 14:56:34 -08:00
|
|
|
PullFrameState pullFrameState(this, aReflowState.mTextContainers);
|
2014-11-25 20:52:50 -08:00
|
|
|
while (!NS_INLINE_IS_BREAK(reflowStatus)) {
|
|
|
|
// We are not handling overflow here.
|
|
|
|
MOZ_ASSERT(reflowStatus == NS_FRAME_COMPLETE);
|
|
|
|
|
|
|
|
// Try pull some frames from next continuations. This call replaces
|
2014-12-28 20:22:19 -08:00
|
|
|
// frames in |column| with the frame pulled in each level.
|
|
|
|
PullOneColumn(lineLayout, pullFrameState, column, isComplete);
|
2014-11-25 20:52:50 -08:00
|
|
|
if (isComplete) {
|
|
|
|
// No more frames can be pulled.
|
|
|
|
break;
|
|
|
|
}
|
2014-12-29 15:05:54 -08:00
|
|
|
icoord += ReflowOneColumn(aReflowState, columnIndex, column, reflowStatus);
|
|
|
|
if (!NS_INLINE_IS_BREAK_BEFORE(reflowStatus)) {
|
|
|
|
columnIndex++;
|
|
|
|
}
|
2014-11-25 20:52:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!e.AtEnd() && NS_INLINE_IS_BREAK_AFTER(reflowStatus)) {
|
2014-12-28 19:30:00 -08:00
|
|
|
// The current column has been successfully placed.
|
|
|
|
// Skip to the next column and mark break before.
|
2014-11-25 20:52:50 -08:00
|
|
|
e.Next();
|
2014-12-28 20:22:19 -08:00
|
|
|
e.GetColumn(column);
|
2014-11-25 20:52:50 -08:00
|
|
|
reflowStatus = NS_INLINE_LINE_BREAK_BEFORE();
|
|
|
|
}
|
|
|
|
if (!e.AtEnd() || (GetNextInFlow() && !isComplete)) {
|
|
|
|
NS_FRAME_SET_INCOMPLETE(aStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_INLINE_IS_BREAK_BEFORE(reflowStatus)) {
|
2014-12-29 15:05:54 -08:00
|
|
|
if (!columnIndex || !aReflowState.mAllowLineBreak) {
|
2014-12-28 19:30:00 -08:00
|
|
|
// If no column has been placed yet, or we have any span,
|
2014-11-25 20:52:50 -08:00
|
|
|
// the whole container should be in the next line.
|
|
|
|
aStatus = NS_INLINE_LINE_BREAK_BEFORE();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
aStatus = NS_INLINE_LINE_BREAK_AFTER(aStatus);
|
2014-12-29 14:24:57 -08:00
|
|
|
MOZ_ASSERT(NS_FRAME_IS_COMPLETE(aStatus) || aReflowState.mAllowLineBreak);
|
2014-11-25 20:52:50 -08:00
|
|
|
|
2015-01-07 23:28:09 -08: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-25 20:52:50 -08:00
|
|
|
}
|
|
|
|
for (uint32_t i = 0; i < rtcCount; i++) {
|
2015-01-07 23:28:09 -08:00
|
|
|
nsRubyTextFrame* textFrame = column.mTextFrames[i];
|
2015-01-07 23:28:09 -08:00
|
|
|
if (!textFrame && nextColumn.isSome()) {
|
|
|
|
textFrame = nextColumn->mTextFrames[i];
|
|
|
|
}
|
2014-11-25 20:52:50 -08:00
|
|
|
if (textFrame) {
|
2014-12-29 14:56:34 -08:00
|
|
|
aReflowState.mTextContainers[i]->PushChildren(
|
|
|
|
textFrame, textFrame->GetPrevSibling());
|
2014-11-25 20:52:50 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (NS_INLINE_IS_BREAK_AFTER(reflowStatus)) {
|
|
|
|
// |reflowStatus| being break after here may only happen when
|
2014-12-28 19:30:00 -08:00
|
|
|
// there is a break after the column just pulled, or the whole
|
2014-11-25 20:52:50 -08:00
|
|
|
// segment has been completely reflowed. In those cases, we do
|
|
|
|
// not need to push anything.
|
|
|
|
MOZ_ASSERT(e.AtEnd());
|
|
|
|
aStatus = NS_INLINE_LINE_BREAK_AFTER(aStatus);
|
2014-11-25 20:52:50 -08:00
|
|
|
}
|
|
|
|
|
2015-01-15 01:02:11 -08:00
|
|
|
return icoord;
|
2014-11-25 20:52:50 -08:00
|
|
|
}
|
|
|
|
|
2014-11-25 20:52:50 -08:00
|
|
|
nscoord
|
2014-12-28 20:03:38 -08:00
|
|
|
nsRubyBaseContainerFrame::ReflowOneColumn(const ReflowState& aReflowState,
|
2014-12-29 15:05:54 -08:00
|
|
|
uint32_t aColumnIndex,
|
2014-12-28 20:22:19 -08:00
|
|
|
const RubyColumn& aColumn,
|
2014-12-28 19:30:00 -08:00
|
|
|
nsReflowStatus& aStatus)
|
2014-11-25 20:52:50 -08:00
|
|
|
{
|
2014-12-28 20:03:38 -08:00
|
|
|
const nsHTMLReflowState& baseReflowState = aReflowState.mBaseReflowState;
|
|
|
|
const auto& textReflowStates = aReflowState.mTextReflowStates;
|
2015-03-10 16:28:21 -07:00
|
|
|
nscoord istart = baseReflowState.mLineLayout->GetCurrentICoord();
|
2014-12-28 20:03:38 -08:00
|
|
|
|
2015-02-10 15:26:56 -08:00
|
|
|
if (aColumn.mBaseFrame) {
|
2015-03-10 16:28:21 -07:00
|
|
|
bool allowBreakBefore = aColumnIndex ?
|
|
|
|
aReflowState.mAllowLineBreak : aReflowState.mAllowInitialLineBreak;
|
|
|
|
if (allowBreakBefore) {
|
|
|
|
gfxBreakPriority breakPriority = LineBreakBefore(
|
|
|
|
aColumn.mBaseFrame, baseReflowState.rendContext,
|
|
|
|
baseReflowState.mLineLayout->LineContainerFrame(),
|
|
|
|
baseReflowState.mLineLayout->GetLine());
|
|
|
|
if (breakPriority != gfxBreakPriority::eNoBreak) {
|
2015-03-10 20:14:48 -07:00
|
|
|
gfxBreakPriority lastBreakPriority =
|
|
|
|
baseReflowState.mLineLayout->LastOptionalBreakPriority();
|
2015-03-10 16:28:21 -07:00
|
|
|
if (breakPriority >= lastBreakPriority) {
|
|
|
|
// Either we have been overflow, or we are forced
|
|
|
|
// to break here, do break before.
|
|
|
|
if (istart > baseReflowState.AvailableISize() ||
|
|
|
|
baseReflowState.mLineLayout->NotifyOptionalBreakPosition(
|
|
|
|
aColumn.mBaseFrame, 0, true, breakPriority)) {
|
|
|
|
aStatus = NS_INLINE_LINE_BREAK_BEFORE();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-10 15:26:56 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-29 14:56:34 -08:00
|
|
|
const uint32_t rtcCount = aReflowState.mTextContainers.Length();
|
2014-12-28 20:22:19 -08:00
|
|
|
MOZ_ASSERT(aColumn.mTextFrames.Length() == rtcCount);
|
2014-12-28 20:03:38 -08:00
|
|
|
MOZ_ASSERT(textReflowStates.Length() == rtcCount);
|
2014-12-28 19:30:00 -08:00
|
|
|
nscoord columnISize = 0;
|
2014-08-15 10:34:20 -07:00
|
|
|
|
2014-12-14 19:37:15 -08:00
|
|
|
nsAutoString baseText;
|
2014-12-28 20:22:19 -08:00
|
|
|
if (aColumn.mBaseFrame) {
|
2015-05-22 11:16:20 -07:00
|
|
|
nsContentUtils::GetNodeTextContent(aColumn.mBaseFrame->GetContent(),
|
|
|
|
true, baseText);
|
2014-12-14 19:37:15 -08:00
|
|
|
}
|
|
|
|
|
2014-11-25 20:52:50 -08:00
|
|
|
// Reflow text frames
|
2014-11-25 20:52:50 -08:00
|
|
|
for (uint32_t i = 0; i < rtcCount; i++) {
|
2015-01-07 23:28:09 -08:00
|
|
|
nsRubyTextFrame* textFrame = aColumn.mTextFrames[i];
|
2014-12-14 19:37:15 -08:00
|
|
|
if (textFrame) {
|
|
|
|
nsAutoString annotationText;
|
2015-05-22 11:16:20 -07:00
|
|
|
nsContentUtils::GetNodeTextContent(textFrame->GetContent(),
|
|
|
|
true, annotationText);
|
|
|
|
|
2014-12-14 19:37:15 -08: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-12 16:05:02 -08:00
|
|
|
RubyUtils::ClearReservedISize(textFrame);
|
2014-11-25 20:52:48 -08:00
|
|
|
|
|
|
|
bool pushedFrame;
|
2015-01-15 01:02:11 -08:00
|
|
|
nsReflowStatus reflowStatus;
|
|
|
|
nsLineLayout* lineLayout = textReflowStates[i]->mLineLayout;
|
|
|
|
nscoord textIStart = lineLayout->GetCurrentICoord();
|
|
|
|
lineLayout->ReflowFrame(textFrame, reflowStatus, nullptr, pushedFrame);
|
2015-03-13 22:29:06 -07:00
|
|
|
if (MOZ_UNLIKELY(NS_INLINE_IS_BREAK(reflowStatus) || pushedFrame)) {
|
|
|
|
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 01:02:11 -08:00
|
|
|
nscoord textISize = lineLayout->GetCurrentICoord() - textIStart;
|
|
|
|
columnISize = std::max(columnISize, textISize);
|
2014-08-15 10:34:20 -07:00
|
|
|
}
|
2014-11-25 20:52:50 -08:00
|
|
|
}
|
2014-08-15 10:34:20 -07:00
|
|
|
|
2014-11-25 20:52:50 -08:00
|
|
|
// Reflow the base frame
|
2014-12-28 20:22:19 -08:00
|
|
|
if (aColumn.mBaseFrame) {
|
|
|
|
RubyUtils::ClearReservedISize(aColumn.mBaseFrame);
|
2014-11-25 20:52:50 -08:00
|
|
|
|
|
|
|
bool pushedFrame;
|
2015-01-15 01:02:11 -08:00
|
|
|
nsReflowStatus reflowStatus;
|
|
|
|
nsLineLayout* lineLayout = baseReflowState.mLineLayout;
|
|
|
|
nscoord baseIStart = lineLayout->GetCurrentICoord();
|
|
|
|
lineLayout->ReflowFrame(aColumn.mBaseFrame, reflowStatus,
|
|
|
|
nullptr, pushedFrame);
|
2015-03-13 22:29:06 -07:00
|
|
|
if (MOZ_UNLIKELY(NS_INLINE_IS_BREAK(reflowStatus) || pushedFrame)) {
|
|
|
|
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 01:02:11 -08:00
|
|
|
nscoord baseISize = lineLayout->GetCurrentICoord() - baseIStart;
|
|
|
|
columnISize = std::max(columnISize, baseISize);
|
2015-02-10 15:26:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Align all the line layout to the new coordinate.
|
2015-03-10 16:28:21 -07:00
|
|
|
nscoord icoord = istart + columnISize;
|
2014-12-28 20:03:38 -08:00
|
|
|
nscoord deltaISize = icoord - baseReflowState.mLineLayout->GetCurrentICoord();
|
2014-12-12 16:05:02 -08:00
|
|
|
if (deltaISize > 0) {
|
2014-12-28 20:03:38 -08:00
|
|
|
baseReflowState.mLineLayout->AdvanceICoord(deltaISize);
|
2014-12-28 20:22:19 -08:00
|
|
|
if (aColumn.mBaseFrame) {
|
|
|
|
RubyUtils::SetReservedISize(aColumn.mBaseFrame, deltaISize);
|
2014-12-12 16:05:02 -08:00
|
|
|
}
|
|
|
|
}
|
2014-11-25 20:52:50 -08:00
|
|
|
for (uint32_t i = 0; i < rtcCount; i++) {
|
2014-12-29 14:56:34 -08:00
|
|
|
if (aReflowState.mTextContainers[i]->IsSpanContainer()) {
|
2014-12-29 14:44:12 -08:00
|
|
|
continue;
|
|
|
|
}
|
2014-12-28 20:03:38 -08:00
|
|
|
nsLineLayout* lineLayout = textReflowStates[i]->mLineLayout;
|
2015-01-07 23:28:09 -08:00
|
|
|
nsRubyTextFrame* textFrame = aColumn.mTextFrames[i];
|
2014-12-12 16:05:02 -08:00
|
|
|
nscoord deltaISize = icoord - lineLayout->GetCurrentICoord();
|
|
|
|
if (deltaISize > 0) {
|
|
|
|
lineLayout->AdvanceICoord(deltaISize);
|
2015-03-10 16:28:21 -07:00
|
|
|
if (textFrame && !textFrame->IsAutoHidden()) {
|
2014-12-12 16:05:02 -08:00
|
|
|
RubyUtils::SetReservedISize(textFrame, deltaISize);
|
|
|
|
}
|
|
|
|
}
|
2014-12-28 20:22:19 -08:00
|
|
|
if (aColumn.mBaseFrame && textFrame) {
|
2014-12-09 15:04:15 -08:00
|
|
|
lineLayout->AttachLastFrameToBaseLineLayout();
|
|
|
|
}
|
2014-11-25 20:52:50 -08:00
|
|
|
}
|
|
|
|
|
2014-12-28 19:30:00 -08:00
|
|
|
return columnISize;
|
2014-11-25 20:52:50 -08:00
|
|
|
}
|
|
|
|
|
2014-11-25 20:52:50 -08:00
|
|
|
nsRubyBaseContainerFrame::PullFrameState::PullFrameState(
|
2014-12-29 14:56:34 -08:00
|
|
|
nsRubyBaseContainerFrame* aBaseContainer,
|
2015-04-07 16:22:34 -07:00
|
|
|
const AutoRubyTextContainerArray& aTextContainers)
|
2014-12-29 14:56:34 -08:00
|
|
|
: mBase(aBaseContainer)
|
|
|
|
, mTextContainers(aTextContainers)
|
2014-11-25 20:52:50 -08:00
|
|
|
{
|
2014-12-29 14:56:34 -08:00
|
|
|
const uint32_t rtcCount = aTextContainers.Length();
|
2014-11-25 20:52:50 -08:00
|
|
|
for (uint32_t i = 0; i < rtcCount; i++) {
|
2014-12-29 14:56:34 -08:00
|
|
|
mTexts.AppendElement(aTextContainers[i]);
|
2014-11-25 20:52:50 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-28 19:30:00 -08:00
|
|
|
nsRubyBaseContainerFrame::PullOneColumn(nsLineLayout* aLineLayout,
|
|
|
|
PullFrameState& aPullFrameState,
|
2014-12-28 20:22:19 -08:00
|
|
|
RubyColumn& aColumn,
|
2014-12-28 19:30:00 -08:00
|
|
|
bool& aIsComplete)
|
2014-11-25 20:52:50 -08:00
|
|
|
{
|
2015-04-07 16:22:34 -07:00
|
|
|
const AutoRubyTextContainerArray& textContainers =
|
|
|
|
aPullFrameState.mTextContainers;
|
2014-12-29 14:56:34 -08:00
|
|
|
const uint32_t rtcCount = textContainers.Length();
|
2014-11-25 20:52:50 -08:00
|
|
|
|
2015-01-07 23:28:09 -08:00
|
|
|
nsIFrame* nextBase = GetNextInFlowChild(aPullFrameState.mBase);
|
2015-01-07 23:28:09 -08:00
|
|
|
MOZ_ASSERT(!nextBase || nextBase->GetType() == nsGkAtoms::rubyBaseFrame);
|
|
|
|
aColumn.mBaseFrame = static_cast<nsRubyBaseFrame*>(nextBase);
|
2014-12-28 20:22:19 -08:00
|
|
|
aIsComplete = !aColumn.mBaseFrame;
|
2015-01-07 23:28:09 -08:00
|
|
|
bool pullingIntraLevelWhitespace =
|
|
|
|
aColumn.mBaseFrame && aColumn.mBaseFrame->IsIntraLevelWhitespace();
|
2014-11-25 20:52:50 -08:00
|
|
|
|
2014-12-28 20:22:19 -08:00
|
|
|
aColumn.mTextFrames.ClearAndRetainStorage();
|
2014-11-25 20:52:50 -08:00
|
|
|
for (uint32_t i = 0; i < rtcCount; i++) {
|
|
|
|
nsIFrame* nextText =
|
2015-01-07 23:28:09 -08:00
|
|
|
textContainers[i]->GetNextInFlowChild(aPullFrameState.mTexts[i]);
|
2015-01-07 23:28:09 -08:00
|
|
|
MOZ_ASSERT(!nextText || nextText->GetType() == nsGkAtoms::rubyTextFrame);
|
2015-01-07 23:28:09 -08:00
|
|
|
nsRubyTextFrame* textFrame = static_cast<nsRubyTextFrame*>(nextText);
|
|
|
|
aColumn.mTextFrames.AppendElement(textFrame);
|
2014-11-25 20:52:50 -08:00
|
|
|
// If there exists any frame in continations, we haven't
|
|
|
|
// completed the reflow process.
|
|
|
|
aIsComplete = aIsComplete && !nextText;
|
2015-01-07 23:28:09 -08:00
|
|
|
if (nextText && !pullingIntraLevelWhitespace) {
|
|
|
|
pullingIntraLevelWhitespace = textFrame->IsIntraLevelWhitespace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-25 20:52:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!aIsComplete) {
|
|
|
|
// We pulled frames from the next line, hence mark it dirty.
|
|
|
|
aLineLayout->SetDirtyNextLine();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-25 20:52:50 -08:00
|
|
|
nscoord
|
2014-12-28 20:03:38 -08:00
|
|
|
nsRubyBaseContainerFrame::ReflowSpans(const ReflowState& aReflowState)
|
2014-11-25 20:52:50 -08:00
|
|
|
{
|
2014-11-25 20:52:49 -08:00
|
|
|
nscoord spanISize = 0;
|
2014-12-29 14:56:34 -08:00
|
|
|
for (uint32_t i = 0, iend = aReflowState.mTextContainers.Length();
|
|
|
|
i < iend; i++) {
|
|
|
|
nsRubyTextContainerFrame* container = aReflowState.mTextContainers[i];
|
2014-12-29 14:44:12 -08:00
|
|
|
if (!container->IsSpanContainer()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-11-25 20:52:49 -08:00
|
|
|
nsIFrame* rtFrame = container->GetFirstPrincipalChild();
|
|
|
|
nsReflowStatus reflowStatus;
|
|
|
|
bool pushedFrame;
|
2015-01-15 01:02:11 -08:00
|
|
|
nsLineLayout* lineLayout = aReflowState.mTextReflowStates[i]->mLineLayout;
|
2015-01-15 01:02:11 -08:00
|
|
|
MOZ_ASSERT(lineLayout->GetCurrentICoord() == 0,
|
|
|
|
"border/padding of rtc should have been suppressed");
|
2015-01-15 01:02:11 -08:00
|
|
|
lineLayout->ReflowFrame(rtFrame, reflowStatus, nullptr, pushedFrame);
|
2014-12-21 21:16:06 -08:00
|
|
|
MOZ_ASSERT(!NS_INLINE_IS_BREAK(reflowStatus) && !pushedFrame,
|
|
|
|
"Any line break inside ruby box should has been suppressed");
|
2015-01-15 01:02:11 -08:00
|
|
|
spanISize = std::max(spanISize, lineLayout->GetCurrentICoord());
|
2014-11-25 20:52:49 -08:00
|
|
|
}
|
2014-11-25 20:52:50 -08:00
|
|
|
return spanISize;
|
2014-08-15 10:34:20 -07:00
|
|
|
}
|