Bug 196288 [ATK Accessibility] implement ATK link_selected event

r=aaronl, sr=henry.jia
This commit is contained in:
kyle.yuan%sun.com 2003-03-20 08:27:31 +00:00
parent 6d3853b279
commit d1162be93d
9 changed files with 161 additions and 61 deletions

View File

@ -83,6 +83,7 @@ interface nsIAccessibleEventListener : nsISupports
const unsigned long EVENT_ATK_TABLE_COLUMN_INSERT = 0x0114;
const unsigned long EVENT_ATK_TABLE_COLUMN_DELETE = 0x0115;
const unsigned long EVENT_ATK_TABLE_COLUMN_REORDER = 0x0116;
const unsigned long EVENT_ATK_LINK_SELECTED = 0x0117;
[noscript]
void handleEvent(in unsigned long aEvent, in nsIAccessible aTarget, in voidPtr aData);

View File

@ -40,6 +40,7 @@ interface nsIAccessibleHyperLink : nsISupports
nsIAccessible getObject (in long i);
boolean isValid ();
boolean isSelected ();
};
/*

View File

@ -35,4 +35,5 @@ interface nsIAccessibleHyperText : nsISupports
nsIAccessibleHyperLink getLink (in long index);
long getLinkIndex (in long charIndex);
long getSelectedLinkIndex ();
};

View File

@ -1630,3 +1630,45 @@ NS_IMETHODIMP nsAccessible::HandleEvent(PRUint32 aEvent, nsIAccessible *aTarget,
GetAccParent(getter_AddRefs(parent));
return parent ? parent->HandleEvent(aEvent, aTarget, aData) : NS_ERROR_NOT_IMPLEMENTED;
}
#ifdef MOZ_ACCESSIBILITY_ATK
// static helper function
nsresult nsAccessible::GetParentBlockNode(nsIDOMNode *aCurrentNode, nsIDOMNode **aBlockNode)
{
*aBlockNode = nsnull;
nsCOMPtr<nsIContent> content(do_QueryInterface(aCurrentNode));
if (!content)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocument> doc;
content->GetDocument(*getter_AddRefs(doc));
if (!doc)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIPresShell> presShell;
doc->GetShellAt(0, getter_AddRefs(presShell));
nsIFrame* frame = nsnull;
nsCOMPtr<nsIAtom> frameType;
presShell->GetPrimaryFrameFor(content, &frame);
if (frame)
frame->GetFrameType(getter_AddRefs(frameType));
while (frame && frameType != nsLayoutAtoms::blockFrame) {
nsIFrame* parentFrame = nsnull;
frame->GetParent(&parentFrame);
if (parentFrame)
parentFrame->GetFrameType(getter_AddRefs(frameType));
frame = parentFrame;
}
if (! frame)
return NS_ERROR_FAILURE;
frame->GetContent(getter_AddRefs(content));
nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(content));
*aBlockNode = domNode;
NS_IF_ADDREF(*aBlockNode);
return NS_OK;
}
#endif //MOZ_ACCESSIBILITY_ATK

View File

@ -95,6 +95,10 @@ public:
NS_IMETHOD AccTakeFocus(void);
NS_IMETHOD AccGetDOMNode(nsIDOMNode **_retval);
#ifdef MOZ_ACCESSIBILITY_ATK
static nsresult GetParentBlockNode(nsIDOMNode *aCurrentNode, nsIDOMNode **aBlockNode);
#endif
protected:
virtual nsIFrame* GetFrame();
virtual nsIFrame* GetBoundsFrame();

View File

@ -36,55 +36,42 @@
*
* ***** END LICENSE BLOCK ***** */
#include "nsIAccessible.h"
#include "nsRootAccessible.h"
#include "nsCOMPtr.h"
#include "nsIDocument.h"
#include "nsIDOMNSDocument.h"
#include "nsIPresShell.h"
#include "nsIPresContext.h"
#include "nsIContent.h"
#include "nsIFrame.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMElement.h"
#include "nsIDOMNSEvent.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOMEventListener.h"
#include "nsReadableUtils.h"
#include "nsILink.h"
#include "nsHTMLFormControlAccessible.h"
#include "nsHTMLLinkAccessible.h"
#include "nsIURI.h"
#include "nsIDocShell.h"
#include "nsIDocShellTreeItem.h"
#include "nsIWebNavigation.h"
#include "nsIXULDocument.h"
// NOTE: alphabetically ordered
#include "nsAccessibilityService.h"
#include "nsAccessibleEventData.h"
#include "nsHTMLSelectAccessible.h"
#include "nsIAccessibleCaret.h"
#include "nsIAccessibleHyperText.h"
#include "nsIDOMDocument.h"
#include "nsIDOMDocumentType.h"
#include "nsINameSpaceManager.h"
#include "nsIDOMNSHTMLSelectElement.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "nsIAccessibilityService.h"
#include "nsIServiceManager.h"
#include "nsHTMLSelectAccessible.h"
#include "nsIDOMElement.h"
#include "nsIDOMEventListener.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMHTMLAnchorElement.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIDOMHTMLSelectElement.h"
#include "nsCURILoader.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDOMWindow.h"
#include "nsIViewManager.h"
#include "nsIScrollableView.h"
#include "nsIDOMNSDocument.h"
#include "nsIDOMNSEvent.h"
#include "nsIDOMXULSelectCntrlEl.h"
#include "nsIDOMXULSelectCntrlItemEl.h"
#include "nsXULTreeAccessible.h"
#include "nsIDocShell.h"
#include "nsIDocShellTreeItem.h"
#include "nsIDocument.h"
#include "nsIFrame.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsINameSpaceManager.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScrollableView.h"
#include "nsIServiceManager.h"
#include "nsITreeSelection.h"
#include "nsAccessibilityService.h"
#include "nsISelectionPrivate.h"
#include "nsICaret.h"
#include "nsIAccessibleCaret.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsAccessibleEventData.h"
#include "nsIURI.h"
#include "nsIViewManager.h"
#include "nsIWebNavigation.h"
#include "nsIXULDocument.h"
#include "nsLayoutAtoms.h"
#include "nsReadableUtils.h"
#include "nsRootAccessible.h"
#include "nsXULTreeAccessible.h"
NS_INTERFACE_MAP_BEGIN(nsRootAccessible)
NS_INTERFACE_MAP_ENTRY(nsIAccessibleDocument)
@ -473,6 +460,16 @@ NS_IMETHODIMP nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent)
optionTargetNode = do_QueryInterface(selectItem);
}
#ifdef MOZ_ACCESSIBILITY_ATK
nsCOMPtr<nsIDOMHTMLAnchorElement> anchorElement(do_QueryInterface(targetNode));
if (anchorElement) {
nsCOMPtr<nsIDOMNode> blockNode;
// For ATK, we don't create any individual object for hyperlink, use its parent who has block frame instead
nsAccessible::GetParentBlockNode(targetNode, getter_AddRefs(blockNode));
targetNode = blockNode;
}
#endif
nsCOMPtr<nsIAccessible> accessible;
if (NS_FAILED(mAccService->GetAccessibleFor(targetNode, getter_AddRefs(accessible))))
return NS_OK;
@ -571,6 +568,14 @@ NS_IMETHODIMP nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent)
if (eventType.EqualsIgnoreCase("focus") || eventType.EqualsIgnoreCase("DOMMenuItemActive")) {
if (treeItemAccessible) // use focused treeitem
HandleEvent(nsIAccessibleEventListener::EVENT_FOCUS, treeItemAccessible, nsnull);
else if (anchorElement) {
nsCOMPtr<nsIAccessibleHyperText> hyperText(do_QueryInterface(accessible));
if (hyperText) {
PRInt32 selectedLink;
hyperText->GetSelectedLinkIndex(&selectedLink);
HandleEvent(nsIAccessibleEventListener::EVENT_ATK_LINK_SELECTED, accessible, &selectedLink);
}
}
else if (optionTargetNode && // use focused option
NS_SUCCEEDED(mAccService->GetAccessibleFor(optionTargetNode, getter_AddRefs(accessible))))
FireAccessibleFocusEvent(accessible, optionTargetNode);
@ -899,6 +904,9 @@ NS_IMETHODIMP nsRootAccessible::OnSecurityChange(nsIWebProgress *aWebProgress,
return NS_OK;
}
//-----------------------------------------------------
// nsDocAccessibleMixin
//-----------------------------------------------------
nsDocAccessibleMixin::nsDocAccessibleMixin(nsIDocument *aDoc):mDocument(aDoc)
{
}

View File

@ -147,16 +147,42 @@ NS_IMETHODIMP nsHTMLIFrameAccessible::GetLinks(PRInt32 *aLinks)
/* nsIAccessibleHyperLink getLink (in long index); */
NS_IMETHODIMP nsHTMLIFrameAccessible::GetLink(PRInt32 aIndex,
nsIAccessibleHyperLink **_retval)
nsIAccessibleHyperLink **aLink)
{
return GetLinkFromAccNode(aIndex, this, _retval);
return GetLinkFromAccNode(aIndex, this, aLink);
}
/* long getLinkIndex (in long charIndex); */
NS_IMETHODIMP nsHTMLIFrameAccessible::GetLinkIndex(PRInt32 aCharIndex,
PRInt32 *_retval)
PRInt32 *aLinkIndex)
{
return GetLinkIndexFromAccNode(this, aCharIndex, _retval);
return GetLinkIndexFromAccNode(this, aCharIndex, aLinkIndex);
}
/* long getSelectedLinkIndex (); */
NS_IMETHODIMP nsHTMLIFrameAccessible::GetSelectedLinkIndex(PRInt32 *aSelectedLinkIndex)
{
*aSelectedLinkIndex = -1;
nsCOMPtr<nsIDOMNode> focusedNode;
GetFocusedNode(getter_AddRefs(focusedNode));
PRInt32 index, links = GetLinksFromAccNode(this);
for (index = 0; index < links; index++) {
nsCOMPtr<nsIAccessibleHyperLink> hyperLink;
GetLink(index, getter_AddRefs(hyperLink));
nsCOMPtr<nsIAccessible> acc(do_QueryInterface(hyperLink));
if (acc) {
nsCOMPtr<nsIDOMNode> linkNode;
acc->AccGetDOMNode(getter_AddRefs(linkNode));
if (focusedNode == linkNode) {
*aSelectedLinkIndex = index;
return NS_OK;
}
}
}
return NS_ERROR_FAILURE;
}
//helper function for nsIAccessibleHyperText

