Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 :
8 : #include "nsMathMLElement.h"
9 : #include "base/compiler_specific.h"
10 : #include "mozilla/ArrayUtils.h"
11 : #include "nsGkAtoms.h"
12 : #include "nsITableCellLayout.h" // for MAX_COLSPAN / MAX_ROWSPAN
13 : #include "nsCRT.h"
14 : #include "nsLayoutStylesheetCache.h"
15 : #include "nsRuleData.h"
16 : #include "nsCSSValue.h"
17 : #include "nsCSSParser.h"
18 : #include "nsMappedAttributes.h"
19 : #include "nsStyleConsts.h"
20 : #include "nsIDocument.h"
21 : #include "nsIPresShell.h"
22 : #include "nsPresContext.h"
23 : #include "mozAutoDocUpdate.h"
24 : #include "nsIScriptError.h"
25 : #include "nsContentUtils.h"
26 : #include "nsIURI.h"
27 :
28 : #include "mozilla/EventDispatcher.h"
29 : #include "mozilla/EventStates.h"
30 : #include "mozilla/GenericSpecifiedValuesInlines.h"
31 : #include "mozilla/dom/ElementBinding.h"
32 :
33 : using namespace mozilla;
34 : using namespace mozilla::dom;
35 :
36 : //----------------------------------------------------------------------
37 : // nsISupports methods:
38 :
39 0 : NS_IMPL_ISUPPORTS_INHERITED(nsMathMLElement, nsMathMLElementBase,
40 : nsIDOMElement, nsIDOMNode, Link)
41 :
42 : static nsresult
43 0 : WarnDeprecated(const char16_t* aDeprecatedAttribute,
44 : const char16_t* aFavoredAttribute, nsIDocument* aDocument)
45 : {
46 : const char16_t *argv[] =
47 0 : { aDeprecatedAttribute, aFavoredAttribute };
48 : return nsContentUtils::
49 0 : ReportToConsole(nsIScriptError::warningFlag,
50 0 : NS_LITERAL_CSTRING("MathML"), aDocument,
51 : nsContentUtils::eMATHML_PROPERTIES,
52 0 : "DeprecatedSupersededBy", argv, 2);
53 : }
54 :
55 : static nsresult
56 0 : ReportLengthParseError(const nsString& aValue, nsIDocument* aDocument)
57 : {
58 0 : const char16_t *arg = aValue.get();
59 : return nsContentUtils::
60 0 : ReportToConsole(nsIScriptError::errorFlag,
61 0 : NS_LITERAL_CSTRING("MathML"), aDocument,
62 : nsContentUtils::eMATHML_PROPERTIES,
63 0 : "LengthParsingError", &arg, 1);
64 : }
65 :
66 : static nsresult
67 0 : ReportParseErrorNoTag(const nsString& aValue,
68 : nsIAtom* aAtom,
69 : nsIDocument* aDocument)
70 : {
71 : const char16_t *argv[] =
72 0 : { aValue.get(), aAtom->GetUTF16String() };
73 : return nsContentUtils::
74 0 : ReportToConsole(nsIScriptError::errorFlag,
75 0 : NS_LITERAL_CSTRING("MathML"), aDocument,
76 : nsContentUtils::eMATHML_PROPERTIES,
77 0 : "AttributeParsingErrorNoTag", argv, 2);
78 : }
79 :
80 0 : nsMathMLElement::nsMathMLElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
81 : : nsMathMLElementBase(aNodeInfo),
82 : ALLOW_THIS_IN_INITIALIZER_LIST(Link(this)),
83 0 : mIncrementScriptLevel(false)
84 : {
85 0 : }
86 :
87 0 : nsMathMLElement::nsMathMLElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
88 : : nsMathMLElementBase(aNodeInfo),
89 : ALLOW_THIS_IN_INITIALIZER_LIST(Link(this)),
90 0 : mIncrementScriptLevel(false)
91 : {
92 0 : }
93 :
94 : nsresult
95 0 : nsMathMLElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
96 : nsIContent* aBindingParent,
97 : bool aCompileEventHandlers)
98 : {
99 0 : Link::ResetLinkState(false, Link::ElementHasHref());
100 :
101 0 : nsresult rv = nsMathMLElementBase::BindToTree(aDocument, aParent,
102 : aBindingParent,
103 0 : aCompileEventHandlers);
104 0 : NS_ENSURE_SUCCESS(rv, rv);
105 :
106 0 : if (aDocument) {
107 0 : aDocument->RegisterPendingLinkUpdate(this);
108 : }
109 :
110 0 : nsIDocument* doc = GetComposedDoc();
111 0 : if (doc) {
112 0 : if (!doc->GetMathMLEnabled()) {
113 : // Enable MathML and setup the style sheet during binding, not element
114 : // construction, because we could move a MathML element from the document
115 : // that created it to another document.
116 0 : auto cache = nsLayoutStylesheetCache::For(doc->GetStyleBackendType());
117 0 : doc->SetMathMLEnabled();
118 0 : doc->EnsureOnDemandBuiltInUASheet(cache->MathMLSheet());
119 :
120 : // Rebuild style data for the presshell, because style system
121 : // optimizations may have taken place assuming MathML was disabled.
122 : // (See nsRuleNode::CheckSpecifiedProperties.)
123 0 : nsCOMPtr<nsIPresShell> shell = doc->GetShell();
124 0 : if (shell) {
125 : shell->GetPresContext()->
126 0 : PostRebuildAllStyleDataEvent(nsChangeHint(0), eRestyle_Subtree);
127 : }
128 : }
129 : }
130 :
131 0 : return rv;
132 : }
133 :
134 : void
135 0 : nsMathMLElement::UnbindFromTree(bool aDeep, bool aNullParent)
136 : {
137 : // If this link is ever reinserted into a document, it might
138 : // be under a different xml:base, so forget the cached state now.
139 0 : Link::ResetLinkState(false, Link::ElementHasHref());
140 :
141 0 : nsMathMLElementBase::UnbindFromTree(aDeep, aNullParent);
142 0 : }
143 :
144 : bool
145 0 : nsMathMLElement::ParseAttribute(int32_t aNamespaceID,
146 : nsIAtom* aAttribute,
147 : const nsAString& aValue,
148 : nsAttrValue& aResult)
149 : {
150 0 : MOZ_ASSERT(IsMathMLElement());
151 :
152 0 : if (aNamespaceID == kNameSpaceID_None) {
153 0 : if (mNodeInfo->Equals(nsGkAtoms::math) && aAttribute == nsGkAtoms::mode) {
154 0 : WarnDeprecated(nsGkAtoms::mode->GetUTF16String(),
155 0 : nsGkAtoms::display->GetUTF16String(), OwnerDoc());
156 : }
157 0 : if (aAttribute == nsGkAtoms::color) {
158 0 : WarnDeprecated(nsGkAtoms::color->GetUTF16String(),
159 0 : nsGkAtoms::mathcolor_->GetUTF16String(), OwnerDoc());
160 : }
161 0 : if (aAttribute == nsGkAtoms::color ||
162 0 : aAttribute == nsGkAtoms::mathcolor_ ||
163 0 : aAttribute == nsGkAtoms::background ||
164 0 : aAttribute == nsGkAtoms::mathbackground_) {
165 0 : return aResult.ParseColor(aValue);
166 : }
167 0 : if (mNodeInfo->Equals(nsGkAtoms::mtd_)) {
168 0 : if (aAttribute == nsGkAtoms::columnspan_) {
169 0 : aResult.ParseClampedNonNegativeInt(aValue, 1, 1, MAX_COLSPAN);
170 0 : return true;
171 : }
172 0 : if (aAttribute == nsGkAtoms::rowspan) {
173 0 : aResult.ParseClampedNonNegativeInt(aValue, 1, 0, MAX_ROWSPAN);
174 0 : return true;
175 : }
176 : }
177 : }
178 :
179 0 : return nsMathMLElementBase::ParseAttribute(aNamespaceID, aAttribute,
180 0 : aValue, aResult);
181 : }
182 :
183 : static Element::MappedAttributeEntry sMtableStyles[] = {
184 : { &nsGkAtoms::width },
185 : { nullptr }
186 : };
187 :
188 : static Element::MappedAttributeEntry sTokenStyles[] = {
189 : { &nsGkAtoms::mathsize_ },
190 : { &nsGkAtoms::fontsize_ },
191 : { &nsGkAtoms::color },
192 : { &nsGkAtoms::fontfamily_ },
193 : { &nsGkAtoms::fontstyle_ },
194 : { &nsGkAtoms::fontweight_ },
195 : { &nsGkAtoms::mathvariant_},
196 : { nullptr }
197 : };
198 :
199 : static Element::MappedAttributeEntry sEnvironmentStyles[] = {
200 : { &nsGkAtoms::scriptlevel_ },
201 : { &nsGkAtoms::scriptminsize_ },
202 : { &nsGkAtoms::scriptsizemultiplier_ },
203 : { &nsGkAtoms::background },
204 : { nullptr }
205 : };
206 :
207 : static Element::MappedAttributeEntry sCommonPresStyles[] = {
208 : { &nsGkAtoms::mathcolor_ },
209 : { &nsGkAtoms::mathbackground_ },
210 : { nullptr }
211 : };
212 :
213 : static Element::MappedAttributeEntry sDirStyles[] = {
214 : { &nsGkAtoms::dir },
215 : { nullptr }
216 : };
217 :
218 : bool
219 0 : nsMathMLElement::IsAttributeMapped(const nsIAtom* aAttribute) const
220 : {
221 0 : MOZ_ASSERT(IsMathMLElement());
222 :
223 : static const MappedAttributeEntry* const mtableMap[] = {
224 : sMtableStyles,
225 : sCommonPresStyles
226 : };
227 : static const MappedAttributeEntry* const tokenMap[] = {
228 : sTokenStyles,
229 : sCommonPresStyles,
230 : sDirStyles
231 : };
232 : static const MappedAttributeEntry* const mstyleMap[] = {
233 : sTokenStyles,
234 : sEnvironmentStyles,
235 : sCommonPresStyles,
236 : sDirStyles
237 : };
238 : static const MappedAttributeEntry* const commonPresMap[] = {
239 : sCommonPresStyles
240 : };
241 : static const MappedAttributeEntry* const mrowMap[] = {
242 : sCommonPresStyles,
243 : sDirStyles
244 : };
245 :
246 : // We don't support mglyph (yet).
247 0 : if (IsAnyOfMathMLElements(nsGkAtoms::ms_, nsGkAtoms::mi_, nsGkAtoms::mn_,
248 : nsGkAtoms::mo_, nsGkAtoms::mtext_,
249 : nsGkAtoms::mspace_))
250 0 : return FindAttributeDependence(aAttribute, tokenMap);
251 0 : if (IsAnyOfMathMLElements(nsGkAtoms::mstyle_, nsGkAtoms::math))
252 0 : return FindAttributeDependence(aAttribute, mstyleMap);
253 :
254 0 : if (mNodeInfo->Equals(nsGkAtoms::mtable_))
255 0 : return FindAttributeDependence(aAttribute, mtableMap);
256 :
257 0 : if (mNodeInfo->Equals(nsGkAtoms::mrow_))
258 0 : return FindAttributeDependence(aAttribute, mrowMap);
259 :
260 0 : if (IsAnyOfMathMLElements(nsGkAtoms::maction_,
261 : nsGkAtoms::maligngroup_,
262 : nsGkAtoms::malignmark_,
263 : nsGkAtoms::menclose_,
264 : nsGkAtoms::merror_,
265 : nsGkAtoms::mfenced_,
266 : nsGkAtoms::mfrac_,
267 : nsGkAtoms::mover_,
268 : nsGkAtoms::mpadded_,
269 : nsGkAtoms::mphantom_,
270 : nsGkAtoms::mprescripts_,
271 : nsGkAtoms::mroot_,
272 : nsGkAtoms::msqrt_,
273 : nsGkAtoms::msub_,
274 : nsGkAtoms::msubsup_,
275 : nsGkAtoms::msup_,
276 : nsGkAtoms::mtd_,
277 : nsGkAtoms::mtr_,
278 : nsGkAtoms::munder_,
279 : nsGkAtoms::munderover_,
280 : nsGkAtoms::none)) {
281 0 : return FindAttributeDependence(aAttribute, commonPresMap);
282 : }
283 :
284 0 : return false;
285 : }
286 :
287 : nsMapRuleToAttributesFunc
288 0 : nsMathMLElement::GetAttributeMappingFunction() const
289 : {
290 : // It doesn't really matter what our tag is here, because only attributes
291 : // that satisfy IsAttributeMapped will be stored in the mapped attributes
292 : // list and available to the mapping function
293 0 : return &MapMathMLAttributesInto;
294 : }
295 :
296 : /* static */ bool
297 0 : nsMathMLElement::ParseNamedSpaceValue(const nsString& aString,
298 : nsCSSValue& aCSSValue,
299 : uint32_t aFlags)
300 : {
301 0 : int32_t i = 0;
302 : // See if it is one of the 'namedspace' (ranging -7/18em, -6/18, ... 7/18em)
303 0 : if (aString.EqualsLiteral("veryverythinmathspace")) {
304 0 : i = 1;
305 0 : } else if (aString.EqualsLiteral("verythinmathspace")) {
306 0 : i = 2;
307 0 : } else if (aString.EqualsLiteral("thinmathspace")) {
308 0 : i = 3;
309 0 : } else if (aString.EqualsLiteral("mediummathspace")) {
310 0 : i = 4;
311 0 : } else if (aString.EqualsLiteral("thickmathspace")) {
312 0 : i = 5;
313 0 : } else if (aString.EqualsLiteral("verythickmathspace")) {
314 0 : i = 6;
315 0 : } else if (aString.EqualsLiteral("veryverythickmathspace")) {
316 0 : i = 7;
317 0 : } else if (aFlags & PARSE_ALLOW_NEGATIVE) {
318 0 : if (aString.EqualsLiteral("negativeveryverythinmathspace")) {
319 0 : i = -1;
320 0 : } else if (aString.EqualsLiteral("negativeverythinmathspace")) {
321 0 : i = -2;
322 0 : } else if (aString.EqualsLiteral("negativethinmathspace")) {
323 0 : i = -3;
324 0 : } else if (aString.EqualsLiteral("negativemediummathspace")) {
325 0 : i = -4;
326 0 : } else if (aString.EqualsLiteral("negativethickmathspace")) {
327 0 : i = -5;
328 0 : } else if (aString.EqualsLiteral("negativeverythickmathspace")) {
329 0 : i = -6;
330 0 : } else if (aString.EqualsLiteral("negativeveryverythickmathspace")) {
331 0 : i = -7;
332 : }
333 : }
334 0 : if (0 != i) {
335 0 : aCSSValue.SetFloatValue(float(i)/float(18), eCSSUnit_EM);
336 0 : return true;
337 : }
338 :
339 0 : return false;
340 : }
341 :
342 : // The REC says:
343 : //
344 : // "Most presentation elements have attributes that accept values representing
345 : // lengths to be used for size, spacing or similar properties. The syntax of a
346 : // length is specified as
347 : //
348 : // number | number unit | namedspace
349 : //
350 : // There should be no space between the number and the unit of a length."
351 : //
352 : // "A trailing '%' represents a percent of the default value. The default
353 : // value, or how it is obtained, is listed in the table of attributes for each
354 : // element. [...] A number without a unit is intepreted as a multiple of the
355 : // default value."
356 : //
357 : // "The possible units in MathML are:
358 : //
359 : // Unit Description
360 : // em an em (font-relative unit traditionally used for horizontal lengths)
361 : // ex an ex (font-relative unit traditionally used for vertical lengths)
362 : // px pixels, or size of a pixel in the current display
363 : // in inches (1 inch = 2.54 centimeters)
364 : // cm centimeters
365 : // mm millimeters
366 : // pt points (1 point = 1/72 inch)
367 : // pc picas (1 pica = 12 points)
368 : // % percentage of default value"
369 : //
370 : // The numbers are defined that way:
371 : // - unsigned-number: "a string of decimal digits with up to one decimal point
372 : // (U+002E), representing a non-negative terminating decimal number (a type of
373 : // rational number)"
374 : // - number: "an optional prefix of '-' (U+002D), followed by an unsigned
375 : // number, representing a terminating decimal number (a type of rational
376 : // number)"
377 : //
378 : /* static */ bool
379 0 : nsMathMLElement::ParseNumericValue(const nsString& aString,
380 : nsCSSValue& aCSSValue,
381 : uint32_t aFlags,
382 : nsIDocument* aDocument)
383 : {
384 0 : nsAutoString str(aString);
385 0 : str.CompressWhitespace(); // aString is const in this code...
386 :
387 0 : int32_t stringLength = str.Length();
388 0 : if (!stringLength) {
389 0 : if (!(aFlags & PARSE_SUPPRESS_WARNINGS)) {
390 0 : ReportLengthParseError(aString, aDocument);
391 : }
392 0 : return false;
393 : }
394 :
395 0 : if (ParseNamedSpaceValue(str, aCSSValue, aFlags)) {
396 0 : return true;
397 : }
398 :
399 0 : nsAutoString number, unit;
400 :
401 : // see if the negative sign is there
402 0 : int32_t i = 0;
403 0 : char16_t c = str[0];
404 0 : if (c == '-') {
405 0 : number.Append(c);
406 0 : i++;
407 : }
408 :
409 : // Gather up characters that make up the number
410 0 : bool gotDot = false;
411 0 : for ( ; i < stringLength; i++) {
412 0 : c = str[i];
413 0 : if (gotDot && c == '.') {
414 0 : if (!(aFlags & PARSE_SUPPRESS_WARNINGS)) {
415 0 : ReportLengthParseError(aString, aDocument);
416 : }
417 0 : return false; // two dots encountered
418 : }
419 0 : else if (c == '.')
420 0 : gotDot = true;
421 0 : else if (!nsCRT::IsAsciiDigit(c)) {
422 0 : str.Right(unit, stringLength - i);
423 : // some authors leave blanks before the unit, but that shouldn't
424 : // be allowed, so don't CompressWhitespace on 'unit'.
425 0 : break;
426 : }
427 0 : number.Append(c);
428 : }
429 :
430 : // Convert number to floating point
431 : nsresult errorCode;
432 0 : float floatValue = number.ToFloat(&errorCode);
433 0 : if (NS_FAILED(errorCode)) {
434 0 : if (!(aFlags & PARSE_SUPPRESS_WARNINGS)) {
435 0 : ReportLengthParseError(aString, aDocument);
436 : }
437 0 : return false;
438 : }
439 0 : if (floatValue < 0 && !(aFlags & PARSE_ALLOW_NEGATIVE)) {
440 0 : if (!(aFlags & PARSE_SUPPRESS_WARNINGS)) {
441 0 : ReportLengthParseError(aString, aDocument);
442 : }
443 0 : return false;
444 : }
445 :
446 : nsCSSUnit cssUnit;
447 0 : if (unit.IsEmpty()) {
448 0 : if (aFlags & PARSE_ALLOW_UNITLESS) {
449 : // no explicit unit, this is a number that will act as a multiplier
450 0 : if (!(aFlags & PARSE_SUPPRESS_WARNINGS)) {
451 0 : nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
452 0 : NS_LITERAL_CSTRING("MathML"), aDocument,
453 : nsContentUtils::eMATHML_PROPERTIES,
454 0 : "UnitlessValuesAreDeprecated");
455 : }
456 0 : if (aFlags & CONVERT_UNITLESS_TO_PERCENT) {
457 0 : aCSSValue.SetPercentValue(floatValue);
458 0 : return true;
459 : }
460 : else
461 0 : cssUnit = eCSSUnit_Number;
462 : } else {
463 : // We are supposed to have a unit, but there isn't one.
464 : // If the value is 0 we can just call it "pixels" otherwise
465 : // this is illegal.
466 0 : if (floatValue != 0.0) {
467 0 : if (!(aFlags & PARSE_SUPPRESS_WARNINGS)) {
468 0 : ReportLengthParseError(aString, aDocument);
469 : }
470 0 : return false;
471 : }
472 0 : cssUnit = eCSSUnit_Pixel;
473 : }
474 : }
475 0 : else if (unit.EqualsLiteral("%")) {
476 0 : aCSSValue.SetPercentValue(floatValue / 100.0f);
477 0 : return true;
478 : }
479 0 : else if (unit.EqualsLiteral("em")) cssUnit = eCSSUnit_EM;
480 0 : else if (unit.EqualsLiteral("ex")) cssUnit = eCSSUnit_XHeight;
481 0 : else if (unit.EqualsLiteral("px")) cssUnit = eCSSUnit_Pixel;
482 0 : else if (unit.EqualsLiteral("in")) cssUnit = eCSSUnit_Inch;
483 0 : else if (unit.EqualsLiteral("cm")) cssUnit = eCSSUnit_Centimeter;
484 0 : else if (unit.EqualsLiteral("mm")) cssUnit = eCSSUnit_Millimeter;
485 0 : else if (unit.EqualsLiteral("pt")) cssUnit = eCSSUnit_Point;
486 0 : else if (unit.EqualsLiteral("pc")) cssUnit = eCSSUnit_Pica;
487 0 : else if (unit.EqualsLiteral("q")) cssUnit = eCSSUnit_Quarter;
488 : else { // unexpected unit
489 0 : if (!(aFlags & PARSE_SUPPRESS_WARNINGS)) {
490 0 : ReportLengthParseError(aString, aDocument);
491 : }
492 0 : return false;
493 : }
494 :
495 0 : aCSSValue.SetFloatValue(floatValue, cssUnit);
496 0 : return true;
497 : }
498 :
499 : void
500 0 : nsMathMLElement::MapMathMLAttributesInto(const nsMappedAttributes* aAttributes,
501 : GenericSpecifiedValues* aData)
502 : {
503 0 : if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Font)) {
504 : // scriptsizemultiplier
505 : //
506 : // "Specifies the multiplier to be used to adjust font size due to changes
507 : // in scriptlevel.
508 : //
509 : // values: number
510 : // default: 0.71
511 : //
512 : const nsAttrValue* value =
513 0 : aAttributes->GetAttr(nsGkAtoms::scriptsizemultiplier_);
514 0 : if (value && value->Type() == nsAttrValue::eString &&
515 0 : !aData->PropertyIsSet(eCSSProperty__moz_script_size_multiplier)) {
516 0 : nsAutoString str(value->GetStringValue());
517 0 : str.CompressWhitespace();
518 : // MathML numbers can't have leading '+'
519 0 : if (str.Length() > 0 && str.CharAt(0) != '+') {
520 : nsresult errorCode;
521 0 : float floatValue = str.ToFloat(&errorCode);
522 : // Negative scriptsizemultipliers are not parsed
523 0 : if (NS_SUCCEEDED(errorCode) && floatValue >= 0.0f) {
524 0 : aData->SetNumberValue(eCSSProperty__moz_script_size_multiplier, floatValue);
525 : } else {
526 0 : ReportParseErrorNoTag(str,
527 : nsGkAtoms::scriptsizemultiplier_,
528 0 : aData->mPresContext->Document());
529 : }
530 : }
531 : }
532 :
533 : // scriptminsize
534 : //
535 : // "Specifies the minimum font size allowed due to changes in scriptlevel.
536 : // Note that this does not limit the font size due to changes to mathsize."
537 : //
538 : // values: length
539 : // default: 8pt
540 : //
541 : // We don't allow negative values.
542 : // Unitless and percent values give a multiple of the default value.
543 : //
544 0 : value = aAttributes->GetAttr(nsGkAtoms::scriptminsize_);
545 0 : if (value && value->Type() == nsAttrValue::eString &&
546 0 : !aData->PropertyIsSet(eCSSProperty__moz_script_min_size)) {
547 0 : nsCSSValue scriptMinSize;
548 0 : ParseNumericValue(value->GetStringValue(), scriptMinSize,
549 : PARSE_ALLOW_UNITLESS | CONVERT_UNITLESS_TO_PERCENT,
550 0 : aData->mPresContext->Document());
551 :
552 0 : if (scriptMinSize.GetUnit() == eCSSUnit_Percent) {
553 0 : scriptMinSize.SetFloatValue(8.0 * scriptMinSize.GetPercentValue(),
554 0 : eCSSUnit_Point);
555 : }
556 0 : if (scriptMinSize.GetUnit() != eCSSUnit_Null) {
557 0 : aData->SetLengthValue(eCSSProperty__moz_script_min_size, scriptMinSize);
558 : }
559 : }
560 :
561 : // scriptlevel
562 : //
563 : // "Changes the scriptlevel in effect for the children. When the value is
564 : // given without a sign, it sets scriptlevel to the specified value; when a
565 : // sign is given, it increments ("+") or decrements ("-") the current
566 : // value. (Note that large decrements can result in negative values of
567 : // scriptlevel, but these values are considered legal.)"
568 : //
569 : // values: ( "+" | "-" )? unsigned-integer
570 : // default: inherited
571 : //
572 0 : value = aAttributes->GetAttr(nsGkAtoms::scriptlevel_);
573 0 : if (value && value->Type() == nsAttrValue::eString &&
574 0 : !aData->PropertyIsSet(eCSSProperty__moz_script_level)) {
575 0 : nsAutoString str(value->GetStringValue());
576 0 : str.CompressWhitespace();
577 0 : if (str.Length() > 0) {
578 : nsresult errorCode;
579 0 : int32_t intValue = str.ToInteger(&errorCode);
580 0 : if (NS_SUCCEEDED(errorCode)) {
581 : // This is kind of cheesy ... if the scriptlevel has a sign,
582 : // then it's a relative value and we store the nsCSSValue as an
583 : // Integer to indicate that. Otherwise we store it as a Number
584 : // to indicate that the scriptlevel is absolute.
585 0 : char16_t ch = str.CharAt(0);
586 0 : if (ch == '+' || ch == '-') {
587 0 : aData->SetIntValue(eCSSProperty__moz_script_level, intValue);
588 : } else {
589 0 : aData->SetNumberValue(eCSSProperty__moz_script_level, intValue);
590 : }
591 : } else {
592 0 : ReportParseErrorNoTag(str,
593 : nsGkAtoms::scriptlevel_,
594 0 : aData->mPresContext->Document());
595 : }
596 : }
597 : }
598 :
599 : // mathsize
600 : //
601 : // "Specifies the size to display the token content. The values 'small' and
602 : // 'big' choose a size smaller or larger than the current font size, but
603 : // leave the exact proportions unspecified; 'normal' is allowed for
604 : // completeness, but since it is equivalent to '100%' or '1em', it has no
605 : // effect."
606 : //
607 : // values: "small" | "normal" | "big" | length
608 : // default: inherited
609 : //
610 : // fontsize
611 : //
612 : // "Specified the size for the token. Deprecated in favor of mathsize."
613 : //
614 : // values: length
615 : // default: inherited
616 : //
617 : // In both cases, we don't allow negative values.
618 : // Unitless values give a multiple of the default value.
619 : //
620 0 : bool parseSizeKeywords = true;
621 0 : value = aAttributes->GetAttr(nsGkAtoms::mathsize_);
622 0 : if (!value) {
623 0 : parseSizeKeywords = false;
624 0 : value = aAttributes->GetAttr(nsGkAtoms::fontsize_);
625 0 : if (value) {
626 0 : WarnDeprecated(nsGkAtoms::fontsize_->GetUTF16String(),
627 : nsGkAtoms::mathsize_->GetUTF16String(),
628 0 : aData->mPresContext->Document());
629 : }
630 : }
631 0 : if (value && value->Type() == nsAttrValue::eString &&
632 0 : !aData->PropertyIsSet(eCSSProperty_font_size)) {
633 0 : nsAutoString str(value->GetStringValue());
634 0 : nsCSSValue fontSize;
635 0 : if (!ParseNumericValue(str, fontSize, PARSE_SUPPRESS_WARNINGS |
636 : PARSE_ALLOW_UNITLESS | CONVERT_UNITLESS_TO_PERCENT,
637 : nullptr)
638 0 : && parseSizeKeywords) {
639 : static const char sizes[3][7] = { "small", "normal", "big" };
640 : static const int32_t values[MOZ_ARRAY_LENGTH(sizes)] = {
641 : NS_STYLE_FONT_SIZE_SMALL, NS_STYLE_FONT_SIZE_MEDIUM,
642 : NS_STYLE_FONT_SIZE_LARGE
643 : };
644 0 : str.CompressWhitespace();
645 0 : for (uint32_t i = 0; i < ArrayLength(sizes); ++i) {
646 0 : if (str.EqualsASCII(sizes[i])) {
647 0 : aData->SetKeywordValue(eCSSProperty_font_size, values[i]);
648 0 : break;
649 : }
650 : }
651 0 : } else if (fontSize.GetUnit() == eCSSUnit_Percent) {
652 0 : aData->SetPercentValue(eCSSProperty_font_size,
653 0 : fontSize.GetPercentValue());
654 0 : } else if (fontSize.GetUnit() != eCSSUnit_Null) {
655 0 : aData->SetLengthValue(eCSSProperty_font_size, fontSize);
656 : }
657 : }
658 :
659 : // fontfamily
660 : //
661 : // "Should be the name of a font that may be available to a MathML renderer,
662 : // or a CSS font specification; See Section 6.5 Using CSS with MathML and
663 : // CSS for more information. Deprecated in favor of mathvariant."
664 : //
665 : // values: string
666 : //
667 0 : value = aAttributes->GetAttr(nsGkAtoms::fontfamily_);
668 0 : if (value) {
669 0 : WarnDeprecated(nsGkAtoms::fontfamily_->GetUTF16String(),
670 : nsGkAtoms::mathvariant_->GetUTF16String(),
671 0 : aData->mPresContext->Document());
672 : }
673 0 : if (value && value->Type() == nsAttrValue::eString &&
674 0 : !aData->PropertyIsSet(eCSSProperty_font_family)) {
675 0 : aData->SetFontFamily(value->GetStringValue());
676 : }
677 :
678 : // fontstyle
679 : //
680 : // "Specified the font style to use for the token. Deprecated in favor of
681 : // mathvariant."
682 : //
683 : // values: "normal" | "italic"
684 : // default: normal (except on <mi>)
685 : //
686 : // Note that the font-style property is reset in layout/style/ when
687 : // -moz-math-variant is specified.
688 0 : value = aAttributes->GetAttr(nsGkAtoms::fontstyle_);
689 0 : if (value) {
690 0 : WarnDeprecated(nsGkAtoms::fontstyle_->GetUTF16String(),
691 : nsGkAtoms::mathvariant_->GetUTF16String(),
692 0 : aData->mPresContext->Document());
693 0 : if (value->Type() == nsAttrValue::eString &&
694 0 : !aData->PropertyIsSet(eCSSProperty_font_style)) {
695 0 : nsAutoString str(value->GetStringValue());
696 0 : str.CompressWhitespace();
697 0 : if (str.EqualsASCII("normal")) {
698 : aData->SetKeywordValue(eCSSProperty_font_style,
699 0 : NS_STYLE_FONT_STYLE_NORMAL);
700 0 : } else if (str.EqualsASCII("italic")) {
701 : aData->SetKeywordValue(eCSSProperty_font_style,
702 0 : NS_STYLE_FONT_STYLE_ITALIC);
703 : }
704 : }
705 : }
706 :
707 : // fontweight
708 : //
709 : // "Specified the font weight for the token. Deprecated in favor of
710 : // mathvariant."
711 : //
712 : // values: "normal" | "bold"
713 : // default: normal
714 : //
715 : // Note that the font-weight property is reset in layout/style/ when
716 : // -moz-math-variant is specified.
717 0 : value = aAttributes->GetAttr(nsGkAtoms::fontweight_);
718 0 : if (value) {
719 0 : WarnDeprecated(nsGkAtoms::fontweight_->GetUTF16String(),
720 : nsGkAtoms::mathvariant_->GetUTF16String(),
721 0 : aData->mPresContext->Document());
722 0 : if (value->Type() == nsAttrValue::eString &&
723 0 : !aData->PropertyIsSet(eCSSProperty_font_weight)) {
724 0 : nsAutoString str(value->GetStringValue());
725 0 : str.CompressWhitespace();
726 0 : if (str.EqualsASCII("normal")) {
727 : aData->SetKeywordValue(eCSSProperty_font_weight,
728 0 : NS_STYLE_FONT_WEIGHT_NORMAL);
729 0 : } else if (str.EqualsASCII("bold")) {
730 : aData->SetKeywordValue(eCSSProperty_font_weight,
731 0 : NS_STYLE_FONT_WEIGHT_BOLD);
732 : }
733 : }
734 : }
735 :
736 : // mathvariant
737 : //
738 : // "Specifies the logical class of the token. Note that this class is more
739 : // than styling, it typically conveys semantic intent;"
740 : //
741 : // values: "normal" | "bold" | "italic" | "bold-italic" | "double-struck" |
742 : // "bold-fraktur" | "script" | "bold-script" | "fraktur" | "sans-serif" |
743 : // "bold-sans-serif" | "sans-serif-italic" | "sans-serif-bold-italic" |
744 : // "monospace" | "initial" | "tailed" | "looped" | "stretched"
745 : // default: normal (except on <mi>)
746 : //
747 0 : value = aAttributes->GetAttr(nsGkAtoms::mathvariant_);
748 0 : if (value && value->Type() == nsAttrValue::eString &&
749 0 : !aData->PropertyIsSet(eCSSProperty__moz_math_variant)) {
750 0 : nsAutoString str(value->GetStringValue());
751 0 : str.CompressWhitespace();
752 : static const char sizes[19][23] = {
753 : "normal", "bold", "italic", "bold-italic", "script", "bold-script",
754 : "fraktur", "double-struck", "bold-fraktur", "sans-serif",
755 : "bold-sans-serif", "sans-serif-italic", "sans-serif-bold-italic",
756 : "monospace", "initial", "tailed", "looped", "stretched"
757 : };
758 : static const int32_t values[MOZ_ARRAY_LENGTH(sizes)] = {
759 : NS_MATHML_MATHVARIANT_NORMAL, NS_MATHML_MATHVARIANT_BOLD,
760 : NS_MATHML_MATHVARIANT_ITALIC, NS_MATHML_MATHVARIANT_BOLD_ITALIC,
761 : NS_MATHML_MATHVARIANT_SCRIPT, NS_MATHML_MATHVARIANT_BOLD_SCRIPT,
762 : NS_MATHML_MATHVARIANT_FRAKTUR, NS_MATHML_MATHVARIANT_DOUBLE_STRUCK,
763 : NS_MATHML_MATHVARIANT_BOLD_FRAKTUR, NS_MATHML_MATHVARIANT_SANS_SERIF,
764 : NS_MATHML_MATHVARIANT_BOLD_SANS_SERIF,
765 : NS_MATHML_MATHVARIANT_SANS_SERIF_ITALIC,
766 : NS_MATHML_MATHVARIANT_SANS_SERIF_BOLD_ITALIC,
767 : NS_MATHML_MATHVARIANT_MONOSPACE, NS_MATHML_MATHVARIANT_INITIAL,
768 : NS_MATHML_MATHVARIANT_TAILED, NS_MATHML_MATHVARIANT_LOOPED,
769 : NS_MATHML_MATHVARIANT_STRETCHED
770 : };
771 0 : for (uint32_t i = 0; i < ArrayLength(sizes); ++i) {
772 0 : if (str.EqualsASCII(sizes[i])) {
773 0 : aData->SetKeywordValue(eCSSProperty__moz_math_variant, values[i]);
774 0 : break;
775 : }
776 : }
777 : }
778 : }
779 :
780 : // mathbackground
781 : //
782 : // "Specifies the background color to be used to fill in the bounding box of
783 : // the element and its children. The default, 'transparent', lets the
784 : // background color, if any, used in the current rendering context to show
785 : // through."
786 : //
787 : // values: color | "transparent"
788 : // default: "transparent"
789 : //
790 : // background
791 : //
792 : // "Specified the background color to be used to fill in the bounding box of
793 : // the element and its children. Deprecated in favor of mathbackground."
794 : //
795 : // values: color | "transparent"
796 : // default: "transparent"
797 : //
798 0 : if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Background)) {
799 : const nsAttrValue* value =
800 0 : aAttributes->GetAttr(nsGkAtoms::mathbackground_);
801 0 : if (!value) {
802 0 : value = aAttributes->GetAttr(nsGkAtoms::background);
803 0 : if (value) {
804 0 : WarnDeprecated(nsGkAtoms::background->GetUTF16String(),
805 : nsGkAtoms::mathbackground_->GetUTF16String(),
806 0 : aData->mPresContext->Document());
807 : }
808 : }
809 0 : if (value) {
810 : nscolor color;
811 0 : if (value->GetColorValue(color)) {
812 0 : aData->SetColorValueIfUnset(eCSSProperty_background_color, color);
813 : }
814 : }
815 : }
816 :
817 : // mathcolor
818 : //
819 : // "Specifies the foreground color to use when drawing the components of this
820 : // element, such as the content for token elements or any lines, surds, or
821 : // other decorations. It also establishes the default mathcolor used for
822 : // child elements when used on a layout element."
823 : //
824 : // values: color
825 : // default: inherited
826 : //
827 : // color
828 : //
829 : // "Specified the color for the token. Deprecated in favor of mathcolor."
830 : //
831 : // values: color
832 : // default: inherited
833 : //
834 0 : if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Color)) {
835 0 : const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::mathcolor_);
836 0 : if (!value) {
837 0 : value = aAttributes->GetAttr(nsGkAtoms::color);
838 0 : if (value) {
839 0 : WarnDeprecated(nsGkAtoms::color->GetUTF16String(),
840 : nsGkAtoms::mathcolor_->GetUTF16String(),
841 0 : aData->mPresContext->Document());
842 : }
843 : }
844 : nscolor color;
845 0 : if (value && value->GetColorValue(color)) {
846 0 : aData->SetColorValueIfUnset(eCSSProperty_color, color);
847 : }
848 : }
849 :
850 0 : if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Position)) {
851 : // width
852 : //
853 : // "Specifies the desired width of the entire table and is intended for
854 : // visual user agents. When the value is a percentage value, the value is
855 : // relative to the horizontal space a MathML renderer has available for the
856 : // math element. When the value is "auto", the MathML renderer should
857 : // calculate the table width from its contents using whatever layout
858 : // algorithm it chooses. "
859 : //
860 : // values: "auto" | length
861 : // default: auto
862 : //
863 0 : if (!aData->PropertyIsSet(eCSSProperty_width)) {
864 0 : const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::width);
865 0 : nsCSSValue width;
866 : // This does not handle auto and unitless values
867 0 : if (value && value->Type() == nsAttrValue::eString) {
868 0 : ParseNumericValue(value->GetStringValue(), width, 0,
869 0 : aData->mPresContext->Document());
870 0 : if (width.GetUnit() == eCSSUnit_Percent) {
871 0 : aData->SetPercentValue(eCSSProperty_width,
872 0 : width.GetPercentValue());
873 0 : } else if (width.GetUnit() != eCSSUnit_Null) {
874 0 : aData->SetLengthValue(eCSSProperty_width, width);
875 : }
876 : }
877 : }
878 : }
879 :
880 : // dir
881 : //
882 : // Overall Directionality of Mathematics Formulas:
883 : // "The overall directionality for a formula, basically the direction of the
884 : // Layout Schemata, is specified by the dir attribute on the containing math
885 : // element (see Section 2.2 The Top-Level math Element). The default is ltr.
886 : // [...] The overall directionality is usually set on the math, but may also
887 : // be switched for individual subformula by using the dir attribute on mrow
888 : // or mstyle elements."
889 : //
890 : // Bidirectional Layout in Token Elements:
891 : // "Specifies the initial directionality for text within the token:
892 : // ltr (Left To Right) or rtl (Right To Left). This attribute should only be
893 : // needed in rare cases involving weak or neutral characters;
894 : // see Section 3.1.5.1 Overall Directionality of Mathematics Formulas for
895 : // further discussion. It has no effect on mspace."
896 : //
897 : // values: "ltr" | "rtl"
898 : // default: inherited
899 : //
900 0 : if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Visibility)) {
901 0 : const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::dir);
902 0 : if (value && value->Type() == nsAttrValue::eString &&
903 0 : !aData->PropertyIsSet(eCSSProperty_direction)) {
904 0 : nsAutoString str(value->GetStringValue());
905 : static const char dirs[][4] = { "ltr", "rtl" };
906 : static const int32_t dirValues[MOZ_ARRAY_LENGTH(dirs)] = {
907 : NS_STYLE_DIRECTION_LTR, NS_STYLE_DIRECTION_RTL
908 : };
909 0 : for (uint32_t i = 0; i < ArrayLength(dirs); ++i) {
910 0 : if (str.EqualsASCII(dirs[i])) {
911 0 : aData->SetKeywordValue(eCSSProperty_direction, dirValues[i]);
912 0 : break;
913 : }
914 : }
915 : }
916 : }
917 0 : }
918 :
919 : nsresult
920 0 : nsMathMLElement::GetEventTargetParent(EventChainPreVisitor& aVisitor)
921 : {
922 0 : nsresult rv = Element::GetEventTargetParent(aVisitor);
923 0 : NS_ENSURE_SUCCESS(rv, rv);
924 :
925 0 : return GetEventTargetParentForLinks(aVisitor);
926 : }
927 :
928 : nsresult
929 0 : nsMathMLElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
930 : {
931 0 : return PostHandleEventForLinks(aVisitor);
932 : }
933 :
934 0 : NS_IMPL_ELEMENT_CLONE(nsMathMLElement)
935 :
936 : EventStates
937 0 : nsMathMLElement::IntrinsicState() const
938 : {
939 0 : return Link::LinkState() | nsMathMLElementBase::IntrinsicState() |
940 0 : (mIncrementScriptLevel ?
941 0 : NS_EVENT_STATE_INCREMENT_SCRIPT_LEVEL : EventStates());
942 : }
943 :
944 : bool
945 0 : nsMathMLElement::IsNodeOfType(uint32_t aFlags) const
946 : {
947 0 : return !(aFlags & ~eCONTENT);
948 : }
949 :
950 : void
951 0 : nsMathMLElement::SetIncrementScriptLevel(bool aIncrementScriptLevel,
952 : bool aNotify)
953 : {
954 0 : if (aIncrementScriptLevel == mIncrementScriptLevel)
955 0 : return;
956 0 : mIncrementScriptLevel = aIncrementScriptLevel;
957 :
958 0 : NS_ASSERTION(aNotify, "We always notify!");
959 :
960 0 : UpdateState(true);
961 : }
962 :
963 : bool
964 0 : nsMathMLElement::IsFocusableInternal(int32_t* aTabIndex, bool aWithMouse)
965 : {
966 0 : nsCOMPtr<nsIURI> uri;
967 0 : if (IsLink(getter_AddRefs(uri))) {
968 0 : if (aTabIndex) {
969 0 : *aTabIndex = ((sTabFocusModel & eTabFocus_linksMask) == 0 ? -1 : 0);
970 : }
971 0 : return true;
972 : }
973 :
974 0 : if (aTabIndex) {
975 0 : *aTabIndex = -1;
976 : }
977 :
978 0 : return false;
979 : }
980 :
981 : bool
982 0 : nsMathMLElement::IsLink(nsIURI** aURI) const
983 : {
984 : // http://www.w3.org/TR/2010/REC-MathML3-20101021/chapter6.html#interf.link
985 : // The REC says that the following elements should not be linking elements:
986 0 : if (IsAnyOfMathMLElements(nsGkAtoms::mprescripts_, nsGkAtoms::none,
987 : nsGkAtoms::malignmark_, nsGkAtoms::maligngroup_)) {
988 0 : *aURI = nullptr;
989 0 : return false;
990 : }
991 :
992 0 : bool hasHref = false;
993 0 : const nsAttrValue* href = mAttrsAndChildren.GetAttr(nsGkAtoms::href,
994 0 : kNameSpaceID_None);
995 0 : if (href) {
996 : // MathML href
997 : // The REC says: "When user agents encounter MathML elements with both href
998 : // and xlink:href attributes, the href attribute should take precedence."
999 0 : hasHref = true;
1000 : } else {
1001 : // To be a clickable XLink for styling and interaction purposes, we require:
1002 : //
1003 : // xlink:href - must be set
1004 : // xlink:type - must be unset or set to "" or set to "simple"
1005 : // xlink:show - must be unset or set to "", "new" or "replace"
1006 : // xlink:actuate - must be unset or set to "" or "onRequest"
1007 : //
1008 : // For any other values, we're either not a *clickable* XLink, or the end
1009 : // result is poorly specified. Either way, we return false.
1010 :
1011 : static nsIContent::AttrValuesArray sTypeVals[] =
1012 : { &nsGkAtoms::_empty, &nsGkAtoms::simple, nullptr };
1013 :
1014 : static nsIContent::AttrValuesArray sShowVals[] =
1015 : { &nsGkAtoms::_empty, &nsGkAtoms::_new, &nsGkAtoms::replace, nullptr };
1016 :
1017 : static nsIContent::AttrValuesArray sActuateVals[] =
1018 : { &nsGkAtoms::_empty, &nsGkAtoms::onRequest, nullptr };
1019 :
1020 : // Optimization: check for href first for early return
1021 0 : href = mAttrsAndChildren.GetAttr(nsGkAtoms::href,
1022 0 : kNameSpaceID_XLink);
1023 0 : if (href &&
1024 0 : FindAttrValueIn(kNameSpaceID_XLink, nsGkAtoms::type,
1025 0 : sTypeVals, eCaseMatters) !=
1026 0 : nsIContent::ATTR_VALUE_NO_MATCH &&
1027 0 : FindAttrValueIn(kNameSpaceID_XLink, nsGkAtoms::show,
1028 0 : sShowVals, eCaseMatters) !=
1029 0 : nsIContent::ATTR_VALUE_NO_MATCH &&
1030 0 : FindAttrValueIn(kNameSpaceID_XLink, nsGkAtoms::actuate,
1031 0 : sActuateVals, eCaseMatters) !=
1032 : nsIContent::ATTR_VALUE_NO_MATCH) {
1033 0 : hasHref = true;
1034 : }
1035 : }
1036 :
1037 0 : if (hasHref) {
1038 0 : nsCOMPtr<nsIURI> baseURI = GetBaseURI();
1039 : // Get absolute URI
1040 0 : nsAutoString hrefStr;
1041 0 : href->ToString(hrefStr);
1042 0 : nsContentUtils::NewURIWithDocumentCharset(aURI, hrefStr,
1043 0 : OwnerDoc(), baseURI);
1044 : // must promise out param is non-null if we return true
1045 0 : return !!*aURI;
1046 : }
1047 :
1048 0 : *aURI = nullptr;
1049 0 : return false;
1050 : }
1051 :
1052 : void
1053 0 : nsMathMLElement::GetLinkTarget(nsAString& aTarget)
1054 : {
1055 0 : const nsAttrValue* target = mAttrsAndChildren.GetAttr(nsGkAtoms::target,
1056 0 : kNameSpaceID_XLink);
1057 0 : if (target) {
1058 0 : target->ToString(aTarget);
1059 : }
1060 :
1061 0 : if (aTarget.IsEmpty()) {
1062 :
1063 : static nsIContent::AttrValuesArray sShowVals[] =
1064 : { &nsGkAtoms::_new, &nsGkAtoms::replace, nullptr };
1065 :
1066 0 : switch (FindAttrValueIn(kNameSpaceID_XLink, nsGkAtoms::show,
1067 0 : sShowVals, eCaseMatters)) {
1068 : case 0:
1069 0 : aTarget.AssignLiteral("_blank");
1070 0 : return;
1071 : case 1:
1072 0 : return;
1073 : }
1074 0 : OwnerDoc()->GetBaseTarget(aTarget);
1075 : }
1076 : }
1077 :
1078 : already_AddRefed<nsIURI>
1079 0 : nsMathMLElement::GetHrefURI() const
1080 : {
1081 0 : nsCOMPtr<nsIURI> hrefURI;
1082 0 : return IsLink(getter_AddRefs(hrefURI)) ? hrefURI.forget() : nullptr;
1083 : }
1084 :
1085 : nsresult
1086 0 : nsMathMLElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
1087 : const nsAttrValue* aValue,
1088 : const nsAttrValue* aOldValue, bool aNotify)
1089 : {
1090 : // It is important that this be done after the attribute is set/unset.
1091 : // We will need the updated attribute value because notifying the document
1092 : // that content states have changed will call IntrinsicState, which will try
1093 : // to get updated information about the visitedness from Link.
1094 0 : if (aName == nsGkAtoms::href &&
1095 0 : (aNameSpaceID == kNameSpaceID_None ||
1096 : aNameSpaceID == kNameSpaceID_XLink)) {
1097 0 : if (aValue && aNameSpaceID == kNameSpaceID_XLink) {
1098 0 : WarnDeprecated(u"xlink:href", u"href", OwnerDoc());
1099 : }
1100 : // Note: When unsetting href, there may still be another href since there
1101 : // are 2 possible namespaces.
1102 0 : Link::ResetLinkState(aNotify, aValue || Link::ElementHasHref());
1103 : }
1104 :
1105 0 : return nsMathMLElementBase::AfterSetAttr(aNameSpaceID, aName, aValue,
1106 0 : aOldValue, aNotify);
1107 : }
1108 :
1109 : JSObject*
1110 0 : nsMathMLElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
1111 : {
1112 0 : return ElementBinding::Wrap(aCx, this, aGivenProto);
1113 : }
|