2004-02-24 00:29:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2004-04-18 18:30:37 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
2001-02-23 19:09:14 +03:00
|
|
|
* The Original Code is Mozilla MathML Project.
|
2004-04-18 18:30:37 +04:00
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* The University Of Queensland.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2001-02-23 19:09:14 +03:00
|
|
|
* Roger B. Sidje <rbs@maths.uq.edu.au>
|
2004-04-18 18:30:37 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-02-23 19:09:14 +03:00
|
|
|
|
2002-01-09 21:51:30 +03:00
|
|
|
#include "nsINameSpaceManager.h"
|
2001-02-23 19:09:14 +03:00
|
|
|
#include "nsMathMLFrame.h"
|
2002-01-09 21:51:30 +03:00
|
|
|
#include "nsMathMLChar.h"
|
2009-12-11 10:37:40 +03:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2001-02-23 19:09:14 +03:00
|
|
|
|
2002-02-14 15:26:43 +03:00
|
|
|
// used to map attributes into CSS rules
|
2004-01-08 01:30:53 +03:00
|
|
|
#include "nsStyleSet.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
2011-04-08 05:04:40 +04:00
|
|
|
#include "nsRenderingContext.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2006-08-15 08:49:43 +04: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 20:06:34 +04: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.
|
2006-09-19 08:43:14 +04:00
|
|
|
/* static */ void
|
|
|
|
nsMathMLFrame::FindAttrDisplaystyle(nsIContent* aContent,
|
|
|
|
nsPresentationData& aPresentationData)
|
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
NS_ASSERTION(aContent->Tag() == nsGkAtoms::mstyle_ ||
|
2011-07-12 20:06:34 +04:00
|
|
|
aContent->Tag() == nsGkAtoms::mtable_ ||
|
|
|
|
aContent->Tag() == nsGkAtoms::math, "bad caller");
|
2006-09-19 08:43:14 +04:00
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
2006-12-26 20:47:52 +03:00
|
|
|
{&nsGkAtoms::_false, &nsGkAtoms::_true, nsnull};
|
2006-09-19 08:43:14 +04:00
|
|
|
// see if the explicit displaystyle attribute is there
|
|
|
|
switch (aContent->FindAttrValueIn(kNameSpaceID_None,
|
2006-12-26 20:47:52 +03:00
|
|
|
nsGkAtoms::displaystyle_, strings, eCaseMatters)) {
|
2006-09-19 08:43:14 +04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2002-02-01 18:10:50 +03:00
|
|
|
NS_IMETHODIMP
|
2005-02-07 04:57:50 +03:00
|
|
|
nsMathMLFrame::InheritAutomaticData(nsIFrame* aParent)
|
2002-02-01 18:10:50 +03:00
|
|
|
{
|
2002-02-02 08:43:03 +03:00
|
|
|
mEmbellishData.flags = 0;
|
2002-02-01 18:10:50 +03:00
|
|
|
mEmbellishData.coreFrame = nsnull;
|
|
|
|
mEmbellishData.direction = NS_STRETCH_DIRECTION_UNSUPPORTED;
|
2002-02-07 07:38:08 +03:00
|
|
|
mEmbellishData.leftSpace = 0;
|
|
|
|
mEmbellishData.rightSpace = 0;
|
|
|
|
|
|
|
|
mPresentationData.flags = 0;
|
2005-09-07 03:47:01 +04:00
|
|
|
mPresentationData.baseFrame = nsnull;
|
2002-02-07 07:38:08 +03:00
|
|
|
mPresentationData.mstyle = nsnull;
|
2002-02-01 18:10:50 +03:00
|
|
|
|
2008-01-09 12:38:28 +03:00
|
|
|
// by default, just inherit the display of our parent
|
2002-02-07 07:38:08 +03:00
|
|
|
nsPresentationData parentData;
|
|
|
|
GetPresentationDataFrom(aParent, parentData);
|
|
|
|
mPresentationData.mstyle = parentData.mstyle;
|
|
|
|
if (NS_MATHML_IS_DISPLAYSTYLE(parentData.flags)) {
|
|
|
|
mPresentationData.flags |= NS_MATHML_DISPLAYSTYLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(NS_DEBUG) && defined(SHOW_BOUNDING_BOX)
|
|
|
|
mPresentationData.flags |= NS_MATHML_SHOW_BOUNDING_METRICS;
|
|
|
|
#endif
|
|
|
|
|
2002-02-01 18:10:50 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-02-23 19:09:14 +03:00
|
|
|
NS_IMETHODIMP
|
2008-01-09 12:38:28 +03:00
|
|
|
nsMathMLFrame::UpdatePresentationData(PRUint32 aFlagsValues,
|
2006-09-19 08:43:14 +04:00
|
|
|
PRUint32 aWhichFlags)
|
2001-02-23 19:09:14 +03:00
|
|
|
{
|
|
|
|
// update flags that are relevant to this call
|
2006-09-19 08:43:14 +04:00
|
|
|
if (NS_MATHML_IS_DISPLAYSTYLE(aWhichFlags)) {
|
2001-02-23 19:09:14 +03:00
|
|
|
// updating the displaystyle flag is allowed
|
|
|
|
if (NS_MATHML_IS_DISPLAYSTYLE(aFlagsValues)) {
|
|
|
|
mPresentationData.flags |= NS_MATHML_DISPLAYSTYLE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mPresentationData.flags &= ~NS_MATHML_DISPLAYSTYLE;
|
|
|
|
}
|
|
|
|
}
|
2006-09-19 08:43:14 +04:00
|
|
|
if (NS_MATHML_IS_COMPRESSED(aWhichFlags)) {
|
2001-02-23 19:09:14 +03:00
|
|
|
// 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;
|
|
|
|
}
|
2002-01-09 21:51:30 +03:00
|
|
|
|
|
|
|
// Helper to give a style context suitable for doing the stretching of
|
|
|
|
// a MathMLChar. Frame classes that use this should ensure that the
|
2005-11-21 01:05:24 +03:00
|
|
|
// extra leaf style contexts given to the MathMLChars are accessible to
|
2002-01-09 21:51:30 +03:00
|
|
|
// the Style System via the Get/Set AdditionalStyleContext() APIs.
|
2002-02-07 07:38:08 +03:00
|
|
|
/* static */ void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsMathMLFrame::ResolveMathMLCharStyle(nsPresContext* aPresContext,
|
2002-01-09 21:51:30 +03:00
|
|
|
nsIContent* aContent,
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* aParentStyleContext,
|
2002-02-07 07:38:08 +03:00
|
|
|
nsMathMLChar* aMathMLChar,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsMutableChar)
|
2002-01-09 21:51:30 +03:00
|
|
|
{
|
2009-12-11 10:37:40 +03:00
|
|
|
nsCSSPseudoElements::Type pseudoType = (aIsMutableChar) ?
|
|
|
|
nsCSSPseudoElements::ePseudo_mozMathStretchy :
|
|
|
|
nsCSSPseudoElements::ePseudo_mozMathAnonymous; // savings
|
2003-02-22 03:32:13 +03:00
|
|
|
nsRefPtr<nsStyleContext> newStyleContext;
|
2004-01-28 03:18:22 +03:00
|
|
|
newStyleContext = aPresContext->StyleSet()->
|
2010-04-30 17:12:06 +04:00
|
|
|
ResolvePseudoElementStyle(aContent->AsElement(), pseudoType,
|
|
|
|
aParentStyleContext);
|
2004-01-28 03:18:22 +03:00
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
if (newStyleContext)
|
2002-01-09 21:51:30 +03:00
|
|
|
aMathMLChar->SetStyleContext(newStyleContext);
|
2002-02-07 07:38:08 +03:00
|
|
|
}
|
2002-01-09 21:51:30 +03:00
|
|
|
|
2002-02-07 07:38:08 +03:00
|
|
|
/* static */ void
|
|
|
|
nsMathMLFrame::GetEmbellishDataFrom(nsIFrame* aFrame,
|
|
|
|
nsEmbellishData& aEmbellishData)
|
|
|
|
{
|
|
|
|
// initialize OUT params
|
|
|
|
aEmbellishData.flags = 0;
|
|
|
|
aEmbellishData.coreFrame = nsnull;
|
|
|
|
aEmbellishData.direction = NS_STRETCH_DIRECTION_UNSUPPORTED;
|
|
|
|
aEmbellishData.leftSpace = 0;
|
|
|
|
aEmbellishData.rightSpace = 0;
|
|
|
|
|
2006-08-15 08:49:43 +04:00
|
|
|
if (aFrame && aFrame->IsFrameOfType(nsIFrame::eMathML)) {
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(aFrame);
|
2002-02-07 07:38:08 +03:00
|
|
|
if (mathMLFrame) {
|
|
|
|
mathMLFrame->GetEmbellishData(aEmbellishData);
|
|
|
|
}
|
|
|
|
}
|
2002-01-09 21:51:30 +03:00
|
|
|
}
|
|
|
|
|
2002-01-12 11:06:08 +03:00
|
|
|
// 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,
|
2002-02-07 07:38:08 +03:00
|
|
|
nsPresentationData& aPresentationData,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aClimbTree)
|
2002-01-12 11:06:08 +03:00
|
|
|
{
|
2002-02-07 07:38:08 +03:00
|
|
|
// initialize OUT params
|
|
|
|
aPresentationData.flags = 0;
|
2005-09-07 03:47:01 +04:00
|
|
|
aPresentationData.baseFrame = nsnull;
|
2002-02-07 07:38:08 +03:00
|
|
|
aPresentationData.mstyle = nsnull;
|
|
|
|
|
2002-01-12 11:06:08 +03:00
|
|
|
nsIFrame* frame = aFrame;
|
|
|
|
while (frame) {
|
2006-08-15 08:49:43 +04:00
|
|
|
if (frame->IsFrameOfType(nsIFrame::eMathML)) {
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(frame);
|
2006-08-15 08:49:43 +04:00
|
|
|
if (mathMLFrame) {
|
|
|
|
mathMLFrame->GetPresentationData(aPresentationData);
|
|
|
|
break;
|
|
|
|
}
|
2002-02-07 07:38:08 +03:00
|
|
|
}
|
|
|
|
// stop if the caller doesn't want to lookup beyond the frame
|
|
|
|
if (!aClimbTree) {
|
2002-01-12 11:06:08 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// stop if we reach the root <math> tag
|
2003-07-08 15:00:00 +04:00
|
|
|
nsIContent* content = frame->GetContent();
|
2008-01-16 08:07:09 +03:00
|
|
|
NS_ASSERTION(content || !frame->GetParent(), // no assert for the root
|
|
|
|
"dangling frame without a content node");
|
2002-04-02 07:57:56 +04:00
|
|
|
if (!content)
|
|
|
|
break;
|
2003-11-19 04:20:56 +03:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (content->Tag() == nsGkAtoms::math) {
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleDisplay* display = frame->GetStyleDisplay();
|
2002-01-12 11:06:08 +03:00
|
|
|
if (display->mDisplay == NS_STYLE_DISPLAY_BLOCK) {
|
|
|
|
aPresentationData.flags |= NS_MATHML_DISPLAYSTYLE;
|
|
|
|
}
|
2011-07-12 20:06:34 +04:00
|
|
|
FindAttrDisplaystyle(content, aPresentationData);
|
2011-05-30 01:21:12 +04:00
|
|
|
aPresentationData.mstyle = frame->GetFirstContinuation();
|
2002-01-12 11:06:08 +03:00
|
|
|
break;
|
|
|
|
}
|
2003-07-08 15:00:00 +04:00
|
|
|
frame = frame->GetParent();
|
2002-01-12 11:06:08 +03:00
|
|
|
}
|
2008-01-16 08:07:09 +03:00
|
|
|
NS_WARN_IF_FALSE(frame && frame->GetContent(),
|
|
|
|
"bad MathML markup - could not find the top <math> element");
|
2002-01-12 11:06:08 +03:00
|
|
|
}
|
|
|
|
|
2002-01-09 21:51:30 +03:00
|
|
|
// helper to get an attribute from the content or the surrounding <mstyle> hierarchy
|
2011-09-29 10:19:26 +04:00
|
|
|
/* static */ bool
|
2002-01-09 21:51:30 +03:00
|
|
|
nsMathMLFrame::GetAttribute(nsIContent* aContent,
|
|
|
|
nsIFrame* aMathMLmstyleFrame,
|
|
|
|
nsIAtom* aAttributeAtom,
|
|
|
|
nsString& aValue)
|
|
|
|
{
|
|
|
|
// see if we can get the attribute from the content
|
2005-10-28 15:25:24 +04:00
|
|
|
if (aContent && aContent->GetAttr(kNameSpaceID_None, aAttributeAtom,
|
|
|
|
aValue)) {
|
|
|
|
return PR_TRUE;
|
2002-01-09 21:51:30 +03:00
|
|
|
}
|
|
|
|
|
2005-10-28 15:25:24 +04:00
|
|
|
// see if we can get the attribute from the mstyle frame
|
|
|
|
if (!aMathMLmstyleFrame) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2002-01-09 21:51:30 +03:00
|
|
|
|
2005-10-28 15:25:24 +04:00
|
|
|
nsIFrame* mstyleParent = aMathMLmstyleFrame->GetParent();
|
2002-01-09 21:51:30 +03:00
|
|
|
|
2005-10-28 15:25:24 +04:00
|
|
|
nsPresentationData mstyleParentData;
|
|
|
|
mstyleParentData.mstyle = nsnull;
|
2002-01-09 21:51:30 +03:00
|
|
|
|
2005-10-28 15:25:24 +04:00
|
|
|
if (mstyleParent) {
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(mstyleParent);
|
2005-10-28 15:25:24 +04:00
|
|
|
if (mathMLFrame) {
|
|
|
|
mathMLFrame->GetPresentationData(mstyleParentData);
|
2002-01-09 21:51:30 +03:00
|
|
|
}
|
|
|
|
}
|
2005-10-28 15:25:24 +04:00
|
|
|
|
|
|
|
// recurse all the way up into the <mstyle> hierarchy
|
|
|
|
return GetAttribute(aMathMLmstyleFrame->GetContent(),
|
|
|
|
mstyleParentData.mstyle, aAttributeAtom, aValue);
|
2002-01-09 21:51:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
2011-04-08 05:04:40 +04:00
|
|
|
nsMathMLFrame::GetRuleThickness(nsRenderingContext& aRenderingContext,
|
2011-04-08 05:05:49 +04:00
|
|
|
nsFontMetrics* aFontMetrics,
|
2002-01-09 21:51:30 +03: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-08 05:04:40 +04:00
|
|
|
NS_ASSERTION(aRenderingContext.FontMetrics()->Font().
|
|
|
|
Equals(aFontMetrics->Font()),
|
|
|
|
"unexpected state");
|
|
|
|
|
2011-04-08 08:18:43 +04:00
|
|
|
nscoord xHeight = aFontMetrics->XHeight();
|
2002-01-09 21:51:30 +03:00
|
|
|
PRUnichar overBar = 0x00AF;
|
2011-04-08 05:04:40 +04:00
|
|
|
nsBoundingMetrics bm = aRenderingContext.GetBoundingMetrics(&overBar, 1);
|
|
|
|
aRuleThickness = bm.ascent + bm.descent;
|
|
|
|
if (aRuleThickness <= 0 || aRuleThickness >= xHeight) {
|
2002-01-09 21:51:30 +03:00
|
|
|
// fall-back to the other version
|
|
|
|
GetRuleThickness(aFontMetrics, aRuleThickness);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
2011-04-08 05:04:40 +04:00
|
|
|
nsMathMLFrame::GetAxisHeight(nsRenderingContext& aRenderingContext,
|
2011-04-08 05:05:49 +04:00
|
|
|
nsFontMetrics* aFontMetrics,
|
2002-01-09 21:51:30 +03: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-08 05:04:40 +04:00
|
|
|
NS_ASSERTION(aRenderingContext.FontMetrics()->Font().
|
|
|
|
Equals(aFontMetrics->Font()),
|
|
|
|
"unexpected state");
|
|
|
|
|
2011-04-08 08:18:43 +04:00
|
|
|
nscoord xHeight = aFontMetrics->XHeight();
|
2002-02-27 04:35:27 +03:00
|
|
|
PRUnichar minus = 0x2212; // not '-', but official Unicode minus sign
|
2011-04-08 05:04:40 +04:00
|
|
|
nsBoundingMetrics bm = aRenderingContext.GetBoundingMetrics(&minus, 1);
|
|
|
|
aAxisHeight = bm.ascent - (bm.ascent + bm.descent)/2;
|
|
|
|
if (aAxisHeight <= 0 || aAxisHeight >= xHeight) {
|
2002-01-09 21:51:30 +03:00
|
|
|
// fall-back to the other version
|
|
|
|
GetAxisHeight(aFontMetrics, aAxisHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nscoord
|
2004-08-01 03:15:21 +04:00
|
|
|
nsMathMLFrame::CalcLength(nsPresContext* aPresContext,
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* aStyleContext,
|
2002-01-09 21:51:30 +03:00
|
|
|
const nsCSSValue& aCSSValue)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aCSSValue.IsLengthUnit(), "not a length unit");
|
|
|
|
|
|
|
|
if (aCSSValue.IsFixedLengthUnit()) {
|
2010-08-13 13:58:01 +04:00
|
|
|
return aCSSValue.GetFixedLength(aPresContext);
|
|
|
|
}
|
|
|
|
if (aCSSValue.IsPixelLengthUnit()) {
|
|
|
|
return aCSSValue.GetPixelLength();
|
2002-01-09 21:51:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSUnit unit = aCSSValue.GetUnit();
|
|
|
|
|
2010-08-13 13:58:01 +04:00
|
|
|
if (eCSSUnit_EM == unit) {
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleFont* font = aStyleContext->GetStyleFont();
|
2002-01-09 21:51:30 +03:00
|
|
|
return NSToCoordRound(aCSSValue.GetFloatValue() * (float)font->mFont.size);
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_XHeight == unit) {
|
2011-08-14 21:08:04 +04:00
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
|
|
|
nsLayoutUtils::GetFontMetricsForStyleContext(aStyleContext,
|
|
|
|
getter_AddRefs(fm));
|
2011-04-08 08:18:43 +04:00
|
|
|
nscoord xHeight = fm->XHeight();
|
2002-01-09 21:51:30 +03:00
|
|
|
return NSToCoordRound(aCSSValue.GetFloatValue() * (float)xHeight);
|
|
|
|
}
|
|
|
|
|
2010-08-13 13:58:01 +04:00
|
|
|
// MathML doesn't specify other CSS units such as rem or ch
|
|
|
|
NS_ERROR("Unsupported unit");
|
2002-01-09 21:51:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
/* static */ bool
|
2002-01-09 21:51:30 +03:00
|
|
|
nsMathMLFrame::ParseNamedSpaceValue(nsIFrame* aMathMLmstyleFrame,
|
|
|
|
nsString& aString,
|
|
|
|
nsCSSValue& aCSSValue)
|
|
|
|
{
|
|
|
|
aCSSValue.Reset();
|
|
|
|
aString.CompressWhitespace(); // aString is not a const in this code...
|
|
|
|
if (!aString.Length()) return PR_FALSE;
|
|
|
|
|
|
|
|
// See if it is one of the 'namedspace' (ranging 1/18em...7/18em)
|
|
|
|
PRInt32 i = 0;
|
2002-02-19 02:16:33 +03:00
|
|
|
nsIAtom* namedspaceAtom = nsnull;
|
2004-04-30 17:23:43 +04:00
|
|
|
if (aString.EqualsLiteral("veryverythinmathspace")) {
|
2002-01-09 21:51:30 +03:00
|
|
|
i = 1;
|
2006-12-26 20:47:52 +03:00
|
|
|
namedspaceAtom = nsGkAtoms::veryverythinmathspace_;
|
2002-01-09 21:51:30 +03:00
|
|
|
}
|
2004-04-30 17:23:43 +04:00
|
|
|
else if (aString.EqualsLiteral("verythinmathspace")) {
|
2002-01-09 21:51:30 +03:00
|
|
|
i = 2;
|
2006-12-26 20:47:52 +03:00
|
|
|
namedspaceAtom = nsGkAtoms::verythinmathspace_;
|
2002-01-09 21:51:30 +03:00
|
|
|
}
|
2004-04-30 17:23:43 +04:00
|
|
|
else if (aString.EqualsLiteral("thinmathspace")) {
|
2002-01-09 21:51:30 +03:00
|
|
|
i = 3;
|
2006-12-26 20:47:52 +03:00
|
|
|
namedspaceAtom = nsGkAtoms::thinmathspace_;
|
2002-01-09 21:51:30 +03:00
|
|
|
}
|
2004-04-30 17:23:43 +04:00
|
|
|
else if (aString.EqualsLiteral("mediummathspace")) {
|
2002-01-09 21:51:30 +03:00
|
|
|
i = 4;
|
2006-12-26 20:47:52 +03:00
|
|
|
namedspaceAtom = nsGkAtoms::mediummathspace_;
|
2002-01-09 21:51:30 +03:00
|
|
|
}
|
2004-04-30 17:23:43 +04:00
|
|
|
else if (aString.EqualsLiteral("thickmathspace")) {
|
2002-01-09 21:51:30 +03:00
|
|
|
i = 5;
|
2006-12-26 20:47:52 +03:00
|
|
|
namedspaceAtom = nsGkAtoms::thickmathspace_;
|
2002-01-09 21:51:30 +03:00
|
|
|
}
|
2004-04-30 17:23:43 +04:00
|
|
|
else if (aString.EqualsLiteral("verythickmathspace")) {
|
2002-01-09 21:51:30 +03:00
|
|
|
i = 6;
|
2006-12-26 20:47:52 +03:00
|
|
|
namedspaceAtom = nsGkAtoms::verythickmathspace_;
|
2002-01-09 21:51:30 +03:00
|
|
|
}
|
2004-04-30 17:23:43 +04:00
|
|
|
else if (aString.EqualsLiteral("veryverythickmathspace")) {
|
2002-01-09 21:51:30 +03:00
|
|
|
i = 7;
|
2006-12-26 20:47:52 +03:00
|
|
|
namedspaceAtom = nsGkAtoms::veryverythickmathspace_;
|
2002-01-09 21:51:30 +03:00
|
|
|
}
|
2011-06-22 19:55:05 +04:00
|
|
|
else if (aString.EqualsLiteral("negativeveryverythinmathspace")) {
|
|
|
|
i = -1;
|
|
|
|
namedspaceAtom = nsGkAtoms::negativeveryverythinmathspace_;
|
|
|
|
}
|
|
|
|
else if (aString.EqualsLiteral("negativeverythinmathspace")) {
|
|
|
|
i = -2;
|
|
|
|
namedspaceAtom = nsGkAtoms::negativeverythinmathspace_;
|
|
|
|
}
|
|
|
|
else if (aString.EqualsLiteral("negativethinmathspace")) {
|
|
|
|
i = -3;
|
|
|
|
namedspaceAtom = nsGkAtoms::negativethinmathspace_;
|
|
|
|
}
|
|
|
|
else if (aString.EqualsLiteral("negativemediummathspace")) {
|
|
|
|
i = -4;
|
|
|
|
namedspaceAtom = nsGkAtoms::negativemediummathspace_;
|
|
|
|
}
|
|
|
|
else if (aString.EqualsLiteral("negativethickmathspace")) {
|
|
|
|
i = -5;
|
|
|
|
namedspaceAtom = nsGkAtoms::negativethickmathspace_;
|
|
|
|
}
|
|
|
|
else if (aString.EqualsLiteral("negativeverythickmathspace")) {
|
|
|
|
i = -6;
|
|
|
|
namedspaceAtom = nsGkAtoms::negativeverythickmathspace_;
|
|
|
|
}
|
|
|
|
else if (aString.EqualsLiteral("negativeveryverythickmathspace")) {
|
|
|
|
i = -7;
|
|
|
|
namedspaceAtom = nsGkAtoms::negativeveryverythickmathspace_;
|
|
|
|
}
|
2002-01-09 21:51:30 +03:00
|
|
|
|
|
|
|
if (0 != i) {
|
|
|
|
if (aMathMLmstyleFrame) {
|
|
|
|
// see if there is a <mstyle> that has overriden the default value
|
|
|
|
// GetAttribute() will recurse all the way up into the <mstyle> hierarchy
|
|
|
|
nsAutoString value;
|
2005-10-28 15:25:24 +04:00
|
|
|
GetAttribute(nsnull, aMathMLmstyleFrame, namedspaceAtom, value);
|
|
|
|
if (!value.IsEmpty()) {
|
2002-01-09 21:51:30 +03:00
|
|
|
if (ParseNumericValue(value, aCSSValue) &&
|
|
|
|
aCSSValue.IsLengthUnit()) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// fall back to the default value
|
|
|
|
aCSSValue.SetFloatValue(float(i)/float(18), eCSSUnit_EM);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2002-02-14 15:26:43 +03: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;
|
|
|
|
};
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
#if defined(NS_DEBUG) && defined(SHOW_BOUNDING_BOX)
|
|
|
|
class nsDisplayMathMLBoundingMetrics : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayMathMLBoundingMetrics(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, const nsRect& aRect)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame), mRect(aRect) {
|
2006-01-29 21:48:58 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayMathMLBoundingMetrics);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayMathMLBoundingMetrics() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayMathMLBoundingMetrics);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-07 04:35:14 +04:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx);
|
2010-07-16 01:07:49 +04:00
|
|
|
NS_DISPLAY_DECL_NAME("MathMLBoundingMetrics", TYPE_MATHML_BOUNDING_METRICS)
|
2006-01-26 05:29:17 +03:00
|
|
|
private:
|
|
|
|
nsRect mRect;
|
|
|
|
};
|
|
|
|
|
|
|
|
void nsDisplayMathMLBoundingMetrics::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx)
|
2006-01-26 05:29:17 +03:00
|
|
|
{
|
|
|
|
aCtx->SetColor(NS_RGB(0,0,255));
|
2010-08-13 14:01:58 +04:00
|
|
|
aCtx->DrawRect(mRect + ToReferenceFrame());
|
2006-01-26 05:29:17 +03: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 14:01:13 +04:00
|
|
|
nsDisplayMathMLBoundingMetrics(aBuilder, this, nsRect(x,y,w,h)));
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class nsDisplayMathMLBar : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayMathMLBar(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, const nsRect& aRect)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame), mRect(aRect) {
|
2006-01-29 21:48:58 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayMathMLBar);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayMathMLBar() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayMathMLBar);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-07 04:35:14 +04:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx);
|
2010-07-16 01:07:49 +04:00
|
|
|
NS_DISPLAY_DECL_NAME("MathMLBar", TYPE_MATHML_BAR)
|
2006-01-26 05:29:17 +03:00
|
|
|
private:
|
|
|
|
nsRect mRect;
|
|
|
|
};
|
|
|
|
|
|
|
|
void nsDisplayMathMLBar::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx)
|
2006-01-26 05:29:17 +03:00
|
|
|
{
|
|
|
|
// paint the bar with the current text color
|
|
|
|
aCtx->SetColor(mFrame->GetStyleColor()->mColor);
|
2010-08-13 14:01:58 +04:00
|
|
|
aCtx->FillRect(mRect + ToReferenceFrame());
|
2006-01-26 05:29:17 +03: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 14:01:13 +04:00
|
|
|
nsDisplayMathMLBar(aBuilder, aFrame, aRect));
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|