1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/mathml/nsMathMLSelectedFrame.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,154 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "nsMathMLSelectedFrame.h" 1.10 +#include "nsDisplayList.h" 1.11 + 1.12 +nsMathMLSelectedFrame::~nsMathMLSelectedFrame() 1.13 +{ 1.14 +} 1.15 + 1.16 +void 1.17 +nsMathMLSelectedFrame::Init(nsIContent* aContent, 1.18 + nsIFrame* aParent, 1.19 + nsIFrame* aPrevInFlow) 1.20 +{ 1.21 + // Init our local attributes 1.22 + mInvalidMarkup = false; 1.23 + mSelectedFrame = nullptr; 1.24 + 1.25 + // Let the base class do the rest 1.26 + nsMathMLContainerFrame::Init(aContent, aParent, aPrevInFlow); 1.27 +} 1.28 + 1.29 +NS_IMETHODIMP 1.30 +nsMathMLSelectedFrame::TransmitAutomaticData() 1.31 +{ 1.32 + // Note that to determine space-like and embellished op properties: 1.33 + // - <semantics> behaves the same as <maction> 1.34 + // - <annotation-xml> behaves the same as <mrow> 1.35 + 1.36 + // The REC defines the following element to be space-like: 1.37 + // * an maction element whose selected sub-expression exists and is 1.38 + // space-like; 1.39 + nsIMathMLFrame* mathMLFrame = do_QueryFrame(mSelectedFrame); 1.40 + if (mathMLFrame && mathMLFrame->IsSpaceLike()) { 1.41 + mPresentationData.flags |= NS_MATHML_SPACE_LIKE; 1.42 + } else { 1.43 + mPresentationData.flags &= ~NS_MATHML_SPACE_LIKE; 1.44 + } 1.45 + 1.46 + // The REC defines the following element to be an embellished operator: 1.47 + // * an maction element whose selected sub-expression exists and is an 1.48 + // embellished operator; 1.49 + mPresentationData.baseFrame = mSelectedFrame; 1.50 + GetEmbellishDataFrom(mSelectedFrame, mEmbellishData); 1.51 + 1.52 + return NS_OK; 1.53 +} 1.54 + 1.55 +nsresult 1.56 +nsMathMLSelectedFrame::ChildListChanged(int32_t aModType) 1.57 +{ 1.58 + GetSelectedFrame(); 1.59 + return nsMathMLContainerFrame::ChildListChanged(aModType); 1.60 +} 1.61 + 1.62 +nsresult 1.63 +nsMathMLSelectedFrame::SetInitialChildList(ChildListID aListID, 1.64 + nsFrameList& aChildList) 1.65 +{ 1.66 + nsresult rv = nsMathMLContainerFrame::SetInitialChildList(aListID, 1.67 + aChildList); 1.68 + // This very first call to GetSelectedFrame() will cause us to be marked as an 1.69 + // embellished operator if the selected child is an embellished operator 1.70 + GetSelectedFrame(); 1.71 + return rv; 1.72 +} 1.73 + 1.74 +// Only paint the selected child... 1.75 +void 1.76 +nsMathMLSelectedFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, 1.77 + const nsRect& aDirtyRect, 1.78 + const nsDisplayListSet& aLists) 1.79 +{ 1.80 + // Report an error if something wrong was found in this frame. 1.81 + // We can't call nsDisplayMathMLError from here, 1.82 + // so ask nsMathMLContainerFrame to do the work for us. 1.83 + if (NS_MATHML_HAS_ERROR(mPresentationData.flags)) { 1.84 + nsMathMLContainerFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists); 1.85 + return; 1.86 + } 1.87 + 1.88 + DisplayBorderBackgroundOutline(aBuilder, aLists); 1.89 + 1.90 + nsIFrame* childFrame = GetSelectedFrame(); 1.91 + if (childFrame) { 1.92 + // Put the child's background directly onto the content list 1.93 + nsDisplayListSet set(aLists, aLists.Content()); 1.94 + // The children should be in content order 1.95 + BuildDisplayListForChild(aBuilder, childFrame, aDirtyRect, set); 1.96 + } 1.97 + 1.98 +#if defined(DEBUG) && defined(SHOW_BOUNDING_BOX) 1.99 + // visual debug 1.100 + DisplayBoundingMetrics(aBuilder, this, mReference, mBoundingMetrics, aLists); 1.101 +#endif 1.102 +} 1.103 + 1.104 +// Only reflow the selected child ... 1.105 +nsresult 1.106 +nsMathMLSelectedFrame::Reflow(nsPresContext* aPresContext, 1.107 + nsHTMLReflowMetrics& aDesiredSize, 1.108 + const nsHTMLReflowState& aReflowState, 1.109 + nsReflowStatus& aStatus) 1.110 +{ 1.111 + nsresult rv = NS_OK; 1.112 + aStatus = NS_FRAME_COMPLETE; 1.113 + aDesiredSize.Width() = aDesiredSize.Height() = 0; 1.114 + aDesiredSize.SetTopAscent(0); 1.115 + mBoundingMetrics = nsBoundingMetrics(); 1.116 + nsIFrame* childFrame = GetSelectedFrame(); 1.117 + if (childFrame) { 1.118 + nsSize availSize(aReflowState.ComputedWidth(), NS_UNCONSTRAINEDSIZE); 1.119 + nsHTMLReflowState childReflowState(aPresContext, aReflowState, 1.120 + childFrame, availSize); 1.121 + rv = ReflowChild(childFrame, aPresContext, aDesiredSize, 1.122 + childReflowState, aStatus); 1.123 + SaveReflowAndBoundingMetricsFor(childFrame, aDesiredSize, 1.124 + aDesiredSize.mBoundingMetrics); 1.125 + mBoundingMetrics = aDesiredSize.mBoundingMetrics; 1.126 + } 1.127 + FinalizeReflow(*aReflowState.rendContext, aDesiredSize); 1.128 + NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize); 1.129 + return rv; 1.130 +} 1.131 + 1.132 +// Only place the selected child ... 1.133 +/* virtual */ nsresult 1.134 +nsMathMLSelectedFrame::Place(nsRenderingContext& aRenderingContext, 1.135 + bool aPlaceOrigin, 1.136 + nsHTMLReflowMetrics& aDesiredSize) 1.137 +{ 1.138 + nsIFrame* childFrame = GetSelectedFrame(); 1.139 + 1.140 + if (mInvalidMarkup) { 1.141 + return ReflowError(aRenderingContext, aDesiredSize); 1.142 + } 1.143 + 1.144 + aDesiredSize.Width() = aDesiredSize.Height() = 0; 1.145 + aDesiredSize.SetTopAscent(0); 1.146 + mBoundingMetrics = nsBoundingMetrics(); 1.147 + if (childFrame) { 1.148 + GetReflowAndBoundingMetricsFor(childFrame, aDesiredSize, mBoundingMetrics); 1.149 + if (aPlaceOrigin) { 1.150 + FinishReflowChild(childFrame, PresContext(), aDesiredSize, nullptr, 0, 0, 0); 1.151 + } 1.152 + mReference.x = 0; 1.153 + mReference.y = aDesiredSize.TopAscent(); 1.154 + } 1.155 + aDesiredSize.mBoundingMetrics = mBoundingMetrics; 1.156 + return NS_OK; 1.157 +}