Back to index

lightning-sunbird  0.9+nobinonly
nsOuterDocAccessible.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) 2003
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Original 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 "nsOuterDocAccessible.h"
00040 #include "nsIAccessibilityService.h"
00041 #include "nsIAccessibleDocument.h"
00042 #include "nsIDocument.h"
00043 #include "nsIPresShell.h"
00044 #include "nsIServiceManager.h"
00045 #include "nsIContent.h"
00046 
00047 NS_IMPL_ISUPPORTS_INHERITED0(nsOuterDocAccessible, nsAccessible)
00048 
00049 nsOuterDocAccessible::nsOuterDocAccessible(nsIDOMNode* aNode, 
00050                                            nsIWeakReference* aShell):
00051   nsAccessibleWrap(aNode, aShell)
00052 {
00053 }
00054 
00055   /* attribute wstring accName; */
00056 NS_IMETHODIMP nsOuterDocAccessible::GetName(nsAString& aName) 
00057 { 
00058   nsCOMPtr<nsIAccessibleDocument> accDoc(do_QueryInterface(mFirstChild));
00059   if (!accDoc) {
00060     return NS_ERROR_FAILURE;
00061   }
00062   nsresult rv = accDoc->GetTitle(aName);
00063   if (NS_FAILED(rv) || aName.IsEmpty()) {
00064     rv = nsAccessible::GetName(aName);
00065     if (aName.IsEmpty()) {
00066       rv = accDoc->GetURL(aName);
00067     }
00068   }
00069   return rv;
00070 }
00071 
00072 /* unsigned long getRole (); */
00073 NS_IMETHODIMP nsOuterDocAccessible::GetRole(PRUint32 *_retval)
00074 {
00075 #ifndef MOZ_ACCESSIBILITY_ATK
00076   *_retval = ROLE_CLIENT;
00077 #else
00078   *_retval = ROLE_PANE;
00079 #endif
00080   return NS_OK;
00081 }
00082 
00083 NS_IMETHODIMP nsOuterDocAccessible::GetState(PRUint32 *aState)
00084 {
00085   nsAccessible::GetState(aState);
00086   *aState &= ~STATE_FOCUSABLE;
00087   return NS_OK;
00088 }
00089 
00090 void nsOuterDocAccessible::CacheChildren(PRBool aWalkAnonContent)
00091 {  
00092   // An outer doc accessible usually has 1 nsDocAccessible child,
00093   // but could have none if we can't get to the inner documnet
00094   if (!mWeakShell) {
00095     mAccChildCount = eChildCountUninitialized;
00096     return;   // This outer doc node has been shut down
00097   }
00098   if (mAccChildCount != eChildCountUninitialized) {
00099     return;
00100   }
00101 
00102   mAccChildCount = 0;
00103   SetFirstChild(nsnull);
00104 
00105   // In these variable names, "outer" relates to the nsOuterDocAccessible
00106   // as opposed to the nsDocAccessibleWrap which is "inner".
00107   // The outer node is a something like a <browser>, <frame>, <iframe>, <page> or
00108   // <editor> tag, whereas the inner node corresponds to the inner document root.
00109 
00110   nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
00111   NS_ASSERTION(content, "No nsIContent for <browser>/<iframe>/<editor> dom node");
00112 
00113   nsCOMPtr<nsIDocument> outerDoc = content->GetDocument();
00114   if (!outerDoc) {
00115     return;
00116   }
00117 
00118   nsIDocument *innerDoc = outerDoc->GetSubDocumentFor(content);
00119   nsCOMPtr<nsIDOMNode> innerNode(do_QueryInterface(innerDoc));
00120   if (!innerNode) {
00121     return;
00122   }
00123 
00124   nsCOMPtr<nsIAccessible> innerAccessible;
00125   nsCOMPtr<nsIAccessibilityService> accService = 
00126     do_GetService("@mozilla.org/accessibilityService;1");
00127   accService->GetAccessibleFor(innerNode, getter_AddRefs(innerAccessible));
00128   nsCOMPtr<nsPIAccessible> privateInnerAccessible = 
00129     do_QueryInterface(innerAccessible);
00130   if (!privateInnerAccessible) {
00131     return;
00132   }
00133 
00134   // Success getting inner document as first child -- now we cache it.
00135   mAccChildCount = 1;
00136   SetFirstChild(innerAccessible); // weak ref
00137   privateInnerAccessible->SetParent(this);
00138   privateInnerAccessible->SetNextSibling(nsnull);
00139 }
00140