2007-03-22 10:30:00 -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 "nsINameSpaceManager.h"
|
|
|
|
#include "nsMathMLFrame.h"
|
|
|
|
#include "nsMathMLChar.h"
|
2009-12-10 23:37:40 -08:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// used to map attributes into CSS rules
|
|
|
|
#include "nsStyleSet.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsDisplayList.h"
|
2011-04-07 18:04:40 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
eMathMLFrameType
|
|
|
|
nsMathMLFrame::GetMathMLFrameType()
|
|
|
|
{
|
|
|
|
// see if it is an embellished operator (mapped to 'Op' in TeX)
|
|
|
|
if (mEmbellishData.coreFrame)
|
|
|
|
return GetMathMLFrameTypeFor(mEmbellishData.coreFrame);
|
|
|
|
|
|
|
|
// if it has a prescribed base, fetch the type from there
|
|
|
|
if (mPresentationData.baseFrame)
|
|
|
|
return GetMathMLFrameTypeFor(mPresentationData.baseFrame);
|
|
|
|
|
|
|
|
// everything else is treated as ordinary (mapped to 'Ord' in TeX)
|
|
|
|
return eMathMLFrameType_Ordinary;
|
|
|
|
}
|
|
|
|
|
2011-07-12 09:06:34 -07:00
|
|
|
// snippet of code used by <mstyle>, <mtable> and <math> which are the only
|
|
|
|
// three tags where the displaystyle attribute is allowed by the spec.
|
2007-03-22 10:30:00 -07:00
|
|
|
/* static */ void
|
|
|
|
nsMathMLFrame::FindAttrDisplaystyle(nsIContent* aContent,
|
|
|
|
nsPresentationData& aPresentationData)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aContent->Tag() == nsGkAtoms::mstyle_ ||
|
2011-07-12 09:06:34 -07:00
|
|
|
aContent->Tag() == nsGkAtoms::mtable_ ||
|
|
|
|
aContent->Tag() == nsGkAtoms::math, "bad caller");
|
2007-03-22 10:30:00 -07:00
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
2012-07-30 07:20:58 -07:00
|
|
|
{&nsGkAtoms::_false, &nsGkAtoms::_true, nullptr};
|
2007-03-22 10:30:00 -07:00
|
|
|
// see if the explicit displaystyle attribute is there
|
|
|
|
switch (aContent->FindAttrValueIn(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::displaystyle_, strings, eCaseMatters)) {
|
|
|
|
case 0:
|
|
|
|
aPresentationData.flags &= ~NS_MATHML_DISPLAYSTYLE;
|
|
|
|
aPresentationData.flags |= NS_MATHML_EXPLICIT_DISPLAYSTYLE;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
aPresentationData.flags |= NS_MATHML_DISPLAYSTYLE;
|
|
|
|
aPresentationData.flags |= NS_MATHML_EXPLICIT_DISPLAYSTYLE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// no reset if the attr isn't found. so be sure to call it on inherited flags
|
|
|
|
}
|
|
|
|
|
2010-01-03 09:52:33 -08:00
|
|
|
// snippet of code used by the tags where the dir attribute is allowed.
|
|
|
|
/* static */ void
|
|
|
|
nsMathMLFrame::FindAttrDirectionality(nsIContent* aContent,
|
|
|
|
nsPresentationData& aPresentationData)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aContent->Tag() == nsGkAtoms::math ||
|
|
|
|
aContent->Tag() == nsGkAtoms::mrow_ ||
|
|
|
|
aContent->Tag() == nsGkAtoms::mstyle_ ||
|
|
|
|
aContent->Tag() == nsGkAtoms::mi_ ||
|
|
|
|
aContent->Tag() == nsGkAtoms::mn_ ||
|
|
|
|
aContent->Tag() == nsGkAtoms::mo_ ||
|
|
|
|
aContent->Tag() == nsGkAtoms::mtext_ ||
|
|
|
|
aContent->Tag() == nsGkAtoms::ms_, "bad caller");
|
|
|
|
|
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
2012-07-30 07:20:58 -07:00
|
|
|
{&nsGkAtoms::ltr, &nsGkAtoms::rtl, nullptr};
|
2010-01-03 09:52:33 -08:00
|
|
|
|
|
|
|
// see if the explicit dir attribute is there
|
|
|
|
switch (aContent->FindAttrValueIn(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::dir, strings, eCaseMatters))
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
aPresentationData.flags &= ~NS_MATHML_RTL;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
aPresentationData.flags |= NS_MATHML_RTL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// no reset if the attr isn't found. so be sure to call it on inherited flags
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMathMLFrame::InheritAutomaticData(nsIFrame* aParent)
|
|
|
|
{
|
|
|
|
mEmbellishData.flags = 0;
|
2012-07-30 07:20:58 -07:00
|
|
|
mEmbellishData.coreFrame = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
mEmbellishData.direction = NS_STRETCH_DIRECTION_UNSUPPORTED;
|
2011-12-21 14:21:59 -08:00
|
|
|
mEmbellishData.leadingSpace = 0;
|
|
|
|
mEmbellishData.trailingSpace = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mPresentationData.flags = 0;
|
2012-07-30 07:20:58 -07:00
|
|
|
mPresentationData.baseFrame = nullptr;
|
|
|
|
mPresentationData.mstyle = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-09 01:38:28 -08:00
|
|
|
// by default, just inherit the display of our parent
|
2007-03-22 10:30:00 -07:00
|
|
|
nsPresentationData parentData;
|
|
|
|
GetPresentationDataFrom(aParent, parentData);
|
|
|
|
mPresentationData.mstyle = parentData.mstyle;
|
|
|
|
if (NS_MATHML_IS_DISPLAYSTYLE(parentData.flags)) {
|
|
|
|
mPresentationData.flags |= NS_MATHML_DISPLAYSTYLE;
|
|
|
|
}
|
2010-01-03 09:52:33 -08:00
|
|
|
if (NS_MATHML_IS_RTL(parentData.flags)) {
|
|
|
|
mPresentationData.flags |= NS_MATHML_RTL;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-25 12:59:42 -07:00
|
|
|
#if defined(DEBUG) && defined(SHOW_BOUNDING_BOX)
|
2007-03-22 10:30:00 -07:00
|
|
|
mPresentationData.flags |= NS_MATHML_SHOW_BOUNDING_METRICS;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2008-01-09 01:38:28 -08:00
|
|
|
nsMathMLFrame::UpdatePresentationData(PRUint32 aFlagsValues,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRUint32 aWhichFlags)
|
|
|
|
{
|
2010-01-03 09:52:33 -08:00
|
|
|
NS_ASSERTION(NS_MATHML_IS_DISPLAYSTYLE(aWhichFlags) ||
|
|
|
|
NS_MATHML_IS_COMPRESSED(aWhichFlags),
|
|
|
|
"aWhichFlags should only be displaystyle or compression flag");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// update flags that are relevant to this call
|
|
|
|
if (NS_MATHML_IS_DISPLAYSTYLE(aWhichFlags)) {
|
|
|
|
// updating the displaystyle flag is allowed
|
|
|
|
if (NS_MATHML_IS_DISPLAYSTYLE(aFlagsValues)) {
|
|
|
|
mPresentationData.flags |= NS_MATHML_DISPLAYSTYLE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mPresentationData.flags &= ~NS_MATHML_DISPLAYSTYLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (NS_MATHML_IS_COMPRESSED(aWhichFlags)) {
|
|
|
|
// updating the compression flag is allowed
|
|
|
|
if (NS_MATHML_IS_COMPRESSED(aFlagsValues)) {
|
|
|
|
// 'compressed' means 'prime' style in App. G, TeXbook
|
|
|
|
mPresentationData.flags |= NS_MATHML_COMPRESSED;
|
|
|
|
}
|
|
|
|
// no else. the flag is sticky. it retains its value once it is set
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper to give a style context suitable for doing the stretching of
|
|
|
|
// a MathMLChar. Frame classes that use this should ensure that the
|
|
|
|
// extra leaf style contexts given to the MathMLChars are accessible to
|
|
|
|
// the Style System via the Get/Set AdditionalStyleContext() APIs.
|
|
|
|
/* static */ void
|
|
|
|
nsMathMLFrame::ResolveMathMLCharStyle(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsStyleContext* aParentStyleContext,
|
|
|
|
nsMathMLChar* aMathMLChar,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIsMutableChar)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-12-10 23:37:40 -08:00
|
|
|
nsCSSPseudoElements::Type pseudoType = (aIsMutableChar) ?
|
|
|
|
nsCSSPseudoElements::ePseudo_mozMathStretchy :
|
|
|
|
nsCSSPseudoElements::ePseudo_mozMathAnonymous; // savings
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRefPtr<nsStyleContext> newStyleContext;
|
|
|
|
newStyleContext = aPresContext->StyleSet()->
|
2010-04-30 06:12:06 -07:00
|
|
|
ResolvePseudoElementStyle(aContent->AsElement(), pseudoType,
|
|
|
|
aParentStyleContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (newStyleContext)
|
|
|
|
aMathMLChar->SetStyleContext(newStyleContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsMathMLFrame::GetEmbellishDataFrom(nsIFrame* aFrame,
|
|
|
|
nsEmbellishData& aEmbellishData)
|
|
|
|
{
|
|
|
|
// initialize OUT params
|
|
|
|
aEmbellishData.flags = 0;
|
2012-07-30 07:20:58 -07:00
|
|
|
aEmbellishData.coreFrame = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
aEmbellishData.direction = NS_STRETCH_DIRECTION_UNSUPPORTED;
|
2011-12-21 14:21:59 -08:00
|
|
|
aEmbellishData.leadingSpace = 0;
|
|
|
|
aEmbellishData.trailingSpace = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aFrame && aFrame->IsFrameOfType(nsIFrame::eMathML)) {
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mathMLFrame) {
|
|
|
|
mathMLFrame->GetEmbellishData(aEmbellishData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// helper to get the presentation data of a frame, by possibly walking up
|
|
|
|
// the frame hierarchy if we happen to be surrounded by non-MathML frames.
|
|
|
|
/* static */ void
|
|
|
|
nsMathMLFrame::GetPresentationDataFrom(nsIFrame* aFrame,
|
|
|
|
nsPresentationData& aPresentationData,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aClimbTree)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// initialize OUT params
|
|
|
|
aPresentationData.flags = 0;
|
2012-07-30 07:20:58 -07:00
|
|
|
aPresentationData.baseFrame = nullptr;
|
|
|
|
aPresentationData.mstyle = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsIFrame* frame = aFrame;
|
|
|
|
while (frame) {
|
|
|
|
if (frame->IsFrameOfType(nsIFrame::eMathML)) {
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(frame);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mathMLFrame) {
|
|
|
|
mathMLFrame->GetPresentationData(aPresentationData);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// stop if the caller doesn't want to lookup beyond the frame
|
|
|
|
if (!aClimbTree) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// stop if we reach the root <math> tag
|
|
|
|
nsIContent* content = frame->GetContent();
|
2008-01-15 21:07:09 -08:00
|
|
|
NS_ASSERTION(content || !frame->GetParent(), // no assert for the root
|
|
|
|
"dangling frame without a content node");
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!content)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (content->Tag() == nsGkAtoms::math) {
|
|
|
|
const nsStyleDisplay* display = frame->GetStyleDisplay();
|
|
|
|
if (display->mDisplay == NS_STYLE_DISPLAY_BLOCK) {
|
|
|
|
aPresentationData.flags |= NS_MATHML_DISPLAYSTYLE;
|
|
|
|
}
|
2011-07-12 09:06:34 -07:00
|
|
|
FindAttrDisplaystyle(content, aPresentationData);
|
2010-01-03 09:52:33 -08:00
|
|
|
FindAttrDirectionality(content, aPresentationData);
|
2011-05-29 14:21:12 -07:00
|
|
|
aPresentationData.mstyle = frame->GetFirstContinuation();
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
frame = frame->GetParent();
|
|
|
|
}
|
2008-01-15 21:07:09 -08:00
|
|
|
NS_WARN_IF_FALSE(frame && frame->GetContent(),
|
|
|
|
"bad MathML markup - could not find the top <math> element");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// helper to get an attribute from the content or the surrounding <mstyle> hierarchy
|
2011-09-28 23:19:26 -07:00
|
|
|
/* static */ bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMathMLFrame::GetAttribute(nsIContent* aContent,
|
|
|
|
nsIFrame* aMathMLmstyleFrame,
|
|
|
|
nsIAtom* aAttributeAtom,
|
|
|
|
nsString& aValue)
|
|
|
|
{
|
|
|
|
// see if we can get the attribute from the content
|
|
|
|
if (aContent && aContent->GetAttr(kNameSpaceID_None, aAttributeAtom,
|
|
|
|
aValue)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// see if we can get the attribute from the mstyle frame
|
|
|
|
if (!aMathMLmstyleFrame) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* mstyleParent = aMathMLmstyleFrame->GetParent();
|
|
|
|
|
|
|
|
nsPresentationData mstyleParentData;
|
2012-07-30 07:20:58 -07:00
|
|
|
mstyleParentData.mstyle = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mstyleParent) {
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(mstyleParent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mathMLFrame) {
|
|
|
|
mathMLFrame->GetPresentationData(mstyleParentData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// recurse all the way up into the <mstyle> hierarchy
|
|
|
|
return GetAttribute(aMathMLmstyleFrame->GetContent(),
|
|
|
|
mstyleParentData.mstyle, aAttributeAtom, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
2011-04-07 18:04:40 -07:00
|
|
|
nsMathMLFrame::GetRuleThickness(nsRenderingContext& aRenderingContext,
|
2011-04-07 18:05:49 -07:00
|
|
|
nsFontMetrics* aFontMetrics,
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord& aRuleThickness)
|
|
|
|
{
|
|
|
|
// get the bounding metrics of the overbar char, the rendering context
|
|
|
|
// is assumed to have been set with the font of the current style context
|
2011-04-07 18:04:40 -07:00
|
|
|
NS_ASSERTION(aRenderingContext.FontMetrics()->Font().
|
|
|
|
Equals(aFontMetrics->Font()),
|
|
|
|
"unexpected state");
|
|
|
|
|
2011-04-07 21:18:43 -07:00
|
|
|
nscoord xHeight = aFontMetrics->XHeight();
|
2007-03-22 10:30:00 -07:00
|
|
|
PRUnichar overBar = 0x00AF;
|
2011-04-07 18:04:40 -07:00
|
|
|
nsBoundingMetrics bm = aRenderingContext.GetBoundingMetrics(&overBar, 1);
|
|
|
|
aRuleThickness = bm.ascent + bm.descent;
|
|
|
|
if (aRuleThickness <= 0 || aRuleThickness >= xHeight) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// fall-back to the other version
|
|
|
|
GetRuleThickness(aFontMetrics, aRuleThickness);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
2011-04-07 18:04:40 -07:00
|
|
|
nsMathMLFrame::GetAxisHeight(nsRenderingContext& aRenderingContext,
|
2011-04-07 18:05:49 -07:00
|
|
|
nsFontMetrics* aFontMetrics,
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord& aAxisHeight)
|
|
|
|
{
|
|
|
|
// get the bounding metrics of the minus sign, the rendering context
|
|
|
|
// is assumed to have been set with the font of the current style context
|
2011-04-07 18:04:40 -07:00
|
|
|
NS_ASSERTION(aRenderingContext.FontMetrics()->Font().
|
|
|
|
Equals(aFontMetrics->Font()),
|
|
|
|
"unexpected state");
|
|
|
|
|
2011-04-07 21:18:43 -07:00
|
|
|
nscoord xHeight = aFontMetrics->XHeight();
|
2007-03-22 10:30:00 -07:00
|
|
|
PRUnichar minus = 0x2212; // not '-', but official Unicode minus sign
|
2011-04-07 18:04:40 -07:00
|
|
|
nsBoundingMetrics bm = aRenderingContext.GetBoundingMetrics(&minus, 1);
|
|
|
|
aAxisHeight = bm.ascent - (bm.ascent + bm.descent)/2;
|
|
|
|
if (aAxisHeight <= 0 || aAxisHeight >= xHeight) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// fall-back to the other version
|
|
|
|
GetAxisHeight(aFontMetrics, aAxisHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nscoord
|
|
|
|
nsMathMLFrame::CalcLength(nsPresContext* aPresContext,
|
|
|
|
nsStyleContext* aStyleContext,
|
|
|
|
const nsCSSValue& aCSSValue)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aCSSValue.IsLengthUnit(), "not a length unit");
|
|
|
|
|
|
|
|
if (aCSSValue.IsFixedLengthUnit()) {
|
2010-08-13 02:58:01 -07:00
|
|
|
return aCSSValue.GetFixedLength(aPresContext);
|
|
|
|
}
|
|
|
|
if (aCSSValue.IsPixelLengthUnit()) {
|
|
|
|
return aCSSValue.GetPixelLength();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSUnit unit = aCSSValue.GetUnit();
|
|
|
|
|
2010-08-13 02:58:01 -07:00
|
|
|
if (eCSSUnit_EM == unit) {
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsStyleFont* font = aStyleContext->GetStyleFont();
|
|
|
|
return NSToCoordRound(aCSSValue.GetFloatValue() * (float)font->mFont.size);
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_XHeight == unit) {
|
2011-08-14 10:08:04 -07:00
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
|
|
|
nsLayoutUtils::GetFontMetricsForStyleContext(aStyleContext,
|
|
|
|
getter_AddRefs(fm));
|
2011-04-07 21:18:43 -07:00
|
|
|
nscoord xHeight = fm->XHeight();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NSToCoordRound(aCSSValue.GetFloatValue() * (float)xHeight);
|
|
|
|
}
|
|
|
|
|
2010-08-13 02:58:01 -07:00
|
|
|
// MathML doesn't specify other CSS units such as rem or ch
|
|
|
|
NS_ERROR("Unsupported unit");
|
2007-03-22 10:30:00 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-15 15:30:14 -07:00
|
|
|
/* static */ void
|
|
|
|
nsMathMLFrame::ParseNumericValue(const nsString& aString,
|
|
|
|
nscoord* aLengthValue,
|
|
|
|
PRUint32 aFlags,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsStyleContext* aStyleContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-05-15 15:30:14 -07:00
|
|
|
nsCSSValue cssValue;
|
|
|
|
|
|
|
|
if (!nsMathMLElement::ParseNumericValue(aString, cssValue, aFlags)) {
|
|
|
|
// Invalid attribute value. aLengthValue remains unchanged, so the default
|
|
|
|
// length value is used.
|
|
|
|
return;
|
2011-06-22 08:55:05 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-15 15:30:14 -07:00
|
|
|
nsCSSUnit unit = cssValue.GetUnit();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-15 15:30:14 -07:00
|
|
|
if (unit == eCSSUnit_Percent || unit == eCSSUnit_Number) {
|
|
|
|
// Relative units. A multiple of the default length value is used.
|
|
|
|
*aLengthValue = NSToCoordRound(*aLengthValue * (unit == eCSSUnit_Percent ?
|
|
|
|
cssValue.GetPercentValue() :
|
|
|
|
cssValue.GetFloatValue()));
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-05-15 15:30:14 -07:00
|
|
|
|
|
|
|
// Absolute units.
|
|
|
|
*aLengthValue = CalcLength(aPresContext, aStyleContext, cssValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// ================
|
|
|
|
// Utils to map attributes into CSS rules (work-around to bug 69409 which
|
|
|
|
// is not scheduled to be fixed anytime soon)
|
|
|
|
//
|
|
|
|
|
|
|
|
static const PRInt32 kMathMLversion1 = 1;
|
|
|
|
static const PRInt32 kMathMLversion2 = 2;
|
|
|
|
|
|
|
|
struct
|
|
|
|
nsCSSMapping {
|
|
|
|
PRInt32 compatibility;
|
|
|
|
const nsIAtom* attrAtom;
|
|
|
|
const char* cssProperty;
|
|
|
|
};
|
|
|
|
|
2012-06-25 12:59:42 -07:00
|
|
|
#if defined(DEBUG) && defined(SHOW_BOUNDING_BOX)
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsDisplayMathMLBoundingMetrics : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayMathMLBoundingMetrics(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, const nsRect& aRect)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame), mRect(aRect) {
|
2007-03-22 10:30:00 -07:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayMathMLBoundingMetrics);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayMathMLBoundingMetrics() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayMathMLBoundingMetrics);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-06 17:35:14 -07:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx);
|
2010-07-15 14:07:49 -07:00
|
|
|
NS_DISPLAY_DECL_NAME("MathMLBoundingMetrics", TYPE_MATHML_BOUNDING_METRICS)
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
|
|
|
nsRect mRect;
|
|
|
|
};
|
|
|
|
|
|
|
|
void nsDisplayMathMLBoundingMetrics::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aCtx->SetColor(NS_RGB(0,0,255));
|
2010-08-13 03:01:58 -07:00
|
|
|
aCtx->DrawRect(mRect + ToReferenceFrame());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsMathMLFrame::DisplayBoundingMetrics(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, const nsPoint& aPt,
|
|
|
|
const nsBoundingMetrics& aMetrics,
|
|
|
|
const nsDisplayListSet& aLists) {
|
|
|
|
if (!NS_MATHML_PAINT_BOUNDING_METRICS(mPresentationData.flags))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nscoord x = aPt.x + aMetrics.leftBearing;
|
|
|
|
nscoord y = aPt.y - aMetrics.ascent;
|
|
|
|
nscoord w = aMetrics.rightBearing - aMetrics.leftBearing;
|
|
|
|
nscoord h = aMetrics.ascent + aMetrics.descent;
|
|
|
|
|
|
|
|
return aLists.Content()->AppendNewToTop(new (aBuilder)
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayMathMLBoundingMetrics(aBuilder, this, nsRect(x,y,w,h)));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class nsDisplayMathMLBar : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayMathMLBar(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, const nsRect& aRect)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame), mRect(aRect) {
|
2007-03-22 10:30:00 -07:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayMathMLBar);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayMathMLBar() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayMathMLBar);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-06 17:35:14 -07:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx);
|
2010-07-15 14:07:49 -07:00
|
|
|
NS_DISPLAY_DECL_NAME("MathMLBar", TYPE_MATHML_BAR)
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
|
|
|
nsRect mRect;
|
|
|
|
};
|
|
|
|
|
|
|
|
void nsDisplayMathMLBar::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// paint the bar with the current text color
|
2011-10-29 00:04:20 -07:00
|
|
|
aCtx->SetColor(mFrame->GetVisitedDependentColor(eCSSProperty_color));
|
2010-08-13 03:01:58 -07:00
|
|
|
aCtx->FillRect(mRect + ToReferenceFrame());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsMathMLFrame::DisplayBar(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, const nsRect& aRect,
|
|
|
|
const nsDisplayListSet& aLists) {
|
|
|
|
if (!aFrame->GetStyleVisibility()->IsVisible() || aRect.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
return aLists.Content()->AppendNewToTop(new (aBuilder)
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayMathMLBar(aBuilder, aFrame, aRect));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|