Bug 1709347 - Add CanvasRenderingContext2D.reset(). r=lsalzman,webidl,smaug
[gecko.git] / layout / mathml / nsMathMLSelectedFrame.cpp
blob924fed60e63c4a08e99ee7508424a278f8b2bb6a
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsMathMLSelectedFrame.h"
8 #include "nsDisplayList.h"
10 using namespace mozilla;
12 nsMathMLSelectedFrame::~nsMathMLSelectedFrame() = default;
14 NS_IMETHODIMP
15 nsMathMLSelectedFrame::TransmitAutomaticData() {
16 // Note that to determine space-like and embellished op properties:
17 // - <semantics> behaves the same as <maction>
18 // - <annotation-xml> behaves the same as <mrow>
20 // The REC defines the following element to be space-like:
21 // * an maction element whose selected sub-expression exists and is
22 // space-like;
23 nsIMathMLFrame* mathMLFrame = do_QueryFrame(mSelectedFrame);
24 if (mathMLFrame && mathMLFrame->IsSpaceLike()) {
25 mPresentationData.flags |= NS_MATHML_SPACE_LIKE;
26 } else {
27 mPresentationData.flags &= ~NS_MATHML_SPACE_LIKE;
30 // The REC defines the following element to be an embellished operator:
31 // * an maction element whose selected sub-expression exists and is an
32 // embellished operator;
33 mPresentationData.baseFrame = mSelectedFrame;
34 GetEmbellishDataFrom(mSelectedFrame, mEmbellishData);
36 return NS_OK;
39 nsresult nsMathMLSelectedFrame::ChildListChanged(int32_t aModType) {
40 GetSelectedFrame();
41 return nsMathMLContainerFrame::ChildListChanged(aModType);
44 void nsMathMLSelectedFrame::SetInitialChildList(ChildListID aListID,
45 nsFrameList&& aChildList) {
46 nsMathMLContainerFrame::SetInitialChildList(aListID, std::move(aChildList));
47 // This very first call to GetSelectedFrame() will cause us to be marked as an
48 // embellished operator if the selected child is an embellished operator
49 GetSelectedFrame();
52 // Only paint the selected child...
53 void nsMathMLSelectedFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
54 const nsDisplayListSet& aLists) {
55 // Report an error if something wrong was found in this frame.
56 // We can't call nsDisplayMathMLError from here,
57 // so ask nsMathMLContainerFrame to do the work for us.
58 if (NS_MATHML_HAS_ERROR(mPresentationData.flags)) {
59 nsMathMLContainerFrame::BuildDisplayList(aBuilder, aLists);
60 return;
63 DisplayBorderBackgroundOutline(aBuilder, aLists);
65 nsIFrame* childFrame = GetSelectedFrame();
66 if (childFrame) {
67 // Put the child's background directly onto the content list
68 nsDisplayListSet set(aLists, aLists.Content());
69 // The children should be in content order
70 BuildDisplayListForChild(aBuilder, childFrame, set);
73 #if defined(DEBUG) && defined(SHOW_BOUNDING_BOX)
74 // visual debug
75 DisplayBoundingMetrics(aBuilder, this, mReference, mBoundingMetrics, aLists);
76 #endif
79 /* virtual */
80 nsIFrame::SizeComputationResult nsMathMLSelectedFrame::ComputeSize(
81 gfxContext* aRenderingContext, WritingMode aWM, const LogicalSize& aCBSize,
82 nscoord aAvailableISize, const LogicalSize& aMargin,
83 const LogicalSize& aBorderPadding, const StyleSizeOverrides& aSizeOverrides,
84 ComputeSizeFlags aFlags) {
85 nsIFrame* childFrame = GetSelectedFrame();
86 if (childFrame) {
87 // Delegate size computation to the child frame.
88 // Try to account for border/padding/margin on this frame and the child,
89 // though we don't really support them during reflow anyway...
90 const nscoord availableISize =
91 aAvailableISize - aBorderPadding.ISize(aWM) - aMargin.ISize(aWM);
92 const LogicalSize cbSize = aCBSize - aBorderPadding - aMargin;
93 SizeComputationInput offsetState(childFrame, aRenderingContext, aWM,
94 availableISize);
95 const auto bpSize = offsetState.ComputedLogicalBorderPadding(aWM).Size(aWM);
96 auto size = childFrame->ComputeSize(
97 aRenderingContext, aWM, cbSize, availableISize,
98 offsetState.ComputedLogicalMargin(aWM).Size(aWM), bpSize,
99 aSizeOverrides, aFlags);
100 return {size.mLogicalSize + bpSize, size.mAspectRatioUsage};
102 return {LogicalSize(aWM), AspectRatioUsage::None};
105 // Only reflow the selected child ...
106 void nsMathMLSelectedFrame::Reflow(nsPresContext* aPresContext,
107 ReflowOutput& aDesiredSize,
108 const ReflowInput& aReflowInput,
109 nsReflowStatus& aStatus) {
110 MarkInReflow();
111 MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!");
113 mPresentationData.flags &= ~NS_MATHML_ERROR;
114 aDesiredSize.ClearSize();
115 aDesiredSize.SetBlockStartAscent(0);
116 mBoundingMetrics = nsBoundingMetrics();
117 nsIFrame* childFrame = GetSelectedFrame();
118 if (childFrame) {
119 WritingMode wm = childFrame->GetWritingMode();
120 LogicalSize availSize = aReflowInput.ComputedSize(wm);
121 availSize.BSize(wm) = NS_UNCONSTRAINEDSIZE;
122 ReflowInput childReflowInput(aPresContext, aReflowInput, childFrame,
123 availSize);
124 ReflowChild(childFrame, aPresContext, aDesiredSize, childReflowInput,
125 aStatus);
126 SaveReflowAndBoundingMetricsFor(childFrame, aDesiredSize,
127 aDesiredSize.mBoundingMetrics);
128 mBoundingMetrics = aDesiredSize.mBoundingMetrics;
130 FinalizeReflow(aReflowInput.mRenderingContext->GetDrawTarget(), aDesiredSize);
133 // Only place the selected child ...
134 /* virtual */
135 nsresult nsMathMLSelectedFrame::Place(DrawTarget* aDrawTarget,
136 bool aPlaceOrigin,
137 ReflowOutput& aDesiredSize) {
138 nsIFrame* childFrame = GetSelectedFrame();
140 if (mInvalidMarkup) {
141 // Calling PlaceForError when mathml.error_message_layout_for_invalid_markup
142 // is disabled causes assertion failures because nsMathMLSelectedFrame only
143 // performs layout of the selected child. However, this code is only reached
144 // when mathml.legacy_maction_and_semantics_implementations is enabled, so
145 // it is out the scope of the mrow fallback described in MathML Core and
146 // nsMathMLSelectedFrame will go away in the future. So for now let's
147 // continue to always layout this case as an 'invalid-markup' message.
148 return ReflowError(aDrawTarget, aDesiredSize);
151 aDesiredSize.ClearSize();
152 aDesiredSize.SetBlockStartAscent(0);
153 mBoundingMetrics = nsBoundingMetrics();
154 if (childFrame) {
155 GetReflowAndBoundingMetricsFor(childFrame, aDesiredSize, mBoundingMetrics);
156 if (aPlaceOrigin) {
157 FinishReflowChild(childFrame, PresContext(), aDesiredSize, nullptr, 0, 0,
158 ReflowChildFlags::Default);
160 mReference.x = 0;
161 mReference.y = aDesiredSize.BlockStartAscent();
163 aDesiredSize.mBoundingMetrics = mBoundingMetrics;
164 return NS_OK;