summaryrefslogtreecommitdiffstats
path: root/dom/html/ElementInternals.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dom/html/ElementInternals.cpp')
-rw-r--r--dom/html/ElementInternals.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/dom/html/ElementInternals.cpp b/dom/html/ElementInternals.cpp
index aaf58f818e..9a19744603 100644
--- a/dom/html/ElementInternals.cpp
+++ b/dom/html/ElementInternals.cpp
@@ -22,6 +22,10 @@
#include "nsDebug.h"
#include "nsGenericHTMLElement.h"
+#ifdef ACCESSIBILITY
+# include "nsAccessibilityService.h"
+#endif
+
namespace mozilla::dom {
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(ElementInternals)
@@ -482,4 +486,44 @@ void ElementInternals::InitializeControlNumber() {
mControlNumber = mTarget->OwnerDoc()->GetNextControlNumber();
}
+void ElementInternals::SetAttrElement(nsAtom* aAttr, Element* aElement) {
+ // Accessibility requires that no other attribute changes occur between
+ // AttrElementWillChange and AttrElementChanged. Scripts could cause
+ // this, so don't let them run here. We do this even if accessibility isn't
+ // running so that the JS behavior is consistent regardless of accessibility.
+ // Otherwise, JS might be able to use this difference to determine whether
+ // accessibility is running, which would be a privacy concern.
+ nsAutoScriptBlocker scriptBlocker;
+
+#ifdef ACCESSIBILITY
+ // If the target has this attribute defined then it overrides the defaults
+ // defined here in the Internals instance. In that case we don't need to
+ // notify the change to a11y since the attribute hasn't changed, just the
+ // underlying default. We can set accService to null and not notify.
+ nsAccessibilityService* accService =
+ !mTarget->HasAttr(aAttr) ? GetAccService() : nullptr;
+ if (accService) {
+ accService->NotifyAttrElementWillChange(mTarget, aAttr);
+ }
+#endif
+
+ if (aElement) {
+ mAttrElements.InsertOrUpdate(aAttr, do_GetWeakReference(aElement));
+ } else {
+ mAttrElements.Remove(aAttr);
+ }
+
+#ifdef ACCESSIBILITY
+ if (accService) {
+ accService->NotifyAttrElementChanged(mTarget, aAttr);
+ }
+#endif
+}
+
+Element* ElementInternals::GetAttrElement(nsAtom* aAttr) const {
+ nsWeakPtr weakAttrEl = mAttrElements.Get(aAttr);
+ nsCOMPtr<Element> attrEl = do_QueryReferent(weakAttrEl);
+ return attrEl;
+}
+
} // namespace mozilla::dom