A11y: Fix text functions for table cells

Keep the PangoLayout around, and refresh in update_cache.

https://bugzilla.gnome.org/show_bug.cgi?id=707729
This commit is contained in:
Mike Gorse 2014-01-07 15:06:13 -06:00 committed by Matthias Clasen
parent 197785744b
commit e529dfe949

View File

@ -28,6 +28,7 @@ struct _GtkTextCellAccessiblePrivate
gchar *cell_text; gchar *cell_text;
gint caret_pos; gint caret_pos;
gint cell_length; gint cell_length;
PangoLayout *layout;
}; };
static const gchar* gtk_text_cell_accessible_get_name (AtkObject *atk_obj); static const gchar* gtk_text_cell_accessible_get_name (AtkObject *atk_obj);
@ -112,6 +113,9 @@ gtk_text_cell_accessible_finalize (GObject *object)
g_free (text_cell->priv->cell_text); g_free (text_cell->priv->cell_text);
if (text_cell->priv->layout)
g_object_unref (text_cell->priv->layout);
G_OBJECT_CLASS (gtk_text_cell_accessible_parent_class)->finalize (object); G_OBJECT_CLASS (gtk_text_cell_accessible_parent_class)->finalize (object);
} }
@ -136,6 +140,10 @@ gtk_text_cell_accessible_update_cache (GtkCellAccessible *cell)
gchar *text; gchar *text;
GtkCellRenderer *renderer; GtkCellRenderer *renderer;
if (text_cell->priv->layout)
g_object_unref (text_cell->priv->layout);
text_cell->priv->layout = create_pango_layout (text_cell);
g_object_get (cell, "renderer", &renderer, NULL); g_object_get (cell, "renderer", &renderer, NULL);
g_object_get (renderer, "text", &text, NULL); g_object_get (renderer, "text", &text, NULL);
g_object_unref (renderer); g_object_unref (renderer);
@ -226,12 +234,10 @@ gtk_text_cell_accessible_get_text_before_offset (AtkText *atk_text,
gint *start_offset, gint *start_offset,
gint *end_offset) gint *end_offset)
{ {
PangoLayout *layout; GtkTextCellAccessible *text_cell = GTK_TEXT_CELL_ACCESSIBLE (atk_text);
gchar *text; gchar *text;
layout = create_pango_layout (GTK_TEXT_CELL_ACCESSIBLE (atk_text)); text = _gtk_pango_get_text_before (text_cell->priv->layout, boundary_type, offset, start_offset, end_offset);
text = _gtk_pango_get_text_before (layout, boundary_type, offset, start_offset, end_offset);
g_object_unref (layout);
return text; return text;
} }
@ -243,12 +249,10 @@ gtk_text_cell_accessible_get_text_at_offset (AtkText *atk_text,
gint *start_offset, gint *start_offset,
gint *end_offset) gint *end_offset)
{ {
PangoLayout *layout; GtkTextCellAccessible *text_cell = GTK_TEXT_CELL_ACCESSIBLE (atk_text);
gchar *text; gchar *text;
layout = create_pango_layout (GTK_TEXT_CELL_ACCESSIBLE (atk_text)); text = _gtk_pango_get_text_at (text_cell->priv->layout, boundary_type, offset, start_offset, end_offset);
text = _gtk_pango_get_text_at (layout, boundary_type, offset, start_offset, end_offset);
g_object_unref (layout);
return text; return text;
} }
@ -260,12 +264,10 @@ gtk_text_cell_accessible_get_text_after_offset (AtkText *atk_text,
gint *start_offset, gint *start_offset,
gint *end_offset) gint *end_offset)
{ {
PangoLayout *layout; GtkTextCellAccessible *text_cell = GTK_TEXT_CELL_ACCESSIBLE (atk_text);
gchar *text; gchar *text;
layout = create_pango_layout (GTK_TEXT_CELL_ACCESSIBLE (atk_text)); text = _gtk_pango_get_text_after (text_cell->priv->layout, boundary_type, offset, start_offset, end_offset);
text = _gtk_pango_get_text_after (layout, boundary_type, offset, start_offset, end_offset);
g_object_unref (layout);
return text; return text;
} }
@ -318,11 +320,9 @@ gtk_text_cell_accessible_get_run_attributes (AtkText *text,
gint *end_offset) gint *end_offset)
{ {
AtkAttributeSet *attrib_set = NULL; AtkAttributeSet *attrib_set = NULL;
PangoLayout *layout; GtkTextCellAccessible *text_cell = GTK_TEXT_CELL_ACCESSIBLE (text);
layout = create_pango_layout (GTK_TEXT_CELL_ACCESSIBLE (text)); attrib_set = _gtk_pango_get_run_attributes (NULL, text_cell->priv->layout, offset, start_offset, end_offset);
attrib_set = _gtk_pango_get_run_attributes (NULL, layout, offset, start_offset, end_offset);
g_object_unref (G_OBJECT (layout));
return attrib_set; return attrib_set;
} }
@ -345,23 +345,20 @@ static AtkAttributeSet *
gtk_text_cell_accessible_get_default_attributes (AtkText *text) gtk_text_cell_accessible_get_default_attributes (AtkText *text)
{ {
AtkAttributeSet *attrib_set = NULL; AtkAttributeSet *attrib_set = NULL;
PangoLayout *layout; GtkTextCellAccessible *text_cell = GTK_TEXT_CELL_ACCESSIBLE (text);
GtkWidget *widget; GtkWidget *widget;
layout = create_pango_layout (GTK_TEXT_CELL_ACCESSIBLE (text));
widget = get_widget (GTK_TEXT_CELL_ACCESSIBLE (text)); widget = get_widget (GTK_TEXT_CELL_ACCESSIBLE (text));
attrib_set = add_attribute (attrib_set, ATK_TEXT_ATTR_DIRECTION, attrib_set = add_attribute (attrib_set, ATK_TEXT_ATTR_DIRECTION,
atk_text_attribute_get_value (ATK_TEXT_ATTR_DIRECTION, atk_text_attribute_get_value (ATK_TEXT_ATTR_DIRECTION,
gtk_widget_get_direction (widget))); gtk_widget_get_direction (widget)));
attrib_set = _gtk_pango_get_default_attributes (NULL, layout); attrib_set = _gtk_pango_get_default_attributes (NULL, text_cell->priv->layout);
attrib_set = _gtk_style_context_get_attributes (attrib_set, attrib_set = _gtk_style_context_get_attributes (attrib_set,
gtk_widget_get_style_context (widget), gtk_widget_get_style_context (widget),
gtk_widget_get_state_flags (widget)); gtk_widget_get_state_flags (widget));
g_object_unref (G_OBJECT (layout));
return attrib_set; return attrib_set;
} }
@ -529,7 +526,7 @@ gtk_text_cell_accessible_get_character_extents (AtkText *text,
GtkWidget *widget; GtkWidget *widget;
AtkObject *parent; AtkObject *parent;
PangoRectangle char_rect; PangoRectangle char_rect;
PangoLayout *layout; GtkTextCellAccessible *text_cell = GTK_TEXT_CELL_ACCESSIBLE (text);
gchar *renderer_text; gchar *renderer_text;
gfloat xalign, yalign; gfloat xalign, yalign;
gint x_offset, y_offset, index; gint x_offset, y_offset, index;
@ -574,10 +571,8 @@ gtk_text_cell_accessible_get_character_extents (AtkText *text,
x_offset = MAX (0, xalign * (rendered_rect.width - min_size.width)); x_offset = MAX (0, xalign * (rendered_rect.width - min_size.width));
y_offset = MAX (0, yalign * (rendered_rect.height - min_size.height)); y_offset = MAX (0, yalign * (rendered_rect.height - min_size.height));
layout = create_pango_layout (GTK_TEXT_CELL_ACCESSIBLE (text));
index = g_utf8_offset_to_pointer (renderer_text, offset) - renderer_text; index = g_utf8_offset_to_pointer (renderer_text, offset) - renderer_text;
pango_layout_index_to_pos (layout, index, &char_rect); pango_layout_index_to_pos (text_cell->priv->layout, index, &char_rect);
gtk_cell_renderer_get_padding (GTK_CELL_RENDERER (gtk_renderer), &xpad, &ypad); gtk_cell_renderer_get_padding (GTK_CELL_RENDERER (gtk_renderer), &xpad, &ypad);
@ -602,7 +597,6 @@ gtk_text_cell_accessible_get_character_extents (AtkText *text,
} }
g_free (renderer_text); g_free (renderer_text);
g_object_unref (layout);
g_object_unref (gtk_renderer); g_object_unref (gtk_renderer);
} }
@ -618,7 +612,7 @@ gtk_text_cell_accessible_get_offset_at_point (AtkText *text,
GtkRequisition min_size; GtkRequisition min_size;
GtkWidget *widget; GtkWidget *widget;
GdkRectangle rendered_rect; GdkRectangle rendered_rect;
PangoLayout *layout; GtkTextCellAccessible *text_cell = GTK_TEXT_CELL_ACCESSIBLE (text);
gchar *renderer_text; gchar *renderer_text;
gfloat xalign, yalign; gfloat xalign, yalign;
gint x_offset, y_offset, index; gint x_offset, y_offset, index;
@ -661,8 +655,6 @@ gtk_text_cell_accessible_get_offset_at_point (AtkText *text,
x_offset = MAX (0, xalign * (rendered_rect.width - min_size.width)); x_offset = MAX (0, xalign * (rendered_rect.width - min_size.width));
y_offset = MAX (0, yalign * (rendered_rect.height - min_size.height)); y_offset = MAX (0, yalign * (rendered_rect.height - min_size.height));
layout = create_pango_layout (GTK_TEXT_CELL_ACCESSIBLE (text));
gtk_cell_renderer_get_padding (GTK_CELL_RENDERER (gtk_renderer), &xpad, &ypad); gtk_cell_renderer_get_padding (GTK_CELL_RENDERER (gtk_renderer), &xpad, &ypad);
get_origins (widget, &x_window, &y_window, &x_toplevel, &y_toplevel); get_origins (widget, &x_window, &y_window, &x_toplevel, &y_toplevel);
@ -677,7 +669,7 @@ gtk_text_cell_accessible_get_offset_at_point (AtkText *text,
else if (coords != ATK_XY_SCREEN) else if (coords != ATK_XY_SCREEN)
index = -1; index = -1;
ret = pango_layout_xy_to_index (layout, ret = pango_layout_xy_to_index (text_cell->priv->layout,
x_temp * PANGO_SCALE, x_temp * PANGO_SCALE,
y_temp * PANGO_SCALE, y_temp * PANGO_SCALE,
&index, NULL); &index, NULL);
@ -689,7 +681,6 @@ gtk_text_cell_accessible_get_offset_at_point (AtkText *text,
index = -1; index = -1;
} }
g_object_unref (layout);
g_object_unref (gtk_renderer); g_object_unref (gtk_renderer);
if (index == -1) if (index == -1)