accessible/src/generic/ApplicationAccessible.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* vim:expandtab:shiftwidth=4:tabstop=4:
     3  */
     4 /* This Source Code Form is subject to the terms of the Mozilla Public
     5  * License, v. 2.0. If a copy of the MPL was not distributed with this
     6  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     8 #include "ApplicationAccessible.h"
    10 #include "nsAccessibilityService.h"
    11 #include "nsAccUtils.h"
    12 #include "Relation.h"
    13 #include "Role.h"
    14 #include "States.h"
    16 #include "nsIComponentManager.h"
    17 #include "nsIDOMDocument.h"
    18 #include "nsIDOMWindow.h"
    19 #include "nsIWindowMediator.h"
    20 #include "nsServiceManagerUtils.h"
    21 #include "mozilla/Services.h"
    22 #include "nsIStringBundle.h"
    24 using namespace mozilla::a11y;
    26 ApplicationAccessible::ApplicationAccessible() :
    27   AccessibleWrap(nullptr, nullptr)
    28 {
    29   mType = eApplicationType;
    30   mAppInfo = do_GetService("@mozilla.org/xre/app-info;1");
    31 }
    33 ////////////////////////////////////////////////////////////////////////////////
    34 // nsISupports
    36 NS_IMPL_ISUPPORTS_INHERITED(ApplicationAccessible, Accessible,
    37                             nsIAccessibleApplication)
    39 ////////////////////////////////////////////////////////////////////////////////
    40 // nsIAccessible
    42 NS_IMETHODIMP
    43 ApplicationAccessible::GetParent(nsIAccessible** aAccessible)
    44 {
    45   NS_ENSURE_ARG_POINTER(aAccessible);
    46   *aAccessible = nullptr;
    47   return NS_OK;
    48 }
    50 NS_IMETHODIMP
    51 ApplicationAccessible::GetNextSibling(nsIAccessible** aNextSibling)
    52 {
    53   NS_ENSURE_ARG_POINTER(aNextSibling);
    54   *aNextSibling = nullptr;
    55   return NS_OK;
    56 }
    58 NS_IMETHODIMP
    59 ApplicationAccessible::GetPreviousSibling(nsIAccessible** aPreviousSibling)
    60 {
    61   NS_ENSURE_ARG_POINTER(aPreviousSibling);
    62   *aPreviousSibling = nullptr;
    63   return NS_OK;
    64 }
    66 ENameValueFlag
    67 ApplicationAccessible::Name(nsString& aName)
    68 {
    69   aName.Truncate();
    71   nsCOMPtr<nsIStringBundleService> bundleService =
    72     mozilla::services::GetStringBundleService();
    74   NS_ASSERTION(bundleService, "String bundle service must be present!");
    75   if (!bundleService)
    76     return eNameOK;
    78   nsCOMPtr<nsIStringBundle> bundle;
    79   nsresult rv = bundleService->CreateBundle("chrome://branding/locale/brand.properties",
    80                                             getter_AddRefs(bundle));
    81   if (NS_FAILED(rv))
    82     return eNameOK;
    84   nsXPIDLString appName;
    85   rv = bundle->GetStringFromName(MOZ_UTF16("brandShortName"),
    86                                  getter_Copies(appName));
    87   if (NS_FAILED(rv) || appName.IsEmpty()) {
    88     NS_WARNING("brandShortName not found, using default app name");
    89     appName.AssignLiteral("Gecko based application");
    90   }
    92   aName.Assign(appName);
    93   return eNameOK;
    94 }
    96 void
    97 ApplicationAccessible::Description(nsString& aDescription)
    98 {
    99   aDescription.Truncate();
   100 }
   102 void
   103 ApplicationAccessible::Value(nsString& aValue)
   104 {
   105   aValue.Truncate();
   106 }
   108 uint64_t
   109 ApplicationAccessible::State()
   110 {
   111   return IsDefunct() ? states::DEFUNCT : 0;
   112 }
   114 already_AddRefed<nsIPersistentProperties>
   115 ApplicationAccessible::NativeAttributes()
   116 {
   117   return nullptr;
   118 }
   120 GroupPos
   121 ApplicationAccessible::GroupPosition()
   122 {
   123   return GroupPos();
   124 }
   126 Accessible*
   127 ApplicationAccessible::ChildAtPoint(int32_t aX, int32_t aY,
   128                                     EWhichChildAtPoint aWhichChild)
   129 {
   130   return nullptr;
   131 }
   133 Accessible*
   134 ApplicationAccessible::FocusedChild()
   135 {
   136   Accessible* focus = FocusMgr()->FocusedAccessible();
   137   if (focus && focus->Parent() == this)
   138     return focus;
   140   return nullptr;
   141 }
   143 Relation
   144 ApplicationAccessible::RelationByType(RelationType aRelationType)
   145 {
   146   return Relation();
   147 }
   149 NS_IMETHODIMP
   150 ApplicationAccessible::GetBounds(int32_t* aX, int32_t* aY,
   151                                  int32_t* aWidth, int32_t* aHeight)
   152 {
   153   NS_ENSURE_ARG_POINTER(aX);
   154   *aX = 0;
   155   NS_ENSURE_ARG_POINTER(aY);
   156   *aY = 0;
   157   NS_ENSURE_ARG_POINTER(aWidth);
   158   *aWidth = 0;
   159   NS_ENSURE_ARG_POINTER(aHeight);
   160   *aHeight = 0;
   161   return NS_OK;
   162 }
   164 NS_IMETHODIMP
   165 ApplicationAccessible::SetSelected(bool aIsSelected)
   166 {
   167   return NS_OK;
   168 }
   170 NS_IMETHODIMP
   171 ApplicationAccessible::TakeSelection()
   172 {
   173   return NS_OK;
   174 }
   176 NS_IMETHODIMP
   177 ApplicationAccessible::TakeFocus()
   178 {
   179   return NS_OK;
   180 }
   182 uint8_t
   183 ApplicationAccessible::ActionCount()
   184 {
   185   return 0;
   186 }
   188 NS_IMETHODIMP
   189 ApplicationAccessible::GetActionName(uint8_t aIndex, nsAString& aName)
   190 {
   191   aName.Truncate();
   192   return NS_ERROR_INVALID_ARG;
   193 }
   195 NS_IMETHODIMP
   196 ApplicationAccessible::GetActionDescription(uint8_t aIndex,
   197                                             nsAString& aDescription)
   198 {
   199   aDescription.Truncate();
   200   return NS_ERROR_INVALID_ARG;
   201 }
   203 NS_IMETHODIMP
   204 ApplicationAccessible::DoAction(uint8_t aIndex)
   205 {
   206   return NS_OK;
   207 }
   209 ////////////////////////////////////////////////////////////////////////////////
   210 // nsIAccessibleApplication
   212 NS_IMETHODIMP
   213 ApplicationAccessible::GetAppName(nsAString& aName)
   214 {
   215   aName.Truncate();
   217   if (!mAppInfo)
   218     return NS_ERROR_FAILURE;
   220   nsAutoCString cname;
   221   nsresult rv = mAppInfo->GetName(cname);
   222   NS_ENSURE_SUCCESS(rv, rv);
   224   AppendUTF8toUTF16(cname, aName);
   225   return NS_OK;
   226 }
   228 NS_IMETHODIMP
   229 ApplicationAccessible::GetAppVersion(nsAString& aVersion)
   230 {
   231   aVersion.Truncate();
   233   if (!mAppInfo)
   234     return NS_ERROR_FAILURE;
   236   nsAutoCString cversion;
   237   nsresult rv = mAppInfo->GetVersion(cversion);
   238   NS_ENSURE_SUCCESS(rv, rv);
   240   AppendUTF8toUTF16(cversion, aVersion);
   241   return NS_OK;
   242 }
   244 NS_IMETHODIMP
   245 ApplicationAccessible::GetPlatformName(nsAString& aName)
   246 {
   247   aName.AssignLiteral("Gecko");
   248   return NS_OK;
   249 }
   251 NS_IMETHODIMP
   252 ApplicationAccessible::GetPlatformVersion(nsAString& aVersion)
   253 {
   254   aVersion.Truncate();
   256   if (!mAppInfo)
   257     return NS_ERROR_FAILURE;
   259   nsAutoCString cversion;
   260   nsresult rv = mAppInfo->GetPlatformVersion(cversion);
   261   NS_ENSURE_SUCCESS(rv, rv);
   263   AppendUTF8toUTF16(cversion, aVersion);
   264   return NS_OK;
   265 }
   267 ////////////////////////////////////////////////////////////////////////////////
   268 // Accessible public methods
   270 void
   271 ApplicationAccessible::Shutdown()
   272 {
   273   mAppInfo = nullptr;
   274 }
   276 void
   277 ApplicationAccessible::ApplyARIAState(uint64_t* aState) const
   278 {
   279 }
   281 role
   282 ApplicationAccessible::NativeRole()
   283 {
   284   return roles::APP_ROOT;
   285 }
   287 uint64_t
   288 ApplicationAccessible::NativeState()
   289 {
   290   return 0;
   291 }
   293 void
   294 ApplicationAccessible::InvalidateChildren()
   295 {
   296   // Do nothing because application children are kept updated by AppendChild()
   297   // and RemoveChild() method calls.
   298 }
   300 KeyBinding
   301 ApplicationAccessible::AccessKey() const
   302 {
   303   return KeyBinding();
   304 }
   306 ////////////////////////////////////////////////////////////////////////////////
   307 // Accessible protected methods
   309 void
   310 ApplicationAccessible::CacheChildren()
   311 {
   312   // CacheChildren is called only once for application accessible when its
   313   // children are requested because empty InvalidateChldren() prevents its
   314   // repeated calls.
   316   // Basically children are kept updated by Append/RemoveChild method calls.
   317   // However if there are open windows before accessibility was started
   318   // then we need to make sure root accessibles for open windows are created so
   319   // that all root accessibles are stored in application accessible children
   320   // array.
   322   nsCOMPtr<nsIWindowMediator> windowMediator =
   323     do_GetService(NS_WINDOWMEDIATOR_CONTRACTID);
   325   nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
   326   nsresult rv = windowMediator->GetEnumerator(nullptr,
   327                                               getter_AddRefs(windowEnumerator));
   328   if (NS_FAILED(rv))
   329     return;
   331   bool hasMore = false;
   332   windowEnumerator->HasMoreElements(&hasMore);
   333   while (hasMore) {
   334     nsCOMPtr<nsISupports> window;
   335     windowEnumerator->GetNext(getter_AddRefs(window));
   336     nsCOMPtr<nsIDOMWindow> DOMWindow = do_QueryInterface(window);
   337     if (DOMWindow) {
   338       nsCOMPtr<nsIDOMDocument> DOMDocument;
   339       DOMWindow->GetDocument(getter_AddRefs(DOMDocument));
   340       if (DOMDocument) {
   341         nsCOMPtr<nsIDocument> docNode(do_QueryInterface(DOMDocument));
   342         GetAccService()->GetDocAccessible(docNode); // ensure creation
   343       }
   344     }
   345     windowEnumerator->HasMoreElements(&hasMore);
   346   }
   347 }
   349 Accessible*
   350 ApplicationAccessible::GetSiblingAtOffset(int32_t aOffset,
   351                                           nsresult* aError) const
   352 {
   353   if (aError)
   354     *aError = NS_OK; // fail peacefully
   356   return nullptr;
   357 }
   359 ////////////////////////////////////////////////////////////////////////////////
   360 // nsIAccessible
   362 NS_IMETHODIMP
   363 ApplicationAccessible::GetRootDocument(nsIAccessibleDocument** aRootDocument)
   364 {
   365   NS_ENSURE_ARG_POINTER(aRootDocument);
   366   *aRootDocument = nullptr;
   367   return NS_OK;
   368 }
   370 NS_IMETHODIMP
   371 ApplicationAccessible::ScrollTo(uint32_t aScrollType)
   372 {
   373   return NS_OK;
   374 }
   376 NS_IMETHODIMP
   377 ApplicationAccessible::ScrollToPoint(uint32_t aCoordinateType,
   378                                      int32_t aX, int32_t aY)
   379 {
   380   return NS_OK;
   381 }
   383 NS_IMETHODIMP
   384 ApplicationAccessible::GetLanguage(nsAString& aLanguage)
   385 {
   386   aLanguage.Truncate();
   387   return NS_OK;
   388 }

mercurial