mirror of
https://github.com/brl/mutter.git
synced 2024-11-29 19:40:43 -05:00
a11y: get_default_attributes implementation on cally-text
See http://bugzilla.clutter-project.org/show_bug.cgi?id=1733
This commit is contained in:
parent
6812ed7d3a
commit
ae0aa9e4cf
@ -133,6 +133,7 @@ static AtkAttributeSet* cally_text_get_run_attributes (AtkText *text,
|
|||||||
gint offset,
|
gint offset,
|
||||||
gint *start_offset,
|
gint *start_offset,
|
||||||
gint *end_offset);
|
gint *end_offset);
|
||||||
|
static AtkAttributeSet* cally_text_get_default_attributes (AtkText *text);
|
||||||
static void _cally_text_get_selection_bounds (ClutterText *clutter_text,
|
static void _cally_text_get_selection_bounds (ClutterText *clutter_text,
|
||||||
gint *start_offset,
|
gint *start_offset,
|
||||||
gint *end_offset);
|
gint *end_offset);
|
||||||
@ -179,6 +180,9 @@ static AtkAttributeSet* _cally_misc_layout_get_run_attributes (AtkAttributeS
|
|||||||
gint *start_offset,
|
gint *start_offset,
|
||||||
gint *end_offset);
|
gint *end_offset);
|
||||||
|
|
||||||
|
static AtkAttributeSet* _cally_misc_layout_get_default_attributes (AtkAttributeSet *attrib_set,
|
||||||
|
ClutterText *text);
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_CODE (CallyText,
|
G_DEFINE_TYPE_WITH_CODE (CallyText,
|
||||||
cally_text,
|
cally_text,
|
||||||
CALLY_TYPE_ACTOR,
|
CALLY_TYPE_ACTOR,
|
||||||
@ -393,7 +397,7 @@ cally_text_text_interface_init (AtkTextIface *iface)
|
|||||||
iface->remove_selection = cally_text_remove_selection;
|
iface->remove_selection = cally_text_remove_selection;
|
||||||
iface->set_selection = cally_text_set_selection;
|
iface->set_selection = cally_text_set_selection;
|
||||||
iface->get_run_attributes = cally_text_get_run_attributes;
|
iface->get_run_attributes = cally_text_get_run_attributes;
|
||||||
/* iface->get_default_attributes = cally_text_get_default_attributes; */
|
iface->get_default_attributes = cally_text_get_default_attributes;
|
||||||
/* iface->get_character_extents = */
|
/* iface->get_character_extents = */
|
||||||
/* iface->get_offset_at_point = */
|
/* iface->get_offset_at_point = */
|
||||||
|
|
||||||
@ -757,6 +761,24 @@ cally_text_get_run_attributes (AtkText *text,
|
|||||||
return at_set;
|
return at_set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static AtkAttributeSet*
|
||||||
|
cally_text_get_default_attributes (AtkText *text)
|
||||||
|
{
|
||||||
|
ClutterActor *actor = NULL;
|
||||||
|
ClutterText *clutter_text = NULL;
|
||||||
|
AtkAttributeSet *at_set = NULL;
|
||||||
|
|
||||||
|
actor = CALLY_GET_CLUTTER_ACTOR (text);
|
||||||
|
if (actor == NULL) /* State is defunct */
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
clutter_text = CLUTTER_TEXT (actor);
|
||||||
|
|
||||||
|
at_set = _cally_misc_layout_get_default_attributes (at_set, clutter_text);
|
||||||
|
|
||||||
|
return at_set;
|
||||||
|
}
|
||||||
|
|
||||||
/******** Auxiliar private methods ******/
|
/******** Auxiliar private methods ******/
|
||||||
|
|
||||||
/* ClutterText only maintains the current cursor position and a extra selection
|
/* ClutterText only maintains the current cursor position and a extra selection
|
||||||
@ -1341,3 +1363,180 @@ _cally_misc_layout_get_run_attributes (AtkAttributeSet *attrib_set,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _cally_misc_layout_get_default_attributes:
|
||||||
|
*
|
||||||
|
* Reimplementation of gail_misc_layout_get_default_attributes (check this
|
||||||
|
* function for more documentation).
|
||||||
|
*
|
||||||
|
* Returns: A pointer to the #AtkAttributeSet.
|
||||||
|
**/
|
||||||
|
static AtkAttributeSet*
|
||||||
|
_cally_misc_layout_get_default_attributes (AtkAttributeSet *attrib_set,
|
||||||
|
ClutterText *clutter_text)
|
||||||
|
{
|
||||||
|
PangoLayout *layout;
|
||||||
|
PangoContext *context;
|
||||||
|
PangoLanguage* language;
|
||||||
|
PangoFontDescription* font;
|
||||||
|
PangoWrapMode mode;
|
||||||
|
gchar *value = NULL;
|
||||||
|
gint int_value;
|
||||||
|
ClutterTextDirection text_direction;
|
||||||
|
PangoAttrIterator *iter;
|
||||||
|
PangoAttrList *attr;
|
||||||
|
|
||||||
|
text_direction = clutter_actor_get_text_direction (CLUTTER_ACTOR (clutter_text));
|
||||||
|
switch (text_direction)
|
||||||
|
{
|
||||||
|
case CLUTTER_TEXT_DIRECTION_DEFAULT:
|
||||||
|
value = g_strdup ("none");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CLUTTER_TEXT_DIRECTION_LTR:
|
||||||
|
value = g_strdup ("ltr");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CLUTTER_TEXT_DIRECTION_RTL:
|
||||||
|
value = g_strdup ("rtl");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
value = g_strdup ("none");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
attrib_set = _cally_misc_add_attribute (attrib_set,
|
||||||
|
ATK_TEXT_ATTR_DIRECTION,
|
||||||
|
value);
|
||||||
|
|
||||||
|
layout = clutter_text_get_layout (clutter_text);
|
||||||
|
context = pango_layout_get_context (layout);
|
||||||
|
if (context)
|
||||||
|
{
|
||||||
|
if ((language = pango_context_get_language (context)))
|
||||||
|
{
|
||||||
|
value = g_strdup (pango_language_to_string (language));
|
||||||
|
attrib_set = _cally_misc_add_attribute (attrib_set,
|
||||||
|
ATK_TEXT_ATTR_LANGUAGE, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((font = pango_context_get_font_description (context)))
|
||||||
|
{
|
||||||
|
value = g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_STYLE,
|
||||||
|
pango_font_description_get_style (font)));
|
||||||
|
attrib_set = _cally_misc_add_attribute (attrib_set,
|
||||||
|
ATK_TEXT_ATTR_STYLE,
|
||||||
|
value);
|
||||||
|
|
||||||
|
value = g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_VARIANT,
|
||||||
|
pango_font_description_get_variant (font)));
|
||||||
|
attrib_set = _cally_misc_add_attribute (attrib_set,
|
||||||
|
ATK_TEXT_ATTR_VARIANT, value);
|
||||||
|
|
||||||
|
value = g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_STRETCH,
|
||||||
|
pango_font_description_get_stretch (font)));
|
||||||
|
attrib_set = _cally_misc_add_attribute (attrib_set,
|
||||||
|
ATK_TEXT_ATTR_STRETCH, value);
|
||||||
|
|
||||||
|
value = g_strdup (pango_font_description_get_family (font));
|
||||||
|
attrib_set = _cally_misc_add_attribute (attrib_set,
|
||||||
|
ATK_TEXT_ATTR_FAMILY_NAME, value);
|
||||||
|
value = g_strdup_printf ("%d", pango_font_description_get_weight (font));
|
||||||
|
attrib_set = _cally_misc_add_attribute (attrib_set,
|
||||||
|
ATK_TEXT_ATTR_WEIGHT, value);
|
||||||
|
|
||||||
|
value = g_strdup_printf ("%i", pango_font_description_get_size (font) / PANGO_SCALE);
|
||||||
|
attrib_set = _cally_misc_add_attribute (attrib_set,
|
||||||
|
ATK_TEXT_ATTR_SIZE, value);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pango_layout_get_justify (layout))
|
||||||
|
int_value = 3;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PangoAlignment align;
|
||||||
|
|
||||||
|
align = pango_layout_get_alignment (layout);
|
||||||
|
if (align == PANGO_ALIGN_LEFT)
|
||||||
|
int_value = 0;
|
||||||
|
else if (align == PANGO_ALIGN_CENTER)
|
||||||
|
int_value = 2;
|
||||||
|
else /* if (align == PANGO_ALIGN_RIGHT) */
|
||||||
|
int_value = 1;
|
||||||
|
}
|
||||||
|
value = g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_JUSTIFICATION,
|
||||||
|
int_value));
|
||||||
|
attrib_set = _cally_misc_add_attribute (attrib_set,
|
||||||
|
ATK_TEXT_ATTR_JUSTIFICATION,
|
||||||
|
value);
|
||||||
|
|
||||||
|
mode = pango_layout_get_wrap (layout);
|
||||||
|
if (mode == PANGO_WRAP_WORD)
|
||||||
|
int_value = 2;
|
||||||
|
else /* if (mode == PANGO_WRAP_CHAR) */
|
||||||
|
int_value = 1;
|
||||||
|
value = g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_WRAP_MODE,
|
||||||
|
int_value));
|
||||||
|
attrib_set = _cally_misc_add_attribute (attrib_set,
|
||||||
|
ATK_TEXT_ATTR_WRAP_MODE, value);
|
||||||
|
|
||||||
|
if ((attr = clutter_text_get_attributes (clutter_text)))
|
||||||
|
{
|
||||||
|
iter = pango_attr_list_get_iterator (attr);
|
||||||
|
/* Get attributes */
|
||||||
|
attrib_set = _cally_misc_layout_atk_attributes_from_pango (attrib_set, iter);
|
||||||
|
pango_attr_iterator_destroy (iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!_cally_misc_find_atk_attribute (attrib_set, ATK_TEXT_ATTR_FG_COLOR))
|
||||||
|
attrib_set = _cally_misc_add_actor_color_to_attribute_set (attrib_set,
|
||||||
|
clutter_text);
|
||||||
|
|
||||||
|
value = g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_FG_STIPPLE, 0));
|
||||||
|
attrib_set = _cally_misc_add_attribute (attrib_set,
|
||||||
|
ATK_TEXT_ATTR_FG_STIPPLE,
|
||||||
|
value);
|
||||||
|
|
||||||
|
value = g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_BG_STIPPLE, 0));
|
||||||
|
attrib_set = _cally_misc_add_attribute (attrib_set,
|
||||||
|
ATK_TEXT_ATTR_BG_STIPPLE,
|
||||||
|
value);
|
||||||
|
attrib_set = _cally_misc_add_attribute (attrib_set,
|
||||||
|
ATK_TEXT_ATTR_BG_FULL_HEIGHT,
|
||||||
|
g_strdup_printf ("%i", 0));
|
||||||
|
attrib_set = _cally_misc_add_attribute (attrib_set,
|
||||||
|
ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP,
|
||||||
|
g_strdup_printf ("%i", 0));
|
||||||
|
attrib_set = _cally_misc_add_attribute (attrib_set,
|
||||||
|
ATK_TEXT_ATTR_PIXELS_BELOW_LINES,
|
||||||
|
g_strdup_printf ("%i", 0));
|
||||||
|
attrib_set = _cally_misc_add_attribute (attrib_set,
|
||||||
|
ATK_TEXT_ATTR_PIXELS_ABOVE_LINES,
|
||||||
|
g_strdup_printf ("%i", 0));
|
||||||
|
value = g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_EDITABLE,
|
||||||
|
clutter_text_get_editable (clutter_text)));
|
||||||
|
attrib_set = _cally_misc_add_attribute (attrib_set,
|
||||||
|
ATK_TEXT_ATTR_EDITABLE,
|
||||||
|
value);
|
||||||
|
|
||||||
|
value = g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_INVISIBLE,
|
||||||
|
!CLUTTER_ACTOR_IS_VISIBLE (clutter_text)));
|
||||||
|
attrib_set = _cally_misc_add_attribute (attrib_set,
|
||||||
|
ATK_TEXT_ATTR_INVISIBLE, value);
|
||||||
|
|
||||||
|
value = g_strdup_printf ("%i", pango_layout_get_indent (layout));
|
||||||
|
attrib_set = _cally_misc_add_attribute (attrib_set,
|
||||||
|
ATK_TEXT_ATTR_INDENT, value);
|
||||||
|
attrib_set = _cally_misc_add_attribute (attrib_set,
|
||||||
|
ATK_TEXT_ATTR_RIGHT_MARGIN,
|
||||||
|
g_strdup_printf ("%i", 0));
|
||||||
|
attrib_set = _cally_misc_add_attribute (attrib_set,
|
||||||
|
ATK_TEXT_ATTR_LEFT_MARGIN,
|
||||||
|
g_strdup_printf ("%i", 0));
|
||||||
|
|
||||||
|
return attrib_set;
|
||||||
|
}
|
||||||
|
@ -126,6 +126,32 @@ test_atk_text (ClutterActor *actor)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
dump_actor_default_atk_attributes (ClutterActor *actor)
|
||||||
|
{
|
||||||
|
AtkObject *object = NULL;
|
||||||
|
AtkText *cally_text = NULL;
|
||||||
|
AtkAttributeSet *at_set = NULL;
|
||||||
|
GSList *attrs;
|
||||||
|
const gchar *text_value = NULL;
|
||||||
|
|
||||||
|
object = atk_gobject_accessible_for_object (G_OBJECT (actor));
|
||||||
|
cally_text = ATK_TEXT (object);
|
||||||
|
|
||||||
|
if (!cally_text)
|
||||||
|
return;
|
||||||
|
|
||||||
|
text_value = clutter_text_get_text (CLUTTER_TEXT (actor));
|
||||||
|
g_print ("text value = %s\n", text_value);
|
||||||
|
|
||||||
|
at_set = atk_text_get_default_attributes (cally_text);
|
||||||
|
attrs = (GSList*) at_set;
|
||||||
|
while (attrs) {
|
||||||
|
AtkAttribute *at = (AtkAttribute *) attrs->data;
|
||||||
|
g_print ("text default %s = %s\n", at->name, at->value);
|
||||||
|
attrs = g_slist_next (attrs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
button_press_cb (ClutterActor *actor,
|
button_press_cb (ClutterActor *actor,
|
||||||
@ -155,9 +181,12 @@ make_ui (ClutterActor *stage)
|
|||||||
|
|
||||||
/* text */
|
/* text */
|
||||||
text_actor = clutter_text_new_full ("Sans Bold 32px",
|
text_actor = clutter_text_new_full ("Sans Bold 32px",
|
||||||
"Lorem ipsum dolor sit amet",
|
"",
|
||||||
&color_text);
|
&color_text);
|
||||||
|
clutter_text_set_markup (CLUTTER_TEXT(text_actor),
|
||||||
|
"<span fgcolor=\"#FFFF00\" bgcolor=\"#00FF00\"><s>Lorem ipsum dolor sit amet</s></span>");
|
||||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text_actor);
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text_actor);
|
||||||
|
dump_actor_default_atk_attributes (text_actor);
|
||||||
|
|
||||||
/* text_editable */
|
/* text_editable */
|
||||||
text_editable_actor = clutter_text_new_full ("Sans Bold 32px",
|
text_editable_actor = clutter_text_new_full ("Sans Bold 32px",
|
||||||
@ -171,6 +200,7 @@ make_ui (ClutterActor *stage)
|
|||||||
clutter_text_set_line_wrap (CLUTTER_TEXT (text_editable_actor), TRUE);
|
clutter_text_set_line_wrap (CLUTTER_TEXT (text_editable_actor), TRUE);
|
||||||
clutter_actor_grab_key_focus (text_editable_actor);
|
clutter_actor_grab_key_focus (text_editable_actor);
|
||||||
clutter_actor_set_reactive (text_editable_actor, TRUE);
|
clutter_actor_set_reactive (text_editable_actor, TRUE);
|
||||||
|
dump_actor_default_atk_attributes (text_editable_actor);
|
||||||
|
|
||||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text_editable_actor);
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text_editable_actor);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user