Bumping manifests a=b2g-bump
[gecko.git] / layout / mathml / nsMathMLSelectedFrame.cpp
blobaa5b42d552c969a6ff39e70c74be4c89b127c778
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsMathMLSelectedFrame.h"
7 #include "nsDisplayList.h"
9 using namespace mozilla;
11 nsMathMLSelectedFrame::~nsMathMLSelectedFrame()
15 void
16 nsMathMLSelectedFrame::Init(nsIContent* aContent,
17 nsContainerFrame* aParent,
18 nsIFrame* aPrevInFlow)
20 // Init our local attributes
21 mInvalidMarkup = false;
22 mSelectedFrame = nullptr;
24 // Let the base class do the rest
25 nsMathMLContainerFrame::Init(aContent, aParent, aPrevInFlow);
28 NS_IMETHODIMP
29 nsMathMLSelectedFrame::TransmitAutomaticData()
31 // Note that to determine space-like and embellished op properties:
32 // - <semantics> behaves the same as <maction>
33 // - <annotation-xml> behaves the same as <mrow>
35 // The REC defines the following element to be space-like:
36 // * an maction element whose selected sub-expression exists and is
37 // space-like;
38 nsIMathMLFrame* mathMLFrame = do_QueryFrame(mSelectedFrame);
39 if (mathMLFrame && mathMLFrame->IsSpaceLike()) {
40 mPresentationData.flags |= NS_MATHML_SPACE_LIKE;
41 } else {
42 mPresentationData.flags &= ~NS_MATHML_SPACE_LIKE;
45 // The REC defines the following element to be an embellished operator:
46 // * an maction element whose selected sub-expression exists and is an
47 // embellished operator;
48 mPresentationData.baseFrame = mSelectedFrame;
49 GetEmbellishDataFrom(mSelectedFrame, mEmbellishData);
51 return NS_OK;
54 nsresult
55 nsMathMLSelectedFrame::ChildListChanged(int32_t aModType)
57 GetSelectedFrame();
58 return nsMathMLContainerFrame::ChildListChanged(aModType);
61 void
62 nsMathMLSelectedFrame::SetInitialChildList(ChildListID aListID,
63 nsFrameList& aChildList)
65 nsMathMLContainerFrame::SetInitialChildList(aListID, aChildList);
66 // This very first call to GetSelectedFrame() will cause us to be marked as an
67 // embellished operator if the selected child is an embellished operator
68 GetSelectedFrame();
71 // Only paint the selected child...
72 void
73 nsMathMLSelectedFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
74 const nsRect& aDirtyRect,
75 const nsDisplayListSet& aLists)
77 // Report an error if something wrong was found in this frame.
78 // We can't call nsDisplayMathMLError from here,
79 // so ask nsMathMLContainerFrame to do the work for us.
80 if (NS_MATHML_HAS_ERROR(mPresentationData.flags)) {
81 nsMathMLContainerFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
82 return;
85 DisplayBorderBackgroundOutline(aBuilder, aLists);
87 nsIFrame* childFrame = GetSelectedFrame();
88 if (childFrame) {
89 // Put the child's background directly onto the content list
90 nsDisplayListSet set(aLists, aLists.Content());
91 // The children should be in content order
92 BuildDisplayListForChild(aBuilder, childFrame, aDirtyRect, set);
95 #if defined(DEBUG) && defined(SHOW_BOUNDING_BOX)
96 // visual debug
97 DisplayBoundingMetrics(aBuilder, this, mReference, mBoundingMetrics, aLists);
98 #endif
101 // Only reflow the selected child ...
102 void
103 nsMathMLSelectedFrame::Reflow(nsPresContext* aPresContext,
104 nsHTMLReflowMetrics& aDesiredSize,
105 const nsHTMLReflowState& aReflowState,
106 nsReflowStatus& aStatus)
108 aStatus = NS_FRAME_COMPLETE;
109 aDesiredSize.ClearSize();
110 aDesiredSize.SetBlockStartAscent(0);
111 mBoundingMetrics = nsBoundingMetrics();
112 nsIFrame* childFrame = GetSelectedFrame();
113 if (childFrame) {
114 WritingMode wm = childFrame->GetWritingMode();
115 LogicalSize availSize = aReflowState.ComputedSize(wm);
116 availSize.BSize(wm) = NS_UNCONSTRAINEDSIZE;
117 nsHTMLReflowState childReflowState(aPresContext, aReflowState,
118 childFrame, availSize);
119 ReflowChild(childFrame, aPresContext, aDesiredSize,
120 childReflowState, aStatus);
121 SaveReflowAndBoundingMetricsFor(childFrame, aDesiredSize,
122 aDesiredSize.mBoundingMetrics);
123 mBoundingMetrics = aDesiredSize.mBoundingMetrics;
125 FinalizeReflow(*aReflowState.rendContext, aDesiredSize);
126 NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
129 // Only place the selected child ...
130 /* virtual */ nsresult
131 nsMathMLSelectedFrame::Place(nsRenderingContext& aRenderingContext,
132 bool aPlaceOrigin,
133 nsHTMLReflowMetrics& aDesiredSize)
135 nsIFrame* childFrame = GetSelectedFrame();
137 if (mInvalidMarkup) {
138 return ReflowError(aRenderingContext, aDesiredSize);
141 aDesiredSize.ClearSize();
142 aDesiredSize.SetBlockStartAscent(0);
143 mBoundingMetrics = nsBoundingMetrics();
144 if (childFrame) {
145 GetReflowAndBoundingMetricsFor(childFrame, aDesiredSize, mBoundingMetrics);
146 if (aPlaceOrigin) {
147 FinishReflowChild(childFrame, PresContext(), aDesiredSize, nullptr, 0, 0, 0);
149 mReference.x = 0;
150 mReference.y = aDesiredSize.BlockStartAscent();
152 aDesiredSize.mBoundingMetrics = mBoundingMetrics;
153 return NS_OK;