Files
palemoon27/dom/mathml/nsMathMLElement.cpp
T
roytam1 049b3235ac import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1207494 - Part 8: Remove use of expression closure from dom/identity/. r=ferjm (34fac889f8)
- minor crash thing (13fe2827c2)
- Bug 1243359 - initialize mScrollSeriesNumber in all ScrollWheelInput constructors. r=roc (94163d8eca)
- fix misspatch (b380a7bbe4)
- Bug 1207412 - Make SystemTimeConverter use TimeStamp::Now() when converting times; r=karlt (f408549605)
- Bug 1212102 - Drop unnecessary assertion comparing timestamps in SystemTimeConverter; r=karlt (1efaa04b3f)
- Bug 1241302 - Slightly modernize this code. r=jst (c1e97bc069)
- bug 1216916 clean up when InvokeDragSessionWithImage/Selection() fails r=roc (9cdf71b717)
- Bug 1231329 - run ConvertToUnscaledDevPixels if *aPresContext is valid. r=roc (d10f23633b)
- Bug 1245927: Innerize before creating DOM files from the file picker. r=baku (8754128362)
- Bug 1155214 - Mark nsIBidiKeyboard as builtinclass; r=mrbkap (2d00326d2b)
- reorder (c3c1ba92c9)
- Bug 1236566 - add override declarations for widget/windows/GfxInfo.h; r=roc (940b40ed91)
- Bug 1242659: Part 1. More information on the mismatches. r=jrmuizel (78331ddad2)
- Block some Radeon drivers that crash on D3D9. (bug 1213107, r=jrmuizel) (482b66d313)
- Bug 1203199 - Blacklist DXVA on some older intel drivers for causing crashes. r=jrmuizel (f1827d4498)
- Bug 1203199 - Fix driver range with blacklist to avoid blacklisting other OSes. (2c2d547296)
- Bug 1203199 - Bustage fix. CLOSED TREE (3233d407f3)
- Bug 1178385. Enable DXVA on the G45 r=ajones (3c59a58a15)
- Bug 1188442 IMMHandler::GetSelection() should use static Selection instance when IME doesn't have focus and return its or mSelection's reference r=emk (5cc4b30433)
- Bug 1238899 Create hidden native caret for ATOK at composing in windowless plugin r=m_kato (40ef5bb4aa)
- Bug 1257919 part 1. Kill off nsIXSLTException. r=khuey (11f37643f2)
- Bug 1242072 - Change implementation of BaseProxyHandler::get() to follow ES6 [[Get]] specification. r=jorendorff (094a67f284)
- Bug 489636 - Add a GC u-bench test for property tree splitting via deletion; r=sfink (9282fec25f)
- Bug 1257919 part 2. Make nsIException and nsIStackFrame builtinclass, so we can start using [implicit_jscontext] on them. r=khuey (0e65fb8554)
- Bug 1257919 part 3. Make the various toString methods on exceptions take an explicit JSContext. r=khuey (b342fb4930)
- Bug 1257919 part 4. Stop returning StackFrame instances from exceptions::CreateStack. C++ callers of GetCurrentJSStack or exceptions::CreateStack always check for null anyway, and none of them seem to want this non-JS thing. r=khuey (d34036ccf9)
- Bug 1257919 part 5. Get rid of the now-unused StackFrame class. r=khuey (aa13af0dfe)
- Bug 1141222 - Create ScriptError with stack from Cu.reportError. r=bholley (b83ad26aa0)
- Bug 1208641 - Extract stack from DOM/XPC exception. r=bholley (e382b5f48c)
- Bug 1254380 part 1. Find the relevant window when the compartment we've got is an addon sandbox compartment in AutoJSAPI exception/warning reporting code. r=bholley (4b1f6c64a9)
- Bug 1250630 - remove PBackgroundTest and ifdef ENABLE_TEST blocks. r=khuey (d7b36860a3)
- Bug 1250963 part 1. Change NotifyRunnable::Dispatch to not require a JSContext. r=khuey (48e03c2fc2)
- Bug 1250963 part 2. Remove the unused JSContext argument of WorkerPrivate::ModifyBusyCount. r=khuey (0f5ca42be1)
- Bug 1250291 part 1. Stop pretending to report exceptions in MainThreadStopSyncLoopRunnable::PostDispatch. r=khuey (6e1c81cc06)
- Bug 1250291 part 2. Stop pretending to report exceptions in MainThreadWorkerSyncRunnable::PostDispatch. r=khuey (f3d846ea31)
- Bug 1250291 part 3. Stop pretending to report exceptions in WorkerDebuggerRunnable::PostDispatch. r=khuey (10bc1710d1)
- Bug 1250975. Stop passing a JSContext argument to WorkerRunnable::PreDispatch and its overrides. r=khuey (71ab9046f0)
- Bug 1255298. Just pass through the JSContext when passing through the NotificationOptions in notification code. r=wchen (552ae8e33e)
- Bug 1250185 part 2. Remove some JSContext stuff that's no longer needed in Notification code. r=khuey (20b99ef28b)
- Bug 1251045 part 8. Remove the JSContext argument from some nsINotificationStorageCallback methods. r=khuey (170c4afabc)
- Bug 1227015 P7 Supress unused ErrorResult exception if the worker runnable failed to dispatch. r=catalinb (23a3cc6f45)
- Bug 1251045 part 3. Remove the JSContext argument of WorkerRunnable::PostDispatch and its overrides. r=khuey (6a666d1a4a)
- Bug 1251045 part 2. Remove the JSContext argument of ModifyBusyCountFromWorker. r=khuey (105bc4f59e)
- Bug 1252130. Remove unnecessary JSContext argument from NotificationWorkerRunnable::WorkerRunInternal. r=khuey (642727f6f6)
- Bug 1252127. Remove unnecessary JSContext argument from PromiseWorkerProxy::CleanUp. r=khuey (339e1157d1)
- Bug 1251045 part 1. Make it possible to dispatch a ModifyBusyCountRunnable without a JSContext. r=khuey (665c1f81b4)
- Bug 1251045 part 4. Remove the JSContext argument of WorkerRunnable::Dispatch. r=khuey (6c5cdab2b7)
- Bug 1250185 part 1. nsIStructuredCloneContainer.initFromBase64 doesn't need a JSContext argument. r=khuey (d63a219209)
- fix (773c0393aa)
- Bug 1251045 part 5. Remove the JSContext argument from WorkerPrivateParent::Freeze/Thaw. r=khuey (cd419bfd2c)
- Bug 1251045 part 6. Remove the JSContext argument from some worker debugger methods that no longer need it. r=khuey (abcc437cb9)
- Bug 1251045 part 7. Remove the JSContext argument from some worker methods that no longer need it. r=khuey (3ddcbca08c)
- Bug 1249652 part 1. Add a method on ErrorResult to steal an exception, if any, from a JSContext. r=khuey (9c07f5044b)
- Bug 1229071 - importScripts should throw the correct error result in case the loading of one of scripts fails, r=bz (cd37645d76)
- Bug 1229970 Abort script loading start requests if a load has been canceled. r=khuey (a44d9128ca)
- Bug 1233171 Cancel channel when ScriptLoader is aborted during service worker script load. r=khuey (3b6ceafec7)
- Bug 1249351 part 1. When doing importScripts of multiple scripts in a service worker, make sure to track the cache streams per-loadinfo, instead of trying to make them all wait on the same stream. r=bkelly (e1ccea9685)
- Bug 1157544 - Fix a typo in the test; r=baku (8c0bf8f504)
- Bug 1249351 part 2. Clean up test_importscript.html and add multiple-url importScript() case. r=bz (52b0a31032)
- Bug 1249652 part 2. ScriptExecutorRunnable::WorkerRun should immediately move JS exceptions to its ErrorResult instead of allowing them to linger on the JSContext. r=baku,khuey (f628d3c8ba)
- Bug 1249652 part 3. Simplify way we handle canceling when ScriptLoaderRunnable::RunInternal fails by canceling things with its actual failure code, so we don't have to guess which failed loads are actual failures and which are just canceled via this mechanism. r=baku,khuey (388543fbc3)
- Bug 1251369. Use an AutoJSAPI that reports its own exceptions around the main runloop in workers. r=khuey (28b33287cd)
- Bug 1251518. Fix js::ErrorReportToString to make a bit more sense, and change worker code to not use it anyway, so it matches the mainthread code. r=bholley,terrence (a48a40de90)
- Bug 1254380 part 2. Go ahead and log the stack from our exception in AutoJSAPI::ReportException even if we don't have a window. r=bholley (64532b6017)
- Bug 1212328 - Clean up some JSErrorReport-related code. r=Waldo,bz (d5aa611edc)
- Bug 1255192 part 1. Remove the JSContext argument of JS::ExceptionStackOrNull. r=bholley (39b631d5ad)
- bug 1252687 - make the ctor for CycleCollectorStats constexpr r=mccr8 (9e8168d8ac)
- Bug 1254380 part 3. Skip firing error events for mainthread out of memory exceptions via AutoJSAPI::ReportException. r=bholley (d5e4e7dc29)
- Bug 1254230 kinda-fix. Make sure to never send script errors with stacks attached to the console service if the associated windows have already had FreeInnerObjects called on them. r=bholley (8c379fe0e0)
- Bug 1255192 part 2. Clean up the JSContext usage around xpc::FindExceptionStackForConsoleReport now that it just needs a JSContext for rooting. r=bholley (cade862491)
- Bug 1255201. Improve the stack handling in nsXPCComponents_Utils::ReportError for the DOMException case to include the stack from the DOMException. r=bholley (fc6c065284)
- Bug 1257919 part 6. Make the filename getter on JSStackFrame take an explicit JSContext. r=khuey (cde115b789)
- Bug 1257919 part 7. Make the name getter on JSStackFrame take an explicit JSContext. r=khuey (d7466e9eab)
- Bug 1257919 part 8. Make the line/column number getters on JSStackFrame take an explicit JSContext. r=khuey (b8766b98b2)
- Bug 1257919 part 9. Make the asyncCause/asyncCaller getters on JSStackFrame take an explicit JSContext. r=khuey (b776ff9c6d)
- Bug 1257919 part 10. Make the caller and formattedStack getters on JSStackFrame take an explicit JSContext. r=khuey (dc4d3d9091)
- Bug 1252091. Add/RemoveFeature don't need a JSContext argument. r=khuey (5be6253a67)
- Bug 1252123. Remove some unnecessary JSContext arguments from worker ScriptLoader methods. r=khuey (1657a35268)
- Bug 1255181. Remove AutoJSAPI::InitWithLegacyErrorReporting. r=bholley (5ee7ac506e)
- Bug 1254847 part 1. Take ownership of error reporting on the AutoEntryScript in nsXPCWrappedJSClass::DelegatedQueryInterface. r=bholley (62d987b030)
- make style wrong again.... (fa4e6cfbc1)
- Bug 1254847 part 2. Change nsJSNPRuntime to always use AutoEntryScript and always take ownership of error reporting. r=bholley (d24cb80622)
- Bug 1251655 - Remove support for JavaScript-global-constructor-prototype-alias. r=bz. (2b354ea423)
- Bug 1251655 - Remove support for JavaScript-DOM-class and JavaScript-DOM-interface. r=bz. (dd6786ea57)
- Bug 1251275. Switch to using an AutoEntryScript in WorkerPrivate::RunExpiredTimeouts. r=khuey (f10d1b0dec)
- Bug 1072144 part 1. Just release-assert that Promise::Resolve does not fail in service worker code. It can only do that on OOM or overrecursion anyway, and overrecursion is not likely if we're coming right off a runnable. r=khuey (ba4c89a3bc)
- Bug 1072144 part 2. When UnregisterWorker tries to ScheduleWorker and that throws, just suppress the exception: there is no good place to report it anyway. r=khuey (ca563ec5cd)
- Bug 1072144 part 3. Hoist the exception reporting out of WorkerRunnable::PostRun into WorkerRunnable::Run and make it unconditional. r=khuey (9914acd4a6)
- Bug 1252221. When GetOrCreateGlobalScope fails while trying to run a ScriptExecutorRunnable::WorkerRun, just suppress the exception, because there is no way to report it without a compartment to work with. r=khuey (abcc9df148)
- Bug 1072144 part 4. Add a WorkerRunnable::PreRun so that we can move worker global creation to it and always have an AutoEntryScript by the time we're evaluating the main worker script. r=khuey (007b528868)
- Bug 1251276 part 1. Change WorkerPrivate::CancelAllTimeouts to no longer call RunExpiredTimeouts. r=khuey (6b937370a1)
- Bug 1251276 part 2. Remove the JSContext argument of WorkerPrivate::CancelAllTimeouts. r=khuey (336b788e03)
- Bug 1251380. Change things so that WorkerPrivate::NotifyInternal (hopefully) never throws. r=khuey (1d4863f83a)
- Bug 1254846. Add an AutoEntryScript constructor that takes a JSObject instead of an nsIGlobalObject, for convenience. r=bholley (693857f9b0)
- Bug 1255706 part 1. Remove JSContext argument from WorkerPrivate constructor. r=khuey (0486bdb01c)
- Bug 1255706 part 2. Remove JSContext argument from WorkerPrivate::Terminate. r=khuey (f0b62de092)
- Bug 1257568. Remove the JSContext argument of WorkerPrivate::Kill. r=khuey (ebe7d247b5)
- Bug 1252189. Remove the unnecessary JSContext argument from WorkerPrivate::FreezeInternal/ThawInternal. r=khuey (22b137b05e)
- Bug 1119490 - Expose the URL constructor to WorkerDebuggerGlobalScope;r=khuey (6f4fc13e1e)
- Bug 1241841 - Clear the worker's debugger event queue before destroying its context;r=khuey (a1e8dd4b2d)
- Bug 1249950 - Add Performance Markers for MessagePort - patch 1 - remove non-useful 'explicit', r=smaug (8a014b53e6)
- Bug 1249950 - Add Performance Markers for MessagePort - patch 2, r=smaug, r=vporof (560caf0ae1)
- bug 1250486 - make the ComponentsSH ctor constexpr r=bz (1c441dbb0f)
- Bug 1257032: Make files in dom/workers actually build without unification. r=baku (6ab4ae0b65)
- Bug 1241522 - handle OOM in nsExpatDriver::HandleCharacterData; r=hsivonen (b652220cdc)
- Bug 1219482: Replace PRLogModuleInfo with LazyLogModule in various files.r=benjamin (5fd5e8dbc8)
- Bug 1238545 - Remove nsISimpleUnicharStreamFactory; r=froydnj (f0018c5b16)
- Bug 1257335. Replace some AutoSafeJSContext uses with AutoJSAPI or AutoJSContext uses. r=bholley (7baf79deb7)
- Bug 1247635 - Unify PostMessageRunnable and DispatchEventRunnable in MessagePort.cpp, r=smaug (df2765c215)
- Bug 1250572 - Force a parent object in MessagePort/Channel and in StructuredCloneHolder, r=smaug (2a929d59d1)
- Bug 1255375 - MessagePort should not leak if DispatchMessage() fails, r=smaug (0a5cdebfb0)
- Bug 1251272. Remove the dead code in ReportErrorRunnable::ReportError that could fail, and make it infallible. r=khuey (89e80694d0)
- Bug 1072144 part 5. Stop fiddling with compartments on the JSContext before calling PostRun in WorkerRunnable::Run. Add some documentation explaining what's going on. r=khuey (91f4bb6a7c)
- Bug 1072144 part 6. Switch WorkerRunnable::Run to calling TakeOwnershipOfErrorReporting on its AutoJSAPI/AutoEntryScript and remove the remaining JS_ReportPendingException callers in worker code. r=khuey (405d9e0282)
- Bug 1179548 - Close the windows opened in private browsing worker tests; r=baku (acf3430b69)
- Bug 1179753 - Use pushPrefEnv more in worker tests; r=baku (4bfd949c72)
- Bug 1134224 - More test for test_bug1132395.html, r=ehsan (626eb100cd)
- Bug 1134224 - onerror for test_bug1132395.html, r=ehsan (147195f57e)
- Bug 1207635 - get rid of dom.workers.sharedWorkers.enabled pref, r=khuey (22fe2965c6)
- Bug 1252592. JS warnings should not trigger error events on shared workers. r=khuey (7f05c2c00d)
- Bug 1251308; r=luke (3cbec95738)
- Bug 1246838 - Handle const qualifiers and references better in Variant. r=waldo (30da6e3ebf)
- Bug 1254565 - Allow passing matchers as rvalues to Variant::match. r=froydnj (1dd799fb0a)
- Bug 1246841 - Allow construction of Variant values using type inference. r=waldo (6ba3e6704c)
- Bug 1250666 - Forward Variant's move constructor argument correctly to the underlying variant type. r=waldo (7353a53bf0)
- Bug 1252185. Remove the dead "target" variable from CloseEventRunnable::WorkerRun. r=khuey (be172da10b)
- Bug 1253059: Use fallible allocation in the worker error reporter. r=baku (963222bdd4)
- Bug 1253199 - MessagePort should handle the dispatching a message when the parent window is gone, r=smaug (d552e3cd9e)
- Bug 1252839 - Remove some if stmt after allocation with 'new' - patch 2, r=bz (3c7eb959bc)
- Bug 1252839 - Remove some if stmt after allocation with 'new' - patch 1, r=bz (85067dbfb6)
- Bug 1254855. Switch AutoEntryScripts in nsDirectoryViewer to take ownership of error reporting. r=bholley (8c10532323)
- Bug 1252565 part 1. Push the script environment preparer bits up from XPCJSRuntime to CycleCollectedJSRuntime, because we need them on workers to do ctypes on workers properly. r=bholley (aecf2595dd)
- Bug 1252565 part 2. Make dom::WarningOnlyErrorReporter handle workers. r=bholley (f415b8868b)
- Bug 1244222 - Check for function interfaces in DelegatedQueryInterface. r=bz (d213eec83c)
- Bug 1254393. Take ownership of error reporting on the AutoEntryScript in nsXPCWrappedJSClass::CallMethod. r=bholley (4765b501c0)
- Bug 1251769 - Remove remaining references to MOZILLA_XPCOMRT_API from mfbt. r=froydnj (236adc1d4c)
- Bug 1247835 (part 0) - Minor comment and style tweaks in BinarySearch.h. r=luke. (db04793721)
- Bug 1244074 - Part 1: Move SheetParsingMode to a separate file. r=dholbert (290adaadea)
- Bug 1244074 - Part 2: Add HandleRefPtr for refcounting StyleSheetHandles. r=dholbert r=waldo (8549b24392)
- Bug 1244068 - Part 1: Add enum to represent the style system backend type. r=dholbert (c2e53feaf2)
- Bug 1244068 - Part 2: Add skeleton ServoStyleSet and a StyleSetHandle smart pointer. r=dholbert (71a5c28629)
- Bug 1244068 - Part 3: Factor out nsStyleSet getting in RestyleManager/ElementRestyler. r=dholbert (9e9f4f2e80)
- Bug 1245406: In ReflowBlockFrame, use Maybe<> to destroy & reconstruct a stack-allocated object, instead of an explicit call to destructor & placement 'new'. r=dbaron (d36858b818)
- Bug 1244068 - Part 4: Use StyleSetHandle instead of concrete style set class in most places. r=dholbert (93f9bcf799)
- Bug 1244074 - Part 3: Add skeleton ServoStyleSheet and a StyleSheetHandle smart pointer. r=dholbert (5b4fbdce38)
- Bug 1195173 - Apply CSP to preloaded styles within layout/style/Loader.cpp (r=bz) (d1ba920fd3)
- Bug 1245681 - Fix addOverrideStyleSheet. r=bz (64099eac73)
- Bug 1244074 - Part 4: Use StyleSheetHandle instead of concrete style sheet class in most places. r=dholberti (867470ac83)
- Bug 1246013 (part 1) - Store a copy of the ETLDEntry directly in DomainEntry instead of a pointer to it. r=jduell. (587b3a9fb7)
- Bug 1246013 (part 2) - Change "explicit/xpcom/effective-TLD-service" path to the more sensible "explicit/network/effective-TLD-service". r=jduell. (2e0df6f28f)
- Bug 1247835 (part 1) - Use binary search instead of a hash table in nsEffectiveTLDService. r=jduell. (685dae01c0)
- Bug 1257121 part 1 - Use struct for passing some params of font metrics. r=jfkthame (1dfd7a7429)
- Bug 1257121 part 2 - Merge nsFontMetrics::Init to the constructor and remove unused failure handling code. r=jfkthame (0cdc441511)
- Bug 1257121 part 3 - Add GetInflatedFontMetricsForFrame function to simplify a common use pattern. r=jfkthame (d9630ebd1b)
- Bug 1257121 part 4 - Use return value rather than out param to retur font metrics. r=jfkthame (c9a5b1d1dd)
- Bug 1257121 part 5 - Make nsDeviceContext::mFontCache a RefPtr. r=jfkthame (9c53238a6a)
2024-01-29 15:26:23 +08:00

