Bug 606011 - (OSX) focus event not fired on click for elements made specially focusable via tabindex, r=enndeakin, a=blocking
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Wed, 05 Jan 2011 15:23:37 +0200
changeset 60074 f30f14f26ab7f4d5abda8487e5be489d4b18538f
parent 60073 ab1fb1ff366247dd14efa7648f3adf079eb8b341
child 60075 f3bf1a5c419af2c2ec6df023628884349461975f
push id17851
push useropettay@mozilla.com
push dateThu, 06 Jan 2011 16:42:09 +0000
treeherdermozilla-central@f30f14f26ab7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersenndeakin, blocking
bugs606011
milestone2.0b9pre
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 606011 - (OSX) focus event not fired on click for elements made specially focusable via tabindex, r=enndeakin, a=blocking
content/html/content/src/nsGenericHTMLElement.cpp
content/html/content/src/nsGenericHTMLElement.h
content/html/content/src/nsHTMLButtonElement.cpp
content/html/content/src/nsHTMLInputElement.cpp
content/html/content/src/nsHTMLSelectElement.cpp
content/html/content/src/nsHTMLTextAreaElement.cpp
dom/tests/mochitest/chrome/window_focus.xul
dom/tests/mochitest/general/test_focusrings.xul
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -2722,16 +2722,32 @@ nsGenericHTMLFormElement::CanBeDisabled(
   // It's easier to test the types that _cannot_ be disabled
   return
     type != NS_FORM_LABEL &&
     type != NS_FORM_OBJECT &&
     type != NS_FORM_OUTPUT;
 }
 
 PRBool
+nsGenericHTMLFormElement::IsHTMLFocusable(PRBool aWithMouse,
+                                          PRBool* aIsFocusable,
+                                          PRInt32* aTabIndex)
+{
+  if (nsGenericHTMLElement::IsHTMLFocusable(aWithMouse, aIsFocusable, aTabIndex)) {
+    return PR_TRUE;
+  }
+
+#ifdef XP_MACOSX
+  *aIsFocusable =
+    (!aWithMouse || nsFocusManager::sMouseFocusesFormControl) && *aIsFocusable;
+#endif
+  return PR_FALSE;
+}
+
+PRBool
 nsGenericHTMLFormElement::IsSubmitControl() const
 {
   PRInt32 type = GetType();
   return type == NS_FORM_INPUT_SUBMIT ||
          type == NS_FORM_BUTTON_SUBMIT ||
          type == NS_FORM_INPUT_IMAGE;
 }
 
@@ -3312,20 +3328,16 @@ nsGenericHTMLElement::IsHTMLFocusable(PR
   }
 
   if (aTabIndex) {
     *aTabIndex = tabIndex;
   }
 
   // If a tabindex is specified at all, or the default tabindex is 0, we're focusable
   *aIsFocusable = 
-#ifdef XP_MACOSX
-    // can only focus with the mouse on Mac if editable
-    (!aWithMouse || override) &&
-#endif
     (tabIndex >= 0 || (!disabled && HasAttr(kNameSpaceID_None, nsGkAtoms::tabindex)));
 
   return override;
 }
 
 void
 nsGenericHTMLElement::RegUnRegAccessKey(PRBool aDoReg)
 {
--- a/content/html/content/src/nsGenericHTMLElement.h
+++ b/content/html/content/src/nsGenericHTMLElement.h
@@ -919,16 +919,19 @@ public:
     }
   }
 
   /**
    * Returns if the control can be disabled.
    */
   PRBool CanBeDisabled() const;
 
