Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtkhtml/a11y/ChangeLog,v
retrieving revision 1.16
diff -u -p -r1.16 ChangeLog
--- ChangeLog	29 Dec 2004 11:34:33 -0000	1.16
+++ ChangeLog	2 Jan 2005 07:59:40 -0000
@@ -1,3 +1,16 @@
+2005-01-02  Mengjie Yu  <meng-jie.yu@sun.com>
+
+	Fix for 70130 and 70683.	
+
+	* html.c: (html_a11y_get_top_gtkhtml_parent): new function.
+	(html_a11y_get_extents): get correct value.
+	* html.h:
+	* text.c: (atk_text_interface_init), (html_a11y_text_get_extents):
+        get a max rect as the extents.
+	(html_a11y_text_get_size): call get_extents to get size.
+	(html_a11y_text_get_offset_at_point): new function.
+	(html_a11y_text_get_character_extents): new function.
+
 2004-12-29  Mengjie Yu  <meng-jie.yu@sun.com>
 
 	* image.c: (html_a11y_image_get_name),
Index: html.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/a11y/html.c,v
retrieving revision 1.6
diff -u -p -r1.6 html.c
--- html.c	29 Dec 2004 11:23:53 -0000	1.6
+++ html.c	2 Jan 2005 07:59:41 -0000
@@ -27,6 +27,8 @@
 #include <atk/atkstateset.h>
 #include <glib/gi18n.h>
 
+#include "gtkhtml.h"
+#include "htmlengine.h"
 #include "html.h"
 #include "object.h"
 #include "utils.h"
@@ -260,24 +262,48 @@ html_a11y_get_gtkhtml_parent (HTMLA11Y *
 	return gtkhtml_a11y;
 }
 
+GtkHTMLA11Y *
+html_a11y_get_top_gtkhtml_parent (HTMLA11Y *a11y)
+{
+	GtkHTMLA11Y *gtkhtml_a11y;
+	GtkHTML *gtkhtml;
+
+	gtkhtml_a11y = html_a11y_get_gtkhtml_parent (a11y);
+	g_return_val_if_fail (gtkhtml_a11y, NULL);
+
+	gtkhtml = GTK_HTML_A11Y_GTKHTML (gtkhtml_a11y);
+	g_return_val_if_fail (gtkhtml, NULL);
+
+	while (gtkhtml->iframe_parent) 
+		gtkhtml = GTK_HTML (gtkhtml->iframe_parent);
+
+	return gtk_widget_get_accessible (GTK_WIDGET (gtkhtml));
+}
+
 void
 html_a11y_get_extents (AtkComponent *component, gint *x, gint *y, gint *width, gint *height, AtkCoordType coord_type)
 {
 	HTMLObject *obj = HTML_A11Y_HTML (component);
-	GtkHTMLA11Y *a11y = NULL;
+	GtkHTMLA11Y *top_html_a11y = NULL;
+	HTMLEngine *top_engine = NULL;
 	gint ax, ay;
 
 	g_return_if_fail (obj);
 
-	a11y = html_a11y_get_gtkhtml_parent (HTML_A11Y (component));
-	g_return_if_fail (a11y);
+	top_html_a11y = html_a11y_get_top_gtkhtml_parent (HTML_A11Y (component));
+	g_return_if_fail (top_html_a11y);
 
-	atk_component_get_extents (ATK_COMPONENT (a11y), x, y, width, height, coord_type);
+	atk_component_get_extents (ATK_COMPONENT (top_html_a11y), x, y, width, height, coord_type);
 	html_object_calc_abs_position (obj, &ax, &ay);
 	*x += ax;
 	*y += ay - obj->ascent;
 	*width = obj->width;
 	*height = obj->ascent + obj->descent;
+
+	/* scroll window */
+	top_engine = GTK_HTML_A11Y_GTKHTML (top_html_a11y)->engine;
+	*x -=  top_engine->x_offset;
+	*y -=  top_engine->y_offset;
 }
 
 void
