Bumping manifests a=b2g-bump
[gecko.git] / layout / generic / nsRubyTextContainerFrame.cpp
blob2c75e8a738ca278e7e32c66984cfdc78fc118dca
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)
29 nsContainerFrame*
30 NS_NewRubyTextContainerFrame(nsIPresShell* aPresShell,
31 nsStyleContext* aContext)
33 return new (aPresShell) nsRubyTextContainerFrame(aContext);
37 //----------------------------------------------------------------------
39 // nsRubyTextContainerFrame Method Implementations
40 // ===============================================
42 nsIAtom*
43 nsRubyTextContainerFrame::GetType() const
45 return nsGkAtoms::rubyTextContainerFrame;
48 #ifdef DEBUG_FRAME_DUMP
49 nsresult
50 nsRubyTextContainerFrame::GetFrameName(nsAString& aResult) const
52 return MakeFrameName(NS_LITERAL_STRING("RubyTextContainer"), aResult);
54 #endif
56 /* virtual */ bool
57 nsRubyTextContainerFrame::IsFrameOfType(uint32_t aFlags) const
59 if (aFlags & eSupportsCSSTransforms) {
60 return false;
62 return nsRubyTextContainerFrameSuper::IsFrameOfType(aFlags);
65 /* virtual */ void
66 nsRubyTextContainerFrame::SetInitialChildList(ChildListID aListID,
67 nsFrameList& aChildList)
69 nsRubyTextContainerFrameSuper::SetInitialChildList(aListID, aChildList);
70 UpdateSpanFlag();
73 /* virtual */ void
74 nsRubyTextContainerFrame::AppendFrames(ChildListID aListID,
75 nsFrameList& aFrameList)
77 nsRubyTextContainerFrameSuper::AppendFrames(aListID, aFrameList);
78 UpdateSpanFlag();
81 /* virtual */ void
82 nsRubyTextContainerFrame::InsertFrames(ChildListID aListID,
83 nsIFrame* aPrevFrame,
84 nsFrameList& aFrameList)
86 nsRubyTextContainerFrameSuper::InsertFrames(aListID, aPrevFrame, aFrameList);
87 UpdateSpanFlag();
90 /* virtual */ void
91 nsRubyTextContainerFrame::RemoveFrame(ChildListID aListID,
92 nsIFrame* aOldFrame)
94 nsRubyTextContainerFrameSuper::RemoveFrame(aListID, aOldFrame);
95 UpdateSpanFlag();
98 void
99 nsRubyTextContainerFrame::UpdateSpanFlag()
101 bool isSpan = false;
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.
108 isSpan = true;
112 if (isSpan) {
113 AddStateBits(NS_RUBY_TEXT_CONTAINER_IS_SPAN);
114 } else {
115 RemoveStateBits(NS_RUBY_TEXT_CONTAINER_IS_SPAN);
119 /* virtual */ void
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);