1126 lines
39 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "nsMathMLElement.h"
#include "base/compiler_specific.h"
#include "mozilla/ArrayUtils.h"
#include "nsGkAtoms.h"
#include "nsCRT.h"
#include "nsLayoutStylesheetCache.h"
#include "nsRuleData.h"
#include "nsCSSValue.h"
#include "nsCSSParser.h"
#include "nsMappedAttributes.h"
#include "nsStyleConsts.h"
#include "nsIDocument.h"
#include "nsIPresShell.h"
#include "nsPresContext.h"
#include "mozAutoDocUpdate.h"
#include "nsIScriptError.h"
#include "nsContentUtils.h"
#include "nsIURI.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/EventStates.h"
#include "mozilla/dom/ElementBinding.h"
using namespace mozilla;
using namespace mozilla::dom;
//----------------------------------------------------------------------
// nsISupports methods:
NS_IMPL_ISUPPORTS_INHERITED(nsMathMLElement, nsMathMLElementBase,
nsIDOMElement, nsIDOMNode, Link)
static nsresult
WarnDeprecated(const char16_t* aDeprecatedAttribute,
const char16_t* aFavoredAttribute, nsIDocument* aDocument)
{
const char16_t *argv[] =
{ aDeprecatedAttribute, aFavoredAttribute };
return nsContentUtils::
ReportToConsole(nsIScriptError::warningFlag,
NS_LITERAL_CSTRING("MathML"), aDocument,
nsContentUtils::eMATHML_PROPERTIES,
"DeprecatedSupersededBy", argv, 2);
}
static nsresult
ReportLengthParseError(const nsString& aValue, nsIDocument* aDocument)
{
const char16_t *arg = aValue.get();
return nsContentUtils::
ReportToConsole(nsIScriptError::errorFlag,
NS_LITERAL_CSTRING("MathML"), aDocument,
nsContentUtils::eMATHML_PROPERTIES,
"LengthParsingError", &arg, 1);
}
static nsresult
ReportParseErrorNoTag(const nsString& aValue,
nsIAtom* aAtom,
nsIDocument* aDocument)
{
const char16_t *argv[] =
{ aValue.get(), aAtom->GetUTF16String() };
return nsContentUtils::
ReportToConsole(nsIScriptError::errorFlag,
NS_LITERAL_CSTRING("MathML"), aDocument,
nsContentUtils::eMATHML_PROPERTIES,
"AttributeParsingErrorNoTag", argv, 2);
}
nsMathMLElement::nsMathMLElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
: nsMathMLElementBase(aNodeInfo),
ALLOW_THIS_IN_INITIALIZER_LIST(Link(this)),
mIncrementScriptLevel(false)
{
}
nsMathMLElement::nsMathMLElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
: nsMathMLElementBase(aNodeInfo),
ALLOW_THIS_IN_INITIALIZER_LIST(Link(this)),
mIncrementScriptLevel(false)
{
}
nsresult
nsMathMLElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
nsIContent* aBindingParent,
bool aCompileEventHandlers)
{
Link::ResetLinkState(false, Link::ElementHasHref());
nsresult rv = nsMathMLElementBase::BindToTree(aDocument, aParent,
aBindingParent,
aCompileEventHandlers);
NS_ENSURE_SUCCESS(rv, rv);
if (aDocument) {
aDocument->RegisterPendingLinkUpdate(this);
}
nsIDocument* doc = GetComposedDoc();
if (doc) {
if (!doc->GetMathMLEnabled()) {
// Enable MathML and setup the style sheet during binding, not element
// construction, because we could move a MathML element from the document
// that created it to another document.
auto cache = nsLayoutStylesheetCache::For(doc->GetStyleBackendType());
doc->SetMathMLEnabled();
doc->EnsureOnDemandBuiltInUASheet(cache->MathMLSheet());
// Rebuild style data for the presshell, because style system
// optimizations may have taken place assuming MathML was disabled.
// (See nsRuleNode::CheckSpecifiedProperties.)
nsCOMPtr<nsIPresShell> shell = doc->GetShell();
if (shell) {
shell->GetPresContext()->
PostRebuildAllStyleDataEvent(nsChangeHint(0), eRestyle_Subtree);
}
}
}
return rv;
}
void
nsMathMLElement::UnbindFromTree(bool aDeep, bool aNullParent)
{
// If this link is ever reinserted into a document, it might
// be under a different xml:base, so forget the cached state now.
Link::ResetLinkState(false, Link::ElementHasHref());
nsIDocument* doc = GetCurrentDoc();
if (doc) {
doc->UnregisterPendingLinkUpdate(this);
}
nsMathMLElementBase::UnbindFromTree(aDeep, aNullParent);
}
bool
nsMathMLElement::ParseAttribute(int32_t aNamespaceID,
nsIAtom* aAttribute,
const nsAString& aValue,
nsAttrValue& aResult)
{
if (aNamespaceID == kNameSpaceID_None) {
if (IsMathMLElement(nsGkAtoms::math) && aAttribute == nsGkAtoms::mode) {
WarnDeprecated(nsGkAtoms::mode->GetUTF16String(),
nsGkAtoms::display->GetUTF16String(), OwnerDoc());
}
if (aAttribute == nsGkAtoms::color) {
WarnDeprecated(nsGkAtoms::color->GetUTF16String(),
nsGkAtoms::mathcolor_->GetUTF16String(), OwnerDoc());
}
if (aAttribute == nsGkAtoms::color ||
aAttribute == nsGkAtoms::mathcolor_ ||
aAttribute == nsGkAtoms::background ||
aAttribute == nsGkAtoms::mathbackground_) {
return aResult.ParseColor(aValue);
}
}
return nsMathMLElementBase::ParseAttribute(aNamespaceID, aAttribute,
aValue, aResult);
}
static Element::MappedAttributeEntry sMtableStyles[] = {
{ &nsGkAtoms::width },
{ nullptr }
};
static Element::MappedAttributeEntry sTokenStyles[] = {
{ &nsGkAtoms::mathsize_ },
{ &nsGkAtoms::fontsize_ },
{ &nsGkAtoms::color },
{ &nsGkAtoms::fontfamily_ },
{ &nsGkAtoms::fontstyle_ },
{ &nsGkAtoms::fontweight_ },
{ &nsGkAtoms::mathvariant_},
{ nullptr }
};
static Element::MappedAttributeEntry sEnvironmentStyles[] = {
{ &nsGkAtoms::scriptlevel_ },
{ &nsGkAtoms::scriptminsize_ },
{ &nsGkAtoms::scriptsizemultiplier_ },
{ &nsGkAtoms::background },
{ nullptr }
};
static Element::MappedAttributeEntry sCommonPresStyles[] = {
{ &nsGkAtoms::mathcolor_ },
{ &nsGkAtoms::mathbackground_ },
{ nullptr }
};
static Element::MappedAttributeEntry sDirStyles[] = {
{ &nsGkAtoms::dir },
{ nullptr }
};
bool
nsMathMLElement::IsAttributeMapped(const nsIAtom* aAttribute) const
{
static const MappedAttributeEntry* const mtableMap[] = {
sMtableStyles,
sCommonPresStyles
};
static const MappedAttributeEntry* const tokenMap[] = {
sTokenStyles,
sCommonPresStyles,
sDirStyles
};
static const MappedAttributeEntry* const mstyleMap[] = {
sTokenStyles,
sEnvironmentStyles,
sCommonPresStyles,
sDirStyles
};
static const MappedAttributeEntry* const commonPresMap[] = {
sCommonPresStyles
};
static const MappedAttributeEntry* const mrowMap[] = {
sCommonPresStyles,
sDirStyles
};
// We don't support mglyph (yet).
if (IsAnyOfMathMLElements(nsGkAtoms::ms_, nsGkAtoms::mi_, nsGkAtoms::mn_,
nsGkAtoms::mo_, nsGkAtoms::mtext_,
nsGkAtoms::mspace_))
return FindAttributeDependence(aAttribute, tokenMap);
if (IsAnyOfMathMLElements(nsGkAtoms::mstyle_, nsGkAtoms::math))
return FindAttributeDependence(aAttribute, mstyleMap);
if (IsMathMLElement(nsGkAtoms::mtable_))
return FindAttributeDependence(aAttribute, mtableMap);
if (IsMathMLElement(nsGkAtoms::mrow_))
return FindAttributeDependence(aAttribute, mrowMap);
if (IsAnyOfMathMLElements(nsGkAtoms::maction_,
nsGkAtoms::maligngroup_,
nsGkAtoms::malignmark_,
nsGkAtoms::menclose_,
nsGkAtoms::merror_,
nsGkAtoms::mfenced_,
nsGkAtoms::mfrac_,
nsGkAtoms::mover_,
nsGkAtoms::mpadded_,
nsGkAtoms::mphantom_,
nsGkAtoms::mprescripts_,
nsGkAtoms::mroot_,
nsGkAtoms::msqrt_,
nsGkAtoms::msub_,
nsGkAtoms::msubsup_,
nsGkAtoms::msup_,
nsGkAtoms::mtd_,
nsGkAtoms::mtr_,
nsGkAtoms::munder_,
nsGkAtoms::munderover_,
nsGkAtoms::none)) {
return FindAttributeDependence(aAttribute, commonPresMap);
}
return false;
}
nsMapRuleToAttributesFunc
nsMathMLElement::GetAttributeMappingFunction() const
{
// 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;
}
/* static */ bool
nsMathMLElement::ParseNamedSpaceValue(const nsString& aString,
nsCSSValue& aCSSValue,
uint32_t aFlags)
{
int32_t i = 0;
// 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;
}
}
if (0 != i) {
aCSSValue.SetFloatValue(float(i)/float(18), eCSSUnit_EM);
return true;
}
return false;
}
// 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."
//
// "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:
//
// 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)"
//
/* static */ bool
nsMathMLElement::ParseNumericValue(const nsString& aString,
nsCSSValue& aCSSValue,
uint32_t aFlags,
nsIDocument* aDocument)
{
nsAutoString str(aString);
str.CompressWhitespace(); // aString is const in this code...
int32_t stringLength = str.Length();
if (!stringLength) {
if (!(aFlags & PARSE_SUPPRESS_WARNINGS)) {
ReportLengthParseError(aString, aDocument);
}
return false;
}
if (ParseNamedSpaceValue(aString, aCSSValue, aFlags)) {
return true;
}
nsAutoString number, unit;
// see if the negative sign is there
int32_t i = 0;
char16_t c = str[0];
if (c == '-') {
number.Append(c);
i++;
}
// Gather up characters that make up the number
bool gotDot = false;
for ( ; i < stringLength; i++) {
c = str[i];
if (gotDot && c == '.') {
if (!(aFlags & PARSE_SUPPRESS_WARNINGS)) {
ReportLengthParseError(aString, aDocument);
}
return false; // two dots encountered
}
else if (c == '.')
gotDot = true;
else if (!nsCRT::IsAsciiDigit(c)) {
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);
}
// Convert number to floating point
nsresult errorCode;
float floatValue = number.ToFloat(&errorCode);
if (NS_FAILED(errorCode)) {
if (!(aFlags & PARSE_SUPPRESS_WARNINGS)) {
ReportLengthParseError(aString, aDocument);
}
return false;
}
if (floatValue < 0 && !(aFlags & PARSE_ALLOW_NEGATIVE)) {
if (!(aFlags & PARSE_SUPPRESS_WARNINGS)) {
ReportLengthParseError(aString, aDocument);
}
return false;
}
nsCSSUnit cssUnit;
if (unit.IsEmpty()) {
if (aFlags & PARSE_ALLOW_UNITLESS) {
// no explicit unit, this is a number that will act as a multiplier
if (!(aFlags & PARSE_SUPPRESS_WARNINGS)) {
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
NS_LITERAL_CSTRING("MathML"), aDocument,
nsContentUtils::eMATHML_PROPERTIES,
"UnitlessValuesAreDeprecated");
}
if (aFlags & CONVERT_UNITLESS_TO_PERCENT) {
aCSSValue.SetPercentValue(floatValue);
return true;
}
else
cssUnit = eCSSUnit_Number;
} else {
// We are supposed to have a unit, but there isn't one.
// If the value is 0 we can just call it "pixels" otherwise
// this is illegal.
if (floatValue != 0.0) {
if (!(aFlags & PARSE_SUPPRESS_WARNINGS)) {
ReportLengthParseError(aString, aDocument);
}
return false;
}
cssUnit = eCSSUnit_Pixel;
}
}
else if (unit.EqualsLiteral("%")) {
aCSSValue.SetPercentValue(floatValue / 100.0f);
return true;
}
else if (unit.EqualsLiteral("em")) cssUnit = eCSSUnit_EM;
else if (unit.EqualsLiteral("ex")) cssUnit = eCSSUnit_XHeight;
else if (unit.EqualsLiteral("px")) cssUnit = eCSSUnit_Pixel;
else if (unit.EqualsLiteral("in")) cssUnit = eCSSUnit_Inch;
else if (unit.EqualsLiteral("cm")) cssUnit = eCSSUnit_Centimeter;
else if (unit.EqualsLiteral("mm")) cssUnit = eCSSUnit_Millimeter;
else if (unit.EqualsLiteral("pt")) cssUnit = eCSSUnit_Point;
else if (unit.EqualsLiteral("pc")) cssUnit = eCSSUnit_Pica;
else if (unit.EqualsLiteral("q")) cssUnit = eCSSUnit_Quarter;
else { // unexpected unit
if (!(aFlags & PARSE_SUPPRESS_WARNINGS)) {
ReportLengthParseError(aString, aDocument);
}
return false;
}
aCSSValue.SetFloatValue(floatValue, cssUnit);
return true;
}
void
nsMathMLElement::MapMathMLAttributesInto(const nsMappedAttributes* aAttributes,
nsRuleData* aData)
{
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Font)) {
// 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_);
nsCSSValue* scriptSizeMultiplier =
aData->ValueForScriptSizeMultiplier();
if (value && value->Type() == nsAttrValue::eString &&
scriptSizeMultiplier->GetUnit() == eCSSUnit_Null) {
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) {
scriptSizeMultiplier->SetFloatValue(floatValue, eCSSUnit_Number);
} else {
ReportParseErrorNoTag(str,
nsGkAtoms::scriptsizemultiplier_,
aData->mPresContext->Document());
}
}
}
// 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_);
nsCSSValue* scriptMinSize = aData->ValueForScriptMinSize();
if (value && value->Type() == nsAttrValue::eString &&
scriptMinSize->GetUnit() == eCSSUnit_Null) {
ParseNumericValue(value->GetStringValue(), *scriptMinSize,
PARSE_ALLOW_UNITLESS | CONVERT_UNITLESS_TO_PERCENT,
aData->mPresContext->Document());
if (scriptMinSize->GetUnit() == eCSSUnit_Percent) {
scriptMinSize->SetFloatValue(8.0 * scriptMinSize->GetPercentValue(),
eCSSUnit_Point);
}
}
// 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_);
nsCSSValue* scriptLevel = aData->ValueForScriptLevel();
if (value && value->Type() == nsAttrValue::eString &&
scriptLevel->GetUnit() == eCSSUnit_Null) {
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 == '-') {
scriptLevel->SetIntValue(intValue, eCSSUnit_Integer);
} else {
scriptLevel->SetFloatValue(intValue, eCSSUnit_Number);
}
} else {
ReportParseErrorNoTag(str,
nsGkAtoms::scriptlevel_,
aData->mPresContext->Document());
}
}
}
// 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.
//
bool parseSizeKeywords = true;
value = aAttributes->GetAttr(nsGkAtoms::mathsize_);
if (!value) {
parseSizeKeywords = false;
value = aAttributes->GetAttr(nsGkAtoms::fontsize_);
if (value) {
WarnDeprecated(nsGkAtoms::fontsize_->GetUTF16String(),
nsGkAtoms::mathsize_->GetUTF16String(),
aData->mPresContext->Document());
}
}
nsCSSValue* fontSize = aData->ValueForFontSize();
if (value && value->Type() == nsAttrValue::eString &&
fontSize->GetUnit() == eCSSUnit_Null) {
nsAutoString str(value->GetStringValue());
if (!ParseNumericValue(str, *fontSize, PARSE_SUPPRESS_WARNINGS |
PARSE_ALLOW_UNITLESS | CONVERT_UNITLESS_TO_PERCENT,
nullptr)
&& 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])) {
fontSize->SetIntValue(values[i], eCSSUnit_Enumerated);
break;
}
}
}
}
// 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_);
nsCSSValue* fontFamily = aData->ValueForFontFamily();
if (value) {
WarnDeprecated(nsGkAtoms::fontfamily_->GetUTF16String(),
nsGkAtoms::mathvariant_->GetUTF16String(),
aData->mPresContext->Document());
}
if (value && value->Type() == nsAttrValue::eString &&
fontFamily->GetUnit() == eCSSUnit_Null) {
nsCSSParser parser;
parser.ParseFontFamilyListString(value->GetStringValue(),
nullptr, 0, *fontFamily);
}
// 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.
nsCSSValue* fontStyle = aData->ValueForFontStyle();
value = aAttributes->GetAttr(nsGkAtoms::fontstyle_);
if (value) {
WarnDeprecated(nsGkAtoms::fontstyle_->GetUTF16String(),
nsGkAtoms::mathvariant_->GetUTF16String(),
aData->mPresContext->Document());
if (value->Type() == nsAttrValue::eString &&
fontStyle->GetUnit() == eCSSUnit_Null) {
nsAutoString str(value->GetStringValue());
str.CompressWhitespace();
if (str.EqualsASCII("normal")) {
fontStyle->SetIntValue(NS_STYLE_FONT_STYLE_NORMAL,
eCSSUnit_Enumerated);
} else if (str.EqualsASCII("italic")) {
fontStyle->SetIntValue(NS_STYLE_FONT_STYLE_ITALIC,
eCSSUnit_Enumerated);
}
}
}
// 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.
nsCSSValue* fontWeight = aData->ValueForFontWeight();
value = aAttributes->GetAttr(nsGkAtoms::fontweight_);
if (value) {
WarnDeprecated(nsGkAtoms::fontweight_->GetUTF16String(),
nsGkAtoms::mathvariant_->GetUTF16String(),
aData->mPresContext->Document());
if (value->Type() == nsAttrValue::eString &&
fontWeight->GetUnit() == eCSSUnit_Null) {
nsAutoString str(value->GetStringValue());
str.CompressWhitespace();
if (str.EqualsASCII("normal")) {
fontWeight->SetIntValue(NS_STYLE_FONT_WEIGHT_NORMAL,
eCSSUnit_Enumerated);
} else if (str.EqualsASCII("bold")) {
fontWeight->SetIntValue(NS_STYLE_FONT_WEIGHT_BOLD,
eCSSUnit_Enumerated);
}
}
}
// 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>)
//
nsCSSValue* mathVariant = aData->ValueForMathVariant();
value = aAttributes->GetAttr(nsGkAtoms::mathvariant_);
if (value && value->Type() == nsAttrValue::eString &&
mathVariant->GetUnit() == eCSSUnit_Null) {
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) {
if (str.EqualsASCII(sizes[i])) {
mathVariant->SetIntValue(values[i], eCSSUnit_Enumerated);
break;
}
}
}
}
// mathbackground
//
// "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."
//
// values: color | "transparent"
// 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"
//
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Background)) {
const nsAttrValue* value =
aAttributes->GetAttr(nsGkAtoms::mathbackground_);
if (!value) {
value = aAttributes->GetAttr(nsGkAtoms::background);
if (value) {
WarnDeprecated(nsGkAtoms::background->GetUTF16String(),
nsGkAtoms::mathbackground_->GetUTF16String(),
aData->mPresContext->Document());
}
}
nsCSSValue* backgroundColor = aData->ValueForBackgroundColor();
if (value && backgroundColor->GetUnit() == eCSSUnit_Null) {
nscolor color;
if (value->GetColorValue(color)) {
backgroundColor->SetColorValue(color);
}
}
}
// 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
//
// "Specified the color for the token. Deprecated in favor of mathcolor."
//
// values: color
// default: inherited
//
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Color)) {
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::mathcolor_);
if (!value) {
value = aAttributes->GetAttr(nsGkAtoms::color);
if (value) {
WarnDeprecated(nsGkAtoms::color->GetUTF16String(),
nsGkAtoms::mathcolor_->GetUTF16String(),
aData->mPresContext->Document());
}
}
nscolor color;
nsCSSValue* colorValue = aData->ValueForColor();
if (value && value->GetColorValue(color) &&
colorValue->GetUnit() == eCSSUnit_Null) {
colorValue->SetColorValue(color);
}
}
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Position)) {
// 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
//
nsCSSValue* width = aData->ValueForWidth();
if (width->GetUnit() == eCSSUnit_Null) {
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::width);
// This does not handle auto and unitless values
if (value && value->Type() == nsAttrValue::eString) {
ParseNumericValue(value->GetStringValue(), *width, 0,
aData->mPresContext->Document());
}
}
}
// 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.
// [...] The overall directionality is usually set on the math, but may also
// be switched for individual subformula by using the dir attribute on mrow
// or mstyle elements."
//
// 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
//
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Visibility)) {
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::dir);
nsCSSValue* direction = aData->ValueForDirection();
if (value && value->Type() == nsAttrValue::eString &&
direction->GetUnit() == eCSSUnit_Null) {
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) {
if (str.EqualsASCII(dirs[i])) {
direction->SetIntValue(dirValues[i], eCSSUnit_Enumerated);
break;
}
}
}
}
}
nsresult
nsMathMLElement::PreHandleEvent(EventChainPreVisitor& aVisitor)
{
nsresult rv = Element::PreHandleEvent(aVisitor);
NS_ENSURE_SUCCESS(rv, rv);
return PreHandleEventForLinks(aVisitor);
}
nsresult
nsMathMLElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
{
return PostHandleEventForLinks(aVisitor);
}
NS_IMPL_ELEMENT_CLONE(nsMathMLElement)
EventStates
nsMathMLElement::IntrinsicState() const
{
return Link::LinkState() | nsMathMLElementBase::IntrinsicState() |
(mIncrementScriptLevel ?
NS_EVENT_STATE_INCREMENT_SCRIPT_LEVEL : EventStates());
}
bool
nsMathMLElement::IsNodeOfType(uint32_t aFlags) const
{
return !(aFlags & ~eCONTENT);
}
void
nsMathMLElement::SetIncrementScriptLevel(bool aIncrementScriptLevel,
bool aNotify)
{
if (aIncrementScriptLevel == mIncrementScriptLevel)
return;
mIncrementScriptLevel = aIncrementScriptLevel;
NS_ASSERTION(aNotify, "We always notify!");
UpdateState(true);
}
bool
nsMathMLElement::IsFocusableInternal(int32_t* aTabIndex, bool aWithMouse)
{
nsCOMPtr<nsIURI> uri;
if (IsLink(getter_AddRefs(uri))) {
if (aTabIndex) {
*aTabIndex = ((sTabFocusModel & eTabFocus_linksMask) == 0 ? -1 : 0);
}
return true;
}
if (aTabIndex) {
*aTabIndex = -1;
}
return false;
}
bool
nsMathMLElement::IsLink(nsIURI** aURI) const
{
// http://www.w3.org/TR/2010/REC-MathML3-20101021/chapter6.html#interf.link
// The REC says that the following elements should not be linking elements:
if (IsAnyOfMathMLElements(nsGkAtoms::mprescripts_, nsGkAtoms::none,
nsGkAtoms::malignmark_, nsGkAtoms::maligngroup_)) {
*aURI = nullptr;
return false;
}
bool hasHref = false;
const nsAttrValue* href = mAttrsAndChildren.GetAttr(nsGkAtoms::href,
kNameSpaceID_None);
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."
hasHref = true;
} else {
// 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
// result is poorly specified. Either way, we return false.
static nsIContent::AttrValuesArray sTypeVals[] =
{ &nsGkAtoms::_empty, &nsGkAtoms::simple, nullptr };
static nsIContent::AttrValuesArray sShowVals[] =
{ &nsGkAtoms::_empty, &nsGkAtoms::_new, &nsGkAtoms::replace, nullptr };
static nsIContent::AttrValuesArray sActuateVals[] =
{ &nsGkAtoms::_empty, &nsGkAtoms::onRequest, nullptr };
// Optimization: check for href first for early return
href = mAttrsAndChildren.GetAttr(nsGkAtoms::href,
kNameSpaceID_XLink);
if (href &&
FindAttrValueIn(kNameSpaceID_XLink, nsGkAtoms::type,
sTypeVals, eCaseMatters) !=
nsIContent::ATTR_VALUE_NO_MATCH &&
FindAttrValueIn(kNameSpaceID_XLink, nsGkAtoms::show,
sShowVals, eCaseMatters) !=
nsIContent::ATTR_VALUE_NO_MATCH &&
FindAttrValueIn(kNameSpaceID_XLink, nsGkAtoms::actuate,
sActuateVals, eCaseMatters) !=
nsIContent::ATTR_VALUE_NO_MATCH) {
hasHref = true;
}
}
if (hasHref) {
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
// Get absolute URI
nsAutoString hrefStr;
href->ToString(hrefStr);
nsContentUtils::NewURIWithDocumentCharset(aURI, hrefStr,
OwnerDoc(), baseURI);
// must promise out param is non-null if we return true
return !!*aURI;
}
*aURI = nullptr;
return false;
}
void
nsMathMLElement::GetLinkTarget(nsAString& aTarget)
{
const nsAttrValue* target = mAttrsAndChildren.GetAttr(nsGkAtoms::target,
kNameSpaceID_XLink);
if (target) {
target->ToString(aTarget);
}
if (aTarget.IsEmpty()) {
static nsIContent::AttrValuesArray sShowVals[] =
{ &nsGkAtoms::_new, &nsGkAtoms::replace, nullptr };
switch (FindAttrValueIn(kNameSpaceID_XLink, nsGkAtoms::show,
sShowVals, eCaseMatters)) {
case 0:
aTarget.AssignLiteral("_blank");
return;
case 1:
return;
}
OwnerDoc()->GetBaseTarget(aTarget);
}
}
already_AddRefed<nsIURI>
nsMathMLElement::GetHrefURI() const
{
nsCOMPtr<nsIURI> hrefURI;
return IsLink(getter_AddRefs(hrefURI)) ? hrefURI.forget() : nullptr;
}
nsresult
nsMathMLElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
nsIAtom* aPrefix, const nsAString& aValue,
bool aNotify)
{
nsresult rv = nsMathMLElementBase::SetAttr(aNameSpaceID, aName, aPrefix,
aValue, aNotify);
// The ordering of the parent class's SetAttr call and Link::ResetLinkState
// is important here! The attribute is not set until SetAttr returns, and
// we will need the updated attribute value because notifying the document
// 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 ||
aNameSpaceID == kNameSpaceID_XLink)) {
if (aNameSpaceID == kNameSpaceID_XLink) {
WarnDeprecated(MOZ_UTF16("xlink:href"),
MOZ_UTF16("href"), OwnerDoc());
}
Link::ResetLinkState(!!aNotify, true);
}
return rv;
}
nsresult
nsMathMLElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttr,
bool aNotify)
{
nsresult rv = nsMathMLElementBase::UnsetAttr(aNameSpaceID, aAttr, aNotify);
// The ordering of the parent class's UnsetAttr call and Link::ResetLinkState
// is important here! The attribute is not unset until UnsetAttr returns, and
// we will need the updated attribute value because notifying the document
// that content states have changed will call IntrinsicState, which will try
// to get updated information about the visitedness from Link.
if (aAttr == nsGkAtoms::href &&
(aNameSpaceID == kNameSpaceID_None ||
aNameSpaceID == kNameSpaceID_XLink)) {
// Note: just because we removed a single href attr doesn't mean there's no href,
// since there are 2 possible namespaces.
Link::ResetLinkState(!!aNotify, Link::ElementHasHref());
}
return rv;
}
JSObject*
nsMathMLElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
{
return ElementBinding::Wrap(aCx, this, aGivenProto);
}