Index: html.h
===================================================================
RCS file: /cvs/gnome/gtkhtml/a11y/html.h,v
retrieving revision 1.2
diff -u -p -r1.2 html.h
--- html.h	1 Nov 2002 15:34:27 -0000	1.2
+++ html.h	2 Jan 2005 07:59:41 -0000
@@ -55,6 +55,7 @@ struct _HTMLA11YClass {
 AtkObject * html_a11y_new (HTMLObject *html_obj, AtkRole role);
 
 GtkHTMLA11Y * html_a11y_get_gtkhtml_parent (HTMLA11Y *obj);
+GtkHTMLA11Y * html_a11y_get_top_gtkhtml_parent (HTMLA11Y *obj);
 
 /* private, used in text.c */
 void  html_a11y_get_extents (AtkComponent *component, gint *x, gint *y, gint *width, gint *height, AtkCoordType coord_type);
Index: text.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/a11y/text.c,v
retrieving revision 1.11
diff -u -p -r1.11 text.c
--- text.c	29 Dec 2004 11:23:53 -0000	1.11
+++ text.c	2 Jan 2005 07:59:46 -0000
@@ -25,6 +25,7 @@
 #include <atk/atkcomponent.h>
 #include <atk/atktext.h>
 #include <glib/gi18n.h>
+#include <glib/gmacros.h>
 
 #include "gtkhtml.h"
 #include "htmlengine.h"
@@ -67,6 +68,11 @@ static gboolean html_a11y_text_remove_se
 static gboolean html_a11y_text_set_selection (AtkText *text, gint selection_num, gint start_offset, gint end_offset);
 static gint html_a11y_text_get_caret_offset (AtkText *text);
 static gboolean html_a11y_text_set_caret_offset (AtkText *text, gint offset);
+static void html_a11y_text_get_character_extents (AtkText *text, gint offset,
+				gint *x, gint *y, gint *width, gint *height,
+				AtkCoordType coords);
+static gint html_a11y_text_get_offset_at_point (AtkText *text, gint x, gint y,
+					AtkCoordType coords);
 
 /* Editable text interface. */
 static void 	atk_editable_text_interface_init      (AtkEditableTextIface *iface);
@@ -212,6 +218,8 @@ atk_text_interface_init (AtkTextIface *i
 	iface->add_selection = html_a11y_text_add_selection;
 	iface->get_caret_offset = html_a11y_text_get_caret_offset;
 	iface->set_caret_offset = html_a11y_text_set_caret_offset;
+	iface->get_character_extents = html_a11y_text_get_character_extents;
+	iface->get_offset_at_point = html_a11y_text_get_offset_at_point;
 }
 
 static void
@@ -306,47 +314,63 @@ html_a11y_text_ref_state_set (AtkObject 
  * AtkComponent interface
  */
 
-static void
-get_size (HTMLObject *obj, gint *width, gint *height)
-{
-	HTMLObject *last;
-
-	if (obj) {
-		gint ax, ay;
-
-		html_object_calc_abs_position (obj, &ax, &ay);
-		last = obj;
-		while (last->next && HTML_IS_TEXT_SLAVE (last->next))
-			last = last->next;
-		if (HTML_IS_TEXT_SLAVE (last)) {
-			gint lx, ly;
-			html_object_calc_abs_position (last, &lx, &ly);
-
-			*width = lx + last->width - ax;
-			*height = ly + last->descent - ay;
-		}
-	}
-}
 
 static void
 html_a11y_text_get_extents (AtkComponent *component, gint *x, gint *y, gint *width, gint *height, AtkCoordType coord_type)
 {
 	HTMLObject *obj = HTML_A11Y_HTML (component);
+	GtkHTMLA11Y *top_html_a11y = NULL;
+	HTMLEngine *top_engine = NULL;
+	gint min_x, min_y, max_x, max_y;
+	HTMLObject *next;
+	gint sx, sy;
+
+	g_return_if_fail (obj);
+	top_html_a11y = html_a11y_get_top_gtkhtml_parent (HTML_A11Y (component));
+	g_return_if_fail (top_html_a11y);
+
+	if (obj->y <obj->ascent)
+		obj->y = obj->ascent;
+
+	atk_component_get_extents (ATK_COMPONENT (top_html_a11y), x, y, width, height, coord_type);
+
+	/* we need to get a max rect here */
+	html_object_calc_abs_position (obj, &min_x, &min_y);
+	max_x = min_x + obj->width;
+	max_y = min_y + obj->descent;
+	min_y -= obj->ascent;
+
+	next = obj->next;
+	while (next && HTML_IS_TEXT_SLAVE (next)) {
+		html_object_calc_abs_position (next, &sx, &sy);
+		min_x = MIN (min_x, sx);
+		min_y = MIN (min_y, sy - next->ascent);
+		max_x = MAX (max_x, sx + next->width);
+		max_y = MAX (max_y, sy + next->descent);
+
+		next = next->next;
+	}
 
-	html_a11y_get_extents (component, x, y, width, height, coord_type);
-	get_size (obj, width, height);
+	*x += min_x;
+	*y += min_y;
+	*width = max_x - min_x;
+	*height = max_y - min_y;
+
+	/* scroll window */
+	top_engine = GTK_HTML_A11Y_GTKHTML (top_html_a11y)->engine;
+	*x -=  top_engine->x_offset;
+	*y -=  top_engine->y_offset;
 }
 
+
 static void
 html_a11y_text_get_size (AtkComponent *component, gint *width, gint *height)
 {
-	HTMLObject *obj = HTML_A11Y_HTML (component);
+	gint x, y;
 
-	html_a11y_get_size (component, width, height);
-	get_size (obj, width, height);
+	html_a11y_get_extents (component, &x, &y, width, height, ATK_XY_WINDOW);
 }
 
-
 static gboolean
 html_a11y_text_grab_focus (AtkComponent *comp)
 {
@@ -678,6 +702,83 @@ html_a11y_text_set_selection (AtkText *t
 
 */
 
+static gint
+html_a11y_text_get_offset_at_point (AtkText *text, gint x, gint y,
+					AtkCoordType coords)
+{
+	GtkHTML *top_html;
+	GtkHTMLA11Y *top_a11y;
+	HTMLEngine *top_e;
+	HTMLObject *obj, *return_obj;
+	gint offset = -1;
+	gint html_x, html_y, html_height, html_width;
+	gint text_x, text_y, text_height, text_width;
+
+	obj = HTML_A11Y_HTML (text);
+	g_return_if_fail(obj && html_object_is_text(obj));
+
+	atk_component_get_extents (ATK_COMPONENT (text), &text_x, &text_y, &text_width, &text_height, coords);
+
+	/* check whether in range */
+	if (x < text_x || x > text_x + text_width
+		|| y < text_y || y > text_y + text_height)
+		return -1;
+
+	top_a11y = html_a11y_get_top_gtkhtml_parent (HTML_A11Y (text));
+	g_return_if_fail (top_a11y);
+
+	top_html = GTK_HTML_A11Y_GTKHTML (top_a11y);
+	g_return_if_fail (top_html && GTK_IS_HTML(top_html) && top_html->engine);
+	top_e = top_html->engine;
+
+	atk_component_get_extents (ATK_COMPONENT (top_a11y), &html_x, &html_y, &html_width, &html_height, coords);
+
+	x -= html_x;
+	y -= html_y;
+
+	return_obj = html_engine_get_object_at (top_e, x, y, &offset, FALSE);
+		
+	if (obj == return_obj)
+		return offset;
+	else
+		/*since the point is in range, need to return a valid value */ 
+		return 0;
+}
+
+static void
+html_a11y_text_get_character_extents (AtkText *text, gint offset,
+				gint *x, gint *y, gint *width, gint *height,
+				AtkCoordType coords)
+{
+	HTMLObject *obj;
+	GtkHTML *html;
+	HTMLEngine *e;
+	gint x1, x2, y1, y2;
+	GtkHTMLA11Y *a11y;
+
+	obj = HTML_A11Y_HTML (text);
+	g_return_if_fail(obj && html_object_is_text(obj));
+
+	a11y = html_a11y_get_top_gtkhtml_parent (HTML_A11Y (text));
+	g_return_if_fail (a11y);
+
+	html = GTK_HTML_A11Y_GTKHTML (a11y);
+	g_return_if_fail(html && GTK_IS_HTML(html) && html->engine);
+	e = html->engine;
+
+	atk_component_get_extents (ATK_COMPONENT (a11y), x, y, width, height, coords);
+	html_object_get_cursor (obj, e->painter, offset, &x1, &y1, &x2, &y2);
+
+	*x += x1;
+	*y += y1;
+	*height = y2 - y1;
+	/* a reasonable guess */
+	*width = *height / 2;
+
+	/* scroll window */
+	*x -=  e->x_offset;
+	*y -=  e->y_offset;
+}
  
 static void
 atk_editable_text_interface_init (AtkEditableTextIface *iface)
