2007-06-12 10:10:23 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
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"
|
2011-04-08 05:04:40 +04:00
|
|
|
#include "nsRenderingContext.h"
|
1999-09-21 06:12:01 +04:00
|
|
|
|
|
|
|
#include "nsMathMLmrootFrame.h"
|
|
|
|
|
|
|
|
//
|
2000-03-28 13:38:24 +04:00
|
|
|
// <msqrt> and <mroot> -- form a radical - implementation
|
1999-09-21 06:12:01 +04:00
|
|
|
//
|
|
|
|
|
2000-04-17 08:23:03 +04:00
|
|
|
//NOTE:
|
|
|
|
// The code assumes that TeX fonts are picked.
|
2002-02-07 07:38:08 +03:00
|
|
|
// There is no fall-back to draw the branches of the sqrt explicitly
|
|
|
|
// in the case where TeX fonts are not there. In general, there are no
|
2000-04-17 08:23:03 +04:00
|
|
|
// fall-back(s) in MathML when some (freely-downloadable) fonts are missing.
|
|
|
|
// Otherwise, this will add much work and unnecessary complexity to the core
|
|
|
|
// MathML engine. Assuming that authors have the free fonts is part of the
|
|
|
|
// deal. We are not responsible for cases of misconfigurations out there.
|
2000-03-28 13:38:24 +04:00
|
|
|
|
|
|
|
// additional style context to be used by our MathMLChar.
|
|
|
|
#define NS_SQR_CHAR_STYLE_CONTEXT_INDEX 0
|
|
|
|
|
2001-02-02 12:39:18 +03:00
|
|
|
static const PRUnichar kSqrChar = PRUnichar(0x221A);
|
|
|
|
|
2005-11-11 05:36:29 +03:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewMathMLmrootFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1999-09-21 06:12:01 +04:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsMathMLmrootFrame(aContext);
|
1999-09-21 06:12:01 +04:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmrootFrame)
|
|
|
|
|
2006-03-27 01:30:36 +04:00
|
|
|
nsMathMLmrootFrame::nsMathMLmrootFrame(nsStyleContext* aContext) :
|
|
|
|
nsMathMLContainerFrame(aContext),
|
1999-11-23 09:04:02 +03:00
|
|
|
mSqrChar(),
|
2000-03-28 13:38:24 +04:00
|
|
|
mBarRect()
|
1999-09-21 06:12:01 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMathMLmrootFrame::~nsMathMLmrootFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-03-09 21:55:21 +03:00
|
|
|
nsMathMLmrootFrame::Init(nsIContent* aContent,
|
2000-03-28 13:38:24 +04:00
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
1999-09-21 06:12:01 +04:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
nsresult rv = nsMathMLContainerFrame::Init(aContent, aParent, aPrevInFlow);
|
2006-03-09 21:55:21 +03:00
|
|
|
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext *presContext = PresContext();
|
1999-09-21 06:12:01 +04:00
|
|
|
|
2009-08-17 01:53:42 +04:00
|
|
|
// No need to track the style context given to our MathML char.
|
2002-02-07 07:38:08 +03:00
|
|
|
// The Style System will use Get/SetAdditionalStyleContext() to keep it
|
|
|
|
// up-to-date if dynamic changes arise.
|
2001-02-02 12:39:18 +03:00
|
|
|
nsAutoString sqrChar; sqrChar.Assign(kSqrChar);
|
2006-03-27 01:30:36 +04:00
|
|
|
mSqrChar.SetData(presContext, sqrChar);
|
2011-10-17 18:59:28 +04:00
|
|
|
ResolveMathMLCharStyle(presContext, mContent, mStyleContext, &mSqrChar, true);
|
2000-03-28 13:38:24 +04:00
|
|
|
|
1999-09-21 06:12:01 +04:00
|
|
|
return rv;
|
|
|
|
}
|
1999-11-22 15:35:36 +03:00
|
|
|
|
2002-02-07 07:38:08 +03:00
|
|
|
NS_IMETHODIMP
|
2005-02-07 04:57:50 +03:00
|
|
|
nsMathMLmrootFrame::TransmitAutomaticData()
|
2002-02-07 07:38:08 +03:00
|
|
|
{
|
|
|
|
// 1. The REC says:
|
|
|
|
// The <mroot> element increments scriptlevel by 2, and sets displaystyle to
|
|
|
|
// "false", within index, but leaves both attributes unchanged within base.
|
|
|
|
// 2. The TeXbook (Ch 17. p.141) says \sqrt is compressed
|
2008-01-09 12:38:28 +03:00
|
|
|
UpdatePresentationDataFromChildAt(1, 1,
|
2002-02-07 07:38:08 +03:00
|
|
|
~NS_MATHML_DISPLAYSTYLE | NS_MATHML_COMPRESSED,
|
|
|
|
NS_MATHML_DISPLAYSTYLE | NS_MATHML_COMPRESSED);
|
2008-01-09 12:38:28 +03:00
|
|
|
UpdatePresentationDataFromChildAt(0, 0,
|
2002-02-07 07:38:08 +03:00
|
|
|
NS_MATHML_COMPRESSED, NS_MATHML_COMPRESSED);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-22 15:35:36 +03:00
|
|
|
NS_IMETHODIMP
|
2006-01-26 05:29:17 +03:00
|
|
|
nsMathMLmrootFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
1999-11-22 15:35:36 +03:00
|
|
|
{
|
2000-04-17 08:23:03 +04:00
|
|
|
/////////////
|
|
|
|
// paint the content we are square-rooting
|
2006-01-26 05:29:17 +03:00
|
|
|
nsresult rv = nsMathMLContainerFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2000-03-28 13:38:24 +04:00
|
|
|
/////////////
|
|
|
|
// paint the sqrt symbol
|
2002-02-07 07:38:08 +03:00
|
|
|
if (!NS_MATHML_HAS_ERROR(mPresentationData.flags)) {
|
2012-04-27 04:24:54 +04:00
|
|
|
rv = mSqrChar.Display(aBuilder, this, aLists, 0);
|
2006-01-26 05:29:17 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = DisplayBar(aBuilder, this, mBarRect, aLists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2012-06-25 23:59:42 +04:00
|
|
|
#if defined(DEBUG) && defined(SHOW_BOUNDING_BOX)
|
2000-03-28 13:38:24 +04:00
|
|
|
// for visual debug
|
2006-01-26 05:29:17 +03:00
|
|
|
nsRect rect;
|
|
|
|
mSqrChar.GetRect(rect);
|
|
|
|
nsBoundingMetrics bm;
|
|
|
|
mSqrChar.GetBoundingMetrics(bm);
|
|
|
|
rv = DisplayBoundingMetrics(aBuilder, this, rect.TopLeft(), bm, aLists);
|
2000-03-28 13:38:24 +04:00
|
|
|
#endif
|
1999-11-22 15:35:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2008-03-14 08:02:49 +03:00
|
|
|
static void
|
|
|
|
GetRadicalXOffsets(nscoord aIndexWidth, nscoord aSqrWidth,
|
2011-04-08 05:05:49 +04:00
|
|
|
nsFontMetrics* aFontMetrics,
|
2008-03-14 08:02:49 +03:00
|
|
|
nscoord* aIndexOffset, nscoord* aSqrOffset)
|
|
|
|
{
|
|
|
|
// The index is tucked in closer to the radical while making sure
|
|
|
|
// that the kern does not make the index and radical collide
|
|
|
|
nscoord dxIndex, dxSqr;
|
2011-04-08 08:18:43 +04:00
|
|
|
nscoord xHeight = aFontMetrics->XHeight();
|
2008-03-14 08:02:49 +03:00
|
|
|
nscoord indexRadicalKern = NSToCoordRound(1.35f * xHeight);
|
|
|
|
if (indexRadicalKern > aIndexWidth) {
|
|
|
|
dxIndex = indexRadicalKern - aIndexWidth;
|
|
|
|
dxSqr = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dxIndex = 0;
|
|
|
|
dxSqr = aIndexWidth - indexRadicalKern;
|
|
|
|
}
|
|
|
|
// avoid collision by leaving a minimum space between index and radical
|
|
|
|
nscoord minimumClearance = aSqrWidth/2;
|
|
|
|
if (dxIndex + aIndexWidth + minimumClearance > dxSqr + aSqrWidth) {
|
|
|
|
if (aIndexWidth + minimumClearance < aSqrWidth) {
|
|
|
|
dxIndex = aSqrWidth - (aIndexWidth + minimumClearance);
|
|
|
|
dxSqr = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dxIndex = 0;
|
|
|
|
dxSqr = (aIndexWidth + minimumClearance) - aSqrWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIndexOffset)
|
|
|
|
*aIndexOffset = dxIndex;
|
|
|
|
if (aSqrOffset)
|
|
|
|
*aSqrOffset = dxSqr;
|
|
|
|
}
|
|
|
|
|
1999-11-22 15:35:36 +03:00
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsMathMLmrootFrame::Reflow(nsPresContext* aPresContext,
|
1999-11-22 15:35:36 +03:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2008-01-15 04:13:21 +03:00
|
|
|
nsSize availSize(aReflowState.ComputedWidth(), NS_UNCONSTRAINEDSIZE);
|
2000-03-28 13:38:24 +04:00
|
|
|
nsReflowStatus childStatus;
|
|
|
|
|
|
|
|
aDesiredSize.width = aDesiredSize.height = 0;
|
2007-01-23 07:06:56 +03:00
|
|
|
aDesiredSize.ascent = 0;
|
2000-03-28 13:38:24 +04:00
|
|
|
|
|
|
|
nsBoundingMetrics bmSqr, bmBase, bmIndex;
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext& renderingContext = *aReflowState.rendContext;
|
1999-11-22 15:35:36 +03:00
|
|
|
|
|
|
|
//////////////////
|
|
|
|
// Reflow Children
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count = 0;
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIFrame* baseFrame = nullptr;
|
|
|
|
nsIFrame* indexFrame = nullptr;
|
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 indexSize;
|
1999-11-22 15:35:36 +03:00
|
|
|
nsIFrame* childFrame = mFrames.FirstChild();
|
2001-02-23 19:10:51 +03:00
|
|
|
while (childFrame) {
|
2007-12-03 03:54:23 +03:00
|
|
|
// ask our children to compute their bounding metrics
|
|
|
|
nsHTMLReflowMetrics childDesiredSize(aDesiredSize.mFlags
|
|
|
|
| NS_REFLOW_CALC_BOUNDING_METRICS);
|
2001-02-23 19:10:51 +03:00
|
|
|
nsHTMLReflowState childReflowState(aPresContext, aReflowState,
|
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
|
|
|
childFrame, availSize);
|
2001-02-23 19:10:51 +03:00
|
|
|
rv = ReflowChild(childFrame, aPresContext,
|
|
|
|
childDesiredSize, childReflowState, childStatus);
|
|
|
|
//NS_ASSERTION(NS_FRAME_IS_COMPLETE(childStatus), "bad status");
|
2007-03-02 13:55:55 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// Call DidReflow() for the child frames we successfully did reflow.
|
|
|
|
DidReflowChildren(mFrames.FirstChild(), childFrame);
|
|
|
|
return rv;
|
|
|
|
}
|
2001-02-23 19:10:51 +03:00
|
|
|
if (0 == count) {
|
|
|
|
// base
|
|
|
|
baseFrame = childFrame;
|
|
|
|
baseSize = childDesiredSize;
|
|
|
|
bmBase = childDesiredSize.mBoundingMetrics;
|
|
|
|
}
|
|
|
|
else if (1 == count) {
|
|
|
|
// index
|
|
|
|
indexFrame = childFrame;
|
|
|
|
indexSize = childDesiredSize;
|
|
|
|
bmIndex = childDesiredSize.mBoundingMetrics;
|
1999-11-22 15:35:36 +03:00
|
|
|
}
|
2001-02-23 19:10:51 +03:00
|
|
|
count++;
|
2003-07-08 15:00:00 +04:00
|
|
|
childFrame = childFrame->GetNextSibling();
|
1999-11-22 15:35:36 +03:00
|
|
|
}
|
2001-02-23 19:10:51 +03:00
|
|
|
if (2 != count) {
|
2000-03-28 13:38:24 +04:00
|
|
|
// report an error, encourage people to get their markups in order
|
2006-08-04 03:58:42 +04:00
|
|
|
rv = ReflowError(renderingContext, aDesiredSize);
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
2008-10-30 20:10:19 +03:00
|
|
|
// Call DidReflow() for the child frames we successfully did reflow.
|
|
|
|
DidReflowChildren(mFrames.FirstChild(), childFrame);
|
2006-08-04 03:58:42 +04:00
|
|
|
return rv;
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
1999-11-22 15:35:36 +03:00
|
|
|
|
|
|
|
////////////
|
|
|
|
// Prepare the radical symbol and the overline bar
|
|
|
|
|
2011-08-14 21:08:04 +04:00
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm));
|
|
|
|
renderingContext.SetFont(fm);
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2007-11-16 00:51:30 +03:00
|
|
|
// For radical glyphs from TeX fonts and some of the radical glyphs from
|
|
|
|
// Mathematica fonts, the thickness of the overline can be obtained from the
|
|
|
|
// ascent of the glyph. Most fonts however have radical glyphs above the
|
|
|
|
// baseline so no assumption can be made about the meaning of the ascent.
|
2002-01-05 04:08:09 +03:00
|
|
|
nscoord ruleThickness, leading, em;
|
2000-03-28 13:38:24 +04:00
|
|
|
GetRuleThickness(renderingContext, fm, ruleThickness);
|
2001-05-09 08:50:34 +04:00
|
|
|
|
2011-04-08 05:04:40 +04:00
|
|
|
PRUnichar one = '1';
|
|
|
|
nsBoundingMetrics bmOne = renderingContext.GetBoundingMetrics(&one, 1);
|
2003-04-22 07:32:06 +04:00
|
|
|
|
2001-05-09 08:50:34 +04:00
|
|
|
// get the leading to be left at the top of the resulting frame
|
2007-11-16 00:51:30 +03:00
|
|
|
// this seems more reliable than using fm->GetLeading() on suspicious fonts
|
2002-01-05 04:08:09 +03:00
|
|
|
GetEmHeight(fm, em);
|
2001-05-09 08:50:34 +04:00
|
|
|
leading = nscoord(0.2f * em);
|
2000-03-28 13:38:24 +04:00
|
|
|
|
|
|
|
// Rule 11, App. G, TeXbook
|
|
|
|
// psi = clearance between rule and content
|
|
|
|
nscoord phi = 0, psi = 0;
|
|
|
|
if (NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags))
|
2011-04-08 08:18:43 +04:00
|
|
|
phi = fm->XHeight();
|
2000-03-28 13:38:24 +04:00
|
|
|
else
|
|
|
|
phi = ruleThickness;
|
|
|
|
psi = ruleThickness + phi/4;
|
2003-04-22 07:32:06 +04:00
|
|
|
|
|
|
|
// built-in: adjust clearance psi to emulate \mathstrut using '1' (TexBook, p.131)
|
|
|
|
if (bmOne.ascent > bmBase.ascent)
|
|
|
|
psi += bmOne.ascent - bmBase.ascent;
|
|
|
|
|
2007-11-16 00:51:30 +03:00
|
|
|
// make sure that the rule appears on on screen
|
|
|
|
nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
|
|
|
|
if (ruleThickness < onePixel) {
|
|
|
|
ruleThickness = onePixel;
|
|
|
|
}
|
|
|
|
|
|
|
|
// adjust clearance psi to get an exact number of pixels -- this
|
|
|
|
// gives a nicer & uniform look on stacked radicals (bug 130282)
|
|
|
|
nscoord delta = psi % onePixel;
|
|
|
|
if (delta)
|
|
|
|
psi += onePixel - delta; // round up
|
|
|
|
|
2000-03-28 13:38:24 +04:00
|
|
|
// Stretch the radical symbol to the appropriate height if it is not big enough.
|
|
|
|
nsBoundingMetrics contSize = bmBase;
|
|
|
|
contSize.descent = bmBase.ascent + bmBase.descent + psi;
|
|
|
|
contSize.ascent = ruleThickness;
|
|
|
|
|
|
|
|
// height(radical) should be >= height(base) + psi + ruleThickness
|
2001-02-02 12:39:18 +03:00
|
|
|
nsBoundingMetrics radicalSize;
|
2000-03-28 13:38:24 +04:00
|
|
|
mSqrChar.Stretch(aPresContext, renderingContext,
|
|
|
|
NS_STRETCH_DIRECTION_VERTICAL,
|
|
|
|
contSize, radicalSize,
|
2011-12-22 02:22:00 +04:00
|
|
|
NS_STRETCH_LARGER,
|
|
|
|
NS_MATHML_IS_RTL(mPresentationData.flags));
|
2000-03-28 13:38:24 +04:00
|
|
|
// radicalSize have changed at this point, and should match with
|
|
|
|
// the bounding metrics of the char
|
|
|
|
mSqrChar.GetBoundingMetrics(bmSqr);
|
|
|
|
|
2001-02-02 12:39:18 +03:00
|
|
|
// Update the desired size for the container (like msqrt, index is not yet included)
|
2000-03-28 13:38:24 +04:00
|
|
|
// the baseline will be that of the base.
|
|
|
|
mBoundingMetrics.ascent = bmBase.ascent + psi + ruleThickness;
|
|
|
|
mBoundingMetrics.descent =
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MAX(bmBase.descent,
|
2007-11-16 00:51:30 +03:00
|
|
|
(bmSqr.ascent + bmSqr.descent - mBoundingMetrics.ascent));
|
2000-03-28 13:38:24 +04:00
|
|
|
mBoundingMetrics.width = bmSqr.width + bmBase.width;
|
|
|
|
mBoundingMetrics.leftBearing = bmSqr.leftBearing;
|
|
|
|
mBoundingMetrics.rightBearing = bmSqr.width +
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MAX(bmBase.width, bmBase.rightBearing); // take also care of the rule
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2001-02-02 12:39:18 +03:00
|
|
|
aDesiredSize.ascent = mBoundingMetrics.ascent + leading;
|
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
|
|
|
mBoundingMetrics.descent + ruleThickness);
|
2000-03-28 13:38:24 +04:00
|
|
|
aDesiredSize.width = mBoundingMetrics.width;
|
|
|
|
|
|
|
|
/////////////
|
|
|
|
// Re-adjust the desired size to include the index.
|
|
|
|
|
|
|
|
// the index is raised by some fraction of the height
|
|
|
|
// of the radical, see \mroot macro in App. B, TexBook
|
|
|
|
nscoord raiseIndexDelta = NSToCoordRound(0.6f * (bmSqr.ascent + bmSqr.descent));
|
|
|
|
nscoord indexRaisedAscent = mBoundingMetrics.ascent // top of radical
|
|
|
|
- (bmSqr.ascent + bmSqr.descent) // to bottom of radical
|
|
|
|
+ raiseIndexDelta + bmIndex.ascent + bmIndex.descent; // to top of raised index
|
|
|
|
|
|
|
|
nscoord indexClearance = 0;
|
|
|
|
if (mBoundingMetrics.ascent < indexRaisedAscent) {
|
|
|
|
indexClearance =
|
|
|
|
indexRaisedAscent - mBoundingMetrics.ascent; // excess gap introduced by a tall index
|
|
|
|
mBoundingMetrics.ascent = indexRaisedAscent;
|
2007-01-23 07:06:56 +03:00
|
|
|
nscoord descent = aDesiredSize.height - aDesiredSize.ascent;
|
2001-02-02 12:39:18 +03:00
|
|
|
aDesiredSize.ascent = mBoundingMetrics.ascent + leading;
|
2007-01-23 07:06:56 +03:00
|
|
|
aDesiredSize.height = aDesiredSize.ascent + descent;
|
1999-11-22 15:35:36 +03:00
|
|
|
}
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2008-03-14 08:02:49 +03:00
|
|
|
nscoord dxIndex, dxSqr;
|
|
|
|
GetRadicalXOffsets(bmIndex.width, bmSqr.width, fm, &dxIndex, &dxSqr);
|
1999-11-22 15:35:36 +03:00
|
|
|
|
2010-01-05 13:22:31 +03:00
|
|
|
mBoundingMetrics.width = dxSqr + bmSqr.width + bmBase.width;
|
|
|
|
mBoundingMetrics.leftBearing =
|
|
|
|
NS_MIN(dxIndex + bmIndex.leftBearing, dxSqr + bmSqr.leftBearing);
|
|
|
|
mBoundingMetrics.rightBearing = dxSqr + bmSqr.width +
|
|
|
|
NS_MAX(bmBase.width, bmBase.rightBearing);
|
|
|
|
|
|
|
|
aDesiredSize.width = mBoundingMetrics.width;
|
|
|
|
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
|
|
|
|
GatherAndStoreOverflow(&aDesiredSize);
|
|
|
|
|
2001-02-02 12:39:18 +03:00
|
|
|
// place the index
|
2008-03-14 08:02:49 +03:00
|
|
|
nscoord dx = dxIndex;
|
|
|
|
nscoord dy = aDesiredSize.ascent - (indexRaisedAscent + indexSize.ascent - bmIndex.ascent);
|
2012-07-30 18:20:58 +04:00
|
|
|
FinishReflowChild(indexFrame, aPresContext, nullptr, indexSize,
|
2010-01-05 13:22:31 +03:00
|
|
|
MirrorIfRTL(aDesiredSize.width, indexSize.width, dx),
|
|
|
|
dy, 0);
|
1999-11-22 15:35:36 +03:00
|
|
|
|
2001-02-02 12:39:18 +03:00
|
|
|
// place the radical symbol and the radical bar
|
|
|
|
dx = dxSqr;
|
|
|
|
dy = indexClearance + leading; // leave a leading at the top
|
2010-01-05 13:22:31 +03:00
|
|
|
mSqrChar.SetRect(nsRect(MirrorIfRTL(aDesiredSize.width, bmSqr.width, dx),
|
|
|
|
dy, bmSqr.width, bmSqr.ascent + bmSqr.descent));
|
2000-03-28 13:38:24 +04:00
|
|
|
dx += bmSqr.width;
|
2010-01-05 13:22:31 +03:00
|
|
|
mBarRect.SetRect(MirrorIfRTL(aDesiredSize.width, bmBase.width, dx),
|
|
|
|
dy, bmBase.width, ruleThickness);
|
2000-03-28 13:38:24 +04:00
|
|
|
|
|
|
|
// place the base
|
|
|
|
dy = aDesiredSize.ascent - baseSize.ascent;
|
2012-07-30 18:20:58 +04:00
|
|
|
FinishReflowChild(baseFrame, aPresContext, nullptr, baseSize,
|
2010-01-05 13:22:31 +03:00
|
|
|
MirrorIfRTL(aDesiredSize.width, baseSize.width, dx),
|
|
|
|
dy, 0);
|
1999-11-22 15:35:36 +03:00
|
|
|
|
2001-02-02 12:39:18 +03:00
|
|
|
mReference.x = 0;
|
|
|
|
mReference.y = aDesiredSize.ascent;
|
|
|
|
|
1999-11-22 15:35:36 +03:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
2002-05-29 02:50:43 +04:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
2000-03-28 13:38:24 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-01-07 17:49:46 +03:00
|
|
|
|
2008-03-14 08:02:49 +03:00
|
|
|
/* virtual */ nscoord
|
2011-04-08 05:04:40 +04:00
|
|
|
nsMathMLmrootFrame::GetIntrinsicWidth(nsRenderingContext* aRenderingContext)
|
2008-03-14 08:02:49 +03:00
|
|
|
{
|
|
|
|
nsIFrame* baseFrame = mFrames.FirstChild();
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIFrame* indexFrame = nullptr;
|
2008-03-14 08:02:49 +03:00
|
|
|
if (baseFrame)
|
|
|
|
indexFrame = baseFrame->GetNextSibling();
|
|
|
|
if (!indexFrame || indexFrame->GetNextSibling()) {
|
|
|
|
nsHTMLReflowMetrics desiredSize;
|
|
|
|
ReflowError(*aRenderingContext, desiredSize);
|
|
|
|
return desiredSize.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord baseWidth =
|
|
|
|
nsLayoutUtils::IntrinsicForContainer(aRenderingContext, baseFrame,
|
|
|
|
nsLayoutUtils::PREF_WIDTH);
|
|
|
|
nscoord indexWidth =
|
|
|
|
nsLayoutUtils::IntrinsicForContainer(aRenderingContext, indexFrame,
|
|
|
|
nsLayoutUtils::PREF_WIDTH);
|
|
|
|
nscoord sqrWidth = mSqrChar.GetMaxWidth(PresContext(), *aRenderingContext);
|
|
|
|
|
|
|
|
nscoord dxSqr;
|
2011-04-08 05:04:40 +04:00
|
|
|
GetRadicalXOffsets(indexWidth, sqrWidth, aRenderingContext->FontMetrics(),
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr, &dxSqr);
|
2008-03-14 08:02:49 +03:00
|
|
|
|
2008-03-28 01:47:08 +03:00
|
|
|
return dxSqr + sqrWidth + baseWidth;
|
2008-03-14 08:02:49 +03:00
|
|
|
}
|
2000-01-07 17:49:46 +03:00
|
|
|
|
2000-03-28 13:38:24 +04:00
|
|
|
// ----------------------
|
|
|
|
// the Style System will use these to pass the proper style context to our MathMLChar
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext*
|
2012-08-22 19:56:38 +04:00
|
|
|
nsMathMLmrootFrame::GetAdditionalStyleContext(int32_t aIndex) const
|
2000-03-28 13:38:24 +04:00
|
|
|
{
|
|
|
|
switch (aIndex) {
|
|
|
|
case NS_SQR_CHAR_STYLE_CONTEXT_INDEX:
|
2003-02-22 03:32:13 +03:00
|
|
|
return mSqrChar.GetStyleContext();
|
2000-03-28 13:38:24 +04:00
|
|
|
break;
|
|
|
|
default:
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsMathMLmrootFrame::SetAdditionalStyleContext(int32_t aIndex,
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* aStyleContext)
|
2000-03-28 13:38:24 +04:00
|
|
|
{
|
|
|
|
switch (aIndex) {
|
|
|
|
case NS_SQR_CHAR_STYLE_CONTEXT_INDEX:
|
|
|
|
mSqrChar.SetStyleContext(aStyleContext);
|
|
|
|
break;
|
|
|
|
}
|
1999-11-22 15:35:36 +03:00
|
|
|
}
|