2007-06-11 23:10:23 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsMathMLmspaceFrame.h"
|
2013-08-30 14:37:12 -07:00
|
|
|
#include "nsMathMLElement.h"
|
2013-10-07 16:15:59 -07:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// <mspace> -- space - implementation
|
|
|
|
//
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewMathMLmspaceFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsMathMLmspaceFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmspaceFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMathMLmspaceFrame::~nsMathMLmspaceFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMathMLmspaceFrame::IsLeaf() const
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMathMLmspaceFrame::ProcessAttributes(nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
nsAutoString value;
|
|
|
|
|
|
|
|
// width
|
2012-05-15 15:30:14 -07:00
|
|
|
//
|
|
|
|
// "Specifies the desired width of the space."
|
|
|
|
//
|
|
|
|
// values: length
|
|
|
|
// default: 0em
|
|
|
|
//
|
|
|
|
// The default value is "0em", so unitless values can be ignored.
|
|
|
|
// <mspace/> is listed among MathML elements allowing negative spacing and
|
|
|
|
// the MathML test suite contains "Presentation/TokenElements/mspace/mspace2"
|
|
|
|
// as an example. Hence we allow negative values.
|
|
|
|
//
|
2007-03-22 10:30:00 -07:00
|
|
|
mWidth = 0;
|
2014-01-15 07:07:06 -08:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::width, value);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!value.IsEmpty()) {
|
2012-05-15 15:30:14 -07:00
|
|
|
ParseNumericValue(value, &mWidth,
|
|
|
|
nsMathMLElement::PARSE_ALLOW_NEGATIVE,
|
|
|
|
aPresContext, mStyleContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// height
|
2012-05-15 15:30:14 -07:00
|
|
|
//
|
|
|
|
// "Specifies the desired height (above the baseline) of the space."
|
|
|
|
//
|
|
|
|
// values: length
|
|
|
|
// default: 0ex
|
|
|
|
//
|
|
|
|
// The default value is "0ex", so unitless values can be ignored.
|
2012-05-17 06:37:55 -07:00
|
|
|
// We do not allow negative values. See bug 716349.
|
2012-05-15 15:30:14 -07:00
|
|
|
//
|
2007-03-22 10:30:00 -07:00
|
|
|
mHeight = 0;
|
2014-01-15 07:07:06 -08:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::height, value);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!value.IsEmpty()) {
|
2012-05-17 06:37:55 -07:00
|
|
|
ParseNumericValue(value, &mHeight, 0,
|
2012-05-15 15:30:14 -07:00
|
|
|
aPresContext, mStyleContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// depth
|
2012-05-15 15:30:14 -07:00
|
|
|
//
|
|
|
|
// "Specifies the desired depth (below the baseline) of the space."
|
|
|
|
//
|
|
|
|
// values: length
|
|
|
|
// default: 0ex
|
|
|
|
//
|
|
|
|
// The default value is "0ex", so unitless values can be ignored.
|
2012-05-17 06:37:55 -07:00
|
|
|
// We do not allow negative values. See bug 716349.
|
2012-05-15 15:30:14 -07:00
|
|
|
//
|
2007-03-22 10:30:00 -07:00
|
|
|
mDepth = 0;
|
2014-01-15 07:07:06 -08:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::depth_, value);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!value.IsEmpty()) {
|
2012-05-17 06:37:55 -07:00
|
|
|
ParseNumericValue(value, &mDepth, 0,
|
2012-05-15 15:30:14 -07:00
|
|
|
aPresContext, mStyleContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMathMLmspaceFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
ProcessAttributes(aPresContext);
|
|
|
|
|
2011-04-07 18:04:40 -07:00
|
|
|
mBoundingMetrics = nsBoundingMetrics();
|
2013-04-17 04:47:09 -07:00
|
|
|
mBoundingMetrics.width = mWidth;
|
2007-03-22 10:30:00 -07:00
|
|
|
mBoundingMetrics.ascent = mHeight;
|
|
|
|
mBoundingMetrics.descent = mDepth;
|
|
|
|
mBoundingMetrics.leftBearing = 0;
|
2012-05-17 06:37:55 -07:00
|
|
|
mBoundingMetrics.rightBearing = mBoundingMetrics.width;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-12-27 09:59:52 -08:00
|
|
|
aDesiredSize.SetTopAscent(mHeight);
|
|
|
|
aDesiredSize.Width() = std::max(0, mBoundingMetrics.width);
|
|
|
|
aDesiredSize.Height() = aDesiredSize.TopAscent() + mDepth;
|
2007-03-22 10:30:00 -07:00
|
|
|
// Also return our bounding metrics
|
|
|
|
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
|
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-11-29 14:52:02 -08:00
|
|
|
|
|
|
|
/* virtual */ nsresult
|
|
|
|
nsMathMLmspaceFrame::MeasureForWidth(nsRenderingContext& aRenderingContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize)
|
|
|
|
{
|
|
|
|
ProcessAttributes(PresContext());
|
|
|
|
mBoundingMetrics = nsBoundingMetrics();
|
2013-04-17 04:47:09 -07:00
|
|
|
mBoundingMetrics.width = mWidth;
|
2013-12-27 09:59:52 -08:00
|
|
|
aDesiredSize.Width() = std::max(0, mBoundingMetrics.width);
|
2012-11-29 14:52:02 -08:00
|
|
|
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
|
|
|
|
return NS_OK;
|
|
|
|
}
|