[gtk: 1/2] Return -1 for AtkText::get_caret_offset on failure



commit c8d250deb1a805c19b8ce6860256b3886137e33e
Author: Martin Robinson <mrobinson igalia com>
Date:   Tue Mar 26 15:28:03 2019 +0100

    Return -1 for AtkText::get_caret_offset on failure
    
    ATK now expects this virtual method to return -1 on failure. This allows
    ATs to distinguish between a caret at position 0 and a failure.

 gtk/a11y/gtkentryaccessible.c    | 10 ++++++++--
 gtk/a11y/gtklabelaccessible.c    |  6 +++++-
 gtk/a11y/gtktextaccessible.c     | 10 ++++++++--
 gtk/a11y/gtktextcellaccessible.c |  1 +
 gtk/a11y/gtktextviewaccessible.c |  2 +-
 5 files changed, 23 insertions(+), 6 deletions(-)
---
diff --git a/gtk/a11y/gtkentryaccessible.c b/gtk/a11y/gtkentryaccessible.c
index d83d9f9c55..b833e3e37d 100644
--- a/gtk/a11y/gtkentryaccessible.c
+++ b/gtk/a11y/gtkentryaccessible.c
@@ -874,12 +874,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;
+
+  result = gtk_editable_get_selection_bounds (GTK_EDITABLE (widget), NULL, &cursor_position);
+  if (!result)
+    return -1;
 
-  return gtk_editable_get_position (GTK_EDITABLE (widget));
+  return cursor_position;
 }
 
 static gboolean
diff --git a/gtk/a11y/gtklabelaccessible.c b/gtk/a11y/gtklabelaccessible.c
index 7361aa627e..4c7fbf14f2 100644
--- a/gtk/a11y/gtklabelaccessible.c
+++ b/gtk/a11y/gtklabelaccessible.c
@@ -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));
 }
diff --git a/gtk/a11y/gtktextaccessible.c b/gtk/a11y/gtktextaccessible.c
index 6a0bd453b1..8cea128a64 100644
--- a/gtk/a11y/gtktextaccessible.c
+++ b/gtk/a11y/gtktextaccessible.c
@@ -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;
+
+  result = gtk_editable_get_selection_bounds (GTK_EDITABLE (widget), NULL, &cursor_position);
+  if (!result)
+    return -1;
 
-  return gtk_editable_get_position (GTK_EDITABLE (widget));
+  return cursor_position;
 }
 
 static gboolean
diff --git a/gtk/a11y/gtktextcellaccessible.c b/gtk/a11y/gtktextcellaccessible.c
index 0fd83f95c7..7546f2bb63 100644
--- a/gtk/a11y/gtktextcellaccessible.c
+++ b/gtk/a11y/gtktextcellaccessible.c
@@ -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 *
diff --git a/gtk/a11y/gtktextviewaccessible.c b/gtk/a11y/gtktextviewaccessible.c
index b6b5a657f2..52c2514782 100644
--- a/gtk/a11y/gtktextviewaccessible.c
+++ b/gtk/a11y/gtktextviewaccessible.c
@@ -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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]