a11y: add a generic accessible
Using the same idea that shell-generic-container. It implements AtkValue with a dummy implementation based on signals. Javascript code would connect to that and returns the proper value. https://bugzilla.gnome.org/show_bug.cgi?id=648623
This commit is contained in:
parent
bd28d5c48a
commit
5c04840312
@ -52,6 +52,7 @@ st_source_h = \
|
||||
st/st-drawing-area.h \
|
||||
st/st-entry.h \
|
||||
st/st-focus-manager.h \
|
||||
st/st-generic-accessible.h \
|
||||
st/st-icon.h \
|
||||
st/st-icon-colors.h \
|
||||
st/st-im-text.h \
|
||||
@ -120,6 +121,7 @@ st_source_c = \
|
||||
st/st-drawing-area.c \
|
||||
st/st-entry.c \
|
||||
st/st-focus-manager.c \
|
||||
st/st-generic-accessible.c \
|
||||
st/st-icon.c \
|
||||
st/st-icon-colors.c \
|
||||
st/st-im-text.c \
|
||||
|
238
src/st/st-generic-accessible.c
Normal file
238
src/st/st-generic-accessible.c
Normal file
@ -0,0 +1,238 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||
/*
|
||||
* st-generic-accessible.c: generic accessible
|
||||
*
|
||||
* Copyright 2013 Igalia, S.L.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU Lesser General Public License,
|
||||
* version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* SECTION:st-generic-accessible
|
||||
* @short_description: An accessible class with signals for
|
||||
* implementing specific Atk interfaces
|
||||
*
|
||||
* #StGenericAccessible is mainly a workaround for the current lack of
|
||||
* of a proper support for GValue at javascript. See bug#703412 for
|
||||
* more information. We implement the accessible interfaces, but proxy
|
||||
* the virtual functions into signals, which gjs can catch.
|
||||
*
|
||||
* #StGenericAccessible is an #StWidgetAccessible
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "st-generic-accessible.h"
|
||||
|
||||
static void atk_value_iface_init (AtkValueIface *iface);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE(StGenericAccessible,
|
||||
st_generic_accessible,
|
||||
ST_TYPE_WIDGET_ACCESSIBLE,
|
||||
G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE,
|
||||
atk_value_iface_init));
|
||||
/* Signals */
|
||||
enum
|
||||
{
|
||||
GET_CURRENT_VALUE,
|
||||
GET_MAXIMUM_VALUE,
|
||||
GET_MINIMUM_VALUE,
|
||||
SET_CURRENT_VALUE,
|
||||
GET_MINIMUM_INCREMENT,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint st_generic_accessible_signals [LAST_SIGNAL] = { 0 };
|
||||
|
||||
static void
|
||||
st_generic_accessible_init (StGenericAccessible *accessible)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
st_generic_accessible_class_init (StGenericAccessibleClass *klass)
|
||||
{
|
||||
/**
|
||||
* StGenericAccessible::get-current-value:
|
||||
* @self: the #StGenericAccessible
|
||||
*
|
||||
* Emitted when atk_value_get_current_value() is called on
|
||||
* @self. Right now we only care about doubles, so the value is
|
||||
* directly returned by the signal.
|
||||
*
|
||||
* Return value: value of the current element.
|
||||
*/
|
||||
st_generic_accessible_signals[GET_CURRENT_VALUE] =
|
||||
g_signal_new ("get-current-value",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_DOUBLE, 0);
|
||||
|
||||
/**
|
||||
* StGenericAccessible::get-maximum-value:
|
||||
* @self: the #StGenericAccessible
|
||||
*
|
||||
* Emitted when atk_value_get_maximum_value() is called on
|
||||
* @self. Right now we only care about doubles, so the value is
|
||||
* directly returned by the signal.
|
||||
*
|
||||
* Return value: maximum value of the accessible.
|
||||
*/
|
||||
st_generic_accessible_signals[GET_MAXIMUM_VALUE] =
|
||||
g_signal_new ("get-maximum-value",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_DOUBLE, 0);
|
||||
|
||||
/**
|
||||
* StGenericAccessible::get-minimum-value:
|
||||
* @self: the #StGenericAccessible
|
||||
*
|
||||
* Emitted when atk_value_get_current_value() is called on
|
||||
* @self. Right now we only care about doubles, so the value is
|
||||
* directly returned by the signal.
|
||||
*
|
||||
* Return value: minimum value of the accessible.
|
||||
*/
|
||||
st_generic_accessible_signals[GET_MINIMUM_VALUE] =
|
||||
g_signal_new ("get-minimum-value",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_DOUBLE, 0);
|
||||
|
||||
/**
|
||||
* StGenericAccessible::get-minimum-increment:
|
||||
* @self: the #StGenericAccessible
|
||||
*
|
||||
* Emitted when atk_value_get_minimum_increment() is called on
|
||||
* @self. Right now we only care about doubles, so the value is
|
||||
* directly returned by the signal.
|
||||
*
|
||||
* Return value: value of the current element.
|
||||
*/
|
||||
st_generic_accessible_signals[GET_MINIMUM_INCREMENT] =
|
||||
g_signal_new ("get-minimum-increment",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_DOUBLE, 0);
|
||||
|
||||
/**
|
||||
* StGenericAccessible::set-current-value:
|
||||
* @self: the #StGenericAccessible
|
||||
* @new_value: the new value for the accessible
|
||||
*
|
||||
* Emitted when atk_value_set_current_value() is called on
|
||||
* @self. Right now we only care about doubles, so the value is
|
||||
* directly returned by the signal.
|
||||
*
|
||||
* Return value: value of the current element.
|
||||
*/
|
||||
st_generic_accessible_signals[SET_CURRENT_VALUE] =
|
||||
g_signal_new ("set-current-value",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 1, G_TYPE_DOUBLE);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
st_generic_accessible_get_current_value (AtkValue *obj,
|
||||
GValue *value)
|
||||
{
|
||||
gdouble current_value = 0;
|
||||
|
||||
g_value_init (value, G_TYPE_DOUBLE);
|
||||
g_signal_emit (G_OBJECT (obj), st_generic_accessible_signals[GET_CURRENT_VALUE], 0, ¤t_value);
|
||||
g_value_set_double (value, current_value);
|
||||
}
|
||||
|
||||
static void
|
||||
st_generic_accessible_get_maximum_value (AtkValue *obj,
|
||||
GValue *value)
|
||||
{
|
||||
gdouble current_value = 0;
|
||||
|
||||
g_value_init (value, G_TYPE_DOUBLE);
|
||||
g_signal_emit (G_OBJECT (obj), st_generic_accessible_signals[GET_MAXIMUM_VALUE], 0, ¤t_value);
|
||||
g_value_set_double (value, current_value);
|
||||
}
|
||||
|
||||
static void
|
||||
st_generic_accessible_get_minimum_value (AtkValue *obj,
|
||||
GValue *value)
|
||||
{
|
||||
gdouble current_value = 0;
|
||||
|
||||
g_value_init (value, G_TYPE_DOUBLE);
|
||||
g_signal_emit (G_OBJECT (obj), st_generic_accessible_signals[GET_MINIMUM_VALUE], 0, ¤t_value);
|
||||
g_value_set_double (value, current_value);
|
||||
}
|
||||
|
||||
static void
|
||||
st_generic_accessible_get_minimum_increment (AtkValue *obj,
|
||||
GValue *value)
|
||||
{
|
||||
gdouble current_value = 0;
|
||||
|
||||
g_value_init (value, G_TYPE_DOUBLE);
|
||||
g_signal_emit (G_OBJECT (obj), st_generic_accessible_signals[GET_MINIMUM_INCREMENT], 0, ¤t_value);
|
||||
g_value_set_double (value, current_value);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
st_generic_accessible_set_current_value (AtkValue *obj,
|
||||
const GValue *value)
|
||||
{
|
||||
gdouble current_value = 0;
|
||||
|
||||
current_value = g_value_get_double (value);
|
||||
g_signal_emit (G_OBJECT (obj), st_generic_accessible_signals[SET_CURRENT_VALUE], 0, current_value);
|
||||
|
||||
return TRUE; // we assume that the value was properly set
|
||||
}
|
||||
|
||||
static void
|
||||
atk_value_iface_init (AtkValueIface *iface)
|
||||
{
|
||||
iface->get_current_value = st_generic_accessible_get_current_value;
|
||||
iface->get_maximum_value = st_generic_accessible_get_maximum_value;
|
||||
iface->get_minimum_value = st_generic_accessible_get_minimum_value;
|
||||
iface->get_minimum_increment = st_generic_accessible_get_minimum_increment;
|
||||
iface->set_current_value = st_generic_accessible_set_current_value;
|
||||
}
|
||||
|
||||
AtkObject*
|
||||
st_generic_accessible_new_for_actor (ClutterActor *actor)
|
||||
{
|
||||
AtkObject *accessible = NULL;
|
||||
|
||||
g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), NULL);
|
||||
|
||||
accessible = ATK_OBJECT (g_object_new (ST_TYPE_GENERIC_ACCESSIBLE,
|
||||
NULL));
|
||||
atk_object_initialize (accessible, actor);
|
||||
|
||||
return accessible;
|
||||
}
|
62
src/st/st-generic-accessible.h
Normal file
62
src/st/st-generic-accessible.h
Normal file
@ -0,0 +1,62 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||
/*
|
||||
* st-generic-accessible.h: generic accessible
|
||||
*
|
||||
* Copyright 2013 Igalia, S.L.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU Lesser General Public License,
|
||||
* version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if !defined(ST_H_INSIDE) && !defined(ST_COMPILATION)
|
||||
#error "Only <st/st.h> can be included directly.h"
|
||||
#endif
|
||||
|
||||
#ifndef __ST_GENERIC_ACCESSIBLE_H__
|
||||
#define __ST_GENERIC_ACCESSIBLE_H__
|
||||
|
||||
#include <clutter/clutter.h>
|
||||
#include <st/st-widget-accessible.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define ST_TYPE_GENERIC_ACCESSIBLE (st_generic_accessible_get_type ())
|
||||
#define ST_GENERIC_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ST_TYPE_GENERIC_ACCESSIBLE, StGenericAccessible))
|
||||
#define ST_GENERIC_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ST_TYPE_GENERIC_ACCESSIBLE, StGenericAccessibleClass))
|
||||
#define ST_IS_GENERIC_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ST_TYPE_GENERIC_ACCESSIBLE))
|
||||
#define ST_IS_GENERIC_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ST_TYPE_GENERIC_ACCESSIBLE))
|
||||
#define ST_GENERIC_ACCESSIBLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ST_TYPE_GENERIC_ACCESSIBLE, StGenericAccessibleClass))
|
||||
|
||||
typedef struct _StGenericAccessible StGenericAccessible;
|
||||
typedef struct _StGenericAccessibleClass StGenericAccessibleClass;
|
||||
|
||||
typedef struct _StGenericAccessiblePrivate StGenericAccessiblePrivate;
|
||||
|
||||
struct _StGenericAccessible
|
||||
{
|
||||
StWidgetAccessible parent;
|
||||
|
||||
StGenericAccessiblePrivate *priv;
|
||||
};
|
||||
|
||||
struct _StGenericAccessibleClass
|
||||
{
|
||||
StWidgetAccessibleClass parent_class;
|
||||
};
|
||||
|
||||
GType st_generic_accessible_get_type (void) G_GNUC_CONST;
|
||||
|
||||
AtkObject* st_generic_accessible_new_for_actor (ClutterActor *actor);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __ST_GENERIC_ACCESSIBLE_H__ */
|
Loading…
x
Reference in New Issue
Block a user