LCOV - code coverage report
Current view: directory - accessible/src/base - nsAccessNode.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 108 2 1.9 %
Date: 2012-06-02 Functions: 25 2 8.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2003
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Original Author: Aaron Leventhal (aaronl@netscape.com)
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      27                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #include "nsAccessNode.h"
      40                 : 
      41                 : #include "nsAccessibilityService.h"
      42                 : #include "nsAccUtils.h"
      43                 : #include "nsApplicationAccessibleWrap.h"
      44                 : #include "nsCoreUtils.h"
      45                 : #include "nsRootAccessible.h"
      46                 : 
      47                 : #include "nsIDocShell.h"
      48                 : #include "nsIDocShellTreeItem.h"
      49                 : #include "nsIDOMWindow.h"
      50                 : #include "nsIFrame.h"
      51                 : #include "nsIInterfaceRequestorUtils.h"
      52                 : #include "nsIObserverService.h"
      53                 : #include "nsIPrefBranch.h"
      54                 : #include "nsIPrefService.h"
      55                 : #include "nsIPresShell.h"
      56                 : #include "nsIServiceManager.h"
      57                 : #include "nsIStringBundle.h"
      58                 : #include "nsFocusManager.h"
      59                 : #include "nsPresContext.h"
      60                 : #include "mozilla/Services.h"
      61                 : 
      62                 : /* For documentation of the accessibility architecture, 
      63                 :  * see http://lxr.mozilla.org/seamonkey/source/accessible/accessible-docs.html
      64                 :  */
      65                 : 
      66                 : nsIStringBundle *nsAccessNode::gStringBundle = 0;
      67                 : 
      68                 : bool nsAccessNode::gIsFormFillEnabled = false;
      69                 : 
      70                 : nsApplicationAccessible *nsAccessNode::gApplicationAccessible = nsnull;
      71                 : 
      72                 : /*
      73                 :  * Class nsAccessNode
      74                 :  */
      75                 :  
      76                 : ////////////////////////////////////////////////////////////////////////////////
      77                 : // nsAccessible. nsISupports
      78                 : 
      79            1464 : NS_IMPL_CYCLE_COLLECTION_1(nsAccessNode, mContent)
      80                 : 
      81               0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsAccessNode)
      82               0 :   NS_INTERFACE_MAP_ENTRY(nsAccessNode)
      83               0 : NS_INTERFACE_MAP_END
      84                 :  
      85               0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(nsAccessNode)
      86               0 : NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_DESTROY(nsAccessNode, LastRelease())
      87                 : 
      88                 : ////////////////////////////////////////////////////////////////////////////////
      89                 : // nsAccessNode construction/desctruction
      90                 : 
      91               0 : nsAccessNode::
      92                 :   nsAccessNode(nsIContent* aContent, nsDocAccessible* aDoc) :
      93               0 :   mContent(aContent), mDoc(aDoc)
      94                 : {
      95                 : #ifdef DEBUG_A11Y
      96                 :   mIsInitialized = false;
      97                 : #endif
      98               0 : }
      99                 : 
     100               0 : nsAccessNode::~nsAccessNode()
     101                 : {
     102               0 :   NS_ASSERTION(!mDoc, "LastRelease was never called!?!");
     103               0 : }
     104                 : 
     105               0 : void nsAccessNode::LastRelease()
     106                 : {
     107                 :   // First cleanup if needed...
     108               0 :   if (mDoc) {
     109               0 :     Shutdown();
     110               0 :     NS_ASSERTION(!mDoc, "A Shutdown() impl forgot to call its parent's Shutdown?");
     111                 :   }
     112                 :   // ... then die.
     113               0 :   delete this;
     114               0 : }
     115                 : 
     116                 : ////////////////////////////////////////////////////////////////////////////////
     117                 : // nsAccessNode public
     118                 : 
     119                 : bool
     120               0 : nsAccessNode::IsDefunct() const
     121                 : {
     122               0 :   return !mContent;
     123                 : }
     124                 : 
     125                 : bool
     126               0 : nsAccessNode::Init()
     127                 : {
     128               0 :   return true;
     129                 : }
     130                 : 
     131                 : 
     132                 : void
     133               0 : nsAccessNode::Shutdown()
     134                 : {
     135               0 :   mContent = nsnull;
     136               0 :   mDoc = nsnull;
     137               0 : }
     138                 : 
     139                 : nsApplicationAccessible*
     140               0 : nsAccessNode::GetApplicationAccessible()
     141                 : {
     142               0 :   NS_ASSERTION(!nsAccessibilityService::IsShutdown(),
     143                 :                "Accessibility wasn't initialized!");
     144                 : 
     145               0 :   if (!gApplicationAccessible) {
     146               0 :     nsApplicationAccessibleWrap::PreCreate();
     147                 : 
     148               0 :     gApplicationAccessible = new nsApplicationAccessibleWrap();
     149               0 :     if (!gApplicationAccessible)
     150               0 :       return nsnull;
     151                 : 
     152                 :     // Addref on create. Will Release in ShutdownXPAccessibility()
     153               0 :     NS_ADDREF(gApplicationAccessible);
     154                 : 
     155               0 :     nsresult rv = gApplicationAccessible->Init();
     156               0 :     if (NS_FAILED(rv)) {
     157               0 :       gApplicationAccessible->Shutdown();
     158               0 :       NS_RELEASE(gApplicationAccessible);
     159               0 :       return nsnull;
     160                 :     }
     161                 :   }
     162                 : 
     163               0 :   return gApplicationAccessible;
     164                 : }
     165                 : 
     166               0 : void nsAccessNode::InitXPAccessibility()
     167                 : {
     168                 :   nsCOMPtr<nsIStringBundleService> stringBundleService =
     169               0 :     mozilla::services::GetStringBundleService();
     170               0 :   if (stringBundleService) {
     171                 :     // Static variables are released in ShutdownAllXPAccessibility();
     172               0 :     stringBundleService->CreateBundle(ACCESSIBLE_BUNDLE_URL, 
     173               0 :                                       &gStringBundle);
     174                 :   }
     175                 : 
     176               0 :   nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
     177               0 :   if (prefBranch) {
     178               0 :     prefBranch->GetBoolPref("browser.formfill.enable", &gIsFormFillEnabled);
     179                 :   }
     180                 : 
     181               0 :   NotifyA11yInitOrShutdown(true);
     182               0 : }
     183                 : 
     184                 : // nsAccessNode protected static
     185               0 : void nsAccessNode::NotifyA11yInitOrShutdown(bool aIsInit)
     186                 : {
     187                 :   nsCOMPtr<nsIObserverService> obsService =
     188               0 :     mozilla::services::GetObserverService();
     189               0 :   NS_ASSERTION(obsService, "No observer service to notify of a11y init/shutdown");
     190               0 :   if (!obsService)
     191                 :     return;
     192                 : 
     193                 :   static const PRUnichar kInitIndicator[] = { '1', 0 };
     194                 :   static const PRUnichar kShutdownIndicator[] = { '0', 0 }; 
     195               0 :   obsService->NotifyObservers(nsnull, "a11y-init-or-shutdown",
     196               0 :                               aIsInit ? kInitIndicator  : kShutdownIndicator);
     197                 : }
     198                 : 
     199               0 : void nsAccessNode::ShutdownXPAccessibility()
     200                 : {
     201                 :   // Called by nsAccessibilityService::Shutdown()
     202                 :   // which happens when xpcom is shutting down
     203                 :   // at exit of program
     204                 : 
     205               0 :   NS_IF_RELEASE(gStringBundle);
     206                 : 
     207                 :   // Release gApplicationAccessible after everything else is shutdown
     208                 :   // so we don't accidently create it again while tearing down root accessibles
     209               0 :   nsApplicationAccessibleWrap::Unload();
     210               0 :   if (gApplicationAccessible) {
     211               0 :     gApplicationAccessible->Shutdown();
     212               0 :     NS_RELEASE(gApplicationAccessible);
     213                 :   }
     214                 : 
     215               0 :   NotifyA11yInitOrShutdown(false);
     216               0 : }
     217                 : 
     218                 : // nsAccessNode protected
     219               0 : nsPresContext* nsAccessNode::GetPresContext()
     220                 : {
     221               0 :   if (IsDefunct())
     222               0 :     return nsnull;
     223                 : 
     224               0 :   nsIPresShell* presShell(mDoc->PresShell());
     225                 : 
     226               0 :   return presShell ? presShell->GetPresContext() : nsnull;
     227                 : }
     228                 : 
     229                 : nsRootAccessible*
     230               0 : nsAccessNode::RootAccessible() const
     231                 : {
     232                 :   nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem =
     233               0 :     nsCoreUtils::GetDocShellTreeItemFor(mContent);
     234               0 :   NS_ASSERTION(docShellTreeItem, "No docshell tree item for mContent");
     235               0 :   if (!docShellTreeItem) {
     236               0 :     return nsnull;
     237                 :   }
     238               0 :   nsCOMPtr<nsIDocShellTreeItem> root;
     239               0 :   docShellTreeItem->GetRootTreeItem(getter_AddRefs(root));
     240               0 :   NS_ASSERTION(root, "No root content tree item");
     241               0 :   if (!root) {
     242               0 :     return nsnull;
     243                 :   }
     244                 : 
     245               0 :   nsDocAccessible* docAcc = nsAccUtils::GetDocAccessibleFor(root);
     246               0 :   return docAcc ? docAcc->AsRoot() : nsnull;
     247                 : }
     248                 : 
     249                 : nsIFrame*
     250               0 : nsAccessNode::GetFrame() const
     251                 : {
     252               0 :   return mContent ? mContent->GetPrimaryFrame() : nsnull;
     253                 : }
     254                 : 
     255                 : bool
     256               0 : nsAccessNode::IsPrimaryForNode() const
     257                 : {
     258               0 :   return true;
     259                 : }
     260                 : 
     261                 : ////////////////////////////////////////////////////////////////////////////////
     262                 : void
     263               0 : nsAccessNode::ScrollTo(PRUint32 aScrollType)
     264                 : {
     265               0 :   if (IsDefunct())
     266               0 :     return;
     267                 : 
     268               0 :   nsIPresShell* shell = mDoc->PresShell();
     269               0 :   if (!shell)
     270               0 :     return;
     271                 : 
     272               0 :   nsIFrame *frame = GetFrame();
     273               0 :   if (!frame)
     274               0 :     return;
     275                 : 
     276               0 :   nsIContent* content = frame->GetContent();
     277               0 :   if (!content)
     278               0 :     return;
     279                 : 
     280                 :   PRInt16 vPercent, hPercent;
     281               0 :   nsCoreUtils::ConvertScrollTypeToPercents(aScrollType, &vPercent, &hPercent);
     282                 :   shell->ScrollContentIntoView(content, vPercent, hPercent,
     283               0 :                                nsIPresShell::SCROLL_OVERFLOW_HIDDEN);
     284                 : }
     285                 : 
     286                 : void
     287               0 : nsAccessNode::Language(nsAString& aLanguage)
     288                 : {
     289               0 :   aLanguage.Truncate();
     290                 : 
     291               0 :   if (IsDefunct())
     292               0 :     return;
     293                 : 
     294               0 :   nsCoreUtils::GetLanguageFor(mContent, nsnull, aLanguage);
     295               0 :   if (aLanguage.IsEmpty()) { // Nothing found, so use document's language
     296               0 :     mContent->OwnerDoc()->GetHeaderData(nsGkAtoms::headerContentLanguage,
     297               0 :                                         aLanguage);
     298                 :   }
     299            4392 : }
     300                 : 

Generated by: LCOV version 1.7