Re: [evolution-patches] Patch to enable cursor and keyboard navigation in mail reader,(v8)



I last find that it's not a good idea to implement it in
html_object_get_cursor(), because the method is used somewhere else. May
cause some side effect.  So I want to still put it in the
html_engine_show_cursor_in_area(). But change to
,                                                                                
        html_object_get_cursor (obj, engine->painter, offset, &x1, &y1,
&x2, &y2);
+       while (obj) {
+               if (html_object_is_frame(obj)) {
+                       x1 -= HTML_EMBEDDED(obj)->abs_x;
+                       x2 -= HTML_EMBEDDED(obj)->abs_x;
+                       y1 -= HTML_EMBEDDED(obj)->abs_y;
+                       y2 -= HTML_EMBEDDED(obj)->abs_y;
+                       break;
+               }
+                obj = obj->parent;
+        }
                                                                                
Now, I have the patch re-attached, please review.



> > > +       if (obj) {
> > > +               HTMLEmbedded * element;
> > > +
> > > +               element = HTML_EMBEDDED(obj);
> > > +               x1 -= element->abs_x;
> > > +               x2 -= element->abs_x;
> > > +               y1 -= element->abs_y;
> > > +               y2 -= element->abs_y;
> > > +       }
> > 
> > I think this could be rather implemented as part of get_cursor of embedded object?
> 
> Because the focused object is not the embedded object, so I cannot
> implement it into embeded object's get_cursor. But it can be implemented
> in get_cursor of htmlobject.


> 
> Now I change it as below, deprecate using of "embeddedelement" on
> g_object. Much cleaner I think.
> 
> 
> 
> > >  -- src/htmlobject.c    1 May 2003 16:41:23 -0000       1.160
> +++ src/htmlobject.c    3 Jul 2003 10:42:41 -0000
> @@ -1080,6 +1080,17 @@
>                 *y1 -= (missing >> 1) + ((missing >> 1) & 1);
>                 *y2 += missing >> 1;
>         }
> +
> +       while (self) {
> +               if (html_object_is_frame(self)) {
> +                       *x1 -= HTML_EMBEDDED(self)->abs_x;
> +                       *x2 -= HTML_EMBEDDED(self)->abs_x;
> +                       *y1 -= HTML_EMBEDDED(self)->abs_y;
> +                       *y2 -= HTML_EMBEDDED(self)->abs_y;
> +                       break;
> +               }
> +               self = self->parent;
> +       }
> }
Index: gtkhtml.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/gtkhtml.c,v
retrieving revision 1.521
diff -u -r1.521 gtkhtml.c
--- gtkhtml.c	27 Jun 2003 15:51:06 -0000	1.521
+++ gtkhtml.c	7 Jul 2003 08:13:33 -0000
@@ -760,11 +760,35 @@
 	g_free (fixed_name);
 }
 
