2007-06-01 20:01:38 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim:expandtab:shiftwidth=4:tabstop=4:
|
|
|
|
*/
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2007
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Bolian Yin <bolian.yin@sun.com>
|
|
|
|
* Ginn Chen <ginn.chen@sun.com>
|
|
|
|
* Alexander Surkov <surkov.alexander@gmail.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsApplicationAccessible.h"
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
#include "nsAccessibilityService.h"
|
|
|
|
|
2007-06-01 20:01:38 -07:00
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
nsApplicationAccessible::nsApplicationAccessible() :
|
|
|
|
nsAccessibleWrap(nsnull, nsnull)
|
2007-06-01 20:01:38 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-08-06 05:19:56 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2007-06-01 20:01:38 -07:00
|
|
|
// nsISupports
|
|
|
|
|
2010-03-18 11:49:39 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsApplicationAccessible, nsAccessible,
|
|
|
|
nsIAccessibleApplication)
|
2008-08-06 05:19:56 -07:00
|
|
|
|
2010-04-22 20:45:16 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIAccessNode
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsApplicationAccessible::GetRootDocument(nsIAccessibleDocument **aRootDocument)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRootDocument);
|
|
|
|
*aRootDocument = nsnull;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-08-06 05:19:56 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2007-06-01 20:01:38 -07:00
|
|
|
// nsIAccessible
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsApplicationAccessible::GetName(nsAString& aName)
|
|
|
|
{
|
2008-08-24 09:45:56 -07:00
|
|
|
aName.Truncate();
|
|
|
|
|
2007-06-01 20:01:38 -07:00
|
|
|
nsCOMPtr<nsIStringBundleService> bundleService =
|
|
|
|
do_GetService(NS_STRINGBUNDLE_CONTRACTID);
|
|
|
|
|
|
|
|
NS_ASSERTION(bundleService, "String bundle service must be present!");
|
|
|
|
NS_ENSURE_STATE(bundleService);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStringBundle> bundle;
|
2008-10-08 05:58:46 -07:00
|
|
|
nsresult rv = bundleService->CreateBundle("chrome://branding/locale/brand.properties",
|
|
|
|
getter_AddRefs(bundle));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-06-01 20:01:38 -07:00
|
|
|
|
|
|
|
nsXPIDLString appName;
|
2008-10-08 05:58:46 -07:00
|
|
|
rv = bundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(),
|
|
|
|
getter_Copies(appName));
|
|
|
|
if (NS_FAILED(rv) || appName.IsEmpty()) {
|
|
|
|
NS_WARNING("brandShortName not found, using default app name");
|
|
|
|
appName.AssignLiteral("Gecko based application");
|
2007-06-01 20:01:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
aName.Assign(appName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsApplicationAccessible::GetDescription(nsAString& aValue)
|
2007-06-01 20:01:38 -07:00
|
|
|
{
|
2009-12-10 11:12:19 -08:00
|
|
|
aValue.Truncate();
|
2007-06-01 20:01:38 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-03-07 07:38:58 -08:00
|
|
|
nsApplicationAccessible::GetRole(PRUint32 *aRole)
|
2007-06-01 20:01:38 -07:00
|
|
|
{
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(aRole);
|
|
|
|
|
2009-03-07 07:38:58 -08:00
|
|
|
return GetRoleInternal(aRole);
|
2007-06-01 20:01:38 -07:00
|
|
|
}
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsApplicationAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState)
|
2007-06-01 20:01:38 -07:00
|
|
|
{
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(aState);
|
2007-06-01 20:01:38 -07:00
|
|
|
*aState = 0;
|
2009-12-10 11:12:19 -08:00
|
|
|
|
2007-06-01 20:01:38 -07:00
|
|
|
if (aExtraState)
|
|
|
|
*aExtraState = 0;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-12-10 11:12:19 -08:00
|
|
|
nsApplicationAccessible::GetParent(nsIAccessible **aAccessible)
|
2009-11-19 06:44:59 -08:00
|
|
|
{
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(aAccessible);
|
|
|
|
*aAccessible = nsnull;
|
2007-06-01 20:01:38 -07:00
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
return IsDefunct() ? NS_ERROR_FAILURE : NS_OK;
|
|
|
|
}
|
2009-11-19 08:35:38 -08:00
|
|
|
|
2010-03-18 11:49:39 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIAccessibleApplication
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsApplicationAccessible::GetAppName(nsAString& aName)
|
|
|
|
{
|
|
|
|
aName.Truncate();
|
|
|
|
|
|
|
|
if (!mAppInfo)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCAutoString cname;
|
|
|
|
nsresult rv = mAppInfo->GetName(cname);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
AppendUTF8toUTF16(cname, aName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsApplicationAccessible::GetAppVersion(nsAString& aVersion)
|
|
|
|
{
|
|
|
|
aVersion.Truncate();
|
|
|
|
|
|
|
|
if (!mAppInfo)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCAutoString cversion;
|
|
|
|
nsresult rv = mAppInfo->GetVersion(cversion);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
AppendUTF8toUTF16(cversion, aVersion);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsApplicationAccessible::GetPlatformName(nsAString& aName)
|
|
|
|
{
|
|
|
|
aName.AssignLiteral("Gecko");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsApplicationAccessible::GetPlatformVersion(nsAString& aVersion)
|
|
|
|
{
|
|
|
|
aVersion.Truncate();
|
|
|
|
|
|
|
|
if (!mAppInfo)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCAutoString cversion;
|
|
|
|
nsresult rv = mAppInfo->GetPlatformVersion(cversion);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
AppendUTF8toUTF16(cversion, aVersion);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsAccessNode public methods
|
2009-11-19 08:35:38 -08:00
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
PRBool
|
|
|
|
nsApplicationAccessible::IsDefunct()
|
|
|
|
{
|
|
|
|
return nsAccessibilityService::gIsShutdown;
|
|
|
|
}
|
2007-06-01 20:01:38 -07:00
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
nsresult
|
|
|
|
nsApplicationAccessible::Init()
|
|
|
|
{
|
2010-03-18 11:49:39 -07:00
|
|
|
mAppInfo = do_GetService("@mozilla.org/xre/app-info;1");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsApplicationAccessible::Shutdown()
|
|
|
|
{
|
|
|
|
mAppInfo = nsnull;
|
2007-06-01 20:01:38 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsAccessible public methods
|
2007-06-01 20:01:38 -07:00
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
nsresult
|
|
|
|
nsApplicationAccessible::GetRoleInternal(PRUint32 *aRole)
|
|
|
|
{
|
|
|
|
*aRole = nsIAccessibleRole::ROLE_APP_ROOT;
|
2007-06-01 20:01:38 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
nsresult
|
|
|
|
nsApplicationAccessible::GetStateInternal(PRUint32 *aState,
|
|
|
|
PRUint32 *aExtraState)
|
2008-03-29 20:24:02 -07:00
|
|
|
{
|
2009-12-10 11:12:19 -08:00
|
|
|
*aState = 0;
|
|
|
|
if (aExtraState)
|
|
|
|
*aExtraState = 0;
|
2009-11-19 08:35:38 -08:00
|
|
|
|
|
|
|
return NS_OK;
|
2009-11-19 06:44:59 -08:00
|
|
|
}
|
2008-03-29 20:24:02 -07:00
|
|
|
|
2010-01-11 06:14:06 -08:00
|
|
|
nsAccessible*
|
2009-12-10 11:12:19 -08:00
|
|
|
nsApplicationAccessible::GetParent()
|
2009-11-19 06:44:59 -08:00
|
|
|
{
|
2009-12-10 11:12:19 -08:00
|
|
|
return nsnull;
|
|
|
|
}
|
2008-03-29 20:24:02 -07:00
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
void
|
|
|
|
nsApplicationAccessible::InvalidateChildren()
|
|
|
|
{
|
|
|
|
// Do nothing because application children are kept updated by
|
|
|
|
// AddRootAccessible() and RemoveRootAccessible() method calls.
|
2009-11-19 08:35:38 -08:00
|
|
|
}
|
2009-11-19 06:44:59 -08:00
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsAccessible protected methods
|
|
|
|
|
2007-06-01 20:01:38 -07:00
|
|
|
void
|
|
|
|
nsApplicationAccessible::CacheChildren()
|
|
|
|
{
|
2009-12-10 11:12:19 -08:00
|
|
|
// Nothing to do. Children are keeped up to dated by Add/RemoveRootAccessible
|
|
|
|
// method calls.
|
|
|
|
}
|
|
|
|
|
2010-03-10 02:26:11 -08:00
|
|
|
nsAccessible*
|
2009-12-10 11:12:19 -08:00
|
|
|
nsApplicationAccessible::GetSiblingAtOffset(PRInt32 aOffset, nsresult* aError)
|
|
|
|
{
|
|
|
|
if (IsDefunct()) {
|
|
|
|
if (aError)
|
|
|
|
*aError = NS_ERROR_FAILURE;
|
2009-11-19 06:44:59 -08:00
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
return nsnull;
|
2009-11-19 08:35:38 -08:00
|
|
|
}
|
2009-12-10 11:12:19 -08:00
|
|
|
|
|
|
|
if (aError)
|
|
|
|
*aError = NS_OK; // fail peacefully
|
|
|
|
|
|
|
|
return nsnull;
|
2007-06-01 20:01:38 -07:00
|
|
|
}
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Public methods
|
2007-06-01 20:01:38 -07:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsApplicationAccessible::AddRootAccessible(nsIAccessible *aRootAccessible)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRootAccessible);
|
|
|
|
|
2010-01-11 06:14:06 -08:00
|
|
|
nsRefPtr<nsAccessible> rootAcc =
|
|
|
|
nsAccUtils::QueryObject<nsAccessible>(aRootAccessible);
|
|
|
|
|
|
|
|
if (!mChildren.AppendElement(rootAcc))
|
2009-12-10 11:12:19 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
rootAcc->SetParent(this);
|
2007-06-01 20:01:38 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsApplicationAccessible::RemoveRootAccessible(nsIAccessible *aRootAccessible)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRootAccessible);
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
// It's not needed to void root accessible parent because this method is
|
|
|
|
// called on root accessible shutdown and its parent will be cleared
|
|
|
|
// properly.
|
2010-01-11 06:14:06 -08:00
|
|
|
return mChildren.RemoveElement(aRootAccessible) ? NS_OK : NS_ERROR_FAILURE;
|
2007-06-01 20:01:38 -07:00
|
|
|
}
|