From a4d0ce6ac8d56d85ad2836f747419632e5edcede Mon Sep 17 00:00:00 2001 From: "evaughan%netscape.com" Date: Thu, 17 May 2001 23:52:32 +0000 Subject: [PATCH] Fix for bug #80902 -r jeff@tcbnetworks.com -sr waterson Fix for bug #80505 -r aaronl, jgaunt -sr brendan git-svn-id: svn://10.0.0.236/trunk@95337 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/accessible/public/nsIAccessible.idl | 3 + .../src/base/nsAccessibilityService.cpp | 6 +- mozilla/accessible/src/base/nsAccessible.cpp | 165 +++++++++++++----- mozilla/accessible/src/base/nsAccessible.h | 4 +- .../src/base/nsGenericAccessible.cpp | 11 ++ .../accessible/src/base/nsGenericAccessible.h | 1 + .../accessible/src/base/nsRootAccessible.cpp | 6 +- .../accessible/src/base/nsRootAccessible.h | 2 +- .../accessible/src/nsAccessibilityService.cpp | 6 +- mozilla/accessible/src/nsAccessible.cpp | 165 +++++++++++++----- mozilla/accessible/src/nsAccessible.h | 4 +- .../accessible/src/nsGenericAccessible.cpp | 11 ++ mozilla/accessible/src/nsGenericAccessible.h | 1 + mozilla/accessible/src/nsRootAccessible.cpp | 6 +- mozilla/accessible/src/nsRootAccessible.h | 2 +- mozilla/layout/base/public/nsIFrame.h | 11 ++ .../layout/forms/nsComboboxControlFrame.cpp | 25 +-- mozilla/layout/forms/nsComboboxControlFrame.h | 2 + .../layout/forms/nsGfxButtonControlFrame.cpp | 25 +-- .../layout/forms/nsGfxButtonControlFrame.h | 4 + .../forms/nsGfxCheckboxControlFrame.cpp | 24 +-- .../layout/forms/nsGfxCheckboxControlFrame.h | 5 + .../layout/forms/nsGfxRadioControlFrame.cpp | 24 ++- mozilla/layout/forms/nsGfxRadioControlFrame.h | 3 + .../layout/forms/nsHTMLButtonControlFrame.cpp | 22 ++- .../layout/forms/nsHTMLButtonControlFrame.h | 3 + mozilla/layout/forms/nsImageControlFrame.cpp | 24 +-- mozilla/layout/generic/nsFrame.cpp | 17 +- mozilla/layout/generic/nsFrame.h | 2 + mozilla/layout/generic/nsFrameFrame.cpp | 29 +-- mozilla/layout/generic/nsIFrame.h | 11 ++ mozilla/layout/generic/nsImageFrame.cpp | 24 +-- mozilla/layout/generic/nsImageFrame.h | 3 + mozilla/layout/generic/nsTextFrame.cpp | 33 ++-- mozilla/layout/html/base/src/nsFrame.cpp | 17 +- mozilla/layout/html/base/src/nsFrame.h | 2 + mozilla/layout/html/base/src/nsImageFrame.cpp | 24 +-- mozilla/layout/html/base/src/nsImageFrame.h | 3 + mozilla/layout/html/base/src/nsTextFrame.cpp | 33 ++-- .../layout/html/document/src/nsFrameFrame.cpp | 29 +-- .../html/forms/src/nsComboboxControlFrame.cpp | 25 +-- .../html/forms/src/nsComboboxControlFrame.h | 2 + .../forms/src/nsGfxButtonControlFrame.cpp | 25 +-- .../html/forms/src/nsGfxButtonControlFrame.h | 4 + .../forms/src/nsGfxCheckboxControlFrame.cpp | 24 +-- .../forms/src/nsGfxCheckboxControlFrame.h | 5 + .../html/forms/src/nsGfxRadioControlFrame.cpp | 24 ++- .../html/forms/src/nsGfxRadioControlFrame.h | 3 + .../html/forms/src/nsGfxTextControlFrame.cpp | 24 +-- .../html/forms/src/nsGfxTextControlFrame2.cpp | 23 +-- .../html/forms/src/nsGfxTextControlFrame2.h | 2 + .../forms/src/nsHTMLButtonControlFrame.cpp | 22 ++- .../html/forms/src/nsHTMLButtonControlFrame.h | 3 + .../html/forms/src/nsImageControlFrame.cpp | 24 +-- .../html/table/src/nsTableCellFrame.cpp | 26 +-- .../layout/html/table/src/nsTableCellFrame.h | 3 + .../html/table/src/nsTableOuterFrame.cpp | 27 +-- .../layout/html/table/src/nsTableOuterFrame.h | 2 + mozilla/layout/tables/nsTableCellFrame.cpp | 26 +-- mozilla/layout/tables/nsTableCellFrame.h | 3 + mozilla/layout/tables/nsTableOuterFrame.cpp | 27 +-- mozilla/layout/tables/nsTableOuterFrame.h | 2 + mozilla/widget/src/windows/Accessible.cpp | 32 +++- mozilla/widget/src/windows/Accessible.h | 7 +- mozilla/widget/src/windows/nsWindow.h | 1 + 65 files changed, 734 insertions(+), 424 deletions(-) diff --git a/mozilla/accessible/public/nsIAccessible.idl b/mozilla/accessible/public/nsIAccessible.idl index cc44f1954b7..8e131ddf3c5 100644 --- a/mozilla/accessible/public/nsIAccessible.idl +++ b/mozilla/accessible/public/nsIAccessible.idl @@ -25,6 +25,7 @@ */ #include "nsISupports.idl" +#include "nsIDOMNode.idl" [scriptable, uuid(B26FBE47-9A5F-42a1-822B-082461AE4D6D)] interface nsIAccessible : nsISupports @@ -71,6 +72,8 @@ interface nsIAccessible : nsISupports wstring getAccActionName(in PRUint8 index); void accDoAction(in PRUint8 index); // Action number 0 is the default action + nsIDOMNode accGetDOMNode(); + // MSAA State flags - used for bitfield. More than 1 allowed. const unsigned long STATE_UNAVAILABLE = 0x00000001; // Disabled, maps to opposite of Java ENABLED, Gnome/ATK SENSITIVE? const unsigned long STATE_SELECTED = 0x00000002; diff --git a/mozilla/accessible/src/base/nsAccessibilityService.cpp b/mozilla/accessible/src/base/nsAccessibilityService.cpp index 2b8ddf2e401..a4413ad5107 100644 --- a/mozilla/accessible/src/base/nsAccessibilityService.cpp +++ b/mozilla/accessible/src/base/nsAccessibilityService.cpp @@ -80,7 +80,7 @@ nsAccessibilityService::CreateRootAccessible(nsISupports* aPresContext, nsISuppo NS_ASSERTION(s,"Error not presshell!!"); - nsCOMPtr wr = getter_AddRefs(NS_GetWeakReference(s)); + nsCOMPtr wr (getter_AddRefs(NS_GetWeakReference(s))); //printf("################################## CreateRootAccessible\n"); *_retval = new nsRootAccessible(wr); @@ -343,7 +343,7 @@ nsAccessibilityService::CreateHTMLIFrameAccessible(nsIDOMNode* node, nsISupports presContext->GetShell(getter_AddRefs(presShell)); NS_ASSERTION(presShell,"Error non PresShell passed to accessible factory!!!"); - nsCOMPtr weakRef = getter_AddRefs(NS_GetWeakReference(presShell)); + nsCOMPtr weakRef (getter_AddRefs(NS_GetWeakReference(presShell))); nsCOMPtr doc; if (NS_SUCCEEDED(content->GetDocument(*getter_AddRefs(doc))) && doc) { @@ -357,7 +357,7 @@ nsAccessibilityService::CreateHTMLIFrameAccessible(nsIDOMNode* node, nsISupports nsCOMPtr ps; docShell->GetPresShell(getter_AddRefs(ps)); if (ps) { - nsCOMPtr wr = getter_AddRefs(NS_GetWeakReference(ps)); + nsCOMPtr wr (getter_AddRefs(NS_GetWeakReference(ps))); //printf("################################## CreateHTMLIFrameAccessible\n"); nsCOMPtr root = new nsHTMLIFrameRootAccessible(wr,node); diff --git a/mozilla/accessible/src/base/nsAccessible.cpp b/mozilla/accessible/src/base/nsAccessible.cpp index 98961397550..67cf574f558 100644 --- a/mozilla/accessible/src/base/nsAccessible.cpp +++ b/mozilla/accessible/src/base/nsAccessible.cpp @@ -62,13 +62,19 @@ static gnsAccessibles = 0; static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); +/* + * This class is used to get the bounds of a DOM node. + * This is harder that it looks. Many frames point to + * the same DOM node. Some good examples are links and wrapping text. + */ class nsFrameTreeWalker { public: nsFrameTreeWalker(nsIPresContext* aPresContext, nsIDOMNode* aNode); PRBool GetNextSibling(); PRBool GetParent(); PRBool GetFirstChild(); - void GetBounds(nsRect& aBounds); + void GetBounds(nsRect& aBounds, nsIFrame** aParent); + void GetCommonParent(nsIFrame* aStartParent, nsIFrame* aChild, nsIFrame** aCommonParent); PRBool IsSameContent(); @@ -84,11 +90,15 @@ private: PRInt32 mDepthToFind; }; +/** + * This class uses a nsFrameTreeWalker to get the frames of a DOM node + * and then unions them all together into 1 rect. + */ class nsDOMNodeBoundsFinder { public: nsDOMNodeBoundsFinder(nsIPresContext* aPresContext, nsIDOMNode* aNode); - virtual void GetBounds(nsRect& aBounds); + virtual void GetBounds(nsRect& aBounds, nsIFrame** aRelativeFrame); private: nsCOMPtr mDOMNode; @@ -102,18 +112,32 @@ nsDOMNodeBoundsFinder::nsDOMNodeBoundsFinder(nsIPresContext* aPresContext, nsIDO { }; -void nsDOMNodeBoundsFinder::GetBounds(nsRect& aBounds) +void nsDOMNodeBoundsFinder::GetBounds(nsRect& aBounds, nsIFrame** aRelativeFrame) { - // sum up all the child rectangles +/* + * This method is used to determine the bounds of a content node. + * Because HTML wraps and links are not always rectangular, this + * method uses the following algorithm: + * + * 1) get the primary from for the DOM node. + * 2) Get its depth in the frame tree. + * 3) Find the next frame at the same depth. + * 4) If that frame has the same DOM node union it with the old bounds and continue. + * 5) If not stop. + */ + nsCOMPtr node(mDOMNode); mWalker.SetNode(mDOMNode); - mWalker.GetBounds(aBounds); + mWalker.mFrame->GetParent(aRelativeFrame); + + mWalker.GetBounds(aBounds, aRelativeFrame); + while(mWalker.GetNextSibling()) { nsRect rect; - mWalker.GetBounds(rect); + mWalker.GetBounds(rect, aRelativeFrame); aBounds.UnionRect(aBounds,rect); } } @@ -155,9 +179,52 @@ void nsFrameTreeWalker::InitDepth() } } -void nsFrameTreeWalker::GetBounds(nsRect& aBounds) +void nsFrameTreeWalker::GetCommonParent(nsIFrame* aStartParent, nsIFrame* aChild, nsIFrame** aCommonParent) { + // go up our parent chain until we hit the common parent + nsIFrame* parent = nsnull; + aChild->GetParent(&parent); + while(parent) + { + // if we find one return. + if (parent == aStartParent) { + *aCommonParent = aStartParent; + return; + } + + parent->GetParent(&parent); + } + + // if we don't find a common parent recursively call this with + // the starts parent. + aStartParent->GetParent(&aStartParent); + + if (aStartParent) + GetCommonParent(aStartParent, aChild, aCommonParent); + else + aCommonParent = nsnull; +} + +void nsFrameTreeWalker::GetBounds(nsRect& aBounds, nsIFrame** aParent) +{ + GetCommonParent(*aParent, mFrame, aParent); + + nsIFrame* parent = nsnull; + mFrame->GetParent(&parent); + mFrame->GetRect(aBounds); + nsRect rect; + + while(parent) + { + parent->GetRect(rect); + aBounds.x += rect.x; + aBounds.y += rect.y; + if (parent == *aParent) + return; + + parent->GetParent(&parent); + } } PRBool nsFrameTreeWalker::GetParent() @@ -309,6 +376,10 @@ PRBool nsFrameTreeWalker::IsSameContent() //-------------- +/** This class is used to walk the DOM tree. It skips + * everything but nodes that either implement nsIAccessible + * or have primary frames that implement "GetAccessible" + */ class nsDOMTreeWalker { public: nsDOMTreeWalker(nsIWeakReference* aShell, nsIDOMNode* aContent); @@ -370,9 +441,9 @@ PRBool nsDOMTreeWalker::GetParent() { nsCOMPtr acc; nsresult rv = mAccessible->GetAccParent(getter_AddRefs(acc)); - if (NS_SUCCEEDED(rv)) { + if (NS_SUCCEEDED(rv) && acc) { mAccessible = acc; - mDOMNode = do_QueryInterface(acc); + acc->AccGetDOMNode(getter_AddRefs(mDOMNode)); return PR_TRUE; } } @@ -393,21 +464,25 @@ PRBool nsDOMTreeWalker::GetParent() getter_AddRefs(content)))) { nsIFrame* frame; parentPresShell->GetPrimaryFrameFor(content, &frame); - nsCOMPtr accessible(do_QueryInterface(frame)); - if (!accessible) - accessible = do_QueryInterface(content); - if (accessible) { - nsCOMPtr wr = getter_AddRefs(NS_GetWeakReference(parentPresShell)); - nsCOMPtr node(do_QueryInterface(accessible)); - mAccessible = accessible; - mDOMNode = node; - mPresShell = wr; - return PR_TRUE; + if (frame) { + nsCOMPtr accessible; + + frame->GetAccessible(getter_AddRefs(accessible)); + + if (!accessible) + accessible = do_QueryInterface(content); + if (accessible) { + nsCOMPtr wr (getter_AddRefs(NS_GetWeakReference(parentPresShell))); + accessible->AccGetDOMNode(getter_AddRefs(mDOMNode)); + mAccessible = accessible; + mPresShell = wr; + return PR_TRUE; + } } } mAccessible = new nsRootAccessible(mPresShell); - mDOMNode = do_QueryInterface(mAccessible); + mAccessible->AccGetDOMNode(getter_AddRefs(mDOMNode)); return PR_TRUE; } @@ -439,9 +514,9 @@ PRBool nsDOMTreeWalker::GetNextSibling() { nsCOMPtr acc; nsresult rv = mAccessible->GetAccNextSibling(getter_AddRefs(acc)); - if (NS_SUCCEEDED(rv)) { + if (NS_SUCCEEDED(rv) && acc) { mAccessible = acc; - mDOMNode = do_QueryInterface(acc); + acc->AccGetDOMNode(getter_AddRefs(mDOMNode)); return PR_TRUE; } } @@ -523,9 +598,9 @@ PRBool nsDOMTreeWalker::GetFirstChild() { nsCOMPtr acc; nsresult rv = mAccessible->GetAccFirstChild(getter_AddRefs(acc)); - if (NS_SUCCEEDED(rv)) { + if (NS_SUCCEEDED(rv) && acc) { mAccessible = acc; - mDOMNode = do_QueryInterface(acc); + acc->AccGetDOMNode(getter_AddRefs(mDOMNode)); return PR_TRUE; } } @@ -638,6 +713,10 @@ PRInt32 nsDOMTreeWalker::GetCount() return count; } +/** + * If the DOM node's frame has and accessible or the DOMNode + * itself implements nsIAccessible return it. + */ PRBool nsDOMTreeWalker::GetAccessible() { mAccessible = nsnull; @@ -655,7 +734,8 @@ PRBool nsDOMTreeWalker::GetAccessible() if (!frame) return PR_FALSE; - mAccessible = do_QueryInterface(frame); + frame->GetAccessible(getter_AddRefs(mAccessible)); + if (!mAccessible) mAccessible = do_QueryInterface(mDOMNode); @@ -735,20 +815,7 @@ nsAccessible::~nsAccessible() #endif } -NS_IMPL_ADDREF(nsAccessible); -NS_IMPL_RELEASE(nsAccessible); - -//NS_IMPL_ISUPPORTS1(nsAccessible, nsIAccessible); -NS_INTERFACE_MAP_BEGIN(nsAccessible) - NS_INTERFACE_MAP_ENTRY(nsIAccessible) - if (aIID.Equals(NS_GET_IID(nsIDOMNode))) { - nsIDOMNode* node = mDOMNode; - *aInstancePtr = (void*) node; - NS_ADDREF(node); - return NS_OK; - } else -NS_INTERFACE_MAP_END - +NS_IMPL_ISUPPORTS1(nsAccessible, nsIAccessible); nsresult nsAccessible::GetAccParent(nsIAccessible ** aAccParent) { @@ -959,7 +1026,7 @@ NS_IMETHODIMP nsAccessible::GetAccActionName(PRUint8 index, PRUnichar **_retval) *_retval = 0; if (mAccessible && NS_SUCCEEDED(GetAccNumActions(&numActions)) && indexGetAccActionName(index, _retval); - if (**_retval && NS_SUCCEEDED(rv)) { + if (*_retval && NS_SUCCEEDED(rv)) { nsAutoString newString; rv = GetTranslatedString(*_retval, &newString); if (NS_SUCCEEDED(rv)) { @@ -1223,7 +1290,12 @@ NS_IMETHODIMP nsAccessible::AccTakeFocus(void) return NS_ERROR_FAILURE; } - +NS_IMETHODIMP nsAccessible::AccGetDOMNode(nsIDOMNode **_retval) +{ + *_retval = mDOMNode; + NS_IF_ADDREF(*_retval); + return NS_OK; +} nsresult nsAccessible::GetDocShellFromPS(nsIPresShell* aPresShell, nsIDocShell** aDocShell) { @@ -1513,13 +1585,13 @@ nsAccessible::GetAbsoluteFramePosition(nsIPresContext* aPresContext, } -void nsAccessible::GetBounds(nsRect& aBounds) +void nsAccessible::GetBounds(nsRect& aBounds, nsIFrame** aRelativeParent) { nsCOMPtr presContext; GetPresContext(presContext); nsDOMNodeBoundsFinder finder(presContext, mDOMNode); - finder.GetBounds(aBounds); + finder.GetBounds(aBounds, aRelativeParent); } @@ -1551,7 +1623,8 @@ NS_IMETHODIMP nsAccessible::AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, presContext->GetTwipsToPixels(&t2p); // Get pixels to twips conversion factor nsRect unionRectTwips; - GetBounds(unionRectTwips); // Unions up all primary frames for this node and all siblings after it + nsIFrame* aRelativeFrame = nsnull; + GetBounds(unionRectTwips, &aRelativeFrame); // Unions up all primary frames for this node and all siblings after it *x = NSTwipsToIntPixels(unionRectTwips.x, t2p); *y = NSTwipsToIntPixels(unionRectTwips.y, t2p); @@ -1565,8 +1638,8 @@ NS_IMETHODIMP nsAccessible::AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, nsRect orgRectTwips, frameRectTwips, orgRectPixels; // Get the offset of this frame in screen coordinates - if (frame && NS_SUCCEEDED(GetAbsoluteFramePosition(presContext, frame, orgRectTwips, orgRectPixels))) { - frame->GetRect(frameRectTwips); // Usually just the primary frame, but can be the choice list frame for an nsSelectAccessible + if (frame && NS_SUCCEEDED(GetAbsoluteFramePosition(presContext, aRelativeFrame, orgRectTwips, orgRectPixels))) { + aRelativeFrame->GetRect(frameRectTwips); // Usually just the primary frame, but can be the choice list frame for an nsSelectAccessible // Add in the absolute coorinates. // Since these absolute coordinates are for the primary frame, // also subtract the difference between our primary frame and our bounds frame diff --git a/mozilla/accessible/src/base/nsAccessible.h b/mozilla/accessible/src/base/nsAccessible.h index 261f977f430..e320d90433e 100644 --- a/mozilla/accessible/src/base/nsAccessible.h +++ b/mozilla/accessible/src/base/nsAccessible.h @@ -50,8 +50,6 @@ class nsAccessible : public nsIAccessible // nsIAccessibilityService methods: NS_DECL_NSIACCESSIBLE - //NS_IMETHOD AccGetWidget(nsIWidget**); - public: nsAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell); virtual ~nsAccessible(); @@ -87,7 +85,7 @@ class nsAccessible : public nsIAccessible protected: virtual nsIFrame* GetFrame(); virtual nsIFrame* GetBoundsFrame(); - virtual void GetBounds(nsRect& aRect); + virtual void GetBounds(nsRect& aRect, nsIFrame** aRelativeFrame); virtual void GetPresContext(nsCOMPtr& aContext); virtual nsIAccessible* CreateNewNextAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell); virtual nsIAccessible* CreateNewPreviousAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell); diff --git a/mozilla/accessible/src/base/nsGenericAccessible.cpp b/mozilla/accessible/src/base/nsGenericAccessible.cpp index cc5b00db909..368f160b304 100644 --- a/mozilla/accessible/src/base/nsGenericAccessible.cpp +++ b/mozilla/accessible/src/base/nsGenericAccessible.cpp @@ -236,6 +236,11 @@ NS_IMETHODIMP nsGenericAccessible::GetAccExtState(PRUint32 *_retval) return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMETHODIMP nsGenericAccessible::AccGetDOMNode(nsIDOMNode **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + //------------- // nsDOMAccessible //------------- @@ -262,6 +267,12 @@ nsDOMAccessible::nsDOMAccessible(nsIPresShell* aShell, nsIDOMNode* aNode) mNode = aNode; } +NS_IMETHODIMP nsDOMAccessible::AccGetDOMNode(nsIDOMNode **_retval) +{ + *_retval = mNode; + NS_IF_ADDREF(*_retval); + return NS_OK; +} /* void accRemoveSelection (); */ NS_IMETHODIMP nsDOMAccessible::AccRemoveSelection() diff --git a/mozilla/accessible/src/base/nsGenericAccessible.h b/mozilla/accessible/src/base/nsGenericAccessible.h index 6083e4ccac0..88e997d2580 100644 --- a/mozilla/accessible/src/base/nsGenericAccessible.h +++ b/mozilla/accessible/src/base/nsGenericAccessible.h @@ -63,6 +63,7 @@ class nsDOMAccessible : public nsGenericAccessible NS_IMETHOD AccTakeSelection(void); NS_IMETHOD AccTakeFocus(void); NS_IMETHOD AccRemoveSelection(void); + NS_IMETHOD AccGetDOMNode(nsIDOMNode **_retval); protected: NS_IMETHOD AppendFlatStringFromSubtree(nsIContent *aContent, nsAWritableString *aFlatString); diff --git a/mozilla/accessible/src/base/nsRootAccessible.cpp b/mozilla/accessible/src/base/nsRootAccessible.cpp index 7b80b7d27d4..e2aa31a6879 100644 --- a/mozilla/accessible/src/base/nsRootAccessible.cpp +++ b/mozilla/accessible/src/base/nsRootAccessible.cpp @@ -89,10 +89,10 @@ nsIFrame* nsRootAccessible::GetFrame() return root; } -void nsRootAccessible::GetBounds(nsRect& aBounds) +void nsRootAccessible::GetBounds(nsRect& aBounds, nsIFrame** aRelativeFrame) { - nsIFrame* frame = GetFrame(); - frame->GetRect(aBounds); + *aRelativeFrame = GetFrame(); + (*aRelativeFrame)->GetRect(aBounds); } nsIAccessible* nsRootAccessible::CreateNewAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell) diff --git a/mozilla/accessible/src/base/nsRootAccessible.h b/mozilla/accessible/src/base/nsRootAccessible.h index ad10ca6c5d0..33f01a10aef 100644 --- a/mozilla/accessible/src/base/nsRootAccessible.h +++ b/mozilla/accessible/src/base/nsRootAccessible.h @@ -69,7 +69,7 @@ class nsRootAccessible : public nsAccessible, NS_IMETHOD Input(nsIDOMEvent* aEvent); protected: - virtual void GetBounds(nsRect& aRect); + virtual void GetBounds(nsRect& aRect, nsIFrame** aRelativeFrame); virtual nsIFrame* GetFrame(); virtual nsIAccessible* CreateNewAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell); diff --git a/mozilla/accessible/src/nsAccessibilityService.cpp b/mozilla/accessible/src/nsAccessibilityService.cpp index 2b8ddf2e401..a4413ad5107 100644 --- a/mozilla/accessible/src/nsAccessibilityService.cpp +++ b/mozilla/accessible/src/nsAccessibilityService.cpp @@ -80,7 +80,7 @@ nsAccessibilityService::CreateRootAccessible(nsISupports* aPresContext, nsISuppo NS_ASSERTION(s,"Error not presshell!!"); - nsCOMPtr wr = getter_AddRefs(NS_GetWeakReference(s)); + nsCOMPtr wr (getter_AddRefs(NS_GetWeakReference(s))); //printf("################################## CreateRootAccessible\n"); *_retval = new nsRootAccessible(wr); @@ -343,7 +343,7 @@ nsAccessibilityService::CreateHTMLIFrameAccessible(nsIDOMNode* node, nsISupports presContext->GetShell(getter_AddRefs(presShell)); NS_ASSERTION(presShell,"Error non PresShell passed to accessible factory!!!"); - nsCOMPtr weakRef = getter_AddRefs(NS_GetWeakReference(presShell)); + nsCOMPtr weakRef (getter_AddRefs(NS_GetWeakReference(presShell))); nsCOMPtr doc; if (NS_SUCCEEDED(content->GetDocument(*getter_AddRefs(doc))) && doc) { @@ -357,7 +357,7 @@ nsAccessibilityService::CreateHTMLIFrameAccessible(nsIDOMNode* node, nsISupports nsCOMPtr ps; docShell->GetPresShell(getter_AddRefs(ps)); if (ps) { - nsCOMPtr wr = getter_AddRefs(NS_GetWeakReference(ps)); + nsCOMPtr wr (getter_AddRefs(NS_GetWeakReference(ps))); //printf("################################## CreateHTMLIFrameAccessible\n"); nsCOMPtr root = new nsHTMLIFrameRootAccessible(wr,node); diff --git a/mozilla/accessible/src/nsAccessible.cpp b/mozilla/accessible/src/nsAccessible.cpp index 98961397550..67cf574f558 100644 --- a/mozilla/accessible/src/nsAccessible.cpp +++ b/mozilla/accessible/src/nsAccessible.cpp @@ -62,13 +62,19 @@ static gnsAccessibles = 0; static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); +/* + * This class is used to get the bounds of a DOM node. + * This is harder that it looks. Many frames point to + * the same DOM node. Some good examples are links and wrapping text. + */ class nsFrameTreeWalker { public: nsFrameTreeWalker(nsIPresContext* aPresContext, nsIDOMNode* aNode); PRBool GetNextSibling(); PRBool GetParent(); PRBool GetFirstChild(); - void GetBounds(nsRect& aBounds); + void GetBounds(nsRect& aBounds, nsIFrame** aParent); + void GetCommonParent(nsIFrame* aStartParent, nsIFrame* aChild, nsIFrame** aCommonParent); PRBool IsSameContent(); @@ -84,11 +90,15 @@ private: PRInt32 mDepthToFind; }; +/** + * This class uses a nsFrameTreeWalker to get the frames of a DOM node + * and then unions them all together into 1 rect. + */ class nsDOMNodeBoundsFinder { public: nsDOMNodeBoundsFinder(nsIPresContext* aPresContext, nsIDOMNode* aNode); - virtual void GetBounds(nsRect& aBounds); + virtual void GetBounds(nsRect& aBounds, nsIFrame** aRelativeFrame); private: nsCOMPtr mDOMNode; @@ -102,18 +112,32 @@ nsDOMNodeBoundsFinder::nsDOMNodeBoundsFinder(nsIPresContext* aPresContext, nsIDO { }; -void nsDOMNodeBoundsFinder::GetBounds(nsRect& aBounds) +void nsDOMNodeBoundsFinder::GetBounds(nsRect& aBounds, nsIFrame** aRelativeFrame) { - // sum up all the child rectangles +/* + * This method is used to determine the bounds of a content node. + * Because HTML wraps and links are not always rectangular, this + * method uses the following algorithm: + * + * 1) get the primary from for the DOM node. + * 2) Get its depth in the frame tree. + * 3) Find the next frame at the same depth. + * 4) If that frame has the same DOM node union it with the old bounds and continue. + * 5) If not stop. + */ + nsCOMPtr node(mDOMNode); mWalker.SetNode(mDOMNode); - mWalker.GetBounds(aBounds); + mWalker.mFrame->GetParent(aRelativeFrame); + + mWalker.GetBounds(aBounds, aRelativeFrame); + while(mWalker.GetNextSibling()) { nsRect rect; - mWalker.GetBounds(rect); + mWalker.GetBounds(rect, aRelativeFrame); aBounds.UnionRect(aBounds,rect); } } @@ -155,9 +179,52 @@ void nsFrameTreeWalker::InitDepth() } } -void nsFrameTreeWalker::GetBounds(nsRect& aBounds) +void nsFrameTreeWalker::GetCommonParent(nsIFrame* aStartParent, nsIFrame* aChild, nsIFrame** aCommonParent) { + // go up our parent chain until we hit the common parent + nsIFrame* parent = nsnull; + aChild->GetParent(&parent); + while(parent) + { + // if we find one return. + if (parent == aStartParent) { + *aCommonParent = aStartParent; + return; + } + + parent->GetParent(&parent); + } + + // if we don't find a common parent recursively call this with + // the starts parent. + aStartParent->GetParent(&aStartParent); + + if (aStartParent) + GetCommonParent(aStartParent, aChild, aCommonParent); + else + aCommonParent = nsnull; +} + +void nsFrameTreeWalker::GetBounds(nsRect& aBounds, nsIFrame** aParent) +{ + GetCommonParent(*aParent, mFrame, aParent); + + nsIFrame* parent = nsnull; + mFrame->GetParent(&parent); + mFrame->GetRect(aBounds); + nsRect rect; + + while(parent) + { + parent->GetRect(rect); + aBounds.x += rect.x; + aBounds.y += rect.y; + if (parent == *aParent) + return; + + parent->GetParent(&parent); + } } PRBool nsFrameTreeWalker::GetParent() @@ -309,6 +376,10 @@ PRBool nsFrameTreeWalker::IsSameContent() //-------------- +/** This class is used to walk the DOM tree. It skips + * everything but nodes that either implement nsIAccessible + * or have primary frames that implement "GetAccessible" + */ class nsDOMTreeWalker { public: nsDOMTreeWalker(nsIWeakReference* aShell, nsIDOMNode* aContent); @@ -370,9 +441,9 @@ PRBool nsDOMTreeWalker::GetParent() { nsCOMPtr acc; nsresult rv = mAccessible->GetAccParent(getter_AddRefs(acc)); - if (NS_SUCCEEDED(rv)) { + if (NS_SUCCEEDED(rv) && acc) { mAccessible = acc; - mDOMNode = do_QueryInterface(acc); + acc->AccGetDOMNode(getter_AddRefs(mDOMNode)); return PR_TRUE; } } @@ -393,21 +464,25 @@ PRBool nsDOMTreeWalker::GetParent() getter_AddRefs(content)))) { nsIFrame* frame; parentPresShell->GetPrimaryFrameFor(content, &frame); - nsCOMPtr accessible(do_QueryInterface(frame)); - if (!accessible) - accessible = do_QueryInterface(content); - if (accessible) { - nsCOMPtr wr = getter_AddRefs(NS_GetWeakReference(parentPresShell)); - nsCOMPtr node(do_QueryInterface(accessible)); - mAccessible = accessible; - mDOMNode = node; - mPresShell = wr; - return PR_TRUE; + if (frame) { + nsCOMPtr accessible; + + frame->GetAccessible(getter_AddRefs(accessible)); + + if (!accessible) + accessible = do_QueryInterface(content); + if (accessible) { + nsCOMPtr wr (getter_AddRefs(NS_GetWeakReference(parentPresShell))); + accessible->AccGetDOMNode(getter_AddRefs(mDOMNode)); + mAccessible = accessible; + mPresShell = wr; + return PR_TRUE; + } } } mAccessible = new nsRootAccessible(mPresShell); - mDOMNode = do_QueryInterface(mAccessible); + mAccessible->AccGetDOMNode(getter_AddRefs(mDOMNode)); return PR_TRUE; } @@ -439,9 +514,9 @@ PRBool nsDOMTreeWalker::GetNextSibling() { nsCOMPtr acc; nsresult rv = mAccessible->GetAccNextSibling(getter_AddRefs(acc)); - if (NS_SUCCEEDED(rv)) { + if (NS_SUCCEEDED(rv) && acc) { mAccessible = acc; - mDOMNode = do_QueryInterface(acc); + acc->AccGetDOMNode(getter_AddRefs(mDOMNode)); return PR_TRUE; } } @@ -523,9 +598,9 @@ PRBool nsDOMTreeWalker::GetFirstChild() { nsCOMPtr acc; nsresult rv = mAccessible->GetAccFirstChild(getter_AddRefs(acc)); - if (NS_SUCCEEDED(rv)) { + if (NS_SUCCEEDED(rv) && acc) { mAccessible = acc; - mDOMNode = do_QueryInterface(acc); + acc->AccGetDOMNode(getter_AddRefs(mDOMNode)); return PR_TRUE; } } @@ -638,6 +713,10 @@ PRInt32 nsDOMTreeWalker::GetCount() return count; } +/** + * If the DOM node's frame has and accessible or the DOMNode + * itself implements nsIAccessible return it. + */ PRBool nsDOMTreeWalker::GetAccessible() { mAccessible = nsnull; @@ -655,7 +734,8 @@ PRBool nsDOMTreeWalker::GetAccessible() if (!frame) return PR_FALSE; - mAccessible = do_QueryInterface(frame); + frame->GetAccessible(getter_AddRefs(mAccessible)); + if (!mAccessible) mAccessible = do_QueryInterface(mDOMNode); @@ -735,20 +815,7 @@ nsAccessible::~nsAccessible() #endif } -NS_IMPL_ADDREF(nsAccessible); -NS_IMPL_RELEASE(nsAccessible); - -//NS_IMPL_ISUPPORTS1(nsAccessible, nsIAccessible); -NS_INTERFACE_MAP_BEGIN(nsAccessible) - NS_INTERFACE_MAP_ENTRY(nsIAccessible) - if (aIID.Equals(NS_GET_IID(nsIDOMNode))) { - nsIDOMNode* node = mDOMNode; - *aInstancePtr = (void*) node; - NS_ADDREF(node); - return NS_OK; - } else -NS_INTERFACE_MAP_END - +NS_IMPL_ISUPPORTS1(nsAccessible, nsIAccessible); nsresult nsAccessible::GetAccParent(nsIAccessible ** aAccParent) { @@ -959,7 +1026,7 @@ NS_IMETHODIMP nsAccessible::GetAccActionName(PRUint8 index, PRUnichar **_retval) *_retval = 0; if (mAccessible && NS_SUCCEEDED(GetAccNumActions(&numActions)) && indexGetAccActionName(index, _retval); - if (**_retval && NS_SUCCEEDED(rv)) { + if (*_retval && NS_SUCCEEDED(rv)) { nsAutoString newString; rv = GetTranslatedString(*_retval, &newString); if (NS_SUCCEEDED(rv)) { @@ -1223,7 +1290,12 @@ NS_IMETHODIMP nsAccessible::AccTakeFocus(void) return NS_ERROR_FAILURE; } - +NS_IMETHODIMP nsAccessible::AccGetDOMNode(nsIDOMNode **_retval) +{ + *_retval = mDOMNode; + NS_IF_ADDREF(*_retval); + return NS_OK; +} nsresult nsAccessible::GetDocShellFromPS(nsIPresShell* aPresShell, nsIDocShell** aDocShell) { @@ -1513,13 +1585,13 @@ nsAccessible::GetAbsoluteFramePosition(nsIPresContext* aPresContext, } -void nsAccessible::GetBounds(nsRect& aBounds) +void nsAccessible::GetBounds(nsRect& aBounds, nsIFrame** aRelativeParent) { nsCOMPtr presContext; GetPresContext(presContext); nsDOMNodeBoundsFinder finder(presContext, mDOMNode); - finder.GetBounds(aBounds); + finder.GetBounds(aBounds, aRelativeParent); } @@ -1551,7 +1623,8 @@ NS_IMETHODIMP nsAccessible::AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, presContext->GetTwipsToPixels(&t2p); // Get pixels to twips conversion factor nsRect unionRectTwips; - GetBounds(unionRectTwips); // Unions up all primary frames for this node and all siblings after it + nsIFrame* aRelativeFrame = nsnull; + GetBounds(unionRectTwips, &aRelativeFrame); // Unions up all primary frames for this node and all siblings after it *x = NSTwipsToIntPixels(unionRectTwips.x, t2p); *y = NSTwipsToIntPixels(unionRectTwips.y, t2p); @@ -1565,8 +1638,8 @@ NS_IMETHODIMP nsAccessible::AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, nsRect orgRectTwips, frameRectTwips, orgRectPixels; // Get the offset of this frame in screen coordinates - if (frame && NS_SUCCEEDED(GetAbsoluteFramePosition(presContext, frame, orgRectTwips, orgRectPixels))) { - frame->GetRect(frameRectTwips); // Usually just the primary frame, but can be the choice list frame for an nsSelectAccessible + if (frame && NS_SUCCEEDED(GetAbsoluteFramePosition(presContext, aRelativeFrame, orgRectTwips, orgRectPixels))) { + aRelativeFrame->GetRect(frameRectTwips); // Usually just the primary frame, but can be the choice list frame for an nsSelectAccessible // Add in the absolute coorinates. // Since these absolute coordinates are for the primary frame, // also subtract the difference between our primary frame and our bounds frame diff --git a/mozilla/accessible/src/nsAccessible.h b/mozilla/accessible/src/nsAccessible.h index 261f977f430..e320d90433e 100644 --- a/mozilla/accessible/src/nsAccessible.h +++ b/mozilla/accessible/src/nsAccessible.h @@ -50,8 +50,6 @@ class nsAccessible : public nsIAccessible // nsIAccessibilityService methods: NS_DECL_NSIACCESSIBLE - //NS_IMETHOD AccGetWidget(nsIWidget**); - public: nsAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell); virtual ~nsAccessible(); @@ -87,7 +85,7 @@ class nsAccessible : public nsIAccessible protected: virtual nsIFrame* GetFrame(); virtual nsIFrame* GetBoundsFrame(); - virtual void GetBounds(nsRect& aRect); + virtual void GetBounds(nsRect& aRect, nsIFrame** aRelativeFrame); virtual void GetPresContext(nsCOMPtr& aContext); virtual nsIAccessible* CreateNewNextAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell); virtual nsIAccessible* CreateNewPreviousAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell); diff --git a/mozilla/accessible/src/nsGenericAccessible.cpp b/mozilla/accessible/src/nsGenericAccessible.cpp index cc5b00db909..368f160b304 100644 --- a/mozilla/accessible/src/nsGenericAccessible.cpp +++ b/mozilla/accessible/src/nsGenericAccessible.cpp @@ -236,6 +236,11 @@ NS_IMETHODIMP nsGenericAccessible::GetAccExtState(PRUint32 *_retval) return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMETHODIMP nsGenericAccessible::AccGetDOMNode(nsIDOMNode **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + //------------- // nsDOMAccessible //------------- @@ -262,6 +267,12 @@ nsDOMAccessible::nsDOMAccessible(nsIPresShell* aShell, nsIDOMNode* aNode) mNode = aNode; } +NS_IMETHODIMP nsDOMAccessible::AccGetDOMNode(nsIDOMNode **_retval) +{ + *_retval = mNode; + NS_IF_ADDREF(*_retval); + return NS_OK; +} /* void accRemoveSelection (); */ NS_IMETHODIMP nsDOMAccessible::AccRemoveSelection() diff --git a/mozilla/accessible/src/nsGenericAccessible.h b/mozilla/accessible/src/nsGenericAccessible.h index 6083e4ccac0..88e997d2580 100644 --- a/mozilla/accessible/src/nsGenericAccessible.h +++ b/mozilla/accessible/src/nsGenericAccessible.h @@ -63,6 +63,7 @@ class nsDOMAccessible : public nsGenericAccessible NS_IMETHOD AccTakeSelection(void); NS_IMETHOD AccTakeFocus(void); NS_IMETHOD AccRemoveSelection(void); + NS_IMETHOD AccGetDOMNode(nsIDOMNode **_retval); protected: NS_IMETHOD AppendFlatStringFromSubtree(nsIContent *aContent, nsAWritableString *aFlatString); diff --git a/mozilla/accessible/src/nsRootAccessible.cpp b/mozilla/accessible/src/nsRootAccessible.cpp index 7b80b7d27d4..e2aa31a6879 100644 --- a/mozilla/accessible/src/nsRootAccessible.cpp +++ b/mozilla/accessible/src/nsRootAccessible.cpp @@ -89,10 +89,10 @@ nsIFrame* nsRootAccessible::GetFrame() return root; } -void nsRootAccessible::GetBounds(nsRect& aBounds) +void nsRootAccessible::GetBounds(nsRect& aBounds, nsIFrame** aRelativeFrame) { - nsIFrame* frame = GetFrame(); - frame->GetRect(aBounds); + *aRelativeFrame = GetFrame(); + (*aRelativeFrame)->GetRect(aBounds); } nsIAccessible* nsRootAccessible::CreateNewAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell) diff --git a/mozilla/accessible/src/nsRootAccessible.h b/mozilla/accessible/src/nsRootAccessible.h index ad10ca6c5d0..33f01a10aef 100644 --- a/mozilla/accessible/src/nsRootAccessible.h +++ b/mozilla/accessible/src/nsRootAccessible.h @@ -69,7 +69,7 @@ class nsRootAccessible : public nsAccessible, NS_IMETHOD Input(nsIDOMEvent* aEvent); protected: - virtual void GetBounds(nsRect& aRect); + virtual void GetBounds(nsRect& aRect, nsIFrame** aRelativeFrame); virtual nsIFrame* GetFrame(); virtual nsIAccessible* CreateNewAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell); diff --git a/mozilla/layout/base/public/nsIFrame.h b/mozilla/layout/base/public/nsIFrame.h index 07780f5a569..c31048f885c 100644 --- a/mozilla/layout/base/public/nsIFrame.h +++ b/mozilla/layout/base/public/nsIFrame.h @@ -77,6 +77,8 @@ class nsICaret; class nsISelectionController; struct PRLogModuleInfo; +class nsIAccessible; + // IID for the nsIFrame interface // a6cf9050-15b3-11d2-932e-00805f8add32 #define NS_IFRAME_IID \ @@ -1091,6 +1093,15 @@ public: NS_IMETHOD ReflowDirtyChild(nsIPresShell* aPresShell, nsIFrame* aChild) = 0; + /** + * Called to retrieve this frame's accessible. + * If this frame implements Accessibility return a valid accessible + * If not return NS_ERROR_NOT_IMPLEMENTED. + * Note: nsAccessible must be refcountable. Do not implement directly on your frame + * Use a mediatior of some kind. + */ + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible) = 0; + /** * Called during appending or cancelling a reflow command to give frames notice * of reflow commands that will be targeted below them. diff --git a/mozilla/layout/forms/nsComboboxControlFrame.cpp b/mozilla/layout/forms/nsComboboxControlFrame.cpp index 68b80ae23b6..40a514e34b4 100644 --- a/mozilla/layout/forms/nsComboboxControlFrame.cpp +++ b/mozilla/layout/forms/nsComboboxControlFrame.cpp @@ -305,23 +305,24 @@ nsComboboxControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) } else if (aIID.Equals(NS_GET_IID(nsIScrollableViewProvider))) { *aInstancePtr = (void*)(nsIScrollableViewProvider*)this; return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv = NS_OK; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsCOMPtr node = do_QueryInterface(mContent); - nsIAccessible* acc = nsnull; - accService->CreateHTMLSelectAccessible(nsLayoutAtoms::popupList, node, mPresContext, &acc); - *aInstancePtr = acc; - return NS_OK; - } - return NS_ERROR_FAILURE; } - return nsAreaFrame::QueryInterface(aIID, aInstancePtr); } +NS_IMETHODIMP nsComboboxControlFrame::GetAccessible(nsIAccessible** aAccessible) +{ + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsCOMPtr node = do_QueryInterface(mContent); + return accService->CreateHTMLSelectAccessible(nsLayoutAtoms::popupList, node, mPresContext, aAccessible); + } + + return NS_ERROR_FAILURE; +} + + NS_IMETHODIMP nsComboboxControlFrame::Init(nsIPresContext* aPresContext, diff --git a/mozilla/layout/forms/nsComboboxControlFrame.h b/mozilla/layout/forms/nsComboboxControlFrame.h index b3402961f57..4889339694e 100644 --- a/mozilla/layout/forms/nsComboboxControlFrame.h +++ b/mozilla/layout/forms/nsComboboxControlFrame.h @@ -86,6 +86,8 @@ public: nsIContent * aContent, nsIFrame** aFrame); + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + // nsIFrame NS_IMETHOD Init(nsIPresContext* aPresContext, nsIContent* aContent, diff --git a/mozilla/layout/forms/nsGfxButtonControlFrame.cpp b/mozilla/layout/forms/nsGfxButtonControlFrame.cpp index 6363cf94198..6be2626455a 100644 --- a/mozilla/layout/forms/nsGfxButtonControlFrame.cpp +++ b/mozilla/layout/forms/nsGfxButtonControlFrame.cpp @@ -462,6 +462,18 @@ nsGfxButtonControlFrame::CreateFrameFor(nsIPresContext* aPresContext, return rv; } +NS_IMETHODIMP nsGfxButtonControlFrame::GetAccessible(nsIAccessible** aAccessible) +{ + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsIAccessible* acc = nsnull; + return accService->CreateHTMLButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); + } + + return NS_ERROR_FAILURE; +} + // Frames are not refcounted, no need to AddRef NS_IMETHODIMP nsGfxButtonControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) @@ -472,18 +484,7 @@ nsGfxButtonControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) *aInstancePtr = NS_STATIC_CAST(nsIAnonymousContentCreator*, this); } else if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) { *aInstancePtr = NS_STATIC_CAST(nsIStatefulFrame*, this); - } else if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv = NS_OK; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsIAccessible* acc = nsnull; - accService->CreateHTMLButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), &acc); - *aInstancePtr = acc; - return NS_OK; - } - return NS_ERROR_FAILURE; - - } + } else { return nsHTMLButtonControlFrame::QueryInterface(aIID, aInstancePtr); } diff --git a/mozilla/layout/forms/nsGfxButtonControlFrame.h b/mozilla/layout/forms/nsGfxButtonControlFrame.h index 97d98465fb3..f4445defeef 100644 --- a/mozilla/layout/forms/nsGfxButtonControlFrame.h +++ b/mozilla/layout/forms/nsGfxButtonControlFrame.h @@ -30,6 +30,8 @@ #include "nsITextContent.h" #include "nsIStatefulFrame.h" +class nsIAccessible; + // Class which implements the input[type=button, reset, submit] and // browse button for input[type=file]. // The label for button is specified through generated content @@ -57,6 +59,8 @@ public: nsEventStatus* aEventStatus); + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + // nsFormControlFrame NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight); #ifdef DEBUG diff --git a/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp b/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp index f262923562f..b09b0022f7a 100644 --- a/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp +++ b/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp @@ -87,21 +87,21 @@ nsGfxCheckboxControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr return NS_OK; } - if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv = NS_OK; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsIAccessible* acc = nsnull; - accService->CreateHTMLCheckboxAccessible(NS_STATIC_CAST(nsIFrame*, this), &acc); - *aInstancePtr = acc; - return NS_OK; - } - return NS_ERROR_FAILURE; - } - return nsFormControlFrame::QueryInterface(aIID, aInstancePtr); } +NS_IMETHODIMP nsGfxCheckboxControlFrame::GetAccessible(nsIAccessible** aAccessible) +{ + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsIAccessible* acc = nsnull; + return accService->CreateHTMLCheckboxAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); + } + + return NS_ERROR_FAILURE; +} + //-------------------------------------------------------------- NS_IMETHODIMP nsGfxCheckboxControlFrame::SetCheckboxFaceStyleContext(nsIStyleContext *aCheckboxFaceStyleContext) diff --git a/mozilla/layout/forms/nsGfxCheckboxControlFrame.h b/mozilla/layout/forms/nsGfxCheckboxControlFrame.h index 96b58d3ad56..512bb40c086 100644 --- a/mozilla/layout/forms/nsGfxCheckboxControlFrame.h +++ b/mozilla/layout/forms/nsGfxCheckboxControlFrame.h @@ -26,6 +26,8 @@ #include "nsIStatefulFrame.h" #include "nsICheckboxControlFrame.h" +class nsIAccessible; + #define NS_GFX_CHECKBOX_CONTROL_FRAME_FACE_CONTEXT_INDEX 0 // for additional style contexts #define NS_GFX_CHECKBOX_CONTROL_FRAME_LAST_CONTEXT_INDEX 0 @@ -67,6 +69,9 @@ public: const nsRect& aDirtyRect, nsFramePaintLayer aWhichLayer); + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + + //nsICheckboxControlFrame methods NS_IMETHOD SetCheckboxFaceStyleContext(nsIStyleContext *aCheckboxFaceStyleContext); diff --git a/mozilla/layout/forms/nsGfxRadioControlFrame.cpp b/mozilla/layout/forms/nsGfxRadioControlFrame.cpp index 534efccb778..2abf03ad3f9 100644 --- a/mozilla/layout/forms/nsGfxRadioControlFrame.cpp +++ b/mozilla/layout/forms/nsGfxRadioControlFrame.cpp @@ -80,23 +80,21 @@ nsGfxRadioControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) *aInstancePtr = (void*) ((nsIStatefulFrame*) this); return NS_OK; } - - if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv = NS_OK; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsCOMPtr node = do_QueryInterface(mContent); - nsIAccessible* acc = nsnull; - accService->CreateHTMLRadioButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), &acc); - *aInstancePtr = acc; - return NS_OK; - } - return NS_ERROR_FAILURE; - } return nsFormControlFrame::QueryInterface(aIID, aInstancePtr); } +NS_IMETHODIMP nsGfxRadioControlFrame::GetAccessible(nsIAccessible** aAccessible) +{ + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsIAccessible* acc = nsnull; + return accService->CreateHTMLRadioButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); + } + + return NS_ERROR_FAILURE; +} //-------------------------------------------------------------- NS_IMETHODIMP diff --git a/mozilla/layout/forms/nsGfxRadioControlFrame.h b/mozilla/layout/forms/nsGfxRadioControlFrame.h index 44d09ce3869..05823144e4b 100644 --- a/mozilla/layout/forms/nsGfxRadioControlFrame.h +++ b/mozilla/layout/forms/nsGfxRadioControlFrame.h @@ -27,6 +27,8 @@ #include "nsIStatefulFrame.h" #include "nsIRadioControlFrame.h" +class nsIAccessible; + // nsGfxRadioControlFrame #define NS_GFX_RADIO_CONTROL_FRAME_FACE_CONTEXT_INDEX 0 // for additional style contexts @@ -47,6 +49,7 @@ public: NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); NS_IMETHOD SetRadioButtonFaceStyleContext(nsIStyleContext *aRadioButtonFaceStyleContext); NS_IMETHOD GetRadioGroupSelectedContent(nsIContent ** aRadioBtn); + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); virtual PRBool GetChecked(); virtual PRBool GetDefaultChecked(); diff --git a/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp b/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp index 36183494179..9bb5a1ca5e9 100644 --- a/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp +++ b/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp @@ -162,20 +162,24 @@ nsHTMLButtonControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) if (aIID.Equals(NS_GET_IID(nsIFormControlFrame))) { *aInstancePtr = (void*) ((nsIFormControlFrame*) this); return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv = NS_OK; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsIAccessible* acc = nsnull; - accService->CreateHTML4ButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), &acc); - *aInstancePtr = acc; - return NS_OK; - } } return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr); } +NS_IMETHODIMP nsHTMLButtonControlFrame::GetAccessible(nsIAccessible** aAccessible) +{ + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsIAccessible* acc = nsnull; + return accService->CreateHTML4ButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); + } + + return NS_ERROR_FAILURE; +} + + void nsHTMLButtonControlFrame::GetDefaultLabel(nsString& aString) { diff --git a/mozilla/layout/forms/nsHTMLButtonControlFrame.h b/mozilla/layout/forms/nsHTMLButtonControlFrame.h index d4eaa47f4a5..7e1074fd496 100644 --- a/mozilla/layout/forms/nsHTMLButtonControlFrame.h +++ b/mozilla/layout/forms/nsHTMLButtonControlFrame.h @@ -99,6 +99,9 @@ public: nsIPresShell& aPresShell, nsIAtom* aListName, nsIFrame* aFrameList); + + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + #ifdef DEBUG NS_IMETHOD GetFrameName(nsString& aResult) const { return MakeFrameName("ButtonControl", aResult); diff --git a/mozilla/layout/forms/nsImageControlFrame.cpp b/mozilla/layout/forms/nsImageControlFrame.cpp index b746d7bd705..6cc83a19815 100644 --- a/mozilla/layout/forms/nsImageControlFrame.cpp +++ b/mozilla/layout/forms/nsImageControlFrame.cpp @@ -83,6 +83,8 @@ public: nsGUIEvent* aEvent, nsEventStatus* aEventStatus); + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + #ifdef DEBUG NS_IMETHOD GetFrameName(nsString& aResult) const { return MakeFrameName("ImageControl", aResult); @@ -199,21 +201,23 @@ nsImageControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) if (aIID.Equals(NS_GET_IID(nsIFormControlFrame))) { *aInstancePtr = (void*) ((nsIFormControlFrame*) this); return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsIAccessible* acc = nsnull; - accService->CreateHTML4ButtonAccessible(NS_STATIC_CAST(nsIFrame*, this),&acc); - *aInstancePtr = acc; - return NS_OK; - } - return NS_ERROR_FAILURE; } return nsImageControlFrameSuper::QueryInterface(aIID, aInstancePtr); } +NS_IMETHODIMP nsImageControlFrame::GetAccessible(nsIAccessible** aAccessible) +{ + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsIAccessible* acc = nsnull; + return accService->CreateHTML4ButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); + } + + return NS_ERROR_FAILURE; +} + nsrefcnt nsImageControlFrame::AddRef(void) { NS_WARNING("not supported"); diff --git a/mozilla/layout/generic/nsFrame.cpp b/mozilla/layout/generic/nsFrame.cpp index 07fe9a085fb..bb63d242185 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -270,16 +270,7 @@ nsresult nsFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) if (aIID.Equals(kClassIID) || aIID.Equals(kISupportsIID)) { *aInstancePtr = (void*)this; return NS_OK; - } /* else if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsIAccessible* acc = nsnull; - accService->CreateHTMLFrameAccessible(NS_STATIC_CAST(nsIFrame*, this),&acc); - *aInstancePtr = acc; - return NS_OK; - } - } */ + } return NS_NOINTERFACE; } @@ -3829,6 +3820,12 @@ nsFrame::ReflowDirtyChild(nsIPresShell* aPresShell, nsIFrame* aChild) } +NS_IMETHODIMP +nsFrame::GetAccessible(nsIAccessible** aAccessible) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP nsFrame::ReflowCommandNotify(nsIPresShell* aShell, nsIReflowCommand* aRC, diff --git a/mozilla/layout/generic/nsFrame.h b/mozilla/layout/generic/nsFrame.h index 225c23502c9..684216de76f 100644 --- a/mozilla/layout/generic/nsFrame.h +++ b/mozilla/layout/generic/nsFrame.h @@ -279,6 +279,8 @@ public: nsIReflowCommand* aRC, PRBool aCommandAdded); + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + NS_IMETHOD GetParentStyleContextProvider(nsIPresContext* aPresContext, nsIFrame** aProviderFrame, nsContextProviderRelationship& aRelationship); diff --git a/mozilla/layout/generic/nsFrameFrame.cpp b/mozilla/layout/generic/nsFrameFrame.cpp index c7a2ab7ebc0..537e0d8a8dc 100644 --- a/mozilla/layout/generic/nsFrameFrame.cpp +++ b/mozilla/layout/generic/nsFrameFrame.cpp @@ -152,6 +152,9 @@ public: PRInt32 aNameSpaceID, nsIAtom* aAttribute, PRInt32 aHint); + + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + NS_IMETHOD VerifyTree() const; PRBool IsInline(); @@ -238,6 +241,18 @@ nsHTMLFrameOuterFrame::~nsHTMLFrameOuterFrame() //printf("nsHTMLFrameOuterFrame destructor %X \n", this); } +NS_IMETHODIMP nsHTMLFrameOuterFrame::GetAccessible(nsIAccessible** aAccessible) +{ + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsCOMPtr node = do_QueryInterface(mContent); + return accService->CreateHTMLIFrameAccessible(node, mPresContext, aAccessible); + } + + return NS_ERROR_FAILURE; +} + //-------------------------------------------------------------- // Frames are not refcounted, no need to AddRef NS_IMETHODIMP @@ -248,20 +263,6 @@ nsHTMLFrameOuterFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) return NS_ERROR_NULL_POINTER; } - if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv = NS_OK; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsCOMPtr node = do_QueryInterface(mContent); - nsIAccessible* acc = nsnull; - accService->CreateHTMLIFrameAccessible(node, mPresContext, &acc); - NS_IF_ADDREF(acc); - *aInstancePtr = acc; - return NS_OK; - } - return NS_ERROR_FAILURE; - } - return nsHTMLFrameOuterFrameSuper::QueryInterface(aIID, aInstancePtr); } diff --git a/mozilla/layout/generic/nsIFrame.h b/mozilla/layout/generic/nsIFrame.h index 07780f5a569..c31048f885c 100644 --- a/mozilla/layout/generic/nsIFrame.h +++ b/mozilla/layout/generic/nsIFrame.h @@ -77,6 +77,8 @@ class nsICaret; class nsISelectionController; struct PRLogModuleInfo; +class nsIAccessible; + // IID for the nsIFrame interface // a6cf9050-15b3-11d2-932e-00805f8add32 #define NS_IFRAME_IID \ @@ -1091,6 +1093,15 @@ public: NS_IMETHOD ReflowDirtyChild(nsIPresShell* aPresShell, nsIFrame* aChild) = 0; + /** + * Called to retrieve this frame's accessible. + * If this frame implements Accessibility return a valid accessible + * If not return NS_ERROR_NOT_IMPLEMENTED. + * Note: nsAccessible must be refcountable. Do not implement directly on your frame + * Use a mediatior of some kind. + */ + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible) = 0; + /** * Called during appending or cancelling a reflow command to give frames notice * of reflow commands that will be targeted below them. diff --git a/mozilla/layout/generic/nsImageFrame.cpp b/mozilla/layout/generic/nsImageFrame.cpp index 9ecabcf6d84..2550f6e8128 100644 --- a/mozilla/layout/generic/nsImageFrame.cpp +++ b/mozilla/layout/generic/nsImageFrame.cpp @@ -144,21 +144,23 @@ nsImageFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) } else if (aIID.Equals(NS_GET_IID(nsISupports))) { *aInstancePtr = NS_STATIC_CAST(nsIImageFrame*,this); return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsIAccessible* acc = nsnull; - accService->CreateHTMLImageAccessible(NS_STATIC_CAST(nsIFrame*, this),&acc); - *aInstancePtr = acc; - return NS_OK; - } - return NS_ERROR_FAILURE; - } + } return NS_NOINTERFACE; } +NS_IMETHODIMP nsImageFrame::GetAccessible(nsIAccessible** aAccessible) +{ + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsIAccessible* acc = nsnull; + return accService->CreateHTMLImageAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); + } + + return NS_ERROR_FAILURE; +} + NS_IMETHODIMP_(nsrefcnt) nsImageFrame::AddRef(void) { NS_WARNING("not supported for frames"); diff --git a/mozilla/layout/generic/nsImageFrame.h b/mozilla/layout/generic/nsImageFrame.h index 060ce61c68c..4c8065a4e94 100644 --- a/mozilla/layout/generic/nsImageFrame.h +++ b/mozilla/layout/generic/nsImageFrame.h @@ -96,6 +96,9 @@ public: PRInt32 aNameSpaceID, nsIAtom* aAttribute, PRInt32 aHint); + + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + NS_IMETHOD GetFrameType(nsIAtom** aResult) const; NS_IMETHOD GetIntrinsicImageSize(nsSize& aSize); diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index d8a7f3de192..8d28ea3b97f 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -454,6 +454,8 @@ public: PRBool aCheckVis, PRBool* aIsVisible); + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + // nsIHTMLReflow NS_IMETHOD Reflow(nsIPresContext* aPresContext, nsHTMLReflowMetrics& aMetrics, @@ -762,6 +764,20 @@ private: #endif }; +NS_IMETHODIMP nsTextFrame::GetAccessible(nsIAccessible** aAccessible) +{ + if (mRect.width > 0 || mRect.height > 0) { + + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsIAccessible* acc = nsnull; + return accService->CreateHTMLTextAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); + } + } + return NS_ERROR_FAILURE; +} + //----------------------------------------------------------------------------- NS_IMETHODIMP nsTextFrame::QueryInterface(const nsIID& aIID, void** aInstancePtrResult) @@ -771,28 +787,13 @@ NS_IMETHODIMP nsTextFrame::QueryInterface(const nsIID& aIID, if (!aInstancePtrResult) return NS_ERROR_NULL_POINTER; - // create a new accessible only if we have a size. - if (aIID.Equals(NS_GET_IID(nsIAccessible)) && (mRect.width > 0 || mRect.height > 0)) { - nsresult rv = NS_OK; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsIAccessible* acc = nsnull; - accService->CreateHTMLTextAccessible(NS_STATIC_CAST(nsIFrame*, this),&acc); - *aInstancePtrResult = acc; - return NS_OK; - } - return NS_ERROR_FAILURE; #ifdef IBMBIDI - } if (aIID.Equals(NS_GET_IID(nsITextFrame))) { *aInstancePtrResult = NS_STATIC_CAST(nsITextFrame*, this); return NS_OK; } - return nsFrame::QueryInterface(aIID, aInstancePtrResult); -#else - } else - return nsFrame::QueryInterface(aIID, aInstancePtrResult); #endif + return nsFrame::QueryInterface(aIID, aInstancePtrResult); } class nsContinuingTextFrame : public nsTextFrame { diff --git a/mozilla/layout/html/base/src/nsFrame.cpp b/mozilla/layout/html/base/src/nsFrame.cpp index 07fe9a085fb..bb63d242185 100644 --- a/mozilla/layout/html/base/src/nsFrame.cpp +++ b/mozilla/layout/html/base/src/nsFrame.cpp @@ -270,16 +270,7 @@ nsresult nsFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) if (aIID.Equals(kClassIID) || aIID.Equals(kISupportsIID)) { *aInstancePtr = (void*)this; return NS_OK; - } /* else if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsIAccessible* acc = nsnull; - accService->CreateHTMLFrameAccessible(NS_STATIC_CAST(nsIFrame*, this),&acc); - *aInstancePtr = acc; - return NS_OK; - } - } */ + } return NS_NOINTERFACE; } @@ -3829,6 +3820,12 @@ nsFrame::ReflowDirtyChild(nsIPresShell* aPresShell, nsIFrame* aChild) } +NS_IMETHODIMP +nsFrame::GetAccessible(nsIAccessible** aAccessible) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP nsFrame::ReflowCommandNotify(nsIPresShell* aShell, nsIReflowCommand* aRC, diff --git a/mozilla/layout/html/base/src/nsFrame.h b/mozilla/layout/html/base/src/nsFrame.h index 225c23502c9..684216de76f 100644 --- a/mozilla/layout/html/base/src/nsFrame.h +++ b/mozilla/layout/html/base/src/nsFrame.h @@ -279,6 +279,8 @@ public: nsIReflowCommand* aRC, PRBool aCommandAdded); + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + NS_IMETHOD GetParentStyleContextProvider(nsIPresContext* aPresContext, nsIFrame** aProviderFrame, nsContextProviderRelationship& aRelationship); diff --git a/mozilla/layout/html/base/src/nsImageFrame.cpp b/mozilla/layout/html/base/src/nsImageFrame.cpp index 9ecabcf6d84..2550f6e8128 100644 --- a/mozilla/layout/html/base/src/nsImageFrame.cpp +++ b/mozilla/layout/html/base/src/nsImageFrame.cpp @@ -144,21 +144,23 @@ nsImageFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) } else if (aIID.Equals(NS_GET_IID(nsISupports))) { *aInstancePtr = NS_STATIC_CAST(nsIImageFrame*,this); return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsIAccessible* acc = nsnull; - accService->CreateHTMLImageAccessible(NS_STATIC_CAST(nsIFrame*, this),&acc); - *aInstancePtr = acc; - return NS_OK; - } - return NS_ERROR_FAILURE; - } + } return NS_NOINTERFACE; } +NS_IMETHODIMP nsImageFrame::GetAccessible(nsIAccessible** aAccessible) +{ + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsIAccessible* acc = nsnull; + return accService->CreateHTMLImageAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); + } + + return NS_ERROR_FAILURE; +} + NS_IMETHODIMP_(nsrefcnt) nsImageFrame::AddRef(void) { NS_WARNING("not supported for frames"); diff --git a/mozilla/layout/html/base/src/nsImageFrame.h b/mozilla/layout/html/base/src/nsImageFrame.h index 060ce61c68c..4c8065a4e94 100644 --- a/mozilla/layout/html/base/src/nsImageFrame.h +++ b/mozilla/layout/html/base/src/nsImageFrame.h @@ -96,6 +96,9 @@ public: PRInt32 aNameSpaceID, nsIAtom* aAttribute, PRInt32 aHint); + + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + NS_IMETHOD GetFrameType(nsIAtom** aResult) const; NS_IMETHOD GetIntrinsicImageSize(nsSize& aSize); diff --git a/mozilla/layout/html/base/src/nsTextFrame.cpp b/mozilla/layout/html/base/src/nsTextFrame.cpp index d8a7f3de192..8d28ea3b97f 100644 --- a/mozilla/layout/html/base/src/nsTextFrame.cpp +++ b/mozilla/layout/html/base/src/nsTextFrame.cpp @@ -454,6 +454,8 @@ public: PRBool aCheckVis, PRBool* aIsVisible); + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + // nsIHTMLReflow NS_IMETHOD Reflow(nsIPresContext* aPresContext, nsHTMLReflowMetrics& aMetrics, @@ -762,6 +764,20 @@ private: #endif }; +NS_IMETHODIMP nsTextFrame::GetAccessible(nsIAccessible** aAccessible) +{ + if (mRect.width > 0 || mRect.height > 0) { + + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsIAccessible* acc = nsnull; + return accService->CreateHTMLTextAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); + } + } + return NS_ERROR_FAILURE; +} + //----------------------------------------------------------------------------- NS_IMETHODIMP nsTextFrame::QueryInterface(const nsIID& aIID, void** aInstancePtrResult) @@ -771,28 +787,13 @@ NS_IMETHODIMP nsTextFrame::QueryInterface(const nsIID& aIID, if (!aInstancePtrResult) return NS_ERROR_NULL_POINTER; - // create a new accessible only if we have a size. - if (aIID.Equals(NS_GET_IID(nsIAccessible)) && (mRect.width > 0 || mRect.height > 0)) { - nsresult rv = NS_OK; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsIAccessible* acc = nsnull; - accService->CreateHTMLTextAccessible(NS_STATIC_CAST(nsIFrame*, this),&acc); - *aInstancePtrResult = acc; - return NS_OK; - } - return NS_ERROR_FAILURE; #ifdef IBMBIDI - } if (aIID.Equals(NS_GET_IID(nsITextFrame))) { *aInstancePtrResult = NS_STATIC_CAST(nsITextFrame*, this); return NS_OK; } - return nsFrame::QueryInterface(aIID, aInstancePtrResult); -#else - } else - return nsFrame::QueryInterface(aIID, aInstancePtrResult); #endif + return nsFrame::QueryInterface(aIID, aInstancePtrResult); } class nsContinuingTextFrame : public nsTextFrame { diff --git a/mozilla/layout/html/document/src/nsFrameFrame.cpp b/mozilla/layout/html/document/src/nsFrameFrame.cpp index c7a2ab7ebc0..537e0d8a8dc 100644 --- a/mozilla/layout/html/document/src/nsFrameFrame.cpp +++ b/mozilla/layout/html/document/src/nsFrameFrame.cpp @@ -152,6 +152,9 @@ public: PRInt32 aNameSpaceID, nsIAtom* aAttribute, PRInt32 aHint); + + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + NS_IMETHOD VerifyTree() const; PRBool IsInline(); @@ -238,6 +241,18 @@ nsHTMLFrameOuterFrame::~nsHTMLFrameOuterFrame() //printf("nsHTMLFrameOuterFrame destructor %X \n", this); } +NS_IMETHODIMP nsHTMLFrameOuterFrame::GetAccessible(nsIAccessible** aAccessible) +{ + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsCOMPtr node = do_QueryInterface(mContent); + return accService->CreateHTMLIFrameAccessible(node, mPresContext, aAccessible); + } + + return NS_ERROR_FAILURE; +} + //-------------------------------------------------------------- // Frames are not refcounted, no need to AddRef NS_IMETHODIMP @@ -248,20 +263,6 @@ nsHTMLFrameOuterFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) return NS_ERROR_NULL_POINTER; } - if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv = NS_OK; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsCOMPtr node = do_QueryInterface(mContent); - nsIAccessible* acc = nsnull; - accService->CreateHTMLIFrameAccessible(node, mPresContext, &acc); - NS_IF_ADDREF(acc); - *aInstancePtr = acc; - return NS_OK; - } - return NS_ERROR_FAILURE; - } - return nsHTMLFrameOuterFrameSuper::QueryInterface(aIID, aInstancePtr); } diff --git a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp index 68b80ae23b6..40a514e34b4 100644 --- a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp @@ -305,23 +305,24 @@ nsComboboxControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) } else if (aIID.Equals(NS_GET_IID(nsIScrollableViewProvider))) { *aInstancePtr = (void*)(nsIScrollableViewProvider*)this; return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv = NS_OK; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsCOMPtr node = do_QueryInterface(mContent); - nsIAccessible* acc = nsnull; - accService->CreateHTMLSelectAccessible(nsLayoutAtoms::popupList, node, mPresContext, &acc); - *aInstancePtr = acc; - return NS_OK; - } - return NS_ERROR_FAILURE; } - return nsAreaFrame::QueryInterface(aIID, aInstancePtr); } +NS_IMETHODIMP nsComboboxControlFrame::GetAccessible(nsIAccessible** aAccessible) +{ + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsCOMPtr node = do_QueryInterface(mContent); + return accService->CreateHTMLSelectAccessible(nsLayoutAtoms::popupList, node, mPresContext, aAccessible); + } + + return NS_ERROR_FAILURE; +} + + NS_IMETHODIMP nsComboboxControlFrame::Init(nsIPresContext* aPresContext, diff --git a/mozilla/layout/html/forms/src/nsComboboxControlFrame.h b/mozilla/layout/html/forms/src/nsComboboxControlFrame.h index b3402961f57..4889339694e 100644 --- a/mozilla/layout/html/forms/src/nsComboboxControlFrame.h +++ b/mozilla/layout/html/forms/src/nsComboboxControlFrame.h @@ -86,6 +86,8 @@ public: nsIContent * aContent, nsIFrame** aFrame); + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + // nsIFrame NS_IMETHOD Init(nsIPresContext* aPresContext, nsIContent* aContent, diff --git a/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp index 6363cf94198..6be2626455a 100644 --- a/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp @@ -462,6 +462,18 @@ nsGfxButtonControlFrame::CreateFrameFor(nsIPresContext* aPresContext, return rv; } +NS_IMETHODIMP nsGfxButtonControlFrame::GetAccessible(nsIAccessible** aAccessible) +{ + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsIAccessible* acc = nsnull; + return accService->CreateHTMLButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); + } + + return NS_ERROR_FAILURE; +} + // Frames are not refcounted, no need to AddRef NS_IMETHODIMP nsGfxButtonControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) @@ -472,18 +484,7 @@ nsGfxButtonControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) *aInstancePtr = NS_STATIC_CAST(nsIAnonymousContentCreator*, this); } else if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) { *aInstancePtr = NS_STATIC_CAST(nsIStatefulFrame*, this); - } else if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv = NS_OK; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsIAccessible* acc = nsnull; - accService->CreateHTMLButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), &acc); - *aInstancePtr = acc; - return NS_OK; - } - return NS_ERROR_FAILURE; - - } + } else { return nsHTMLButtonControlFrame::QueryInterface(aIID, aInstancePtr); } diff --git a/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.h b/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.h index 97d98465fb3..f4445defeef 100644 --- a/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.h +++ b/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.h @@ -30,6 +30,8 @@ #include "nsITextContent.h" #include "nsIStatefulFrame.h" +class nsIAccessible; + // Class which implements the input[type=button, reset, submit] and // browse button for input[type=file]. // The label for button is specified through generated content @@ -57,6 +59,8 @@ public: nsEventStatus* aEventStatus); + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + // nsFormControlFrame NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight); #ifdef DEBUG diff --git a/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp index f262923562f..b09b0022f7a 100644 --- a/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp @@ -87,21 +87,21 @@ nsGfxCheckboxControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr return NS_OK; } - if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv = NS_OK; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsIAccessible* acc = nsnull; - accService->CreateHTMLCheckboxAccessible(NS_STATIC_CAST(nsIFrame*, this), &acc); - *aInstancePtr = acc; - return NS_OK; - } - return NS_ERROR_FAILURE; - } - return nsFormControlFrame::QueryInterface(aIID, aInstancePtr); } +NS_IMETHODIMP nsGfxCheckboxControlFrame::GetAccessible(nsIAccessible** aAccessible) +{ + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsIAccessible* acc = nsnull; + return accService->CreateHTMLCheckboxAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); + } + + return NS_ERROR_FAILURE; +} + //-------------------------------------------------------------- NS_IMETHODIMP nsGfxCheckboxControlFrame::SetCheckboxFaceStyleContext(nsIStyleContext *aCheckboxFaceStyleContext) diff --git a/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.h b/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.h index 96b58d3ad56..512bb40c086 100644 --- a/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.h +++ b/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.h @@ -26,6 +26,8 @@ #include "nsIStatefulFrame.h" #include "nsICheckboxControlFrame.h" +class nsIAccessible; + #define NS_GFX_CHECKBOX_CONTROL_FRAME_FACE_CONTEXT_INDEX 0 // for additional style contexts #define NS_GFX_CHECKBOX_CONTROL_FRAME_LAST_CONTEXT_INDEX 0 @@ -67,6 +69,9 @@ public: const nsRect& aDirtyRect, nsFramePaintLayer aWhichLayer); + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + + //nsICheckboxControlFrame methods NS_IMETHOD SetCheckboxFaceStyleContext(nsIStyleContext *aCheckboxFaceStyleContext); diff --git a/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp index 534efccb778..2abf03ad3f9 100644 --- a/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp @@ -80,23 +80,21 @@ nsGfxRadioControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) *aInstancePtr = (void*) ((nsIStatefulFrame*) this); return NS_OK; } - - if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv = NS_OK; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsCOMPtr node = do_QueryInterface(mContent); - nsIAccessible* acc = nsnull; - accService->CreateHTMLRadioButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), &acc); - *aInstancePtr = acc; - return NS_OK; - } - return NS_ERROR_FAILURE; - } return nsFormControlFrame::QueryInterface(aIID, aInstancePtr); } +NS_IMETHODIMP nsGfxRadioControlFrame::GetAccessible(nsIAccessible** aAccessible) +{ + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsIAccessible* acc = nsnull; + return accService->CreateHTMLRadioButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); + } + + return NS_ERROR_FAILURE; +} //-------------------------------------------------------------- NS_IMETHODIMP diff --git a/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.h b/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.h index 44d09ce3869..05823144e4b 100644 --- a/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.h +++ b/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.h @@ -27,6 +27,8 @@ #include "nsIStatefulFrame.h" #include "nsIRadioControlFrame.h" +class nsIAccessible; + // nsGfxRadioControlFrame #define NS_GFX_RADIO_CONTROL_FRAME_FACE_CONTEXT_INDEX 0 // for additional style contexts @@ -47,6 +49,7 @@ public: NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); NS_IMETHOD SetRadioButtonFaceStyleContext(nsIStyleContext *aRadioButtonFaceStyleContext); NS_IMETHOD GetRadioGroupSelectedContent(nsIContent ** aRadioBtn); + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); virtual PRBool GetChecked(); virtual PRBool GetDefaultChecked(); diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp index 31c30e099d1..1ede27b3249 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp @@ -406,22 +406,22 @@ nsGfxTextControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) *aInstancePtr = (void*)(nsIStatefulFrame*) this; return NS_OK; } - - if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv = NS_OK; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsIAccessible* acc = nsnull; - accService->CreateHTMLTextFieldAccessible(NS_STATIC_CAST(nsIFrame*, this), &acc); - *aInstancePtr = acc; - return NS_OK; - } - return NS_ERROR_FAILURE; - } return nsFormControlFrame::QueryInterface(aIID, aInstancePtr); } +NS_IMETHODIMP nsGfxTextControlFrame::GetAccessible(nsIAccessible** aAccessible) +{ + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsIAccessible* acc = nsnull; + return accService->CreateHTMLTextFieldAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); + } + + return NS_ERROR_FAILURE; +} + NS_IMETHODIMP nsGfxTextControlFrame::Init(nsIPresContext* aPresContext, nsIContent* aContent, diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp index dff593179bc..68c35200315 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp @@ -1277,20 +1277,21 @@ nsGfxTextControlFrame2::QueryInterface(const nsIID& aIID, void** aInstancePtr) return NS_OK; } - if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv = NS_OK; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsIAccessible* acc = nsnull; - accService->CreateHTMLTextFieldAccessible(NS_STATIC_CAST(nsIFrame*, this), &acc); - *aInstancePtr = acc; - return NS_OK; - } - return NS_ERROR_FAILURE; - } return nsBoxFrame::QueryInterface(aIID, aInstancePtr); } +NS_IMETHODIMP nsGfxTextControlFrame2::GetAccessible(nsIAccessible** aAccessible) +{ + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsIAccessible* acc = nsnull; + return accService->CreateHTMLTextFieldAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); + } + + return NS_ERROR_FAILURE; +} + nsGfxTextControlFrame2::nsGfxTextControlFrame2(nsIPresShell* aShell):nsStackFrame(aShell) { mUseEditor=PR_FALSE; diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.h b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.h index 938b04d361f..3872c68c59a 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.h +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.h @@ -47,6 +47,7 @@ class nsTextInputSelectionImpl; class nsTextInputListener; class nsIDOMCharacterData; class nsIScrollableView; +class nsIAccessible; class nsGfxTextControlFrame2 : public nsStackFrame, @@ -77,6 +78,7 @@ public: NS_IMETHOD GetMinSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize); NS_IMETHOD GetMaxSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize); NS_IMETHOD GetAscent(nsBoxLayoutState& aBoxLayoutState, nscoord& aAscent); + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); #ifdef NS_DEBUG NS_IMETHOD GetFrameName(nsString& aResult) const diff --git a/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp b/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp index 36183494179..9bb5a1ca5e9 100644 --- a/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp @@ -162,20 +162,24 @@ nsHTMLButtonControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) if (aIID.Equals(NS_GET_IID(nsIFormControlFrame))) { *aInstancePtr = (void*) ((nsIFormControlFrame*) this); return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv = NS_OK; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsIAccessible* acc = nsnull; - accService->CreateHTML4ButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), &acc); - *aInstancePtr = acc; - return NS_OK; - } } return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr); } +NS_IMETHODIMP nsHTMLButtonControlFrame::GetAccessible(nsIAccessible** aAccessible) +{ + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsIAccessible* acc = nsnull; + return accService->CreateHTML4ButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); + } + + return NS_ERROR_FAILURE; +} + + void nsHTMLButtonControlFrame::GetDefaultLabel(nsString& aString) { diff --git a/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.h b/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.h index d4eaa47f4a5..7e1074fd496 100644 --- a/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.h +++ b/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.h @@ -99,6 +99,9 @@ public: nsIPresShell& aPresShell, nsIAtom* aListName, nsIFrame* aFrameList); + + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + #ifdef DEBUG NS_IMETHOD GetFrameName(nsString& aResult) const { return MakeFrameName("ButtonControl", aResult); diff --git a/mozilla/layout/html/forms/src/nsImageControlFrame.cpp b/mozilla/layout/html/forms/src/nsImageControlFrame.cpp index b746d7bd705..6cc83a19815 100644 --- a/mozilla/layout/html/forms/src/nsImageControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsImageControlFrame.cpp @@ -83,6 +83,8 @@ public: nsGUIEvent* aEvent, nsEventStatus* aEventStatus); + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + #ifdef DEBUG NS_IMETHOD GetFrameName(nsString& aResult) const { return MakeFrameName("ImageControl", aResult); @@ -199,21 +201,23 @@ nsImageControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) if (aIID.Equals(NS_GET_IID(nsIFormControlFrame))) { *aInstancePtr = (void*) ((nsIFormControlFrame*) this); return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsIAccessible* acc = nsnull; - accService->CreateHTML4ButtonAccessible(NS_STATIC_CAST(nsIFrame*, this),&acc); - *aInstancePtr = acc; - return NS_OK; - } - return NS_ERROR_FAILURE; } return nsImageControlFrameSuper::QueryInterface(aIID, aInstancePtr); } +NS_IMETHODIMP nsImageControlFrame::GetAccessible(nsIAccessible** aAccessible) +{ + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsIAccessible* acc = nsnull; + return accService->CreateHTML4ButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); + } + + return NS_ERROR_FAILURE; +} + nsrefcnt nsImageControlFrame::AddRef(void) { NS_WARNING("not supported"); diff --git a/mozilla/layout/html/table/src/nsTableCellFrame.cpp b/mozilla/layout/html/table/src/nsTableCellFrame.cpp index 299594968b7..108b9da2ebb 100644 --- a/mozilla/layout/html/table/src/nsTableCellFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableCellFrame.cpp @@ -1174,19 +1174,21 @@ nsresult nsTableCellFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr if (aIID.Equals(NS_GET_IID(nsITableCellLayout))) { *aInstancePtr = (void*) (nsITableCellLayout *)this; return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv = NS_OK; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsIAccessible* acc = nsnull; - accService->CreateHTMLTableCellAccessible(NS_STATIC_CAST(nsIFrame*, this), &acc); - *aInstancePtr = acc; - return NS_OK; - } - return NS_ERROR_FAILURE; - } else { - return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr); } + + return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr); +} + +NS_IMETHODIMP nsTableCellFrame::GetAccessible(nsIAccessible** aAccessible) +{ + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsIAccessible* acc = nsnull; + return accService->CreateHTMLTableCellAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); + } + + return NS_ERROR_FAILURE; } /* This is primarily for editor access via nsITableLayout */ diff --git a/mozilla/layout/html/table/src/nsTableCellFrame.h b/mozilla/layout/html/table/src/nsTableCellFrame.h index 11dd9e4dabf..f6c7e6f7db6 100644 --- a/mozilla/layout/html/table/src/nsTableCellFrame.h +++ b/mozilla/layout/html/table/src/nsTableCellFrame.h @@ -65,6 +65,9 @@ public: nsIStyleContext* aContext, nsIFrame* aPrevInFlow); + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + + NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext, nsIContent* aChild, PRInt32 aNameSpaceID, diff --git a/mozilla/layout/html/table/src/nsTableOuterFrame.cpp b/mozilla/layout/html/table/src/nsTableOuterFrame.cpp index aa13efbec1b..5dbc108f285 100644 --- a/mozilla/layout/html/table/src/nsTableOuterFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableOuterFrame.cpp @@ -123,20 +123,23 @@ nsresult nsTableOuterFrame::QueryInterface(const nsIID& aIID, void** aInstancePt { // note there is no addref here, frames are not addref'd *aInstancePtr = (void*)(nsITableLayout*)this; return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv = NS_OK; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsIAccessible* acc = nsnull; - accService->CreateHTMLTableAccessible(NS_STATIC_CAST(nsIFrame*, this), &acc); - *aInstancePtr = acc; - return NS_OK; - } - return NS_ERROR_FAILURE; - } else { - return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr); } + + return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr); } + +NS_IMETHODIMP nsTableOuterFrame::GetAccessible(nsIAccessible** aAccessible) +{ + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsIAccessible* acc = nsnull; + return accService->CreateHTMLTableAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); + } + + return NS_ERROR_FAILURE; +} + NS_IMETHODIMP nsTableOuterFrame::IsPercentageBase(PRBool& aBase) const { diff --git a/mozilla/layout/html/table/src/nsTableOuterFrame.h b/mozilla/layout/html/table/src/nsTableOuterFrame.h index 1794887fb7c..f9eff5b7ebe 100644 --- a/mozilla/layout/html/table/src/nsTableOuterFrame.h +++ b/mozilla/layout/html/table/src/nsTableOuterFrame.h @@ -107,6 +107,8 @@ public: nsIAtom* aListName, nsIFrame* aOldFrame); + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + /** @see nsIFrame::Paint */ NS_IMETHOD Paint(nsIPresContext* aPresContext, nsIRenderingContext& aRenderingContext, diff --git a/mozilla/layout/tables/nsTableCellFrame.cpp b/mozilla/layout/tables/nsTableCellFrame.cpp index 299594968b7..108b9da2ebb 100644 --- a/mozilla/layout/tables/nsTableCellFrame.cpp +++ b/mozilla/layout/tables/nsTableCellFrame.cpp @@ -1174,19 +1174,21 @@ nsresult nsTableCellFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr if (aIID.Equals(NS_GET_IID(nsITableCellLayout))) { *aInstancePtr = (void*) (nsITableCellLayout *)this; return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv = NS_OK; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsIAccessible* acc = nsnull; - accService->CreateHTMLTableCellAccessible(NS_STATIC_CAST(nsIFrame*, this), &acc); - *aInstancePtr = acc; - return NS_OK; - } - return NS_ERROR_FAILURE; - } else { - return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr); } + + return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr); +} + +NS_IMETHODIMP nsTableCellFrame::GetAccessible(nsIAccessible** aAccessible) +{ + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsIAccessible* acc = nsnull; + return accService->CreateHTMLTableCellAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); + } + + return NS_ERROR_FAILURE; } /* This is primarily for editor access via nsITableLayout */ diff --git a/mozilla/layout/tables/nsTableCellFrame.h b/mozilla/layout/tables/nsTableCellFrame.h index 11dd9e4dabf..f6c7e6f7db6 100644 --- a/mozilla/layout/tables/nsTableCellFrame.h +++ b/mozilla/layout/tables/nsTableCellFrame.h @@ -65,6 +65,9 @@ public: nsIStyleContext* aContext, nsIFrame* aPrevInFlow); + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + + NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext, nsIContent* aChild, PRInt32 aNameSpaceID, diff --git a/mozilla/layout/tables/nsTableOuterFrame.cpp b/mozilla/layout/tables/nsTableOuterFrame.cpp index aa13efbec1b..5dbc108f285 100644 --- a/mozilla/layout/tables/nsTableOuterFrame.cpp +++ b/mozilla/layout/tables/nsTableOuterFrame.cpp @@ -123,20 +123,23 @@ nsresult nsTableOuterFrame::QueryInterface(const nsIID& aIID, void** aInstancePt { // note there is no addref here, frames are not addref'd *aInstancePtr = (void*)(nsITableLayout*)this; return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIAccessible))) { - nsresult rv = NS_OK; - NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); - if (accService) { - nsIAccessible* acc = nsnull; - accService->CreateHTMLTableAccessible(NS_STATIC_CAST(nsIFrame*, this), &acc); - *aInstancePtr = acc; - return NS_OK; - } - return NS_ERROR_FAILURE; - } else { - return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr); } + + return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr); } + +NS_IMETHODIMP nsTableOuterFrame::GetAccessible(nsIAccessible** aAccessible) +{ + nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + + if (accService) { + nsIAccessible* acc = nsnull; + return accService->CreateHTMLTableAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); + } + + return NS_ERROR_FAILURE; +} + NS_IMETHODIMP nsTableOuterFrame::IsPercentageBase(PRBool& aBase) const { diff --git a/mozilla/layout/tables/nsTableOuterFrame.h b/mozilla/layout/tables/nsTableOuterFrame.h index 1794887fb7c..f9eff5b7ebe 100644 --- a/mozilla/layout/tables/nsTableOuterFrame.h +++ b/mozilla/layout/tables/nsTableOuterFrame.h @@ -107,6 +107,8 @@ public: nsIAtom* aListName, nsIFrame* aOldFrame); + NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + /** @see nsIFrame::Paint */ NS_IMETHOD Paint(nsIPresContext* aPresContext, nsIRenderingContext& aRenderingContext, diff --git a/mozilla/widget/src/windows/Accessible.cpp b/mozilla/widget/src/windows/Accessible.cpp index 3b6e8438dcf..fbbc33e712b 100644 --- a/mozilla/widget/src/windows/Accessible.cpp +++ b/mozilla/widget/src/windows/Accessible.cpp @@ -117,9 +117,13 @@ STDMETHODIMP_(ULONG) Accessible::Release() } HINSTANCE Accessible::gmAccLib = 0; +HINSTANCE Accessible::gmUserLib = 0; LPFNACCESSIBLEOBJECTFROMWINDOW Accessible::gmAccessibleObjectFromWindow = 0; LPFNLRESULTFROMOBJECT Accessible::gmLresultFromObject = 0; + +LPFNNOTIFYWINEVENT Accessible::gmNotifyWinEvent = 0; + //----------------------------------------------------- // IAccessible methods //----------------------------------------------------- @@ -139,13 +143,36 @@ STDMETHODIMP Accessible::AccessibleObjectFromWindow( if (!gmAccessibleObjectFromWindow) gmAccessibleObjectFromWindow = (LPFNACCESSIBLEOBJECTFROMWINDOW)GetProcAddress(gmAccLib,"AccessibleObjectFromWindow"); - return gmAccessibleObjectFromWindow(hwnd, dwObjectID, riid, ppvObject); + if (gmAccessibleObjectFromWindow) + return gmAccessibleObjectFromWindow(hwnd, dwObjectID, riid, ppvObject); } return S_FALSE; } +STDMETHODIMP Accessible::NotifyWinEvent( + DWORD event, + HWND hwnd, + LONG idObjectType, + LONG idObject) +{ + + // open the dll dynamically + if (!gmUserLib) + gmUserLib =::LoadLibrary("USER32.DLL"); + + if (gmUserLib) { + if (!gmNotifyWinEvent) + gmNotifyWinEvent = (LPFNNOTIFYWINEVENT)GetProcAddress(gmUserLib,"NotifyWinEvent"); + + if (gmNotifyWinEvent) + return gmNotifyWinEvent(event, hwnd, idObjectType, idObject); + } + + return S_FALSE; +} + STDMETHODIMP_(LRESULT) Accessible::LresultFromObject( @@ -161,7 +188,8 @@ STDMETHODIMP_(LRESULT) Accessible::LresultFromObject( if (!gmAccessibleObjectFromWindow) gmLresultFromObject = (LPFNLRESULTFROMOBJECT)GetProcAddress(gmAccLib,"LresultFromObject"); - return gmLresultFromObject(riid,wParam,pAcc); + if (gmLresultFromObject) + return gmLresultFromObject(riid,wParam,pAcc); } return 0; diff --git a/mozilla/widget/src/windows/Accessible.h b/mozilla/widget/src/windows/Accessible.h index df443e5ba1c..2ccb99045da 100644 --- a/mozilla/widget/src/windows/Accessible.h +++ b/mozilla/widget/src/windows/Accessible.h @@ -40,6 +40,8 @@ #include "nsString.h" +typedef LRESULT (STDAPICALLTYPE *LPFNNOTIFYWINEVENT)(DWORD event,HWND hwnd,LONG idObjectType,LONG idObject); + class Accessible : public IAccessible { public: // construction, destruction @@ -155,7 +157,7 @@ class Accessible : public IAccessible // load the library only if needed. static STDMETHODIMP AccessibleObjectFromWindow(HWND hwnd,DWORD dwObjectID,REFIID riid,void **ppvObject); static STDMETHODIMP_(LRESULT) LresultFromObject(REFIID riid,WPARAM wParam,LPUNKNOWN pAcc); - + static STDMETHODIMP NotifyWinEvent(DWORD event,HWND hwnd,LONG idObjectType,LONG idObject); static ULONG g_cRef; // the cum reference count of all instances ULONG m_cRef; // the reference count @@ -173,9 +175,12 @@ class Accessible : public IAccessible private: /// the accessible library and cached methods static HINSTANCE gmAccLib; + static HINSTANCE gmUserLib; static LPFNACCESSIBLEOBJECTFROMWINDOW gmAccessibleObjectFromWindow; static LPFNLRESULTFROMOBJECT gmLresultFromObject; + static LPFNNOTIFYWINEVENT gmNotifyWinEvent; + }; class nsAccessibleEventMap diff --git a/mozilla/widget/src/windows/nsWindow.h b/mozilla/widget/src/windows/nsWindow.h index 70af737c706..80bad721bfe 100644 --- a/mozilla/widget/src/windows/nsWindow.h +++ b/mozilla/widget/src/windows/nsWindow.h @@ -377,6 +377,7 @@ protected: private: + #ifdef DEBUG void DebugPrintEvent(nsGUIEvent & aEvent, HWND aWnd);