2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2017-10-27 20:09:35 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2014-07-23 06:08:01 +04:00
|
|
|
|
|
|
|
/* rendering object for CSS "display: ruby" */
|
2015-03-26 10:29:31 +03:00
|
|
|
|
2014-07-23 06:08:01 +04:00
|
|
|
#include "nsRubyFrame.h"
|
2015-03-26 10:29:31 +03:00
|
|
|
|
|
|
|
#include "RubyUtils.h"
|
2018-03-22 21:20:41 +03:00
|
|
|
#include "mozilla/ComputedStyle.h"
|
2015-03-26 10:29:31 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2019-04-16 10:24:49 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2019-08-14 01:52:38 +03:00
|
|
|
#include "mozilla/StaticPrefs_layout.h"
|
2015-03-26 10:29:31 +03:00
|
|
|
#include "mozilla/WritingModes.h"
|
2014-08-15 21:34:20 +04:00
|
|
|
#include "nsLineLayout.h"
|
2014-07-23 06:08:01 +04:00
|
|
|
#include "nsPresContext.h"
|
2021-03-23 13:26:17 +03:00
|
|
|
#include "nsContainerFrameInlines.h"
|
2014-08-15 21:34:20 +04:00
|
|
|
#include "nsRubyBaseContainerFrame.h"
|
|
|
|
#include "nsRubyTextContainerFrame.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2014-07-23 06:08:01 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Frame class boilerplate
|
|
|
|
// =======================
|
|
|
|
|
|
|
|
NS_QUERYFRAME_HEAD(nsRubyFrame)
|
2018-12-07 23:00:18 +03:00
|
|
|
NS_QUERYFRAME_ENTRY(nsRubyFrame)
|
2016-04-18 09:11:08 +03:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsInlineFrame)
|
2014-07-23 06:08:01 +04:00
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsRubyFrame)
|
|
|
|
|
2019-04-16 10:24:49 +03:00
|
|
|
nsContainerFrame* NS_NewRubyFrame(PresShell* aPresShell,
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle* aStyle) {
|
2019-02-05 19:45:54 +03:00
|
|
|
return new (aPresShell) nsRubyFrame(aStyle, aPresShell->GetPresContext());
|
2014-07-23 06:08:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// nsRubyFrame Method Implementations
|
|
|
|
// ==================================
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* virtual */
|
|
|
|
bool nsRubyFrame::IsFrameOfType(uint32_t aFlags) const {
|
2015-01-15 12:02:11 +03:00
|
|
|
if (aFlags & eBidiInlineContainer) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-18 09:11:08 +03:00
|
|
|
return nsInlineFrame::IsFrameOfType(aFlags);
|
2014-07-23 06:08:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
|
|
|
nsresult nsRubyFrame::GetFrameName(nsAString& aResult) const {
|
|
|
|
return MakeFrameName(u"Ruby"_ns, aResult);
|
|
|
|
}
|
|
|
|
#endif
|
2014-08-15 21:34:20 +04:00
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* virtual */
|
|
|
|
void nsRubyFrame::AddInlineMinISize(gfxContext* aRenderingContext,
|
|
|
|
nsIFrame::InlineMinISizeData* aData) {
|
2021-03-23 13:26:17 +03:00
|
|
|
auto handleChildren = [aRenderingContext](auto frame, auto data) {
|
2015-04-08 02:22:34 +03:00
|
|
|
for (RubySegmentEnumerator e(static_cast<nsRubyFrame*>(frame)); !e.AtEnd();
|
2015-02-21 14:39:33 +03:00
|
|
|
e.Next()) {
|
2021-03-23 13:26:17 +03:00
|
|
|
e.GetBaseContainer()->AddInlineMinISize(aRenderingContext, data);
|
2015-02-21 14:39:33 +03:00
|
|
|
}
|
2021-03-23 13:26:17 +03:00
|
|
|
};
|
|
|
|
DoInlineIntrinsicISize(aData, handleChildren);
|
2014-08-15 21:34:20 +04:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* virtual */
|
|
|
|
void nsRubyFrame::AddInlinePrefISize(gfxContext* aRenderingContext,
|
|
|
|
nsIFrame::InlinePrefISizeData* aData) {
|
2021-03-23 13:26:17 +03:00
|
|
|
auto handleChildren = [aRenderingContext](auto frame, auto data) {
|
2015-04-08 02:22:34 +03:00
|
|
|
for (RubySegmentEnumerator e(static_cast<nsRubyFrame*>(frame)); !e.AtEnd();
|
2015-02-21 14:39:33 +03:00
|
|
|
e.Next()) {
|
2021-03-23 13:26:17 +03:00
|
|
|
e.GetBaseContainer()->AddInlinePrefISize(aRenderingContext, data);
|
2015-02-21 14:39:33 +03:00
|
|
|
}
|
2021-03-23 13:26:17 +03:00
|
|
|
};
|
|
|
|
DoInlineIntrinsicISize(aData, handleChildren);
|
2016-08-23 02:29:45 +03:00
|
|
|
aData->mLineIsEmpty = false;
|
2014-08-15 21:34:20 +04:00
|
|
|
}
|
|
|
|
|
2016-10-26 09:40:58 +03:00
|
|
|
static nsRubyBaseContainerFrame* FindRubyBaseContainerAncestor(
|
|
|
|
nsIFrame* aFrame) {
|
|
|
|
for (nsIFrame* ancestor = aFrame->GetParent();
|
|
|
|
ancestor && ancestor->IsFrameOfType(nsIFrame::eLineParticipant);
|
|
|
|
ancestor = ancestor->GetParent()) {
|
2017-04-30 18:30:08 +03:00
|
|
|
if (ancestor->IsRubyBaseContainerFrame()) {
|
2016-10-26 09:40:58 +03:00
|
|
|
return static_cast<nsRubyBaseContainerFrame*>(ancestor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* virtual */
|
|
|
|
void nsRubyFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
ReflowOutput& aDesiredSize,
|
|
|
|
const ReflowInput& aReflowInput,
|
|
|
|
nsReflowStatus& aStatus) {
|
2015-03-30 01:38:40 +03:00
|
|
|
MarkInReflow();
|
2014-08-15 21:34:20 +04:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsRubyFrame");
|
2016-07-21 13:36:39 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus);
|
2017-09-13 13:00:25 +03:00
|
|
|
MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!");
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
if (!aReflowInput.mLineLayout) {
|
|
|
|
NS_ASSERTION(aReflowInput.mLineLayout,
|
2014-08-15 21:34:20 +04:00
|
|
|
"No line layout provided to RubyFrame reflow method.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-26 07:52:50 +03:00
|
|
|
// Grab overflow frames from prev-in-flow and its own.
|
2017-10-03 08:19:41 +03:00
|
|
|
MoveInlineOverflowToChildList(aReflowInput.mLineLayout->LineContainerFrame());
|
2014-11-26 07:52:50 +03:00
|
|
|
|
2015-12-04 05:08:17 +03:00
|
|
|
// Clear leadings
|
2016-11-10 03:10:42 +03:00
|
|
|
mLeadings.Reset();
|
2015-12-04 05:08:17 +03:00
|
|
|
|
2014-08-15 21:34:20 +04:00
|
|
|
// Begin the span for the ruby frame
|
2016-07-21 13:36:39 +03:00
|
|
|
WritingMode frameWM = aReflowInput.GetWritingMode();
|
|
|
|
WritingMode lineWM = aReflowInput.mLineLayout->GetWritingMode();
|
2020-11-03 22:57:40 +03:00
|
|
|
LogicalMargin borderPadding =
|
|
|
|
aReflowInput.ComputedLogicalBorderPadding(frameWM);
|
2019-09-02 13:09:30 +03:00
|
|
|
nsLayoutUtils::SetBSizeFromFontMetrics(this, aDesiredSize, borderPadding,
|
|
|
|
lineWM, frameWM);
|
|
|
|
|
2015-01-15 12:02:11 +03:00
|
|
|
nscoord startEdge = 0;
|
|
|
|
const bool boxDecorationBreakClone =
|
2016-08-26 10:14:32 +03:00
|
|
|
StyleBorder()->mBoxDecorationBreak == StyleBoxDecorationBreak::Clone;
|
2015-01-15 12:02:11 +03:00
|
|
|
if (boxDecorationBreakClone || !GetPrevContinuation()) {
|
|
|
|
startEdge = borderPadding.IStart(frameWM);
|
|
|
|
}
|
2016-07-21 13:36:39 +03:00
|
|
|
NS_ASSERTION(aReflowInput.AvailableISize() != NS_UNCONSTRAINEDSIZE,
|
2014-08-15 21:34:20 +04:00
|
|
|
"should no longer use available widths");
|
2021-03-23 13:26:16 +03:00
|
|
|
nscoord endEdge = aReflowInput.AvailableISize() - borderPadding.IEnd(frameWM);
|
|
|
|
aReflowInput.mLineLayout->BeginSpan(this, &aReflowInput, startEdge, endEdge,
|
|
|
|
&mBaseline);
|
2014-08-15 21:34:20 +04:00
|
|
|
|
2015-04-08 02:22:34 +03:00
|
|
|
for (RubySegmentEnumerator e(this); !e.AtEnd(); e.Next()) {
|
2019-09-02 13:09:30 +03:00
|
|
|
ReflowSegment(aPresContext, aReflowInput, aDesiredSize.BlockStartAscent(),
|
|
|
|
aDesiredSize.BSize(lineWM), e.GetBaseContainer(), aStatus);
|
2014-11-26 07:52:50 +03:00
|
|
|
|
2017-02-14 11:33:37 +03:00
|
|
|
if (aStatus.IsInlineBreak()) {
|
2014-11-26 07:52:50 +03:00
|
|
|
// A break occurs when reflowing the segment.
|
|
|
|
// Don't continue reflowing more segments.
|
|
|
|
break;
|
|
|
|
}
|
2014-08-15 21:34:20 +04:00
|
|
|
}
|
|
|
|
|
2014-11-26 07:52:50 +03:00
|
|
|
ContinuationTraversingState pullState(this);
|
2017-02-14 12:55:48 +03:00
|
|
|
while (aStatus.IsEmpty()) {
|
2016-01-27 08:58:53 +03:00
|
|
|
nsRubyBaseContainerFrame* baseContainer =
|
2016-07-21 13:36:39 +03:00
|
|
|
PullOneSegment(aReflowInput.mLineLayout, pullState);
|
2014-11-26 07:52:50 +03:00
|
|
|
if (!baseContainer) {
|
|
|
|
// No more continuations after, finish now.
|
|
|
|
break;
|
|
|
|
}
|
2019-09-02 13:09:30 +03:00
|
|
|
ReflowSegment(aPresContext, aReflowInput, aDesiredSize.BlockStartAscent(),
|
|
|
|
aDesiredSize.BSize(lineWM), baseContainer, aStatus);
|
2014-11-26 07:52:50 +03:00
|
|
|
}
|
|
|
|
// We never handle overflow in ruby.
|
2017-02-11 17:54:26 +03:00
|
|
|
MOZ_ASSERT(!aStatus.IsOverflowIncomplete());
|
2014-11-26 07:52:50 +03:00
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
aDesiredSize.ISize(lineWM) = aReflowInput.mLineLayout->EndSpan(this);
|
2015-01-15 12:02:11 +03:00
|
|
|
if (boxDecorationBreakClone || !GetPrevContinuation()) {
|
|
|
|
aDesiredSize.ISize(lineWM) += borderPadding.IStart(frameWM);
|
|
|
|
}
|
2017-02-11 17:45:07 +03:00
|
|
|
if (boxDecorationBreakClone || aStatus.IsComplete()) {
|
2015-01-15 12:02:11 +03:00
|
|
|
aDesiredSize.ISize(lineWM) += borderPadding.IEnd(frameWM);
|
|
|
|
}
|
|
|
|
|
2016-10-26 09:40:58 +03:00
|
|
|
// Update descendant leadings of ancestor ruby base container.
|
|
|
|
if (nsRubyBaseContainerFrame* rbc = FindRubyBaseContainerAncestor(this)) {
|
|
|
|
rbc->UpdateDescendantLeadings(mLeadings);
|
|
|
|
}
|
2020-06-06 08:38:12 +03:00
|
|
|
|
|
|
|
ReflowAbsoluteFrames(aPresContext, aDesiredSize, aReflowInput, aStatus);
|
2014-08-15 21:34:20 +04:00
|
|
|
}
|
2014-11-26 07:52:50 +03:00
|
|
|
|
|
|
|
void nsRubyFrame::ReflowSegment(nsPresContext* aPresContext,
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& aReflowInput,
|
2019-09-02 13:09:30 +03:00
|
|
|
nscoord aBlockStartAscent, nscoord aBlockSize,
|
2014-11-26 07:52:50 +03:00
|
|
|
nsRubyBaseContainerFrame* aBaseContainer,
|
|
|
|
nsReflowStatus& aStatus) {
|
2016-07-21 13:36:39 +03:00
|
|
|
WritingMode lineWM = aReflowInput.mLineLayout->GetWritingMode();
|
|
|
|
LogicalSize availSize(lineWM, aReflowInput.AvailableISize(),
|
|
|
|
aReflowInput.AvailableBSize());
|
2020-11-19 03:29:45 +03:00
|
|
|
NS_ASSERTION(!GetWritingMode().IsOrthogonalTo(lineWM),
|
2015-04-08 02:22:34 +03:00
|
|
|
"Ruby frame writing-mode shouldn't be orthogonal to its line");
|
2014-11-26 07:52:50 +03:00
|
|
|
|
2015-04-08 02:22:34 +03:00
|
|
|
AutoRubyTextContainerArray textContainers(aBaseContainer);
|
2014-11-26 07:52:50 +03:00
|
|
|
const uint32_t rtcCount = textContainers.Length();
|
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowOutput baseMetrics(aReflowInput);
|
2014-11-26 07:52:50 +03:00
|
|
|
bool pushedFrame;
|
2016-07-21 13:36:39 +03:00
|
|
|
aReflowInput.mLineLayout->ReflowFrame(aBaseContainer, aStatus, &baseMetrics,
|
2014-11-26 07:52:50 +03:00
|
|
|
pushedFrame);
|
|
|
|
|
2017-02-14 11:05:24 +03:00
|
|
|
if (aStatus.IsInlineBreakBefore()) {
|
2014-11-26 07:52:50 +03:00
|
|
|
if (aBaseContainer != mFrames.FirstChild()) {
|
|
|
|
// Some segments may have been reflowed before, hence it is not
|
|
|
|
// a break-before for the ruby container.
|
2017-02-14 06:52:53 +03:00
|
|
|
aStatus.Reset();
|
|
|
|
aStatus.SetInlineLineBreakAfter();
|
|
|
|
aStatus.SetIncomplete();
|
2017-09-29 01:36:36 +03:00
|
|
|
PushChildrenToOverflow(aBaseContainer, aBaseContainer->GetPrevSibling());
|
2016-07-21 13:36:39 +03:00
|
|
|
aReflowInput.mLineLayout->SetDirtyNextLine();
|
2014-11-26 07:52:50 +03:00
|
|
|
}
|
|
|
|
// This base container is not placed at all, we can skip all
|
|
|
|
// text containers paired with it.
|
|
|
|
return;
|
|
|
|
}
|
2017-02-11 17:17:26 +03:00
|
|
|
if (aStatus.IsIncomplete()) {
|
2014-11-26 07:52:50 +03:00
|
|
|
// It always promise that if the status is incomplete, there is a
|
|
|
|
// break occurs. Break before has been processed above. However,
|
|
|
|
// it is possible that break after happens with the frame reflow
|
|
|
|
// completed. It happens if there is a force break at the end.
|
2017-02-14 11:22:04 +03:00
|
|
|
MOZ_ASSERT(aStatus.IsInlineBreakAfter());
|
2014-11-26 07:52:50 +03:00
|
|
|
// Find the previous sibling which we will
|
|
|
|
// insert new continuations after.
|
|
|
|
nsIFrame* lastChild;
|
|
|
|
if (rtcCount > 0) {
|
|
|
|
lastChild = textContainers.LastElement();
|
|
|
|
} else {
|
|
|
|
lastChild = aBaseContainer;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create continuations for the base container
|
2014-12-02 09:03:57 +03:00
|
|
|
nsIFrame* newBaseContainer = CreateNextInFlow(aBaseContainer);
|
2014-11-26 07:52:50 +03:00
|
|
|
// newBaseContainer is null if there are existing next-in-flows.
|
|
|
|
// We only need to move and push if there were not.
|
|
|
|
if (newBaseContainer) {
|
|
|
|
// Move the new frame after all the text containers
|
|
|
|
mFrames.RemoveFrame(newBaseContainer);
|
|
|
|
mFrames.InsertFrame(nullptr, lastChild, newBaseContainer);
|
|
|
|
|
|
|
|
// Create continuations for text containers
|
|
|
|
nsIFrame* newLastChild = newBaseContainer;
|
|
|
|
for (uint32_t i = 0; i < rtcCount; i++) {
|
2014-12-02 09:03:57 +03:00
|
|
|
nsIFrame* newTextContainer = CreateNextInFlow(textContainers[i]);
|
2014-11-26 07:52:50 +03:00
|
|
|
MOZ_ASSERT(newTextContainer,
|
|
|
|
"Next-in-flow of rtc should not exist "
|
|
|
|
"if the corresponding rbc does not");
|
|
|
|
mFrames.RemoveFrame(newTextContainer);
|
|
|
|
mFrames.InsertFrame(nullptr, newLastChild, newTextContainer);
|
|
|
|
newLastChild = newTextContainer;
|
|
|
|
}
|
2015-01-07 04:47:09 +03:00
|
|
|
}
|
|
|
|
if (lastChild != mFrames.LastChild()) {
|
|
|
|
// Always push the next frame after the last child in this segment.
|
|
|
|
// It is possible that we pulled it back before our next-in-flow
|
|
|
|
// drain our overflow.
|
2017-09-29 01:36:36 +03:00
|
|
|
PushChildrenToOverflow(lastChild->GetNextSibling(), lastChild);
|
2016-07-21 13:36:39 +03:00
|
|
|
aReflowInput.mLineLayout->SetDirtyNextLine();
|
2014-11-26 07:52:50 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If the ruby base container is reflowed completely, the line
|
|
|
|
// layout will remove the next-in-flows of that frame. But the
|
|
|
|
// line layout is not aware of the ruby text containers, hence
|
|
|
|
// it is necessary to remove them here.
|
|
|
|
for (uint32_t i = 0; i < rtcCount; i++) {
|
|
|
|
nsIFrame* nextRTC = textContainers[i]->GetNextInFlow();
|
|
|
|
if (nextRTC) {
|
|
|
|
nextRTC->GetParent()->DeleteNextInFlowChild(nextRTC, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-07 04:47:09 +03:00
|
|
|
nscoord segmentISize = baseMetrics.ISize(lineWM);
|
2015-07-16 12:07:57 +03:00
|
|
|
const nsSize dummyContainerSize;
|
|
|
|
LogicalRect baseRect =
|
|
|
|
aBaseContainer->GetLogicalRect(lineWM, dummyContainerSize);
|
2014-12-17 11:42:32 +03:00
|
|
|
// We need to position our rtc frames on one side or the other of the
|
|
|
|
// base container's rect, using a coordinate space that's relative to
|
|
|
|
// the ruby frame. Right now, the base container's rect's block-axis
|
|
|
|
// position is relative to the block container frame containing the
|
2019-09-02 13:09:30 +03:00
|
|
|
// lines, so here we reset it to the different between the ascents of
|
|
|
|
// the ruby container and the ruby base container, assuming they are
|
|
|
|
// aligned with the baseline.
|
2014-12-17 11:42:32 +03:00
|
|
|
// XXX We may need to add border/padding here. See bug 1055667.
|
2019-09-02 13:09:30 +03:00
|
|
|
baseRect.BStart(lineWM) = aBlockStartAscent - baseMetrics.BlockStartAscent();
|
2014-12-17 11:42:32 +03:00
|
|
|
// The rect for offsets of text containers.
|
2015-03-14 08:46:33 +03:00
|
|
|
LogicalRect offsetRect = baseRect;
|
2016-10-26 09:40:58 +03:00
|
|
|
RubyBlockLeadings descLeadings = aBaseContainer->GetDescendantLeadings();
|
|
|
|
offsetRect.BStart(lineWM) -= descLeadings.mStart;
|
|
|
|
offsetRect.BSize(lineWM) += descLeadings.mStart + descLeadings.mEnd;
|
2021-03-10 13:46:14 +03:00
|
|
|
Maybe<LineRelativeDir> lastLineSide;
|
2014-11-26 07:52:50 +03:00
|
|
|
for (uint32_t i = 0; i < rtcCount; i++) {
|
|
|
|
nsRubyTextContainerFrame* textContainer = textContainers[i];
|
2015-04-08 02:22:34 +03:00
|
|
|
WritingMode rtcWM = textContainer->GetWritingMode();
|
2014-11-26 07:52:50 +03:00
|
|
|
nsReflowStatus textReflowStatus;
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowOutput textMetrics(aReflowInput);
|
|
|
|
ReflowInput textReflowInput(aPresContext, aReflowInput, textContainer,
|
2015-04-08 02:22:34 +03:00
|
|
|
availSize.ConvertTo(rtcWM, lineWM));
|
2014-11-26 07:52:50 +03:00
|
|
|
textContainer->Reflow(aPresContext, textMetrics, textReflowInput,
|
2016-07-21 13:36:39 +03:00
|
|
|
textReflowStatus);
|
2017-02-14 12:55:48 +03:00
|
|
|
// Ruby text containers always return complete reflow status even when
|
2014-11-26 07:52:50 +03:00
|
|
|
// they have continuations, because the breaking has already been
|
|
|
|
// handled when reflowing the base containers.
|
2017-02-14 12:55:48 +03:00
|
|
|
NS_ASSERTION(textReflowStatus.IsEmpty(),
|
2014-11-26 07:52:50 +03:00
|
|
|
"Ruby text container must not break itself inside");
|
2020-11-19 03:29:45 +03:00
|
|
|
const LogicalSize size = textMetrics.Size(lineWM);
|
2015-04-08 02:22:34 +03:00
|
|
|
textContainer->SetSize(lineWM, size);
|
2015-01-07 04:47:09 +03:00
|
|
|
|
|
|
|
nscoord reservedISize = RubyUtils::GetReservedISize(textContainer);
|
2015-04-08 02:22:34 +03:00
|
|
|
segmentISize = std::max(segmentISize, size.ISize(lineWM) + reservedISize);
|
2014-12-17 11:42:32 +03:00
|
|
|
|
2021-03-10 13:46:14 +03:00
|
|
|
Maybe<LineRelativeDir> lineSide;
|
|
|
|
switch (textContainer->StyleText()->mRubyPosition) {
|
|
|
|
case StyleRubyPosition::Over:
|
|
|
|
lineSide.emplace(eLineRelativeDirOver);
|
|
|
|
break;
|
|
|
|
case StyleRubyPosition::Under:
|
|
|
|
lineSide.emplace(eLineRelativeDirUnder);
|
|
|
|
break;
|
|
|
|
case StyleRubyPosition::AlternateOver:
|
|
|
|
if (lastLineSide.isSome() &&
|
|
|
|
lastLineSide.value() == eLineRelativeDirOver) {
|
|
|
|
lineSide.emplace(eLineRelativeDirUnder);
|
|
|
|
} else {
|
|
|
|
lineSide.emplace(eLineRelativeDirOver);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case StyleRubyPosition::AlternateUnder:
|
|
|
|
if (lastLineSide.isSome() &&
|
|
|
|
lastLineSide.value() == eLineRelativeDirUnder) {
|
|
|
|
lineSide.emplace(eLineRelativeDirOver);
|
|
|
|
} else {
|
|
|
|
lineSide.emplace(eLineRelativeDirUnder);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// XXX inter-character support in bug 1055672
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Unsupported ruby-position");
|
2015-01-22 06:04:55 +03:00
|
|
|
}
|
2021-03-10 13:46:14 +03:00
|
|
|
lastLineSide = lineSide;
|
2015-01-22 06:04:55 +03:00
|
|
|
|
2015-03-14 08:46:33 +03:00
|
|
|
LogicalPoint position(lineWM);
|
2021-03-10 13:46:14 +03:00
|
|
|
if (lineSide.isSome()) {
|
|
|
|
LogicalSide logicalSide =
|
|
|
|
lineWM.LogicalSideForLineRelativeDir(lineSide.value());
|
2019-08-14 01:52:38 +03:00
|
|
|
if (StaticPrefs::layout_css_ruby_intercharacter_enabled() &&
|
2017-09-01 03:41:13 +03:00
|
|
|
rtcWM.IsVerticalRL() &&
|
|
|
|
lineWM.GetInlineDir() == WritingMode::eInlineLTR) {
|
|
|
|
// Inter-character ruby annotations are only supported for vertical-rl
|
|
|
|
// in ltr horizontal writing. Fall back to non-inter-character behavior
|
|
|
|
// otherwise.
|
|
|
|
LogicalPoint offset(
|
|
|
|
lineWM, offsetRect.ISize(lineWM),
|
|
|
|
offsetRect.BSize(lineWM) > size.BSize(lineWM)
|
|
|
|
? (offsetRect.BSize(lineWM) - size.BSize(lineWM)) / 2
|
|
|
|
: 0);
|
|
|
|
position = offsetRect.Origin(lineWM) + offset;
|
|
|
|
aReflowInput.mLineLayout->AdvanceICoord(size.ISize(lineWM));
|
2021-03-10 13:46:14 +03:00
|
|
|
} else if (logicalSide == eLogicalSideBStart) {
|
2015-04-08 02:22:34 +03:00
|
|
|
offsetRect.BStart(lineWM) -= size.BSize(lineWM);
|
|
|
|
offsetRect.BSize(lineWM) += size.BSize(lineWM);
|
2015-03-14 08:46:33 +03:00
|
|
|
position = offsetRect.Origin(lineWM);
|
2021-03-10 13:46:14 +03:00
|
|
|
} else if (logicalSide == eLogicalSideBEnd) {
|
2015-03-14 08:46:33 +03:00
|
|
|
position = offsetRect.Origin(lineWM) +
|
|
|
|
LogicalPoint(lineWM, 0, offsetRect.BSize(lineWM));
|
2015-04-08 02:22:34 +03:00
|
|
|
offsetRect.BSize(lineWM) += size.BSize(lineWM);
|
2015-03-14 08:46:33 +03:00
|
|
|
} else {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("???");
|
2014-12-17 11:42:32 +03:00
|
|
|
}
|
2014-11-26 07:52:50 +03:00
|
|
|
}
|
2015-07-16 12:07:57 +03:00
|
|
|
// Using a dummy container-size here, so child positioning may not be
|
|
|
|
// correct. We will fix it in nsLineLayout after the whole line is
|
|
|
|
// reflowed.
|
2014-11-26 07:52:50 +03:00
|
|
|
FinishReflowChild(textContainer, aPresContext, textMetrics,
|
2016-07-21 13:36:39 +03:00
|
|
|
&textReflowInput, lineWM, position, dummyContainerSize,
|
2019-08-08 22:48:19 +03:00
|
|
|
ReflowChildFlags::Default);
|
2014-11-26 07:52:50 +03:00
|
|
|
}
|
2015-03-14 08:46:33 +03:00
|
|
|
MOZ_ASSERT(baseRect.ISize(lineWM) == offsetRect.ISize(lineWM),
|
2015-01-22 06:04:55 +03:00
|
|
|
"Annotations should only be placed on the block directions");
|
2015-01-07 04:47:09 +03:00
|
|
|
|
|
|
|
nscoord deltaISize = segmentISize - baseMetrics.ISize(lineWM);
|
|
|
|
if (deltaISize <= 0) {
|
|
|
|
RubyUtils::ClearReservedISize(aBaseContainer);
|
|
|
|
} else {
|
|
|
|
RubyUtils::SetReservedISize(aBaseContainer, deltaISize);
|
2016-07-21 13:36:39 +03:00
|
|
|
aReflowInput.mLineLayout->AdvanceICoord(deltaISize);
|
2015-01-07 04:47:09 +03:00
|
|
|
}
|
2015-01-08 08:02:41 +03:00
|
|
|
|
2019-09-02 13:09:30 +03:00
|
|
|
// Set block leadings of the base container.
|
|
|
|
// The leadings are the difference between the offsetRect and the rect
|
|
|
|
// of this ruby container, which has block start zero and block size
|
|
|
|
// aBlockSize.
|
|
|
|
nscoord startLeading = -offsetRect.BStart(lineWM);
|
|
|
|
nscoord endLeading = offsetRect.BEnd(lineWM) - aBlockSize;
|
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(startLeading >= 0 && endLeading >= 0,
|
|
|
|
"Leadings should be non-negative (because adding "
|
|
|
|
"ruby annotation can only increase the size)");
|
2016-11-10 03:10:42 +03:00
|
|
|
mLeadings.Update(startLeading, endLeading);
|
2014-11-26 07:52:50 +03:00
|
|
|
}
|
2014-11-26 07:52:50 +03:00
|
|
|
|
2016-01-27 08:58:53 +03:00
|
|
|
nsRubyBaseContainerFrame* nsRubyFrame::PullOneSegment(
|
|
|
|
const nsLineLayout* aLineLayout, ContinuationTraversingState& aState) {
|
2014-11-26 07:52:50 +03:00
|
|
|
// Pull a ruby base container
|
2016-01-27 08:58:53 +03:00
|
|
|
nsIFrame* baseFrame = GetNextInFlowChild(aState);
|
2014-11-26 07:52:50 +03:00
|
|
|
if (!baseFrame) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-04-30 18:30:08 +03:00
|
|
|
MOZ_ASSERT(baseFrame->IsRubyBaseContainerFrame());
|
2014-11-26 07:52:50 +03:00
|
|
|
|
2016-01-27 08:58:53 +03:00
|
|
|
// Get the float containing block of the base frame before we pull it.
|
|
|
|
nsBlockFrame* oldFloatCB = nsLayoutUtils::GetFloatContainingBlock(baseFrame);
|
|
|
|
PullNextInFlowChild(aState);
|
|
|
|
|
2014-11-26 07:52:50 +03:00
|
|
|
// Pull all ruby text containers following the base container
|
|
|
|
nsIFrame* nextFrame;
|
|
|
|
while ((nextFrame = GetNextInFlowChild(aState)) != nullptr &&
|
2017-04-30 18:30:08 +03:00
|
|
|
nextFrame->IsRubyTextContainerFrame()) {
|
2014-11-26 07:52:50 +03:00
|
|
|
PullNextInFlowChild(aState);
|
|
|
|
}
|
|
|
|
|
2016-01-27 08:58:53 +03:00
|
|
|
if (nsBlockFrame* newFloatCB =
|
2019-02-15 04:38:05 +03:00
|
|
|
do_QueryFrame(aLineLayout->LineContainerFrame())) {
|
2016-01-27 08:58:53 +03:00
|
|
|
if (oldFloatCB && oldFloatCB != newFloatCB) {
|
2019-07-02 00:58:35 +03:00
|
|
|
newFloatCB->ReparentFloats(baseFrame, oldFloatCB, true);
|
2016-01-27 08:58:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-26 07:52:50 +03:00
|
|
|
return static_cast<nsRubyBaseContainerFrame*>(baseFrame);
|
|
|
|
}
|