2009-05-29 11:08:35 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
2009-05-29 11:08:35 +00:00
|
|
|
|
2013-08-30 21:37:12 +00:00
|
|
|
#include "nsMathMLmencloseFrame.h"
|
2014-10-16 11:03:44 +00:00
|
|
|
|
|
|
|
#include "gfx2DGlue.h"
|
2014-10-17 11:53:16 +00:00
|
|
|
#include "gfxUtils.h"
|
2014-10-16 11:03:44 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/gfx/PathHelpers.h"
|
2009-05-29 11:08:35 +00:00
|
|
|
#include "nsPresContext.h"
|
2011-04-08 01:04:40 +00:00
|
|
|
#include "nsRenderingContext.h"
|
2009-05-29 11:08:35 +00:00
|
|
|
#include "nsWhitespaceTokenizer.h"
|
|
|
|
|
|
|
|
#include "nsDisplayList.h"
|
|
|
|
#include "gfxContext.h"
|
2013-08-30 21:37:12 +00:00
|
|
|
#include "nsMathMLChar.h"
|
2013-01-15 12:22:03 +00:00
|
|
|
#include <algorithm>
|
2009-05-29 11:08:35 +00:00
|
|
|
|
2014-10-16 11:03:44 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2009-05-29 11:08:35 +00:00
|
|
|
//
|
|
|
|
// <menclose> -- enclose content with a stretching symbol such
|
|
|
|
// as a long division sign. - implementation
|
|
|
|
|
|
|
|
// longdiv:
|
|
|
|
// Unicode 5.1 assigns U+27CC to LONG DIVISION, but a right parenthesis
|
|
|
|
// renders better with current font support.
|
2014-01-04 15:02:17 +00:00
|
|
|
static const char16_t kLongDivChar = ')';
|
2009-05-29 11:08:35 +00:00
|
|
|
|
|
|
|
// radical: 'SQUARE ROOT'
|
2014-01-04 15:02:17 +00:00
|
|
|
static const char16_t kRadicalChar = 0x221A;
|
2009-05-29 11:08:35 +00:00
|
|
|
|
2013-06-04 12:21:25 +00:00
|
|
|
// updiagonalstrike
|
|
|
|
static const uint8_t kArrowHeadSize = 10;
|
|
|
|
|
2014-05-11 19:48:00 +00:00
|
|
|
// phasorangle
|
|
|
|
static const uint8_t kPhasorangleWidth = 8;
|
|
|
|
|
2009-05-29 11:08:35 +00:00
|
|
|
nsIFrame*
|
|
|
|
NS_NewMathMLmencloseFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsMathMLmencloseFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmencloseFrame)
|
|
|
|
|
2009-05-29 11:08:35 +00:00
|
|
|
nsMathMLmencloseFrame::nsMathMLmencloseFrame(nsStyleContext* aContext) :
|
|
|
|
nsMathMLContainerFrame(aContext), mNotationsToDraw(0),
|
|
|
|
mLongDivCharIndex(-1), mRadicalCharIndex(-1), mContentWidth(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMathMLmencloseFrame::~nsMathMLmencloseFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsMathMLmencloseFrame::AllocateMathMLChar(nsMencloseNotation mask)
|
|
|
|
{
|
|
|
|
// Is the char already allocated?
|
|
|
|
if ((mask == NOTATION_LONGDIV && mLongDivCharIndex >= 0) ||
|
|
|
|
(mask == NOTATION_RADICAL && mRadicalCharIndex >= 0))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// No need to track the style context given to our MathML chars.
|
|
|
|
// The Style System will use Get/SetAdditionalStyleContext() to keep it
|
|
|
|
// up-to-date if dynamic changes arise.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t i = mMathMLChar.Length();
|
2009-05-29 11:08:35 +00:00
|
|
|
nsAutoString Char;
|
|
|
|
|
|
|
|
if (!mMathMLChar.AppendElement())
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
if (mask == NOTATION_LONGDIV) {
|
|
|
|
Char.Assign(kLongDivChar);
|
|
|
|
mLongDivCharIndex = i;
|
|
|
|
} else if (mask == NOTATION_RADICAL) {
|
|
|
|
Char.Assign(kRadicalChar);
|
|
|
|
mRadicalCharIndex = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPresContext *presContext = PresContext();
|
2015-12-07 01:15:53 +00:00
|
|
|
mMathMLChar[i].SetData(Char);
|
2014-04-24 19:30:00 +00:00
|
|
|
ResolveMathMLCharStyle(presContext, mContent, mStyleContext, &mMathMLChar[i]);
|
2009-05-29 11:08:35 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a notation to draw, if the argument is the name of a known notation.
|
|
|
|
* @param aNotation string name of a notation
|
|
|
|
*/
|
|
|
|
nsresult nsMathMLmencloseFrame::AddNotation(const nsAString& aNotation)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (aNotation.EqualsLiteral("longdiv")) {
|
|
|
|
rv = AllocateMathMLChar(NOTATION_LONGDIV);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
mNotationsToDraw |= NOTATION_LONGDIV;
|
|
|
|
} else if (aNotation.EqualsLiteral("actuarial")) {
|
|
|
|
mNotationsToDraw |= (NOTATION_RIGHT | NOTATION_TOP);
|
|
|
|
} else if (aNotation.EqualsLiteral("radical")) {
|
|
|
|
rv = AllocateMathMLChar(NOTATION_RADICAL);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
mNotationsToDraw |= NOTATION_RADICAL;
|
|
|
|
} else if (aNotation.EqualsLiteral("box")) {
|
|
|
|
mNotationsToDraw |= (NOTATION_LEFT | NOTATION_RIGHT |
|
|
|
|
NOTATION_TOP | NOTATION_BOTTOM);
|
|
|
|
} else if (aNotation.EqualsLiteral("roundedbox")) {
|
|
|
|
mNotationsToDraw |= NOTATION_ROUNDEDBOX;
|
|
|
|
} else if (aNotation.EqualsLiteral("circle")) {
|
|
|
|
mNotationsToDraw |= NOTATION_CIRCLE;
|
|
|
|
} else if (aNotation.EqualsLiteral("left")) {
|
|
|
|
mNotationsToDraw |= NOTATION_LEFT;
|
|
|
|
} else if (aNotation.EqualsLiteral("right")) {
|
|
|
|
mNotationsToDraw |= NOTATION_RIGHT;
|
|
|
|
} else if (aNotation.EqualsLiteral("top")) {
|
|
|
|
mNotationsToDraw |= NOTATION_TOP;
|
|
|
|
} else if (aNotation.EqualsLiteral("bottom")) {
|
|
|
|
mNotationsToDraw |= NOTATION_BOTTOM;
|
|
|
|
} else if (aNotation.EqualsLiteral("updiagonalstrike")) {
|
|
|
|
mNotationsToDraw |= NOTATION_UPDIAGONALSTRIKE;
|
2013-06-04 12:21:25 +00:00
|
|
|
} else if (aNotation.EqualsLiteral("updiagonalarrow")) {
|
|
|
|
mNotationsToDraw |= NOTATION_UPDIAGONALARROW;
|
2009-05-29 11:08:35 +00:00
|
|
|
} else if (aNotation.EqualsLiteral("downdiagonalstrike")) {
|
|
|
|
mNotationsToDraw |= NOTATION_DOWNDIAGONALSTRIKE;
|
|
|
|
} else if (aNotation.EqualsLiteral("verticalstrike")) {
|
|
|
|
mNotationsToDraw |= NOTATION_VERTICALSTRIKE;
|
|
|
|
} else if (aNotation.EqualsLiteral("horizontalstrike")) {
|
|
|
|
mNotationsToDraw |= NOTATION_HORIZONTALSTRIKE;
|
2010-04-21 03:38:15 +00:00
|
|
|
} else if (aNotation.EqualsLiteral("madruwb")) {
|
|
|
|
mNotationsToDraw |= (NOTATION_RIGHT | NOTATION_BOTTOM);
|
2014-05-11 19:48:00 +00:00
|
|
|
} else if (aNotation.EqualsLiteral("phasorangle")) {
|
|
|
|
mNotationsToDraw |= (NOTATION_BOTTOM | NOTATION_PHASORANGLE);
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the list of notations to draw
|
|
|
|
*/
|
|
|
|
void nsMathMLmencloseFrame::InitNotations()
|
|
|
|
{
|
2011-05-12 21:31:34 +00:00
|
|
|
mNotationsToDraw = 0;
|
|
|
|
mLongDivCharIndex = mRadicalCharIndex = -1;
|
|
|
|
mMathMLChar.Clear();
|
|
|
|
|
2009-05-29 11:08:35 +00:00
|
|
|
nsAutoString value;
|
|
|
|
|
2014-01-15 15:07:06 +00:00
|
|
|
if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::notation_, value)) {
|
2009-05-29 11:08:35 +00:00
|
|
|
// parse the notation attribute
|
|
|
|
nsWhitespaceTokenizer tokenizer(value);
|
|
|
|
|
|
|
|
while (tokenizer.hasMoreTokens())
|
|
|
|
AddNotation(tokenizer.nextToken());
|
2013-06-04 12:21:25 +00:00
|
|
|
|
|
|
|
if (IsToDraw(NOTATION_UPDIAGONALARROW)) {
|
|
|
|
// For <menclose notation="updiagonalstrike updiagonalarrow">, if
|
|
|
|
// the two notations are drawn then the strike line may cause the point of
|
|
|
|
// the arrow to be too wide. Hence we will only draw the updiagonalarrow
|
|
|
|
// and the arrow shaft may be thought to be the updiagonalstrike.
|
|
|
|
mNotationsToDraw &= ~NOTATION_UPDIAGONALSTRIKE;
|
|
|
|
}
|
2009-05-29 11:08:35 +00:00
|
|
|
} else {
|
|
|
|
// default: longdiv
|
|
|
|
if (NS_FAILED(AllocateMathMLChar(NOTATION_LONGDIV)))
|
|
|
|
return;
|
|
|
|
mNotationsToDraw = NOTATION_LONGDIV;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMathMLmencloseFrame::InheritAutomaticData(nsIFrame* aParent)
|
|
|
|
{
|
|
|
|
// let the base class get the default from our parent
|
|
|
|
nsMathMLContainerFrame::InheritAutomaticData(aParent);
|
|
|
|
|
|
|
|
mPresentationData.flags |= NS_MATHML_STRETCH_ALL_CHILDREN_VERTICALLY;
|
|
|
|
|
2011-05-12 21:31:34 +00:00
|
|
|
InitNotations();
|
|
|
|
|
2009-05-29 11:08:35 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMathMLmencloseFrame::TransmitAutomaticData()
|
|
|
|
{
|
|
|
|
if (IsToDraw(NOTATION_RADICAL)) {
|
|
|
|
// The TeXBook (Ch 17. p.141) says that \sqrt is cramped
|
|
|
|
UpdatePresentationDataFromChildAt(0, -1,
|
|
|
|
NS_MATHML_COMPRESSED,
|
|
|
|
NS_MATHML_COMPRESSED);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-02-14 11:12:27 +00:00
|
|
|
void
|
2009-05-29 11:08:35 +00:00
|
|
|
nsMathMLmencloseFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
/////////////
|
|
|
|
// paint the menclosed content
|
2013-02-14 11:12:27 +00:00
|
|
|
nsMathMLContainerFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
|
2009-05-29 11:08:35 +00:00
|
|
|
|
|
|
|
if (NS_MATHML_HAS_ERROR(mPresentationData.flags))
|
2013-02-14 11:12:27 +00:00
|
|
|
return;
|
2009-05-29 11:08:35 +00:00
|
|
|
|
|
|
|
nsRect mencloseRect = nsIFrame::GetRect();
|
|
|
|
mencloseRect.x = mencloseRect.y = 0;
|
|
|
|
|
|
|
|
if (IsToDraw(NOTATION_RADICAL)) {
|
2013-02-14 11:12:27 +00:00
|
|
|
mMathMLChar[mRadicalCharIndex].Display(aBuilder, this, aLists, 0);
|
2009-05-29 11:08:35 +00:00
|
|
|
|
|
|
|
nsRect rect;
|
|
|
|
mMathMLChar[mRadicalCharIndex].GetRect(rect);
|
2013-05-29 23:26:40 +00:00
|
|
|
rect.MoveBy(StyleVisibility()->mDirection ? -mContentWidth : rect.width, 0);
|
2014-06-17 06:40:00 +00:00
|
|
|
rect.SizeTo(mContentWidth, mRadicalRuleThickness);
|
2013-02-14 11:12:27 +00:00
|
|
|
DisplayBar(aBuilder, this, rect, aLists);
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
2014-05-11 19:48:00 +00:00
|
|
|
if (IsToDraw(NOTATION_PHASORANGLE)) {
|
|
|
|
DisplayNotation(aBuilder, this, mencloseRect, aLists,
|
|
|
|
mRuleThickness, NOTATION_PHASORANGLE);
|
|
|
|
}
|
|
|
|
|
2009-05-29 11:08:35 +00:00
|
|
|
if (IsToDraw(NOTATION_LONGDIV)) {
|
2013-02-14 11:12:27 +00:00
|
|
|
mMathMLChar[mLongDivCharIndex].Display(aBuilder, this, aLists, 1);
|
2009-05-29 11:08:35 +00:00
|
|
|
|
|
|
|
nsRect rect;
|
|
|
|
mMathMLChar[mLongDivCharIndex].GetRect(rect);
|
|
|
|
rect.SizeTo(rect.width + mContentWidth, mRuleThickness);
|
2013-02-14 11:12:27 +00:00
|
|
|
DisplayBar(aBuilder, this, rect, aLists);
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsToDraw(NOTATION_TOP)) {
|
|
|
|
nsRect rect(0, 0, mencloseRect.width, mRuleThickness);
|
2013-02-14 11:12:27 +00:00
|
|
|
DisplayBar(aBuilder, this, rect, aLists);
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsToDraw(NOTATION_BOTTOM)) {
|
|
|
|
nsRect rect(0, mencloseRect.height - mRuleThickness,
|
|
|
|
mencloseRect.width, mRuleThickness);
|
2013-02-14 11:12:27 +00:00
|
|
|
DisplayBar(aBuilder, this, rect, aLists);
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsToDraw(NOTATION_LEFT)) {
|
|
|
|
nsRect rect(0, 0, mRuleThickness, mencloseRect.height);
|
2013-02-14 11:12:27 +00:00
|
|
|
DisplayBar(aBuilder, this, rect, aLists);
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsToDraw(NOTATION_RIGHT)) {
|
|
|
|
nsRect rect(mencloseRect.width - mRuleThickness, 0,
|
|
|
|
mRuleThickness, mencloseRect.height);
|
2013-02-14 11:12:27 +00:00
|
|
|
DisplayBar(aBuilder, this, rect, aLists);
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsToDraw(NOTATION_ROUNDEDBOX)) {
|
2013-02-14 11:12:27 +00:00
|
|
|
DisplayNotation(aBuilder, this, mencloseRect, aLists,
|
|
|
|
mRuleThickness, NOTATION_ROUNDEDBOX);
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsToDraw(NOTATION_CIRCLE)) {
|
2013-02-14 11:12:27 +00:00
|
|
|
DisplayNotation(aBuilder, this, mencloseRect, aLists,
|
|
|
|
mRuleThickness, NOTATION_CIRCLE);
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsToDraw(NOTATION_UPDIAGONALSTRIKE)) {
|
2013-02-14 11:12:27 +00:00
|
|
|
DisplayNotation(aBuilder, this, mencloseRect, aLists,
|
|
|
|
mRuleThickness, NOTATION_UPDIAGONALSTRIKE);
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
2013-06-04 12:21:25 +00:00
|
|
|
if (IsToDraw(NOTATION_UPDIAGONALARROW)) {
|
|
|
|
DisplayNotation(aBuilder, this, mencloseRect, aLists,
|
|
|
|
mRuleThickness, NOTATION_UPDIAGONALARROW);
|
|
|
|
}
|
|
|
|
|
2009-05-29 11:08:35 +00:00
|
|
|
if (IsToDraw(NOTATION_DOWNDIAGONALSTRIKE)) {
|
2013-02-14 11:12:27 +00:00
|
|
|
DisplayNotation(aBuilder, this, mencloseRect, aLists,
|
|
|
|
mRuleThickness, NOTATION_DOWNDIAGONALSTRIKE);
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsToDraw(NOTATION_HORIZONTALSTRIKE)) {
|
|
|
|
nsRect rect(0, mencloseRect.height / 2 - mRuleThickness / 2,
|
|
|
|
mencloseRect.width, mRuleThickness);
|
2013-02-14 11:12:27 +00:00
|
|
|
DisplayBar(aBuilder, this, rect, aLists);
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsToDraw(NOTATION_VERTICALSTRIKE)) {
|
|
|
|
nsRect rect(mencloseRect.width / 2 - mRuleThickness / 2, 0,
|
|
|
|
mRuleThickness, mencloseRect.height);
|
2013-02-14 11:12:27 +00:00
|
|
|
DisplayBar(aBuilder, this, rect, aLists);
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nsresult
|
2015-12-15 21:56:41 +00:00
|
|
|
nsMathMLmencloseFrame::MeasureForWidth(DrawTarget* aDrawTarget,
|
2016-07-21 10:36:38 +00:00
|
|
|
ReflowOutput& aDesiredSize)
|
2009-05-29 11:08:35 +00:00
|
|
|
{
|
2015-12-15 21:56:41 +00:00
|
|
|
return PlaceInternal(aDrawTarget, false, aDesiredSize, true);
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nsresult
|
2015-12-15 21:56:41 +00:00
|
|
|
nsMathMLmencloseFrame::Place(DrawTarget* aDrawTarget,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aPlaceOrigin,
|
2016-07-21 10:36:38 +00:00
|
|
|
ReflowOutput& aDesiredSize)
|
2009-05-29 11:08:35 +00:00
|
|
|
{
|
2015-12-15 21:56:41 +00:00
|
|
|
return PlaceInternal(aDrawTarget, aPlaceOrigin, aDesiredSize, false);
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nsresult
|
2015-12-15 21:56:41 +00:00
|
|
|
nsMathMLmencloseFrame::PlaceInternal(DrawTarget* aDrawTarget,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aPlaceOrigin,
|
2016-07-21 10:36:38 +00:00
|
|
|
ReflowOutput& aDesiredSize,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aWidthOnly)
|
2009-05-29 11:08:35 +00:00
|
|
|
{
|
|
|
|
///////////////
|
|
|
|
// Measure the size of our content using the base class to format like an
|
|
|
|
// inferred mrow.
|
2016-07-21 10:36:38 +00:00
|
|
|
ReflowOutput baseSize(aDesiredSize.GetWritingMode());
|
2009-05-29 11:08:35 +00:00
|
|
|
nsresult rv =
|
2015-12-15 21:56:41 +00:00
|
|
|
nsMathMLContainerFrame::Place(aDrawTarget, false, baseSize);
|
2009-05-29 11:08:35 +00:00
|
|
|
|
|
|
|
if (NS_MATHML_HAS_ERROR(mPresentationData.flags) || NS_FAILED(rv)) {
|
2016-01-29 14:42:14 +00:00
|
|
|
DidReflowChildren(PrincipalChildList().FirstChild());
|
2009-05-29 11:08:35 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBoundingMetrics bmBase = baseSize.mBoundingMetrics;
|
|
|
|
nscoord dx_left = 0, dx_right = 0;
|
|
|
|
nsBoundingMetrics bmLongdivChar, bmRadicalChar;
|
|
|
|
nscoord radicalAscent = 0, radicalDescent = 0;
|
|
|
|
nscoord longdivAscent = 0, longdivDescent = 0;
|
|
|
|
nscoord psi = 0;
|
2014-06-17 06:40:00 +00:00
|
|
|
nscoord leading = 0;
|
2009-05-29 11:08:35 +00:00
|
|
|
|
|
|
|
///////////////
|
|
|
|
// Thickness of bars and font metrics
|
|
|
|
nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
|
2011-04-08 01:04:39 +00:00
|
|
|
|
2014-10-25 06:30:00 +00:00
|
|
|
float fontSizeInflation = nsLayoutUtils::FontSizeInflationFor(this);
|
2016-03-17 05:55:48 +00:00
|
|
|
RefPtr<nsFontMetrics> fm =
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, fontSizeInflation);
|
2015-12-15 21:56:41 +00:00
|
|
|
GetRuleThickness(aDrawTarget, fm, mRuleThickness);
|
2014-06-17 06:40:00 +00:00
|
|
|
if (mRuleThickness < onePixel) {
|
|
|
|
mRuleThickness = onePixel;
|
|
|
|
}
|
2009-05-29 11:08:35 +00:00
|
|
|
|
2014-01-04 15:02:17 +00:00
|
|
|
char16_t one = '1';
|
2014-10-24 15:28:14 +00:00
|
|
|
nsBoundingMetrics bmOne =
|
2015-12-15 21:56:41 +00:00
|
|
|
nsLayoutUtils::AppUnitBoundsOfString(&one, 1, *fm, aDrawTarget);
|
2009-05-29 11:08:35 +00:00
|
|
|
|
|
|
|
///////////////
|
|
|
|
// General rules: the menclose element takes the size of the enclosed content.
|
|
|
|
// We add a padding when needed.
|
|
|
|
|
|
|
|
// determine padding & psi
|
|
|
|
nscoord padding = 3 * mRuleThickness;
|
|
|
|
nscoord delta = padding % onePixel;
|
|
|
|
if (delta)
|
|
|
|
padding += onePixel - delta; // round up
|
|
|
|
|
|
|
|
if (IsToDraw(NOTATION_LONGDIV) || IsToDraw(NOTATION_RADICAL)) {
|
2014-06-17 06:40:00 +00:00
|
|
|
GetRadicalParameters(fm, StyleFont()->mMathDisplay ==
|
|
|
|
NS_MATHML_DISPLAYSTYLE_BLOCK,
|
|
|
|
mRadicalRuleThickness, leading, psi);
|
|
|
|
|
|
|
|
// make sure that the rule appears on on screen
|
|
|
|
if (mRadicalRuleThickness < onePixel) {
|
|
|
|
mRadicalRuleThickness = onePixel;
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
2014-06-17 06:40:00 +00:00
|
|
|
// adjust clearance psi to get an exact number of pixels -- this
|
|
|
|
// gives a nicer & uniform look on stacked radicals (bug 130282)
|
|
|
|
delta = psi % onePixel;
|
|
|
|
if (delta) {
|
|
|
|
psi += onePixel - delta; // round up
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-29 11:08:35 +00:00
|
|
|
// Set horizontal parameters
|
|
|
|
if (IsToDraw(NOTATION_ROUNDEDBOX) ||
|
|
|
|
IsToDraw(NOTATION_TOP) ||
|
|
|
|
IsToDraw(NOTATION_LEFT) ||
|
|
|
|
IsToDraw(NOTATION_BOTTOM) ||
|
|
|
|
IsToDraw(NOTATION_CIRCLE))
|
|
|
|
dx_left = padding;
|
|
|
|
|
|
|
|
if (IsToDraw(NOTATION_ROUNDEDBOX) ||
|
|
|
|
IsToDraw(NOTATION_TOP) ||
|
|
|
|
IsToDraw(NOTATION_RIGHT) ||
|
|
|
|
IsToDraw(NOTATION_BOTTOM) ||
|
|
|
|
IsToDraw(NOTATION_CIRCLE))
|
|
|
|
dx_right = padding;
|
|
|
|
|
|
|
|
// Set vertical parameters
|
|
|
|
if (IsToDraw(NOTATION_RIGHT) ||
|
|
|
|
IsToDraw(NOTATION_LEFT) ||
|
|
|
|
IsToDraw(NOTATION_UPDIAGONALSTRIKE) ||
|
2013-06-04 12:21:25 +00:00
|
|
|
IsToDraw(NOTATION_UPDIAGONALARROW) ||
|
2009-05-29 11:08:35 +00:00
|
|
|
IsToDraw(NOTATION_DOWNDIAGONALSTRIKE) ||
|
|
|
|
IsToDraw(NOTATION_VERTICALSTRIKE) ||
|
|
|
|
IsToDraw(NOTATION_CIRCLE) ||
|
|
|
|
IsToDraw(NOTATION_ROUNDEDBOX) ||
|
|
|
|
IsToDraw(NOTATION_RADICAL) ||
|
2014-05-11 19:48:00 +00:00
|
|
|
IsToDraw(NOTATION_LONGDIV) ||
|
|
|
|
IsToDraw(NOTATION_PHASORANGLE)) {
|
2009-05-29 11:08:35 +00:00
|
|
|
// set a minimal value for the base height
|
2013-01-15 12:22:03 +00:00
|
|
|
bmBase.ascent = std::max(bmOne.ascent, bmBase.ascent);
|
|
|
|
bmBase.descent = std::max(0, bmBase.descent);
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mBoundingMetrics.ascent = bmBase.ascent;
|
|
|
|
mBoundingMetrics.descent = bmBase.descent;
|
|
|
|
|
|
|
|
if (IsToDraw(NOTATION_ROUNDEDBOX) ||
|
|
|
|
IsToDraw(NOTATION_TOP) ||
|
|
|
|
IsToDraw(NOTATION_LEFT) ||
|
|
|
|
IsToDraw(NOTATION_RIGHT) ||
|
|
|
|
IsToDraw(NOTATION_CIRCLE))
|
|
|
|
mBoundingMetrics.ascent += padding;
|
|
|
|
|
|
|
|
if (IsToDraw(NOTATION_ROUNDEDBOX) ||
|
|
|
|
IsToDraw(NOTATION_LEFT) ||
|
|
|
|
IsToDraw(NOTATION_RIGHT) ||
|
|
|
|
IsToDraw(NOTATION_BOTTOM) ||
|
|
|
|
IsToDraw(NOTATION_CIRCLE))
|
|
|
|
mBoundingMetrics.descent += padding;
|
|
|
|
|
2014-05-11 19:48:00 +00:00
|
|
|
///////////////
|
|
|
|
// phasorangle notation
|
|
|
|
if (IsToDraw(NOTATION_PHASORANGLE)) {
|
|
|
|
nscoord phasorangleWidth = kPhasorangleWidth * mRuleThickness;
|
|
|
|
// Update horizontal parameters
|
|
|
|
dx_left = std::max(dx_left, phasorangleWidth);
|
|
|
|
}
|
|
|
|
|
2013-06-04 12:21:25 +00:00
|
|
|
///////////////
|
|
|
|
// updiagonal arrow notation. We need enough space at the top right corner to
|
|
|
|
// draw the arrow head.
|
|
|
|
if (IsToDraw(NOTATION_UPDIAGONALARROW)) {
|
|
|
|
// This is an estimate, see nsDisplayNotation::Paint for the exact head size
|
|
|
|
nscoord arrowHeadSize = kArrowHeadSize * mRuleThickness;
|
|
|
|
|
|
|
|
// We want that the arrow shaft strikes the menclose content and that the
|
|
|
|
// arrow head does not overlap with that content. Hence we add some space
|
|
|
|
// on the right. We don't add space on the top but only ensure that the
|
|
|
|
// ascent is large enough.
|
|
|
|
dx_right = std::max(dx_right, arrowHeadSize);
|
|
|
|
mBoundingMetrics.ascent = std::max(mBoundingMetrics.ascent, arrowHeadSize);
|
|
|
|
}
|
|
|
|
|
2009-05-29 11:08:35 +00:00
|
|
|
///////////////
|
|
|
|
// circle notation: we don't want the ellipse to overlap the enclosed
|
|
|
|
// content. Hence, we need to increase the size of the bounding box by a
|
|
|
|
// factor of at least sqrt(2).
|
|
|
|
if (IsToDraw(NOTATION_CIRCLE)) {
|
2009-08-12 00:04:42 +00:00
|
|
|
double ratio = (sqrt(2.0) - 1.0) / 2.0;
|
2009-05-29 11:08:35 +00:00
|
|
|
nscoord padding2;
|
|
|
|
|
|
|
|
// Update horizontal parameters
|
|
|
|
padding2 = ratio * bmBase.width;
|
|
|
|
|
2013-01-15 12:22:03 +00:00
|
|
|
dx_left = std::max(dx_left, padding2);
|
|
|
|
dx_right = std::max(dx_right, padding2);
|
2009-05-29 11:08:35 +00:00
|
|
|
|
|
|
|
// Update vertical parameters
|
|
|
|
padding2 = ratio * (bmBase.ascent + bmBase.descent);
|
|
|
|
|
2013-01-15 12:22:03 +00:00
|
|
|
mBoundingMetrics.ascent = std::max(mBoundingMetrics.ascent,
|
2009-05-29 11:08:35 +00:00
|
|
|
bmBase.ascent + padding2);
|
2013-01-15 12:22:03 +00:00
|
|
|
mBoundingMetrics.descent = std::max(mBoundingMetrics.descent,
|
2009-05-29 11:08:35 +00:00
|
|
|
bmBase.descent + padding2);
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////
|
|
|
|
// longdiv notation:
|
|
|
|
if (IsToDraw(NOTATION_LONGDIV)) {
|
|
|
|
if (aWidthOnly) {
|
|
|
|
nscoord longdiv_width = mMathMLChar[mLongDivCharIndex].
|
2015-12-15 21:56:41 +00:00
|
|
|
GetMaxWidth(PresContext(), aDrawTarget, fontSizeInflation);
|
2009-05-29 11:08:35 +00:00
|
|
|
|
|
|
|
// Update horizontal parameters
|
2013-01-15 12:22:03 +00:00
|
|
|
dx_left = std::max(dx_left, longdiv_width);
|
2009-05-29 11:08:35 +00:00
|
|
|
} else {
|
|
|
|
// Stretch the parenthesis to the appropriate height if it is not
|
|
|
|
// big enough.
|
|
|
|
nsBoundingMetrics contSize = bmBase;
|
|
|
|
contSize.ascent = mRuleThickness;
|
|
|
|
contSize.descent = bmBase.ascent + bmBase.descent + psi;
|
|
|
|
|
|
|
|
// height(longdiv) should be >= height(base) + psi + mRuleThickness
|
2015-12-15 21:56:41 +00:00
|
|
|
mMathMLChar[mLongDivCharIndex].Stretch(PresContext(), aDrawTarget,
|
2014-10-25 06:30:00 +00:00
|
|
|
fontSizeInflation,
|
2009-05-29 11:08:35 +00:00
|
|
|
NS_STRETCH_DIRECTION_VERTICAL,
|
|
|
|
contSize, bmLongdivChar,
|
2011-12-21 22:22:00 +00:00
|
|
|
NS_STRETCH_LARGER, false);
|
2009-05-29 11:08:35 +00:00
|
|
|
mMathMLChar[mLongDivCharIndex].GetBoundingMetrics(bmLongdivChar);
|
|
|
|
|
|
|
|
// Update horizontal parameters
|
2013-01-15 12:22:03 +00:00
|
|
|
dx_left = std::max(dx_left, bmLongdivChar.width);
|
2009-05-29 11:08:35 +00:00
|
|
|
|
|
|
|
// Update vertical parameters
|
|
|
|
longdivAscent = bmBase.ascent + psi + mRuleThickness;
|
2013-01-15 12:22:03 +00:00
|
|
|
longdivDescent = std::max(bmBase.descent,
|
2009-05-29 11:08:35 +00:00
|
|
|
(bmLongdivChar.ascent + bmLongdivChar.descent -
|
|
|
|
longdivAscent));
|
|
|
|
|
2013-01-15 12:22:03 +00:00
|
|
|
mBoundingMetrics.ascent = std::max(mBoundingMetrics.ascent,
|
2009-05-29 11:08:35 +00:00
|
|
|
longdivAscent);
|
2013-01-15 12:22:03 +00:00
|
|
|
mBoundingMetrics.descent = std::max(mBoundingMetrics.descent,
|
2009-05-29 11:08:35 +00:00
|
|
|
longdivDescent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////
|
|
|
|
// radical notation:
|
|
|
|
if (IsToDraw(NOTATION_RADICAL)) {
|
2013-05-29 23:26:40 +00:00
|
|
|
nscoord *dx_leading = StyleVisibility()->mDirection ? &dx_right : &dx_left;
|
2010-01-05 10:22:31 +00:00
|
|
|
|
2009-05-29 11:08:35 +00:00
|
|
|
if (aWidthOnly) {
|
|
|
|
nscoord radical_width = mMathMLChar[mRadicalCharIndex].
|
2015-12-15 21:56:41 +00:00
|
|
|
GetMaxWidth(PresContext(), aDrawTarget, fontSizeInflation);
|
2009-05-29 11:08:35 +00:00
|
|
|
|
|
|
|
// Update horizontal parameters
|
2013-01-15 12:22:03 +00:00
|
|
|
*dx_leading = std::max(*dx_leading, radical_width);
|
2009-05-29 11:08:35 +00:00
|
|
|
} else {
|
|
|
|
// Stretch the radical symbol to the appropriate height if it is not
|
|
|
|
// big enough.
|
|
|
|
nsBoundingMetrics contSize = bmBase;
|
2014-06-17 06:40:00 +00:00
|
|
|
contSize.ascent = mRadicalRuleThickness;
|
2009-05-29 11:08:35 +00:00
|
|
|
contSize.descent = bmBase.ascent + bmBase.descent + psi;
|
|
|
|
|
2014-06-17 06:40:00 +00:00
|
|
|
// height(radical) should be >= height(base) + psi + mRadicalRuleThickness
|
2015-12-15 21:56:41 +00:00
|
|
|
mMathMLChar[mRadicalCharIndex].Stretch(PresContext(), aDrawTarget,
|
2014-10-25 06:30:00 +00:00
|
|
|
fontSizeInflation,
|
2009-05-29 11:08:35 +00:00
|
|
|
NS_STRETCH_DIRECTION_VERTICAL,
|
|
|
|
contSize, bmRadicalChar,
|
2011-12-21 22:22:00 +00:00
|
|
|
NS_STRETCH_LARGER,
|
2013-05-29 23:26:40 +00:00
|
|
|
StyleVisibility()->mDirection);
|
2009-05-29 11:08:35 +00:00
|
|
|
mMathMLChar[mRadicalCharIndex].GetBoundingMetrics(bmRadicalChar);
|
|
|
|
|
|
|
|
// Update horizontal parameters
|
2013-01-15 12:22:03 +00:00
|
|
|
*dx_leading = std::max(*dx_leading, bmRadicalChar.width);
|
2009-05-29 11:08:35 +00:00
|
|
|
|
|
|
|
// Update vertical parameters
|
2014-06-17 06:40:00 +00:00
|
|
|
radicalAscent = bmBase.ascent + psi + mRadicalRuleThickness;
|
2013-01-15 12:22:03 +00:00
|
|
|
radicalDescent = std::max(bmBase.descent,
|
2009-05-29 11:08:35 +00:00
|
|
|
(bmRadicalChar.ascent + bmRadicalChar.descent -
|
|
|
|
radicalAscent));
|
|
|
|
|
2013-01-15 12:22:03 +00:00
|
|
|
mBoundingMetrics.ascent = std::max(mBoundingMetrics.ascent,
|
2009-05-29 11:08:35 +00:00
|
|
|
radicalAscent);
|
2013-01-15 12:22:03 +00:00
|
|
|
mBoundingMetrics.descent = std::max(mBoundingMetrics.descent,
|
2009-05-29 11:08:35 +00:00
|
|
|
radicalDescent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////
|
|
|
|
//
|
|
|
|
if (IsToDraw(NOTATION_CIRCLE) ||
|
|
|
|
IsToDraw(NOTATION_ROUNDEDBOX) ||
|
|
|
|
(IsToDraw(NOTATION_LEFT) && IsToDraw(NOTATION_RIGHT))) {
|
|
|
|
// center the menclose around the content (horizontally)
|
2013-01-15 12:22:03 +00:00
|
|
|
dx_left = dx_right = std::max(dx_left, dx_right);
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////
|
|
|
|
// The maximum size is now computed: set the remaining parameters
|
|
|
|
mBoundingMetrics.width = dx_left + bmBase.width + dx_right;
|
|
|
|
|
2013-01-15 12:22:03 +00:00
|
|
|
mBoundingMetrics.leftBearing = std::min(0, dx_left + bmBase.leftBearing);
|
2009-05-29 11:08:35 +00:00
|
|
|
mBoundingMetrics.rightBearing =
|
2013-01-15 12:22:03 +00:00
|
|
|
std::max(mBoundingMetrics.width, dx_left + bmBase.rightBearing);
|
2009-05-29 11:08:35 +00:00
|
|
|
|
2013-12-27 17:59:52 +00:00
|
|
|
aDesiredSize.Width() = mBoundingMetrics.width;
|
2009-05-29 11:08:35 +00:00
|
|
|
|
2014-06-11 09:45:31 +00:00
|
|
|
aDesiredSize.SetBlockStartAscent(std::max(mBoundingMetrics.ascent,
|
|
|
|
baseSize.BlockStartAscent()));
|
|
|
|
aDesiredSize.Height() = aDesiredSize.BlockStartAscent() +
|
|
|
|
std::max(mBoundingMetrics.descent,
|
|
|
|
baseSize.Height() - baseSize.BlockStartAscent());
|
2009-05-29 11:08:35 +00:00
|
|
|
|
|
|
|
if (IsToDraw(NOTATION_LONGDIV) || IsToDraw(NOTATION_RADICAL)) {
|
2014-06-11 09:45:31 +00:00
|
|
|
nscoord desiredSizeAscent = aDesiredSize.BlockStartAscent();
|
|
|
|
nscoord desiredSizeDescent = aDesiredSize.Height() -
|
|
|
|
aDesiredSize.BlockStartAscent();
|
2009-05-29 11:08:35 +00:00
|
|
|
|
|
|
|
if (IsToDraw(NOTATION_LONGDIV)) {
|
2013-01-15 12:22:03 +00:00
|
|
|
desiredSizeAscent = std::max(desiredSizeAscent,
|
2009-05-29 11:08:35 +00:00
|
|
|
longdivAscent + leading);
|
2013-01-15 12:22:03 +00:00
|
|
|
desiredSizeDescent = std::max(desiredSizeDescent,
|
2009-05-29 11:08:35 +00:00
|
|
|
longdivDescent + mRuleThickness);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsToDraw(NOTATION_RADICAL)) {
|
2013-01-15 12:22:03 +00:00
|
|
|
desiredSizeAscent = std::max(desiredSizeAscent,
|
2009-05-29 11:08:35 +00:00
|
|
|
radicalAscent + leading);
|
2013-01-15 12:22:03 +00:00
|
|
|
desiredSizeDescent = std::max(desiredSizeDescent,
|
2014-06-17 06:40:00 +00:00
|
|
|
radicalDescent + mRadicalRuleThickness);
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
2014-06-11 09:45:31 +00:00
|
|
|
aDesiredSize.SetBlockStartAscent(desiredSizeAscent);
|
2013-12-27 17:59:52 +00:00
|
|
|
aDesiredSize.Height() = desiredSizeAscent + desiredSizeDescent;
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsToDraw(NOTATION_CIRCLE) ||
|
|
|
|
IsToDraw(NOTATION_ROUNDEDBOX) ||
|
|
|
|
(IsToDraw(NOTATION_TOP) && IsToDraw(NOTATION_BOTTOM))) {
|
|
|
|
// center the menclose around the content (vertically)
|
2014-06-11 09:45:31 +00:00
|
|
|
nscoord dy = std::max(aDesiredSize.BlockStartAscent() - bmBase.ascent,
|
|
|
|
aDesiredSize.Height() -
|
|
|
|
aDesiredSize.BlockStartAscent() - bmBase.descent);
|
2009-05-29 11:08:35 +00:00
|
|
|
|
2014-06-11 09:45:31 +00:00
|
|
|
aDesiredSize.SetBlockStartAscent(bmBase.ascent + dy);
|
|
|
|
aDesiredSize.Height() = aDesiredSize.BlockStartAscent() + bmBase.descent + dy;
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update mBoundingMetrics ascent/descent
|
|
|
|
if (IsToDraw(NOTATION_TOP) ||
|
|
|
|
IsToDraw(NOTATION_RIGHT) ||
|
|
|
|
IsToDraw(NOTATION_LEFT) ||
|
|
|
|
IsToDraw(NOTATION_UPDIAGONALSTRIKE) ||
|
2013-06-04 12:21:25 +00:00
|
|
|
IsToDraw(NOTATION_UPDIAGONALARROW) ||
|
2009-05-29 11:08:35 +00:00
|
|
|
IsToDraw(NOTATION_DOWNDIAGONALSTRIKE) ||
|
|
|
|
IsToDraw(NOTATION_VERTICALSTRIKE) ||
|
|
|
|
IsToDraw(NOTATION_CIRCLE) ||
|
|
|
|
IsToDraw(NOTATION_ROUNDEDBOX))
|
2014-06-11 09:45:31 +00:00
|
|
|
mBoundingMetrics.ascent = aDesiredSize.BlockStartAscent();
|
2009-05-29 11:08:35 +00:00
|
|
|
|
|
|
|
if (IsToDraw(NOTATION_BOTTOM) ||
|
|
|
|
IsToDraw(NOTATION_RIGHT) ||
|
|
|
|
IsToDraw(NOTATION_LEFT) ||
|
|
|
|
IsToDraw(NOTATION_UPDIAGONALSTRIKE) ||
|
2013-06-04 12:21:25 +00:00
|
|
|
IsToDraw(NOTATION_UPDIAGONALARROW) ||
|
2009-05-29 11:08:35 +00:00
|
|
|
IsToDraw(NOTATION_DOWNDIAGONALSTRIKE) ||
|
|
|
|
IsToDraw(NOTATION_VERTICALSTRIKE) ||
|
|
|
|
IsToDraw(NOTATION_CIRCLE) ||
|
|
|
|
IsToDraw(NOTATION_ROUNDEDBOX))
|
2014-06-11 09:45:31 +00:00
|
|
|
mBoundingMetrics.descent = aDesiredSize.Height() - aDesiredSize.BlockStartAscent();
|
2009-05-29 11:08:35 +00:00
|
|
|
|
2014-05-11 19:48:00 +00:00
|
|
|
// phasorangle notation:
|
|
|
|
// move up from the bottom by the angled line height
|
|
|
|
if (IsToDraw(NOTATION_PHASORANGLE))
|
|
|
|
mBoundingMetrics.ascent = std::max(mBoundingMetrics.ascent, 2 * kPhasorangleWidth * mRuleThickness - mBoundingMetrics.descent);
|
|
|
|
|
2009-05-29 11:08:35 +00:00
|
|
|
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
|
|
|
|
|
|
|
|
mReference.x = 0;
|
2014-06-11 09:45:31 +00:00
|
|
|
mReference.y = aDesiredSize.BlockStartAscent();
|
2009-05-29 11:08:35 +00:00
|
|
|
|
|
|
|
if (aPlaceOrigin) {
|
|
|
|
//////////////////
|
|
|
|
// Set position and size of MathMLChars
|
|
|
|
if (IsToDraw(NOTATION_LONGDIV))
|
|
|
|
mMathMLChar[mLongDivCharIndex].SetRect(nsRect(dx_left -
|
|
|
|
bmLongdivChar.width,
|
2014-06-11 09:45:31 +00:00
|
|
|
aDesiredSize.BlockStartAscent() -
|
2009-05-29 11:08:35 +00:00
|
|
|
longdivAscent,
|
|
|
|
bmLongdivChar.width,
|
|
|
|
bmLongdivChar.ascent +
|
|
|
|
bmLongdivChar.descent));
|
|
|
|
|
2010-01-05 10:22:31 +00:00
|
|
|
if (IsToDraw(NOTATION_RADICAL)) {
|
2013-05-29 23:26:40 +00:00
|
|
|
nscoord dx = (StyleVisibility()->mDirection ?
|
|
|
|
dx_left + bmBase.width : dx_left - bmRadicalChar.width);
|
2010-01-05 10:22:31 +00:00
|
|
|
|
|
|
|
mMathMLChar[mRadicalCharIndex].SetRect(nsRect(dx,
|
2014-06-11 09:45:31 +00:00
|
|
|
aDesiredSize.BlockStartAscent() -
|
2009-05-29 11:08:35 +00:00
|
|
|
radicalAscent,
|
|
|
|
bmRadicalChar.width,
|
|
|
|
bmRadicalChar.ascent +
|
|
|
|
bmRadicalChar.descent));
|
2010-01-05 10:22:31 +00:00
|
|
|
}
|
2009-05-29 11:08:35 +00:00
|
|
|
|
|
|
|
mContentWidth = bmBase.width;
|
|
|
|
|
|
|
|
//////////////////
|
|
|
|
// Finish reflowing child frames
|
2014-06-11 09:45:31 +00:00
|
|
|
PositionRowChildFrames(dx_left, aDesiredSize.BlockStartAscent());
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
2016-07-21 10:36:38 +00:00
|
|
|
nsMathMLmencloseFrame::FixInterFrameSpacing(ReflowOutput& aDesiredSize)
|
2009-05-29 11:08:35 +00:00
|
|
|
{
|
|
|
|
nscoord gap = nsMathMLContainerFrame::FixInterFrameSpacing(aDesiredSize);
|
|
|
|
if (!gap)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Move the MathML characters
|
|
|
|
nsRect rect;
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < mMathMLChar.Length(); i++) {
|
2009-05-29 11:08:35 +00:00
|
|
|
mMathMLChar[i].GetRect(rect);
|
|
|
|
rect.MoveBy(gap, 0);
|
|
|
|
mMathMLChar[i].SetRect(rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gap;
|
|
|
|
}
|
|
|
|
|
2014-02-18 07:47:48 +00:00
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
nsMathMLmencloseFrame::AttributeChanged(int32_t aNameSpaceID,
|
2009-05-29 11:08:35 +00:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aModType)
|
2009-05-29 11:08:35 +00:00
|
|
|
{
|
|
|
|
if (aAttribute == nsGkAtoms::notation_) {
|
|
|
|
InitNotations();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsMathMLContainerFrame::
|
|
|
|
AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////
|
|
|
|
// the Style System will use these to pass the proper style context to our
|
|
|
|
// MathMLChar
|
|
|
|
nsStyleContext*
|
2012-08-22 15:56:38 +00:00
|
|
|
nsMathMLmencloseFrame::GetAdditionalStyleContext(int32_t aIndex) const
|
2009-05-29 11:08:35 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t len = mMathMLChar.Length();
|
2009-05-29 11:08:35 +00:00
|
|
|
if (aIndex >= 0 && aIndex < len)
|
|
|
|
return mMathMLChar[aIndex].GetStyleContext();
|
|
|
|
else
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsMathMLmencloseFrame::SetAdditionalStyleContext(int32_t aIndex,
|
2009-05-29 11:08:35 +00:00
|
|
|
nsStyleContext* aStyleContext)
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t len = mMathMLChar.Length();
|
2009-05-29 11:08:35 +00:00
|
|
|
if (aIndex >= 0 && aIndex < len)
|
|
|
|
mMathMLChar[aIndex].SetStyleContext(aStyleContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
class nsDisplayNotation : public nsDisplayItem
|
|
|
|
{
|
|
|
|
public:
|
2010-08-13 10:01:13 +00:00
|
|
|
nsDisplayNotation(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, const nsRect& aRect,
|
2009-05-29 11:08:35 +00:00
|
|
|
nscoord aThickness, nsMencloseNotation aType)
|
2010-08-13 10:01:13 +00:00
|
|
|
: nsDisplayItem(aBuilder, aFrame), mRect(aRect),
|
2009-05-29 11:08:35 +00:00
|
|
|
mThickness(aThickness), mType(aType) {
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayNotation);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayNotation() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayNotation);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-07 00:35:14 +00:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsRenderingContext* aCtx) override;
|
2010-07-15 21:07:49 +00:00
|
|
|
NS_DISPLAY_DECL_NAME("MathMLMencloseNotation", TYPE_MATHML_MENCLOSE_NOTATION)
|
2009-05-29 11:08:35 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsRect mRect;
|
|
|
|
nscoord mThickness;
|
|
|
|
nsMencloseNotation mType;
|
|
|
|
};
|
|
|
|
|
|
|
|
void nsDisplayNotation::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 01:04:40 +00:00
|
|
|
nsRenderingContext* aCtx)
|
2009-05-29 11:08:35 +00:00
|
|
|
{
|
2014-10-24 07:26:28 +00:00
|
|
|
DrawTarget& aDrawTarget = *aCtx->GetDrawTarget();
|
2009-05-29 11:08:35 +00:00
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
|
|
|
|
2014-10-24 07:26:28 +00:00
|
|
|
Float strokeWidth = presContext->AppUnitsToGfxUnits(mThickness);
|
2014-10-16 11:03:44 +00:00
|
|
|
|
2014-10-24 07:26:28 +00:00
|
|
|
Rect rect = NSRectToRect(mRect + ToReferenceFrame(),
|
|
|
|
presContext->AppUnitsPerDevPixel());
|
|
|
|
rect.Deflate(strokeWidth / 2.f);
|
2009-05-29 11:08:35 +00:00
|
|
|
|
2014-10-24 07:26:28 +00:00
|
|
|
ColorPattern color(ToDeviceColor(
|
2016-09-16 04:40:45 +00:00
|
|
|
mFrame->GetVisitedDependentColor(eCSSProperty__webkit_text_fill_color)));
|
2009-05-29 11:08:35 +00:00
|
|
|
|
2014-10-24 07:26:28 +00:00
|
|
|
StrokeOptions strokeOptions(strokeWidth);
|
2009-05-29 11:08:35 +00:00
|
|
|
|
|
|
|
switch(mType)
|
2014-10-16 11:03:44 +00:00
|
|
|
{
|
|
|
|
case NOTATION_CIRCLE: {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Path> ellipse =
|
2014-10-24 07:26:28 +00:00
|
|
|
MakePathForEllipse(aDrawTarget, rect.Center(), rect.Size());
|
|
|
|
aDrawTarget.Stroke(ellipse, color, strokeOptions);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case NOTATION_ROUNDEDBOX: {
|
|
|
|
Float radius = 3 * strokeWidth;
|
2014-10-30 09:34:10 +00:00
|
|
|
RectCornerRadii radii(radius, radius);
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Path> roundedRect =
|
2014-10-24 07:26:28 +00:00
|
|
|
MakePathForRoundedRect(aDrawTarget, rect, radii, true);
|
|
|
|
aDrawTarget.Stroke(roundedRect, color, strokeOptions);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case NOTATION_UPDIAGONALSTRIKE: {
|
|
|
|
aDrawTarget.StrokeLine(rect.BottomLeft(), rect.TopRight(),
|
|
|
|
color, strokeOptions);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case NOTATION_DOWNDIAGONALSTRIKE: {
|
|
|
|
aDrawTarget.StrokeLine(rect.TopLeft(), rect.BottomRight(),
|
|
|
|
color, strokeOptions);
|
|
|
|
return;
|
2014-10-16 11:03:44 +00:00
|
|
|
}
|
2013-06-04 12:21:25 +00:00
|
|
|
case NOTATION_UPDIAGONALARROW: {
|
|
|
|
// Compute some parameters to draw the updiagonalarrow. The values below
|
|
|
|
// are taken from MathJax's HTML-CSS output.
|
2014-10-24 07:26:28 +00:00
|
|
|
Float W = rect.Width(); gfxFloat H = rect.Height();
|
|
|
|
Float l = sqrt(W*W + H*H);
|
|
|
|
Float f = Float(kArrowHeadSize) * strokeWidth / l;
|
|
|
|
Float w = W * f; gfxFloat h = H * f;
|
2013-06-04 12:21:25 +00:00
|
|
|
|
|
|
|
// Draw the arrow shaft
|
2014-10-24 07:26:28 +00:00
|
|
|
aDrawTarget.StrokeLine(rect.BottomLeft(),
|
|
|
|
rect.TopRight() + Point(-.7*w, .7*h),
|
|
|
|
color, strokeOptions);
|
2013-06-04 12:21:25 +00:00
|
|
|
|
|
|
|
// Draw the arrow head
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<PathBuilder> builder = aDrawTarget.CreatePathBuilder();
|
2014-10-24 07:26:28 +00:00
|
|
|
builder->MoveTo(rect.TopRight());
|
|
|
|
builder->LineTo(rect.TopRight() + Point(-w -.4*h, std::max(-strokeWidth / 2.0, h - .4*w)));
|
|
|
|
builder->LineTo(rect.TopRight() + Point(-.7*w, .7*h));
|
|
|
|
builder->LineTo(rect.TopRight() + Point(std::min(strokeWidth / 2.0, -w + .4*h), h + .4*w));
|
|
|
|
builder->Close();
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Path> path = builder->Finish();
|
2014-10-24 07:26:28 +00:00
|
|
|
aDrawTarget.Fill(path, color);
|
|
|
|
return;
|
2013-06-04 12:21:25 +00:00
|
|
|
}
|
2014-05-11 19:48:00 +00:00
|
|
|
case NOTATION_PHASORANGLE: {
|
|
|
|
// Compute some parameters to draw the angled line,
|
|
|
|
// that uses a slope of 2 (angle = tan^-1(2)).
|
|
|
|
// H = w * tan(angle) = w * 2
|
2014-10-24 07:26:28 +00:00
|
|
|
Float w = Float(kPhasorangleWidth) * strokeWidth;
|
|
|
|
Float H = 2 * w;
|
2014-05-11 19:48:00 +00:00
|
|
|
|
|
|
|
// Draw the angled line
|
2014-10-24 07:26:28 +00:00
|
|
|
aDrawTarget.StrokeLine(rect.BottomLeft(),
|
|
|
|
rect.BottomLeft() + Point(w, -H),
|
|
|
|
color, strokeOptions);
|
|
|
|
return;
|
2014-05-11 19:48:00 +00:00
|
|
|
}
|
2009-05-29 11:08:35 +00:00
|
|
|
default:
|
|
|
|
NS_NOTREACHED("This notation can not be drawn using nsDisplayNotation");
|
2014-10-16 11:03:44 +00:00
|
|
|
}
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 11:12:27 +00:00
|
|
|
void
|
2009-05-29 11:08:35 +00:00
|
|
|
nsMathMLmencloseFrame::DisplayNotation(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, const nsRect& aRect,
|
|
|
|
const nsDisplayListSet& aLists,
|
|
|
|
nscoord aThickness,
|
|
|
|
nsMencloseNotation aType)
|
|
|
|
{
|
2013-02-16 21:51:02 +00:00
|
|
|
if (!aFrame->StyleVisibility()->IsVisible() || aRect.IsEmpty() ||
|
2009-05-29 11:08:35 +00:00
|
|
|
aThickness <= 0)
|
2013-02-14 11:12:27 +00:00
|
|
|
return;
|
2009-05-29 11:08:35 +00:00
|
|
|
|
2013-02-14 11:12:27 +00:00
|
|
|
aLists.Content()->AppendNewToTop(new (aBuilder)
|
|
|
|
nsDisplayNotation(aBuilder, aFrame, aRect, aThickness, aType));
|
2009-05-29 11:08:35 +00:00
|
|
|
}
|