// Interface methods NS_IMETHODIMP nsHTMLSelectableAccessible::GetSelectedChildren(nsIArray **_retval) { *_retval = nsnull; nsCOMPtr<nsIAccessibilityService> accService(do_GetService("@mozilla.org/accessibilityService;1")); if (!accService) return NS_ERROR_FAILURE; nsCOMPtr<nsIMutableArray> selectedAccessibles = do_CreateInstance(NS_ARRAY_CONTRACTID); NS_ENSURE_STATE(selectedAccessibles); nsPresContext *context = GetPresContext(); if (!context) return NS_ERROR_FAILURE; nsHTMLSelectableAccessible::iterator iter(this, mWeakShell); while (iter.Advance()) iter.AddAccessibleIfSelected(accService, selectedAccessibles, context); PRUint32 uLength = 0; selectedAccessibles->GetLength(&uLength); if (uLength != 0) { // length of nsIArray containing selected options *_retval = selectedAccessibles; NS_ADDREF(*_retval); } return NS_OK; }
// return the nth selected child's nsIAccessible object NS_IMETHODIMP nsHTMLSelectableAccessible::RefSelection(PRInt32 aIndex, nsIAccessible **_retval) { *_retval = nsnull; nsCOMPtr<nsIAccessibilityService> accService(do_GetService("@mozilla.org/accessibilityService;1")); if (!accService) return NS_ERROR_FAILURE; nsPresContext *context = GetPresContext(); if (!context) return NS_ERROR_FAILURE; nsHTMLSelectableAccessible::iterator iter(this, mWeakShell); while (iter.Advance()) if (iter.GetAccessibleIfSelected(aIndex, accService, context, _retval)) return NS_OK; // No matched item found return NS_ERROR_FAILURE; }
void nsHTMLSelectListAccessible::CacheChildren() { // Cache the number of <optgroup> and <option> DOM decendents, // as well as the accessibles for them. Avoid whitespace text nodes. nsCOMPtr<nsIContent> selectContent(do_QueryInterface(mDOMNode)); nsCOMPtr<nsIAccessibilityService> accService(do_GetService("@mozilla.org/accessibilityService;1")); if (!selectContent || !accService) { mAccChildCount = eChildCountUninitialized; return; } if (mAccChildCount != eChildCountUninitialized) { return; } mAccChildCount = 0; // Avoid reentry PRInt32 childCount = 0; nsCOMPtr<nsIAccessible> lastGoodAccessible = CacheOptSiblings(accService, selectContent, nsnull, &childCount); mAccChildCount = childCount; }
NS_IMETHODIMP nsInlineFrame::GetAccessible(nsIAccessible** aAccessible) { // Broken image accessibles are created here, because layout // replaces the image or image control frame with an inline frame *aAccessible = nsnull; nsIAtom *tagAtom = mContent->Tag(); if ((tagAtom == nsGkAtoms::img || tagAtom == nsGkAtoms::input || tagAtom == nsGkAtoms::label) && mContent->IsNodeOfType(nsINode::eHTML)) { // Only get accessibility service if we're going to use it nsCOMPtr<nsIAccessibilityService> accService(do_GetService("@mozilla.org/accessibilityService;1")); if (!accService) return NS_ERROR_FAILURE; if (tagAtom == nsGkAtoms::input) // Broken <input type=image ... /> return accService->CreateHTMLButtonAccessible(static_cast<nsIFrame*>(this), aAccessible); else if (tagAtom == nsGkAtoms::img) // Create accessible for broken <img> return accService->CreateHTMLImageAccessible(static_cast<nsIFrame*>(this), aAccessible); else if (tagAtom == nsGkAtoms::label) // Creat accessible for <label> return accService->CreateHTMLLabelAccessible(static_cast<nsIFrame*>(this), aAccessible); } return NS_ERROR_FAILURE; }
/** Default Constructor */ nsHTMLSelectOptionAccessible::nsHTMLSelectOptionAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell): nsHyperTextAccessibleWrap(aDOMNode, aShell) { nsCOMPtr<nsIAccessibilityService> accService(do_GetService("@mozilla.org/accessibilityService;1")); nsCOMPtr<nsIDOMNode> parentNode; aDOMNode->GetParentNode(getter_AddRefs(parentNode)); nsCOMPtr<nsIAccessible> parentAccessible; if (parentNode) { // If the parent node is a Combobox, then the option's accessible parent // is nsHTMLComboboxListAccessible, not the nsHTMLComboboxAccessible that // GetParent would normally return. This is because the // nsHTMLComboboxListAccessible is inserted into the accessible hierarchy // where there is no DOM node for it. accService->GetAccessibleInWeakShell(parentNode, mWeakShell, getter_AddRefs(parentAccessible)); if (parentAccessible) { if (nsAccUtils::RoleInternal(parentAccessible) == nsIAccessibleRole::ROLE_COMBOBOX) { nsCOMPtr<nsIAccessible> comboAccessible(parentAccessible); comboAccessible->GetLastChild(getter_AddRefs(parentAccessible)); } } } SetParent(parentAccessible); }
NS_IMETHODIMP inDOMView::GetCellProperties(PRInt32 row, nsITreeColumn* col, nsISupportsArray *properties) { inDOMViewNode* node = nsnull; RowToNode(row, &node); if (!node) return NS_ERROR_FAILURE; nsCOMPtr<nsIContent> content = do_QueryInterface(node->node); if (content && content->IsInAnonymousSubtree()) { properties->AppendElement(kAnonymousAtom); } PRUint16 nodeType; node->node->GetNodeType(&nodeType); switch (nodeType) { case nsIDOMNode::ELEMENT_NODE: properties->AppendElement(kElementNodeAtom); break; case nsIDOMNode::ATTRIBUTE_NODE: properties->AppendElement(kAttributeNodeAtom); break; case nsIDOMNode::TEXT_NODE: properties->AppendElement(kTextNodeAtom); break; case nsIDOMNode::CDATA_SECTION_NODE: properties->AppendElement(kCDataSectionNodeAtom); break; case nsIDOMNode::ENTITY_REFERENCE_NODE: properties->AppendElement(kEntityReferenceNodeAtom); break; case nsIDOMNode::ENTITY_NODE: properties->AppendElement(kEntityNodeAtom); break; case nsIDOMNode::PROCESSING_INSTRUCTION_NODE: properties->AppendElement(kProcessingInstructionNodeAtom); break; case nsIDOMNode::COMMENT_NODE: properties->AppendElement(kCommentNodeAtom); break; case nsIDOMNode::DOCUMENT_NODE: properties->AppendElement(kDocumentNodeAtom); break; case nsIDOMNode::DOCUMENT_TYPE_NODE: properties->AppendElement(kDocumentTypeNodeAtom); break; case nsIDOMNode::DOCUMENT_FRAGMENT_NODE: properties->AppendElement(kDocumentFragmentNodeAtom); break; case nsIDOMNode::NOTATION_NODE: properties->AppendElement(kNotationNodeAtom); break; } #ifdef ACCESSIBILITY if (mShowAccessibleNodes) { nsCOMPtr<nsIAccessibilityService> accService( do_GetService("@mozilla.org/accessibilityService;1")); NS_ENSURE_TRUE(accService, NS_ERROR_FAILURE); nsCOMPtr<nsIAccessible> accessible; nsresult rv = accService->GetAccessibleFor(node->node, getter_AddRefs(accessible)); if (NS_SUCCEEDED(rv) && accessible) properties->AppendElement(kAccessibleNodeAtom); } #endif return NS_OK; }