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 "nsCOMPtr.h"
|
|
|
|
#include "nsFrame.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsStyleContext.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
|
|
|
|
#include "nsMathMLmspaceFrame.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;
|
|
|
|
GetAttribute(mContent, mPresentationData.mstyle, nsGkAtoms::width,
|
|
|
|
value);
|
|
|
|
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;
|
|
|
|
GetAttribute(mContent, mPresentationData.mstyle, nsGkAtoms::height,
|
|
|
|
value);
|
|
|
|
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;
|
|
|
|
GetAttribute(mContent, mPresentationData.mstyle, nsGkAtoms::depth_,
|
|
|
|
value);
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
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
|
|
|
|
|
|
|
aDesiredSize.ascent = mHeight;
|
2013-04-17 04:47:09 -07:00
|
|
|
aDesiredSize.width = std::max(0, mBoundingMetrics.width);
|
2007-03-22 10:30:00 -07:00
|
|
|
aDesiredSize.height = aDesiredSize.ascent + mDepth;
|
|
|
|
// 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;
|
|
|
|
aDesiredSize.width = std::max(0, mBoundingMetrics.width);
|
2012-11-29 14:52:02 -08:00
|
|
|
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
|
|
|
|
return NS_OK;
|
|
|
|
}
|