1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/mathml/nsMathMLmspaceFrame.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,130 @@ 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 "nsMathMLmspaceFrame.h" 1.10 +#include "nsMathMLElement.h" 1.11 +#include "mozilla/gfx/2D.h" 1.12 +#include <algorithm> 1.13 + 1.14 + 1.15 +// 1.16 +// <mspace> -- space - implementation 1.17 +// 1.18 + 1.19 +nsIFrame* 1.20 +NS_NewMathMLmspaceFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) 1.21 +{ 1.22 + return new (aPresShell) nsMathMLmspaceFrame(aContext); 1.23 +} 1.24 + 1.25 +NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmspaceFrame) 1.26 + 1.27 +nsMathMLmspaceFrame::~nsMathMLmspaceFrame() 1.28 +{ 1.29 +} 1.30 + 1.31 +bool 1.32 +nsMathMLmspaceFrame::IsLeaf() const 1.33 +{ 1.34 + return true; 1.35 +} 1.36 + 1.37 +void 1.38 +nsMathMLmspaceFrame::ProcessAttributes(nsPresContext* aPresContext) 1.39 +{ 1.40 + nsAutoString value; 1.41 + 1.42 + // width 1.43 + // 1.44 + // "Specifies the desired width of the space." 1.45 + // 1.46 + // values: length 1.47 + // default: 0em 1.48 + // 1.49 + // The default value is "0em", so unitless values can be ignored. 1.50 + // <mspace/> is listed among MathML elements allowing negative spacing and 1.51 + // the MathML test suite contains "Presentation/TokenElements/mspace/mspace2" 1.52 + // as an example. Hence we allow negative values. 1.53 + // 1.54 + mWidth = 0; 1.55 + mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::width, value); 1.56 + if (!value.IsEmpty()) { 1.57 + ParseNumericValue(value, &mWidth, 1.58 + nsMathMLElement::PARSE_ALLOW_NEGATIVE, 1.59 + aPresContext, mStyleContext); 1.60 + } 1.61 + 1.62 + // height 1.63 + // 1.64 + // "Specifies the desired height (above the baseline) of the space." 1.65 + // 1.66 + // values: length 1.67 + // default: 0ex 1.68 + // 1.69 + // The default value is "0ex", so unitless values can be ignored. 1.70 + // We do not allow negative values. See bug 716349. 1.71 + // 1.72 + mHeight = 0; 1.73 + mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::height, value); 1.74 + if (!value.IsEmpty()) { 1.75 + ParseNumericValue(value, &mHeight, 0, 1.76 + aPresContext, mStyleContext); 1.77 + } 1.78 + 1.79 + // depth 1.80 + // 1.81 + // "Specifies the desired depth (below the baseline) of the space." 1.82 + // 1.83 + // values: length 1.84 + // default: 0ex 1.85 + // 1.86 + // The default value is "0ex", so unitless values can be ignored. 1.87 + // We do not allow negative values. See bug 716349. 1.88 + // 1.89 + mDepth = 0; 1.90 + mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::depth_, value); 1.91 + if (!value.IsEmpty()) { 1.92 + ParseNumericValue(value, &mDepth, 0, 1.93 + aPresContext, mStyleContext); 1.94 + } 1.95 +} 1.96 + 1.97 +nsresult 1.98 +nsMathMLmspaceFrame::Reflow(nsPresContext* aPresContext, 1.99 + nsHTMLReflowMetrics& aDesiredSize, 1.100 + const nsHTMLReflowState& aReflowState, 1.101 + nsReflowStatus& aStatus) 1.102 +{ 1.103 + ProcessAttributes(aPresContext); 1.104 + 1.105 + mBoundingMetrics = nsBoundingMetrics(); 1.106 + mBoundingMetrics.width = mWidth; 1.107 + mBoundingMetrics.ascent = mHeight; 1.108 + mBoundingMetrics.descent = mDepth; 1.109 + mBoundingMetrics.leftBearing = 0; 1.110 + mBoundingMetrics.rightBearing = mBoundingMetrics.width; 1.111 + 1.112 + aDesiredSize.SetTopAscent(mHeight); 1.113 + aDesiredSize.Width() = std::max(0, mBoundingMetrics.width); 1.114 + aDesiredSize.Height() = aDesiredSize.TopAscent() + mDepth; 1.115 + // Also return our bounding metrics 1.116 + aDesiredSize.mBoundingMetrics = mBoundingMetrics; 1.117 + 1.118 + aStatus = NS_FRAME_COMPLETE; 1.119 + NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize); 1.120 + return NS_OK; 1.121 +} 1.122 + 1.123 +/* virtual */ nsresult 1.124 +nsMathMLmspaceFrame::MeasureForWidth(nsRenderingContext& aRenderingContext, 1.125 + nsHTMLReflowMetrics& aDesiredSize) 1.126 +{ 1.127 + ProcessAttributes(PresContext()); 1.128 + mBoundingMetrics = nsBoundingMetrics(); 1.129 + mBoundingMetrics.width = mWidth; 1.130 + aDesiredSize.Width() = std::max(0, mBoundingMetrics.width); 1.131 + aDesiredSize.mBoundingMetrics = mBoundingMetrics; 1.132 + return NS_OK; 1.133 +}