2011-04-27 06:42:27 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2011-05-27 15:37:24 -07:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-04-25 04:29:40 -07:00
|
|
|
#include "ApplicationAccessibleWrap.h"
|
2009-08-21 05:33:31 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsMai.h"
|
2007-06-01 20:01:38 -07:00
|
|
|
#include "nsAutoPtr.h"
|
2009-08-11 00:03:01 -07:00
|
|
|
#include "nsAccessibilityService.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <atk/atk.h>
|
|
|
|
|
2011-11-26 11:48:55 -08:00
|
|
|
using namespace mozilla;
|
2012-01-04 17:54:17 -08:00
|
|
|
using namespace mozilla::a11y;
|
2011-11-26 11:48:55 -08:00
|
|
|
|
2012-11-20 07:33:30 -08:00
|
|
|
|
2012-04-25 04:29:40 -07:00
|
|
|
// ApplicationAccessibleWrap
|
2007-06-01 20:01:38 -07:00
|
|
|
|
2012-04-25 04:29:40 -07:00
|
|
|
ApplicationAccessibleWrap::ApplicationAccessibleWrap():
|
|
|
|
ApplicationAccessible()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-04-25 04:29:40 -07:00
|
|
|
ApplicationAccessibleWrap::~ApplicationAccessibleWrap()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap::ShutdownAtkObject();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-01 16:58:25 -08:00
|
|
|
gboolean
|
2011-07-13 18:58:32 -07:00
|
|
|
toplevel_event_watcher(GSignalInvocationHint* ihint,
|
|
|
|
guint n_param_values,
|
|
|
|
const GValue* param_values,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2011-07-21 14:31:36 -07: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-13 18:58:32 -07: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-28 18:18:45 -07:00
|
|
|
Accessible* windowAcc = GetAccService()->AddNativeRootAccessible(child);
|
2011-07-13 18:58:32 -07:00
|
|
|
g_object_set_qdata(G_OBJECT(child), sQuark_gecko_acc_obj,
|
|
|
|
reinterpret_cast<gpointer>(windowAcc));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Deattach the dialog accessible
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* windowAcc =
|
|
|
|
reinterpret_cast<Accessible*>
|
2011-07-13 18:58:32 -07:00
|
|
|
(g_object_get_qdata(G_OBJECT(child), sQuark_gecko_acc_obj));
|
|
|
|
if (windowAcc) {
|
|
|
|
GetAccService()->RemoveNativeRootAccessible(windowAcc);
|
2013-04-02 17:33:43 -07:00
|
|
|
g_object_set_qdata(G_OBJECT(child), sQuark_gecko_acc_obj, nullptr);
|
2011-07-13 18:58:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-04-30 20:08:31 -07:00
|
|
|
ENameValueFlag
|
|
|
|
ApplicationAccessibleWrap::Name(nsString& aName)
|
2012-03-06 02:01:55 -08: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 05:23:02 -07:00
|
|
|
AppName(aName);
|
2012-04-30 20:08:31 -07:00
|
|
|
return eNameOK;
|
2012-03-06 02:01:55 -08:00
|
|
|
}
|
|
|
|
|
2014-10-21 17:49:28 -07:00
|
|
|
void
|
2012-04-25 04:29:40 -07:00
|
|
|
ApplicationAccessibleWrap::GetNativeInterface(void** aOutAccessible)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-10-21 17:49:28 -07:00
|
|
|
*aOutAccessible = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-10-21 17:49:28 -07:00
|
|
|
if (!mAtkObject) {
|
|
|
|
mAtkObject =
|
|
|
|
reinterpret_cast<AtkObject*>(g_object_new(MAI_TYPE_ATK_OBJECT, nullptr));
|
|
|
|
if (!mAtkObject)
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-10-21 17:49:28 -07:00
|
|
|
atk_object_initialize(mAtkObject, this);
|
|
|
|
mAtkObject->role = ATK_ROLE_INVALID;
|
|
|
|
mAtkObject->layer = ATK_LAYER_INVALID;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-10-21 17:49:28 -07:00
|
|
|
*aOutAccessible = mAtkObject;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-01-05 22:56:56 -08:00
|
|
|
struct AtkRootAccessibleAddedEvent {
|
|
|
|
AtkObject *app_accessible;
|
|
|
|
AtkObject *root_accessible;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t index;
|
2010-01-05 22:56:56 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
gboolean fireRootAccessibleAddedCB(gpointer data)
|
|
|
|
{
|
|
|
|
AtkRootAccessibleAddedEvent* eventData = (AtkRootAccessibleAddedEvent*)data;
|
|
|
|
g_signal_emit_by_name(eventData->app_accessible, "children_changed::add",
|
2013-04-02 17:33:43 -07:00
|
|
|
eventData->index, eventData->root_accessible, nullptr);
|
2010-01-05 22:56:56 -08:00
|
|
|
g_object_unref(eventData->app_accessible);
|
|
|
|
g_object_unref(eventData->root_accessible);
|
|
|
|
free(data);
|
2011-07-13 18:58:32 -07:00
|
|
|
|
2010-01-05 22:56:56 -08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-03-13 21:53:28 -07:00
|
|
|
ApplicationAccessibleWrap::InsertChildAt(uint32_t aIdx, Accessible* aChild)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-13 21:53:28 -07:00
|
|
|
if (!ApplicationAccessible::InsertChildAt(aIdx, aChild))
|
2012-05-28 18:18:45 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
AtkObject* atkAccessible = AccessibleWrap::GetAtkObject(aChild);
|
|
|
|
atk_object_set_parent(atkAccessible, mAtkObject);
|
2007-06-08 02:09:24 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t count = mChildren.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-05 22:56:56 -08: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);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
ApplicationAccessibleWrap::RemoveChild(Accessible* aChild)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t index = aChild->IndexInParent();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
AtkObject* atkAccessible = AccessibleWrap::GetAtkObject(aChild);
|
2013-04-02 17:33:43 -07:00
|
|
|
atk_object_set_parent(atkAccessible, nullptr);
|
2012-05-28 18:18:45 -07:00
|
|
|
g_signal_emit_by_name(mAtkObject, "children_changed::remove", index,
|
2013-04-02 17:33:43 -07:00
|
|
|
atkAccessible, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
return ApplicationAccessible::RemoveChild(aChild);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|