Merge branch 'get_caret_offset_negative_one' into 'master'

Return -1 for AtkText::get_caret_offset on failure

See merge request GNOME/gtk!666
This commit is contained in:
Matthias Clasen 2019-03-26 23:14:48 +00:00
commit 8d4343a550
5 changed files with 23 additions and 6 deletions

View File

@ -876,12 +876,18 @@ static gint
gtk_entry_accessible_get_caret_offset (AtkText *text)
{
GtkWidget *widget;
gboolean result;
int cursor_position;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
if (widget == NULL)
return 0;
return -1;
return gtk_editable_get_position (GTK_EDITABLE (widget));
result = gtk_editable_get_selection_bounds (GTK_EDITABLE (widget), NULL, &cursor_position);
if (!result)
return -1;
return cursor_position;
}
static gboolean

View File

@ -822,7 +822,11 @@ gtk_label_accessible_get_caret_offset (AtkText *text)
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
if (widget == NULL)
return 0;
return -1;
/* Non-selectable labels cannot have a caret. */
if (!gtk_label_get_selectable (GTK_LABEL (widget)))
return -1;
return _gtk_label_get_cursor_position (GTK_LABEL (widget));
}

View File

@ -317,12 +317,18 @@ static gint
gtk_text_accessible_get_caret_offset (AtkText *text)
{
GtkWidget *widget;
gboolean result;
int cursor_position;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
if (widget == NULL)
return 0;
return -1;
return gtk_editable_get_position (GTK_EDITABLE (widget));
result = gtk_editable_get_selection_bounds (GTK_EDITABLE (widget), NULL, &cursor_position);
if (!result)
return -1;
return cursor_position;
}
static gboolean

View File

@ -198,6 +198,7 @@ static void
gtk_text_cell_accessible_init (GtkTextCellAccessible *text_cell)
{
text_cell->priv = gtk_text_cell_accessible_get_instance_private (text_cell);
text_cell->priv->caret_pos = -1;
}
static gchar *

View File

@ -412,7 +412,7 @@ gtk_text_view_accessible_get_caret_offset (AtkText *text)
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
if (widget == NULL)
return 0;
return -1;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget));
return get_insert_offset (buffer);