NS_IMETHODIMP nsXULComboboxAccessible::GetActionName(PRUint8 aIndex, nsAString& aName) { if (aIndex != nsXULComboboxAccessible::eAction_Click) { return NS_ERROR_INVALID_ARG; } if (IsDefunct()) return NS_ERROR_FAILURE; // Our action name is the reverse of our state: // if we are close -> open is our name. // if we are open -> close is our name. // Uses the frame to get the state, updated on every click. nsCOMPtr<nsIDOMXULMenuListElement> menuList(do_QueryInterface(mDOMNode)); if (!menuList) { return NS_ERROR_FAILURE; } PRBool isDroppedDown; menuList->GetOpen(&isDroppedDown); if (isDroppedDown) aName.AssignLiteral("close"); else aName.AssignLiteral("open"); return NS_OK; }
nsresult nsXULComboboxAccessible::GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState) { // As a nsComboboxAccessible we can have the following states: // STATE_FOCUSED // STATE_FOCUSABLE // STATE_HASPOPUP // STATE_EXPANDED // STATE_COLLAPSED // Get focus status from base class nsresult rv = nsAccessible::GetStateInternal(aState, aExtraState); NS_ENSURE_A11Y_SUCCESS(rv, rv); nsCOMPtr<nsIDOMXULMenuListElement> menuList(do_QueryInterface(mDOMNode)); if (menuList) { PRBool isOpen; menuList->GetOpen(&isOpen); if (isOpen) { *aState |= nsIAccessibleStates::STATE_EXPANDED; } else { *aState |= nsIAccessibleStates::STATE_COLLAPSED; } } *aState |= nsIAccessibleStates::STATE_HASPOPUP | nsIAccessibleStates::STATE_FOCUSABLE; return NS_OK; }
BPopUpMenu* MenuBuilder::_BuildPopUpMenu(KeyBind* bind, BView* target) { if (bind == NULL) return NULL; // The first item describe the menu BPopUpMenu* menu = new BPopUpMenu(bind[0].label); BObjectList<BPopUpMenu> menuList(false); menuList.AddItem(menu); for (int i = 1; bind[i].message != FABER_EOF; i++) { menu = menuList.ItemAt(menuList.CountItems()-1); if (bind[i].message == FABER_ITEM_START) { BPopUpMenu* subMenu = new BPopUpMenu(bind[i].label); menu->AddItem(subMenu); menuList.AddItem(subMenu); } else if (bind[i].message == FABER_ITEM_END) { if (menuList.CountItems() > 1) menuList.RemoveItemAt(menuList.CountItems()-1); } else { BMenuItem* item = _BuildMenuItem(bind[i].message, bind[i].label); if (target != NULL) item->SetTarget(target); menu->AddItem(item); } } return menuList.ItemAt(0); }
NS_IMETHODIMP nsXULComboboxAccessible::GetValue(nsAString& aValue) { aValue.Truncate(); if (IsDefunct()) return NS_ERROR_FAILURE; // The value is the option or text shown entered in the combobox. nsCOMPtr<nsIDOMXULMenuListElement> menuList(do_QueryInterface(mDOMNode)); if (menuList) return menuList->GetLabel(aValue); return NS_ERROR_FAILURE; }
NS_IMETHODIMP nsXULComboboxAccessible::DoAction(PRUint8 aIndex) { if (aIndex != nsXULComboboxAccessible::eAction_Click) { return NS_ERROR_INVALID_ARG; } if (IsDefunct()) return NS_ERROR_FAILURE; // Programmaticaly toggle the combo box. nsCOMPtr<nsIDOMXULMenuListElement> menuList(do_QueryInterface(mDOMNode)); if (!menuList) { return NS_ERROR_FAILURE; } PRBool isDroppedDown; menuList->GetOpen(&isDroppedDown); return menuList->SetOpen(!isDroppedDown); }
NS_IMETHODIMP nsXULTextFieldAccessible::GetValue(nsAString& aValue) { PRUint32 state; nsresult rv = GetStateInternal(&state, nsnull); NS_ENSURE_SUCCESS(rv, rv); if (state & nsIAccessibleStates::STATE_PROTECTED) // Don't return password text! return NS_ERROR_FAILURE; nsCOMPtr<nsIDOMXULTextBoxElement> textBox(do_QueryInterface(mContent)); if (textBox) { return textBox->GetValue(aValue); } nsCOMPtr<nsIDOMXULMenuListElement> menuList(do_QueryInterface(mContent)); if (menuList) { return menuList->GetLabel(aValue); } return NS_ERROR_FAILURE; }
nsresult nsXULTextFieldAccessible::GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState) { nsresult rv = nsHyperTextAccessibleWrap::GetStateInternal(aState, aExtraState); NS_ENSURE_A11Y_SUCCESS(rv, rv); nsCOMPtr<nsIContent> inputField(GetInputField()); NS_ENSURE_TRUE(inputField, NS_ERROR_FAILURE); // Create a temporary accessible from the HTML text field // to get the accessible state from. Doesn't add to cache // because Init() is not called. nsHTMLTextFieldAccessible* tempAccessible = new nsHTMLTextFieldAccessible(inputField, mWeakShell); if (!tempAccessible) return NS_ERROR_OUT_OF_MEMORY; nsCOMPtr<nsIAccessible> kungFuDeathGrip = tempAccessible; rv = tempAccessible->GetStateInternal(aState, nsnull); NS_ENSURE_SUCCESS(rv, rv); if (gLastFocusedNode == mContent) *aState |= nsIAccessibleStates::STATE_FOCUSED; nsCOMPtr<nsIDOMXULMenuListElement> menuList(do_QueryInterface(mContent)); if (menuList) { // <xul:menulist droppable="false"> if (!mContent->AttrValueIs(kNameSpaceID_None, nsAccessibilityAtoms::editable, nsAccessibilityAtoms::_true, eIgnoreCase)) { *aState |= nsIAccessibleStates::STATE_READONLY; } } else { // <xul:textbox> if (mContent->AttrValueIs(kNameSpaceID_None, nsAccessibilityAtoms::type, nsAccessibilityAtoms::password, eIgnoreCase)) { *aState |= nsIAccessibleStates::STATE_PROTECTED; } if (mContent->AttrValueIs(kNameSpaceID_None, nsAccessibilityAtoms::readonly, nsAccessibilityAtoms::_true, eIgnoreCase)) { *aState |= nsIAccessibleStates::STATE_READONLY; } } if (!aExtraState) return NS_OK; PRBool isMultiLine = mContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::multiline); if (isMultiLine) { *aExtraState |= nsIAccessibleStates::EXT_STATE_MULTI_LINE; } else { *aExtraState |= nsIAccessibleStates::EXT_STATE_SINGLE_LINE; } return NS_OK; }