gecko-dev/layout/mathml/nsMathMLmspaceFrame.cpp

141 строка
3.9 KiB
C++
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2012-05-21 15:12:37 +04: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/. */
2000-01-27 15:31:12 +03:00
#include "nsCOMPtr.h"
#include "nsFrame.h"
#include "nsPresContext.h"
#include "nsStyleContext.h"
2000-01-27 15:31:12 +03:00
#include "nsStyleConsts.h"
#include "nsMathMLmspaceFrame.h"
#include <algorithm>
2000-01-27 15:31:12 +03:00
//
// <mspace> -- space - implementation
//
nsIFrame*
NS_NewMathMLmspaceFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
2000-01-27 15:31:12 +03:00
{
return new (aPresShell) nsMathMLmspaceFrame(aContext);
2000-01-27 15:31:12 +03:00
}
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmspaceFrame)
2000-01-27 15:31:12 +03:00
nsMathMLmspaceFrame::~nsMathMLmspaceFrame()
{
}
bool
nsMathMLmspaceFrame::IsLeaf() const
{
return true;
}
void
nsMathMLmspaceFrame::ProcessAttributes(nsPresContext* aPresContext)
2000-01-27 15:31:12 +03:00
{
nsAutoString value;
// width
//
// "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.
//
2000-01-27 15:31:12 +03:00
mWidth = 0;
GetAttribute(mContent, mPresentationData.mstyle, nsGkAtoms::width,
value);
if (!value.IsEmpty()) {
ParseNumericValue(value, &mWidth,
nsMathMLElement::PARSE_ALLOW_NEGATIVE,
aPresContext, mStyleContext);
2000-01-27 15:31:12 +03:00
}
// height
//
// "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.
// We do not allow negative values. See bug 716349.
//
2000-01-27 15:31:12 +03:00
mHeight = 0;
GetAttribute(mContent, mPresentationData.mstyle, nsGkAtoms::height,
value);
if (!value.IsEmpty()) {
ParseNumericValue(value, &mHeight, 0,
aPresContext, mStyleContext);
2000-01-27 15:31:12 +03:00
}
// depth
//
// "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.
// We do not allow negative values. See bug 716349.
//
2000-01-27 15:31:12 +03:00
mDepth = 0;
GetAttribute(mContent, mPresentationData.mstyle, nsGkAtoms::depth_,
value);
if (!value.IsEmpty()) {
ParseNumericValue(value, &mDepth, 0,
aPresContext, mStyleContext);
2000-01-27 15:31:12 +03:00
}
}
NS_IMETHODIMP
nsMathMLmspaceFrame::Reflow(nsPresContext* aPresContext,
2000-01-27 15:31:12 +03:00
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus)
{
ProcessAttributes(aPresContext);
// nsLineLayout doesn't expect negative widths.
// XXXfredw Negative spaces are not implemented. See bug 717546
mBoundingMetrics = nsBoundingMetrics();
mBoundingMetrics.width = std::max(0, mWidth);
2000-01-27 15:31:12 +03:00
mBoundingMetrics.ascent = mHeight;
mBoundingMetrics.descent = mDepth;
mBoundingMetrics.leftBearing = 0;
mBoundingMetrics.rightBearing = mBoundingMetrics.width;
2000-01-27 15:31:12 +03:00
aDesiredSize.ascent = mHeight;
aDesiredSize.width = mBoundingMetrics.width;
aDesiredSize.height = aDesiredSize.ascent + mDepth;
2000-01-27 15:31:12 +03:00
// Also return our bounding metrics
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
aStatus = NS_FRAME_COMPLETE;
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
2000-01-27 15:31:12 +03:00
return NS_OK;
}
/* virtual */ nsresult
nsMathMLmspaceFrame::MeasureForWidth(nsRenderingContext& aRenderingContext,
nsHTMLReflowMetrics& aDesiredSize)
{
ProcessAttributes(PresContext());
mBoundingMetrics = nsBoundingMetrics();
mBoundingMetrics.width = std::max(0, mWidth);
aDesiredSize.width = mBoundingMetrics.width;
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
return NS_OK;
}