+static void
+set_caret_mode(HTMLEngine *engine, gboolean caret_mode)
+{
+	if (engine->editable)
+		return;
+
+	engine->caret_mode = caret_mode;
+
+	if (caret_mode && !engine->parsing && !engine->timerId == 0)
+		gtk_html_edit_make_cursor_visible(engine->widget);
+
+	/* Normally, blink cursor handler is setup in focus in event.
+	 * However, in the case focus already in this engine, and user
+	 * type F7 to enable cursor, we must setup the handler by
+	 * ourselves.
+	 */
+	if (caret_mode && !engine->blinking_timer_id && engine->have_focus)
+		html_engine_setup_blinking_cursor (engine);
+
+
+	return;
+}
+
 /* GtkWidget methods.  */
 static void
 style_set (GtkWidget *widget, GtkStyle  *previous_style)
 {
 	HTMLEngine *engine = GTK_HTML (widget)->engine;
+	gboolean caret_mode = FALSE;
 
 	/* we don't need to set font's in idle time so call idle callback directly to avoid
 	   recalculating whole document
@@ -779,6 +803,8 @@
 		}
 	}
 
+	gtk_widget_style_get (widget, "caret_mode", &caret_mode, NULL);
+	set_caret_mode(engine, caret_mode);
 
 	html_colorset_set_style (engine->defaultSettings->color_set, widget);
 	html_colorset_set_unchanged (engine->settings->color_set,
@@ -1485,8 +1511,11 @@
 				if (obj && ((HTML_IS_IMAGE (obj) && HTML_IMAGE (obj)->url && *HTML_IMAGE (obj)->url)
 					    || HTML_IS_LINK_TEXT (obj)))
 					html_engine_set_focus_object (orig_e, obj);
-				else
+				else {
 					html_engine_set_focus_object (orig_e, NULL);
+					if (orig_e->caret_mode)
+						html_engine_jump_at (engine, x, y);
+				}
 			}
 			if (html->allow_selection) {
 				if (event->state & GDK_SHIFT_MASK)
@@ -2605,6 +2634,13 @@
 								     _("The color of the spelling error markers"),
 								     GDK_TYPE_COLOR,
 								     G_PARAM_READABLE));
+	gtk_widget_class_install_style_property (widget_class,
+						g_param_spec_boxed ("caret_mode",
+								    _("Caret Mode"),
+								    _("Enable cursor when reading mail"),
+								    G_TYPE_BOOLEAN,
+								    G_PARAM_READABLE));
+
 
 	widget_class->realize = realize;
 	widget_class->unrealize = unrealize;
@@ -3794,9 +3830,6 @@
 cursor_move (GtkHTML *html, GtkDirectionType dir_type, GtkHTMLCursorSkipType skip)
 {
 	gint amount;
-
-	if (!html_engine_get_editable (html->engine))
-		return;
 
 	if (html->engine->selection_mode) {
 		if (!html->engine->mark)
Index: htmlengine-edit-cursor.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmlengine-edit-cursor.c,v
retrieving revision 1.22
diff -u -r1.22 htmlengine-edit-cursor.c
--- htmlengine-edit-cursor.c	2 Apr 2003 05:41:47 -0000	1.22
+++ htmlengine-edit-cursor.c	7 Jul 2003 08:13:33 -0000
@@ -31,6 +31,7 @@
 #include "htmlimage.h"
 #include "htmlobject.h"
 #include "htmltable.h"
+#include "htmlembedded.h"
 
 #define BLINK_TIMEOUT 500
 
@@ -50,11 +51,21 @@
 void
 html_engine_hide_cursor  (HTMLEngine *engine)
 {
+	HTMLEngine *e = engine;
+
 	g_return_if_fail (engine != NULL);
 	g_return_if_fail (HTML_IS_ENGINE (engine));
 
-	if (engine->editable && engine->cursor_hide_count == 0)
-		html_engine_draw_cursor_in_area (engine, 0, 0, -1, -1);
+	if ((engine->editable || engine->caret_mode) && engine->cursor_hide_count == 0) {
+		if (!engine->editable) {
+			e = html_object_engine(engine->cursor->object, NULL);
+			if (e) {
+				e->caret_mode = engine->caret_mode;
+				html_cursor_copy(e->cursor, engine->cursor);
+			} else 	e = engine;
+		}
+		html_engine_draw_cursor_in_area (e, 0, 0, -1, -1);
+	}
 
 	engine->cursor_hide_count++;
 }
@@ -62,22 +73,37 @@
 void
 html_engine_show_cursor  (HTMLEngine *engine)
 {
+        HTMLEngine * e = engine;
+
 	g_return_if_fail (engine != NULL);
 	g_return_if_fail (HTML_IS_ENGINE (engine));
+	g_return_if_fail (engine->cursor != NULL);
 
 	if (engine->cursor_hide_count > 0) {
 		engine->cursor_hide_count--;
-		if (engine->editable && engine->cursor_hide_count == 0)
-			html_engine_draw_cursor_in_area (engine, 0, 0, -1, -1);
+		if ((engine->editable || engine->caret_mode) && engine->cursor_hide_count == 0) {
+			if (!engine->editable) {
+				e = html_object_engine(engine->cursor->object, NULL);
+				if (e) {
+					e->caret_mode = engine->caret_mode;
+					html_cursor_copy(e->cursor, engine->cursor);
+				} else e = engine;
+			}
+			html_engine_draw_cursor_in_area (e, 0, 0, -1, -1);
+		}
 	}
 }
 
 static gboolean
 clip_rect (HTMLEngine *engine, gint x, gint y, gint width, gint height, gint *x1, gint *y1, gint *x2, gint *y2)
 {
-	if (*x1 >= x + width || *y1 >= y + height || *x2 < x || *y2 < y)
+	if (*x1 > x + width || *y1 > y + height || *x2 < x || *y2 < y)
 		return FALSE;
 
+	if (*x1 == x + width)
+		*x1 = x + width - 1;
+	if (*y1 == y + width)
+		*y1 = y + height - 1;
 	if (*x2 >= x + width)
 		*x2 = x + width - 1;
 	if (*y2 >= y + height)
@@ -265,15 +291,13 @@
 	gint x1, y1, x2, y2;
 	GdkRectangle pos;
 
-	g_assert (engine->editable);
-
-	if (engine->editable && (engine->cursor_hide_count <= 0 && !engine->thaw_idle_id)) {
+	if ((engine->editable || engine->caret_mode) && (engine->cursor_hide_count <= 0 && !engine->thaw_idle_id)) {
 		html_engine_draw_table_cursor (engine);
 		html_engine_draw_cell_cursor (engine);
 		html_engine_draw_image_cursor (engine);
 	}
 
-	if (!cursor_enabled || engine->cursor_hide_count > 0 || ! engine->editable || engine->thaw_idle_id)
+	if (!cursor_enabled || engine->cursor_hide_count > 0 || !(engine->editable || engine->caret_mode) || engine->thaw_idle_id)
 		return;
 
 	obj = engine->cursor->object;
@@ -291,6 +315,16 @@
 
 	
 	html_object_get_cursor (obj, engine->painter, offset, &x1, &y1, &x2, &y2);
+	while (obj) {
+		if (html_object_is_frame(obj)) {
+			x1 -= HTML_EMBEDDED(obj)->abs_x;
+			x2 -= HTML_EMBEDDED(obj)->abs_x;
+			y1 -= HTML_EMBEDDED(obj)->abs_y;
+			y2 -= HTML_EMBEDDED(obj)->abs_y;
+			break;
+		}
+                obj = obj->parent;
+        }
 	
 	pos.x = x1; 
 	pos.y = y1;
Index: htmlengine-edit-movement.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmlengine-edit-movement.c,v
retrieving revision 1.15
diff -u -r1.15 htmlengine-edit-movement.c
--- htmlengine-edit-movement.c	25 Apr 2001 21:31:53 -0000	1.15
+++ htmlengine-edit-movement.c	7 Jul 2003 08:13:33 -0000
@@ -275,8 +275,10 @@
 		if (new_y == y)
 			break;
 
-		if (new_y < start_y)
+		if (new_y < start_y) {
+			html_engine_show_cursor (engine);
 			return 0;
+		}
 
 		if (new_y - start_y >= amount) {
 			html_cursor_copy (cursor, &prev_cursor);
Index: htmlengine.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmlengine.c,v
retrieving revision 1.545
diff -u -r1.545 htmlengine.c
--- htmlengine.c	25 Jun 2003 18:15:46 -0000	1.545
+++ htmlengine.c	7 Jul 2003 08:13:43 -0000
@@ -3583,6 +3583,7 @@
 	engine->allow_frameset = FALSE;
 
 	engine->editable = FALSE;
+	engine->caret_mode = FALSE;
 	engine->clipboard = NULL;
 	engine->clipboard_stack = NULL;
 	engine->selection_stack  = NULL;
@@ -4603,12 +4604,14 @@
 		html_engine_ensure_editable (e);
 		html_cursor_home (e->cursor, e);
 		e->newPage = FALSE;
-
 		if (e->have_focus)
 			html_engine_setup_blinking_cursor (e);
 	} else {
-		if (e->have_focus)
-			html_engine_stop_blinking_cursor (e);
+		if (e->have_focus )
+			if (e->caret_mode)
+				html_engine_setup_blinking_cursor (e);
+			else 
+				html_engine_stop_blinking_cursor (e);
 	}
 }
 
@@ -4640,7 +4643,7 @@
 	g_return_if_fail (engine != NULL);
 	g_return_if_fail (HTML_IS_ENGINE (engine));
 
-	if (engine->editable) {
+	if (engine->editable || engine->caret_mode) {
 		if (! engine->have_focus && have_focus)
 			html_engine_setup_blinking_cursor (engine);
 		else if (engine->have_focus && ! have_focus)
@@ -4680,7 +4683,7 @@
 
 	g_return_val_if_fail (e != NULL, FALSE);
 
-	if (! e->editable)
+	if (! e->editable && !e->caret_mode)
 		return FALSE;
 
 	if (e->cursor->object == NULL)
Index: htmlengine.h
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmlengine.h,v
retrieving revision 1.168
diff -u -r1.168 htmlengine.h
--- htmlengine.h	19 May 2003 12:58:36 -0000	1.168
+++ htmlengine.h	7 Jul 2003 08:13:43 -0000
@@ -65,6 +65,7 @@
 	GdkGC *invert_gc;
 
 	gboolean editable;
+	gboolean caret_mode;
 
 	HTMLObject *clipboard;
 	guint       clipboard_len;
Index: htmliframe.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmliframe.c,v
retrieving revision 1.74
diff -u -r1.74 htmliframe.c
--- htmliframe.c	19 May 2003 13:12:04 -0000	1.74
+++ htmliframe.c	7 Jul 2003 08:13:44 -0000
@@ -592,6 +592,7 @@
 
 	new_widget = gtk_html_new ();
 	new_html = GTK_HTML (new_widget);
+	new_html->engine->cursor_hide_count = 0;
 
 	new_tokenizer = html_tokenizer_clone (parent_html->engine->ht);
 


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