+  virtual PRBool IsHTMLFocusable(PRBool aWithMouse, PRBool* aIsFocusable,
+                                 PRInt32* aTabIndex);
+
 protected:
   virtual nsresult BeforeSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
                                  const nsAString* aValue, PRBool aNotify);
 
   virtual nsresult AfterSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
                                 const nsAString* aValue, PRBool aNotify);
 
   /**
--- a/content/html/content/src/nsHTMLButtonElement.cpp
+++ b/content/html/content/src/nsHTMLButtonElement.cpp
@@ -276,17 +276,17 @@ nsHTMLButtonElement::Click()
   mHandlingClick = PR_FALSE;
 
   return NS_OK;
 }
 
 PRBool
 nsHTMLButtonElement::IsHTMLFocusable(PRBool aWithMouse, PRBool *aIsFocusable, PRInt32 *aTabIndex)
 {
-  if (nsGenericHTMLElement::IsHTMLFocusable(aWithMouse, aIsFocusable, aTabIndex)) {
+  if (nsGenericHTMLFormElement::IsHTMLFocusable(aWithMouse, aIsFocusable, aTabIndex)) {
     return PR_TRUE;
   }
 
   *aIsFocusable = 
 #ifdef XP_MACOSX
     (!aWithMouse || nsFocusManager::sMouseFocusesFormControl) &&
 #endif
     !IsDisabled();
--- a/content/html/content/src/nsHTMLInputElement.cpp
+++ b/content/html/content/src/nsHTMLInputElement.cpp
@@ -3526,17 +3526,17 @@ nsHTMLInputElement::WillRemoveFromRadioG
     container->RemoveFromRadioGroup(name,
                                     static_cast<nsIFormControl*>(this));
   }
 }
 
 PRBool
 nsHTMLInputElement::IsHTMLFocusable(PRBool aWithMouse, PRBool *aIsFocusable, PRInt32 *aTabIndex)
 {
-  if (nsGenericHTMLElement::IsHTMLFocusable(aWithMouse, aIsFocusable, aTabIndex)) {
+  if (nsGenericHTMLFormElement::IsHTMLFocusable(aWithMouse, aIsFocusable, aTabIndex)) {
     return PR_TRUE;
   }
 
   if (IsDisabled()) {
     *aIsFocusable = PR_FALSE;
     return PR_TRUE;
   }
 
--- a/content/html/content/src/nsHTMLSelectElement.cpp
+++ b/content/html/content/src/nsHTMLSelectElement.cpp
@@ -1284,17 +1284,17 @@ nsHTMLSelectElement::Focus()
 {
   return nsGenericHTMLElement::Focus();
 }
 
 PRBool
 nsHTMLSelectElement::IsHTMLFocusable(PRBool aWithMouse,
                                      PRBool *aIsFocusable, PRInt32 *aTabIndex)
 {
-  if (nsGenericHTMLElement::IsHTMLFocusable(aWithMouse, aIsFocusable, aTabIndex)) {
+  if (nsGenericHTMLFormElement::IsHTMLFocusable(aWithMouse, aIsFocusable, aTabIndex)) {
     return PR_TRUE;
   }
 
   *aIsFocusable = !IsDisabled();
 
   return PR_FALSE;
 }
 
--- a/content/html/content/src/nsHTMLTextAreaElement.cpp
+++ b/content/html/content/src/nsHTMLTextAreaElement.cpp
@@ -475,17 +475,17 @@ nsHTMLTextAreaElement::SelectAll(nsPresC
 
   return NS_OK;
 }
 
 PRBool
 nsHTMLTextAreaElement::IsHTMLFocusable(PRBool aWithMouse,
                                        PRBool *aIsFocusable, PRInt32 *aTabIndex)
 {
-  if (nsGenericHTMLElement::IsHTMLFocusable(aWithMouse, aIsFocusable, aTabIndex)) {
+  if (nsGenericHTMLFormElement::IsHTMLFocusable(aWithMouse, aIsFocusable, aTabIndex)) {
     return PR_TRUE;
   }
 
   // disabled textareas are not focusable
   *aIsFocusable = !IsDisabled();
   return PR_FALSE;
 }
 
--- a/dom/tests/mochitest/chrome/window_focus.xul
+++ b/dom/tests/mochitest/chrome/window_focus.xul
@@ -278,22 +278,23 @@ function getTopWindow(win)
              QueryInterface(Components.interfaces.nsIDocShellTreeItem).rootTreeItem.
              QueryInterface(Components.interfaces.nsIInterfaceRequestor).
              getInterface(Components.interfaces.nsIDOMWindow);
 }
 
 function mouseOnElement(element, expectedElement, focusChanged, testid)
 {
   var expectedWindow = (element.ownerDocument.defaultView == gChildWindow) ? gChildWindow : window;
-  // on Mac, elements are not focused when clicking, except for lists and textboxes.
+  // on Mac, form elements are not focused when clicking, except for lists and textboxes.
   var noFocusOnMouse = (navigator.platform.indexOf("Mac") == 0);
   if (noFocusOnMouse) {
     if (element.namespaceURI == "http://www.w3.org/1999/xhtml") {
       // links are special. They can be focused but show no focus ring
-      if (element.localName == "a" || element.localName == "select" ||
+      if (element.localName == "a" || element.localName == "div" ||
+          element.localName == "select" ||
           element.localName == "input" && (element.type == "text" ||
                                            element.type == "password")) {
         noFocusOnMouse = false;
       }
     }
     else if (element.localName == "listbox") {
       noFocusOnMouse = false;
     }
--- a/dom/tests/mochitest/general/test_focusrings.xul
+++ b/dom/tests/mochitest/general/test_focusrings.xul
@@ -128,17 +128,17 @@ var htmlElements = [
   "<button id='elem'>Button</button>",
   "<input id='elem' class='canfocus'>",
   "<input id='elem' type='password' class='canfocus'>",
   "<input id='elem' type='button'>",
   "<input id='elem' type='checkbox'>",
   "<textarea id='elem' class='canfocus'></textarea>",
   "<select id='elem' class='canfocus'><option>One</select>",
   "<select id='elem' rows='5' class='canfocus'><option>One</select>",
-  "<div id='elem' tabindex='0' style='width: 10px; height: 10px;'></div>",
+  "<div id='elem' tabindex='0' class='canfocus' style='width: 10px; height: 10px;'></div>",
   "<a href='about:blank' class='canfocus' onclick='return false;'>about:blank</a>",
 ];
 
 var htmlElementsMacPrefSet = [
   "<button id='elem' class='canfocus'>Button</button>",
   "<input id='elem' class='canfocus'>",
   "<input id='elem' type='button' class='canfocus'>",
   "<input id='elem' type='checkbox' class='canfocus'>",