2007-06-12 06:10:23 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2004-04-18 14:30:37 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2000-01-26 06:49:38 +00:00
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* 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.
|
2000-01-26 06:49:38 +00:00
|
|
|
*
|
1999-09-21 02:12:01 +00:00
|
|
|
* The Original Code is Mozilla MathML Project.
|
2000-01-26 06:49:38 +00:00
|
|
|
*
|
2004-04-18 14:30:37 +00: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.
|
2000-01-26 06:49:38 +00:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-09-21 02:12:01 +00:00
|
|
|
* Roger B. Sidje <rbs@maths.uq.edu.au>
|
|
|
|
* David J. Fiddes <D.J.Fiddes@hw.ac.uk>
|
2000-03-28 09:38:24 +00:00
|
|
|
* Shyjan Mahamud <mahamud@cs.cmu.edu>
|
2004-04-18 14:30:37 +00: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 ***** */
|
1999-09-21 02:12:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsFrame.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
2003-02-22 00:32:13 +00:00
|
|
|
#include "nsStyleContext.h"
|
1999-09-21 02:12:01 +00:00
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
|
2002-01-05 01:15:04 +00:00
|
|
|
#include "nsMathMLmfencedFrame.h"
|
1999-09-21 02:12:01 +00:00
|
|
|
#include "nsMathMLmfracFrame.h"
|
|
|
|
|
|
|
|
//
|
|
|
|
// <mfrac> -- form a fraction from two subexpressions - implementation
|
|
|
|
//
|
|
|
|
|
2000-03-28 09:38:24 +00:00
|
|
|
// various fraction line thicknesses (multiplicative values of the default rule thickness)
|
|
|
|
|
|
|
|
#define THIN_FRACTION_LINE 0.5f
|
|
|
|
#define THIN_FRACTION_LINE_MINIMUM_PIXELS 1 // minimum of 1 pixel
|
|
|
|
|
|
|
|
#define MEDIUM_FRACTION_LINE 1.5f
|
|
|
|
#define MEDIUM_FRACTION_LINE_MINIMUM_PIXELS 2 // minimum of 2 pixels
|
|
|
|
|
|
|
|
#define THICK_FRACTION_LINE 2.0f
|
|
|
|
#define THICK_FRACTION_LINE_MINIMUM_PIXELS 4 // minimum of 4 pixels
|
|
|
|
|
2002-01-05 01:15:04 +00:00
|
|
|
// additional style context to be used by our MathMLChar.
|
|
|
|
#define NS_SLASH_CHAR_STYLE_CONTEXT_INDEX 0
|
|
|
|
|
|
|
|
static const PRUnichar kSlashChar = PRUnichar('/');
|
|
|
|
|
2005-11-11 02:36:29 +00:00
|
|
|
nsIFrame*
|
2006-03-26 21:30:36 +00:00
|
|
|
NS_NewMathMLmfracFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1999-09-21 02:12:01 +00:00
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
return new (aPresShell) nsMathMLmfracFrame(aContext);
|
1999-09-21 02:12:01 +00:00
|
|
|
}
|
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmfracFrame)
|
|
|
|
|
1999-09-21 02:12:01 +00:00
|
|
|
nsMathMLmfracFrame::~nsMathMLmfracFrame()
|
|
|
|
{
|
2002-01-05 01:15:04 +00:00
|
|
|
if (mSlashChar) {
|
|
|
|
delete mSlashChar;
|
|
|
|
mSlashChar = nsnull;
|
|
|
|
}
|
1999-09-21 02:12:01 +00:00
|
|
|
}
|
|
|
|
|
2002-02-07 04:38:08 +00:00
|
|
|
PRBool
|
|
|
|
nsMathMLmfracFrame::IsBevelled()
|
|
|
|
{
|
|
|
|
nsAutoString value;
|
2006-12-26 17:47:52 +00:00
|
|
|
GetAttribute(mContent, mPresentationData.mstyle, nsGkAtoms::bevelled_,
|
2005-10-28 11:25:24 +00:00
|
|
|
value);
|
|
|
|
return value.EqualsLiteral("true");
|
2002-02-07 04:38:08 +00:00
|
|
|
}
|
|
|
|
|
1999-09-21 02:12:01 +00:00
|
|
|
NS_IMETHODIMP
|
2006-03-09 18:55:21 +00:00
|
|
|
nsMathMLmfracFrame::Init(nsIContent* aContent,
|
1999-09-21 02:12:01 +00:00
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
nsresult rv = nsMathMLContainerFrame::Init(aContent, aParent, aPrevInFlow);
|
1999-09-21 02:12:01 +00:00
|
|
|
|
2002-01-05 01:15:04 +00:00
|
|
|
if (IsBevelled()) {
|
|
|
|
// enable the bevelled rendering
|
|
|
|
mSlashChar = new nsMathMLChar();
|
|
|
|
if (mSlashChar) {
|
2007-03-30 21:11:41 +00:00
|
|
|
nsPresContext* presContext = PresContext();
|
2006-03-09 18:55:21 +00:00
|
|
|
|
2002-01-05 01:15:04 +00:00
|
|
|
nsAutoString slashChar; slashChar.Assign(kSlashChar);
|
2006-03-26 21:30:36 +00:00
|
|
|
mSlashChar->SetData(presContext, slashChar);
|
|
|
|
ResolveMathMLCharStyle(presContext, mContent, mStyleContext, mSlashChar, PR_TRUE);
|
2002-01-05 01:15:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-01 15:10:50 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2006-08-15 04:49:43 +00:00
|
|
|
eMathMLFrameType
|
|
|
|
nsMathMLmfracFrame::GetMathMLFrameType()
|
2005-09-06 23:47:01 +00:00
|
|
|
{
|
|
|
|
// frac is "inner" in TeXBook, Appendix G, rule 15e. See also page 170.
|
2006-08-15 04:49:43 +00:00
|
|
|
return eMathMLFrameType_Inner;
|
2005-09-06 23:47:01 +00:00
|
|
|
}
|
|
|
|
|
2002-02-01 15:10:50 +00:00
|
|
|
NS_IMETHODIMP
|
2005-02-07 01:57:50 +00:00
|
|
|
nsMathMLmfracFrame::TransmitAutomaticData()
|
2002-02-01 15:10:50 +00:00
|
|
|
{
|
|
|
|
// 1. The REC says:
|
|
|
|
// The <mfrac> element sets displaystyle to "false", or if it was already
|
|
|
|
// false increments scriptlevel by 1, within numerator and denominator.
|
|
|
|
// 2. The TeXbook (Ch 17. p.141) says the numerator inherits the compression
|
|
|
|
// while the denominator is compressed
|
2008-01-18 04:41:54 +00:00
|
|
|
PRBool increment = !NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags);
|
|
|
|
SetIncrementScriptLevel(0, increment);
|
|
|
|
SetIncrementScriptLevel(1, increment);
|
2008-01-09 09:38:28 +00:00
|
|
|
|
|
|
|
UpdatePresentationDataFromChildAt(0, -1,
|
2002-02-01 15:10:50 +00:00
|
|
|
~NS_MATHML_DISPLAYSTYLE,
|
|
|
|
NS_MATHML_DISPLAYSTYLE);
|
2008-01-09 09:38:28 +00:00
|
|
|
UpdatePresentationDataFromChildAt(1, 1,
|
2002-02-01 15:10:50 +00:00
|
|
|
NS_MATHML_COMPRESSED,
|
|
|
|
NS_MATHML_COMPRESSED);
|
2002-02-07 04:38:08 +00:00
|
|
|
|
|
|
|
// if our numerator is an embellished operator, let its state bubble to us
|
|
|
|
GetEmbellishDataFrom(mFrames.FirstChild(), mEmbellishData);
|
|
|
|
if (NS_MATHML_IS_EMBELLISH_OPERATOR(mEmbellishData.flags)) {
|
|
|
|
// even when embellished, we need to record that <mfrac> won't fire
|
|
|
|
// Stretch() on its embellished child
|
|
|
|
mEmbellishData.direction = NS_STRETCH_DIRECTION_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
2002-02-01 15:10:50 +00:00
|
|
|
return NS_OK;
|
2000-03-28 09:38:24 +00:00
|
|
|
}
|
2000-01-26 06:49:38 +00:00
|
|
|
|
2000-03-28 09:38:24 +00:00
|
|
|
nscoord
|
2004-07-31 23:15:21 +00:00
|
|
|
nsMathMLmfracFrame::CalcLineThickness(nsPresContext* aPresContext,
|
2003-02-22 00:32:13 +00:00
|
|
|
nsStyleContext* aStyleContext,
|
2000-03-28 09:38:24 +00:00
|
|
|
nsString& aThicknessAttribute,
|
|
|
|
nscoord onePixel,
|
|
|
|
nscoord aDefaultRuleThickness)
|
|
|
|
{
|
|
|
|
nscoord defaultThickness = aDefaultRuleThickness;
|
|
|
|
nscoord lineThickness = aDefaultRuleThickness;
|
|
|
|
nscoord minimumThickness = onePixel;
|
|
|
|
|
2003-05-23 21:34:47 +00:00
|
|
|
if (!aThicknessAttribute.IsEmpty()) {
|
2004-04-30 13:23:43 +00:00
|
|
|
if (aThicknessAttribute.EqualsLiteral("thin")) {
|
2000-03-28 09:38:24 +00:00
|
|
|
lineThickness = NSToCoordFloor(defaultThickness * THIN_FRACTION_LINE);
|
|
|
|
minimumThickness = onePixel * THIN_FRACTION_LINE_MINIMUM_PIXELS;
|
|
|
|
// should visually decrease by at least one pixel, if default is not a pixel
|
|
|
|
if (defaultThickness > onePixel && lineThickness > defaultThickness - onePixel)
|
|
|
|
lineThickness = defaultThickness - onePixel;
|
|
|
|
}
|
2004-04-30 13:23:43 +00:00
|
|
|
else if (aThicknessAttribute.EqualsLiteral("medium")) {
|
2000-03-28 09:38:24 +00:00
|
|
|
lineThickness = NSToCoordRound(defaultThickness * MEDIUM_FRACTION_LINE);
|
|
|
|
minimumThickness = onePixel * MEDIUM_FRACTION_LINE_MINIMUM_PIXELS;
|
|
|
|
// should visually increase by at least one pixel
|
|
|
|
if (lineThickness < defaultThickness + onePixel)
|
|
|
|
lineThickness = defaultThickness + onePixel;
|
|
|
|
}
|
2004-04-30 13:23:43 +00:00
|
|
|
else if (aThicknessAttribute.EqualsLiteral("thick")) {
|
2000-03-28 09:38:24 +00:00
|
|
|
lineThickness = NSToCoordCeil(defaultThickness * THICK_FRACTION_LINE);
|
|
|
|
minimumThickness = onePixel * THICK_FRACTION_LINE_MINIMUM_PIXELS;
|
|
|
|
// should visually increase by at least two pixels
|
|
|
|
if (lineThickness < defaultThickness + 2*onePixel)
|
|
|
|
lineThickness = defaultThickness + 2*onePixel;
|
|
|
|
}
|
2000-01-26 06:49:38 +00:00
|
|
|
else { // see if it is a plain number, or a percentage, or a h/v-unit like 1ex, 2px, 1em
|
|
|
|
nsCSSValue cssValue;
|
2000-03-28 09:38:24 +00:00
|
|
|
if (ParseNumericValue(aThicknessAttribute, cssValue)) {
|
2000-01-26 06:49:38 +00:00
|
|
|
nsCSSUnit unit = cssValue.GetUnit();
|
|
|
|
if (eCSSUnit_Number == unit)
|
2000-03-28 09:38:24 +00:00
|
|
|
lineThickness = nscoord(float(defaultThickness) * cssValue.GetFloatValue());
|
2000-01-26 06:49:38 +00:00
|
|
|
else if (eCSSUnit_Percent == unit)
|
2000-03-28 09:38:24 +00:00
|
|
|
lineThickness = nscoord(float(defaultThickness) * cssValue.GetPercentValue());
|
2000-01-26 06:49:38 +00:00
|
|
|
else if (eCSSUnit_Null != unit)
|
2000-03-28 09:38:24 +00:00
|
|
|
lineThickness = CalcLength(aPresContext, aStyleContext, cssValue);
|
2000-01-26 06:49:38 +00:00
|
|
|
}
|
1999-09-21 02:12:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-28 09:38:24 +00:00
|
|
|
// use minimum if the lineThickness is a non-zero value less than minimun
|
2001-02-23 16:10:51 +00:00
|
|
|
if (lineThickness && lineThickness < minimumThickness)
|
2000-03-28 09:38:24 +00:00
|
|
|
lineThickness = minimumThickness;
|
1999-09-21 02:12:01 +00:00
|
|
|
|
2000-03-28 09:38:24 +00:00
|
|
|
return lineThickness;
|
1999-09-21 02:12:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-01-26 02:29:17 +00:00
|
|
|
nsMathMLmfracFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
1999-09-21 02:12:01 +00:00
|
|
|
{
|
2005-08-08 03:20:59 +00:00
|
|
|
/////////////
|
|
|
|
// paint the numerator and denominator
|
2006-01-26 02:29:17 +00:00
|
|
|
nsresult rv = nsMathMLContainerFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-08-08 03:20:59 +00:00
|
|
|
/////////////
|
|
|
|
// paint the fraction line
|
2002-01-05 01:15:04 +00:00
|
|
|
if (mSlashChar) {
|
|
|
|
// bevelled rendering
|
2006-01-26 02:29:17 +00:00
|
|
|
rv = mSlashChar->Display(aBuilder, this, aLists);
|
|
|
|
} else {
|
|
|
|
rv = DisplayBar(aBuilder, this, mLineRect, aLists);
|
1999-09-21 02:12:01 +00:00
|
|
|
}
|
|
|
|
|
2005-08-08 03:20:59 +00:00
|
|
|
return rv;
|
1999-09-21 02:12:01 +00:00
|
|
|
}
|
|
|
|
|
2002-01-05 01:15:04 +00:00
|
|
|
NS_IMETHODIMP
|
2004-07-31 23:15:21 +00:00
|
|
|
nsMathMLmfracFrame::Reflow(nsPresContext* aPresContext,
|
2002-01-05 01:15:04 +00:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
if (mSlashChar) {
|
|
|
|
// bevelled rendering
|
|
|
|
return nsMathMLmfencedFrame::doReflow(aPresContext, aReflowState,
|
|
|
|
aDesiredSize, aStatus, this,
|
|
|
|
nsnull, nsnull, mSlashChar, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// default rendering
|
|
|
|
return nsMathMLContainerFrame::Reflow(aPresContext, aDesiredSize,
|
|
|
|
aReflowState, aStatus);
|
|
|
|
}
|
|
|
|
|
2008-03-14 05:02:49 +00:00
|
|
|
/* virtual */ nscoord
|
|
|
|
nsMathMLmfracFrame::GetIntrinsicWidth(nsIRenderingContext* aRenderingContext)
|
|
|
|
{
|
|
|
|
if (mSlashChar) {
|
|
|
|
// bevelled rendering
|
|
|
|
return nsMathMLmfencedFrame::doGetIntrinsicWidth(aRenderingContext, this,
|
|
|
|
nsnull, nsnull,
|
|
|
|
mSlashChar, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// default rendering
|
|
|
|
return nsMathMLContainerFrame::GetIntrinsicWidth(aRenderingContext);
|
|
|
|
}
|
|
|
|
|
2005-09-16 00:39:27 +00:00
|
|
|
nscoord
|
|
|
|
nsMathMLmfracFrame::FixInterFrameSpacing(nsHTMLReflowMetrics& aDesiredSize)
|
|
|
|
{
|
|
|
|
nscoord gap = nsMathMLContainerFrame::FixInterFrameSpacing(aDesiredSize);
|
|
|
|
if (!gap) return 0;
|
|
|
|
|
|
|
|
if (mSlashChar) {
|
|
|
|
nsRect rect;
|
|
|
|
mSlashChar->GetRect(rect);
|
|
|
|
rect.MoveBy(gap, 0);
|
|
|
|
mSlashChar->SetRect(rect);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mLineRect.MoveBy(gap, 0);
|
|
|
|
}
|
|
|
|
return gap;
|
|
|
|
}
|
|
|
|
|
2008-03-18 04:52:48 +00:00
|
|
|
/* virtual */ nsresult
|
2006-08-03 23:27:55 +00:00
|
|
|
nsMathMLmfracFrame::Place(nsIRenderingContext& aRenderingContext,
|
|
|
|
PRBool aPlaceOrigin,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize)
|
2000-03-28 09:38:24 +00:00
|
|
|
{
|
|
|
|
////////////////////////////////////
|
|
|
|
// Get the children's desired sizes
|
|
|
|
nsBoundingMetrics bmNum, bmDen;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
nsHTMLReflowMetrics sizeNum;
|
|
|
|
nsHTMLReflowMetrics sizeDen;
|
2000-03-28 09:38:24 +00:00
|
|
|
nsIFrame* frameDen = nsnull;
|
2002-02-07 04:38:08 +00:00
|
|
|
nsIFrame* frameNum = mFrames.FirstChild();
|
|
|
|
if (frameNum)
|
2003-07-08 11:00:00 +00:00
|
|
|
frameDen = frameNum->GetNextSibling();
|
|
|
|
if (!frameNum || !frameDen || frameDen->GetNextSibling()) {
|
2000-03-28 09:38:24 +00:00
|
|
|
// report an error, encourage people to get their markups in order
|
2006-08-03 23:27:55 +00:00
|
|
|
return ReflowError(aRenderingContext, aDesiredSize);
|
1999-09-21 02:12:01 +00:00
|
|
|
}
|
2002-02-07 04:38:08 +00:00
|
|
|
GetReflowAndBoundingMetricsFor(frameNum, sizeNum, bmNum);
|
|
|
|
GetReflowAndBoundingMetricsFor(frameDen, sizeDen, bmDen);
|
1999-09-21 02:12:01 +00:00
|
|
|
|
|
|
|
//////////////////
|
2000-03-28 09:38:24 +00:00
|
|
|
// Get shifts
|
1999-09-21 02:12:01 +00:00
|
|
|
|
2007-03-30 21:11:41 +00:00
|
|
|
nsPresContext* presContext = PresContext();
|
2007-02-07 07:46:44 +00:00
|
|
|
nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
|
2000-01-26 06:49:38 +00:00
|
|
|
|
2008-12-04 16:09:53 +00:00
|
|
|
aRenderingContext.SetFont(GetStyleFont()->mFont, nsnull,
|
|
|
|
presContext->GetUserFontSet());
|
2000-03-28 09:38:24 +00:00
|
|
|
nsCOMPtr<nsIFontMetrics> fm;
|
|
|
|
aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));
|
1999-09-21 02:12:01 +00:00
|
|
|
|
2002-01-06 19:50:51 +00:00
|
|
|
nscoord defaultRuleThickness, axisHeight;
|
2000-03-28 09:38:24 +00:00
|
|
|
GetRuleThickness(aRenderingContext, fm, defaultRuleThickness);
|
2002-01-06 19:50:51 +00:00
|
|
|
GetAxisHeight(aRenderingContext, fm, axisHeight);
|
1999-09-21 02:12:01 +00:00
|
|
|
|
2002-01-05 01:15:04 +00:00
|
|
|
// by default, leave at least one-pixel padding at either end, or use
|
2002-02-07 04:38:08 +00:00
|
|
|
// lspace & rspace that may come from <mo> if we are an embellished container
|
|
|
|
// (we fetch values from the core since they may use units that depend
|
2005-11-20 22:05:24 +00:00
|
|
|
// on style data, and style changes could have occurred in the core since
|
2002-02-07 04:38:08 +00:00
|
|
|
// our last visit there)
|
|
|
|
nsEmbellishData coreData;
|
|
|
|
GetEmbellishDataFrom(mEmbellishData.coreFrame, coreData);
|
2009-09-16 15:01:36 +00:00
|
|
|
nscoord leftSpace = NS_MAX(onePixel, coreData.leftSpace);
|
|
|
|
nscoord rightSpace = NS_MAX(onePixel, coreData.rightSpace);
|
2002-01-05 01:15:04 +00:00
|
|
|
|
2000-03-28 09:38:24 +00:00
|
|
|
// see if the linethickness attribute is there
|
|
|
|
nsAutoString value;
|
2006-12-26 17:47:52 +00:00
|
|
|
GetAttribute(mContent, mPresentationData.mstyle, nsGkAtoms::linethickness_, value);
|
2005-02-07 01:57:50 +00:00
|
|
|
mLineRect.height = CalcLineThickness(presContext, mStyleContext, value,
|
|
|
|
onePixel, defaultRuleThickness);
|
2000-03-28 09:38:24 +00:00
|
|
|
nscoord numShift = 0;
|
|
|
|
nscoord denShift = 0;
|
|
|
|
|
|
|
|
// Rule 15b, App. G, TeXbook
|
|
|
|
nscoord numShift1, numShift2, numShift3;
|
|
|
|
nscoord denShift1, denShift2;
|
|
|
|
|
|
|
|
GetNumeratorShifts(fm, numShift1, numShift2, numShift3);
|
|
|
|
GetDenominatorShifts(fm, denShift1, denShift2);
|
|
|
|
if (NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags)) {
|
|
|
|
// C > T
|
|
|
|
numShift = numShift1;
|
|
|
|
denShift = denShift1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
numShift = (0 < mLineRect.height) ? numShift2 : numShift3;
|
|
|
|
denShift = denShift2;
|
1999-12-10 13:02:23 +00:00
|
|
|
}
|
1999-09-21 02:12:01 +00:00
|
|
|
|
2000-03-28 09:38:24 +00:00
|
|
|
nscoord minClearance = 0;
|
|
|
|
nscoord actualClearance = 0;
|
|
|
|
|
2001-02-02 09:38:48 +00:00
|
|
|
nscoord actualRuleThickness = mLineRect.height;
|
2000-03-28 09:38:24 +00:00
|
|
|
|
|
|
|
if (0 == actualRuleThickness) {
|
|
|
|
// Rule 15c, App. G, TeXbook
|
|
|
|
|
|
|
|
// min clearance between numerator and denominator
|
|
|
|
minClearance = (NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags)) ?
|
|
|
|
7 * defaultRuleThickness : 3 * defaultRuleThickness;
|
|
|
|
actualClearance =
|
|
|
|
(numShift - bmNum.descent) - (bmDen.ascent - denShift);
|
|
|
|
// actualClearance should be >= minClearance
|
|
|
|
if (actualClearance < minClearance) {
|
|
|
|
nscoord halfGap = (minClearance - actualClearance)/2;
|
|
|
|
numShift += halfGap;
|
|
|
|
denShift += halfGap;
|
|
|
|
}
|
1999-09-21 02:12:01 +00:00
|
|
|
}
|
2000-03-28 09:38:24 +00:00
|
|
|
else {
|
|
|
|
// Rule 15d, App. G, TeXbook
|
|
|
|
|
|
|
|
// min clearance between numerator or denominator and middle of bar
|
|
|
|
|
2002-01-06 19:50:51 +00:00
|
|
|
// TeX has a different interpretation of the thickness.
|
2000-03-28 09:38:24 +00:00
|
|
|
// Try $a \above10pt b$ to see. Here is what TeX does:
|
2001-02-02 09:38:48 +00:00
|
|
|
// minClearance = (NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags)) ?
|
|
|
|
// 3 * actualRuleThickness : actualRuleThickness;
|
2000-03-28 09:38:24 +00:00
|
|
|
|
2001-02-02 09:38:48 +00:00
|
|
|
// we slightly depart from TeX here. We use the defaultRuleThickness instead
|
|
|
|
// of the value coming from the linethickness attribute, i.e., we recover what
|
|
|
|
// TeX does if the user hasn't set linethickness. But when the linethickness
|
|
|
|
// is set, we avoid the wide gap problem.
|
|
|
|
minClearance = (NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags)) ?
|
|
|
|
3 * defaultRuleThickness : defaultRuleThickness + onePixel;
|
2000-03-28 09:38:24 +00:00
|
|
|
|
|
|
|
// adjust numShift to maintain minClearance if needed
|
|
|
|
actualClearance =
|
|
|
|
(numShift - bmNum.descent) - (axisHeight + actualRuleThickness/2);
|
|
|
|
if (actualClearance < minClearance) {
|
|
|
|
numShift += (minClearance - actualClearance);
|
|
|
|
}
|
|
|
|
// adjust denShift to maintain minClearance if needed
|
|
|
|
actualClearance =
|
|
|
|
(axisHeight - actualRuleThickness/2) - (bmDen.ascent - denShift);
|
|
|
|
if (actualClearance < minClearance) {
|
|
|
|
denShift += (minClearance - actualClearance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////
|
|
|
|
// Place Children
|
2000-01-07 14:49:46 +00:00
|
|
|
|
2001-02-02 09:38:48 +00:00
|
|
|
// XXX Need revisiting the width. TeX uses the exact width
|
|
|
|
// e.g. in $$\huge\frac{\displaystyle\int}{i}$$
|
2009-09-16 15:01:36 +00:00
|
|
|
nscoord width = NS_MAX(bmNum.width, bmDen.width);
|
2002-01-05 01:15:04 +00:00
|
|
|
nscoord dxNum = leftSpace + (width - sizeNum.width)/2;
|
|
|
|
nscoord dxDen = leftSpace + (width - sizeDen.width)/2;
|
|
|
|
width += leftSpace + rightSpace;
|
2000-03-28 09:38:24 +00:00
|
|
|
|
2000-05-11 23:02:00 +00:00
|
|
|
// see if the numalign attribute is there
|
2006-12-26 17:47:52 +00:00
|
|
|
GetAttribute(mContent, mPresentationData.mstyle, nsGkAtoms::numalign_,
|
2005-10-28 11:25:24 +00:00
|
|
|
value);
|
|
|
|
if (value.EqualsLiteral("left"))
|
|
|
|
dxNum = leftSpace;
|
|
|
|
else if (value.EqualsLiteral("right"))
|
|
|
|
dxNum = width - rightSpace - sizeNum.width;
|
|
|
|
|
2000-05-11 23:02:00 +00:00
|
|
|
// see if the denomalign attribute is there
|
2006-12-26 17:47:52 +00:00
|
|
|
GetAttribute(mContent, mPresentationData.mstyle, nsGkAtoms::denomalign_,
|
2005-10-28 11:25:24 +00:00
|
|
|
value);
|
|
|
|
if (value.EqualsLiteral("left"))
|
|
|
|
dxDen = leftSpace;
|
|
|
|
else if (value.EqualsLiteral("right"))
|
|
|
|
dxDen = width - rightSpace - sizeDen.width;
|
2000-05-11 23:02:00 +00:00
|
|
|
|
2000-03-28 09:38:24 +00:00
|
|
|
mBoundingMetrics.rightBearing =
|
2009-09-16 15:01:36 +00:00
|
|
|
NS_MAX(dxNum + bmNum.rightBearing, dxDen + bmDen.rightBearing);
|
2002-01-05 01:15:04 +00:00
|
|
|
if (mBoundingMetrics.rightBearing < width - rightSpace)
|
|
|
|
mBoundingMetrics.rightBearing = width - rightSpace;
|
2000-03-28 09:38:24 +00:00
|
|
|
mBoundingMetrics.leftBearing =
|
2009-09-16 15:01:36 +00:00
|
|
|
NS_MIN(dxNum + bmNum.leftBearing, dxDen + bmDen.leftBearing);
|
2002-01-05 01:15:04 +00:00
|
|
|
if (mBoundingMetrics.leftBearing > leftSpace)
|
|
|
|
mBoundingMetrics.leftBearing = leftSpace;
|
2000-03-28 09:38:24 +00:00
|
|
|
mBoundingMetrics.ascent = bmNum.ascent + numShift;
|
|
|
|
mBoundingMetrics.descent = bmDen.descent + denShift;
|
|
|
|
mBoundingMetrics.width = width;
|
|
|
|
|
|
|
|
aDesiredSize.ascent = sizeNum.ascent + numShift;
|
2007-01-23 04:06:56 +00:00
|
|
|
aDesiredSize.height = aDesiredSize.ascent +
|
|
|
|
sizeDen.height - sizeDen.ascent + denShift;
|
2000-03-28 09:38:24 +00:00
|
|
|
aDesiredSize.width = mBoundingMetrics.width;
|
2001-02-02 21:29:21 +00:00
|
|
|
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
|
2000-03-28 09:38:24 +00:00
|
|
|
|
|
|
|
mReference.x = 0;
|
|
|
|
mReference.y = aDesiredSize.ascent;
|
|
|
|
|
|
|
|
if (aPlaceOrigin) {
|
|
|
|
nscoord dy;
|
|
|
|
// place numerator
|
|
|
|
dy = 0;
|
2005-02-07 01:57:50 +00:00
|
|
|
FinishReflowChild(frameNum, presContext, nsnull, sizeNum, dxNum, dy, 0);
|
2000-03-28 09:38:24 +00:00
|
|
|
// place denominator
|
|
|
|
dy = aDesiredSize.height - sizeDen.height;
|
2005-02-07 01:57:50 +00:00
|
|
|
FinishReflowChild(frameDen, presContext, nsnull, sizeDen, dxDen, dy, 0);
|
2000-03-28 09:38:24 +00:00
|
|
|
// place the fraction bar - dy is top of bar
|
|
|
|
dy = aDesiredSize.ascent - (axisHeight + actualRuleThickness/2);
|
2002-01-05 01:15:04 +00:00
|
|
|
mLineRect.SetRect(leftSpace, dy, width - (leftSpace + rightSpace), actualRuleThickness);
|
2000-03-28 09:38:24 +00:00
|
|
|
}
|
2000-01-07 14:49:46 +00:00
|
|
|
|
1999-09-21 02:12:01 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-01-05 01:15:04 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-09-07 16:49:21 +00:00
|
|
|
nsMathMLmfracFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
2002-01-05 01:15:04 +00:00
|
|
|
nsIAtom* aAttribute,
|
2003-07-11 21:16:12 +00:00
|
|
|
PRInt32 aModType)
|
2002-01-05 01:15:04 +00:00
|
|
|
{
|
2006-12-26 17:47:52 +00:00
|
|
|
if (nsGkAtoms::bevelled_ == aAttribute) {
|
2002-01-05 01:15:04 +00:00
|
|
|
if (!IsBevelled()) {
|
|
|
|
// disable the bevelled rendering
|
|
|
|
if (mSlashChar) {
|
|
|
|
delete mSlashChar;
|
|
|
|
mSlashChar = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// enable the bevelled rendering
|
|
|
|
if (!mSlashChar) {
|
|
|
|
mSlashChar = new nsMathMLChar();
|
|
|
|
if (mSlashChar) {
|
2007-03-30 21:11:41 +00:00
|
|
|
nsPresContext* presContext = PresContext();
|
2002-01-05 01:15:04 +00:00
|
|
|
nsAutoString slashChar; slashChar.Assign(kSlashChar);
|
2004-12-31 01:13:27 +00:00
|
|
|
mSlashChar->SetData(presContext, slashChar);
|
|
|
|
ResolveMathMLCharStyle(presContext, mContent, mStyleContext, mSlashChar, PR_TRUE);
|
2002-01-05 01:15:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsMathMLContainerFrame::
|
2005-09-07 16:49:21 +00:00
|
|
|
AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
2002-01-05 01:15:04 +00:00
|
|
|
}
|
|
|
|
|
2002-01-10 04:42:55 +00:00
|
|
|
NS_IMETHODIMP
|
2005-02-07 01:57:50 +00:00
|
|
|
nsMathMLmfracFrame::UpdatePresentationDataFromChildAt(PRInt32 aFirstIndex,
|
2002-01-10 04:42:55 +00:00
|
|
|
PRInt32 aLastIndex,
|
|
|
|
PRUint32 aFlagsValues,
|
|
|
|
PRUint32 aFlagsToUpdate)
|
|
|
|
{
|
2002-01-10 23:40:40 +00:00
|
|
|
// The REC says "The <mfrac> element sets displaystyle to "false" within
|
|
|
|
// numerator and denominator"
|
|
|
|
#if 0
|
|
|
|
// At one point I thought that it meant that the displaystyle state of
|
|
|
|
// the numerator and denominator cannot be modified by an ancestor, i.e.,
|
|
|
|
// to change the displaystlye, one has to use displaystyle="true" with mstyle:
|
|
|
|
// <mfrac> <mstyle>numerator</mstyle> <mstyle>denominator</mstyle> </mfrac>
|
|
|
|
|
|
|
|
// Commenting out for now until it is clear what the intention really is.
|
|
|
|
// See also the variants for <mover>, <munder>, <munderover>
|
|
|
|
|
2002-01-10 04:42:55 +00:00
|
|
|
aFlagsToUpdate &= ~NS_MATHML_DISPLAYSTYLE;
|
|
|
|
aFlagsValues &= ~NS_MATHML_DISPLAYSTYLE;
|
2002-01-10 23:40:40 +00:00
|
|
|
#endif
|
2002-01-10 04:42:55 +00:00
|
|
|
return nsMathMLContainerFrame::
|
2005-02-07 01:57:50 +00:00
|
|
|
UpdatePresentationDataFromChildAt(aFirstIndex, aLastIndex,
|
2008-01-09 09:38:28 +00:00
|
|
|
aFlagsValues, aFlagsToUpdate);
|
2002-01-10 04:42:55 +00:00
|
|
|
}
|
|
|
|
|
2002-01-05 01:15:04 +00:00
|
|
|
// ----------------------
|
|
|
|
// the Style System will use these to pass the proper style context to our MathMLChar
|
2003-02-22 00:32:13 +00:00
|
|
|
nsStyleContext*
|
|
|
|
nsMathMLmfracFrame::GetAdditionalStyleContext(PRInt32 aIndex) const
|
2002-01-05 01:15:04 +00:00
|
|
|
{
|
2003-02-22 00:32:13 +00:00
|
|
|
if (!mSlashChar) {
|
|
|
|
return nsnull;
|
2002-01-05 01:15:04 +00:00
|
|
|
}
|
|
|
|
switch (aIndex) {
|
|
|
|
case NS_SLASH_CHAR_STYLE_CONTEXT_INDEX:
|
2003-02-22 00:32:13 +00:00
|
|
|
return mSlashChar->GetStyleContext();
|
2002-01-05 01:15:04 +00:00
|
|
|
break;
|
|
|
|
default:
|
2003-02-22 00:32:13 +00:00
|
|
|
return nsnull;
|
2002-01-05 01:15:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-22 00:32:13 +00:00
|
|
|
void
|
2002-01-05 01:15:04 +00:00
|
|
|
nsMathMLmfracFrame::SetAdditionalStyleContext(PRInt32 aIndex,
|
2003-02-22 00:32:13 +00:00
|
|
|
nsStyleContext* aStyleContext)
|
2002-01-05 01:15:04 +00:00
|
|
|
{
|
2003-02-22 00:32:13 +00:00
|
|
|
if (!mSlashChar) {
|
|
|
|
return;
|
2002-01-05 01:15:04 +00:00
|
|
|
}
|
|
|
|
switch (aIndex) {
|
|
|
|
case NS_SLASH_CHAR_STYLE_CONTEXT_INDEX:
|
|
|
|
mSlashChar->SetStyleContext(aStyleContext);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|