aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchris <chris@e22d1c8e-a203-0410-8502-864332bf3fbf>2006-05-18 18:19:56 +0000
committerchris <chris@e22d1c8e-a203-0410-8502-864332bf3fbf>2006-05-18 18:19:56 +0000
commit6658001923050d17cfe846056fcfbcc0f8c3d9f2 (patch)
tree8f19a8a4d9c56e1809800df950d3ac3d4b52c4b9
parent4060b49bf900a5abdb35b68b99b2bc319d09e88c (diff)
downloadweb-sato-6658001923050d17cfe846056fcfbcc0f8c3d9f2.tar.gz
web-sato-6658001923050d17cfe846056fcfbcc0f8c3d9f2.tar.bz2
web-sato-6658001923050d17cfe846056fcfbcc0f8c3d9f2.zip
- Add edit toggle to tool-button
- Add push-scroll and jitter correction features git-svn-id: https://svn.o-hand.com/repos/web/trunk@93 e22d1c8e-a203-0410-8502-864332bf3fbf
-rw-r--r--ChangeLog12
-rw-r--r--data/web.glade19
-rw-r--r--src/gtkhtml2/web_gtkhtml2.c10
-rw-r--r--src/web.h8
-rw-r--r--src/web_main.c109
5 files changed, 146 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 469d63b..2f4ab1c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2006-05-18 Chris Lord,,, <chris@openedhand.com>
+
+ * data/web.glade:
+ - Add edit toggle to tool-button
+
+ * src/gtkhtml2/web_gtkhtml2.c: (web_gtkhtml2_new):
+ * src/web.h:
+ * src/web_main.c: (web_new_tab_switch_idle),
+ (web_page_button_press_cb), (web_page_motion_notify_cb),
+ (web_page_button_release_cb), (web_new_tab_cb), (main):
+ - Add push-scroll and jitter correction features
+
2006-05-10 Chris Lord,,, <chris@openedhand.com>
* data/ssr.user.js:
diff --git a/data/web.glade b/data/web.glade
index 4b28a43..c21b1d7 100644
--- a/data/web.glade
+++ b/data/web.glade
@@ -8,7 +8,7 @@
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
- <property name="default_width">360</property>
+ <property name="default_width">400</property>
<property name="default_height">480</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
@@ -858,6 +858,21 @@
</child>
<child>
+ <widget class="GtkToggleToolButton" id="edit_button">
+ <property name="visible">True</property>
+ <property name="stock_id">gtk-edit</property>
+ <property name="visible_horizontal">True</property>
+ <property name="visible_vertical">True</property>
+ <property name="is_important">False</property>
+ <property name="active">False</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
+
+ <child>
<widget class="GtkToolButton" id="zoomout_button">
<property name="visible">True</property>
<property name="stock_id">gtk-zoom-out</property>
@@ -888,7 +903,7 @@
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
- <property name="fill">False</property>
+ <property name="fill">True</property>
</packing>
</child>
</widget>
diff --git a/src/gtkhtml2/web_gtkhtml2.c b/src/gtkhtml2/web_gtkhtml2.c
index 11b2be5..1cce591 100644
--- a/src/gtkhtml2/web_gtkhtml2.c
+++ b/src/gtkhtml2/web_gtkhtml2.c
@@ -265,12 +265,6 @@ web_gtkhtml2_new (gpointer backend_data_p, gpointer *page_data_pointer,
page_data->view = HTML_VIEW (html_view_new ());
page_data->data = data;
- /* Create scrolled html view */
- scroll = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
- GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- gtk_container_add (GTK_CONTAINER (scroll),
- GTK_WIDGET (page_data->view));
html_view_set_document (page_data->view, page_data->document);
/* Note: Need to set a blank page, or setting page magnification won't
@@ -302,9 +296,9 @@ web_gtkhtml2_new (gpointer backend_data_p, gpointer *page_data_pointer,
g_signal_connect (G_OBJECT (page_data->document), "submit",
G_CALLBACK (web_gtkhtml2_submit_cb), data);
- gtk_widget_show_all (scroll);
+ gtk_widget_show_all (page_data->view);
- return scroll;
+ return page_data->view;
}
static void
diff --git a/src/web.h b/src/web.h
index 61f7a76..ce96195 100644
--- a/src/web.h
+++ b/src/web.h
@@ -109,6 +109,14 @@ struct _WebData {
GList *history_forward;
gpointer ssr_style;
gpointer ssr_script;
+
+ /* Variables for jitter-correction/push-scrolling */
+ GtkScrolledWindow *scroll;
+ GTimeVal click_start;
+ gdouble x;
+ gdouble y;
+ gboolean moved;
+ gboolean clicked;
};
struct _WebPages {
diff --git a/src/web_main.c b/src/web_main.c
index ad1b8d1..ca6730a 100644
--- a/src/web_main.c
+++ b/src/web_main.c
@@ -485,6 +485,97 @@ web_new_tab_switch_idle (gpointer data)
return FALSE;
}
+static gboolean
+web_page_button_press_cb (GtkWidget *page, GdkEventButton *event, WebData *data)
+{
+ GtkWidget *widget = glade_xml_get_widget (data->parent->xml,
+ "edit_button");
+
+ if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (widget)))
+ return FALSE;
+ if (data->clicked) return FALSE;
+
+ /* TODO: A right-click context menu, middle-click open in new tab? */
+ if (event->button != 1) return TRUE;
+
+ g_get_current_time (&data->click_start);
+ data->x = event->x_root;
+ data->y = event->y_root;
+ data->moved = FALSE;
+ data->clicked = TRUE;
+
+ return TRUE;
+}
+
+static gboolean
+web_page_motion_notify_cb (GtkWidget *page, GdkEventMotion *event,
+ WebData *data)
+{
+ GtkWidget *widget = glade_xml_get_widget (data->parent->xml,
+ "edit_button");
+
+ if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (widget)))
+ return FALSE;
+ if (!data->clicked) return FALSE;
+
+ if ((abs (event->x_root - data->x) > 3) ||
+ (abs (event->y_root - data->y) > 3)) {
+ data->moved = TRUE;
+ }
+
+ if (data->moved) {
+ gdouble h, v;
+ GtkAdjustment *hadjust = gtk_scrolled_window_get_hadjustment (
+ GTK_SCROLLED_WINDOW (data->scroll));
+ GtkAdjustment *vadjust = gtk_scrolled_window_get_vadjustment (
+ GTK_SCROLLED_WINDOW (data->scroll));
+ h = gtk_adjustment_get_value (hadjust) +
+ (2*(event->x_root - data->x));
+ v = gtk_adjustment_get_value (vadjust) +
+ (2*(event->y_root - data->y));
+ data->x = event->x_root;
+ data->y = event->y_root;
+ if ((h >= hadjust->lower) &&
+ (h <= (hadjust->upper - hadjust->page_size)))
+ gtk_adjustment_set_value (hadjust, h);
+ if ((v >= vadjust->lower) &&
+ (v <= (vadjust->upper - vadjust->page_size)))
+ gtk_adjustment_set_value (vadjust, v);
+ }
+
+ return TRUE;
+}
+
+static gboolean
+web_page_button_release_cb (GtkWidget *page, GdkEventButton *event,
+ WebData *data)
+{
+ GTimeVal current;
+ GtkWidget *widget = glade_xml_get_widget (data->parent->xml,
+ "edit_button");
+
+ if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (widget)))
+ return FALSE;
+ if (!data->clicked) return FALSE;
+ if (event->button != 1) return TRUE;
+
+ g_get_current_time (&current);
+
+ if ((!data->moved) &&
+ ((current.tv_sec > data->click_start.tv_sec) ||
+ (current.tv_usec - data->click_start.tv_usec > 500))) {
+ /* Send synthetic click event to avoid jitter */
+ event->type = GDK_BUTTON_PRESS;
+ gtk_widget_event (page, (GdkEvent *)event);
+ data->clicked = FALSE;
+ event->type = GDK_BUTTON_RELEASE;
+ gtk_widget_event (page, (GdkEvent *)event);
+ }
+ data->clicked = FALSE;
+
+ return TRUE;
+}
+
static void
web_new_tab_cb (GtkWidget *source, WebPages *wdata)
{
@@ -508,6 +599,12 @@ web_new_tab_cb (GtkWidget *source, WebPages *wdata)
wdata->backend->set_zoom (wdata->backend_data, data->page_data,
wdata->last_zoom);
+ /* Attach to mouse-button signals for jitter correction and such */
+ g_signal_connect (G_OBJECT (widget), "button-press-event",
+ G_CALLBACK (web_page_button_press_cb), data);
+ g_signal_connect (G_OBJECT (widget), "button-release-event",
+ G_CALLBACK (web_page_button_release_cb), data);
+
/* Create close button */
button = gtk_button_new ();
close_image = gtk_image_new_from_stock (
@@ -532,9 +629,17 @@ web_new_tab_cb (GtkWidget *source, WebPages *wdata)
gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
gtk_box_pack_end (GTK_BOX (box), align, TRUE, TRUE, 0);
+ /* Create scrollview */
+ data->scroll = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (data->scroll),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_container_add (GTK_CONTAINER (data->scroll), widget);
+ g_signal_connect (G_OBJECT (data->scroll), "motion-notify-event",
+ G_CALLBACK (web_page_motion_notify_cb), data);
+
/* Create vpaned and vbox */
data->vpaned = gtk_vpaned_new ();
- gtk_paned_add2 (GTK_PANED (data->vpaned), widget);
+ gtk_paned_add2 (GTK_PANED (data->vpaned), data->scroll);
data->vbox = gtk_vbox_new (FALSE, 0);
gtk_box_pack_end (GTK_BOX (data->vbox),
GTK_WIDGET (data->vpaned), TRUE, TRUE, 0);
@@ -840,7 +945,7 @@ main (int argc, char **argv)
pages.book = GTK_NOTEBOOK (
glade_xml_get_widget (pages.xml, "pages_notebook"));
- /* Set transient parents for about/preferences dialogs and hide them */
+ /* Set transient parents for about/preferences dialogs */
gtk_window_set_transient_for (
GTK_WINDOW (glade_xml_get_widget (pages.xml, "about_dialog")),
GTK_WINDOW (pages.window));