Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsMathMLSelectedFrame.h" |
michael@0 | 7 | #include "nsDisplayList.h" |
michael@0 | 8 | |
michael@0 | 9 | nsMathMLSelectedFrame::~nsMathMLSelectedFrame() |
michael@0 | 10 | { |
michael@0 | 11 | } |
michael@0 | 12 | |
michael@0 | 13 | void |
michael@0 | 14 | nsMathMLSelectedFrame::Init(nsIContent* aContent, |
michael@0 | 15 | nsIFrame* aParent, |
michael@0 | 16 | nsIFrame* aPrevInFlow) |
michael@0 | 17 | { |
michael@0 | 18 | // Init our local attributes |
michael@0 | 19 | mInvalidMarkup = false; |
michael@0 | 20 | mSelectedFrame = nullptr; |
michael@0 | 21 | |
michael@0 | 22 | // Let the base class do the rest |
michael@0 | 23 | nsMathMLContainerFrame::Init(aContent, aParent, aPrevInFlow); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | NS_IMETHODIMP |
michael@0 | 27 | nsMathMLSelectedFrame::TransmitAutomaticData() |
michael@0 | 28 | { |
michael@0 | 29 | // Note that to determine space-like and embellished op properties: |
michael@0 | 30 | // - <semantics> behaves the same as <maction> |
michael@0 | 31 | // - <annotation-xml> behaves the same as <mrow> |
michael@0 | 32 | |
michael@0 | 33 | // The REC defines the following element to be space-like: |
michael@0 | 34 | // * an maction element whose selected sub-expression exists and is |
michael@0 | 35 | // space-like; |
michael@0 | 36 | nsIMathMLFrame* mathMLFrame = do_QueryFrame(mSelectedFrame); |
michael@0 | 37 | if (mathMLFrame && mathMLFrame->IsSpaceLike()) { |
michael@0 | 38 | mPresentationData.flags |= NS_MATHML_SPACE_LIKE; |
michael@0 | 39 | } else { |
michael@0 | 40 | mPresentationData.flags &= ~NS_MATHML_SPACE_LIKE; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | // The REC defines the following element to be an embellished operator: |
michael@0 | 44 | // * an maction element whose selected sub-expression exists and is an |
michael@0 | 45 | // embellished operator; |
michael@0 | 46 | mPresentationData.baseFrame = mSelectedFrame; |
michael@0 | 47 | GetEmbellishDataFrom(mSelectedFrame, mEmbellishData); |
michael@0 | 48 | |
michael@0 | 49 | return NS_OK; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | nsresult |
michael@0 | 53 | nsMathMLSelectedFrame::ChildListChanged(int32_t aModType) |
michael@0 | 54 | { |
michael@0 | 55 | GetSelectedFrame(); |
michael@0 | 56 | return nsMathMLContainerFrame::ChildListChanged(aModType); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | nsresult |
michael@0 | 60 | nsMathMLSelectedFrame::SetInitialChildList(ChildListID aListID, |
michael@0 | 61 | nsFrameList& aChildList) |
michael@0 | 62 | { |
michael@0 | 63 | nsresult rv = nsMathMLContainerFrame::SetInitialChildList(aListID, |
michael@0 | 64 | aChildList); |
michael@0 | 65 | // This very first call to GetSelectedFrame() will cause us to be marked as an |
michael@0 | 66 | // embellished operator if the selected child is an embellished operator |
michael@0 | 67 | GetSelectedFrame(); |
michael@0 | 68 | return rv; |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | // Only paint the selected child... |
michael@0 | 72 | void |
michael@0 | 73 | nsMathMLSelectedFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, |
michael@0 | 74 | const nsRect& aDirtyRect, |
michael@0 | 75 | const nsDisplayListSet& aLists) |
michael@0 | 76 | { |
michael@0 | 77 | // Report an error if something wrong was found in this frame. |
michael@0 | 78 | // We can't call nsDisplayMathMLError from here, |
michael@0 | 79 | // so ask nsMathMLContainerFrame to do the work for us. |
michael@0 | 80 | if (NS_MATHML_HAS_ERROR(mPresentationData.flags)) { |
michael@0 | 81 | nsMathMLContainerFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists); |
michael@0 | 82 | return; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | DisplayBorderBackgroundOutline(aBuilder, aLists); |
michael@0 | 86 | |
michael@0 | 87 | nsIFrame* childFrame = GetSelectedFrame(); |
michael@0 | 88 | if (childFrame) { |
michael@0 | 89 | // Put the child's background directly onto the content list |
michael@0 | 90 | nsDisplayListSet set(aLists, aLists.Content()); |
michael@0 | 91 | // The children should be in content order |
michael@0 | 92 | BuildDisplayListForChild(aBuilder, childFrame, aDirtyRect, set); |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | #if defined(DEBUG) && defined(SHOW_BOUNDING_BOX) |
michael@0 | 96 | // visual debug |
michael@0 | 97 | DisplayBoundingMetrics(aBuilder, this, mReference, mBoundingMetrics, aLists); |
michael@0 | 98 | #endif |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | // Only reflow the selected child ... |
michael@0 | 102 | nsresult |
michael@0 | 103 | nsMathMLSelectedFrame::Reflow(nsPresContext* aPresContext, |
michael@0 | 104 | nsHTMLReflowMetrics& aDesiredSize, |
michael@0 | 105 | const nsHTMLReflowState& aReflowState, |
michael@0 | 106 | nsReflowStatus& aStatus) |
michael@0 | 107 | { |
michael@0 | 108 | nsresult rv = NS_OK; |
michael@0 | 109 | aStatus = NS_FRAME_COMPLETE; |
michael@0 | 110 | aDesiredSize.Width() = aDesiredSize.Height() = 0; |
michael@0 | 111 | aDesiredSize.SetTopAscent(0); |
michael@0 | 112 | mBoundingMetrics = nsBoundingMetrics(); |
michael@0 | 113 | nsIFrame* childFrame = GetSelectedFrame(); |
michael@0 | 114 | if (childFrame) { |
michael@0 | 115 | nsSize availSize(aReflowState.ComputedWidth(), NS_UNCONSTRAINEDSIZE); |
michael@0 | 116 | nsHTMLReflowState childReflowState(aPresContext, aReflowState, |
michael@0 | 117 | childFrame, availSize); |
michael@0 | 118 | rv = ReflowChild(childFrame, aPresContext, aDesiredSize, |
michael@0 | 119 | childReflowState, aStatus); |
michael@0 | 120 | SaveReflowAndBoundingMetricsFor(childFrame, aDesiredSize, |
michael@0 | 121 | aDesiredSize.mBoundingMetrics); |
michael@0 | 122 | mBoundingMetrics = aDesiredSize.mBoundingMetrics; |
michael@0 | 123 | } |
michael@0 | 124 | FinalizeReflow(*aReflowState.rendContext, aDesiredSize); |
michael@0 | 125 | NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize); |
michael@0 | 126 | return rv; |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | // Only place the selected child ... |
michael@0 | 130 | /* virtual */ nsresult |
michael@0 | 131 | nsMathMLSelectedFrame::Place(nsRenderingContext& aRenderingContext, |
michael@0 | 132 | bool aPlaceOrigin, |
michael@0 | 133 | nsHTMLReflowMetrics& aDesiredSize) |
michael@0 | 134 | { |
michael@0 | 135 | nsIFrame* childFrame = GetSelectedFrame(); |
michael@0 | 136 | |
michael@0 | 137 | if (mInvalidMarkup) { |
michael@0 | 138 | return ReflowError(aRenderingContext, aDesiredSize); |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | aDesiredSize.Width() = aDesiredSize.Height() = 0; |
michael@0 | 142 | aDesiredSize.SetTopAscent(0); |
michael@0 | 143 | mBoundingMetrics = nsBoundingMetrics(); |
michael@0 | 144 | if (childFrame) { |
michael@0 | 145 | GetReflowAndBoundingMetricsFor(childFrame, aDesiredSize, mBoundingMetrics); |
michael@0 | 146 | if (aPlaceOrigin) { |
michael@0 | 147 | FinishReflowChild(childFrame, PresContext(), aDesiredSize, nullptr, 0, 0, 0); |
michael@0 | 148 | } |
michael@0 | 149 | mReference.x = 0; |
michael@0 | 150 | mReference.y = aDesiredSize.TopAscent(); |
michael@0 | 151 | } |
michael@0 | 152 | aDesiredSize.mBoundingMetrics = mBoundingMetrics; |
michael@0 | 153 | return NS_OK; |
michael@0 | 154 | } |