[Fwd: [gthktml] fix to avoid race condition which causes infinite loop]



Hello,

please review patch in forwarded message for the gtkhtml/gnome-2-10 release.

Cheers
Radek
--
Radek Doulík <rodo novell com>
Novell, Inc.
--- Begin Message --- Attached patch basically propagates painter to low level cursor functions, so that we can get up-to-date pango information there.

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/ChangeLog,v
retrieving revision 1.2099
diff -u -p -r1.2099 ChangeLog
--- ChangeLog	28 Feb 2005 15:36:25 -0000	1.2099
+++ ChangeLog	7 Mar 2005 16:58:48 -0000
@@ -1,3 +1,21 @@
+2005-03-07  Radek Doulik  <rodo novell com>
+
+	* htmltextslave.c (html_text_slave_get_left_edge_offset): make
+	sure offset is in slave boundaries (should not happen with below
+	fixes anymore, but to be sure)
+
+	* htmlcursor.c: pass engine deeper in cursor function so that we
+	can call object funtions with painter
+
+	* htmlobject.c: as below
+
+	* htmltext.c: as below
+
+	* htmltextslave.c: add painter to cursor movements function
+	arguments to be able to recalculate items. there was a race
+	condition where cursor movement happened before line breaks were
+	recalculated which lead to infinite loop.
+
 2005-02-28  Radek Doulik  <rodo novell com>
 
 	* htmltext.c (html_text_direction_pango_to_html): new helper
Index: htmlcursor.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmlcursor.c,v
retrieving revision 1.71
diff -u -p -r1.71 htmlcursor.c
--- htmlcursor.c	21 Feb 2005 16:34:49 -0000	1.71
+++ htmlcursor.c	7 Mar 2005 16:59:09 -0000
@@ -37,8 +37,8 @@
 
 #include "htmlcursor.h"
 
-static gboolean move_right (HTMLCursor *cursor);
-static gboolean move_left (HTMLCursor *cursor);
+static gboolean move_right (HTMLCursor *cursor, HTMLEngine *e);
+static gboolean move_left (HTMLCursor *cursor, HTMLEngine *e);
 
 /* #define _HTML_CURSOR_DEBUG */
 
