2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsMathMLFrame.h"
|
2014-10-17 07:06:34 -07:00
|
|
|
|
|
|
|
#include "gfxUtils.h"
|
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
2014-02-27 15:04:46 -08:00
|
|
|
#include "nsNameSpaceManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsMathMLChar.h"
|
2009-12-10 23:37:40 -08:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2013-08-30 14:37:12 -07:00
|
|
|
#include "nsMathMLElement.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// used to map attributes into CSS rules
|
|
|
|
#include "nsStyleSet.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsDisplayList.h"
|
2011-04-07 18:04:40 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-10-17 07:06:34 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
eMathMLFrameType
|
|
|
|
nsMathMLFrame::GetMathMLFrameType()
|
|
|
|
{
|
|
|
|
// see if it is an embellished operator (mapped to 'Op' in TeX)
|
|
|
|
if (mEmbellishData.coreFrame)
|
|
|
|
return GetMathMLFrameTypeFor(mEmbellishData.coreFrame);
|
|
|
|
|
|
|
|
// if it has a prescribed base, fetch the type from there
|
|
|
|
if (mPresentationData.baseFrame)
|
|
|
|
return GetMathMLFrameTypeFor(mPresentationData.baseFrame);
|
|
|
|
|
|
|
|
// everything else is treated as ordinary (mapped to 'Ord' in TeX)
|
|
|
|
return eMathMLFrameType_Ordinary;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMathMLFrame::InheritAutomaticData(nsIFrame* aParent)
|
|
|
|
{
|
|
|
|
mEmbellishData.flags = 0;
|
2012-07-30 07:20:58 -07:00
|
|
|
mEmbellishData.coreFrame = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
mEmbellishData.direction = NS_STRETCH_DIRECTION_UNSUPPORTED;
|
2011-12-21 14:21:59 -08:00
|
|
|
mEmbellishData.leadingSpace = 0;
|
|
|
|
mEmbellishData.trailingSpace = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mPresentationData.flags = 0;
|
2012-07-30 07:20:58 -07:00
|
|
|
mPresentationData.baseFrame = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-09 01:38:28 -08:00
|
|
|
// by default, just inherit the display of our parent
|
2007-03-22 10:30:00 -07:00
|
|
|
nsPresentationData parentData;
|
|
|
|
GetPresentationDataFrom(aParent, parentData);
|
|
|
|
|
2012-06-25 12:59:42 -07:00
|
|
|
#if defined(DEBUG) && defined(SHOW_BOUNDING_BOX)
|
2007-03-22 10:30:00 -07:00
|
|
|
mPresentationData.flags |= NS_MATHML_SHOW_BOUNDING_METRICS;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsMathMLFrame::UpdatePresentationData(uint32_t aFlagsValues,
|
|
|
|
uint32_t aWhichFlags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-09-24 01:33:00 -07:00
|
|
|
NS_ASSERTION(NS_MATHML_IS_COMPRESSED(aWhichFlags) ||
|
|
|
|
NS_MATHML_IS_DTLS_SET(aWhichFlags),
|
|
|
|
"aWhichFlags should only be compression or dtls flag");
|
2014-01-14 06:39:50 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_MATHML_IS_COMPRESSED(aWhichFlags)) {
|
|
|
|
// updating the compression flag is allowed
|
|
|
|
if (NS_MATHML_IS_COMPRESSED(aFlagsValues)) {
|
|
|
|
// 'compressed' means 'prime' style in App. G, TeXbook
|
|
|
|
mPresentationData.flags |= NS_MATHML_COMPRESSED;
|
|
|
|
}
|
|
|
|
// no else. the flag is sticky. it retains its value once it is set
|
|
|
|
}
|
2014-09-24 01:33:00 -07:00
|
|
|
// These flags determine whether the dtls font feature settings should
|
|
|
|
// be applied.
|
|
|
|
if (NS_MATHML_IS_DTLS_SET(aWhichFlags)) {
|
|
|
|
if (NS_MATHML_IS_DTLS_SET(aFlagsValues)) {
|
|
|
|
mPresentationData.flags |= NS_MATHML_DTLS;
|
|
|
|
} else {
|
|
|
|
mPresentationData.flags &= ~NS_MATHML_DTLS;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper to give a style context suitable for doing the stretching of
|
|
|
|
// a MathMLChar. Frame classes that use this should ensure that the
|
|
|
|
// extra leaf style contexts given to the MathMLChars are accessible to
|
|
|
|
// the Style System via the Get/Set AdditionalStyleContext() APIs.
|
|
|
|
/* static */ void
|
|
|
|
nsMathMLFrame::ResolveMathMLCharStyle(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsStyleContext* aParentStyleContext,
|
2014-04-24 12:30:00 -07:00
|
|
|
nsMathMLChar* aMathMLChar)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-04-24 12:30:00 -07:00
|
|
|
nsCSSPseudoElements::Type pseudoType =
|
2009-12-10 23:37:40 -08:00
|
|
|
nsCSSPseudoElements::ePseudo_mozMathAnonymous; // savings
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRefPtr<nsStyleContext> newStyleContext;
|
|
|
|
newStyleContext = aPresContext->StyleSet()->
|
2010-04-30 06:12:06 -07:00
|
|
|
ResolvePseudoElementStyle(aContent->AsElement(), pseudoType,
|
2013-11-27 22:46:38 -08:00
|
|
|
aParentStyleContext, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-08-02 21:11:06 -07:00
|
|
|
aMathMLChar->SetStyleContext(newStyleContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsMathMLFrame::GetEmbellishDataFrom(nsIFrame* aFrame,
|
|
|
|
nsEmbellishData& aEmbellishData)
|
|
|
|
{
|
|
|
|
// initialize OUT params
|
|
|
|
aEmbellishData.flags = 0;
|
2012-07-30 07:20:58 -07:00
|
|
|
aEmbellishData.coreFrame = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
aEmbellishData.direction = NS_STRETCH_DIRECTION_UNSUPPORTED;
|
2011-12-21 14:21:59 -08:00
|
|
|
aEmbellishData.leadingSpace = 0;
|
|
|
|
aEmbellishData.trailingSpace = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aFrame && aFrame->IsFrameOfType(nsIFrame::eMathML)) {
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mathMLFrame) {
|
|
|
|
mathMLFrame->GetEmbellishData(aEmbellishData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// helper to get the presentation data of a frame, by possibly walking up
|
|
|
|
// the frame hierarchy if we happen to be surrounded by non-MathML frames.
|
|
|
|
/* static */ void
|
|
|
|
nsMathMLFrame::GetPresentationDataFrom(nsIFrame* aFrame,
|
|
|
|
nsPresentationData& aPresentationData,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aClimbTree)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// initialize OUT params
|
|
|
|
aPresentationData.flags = 0;
|
2012-07-30 07:20:58 -07:00
|
|
|
aPresentationData.baseFrame = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsIFrame* frame = aFrame;
|
|
|
|
while (frame) {
|
|
|
|
if (frame->IsFrameOfType(nsIFrame::eMathML)) {
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(frame);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mathMLFrame) {
|
|
|
|
mathMLFrame->GetPresentationData(aPresentationData);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// stop if the caller doesn't want to lookup beyond the frame
|
|
|
|
if (!aClimbTree) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// stop if we reach the root <math> tag
|
|
|
|
nsIContent* content = frame->GetContent();
|
2008-01-15 21:07:09 -08:00
|
|
|
NS_ASSERTION(content || !frame->GetParent(), // no assert for the root
|
|
|
|
"dangling frame without a content node");
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!content)
|
|
|
|
break;
|
|
|
|
|
2015-03-03 03:09:00 -08:00
|
|
|
if (content->IsMathMLElement(nsGkAtoms::math)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
frame = frame->GetParent();
|
|
|
|
}
|
2008-01-15 21:07:09 -08:00
|
|
|
NS_WARN_IF_FALSE(frame && frame->GetContent(),
|
|
|
|
"bad MathML markup - could not find the top <math> element");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
2011-04-07 18:04:40 -07:00
|
|
|
nsMathMLFrame::GetRuleThickness(nsRenderingContext& aRenderingContext,
|
2011-04-07 18:05:49 -07:00
|
|
|
nsFontMetrics* aFontMetrics,
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord& aRuleThickness)
|
|
|
|
{
|
2011-04-07 21:18:43 -07:00
|
|
|
nscoord xHeight = aFontMetrics->XHeight();
|
2014-01-04 07:02:17 -08:00
|
|
|
char16_t overBar = 0x00AF;
|
2014-10-24 08:28:14 -07:00
|
|
|
nsBoundingMetrics bm =
|
2014-10-24 08:28:14 -07:00
|
|
|
nsLayoutUtils::AppUnitBoundsOfString(&overBar, 1, *aFontMetrics,
|
|
|
|
aRenderingContext);
|
2011-04-07 18:04:40 -07:00
|
|
|
aRuleThickness = bm.ascent + bm.descent;
|
|
|
|
if (aRuleThickness <= 0 || aRuleThickness >= xHeight) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// fall-back to the other version
|
|
|
|
GetRuleThickness(aFontMetrics, aRuleThickness);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
2011-04-07 18:04:40 -07:00
|
|
|
nsMathMLFrame::GetAxisHeight(nsRenderingContext& aRenderingContext,
|
2011-04-07 18:05:49 -07:00
|
|
|
nsFontMetrics* aFontMetrics,
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord& aAxisHeight)
|
|
|
|
{
|
2014-07-01 20:29:00 -07:00
|
|
|
gfxFont* mathFont = aFontMetrics->GetThebesFontGroup()->GetFirstMathFont();
|
|
|
|
if (mathFont) {
|
|
|
|
aAxisHeight =
|
|
|
|
mathFont->GetMathConstant(gfxFontEntry::AxisHeight,
|
|
|
|
aFontMetrics->AppUnitsPerDevPixel());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-07 21:18:43 -07:00
|
|
|
nscoord xHeight = aFontMetrics->XHeight();
|
2014-01-04 07:02:17 -08:00
|
|
|
char16_t minus = 0x2212; // not '-', but official Unicode minus sign
|
2014-10-24 08:28:14 -07:00
|
|
|
nsBoundingMetrics bm =
|
2014-10-24 08:28:14 -07:00
|
|
|
nsLayoutUtils::AppUnitBoundsOfString(&minus, 1, *aFontMetrics,
|
|
|
|
aRenderingContext);
|
2011-04-07 18:04:40 -07:00
|
|
|
aAxisHeight = bm.ascent - (bm.ascent + bm.descent)/2;
|
|
|
|
if (aAxisHeight <= 0 || aAxisHeight >= xHeight) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// fall-back to the other version
|
|
|
|
GetAxisHeight(aFontMetrics, aAxisHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nscoord
|
|
|
|
nsMathMLFrame::CalcLength(nsPresContext* aPresContext,
|
|
|
|
nsStyleContext* aStyleContext,
|
2014-10-24 23:29:00 -07:00
|
|
|
const nsCSSValue& aCSSValue,
|
|
|
|
float aFontSizeInflation)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aCSSValue.IsLengthUnit(), "not a length unit");
|
|
|
|
|
|
|
|
if (aCSSValue.IsFixedLengthUnit()) {
|
2010-08-13 02:58:01 -07:00
|
|
|
return aCSSValue.GetFixedLength(aPresContext);
|
|
|
|
}
|
|
|
|
if (aCSSValue.IsPixelLengthUnit()) {
|
|
|
|
return aCSSValue.GetPixelLength();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSUnit unit = aCSSValue.GetUnit();
|
|
|
|
|
2010-08-13 02:58:01 -07:00
|
|
|
if (eCSSUnit_EM == unit) {
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleFont* font = aStyleContext->StyleFont();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NSToCoordRound(aCSSValue.GetFloatValue() * (float)font->mFont.size);
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_XHeight == unit) {
|
2015-03-06 00:44:14 -08:00
|
|
|
aPresContext->SetUsesExChUnits(true);
|
2011-08-14 10:08:04 -07:00
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
|
|
|
nsLayoutUtils::GetFontMetricsForStyleContext(aStyleContext,
|
2014-10-24 23:29:00 -07:00
|
|
|
getter_AddRefs(fm),
|
|
|
|
aFontSizeInflation);
|
2011-04-07 21:18:43 -07:00
|
|
|
nscoord xHeight = fm->XHeight();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NSToCoordRound(aCSSValue.GetFloatValue() * (float)xHeight);
|
|
|
|
}
|
|
|
|
|
2010-08-13 02:58:01 -07:00
|
|
|
// MathML doesn't specify other CSS units such as rem or ch
|
|
|
|
NS_ERROR("Unsupported unit");
|
2007-03-22 10:30:00 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-15 15:30:14 -07:00
|
|
|
/* static */ void
|
|
|
|
nsMathMLFrame::ParseNumericValue(const nsString& aString,
|
|
|
|
nscoord* aLengthValue,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags,
|
2012-05-15 15:30:14 -07:00
|
|
|
nsPresContext* aPresContext,
|
2014-10-24 23:29:00 -07:00
|
|
|
nsStyleContext* aStyleContext,
|
|
|
|
float aFontSizeInflation)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-05-15 15:30:14 -07:00
|
|
|
nsCSSValue cssValue;
|
|
|
|
|
2012-12-27 08:12:05 -08:00
|
|
|
if (!nsMathMLElement::ParseNumericValue(aString, cssValue, aFlags,
|
|
|
|
aPresContext->Document())) {
|
2012-05-15 15:30:14 -07:00
|
|
|
// Invalid attribute value. aLengthValue remains unchanged, so the default
|
|
|
|
// length value is used.
|
|
|
|
return;
|
2011-06-22 08:55:05 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-15 15:30:14 -07:00
|
|
|
nsCSSUnit unit = cssValue.GetUnit();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-15 15:30:14 -07:00
|
|
|
if (unit == eCSSUnit_Percent || unit == eCSSUnit_Number) {
|
|
|
|
// Relative units. A multiple of the default length value is used.
|
|
|
|
*aLengthValue = NSToCoordRound(*aLengthValue * (unit == eCSSUnit_Percent ?
|
|
|
|
cssValue.GetPercentValue() :
|
|
|
|
cssValue.GetFloatValue()));
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-05-15 15:30:14 -07:00
|
|
|
|
|
|
|
// Absolute units.
|
2014-10-24 23:29:00 -07:00
|
|
|
*aLengthValue = CalcLength(aPresContext, aStyleContext, cssValue,
|
|
|
|
aFontSizeInflation);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// ================
|
|
|
|
// Utils to map attributes into CSS rules (work-around to bug 69409 which
|
|
|
|
// is not scheduled to be fixed anytime soon)
|
|
|
|
//
|
|
|
|
|
|
|
|
struct
|
|
|
|
nsCSSMapping {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t compatibility;
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsIAtom* attrAtom;
|
|
|
|
const char* cssProperty;
|
|
|
|
};
|
|
|
|
|
2012-06-25 12:59:42 -07:00
|
|
|
#if defined(DEBUG) && defined(SHOW_BOUNDING_BOX)
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsDisplayMathMLBoundingMetrics : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayMathMLBoundingMetrics(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, const nsRect& aRect)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame), mRect(aRect) {
|
2007-03-22 10:30:00 -07:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayMathMLBoundingMetrics);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayMathMLBoundingMetrics() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayMathMLBoundingMetrics);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-06 17:35:14 -07:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2014-02-24 06:41:56 -08:00
|
|
|
nsRenderingContext* aCtx) MOZ_OVERRIDE;
|
2010-07-15 14:07:49 -07:00
|
|
|
NS_DISPLAY_DECL_NAME("MathMLBoundingMetrics", TYPE_MATHML_BOUNDING_METRICS)
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
|
|
|
nsRect mRect;
|
|
|
|
};
|
|
|
|
|
|
|
|
void nsDisplayMathMLBoundingMetrics::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-10-17 07:06:34 -07:00
|
|
|
DrawTarget* drawTarget = aRenderingContext->GetDrawTarget();
|
|
|
|
Rect r = NSRectToRect(mRect + ToReferenceFrame(),
|
|
|
|
mFrame->PresContext()->AppUnitsPerDevPixel());
|
|
|
|
ColorPattern blue(ToDeviceColor(Color(0.f, 0.f, 1.f, 1.f)));
|
|
|
|
drawTarget->StrokeRect(r, blue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsMathMLFrame::DisplayBoundingMetrics(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, const nsPoint& aPt,
|
|
|
|
const nsBoundingMetrics& aMetrics,
|
|
|
|
const nsDisplayListSet& aLists) {
|
|
|
|
if (!NS_MATHML_PAINT_BOUNDING_METRICS(mPresentationData.flags))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nscoord x = aPt.x + aMetrics.leftBearing;
|
|
|
|
nscoord y = aPt.y - aMetrics.ascent;
|
|
|
|
nscoord w = aMetrics.rightBearing - aMetrics.leftBearing;
|
|
|
|
nscoord h = aMetrics.ascent + aMetrics.descent;
|
|
|
|
|
|
|
|
return aLists.Content()->AppendNewToTop(new (aBuilder)
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayMathMLBoundingMetrics(aBuilder, this, nsRect(x,y,w,h)));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class nsDisplayMathMLBar : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayMathMLBar(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, const nsRect& aRect)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame), mRect(aRect) {
|
2007-03-22 10:30:00 -07:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayMathMLBar);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayMathMLBar() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayMathMLBar);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-06 17:35:14 -07:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2014-02-24 06:41:56 -08:00
|
|
|
nsRenderingContext* aCtx) MOZ_OVERRIDE;
|
2010-07-15 14:07:49 -07:00
|
|
|
NS_DISPLAY_DECL_NAME("MathMLBar", TYPE_MATHML_BAR)
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
|
|
|
nsRect mRect;
|
|
|
|
};
|
|
|
|
|
|
|
|
void nsDisplayMathMLBar::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// paint the bar with the current text color
|
2014-10-19 05:22:22 -07:00
|
|
|
DrawTarget* drawTarget = aCtx->GetDrawTarget();
|
2014-10-22 04:29:06 -07:00
|
|
|
Rect rect = NSRectToSnappedRect(mRect + ToReferenceFrame(),
|
|
|
|
mFrame->PresContext()->AppUnitsPerDevPixel(),
|
|
|
|
*drawTarget);
|
2014-10-19 05:22:22 -07:00
|
|
|
ColorPattern color(ToDeviceColor(
|
|
|
|
mFrame->GetVisitedDependentColor(eCSSProperty_color)));
|
|
|
|
drawTarget->FillRect(rect, color);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMathMLFrame::DisplayBar(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, const nsRect& aRect,
|
|
|
|
const nsDisplayListSet& aLists) {
|
2013-02-16 13:51:02 -08:00
|
|
|
if (!aFrame->StyleVisibility()->IsVisible() || aRect.IsEmpty())
|
2013-02-14 03:12:27 -08:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-14 03:08:08 -08:00
|
|
|
aLists.Content()->AppendNewToTop(new (aBuilder)
|
|
|
|
nsDisplayMathMLBar(aBuilder, aFrame, aRect));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-06-16 23:40:00 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
nsMathMLFrame::GetRadicalParameters(nsFontMetrics* aFontMetrics,
|
|
|
|
bool aDisplayStyle,
|
|
|
|
nscoord& aRadicalRuleThickness,
|
|
|
|
nscoord& aRadicalExtraAscender,
|
|
|
|
nscoord& aRadicalVerticalGap)
|
|
|
|
{
|
|
|
|
nscoord oneDevPixel = aFontMetrics->AppUnitsPerDevPixel();
|
|
|
|
gfxFont* mathFont = aFontMetrics->GetThebesFontGroup()->GetFirstMathFont();
|
|
|
|
|
|
|
|
// get the radical rulethickness
|
|
|
|
if (mathFont) {
|
|
|
|
aRadicalRuleThickness =
|
|
|
|
mathFont->GetMathConstant(gfxFontEntry::RadicalRuleThickness,
|
|
|
|
oneDevPixel);
|
|
|
|
} else {
|
|
|
|
GetRuleThickness(aFontMetrics, aRadicalRuleThickness);
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the leading to be left at the top of the resulting frame
|
|
|
|
if (mathFont) {
|
|
|
|
aRadicalExtraAscender =
|
|
|
|
mathFont->GetMathConstant(gfxFontEntry::RadicalExtraAscender,
|
|
|
|
oneDevPixel);
|
|
|
|
} else {
|
|
|
|
// This seems more reliable than using aFontMetrics->GetLeading() on
|
|
|
|
// suspicious fonts.
|
|
|
|
nscoord em;
|
|
|
|
GetEmHeight(aFontMetrics, em);
|
|
|
|
aRadicalExtraAscender = nscoord(0.2f * em);
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the clearance between rule and content
|
|
|
|
if (mathFont) {
|
|
|
|
aRadicalVerticalGap =
|
|
|
|
mathFont->GetMathConstant(aDisplayStyle ?
|
|
|
|
gfxFontEntry::RadicalDisplayStyleVerticalGap :
|
|
|
|
gfxFontEntry::RadicalVerticalGap,
|
|
|
|
oneDevPixel);
|
|
|
|
} else {
|
|
|
|
// Rule 11, App. G, TeXbook
|
|
|
|
aRadicalVerticalGap = aRadicalRuleThickness +
|
|
|
|
(aDisplayStyle ? aFontMetrics->XHeight() : aRadicalRuleThickness) / 4;
|
|
|
|
}
|
|
|
|
}
|