Bug 267190. [MSAA] Fire events for jump to named anchor. r=pkwarren, sr=bryner

This commit is contained in:
[email protected] committed 2004-11-08 21:07:50 +00:00
1 parent ed6364481e
commit 295a55873c
7 files changed
+164 -22

No files matched your search

@@ -1725,7 +1725,7 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessible(nsIDOMNode *aNode,
// Frame hint not correct, get true frame, we try to optimize away from this
aPresShell->GetPrimaryFrameFor(content, &frame);
if (frame) {
#ifdef DEBUG_aleventhal
#ifdef DEBUG_aleventhal_
// Frame hint debugging
++frameHintFailed;
if (content->IsContentOfType(nsIContent::eTEXT)) {
-1
View File
@@ -662,7 +662,6 @@ void nsAccessible::GetScreenOrigin(nsPresContext *aPresContext, nsIFrame *aFrame
origin.y = NSTwipsToIntPixels(origin.y, t2p);
// Add the widget's screen coordinates to the offset we've counted
//nsIWidget *widget = view->GetWidget();
NS_ASSERTION(widget, "No widget for top view");
widget->WidgetToScreen(nsRect(origin.x, origin.y, 1, 1), *aRect);
}
+3 -12
View File
@@ -615,23 +615,14 @@ void nsDocAccessible::FireDocLoadFinished()
PRUint32 state;
GetState(&state);
if ((state & STATE_INVISIBLE) != 0) {
return; // Don't consider load finished until window unhidden
}
if (mIsNewDocument) {
if ((state & STATE_INVISIBLE) == 0) {
// Don't consider load finished until window unhidden
mIsNewDocument = PR_FALSE;
if (mBusy != eBusyStateDone) {
AddScrollListener();
#ifndef MOZ_ACCESSIBILITY_ATK
mBusy = eBusyStateDone; // before event callback so STATE_BUSY is not reported
FireToolkitEvent(nsIAccessibleEvent::EVENT_STATE_CHANGE, this, nsnull);
#endif
}
mBusy = eBusyStateDone;
}
mBusy = eBusyStateDone;
}
void nsDocAccessible::DocLoadCallback(nsITimer *aTimer, void *aClosure)
+4 -4
View File
@@ -64,9 +64,7 @@ class nsDocAccessible : public nsBlockAccessible,
public nsIDOMMutationListener,
public nsIScrollPositionListener,
public nsSupportsWeakReference
{
enum EBusyState {eBusyStateUninitialized, eBusyStateLoading, eBusyStateDone};
{
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIACCESSIBLEDOCUMENT
NS_DECL_NSPIACCESSIBLEDOCUMENT
@@ -104,13 +102,15 @@ class nsDocAccessible : public nsBlockAccessible,
NS_IMETHOD Init();
protected:
enum EBusyState {eBusyStateUninitialized, eBusyStateLoading, eBusyStateDone};
virtual void GetBoundsRect(nsRect& aRect, nsIFrame** aRelativeFrame);
virtual nsIFrame* GetFrame();
virtual nsresult AddEventListeners();
virtual nsresult RemoveEventListeners();
void AddScrollListener();
void RemoveScrollListener();
void FireDocLoadFinished();
virtual void FireDocLoadFinished();
void HandleMutationEvent(nsIDOMEvent *aEvent, PRUint32 aEventType);
static void DocLoadCallback(nsITimer *aTimer, void *aClosure);
static void ScrollTimerCallback(nsITimer *aTimer, void *aClosure);
+2 -3
View File
@@ -490,10 +490,9 @@ NS_IMETHODIMP nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent)
privAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_MENUSTART, accessible, nsnull);
else if (eventType.LowerCaseEqualsLiteral("dommenubarinactive")) {
privAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_MENUEND, accessible, nsnull);
GetFocusedChild(getter_AddRefs(accessible));
GetFocusedChild(getter_AddRefs(accessible)); // Returns null if no focus
nsCOMPtr<nsIAccessNode> accessNode(do_QueryInterface(accessible));
NS_ASSERTION(accessNode, "Unable to QI to nsIAccessNode");
if (accessible) {
if (accessNode) {
accessNode->GetDOMNode(getter_AddRefs(targetNode));
FireAccessibleFocusEvent(accessible, targetNode);
}
+146 -1
View File
@@ -38,9 +38,18 @@
#include "nsDocAccessibleWrap.h"
#include "ISimpleDOMDocument_i.c"
#include "nsIAccessibilityService.h"
#include "nsIAccessibleEvent.h"
#include "nsIDOMDocumentTraversal.h"
#include "nsIDOMNodeFilter.h"
#include "nsIDOMTreeWalker.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIPresShell.h"
#include "nsISelectionController.h"
#include "nsIServiceManager.h"
#include "nsIURI.h"
#include "nsIViewManager.h"
#include "nsIWebNavigation.h"
#include "nsIWidget.h"
/* For documentation of the accessibility architecture,
@@ -50,7 +59,7 @@
//----- nsDocAccessibleWrap -----
nsDocAccessibleWrap::nsDocAccessibleWrap(nsIDOMNode *aDOMNode, nsIWeakReference *aShell):
nsDocAccessible(aDOMNode, aShell)
nsDocAccessible(aDOMNode, aShell), mWasAnchor(PR_FALSE)
{
}
@@ -258,6 +267,142 @@ PRInt32 nsDocAccessibleWrap::GetChildIDFor(nsIAccessible* aAccessible)
return - NS_PTR_TO_INT32(uniqueID);
}
already_AddRefed<nsIAccessible>
nsDocAccessibleWrap::GetFirstLeafAccessible(nsIDOMNode *aStartNode)
{
nsCOMPtr<nsIAccessibilityService> accService(do_GetService("@mozilla.org/accessibilityService;1"));
nsCOMPtr<nsIAccessible> accessible;
nsCOMPtr<nsIDOMTreeWalker> walker;
nsCOMPtr<nsIDOMNode> currentNode(aStartNode);
while (currentNode) {
accService->GetAccessibleInWeakShell(currentNode, mWeakShell, getter_AddRefs(accessible)); // AddRef'd
if (accessible) {
PRInt32 numChildren;
accessible->GetChildCount(&numChildren);
if (numChildren == 0) {
nsIAccessible *leafAccessible = accessible;
NS_ADDREF(leafAccessible);
return leafAccessible; // It's a leaf accessible, return it
}
}
if (!walker) {
// Instantiate walker lazily since we won't need it in 90% of the cases
// where the first DOM node we're given provides an accessible
nsCOMPtr<nsIDOMDocumentTraversal> trav = do_QueryInterface(mDocument);
NS_ASSERTION(trav, "No DOM document traversal for document");
trav->CreateTreeWalker(mDOMNode,
nsIDOMNodeFilter::SHOW_ELEMENT | nsIDOMNodeFilter::SHOW_TEXT,
nsnull, PR_FALSE, getter_AddRefs(walker));
NS_ENSURE_TRUE(walker, nsnull);
walker->SetCurrentNode(currentNode);
}
walker->NextNode(getter_AddRefs(currentNode));
}
return nsnull;
}
void nsDocAccessibleWrap::FireAnchorJumpEvent()
{
// Staying on the same page, jumping to a named anchor
// Fire EVENT_SELECTION_WITHIN on first leaf accessible -- because some
// assistive technologies only cache the child numbers for leaf accessibles
// the can only relate events back to their internal model if it's a leaf.
// There is usually an accessible for the focus node, but if it's an empty text node
// we have to move forward in the document to get one
nsCOMPtr<nsISupports> container = mDocument->GetContainer();
nsCOMPtr<nsIWebNavigation> webNav(do_GetInterface(container));
nsCAutoString theURL;
if (webNav) {
nsCOMPtr<nsIURI> pURI;
webNav->GetCurrentURI(getter_AddRefs(pURI));
if (pURI) {
pURI->GetSpec(theURL);
}
}
const char kHash = '#';
PRBool hasAnchor = PR_FALSE;
if (theURL.FindChar(kHash) > 0) {
hasAnchor = PR_TRUE;
}
// mWasAnchor is set when the previous URL included a named anchor.
// This way we still know to fire the SELECTION_WITHIN event when we
// move from a named anchor back to the top.
if (!mWasAnchor && !hasAnchor) {
return;
}
mWasAnchor = hasAnchor;
nsCOMPtr<nsIDOMNode> focusNode;
if (hasAnchor) {
nsCOMPtr<nsISelectionController> selCon(do_QueryReferent(mWeakShell));
if (!selCon) {
return;
}
nsCOMPtr<nsISelection> domSel;
selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSel));
if (!domSel) {
return;
}
domSel->GetFocusNode(getter_AddRefs(focusNode));
}
else {
focusNode = mDOMNode; // Moved to top, so event is for 1st leaf after root
}
nsCOMPtr<nsIAccessible> accessible = GetFirstLeafAccessible(focusNode);
nsCOMPtr<nsPIAccessible> privateAccessible = do_QueryInterface(accessible);
if (privateAccessible) {
privateAccessible->FireToolkitEvent(nsIAccessibleEvent::EVENT_SELECTION_WITHIN,
accessible, nsnull);
}
}
void nsDocAccessibleWrap::FireDocLoadFinished()
{
if (!mDocument || !mWeakShell)
return; // Document has been shut down
PRUint32 state;
GetState(&state);
if ((state & STATE_INVISIBLE) != 0) {
return; // Don't consider load finished until window unhidden
}
if (mIsNewDocument) {
mIsNewDocument = PR_FALSE;
if (mBusy != eBusyStateDone) {
mBusy = eBusyStateDone; // before event callback so STATE_BUSY is not reported
FireToolkitEvent(nsIAccessibleEvent::EVENT_STATE_CHANGE, this, nsnull);
FireAnchorJumpEvent();
}
}
mBusy = eBusyStateDone;
}
NS_IMETHODIMP nsDocAccessibleWrap::OnLocationChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
nsIURI *location)
{
if (!mWeakShell || !mDocument) {
return NS_OK;
}
PRBool isLoadingDocument;
aWebProgress->GetIsLoadingDocument(&isLoadingDocument);
if (isLoadingDocument) {
return nsDocAccessible::OnLocationChange(aWebProgress, aRequest, location);
}
FireAnchorJumpEvent();
return NS_OK;
}
STDMETHODIMP nsDocAccessibleWrap::get_URL(/* [out] */ BSTR __RPC_FAR *aURL)
{
*aURL = NULL;
@@ -98,6 +98,14 @@ public:
/* [retval][out] */ IDispatch __RPC_FAR *__RPC_FAR *ppdispParent);
NS_IMETHOD FireToolkitEvent(PRUint32 aEvent, nsIAccessible* aAccessible, void* aData);
NS_IMETHOD OnLocationChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest, nsIURI *location);
protected:
void FireDocLoadFinished();
private:
void FireAnchorJumpEvent();
already_AddRefed<nsIAccessible> GetFirstLeafAccessible(nsIDOMNode *aStartNode);
PRPackedBool mWasAnchor;
};
#endif