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
|
|
|
|
2013-08-31 01:37:12 +04:00
|
|
|
#include "nsMathMLmrootFrame.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2017-06-13 01:30:03 +03:00
|
|
|
#include "nsRenderingContext.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2016-11-02 21:47:18 +03:00
|
|
|
#include "gfxMathTable.h"
|
1999-09-21 06:12:01 +04:00
|
|
|
|
2014-07-24 12:28:46 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
1999-09-21 06:12:01 +04:00
|
|
|
//
|
2014-06-17 10:40:00 +04:00
|
|
|
// <mroot> -- form a radical - implementation
|
1999-09-21 06:12:01 +04:00
|
|
|
//
|
|
|
|
|
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
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
static const char16_t kSqrChar = char16_t(0x221A);
|
2001-02-02 12:39:18 +03:00
|
|
|
|
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) :
|
2017-05-26 13:11:11 +03:00
|
|
|
nsMathMLContainerFrame(aContext, kClassID),
|
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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-20 05:47:48 +04:00
|
|
|
void
|
2014-05-25 02:20:40 +04:00
|
|
|
nsMathMLmrootFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
1999-09-21 06:12:01 +04:00
|
|
|
{
|
2013-03-20 05:47:48 +04:00
|
|
|
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);
|
2015-12-07 04:15:53 +03:00
|
|
|
mSqrChar.SetData(sqrChar);
|
2014-04-24 23:30:00 +04:00
|
|
|
ResolveMathMLCharStyle(presContext, mContent, mStyleContext, &mSqrChar);
|
1999-09-21 06:12:01 +04:00
|
|
|
}
|
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,
|
2014-01-14 18:39:50 +04:00
|
|
|
NS_MATHML_COMPRESSED,
|
|
|
|
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);
|
|
|
|
|
2014-01-15 18:49:00 +04:00
|
|
|
PropagateFrameFlagFor(mFrames.LastChild(),
|
|
|
|
NS_FRAME_MATHML_SCRIPT_DESCENDANT);
|
|
|
|
|
2002-02-07 07:38:08 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-02-14 15:12:27 +04:00
|
|
|
void
|
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
|
2013-02-14 15:12:27 +04:00
|
|
|
nsMathMLContainerFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
|
2006-01-26 05:29:17 +03:00
|
|
|
|
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)) {
|
2013-02-14 15:12:27 +04:00
|
|
|
mSqrChar.Display(aBuilder, this, aLists, 0);
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2013-02-14 15:12:27 +04:00
|
|
|
DisplayBar(aBuilder, this, mBarRect, aLists);
|
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);
|
2013-02-14 15:12:27 +04:00
|
|
|
DisplayBoundingMetrics(aBuilder, this, rect.TopLeft(), bm, aLists);
|
2000-03-28 13:38:24 +04:00
|
|
|
#endif
|
1999-11-22 15:35:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-17 10:40:00 +04:00
|
|
|
void
|
|
|
|
nsMathMLmrootFrame::GetRadicalXOffsets(nscoord aIndexWidth, nscoord aSqrWidth,
|
|
|
|
nsFontMetrics* aFontMetrics,
|
|
|
|
nscoord* aIndexOffset,
|
|
|
|
nscoord* aSqrOffset)
|
2008-03-14 08:02:49 +03:00
|
|
|
{
|
|
|
|
// 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);
|
2014-06-17 10:40:00 +04:00
|
|
|
nscoord oneDevPixel = aFontMetrics->AppUnitsPerDevPixel();
|
|
|
|
gfxFont* mathFont = aFontMetrics->GetThebesFontGroup()->GetFirstMathFont();
|
|
|
|
if (mathFont) {
|
|
|
|
indexRadicalKern =
|
2016-11-02 21:47:18 +03:00
|
|
|
mathFont->MathTable()->Constant(gfxMathTable::RadicalKernAfterDegree,
|
|
|
|
oneDevPixel);
|
2014-06-17 10:40:00 +04:00
|
|
|
indexRadicalKern = -indexRadicalKern;
|
|
|
|
}
|
2008-03-14 08:02:49 +03:00
|
|
|
if (indexRadicalKern > aIndexWidth) {
|
|
|
|
dxIndex = indexRadicalKern - aIndexWidth;
|
|
|
|
dxSqr = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dxIndex = 0;
|
|
|
|
dxSqr = aIndexWidth - indexRadicalKern;
|
|
|
|
}
|
2014-06-17 10:40:00 +04:00
|
|
|
|
|
|
|
if (mathFont) {
|
|
|
|
// add some kern before the radical index
|
|
|
|
nscoord indexRadicalKernBefore = 0;
|
|
|
|
indexRadicalKernBefore =
|
2016-11-02 21:47:18 +03:00
|
|
|
mathFont->MathTable()->Constant(gfxMathTable::RadicalKernBeforeDegree,
|
|
|
|
oneDevPixel);
|
2014-06-17 10:40:00 +04:00
|
|
|
dxIndex += indexRadicalKernBefore;
|
|
|
|
dxSqr += indexRadicalKernBefore;
|
|
|
|
} else {
|
|
|
|
// 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;
|
|
|
|
}
|
2008-03-14 08:02:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIndexOffset)
|
|
|
|
*aIndexOffset = dxIndex;
|
|
|
|
if (aSqrOffset)
|
|
|
|
*aSqrOffset = dxSqr;
|
|
|
|
}
|
|
|
|
|
2014-05-13 04:47:52 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsMathMLmrootFrame::Reflow(nsPresContext* aPresContext,
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput& aDesiredSize,
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& aReflowInput,
|
1999-11-22 15:35:36 +03:00
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2015-03-30 01:38:40 +03:00
|
|
|
MarkInReflow();
|
2000-03-28 13:38:24 +04:00
|
|
|
nsReflowStatus childStatus;
|
|
|
|
|
2015-03-30 01:38:39 +03:00
|
|
|
mPresentationData.flags &= ~NS_MATHML_ERROR;
|
2014-07-24 12:30:07 +04:00
|
|
|
aDesiredSize.ClearSize();
|
2014-06-11 13:45:31 +04:00
|
|
|
aDesiredSize.SetBlockStartAscent(0);
|
2000-03-28 13:38:24 +04:00
|
|
|
|
|
|
|
nsBoundingMetrics bmSqr, bmBase, bmIndex;
|
2016-07-21 13:36:39 +03:00
|
|
|
DrawTarget* drawTarget = aReflowInput.mRenderingContext->GetDrawTarget();
|
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;
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowOutput baseSize(aReflowInput);
|
|
|
|
ReflowOutput indexSize(aReflowInput);
|
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
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowOutput childDesiredSize(aReflowInput,
|
2013-12-27 21:59:52 +04:00
|
|
|
aDesiredSize.mFlags
|
2007-12-03 03:54:23 +03:00
|
|
|
| NS_REFLOW_CALC_BOUNDING_METRICS);
|
2014-07-24 12:28:46 +04:00
|
|
|
WritingMode wm = childFrame->GetWritingMode();
|
2016-07-21 13:36:39 +03:00
|
|
|
LogicalSize availSize = aReflowInput.ComputedSize(wm);
|
2014-07-24 12:28:46 +04:00
|
|
|
availSize.BSize(wm) = NS_UNCONSTRAINEDSIZE;
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowInput childReflowInput(aPresContext, aReflowInput,
|
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);
|
2014-05-13 04:47:52 +04:00
|
|
|
ReflowChild(childFrame, aPresContext,
|
2016-07-21 13:36:39 +03:00
|
|
|
childDesiredSize, childReflowInput, childStatus);
|
2017-02-11 17:45:07 +03:00
|
|
|
//NS_ASSERTION(childStatus.IsComplete(), "bad status");
|
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
|
2012-12-27 20:12:05 +04:00
|
|
|
ReportChildCountError();
|
2015-12-16 00:56:41 +03:00
|
|
|
ReflowError(drawTarget, aDesiredSize);
|
2017-02-14 12:55:48 +03:00
|
|
|
aStatus.Reset();
|
2016-07-21 13:36:39 +03:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize);
|
2008-10-30 20:10:19 +03:00
|
|
|
// Call DidReflow() for the child frames we successfully did reflow.
|
|
|
|
DidReflowChildren(mFrames.FirstChild(), childFrame);
|
2014-05-13 04:47:52 +04:00
|
|
|
return;
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
1999-11-22 15:35:36 +03:00
|
|
|
|
|
|
|
////////////
|
|
|
|
// Prepare the radical symbol and the overline bar
|
|
|
|
|
2014-10-25 10:30:00 +04:00
|
|
|
float fontSizeInflation = nsLayoutUtils::FontSizeInflationFor(this);
|
2016-03-17 08:55:48 +03:00
|
|
|
RefPtr<nsFontMetrics> fm =
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, fontSizeInflation);
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2014-06-17 10:40:00 +04:00
|
|
|
nscoord ruleThickness, leading, psi;
|
|
|
|
GetRadicalParameters(fm, StyleFont()->mMathDisplay ==
|
|
|
|
NS_MATHML_DISPLAYSTYLE_BLOCK,
|
|
|
|
ruleThickness, leading, psi);
|
2001-05-09 08:50:34 +04:00
|
|
|
|
2014-06-17 10:40:00 +04:00
|
|
|
// built-in: adjust clearance psi to emulate \mathstrut using '1' (TexBook, p.131)
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t one = '1';
|
2014-10-24 19:28:14 +04:00
|
|
|
nsBoundingMetrics bmOne =
|
2015-12-16 00:56:41 +03:00
|
|
|
nsLayoutUtils::AppUnitBoundsOfString(&one, 1, *fm, drawTarget);
|
2003-04-22 07:32:06 +04:00
|
|
|
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;
|
2015-12-16 00:56:41 +03:00
|
|
|
mSqrChar.Stretch(aPresContext, drawTarget,
|
2014-10-25 10:30:00 +04:00
|
|
|
fontSizeInflation,
|
2000-03-28 13:38:24 +04:00
|
|
|
NS_STRETCH_DIRECTION_VERTICAL,
|
|
|
|
contSize, radicalSize,
|
2011-12-22 02:22:00 +04:00
|
|
|
NS_STRETCH_LARGER,
|
2013-05-30 03:26:40 +04:00
|
|
|
StyleVisibility()->mDirection);
|
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 =
|
2013-01-15 16:22:03 +04:00
|
|
|
std::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 +
|
2013-01-15 16:22:03 +04:00
|
|
|
std::max(bmBase.width, bmBase.rightBearing); // take also care of the rule
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2014-06-11 13:45:31 +04:00
|
|
|
aDesiredSize.SetBlockStartAscent(mBoundingMetrics.ascent + leading);
|
|
|
|
aDesiredSize.Height() = aDesiredSize.BlockStartAscent() +
|
|
|
|
std::max(baseSize.Height() - baseSize.BlockStartAscent(),
|
|
|
|
mBoundingMetrics.descent + ruleThickness);
|
2013-12-27 21:59:52 +04:00
|
|
|
aDesiredSize.Width() = mBoundingMetrics.width;
|
2000-03-28 13:38:24 +04:00
|
|
|
|
|
|
|
/////////////
|
|
|
|
// 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
|
2014-06-17 10:40:00 +04:00
|
|
|
float raiseIndexPercent = 0.6f;
|
|
|
|
gfxFont* mathFont = fm->GetThebesFontGroup()->GetFirstMathFont();
|
|
|
|
if (mathFont) {
|
2016-11-02 21:47:18 +03:00
|
|
|
raiseIndexPercent = mathFont->MathTable()->
|
|
|
|
Constant(gfxMathTable::RadicalDegreeBottomRaisePercent);
|
2014-06-17 10:40:00 +04:00
|
|
|
}
|
|
|
|
nscoord raiseIndexDelta = NSToCoordRound(raiseIndexPercent *
|
|
|
|
(bmSqr.ascent + bmSqr.descent));
|
2000-03-28 13:38:24 +04:00
|
|
|
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;
|
2014-06-11 13:45:31 +04:00
|
|
|
nscoord descent = aDesiredSize.Height() - aDesiredSize.BlockStartAscent();
|
|
|
|
aDesiredSize.SetBlockStartAscent(mBoundingMetrics.ascent + leading);
|
|
|
|
aDesiredSize.Height() = aDesiredSize.BlockStartAscent() + 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 =
|
2013-01-15 16:22:03 +04:00
|
|
|
std::min(dxIndex + bmIndex.leftBearing, dxSqr + bmSqr.leftBearing);
|
2010-01-05 13:22:31 +03:00
|
|
|
mBoundingMetrics.rightBearing = dxSqr + bmSqr.width +
|
2013-01-15 16:22:03 +04:00
|
|
|
std::max(bmBase.width, bmBase.rightBearing);
|
2010-01-05 13:22:31 +03:00
|
|
|
|
2013-12-27 21:59:52 +04:00
|
|
|
aDesiredSize.Width() = mBoundingMetrics.width;
|
2010-01-05 13:22:31 +03:00
|
|
|
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;
|
2014-06-11 13:45:31 +04:00
|
|
|
nscoord dy = aDesiredSize.BlockStartAscent() -
|
|
|
|
(indexRaisedAscent + indexSize.BlockStartAscent() - bmIndex.ascent);
|
2014-01-17 05:34:44 +04:00
|
|
|
FinishReflowChild(indexFrame, aPresContext, indexSize, nullptr,
|
2013-12-27 21:59:52 +04:00
|
|
|
MirrorIfRTL(aDesiredSize.Width(), indexSize.Width(), dx),
|
2010-01-05 13:22:31 +03:00
|
|
|
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
|
2013-12-27 21:59:52 +04:00
|
|
|
mSqrChar.SetRect(nsRect(MirrorIfRTL(aDesiredSize.Width(), bmSqr.width, dx),
|
2010-01-05 13:22:31 +03:00
|
|
|
dy, bmSqr.width, bmSqr.ascent + bmSqr.descent));
|
2000-03-28 13:38:24 +04:00
|
|
|
dx += bmSqr.width;
|
2013-12-27 21:59:52 +04:00
|
|
|
mBarRect.SetRect(MirrorIfRTL(aDesiredSize.Width(), bmBase.width, dx),
|
2010-01-05 13:22:31 +03:00
|
|
|
dy, bmBase.width, ruleThickness);
|
2000-03-28 13:38:24 +04:00
|
|
|
|
|
|
|
// place the base
|
2014-06-11 13:45:31 +04:00
|
|
|
dy = aDesiredSize.BlockStartAscent() - baseSize.BlockStartAscent();
|
2014-01-17 05:34:44 +04:00
|
|
|
FinishReflowChild(baseFrame, aPresContext, baseSize, nullptr,
|
2013-12-27 21:59:52 +04:00
|
|
|
MirrorIfRTL(aDesiredSize.Width(), baseSize.Width(), dx),
|
2010-01-05 13:22:31 +03:00
|
|
|
dy, 0);
|
1999-11-22 15:35:36 +03:00
|
|
|
|
2001-02-02 12:39:18 +03:00
|
|
|
mReference.x = 0;
|
2014-06-11 13:45:31 +04:00
|
|
|
mReference.y = aDesiredSize.BlockStartAscent();
|
2001-02-02 12:39:18 +03:00
|
|
|
|
2017-02-14 12:55:48 +03:00
|
|
|
aStatus.Reset();
|
2016-07-21 13:36:39 +03:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize);
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
2000-01-07 17:49:46 +03:00
|
|
|
|
2013-11-25 18:20:20 +04:00
|
|
|
/* virtual */ void
|
2017-06-13 01:30:03 +03:00
|
|
|
nsMathMLmrootFrame::GetIntrinsicISizeMetrics(nsRenderingContext* aRenderingContext, ReflowOutput& aDesiredSize)
|
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()) {
|
2015-12-16 00:56:41 +03:00
|
|
|
ReflowError(aRenderingContext->GetDrawTarget(), aDesiredSize);
|
2013-11-25 18:20:20 +04:00
|
|
|
return;
|
2008-03-14 08:02:49 +03:00
|
|
|
}
|
|
|
|
|
2014-10-25 10:30:00 +04:00
|
|
|
float fontSizeInflation = nsLayoutUtils::FontSizeInflationFor(this);
|
2008-03-14 08:02:49 +03:00
|
|
|
nscoord baseWidth =
|
|
|
|
nsLayoutUtils::IntrinsicForContainer(aRenderingContext, baseFrame,
|
2014-07-24 21:03:26 +04:00
|
|
|
nsLayoutUtils::PREF_ISIZE);
|
2008-03-14 08:02:49 +03:00
|
|
|
nscoord indexWidth =
|
|
|
|
nsLayoutUtils::IntrinsicForContainer(aRenderingContext, indexFrame,
|
2014-07-24 21:03:26 +04:00
|
|
|
nsLayoutUtils::PREF_ISIZE);
|
2015-12-16 00:56:41 +03:00
|
|
|
nscoord sqrWidth = mSqrChar.GetMaxWidth(PresContext(),
|
|
|
|
aRenderingContext->GetDrawTarget(),
|
2014-10-25 10:30:00 +04:00
|
|
|
fontSizeInflation);
|
2008-03-14 08:02:49 +03:00
|
|
|
|
|
|
|
nscoord dxSqr;
|
2016-03-17 08:55:48 +03:00
|
|
|
RefPtr<nsFontMetrics> fm =
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, fontSizeInflation);
|
2014-02-13 18:53:52 +04:00
|
|
|
GetRadicalXOffsets(indexWidth, sqrWidth, fm, nullptr, &dxSqr);
|
2008-03-14 08:02:49 +03:00
|
|
|
|
2013-11-25 18:20:20 +04:00
|
|
|
nscoord width = dxSqr + sqrWidth + baseWidth;
|
|
|
|
|
2013-12-27 21:59:52 +04:00
|
|
|
aDesiredSize.Width() = width;
|
2013-11-25 18:20:20 +04:00
|
|
|
aDesiredSize.mBoundingMetrics.width = width;
|
|
|
|
aDesiredSize.mBoundingMetrics.leftBearing = 0;
|
|
|
|
aDesiredSize.mBoundingMetrics.rightBearing = width;
|
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
|
|
|
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
|
|
|
}
|