View File

@ -223,9 +223,9 @@ NS_IMETHODIMP nsHTMLImageMapAccessible::GetEndIndex(PRInt32 *aEndIndex)
}
/* nsIURI getURI (in long i); */
NS_IMETHODIMP nsHTMLImageMapAccessible::GetURI(PRInt32 aIndex, nsIURI **_retval)
NS_IMETHODIMP nsHTMLImageMapAccessible::GetURI(PRInt32 aIndex, nsIURI **aURI)
{
*_retval = nsnull;
*aURI = nsnull;
nsCOMPtr<nsIDOMHTMLCollection> mapAreas;
mMapElement->GetAreas(getter_AddRefs(mapAreas));
@ -246,7 +246,7 @@ NS_IMETHODIMP nsHTMLImageMapAccessible::GetURI(PRInt32 aIndex, nsIURI **_retval)
nsCOMPtr<nsIDOMElement> area(do_QueryInterface(domNode));
nsAutoString hrefValue;
if (NS_SUCCEEDED(area->GetAttribute(NS_LITERAL_STRING("href"), hrefValue))) {
return NS_NewURI(_retval, hrefValue, nsnull, baseURI);
return NS_NewURI(aURI, hrefValue, nsnull, baseURI);
}
}
}
@ -257,15 +257,22 @@ NS_IMETHODIMP nsHTMLImageMapAccessible::GetURI(PRInt32 aIndex, nsIURI **_retval)
/* nsIAccessible getObject (in long i); */
NS_IMETHODIMP nsHTMLImageMapAccessible::GetObject(PRInt32 aIndex,
nsIAccessible **_retval)
nsIAccessible **aAccessible)
{
*_retval = CreateAreaAccessible(aIndex);
*aAccessible = CreateAreaAccessible(aIndex);
return NS_OK;
}
/* boolean isValid (); */
NS_IMETHODIMP nsHTMLImageMapAccessible::IsValid(PRBool *_retval)
NS_IMETHODIMP nsHTMLImageMapAccessible::IsValid(PRBool *aIsValid)
{
*_retval = PR_TRUE;
*aIsValid = PR_TRUE;
return NS_OK;
}
/* boolean isSelected (); */
NS_IMETHODIMP nsHTMLImageMapAccessible::IsSelected(PRBool *aIsSelected)
{
*aIsSelected = PR_FALSE;
return NS_OK;
}

