accessible/src/atk/ApplicationAccessibleWrap.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/src/atk/ApplicationAccessibleWrap.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,169 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "ApplicationAccessibleWrap.h"
    1.11 +
    1.12 +#include "nsCOMPtr.h"
    1.13 +#include "nsMai.h"
    1.14 +#include "nsAutoPtr.h"
    1.15 +#include "nsAccessibilityService.h"
    1.16 +
    1.17 +#include <gtk/gtk.h>
    1.18 +#include <atk/atk.h>
    1.19 +
    1.20 +using namespace mozilla;
    1.21 +using namespace mozilla::a11y;
    1.22 +
    1.23 +
    1.24 +// ApplicationAccessibleWrap
    1.25 +
    1.26 +ApplicationAccessibleWrap::ApplicationAccessibleWrap():
    1.27 +  ApplicationAccessible()
    1.28 +{
    1.29 +}
    1.30 +
    1.31 +ApplicationAccessibleWrap::~ApplicationAccessibleWrap()
    1.32 +{
    1.33 +  AccessibleWrap::ShutdownAtkObject();
    1.34 +}
    1.35 +
    1.36 +gboolean
    1.37 +toplevel_event_watcher(GSignalInvocationHint* ihint,
    1.38 +                       guint                  n_param_values,
    1.39 +                       const GValue*          param_values,
    1.40 +                       gpointer               data)
    1.41 +{
    1.42 +  static GQuark sQuark_gecko_acc_obj = 0;
    1.43 +
    1.44 +  if (!sQuark_gecko_acc_obj)
    1.45 +    sQuark_gecko_acc_obj = g_quark_from_static_string("GeckoAccObj");
    1.46 +
    1.47 +  if (nsAccessibilityService::IsShutdown())
    1.48 +    return TRUE;
    1.49 +
    1.50 +  GObject* object = reinterpret_cast<GObject*>(g_value_get_object(param_values));
    1.51 +  if (!GTK_IS_WINDOW(object))
    1.52 +    return TRUE;
    1.53 +
    1.54 +  AtkObject* child = gtk_widget_get_accessible(GTK_WIDGET(object));
    1.55 +
    1.56 +  // GTK native dialog
    1.57 +  if (!IS_MAI_OBJECT(child) &&
    1.58 +      (atk_object_get_role(child) == ATK_ROLE_DIALOG)) {
    1.59 +
    1.60 +    if (data == reinterpret_cast<gpointer>(nsIAccessibleEvent::EVENT_SHOW)) {
    1.61 +
    1.62 +      // Attach the dialog accessible to app accessible tree
    1.63 +      Accessible* windowAcc = GetAccService()->AddNativeRootAccessible(child);
    1.64 +      g_object_set_qdata(G_OBJECT(child), sQuark_gecko_acc_obj,
    1.65 +                         reinterpret_cast<gpointer>(windowAcc));
    1.66 +
    1.67 +    } else {
    1.68 +
    1.69 +      // Deattach the dialog accessible
    1.70 +      Accessible* windowAcc =
    1.71 +        reinterpret_cast<Accessible*>
    1.72 +                        (g_object_get_qdata(G_OBJECT(child), sQuark_gecko_acc_obj));
    1.73 +      if (windowAcc) {
    1.74 +        GetAccService()->RemoveNativeRootAccessible(windowAcc);
    1.75 +        g_object_set_qdata(G_OBJECT(child), sQuark_gecko_acc_obj, nullptr);
    1.76 +      }
    1.77 +
    1.78 +    }
    1.79 +  }
    1.80 +
    1.81 +  return TRUE;
    1.82 +}
    1.83 +
    1.84 +ENameValueFlag
    1.85 +ApplicationAccessibleWrap::Name(nsString& aName)
    1.86 +{
    1.87 +  // ATK doesn't provide a way to obtain an application name (for example,
    1.88 +  // Firefox or Thunderbird) like IA2 does. Thus let's return an application
    1.89 +  // name as accessible name that was used to get a branding name (for example,
    1.90 +  // Minefield aka nightly Firefox or Daily aka nightly Thunderbird).
    1.91 +  GetAppName(aName);
    1.92 +  return eNameOK;
    1.93 +}
    1.94 +
    1.95 +NS_IMETHODIMP
    1.96 +ApplicationAccessibleWrap::GetNativeInterface(void** aOutAccessible)
    1.97 +{
    1.98 +    *aOutAccessible = nullptr;
    1.99 +
   1.100 +    if (!mAtkObject) {
   1.101 +        mAtkObject =
   1.102 +            reinterpret_cast<AtkObject *>
   1.103 +                            (g_object_new(MAI_TYPE_ATK_OBJECT, nullptr));
   1.104 +        NS_ENSURE_TRUE(mAtkObject, NS_ERROR_OUT_OF_MEMORY);
   1.105 +
   1.106 +        atk_object_initialize(mAtkObject, this);
   1.107 +        mAtkObject->role = ATK_ROLE_INVALID;
   1.108 +        mAtkObject->layer = ATK_LAYER_INVALID;
   1.109 +    }
   1.110 +
   1.111 +    *aOutAccessible = mAtkObject;
   1.112 +    return NS_OK;
   1.113 +}
   1.114 +
   1.115 +struct AtkRootAccessibleAddedEvent {
   1.116 +  AtkObject *app_accessible;
   1.117 +  AtkObject *root_accessible;
   1.118 +  uint32_t index;
   1.119 +};
   1.120 +
   1.121 +gboolean fireRootAccessibleAddedCB(gpointer data)
   1.122 +{
   1.123 +    AtkRootAccessibleAddedEvent* eventData = (AtkRootAccessibleAddedEvent*)data;
   1.124 +    g_signal_emit_by_name(eventData->app_accessible, "children_changed::add",
   1.125 +                          eventData->index, eventData->root_accessible, nullptr);
   1.126 +    g_object_unref(eventData->app_accessible);
   1.127 +    g_object_unref(eventData->root_accessible);
   1.128 +    free(data);
   1.129 +
   1.130 +    return FALSE;
   1.131 +}
   1.132 +
   1.133 +bool
   1.134 +ApplicationAccessibleWrap::InsertChildAt(uint32_t aIdx, Accessible* aChild)
   1.135 +{
   1.136 +  if (!ApplicationAccessible::InsertChildAt(aIdx, aChild))
   1.137 +    return false;
   1.138 +
   1.139 +  AtkObject* atkAccessible = AccessibleWrap::GetAtkObject(aChild);
   1.140 +  atk_object_set_parent(atkAccessible, mAtkObject);
   1.141 +
   1.142 +    uint32_t count = mChildren.Length();
   1.143 +
   1.144 +    // Emit children_changed::add in a timeout
   1.145 +    // to make sure aRootAccWrap is fully initialized.
   1.146 +    AtkRootAccessibleAddedEvent* eventData = (AtkRootAccessibleAddedEvent*)
   1.147 +      malloc(sizeof(AtkRootAccessibleAddedEvent));
   1.148 +    if (eventData) {
   1.149 +      eventData->app_accessible = mAtkObject;
   1.150 +      eventData->root_accessible = atkAccessible;
   1.151 +      eventData->index = count -1;
   1.152 +      g_object_ref(mAtkObject);
   1.153 +      g_object_ref(atkAccessible);
   1.154 +      g_timeout_add(0, fireRootAccessibleAddedCB, eventData);
   1.155 +    }
   1.156 +
   1.157 +    return true;
   1.158 +}
   1.159 +
   1.160 +bool
   1.161 +ApplicationAccessibleWrap::RemoveChild(Accessible* aChild)
   1.162 +{
   1.163 +  int32_t index = aChild->IndexInParent();
   1.164 +
   1.165 +  AtkObject* atkAccessible = AccessibleWrap::GetAtkObject(aChild);
   1.166 +  atk_object_set_parent(atkAccessible, nullptr);
   1.167 +  g_signal_emit_by_name(mAtkObject, "children_changed::remove", index,
   1.168 +                        atkAccessible, nullptr);
   1.169 +
   1.170 +  return ApplicationAccessible::RemoveChild(aChild);
   1.171 +}
   1.172 +

mercurial