Bug 301621. Expose elements with onclick from addEventListener(). r=smaug

This commit is contained in:
aaronleventhal@moonset.net 2007-05-08 14:44:04 -07:00
parent cfe81fc145
commit c3333e186a
6 changed files with 23 additions and 5 deletions

View File

@ -39,6 +39,7 @@
// NOTE: alphabetically ordered
#include "nsAccessibilityAtoms.h"
#include "nsAccessibilityService.h"
#include "nsAccessibilityUtils.h"
#include "nsCURILoader.h"
#include "nsDocAccessible.h"
#include "nsHTMLAreaAccessible.h"
@ -532,7 +533,8 @@ nsAccessibilityService::CreateHyperTextAccessible(nsISupports *aFrame, nsIAccess
nsCOMPtr<nsIContent> content(do_QueryInterface(node));
NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
if (content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::onclick)) {
if (nsAccessibilityUtils::HasListener(content, NS_LITERAL_STRING("click"))) {
// nsLinkableAccessible inherits from nsHyperTextAccessible, but
// it also includes code for dealing with the onclick
*aAccessible = new nsLinkableAccessible(node, weakShell);
@ -1249,7 +1251,7 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessible(nsIDOMNode *aNode,
// correspond to the doc accessible and will be created in any case
if (!newAcc && content->Tag() != nsAccessibilityAtoms::body && content->GetParent() &&
(content->IsFocusable() ||
content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::onclick) ||
nsAccessibilityUtils::HasListener(content, NS_LITERAL_STRING("click")) ||
content->HasAttr(kNameSpaceID_WAIProperties, nsAccessibilityAtoms::describedby) ||
content->HasAttr(kNameSpaceID_WAIProperties, nsAccessibilityAtoms::labelledby) ||
content->HasAttr(kNameSpaceID_WAIProperties, nsAccessibilityAtoms::required) ||

View File

@ -82,6 +82,7 @@ private:
* interface.
*/
nsresult GetAccessibleByType(nsIDOMNode *aNode, nsIAccessible **aAccessible);
PRBool HasListener(nsIContent *aContent, nsAString& aEventType);
};
#endif /* __nsIAccessibilityService_h__ */

View File

@ -39,6 +39,7 @@
#include "nsAccessibilityUtils.h"
#include "nsIDOMXULSelectCntrlEl.h"
#include "nsIDOMXULSelectCntrlItemEl.h"
#include "nsIEventListenerManager.h"
void
nsAccessibilityUtils::GetAccAttr(nsIPersistentProperties *aAttributes,
@ -155,3 +156,13 @@ nsAccessibilityUtils::SetAccAttrsForXULSelectControlItem(nsIDOMNode *aNode,
SetAccGroupAttrs(aAttributes, 0, indexOf + 1, itemsCount);
}
PRBool nsAccessibilityUtils::HasListener(nsIContent *aContent, const nsAString& aEventType)
{
NS_ENSURE_ARG_POINTER(aContent);
nsCOMPtr<nsIEventListenerManager> listenerManager;
aContent->GetListenerManager(PR_FALSE, getter_AddRefs(listenerManager));
return listenerManager && listenerManager->HasListenersFor(aEventType);
}

View File

@ -43,6 +43,7 @@
#include "nsIDOMNode.h"
#include "nsIPersistentProperties2.h"
#include "nsIContent.h"
class nsAccessibilityUtils
{
@ -99,6 +100,8 @@ public:
*/
static void SetAccAttrsForXULSelectControlItem(nsIDOMNode *aNode,
nsIPersistentProperties *aAttributes);
static PRBool HasListener(nsIContent *aContent, const nsAString& aEventType);
};
#endif

View File

@ -41,6 +41,7 @@
#include "nsIAccessibilityService.h"
#include "nsIAccessibleDocument.h"
#include "nsAccessibleWrap.h"
#include "nsAccessibilityUtils.h"
#include "nsGUIEvent.h"
#include "nsHyperTextAccessibleWrap.h"
#include "nsILink.h"
@ -256,8 +257,7 @@ void nsLinkableAccessible::CacheActionContent()
}
}
}
if (walkUpContent->HasAttr(kNameSpaceID_None,
nsAccessibilityAtoms::onclick)) {
if (nsAccessibilityUtils::HasListener(walkUpContent, NS_LITERAL_STRING("click"))) {
mActionContent = walkUpContent;
mIsOnclick = PR_TRUE;
break;

View File

@ -39,6 +39,7 @@
// NOTE: alphabetically ordered
#include "nsAccessibilityAtoms.h"
#include "nsAccessibilityUtils.h"
#include "nsBaseWidgetAccessible.h"
#include "nsIDOMXULDescriptionElement.h"
#include "nsINameSpaceManager.h"
@ -169,7 +170,7 @@ void nsXULLinkAccessible::CacheActionContent()
mIsLink = PR_TRUE;
mActionContent = mTempContent;
}
else if (mTempContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::onclick)) {
else if (nsAccessibilityUtils::HasListener(mTempContent, NS_LITERAL_STRING("click"))) {
mIsOnclick = PR_TRUE;
mActionContent = mTempContent;
}