To account for spacing between bases or text boxes during reflow, the line layout which manages the bases updates its inline direction coordinate based on the preferred inline size for the corresponding text boxes. Next, the base is reflowed at the correct inline coordinate. Each paired text box is then also reflowed at the proper inline position determined by (1) the current position of its corresponding base and (2) its own preferred width. In computing intrinsic widths, accounting for spacing is less complicated. The minimum intrinsic width is the width of the widest ruby column, and the preferred intrinsic width is the sum of all the ruby column widths. Each ruby column width is the maximum width of its base box and text boxes. These individual widths are determined using GetPrefISize on the base and text boxes. Ruby base container frames store a list of pointers to the ruby text container frames in the segment they denote. This list of pointers is created in the ruby frame reflow method before calling the reflow method for the ruby base container. The list exists and is used only during reflow of the main ruby frame and is cleared before returning from reflow.
149 lines
4.7 KiB
C++
149 lines
4.7 KiB
C++
/* -*- 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" */
|
|
|
|
#include "nsRubyBaseFrame.h"
|
|
#include "nsLineLayout.h"
|
|
#include "nsPresContext.h"
|
|
#include "nsStyleContext.h"
|
|
#include "WritingModes.h"
|
|
|
|
using namespace mozilla;
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Frame class boilerplate
|
|
// =======================
|
|
|
|
NS_QUERYFRAME_HEAD(nsRubyBaseFrame)
|
|
NS_QUERYFRAME_ENTRY(nsRubyBaseFrame)
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsRubyBaseFrame)
|
|
|
|
nsContainerFrame*
|
|
NS_NewRubyBaseFrame(nsIPresShell* aPresShell,
|
|
nsStyleContext* aContext)
|
|
{
|
|
return new (aPresShell) nsRubyBaseFrame(aContext);
|
|
}
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsRubyBaseFrame Method Implementations
|
|
// ======================================
|
|
|
|
nsIAtom*
|
|
nsRubyBaseFrame::GetType() const
|
|
{
|
|
return nsGkAtoms::rubyBaseFrame;
|
|
}
|
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
|
nsresult
|
|
nsRubyBaseFrame::GetFrameName(nsAString& aResult) const
|
|
{
|
|
return MakeFrameName(NS_LITERAL_STRING("RubyBase"), aResult);
|
|
}
|
|
#endif
|
|
|
|
nscoord
|
|
nsRubyBaseFrame::GetMinISize(nsRenderingContext *aRenderingContext)
|
|
{
|
|
return nsLayoutUtils::MinISizeFromInline(this, aRenderingContext);
|
|
}
|
|
|
|
nscoord
|
|
nsRubyBaseFrame::GetPrefISize(nsRenderingContext *aRenderingContext)
|
|
{
|
|
return nsLayoutUtils::PrefISizeFromInline(this, aRenderingContext);
|
|
}
|
|
|
|
/* virtual */ void
|
|
nsRubyBaseFrame::AddInlineMinISize(nsRenderingContext *aRenderingContext,
|
|
nsIFrame::InlineMinISizeData *aData)
|
|
{
|
|
for (nsFrameList::Enumerator e(PrincipalChildList()); !e.AtEnd(); e.Next()) {
|
|
e.get()->AddInlineMinISize(aRenderingContext, aData);
|
|
}
|
|
}
|
|
|
|
/* virtual */ void
|
|
nsRubyBaseFrame::AddInlinePrefISize(nsRenderingContext *aRenderingContext,
|
|
nsIFrame::InlinePrefISizeData *aData)
|
|
{
|
|
for (nsFrameList::Enumerator e(PrincipalChildList()); !e.AtEnd(); e.Next()) {
|
|
e.get()->AddInlinePrefISize(aRenderingContext, aData);
|
|
}
|
|
}
|
|
|
|
/* virtual */ bool
|
|
nsRubyBaseFrame::IsFrameOfType(uint32_t aFlags) const
|
|
{
|
|
return nsContainerFrame::IsFrameOfType(aFlags &
|
|
~(nsIFrame::eLineParticipant));
|
|
}
|
|
|
|
/* virtual */ nscoord
|
|
nsRubyBaseFrame::GetLogicalBaseline(WritingMode aWritingMode) const
|
|
{
|
|
return mBaseline;
|
|
}
|
|
|
|
/* virtual */ void
|
|
nsRubyBaseFrame::Reflow(nsPresContext* aPresContext,
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
const nsHTMLReflowState& aReflowState,
|
|
nsReflowStatus& aStatus)
|
|
{
|
|
DO_GLOBAL_REFLOW_COUNT("nsRubyBaseFrame");
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
|
|
|
if (!aReflowState.mLineLayout) {
|
|
NS_ASSERTION(aReflowState.mLineLayout,
|
|
"No line layout provided to RubyBaseFrame reflow method.");
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
return;
|
|
}
|
|
|
|
WritingMode lineWM = aReflowState.mLineLayout->GetWritingMode();
|
|
WritingMode frameWM = aReflowState.GetWritingMode();
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
LogicalSize availSize(lineWM, aReflowState.AvailableWidth(),
|
|
aReflowState.AvailableHeight());
|
|
LogicalMargin borderPadding = aReflowState.ComputedLogicalBorderPadding();
|
|
|
|
// Begin the span for the ruby base frame
|
|
nscoord availableISize = aReflowState.AvailableISize();
|
|
NS_ASSERTION(availableISize != NS_UNCONSTRAINEDSIZE,
|
|
"should no longer use available widths");
|
|
// Subtract off inline axis border+padding from availableISize
|
|
availableISize -= borderPadding.IStartEnd(frameWM);
|
|
aReflowState.mLineLayout->BeginSpan(this, &aReflowState,
|
|
borderPadding.IStart(frameWM),
|
|
availableISize, &mBaseline);
|
|
|
|
for (nsFrameList::Enumerator e(mFrames); !e.AtEnd(); e.Next()) {
|
|
nsReflowStatus frameReflowStatus;
|
|
nsHTMLReflowMetrics metrics(aReflowState, aDesiredSize.mFlags);
|
|
|
|
bool pushedFrame;
|
|
aReflowState.mLineLayout->ReflowFrame(e.get(), frameReflowStatus,
|
|
&metrics, pushedFrame);
|
|
NS_ASSERTION(!pushedFrame,
|
|
"Ruby line breaking is not yet implemented");
|
|
|
|
e.get()->SetSize(LogicalSize(lineWM, metrics.ISize(lineWM),
|
|
metrics.BSize(lineWM)));
|
|
}
|
|
|
|
aDesiredSize.ISize(lineWM) = aReflowState.mLineLayout->EndSpan(this);
|
|
nsLayoutUtils::SetBSizeFromFontMetrics(this, aDesiredSize, aReflowState,
|
|
borderPadding, lineWM, frameWM);
|
|
}
|