2007-06-12 10:10:23 +04: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.
|
|
|
|
*
|
1999-09-21 06:12:01 +04: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):
|
1999-09-21 06:12:01 +04:00
|
|
|
* Roger B. Sidje <rbs@maths.uq.edu.au>
|
|
|
|
* David J. Fiddes <D.J.Fiddes@hw.ac.uk>
|
2000-01-07 17:49:46 +03:00
|
|
|
* Shyjan Mahamud <mahamud@cs.cmu.edu> (added TeX rendering rules)
|
2012-05-16 02:30:14 +04:00
|
|
|
* Frederic Wang <fred.wang@free.fr>
|
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 ***** */
|
1999-09-21 06:12:01 +04:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsFrame.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.h"
|
1999-09-21 06:12:01 +04:00
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
|
|
|
|
#include "nsMathMLmsupFrame.h"
|
|
|
|
|
|
|
|
//
|
|
|
|
// <msup> -- attach a superscript to a base - implementation
|
|
|
|
//
|
|
|
|
|
2005-11-11 05:36:29 +03:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewMathMLmsupFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1999-09-21 06:12:01 +04:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsMathMLmsupFrame(aContext);
|
1999-09-21 06:12:01 +04:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmsupFrame)
|
|
|
|
|
1999-09-21 06:12:01 +04:00
|
|
|
nsMathMLmsupFrame::~nsMathMLmsupFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-02-07 04:57:50 +03:00
|
|
|
nsMathMLmsupFrame::TransmitAutomaticData()
|
2002-02-07 07:38:08 +03:00
|
|
|
{
|
|
|
|
// if our base is an embellished operator, its flags bubble to us
|
2005-09-07 03:47:01 +04:00
|
|
|
mPresentationData.baseFrame = mFrames.FirstChild();
|
|
|
|
GetEmbellishDataFrom(mPresentationData.baseFrame, mEmbellishData);
|
2002-02-07 07:38:08 +03:00
|
|
|
|
|
|
|
// 1. The REC says:
|
|
|
|
// The <msup> element increments scriptlevel by 1, and sets displaystyle to
|
|
|
|
// "false", within superscript, but leaves both attributes unchanged within base.
|
|
|
|
// 2. The TeXbook (Ch 17. p.141) says the superscript *inherits* the compression,
|
|
|
|
// so we don't set the compression flag. Our parent will propagate its own.
|
2008-01-09 12:38:28 +03:00
|
|
|
UpdatePresentationDataFromChildAt(1, -1,
|
2002-02-07 07:38:08 +03:00
|
|
|
~NS_MATHML_DISPLAYSTYLE,
|
|
|
|
NS_MATHML_DISPLAYSTYLE);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-03-18 08:57:35 +03:00
|
|
|
/* virtual */ nsresult
|
2011-04-08 05:04:40 +04:00
|
|
|
nsMathMLmsupFrame::Place(nsRenderingContext& aRenderingContext,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aPlaceOrigin,
|
2006-08-04 03:27:55 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize)
|
2001-02-02 12:37:14 +03:00
|
|
|
{
|
2005-09-07 03:47:01 +04:00
|
|
|
// extra spacing after sup/subscript
|
2010-08-13 13:58:04 +04:00
|
|
|
nscoord scriptSpace = nsPresContext::CSSPointsToAppUnits(0.5f); // 0.5pt as in plain TeX
|
2001-02-23 19:10:51 +03:00
|
|
|
|
2012-05-16 02:30:14 +04:00
|
|
|
// superscriptshift
|
|
|
|
//
|
|
|
|
// "Specifies the minimum amount to shift the baseline of superscript up; the
|
|
|
|
// default is for the rendering agent to use its own positioning rules."
|
|
|
|
//
|
|
|
|
// values: length
|
|
|
|
// default: automatic
|
|
|
|
//
|
|
|
|
// We use 0 as the default value so unitless values can be ignored.
|
|
|
|
// XXXfredw Should we forbid negative values? (bug 411227)
|
|
|
|
//
|
2001-02-23 19:10:51 +03:00
|
|
|
nsAutoString value;
|
|
|
|
nscoord supScriptShift = 0;
|
2005-10-28 15:25:24 +04:00
|
|
|
GetAttribute(mContent, mPresentationData.mstyle,
|
2006-12-26 20:47:52 +03:00
|
|
|
nsGkAtoms::superscriptshift_, value);
|
2005-10-28 15:25:24 +04:00
|
|
|
if (!value.IsEmpty()) {
|
2012-05-16 02:30:14 +04:00
|
|
|
ParseNumericValue(value, &supScriptShift,
|
|
|
|
nsMathMLElement::PARSE_ALLOW_NEGATIVE,
|
|
|
|
PresContext(), mStyleContext);
|
2001-02-23 19:10:51 +03:00
|
|
|
}
|
|
|
|
|
2007-03-31 01:11:41 +04:00
|
|
|
return nsMathMLmsupFrame::PlaceSuperScript(PresContext(),
|
2002-02-07 07:38:08 +03:00
|
|
|
aRenderingContext,
|
|
|
|
aPlaceOrigin,
|
|
|
|
aDesiredSize,
|
|
|
|
this,
|
|
|
|
supScriptShift,
|
|
|
|
scriptSpace);
|
2001-02-02 12:37:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// exported routine that both mover and msup share.
|
|
|
|
// mover uses this when movablelimits is set.
|
|
|
|
nsresult
|
2006-08-04 03:27:55 +04:00
|
|
|
nsMathMLmsupFrame::PlaceSuperScript(nsPresContext* aPresContext,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext& aRenderingContext,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aPlaceOrigin,
|
2006-08-04 03:27:55 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
2007-03-02 13:55:55 +03:00
|
|
|
nsMathMLContainerFrame* aFrame,
|
2006-08-04 03:27:55 +04:00
|
|
|
nscoord aUserSupScriptShift,
|
|
|
|
nscoord aScriptSpace)
|
1999-09-21 06:12:01 +04:00
|
|
|
{
|
2001-02-02 12:37:14 +03:00
|
|
|
// force the scriptSpace to be at least 1 pixel
|
2007-02-07 10:46:44 +03:00
|
|
|
nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
|
2009-09-16 19:01:36 +04:00
|
|
|
aScriptSpace = NS_MAX(onePixel, aScriptSpace);
|
2001-02-02 12:37:14 +03:00
|
|
|
|
2000-01-07 17:49:46 +03:00
|
|
|
////////////////////////////////////
|
|
|
|
// Get the children's desired sizes
|
|
|
|
|
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 08:38:33 +03:00
|
|
|
nsHTMLReflowMetrics baseSize;
|
|
|
|
nsHTMLReflowMetrics supScriptSize;
|
2002-02-07 07:38:08 +03:00
|
|
|
nsBoundingMetrics bmBase, bmSupScript;
|
2000-03-28 13:38:24 +04:00
|
|
|
nsIFrame* supScriptFrame = nsnull;
|
2011-08-25 00:54:30 +04:00
|
|
|
nsIFrame* baseFrame = aFrame->GetFirstPrincipalChild();
|
2002-02-07 07:38:08 +03:00
|
|
|
if (baseFrame)
|
2003-07-08 15:00:00 +04:00
|
|
|
supScriptFrame = baseFrame->GetNextSibling();
|
|
|
|
if (!baseFrame || !supScriptFrame || supScriptFrame->GetNextSibling()) {
|
2000-03-28 13:38:24 +04:00
|
|
|
// report an error, encourage people to get their markups in order
|
2008-10-30 20:10:19 +03:00
|
|
|
return aFrame->ReflowError(aRenderingContext, aDesiredSize);
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
2002-02-07 07:38:08 +03:00
|
|
|
GetReflowAndBoundingMetricsFor(baseFrame, baseSize, bmBase);
|
|
|
|
GetReflowAndBoundingMetricsFor(supScriptFrame, supScriptSize, bmSupScript);
|
|
|
|
|
|
|
|
// get the supdrop from the supscript font
|
|
|
|
nscoord supDrop;
|
2005-02-07 04:57:50 +03:00
|
|
|
GetSupDropFromChild(supScriptFrame, supDrop);
|
2002-02-07 07:38:08 +03:00
|
|
|
// parameter u, Rule 18a, App. G, TeXbook
|
|
|
|
nscoord minSupScriptShift = bmBase.ascent - supDrop;
|
1999-09-21 06:12:01 +04:00
|
|
|
|
2000-01-07 17:49:46 +03:00
|
|
|
//////////////////
|
|
|
|
// Place Children
|
|
|
|
|
|
|
|
// get min supscript shift limit from x-height
|
|
|
|
// = d(x) + 1/4 * sigma_5, Rule 18c, App. G, TeXbook
|
|
|
|
nscoord xHeight = 0;
|
2011-08-14 21:08:04 +04:00
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(baseFrame, getter_AddRefs(fm));
|
2000-01-18 07:35:37 +03:00
|
|
|
|
2011-04-08 08:18:43 +04:00
|
|
|
xHeight = fm->XHeight();
|
2000-01-07 17:49:46 +03:00
|
|
|
nscoord minShiftFromXHeight = (nscoord)
|
2000-01-18 07:35:37 +03:00
|
|
|
(bmSupScript.descent + (1.0f/4.0f) * xHeight);
|
2001-02-02 12:37:14 +03:00
|
|
|
nscoord italicCorrection;
|
|
|
|
GetItalicCorrection(bmBase, italicCorrection);
|
2000-01-07 17:49:46 +03:00
|
|
|
|
2001-02-23 19:10:51 +03:00
|
|
|
// supScriptShift{1,2,3}
|
2000-01-07 17:49:46 +03:00
|
|
|
// = minimum amount to shift the supscript up
|
|
|
|
// = sup{1,2,3} in TeX
|
2001-02-23 19:10:51 +03:00
|
|
|
// supScriptShift1 = superscriptshift attribute * x-height
|
2000-01-07 17:49:46 +03:00
|
|
|
// Note that there are THREE values for supscript shifts depending
|
|
|
|
// on the current style
|
2001-02-23 19:10:51 +03:00
|
|
|
nscoord supScriptShift1, supScriptShift2, supScriptShift3;
|
|
|
|
// Set supScriptShift{1,2,3} default from font
|
|
|
|
GetSupScriptShifts (fm, supScriptShift1, supScriptShift2, supScriptShift3);
|
1999-09-21 06:12:01 +04:00
|
|
|
|
2001-02-02 12:37:14 +03:00
|
|
|
if (0 < aUserSupScriptShift) {
|
2000-01-26 09:49:38 +03:00
|
|
|
// the user has set the superscriptshift attribute
|
2001-02-23 19:10:51 +03:00
|
|
|
float scaler2 = ((float) supScriptShift2) / supScriptShift1;
|
|
|
|
float scaler3 = ((float) supScriptShift3) / supScriptShift1;
|
|
|
|
supScriptShift1 =
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MAX(supScriptShift1, aUserSupScriptShift);
|
2001-02-23 19:10:51 +03:00
|
|
|
supScriptShift2 = NSToCoordRound(scaler2 * supScriptShift1);
|
|
|
|
supScriptShift3 = NSToCoordRound(scaler3 * supScriptShift1);
|
2000-01-07 17:49:46 +03:00
|
|
|
}
|
1999-09-21 06:12:01 +04:00
|
|
|
|
2000-01-07 17:49:46 +03:00
|
|
|
// get sup script shift depending on current script level and display style
|
|
|
|
// Rule 18c, App. G, TeXbook
|
2001-02-23 19:10:51 +03:00
|
|
|
nscoord supScriptShift;
|
2001-02-02 12:37:14 +03:00
|
|
|
nsPresentationData presentationData;
|
2007-03-02 13:55:55 +03:00
|
|
|
aFrame->GetPresentationData (presentationData);
|
2008-01-09 12:38:28 +03:00
|
|
|
if ( aFrame->GetStyleFont()->mScriptLevel == 0 &&
|
2001-02-02 12:37:14 +03:00
|
|
|
NS_MATHML_IS_DISPLAYSTYLE(presentationData.flags) &&
|
|
|
|
!NS_MATHML_IS_COMPRESSED(presentationData.flags)) {
|
2000-01-07 17:49:46 +03:00
|
|
|
// Style D in TeXbook
|
2001-02-23 19:10:51 +03:00
|
|
|
supScriptShift = supScriptShift1;
|
2000-01-07 17:49:46 +03:00
|
|
|
}
|
2001-02-02 12:37:14 +03:00
|
|
|
else if (NS_MATHML_IS_COMPRESSED(presentationData.flags)) {
|
2000-01-07 17:49:46 +03:00
|
|
|
// Style C' in TeXbook = D',T',S',SS'
|
2001-02-23 19:10:51 +03:00
|
|
|
supScriptShift = supScriptShift3;
|
2000-01-07 17:49:46 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// everything else = T,S,SS
|
2001-02-23 19:10:51 +03:00
|
|
|
supScriptShift = supScriptShift2;
|
2000-01-07 17:49:46 +03:00
|
|
|
}
|
2000-01-20 01:36:23 +03:00
|
|
|
|
2000-01-07 17:49:46 +03:00
|
|
|
// get actual supscriptshift to be used
|
|
|
|
// Rule 18c, App. G, TeXbook
|
|
|
|
nscoord actualSupScriptShift =
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MAX(minSupScriptShift,NS_MAX(supScriptShift,minShiftFromXHeight));
|
1999-12-10 16:02:23 +03:00
|
|
|
|
2000-01-20 01:36:23 +03:00
|
|
|
// bounding box
|
2001-02-02 12:37:14 +03:00
|
|
|
nsBoundingMetrics boundingMetrics;
|
|
|
|
boundingMetrics.ascent =
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MAX(bmBase.ascent, (bmSupScript.ascent + actualSupScriptShift));
|
2001-02-02 12:37:14 +03:00
|
|
|
boundingMetrics.descent =
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MAX(bmBase.descent, (bmSupScript.descent - actualSupScriptShift));
|
2005-09-07 03:47:01 +04:00
|
|
|
|
|
|
|
// leave aScriptSpace after superscript
|
|
|
|
// add italicCorrection between base and superscript
|
|
|
|
// add "a little to spare" as well (see TeXbook Ch.11, p.64), as we
|
|
|
|
// estimate the italic creation ourselves and it isn't the same as TeX
|
|
|
|
italicCorrection += onePixel;
|
|
|
|
boundingMetrics.width = bmBase.width + italicCorrection +
|
|
|
|
bmSupScript.width + aScriptSpace;
|
2001-02-02 12:37:14 +03:00
|
|
|
boundingMetrics.leftBearing = bmBase.leftBearing;
|
2005-09-07 03:47:01 +04:00
|
|
|
boundingMetrics.rightBearing = bmBase.width + italicCorrection +
|
|
|
|
bmSupScript.rightBearing;
|
2007-03-02 13:55:55 +03:00
|
|
|
aFrame->SetBoundingMetrics(boundingMetrics);
|
2000-01-14 11:38:25 +03:00
|
|
|
|
2000-01-20 01:36:23 +03:00
|
|
|
// reflow metrics
|
|
|
|
aDesiredSize.ascent =
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MAX(baseSize.ascent, (supScriptSize.ascent + actualSupScriptShift));
|
2007-01-23 07:06:56 +03:00
|
|
|
aDesiredSize.height = aDesiredSize.ascent +
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MAX(baseSize.height - baseSize.ascent,
|
2007-01-23 07:06:56 +03:00
|
|
|
(supScriptSize.height - supScriptSize.ascent - actualSupScriptShift));
|
2005-09-07 03:47:01 +04:00
|
|
|
aDesiredSize.width = boundingMetrics.width;
|
2001-02-03 00:29:21 +03:00
|
|
|
aDesiredSize.mBoundingMetrics = boundingMetrics;
|
2000-01-18 07:35:37 +03:00
|
|
|
|
2007-03-02 13:55:55 +03:00
|
|
|
aFrame->SetReference(nsPoint(0, aDesiredSize.ascent));
|
2000-01-07 17:49:46 +03:00
|
|
|
|
|
|
|
if (aPlaceOrigin) {
|
|
|
|
nscoord dx, dy;
|
|
|
|
// now place the base ...
|
2010-01-05 13:22:31 +03:00
|
|
|
dx = aFrame->MirrorIfRTL(aDesiredSize.width, baseSize.width, 0);
|
|
|
|
dy = aDesiredSize.ascent - baseSize.ascent;
|
2001-12-07 17:51:12 +03:00
|
|
|
FinishReflowChild (baseFrame, aPresContext, nsnull, baseSize, dx, dy, 0);
|
2000-01-07 17:49:46 +03:00
|
|
|
// ... and supscript
|
2010-01-05 13:22:31 +03:00
|
|
|
dx = aFrame->MirrorIfRTL(aDesiredSize.width, supScriptSize.width,
|
|
|
|
bmBase.width + italicCorrection);
|
2000-01-20 01:36:23 +03:00
|
|
|
dy = aDesiredSize.ascent - (supScriptSize.ascent + actualSupScriptShift);
|
2001-12-07 17:51:12 +03:00
|
|
|
FinishReflowChild (supScriptFrame, aPresContext, nsnull, supScriptSize, dx, dy, 0);
|
1999-09-21 06:12:01 +04:00
|
|
|
}
|
2000-01-07 17:49:46 +03:00
|
|
|
|
1999-09-21 06:12:01 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|