Back to index

lightning-sunbird  0.9+nobinonly
nsXULTextAccessible.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  *   Aaron Leventhal (aaronl@netscape.com)
00024  *   Kyle Yuan (kyle.yuan@sun.com)
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 // NOTE: alphabetically ordered
00041 #include "nsAccessibilityAtoms.h"
00042 #include "nsBaseWidgetAccessible.h"
00043 #include "nsIDOMXULDescriptionElement.h"
00044 #include "nsINameSpaceManager.h"
00045 #include "nsString.h"
00046 #include "nsXULTextAccessible.h"
00047 
00051 nsXULTextAccessible::nsXULTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell):
00052 nsTextAccessibleWrap(aDomNode, aShell)
00053 { 
00054 }
00055 
00056 /* wstring getName (); */
00057 NS_IMETHODIMP nsXULTextAccessible::GetName(nsAString& aName)
00058 { 
00059   nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
00060   if (!content) {
00061     return NS_ERROR_FAILURE;  // Node shut down
00062   }
00063   nsresult rv = content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::value, aName);
00064   if (rv == NS_CONTENT_ATTR_NOT_THERE) {
00065     // if the value doesn't exist, flatten the inner content as the name (for descriptions)
00066     return AppendFlatStringFromSubtree(content, &aName);
00067   }
00068   // otherwise, use the value attribute as the name (for labels)
00069   return NS_OK;
00070 }
00071 
00072 NS_IMETHODIMP nsXULTextAccessible::GetState(PRUint32 *_retval)
00073 {
00074   // Labels and description can only have read only state
00075   // They are not focusable or selectable
00076   *_retval = STATE_READONLY;
00077   return NS_OK;
00078 }
00079 
00083 nsXULTooltipAccessible::nsXULTooltipAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell):
00084 nsLeafAccessible(aDomNode, aShell)
00085 { 
00086 }
00087 
00088 NS_IMETHODIMP nsXULTooltipAccessible::GetName(nsAString& _retval)
00089 {
00090   //XXX, kyle.yuan@sun.com, we don't know how to get at this information at the moment,
00091   //  because it is not loaded until it shows.
00092   return NS_OK;
00093 }
00094 
00095 NS_IMETHODIMP nsXULTooltipAccessible::GetState(PRUint32 *_retval)
00096 {
00097   nsLeafAccessible::GetState(_retval);
00098   *_retval &= ~STATE_FOCUSABLE;
00099   *_retval |= STATE_READONLY;
00100   return NS_OK;
00101 }
00102 
00103 NS_IMETHODIMP nsXULTooltipAccessible::GetRole(PRUint32 *_retval)
00104 {
00105   *_retval = ROLE_TOOLTIP;
00106   return NS_OK;
00107 }
00108 
00112 nsXULLinkAccessible::nsXULLinkAccessible(nsIDOMNode *aDomNode, nsIWeakReference *aShell):
00113 nsXULTextAccessible(aDomNode, aShell)
00114 {
00115 }
00116 
00117 NS_IMETHODIMP nsXULLinkAccessible::GetValue(nsAString& aValue)
00118 {
00119   if (mIsLink) {
00120     return mActionContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::href, aValue);
00121   }
00122   return NS_ERROR_NOT_IMPLEMENTED;
00123 }
00124 
00125 NS_IMETHODIMP nsXULLinkAccessible::GetRole(PRUint32 *aRole)
00126 {
00127   if (mIsLink) {
00128     *aRole = ROLE_LINK;
00129   } else {
00130     // default to calling the link a button; might have javascript
00131     *aRole = ROLE_PUSHBUTTON;
00132   }
00133   // should there be a third case where it becomes just text?
00134   return NS_OK;
00135 }
00136 
00137 void nsXULLinkAccessible::CacheActionContent()
00138 {
00139   // not a link if no content
00140   nsCOMPtr<nsIContent> mTempContent = do_QueryInterface(mDOMNode);
00141   if (!mTempContent) {
00142     return;
00143   }
00144 
00145   // not a link if there is no href attribute or not on a <link> tag
00146   if (mTempContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::href) ||
00147       mTempContent->Tag() == nsAccessibilityAtoms::link) {
00148     mIsLink = PR_TRUE;
00149     mActionContent = mTempContent;
00150   }
00151   else if (mTempContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::onclick)) {
00152     mIsOnclick = PR_TRUE;
00153     mActionContent = mTempContent;
00154   }
00155 }