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-text-container" */
|
|
|
|
|
|
|
|
#include "nsRubyTextContainerFrame.h"
|
2015-03-26 10:29:31 +03:00
|
|
|
|
|
|
|
#include "mozilla/UniquePtr.h"
|
|
|
|
#include "mozilla/WritingModes.h"
|
2016-03-17 04:46:33 +03:00
|
|
|
#include "nsLineLayout.h"
|
2014-07-23 06:08:01 +04:00
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsStyleContext.h"
|
|
|
|
|
2014-11-26 07:52:49 +03:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2014-07-23 06:08:01 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Frame class boilerplate
|
|
|
|
// =======================
|
|
|
|
|
|
|
|
NS_QUERYFRAME_HEAD(nsRubyTextContainerFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsRubyTextContainerFrame)
|
2014-11-26 07:52:49 +03:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
|
2014-07-23 06:08:01 +04:00
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsRubyTextContainerFrame)
|
|
|
|
|
|
|
|
nsContainerFrame*
|
|
|
|
NS_NewRubyTextContainerFrame(nsIPresShell* aPresShell,
|
|
|
|
nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsRubyTextContainerFrame(aContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// nsRubyTextContainerFrame Method Implementations
|
|
|
|
// ===============================================
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsRubyTextContainerFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::rubyTextContainerFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
|
|
|
nsresult
|
|
|
|
nsRubyTextContainerFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("RubyTextContainer"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
2014-08-15 21:34:20 +04:00
|
|
|
|
2014-11-26 07:52:49 +03:00
|
|
|
/* virtual */ bool
|
|
|
|
nsRubyTextContainerFrame::IsFrameOfType(uint32_t aFlags) const
|
|
|
|
{
|
|
|
|
if (aFlags & eSupportsCSSTransforms) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-18 09:12:52 +03:00
|
|
|
return nsContainerFrame::IsFrameOfType(aFlags);
|
2014-11-26 07:52:49 +03:00
|
|
|
}
|
|
|
|
|
2014-12-29 05:34:07 +03:00
|
|
|
/* virtual */ void
|
|
|
|
nsRubyTextContainerFrame::SetInitialChildList(ChildListID aListID,
|
|
|
|
nsFrameList& aChildList)
|
|
|
|
{
|
2016-04-18 09:12:52 +03:00
|
|
|
nsContainerFrame::SetInitialChildList(aListID, aChildList);
|
2016-01-28 02:11:00 +03:00
|
|
|
if (aListID == kPrincipalList) {
|
|
|
|
UpdateSpanFlag();
|
|
|
|
}
|
2014-12-29 05:34:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
nsRubyTextContainerFrame::AppendFrames(ChildListID aListID,
|
|
|
|
nsFrameList& aFrameList)
|
|
|
|
{
|
2016-04-18 09:12:52 +03:00
|
|
|
nsContainerFrame::AppendFrames(aListID, aFrameList);
|
2014-12-29 05:34:07 +03:00
|
|
|
UpdateSpanFlag();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
nsRubyTextContainerFrame::InsertFrames(ChildListID aListID,
|
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsFrameList& aFrameList)
|
|
|
|
{
|
2016-04-18 09:12:52 +03:00
|
|
|
nsContainerFrame::InsertFrames(aListID, aPrevFrame, aFrameList);
|
2014-12-29 05:34:07 +03:00
|
|
|
UpdateSpanFlag();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
nsRubyTextContainerFrame::RemoveFrame(ChildListID aListID,
|
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
2016-04-18 09:12:52 +03:00
|
|
|
nsContainerFrame::RemoveFrame(aListID, aOldFrame);
|
2014-12-29 05:34:07 +03:00
|
|
|
UpdateSpanFlag();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRubyTextContainerFrame::UpdateSpanFlag()
|
|
|
|
{
|
|
|
|
bool isSpan = false;
|
|
|
|
// The continuation checks are safe here because spans never break.
|
|
|
|
if (!GetPrevContinuation() && !GetNextContinuation()) {
|
|
|
|
nsIFrame* onlyChild = mFrames.OnlyChild();
|
|
|
|
if (onlyChild && onlyChild->IsPseudoFrame(GetContent())) {
|
|
|
|
// Per CSS Ruby spec, if the only child of an rtc frame is
|
|
|
|
// a pseudo rt frame, it spans all bases in the segment.
|
|
|
|
isSpan = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isSpan) {
|
|
|
|
AddStateBits(NS_RUBY_TEXT_CONTAINER_IS_SPAN);
|
|
|
|
} else {
|
|
|
|
RemoveStateBits(NS_RUBY_TEXT_CONTAINER_IS_SPAN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-15 21:34:20 +04:00
|
|
|
/* virtual */ void
|
|
|
|
nsRubyTextContainerFrame::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("nsRubyTextContainerFrame");
|
2016-07-21 13:36:39 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus);
|
2014-08-15 21:34:20 +04:00
|
|
|
|
2014-11-26 07:52:50 +03:00
|
|
|
// Although a ruby text container may have continuations, returning
|
2017-02-14 12:55:48 +03:00
|
|
|
// complete reflow status is still safe, since its parent, ruby frame,
|
2014-11-26 07:52:50 +03:00
|
|
|
// ignores the status, and continuations of the ruby base container
|
|
|
|
// will take care of our continuations.
|
2017-02-14 12:55:48 +03:00
|
|
|
aStatus.Reset();
|
2016-07-21 13:36:39 +03:00
|
|
|
WritingMode lineWM = aReflowInput.mLineLayout->GetWritingMode();
|
2015-01-13 12:04:41 +03:00
|
|
|
|
2015-02-17 04:25:18 +03:00
|
|
|
nscoord minBCoord = nscoord_MAX;
|
|
|
|
nscoord maxBCoord = nscoord_MIN;
|
2015-07-16 12:07:57 +03:00
|
|
|
// The container size is not yet known, so we use a dummy (0, 0) size.
|
|
|
|
// The block-dir position will be corrected below after containerSize
|
|
|
|
// is finalized.
|
|
|
|
const nsSize dummyContainerSize;
|
2015-02-17 04:25:18 +03:00
|
|
|
for (nsFrameList::Enumerator e(mFrames); !e.AtEnd(); e.Next()) {
|
|
|
|
nsIFrame* child = e.get();
|
|
|
|
MOZ_ASSERT(child->GetType() == nsGkAtoms::rubyTextFrame);
|
2015-07-16 12:07:57 +03:00
|
|
|
LogicalRect rect = child->GetLogicalRect(lineWM, dummyContainerSize);
|
2015-02-17 04:25:18 +03:00
|
|
|
LogicalMargin margin = child->GetLogicalUsedMargin(lineWM);
|
|
|
|
nscoord blockStart = rect.BStart(lineWM) - margin.BStart(lineWM);
|
|
|
|
minBCoord = std::min(minBCoord, blockStart);
|
|
|
|
nscoord blockEnd = rect.BEnd(lineWM) + margin.BEnd(lineWM);
|
|
|
|
maxBCoord = std::max(maxBCoord, blockEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
LogicalSize size(lineWM, mISize, 0);
|
|
|
|
if (!mFrames.IsEmpty()) {
|
2015-03-31 06:08:03 +03:00
|
|
|
if (MOZ_UNLIKELY(minBCoord > maxBCoord)) {
|
2015-03-31 08:30:29 +03:00
|
|
|
// XXX When bug 765861 gets fixed, this warning should be upgraded.
|
2015-03-31 06:08:03 +03:00
|
|
|
NS_WARNING("bad block coord");
|
|
|
|
minBCoord = maxBCoord = 0;
|
|
|
|
}
|
2015-02-17 04:25:18 +03:00
|
|
|
size.BSize(lineWM) = maxBCoord - minBCoord;
|
2015-07-16 12:07:57 +03:00
|
|
|
nsSize containerSize = size.GetPhysicalSize(lineWM);
|
2015-03-14 08:46:33 +03:00
|
|
|
for (nsFrameList::Enumerator e(mFrames); !e.AtEnd(); e.Next()) {
|
|
|
|
nsIFrame* child = e.get();
|
2015-07-16 12:07:57 +03:00
|
|
|
// We reflowed the child with a dummy container size, as the true size
|
2015-03-14 08:46:33 +03:00
|
|
|
// was not yet known at that time.
|
2015-07-16 12:07:57 +03:00
|
|
|
LogicalPoint pos = child->GetLogicalPosition(lineWM, dummyContainerSize);
|
2015-03-14 08:46:33 +03:00
|
|
|
// Adjust block position to account for minBCoord,
|
|
|
|
// then reposition child based on the true container width.
|
|
|
|
pos.B(lineWM) -= minBCoord;
|
|
|
|
// Relative positioning hasn't happened yet.
|
|
|
|
// So MovePositionBy should not be used here.
|
2015-07-16 12:07:57 +03:00
|
|
|
child->SetPosition(lineWM, pos, containerSize);
|
2015-03-14 08:46:33 +03:00
|
|
|
nsContainerFrame::PlaceFrameView(child);
|
2015-01-13 12:04:41 +03:00
|
|
|
}
|
|
|
|
}
|
2015-02-17 04:25:18 +03:00
|
|
|
|
|
|
|
aDesiredSize.SetSize(lineWM, size);
|
2014-08-15 21:34:20 +04:00
|
|
|
}
|