From f45294373048952a71b4a6e41feb732900894d14 Mon Sep 17 00:00:00 2001 From: "aaronleventhal%moonset.net" Date: Fri, 4 Jun 2004 19:28:36 +0000 Subject: [PATCH] Bug 242594. Expose list and list item objects, and bullet text. r=Louie.Zhao, sr=jst/dbaron --- accessible/public/nsIAccessibilityService.idl | 2 + accessible/src/base/nsAccessibilityAtomList.h | 8 ++ .../src/base/nsAccessibilityService.cpp | 121 ++++++++++++------ accessible/src/base/nsAccessible.cpp | 3 +- accessible/src/base/nsAccessible.h | 2 +- accessible/src/html/nsHTMLTextAccessible.cpp | 75 ++++++++++- accessible/src/html/nsHTMLTextAccessible.h | 48 ++++++- accessible/src/msaa/nsAccessibleWrap.cpp | 4 +- accessible/src/xul/nsXULTextAccessible.h | 1 + layout/generic/nsBlockFrame.cpp | 35 ++++- layout/generic/nsBlockFrame.h | 4 + layout/generic/nsBulletFrame.h | 9 +- layout/html/base/src/nsBlockFrame.cpp | 35 ++++- layout/html/base/src/nsBlockFrame.h | 4 + layout/html/base/src/nsBulletFrame.h | 9 +- 15 files changed, 298 insertions(+), 62 deletions(-) diff --git a/accessible/public/nsIAccessibilityService.idl b/accessible/public/nsIAccessibilityService.idl index 78b74e1abab..6b4cd62aa67 100644 --- a/accessible/public/nsIAccessibilityService.idl +++ b/accessible/public/nsIAccessibilityService.idl @@ -55,6 +55,8 @@ interface nsIAccessibilityService : nsIAccessibleRetrieval nsIAccessible createHTMLBlockAccessible(in nsISupports aFrame); nsIAccessible createHTMLButtonAccessible(in nsISupports aFrame); nsIAccessible createHTMLButtonAccessibleXBL(in nsIDOMNode aNode); + nsIAccessible createHTMLAccessibleByMarkup(in nsISupports aFrame); + nsIAccessible createHTMLLIAccessible(in nsISupports aFrame, in nsISupports aBulletFrame, in AString aBulletText); nsIAccessible createHTMLCheckboxAccessible(in nsISupports aFrame); nsIAccessible createHTMLCheckboxAccessibleXBL(in nsIDOMNode aNode); nsIAccessible createHTMLComboboxAccessible(in nsIDOMNode aNode, in nsISupports aPresShell); diff --git a/accessible/src/base/nsAccessibilityAtomList.h b/accessible/src/base/nsAccessibilityAtomList.h index 38f7d442d63..2d30bc44329 100755 --- a/accessible/src/base/nsAccessibilityAtomList.h +++ b/accessible/src/base/nsAccessibilityAtomList.h @@ -60,3 +60,11 @@ ACCESSIBILITY_ATOM(blockFrame, "BlockFrame") ACCESSIBILITY_ATOM(inlineFrame, "InlineFrame") ACCESSIBILITY_ATOM(objectFrame, "ObjectFrame") ACCESSIBILITY_ATOM(textFrame, "TextFrame") + + // Alphabetical list of tag names +ACCESSIBILITY_ATOM(a, "a") +ACCESSIBILITY_ATOM(ol, "ol") +ACCESSIBILITY_ATOM(optgroup, "optgroup") +ACCESSIBILITY_ATOM(option, "option") +ACCESSIBILITY_ATOM(ul, "ul") + diff --git a/accessible/src/base/nsAccessibilityService.cpp b/accessible/src/base/nsAccessibilityService.cpp index 2e06e112e31..51220c313aa 100644 --- a/accessible/src/base/nsAccessibilityService.cpp +++ b/accessible/src/base/nsAccessibilityService.cpp @@ -416,6 +416,69 @@ nsAccessibilityService::CreateHTMLButtonAccessibleXBL(nsIDOMNode *aNode, nsIAcce return NS_OK; } +NS_IMETHODIMP +nsAccessibilityService::CreateHTMLAccessibleByMarkup(nsISupports *aFrame, + nsIAccessible **aAccessible) +{ + // Frame type was generic, we'll use the DOM to decide + // if and what kind of accessible object is needed. + // This method assumes we're in an HTML namespace. + *aAccessible = nsnull; + nsIFrame* frame; + nsCOMPtr node; + nsCOMPtr weakShell; + nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node)); + NS_ENSURE_SUCCESS(rv, rv); + nsIContent *content = frame->GetContent(); + NS_ENSURE_TRUE(content, NS_ERROR_FAILURE); + + nsIAtom *tag = content->Tag(); + if (tag == nsAccessibilityAtoms::option) { + *aAccessible = new nsHTMLSelectOptionAccessible(node, weakShell); + } + else if (tag == nsAccessibilityAtoms::optgroup) { + *aAccessible = new nsHTMLSelectOptGroupAccessible(node, weakShell); + } +#ifndef MOZ_ACCESSIBILITY_ATK + else if (tag == nsAccessibilityAtoms::ul || tag == nsAccessibilityAtoms::ol) { + *aAccessible = new nsHTMLListAccessible(node, weakShell); + } + else if (tag == nsAccessibilityAtoms::a) { + *aAccessible = new nsHTMLLinkAccessible(node, weakShell, frame); + } +#endif + else { + return NS_ERROR_FAILURE; + } + + NS_ENSURE_TRUE(aAccessible, NS_ERROR_OUT_OF_MEMORY); + NS_ADDREF(*aAccessible); + return NS_OK; +} + +NS_IMETHODIMP +nsAccessibilityService::CreateHTMLLIAccessible(nsISupports *aFrame, + nsISupports *aBulletFrame, + const nsAString& aBulletText, + nsIAccessible **_retval) +{ + nsIFrame* frame; + nsCOMPtr node; + nsCOMPtr weakShell; + nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node)); + if (NS_FAILED(rv)) + return rv; + nsIFrame *bulletFrame = NS_STATIC_CAST(nsIFrame*, aBulletFrame); + NS_ASSERTION(bulletFrame, "bullet frame argument not a frame"); + + *_retval = new nsHTMLLIAccessible(node, weakShell, bulletFrame, aBulletText); + if (! *_retval) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(*_retval); + return NS_OK; +} + NS_IMETHODIMP nsAccessibilityService::CreateHTMLCheckboxAccessible(nsISupports *aFrame, nsIAccessible **_retval) { @@ -1566,7 +1629,7 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessible(nsIDOMNode *aNode, // Please leave this in for now, it's a convenient debugging method nsAutoString name; aNode->GetLocalName(name); - if (name.EqualsIgnoreCase("browser")) + if (name.EqualsIgnoreCase("ol")) printf("## aaronl debugging tag name\n"); nsAutoString attrib; @@ -1653,6 +1716,13 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessible(nsIDOMNode *aNode, printf("* "); // Aaron's break point } #endif + if (frame->GetContent() != content) { + // Not the main content for this frame! + // For example, this happens because elements return the + // image frame as their primary frame. The main content for the + // image frame is the image content. + return NS_ERROR_FAILURE; + } *aFrameHint = frame; } } @@ -1665,17 +1735,20 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessible(nsIDOMNode *aNode, return NS_ERROR_FAILURE; } + /** + * Attempt to create an accessible based on what we know + */ if (content->IsContentOfType(nsIContent::eTEXT)) { - // ---- Try using frame to get nsIAccessible ---- + // --- Create HTML for visible text frames --- nsSize frameSize = frame->GetSize(); if (frameSize.height == 0 || frameSize.width == 0) { *aIsHidden = true; return NS_ERROR_FAILURE; } frame->GetAccessible(getter_AddRefs(newAcc)); - return InitAccessible(newAcc, aAccessible); } else if (!content->IsContentOfType(nsIContent::eHTML)) { + // --- Try creating accessible non-HTML (XUL, etc.) --- // XUL elements may implement nsIAccessibleProvider via XBL // This allows them to say what kind of accessible to create nsCOMPtr accProv(do_QueryInterface(aNode)); @@ -1684,42 +1757,14 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessible(nsIDOMNode *aNode, if (!accProv) return NS_ERROR_FAILURE; accProv->GetAccessible(getter_AddRefs(newAcc)); - return InitAccessible(newAcc, aAccessible); } - - // ---- Check if area node ---- - nsCOMPtr areaContent(do_QueryInterface(aNode)); - if (areaContent) // Area elements are implemented in nsHTMLImageAccessible as children of the image - return NS_ERROR_FAILURE; // Return, otherwise the image frame looks like an accessible object in the wrong place - - // ---- Try using frame to get nsIAccessible ---- - frame->GetAccessible(getter_AddRefs(newAcc)); - -#ifndef MOZ_ACCESSIBILITY_ATK - // ---- If link, create link accessible ---- - if (!newAcc) { - // is it a link? - nsCOMPtr link(do_QueryInterface(aNode)); - if (link) { - newAcc = new nsHTMLLinkAccessible(aNode, aWeakShell, frame); - } - } -#endif //MOZ_ACCESSIBILITY_ATK - - // ---- If