Bug 735251 - don't show focusrings on HTML video / audio elements on non-Windows, r?bz draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Thu, 10 Mar 2016 13:32:55 +0000
changeset 339156 8caf1ff789f7ed06d48a9587480b89860af5df9d
parent 338142 9b6dc52f6012ef7e40311c1d1bca0ed820f26c3d
child 515908 3e9c4c5d97b27abe24596db77c89410e2cee211f
push id12637
push usergijskruitbosch@gmail.com
push dateThu, 10 Mar 2016 13:33:16 +0000
reviewersbz
bugs735251
milestone47.0a1
Bug 735251 - don't show focusrings on HTML video / audio elements on non-Windows, r?bz MozReview-Commit-ID: J7vFGY6ylZ8
dom/base/nsGlobalWindow.cpp
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -9627,16 +9627,28 @@ nsGlobalWindow::SetChromeEventHandler(Ev
 
 static bool IsLink(nsIContent* aContent)
 {
   return aContent && (aContent->IsHTMLElement(nsGkAtoms::a) ||
                       aContent->AttrValueIs(kNameSpaceID_XLink, nsGkAtoms::type,
                                             nsGkAtoms::simple, eCaseMatters));
 }
 
+static bool ShouldShowFocusRingIfFocusedByMouse(nsIContent* aNode)
+{
+  if (aNode) {
+    if (IsLink(aNode) ||
+        aNode->IsHTMLElement(nsGkAtoms::video) ||
+        aNode->IsHTMLElement(nsGkAtoms::audio)) {
+      return false;
+    }
+  }
+  return true;
+}
+
 void
 nsGlobalWindow::SetFocusedNode(nsIContent* aNode,
                                uint32_t aFocusMethod,
                                bool aNeedsFocus)
 {
   FORWARD_TO_INNER_VOID(SetFocusedNode, (aNode, aFocusMethod, aNeedsFocus));
 
   if (aNode && aNode->GetComposedDoc() != mDoc) {
@@ -9660,19 +9672,20 @@ nsGlobalWindow::SetFocusedNode(nsIConten
     // if a node was focused by a keypress, turn on focus rings for the
     // window.
     if (mFocusMethod & nsIFocusManager::FLAG_BYKEY) {
       mFocusByKeyOccurred = true;
     } else if (
       // otherwise, we set mShowFocusRingForContent, as we don't want this to
       // be permanent for the window. On Windows, focus rings are only shown
       // when the FLAG_SHOWRING flag is used. On other platforms, focus rings
-      // are only hidden for clicks on links.
+      // are only visible on some elements.
 #ifndef XP_WIN
-      !(mFocusMethod & nsIFocusManager::FLAG_BYMOUSE) || !IsLink(aNode) ||
+      !(mFocusMethod & nsIFocusManager::FLAG_BYMOUSE) ||
+      ShouldShowFocusRingIfFocusedByMouse(aNode) ||
 #endif
       aFocusMethod & nsIFocusManager::FLAG_SHOWRING) {
         mShowFocusRingForContent = true;
     }
   }
 
   if (aNeedsFocus)
     mNeedsFocus = aNeedsFocus;