Back to index

lightning-sunbird  0.9+nobinonly
nsXULTabAccessible.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: John Gaunt (jgaunt@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 // NOTE: alphabetically ordered
00040 #include "nsXULTabAccessible.h"
00041 #include "nsIDocument.h"
00042 #include "nsIFrame.h"
00043 #include "nsIDOMDocument.h"
00044 #include "nsIDOMXULSelectCntrlEl.h"
00045 #include "nsIDOMXULSelectCntrlItemEl.h"
00046 
00052 nsXULTabAccessible::nsXULTabAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
00053 nsLeafAccessible(aNode, aShell)
00054 { 
00055 }
00056 
00058 NS_IMETHODIMP nsXULTabAccessible::GetNumActions(PRUint8 *_retval)
00059 {
00060   *_retval = eSingle_Action;
00061   return NS_OK;
00062 }
00063 
00065 NS_IMETHODIMP nsXULTabAccessible::GetActionName(PRUint8 index, nsAString& _retval)
00066 {
00067   if (index == eAction_Click) {
00068     nsAccessible::GetTranslatedString(NS_LITERAL_STRING("switch"), _retval); 
00069     return NS_OK;
00070   }
00071   return NS_ERROR_INVALID_ARG;
00072 }
00073 
00075 NS_IMETHODIMP nsXULTabAccessible::DoAction(PRUint8 index)
00076 {
00077   if (index == eAction_Switch) {
00078     nsCOMPtr<nsIDOMXULElement> tab(do_QueryInterface(mDOMNode));
00079     if ( tab )
00080     {
00081       tab->Click();
00082       return NS_OK;
00083     }
00084     return NS_ERROR_FAILURE;
00085   }
00086   return NS_ERROR_INVALID_ARG;
00087 }
00088 
00090 NS_IMETHODIMP nsXULTabAccessible::GetRole(PRUint32 *_retval)
00091 {
00092   *_retval = ROLE_PAGETAB;
00093   return NS_OK;
00094 }
00095 
00099 NS_IMETHODIMP nsXULTabAccessible::GetState(PRUint32 *_retval)
00100 {
00101   // get focus and disable status from base class
00102   nsLeafAccessible::GetState(_retval);
00103 
00104   // In the past, tabs have been focusable in classic theme
00105   // They may be again in the future
00106   // Check style for -moz-user-focus: normal to see if it's focusable
00107   *_retval &= ~STATE_FOCUSABLE;
00108   nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
00109   nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mWeakShell));
00110   if (presShell && content) {
00111     nsIFrame *frame = nsnull;
00112     presShell->GetPrimaryFrameFor(content, &frame);
00113     if (frame) {
00114       const nsStyleUserInterface* ui = frame->GetStyleUserInterface();
00115       if (ui->mUserFocus == NS_STYLE_USER_FOCUS_NORMAL)
00116         *_retval |= STATE_FOCUSABLE;
00117     }
00118   }
00119   // Check whether the tab is selected
00120   *_retval |= STATE_SELECTABLE;
00121   *_retval &= ~STATE_SELECTED;
00122   nsCOMPtr<nsIDOMXULSelectControlItemElement> tab(do_QueryInterface(mDOMNode));
00123   if (tab) {
00124     PRBool selected = PR_FALSE;
00125     if (NS_SUCCEEDED(tab->GetSelected(&selected)) && selected)
00126       *_retval |= STATE_SELECTED;
00127   }
00128   return NS_OK;
00129 }
00130 
00138 nsXULTabBoxAccessible::nsXULTabBoxAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
00139 nsAccessibleWrap(aNode, aShell)
00140 { 
00141 }
00142 
00144 NS_IMETHODIMP nsXULTabBoxAccessible::GetRole(PRUint32 *_retval)
00145 {
00146   *_retval = ROLE_PANE;
00147   return NS_OK;
00148 }
00149 
00151 NS_IMETHODIMP nsXULTabBoxAccessible::GetState(PRUint32 *_retval)
00152 {
00153   nsAccessible::GetState(_retval);
00154   *_retval &= ~STATE_FOCUSABLE;
00155   return NS_OK;
00156 }
00157 
00158 #ifdef NEVER
00159 
00160 NS_IMETHODIMP nsXULTabBoxAccessible::GetChildCount(PRInt32 *_retval)
00161 {
00162   *_retval = 2;
00163   return NS_OK;
00164 }
00165 #endif
00166 
00181 nsXULTabPanelsAccessible::nsXULTabPanelsAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
00182 nsAccessibleWrap(aNode, aShell)
00183 { 
00184 }
00185 
00187 NS_IMETHODIMP nsXULTabPanelsAccessible::GetRole(PRUint32 *_retval)
00188 {
00189 #ifndef MOZ_ACCESSIBILITY_ATK
00190   *_retval = ROLE_PROPERTYPAGE;
00191 #else
00192   *_retval = ROLE_SCROLL_PANE;
00193 #endif
00194   return NS_OK;
00195 }
00196 
00200 NS_IMETHODIMP nsXULTabPanelsAccessible::GetState(PRUint32 *_retval)
00201 {
00202   // get focus and disable status from base class -- skip container because we have state
00203   nsAccessible::GetState(_retval);
00204   return NS_OK;
00205 }
00206 
00212 NS_IMETHODIMP nsXULTabPanelsAccessible::GetName(nsAString& _retval)
00213 {
00214   return NS_ERROR_NOT_IMPLEMENTED;
00215 }
00216 
00222 nsXULTabsAccessible::nsXULTabsAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
00223 nsXULSelectableAccessible(aNode, aShell)
00224 { 
00225 }
00226 
00228 NS_IMETHODIMP nsXULTabsAccessible::GetRole(PRUint32 *_retval)
00229 {
00230   *_retval = ROLE_PAGETABLIST;
00231   return NS_OK;
00232 }
00233 
00235 NS_IMETHODIMP nsXULTabsAccessible::GetNumActions(PRUint8 *_retval)
00236 {
00237   *_retval = eNo_Action;
00238   return NS_OK;
00239 }
00240 
00242 NS_IMETHODIMP nsXULTabsAccessible::GetState(PRUint32 *_retval)
00243 {
00244   return nsAccessible::GetState(_retval);
00245 }
00246 
00248 NS_IMETHODIMP nsXULTabsAccessible::GetValue(nsAString& _retval)
00249 {
00250   return NS_OK;
00251 }
00252 
00254 NS_IMETHODIMP nsXULTabsAccessible::GetName(nsAString& _retval)
00255 {
00256   _retval.Truncate();
00257   return NS_OK;
00258 }