@@ -446,10 +446,10 @@ html_cursor_down (HTMLCursor *cursor,
 		prev_y = y;
 
 		if (dir == HTML_DIRECTION_RTL) {
-			if (! move_left (cursor))
+			if (! move_left (cursor, engine))
 				return FALSE;
 		} else {
-			if (! move_right (cursor))
+			if (! move_right (cursor, engine))
 				return FALSE;
 		}
 
@@ -843,7 +843,7 @@ html_cursor_child_of (HTMLCursor *cursor
 }
 
 static gboolean
-move_to_next_object (HTMLCursor *cursor)
+move_to_next_object (HTMLCursor *cursor, HTMLEngine *e)
 {
 	HTMLObject *next;
 
@@ -854,9 +854,9 @@ move_to_next_object (HTMLCursor *cursor)
 
 		if (!html_object_is_container (next)) {
 			if (html_object_get_direction (next->parent) == HTML_DIRECTION_RTL) {
-				cursor->offset = html_object_get_right_edge_offset (next, 0);
+				cursor->offset = html_object_get_right_edge_offset (next, e->painter, 0);
 			} else {
-				cursor->offset = html_object_get_left_edge_offset (next, 0);
+				cursor->offset = html_object_get_left_edge_offset (next, e->painter, 0);
 			}
 			cursor->position += cursor->offset;
 		}
@@ -867,7 +867,7 @@ move_to_next_object (HTMLCursor *cursor)
 }
 
 static gboolean
-move_to_prev_object (HTMLCursor *cursor)
+move_to_prev_object (HTMLCursor *cursor, HTMLEngine *e)
 {
 	HTMLObject *prev;
 
@@ -878,9 +878,9 @@ move_to_prev_object (HTMLCursor *cursor)
 
 		if (!html_object_is_container (prev)) {
 			if (html_object_get_direction (prev->parent) == HTML_DIRECTION_RTL) {
-				cursor->offset = html_object_get_left_edge_offset (prev, html_object_get_length (prev));
+				cursor->offset = html_object_get_left_edge_offset (prev, e->painter, html_object_get_length (prev));
 			} else {
-				cursor->offset = html_object_get_right_edge_offset (prev, html_object_get_length (prev));
+				cursor->offset = html_object_get_right_edge_offset (prev, e->painter, html_object_get_length (prev));
 			}
 			cursor->position -= cursor->offset - html_object_get_length (prev);
 		}
@@ -891,14 +891,14 @@ move_to_prev_object (HTMLCursor *cursor)
 }
 
 static gboolean
-move_left (HTMLCursor *cursor)
+move_left (HTMLCursor *cursor, HTMLEngine *e)
 {
-	if (!html_object_cursor_left (cursor->object, cursor)) {
+	if (!html_object_cursor_left (cursor->object, e->painter, cursor)) {
 		if (cursor->object->parent) {
 			if (html_object_get_direction (cursor->object->parent) == HTML_DIRECTION_RTL)
-				return move_to_next_object (cursor);
+				return move_to_next_object (cursor, e);
 			else
-				return move_to_prev_object (cursor);
+				return move_to_prev_object (cursor, e);
 		}
 	}
 
@@ -919,7 +919,7 @@ html_cursor_left (HTMLCursor *cursor, HT
 		html_engine_spell_check_range (engine, engine->cursor, engine->cursor);
 
 	cursor->have_target_x = FALSE;
-	retval = move_left (cursor);
+	retval = move_left (cursor, engine);
 
 	debug_location (cursor);
 
@@ -927,22 +927,22 @@ html_cursor_left (HTMLCursor *cursor, HT
 }
 
 static gboolean
-left_in_flow (HTMLCursor *cursor)
+left_in_flow (HTMLCursor *cursor, HTMLEngine *e)
 {
 	gboolean retval;
 
 	retval = TRUE;
-	if (cursor->offset != html_object_get_left_edge_offset (cursor->object, cursor->offset) && html_object_is_container (cursor->object)) {
+	if (cursor->offset != html_object_get_left_edge_offset (cursor->object, e->painter, cursor->offset) && html_object_is_container (cursor->object)) {
 		HTMLObject *obj;
 
 		obj = cursor->object;
-		while ((retval = move_left (cursor)) && cursor->object != obj)
+		while ((retval = move_left (cursor, e)) && cursor->object != obj)
 			;
 	} else {
 		if (cursor->offset > 1 || !cursor->object->prev)
-			retval = html_object_cursor_left (cursor->object, cursor);
+			retval = html_object_cursor_left (cursor->object, e->painter, cursor);
 		else if (cursor->object->prev)
-			retval = move_left (cursor);
+			retval = move_left (cursor, e);
 		else
 			retval = FALSE;
 	}
@@ -972,7 +972,7 @@ html_cursor_left_edge_of_line (HTMLCurso
 				     &x, &prev_y);
 
 	while (1) {
-		if (! left_in_flow (cursor))
+		if (! left_in_flow (cursor, engine))
 			return TRUE;
 
 		html_object_get_cursor_base (cursor->object, engine->painter, cursor->offset,
@@ -989,17 +989,17 @@ html_cursor_left_edge_of_line (HTMLCurso
 }
 
 static gboolean
-move_right (HTMLCursor *cursor)
+move_right (HTMLCursor *cursor, HTMLEngine *e)
 {
 	gboolean retval;
 
 	retval = TRUE;
-	if (!html_object_cursor_right (cursor->object, cursor)) {
+	if (!html_object_cursor_right (cursor->object, e->painter, cursor)) {
 		if (cursor->object->parent) {
 			if (html_object_get_direction (cursor->object->parent) == HTML_DIRECTION_RTL)
-				return move_to_prev_object (cursor);
+				return move_to_prev_object (cursor, e);
 			else
-				return move_to_next_object (cursor);
+				return move_to_next_object (cursor, e);
 		}
 	}
 	return retval;
@@ -1019,7 +1019,7 @@ html_cursor_right (HTMLCursor *cursor, H
 		html_engine_spell_check_range (engine, engine->cursor, engine->cursor);
 
 	cursor->have_target_x = FALSE;
-	retval = move_right (cursor);
+	retval = move_right (cursor, engine);
 
 	debug_location (cursor);
 
@@ -1027,23 +1027,23 @@ html_cursor_right (HTMLCursor *cursor, H
 }
 
 static gboolean
-right_in_flow (HTMLCursor *cursor)
+right_in_flow (HTMLCursor *cursor, HTMLEngine *e)
 {
 	gboolean retval;
 
 	retval = TRUE;
-	if (cursor->offset != html_object_get_right_edge_offset (cursor->object, cursor->offset)) {
+	if (cursor->offset != html_object_get_right_edge_offset (cursor->object, e->painter, cursor->offset)) {
 		if (html_object_is_container (cursor->object)) {
 			HTMLObject *obj;
 
 			obj = cursor->object;
-			while ((retval = move_right (cursor)) && cursor->object != obj)
+			while ((retval = move_right (cursor, e)) && cursor->object != obj)
 				;
 		} else
-			retval = html_object_cursor_right (cursor->object, cursor);
+			retval = html_object_cursor_right (cursor->object, e->painter, cursor);
 	} else {
 		if (html_object_next_not_slave (cursor->object))
-			retval = move_right (cursor);
+			retval = move_right (cursor, e);
 		else
 			retval = FALSE;
 	}
@@ -1073,7 +1073,7 @@ html_cursor_right_edge_of_line (HTMLCurs
 				     &x, &prev_y);
 
 	while (1) {
-		if (! right_in_flow (cursor))
+		if (! right_in_flow (cursor, engine))
 			return TRUE;
 
 		html_object_get_cursor_base (cursor->object, engine->painter, cursor->offset,
Index: htmlobject.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmlobject.c,v
retrieving revision 1.186
diff -u -p -r1.186 htmlobject.c
--- htmlobject.c	3 Feb 2005 17:18:43 -0000	1.186
+++ htmlobject.c	7 Mar 2005 16:59:15 -0000
@@ -642,7 +642,7 @@ html_object_real_cursor_backward (HTMLOb
 }
 
 static gboolean
-html_object_real_cursor_right (HTMLObject *self, HTMLCursor *cursor)
+html_object_real_cursor_right (HTMLObject *self, HTMLPainter *painter, HTMLCursor *cursor)
 {
 	HTMLDirection dir = html_object_get_direction (self);
 
@@ -677,7 +677,7 @@ html_object_real_cursor_right (HTMLObjec
 }
 
 static gboolean
-html_object_real_cursor_left (HTMLObject *self, HTMLCursor *cursor)
+html_object_real_cursor_left (HTMLObject *self, HTMLPainter *painter, HTMLCursor *cursor)
 {
 	HTMLDirection dir = html_object_get_direction (self);
 
@@ -711,13 +711,13 @@ html_object_real_cursor_left (HTMLObject
 }
 
 static int
-html_object_real_get_right_edge_offset (HTMLObject *o, int offset)
+html_object_real_get_right_edge_offset (HTMLObject *o, HTMLPainter *painter, int offset)
 {
 	return html_object_get_length (o);
 }
 
 static int
-html_object_real_get_left_edge_offset (HTMLObject *o, int offset)
+html_object_real_get_left_edge_offset (HTMLObject *o, HTMLPainter *painter, int offset)
 {
 	return 0;
 }
@@ -1542,15 +1542,15 @@ html_object_cursor_backward (HTMLObject 
 }
 
 gboolean
-html_object_cursor_right (HTMLObject *self, HTMLCursor *cursor)
+html_object_cursor_right (HTMLObject *self, HTMLPainter *painter, HTMLCursor *cursor)
 {
-	return (* HO_CLASS (self)->cursor_right) (self, cursor);
+	return (* HO_CLASS (self)->cursor_right) (self, painter, cursor);
 }
 
 gboolean
-html_object_cursor_left (HTMLObject *self, HTMLCursor *cursor)
+html_object_cursor_left (HTMLObject *self, HTMLPainter *painter, HTMLCursor *cursor)
 {
-	return (* HO_CLASS (self)->cursor_left) (self, cursor);
+	return (* HO_CLASS (self)->cursor_left) (self, painter, cursor);
 }
 
 /*********************
@@ -2240,13 +2240,13 @@ html_object_get_flow (HTMLObject *o)
 }
 
 int
-html_object_get_right_edge_offset (HTMLObject *o, int offset)
+html_object_get_right_edge_offset (HTMLObject *o, HTMLPainter *painter, int offset)
 {
-	return (* HO_CLASS (o)->get_right_edge_offset) (o, offset);
+	return (* HO_CLASS (o)->get_right_edge_offset) (o, painter, offset);
 }
 
 int
-html_object_get_left_edge_offset (HTMLObject *o, int offset)
+html_object_get_left_edge_offset (HTMLObject *o, HTMLPainter *painter, int offset)
 {
-	return (* HO_CLASS (o)->get_left_edge_offset) (o, offset);
+	return (* HO_CLASS (o)->get_left_edge_offset) (o, painter, offset);
 }
Index: htmlobject.h
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmlobject.h,v
retrieving revision 1.133
diff -u -p -r1.133 htmlobject.h
--- htmlobject.h	31 Jan 2005 11:20:43 -0000	1.133
+++ htmlobject.h	7 Mar 2005 16:59:17 -0000
@@ -264,11 +264,11 @@ struct _HTMLObjectClass {
 
 	gboolean (*cursor_forward)       (HTMLObject *self, HTMLCursor *cursor);
 	gboolean (*cursor_backward)       (HTMLObject *self, HTMLCursor *cursor);
-	gboolean (*cursor_right)         (HTMLObject *self, HTMLCursor *cursor);
-	gboolean (*cursor_left)          (HTMLObject *self, HTMLCursor *cursor);
+	gboolean (*cursor_right)         (HTMLObject *self, HTMLPainter *painter, HTMLCursor *cursor);
+	gboolean (*cursor_left)          (HTMLObject *self, HTMLPainter *painter, HTMLCursor *cursor);
 
-	int (*get_right_edge_offset) (HTMLObject *o, int offset);
-	int (*get_left_edge_offset) (HTMLObject *o, int offset);
+	int (*get_right_edge_offset) (HTMLObject *o, HTMLPainter *painter, int offset);
+	int (*get_left_edge_offset) (HTMLObject *o, HTMLPainter *painter, int offset);
 };
 
 extern HTMLObjectClass html_object_class;
@@ -465,8 +465,10 @@ gboolean        html_object_cursor_forwa
 gboolean        html_object_cursor_backward       (HTMLObject            *self,
 						   HTMLCursor            *cursor);
 gboolean        html_object_cursor_left           (HTMLObject            *self,
+						   HTMLPainter           *painter,
 						   HTMLCursor            *cursor);
 gboolean        html_object_cursor_right          (HTMLObject            *self,
+						   HTMLPainter           *painter,
 						   HTMLCursor            *cursor);
 
 /* get prev/next object in scope of parent */
@@ -613,8 +615,10 @@ HTMLObject *html_object_prev_cursor_leaf
 					     HTMLEngine *e);
 
 int  html_object_get_right_edge_offset  (HTMLObject *o,
+					 HTMLPainter *painter,
 					 int offset);
 int  html_object_get_left_edge_offset   (HTMLObject *o,
+					 HTMLPainter *painter,
 					 int offset);
 
 const char *html_object_get_id  (HTMLObject *o);
Index: htmltext.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmltext.c,v
retrieving revision 1.275
diff -u -p -r1.275 htmltext.c
--- htmltext.c	28 Feb 2005 15:36:25 -0000	1.275
+++ htmltext.c	7 Mar 2005 16:59:26 -0000
@@ -2448,13 +2448,13 @@ html_text_get_slave_at_offset (HTMLText 
 }
 
 static gboolean
-html_text_cursor_prev_slave (HTMLObject *slave, HTMLCursor *cursor)
+html_text_cursor_prev_slave (HTMLObject *slave, HTMLPainter *painter, HTMLCursor *cursor)
 {
 	HTMLObject *prev = HTML_OBJECT (slave)->prev;
 	int offset = cursor->offset;
 
 	if (prev && HTML_IS_TEXT_SLAVE (prev)) {
-		if (html_text_slave_cursor_tail (HTML_TEXT_SLAVE (prev), cursor)) {
+		if (html_text_slave_cursor_tail (HTML_TEXT_SLAVE (prev), cursor, painter)) {
 			cursor->position += cursor->offset - offset;
 			return TRUE;
 		}
@@ -2464,13 +2464,13 @@ html_text_cursor_prev_slave (HTMLObject 
 }
 
 static gboolean
-html_text_cursor_next_slave (HTMLObject *slave, HTMLCursor *cursor)
+html_text_cursor_next_slave (HTMLObject *slave, HTMLPainter *painter, HTMLCursor *cursor)
 {
 	HTMLObject *next = slave->next;
 	int offset = cursor->offset;
 
 	if (next && HTML_IS_TEXT_SLAVE (next)) {
-		if (html_text_slave_cursor_head (HTML_TEXT_SLAVE (next), cursor)) {
+		if (html_text_slave_cursor_head (HTML_TEXT_SLAVE (next), cursor, painter)) {
 			cursor->position += cursor->offset - offset;
 			return TRUE;
 		}
@@ -2480,7 +2480,7 @@ html_text_cursor_next_slave (HTMLObject 
 }
 
 static gboolean
-html_text_cursor_right (HTMLObject *self, HTMLCursor *cursor)
+html_text_cursor_right (HTMLObject *self, HTMLPainter *painter, HTMLCursor *cursor)
 {
 	HTMLTextSlave *slave;
 
@@ -2490,14 +2490,14 @@ html_text_cursor_right (HTMLObject *self
 	slave = html_text_get_slave_at_offset (HTML_TEXT (self), NULL, cursor->offset);
 
 	if (slave) {
-		if (html_text_slave_cursor_right (slave, cursor))
+		if (html_text_slave_cursor_right (slave, painter, cursor))
 			return TRUE;
 		else {
 			if (self->parent) {
 				if (html_object_get_direction (self->parent) == HTML_DIRECTION_RTL)
-					return html_text_cursor_prev_slave (HTML_OBJECT (slave), cursor);
+					return html_text_cursor_prev_slave (HTML_OBJECT (slave), painter, cursor);
 				else
-					return html_text_cursor_next_slave (HTML_OBJECT (slave), cursor);
+					return html_text_cursor_next_slave (HTML_OBJECT (slave), painter, cursor);
 			}
 		}
 	}
@@ -2506,7 +2506,7 @@ html_text_cursor_right (HTMLObject *self
 }
 
 static gboolean
-html_text_cursor_left (HTMLObject *self, HTMLCursor *cursor)
+html_text_cursor_left (HTMLObject *self, HTMLPainter *painter, HTMLCursor *cursor)
 {
 	HTMLTextSlave *slave;
 
@@ -2516,14 +2516,14 @@ html_text_cursor_left (HTMLObject *self,
 	slave = html_text_get_slave_at_offset (HTML_TEXT (self), NULL, cursor->offset);
 
 	if (slave) {
-		if (html_text_slave_cursor_left (slave, cursor))
+		if (html_text_slave_cursor_left (slave, painter, cursor))
 			return TRUE;
 		else {
 			if (self->parent) {
 				if (html_object_get_direction (self->parent) == HTML_DIRECTION_RTL)
-					return html_text_cursor_next_slave (HTML_OBJECT (slave), cursor);
+					return html_text_cursor_next_slave (HTML_OBJECT (slave), painter, cursor);
 				else
-					return html_text_cursor_prev_slave (HTML_OBJECT (slave), cursor);
+					return html_text_cursor_prev_slave (HTML_OBJECT (slave), painter, cursor);
 			}
 		}
 	}
@@ -2532,12 +2532,12 @@ html_text_cursor_left (HTMLObject *self,
 }
 
 static int
-html_text_get_right_edge_offset (HTMLObject *o, int offset)
+html_text_get_right_edge_offset (HTMLObject *o, HTMLPainter *painter, int offset)
 {
 	HTMLTextSlave *slave = html_text_get_slave_at_offset (HTML_TEXT (o), NULL, offset);
 
 	if (slave) {
-		return html_text_slave_get_right_edge_offset (slave);
+		return html_text_slave_get_right_edge_offset (slave, painter);
 	} else {
 		g_warning ("getting right edge offset from text object without slave(s)");
 
@@ -2546,12 +2546,12 @@ html_text_get_right_edge_offset (HTMLObj
 }
 
 static int
-html_text_get_left_edge_offset (HTMLObject *o, int offset)
+html_text_get_left_edge_offset (HTMLObject *o, HTMLPainter *painter, int offset)
 {
 	HTMLTextSlave *slave = html_text_get_slave_at_offset (HTML_TEXT (o), NULL, offset);
 
 	if (slave) {
-		return html_text_slave_get_left_edge_offset (slave);
+		return html_text_slave_get_left_edge_offset (slave, painter);
 	} else {
 		g_warning ("getting left edge offset from text object without slave(s)");
 
Index: htmltextslave.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmltextslave.c,v
retrieving revision 1.188
diff -u -p -r1.188 htmltextslave.c
--- htmltextslave.c	21 Feb 2005 17:44:41 -0000	1.188
+++ htmltextslave.c	7 Mar 2005 16:59:32 -0000
@@ -1255,11 +1255,11 @@ html_text_slave_gi_right_edge (HTMLTextS
 }
 
 static gboolean
-html_text_slave_cursor_right_one (HTMLTextSlave *slave, HTMLCursor *cursor)
+html_text_slave_cursor_right_one (HTMLTextSlave *slave, HTMLPainter *painter, HTMLCursor *cursor)
 {
 	HTMLTextSlaveGlyphItem *prev, *next;
 	int index;
-	HTMLTextSlaveGlyphItem *gi = html_text_slave_get_glyph_item_at_offset (slave, NULL, cursor->offset - slave->posStart, &prev, &next, NULL, &index);
+	HTMLTextSlaveGlyphItem *gi = html_text_slave_get_glyph_item_at_offset (slave, painter, cursor->offset - slave->posStart, &prev, &next, NULL, &index);
 
 	if (!gi)
 		return FALSE;
@@ -1302,24 +1302,24 @@ html_text_slave_cursor_right_one (HTMLTe
 }
 
 gboolean
-html_text_slave_cursor_right (HTMLTextSlave *slave, HTMLCursor *cursor)
+html_text_slave_cursor_right (HTMLTextSlave *slave, HTMLPainter *painter, HTMLCursor *cursor)
 {
-	HTMLTextPangoInfo *pi = html_text_get_pango_info (slave->owner, NULL);
+	HTMLTextPangoInfo *pi = html_text_get_pango_info (slave->owner, painter);
 	gboolean step_success;
 
 	do
-		step_success = html_text_slave_cursor_right_one (slave, cursor);
+		step_success = html_text_slave_cursor_right_one (slave, painter, cursor);
 	while (step_success && !pi->attrs [cursor->offset].is_cursor_position);
 
 	return step_success;
 }
 
 static gboolean
-html_text_slave_cursor_left_one (HTMLTextSlave *slave, HTMLCursor *cursor)
+html_text_slave_cursor_left_one (HTMLTextSlave *slave, HTMLPainter *painter, HTMLCursor *cursor)
 {
 	HTMLTextSlaveGlyphItem *prev, *next;
 	int index;
-	HTMLTextSlaveGlyphItem *gi = html_text_slave_get_glyph_item_at_offset (slave, NULL, cursor->offset - slave->posStart, &prev, &next, NULL, &index);
+	HTMLTextSlaveGlyphItem *gi = html_text_slave_get_glyph_item_at_offset (slave, painter, cursor->offset - slave->posStart, &prev, &next, NULL, &index);
 
 /* 	printf ("gi: %p item num chars: %d\n", gi, gi ? gi->glyph_item.item->num_chars : -1); */
 
@@ -1366,31 +1366,31 @@ html_text_slave_cursor_left_one (HTMLTex
 }
 
 gboolean
-html_text_slave_cursor_left (HTMLTextSlave *slave, HTMLCursor *cursor)
+html_text_slave_cursor_left (HTMLTextSlave *slave, HTMLPainter *painter, HTMLCursor *cursor)
 {
-	HTMLTextPangoInfo *pi = html_text_get_pango_info (slave->owner, NULL);
+	HTMLTextPangoInfo *pi = html_text_get_pango_info (slave->owner, painter);
 	gboolean step_success;
 
 	do
-		step_success = html_text_slave_cursor_left_one (slave, cursor);
+		step_success = html_text_slave_cursor_left_one (slave, painter, cursor);
 	while (step_success && !pi->attrs [cursor->offset].is_cursor_position);
 
 	return step_success;
 }
 
 static gboolean
-html_text_slave_get_left_edge (HTMLTextSlave *slave, HTMLCursor *cursor)
+html_text_slave_get_left_edge (HTMLTextSlave *slave, HTMLPainter *painter, HTMLCursor *cursor)
 {
-	HTMLTextPangoInfo *pi = html_text_get_pango_info (slave->owner, NULL);
+	HTMLTextPangoInfo *pi = html_text_get_pango_info (slave->owner, painter);
 	int old_offset = cursor->offset;
 	int old_position = cursor->position;
 
-	cursor->offset = html_text_slave_get_left_edge_offset (slave);
+	cursor->offset = html_text_slave_get_left_edge_offset (slave, painter);
 
 	if (pi->attrs [cursor->offset].is_cursor_position && old_offset != cursor->offset)
 		return TRUE;
 	else {
-		if (html_text_slave_cursor_right (slave, cursor)) {
+		if (html_text_slave_cursor_right (slave, painter, cursor)) {
 			/* we should preserve position here as caller function correct position themselves */
 			cursor->position = old_position;
 			return TRUE;
@@ -1400,18 +1400,18 @@ html_text_slave_get_left_edge (HTMLTextS
 }
 
 static gboolean
-html_text_slave_get_right_edge (HTMLTextSlave *slave, HTMLCursor *cursor)
+html_text_slave_get_right_edge (HTMLTextSlave *slave, HTMLPainter *painter, HTMLCursor *cursor)
 {
-	HTMLTextPangoInfo *pi = html_text_get_pango_info (slave->owner, NULL);
+	HTMLTextPangoInfo *pi = html_text_get_pango_info (slave->owner, painter);
 	int old_offset = cursor->offset;
 	int old_position = cursor->position;
 
-	cursor->offset = html_text_slave_get_right_edge_offset (slave);
+	cursor->offset = html_text_slave_get_right_edge_offset (slave, painter);
 
 	if (pi->attrs [cursor->offset].is_cursor_position && old_offset != cursor->offset)
 		return TRUE;
 	else {
-		if (html_text_slave_cursor_left (slave, cursor)) {
+		if (html_text_slave_cursor_left (slave, painter, cursor)) {
 			/* we should preserve position here as caller function correct position themselves */
 			cursor->position = old_position;
 			return TRUE;
@@ -1421,17 +1421,17 @@ html_text_slave_get_right_edge (HTMLText
 }
 
 gboolean
-html_text_slave_cursor_head (HTMLTextSlave *slave, HTMLCursor *cursor)
+html_text_slave_cursor_head (HTMLTextSlave *slave, HTMLCursor *cursor, HTMLPainter *painter)
 {
-	if (html_text_slave_get_glyph_items (slave, NULL)) {
+	if (html_text_slave_get_glyph_items (slave, painter)) {
 		cursor->object = HTML_OBJECT (slave->owner);
 
 		if (html_text_get_pango_direction (slave->owner) != PANGO_DIRECTION_RTL) {
 			/* LTR */
-			return html_text_slave_get_left_edge (slave, cursor);
+			return html_text_slave_get_left_edge (slave, painter, cursor);
 		} else {
 			/* RTL */
-			return html_text_slave_get_right_edge (slave, cursor);
+			return html_text_slave_get_right_edge (slave, painter, cursor);
 		}
 	}
 
@@ -1439,17 +1439,17 @@ html_text_slave_cursor_head (HTMLTextSla
 }
 
 gboolean
-html_text_slave_cursor_tail (HTMLTextSlave *slave, HTMLCursor *cursor)
+html_text_slave_cursor_tail (HTMLTextSlave *slave, HTMLCursor *cursor, HTMLPainter *painter)
 {
-	if (html_text_slave_get_glyph_items (slave, NULL)) {
+	if (html_text_slave_get_glyph_items (slave, painter)) {
 		cursor->object = HTML_OBJECT (slave->owner);
 
 		if (html_text_get_pango_direction (slave->owner) != PANGO_DIRECTION_RTL) {
 			/* LTR */
-			return html_text_slave_get_right_edge (slave, cursor);
+			return html_text_slave_get_right_edge (slave, painter, cursor);
 		} else {
 			/* RTL */
-			return html_text_slave_get_left_edge (slave, cursor);
+			return html_text_slave_get_left_edge (slave, painter, cursor);
 		}
 	}
 
@@ -1481,9 +1481,9 @@ html_text_slave_get_cursor_base (HTMLTex
 }
 
 int
-html_text_slave_get_left_edge_offset (HTMLTextSlave *slave)
+html_text_slave_get_left_edge_offset (HTMLTextSlave *slave, HTMLPainter *painter)
 {
-	GSList *gis = html_text_slave_get_glyph_items (slave, NULL);
+	GSList *gis = html_text_slave_get_glyph_items (slave, painter);
 
 	if (gis) {
 		HTMLTextSlaveGlyphItem *gi = (HTMLTextSlaveGlyphItem *) gis->data;
@@ -1493,8 +1493,9 @@ html_text_slave_get_left_edge_offset (HT
 			return slave->posStart + g_utf8_pointer_to_offset (html_text_slave_get_text (slave), slave->owner->text + gi->glyph_item.item->offset);
 		} else {
 			/* RTL */
-			return slave->posStart + g_utf8_pointer_to_offset (html_text_slave_get_text (slave),
-									   slave->owner->text + gi->glyph_item.item->offset + gi->glyph_item.item->length);
+			return slave->posStart + MIN (slave->posLen, g_utf8_pointer_to_offset (html_text_slave_get_text (slave),
+											       slave->owner->text
+											       + gi->glyph_item.item->offset + gi->glyph_item.item->length));
 		}
 	} else {
 		if (slave->owner->text_len > 0)
@@ -1505,17 +1506,18 @@ html_text_slave_get_left_edge_offset (HT
 }
 
 int
-html_text_slave_get_right_edge_offset (HTMLTextSlave *slave)
+html_text_slave_get_right_edge_offset (HTMLTextSlave *slave, HTMLPainter *painter)
 {
-	GSList *gis = html_text_slave_get_glyph_items (slave, NULL);
+	GSList *gis = html_text_slave_get_glyph_items (slave, painter);
 
 	if (gis) {
 		HTMLTextSlaveGlyphItem *gi = (HTMLTextSlaveGlyphItem *) g_slist_last (gis)->data;
 
 		if (gi->glyph_item.item->analysis.level % 2 == 0) {
 			/* LTR */
-			return slave->posStart + g_utf8_pointer_to_offset (html_text_slave_get_text (slave),
-									   slave->owner->text + gi->glyph_item.item->offset + gi->glyph_item.item->length);
+			return slave->posStart + MIN (slave->posLen, g_utf8_pointer_to_offset (html_text_slave_get_text (slave),
+											       slave->owner->text
+											       + gi->glyph_item.item->offset + gi->glyph_item.item->length));
 		} else {
 			/* RTL */
 			return slave->posStart + g_utf8_pointer_to_offset (html_text_slave_get_text (slave), slave->owner->text + gi->glyph_item.item->offset);
Index: htmltextslave.h
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmltextslave.h,v
retrieving revision 1.25
diff -u -p -r1.25 htmltextslave.h
--- htmltextslave.h	25 Jan 2005 15:09:40 -0000	1.25
+++ htmltextslave.h	7 Mar 2005 16:59:32 -0000
@@ -87,18 +87,24 @@ GList      *html_get_glyphs_non_tab     
 GSList     *html_text_slave_get_glyph_items       (HTMLTextSlave      *slave,
 						   HTMLPainter        *painter);
 gboolean    html_text_slave_cursor_right          (HTMLTextSlave      *slave,
+						   HTMLPainter        *painter,
 						   HTMLCursor         *cursor);
 gboolean    html_text_slave_cursor_left           (HTMLTextSlave      *slave,
+						   HTMLPainter        *painter,
 						   HTMLCursor         *cursor);
 gboolean    html_text_slave_cursor_head           (HTMLTextSlave      *slave,
-						   HTMLCursor         *cursor);
+						   HTMLCursor         *cursor,
+						   HTMLPainter        *painter);
 gboolean    html_text_slave_cursor_tail           (HTMLTextSlave      *slave,
-						   HTMLCursor         *cursor);
+						   HTMLCursor         *cursor,
+						   HTMLPainter        *painter);
 void        html_text_slave_get_cursor_base       (HTMLTextSlave      *slave,
 						   HTMLPainter        *painter,
 						   guint               offset,
 						   gint               *x,
 						   gint               *y);
-int         html_text_slave_get_left_edge_offset  (HTMLTextSlave      *slave);
-int         html_text_slave_get_right_edge_offset (HTMLTextSlave      *slave);
+int         html_text_slave_get_left_edge_offset  (HTMLTextSlave      *slave,
+						   HTMLPainter        *painter);
+int         html_text_slave_get_right_edge_offset (HTMLTextSlave      *slave,
+						   HTMLPainter        *painter);
 #endif /* _HTMLTEXTSLAVE_H_ */

--- End Message ---


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