1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code is subject to the terms of the Mozilla Public License
4 * version 2.0 (the "License"). You can obtain a copy of the License at
5 * http://mozilla.org/MPL/2.0/. */
7 /* rendering object for CSS "display: ruby-text-container" */
9 #include "nsRubyTextContainerFrame.h"
10 #include "nsPresContext.h"
11 #include "nsStyleContext.h"
12 #include "WritingModes.h"
13 #include "RubyReflowState.h"
14 #include "mozilla/UniquePtr.h"
16 using namespace mozilla
;
18 //----------------------------------------------------------------------
20 // Frame class boilerplate
21 // =======================
23 NS_QUERYFRAME_HEAD(nsRubyTextContainerFrame
)
24 NS_QUERYFRAME_ENTRY(nsRubyTextContainerFrame
)
25 NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame
)
27 NS_IMPL_FRAMEARENA_HELPERS(nsRubyTextContainerFrame
)
30 NS_NewRubyTextContainerFrame(nsIPresShell
* aPresShell
,
31 nsStyleContext
* aContext
)
33 return new (aPresShell
) nsRubyTextContainerFrame(aContext
);
37 //----------------------------------------------------------------------
39 // nsRubyTextContainerFrame Method Implementations
40 // ===============================================
43 nsRubyTextContainerFrame::GetType() const
45 return nsGkAtoms::rubyTextContainerFrame
;
48 #ifdef DEBUG_FRAME_DUMP
50 nsRubyTextContainerFrame::GetFrameName(nsAString
& aResult
) const
52 return MakeFrameName(NS_LITERAL_STRING("RubyTextContainer"), aResult
);
57 nsRubyTextContainerFrame::IsFrameOfType(uint32_t aFlags
) const
59 if (aFlags
& eSupportsCSSTransforms
) {
62 return nsRubyTextContainerFrameSuper::IsFrameOfType(aFlags
);
66 nsRubyTextContainerFrame::SetInitialChildList(ChildListID aListID
,
67 nsFrameList
& aChildList
)
69 nsRubyTextContainerFrameSuper::SetInitialChildList(aListID
, aChildList
);
74 nsRubyTextContainerFrame::AppendFrames(ChildListID aListID
,
75 nsFrameList
& aFrameList
)
77 nsRubyTextContainerFrameSuper::AppendFrames(aListID
, aFrameList
);
82 nsRubyTextContainerFrame::InsertFrames(ChildListID aListID
,
84 nsFrameList
& aFrameList
)
86 nsRubyTextContainerFrameSuper::InsertFrames(aListID
, aPrevFrame
, aFrameList
);
91 nsRubyTextContainerFrame::RemoveFrame(ChildListID aListID
,
94 nsRubyTextContainerFrameSuper::RemoveFrame(aListID
, aOldFrame
);
99 nsRubyTextContainerFrame::UpdateSpanFlag()
102 // The continuation checks are safe here because spans never break.
103 if (!GetPrevContinuation() && !GetNextContinuation()) {
104 nsIFrame
* onlyChild
= mFrames
.OnlyChild();
105 if (onlyChild
&& onlyChild
->IsPseudoFrame(GetContent())) {
106 // Per CSS Ruby spec, if the only child of an rtc frame is
107 // a pseudo rt frame, it spans all bases in the segment.
113 AddStateBits(NS_RUBY_TEXT_CONTAINER_IS_SPAN
);
115 RemoveStateBits(NS_RUBY_TEXT_CONTAINER_IS_SPAN
);
120 nsRubyTextContainerFrame::Reflow(nsPresContext
* aPresContext
,
121 nsHTMLReflowMetrics
& aDesiredSize
,
122 const nsHTMLReflowState
& aReflowState
,
123 nsReflowStatus
& aStatus
)
125 DO_GLOBAL_REFLOW_COUNT("nsRubyTextContainerFrame");
126 DISPLAY_REFLOW(aPresContext
, this, aReflowState
, aDesiredSize
, aStatus
);
128 MOZ_ASSERT(aReflowState
.mRubyReflowState
, "No ruby reflow state provided");
130 // All rt children have already been reflowed. All we need to do is
131 // to report complete and return the desired size provided by the
132 // ruby base container.
134 // Although a ruby text container may have continuations, returning
135 // NS_FRAME_COMPLETE here is still safe, since its parent, ruby frame,
136 // ignores the status, and continuations of the ruby base container
137 // will take care of our continuations.
138 aStatus
= NS_FRAME_COMPLETE
;
139 WritingMode lineWM
= aReflowState
.mLineLayout
->GetWritingMode();
140 const RubyReflowState::TextContainerInfo
& info
=
141 aReflowState
.mRubyReflowState
->GetCurrentTextContainerInfo(this);
142 aDesiredSize
.SetSize(lineWM
, info
.mLineSize
);