2011-04-27 13:42:27 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2011-05-27 22:37:24 +00:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2003-04-23 05:28:41 +00:00
|
|
|
|
2012-04-25 11:29:40 +00:00
|
|
|
#include "ApplicationAccessibleWrap.h"
|
2009-08-21 12:33:31 +00:00
|
|
|
|
2003-04-23 05:28:41 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2003-05-06 02:23:50 +00:00
|
|
|
#include "nsMai.h"
|
2009-08-11 07:03:01 +00:00
|
|
|
#include "nsAccessibilityService.h"
|
2003-04-23 05:28:41 +00:00
|
|
|
|
2003-05-16 01:41:46 +00:00
|
|
|
#include <gtk/gtk.h>
|
2003-04-23 05:28:41 +00:00
|
|
|
#include <atk/atk.h>
|
|
|
|
|
2011-11-26 19:48:55 +00:00
|
|
|
using namespace mozilla;
|
2012-01-05 01:54:17 +00:00
|
|
|
using namespace mozilla::a11y;
|
2011-11-26 19:48:55 +00:00
|
|
|
|
2012-11-20 15:33:30 +00:00
|
|
|
|
2012-04-25 11:29:40 +00:00
|
|
|
// ApplicationAccessibleWrap
|
2007-06-02 03:01:38 +00:00
|
|
|
|
2012-04-25 11:29:40 +00:00
|
|
|
ApplicationAccessibleWrap::ApplicationAccessibleWrap():
|
|
|
|
ApplicationAccessible()
|
2003-04-23 05:28:41 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-04-25 11:29:40 +00:00
|
|
|
ApplicationAccessibleWrap::~ApplicationAccessibleWrap()
|
2003-04-23 05:28:41 +00:00
|
|
|
{
|
2012-05-29 01:18:45 +00:00
|
|
|
AccessibleWrap::ShutdownAtkObject();
|
2003-04-23 05:28:41 +00:00
|
|
|
}
|
|
|
|
|
2012-12-02 00:58:25 +00:00
|
|
|
gboolean
|
2011-07-14 01:58:32 +00:00
|
|
|
toplevel_event_watcher(GSignalInvocationHint* ihint,
|
|
|
|
guint n_param_values,
|
|
|
|
const GValue* param_values,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2011-07-21 21:31:36 +00:00
|
|
|
static GQuark sQuark_gecko_acc_obj = 0;
|
|
|
|
|
|
|
|
if (!sQuark_gecko_acc_obj)
|
|
|
|
sQuark_gecko_acc_obj = g_quark_from_static_string("GeckoAccObj");
|
|
|
|
|
2011-07-14 01:58:32 +00:00
|
|
|
if (nsAccessibilityService::IsShutdown())
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
GObject* object = reinterpret_cast<GObject*>(g_value_get_object(param_values));
|
|
|
|
if (!GTK_IS_WINDOW(object))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
AtkObject* child = gtk_widget_get_accessible(GTK_WIDGET(object));
|
|
|
|
|
|
|
|
// GTK native dialog
|
|
|
|
if (!IS_MAI_OBJECT(child) &&
|
|
|
|
(atk_object_get_role(child) == ATK_ROLE_DIALOG)) {
|
|
|
|
|
|
|
|
if (data == reinterpret_cast<gpointer>(nsIAccessibleEvent::EVENT_SHOW)) {
|
|
|
|
|
|
|
|
// Attach the dialog accessible to app accessible tree
|
2012-05-29 01:18:45 +00:00
|
|
|
Accessible* windowAcc = GetAccService()->AddNativeRootAccessible(child);
|
2011-07-14 01:58:32 +00:00
|
|
|
g_object_set_qdata(G_OBJECT(child), sQuark_gecko_acc_obj,
|
|
|
|
reinterpret_cast<gpointer>(windowAcc));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Deattach the dialog accessible
|
2012-05-29 01:18:45 +00:00
|
|
|
Accessible* windowAcc =
|
|
|
|
reinterpret_cast<Accessible*>
|
2011-07-14 01:58:32 +00:00
|
|
|
(g_object_get_qdata(G_OBJECT(child), sQuark_gecko_acc_obj));
|
|
|
|
if (windowAcc) {
|
|
|
|
GetAccService()->RemoveNativeRootAccessible(windowAcc);
|
2013-04-03 00:33:43 +00:00
|
|
|
g_object_set_qdata(G_OBJECT(child), sQuark_gecko_acc_obj, nullptr);
|
2011-07-14 01:58:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-05-01 03:08:31 +00:00
|
|
|
ENameValueFlag
|
|
|
|
ApplicationAccessibleWrap::Name(nsString& aName)
|
2012-03-06 10:01:55 +00:00
|
|
|
{
|
|
|
|
// ATK doesn't provide a way to obtain an application name (for example,
|
|
|
|
// Firefox or Thunderbird) like IA2 does. Thus let's return an application
|
|
|
|
// name as accessible name that was used to get a branding name (for example,
|
|
|
|
// Minefield aka nightly Firefox or Daily aka nightly Thunderbird).
|
2014-09-23 12:23:02 +00:00
|
|
|
AppName(aName);
|
2012-05-01 03:08:31 +00:00
|
|
|
return eNameOK;
|
2012-03-06 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
2014-10-22 00:49:28 +00:00
|
|
|
void
|
2012-04-25 11:29:40 +00:00
|
|
|
ApplicationAccessibleWrap::GetNativeInterface(void** aOutAccessible)
|
2003-05-06 02:23:50 +00:00
|
|
|
{
|
2014-10-22 00:49:28 +00:00
|
|
|
*aOutAccessible = nullptr;
|
2003-05-21 03:32:55 +00:00
|
|
|
|
2014-10-22 00:49:28 +00:00
|
|
|
if (!mAtkObject) {
|
|
|
|
mAtkObject =
|
|
|
|
reinterpret_cast<AtkObject*>(g_object_new(MAI_TYPE_ATK_OBJECT, nullptr));
|
|
|
|
if (!mAtkObject)
|
|
|
|
return;
|
2003-05-06 02:23:50 +00:00
|
|
|
|
2014-10-22 00:49:28 +00:00
|
|
|
atk_object_initialize(mAtkObject, this);
|
|
|
|
mAtkObject->role = ATK_ROLE_INVALID;
|
|
|
|
mAtkObject->layer = ATK_LAYER_INVALID;
|
|
|
|
}
|
2003-05-06 02:23:50 +00:00
|
|
|
|
2014-10-22 00:49:28 +00:00
|
|
|
*aOutAccessible = mAtkObject;
|
2003-05-06 02:23:50 +00:00
|
|
|
}
|
|
|
|
|
2010-01-06 06:56:56 +00:00
|
|
|
struct AtkRootAccessibleAddedEvent {
|
|
|
|
AtkObject *app_accessible;
|
|
|
|
AtkObject *root_accessible;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t index;
|
2010-01-06 06:56:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
gboolean fireRootAccessibleAddedCB(gpointer data)
|
|
|
|
{
|
|
|
|
AtkRootAccessibleAddedEvent* eventData = (AtkRootAccessibleAddedEvent*)data;
|
|
|
|
g_signal_emit_by_name(eventData->app_accessible, "children_changed::add",
|
2013-04-03 00:33:43 +00:00
|
|
|
eventData->index, eventData->root_accessible, nullptr);
|
2010-01-06 06:56:56 +00:00
|
|
|
g_object_unref(eventData->app_accessible);
|
|
|
|
g_object_unref(eventData->root_accessible);
|
|
|
|
free(data);
|
2011-07-14 01:58:32 +00:00
|
|
|
|
2010-01-06 06:56:56 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2013-03-14 04:53:28 +00:00
|
|
|
ApplicationAccessibleWrap::InsertChildAt(uint32_t aIdx, Accessible* aChild)
|
2003-04-23 05:28:41 +00:00
|
|
|
{
|
2013-03-14 04:53:28 +00:00
|
|
|
if (!ApplicationAccessible::InsertChildAt(aIdx, aChild))
|
2012-05-29 01:18:45 +00:00
|
|
|
return false;
|
2003-04-23 05:28:41 +00:00
|
|
|
|
2012-05-29 01:18:45 +00:00
|
|
|
AtkObject* atkAccessible = AccessibleWrap::GetAtkObject(aChild);
|
|
|
|
atk_object_set_parent(atkAccessible, mAtkObject);
|
2007-06-08 09:09:24 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = mChildren.Length();
|
2006-08-30 05:19:06 +00:00
|
|
|
|
2010-01-06 06:56:56 +00:00
|
|
|
// Emit children_changed::add in a timeout
|
|
|
|
// to make sure aRootAccWrap is fully initialized.
|
|
|
|
AtkRootAccessibleAddedEvent* eventData = (AtkRootAccessibleAddedEvent*)
|
|
|
|
malloc(sizeof(AtkRootAccessibleAddedEvent));
|
|
|
|
if (eventData) {
|
|
|
|
eventData->app_accessible = mAtkObject;
|
|
|
|
eventData->root_accessible = atkAccessible;
|
|
|
|
eventData->index = count -1;
|
|
|
|
g_object_ref(mAtkObject);
|
|
|
|
g_object_ref(atkAccessible);
|
|
|
|
g_timeout_add(0, fireRootAccessibleAddedCB, eventData);
|
2003-04-23 05:28:41 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2003-04-23 05:28:41 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-05-29 01:18:45 +00:00
|
|
|
ApplicationAccessibleWrap::RemoveChild(Accessible* aChild)
|
2003-04-23 05:28:41 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t index = aChild->IndexInParent();
|
2003-05-06 02:23:50 +00:00
|
|
|
|
2012-05-29 01:18:45 +00:00
|
|
|
AtkObject* atkAccessible = AccessibleWrap::GetAtkObject(aChild);
|
2013-04-03 00:33:43 +00:00
|
|
|
atk_object_set_parent(atkAccessible, nullptr);
|
2012-05-29 01:18:45 +00:00
|
|
|
g_signal_emit_by_name(mAtkObject, "children_changed::remove", index,
|
2013-04-03 00:33:43 +00:00
|
|
|
atkAccessible, nullptr);
|
2006-08-30 05:19:06 +00:00
|
|
|
|
2012-05-29 01:18:45 +00:00
|
|
|
return ApplicationAccessible::RemoveChild(aChild);
|
2003-04-23 05:28:41 +00:00
|
|
|
}
|
|
|
|
|