From 6c18128152a07d502f6c43cdff44c350ecc039ee Mon Sep 17 00:00:00 2001 From: "aaronl%netscape.com" Date: Tue, 18 Sep 2001 03:09:01 +0000 Subject: [PATCH] Bug 82207. Beginning XUL MSAA support (checkboxes). r=jgaunt, sr=hyatt git-svn-id: svn://10.0.0.236/trunk@103067 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/accessible/public/Makefile.in | 1 + mozilla/accessible/public/makefile.win | 1 + .../public/nsIAccessibilityService.idl | 1 + .../src/base/nsAccessibilityService.cpp | 47 +++++++- .../src/base/nsAccessibilityService.h | 1 + mozilla/accessible/src/base/nsAccessible.cpp | 46 +++++++- .../src/base/nsGenericAccessible.cpp | 1 - .../src/html/nsHTMLAreaAccessible.cpp | 1 - .../src/html/nsHTMLFormControlAccessible.cpp | 104 ++++++++++++++---- .../src/html/nsHTMLFormControlAccessible.h | 2 + .../src/html/nsHTMLTextAccessible.cpp | 1 - .../accessible/src/nsAccessibilityService.cpp | 47 +++++++- .../accessible/src/nsAccessibilityService.h | 1 + mozilla/accessible/src/nsAccessible.cpp | 46 +++++++- .../accessible/src/nsGenericAccessible.cpp | 1 - .../accessible/src/nsHTMLAreaAccessible.cpp | 1 - .../src/nsHTMLFormControlAccessible.cpp | 104 ++++++++++++++---- .../src/nsHTMLFormControlAccessible.h | 2 + .../accessible/src/nsHTMLTextAccessible.cpp | 1 - mozilla/dom/public/idl/xul/Makefile.in | 3 + mozilla/dom/public/idl/xul/makefile.win | 3 + .../resources/content/bindings/checkbox.xml | 10 +- 22 files changed, 360 insertions(+), 65 deletions(-) diff --git a/mozilla/accessible/public/Makefile.in b/mozilla/accessible/public/Makefile.in index 3a03a40a3f2..614f00f6ed0 100644 --- a/mozilla/accessible/public/Makefile.in +++ b/mozilla/accessible/public/Makefile.in @@ -36,6 +36,7 @@ XPIDLSRCS = \ nsIAccessibleEventReceiver.idl \ nsIAccessibleEventListener.idl \ nsIAccessibleSelectable.idl \ + nsIAccessibleProvider.idl \ $(NULL) EXPORTS = \ diff --git a/mozilla/accessible/public/makefile.win b/mozilla/accessible/public/makefile.win index 0ee73dd6f71..5f939366785 100644 --- a/mozilla/accessible/public/makefile.win +++ b/mozilla/accessible/public/makefile.win @@ -30,6 +30,7 @@ XPIDLSRCS = \ .\nsIAccessibleEventReceiver.idl \ .\nsIAccessibleEventListener.idl \ .\nsIAccessibleSelectable.idl \ + .\nsIAccessibleProvider.idl \ $(NULL) EXPORTS = \ diff --git a/mozilla/accessible/public/nsIAccessibilityService.idl b/mozilla/accessible/public/nsIAccessibilityService.idl index 31b2ddc6c2d..45d7e030628 100644 --- a/mozilla/accessible/public/nsIAccessibilityService.idl +++ b/mozilla/accessible/public/nsIAccessibilityService.idl @@ -38,6 +38,7 @@ interface nsIAccessibilityService : nsISupports nsIAccessible createHTMLListboxAccessible(in nsIDOMNode aNode, in nsISupports aPresShell); nsIAccessible createHTMLSelectOptionAccessible(in nsIDOMNode aNode, in nsIAccessible aAccParent, in nsISupports aPresShell); nsIAccessible createHTMLCheckboxAccessible(in nsISupports aFrame); + nsIAccessible createXULCheckboxAccessible(in nsIDOMNode aNode); nsIAccessible createHTMLRadioButtonAccessible(in nsISupports aFrame); nsIAccessible createHTMLButtonAccessible(in nsISupports aFrame); nsIAccessible createHTML4ButtonAccessible(in nsISupports aFrame); diff --git a/mozilla/accessible/src/base/nsAccessibilityService.cpp b/mozilla/accessible/src/base/nsAccessibilityService.cpp index e3d1c034ad3..320a2aacaf1 100644 --- a/mozilla/accessible/src/base/nsAccessibilityService.cpp +++ b/mozilla/accessible/src/base/nsAccessibilityService.cpp @@ -45,10 +45,12 @@ #include "nsHTMLListboxAccessible.h" #include "nsIDOMHTMLAreaElement.h" #include "nsHTMLFormControlAccessible.h" +#include "nsIAccessibleProvider.h" #include "nsILink.h" #include "nsIDocShellTreeItem.h" #include "nsIDOMDocument.h" #include "nsIDOMHTMLOptionElement.h" +#include "nsIDOMXULCheckboxElement.h" // IFrame #include "nsIDocShell.h" @@ -95,6 +97,7 @@ nsAccessibilityService::CreateRootAccessible(nsISupports* aPresContext, nsISuppo return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(*_retval); + return NS_OK; } @@ -175,6 +178,19 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTMLCheckboxAccessible(nsISupports * return NS_OK; } +NS_IMETHODIMP nsAccessibilityService::CreateXULCheckboxAccessible(nsIDOMNode *aNode, nsIAccessible **_retval) +{ + nsCOMPtr weakShell; + GetShellFromNode(aNode, getter_AddRefs(weakShell)); + + *_retval = new nsHTMLCheckboxAccessible(aNode, weakShell); + if (! *_retval) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(*_retval); + return NS_OK; +} + /* nsIAccessible createHTMRadioButtonAccessible (in nsISupports aPresShell, in nsISupports aFrame); */ NS_IMETHODIMP nsAccessibilityService::CreateHTMLRadioButtonAccessible(nsISupports *aFrame, nsIAccessible **_retval) { @@ -340,6 +356,28 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTMLTextFieldAccessible(nsISupports return NS_OK; } +NS_IMETHODIMP nsAccessibilityService::GetShellFromNode(nsIDOMNode *aNode, nsIWeakReference **aWeakShell) +{ + nsCOMPtr domDoc; + aNode->GetOwnerDocument(getter_AddRefs(domDoc)); + nsCOMPtr doc(do_QueryInterface(domDoc)); + if (!doc) + return NS_ERROR_INVALID_ARG; + + // ---- Get the pres shell ---- + nsCOMPtr shell; + doc->GetShellAt(0, getter_AddRefs(shell)); + if (!shell) + return NS_ERROR_FAILURE; + + nsCOMPtr weakRef(do_GetWeakReference(shell)); + + *aWeakShell = weakRef; + NS_IF_ADDREF(*aWeakShell); + + return NS_OK; +} + NS_IMETHODIMP nsAccessibilityService::GetInfo(nsISupports* aFrame, nsIFrame** aRealFrame, nsIWeakReference** aShell, nsIDOMNode** aNode) { NS_ASSERTION(aFrame,"Error -- 1st argument (aFrame) is null!!"); @@ -624,9 +662,12 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessibleFor(nsIDOMNode *aNode, nsCOMPtr newAcc; frame->GetAccessible(getter_AddRefs(newAcc)); - // ---- Try QI'ing node to get nsIAccessible ---- - if (!newAcc) - newAcc = do_QueryInterface(aNode); + // ---- Is it a XUL element? -- they impl nsIAccessibleProvider via XBL + if (!newAcc) { + nsCOMPtr accProv(do_QueryInterface(aNode)); + if (accProv) + accProv->GetAccessible(getter_AddRefs(newAcc)); + } // ---- If link, create link accessible ---- if (!newAcc) { diff --git a/mozilla/accessible/src/base/nsAccessibilityService.h b/mozilla/accessible/src/base/nsAccessibilityService.h index 5450fe88de2..47efd845153 100644 --- a/mozilla/accessible/src/base/nsAccessibilityService.h +++ b/mozilla/accessible/src/base/nsAccessibilityService.h @@ -51,6 +51,7 @@ public: private: NS_IMETHOD GetInfo(nsISupports* aFrame, nsIFrame** aRealFrame, nsIWeakReference** aShell, nsIDOMNode** aContent); + NS_IMETHOD GetShellFromNode(nsIDOMNode *aNode, nsIWeakReference **weakShell); void GetOwnerFor(nsIPresShell *aPresShell, nsIPresShell **aOwnerShell, nsIContent **aOwnerContent); nsIContent* FindContentForDocShell(nsIPresShell* aPresShell, nsIContent* aContent, nsIDocShell* aDocShell); diff --git a/mozilla/accessible/src/base/nsAccessible.cpp b/mozilla/accessible/src/base/nsAccessible.cpp index 1958599ce2d..72722824d3e 100644 --- a/mozilla/accessible/src/base/nsAccessible.cpp +++ b/mozilla/accessible/src/base/nsAccessible.cpp @@ -161,7 +161,7 @@ PRBool nsDOMTreeWalker::GetParent() if (!accessible) accessible = do_QueryInterface(content); if (accessible) { - nsCOMPtr wr = do_GetWeakReference(parentPresShell); + nsCOMPtr wr(do_GetWeakReference(parentPresShell)); accessible->AccGetDOMNode(getter_AddRefs(mDOMNode)); mAccessible = accessible; mPresShell = wr; @@ -169,7 +169,6 @@ PRBool nsDOMTreeWalker::GetParent() } } } - mAccessible = new nsRootAccessible(mPresShell); mAccessible->AccGetDOMNode(getter_AddRefs(mDOMNode)); return PR_TRUE; @@ -623,6 +622,49 @@ NS_IMETHODIMP nsAccessible::GetAccState(PRUint32 *aAccState) } } + nsCOMPtr content(do_QueryInterface(mDOMNode)); + if (content) { + nsCOMPtr shell(do_QueryReferent(mPresShell)); + if (shell) { + nsIFrame *frame = nsnull; + shell->GetPrimaryFrameFor(content, &frame); + if (frame) { + /* + PRBool isVisible = PR_FALSE, isFinishedLooking = PR_FALSE; + nsCOMPtr presContext; + shell->GetPresContext(getter_AddRefs(presContext)); + nsRect twipsRect, pixelsRect; + GetAbsoluteFramePosition(presContext, frame, twipsRect, pixelsRect); + + + //frame->IsVisibleForPainting(presContext, presContext, PR_TRUE, &isVisible); // 3rd param = bool to check css visibility + //frame->CheckVisibility(presContext, 0,1, PR_TRUE, &isFinishedLooking, &isVisible); + if (twipsRect.y < 0) + *aAccState |= STATE_OFFSCREEN; + */ + nsSize frameSize; + frame->GetSize(frameSize); + if (frameSize.width == 0) + *aAccState |= STATE_INVISIBLE; + + } + } + } + + + /** + * called to see if the children of the frame are visible from indexstart to index end. + * this does not change any state. returns PR_TRUE only if the indexes are valid and any of + * the children are visible. for textframes this index is the character index. + * if aStart = aEnd result will be PR_FALSE + * @param aStart start index of first child from 0-N (number of children) + * @param aEnd end index of last child from 0-N + * @param aRecurse should this frame talk to siblings to get to the contents other children? + * @param aFinished did this frame have the aEndIndex? or is there more work to do + * @param _retval return value true or false. false = range is not rendered. + */ + //NS_IMETHOD CheckVisibility(nsIPresContext* aContext, PRInt32 aStartIndex, PRInt32 aEndIndex, PRBool aRecurse, PRBool *aFinished, PRBool *_retval)=0; + return rv; } diff --git a/mozilla/accessible/src/base/nsGenericAccessible.cpp b/mozilla/accessible/src/base/nsGenericAccessible.cpp index 9a815144d5a..2ae05b790b7 100644 --- a/mozilla/accessible/src/base/nsGenericAccessible.cpp +++ b/mozilla/accessible/src/base/nsGenericAccessible.cpp @@ -25,7 +25,6 @@ #include "nsIFrame.h" #include "nsCOMPtr.h" #include "nsIWeakReference.h" -#include "nsISelectionController.h" #include "nsReadableUtils.h" #include "nsIContent.h" diff --git a/mozilla/accessible/src/html/nsHTMLAreaAccessible.cpp b/mozilla/accessible/src/html/nsHTMLAreaAccessible.cpp index b87d133fad4..7df379d5449 100644 --- a/mozilla/accessible/src/html/nsHTMLAreaAccessible.cpp +++ b/mozilla/accessible/src/html/nsHTMLAreaAccessible.cpp @@ -30,7 +30,6 @@ #include "nsIServiceManager.h" #include "nsIDOMElement.h" #include "nsIDOMHTMLAreaElement.h" -#include "nsGUIEvent.h" // --- area ----- diff --git a/mozilla/accessible/src/html/nsHTMLFormControlAccessible.cpp b/mozilla/accessible/src/html/nsHTMLFormControlAccessible.cpp index 4ecc9554195..36c39d2d15f 100644 --- a/mozilla/accessible/src/html/nsHTMLFormControlAccessible.cpp +++ b/mozilla/accessible/src/html/nsHTMLFormControlAccessible.cpp @@ -29,12 +29,12 @@ #include "nsHTMLAtoms.h" #include "nsIDOMHTMLButtonElement.h" #include "nsReadableUtils.h" -#include "nsString.h" #include "nsAccessible.h" #include "nsIFrame.h" #include "nsIDOMHTMLLabelElement.h" #include "nsIDOMHTMLFormElement.h" #include "nsISelectionController.h" +#include "nsIDOMXULCheckboxElement.h" nsHTMLFormControlAccessible::nsHTMLFormControlAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): nsLeafAccessible(aNode, aShell) @@ -117,25 +117,29 @@ NS_IMETHODIMP nsHTMLFormControlAccessible::GetAccName(nsAWritableString& _retval NS_IMETHODIMP nsHTMLFormControlAccessible::GetAccState(PRUint32 *_retval) { // can be - // focusable, focused, checked, protected, unavailable - nsCOMPtr element(do_QueryInterface(mDOMNode)); + // focusable, focused, protected, unavailable + nsCOMPtr htmlFormElement(do_QueryInterface(mDOMNode)); nsAccessible::GetAccState(_retval); - *_retval |= STATE_FOCUSABLE; - - PRBool checked = PR_FALSE; - element->GetChecked(&checked); - if (checked) *_retval |= STATE_CHECKED; PRBool disabled = PR_FALSE; - element->GetDisabled(&disabled); + if (htmlFormElement) { + htmlFormElement->GetDisabled(&disabled); + nsAutoString typeString; + htmlFormElement->GetType(typeString); + if (typeString.EqualsIgnoreCase("password")) + *_retval |= STATE_PROTECTED; + } + else { + nsCOMPtr xulFormElement(do_QueryInterface(mDOMNode)); + if (xulFormElement) + xulFormElement->GetDisabled(&disabled); + } + if (disabled) *_retval |= STATE_UNAVAILABLE; - - nsAutoString typeString; - element->GetType(typeString); - if (typeString.EqualsIgnoreCase("password")) - *_retval |= STATE_PROTECTED; + else + *_retval |= STATE_FOCUSABLE; return NS_OK; } @@ -164,15 +168,12 @@ NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccNumActions(PRUint8 *_retval) /* wstring getAccActionName (in PRUint8 index); */ NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval) { - if (index == 0) { + if (index == 0) { // 0 is the magic value for default action // check or uncheck - nsCOMPtr element(do_QueryInterface(mDOMNode)); + PRUint32 state; + GetAccState(&state); - PRBool checked = PR_FALSE; - if (element) - element->GetChecked(&checked); - - if (checked) + if (state & STATE_CHECKED) _retval = NS_LITERAL_STRING("uncheck"); else _retval = NS_LITERAL_STRING("check"); @@ -186,15 +187,43 @@ NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccActionName(PRUint8 index, nsAWrita NS_IMETHODIMP nsHTMLCheckboxAccessible::AccDoAction(PRUint8 index) { if (index == 0) { // 0 is the magic value for default action - nsCOMPtr element(do_QueryInterface(mDOMNode)); + nsCOMPtr htmlCheckboxElement(do_QueryInterface(mDOMNode)); PRBool checked = PR_FALSE; - element->GetChecked(&checked); - element->SetChecked(checked ? PR_FALSE : PR_TRUE); + if (htmlCheckboxElement) { + htmlCheckboxElement->GetChecked(&checked); + htmlCheckboxElement->SetChecked(!checked); + } + else { + nsCOMPtr xulCheckboxElement(do_QueryInterface(mDOMNode)); + if (xulCheckboxElement) { + xulCheckboxElement->GetChecked(&checked); + xulCheckboxElement->SetChecked(!checked); + } + } return NS_OK; } return NS_ERROR_INVALID_ARG; } +NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccState(PRUint32 *_retval) +{ + nsHTMLFormControlAccessible::GetAccState(_retval); + PRBool checked = PR_FALSE; // Radio buttons and check boxes can be checked + + nsCOMPtr htmlCheckboxElement(do_QueryInterface(mDOMNode)); + if (htmlCheckboxElement) + htmlCheckboxElement->GetChecked(&checked); + else { + nsCOMPtr xulCheckboxElement(do_QueryInterface(mDOMNode)); + if (xulCheckboxElement) + xulCheckboxElement->GetChecked(&checked); + } + + if (checked) + *_retval |= STATE_CHECKED; + + return NS_OK; +} //------ Radio button ------- @@ -240,6 +269,28 @@ NS_IMETHODIMP nsHTMLRadioButtonAccessible::GetAccRole(PRUint32 *_retval) return NS_OK; } +NS_IMETHODIMP nsHTMLRadioButtonAccessible::GetAccState(PRUint32 *_retval) +{ + nsHTMLFormControlAccessible::GetAccState(_retval); + PRBool checked = PR_FALSE; // Radio buttons and check boxes can be checked + + nsCOMPtr htmlRadioElement(do_QueryInterface(mDOMNode)); + if (htmlRadioElement) + htmlRadioElement->GetChecked(&checked); + + /* ----- Need to add this code soon + + nsCOMPtr xulRadioElement(do_QueryInteface(mDOMNode)); + if (xulRadioElement) + xulRadioElement->GetChecked(&checked); + */ + + if (checked) + *_retval |= STATE_CHECKED; + + return NS_OK; +} + // ----- Button ----- nsHTMLButtonAccessible::nsHTMLButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): @@ -387,6 +438,11 @@ NS_IMETHODIMP nsHTMLTextFieldAccessible::GetAccRole(PRUint32 *_retval) /* wstring getAccValue (); */ NS_IMETHODIMP nsHTMLTextFieldAccessible::GetAccValue(nsAWritableString& _retval) { + PRUint32 state; + GetAccState(&state); + if (state & STATE_PROTECTED) // Don't return password text! + return NS_ERROR_FAILURE; + nsCOMPtr textArea(do_QueryInterface(mDOMNode)); if (textArea) { textArea->GetValue(_retval); diff --git a/mozilla/accessible/src/html/nsHTMLFormControlAccessible.h b/mozilla/accessible/src/html/nsHTMLFormControlAccessible.h index c83ed2981e0..2b5bc7df41a 100644 --- a/mozilla/accessible/src/html/nsHTMLFormControlAccessible.h +++ b/mozilla/accessible/src/html/nsHTMLFormControlAccessible.h @@ -54,6 +54,7 @@ public: NS_IMETHOD GetAccNumActions(PRUint8 *_retval); NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval); NS_IMETHOD AccDoAction(PRUint8 index); + NS_IMETHOD GetAccState(PRUint32 *_retval); }; class nsHTMLRadioButtonAccessible : public nsHTMLFormControlAccessible @@ -65,6 +66,7 @@ public: NS_IMETHOD GetAccNumActions(PRUint8 *_retval); NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval); NS_IMETHOD AccDoAction(PRUint8 index); + NS_IMETHOD GetAccState(PRUint32 *_retval); }; class nsHTMLButtonAccessible : public nsHTMLFormControlAccessible diff --git a/mozilla/accessible/src/html/nsHTMLTextAccessible.cpp b/mozilla/accessible/src/html/nsHTMLTextAccessible.cpp index 3490eaa3a5e..04055b05269 100644 --- a/mozilla/accessible/src/html/nsHTMLTextAccessible.cpp +++ b/mozilla/accessible/src/html/nsHTMLTextAccessible.cpp @@ -24,7 +24,6 @@ #include "nsHTMLTextAccessible.h" #include "nsWeakReference.h" #include "nsIFrame.h" -#include "nsString.h" #include "nsILink.h" #include "nsILinkHandler.h" #include "nsISelection.h" diff --git a/mozilla/accessible/src/nsAccessibilityService.cpp b/mozilla/accessible/src/nsAccessibilityService.cpp index e3d1c034ad3..320a2aacaf1 100644 --- a/mozilla/accessible/src/nsAccessibilityService.cpp +++ b/mozilla/accessible/src/nsAccessibilityService.cpp @@ -45,10 +45,12 @@ #include "nsHTMLListboxAccessible.h" #include "nsIDOMHTMLAreaElement.h" #include "nsHTMLFormControlAccessible.h" +#include "nsIAccessibleProvider.h" #include "nsILink.h" #include "nsIDocShellTreeItem.h" #include "nsIDOMDocument.h" #include "nsIDOMHTMLOptionElement.h" +#include "nsIDOMXULCheckboxElement.h" // IFrame #include "nsIDocShell.h" @@ -95,6 +97,7 @@ nsAccessibilityService::CreateRootAccessible(nsISupports* aPresContext, nsISuppo return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(*_retval); + return NS_OK; } @@ -175,6 +178,19 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTMLCheckboxAccessible(nsISupports * return NS_OK; } +NS_IMETHODIMP nsAccessibilityService::CreateXULCheckboxAccessible(nsIDOMNode *aNode, nsIAccessible **_retval) +{ + nsCOMPtr weakShell; + GetShellFromNode(aNode, getter_AddRefs(weakShell)); + + *_retval = new nsHTMLCheckboxAccessible(aNode, weakShell); + if (! *_retval) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(*_retval); + return NS_OK; +} + /* nsIAccessible createHTMRadioButtonAccessible (in nsISupports aPresShell, in nsISupports aFrame); */ NS_IMETHODIMP nsAccessibilityService::CreateHTMLRadioButtonAccessible(nsISupports *aFrame, nsIAccessible **_retval) { @@ -340,6 +356,28 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTMLTextFieldAccessible(nsISupports return NS_OK; } +NS_IMETHODIMP nsAccessibilityService::GetShellFromNode(nsIDOMNode *aNode, nsIWeakReference **aWeakShell) +{ + nsCOMPtr domDoc; + aNode->GetOwnerDocument(getter_AddRefs(domDoc)); + nsCOMPtr doc(do_QueryInterface(domDoc)); + if (!doc) + return NS_ERROR_INVALID_ARG; + + // ---- Get the pres shell ---- + nsCOMPtr shell; + doc->GetShellAt(0, getter_AddRefs(shell)); + if (!shell) + return NS_ERROR_FAILURE; + + nsCOMPtr weakRef(do_GetWeakReference(shell)); + + *aWeakShell = weakRef; + NS_IF_ADDREF(*aWeakShell); + + return NS_OK; +} + NS_IMETHODIMP nsAccessibilityService::GetInfo(nsISupports* aFrame, nsIFrame** aRealFrame, nsIWeakReference** aShell, nsIDOMNode** aNode) { NS_ASSERTION(aFrame,"Error -- 1st argument (aFrame) is null!!"); @@ -624,9 +662,12 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessibleFor(nsIDOMNode *aNode, nsCOMPtr newAcc; frame->GetAccessible(getter_AddRefs(newAcc)); - // ---- Try QI'ing node to get nsIAccessible ---- - if (!newAcc) - newAcc = do_QueryInterface(aNode); + // ---- Is it a XUL element? -- they impl nsIAccessibleProvider via XBL + if (!newAcc) { + nsCOMPtr accProv(do_QueryInterface(aNode)); + if (accProv) + accProv->GetAccessible(getter_AddRefs(newAcc)); + } // ---- If link, create link accessible ---- if (!newAcc) { diff --git a/mozilla/accessible/src/nsAccessibilityService.h b/mozilla/accessible/src/nsAccessibilityService.h index 5450fe88de2..47efd845153 100644 --- a/mozilla/accessible/src/nsAccessibilityService.h +++ b/mozilla/accessible/src/nsAccessibilityService.h @@ -51,6 +51,7 @@ public: private: NS_IMETHOD GetInfo(nsISupports* aFrame, nsIFrame** aRealFrame, nsIWeakReference** aShell, nsIDOMNode** aContent); + NS_IMETHOD GetShellFromNode(nsIDOMNode *aNode, nsIWeakReference **weakShell); void GetOwnerFor(nsIPresShell *aPresShell, nsIPresShell **aOwnerShell, nsIContent **aOwnerContent); nsIContent* FindContentForDocShell(nsIPresShell* aPresShell, nsIContent* aContent, nsIDocShell* aDocShell); diff --git a/mozilla/accessible/src/nsAccessible.cpp b/mozilla/accessible/src/nsAccessible.cpp index 1958599ce2d..72722824d3e 100644 --- a/mozilla/accessible/src/nsAccessible.cpp +++ b/mozilla/accessible/src/nsAccessible.cpp @@ -161,7 +161,7 @@ PRBool nsDOMTreeWalker::GetParent() if (!accessible) accessible = do_QueryInterface(content); if (accessible) { - nsCOMPtr wr = do_GetWeakReference(parentPresShell); + nsCOMPtr wr(do_GetWeakReference(parentPresShell)); accessible->AccGetDOMNode(getter_AddRefs(mDOMNode)); mAccessible = accessible; mPresShell = wr; @@ -169,7 +169,6 @@ PRBool nsDOMTreeWalker::GetParent() } } } - mAccessible = new nsRootAccessible(mPresShell); mAccessible->AccGetDOMNode(getter_AddRefs(mDOMNode)); return PR_TRUE; @@ -623,6 +622,49 @@ NS_IMETHODIMP nsAccessible::GetAccState(PRUint32 *aAccState) } } + nsCOMPtr content(do_QueryInterface(mDOMNode)); + if (content) { + nsCOMPtr shell(do_QueryReferent(mPresShell)); + if (shell) { + nsIFrame *frame = nsnull; + shell->GetPrimaryFrameFor(content, &frame); + if (frame) { + /* + PRBool isVisible = PR_FALSE, isFinishedLooking = PR_FALSE; + nsCOMPtr presContext; + shell->GetPresContext(getter_AddRefs(presContext)); + nsRect twipsRect, pixelsRect; + GetAbsoluteFramePosition(presContext, frame, twipsRect, pixelsRect); + + + //frame->IsVisibleForPainting(presContext, presContext, PR_TRUE, &isVisible); // 3rd param = bool to check css visibility + //frame->CheckVisibility(presContext, 0,1, PR_TRUE, &isFinishedLooking, &isVisible); + if (twipsRect.y < 0) + *aAccState |= STATE_OFFSCREEN; + */ + nsSize frameSize; + frame->GetSize(frameSize); + if (frameSize.width == 0) + *aAccState |= STATE_INVISIBLE; + + } + } + } + + + /** + * called to see if the children of the frame are visible from indexstart to index end. + * this does not change any state. returns PR_TRUE only if the indexes are valid and any of + * the children are visible. for textframes this index is the character index. + * if aStart = aEnd result will be PR_FALSE + * @param aStart start index of first child from 0-N (number of children) + * @param aEnd end index of last child from 0-N + * @param aRecurse should this frame talk to siblings to get to the contents other children? + * @param aFinished did this frame have the aEndIndex? or is there more work to do + * @param _retval return value true or false. false = range is not rendered. + */ + //NS_IMETHOD CheckVisibility(nsIPresContext* aContext, PRInt32 aStartIndex, PRInt32 aEndIndex, PRBool aRecurse, PRBool *aFinished, PRBool *_retval)=0; + return rv; } diff --git a/mozilla/accessible/src/nsGenericAccessible.cpp b/mozilla/accessible/src/nsGenericAccessible.cpp index 9a815144d5a..2ae05b790b7 100644 --- a/mozilla/accessible/src/nsGenericAccessible.cpp +++ b/mozilla/accessible/src/nsGenericAccessible.cpp @@ -25,7 +25,6 @@ #include "nsIFrame.h" #include "nsCOMPtr.h" #include "nsIWeakReference.h" -#include "nsISelectionController.h" #include "nsReadableUtils.h" #include "nsIContent.h" diff --git a/mozilla/accessible/src/nsHTMLAreaAccessible.cpp b/mozilla/accessible/src/nsHTMLAreaAccessible.cpp index b87d133fad4..7df379d5449 100644 --- a/mozilla/accessible/src/nsHTMLAreaAccessible.cpp +++ b/mozilla/accessible/src/nsHTMLAreaAccessible.cpp @@ -30,7 +30,6 @@ #include "nsIServiceManager.h" #include "nsIDOMElement.h" #include "nsIDOMHTMLAreaElement.h" -#include "nsGUIEvent.h" // --- area ----- diff --git a/mozilla/accessible/src/nsHTMLFormControlAccessible.cpp b/mozilla/accessible/src/nsHTMLFormControlAccessible.cpp index 4ecc9554195..36c39d2d15f 100644 --- a/mozilla/accessible/src/nsHTMLFormControlAccessible.cpp +++ b/mozilla/accessible/src/nsHTMLFormControlAccessible.cpp @@ -29,12 +29,12 @@ #include "nsHTMLAtoms.h" #include "nsIDOMHTMLButtonElement.h" #include "nsReadableUtils.h" -#include "nsString.h" #include "nsAccessible.h" #include "nsIFrame.h" #include "nsIDOMHTMLLabelElement.h" #include "nsIDOMHTMLFormElement.h" #include "nsISelectionController.h" +#include "nsIDOMXULCheckboxElement.h" nsHTMLFormControlAccessible::nsHTMLFormControlAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): nsLeafAccessible(aNode, aShell) @@ -117,25 +117,29 @@ NS_IMETHODIMP nsHTMLFormControlAccessible::GetAccName(nsAWritableString& _retval NS_IMETHODIMP nsHTMLFormControlAccessible::GetAccState(PRUint32 *_retval) { // can be - // focusable, focused, checked, protected, unavailable - nsCOMPtr element(do_QueryInterface(mDOMNode)); + // focusable, focused, protected, unavailable + nsCOMPtr htmlFormElement(do_QueryInterface(mDOMNode)); nsAccessible::GetAccState(_retval); - *_retval |= STATE_FOCUSABLE; - - PRBool checked = PR_FALSE; - element->GetChecked(&checked); - if (checked) *_retval |= STATE_CHECKED; PRBool disabled = PR_FALSE; - element->GetDisabled(&disabled); + if (htmlFormElement) { + htmlFormElement->GetDisabled(&disabled); + nsAutoString typeString; + htmlFormElement->GetType(typeString); + if (typeString.EqualsIgnoreCase("password")) + *_retval |= STATE_PROTECTED; + } + else { + nsCOMPtr xulFormElement(do_QueryInterface(mDOMNode)); + if (xulFormElement) + xulFormElement->GetDisabled(&disabled); + } + if (disabled) *_retval |= STATE_UNAVAILABLE; - - nsAutoString typeString; - element->GetType(typeString); - if (typeString.EqualsIgnoreCase("password")) - *_retval |= STATE_PROTECTED; + else + *_retval |= STATE_FOCUSABLE; return NS_OK; } @@ -164,15 +168,12 @@ NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccNumActions(PRUint8 *_retval) /* wstring getAccActionName (in PRUint8 index); */ NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval) { - if (index == 0) { + if (index == 0) { // 0 is the magic value for default action // check or uncheck - nsCOMPtr element(do_QueryInterface(mDOMNode)); + PRUint32 state; + GetAccState(&state); - PRBool checked = PR_FALSE; - if (element) - element->GetChecked(&checked); - - if (checked) + if (state & STATE_CHECKED) _retval = NS_LITERAL_STRING("uncheck"); else _retval = NS_LITERAL_STRING("check"); @@ -186,15 +187,43 @@ NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccActionName(PRUint8 index, nsAWrita NS_IMETHODIMP nsHTMLCheckboxAccessible::AccDoAction(PRUint8 index) { if (index == 0) { // 0 is the magic value for default action - nsCOMPtr element(do_QueryInterface(mDOMNode)); + nsCOMPtr htmlCheckboxElement(do_QueryInterface(mDOMNode)); PRBool checked = PR_FALSE; - element->GetChecked(&checked); - element->SetChecked(checked ? PR_FALSE : PR_TRUE); + if (htmlCheckboxElement) { + htmlCheckboxElement->GetChecked(&checked); + htmlCheckboxElement->SetChecked(!checked); + } + else { + nsCOMPtr xulCheckboxElement(do_QueryInterface(mDOMNode)); + if (xulCheckboxElement) { + xulCheckboxElement->GetChecked(&checked); + xulCheckboxElement->SetChecked(!checked); + } + } return NS_OK; } return NS_ERROR_INVALID_ARG; } +NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccState(PRUint32 *_retval) +{ + nsHTMLFormControlAccessible::GetAccState(_retval); + PRBool checked = PR_FALSE; // Radio buttons and check boxes can be checked + + nsCOMPtr htmlCheckboxElement(do_QueryInterface(mDOMNode)); + if (htmlCheckboxElement) + htmlCheckboxElement->GetChecked(&checked); + else { + nsCOMPtr xulCheckboxElement(do_QueryInterface(mDOMNode)); + if (xulCheckboxElement) + xulCheckboxElement->GetChecked(&checked); + } + + if (checked) + *_retval |= STATE_CHECKED; + + return NS_OK; +} //------ Radio button ------- @@ -240,6 +269,28 @@ NS_IMETHODIMP nsHTMLRadioButtonAccessible::GetAccRole(PRUint32 *_retval) return NS_OK; } +NS_IMETHODIMP nsHTMLRadioButtonAccessible::GetAccState(PRUint32 *_retval) +{ + nsHTMLFormControlAccessible::GetAccState(_retval); + PRBool checked = PR_FALSE; // Radio buttons and check boxes can be checked + + nsCOMPtr htmlRadioElement(do_QueryInterface(mDOMNode)); + if (htmlRadioElement) + htmlRadioElement->GetChecked(&checked); + + /* ----- Need to add this code soon + + nsCOMPtr xulRadioElement(do_QueryInteface(mDOMNode)); + if (xulRadioElement) + xulRadioElement->GetChecked(&checked); + */ + + if (checked) + *_retval |= STATE_CHECKED; + + return NS_OK; +} + // ----- Button ----- nsHTMLButtonAccessible::nsHTMLButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): @@ -387,6 +438,11 @@ NS_IMETHODIMP nsHTMLTextFieldAccessible::GetAccRole(PRUint32 *_retval) /* wstring getAccValue (); */ NS_IMETHODIMP nsHTMLTextFieldAccessible::GetAccValue(nsAWritableString& _retval) { + PRUint32 state; + GetAccState(&state); + if (state & STATE_PROTECTED) // Don't return password text! + return NS_ERROR_FAILURE; + nsCOMPtr textArea(do_QueryInterface(mDOMNode)); if (textArea) { textArea->GetValue(_retval); diff --git a/mozilla/accessible/src/nsHTMLFormControlAccessible.h b/mozilla/accessible/src/nsHTMLFormControlAccessible.h index c83ed2981e0..2b5bc7df41a 100644 --- a/mozilla/accessible/src/nsHTMLFormControlAccessible.h +++ b/mozilla/accessible/src/nsHTMLFormControlAccessible.h @@ -54,6 +54,7 @@ public: NS_IMETHOD GetAccNumActions(PRUint8 *_retval); NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval); NS_IMETHOD AccDoAction(PRUint8 index); + NS_IMETHOD GetAccState(PRUint32 *_retval); }; class nsHTMLRadioButtonAccessible : public nsHTMLFormControlAccessible @@ -65,6 +66,7 @@ public: NS_IMETHOD GetAccNumActions(PRUint8 *_retval); NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval); NS_IMETHOD AccDoAction(PRUint8 index); + NS_IMETHOD GetAccState(PRUint32 *_retval); }; class nsHTMLButtonAccessible : public nsHTMLFormControlAccessible diff --git a/mozilla/accessible/src/nsHTMLTextAccessible.cpp b/mozilla/accessible/src/nsHTMLTextAccessible.cpp index 3490eaa3a5e..04055b05269 100644 --- a/mozilla/accessible/src/nsHTMLTextAccessible.cpp +++ b/mozilla/accessible/src/nsHTMLTextAccessible.cpp @@ -24,7 +24,6 @@ #include "nsHTMLTextAccessible.h" #include "nsWeakReference.h" #include "nsIFrame.h" -#include "nsString.h" #include "nsILink.h" #include "nsILinkHandler.h" #include "nsISelection.h" diff --git a/mozilla/dom/public/idl/xul/Makefile.in b/mozilla/dom/public/idl/xul/Makefile.in index 2ac3af0c1e5..bdd88ee38b5 100644 --- a/mozilla/dom/public/idl/xul/Makefile.in +++ b/mozilla/dom/public/idl/xul/Makefile.in @@ -34,6 +34,9 @@ XPIDLSRCS = \ nsIDOMXULDocument.idl \ nsIDOMXULElement.idl \ nsIDOMXULTreeElement.idl \ + nsIDOMXULControlElement.idl \ + nsIDOMXULLabeledControlEl.idl \ + nsIDOMXULCheckboxElement.idl \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/mozilla/dom/public/idl/xul/makefile.win b/mozilla/dom/public/idl/xul/makefile.win index cf8811cc9af..21cbe82ae9e 100644 --- a/mozilla/dom/public/idl/xul/makefile.win +++ b/mozilla/dom/public/idl/xul/makefile.win @@ -30,6 +30,9 @@ XPIDLSRCS = \ .\nsIDOMXULDocument.idl \ .\nsIDOMXULElement.idl \ .\nsIDOMXULTreeElement.idl \ + .\nsIDOMXULControlElement.idl \ + .\nsIDOMXULLabeledControlEl.idl \ + .\nsIDOMXULCheckboxElement.idl \ $(NULL) include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/xpfe/global/resources/content/bindings/checkbox.xml b/mozilla/xpfe/global/resources/content/bindings/checkbox.xml index 588325362c2..458dafe288b 100644 --- a/mozilla/xpfe/global/resources/content/bindings/checkbox.xml +++ b/mozilla/xpfe/global/resources/content/bindings/checkbox.xml @@ -21,7 +21,15 @@ - + + + + + +