Bug 1302340 - Allow SVGElement to be focusable when tabindex is -1; r=heycam
authordmu@mozilla.com <dmu@mozilla.com>
Wed, 28 Sep 2016 12:05:28 +0000
changeset 340909 a20c22b2d924
parent 340878 c5621cb6f907
child 340910 1895e4ebd7e8
push id31321
push userkwierso@gmail.com
push dateTue, 07 Feb 2017 01:37:59 +0000
treeherdermozilla-central@4f8b2d44eaa0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1302340
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1302340 - Allow SVGElement to be focusable when tabindex is -1; r=heycam MozReview-Commit-ID: JMTVxYxQF80
dom/svg/nsSVGElement.cpp
dom/svg/nsSVGElement.h
--- a/dom/svg/nsSVGElement.cpp
+++ b/dom/svg/nsSVGElement.cpp
@@ -1126,26 +1126,49 @@ nsSVGElement::GetViewportElement()
 
 already_AddRefed<SVGAnimatedString>
 nsSVGElement::ClassName()
 {
   return mClassAttribute.ToDOMAnimatedString(this);
 }
 
 bool
-nsSVGElement::IsFocusableInternal(int32_t* aTabIndex, bool)
+nsSVGElement::IsSVGFocusable(bool* aIsFocusable, int32_t* aTabIndex)
 {
-  int32_t index = TabIndex();
-
-  if (index == -1) {
-    return false;
+  nsIDocument* doc = GetComposedDoc();
+  if (!doc || doc->HasFlag(NODE_IS_EDITABLE)) {
+    // In designMode documents we only allow focusing the document.
+    if (aTabIndex) {
+      *aTabIndex = -1;
+    }
+
+    *aIsFocusable = false;
+
+    return true;
   }
 
-  *aTabIndex = index;
-  return true;
+  int32_t tabIndex = TabIndex();
+
+  if (aTabIndex) {
+    *aTabIndex = tabIndex;
+  }
+
+  // If a tabindex is specified at all, or the default tabindex is 0, we're focusable
+  *aIsFocusable =
+    tabIndex >= 0 || HasAttr(kNameSpaceID_None, nsGkAtoms::tabindex);
+
+  return false;
+}
+
+bool
+nsSVGElement::IsFocusableInternal(int32_t* aTabIndex, bool aWithMouse)
+{
+  bool isFocusable = false;
+  IsSVGFocusable(&isFocusable, aTabIndex);
+  return isFocusable;
 }
 
 //------------------------------------------------------------------------
 // Helper class: MappedAttrParser, for parsing values of mapped attributes
 
 namespace {
 
 class MOZ_STACK_CLASS MappedAttrParser {
--- a/dom/svg/nsSVGElement.h
+++ b/dom/svg/nsSVGElement.h
@@ -313,16 +313,18 @@ public:
   virtual void ClearAnyCachedPath() {}
   virtual nsIDOMNode* AsDOMNode() final override { return this; }
   virtual bool IsTransformable() { return false; }
 
   // WebIDL
   mozilla::dom::SVGSVGElement* GetOwnerSVGElement();
   nsSVGElement* GetViewportElement();
   already_AddRefed<mozilla::dom::SVGAnimatedString> ClassName();
+
+  virtual bool IsSVGFocusable(bool* aIsFocusable, int32_t* aTabIndex);
   virtual bool IsFocusableInternal(int32_t* aTabIndex, bool aWithMouse) override;
 
 protected:
   virtual JSObject* WrapNode(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
 
 #ifdef DEBUG
   // We define BeforeSetAttr here and mark it final to ensure it is NOT used
   // by SVG elements.