View File

@ -82,6 +82,7 @@ NS_IMETHODIMP nsHTMLLinkAccessible::GetAccState(PRUint32 *_retval)
return NS_OK;
}
//-------------------------- nsIAccessibleHyperLink -------------------------
/* readonly attribute long anchors; */
NS_IMETHODIMP nsHTMLLinkAccessible::GetAnchors(PRInt32 *aAnchors)
{
@ -107,18 +108,18 @@ NS_IMETHODIMP nsHTMLLinkAccessible::GetEndIndex(PRInt32 *aEndIndex)
}
/* nsIURI getURI (in long i); */
NS_IMETHODIMP nsHTMLLinkAccessible::GetURI(PRInt32 i, nsIURI **_retval)
NS_IMETHODIMP nsHTMLLinkAccessible::GetURI(PRInt32 i, nsIURI **aURI)
{
//I do not know why we have to retrun a nsIURI instead of
//nsILink or just a string of url. Anyway, maybe nsIURI is
//more powerful for the future.
*_retval = nsnull;
*aURI = nsnull;
nsCOMPtr<nsILink> link(do_QueryInterface(mLinkContent));
if (link) {
nsXPIDLCString hrefValue;
if (NS_SUCCEEDED(link->GetHrefCString(*getter_Copies(hrefValue)))) {
return NS_NewURI(_retval, hrefValue, nsnull, nsnull);
return NS_NewURI(aURI, hrefValue, nsnull, nsnull);
}
}
@ -127,18 +128,27 @@ NS_IMETHODIMP nsHTMLLinkAccessible::GetURI(PRInt32 i, nsIURI **_retval)
/* nsIAccessible getObject (in long i); */
NS_IMETHODIMP nsHTMLLinkAccessible::GetObject(PRInt32 aIndex,
nsIAccessible **_retval)
nsIAccessible **aAccessible)
{
if (0 != aIndex)
return NS_ERROR_FAILURE;
return QueryInterface(NS_GET_IID(nsIAccessible), (void **)_retval);
return QueryInterface(NS_GET_IID(nsIAccessible), (void **)aAccessible);
}
/* boolean isValid (); */
NS_IMETHODIMP nsHTMLLinkAccessible::IsValid(PRBool *_retval)
NS_IMETHODIMP nsHTMLLinkAccessible::IsValid(PRBool *aIsValid)
{
// I have not found the cause which makes this attribute false.
*_retval = PR_TRUE;
*aIsValid = PR_TRUE;
return NS_OK;
}
/* boolean isSelected (); */
NS_IMETHODIMP nsHTMLLinkAccessible::IsSelected(PRBool *aIsSelected)
{
nsCOMPtr<nsIDOMNode> focusedNode;
GetFocusedNode(getter_AddRefs(focusedNode));
*aIsSelected = (focusedNode == mDOMNode);
return NS_OK;
}