cvs server: Diffing .
Index: htmlboxblocktextaccessible.c
===================================================================
RCS file: /cvs/gnome/gtkhtml2/libgtkhtml/a11y/htmlboxblocktextaccessible.c,v
retrieving revision 1.7
diff -u -p -r1.7 htmlboxblocktextaccessible.c
--- htmlboxblocktextaccessible.c	30 Jan 2004 17:06:05 -0000	1.7
+++ htmlboxblocktextaccessible.c	5 May 2004 09:40:36 -0000
@@ -1272,6 +1272,102 @@ html_box_block_text_accessible_set_selec
 	return html_box_block_text_accessible_add_selection (text, start_pos, end_pos);
 }
 
+static gboolean is_text_in_line (HtmlBox       *root,
+                                 HtmlBox       *anchor,
+                                 GailOffsetType function)
+{
+	gboolean is_in_line;
+	gint anchor_y;
+	gint root_y;
+	gint delta = 1;
+
+	anchor_y = html_box_get_absolute_y (anchor);
+	root_y = html_box_get_absolute_y (root);
+	if (function == GAIL_AT_OFFSET) {
+		is_in_line = (root_y <= anchor_y + delta && 
+			      root_y >= anchor_y - delta);
+	} else if (function == GAIL_BEFORE_OFFSET) { 
+		is_in_line = (root_y + root->height <= anchor_y + delta && 
+			      root_y + root->height >= anchor_y - delta);
+	} else if (function == GAIL_AFTER_OFFSET) { 
+		is_in_line = (anchor_y + anchor->height <= root_y + delta && 
+			      anchor_y + anchor->height >= root_y - delta);
+	}
+        return is_in_line;             
+}
+
+static void
+append_text_for_line (HtmlBox       *root,
+                      HtmlBox       *anchor,
+                      GString       *content,
+                      GailOffsetType function,
+                      gint          *start,
+                      gint          *end)
+{
+	gint len;
+	HtmlBox *box;
+	gchar *text;
+
+	if (!root)
+		return;
+
+	if (HTML_IS_BOX_TEXT (root)) {
+		text = html_box_text_get_text (HTML_BOX_TEXT (root), &len);
+		if (text) {
+			if (is_text_in_line (root, anchor, function)) {
+				g_string_append_len (content, text, len);
+				if (*start == -1) {
+					*start = *end;
+				}
+			} else if (*start == -1) {
+				*end += g_utf8_strlen (text, len);
+			} else {
+				return;
+			}
+		}
+	}
+	box = root->children;
+	while (box) {
+		append_text_for_line (box, anchor, content, function, start, end);
+		box = box->next;
+	}
+}
+
+static gchar*
+get_line_near_offset (HtmlBox       *root,
+                      GailOffsetType function,
+                      gint           offset,
+                      gint          *start,
+                      gint          *end)
+{
+	HtmlBoxText *box_text;
+	GString *content;
+	gchar *line;
+	gint real_offset;
+
+	if (!root)
+		return NULL;
+
+	real_offset = offset;
+	box_text = find_box_text_for_offset (root, &real_offset);
+	if (!box_text)
+		return NULL;
+
+	*start = -1;
+	*end = 0;
+	content = g_string_new (NULL);
+	append_text_for_line (root, HTML_BOX (box_text), content, function, start, end);
+	line = g_strndup (content->str, content->len);
+	if (content->len) {
+		*end = *start + g_utf8_strlen (line, content->len);
+	} else {
+		*start = 0;
+		*end = 0;
+	}
+	g_string_free (content, TRUE);
+	return line;
+}
+ 
 static gchar*
 get_text_near_offset (AtkText          *text,
                       GailOffsetType   function,
@@ -1280,7 +1376,23 @@ get_text_near_offset (AtkText          *
                       gint             *start_offset,
                       gint             *end_offset)
 {
-	return gail_text_util_get_text (HTML_BOX_BLOCK_TEXT_ACCESSIBLE (text)->priv->textutil, NULL,
-					function, boundary_type, offset, 
-					start_offset, end_offset);
+	if (boundary_type == ATK_TEXT_BOUNDARY_LINE_START ||
+	    boundary_type == ATK_TEXT_BOUNDARY_LINE_END) {
+		AtkGObjectAccessible *atk_gobj;
+		GObject *g_obj;
+		HtmlBox *top_box;
+		gchar 	*text_chars;
+
+		atk_gobj = ATK_GOBJECT_ACCESSIBLE (text);
+		g_obj = atk_gobject_accessible_get_object (atk_gobj);
+		if (g_obj == NULL)
+			return NULL;
+
+		top_box = HTML_BOX (g_obj);
+      		return get_line_near_offset (top_box, function, offset, start_offset, end_offset); 
+	} else {
+		return gail_text_util_get_text (HTML_BOX_BLOCK_TEXT_ACCESSIBLE (text)->priv->textutil, NULL,
+						function, boundary_type, offset, 
+						start_offset, end_offset);
+	}
 }
