Back to index

lightning-sunbird  0.9+nobinonly
nsHTMLTableAccessible.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Author: Aaron Leventhal (aaronl@netscape.com)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsHTMLTableAccessible.h"
00040 #include "nsAccessibilityAtoms.h"
00041 #include "nsIDOMElement.h"
00042 #include "nsINameSpaceManager.h"
00043 
00044 NS_IMPL_ISUPPORTS_INHERITED0(nsHTMLTableCellAccessible, nsBlockAccessible)
00045 
00046 nsHTMLTableCellAccessible::nsHTMLTableCellAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell):
00047 nsBlockAccessible(aDomNode, aShell)
00048 { 
00049 }
00050 
00051 /* unsigned long getRole (); */
00052 NS_IMETHODIMP nsHTMLTableCellAccessible::GetRole(PRUint32 *aResult)
00053 {
00054   *aResult = ROLE_CELL;
00055   return NS_OK;
00056 }
00057 
00058 NS_IMETHODIMP nsHTMLTableCellAccessible::GetState(PRUint32 *aResult)
00059 {
00060   nsAccessible::GetState(aResult);
00061   *aResult &= ~STATE_FOCUSABLE;   // Inherit all states except focusable state since table cells cannot be focused
00062   return NS_OK;
00063 }
00064 
00065 nsHTMLTableCaptionAccessible::nsHTMLTableCaptionAccessible
00066 (nsIDOMNode* aDomNode, nsIWeakReference* aShell):
00067 nsAccessibleWrap(aDomNode, aShell)
00068 {
00069   Init(); // Make sure this generated accessible of the table is cached
00070 }
00071 
00072 NS_IMETHODIMP
00073 nsHTMLTableCaptionAccessible::GetState(PRUint32 *aResult)
00074 {
00075   nsAccessible::GetState(aResult);
00076   *aResult &= ~STATE_FOCUSABLE;
00077   return NS_OK;
00078 }
00079 
00080 NS_IMETHODIMP
00081 nsHTMLTableCaptionAccessible::GetValue(nsAString& aResult)
00082 {
00083   aResult.Truncate();  // Default name is blank
00084 
00085   nsCOMPtr<nsIContent> captionContent(do_QueryInterface(mDOMNode));
00086   AppendFlatStringFromSubtree(captionContent, &aResult);
00087 
00088   return NS_OK;
00089 }
00090 
00091 NS_IMPL_ISUPPORTS_INHERITED0(nsHTMLTableAccessible, nsBlockAccessible)
00092 
00093 nsHTMLTableAccessible::nsHTMLTableAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell):
00094 nsBlockAccessible(aDomNode, aShell)
00095 { 
00096 }
00097 
00098 /* unsigned long getRole (); */
00099 NS_IMETHODIMP nsHTMLTableAccessible::GetRole(PRUint32 *aResult)
00100 {
00101   *aResult = ROLE_TABLE;
00102   return NS_OK;
00103 }
00104 
00105 NS_IMETHODIMP nsHTMLTableAccessible::GetState(PRUint32 *aResult)
00106 {
00107   nsAccessible::GetState(aResult);
00108   *aResult |= STATE_READONLY;
00109   *aResult &= ~STATE_FOCUSABLE;   // Inherit all states except focusable state since tables cannot be focused
00110   return NS_OK;
00111 }
00112 
00113 NS_IMETHODIMP nsHTMLTableAccessible::GetName(nsAString& aName)
00114 {
00115   aName.Truncate();  // Default name is blank
00116 
00117   if (mRoleMapEntry) {
00118     nsAccessible::GetName(aName);
00119     if (!aName.IsEmpty()) {
00120       return NS_OK;
00121     }
00122   }
00123 
00124   nsCOMPtr<nsIDOMElement> element(do_QueryInterface(mDOMNode));
00125   if (element) {
00126     nsCOMPtr<nsIDOMNodeList> captions;
00127     nsAutoString nameSpaceURI;
00128     element->GetNamespaceURI(nameSpaceURI);
00129     element->GetElementsByTagNameNS(nameSpaceURI, NS_LITERAL_STRING("caption"), 
00130                                     getter_AddRefs(captions));
00131     if (captions) {
00132       nsCOMPtr<nsIDOMNode> captionNode;
00133       captions->Item(0, getter_AddRefs(captionNode));
00134       if (captionNode) {
00135         nsCOMPtr<nsIContent> captionContent(do_QueryInterface(captionNode));
00136         AppendFlatStringFromSubtree(captionContent, &aName);
00137       }
00138     }
00139     if (aName.IsEmpty()) {
00140       nsCOMPtr<nsIContent> content(do_QueryInterface(element));
00141       NS_ASSERTION(content, "No content for DOM element");
00142       content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::summary, aName);
00143     }
00144   }
00145   return NS_OK;
00146 }
00147