LCOV - code coverage report
Current view: directory - accessible/src/base - nsApplicationAccessible.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 184 0 0.0 %
Date: 2012-06-02 Functions: 46 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 : /* vim:expandtab:shiftwidth=4:tabstop=4:
       3                 :  */
       4                 : /* ***** BEGIN LICENSE BLOCK *****
       5                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       6                 :  *
       7                 :  * The contents of this file are subject to the Mozilla Public License Version
       8                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       9                 :  * the License. You may obtain a copy of the License at
      10                 :  * http://www.mozilla.org/MPL/
      11                 :  *
      12                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      13                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      14                 :  * for the specific language governing rights and limitations under the
      15                 :  * License.
      16                 :  *
      17                 :  * The Original Code is mozilla.org code.
      18                 :  *
      19                 :  * The Initial Developer of the Original Code is
      20                 :  * Mozilla Foundation.
      21                 :  * Portions created by the Initial Developer are Copyright (C) 2007
      22                 :  * the Initial Developer. All Rights Reserved.
      23                 :  *
      24                 :  * Contributor(s):
      25                 :  *   Bolian Yin <bolian.yin@sun.com>
      26                 :  *   Ginn Chen <ginn.chen@sun.com>
      27                 :  *   Alexander Surkov <surkov.alexander@gmail.com>
      28                 :  *
      29                 :  * Alternatively, the contents of this file may be used under the terms of
      30                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      31                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      32                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      33                 :  * of those above. If you wish to allow use of your version of this file only
      34                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      35                 :  * use your version of this file under the terms of the MPL, indicate your
      36                 :  * decision by deleting the provisions above and replace them with the notice
      37                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      38                 :  * the provisions above, a recipient may use your version of this file under
      39                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      40                 :  *
      41                 :  * ***** END LICENSE BLOCK ***** */
      42                 :  
      43                 : #include "nsApplicationAccessible.h"
      44                 : 
      45                 : #include "nsAccessibilityService.h"
      46                 : #include "nsAccUtils.h"
      47                 : #include "Relation.h"
      48                 : #include "Role.h"
      49                 : #include "States.h"
      50                 : 
      51                 : #include "nsIComponentManager.h"
      52                 : #include "nsIDOMDocument.h"
      53                 : #include "nsIDOMWindow.h"
      54                 : #include "nsIWindowMediator.h"
      55                 : #include "nsServiceManagerUtils.h"
      56                 : #include "mozilla/Services.h"
      57                 : 
      58                 : using namespace mozilla::a11y;
      59                 : 
      60               0 : nsApplicationAccessible::nsApplicationAccessible() :
      61               0 :   nsAccessibleWrap(nsnull, nsnull)
      62                 : {
      63               0 :   mFlags |= eApplicationAccessible;
      64               0 : }
      65                 : 
      66                 : ////////////////////////////////////////////////////////////////////////////////
      67                 : // nsISupports
      68                 : 
      69               0 : NS_IMPL_ISUPPORTS_INHERITED1(nsApplicationAccessible, nsAccessible,
      70                 :                              nsIAccessibleApplication)
      71                 : 
      72                 : ////////////////////////////////////////////////////////////////////////////////
      73                 : // nsIAccessible
      74                 : 
      75                 : NS_IMETHODIMP
      76               0 : nsApplicationAccessible::GetParent(nsIAccessible **aAccessible)
      77                 : {
      78               0 :   NS_ENSURE_ARG_POINTER(aAccessible);
      79               0 :   *aAccessible = nsnull;
      80               0 :   return NS_OK;
      81                 : }
      82                 : 
      83                 : NS_IMETHODIMP
      84               0 : nsApplicationAccessible::GetNextSibling(nsIAccessible **aNextSibling)
      85                 : {
      86               0 :   NS_ENSURE_ARG_POINTER(aNextSibling);
      87               0 :   *aNextSibling = nsnull;
      88               0 :   return NS_OK;
      89                 : }
      90                 : 
      91                 : NS_IMETHODIMP
      92               0 : nsApplicationAccessible::GetPreviousSibling(nsIAccessible **aPreviousSibling)
      93                 : {
      94               0 :   NS_ENSURE_ARG_POINTER(aPreviousSibling);
      95               0 :   *aPreviousSibling = nsnull;
      96               0 :   return NS_OK;
      97                 : }
      98                 : 
      99                 : NS_IMETHODIMP
     100               0 : nsApplicationAccessible::GetName(nsAString& aName)
     101                 : {
     102               0 :   aName.Truncate();
     103                 : 
     104                 :   nsCOMPtr<nsIStringBundleService> bundleService =
     105               0 :     mozilla::services::GetStringBundleService();
     106                 : 
     107               0 :   NS_ASSERTION(bundleService, "String bundle service must be present!");
     108               0 :   NS_ENSURE_STATE(bundleService);
     109                 : 
     110               0 :   nsCOMPtr<nsIStringBundle> bundle;
     111               0 :   nsresult rv = bundleService->CreateBundle("chrome://branding/locale/brand.properties",
     112               0 :                                             getter_AddRefs(bundle));
     113               0 :   NS_ENSURE_SUCCESS(rv, rv);
     114                 : 
     115               0 :   nsXPIDLString appName;
     116               0 :   rv = bundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(),
     117               0 :                                  getter_Copies(appName));
     118               0 :   if (NS_FAILED(rv) || appName.IsEmpty()) {
     119               0 :     NS_WARNING("brandShortName not found, using default app name");
     120               0 :     appName.AssignLiteral("Gecko based application");
     121                 :   }
     122                 : 
     123               0 :   aName.Assign(appName);
     124               0 :   return NS_OK;
     125                 : }
     126                 : 
     127                 : NS_IMETHODIMP
     128               0 : nsApplicationAccessible::GetValue(nsAString &aValue)
     129                 : {
     130               0 :   aValue.Truncate();
     131               0 :   return NS_OK;
     132                 : }
     133                 : 
     134                 : void
     135               0 : nsApplicationAccessible::Description(nsString &aDescription)
     136                 : {
     137               0 :   aDescription.Truncate();
     138               0 : }
     139                 : 
     140                 : PRUint64
     141               0 : nsApplicationAccessible::State()
     142                 : {
     143               0 :   return IsDefunct() ? states::DEFUNCT : 0;
     144                 : }
     145                 : 
     146                 : NS_IMETHODIMP
     147               0 : nsApplicationAccessible::GetAttributes(nsIPersistentProperties **aAttributes)
     148                 : {
     149               0 :   NS_ENSURE_ARG_POINTER(aAttributes);
     150               0 :   *aAttributes = nsnull;
     151               0 :   return NS_OK;
     152                 : }
     153                 : 
     154                 : NS_IMETHODIMP
     155               0 : nsApplicationAccessible::GroupPosition(PRInt32 *aGroupLevel,
     156                 :                                        PRInt32 *aSimilarItemsInGroup,
     157                 :                                        PRInt32 *aPositionInGroup)
     158                 : {
     159               0 :   NS_ENSURE_ARG_POINTER(aGroupLevel);
     160               0 :   *aGroupLevel = 0;
     161               0 :   NS_ENSURE_ARG_POINTER(aSimilarItemsInGroup);
     162               0 :   *aSimilarItemsInGroup = 0;
     163               0 :   NS_ENSURE_ARG_POINTER(aPositionInGroup);
     164               0 :   *aPositionInGroup = 0;
     165               0 :   return NS_OK;
     166                 : }
     167                 : 
     168                 : nsAccessible*
     169               0 : nsApplicationAccessible::ChildAtPoint(PRInt32 aX, PRInt32 aY,
     170                 :                                       EWhichChildAtPoint aWhichChild)
     171                 : {
     172               0 :   return nsnull;
     173                 : }
     174                 : 
     175                 : nsAccessible*
     176               0 : nsApplicationAccessible::FocusedChild()
     177                 : {
     178               0 :   nsAccessible* focus = FocusMgr()->FocusedAccessible();
     179               0 :   if (focus && focus->Parent() == this)
     180               0 :     return focus;
     181                 : 
     182               0 :   return nsnull;
     183                 : }
     184                 : 
     185                 : Relation
     186               0 : nsApplicationAccessible::RelationByType(PRUint32 aRelationType)
     187                 : {
     188               0 :   return Relation();
     189                 : }
     190                 : 
     191                 : NS_IMETHODIMP
     192               0 : nsApplicationAccessible::GetBounds(PRInt32 *aX, PRInt32 *aY,
     193                 :                                    PRInt32 *aWidth, PRInt32 *aHeight)
     194                 : {
     195               0 :   NS_ENSURE_ARG_POINTER(aX);
     196               0 :   *aX = 0;
     197               0 :   NS_ENSURE_ARG_POINTER(aY);
     198               0 :   *aY = 0;
     199               0 :   NS_ENSURE_ARG_POINTER(aWidth);
     200               0 :   *aWidth = 0;
     201               0 :   NS_ENSURE_ARG_POINTER(aHeight);
     202               0 :   *aHeight = 0;
     203               0 :   return NS_OK;
     204                 : }
     205                 : 
     206                 : NS_IMETHODIMP
     207               0 : nsApplicationAccessible::SetSelected(bool aIsSelected)
     208                 : {
     209               0 :   return NS_OK;
     210                 : }
     211                 : 
     212                 : NS_IMETHODIMP
     213               0 : nsApplicationAccessible::TakeSelection()
     214                 : {
     215               0 :   return NS_OK;
     216                 : }
     217                 : 
     218                 : NS_IMETHODIMP
     219               0 : nsApplicationAccessible::TakeFocus()
     220                 : {
     221               0 :   return NS_OK;
     222                 : }
     223                 : 
     224                 : PRUint8
     225               0 : nsApplicationAccessible::ActionCount()
     226                 : {
     227               0 :   return 0;
     228                 : }
     229                 : 
     230                 : NS_IMETHODIMP
     231               0 : nsApplicationAccessible::GetActionName(PRUint8 aIndex, nsAString &aName)
     232                 : {
     233               0 :   aName.Truncate();
     234               0 :   return NS_ERROR_INVALID_ARG;
     235                 : }
     236                 : 
     237                 : NS_IMETHODIMP
     238               0 : nsApplicationAccessible::GetActionDescription(PRUint8 aIndex,
     239                 :                                               nsAString &aDescription)
     240                 : {
     241               0 :   aDescription.Truncate();
     242               0 :   return NS_ERROR_INVALID_ARG;
     243                 : }
     244                 : 
     245                 : NS_IMETHODIMP
     246               0 : nsApplicationAccessible::DoAction(PRUint8 aIndex)
     247                 : {
     248               0 :   return NS_OK;
     249                 : }
     250                 : 
     251                 : ////////////////////////////////////////////////////////////////////////////////
     252                 : // nsIAccessibleApplication
     253                 : 
     254                 : NS_IMETHODIMP
     255               0 : nsApplicationAccessible::GetAppName(nsAString& aName)
     256                 : {
     257               0 :   aName.Truncate();
     258                 : 
     259               0 :   if (!mAppInfo)
     260               0 :     return NS_ERROR_FAILURE;
     261                 : 
     262               0 :   nsCAutoString cname;
     263               0 :   nsresult rv = mAppInfo->GetName(cname);
     264               0 :   NS_ENSURE_SUCCESS(rv, rv);
     265                 : 
     266               0 :   AppendUTF8toUTF16(cname, aName);
     267               0 :   return NS_OK;
     268                 : }
     269                 : 
     270                 : NS_IMETHODIMP
     271               0 : nsApplicationAccessible::GetAppVersion(nsAString& aVersion)
     272                 : {
     273               0 :   aVersion.Truncate();
     274                 : 
     275               0 :   if (!mAppInfo)
     276               0 :     return NS_ERROR_FAILURE;
     277                 : 
     278               0 :   nsCAutoString cversion;
     279               0 :   nsresult rv = mAppInfo->GetVersion(cversion);
     280               0 :   NS_ENSURE_SUCCESS(rv, rv);
     281                 : 
     282               0 :   AppendUTF8toUTF16(cversion, aVersion);
     283               0 :   return NS_OK;
     284                 : }
     285                 : 
     286                 : NS_IMETHODIMP
     287               0 : nsApplicationAccessible::GetPlatformName(nsAString& aName)
     288                 : {
     289               0 :   aName.AssignLiteral("Gecko");
     290               0 :   return NS_OK;
     291                 : }
     292                 : 
     293                 : NS_IMETHODIMP
     294               0 : nsApplicationAccessible::GetPlatformVersion(nsAString& aVersion)
     295                 : {
     296               0 :   aVersion.Truncate();
     297                 : 
     298               0 :   if (!mAppInfo)
     299               0 :     return NS_ERROR_FAILURE;
     300                 : 
     301               0 :   nsCAutoString cversion;
     302               0 :   nsresult rv = mAppInfo->GetPlatformVersion(cversion);
     303               0 :   NS_ENSURE_SUCCESS(rv, rv);
     304                 : 
     305               0 :   AppendUTF8toUTF16(cversion, aVersion);
     306               0 :   return NS_OK;
     307                 : }
     308                 : 
     309                 : ////////////////////////////////////////////////////////////////////////////////
     310                 : // nsAccessNode public methods
     311                 : 
     312                 : bool
     313               0 : nsApplicationAccessible::IsDefunct() const
     314                 : {
     315               0 :   return nsAccessibilityService::IsShutdown();
     316                 : }
     317                 : 
     318                 : bool
     319               0 : nsApplicationAccessible::Init()
     320                 : {
     321               0 :   mAppInfo = do_GetService("@mozilla.org/xre/app-info;1");
     322               0 :   return true;
     323                 : }
     324                 : 
     325                 : void
     326               0 : nsApplicationAccessible::Shutdown()
     327                 : {
     328               0 :   mAppInfo = nsnull;
     329               0 : }
     330                 : 
     331                 : bool
     332               0 : nsApplicationAccessible::IsPrimaryForNode() const
     333                 : {
     334               0 :   return false;
     335                 : }
     336                 : 
     337                 : ////////////////////////////////////////////////////////////////////////////////
     338                 : // nsAccessible public methods
     339                 : 
     340                 : void
     341               0 : nsApplicationAccessible::ApplyARIAState(PRUint64* aState)
     342                 : {
     343               0 : }
     344                 : 
     345                 : role
     346               0 : nsApplicationAccessible::NativeRole()
     347                 : {
     348               0 :   return roles::APP_ROOT;
     349                 : }
     350                 : 
     351                 : PRUint64
     352               0 : nsApplicationAccessible::NativeState()
     353                 : {
     354               0 :   return 0;
     355                 : }
     356                 : 
     357                 : void
     358               0 : nsApplicationAccessible::InvalidateChildren()
     359                 : {
     360                 :   // Do nothing because application children are kept updated by AppendChild()
     361                 :   // and RemoveChild() method calls.
     362               0 : }
     363                 : 
     364                 : KeyBinding
     365               0 : nsApplicationAccessible::AccessKey() const
     366                 : {
     367               0 :   return KeyBinding();
     368                 : }
     369                 : 
     370                 : ////////////////////////////////////////////////////////////////////////////////
     371                 : // nsAccessible protected methods
     372                 : 
     373                 : void
     374               0 : nsApplicationAccessible::CacheChildren()
     375                 : {
     376                 :   // CacheChildren is called only once for application accessible when its
     377                 :   // children are requested because empty InvalidateChldren() prevents its
     378                 :   // repeated calls.
     379                 : 
     380                 :   // Basically children are kept updated by Append/RemoveChild method calls.
     381                 :   // However if there are open windows before accessibility was started
     382                 :   // then we need to make sure root accessibles for open windows are created so
     383                 :   // that all root accessibles are stored in application accessible children
     384                 :   // array.
     385                 : 
     386                 :   nsCOMPtr<nsIWindowMediator> windowMediator =
     387               0 :     do_GetService(NS_WINDOWMEDIATOR_CONTRACTID);
     388                 : 
     389               0 :   nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
     390               0 :   nsresult rv = windowMediator->GetEnumerator(nsnull,
     391               0 :                                               getter_AddRefs(windowEnumerator));
     392               0 :   if (NS_FAILED(rv))
     393                 :     return;
     394                 : 
     395               0 :   bool hasMore = false;
     396               0 :   windowEnumerator->HasMoreElements(&hasMore);
     397               0 :   while (hasMore) {
     398               0 :     nsCOMPtr<nsISupports> window;
     399               0 :     windowEnumerator->GetNext(getter_AddRefs(window));
     400               0 :     nsCOMPtr<nsIDOMWindow> DOMWindow = do_QueryInterface(window);
     401               0 :     if (DOMWindow) {
     402               0 :       nsCOMPtr<nsIDOMDocument> DOMDocument;
     403               0 :       DOMWindow->GetDocument(getter_AddRefs(DOMDocument));
     404               0 :       if (DOMDocument) {
     405               0 :         nsCOMPtr<nsIDocument> docNode(do_QueryInterface(DOMDocument));
     406               0 :         GetAccService()->GetDocAccessible(docNode); // ensure creation
     407                 :       }
     408                 :     }
     409               0 :     windowEnumerator->HasMoreElements(&hasMore);
     410                 :   }
     411                 : }
     412                 : 
     413                 : nsAccessible*
     414               0 : nsApplicationAccessible::GetSiblingAtOffset(PRInt32 aOffset,
     415                 :                                             nsresult* aError) const
     416                 : {
     417               0 :   if (aError)
     418               0 :     *aError = NS_OK; // fail peacefully
     419                 : 
     420               0 :   return nsnull;
     421                 : }
     422                 : 
     423                 : ////////////////////////////////////////////////////////////////////////////////
     424                 : // nsIAccessible
     425                 : 
     426                 : NS_IMETHODIMP
     427               0 : nsApplicationAccessible::GetDOMNode(nsIDOMNode **aDOMNode)
     428                 : {
     429               0 :   NS_ENSURE_ARG_POINTER(aDOMNode);
     430               0 :   *aDOMNode = nsnull;
     431               0 :   return NS_OK;
     432                 : }
     433                 : 
     434                 : NS_IMETHODIMP
     435               0 : nsApplicationAccessible::GetDocument(nsIAccessibleDocument **aDocument)
     436                 : {
     437               0 :   NS_ENSURE_ARG_POINTER(aDocument);
     438               0 :   *aDocument = nsnull;
     439               0 :   return NS_OK;
     440                 : }
     441                 : 
     442                 : NS_IMETHODIMP
     443               0 : nsApplicationAccessible::GetRootDocument(nsIAccessibleDocument **aRootDocument)
     444                 : {
     445               0 :   NS_ENSURE_ARG_POINTER(aRootDocument);
     446               0 :   *aRootDocument = nsnull;
     447               0 :   return NS_OK;
     448                 : }
     449                 : 
     450                 : NS_IMETHODIMP
     451               0 : nsApplicationAccessible::GetInnerHTML(nsAString &aInnerHTML)
     452                 : {
     453               0 :   aInnerHTML.Truncate();
     454               0 :   return NS_OK;
     455                 : }
     456                 : 
     457                 : NS_IMETHODIMP
     458               0 : nsApplicationAccessible::ScrollTo(PRUint32 aScrollType)
     459                 : {
     460               0 :   return NS_OK;
     461                 : }
     462                 : 
     463                 : NS_IMETHODIMP
     464               0 : nsApplicationAccessible::ScrollToPoint(PRUint32 aCoordinateType,
     465                 :                                        PRInt32 aX, PRInt32 aY)
     466                 : {
     467               0 :   return NS_OK;
     468                 : }
     469                 : 
     470                 : NS_IMETHODIMP
     471               0 : nsApplicationAccessible::GetLanguage(nsAString &aLanguage)
     472                 : {
     473               0 :   aLanguage.Truncate();
     474               0 :   return NS_OK;
     475                 : }
     476                 : 

Generated by: LCOV version 1.7