From f19fae9846179badfff34f5c8bb5456f17dbef41 Mon Sep 17 00:00:00 2001 From: "aaronleventhal%moonset.net" Date: Fri, 30 Apr 2004 14:05:27 +0000 Subject: [PATCH] Bug 138069. Make -moz-user-focus work for any html element. r+sr=bryner --- content/events/src/nsEventStateManager.cpp | 44 +++++++++++++++++----- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index 75197dd54c0..7dc927c36d5 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -3559,17 +3559,19 @@ nsEventStateManager::GetNextTabbableContent(nsIContent* aRootContent, } } else if (tag == nsHTMLAtoms::img) { + PRBool hasImageMap = PR_FALSE; // Don't need to set disabled here, because if we // match an imagemap, we'll return from there. - if (sTabFocusModel & eTabFocus_linksMask) { - nsCOMPtr nextImage(do_QueryInterface(child)); - nsAutoString usemap; - if (nextImage) { - nsCOMPtr doc = child->GetDocument(); - if (doc) { - nextImage->GetAttribute(NS_LITERAL_STRING("usemap"), usemap); - nsCOMPtr imageMap = nsImageMapUtils::FindImageMap(doc,usemap); - if (imageMap) { + nsCOMPtr nextImage(do_QueryInterface(child)); + nsAutoString usemap; + if (nextImage) { + nsCOMPtr doc = child->GetDocument(); + if (doc) { + nextImage->GetAttribute(NS_LITERAL_STRING("usemap"), usemap); + nsCOMPtr imageMap = nsImageMapUtils::FindImageMap(doc,usemap); + if (imageMap) { + hasImageMap = PR_TRUE; + if (sTabFocusModel & eTabFocus_linksMask) { nsCOMPtr map(do_QueryInterface(imageMap)); if (map) { nsIContent *childArea; @@ -3615,6 +3617,22 @@ nsEventStateManager::GetNextTabbableContent(nsIContent* aRootContent, } } } + + // Might be using -moz-user-focus and imitating a control + // Check to see if linked + for (nsIContent *findAnchorAncestor = child; findAnchorAncestor; + findAnchorAncestor = findAnchorAncestor->GetParent()) { + nsCOMPtr anchor = + do_QueryInterface(findAnchorAncestor); + if (anchor) { + break; // Found an anchor + } + } + if (!findAnchorAncestor && !hasImageMap) { + // Focusable, but no anchor or image map. + // Therefore, this image is imitating a form control + disabled = !(sTabFocusModel & eTabFocus_formElementsMask); + } } else if (tag == nsHTMLAtoms::object) { // OBJECT is treated as a form element. @@ -3652,7 +3670,13 @@ nsEventStateManager::GetNextTabbableContent(nsIContent* aRootContent, } } } - } + } + else { + // Let any HTML element with -moz-user-focus: normal be tabbable + // Without this rule, DHTML form controls made from div or span + // cannot be put in the tab order. + disabled = !(sTabFocusModel & eTabFocus_formElementsMask); + } } else { // Is it disabled?