2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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/. */
|
2008-01-08 22:36:46 +00:00
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
#include "mozilla/dom/MathMLElement.h"
|
|
|
|
|
2013-04-20 20:36:44 +00:00
|
|
|
#include "base/compiler_specific.h"
|
2019-05-31 14:33:33 +00:00
|
|
|
#include "mozilla/dom/BindContext.h"
|
2013-12-09 02:52:54 +00:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2018-04-13 19:34:37 +00:00
|
|
|
#include "mozilla/FontPropertyTypes.h"
|
2019-08-19 18:28:03 +00:00
|
|
|
#include "mozilla/StaticPrefs_mathml.h"
|
2018-04-13 03:19:30 +00:00
|
|
|
#include "mozilla/TextUtils.h"
|
2008-01-08 22:36:46 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2019-10-04 19:05:36 +00:00
|
|
|
#include "nsIContentInlines.h"
|
2017-06-17 00:49:09 +00:00
|
|
|
#include "nsITableCellLayout.h" // for MAX_COLSPAN / MAX_ROWSPAN
|
2014-05-24 18:46:38 +00:00
|
|
|
#include "nsLayoutStylesheetCache.h"
|
2008-01-08 22:36:46 +00:00
|
|
|
#include "nsCSSValue.h"
|
|
|
|
#include "nsMappedAttributes.h"
|
|
|
|
#include "nsStyleConsts.h"
|
2019-01-02 13:05:23 +00:00
|
|
|
#include "mozilla/dom/Document.h"
|
2008-01-08 22:36:46 +00:00
|
|
|
#include "nsPresContext.h"
|
2008-04-11 17:29:06 +00:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2012-12-27 16:12:05 +00:00
|
|
|
#include "nsIScriptError.h"
|
|
|
|
#include "nsContentUtils.h"
|
2013-09-07 13:01:08 +00:00
|
|
|
#include "nsIURI.h"
|
2008-01-08 22:36:46 +00:00
|
|
|
|
2014-03-18 04:48:21 +00:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-04-03 04:18:36 +00:00
|
|
|
#include "mozilla/EventStates.h"
|
2018-06-22 16:48:42 +00:00
|
|
|
#include "mozilla/MappedDeclarations.h"
|
2019-10-04 19:05:36 +00:00
|
|
|
#include "mozilla/dom/MathMLElementBinding.h"
|
2013-02-06 09:42:16 +00:00
|
|
|
|
2011-10-11 05:50:08 +00:00
|
|
|
using namespace mozilla;
|
2012-11-14 22:10:08 +00:00
|
|
|
using namespace mozilla::dom;
|
2011-10-11 05:50:08 +00:00
|
|
|
|
2008-01-08 22:36:46 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods:
|
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(MathMLElement, MathMLElementBase, Link)
|
2012-12-27 16:12:05 +00:00
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
static nsresult ReportLengthParseError(const nsString& aValue,
|
2019-01-02 13:05:23 +00:00
|
|
|
Document* aDocument) {
|
2019-06-08 21:26:12 +00:00
|
|
|
AutoTArray<nsString, 1> arg = {aValue};
|
2014-06-20 02:01:40 +00:00
|
|
|
return nsContentUtils::ReportToConsole(
|
|
|
|
nsIScriptError::errorFlag, NS_LITERAL_CSTRING("MathML"), aDocument,
|
2019-06-08 21:26:12 +00:00
|
|
|
nsContentUtils::eMATHML_PROPERTIES, "LengthParsingError", arg);
|
2014-03-15 19:00:17 +00:00
|
|
|
}
|
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
static nsresult ReportParseErrorNoTag(const nsString& aValue, nsAtom* aAtom,
|
2019-01-02 13:05:23 +00:00
|
|
|
Document* aDocument) {
|
2019-06-08 21:26:12 +00:00
|
|
|
AutoTArray<nsString, 2> argv = {aValue, nsDependentAtomString(aAtom)};
|
2014-06-20 02:01:40 +00:00
|
|
|
return nsContentUtils::ReportToConsole(
|
|
|
|
nsIScriptError::errorFlag, NS_LITERAL_CSTRING("MathML"), aDocument,
|
2019-06-08 21:26:12 +00:00
|
|
|
nsContentUtils::eMATHML_PROPERTIES, "AttributeParsingErrorNoTag", argv);
|
2013-04-20 20:36:44 +00:00
|
|
|
}
|
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
MathMLElement::MathMLElement(
|
2008-01-08 22:36:46 +00:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2019-09-13 16:27:54 +00:00
|
|
|
: MathMLElementBase(std::move(aNodeInfo)),
|
2008-01-08 22:36:46 +00:00
|
|
|
ALLOW_THIS_IN_INITIALIZER_LIST(Link(this)),
|
2014-03-15 19:00:17 +00:00
|
|
|
mIncrementScriptLevel(false) {}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
MathMLElement::MathMLElement(
|
2014-06-20 02:01:40 +00:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
2019-09-13 16:27:54 +00:00
|
|
|
: MathMLElementBase(std::move(aNodeInfo)),
|
2014-03-15 19:00:17 +00:00
|
|
|
ALLOW_THIS_IN_INITIALIZER_LIST(Link(this)),
|
|
|
|
mIncrementScriptLevel(false) {}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
nsresult MathMLElement::BindToTree(BindContext& aContext, nsINode& aParent) {
|
2012-12-07 14:35:14 +00:00
|
|
|
Link::ResetLinkState(false, Link::ElementHasHref());
|
2011-06-24 12:54:28 +00:00
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
nsresult rv = MathMLElementBase::BindToTree(aContext, aParent);
|
2008-01-08 22:36:46 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 04:27:04 +00:00
|
|
|
// FIXME(emilio): Probably should be composed, this uses all the other link
|
|
|
|
// infrastructure.
|
2019-06-01 14:40:33 +00:00
|
|
|
if (Document* doc = aContext.GetUncomposedDoc()) {
|
|
|
|
doc->RegisterPendingLinkUpdate(this);
|
2014-09-18 10:54:00 +00:00
|
|
|
}
|
|
|
|
|
2018-06-21 14:53:12 +00:00
|
|
|
// Set the bit in the document for telemetry.
|
2019-06-01 14:40:33 +00:00
|
|
|
if (Document* doc = aContext.GetComposedDoc()) {
|
|
|
|
doc->SetMathMLEnabled();
|
2008-01-08 22:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
void MathMLElement::UnbindFromTree(bool aNullParent) {
|
2018-12-13 15:16:52 +00:00
|
|
|
// Without removing the link state we risk a dangling pointer
|
|
|
|
// in the mStyledLinks hashtable
|
2012-12-07 14:35:14 +00:00
|
|
|
Link::ResetLinkState(false, Link::ElementHasHref());
|
2011-06-24 12:54:28 +00:00
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
MathMLElementBase::UnbindFromTree(aNullParent);
|
2011-06-24 12:54:28 +00:00
|
|
|
}
|
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
bool MathMLElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
|
|
|
nsAttrValue& aResult) {
|
2017-06-17 00:49:09 +00:00
|
|
|
MOZ_ASSERT(IsMathMLElement());
|
|
|
|
|
2008-01-08 22:36:46 +00:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::color || aAttribute == nsGkAtoms::mathcolor_ ||
|
|
|
|
aAttribute == nsGkAtoms::background ||
|
|
|
|
aAttribute == nsGkAtoms::mathbackground_) {
|
2010-07-17 08:09:14 +00:00
|
|
|
return aResult.ParseColor(aValue);
|
2008-01-08 22:36:46 +00:00
|
|
|
}
|
2019-10-04 19:05:36 +00:00
|
|
|
if (aAttribute == nsGkAtoms::tabindex) {
|
|
|
|
return aResult.ParseIntValue(aValue);
|
|
|
|
}
|
2017-06-17 00:49:09 +00:00
|
|
|
if (mNodeInfo->Equals(nsGkAtoms::mtd_)) {
|
|
|
|
if (aAttribute == nsGkAtoms::columnspan_) {
|
|
|
|
aResult.ParseClampedNonNegativeInt(aValue, 1, 1, MAX_COLSPAN);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (aAttribute == nsGkAtoms::rowspan) {
|
|
|
|
aResult.ParseClampedNonNegativeInt(aValue, 1, 0, MAX_ROWSPAN);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2008-01-08 22:36:46 +00:00
|
|
|
}
|
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
return MathMLElementBase::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
|
|
|
aMaybeScriptedPrincipal, aResult);
|
2008-01-08 22:36:46 +00:00
|
|
|
}
|
|
|
|
|
2019-08-12 21:13:33 +00:00
|
|
|
// https://mathml-refresh.github.io/mathml-core/#global-attributes
|
|
|
|
static Element::MappedAttributeEntry sGlobalAttributes[] = {
|
|
|
|
{nsGkAtoms::dir},
|
|
|
|
{nsGkAtoms::mathbackground_},
|
|
|
|
{nsGkAtoms::mathcolor_},
|
|
|
|
{nsGkAtoms::mathsize_},
|
|
|
|
{nsGkAtoms::mathvariant_},
|
2018-04-03 03:21:06 +00:00
|
|
|
{nsGkAtoms::scriptlevel_},
|
2019-08-12 21:13:33 +00:00
|
|
|
// XXXfredw: Also map displaystyle to CSS math-style?
|
|
|
|
{nullptr}};
|
|
|
|
|
2019-08-28 14:59:55 +00:00
|
|
|
// XXXfredw(bug 1548471): Add a runtime flag to disable these attributes.
|
|
|
|
static Element::MappedAttributeEntry sDeprecatedScriptAttributes[] = {
|
|
|
|
{nsGkAtoms::scriptminsize_}, {nsGkAtoms::scriptsizemultiplier_}, {nullptr}};
|
|
|
|
|
|
|
|
static Element::MappedAttributeEntry sDeprecatedStyleAttributes[] = {
|
2018-04-03 03:21:06 +00:00
|
|
|
{nsGkAtoms::background},
|
2019-08-12 21:13:33 +00:00
|
|
|
{nsGkAtoms::color},
|
|
|
|
{nsGkAtoms::fontfamily_},
|
|
|
|
{nsGkAtoms::fontsize_},
|
|
|
|
{nsGkAtoms::fontstyle_},
|
|
|
|
{nsGkAtoms::fontweight_},
|
2012-07-30 14:20:58 +00:00
|
|
|
{nullptr}};
|
2008-01-08 22:36:46 +00:00
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
bool MathMLElement::IsAttributeMapped(const nsAtom* aAttribute) const {
|
2017-06-17 00:49:09 +00:00
|
|
|
MOZ_ASSERT(IsMathMLElement());
|
|
|
|
|
2019-08-28 14:59:55 +00:00
|
|
|
static const MappedAttributeEntry* const globalMap[] = {
|
|
|
|
sGlobalAttributes, sDeprecatedScriptAttributes};
|
|
|
|
static const MappedAttributeEntry* const styleMap[] = {
|
|
|
|
sDeprecatedStyleAttributes};
|
2012-02-27 23:57:28 +00:00
|
|
|
|
2019-08-28 14:59:55 +00:00
|
|
|
return FindAttributeDependence(aAttribute, globalMap) ||
|
|
|
|
(!StaticPrefs::mathml_deprecated_style_attributes_disabled() &&
|
|
|
|
FindAttributeDependence(aAttribute, styleMap)) ||
|
|
|
|
(mNodeInfo->Equals(nsGkAtoms::mtable_) &&
|
|
|
|
aAttribute == nsGkAtoms::width);
|
2008-01-08 22:36:46 +00:00
|
|
|
}
|
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
nsMapRuleToAttributesFunc MathMLElement::GetAttributeMappingFunction() const {
|
2008-01-08 22:36:46 +00:00
|
|
|
// It doesn't really matter what our tag is here, because only attributes
|
|
|
|
// that satisfy IsAttributeMapped will be stored in the mapped attributes
|
|
|
|
// list and available to the mapping function
|
|
|
|
return &MapMathMLAttributesInto;
|
|
|
|
}
|
|
|
|
|
2019-02-25 22:05:29 +00:00
|
|
|
/* static */
|
2019-09-13 16:27:54 +00:00
|
|
|
bool MathMLElement::ParseNamedSpaceValue(const nsString& aString,
|
|
|
|
nsCSSValue& aCSSValue, uint32_t aFlags,
|
|
|
|
const Document& aDocument) {
|
2019-08-21 12:56:30 +00:00
|
|
|
if (StaticPrefs::mathml_mathspace_names_disabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t i = 0;
|
2012-05-15 22:30:14 +00:00
|
|
|
// See if it is one of the 'namedspace' (ranging -7/18em, -6/18, ... 7/18em)
|
|
|
|
if (aString.EqualsLiteral("veryverythinmathspace")) {
|
|
|
|
i = 1;
|
|
|
|
} else if (aString.EqualsLiteral("verythinmathspace")) {
|
|
|
|
i = 2;
|
|
|
|
} else if (aString.EqualsLiteral("thinmathspace")) {
|
|
|
|
i = 3;
|
|
|
|
} else if (aString.EqualsLiteral("mediummathspace")) {
|
|
|
|
i = 4;
|
|
|
|
} else if (aString.EqualsLiteral("thickmathspace")) {
|
|
|
|
i = 5;
|
|
|
|
} else if (aString.EqualsLiteral("verythickmathspace")) {
|
|
|
|
i = 6;
|
|
|
|
} else if (aString.EqualsLiteral("veryverythickmathspace")) {
|
|
|
|
i = 7;
|
|
|
|
} else if (aFlags & PARSE_ALLOW_NEGATIVE) {
|
|
|
|
if (aString.EqualsLiteral("negativeveryverythinmathspace")) {
|
|
|
|
i = -1;
|
|
|
|
} else if (aString.EqualsLiteral("negativeverythinmathspace")) {
|
|
|
|
i = -2;
|
|
|
|
} else if (aString.EqualsLiteral("negativethinmathspace")) {
|
|
|
|
i = -3;
|
|
|
|
} else if (aString.EqualsLiteral("negativemediummathspace")) {
|
|
|
|
i = -4;
|
|
|
|
} else if (aString.EqualsLiteral("negativethickmathspace")) {
|
|
|
|
i = -5;
|
|
|
|
} else if (aString.EqualsLiteral("negativeverythickmathspace")) {
|
|
|
|
i = -6;
|
|
|
|
} else if (aString.EqualsLiteral("negativeveryverythickmathspace")) {
|
|
|
|
i = -7;
|
|
|
|
}
|
|
|
|
}
|
2017-07-06 12:00:35 +00:00
|
|
|
if (0 != i) {
|
2019-08-22 06:29:26 +00:00
|
|
|
aDocument.WarnOnceAbout(dom::Document::eMathML_DeprecatedMathSpaceValue);
|
2012-05-15 22:30:14 +00:00
|
|
|
aCSSValue.SetFloatValue(float(i) / float(18), eCSSUnit_EM);
|
|
|
|
return true;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2012-05-15 22:30:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-07-06 12:00:35 +00:00
|
|
|
|
2012-05-15 22:30:14 +00:00
|
|
|
// The REC says:
|
|
|
|
//
|
|
|
|
// "Most presentation elements have attributes that accept values representing
|
|
|
|
// lengths to be used for size, spacing or similar properties. The syntax of a
|
|
|
|
// length is specified as
|
|
|
|
//
|
|
|
|
// number | number unit | namedspace
|
|
|
|
//
|
|
|
|
// There should be no space between the number and the unit of a length."
|
2017-07-06 12:00:35 +00:00
|
|
|
//
|
2012-05-15 22:30:14 +00:00
|
|
|
// "A trailing '%' represents a percent of the default value. The default
|
|
|
|
// value, or how it is obtained, is listed in the table of attributes for each
|
|
|
|
// element. [...] A number without a unit is intepreted as a multiple of the
|
|
|
|
// default value."
|
|
|
|
//
|
|
|
|
// "The possible units in MathML are:
|
2017-07-06 12:00:35 +00:00
|
|
|
//
|
2012-05-15 22:30:14 +00:00
|
|
|
// Unit Description
|
|
|
|
// em an em (font-relative unit traditionally used for horizontal lengths)
|
|
|
|
// ex an ex (font-relative unit traditionally used for vertical lengths)
|
|
|
|
// px pixels, or size of a pixel in the current display
|
|
|
|
// in inches (1 inch = 2.54 centimeters)
|
|
|
|
// cm centimeters
|
|
|
|
// mm millimeters
|
|
|
|
// pt points (1 point = 1/72 inch)
|
|
|
|
// pc picas (1 pica = 12 points)
|
|
|
|
// % percentage of default value"
|
|
|
|
//
|
|
|
|
// The numbers are defined that way:
|
|
|
|
// - unsigned-number: "a string of decimal digits with up to one decimal point
|
|
|
|
// (U+002E), representing a non-negative terminating decimal number (a type of
|
|
|
|
// rational number)"
|
|
|
|
// - number: "an optional prefix of '-' (U+002D), followed by an unsigned
|
|
|
|
// number, representing a terminating decimal number (a type of rational
|
|
|
|
// number)"
|
|
|
|
//
|
2019-02-25 22:05:29 +00:00
|
|
|
/* static */
|
2019-08-15 18:44:36 +00:00
|
|
|
// XXXfredw: Deprecate legacy MathML syntax and use the CSS parser instead.
|
|
|
|
// See https://github.com/mathml-refresh/mathml/issues/63
|
2019-09-13 16:27:54 +00:00
|
|
|
bool MathMLElement::ParseNumericValue(const nsString& aString,
|
|
|
|
nsCSSValue& aCSSValue, uint32_t aFlags,
|
|
|
|
Document* aDocument) {
|
2008-01-08 22:36:46 +00:00
|
|
|
nsAutoString str(aString);
|
|
|
|
str.CompressWhitespace(); // aString is const in this code...
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t stringLength = str.Length();
|
2012-12-27 16:12:05 +00:00
|
|
|
if (!stringLength) {
|
|
|
|
if (!(aFlags & PARSE_SUPPRESS_WARNINGS)) {
|
|
|
|
ReportLengthParseError(aString, aDocument);
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2012-12-27 16:12:05 +00:00
|
|
|
}
|
2008-01-08 22:36:46 +00:00
|
|
|
|
2019-08-22 06:29:26 +00:00
|
|
|
if (aDocument && ParseNamedSpaceValue(str, aCSSValue, aFlags, *aDocument)) {
|
2012-05-15 22:30:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-01-08 22:36:46 +00:00
|
|
|
nsAutoString number, unit;
|
|
|
|
|
|
|
|
// see if the negative sign is there
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t i = 0;
|
2014-01-04 15:02:17 +00:00
|
|
|
char16_t c = str[0];
|
2008-01-08 22:36:46 +00:00
|
|
|
if (c == '-') {
|
|
|
|
number.Append(c);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gather up characters that make up the number
|
2011-09-29 06:19:26 +00:00
|
|
|
bool gotDot = false;
|
2008-01-08 22:36:46 +00:00
|
|
|
for (; i < stringLength; i++) {
|
|
|
|
c = str[i];
|
2012-12-27 16:12:05 +00:00
|
|
|
if (gotDot && c == '.') {
|
|
|
|
if (!(aFlags & PARSE_SUPPRESS_WARNINGS)) {
|
|
|
|
ReportLengthParseError(aString, aDocument);
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return false; // two dots encountered
|
2008-01-08 22:36:46 +00:00
|
|
|
} else if (c == '.')
|
2011-10-17 14:59:28 +00:00
|
|
|
gotDot = true;
|
2018-04-13 03:19:30 +00:00
|
|
|
else if (!IsAsciiDigit(c)) {
|
2008-01-08 22:36:46 +00:00
|
|
|
str.Right(unit, stringLength - i);
|
|
|
|
// some authors leave blanks before the unit, but that shouldn't
|
|
|
|
// be allowed, so don't CompressWhitespace on 'unit'.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
number.Append(c);
|
|
|
|
}
|
2019-10-04 19:05:36 +00:00
|
|
|
if (StaticPrefs::mathml_legacy_number_syntax_disabled() && gotDot &&
|
|
|
|
str[i - 1] == '.') {
|
2019-08-21 23:49:36 +00:00
|
|
|
if (!(aFlags & PARSE_SUPPRESS_WARNINGS)) {
|
|
|
|
ReportLengthParseError(aString, aDocument);
|
|
|
|
}
|
2019-10-04 19:05:36 +00:00
|
|
|
return false; // Number ending with a dot.
|
2019-08-21 23:49:36 +00:00
|
|
|
}
|
2008-01-08 22:36:46 +00:00
|
|
|
|
|
|
|
// Convert number to floating point
|
2012-07-27 13:59:29 +00:00
|
|
|
nsresult errorCode;
|
2008-01-08 22:36:46 +00:00
|
|
|
float floatValue = number.ToFloat(&errorCode);
|
2012-12-27 16:12:05 +00:00
|
|
|
if (NS_FAILED(errorCode)) {
|
|
|
|
if (!(aFlags & PARSE_SUPPRESS_WARNINGS)) {
|
|
|
|
ReportLengthParseError(aString, aDocument);
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2012-12-27 16:12:05 +00:00
|
|
|
}
|
|
|
|
if (floatValue < 0 && !(aFlags & PARSE_ALLOW_NEGATIVE)) {
|
|
|
|
if (!(aFlags & PARSE_SUPPRESS_WARNINGS)) {
|
|
|
|
ReportLengthParseError(aString, aDocument);
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2012-12-27 16:12:05 +00:00
|
|
|
}
|
2008-01-08 22:36:46 +00:00
|
|
|
|
|
|
|
nsCSSUnit cssUnit;
|
|
|
|
if (unit.IsEmpty()) {
|
2019-08-19 17:10:58 +00:00
|
|
|
if (!StaticPrefs::mathml_nonzero_unitless_lengths_disabled() &&
|
|
|
|
(aFlags & PARSE_ALLOW_UNITLESS)) {
|
2008-02-07 04:09:03 +00:00
|
|
|
// no explicit unit, this is a number that will act as a multiplier
|
2012-12-27 16:12:05 +00:00
|
|
|
if (!(aFlags & PARSE_SUPPRESS_WARNINGS)) {
|
|
|
|
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
|
2013-08-21 19:28:26 +00:00
|
|
|
NS_LITERAL_CSTRING("MathML"), aDocument,
|
2012-12-27 16:12:05 +00:00
|
|
|
nsContentUtils::eMATHML_PROPERTIES,
|
|
|
|
"UnitlessValuesAreDeprecated");
|
|
|
|
}
|
2013-01-07 03:24:13 +00:00
|
|
|
if (aFlags & CONVERT_UNITLESS_TO_PERCENT) {
|
|
|
|
aCSSValue.SetPercentValue(floatValue);
|
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
cssUnit = eCSSUnit_Number;
|
2008-02-07 04:09:03 +00:00
|
|
|
} else {
|
|
|
|
// We are supposed to have a unit, but there isn't one.
|
2008-01-08 22:36:46 +00:00
|
|
|
// If the value is 0 we can just call it "pixels" otherwise
|
|
|
|
// this is illegal.
|
2012-12-27 16:12:05 +00:00
|
|
|
if (floatValue != 0.0) {
|
|
|
|
if (!(aFlags & PARSE_SUPPRESS_WARNINGS)) {
|
|
|
|
ReportLengthParseError(aString, aDocument);
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2012-12-27 16:12:05 +00:00
|
|
|
}
|
2008-01-08 22:36:46 +00:00
|
|
|
cssUnit = eCSSUnit_Pixel;
|
|
|
|
}
|
|
|
|
} else if (unit.EqualsLiteral("%")) {
|
|
|
|
aCSSValue.SetPercentValue(floatValue / 100.0f);
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2019-08-15 18:44:36 +00:00
|
|
|
} else if (unit.LowerCaseEqualsLiteral("em"))
|
2008-01-08 22:36:46 +00:00
|
|
|
cssUnit = eCSSUnit_EM;
|
2019-08-15 18:44:36 +00:00
|
|
|
else if (unit.LowerCaseEqualsLiteral("ex"))
|
2008-01-08 22:36:46 +00:00
|
|
|
cssUnit = eCSSUnit_XHeight;
|
2019-08-15 18:44:36 +00:00
|
|
|
else if (unit.LowerCaseEqualsLiteral("px"))
|
2008-01-08 22:36:46 +00:00
|
|
|
cssUnit = eCSSUnit_Pixel;
|
2019-08-15 18:44:36 +00:00
|
|
|
else if (unit.LowerCaseEqualsLiteral("in"))
|
2008-01-08 22:36:46 +00:00
|
|
|
cssUnit = eCSSUnit_Inch;
|
2019-08-15 18:44:36 +00:00
|
|
|
else if (unit.LowerCaseEqualsLiteral("cm"))
|
2008-01-08 22:36:46 +00:00
|
|
|
cssUnit = eCSSUnit_Centimeter;
|
2019-08-15 18:44:36 +00:00
|
|
|
else if (unit.LowerCaseEqualsLiteral("mm"))
|
2008-01-08 22:36:46 +00:00
|
|
|
cssUnit = eCSSUnit_Millimeter;
|
2019-08-15 18:44:36 +00:00
|
|
|
else if (unit.LowerCaseEqualsLiteral("pt"))
|
2008-01-08 22:36:46 +00:00
|
|
|
cssUnit = eCSSUnit_Point;
|
2019-08-15 18:44:36 +00:00
|
|
|
else if (unit.LowerCaseEqualsLiteral("pc"))
|
2008-01-08 22:36:46 +00:00
|
|
|
cssUnit = eCSSUnit_Pica;
|
2019-08-15 18:44:36 +00:00
|
|
|
else if (unit.LowerCaseEqualsLiteral("q"))
|
2016-05-23 07:18:34 +00:00
|
|
|
cssUnit = eCSSUnit_Quarter;
|
2012-12-27 16:12:05 +00:00
|
|
|
else { // unexpected unit
|
|
|
|
if (!(aFlags & PARSE_SUPPRESS_WARNINGS)) {
|
|
|
|
ReportLengthParseError(aString, aDocument);
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2012-12-27 16:12:05 +00:00
|
|
|
}
|
2008-01-08 22:36:46 +00:00
|
|
|
|
|
|
|
aCSSValue.SetFloatValue(floatValue, cssUnit);
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2008-01-08 22:36:46 +00:00
|
|
|
}
|
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
void MathMLElement::MapMathMLAttributesInto(
|
2008-01-08 22:36:46 +00:00
|
|
|
const nsMappedAttributes* aAttributes, MappedDeclarations& aDecls) {
|
2018-03-29 01:39:07 +00:00
|
|
|
// scriptsizemultiplier
|
|
|
|
//
|
|
|
|
// "Specifies the multiplier to be used to adjust font size due to changes
|
|
|
|
// in scriptlevel.
|
|
|
|
//
|
|
|
|
// values: number
|
|
|
|
// default: 0.71
|
|
|
|
//
|
|
|
|
const nsAttrValue* value =
|
|
|
|
aAttributes->GetAttr(nsGkAtoms::scriptsizemultiplier_);
|
|
|
|
if (value && value->Type() == nsAttrValue::eString &&
|
2018-06-22 16:48:42 +00:00
|
|
|
!aDecls.PropertyIsSet(eCSSProperty__moz_script_size_multiplier)) {
|
2018-03-29 01:39:07 +00:00
|
|
|
nsAutoString str(value->GetStringValue());
|
|
|
|
str.CompressWhitespace();
|
|
|
|
// MathML numbers can't have leading '+'
|
|
|
|
if (str.Length() > 0 && str.CharAt(0) != '+') {
|
|
|
|
nsresult errorCode;
|
|
|
|
float floatValue = str.ToFloat(&errorCode);
|
|
|
|
// Negative scriptsizemultipliers are not parsed
|
|
|
|
if (NS_SUCCEEDED(errorCode) && floatValue >= 0.0f) {
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetNumberValue(eCSSProperty__moz_script_size_multiplier,
|
|
|
|
floatValue);
|
2018-03-29 01:39:07 +00:00
|
|
|
} else {
|
|
|
|
ReportParseErrorNoTag(str, nsGkAtoms::scriptsizemultiplier_,
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.Document());
|
2008-01-08 22:36:46 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-29 01:39:07 +00:00
|
|
|
}
|
2008-01-08 22:36:46 +00:00
|
|
|
|
2018-03-29 01:39:07 +00:00
|
|
|
// scriptminsize
|
|
|
|
//
|
|
|
|
// "Specifies the minimum font size allowed due to changes in scriptlevel.
|
|
|
|
// Note that this does not limit the font size due to changes to mathsize."
|
|
|
|
//
|
|
|
|
// values: length
|
|
|
|
// default: 8pt
|
|
|
|
//
|
|
|
|
// We don't allow negative values.
|
|
|
|
// Unitless and percent values give a multiple of the default value.
|
|
|
|
//
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::scriptminsize_);
|
|
|
|
if (value && value->Type() == nsAttrValue::eString &&
|
2018-06-22 16:48:42 +00:00
|
|
|
!aDecls.PropertyIsSet(eCSSProperty__moz_script_min_size)) {
|
2018-03-29 01:39:07 +00:00
|
|
|
nsCSSValue scriptMinSize;
|
|
|
|
ParseNumericValue(value->GetStringValue(), scriptMinSize,
|
|
|
|
PARSE_ALLOW_UNITLESS | CONVERT_UNITLESS_TO_PERCENT,
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.Document());
|
2018-03-29 01:39:07 +00:00
|
|
|
|
|
|
|
if (scriptMinSize.GetUnit() == eCSSUnit_Percent) {
|
|
|
|
scriptMinSize.SetFloatValue(8.0 * scriptMinSize.GetPercentValue(),
|
|
|
|
eCSSUnit_Point);
|
2008-01-08 22:36:46 +00:00
|
|
|
}
|
2018-03-29 01:39:07 +00:00
|
|
|
if (scriptMinSize.GetUnit() != eCSSUnit_Null) {
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetLengthValue(eCSSProperty__moz_script_min_size, scriptMinSize);
|
2008-01-08 22:36:46 +00:00
|
|
|
}
|
2018-03-29 01:39:07 +00:00
|
|
|
}
|
2008-01-08 22:36:46 +00:00
|
|
|
|
2018-03-29 01:39:07 +00:00
|
|
|
// scriptlevel
|
|
|
|
//
|
|
|
|
// "Changes the scriptlevel in effect for the children. When the value is
|
|
|
|
// given without a sign, it sets scriptlevel to the specified value; when a
|
|
|
|
// sign is given, it increments ("+") or decrements ("-") the current
|
|
|
|
// value. (Note that large decrements can result in negative values of
|
|
|
|
// scriptlevel, but these values are considered legal.)"
|
|
|
|
//
|
|
|
|
// values: ( "+" | "-" )? unsigned-integer
|
|
|
|
// default: inherited
|
|
|
|
//
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::scriptlevel_);
|
|
|
|
if (value && value->Type() == nsAttrValue::eString &&
|
2018-06-22 16:48:42 +00:00
|
|
|
!aDecls.PropertyIsSet(eCSSProperty__moz_script_level)) {
|
2018-03-29 01:39:07 +00:00
|
|
|
nsAutoString str(value->GetStringValue());
|
|
|
|
str.CompressWhitespace();
|
|
|
|
if (str.Length() > 0) {
|
|
|
|
nsresult errorCode;
|
|
|
|
int32_t intValue = str.ToInteger(&errorCode);
|
|
|
|
if (NS_SUCCEEDED(errorCode)) {
|
|
|
|
// This is kind of cheesy ... if the scriptlevel has a sign,
|
|
|
|
// then it's a relative value and we store the nsCSSValue as an
|
|
|
|
// Integer to indicate that. Otherwise we store it as a Number
|
|
|
|
// to indicate that the scriptlevel is absolute.
|
|
|
|
char16_t ch = str.CharAt(0);
|
|
|
|
if (ch == '+' || ch == '-') {
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetIntValue(eCSSProperty__moz_script_level, intValue);
|
2018-03-29 01:39:07 +00:00
|
|
|
} else {
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetNumberValue(eCSSProperty__moz_script_level, intValue);
|
2008-01-08 22:36:46 +00:00
|
|
|
}
|
2018-03-29 01:39:07 +00:00
|
|
|
} else {
|
|
|
|
ReportParseErrorNoTag(str, nsGkAtoms::scriptlevel_, aDecls.Document());
|
2008-01-08 22:36:46 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-29 01:39:07 +00:00
|
|
|
}
|
2008-01-08 22:36:46 +00:00
|
|
|
|
2018-03-29 01:39:07 +00:00
|
|
|
// mathsize
|
|
|
|
//
|
|
|
|
// "Specifies the size to display the token content. The values 'small' and
|
|
|
|
// 'big' choose a size smaller or larger than the current font size, but
|
|
|
|
// leave the exact proportions unspecified; 'normal' is allowed for
|
|
|
|
// completeness, but since it is equivalent to '100%' or '1em', it has no
|
|
|
|
// effect."
|
|
|
|
//
|
|
|
|
// values: "small" | "normal" | "big" | length
|
|
|
|
// default: inherited
|
|
|
|
//
|
|
|
|
// fontsize
|
|
|
|
//
|
|
|
|
// "Specified the size for the token. Deprecated in favor of mathsize."
|
|
|
|
//
|
|
|
|
// values: length
|
|
|
|
// default: inherited
|
|
|
|
//
|
|
|
|
// In both cases, we don't allow negative values.
|
|
|
|
// Unitless values give a multiple of the default value.
|
|
|
|
//
|
2019-08-19 18:28:03 +00:00
|
|
|
bool parseSizeKeywords = !StaticPrefs::mathml_mathsize_names_disabled();
|
2018-03-29 01:39:07 +00:00
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::mathsize_);
|
|
|
|
if (!value) {
|
|
|
|
parseSizeKeywords = false;
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::fontsize_);
|
2012-12-27 16:12:05 +00:00
|
|
|
if (value) {
|
2019-08-28 14:59:55 +00:00
|
|
|
aDecls.Document()->WarnOnceAbout(
|
|
|
|
dom::Document::eMathML_DeprecatedStyleAttribute);
|
2012-12-27 16:12:05 +00:00
|
|
|
}
|
2018-03-29 01:39:07 +00:00
|
|
|
}
|
|
|
|
if (value && value->Type() == nsAttrValue::eString &&
|
2018-06-22 16:48:42 +00:00
|
|
|
!aDecls.PropertyIsSet(eCSSProperty_font_size)) {
|
2018-03-29 01:39:07 +00:00
|
|
|
nsAutoString str(value->GetStringValue());
|
|
|
|
nsCSSValue fontSize;
|
2019-08-19 18:28:03 +00:00
|
|
|
uint32_t flags = PARSE_ALLOW_UNITLESS | CONVERT_UNITLESS_TO_PERCENT;
|
|
|
|
if (parseSizeKeywords) {
|
|
|
|
// Do not warn for invalid value if mathsize keywords are accepted.
|
|
|
|
flags |= PARSE_SUPPRESS_WARNINGS;
|
|
|
|
}
|
|
|
|
if (!ParseNumericValue(str, fontSize, flags, nullptr) &&
|
2018-03-29 01:39:07 +00:00
|
|
|
parseSizeKeywords) {
|
|
|
|
static const char sizes[3][7] = {"small", "normal", "big"};
|
|
|
|
static const int32_t values[MOZ_ARRAY_LENGTH(sizes)] = {
|
|
|
|
NS_STYLE_FONT_SIZE_SMALL, NS_STYLE_FONT_SIZE_MEDIUM,
|
|
|
|
NS_STYLE_FONT_SIZE_LARGE};
|
|
|
|
str.CompressWhitespace();
|
|
|
|
for (uint32_t i = 0; i < ArrayLength(sizes); ++i) {
|
|
|
|
if (str.EqualsASCII(sizes[i])) {
|
2019-08-22 06:29:26 +00:00
|
|
|
aDecls.Document()->WarnOnceAbout(
|
|
|
|
dom::Document::eMathML_DeprecatedMathSizeValue);
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetKeywordValue(eCSSProperty_font_size, values[i]);
|
2018-03-29 01:39:07 +00:00
|
|
|
break;
|
2013-12-02 16:49:54 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-29 01:39:07 +00:00
|
|
|
} else if (fontSize.GetUnit() == eCSSUnit_Percent) {
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetPercentValue(eCSSProperty_font_size,
|
2018-03-29 01:39:07 +00:00
|
|
|
fontSize.GetPercentValue());
|
|
|
|
} else if (fontSize.GetUnit() != eCSSUnit_Null) {
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetLengthValue(eCSSProperty_font_size, fontSize);
|
2013-12-02 16:49:54 +00:00
|
|
|
}
|
2018-03-29 01:39:07 +00:00
|
|
|
}
|
2013-12-02 16:49:54 +00:00
|
|
|
|
2018-03-29 01:39:07 +00:00
|
|
|
// fontfamily
|
|
|
|
//
|
|
|
|
// "Should be the name of a font that may be available to a MathML renderer,
|
|
|
|
// or a CSS font specification; See Section 6.5 Using CSS with MathML and
|
|
|
|
// CSS for more information. Deprecated in favor of mathvariant."
|
|
|
|
//
|
|
|
|
// values: string
|
|
|
|
//
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::fontfamily_);
|
|
|
|
if (value) {
|
2019-08-28 14:59:55 +00:00
|
|
|
aDecls.Document()->WarnOnceAbout(
|
|
|
|
dom::Document::eMathML_DeprecatedStyleAttribute);
|
2018-03-29 01:39:07 +00:00
|
|
|
}
|
|
|
|
if (value && value->Type() == nsAttrValue::eString &&
|
2018-06-22 16:48:42 +00:00
|
|
|
!aDecls.PropertyIsSet(eCSSProperty_font_family)) {
|
|
|
|
aDecls.SetFontFamily(value->GetStringValue());
|
2018-03-29 01:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// fontstyle
|
|
|
|
//
|
|
|
|
// "Specified the font style to use for the token. Deprecated in favor of
|
|
|
|
// mathvariant."
|
|
|
|
//
|
|
|
|
// values: "normal" | "italic"
|
|
|
|
// default: normal (except on <mi>)
|
|
|
|
//
|
|
|
|
// Note that the font-style property is reset in layout/style/ when
|
|
|
|
// -moz-math-variant is specified.
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::fontstyle_);
|
|
|
|
if (value) {
|
2019-08-28 14:59:55 +00:00
|
|
|
aDecls.Document()->WarnOnceAbout(
|
|
|
|
dom::Document::eMathML_DeprecatedStyleAttribute);
|
2018-03-29 01:39:07 +00:00
|
|
|
if (value->Type() == nsAttrValue::eString &&
|
2018-06-22 16:48:42 +00:00
|
|
|
!aDecls.PropertyIsSet(eCSSProperty_font_style)) {
|
2018-03-29 01:39:07 +00:00
|
|
|
nsAutoString str(value->GetStringValue());
|
|
|
|
str.CompressWhitespace();
|
2018-04-23 14:52:20 +00:00
|
|
|
// FIXME(emilio): This should use FontSlantStyle or what not. Or even
|
|
|
|
// better, it looks deprecated since forever, we should just kill it.
|
2018-03-29 01:39:07 +00:00
|
|
|
if (str.EqualsASCII("normal")) {
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetKeywordValue(eCSSProperty_font_style, NS_FONT_STYLE_NORMAL);
|
2018-03-29 01:39:07 +00:00
|
|
|
} else if (str.EqualsASCII("italic")) {
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetKeywordValue(eCSSProperty_font_style, NS_FONT_STYLE_ITALIC);
|
2013-12-02 16:49:54 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-29 01:39:07 +00:00
|
|
|
}
|
2013-12-02 16:49:54 +00:00
|
|
|
|
2018-03-29 01:39:07 +00:00
|
|
|
// fontweight
|
|
|
|
//
|
|
|
|
// "Specified the font weight for the token. Deprecated in favor of
|
|
|
|
// mathvariant."
|
|
|
|
//
|
|
|
|
// values: "normal" | "bold"
|
|
|
|
// default: normal
|
|
|
|
//
|
|
|
|
// Note that the font-weight property is reset in layout/style/ when
|
|
|
|
// -moz-math-variant is specified.
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::fontweight_);
|
|
|
|
if (value) {
|
2019-08-28 14:59:55 +00:00
|
|
|
aDecls.Document()->WarnOnceAbout(
|
|
|
|
dom::Document::eMathML_DeprecatedStyleAttribute);
|
2018-03-29 01:39:07 +00:00
|
|
|
if (value->Type() == nsAttrValue::eString &&
|
2018-06-22 16:48:42 +00:00
|
|
|
!aDecls.PropertyIsSet(eCSSProperty_font_weight)) {
|
2013-12-02 16:49:54 +00:00
|
|
|
nsAutoString str(value->GetStringValue());
|
|
|
|
str.CompressWhitespace();
|
2018-03-29 01:39:07 +00:00
|
|
|
if (str.EqualsASCII("normal")) {
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetKeywordValue(eCSSProperty_font_weight,
|
2018-04-13 19:34:37 +00:00
|
|
|
FontWeight::Normal().ToFloat());
|
2018-03-29 01:39:07 +00:00
|
|
|
} else if (str.EqualsASCII("bold")) {
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetKeywordValue(eCSSProperty_font_weight,
|
2018-04-13 19:34:37 +00:00
|
|
|
FontWeight::Bold().ToFloat());
|
2018-03-29 01:39:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// mathvariant
|
|
|
|
//
|
|
|
|
// "Specifies the logical class of the token. Note that this class is more
|
|
|
|
// than styling, it typically conveys semantic intent;"
|
|
|
|
//
|
|
|
|
// values: "normal" | "bold" | "italic" | "bold-italic" | "double-struck" |
|
|
|
|
// "bold-fraktur" | "script" | "bold-script" | "fraktur" | "sans-serif" |
|
|
|
|
// "bold-sans-serif" | "sans-serif-italic" | "sans-serif-bold-italic" |
|
|
|
|
// "monospace" | "initial" | "tailed" | "looped" | "stretched"
|
|
|
|
// default: normal (except on <mi>)
|
|
|
|
//
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::mathvariant_);
|
|
|
|
if (value && value->Type() == nsAttrValue::eString &&
|
2018-06-22 16:48:42 +00:00
|
|
|
!aDecls.PropertyIsSet(eCSSProperty__moz_math_variant)) {
|
2018-03-29 01:39:07 +00:00
|
|
|
nsAutoString str(value->GetStringValue());
|
|
|
|
str.CompressWhitespace();
|
|
|
|
static const char sizes[19][23] = {"normal",
|
|
|
|
"bold",
|
|
|
|
"italic",
|
|
|
|
"bold-italic",
|
|
|
|
"script",
|
|
|
|
"bold-script",
|
|
|
|
"fraktur",
|
|
|
|
"double-struck",
|
|
|
|
"bold-fraktur",
|
|
|
|
"sans-serif",
|
|
|
|
"bold-sans-serif",
|
|
|
|
"sans-serif-italic",
|
|
|
|
"sans-serif-bold-italic",
|
|
|
|
"monospace",
|
|
|
|
"initial",
|
|
|
|
"tailed",
|
|
|
|
"looped",
|
|
|
|
"stretched"};
|
|
|
|
static const int32_t values[MOZ_ARRAY_LENGTH(sizes)] = {
|
|
|
|
NS_MATHML_MATHVARIANT_NORMAL,
|
|
|
|
NS_MATHML_MATHVARIANT_BOLD,
|
|
|
|
NS_MATHML_MATHVARIANT_ITALIC,
|
|
|
|
NS_MATHML_MATHVARIANT_BOLD_ITALIC,
|
|
|
|
NS_MATHML_MATHVARIANT_SCRIPT,
|
|
|
|
NS_MATHML_MATHVARIANT_BOLD_SCRIPT,
|
|
|
|
NS_MATHML_MATHVARIANT_FRAKTUR,
|
|
|
|
NS_MATHML_MATHVARIANT_DOUBLE_STRUCK,
|
|
|
|
NS_MATHML_MATHVARIANT_BOLD_FRAKTUR,
|
|
|
|
NS_MATHML_MATHVARIANT_SANS_SERIF,
|
|
|
|
NS_MATHML_MATHVARIANT_BOLD_SANS_SERIF,
|
|
|
|
NS_MATHML_MATHVARIANT_SANS_SERIF_ITALIC,
|
|
|
|
NS_MATHML_MATHVARIANT_SANS_SERIF_BOLD_ITALIC,
|
|
|
|
NS_MATHML_MATHVARIANT_MONOSPACE,
|
|
|
|
NS_MATHML_MATHVARIANT_INITIAL,
|
|
|
|
NS_MATHML_MATHVARIANT_TAILED,
|
|
|
|
NS_MATHML_MATHVARIANT_LOOPED,
|
|
|
|
NS_MATHML_MATHVARIANT_STRETCHED};
|
|
|
|
for (uint32_t i = 0; i < ArrayLength(sizes); ++i) {
|
2019-08-15 18:44:36 +00:00
|
|
|
if (str.LowerCaseEqualsASCII(sizes[i])) {
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetKeywordValue(eCSSProperty__moz_math_variant, values[i]);
|
2018-03-29 01:39:07 +00:00
|
|
|
break;
|
2013-12-02 16:49:54 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-08 22:36:46 +00:00
|
|
|
}
|
|
|
|
|
2012-05-15 22:30:14 +00:00
|
|
|
// mathbackground
|
2017-07-06 12:00:35 +00:00
|
|
|
//
|
2012-05-15 22:30:14 +00:00
|
|
|
// "Specifies the background color to be used to fill in the bounding box of
|
|
|
|
// the element and its children. The default, 'transparent', lets the
|
|
|
|
// background color, if any, used in the current rendering context to show
|
|
|
|
// through."
|
2017-07-06 12:00:35 +00:00
|
|
|
//
|
|
|
|
// values: color | "transparent"
|
2012-05-15 22:30:14 +00:00
|
|
|
// default: "transparent"
|
|
|
|
//
|
|
|
|
// background
|
|
|
|
//
|
|
|
|
// "Specified the background color to be used to fill in the bounding box of
|
|
|
|
// the element and its children. Deprecated in favor of mathbackground."
|
|
|
|
//
|
|
|
|
// values: color | "transparent"
|
|
|
|
// default: "transparent"
|
|
|
|
//
|
2018-03-29 01:39:07 +00:00
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::mathbackground_);
|
|
|
|
if (!value) {
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::background);
|
2017-04-10 07:28:48 +00:00
|
|
|
if (value) {
|
2019-08-28 14:59:55 +00:00
|
|
|
aDecls.Document()->WarnOnceAbout(
|
|
|
|
dom::Document::eMathML_DeprecatedStyleAttribute);
|
2018-03-29 01:39:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (value) {
|
|
|
|
nscolor color;
|
|
|
|
if (value->GetColorValue(color)) {
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetColorValueIfUnset(eCSSProperty_background_color, color);
|
2008-01-08 22:36:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-15 22:30:14 +00:00
|
|
|
// mathcolor
|
|
|
|
//
|
|
|
|
// "Specifies the foreground color to use when drawing the components of this
|
|
|
|
// element, such as the content for token elements or any lines, surds, or
|
|
|
|
// other decorations. It also establishes the default mathcolor used for
|
|
|
|
// child elements when used on a layout element."
|
|
|
|
//
|
|
|
|
// values: color
|
|
|
|
// default: inherited
|
|
|
|
//
|
|
|
|
// color
|
2017-07-06 12:00:35 +00:00
|
|
|
//
|
|
|
|
// "Specified the color for the token. Deprecated in favor of mathcolor."
|
2012-05-15 22:30:14 +00:00
|
|
|
//
|
|
|
|
// values: color
|
|
|
|
// default: inherited
|
|
|
|
//
|
2018-03-29 01:39:07 +00:00
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::mathcolor_);
|
|
|
|
if (!value) {
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::color);
|
|
|
|
if (value) {
|
2019-08-28 14:59:55 +00:00
|
|
|
aDecls.Document()->WarnOnceAbout(
|
|
|
|
dom::Document::eMathML_DeprecatedStyleAttribute);
|
2008-01-08 22:36:46 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-29 01:39:07 +00:00
|
|
|
nscolor color;
|
|
|
|
if (value && value->GetColorValue(color)) {
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetColorValueIfUnset(eCSSProperty_color, color);
|
2018-03-29 01:39:07 +00:00
|
|
|
}
|
2012-02-27 23:57:28 +00:00
|
|
|
|
2018-03-29 01:39:07 +00:00
|
|
|
// width
|
|
|
|
//
|
|
|
|
// "Specifies the desired width of the entire table and is intended for
|
|
|
|
// visual user agents. When the value is a percentage value, the value is
|
|
|
|
// relative to the horizontal space a MathML renderer has available for the
|
|
|
|
// math element. When the value is "auto", the MathML renderer should
|
|
|
|
// calculate the table width from its contents using whatever layout
|
|
|
|
// algorithm it chooses. "
|
|
|
|
//
|
|
|
|
// values: "auto" | length
|
|
|
|
// default: auto
|
|
|
|
//
|
2018-06-22 16:48:42 +00:00
|
|
|
if (!aDecls.PropertyIsSet(eCSSProperty_width)) {
|
2018-03-29 01:39:07 +00:00
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::width);
|
|
|
|
nsCSSValue width;
|
|
|
|
// This does not handle auto and unitless values
|
|
|
|
if (value && value->Type() == nsAttrValue::eString) {
|
2018-06-22 16:48:42 +00:00
|
|
|
ParseNumericValue(value->GetStringValue(), width, 0, aDecls.Document());
|
2018-03-29 01:39:07 +00:00
|
|
|
if (width.GetUnit() == eCSSUnit_Percent) {
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetPercentValue(eCSSProperty_width, width.GetPercentValue());
|
2018-03-29 01:39:07 +00:00
|
|
|
} else if (width.GetUnit() != eCSSUnit_Null) {
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetLengthValue(eCSSProperty_width, width);
|
2012-02-27 23:57:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-29 23:26:40 +00:00
|
|
|
// dir
|
|
|
|
//
|
|
|
|
// Overall Directionality of Mathematics Formulas:
|
|
|
|
// "The overall directionality for a formula, basically the direction of the
|
|
|
|
// Layout Schemata, is specified by the dir attribute on the containing math
|
|
|
|
// element (see Section 2.2 The Top-Level math Element). The default is ltr.
|
2017-07-06 12:00:35 +00:00
|
|
|
// [...] The overall directionality is usually set on the math, but may also
|
2013-05-29 23:26:40 +00:00
|
|
|
// be switched for individual subformula by using the dir attribute on mrow
|
2017-07-06 12:00:35 +00:00
|
|
|
// or mstyle elements."
|
2013-05-29 23:26:40 +00:00
|
|
|
//
|
|
|
|
// Bidirectional Layout in Token Elements:
|
|
|
|
// "Specifies the initial directionality for text within the token:
|
|
|
|
// ltr (Left To Right) or rtl (Right To Left). This attribute should only be
|
|
|
|
// needed in rare cases involving weak or neutral characters;
|
|
|
|
// see Section 3.1.5.1 Overall Directionality of Mathematics Formulas for
|
|
|
|
// further discussion. It has no effect on mspace."
|
|
|
|
//
|
|
|
|
// values: "ltr" | "rtl"
|
|
|
|
// default: inherited
|
|
|
|
//
|
2018-03-29 01:39:07 +00:00
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::dir);
|
|
|
|
if (value && value->Type() == nsAttrValue::eString &&
|
2018-06-22 16:48:42 +00:00
|
|
|
!aDecls.PropertyIsSet(eCSSProperty_direction)) {
|
2018-03-29 01:39:07 +00:00
|
|
|
nsAutoString str(value->GetStringValue());
|
|
|
|
static const char dirs[][4] = {"ltr", "rtl"};
|
|
|
|
static const int32_t dirValues[MOZ_ARRAY_LENGTH(dirs)] = {
|
|
|
|
NS_STYLE_DIRECTION_LTR, NS_STYLE_DIRECTION_RTL};
|
|
|
|
for (uint32_t i = 0; i < ArrayLength(dirs); ++i) {
|
2019-08-15 18:44:36 +00:00
|
|
|
if (str.LowerCaseEqualsASCII(dirs[i])) {
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetKeywordValue(eCSSProperty_direction, dirValues[i]);
|
2018-03-29 01:39:07 +00:00
|
|
|
break;
|
2013-05-29 23:26:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-01-08 22:36:46 +00:00
|
|
|
}
|
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
void MathMLElement::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
|
2018-04-05 17:42:41 +00:00
|
|
|
Element::GetEventTargetParent(aVisitor);
|
2011-06-24 12:54:28 +00:00
|
|
|
|
2018-04-05 17:42:41 +00:00
|
|
|
GetEventTargetParentForLinks(aVisitor);
|
2011-06-24 12:54:28 +00:00
|
|
|
}
|
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
nsresult MathMLElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
|
2011-06-24 12:54:28 +00:00
|
|
|
return PostHandleEventForLinks(aVisitor);
|
|
|
|
}
|
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
NS_IMPL_ELEMENT_CLONE(MathMLElement)
|
2008-01-08 22:36:46 +00:00
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
EventStates MathMLElement::IntrinsicState() const {
|
|
|
|
return Link::LinkState() | MathMLElementBase::IntrinsicState() |
|
2014-04-03 04:18:36 +00:00
|
|
|
(mIncrementScriptLevel ? NS_EVENT_STATE_INCREMENT_SCRIPT_LEVEL
|
|
|
|
: EventStates());
|
2008-01-08 22:36:46 +00:00
|
|
|
}
|
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
bool MathMLElement::IsNodeOfType(uint32_t aFlags) const { return false; }
|
2008-01-08 22:36:46 +00:00
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
void MathMLElement::SetIncrementScriptLevel(bool aIncrementScriptLevel,
|
|
|
|
bool aNotify) {
|
2008-01-08 22:36:46 +00:00
|
|
|
if (aIncrementScriptLevel == mIncrementScriptLevel) return;
|
|
|
|
mIncrementScriptLevel = aIncrementScriptLevel;
|
|
|
|
|
|
|
|
NS_ASSERTION(aNotify, "We always notify!");
|
|
|
|
|
2011-06-01 01:46:57 +00:00
|
|
|
UpdateState(true);
|
2008-01-08 22:36:46 +00:00
|
|
|
}
|
2011-06-24 12:54:28 +00:00
|
|
|
|
2019-10-04 19:05:36 +00:00
|
|
|
int32_t MathMLElement::TabIndexDefault() {
|
2019-10-04 08:45:04 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2019-10-04 19:05:36 +00:00
|
|
|
return IsLink(getter_AddRefs(uri)) ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX Bug 1586011: Share logic with other element classes.
|
|
|
|
bool MathMLElement::IsFocusableInternal(int32_t* aTabIndex, bool aWithMouse) {
|
|
|
|
Document* doc = GetComposedDoc();
|
|
|
|
if (!doc || doc->HasFlag(NODE_IS_EDITABLE)) {
|
|
|
|
// In designMode documents we only allow focusing the document.
|
2019-10-04 08:45:04 +00:00
|
|
|
if (aTabIndex) {
|
2019-10-04 19:05:36 +00:00
|
|
|
*aTabIndex = -1;
|
2019-10-04 08:45:04 +00:00
|
|
|
}
|
2019-10-04 19:05:36 +00:00
|
|
|
return false;
|
2019-10-04 08:45:04 +00:00
|
|
|
}
|
|
|
|
|
2019-10-04 19:05:36 +00:00
|
|
|
int32_t tabIndex = TabIndex();
|
2019-10-04 14:16:38 +00:00
|
|
|
if (aTabIndex) {
|
2019-10-04 19:05:36 +00:00
|
|
|
*aTabIndex = tabIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
if (!IsLink(getter_AddRefs(uri))) {
|
|
|
|
// If a tabindex is specified at all we're focusable
|
|
|
|
return HasAttr(nsGkAtoms::tabindex);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!OwnerDoc()->LinkHandlingEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Links that are in an editable region should never be focusable, even if
|
|
|
|
// they are in a contenteditable="false" region.
|
|
|
|
if (nsContentUtils::IsNodeInEditableRegion(this)) {
|
|
|
|
if (aTabIndex) {
|
|
|
|
*aTabIndex = -1;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aTabIndex && (sTabFocusModel & eTabFocus_linksMask) == 0) {
|
2011-06-24 12:54:28 +00:00
|
|
|
*aTabIndex = -1;
|
|
|
|
}
|
|
|
|
|
2019-10-04 19:05:36 +00:00
|
|
|
return true;
|
2011-06-24 12:54:28 +00:00
|
|
|
}
|
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
bool MathMLElement::IsLink(nsIURI** aURI) const {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool hasHref = false;
|
2018-08-07 19:07:26 +00:00
|
|
|
const nsAttrValue* href = mAttrs.GetAttr(nsGkAtoms::href, kNameSpaceID_None);
|
2011-06-24 12:54:28 +00:00
|
|
|
if (href) {
|
|
|
|
// MathML href
|
|
|
|
// The REC says: "When user agents encounter MathML elements with both href
|
|
|
|
// and xlink:href attributes, the href attribute should take precedence."
|
2011-10-17 14:59:28 +00:00
|
|
|
hasHref = true;
|
2019-10-05 21:47:38 +00:00
|
|
|
} else if (!StaticPrefs::mathml_xlink_disabled()) {
|
2011-06-24 12:54:28 +00:00
|
|
|
// To be a clickable XLink for styling and interaction purposes, we require:
|
|
|
|
//
|
|
|
|
// xlink:href - must be set
|
|
|
|
// xlink:type - must be unset or set to "" or set to "simple"
|
|
|
|
// xlink:show - must be unset or set to "", "new" or "replace"
|
|
|
|
// xlink:actuate - must be unset or set to "" or "onRequest"
|
|
|
|
//
|
|
|
|
// For any other values, we're either not a *clickable* XLink, or the end
|
2011-10-17 14:59:28 +00:00
|
|
|
// result is poorly specified. Either way, we return false.
|
2017-07-06 12:00:35 +00:00
|
|
|
|
2017-12-07 18:13:50 +00:00
|
|
|
static Element::AttrValuesArray sTypeVals[] = {nsGkAtoms::_empty,
|
2018-04-03 03:21:06 +00:00
|
|
|
nsGkAtoms::simple, nullptr};
|
2017-07-06 12:00:35 +00:00
|
|
|
|
2017-12-07 18:13:50 +00:00
|
|
|
static Element::AttrValuesArray sShowVals[] = {
|
2018-04-03 03:21:06 +00:00
|
|
|
nsGkAtoms::_empty, nsGkAtoms::_new, nsGkAtoms::replace, nullptr};
|
2017-07-06 12:00:35 +00:00
|
|
|
|
2017-12-07 18:13:50 +00:00
|
|
|
static Element::AttrValuesArray sActuateVals[] = {
|
2018-04-03 03:21:06 +00:00
|
|
|
nsGkAtoms::_empty, nsGkAtoms::onRequest, nullptr};
|
2017-07-06 12:00:35 +00:00
|
|
|
|
2011-06-24 12:54:28 +00:00
|
|
|
// Optimization: check for href first for early return
|
2018-08-07 19:07:26 +00:00
|
|
|
href = mAttrs.GetAttr(nsGkAtoms::href, kNameSpaceID_XLink);
|
2011-06-24 12:54:28 +00:00
|
|
|
if (href &&
|
|
|
|
FindAttrValueIn(kNameSpaceID_XLink, nsGkAtoms::type, sTypeVals,
|
2017-12-07 18:13:50 +00:00
|
|
|
eCaseMatters) != Element::ATTR_VALUE_NO_MATCH &&
|
2011-06-24 12:54:28 +00:00
|
|
|
FindAttrValueIn(kNameSpaceID_XLink, nsGkAtoms::show, sShowVals,
|
2017-12-07 18:13:50 +00:00
|
|
|
eCaseMatters) != Element::ATTR_VALUE_NO_MATCH &&
|
2011-06-24 12:54:28 +00:00
|
|
|
FindAttrValueIn(kNameSpaceID_XLink, nsGkAtoms::actuate, sActuateVals,
|
2017-12-07 18:13:50 +00:00
|
|
|
eCaseMatters) != Element::ATTR_VALUE_NO_MATCH) {
|
2019-10-05 21:47:38 +00:00
|
|
|
OwnerDoc()->WarnOnceAbout(
|
|
|
|
dom::Document::eMathML_DeprecatedXLinkAttribute);
|
2011-10-17 14:59:28 +00:00
|
|
|
hasHref = true;
|
2011-06-24 12:54:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasHref) {
|
|
|
|
// Get absolute URI
|
|
|
|
nsAutoString hrefStr;
|
2017-07-06 12:00:35 +00:00
|
|
|
href->ToString(hrefStr);
|
2011-06-24 12:54:28 +00:00
|
|
|
nsContentUtils::NewURIWithDocumentCharset(aURI, hrefStr, OwnerDoc(),
|
2019-07-15 18:29:05 +00:00
|
|
|
GetBaseURI());
|
2011-06-24 12:54:28 +00:00
|
|
|
// must promise out param is non-null if we return true
|
|
|
|
return !!*aURI;
|
|
|
|
}
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
*aURI = nullptr;
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2011-06-24 12:54:28 +00:00
|
|
|
}
|
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
void MathMLElement::GetLinkTarget(nsAString& aTarget) {
|
2019-10-05 21:47:38 +00:00
|
|
|
if (StaticPrefs::mathml_xlink_disabled()) {
|
|
|
|
MathMLElementBase::GetLinkTarget(aTarget);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-07 19:07:26 +00:00
|
|
|
const nsAttrValue* target =
|
|
|
|
mAttrs.GetAttr(nsGkAtoms::target, kNameSpaceID_XLink);
|
2011-06-24 12:54:28 +00:00
|
|
|
if (target) {
|
2019-10-05 21:47:38 +00:00
|
|
|
OwnerDoc()->WarnOnceAbout(dom::Document::eMathML_DeprecatedXLinkAttribute);
|
2011-06-24 12:54:28 +00:00
|
|
|
target->ToString(aTarget);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aTarget.IsEmpty()) {
|
2017-12-07 18:13:50 +00:00
|
|
|
static Element::AttrValuesArray sShowVals[] = {nsGkAtoms::_new,
|
2018-04-03 03:21:06 +00:00
|
|
|
nsGkAtoms::replace, nullptr};
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2019-10-05 21:47:38 +00:00
|
|
|
bool hasDeprecatedShowAttribute = true;
|
2011-06-24 12:54:28 +00:00
|
|
|
switch (FindAttrValueIn(kNameSpaceID_XLink, nsGkAtoms::show, sShowVals,
|
|
|
|
eCaseMatters)) {
|
2019-10-05 21:47:38 +00:00
|
|
|
case ATTR_MISSING:
|
|
|
|
hasDeprecatedShowAttribute = false;
|
|
|
|
break;
|
2011-06-24 12:54:28 +00:00
|
|
|
case 0:
|
|
|
|
aTarget.AssignLiteral("_blank");
|
|
|
|
return;
|
|
|
|
case 1:
|
|
|
|
return;
|
|
|
|
}
|
2019-10-05 21:47:38 +00:00
|
|
|
if (hasDeprecatedShowAttribute) {
|
|
|
|
OwnerDoc()->WarnOnceAbout(
|
|
|
|
dom::Document::eMathML_DeprecatedXLinkAttribute);
|
|
|
|
}
|
2011-10-18 11:19:44 +00:00
|
|
|
OwnerDoc()->GetBaseTarget(aTarget);
|
2011-06-24 12:54:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
already_AddRefed<nsIURI> MathMLElement::GetHrefURI() const {
|
2011-06-24 12:54:28 +00:00
|
|
|
nsCOMPtr<nsIURI> hrefURI;
|
2012-07-30 14:20:58 +00:00
|
|
|
return IsLink(getter_AddRefs(hrefURI)) ? hrefURI.forget() : nullptr;
|
2011-06-24 12:54:28 +00:00
|
|
|
}
|
|
|
|
|
2019-10-04 19:05:36 +00:00
|
|
|
// XXX Bug 1586014: Share logic with other element classes.
|
|
|
|
void MathMLElement::RecompileScriptEventListeners() {
|
|
|
|
int32_t i, count = mAttrs.AttrCount();
|
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
const nsAttrName* name = mAttrs.AttrNameAt(i);
|
|
|
|
|
|
|
|
// Eventlistenener-attributes are always in the null namespace
|
|
|
|
if (!name->IsAtom()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAtom* attr = name->Atom();
|
|
|
|
if (!IsEventAttributeName(attr)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString value;
|
|
|
|
GetAttr(kNameSpaceID_None, attr, value);
|
|
|
|
SetEventHandler(attr, value, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MathMLElement::IsEventAttributeNameInternal(nsAtom* aName) {
|
|
|
|
// The intent is to align MathML event attributes on HTML5, so the flag
|
|
|
|
// EventNameType_HTML is used here.
|
|
|
|
return nsContentUtils::IsEventAttributeName(aName, EventNameType_HTML);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult MathMLElement::BeforeSetAttr(int32_t aNamespaceID, nsAtom* aName,
|
|
|
|
const nsAttrValueOrString* aValue,
|
|
|
|
bool aNotify) {
|
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
if (!aValue && IsEventAttributeName(aName)) {
|
|
|
|
if (EventListenerManager* manager = GetExistingListenerManager()) {
|
|
|
|
manager->RemoveEventHandler(aName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return MathMLElementBase::BeforeSetAttr(aNamespaceID, aName, aValue, aNotify);
|
|
|
|
}
|
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
nsresult MathMLElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
|
|
|
const nsAttrValue* aValue,
|
|
|
|
const nsAttrValue* aOldValue,
|
|
|
|
nsIPrincipal* aSubjectPrincipal,
|
|
|
|
bool aNotify) {
|
2017-06-07 17:28:20 +00:00
|
|
|
// It is important that this be done after the attribute is set/unset.
|
|
|
|
// We will need the updated attribute value because notifying the document
|
2011-06-24 12:54:28 +00:00
|
|
|
// that content states have changed will call IntrinsicState, which will try
|
|
|
|
// to get updated information about the visitedness from Link.
|
|
|
|
if (aName == nsGkAtoms::href && (aNameSpaceID == kNameSpaceID_None ||
|
2019-10-05 21:47:38 +00:00
|
|
|
(!StaticPrefs::mathml_xlink_disabled() &&
|
|
|
|
aNameSpaceID == kNameSpaceID_XLink))) {
|
2017-06-07 17:28:20 +00:00
|
|
|
if (aValue && aNameSpaceID == kNameSpaceID_XLink) {
|
2019-10-05 21:47:38 +00:00
|
|
|
OwnerDoc()->WarnOnceAbout(
|
|
|
|
dom::Document::eMathML_DeprecatedXLinkAttribute);
|
2012-12-27 16:12:05 +00:00
|
|
|
}
|
2017-06-07 17:28:20 +00:00
|
|
|
// Note: When unsetting href, there may still be another href since there
|
|
|
|
// are 2 possible namespaces.
|
|
|
|
Link::ResetLinkState(aNotify, aValue || Link::ElementHasHref());
|
2011-06-24 12:54:28 +00:00
|
|
|
}
|
|
|
|
|
2019-10-04 19:05:36 +00:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (IsEventAttributeName(aName) && aValue) {
|
|
|
|
MOZ_ASSERT(aValue->Type() == nsAttrValue::eString,
|
|
|
|
"Expected string value for script body");
|
|
|
|
nsresult rv = SetEventHandler(aName, aValue->GetStringValue());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
return MathMLElementBase::AfterSetAttr(aNameSpaceID, aName, aValue, aOldValue,
|
|
|
|
aSubjectPrincipal, aNotify);
|
2011-06-24 12:54:28 +00:00
|
|
|
}
|
2013-02-06 09:42:16 +00:00
|
|
|
|
2019-09-13 16:27:54 +00:00
|
|
|
JSObject* MathMLElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2019-10-04 19:05:36 +00:00
|
|
|
return MathMLElement_Binding::Wrap(aCx, this, aGivenProto);
|
2013-02-06 09:42:16 +00:00
|
|
|
}
|