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
|
1999-12-10 16:02:23 +03:00
|
|
|
*
|
2004-04-18 18:30:37 +04: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.
|
1999-12-10 16:02:23 +03:00
|
|
|
*
|
1999-09-21 06:12:01 +04:00
|
|
|
* The Original Code is Mozilla MathML Project.
|
1999-12-10 16:02:23 +03:00
|
|
|
*
|
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.
|
1999-12-10 16:02:23 +03:00
|
|
|
*
|
|
|
|
* 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-03-28 13:38:24 +04:00
|
|
|
* Shyjan Mahamud <mahamud@cs.cmu.edu>
|
2000-02-03 01:24:56 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
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 "nsINameSpaceManager.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
|
|
|
|
#include "nsMathMLmunderoverFrame.h"
|
2001-02-02 12:37:14 +03:00
|
|
|
#include "nsMathMLmsubsupFrame.h"
|
1999-09-21 06:12:01 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// <munderover> -- attach an underscript-overscript pair to a base - implementation
|
|
|
|
//
|
|
|
|
|
2005-11-11 05:36:29 +03:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewMathMLmunderoverFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1999-09-21 06:12:01 +04:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsMathMLmunderoverFrame(aContext);
|
1999-09-21 06:12:01 +04:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmunderoverFrame)
|
|
|
|
|
1999-09-21 06:12:01 +04:00
|
|
|
nsMathMLmunderoverFrame::~nsMathMLmunderoverFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-02-07 07:38:08 +03:00
|
|
|
NS_IMETHODIMP
|
2005-09-07 20:49:21 +04:00
|
|
|
nsMathMLmunderoverFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
2002-02-07 07:38:08 +03:00
|
|
|
nsIAtom* aAttribute,
|
2003-07-12 01:16:12 +04:00
|
|
|
PRInt32 aModType)
|
2002-02-07 07:38:08 +03:00
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
if (nsGkAtoms::accent_ == aAttribute ||
|
|
|
|
nsGkAtoms::accentunder_ == aAttribute) {
|
2002-02-07 07:38:08 +03:00
|
|
|
// When we have automatic data to update within ourselves, we ask our
|
|
|
|
// parent to re-layout its children
|
2009-02-11 01:05:27 +03:00
|
|
|
return ReLayoutChildren(mParent);
|
2002-02-07 07:38:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsMathMLContainerFrame::
|
2005-09-07 20:49:21 +04:00
|
|
|
AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
2002-02-07 07:38:08 +03:00
|
|
|
}
|
|
|
|
|
2002-01-09 21:51:30 +03:00
|
|
|
NS_IMETHODIMP
|
2008-01-09 12:38:28 +03:00
|
|
|
nsMathMLmunderoverFrame::UpdatePresentationData(PRUint32 aFlagsValues,
|
2002-01-09 21:51:30 +03:00
|
|
|
PRUint32 aFlagsToUpdate)
|
|
|
|
{
|
2008-01-09 12:38:28 +03:00
|
|
|
nsMathMLContainerFrame::UpdatePresentationData(aFlagsValues, aFlagsToUpdate);
|
2002-01-09 21:51:30 +03:00
|
|
|
// disable the stretch-all flag if we are going to act like a subscript-superscript pair
|
2002-02-07 07:38:08 +03:00
|
|
|
if ( NS_MATHML_EMBELLISH_IS_MOVABLELIMITS(mEmbellishData.flags) &&
|
2002-01-09 21:51:30 +03:00
|
|
|
!NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags)) {
|
2002-02-07 07:38:08 +03:00
|
|
|
mPresentationData.flags &= ~NS_MATHML_STRETCH_ALL_CHILDREN_HORIZONTALLY;
|
2002-01-09 21:51:30 +03:00
|
|
|
}
|
|
|
|
else {
|
2002-02-07 07:38:08 +03:00
|
|
|
mPresentationData.flags |= NS_MATHML_STRETCH_ALL_CHILDREN_HORIZONTALLY;
|
2002-01-09 21:51:30 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-10 07:42:55 +03:00
|
|
|
NS_IMETHODIMP
|
2005-02-07 04:57:50 +03:00
|
|
|
nsMathMLmunderoverFrame::UpdatePresentationDataFromChildAt(PRInt32 aFirstIndex,
|
2002-01-10 07:42:55 +03:00
|
|
|
PRInt32 aLastIndex,
|
|
|
|
PRUint32 aFlagsValues,
|
|
|
|
PRUint32 aFlagsToUpdate)
|
|
|
|
{
|
|
|
|
// munderover is special... The REC says:
|
|
|
|
// Within underscript, <munder> always sets displaystyle to "false",
|
|
|
|
// but increments scriptlevel by 1 only when accentunder is "false".
|
|
|
|
// Within underscript, <munderover> always sets displaystyle to "false",
|
|
|
|
// but increments scriptlevel by 1 only when accentunder is "false".
|
|
|
|
// This means that
|
|
|
|
// 1. don't allow displaystyle to change in the underscript & overscript
|
|
|
|
// 2a if the value of the accent is changed, we need to recompute the
|
|
|
|
// scriptlevel of the underscript. The problem is that the accent
|
|
|
|
// can change in the <mo> deep down the embellished hierarchy
|
|
|
|
// 2b if the value of the accent is changed, we need to recompute the
|
|
|
|
// scriptlevel of the overscript. The problem is that the accent
|
|
|
|
// can change in the <mo> deep down the embellished hierarchy
|
|
|
|
|
|
|
|
// Do #1 here, prevent displaystyle to be changed in the underscript & overscript
|
|
|
|
PRInt32 index = 0;
|
|
|
|
nsIFrame* childFrame = mFrames.FirstChild();
|
|
|
|
while (childFrame) {
|
|
|
|
if ((index >= aFirstIndex) &&
|
|
|
|
((aLastIndex <= 0) || ((aLastIndex > 0) && (index <= aLastIndex)))) {
|
|
|
|
if (index > 0) {
|
|
|
|
// disable the flag
|
|
|
|
aFlagsToUpdate &= ~NS_MATHML_DISPLAYSTYLE;
|
|
|
|
aFlagsValues &= ~NS_MATHML_DISPLAYSTYLE;
|
|
|
|
}
|
2008-01-09 12:38:28 +03:00
|
|
|
PropagatePresentationDataFor(childFrame, aFlagsValues, aFlagsToUpdate);
|
2002-01-10 07:42:55 +03:00
|
|
|
}
|
|
|
|
index++;
|
2003-07-08 15:00:00 +04:00
|
|
|
childFrame = childFrame->GetNextSibling();
|
2002-01-10 07:42:55 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
|
2002-02-08 03:58:15 +03:00
|
|
|
// For #2, changing the accent attribute will trigger a re-build of
|
|
|
|
// all automatic data in the embellished hierarchy
|
2002-01-10 07:42:55 +03:00
|
|
|
}
|
|
|
|
|
2000-01-14 11:38:25 +03:00
|
|
|
NS_IMETHODIMP
|
2005-02-07 04:57:50 +03:00
|
|
|
nsMathMLmunderoverFrame::InheritAutomaticData(nsIFrame* aParent)
|
2000-01-14 11:38:25 +03:00
|
|
|
{
|
2002-02-07 07:38:08 +03:00
|
|
|
// let the base class get the default from our parent
|
2005-02-07 04:57:50 +03:00
|
|
|
nsMathMLContainerFrame::InheritAutomaticData(aParent);
|
2002-02-01 18:10:50 +03:00
|
|
|
|
2002-02-07 07:38:08 +03:00
|
|
|
mPresentationData.flags |= NS_MATHML_STRETCH_ALL_CHILDREN_HORIZONTALLY;
|
2000-01-14 11:38:25 +03:00
|
|
|
|
2002-02-07 07:38:08 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-02-07 04:57:50 +03:00
|
|
|
nsMathMLmunderoverFrame::TransmitAutomaticData()
|
2002-02-07 07:38:08 +03:00
|
|
|
{
|
|
|
|
// At this stage, all our children are in sync and we can fully
|
|
|
|
// resolve our own mEmbellishData struct
|
|
|
|
//---------------------------------------------------------------------
|
2000-01-14 11:38:25 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
The REC says:
|
|
|
|
|
|
|
|
The accent and accentunder attributes have the same effect as
|
|
|
|
the attributes with the same names on <mover> and <munder>,
|
|
|
|
respectively. Their default values are also computed in the
|
|
|
|
same manner as described for those elements, with the default
|
|
|
|
value of accent depending on overscript and the default value
|
|
|
|
of accentunder depending on underscript.
|
|
|
|
*/
|
|
|
|
|
|
|
|
nsIFrame* overscriptFrame = nsnull;
|
2002-02-07 07:38:08 +03:00
|
|
|
nsIFrame* underscriptFrame = nsnull;
|
|
|
|
nsIFrame* baseFrame = mFrames.FirstChild();
|
|
|
|
if (baseFrame)
|
2003-07-08 15:00:00 +04:00
|
|
|
underscriptFrame = baseFrame->GetNextSibling();
|
2002-02-07 07:38:08 +03:00
|
|
|
if (underscriptFrame)
|
2003-07-08 15:00:00 +04:00
|
|
|
overscriptFrame = underscriptFrame->GetNextSibling();
|
2002-02-07 07:38:08 +03:00
|
|
|
|
|
|
|
// if our base is an embellished operator, let its state bubble to us (in particular,
|
|
|
|
// this is where we get the flag for NS_MATHML_EMBELLISH_MOVABLELIMITS). Our flags
|
|
|
|
// are reset to the default values of false if the base frame isn't embellished.
|
2005-09-07 03:47:01 +04:00
|
|
|
mPresentationData.baseFrame = baseFrame;
|
2002-02-07 07:38:08 +03:00
|
|
|
GetEmbellishDataFrom(baseFrame, mEmbellishData);
|
2000-01-14 11:38:25 +03:00
|
|
|
|
2002-02-07 07:38:08 +03:00
|
|
|
// The default value of accentunder is false, unless the underscript is embellished
|
|
|
|
// and its core <mo> is an accent
|
|
|
|
nsEmbellishData embellishData;
|
|
|
|
GetEmbellishDataFrom(underscriptFrame, embellishData);
|
|
|
|
if (NS_MATHML_EMBELLISH_IS_ACCENT(embellishData.flags))
|
|
|
|
mEmbellishData.flags |= NS_MATHML_EMBELLISH_ACCENTUNDER;
|
|
|
|
else
|
|
|
|
mEmbellishData.flags &= ~NS_MATHML_EMBELLISH_ACCENTUNDER;
|
|
|
|
|
2006-04-24 09:40:11 +04:00
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
2006-12-26 20:47:52 +03:00
|
|
|
{&nsGkAtoms::_true, &nsGkAtoms::_false, nsnull};
|
2006-04-24 09:40:11 +04:00
|
|
|
|
2002-02-07 07:38:08 +03:00
|
|
|
// if we have an accentunder attribute, it overrides what the underscript said
|
2006-12-26 20:47:52 +03:00
|
|
|
switch (mContent->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::accentunder_,
|
2006-04-24 09:40:11 +04:00
|
|
|
strings, eCaseMatters)) {
|
|
|
|
case 0: mEmbellishData.flags |= NS_MATHML_EMBELLISH_ACCENTUNDER; break;
|
|
|
|
case 1: mEmbellishData.flags &= ~NS_MATHML_EMBELLISH_ACCENTUNDER; break;
|
|
|
|
}
|
2000-01-14 11:38:25 +03:00
|
|
|
|
2002-02-07 07:38:08 +03:00
|
|
|
// The default value of accent is false, unless the overscript is embellished
|
|
|
|
// and its core <mo> is an accent
|
|
|
|
GetEmbellishDataFrom(overscriptFrame, embellishData);
|
|
|
|
if (NS_MATHML_EMBELLISH_IS_ACCENT(embellishData.flags))
|
|
|
|
mEmbellishData.flags |= NS_MATHML_EMBELLISH_ACCENTOVER;
|
|
|
|
else
|
|
|
|
mEmbellishData.flags &= ~NS_MATHML_EMBELLISH_ACCENTOVER;
|
|
|
|
|
|
|
|
// if we have an accent attribute, it overrides what the overscript said
|
2006-12-26 20:47:52 +03:00
|
|
|
switch (mContent->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::accent_,
|
2006-04-24 09:40:11 +04:00
|
|
|
strings, eCaseMatters)) {
|
|
|
|
case 0: mEmbellishData.flags |= NS_MATHML_EMBELLISH_ACCENTOVER; break;
|
|
|
|
case 1: mEmbellishData.flags &= ~NS_MATHML_EMBELLISH_ACCENTOVER; break;
|
|
|
|
}
|
2000-01-14 11:38:25 +03:00
|
|
|
|
2002-02-07 07:38:08 +03:00
|
|
|
// disable the stretch-all flag if we are going to act like a superscript
|
|
|
|
if ( NS_MATHML_EMBELLISH_IS_MOVABLELIMITS(mEmbellishData.flags) &&
|
|
|
|
!NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags))
|
|
|
|
mPresentationData.flags &= ~NS_MATHML_STRETCH_ALL_CHILDREN_HORIZONTALLY;
|
2000-01-14 11:38:25 +03:00
|
|
|
|
2002-02-07 07:38:08 +03:00
|
|
|
// Now transmit any change that we want to our children so that they
|
|
|
|
// can update their mPresentationData structs
|
|
|
|
//---------------------------------------------------------------------
|
2000-01-14 11:38:25 +03:00
|
|
|
|
2002-02-07 07:38:08 +03:00
|
|
|
/* The REC says:
|
|
|
|
Within underscript, <munderover> always sets displaystyle to "false",
|
|
|
|
but increments scriptlevel by 1 only when accentunder is "false".
|
|
|
|
|
|
|
|
Within overscript, <munderover> always sets displaystyle to "false",
|
|
|
|
but increments scriptlevel by 1 only when accent is "false".
|
|
|
|
|
2001-02-02 12:37:14 +03:00
|
|
|
The TeXBook treats 'over' like a superscript, so p.141 or Rule 13a
|
|
|
|
say it shouldn't be compressed. However, The TeXBook says
|
|
|
|
that math accents and \overline change uncramped styles to their
|
|
|
|
cramped counterparts.
|
|
|
|
*/
|
2002-02-07 07:38:08 +03:00
|
|
|
PRUint32 compress = NS_MATHML_EMBELLISH_IS_ACCENTOVER(mEmbellishData.flags)
|
|
|
|
? NS_MATHML_COMPRESSED : 0;
|
2008-01-09 12:38:28 +03:00
|
|
|
SetIncrementScriptLevel(2, !NS_MATHML_EMBELLISH_IS_ACCENTOVER(mEmbellishData.flags));
|
|
|
|
PropagatePresentationDataFor(overscriptFrame,
|
2002-02-07 07:38:08 +03:00
|
|
|
~NS_MATHML_DISPLAYSTYLE | compress,
|
|
|
|
NS_MATHML_DISPLAYSTYLE | compress);
|
2001-02-02 12:37:14 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
The TeXBook treats 'under' like a subscript, so p.141 or Rule 13a
|
|
|
|
say it should be compressed
|
|
|
|
*/
|
2008-01-09 12:38:28 +03:00
|
|
|
SetIncrementScriptLevel(1, !NS_MATHML_EMBELLISH_IS_ACCENTUNDER(mEmbellishData.flags));
|
|
|
|
PropagatePresentationDataFor(underscriptFrame,
|
2002-02-07 07:38:08 +03:00
|
|
|
~NS_MATHML_DISPLAYSTYLE | NS_MATHML_COMPRESSED,
|
|
|
|
NS_MATHML_DISPLAYSTYLE | NS_MATHML_COMPRESSED);
|
2002-01-04 02:18:01 +03:00
|
|
|
|
2002-02-01 18:10:50 +03:00
|
|
|
return NS_OK;
|
2000-01-14 11:38:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
The REC says:
|
|
|
|
* If the base is an operator with movablelimits="true" (or an embellished
|
|
|
|
operator whose <mo> element core has movablelimits="true"), and
|
|
|
|
displaystyle="false", then underscript and overscript are drawn in
|
|
|
|
a subscript and superscript position, respectively. In this case,
|
|
|
|
the accent and accentunder attributes are ignored. This is often
|
|
|
|
used for limits on symbols such as ∑.
|
|
|
|
|
2001-02-02 12:37:14 +03:00
|
|
|
i.e.,:
|
2002-02-07 07:38:08 +03:00
|
|
|
if ( NS_MATHML_EMBELLISH_IS_MOVABLELIMITS(mEmbellishDataflags) &&
|
2000-01-14 11:38:25 +03:00
|
|
|
!NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags)) {
|
|
|
|
// place like subscript-superscript pair
|
|
|
|
}
|
|
|
|
else {
|
2001-02-02 12:37:14 +03:00
|
|
|
// place like underscript-overscript pair
|
2000-01-14 11:38:25 +03:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2008-03-18 07:52:48 +03:00
|
|
|
/* virtual */ nsresult
|
2006-08-04 03:27:55 +04:00
|
|
|
nsMathMLmunderoverFrame::Place(nsIRenderingContext& aRenderingContext,
|
|
|
|
PRBool aPlaceOrigin,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize)
|
1999-12-10 16:02:23 +03:00
|
|
|
{
|
2002-02-07 07:38:08 +03:00
|
|
|
if ( NS_MATHML_EMBELLISH_IS_MOVABLELIMITS(mEmbellishData.flags) &&
|
2001-02-23 19:10:51 +03:00
|
|
|
!NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags)) {
|
2001-02-02 12:37:14 +03:00
|
|
|
// place like sub-superscript pair
|
2007-03-31 01:11:41 +04:00
|
|
|
return nsMathMLmsubsupFrame::PlaceSubSupScript(PresContext(),
|
2001-02-02 12:37:14 +03:00
|
|
|
aRenderingContext,
|
|
|
|
aPlaceOrigin,
|
|
|
|
aDesiredSize,
|
2007-03-31 01:11:41 +04:00
|
|
|
this, 0, 0, PresContext()->PointsToAppUnits(0.5f));
|
2001-02-02 12:37:14 +03:00
|
|
|
}
|
|
|
|
|
2000-03-28 13:38:24 +04:00
|
|
|
////////////////////////////////////
|
|
|
|
// Get the children's desired sizes
|
|
|
|
|
|
|
|
nsBoundingMetrics bmBase, bmUnder, bmOver;
|
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 underSize;
|
|
|
|
nsHTMLReflowMetrics overSize;
|
2000-03-28 13:38:24 +04:00
|
|
|
nsIFrame* overFrame = nsnull;
|
|
|
|
nsIFrame* underFrame = nsnull;
|
2002-02-07 07:38:08 +03:00
|
|
|
nsIFrame* baseFrame = mFrames.FirstChild();
|
|
|
|
if (baseFrame)
|
2003-07-08 15:00:00 +04:00
|
|
|
underFrame = baseFrame->GetNextSibling();
|
2002-02-07 07:38:08 +03:00
|
|
|
if (underFrame)
|
2003-07-08 15:00:00 +04:00
|
|
|
overFrame = underFrame->GetNextSibling();
|
|
|
|
if (!baseFrame || !underFrame || !overFrame || overFrame->GetNextSibling()) {
|
2000-03-28 13:38:24 +04:00
|
|
|
// report an error, encourage people to get their markups in order
|
2006-08-04 03:27:55 +04:00
|
|
|
return ReflowError(aRenderingContext, aDesiredSize);
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
2002-02-07 07:38:08 +03:00
|
|
|
GetReflowAndBoundingMetricsFor(baseFrame, baseSize, bmBase);
|
|
|
|
GetReflowAndBoundingMetricsFor(underFrame, underSize, bmUnder);
|
|
|
|
GetReflowAndBoundingMetricsFor(overFrame, overSize, bmOver);
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2007-02-07 10:46:44 +03:00
|
|
|
nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
|
2003-01-22 10:42:20 +03:00
|
|
|
|
2000-03-28 13:38:24 +04:00
|
|
|
////////////////////
|
|
|
|
// Place Children
|
|
|
|
|
2010-02-24 20:57:44 +03:00
|
|
|
aRenderingContext.SetFont(GetStyleFont()->mFont,
|
2008-12-04 19:09:53 +03:00
|
|
|
PresContext()->GetUserFontSet());
|
1999-09-21 06:12:01 +04:00
|
|
|
nsCOMPtr<nsIFontMetrics> fm;
|
2000-03-28 13:38:24 +04:00
|
|
|
aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));
|
|
|
|
|
|
|
|
nscoord xHeight = 0;
|
|
|
|
fm->GetXHeight (xHeight);
|
|
|
|
|
|
|
|
nscoord ruleThickness;
|
|
|
|
GetRuleThickness (aRenderingContext, fm, ruleThickness);
|
|
|
|
|
2003-01-22 10:42:20 +03:00
|
|
|
nscoord correction = 0;
|
|
|
|
GetItalicCorrection (bmBase, correction);
|
|
|
|
|
2000-03-28 13:38:24 +04:00
|
|
|
// there are 2 different types of placement depending on
|
|
|
|
// whether we want an accented under or not
|
|
|
|
|
|
|
|
nscoord underDelta1 = 0; // gap between base and underscript
|
|
|
|
nscoord underDelta2 = 0; // extra space beneath underscript
|
|
|
|
|
2002-02-07 07:38:08 +03:00
|
|
|
if (!NS_MATHML_EMBELLISH_IS_ACCENTUNDER(mEmbellishData.flags)) {
|
2000-03-28 13:38:24 +04:00
|
|
|
// Rule 13a, App. G, TeXbook
|
|
|
|
nscoord bigOpSpacing2, bigOpSpacing4, bigOpSpacing5, dummy;
|
|
|
|
GetBigOpSpacings (fm,
|
|
|
|
dummy, bigOpSpacing2,
|
|
|
|
dummy, bigOpSpacing4,
|
|
|
|
bigOpSpacing5);
|
2009-09-16 19:01:36 +04:00
|
|
|
underDelta1 = NS_MAX(bigOpSpacing2, (bigOpSpacing4 - bmUnder.ascent));
|
2000-03-28 13:38:24 +04:00
|
|
|
underDelta2 = bigOpSpacing5;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// No corresponding rule in TeXbook - we are on our own here
|
|
|
|
// XXX tune the gap delta between base and underscript
|
1999-12-10 16:02:23 +03:00
|
|
|
|
2000-03-28 13:38:24 +04:00
|
|
|
// Should we use Rule 10 like \underline does?
|
2003-01-22 10:42:20 +03:00
|
|
|
underDelta1 = ruleThickness + onePixel/2;
|
2000-03-28 13:38:24 +04:00
|
|
|
underDelta2 = ruleThickness;
|
|
|
|
}
|
|
|
|
// empty under?
|
2001-02-23 19:10:51 +03:00
|
|
|
if (!(bmUnder.ascent + bmUnder.descent)) underDelta1 = 0;
|
2000-03-28 13:38:24 +04:00
|
|
|
|
|
|
|
nscoord overDelta1 = 0; // gap between base and overscript
|
|
|
|
nscoord overDelta2 = 0; // extra space above overscript
|
|
|
|
|
2002-02-07 07:38:08 +03:00
|
|
|
if (!NS_MATHML_EMBELLISH_IS_ACCENTOVER(mEmbellishData.flags)) {
|
2000-03-28 13:38:24 +04:00
|
|
|
// Rule 13a, App. G, TeXbook
|
|
|
|
nscoord bigOpSpacing1, bigOpSpacing3, bigOpSpacing5, dummy;
|
|
|
|
GetBigOpSpacings (fm,
|
|
|
|
bigOpSpacing1, dummy,
|
|
|
|
bigOpSpacing3, dummy,
|
|
|
|
bigOpSpacing5);
|
2009-09-16 19:01:36 +04:00
|
|
|
overDelta1 = NS_MAX(bigOpSpacing1, (bigOpSpacing3 - bmOver.descent));
|
2000-03-28 13:38:24 +04:00
|
|
|
overDelta2 = bigOpSpacing5;
|
|
|
|
|
|
|
|
// XXX This is not a TeX rule...
|
|
|
|
// delta1 (as computed abvove) can become really big when bmOver.descent is
|
|
|
|
// negative, e.g., if the content is &OverBar. In such case, we use the height
|
|
|
|
if (bmOver.descent < 0)
|
2009-09-16 19:01:36 +04:00
|
|
|
overDelta1 = NS_MAX(bigOpSpacing1, (bigOpSpacing3 - (bmOver.ascent + bmOver.descent)));
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
|
|
|
else {
|
2003-01-22 10:42:20 +03:00
|
|
|
// Rule 12, App. G, TeXbook
|
|
|
|
overDelta1 = ruleThickness + onePixel/2;
|
2001-02-02 12:37:14 +03:00
|
|
|
if (bmBase.ascent < xHeight) {
|
|
|
|
overDelta1 += xHeight - bmBase.ascent;
|
|
|
|
}
|
2000-03-28 13:38:24 +04:00
|
|
|
overDelta2 = ruleThickness;
|
1999-09-21 06:12:01 +04:00
|
|
|
}
|
2000-03-28 13:38:24 +04:00
|
|
|
// empty over?
|
2001-02-23 19:10:51 +03:00
|
|
|
if (!(bmOver.ascent + bmOver.descent)) overDelta1 = 0;
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2003-01-22 10:42:20 +03:00
|
|
|
nscoord dxBase, dxOver = 0, dxUnder = 0;
|
|
|
|
|
|
|
|
//////////
|
|
|
|
// pass 1, do what <mover> does: attach the overscript on the base
|
|
|
|
|
|
|
|
// Ad-hoc - This is to override fonts which have ready-made _accent_
|
|
|
|
// glyphs with negative lbearing and rbearing. We want to position
|
|
|
|
// the overscript ourselves
|
|
|
|
nscoord overWidth = bmOver.width;
|
|
|
|
if (!overWidth && (bmOver.rightBearing - bmOver.leftBearing > 0)) {
|
|
|
|
overWidth = bmOver.rightBearing - bmOver.leftBearing;
|
|
|
|
dxOver = -bmOver.leftBearing;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_MATHML_EMBELLISH_IS_ACCENTOVER(mEmbellishData.flags)) {
|
|
|
|
mBoundingMetrics.width = bmBase.width;
|
|
|
|
dxOver += correction + (mBoundingMetrics.width - overWidth)/2;
|
|
|
|
}
|
|
|
|
else {
|
2009-09-16 19:01:36 +04:00
|
|
|
mBoundingMetrics.width = NS_MAX(bmBase.width, overWidth);
|
2003-01-22 10:42:20 +03:00
|
|
|
dxOver += correction/2 + (mBoundingMetrics.width - overWidth)/2;
|
|
|
|
}
|
|
|
|
dxBase = (mBoundingMetrics.width - bmBase.width)/2;
|
|
|
|
|
2000-03-28 13:38:24 +04:00
|
|
|
mBoundingMetrics.ascent =
|
|
|
|
bmBase.ascent + overDelta1 + bmOver.ascent + bmOver.descent;
|
|
|
|
mBoundingMetrics.descent =
|
|
|
|
bmBase.descent + underDelta1 + bmUnder.ascent + bmUnder.descent;
|
2001-02-03 00:31:23 +03:00
|
|
|
mBoundingMetrics.leftBearing =
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MIN(dxBase + bmBase.leftBearing, dxOver + bmOver.leftBearing);
|
2001-02-03 00:31:23 +03:00
|
|
|
mBoundingMetrics.rightBearing =
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MAX(dxBase + bmBase.rightBearing, dxOver + bmOver.rightBearing);
|
2003-01-22 10:42:20 +03:00
|
|
|
|
|
|
|
//////////
|
|
|
|
// pass 2, do what <munder> does: attach the underscript on the previous
|
|
|
|
// result. We conceptually view the previous result as an "anynomous base"
|
|
|
|
// from where to attach the underscript. Hence if the underscript is empty,
|
|
|
|
// we should end up like <mover>. If the overscript is empty, we should
|
|
|
|
// end up like <munder>.
|
2001-02-03 00:31:23 +03:00
|
|
|
|
2003-01-22 10:42:20 +03:00
|
|
|
nsBoundingMetrics bmAnonymousBase = mBoundingMetrics;
|
|
|
|
nscoord ascentAnonymousBase =
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MAX(mBoundingMetrics.ascent + overDelta2,
|
2001-02-02 12:37:14 +03:00
|
|
|
overSize.ascent + bmOver.descent + overDelta1 + bmBase.ascent);
|
2003-01-22 10:42:20 +03:00
|
|
|
|
|
|
|
GetItalicCorrection(bmAnonymousBase, correction);
|
|
|
|
|
2008-07-21 11:32:46 +04:00
|
|
|
// Width of non-spacing marks is zero so use left and right bearing.
|
|
|
|
nscoord underWidth = bmUnder.width;
|
|
|
|
if (!underWidth) {
|
|
|
|
underWidth = bmUnder.rightBearing - bmUnder.leftBearing;
|
|
|
|
dxUnder = -bmUnder.leftBearing;
|
|
|
|
}
|
|
|
|
|
2009-09-16 19:01:36 +04:00
|
|
|
nscoord maxWidth = NS_MAX(bmAnonymousBase.width, underWidth);
|
2008-07-21 11:32:46 +04:00
|
|
|
if (NS_MATHML_EMBELLISH_IS_ACCENTUNDER(mEmbellishData.flags)) {
|
|
|
|
dxUnder += (maxWidth - underWidth)/2;;
|
2003-01-22 10:42:20 +03:00
|
|
|
}
|
|
|
|
else {
|
2008-07-21 11:32:46 +04:00
|
|
|
dxUnder += -correction/2 + (maxWidth - underWidth)/2;
|
2003-01-22 10:42:20 +03:00
|
|
|
}
|
|
|
|
nscoord dxAnonymousBase = (maxWidth - bmAnonymousBase.width)/2;
|
|
|
|
|
|
|
|
// adjust the offsets of the real base and overscript since their
|
|
|
|
// final offsets should be relative to us...
|
|
|
|
dxOver += dxAnonymousBase;
|
|
|
|
dxBase += dxAnonymousBase;
|
|
|
|
|
|
|
|
mBoundingMetrics.width =
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MAX(dxAnonymousBase + bmAnonymousBase.width, dxUnder + bmUnder.width);
|
2003-01-22 10:42:20 +03:00
|
|
|
mBoundingMetrics.leftBearing =
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MIN(dxAnonymousBase + bmAnonymousBase.leftBearing, dxUnder + bmUnder.leftBearing);
|
2003-01-22 10:42:20 +03:00
|
|
|
mBoundingMetrics.rightBearing =
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MAX(dxAnonymousBase + bmAnonymousBase.rightBearing, dxUnder + bmUnder.rightBearing);
|
2003-01-22 10:42:20 +03:00
|
|
|
|
|
|
|
aDesiredSize.ascent = ascentAnonymousBase;
|
2007-01-23 07:06:56 +03:00
|
|
|
aDesiredSize.height = aDesiredSize.ascent +
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MAX(mBoundingMetrics.descent + underDelta2,
|
2007-01-23 07:06:56 +03:00
|
|
|
bmAnonymousBase.descent + underDelta1 + bmUnder.ascent +
|
|
|
|
underSize.height - underSize.ascent);
|
2000-03-28 13:38:24 +04:00
|
|
|
aDesiredSize.width = mBoundingMetrics.width;
|
2001-02-03 00:31:23 +03:00
|
|
|
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
|
2000-03-28 13:38:24 +04:00
|
|
|
|
|
|
|
mReference.x = 0;
|
|
|
|
mReference.y = aDesiredSize.ascent;
|
|
|
|
|
|
|
|
if (aPlaceOrigin) {
|
|
|
|
nscoord dy;
|
|
|
|
// place overscript
|
|
|
|
dy = aDesiredSize.ascent - mBoundingMetrics.ascent + bmOver.ascent - overSize.ascent;
|
2007-03-31 01:11:41 +04:00
|
|
|
FinishReflowChild (overFrame, PresContext(), nsnull, overSize, dxOver, dy, 0);
|
2000-03-28 13:38:24 +04:00
|
|
|
// place base
|
|
|
|
dy = aDesiredSize.ascent - baseSize.ascent;
|
2007-03-31 01:11:41 +04:00
|
|
|
FinishReflowChild (baseFrame, PresContext(), nsnull, baseSize, dxBase, dy, 0);
|
2000-03-28 13:38:24 +04:00
|
|
|
// place underscript
|
|
|
|
dy = aDesiredSize.ascent + mBoundingMetrics.descent - bmUnder.descent - underSize.ascent;
|
2007-03-31 01:11:41 +04:00
|
|
|
FinishReflowChild (underFrame, PresContext(), nsnull, underSize, dxUnder, dy, 0);
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
1999-09-21 06:12:01 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|