From a845b3e2a08db39f274e2e39208fea10e542c623 Mon Sep 17 00:00:00 2001 From: "aaronleventhal%moonset.net" Date: Fri, 27 Oct 2006 16:24:58 +0000 Subject: [PATCH] Bug 352522. In-page comboboxes use entry, do not show current text. r=ginn.chen --- .../src/html/nsHTMLSelectAccessible.cpp | 86 +++++++------------ accessible/src/html/nsHTMLSelectAccessible.h | 10 +-- 2 files changed, 34 insertions(+), 62 deletions(-) diff --git a/accessible/src/html/nsHTMLSelectAccessible.cpp b/accessible/src/html/nsHTMLSelectAccessible.cpp index 0f6ad3ab0ba..59bff48f574 100644 --- a/accessible/src/html/nsHTMLSelectAccessible.cpp +++ b/accessible/src/html/nsHTMLSelectAccessible.cpp @@ -952,7 +952,7 @@ NS_IMETHODIMP nsHTMLComboboxAccessible::GetValue(nsAString& aValue) nsHTMLComboboxTextFieldAccessible::nsHTMLComboboxTextFieldAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell): -nsLeafAccessible(aDOMNode, aShell) +nsHTMLTextFieldAccessible(aDOMNode, aShell) { // There is no cache entry for this item. // It's generated and ref'd by nsHTMLComboboxAccessible @@ -980,31 +980,9 @@ NS_IMETHODIMP nsHTMLComboboxTextFieldAccessible::GetNextSibling(nsIAccessible ** return NS_OK; } -/** - * Currently gets the text from the first option, needs to check for selection - * and then return that text. - * Walks the Frame tree and checks for proper frames. - */ -NS_IMETHODIMP nsHTMLComboboxTextFieldAccessible::GetValue(nsAString& _retval) -{ - nsIFrame* frame = nsAccessible::GetBoundsFrame(); - if (!frame) - return NS_ERROR_FAILURE; - - frame = frame->GetFirstChild(nsnull)->GetFirstChild(nsnull); - nsIContent* content = frame->GetContent(); - - if (!content) - return NS_ERROR_FAILURE; - - AppendFlatStringFromSubtree(content, &_retval); - - return NS_OK; -} - NS_IMETHODIMP nsHTMLComboboxTextFieldAccessible::GetUniqueID(void **aUniqueID) { - // Since mDOMNode is same for all tree item, use |this| pointer as the unique Id + // Since mDOMNode is same as for our parent, use |this| pointer as the unique Id *aUniqueID = NS_STATIC_CAST(void*, this); return NS_OK; } @@ -1026,12 +1004,33 @@ void nsHTMLComboboxTextFieldAccessible::GetBoundsRect(nsRect& aBounds, nsIFrame* aBounds = frame->GetRect(); } -/** Return our cached parent */ -NS_IMETHODIMP nsHTMLComboboxTextFieldAccessible::GetParent(nsIAccessible **_retval) -{ - *_retval = mParent; - NS_IF_ADDREF(*_retval); - return NS_OK; +void nsHTMLComboboxTextFieldAccessible::CacheChildren() +{ + // Allow single text anonymous child, so that nsHyperTextAccessible can operate correctly + // We must override this otherwise we get the dropdown button as a child of the textfield, + // and at least for now we want to keep it as a sibling + if (!mWeakShell) { + // This node has been shut down + mAccChildCount = eChildCountUninitialized; + return; + } + + // Allows only 1 child + if (mAccChildCount == eChildCountUninitialized) { + nsAccessibleTreeWalker walker(mWeakShell, mDOMNode, PR_TRUE); + // Seed the frame hint early while we're still on a container node. + // This is better than doing the GetPrimaryFrameFor() later on + // a text node, because text nodes aren't in the frame map. + walker.mState.frame = GetFrame(); + + walker.GetFirstChild(); + SetFirstChild(walker.mState.accessible); + nsCOMPtr privateChild = + do_QueryInterface(walker.mState.accessible); + privateChild->SetParent(this); + privateChild->SetNextSibling(nsnull); + mAccChildCount = 1; + } } /** @@ -1043,33 +1042,6 @@ NS_IMETHODIMP nsHTMLComboboxTextFieldAccessible::GetPreviousSibling(nsIAccessibl return NS_OK; } -/** - * Our role is currently only static text, but we should be able to have - * editable text here and we need to check that case. - */ -NS_IMETHODIMP nsHTMLComboboxTextFieldAccessible::GetRole(PRUint32 *_retval) -{ - *_retval = ROLE_ENTRY; - return NS_OK; -} - -/** - * As a nsHTMLComboboxTextFieldAccessible we can have the following states: - * STATE_READONLY - * STATE_FOCUSED - * STATE_FOCUSABLE - */ -NS_IMETHODIMP nsHTMLComboboxTextFieldAccessible::GetState(PRUint32 *_retval) -{ - // Get focus status from base class - nsAccessible::GetState(_retval); - - *_retval |= STATE_READONLY | STATE_FOCUSABLE; - - return NS_OK; -} - - /** -----ComboboxButtonAccessible ----- */ /** Constructor -- cache our parent */ diff --git a/accessible/src/html/nsHTMLSelectAccessible.h b/accessible/src/html/nsHTMLSelectAccessible.h index 07966dbcb60..0be5277c517 100644 --- a/accessible/src/html/nsHTMLSelectAccessible.h +++ b/accessible/src/html/nsHTMLSelectAccessible.h @@ -46,6 +46,7 @@ #include "nsIDOMHTMLOptionElement.h" #include "nsIDOMNode.h" #include "nsIAccessibilityService.h" +#include "nsAccessibleTreeWalker.h" class nsIMutableArray; @@ -225,7 +226,7 @@ protected: * A class the represents the text field in the Select to the left * of the drop down button */ -class nsHTMLComboboxTextFieldAccessible : public nsLeafAccessible +class nsHTMLComboboxTextFieldAccessible : public nsHTMLTextFieldAccessible { public: @@ -235,13 +236,12 @@ public: /* ----- nsIAccessible ----- */ NS_IMETHOD GetNextSibling(nsIAccessible **_retval); NS_IMETHOD GetPreviousSibling(nsIAccessible **_retval); - NS_IMETHOD GetParent(nsIAccessible **_retval); - NS_IMETHOD GetRole(PRUint32 *_retval); - NS_IMETHOD GetValue(nsAString& _retval); - NS_IMETHOD GetState(PRUint32 *_retval); NS_IMETHOD GetUniqueID(void **aUniqueID); virtual void GetBoundsRect(nsRect& aBounds, nsIFrame** aBoundingFrame); + +protected: + void CacheChildren(); }; /**