Implement drag (finger) and kinetic scrolling with KatzeScrolled

The feature is primarily interesting for mobile devices and
by default enabled with gtk-touchscreen-mode.
This commit is contained in:
Christian Dywan 2009-09-27 23:48:08 +02:00
parent 7259066e20
commit 96093d9067
7 changed files with 1203 additions and 12 deletions

1086
katze/katze-scrolled.c Normal file

File diff suppressed because it is too large Load diff

59
katze/katze-scrolled.h Normal file
View file

@ -0,0 +1,59 @@
/*
Copyright (C) 2007 Henrik Hedberg <hhedberg@innologies.fi>
Copyright (C) 2009 Nadav Wiener <nadavwr@yahoo.com>
Copyright (C) 2009 Christian Dywan <christian@twotoasts.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
See the file COPYING for the full license text.
*/
#ifndef KATZE_SCROLLED_H
#define KATZE_SCROLLED_H
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define KATZE_TYPE_SCROLLED (katze_scrolled_get_type())
#define KATZE_SCROLLED(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), KATZE_TYPE_SCROLLED, KatzeScrolled))
#define KATZE_SCROLLED_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), KATZE_TYPE_SCROLLED, KatzeScrolledClass))
#define KATZE_IS_SCROLLED(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), KATZE_TYPE_SCROLLED))
#define KATZE_IS_SCROLLED_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), KATZE_TYPE_SCROLLED))
#define KATZE_SCROLLED_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), KATZE_TYPE_SCROLLED, KatzeScrolledClass))
typedef struct _KatzeScrolled KatzeScrolled;
typedef struct _KatzeScrolledClass KatzeScrolledClass;
typedef struct _KatzeScrolledPrivate KatzeScrolledPrivate;
struct _KatzeScrolled
{
GtkScrolledWindow parent;
KatzeScrolledPrivate* priv;
};
struct _KatzeScrolledClass
{
GtkScrolledWindowClass parent;
/* Padding for future expansion */
void (*_katze_reserved1) (void);
void (*_katze_reserved2) (void);
void (*_katze_reserved3) (void);
void (*_katze_reserved4) (void);
};
GType
katze_scrolled_get_type (void);
GtkWidget*
katze_scrolled_new (GtkAdjustment* hadjustment,
GtkAdjustment* vadjustment);
G_END_DECLS
#endif /* __KATZE_SCROLLED_H__ */

View file

@ -21,5 +21,6 @@
#include "katze-arrayaction.h" #include "katze-arrayaction.h"
#include "katze-separatoraction.h" #include "katze-separatoraction.h"
#include "katze-net.h" #include "katze-net.h"
#include "katze-scrolled.h"
#endif /* __KATZE_H__ */ #endif /* __KATZE_H__ */

View file

@ -1554,9 +1554,6 @@ _midori_browser_add_tab (MidoriBrowser* browser,
KatzeItem* item; KatzeItem* item;
guint n; guint n;
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (view),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
GTK_WIDGET_SET_FLAGS (view, GTK_CAN_FOCUS); GTK_WIDGET_SET_FLAGS (view, GTK_CAN_FOCUS);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (view), gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (view),
GTK_SHADOW_ETCHED_IN); GTK_SHADOW_ETCHED_IN);

View file

@ -315,6 +315,9 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
GtkWidget* header; GtkWidget* header;
GtkWindow* parent; GtkWindow* parent;
const gchar* icon_name; const gchar* icon_name;
#if WEBKIT_CHECK_VERSION (1, 1, 15)
GtkSettings* gtk_settings;
#endif
GtkSizeGroup* sizegroup; GtkSizeGroup* sizegroup;
GtkWidget* toolbar; GtkWidget* toolbar;
GtkWidget* toolbutton; GtkWidget* toolbutton;
@ -341,6 +344,9 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
gtk_window_get_title (GTK_WINDOW (preferences))))) gtk_window_get_title (GTK_WINDOW (preferences)))))
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (preferences)->vbox), gtk_box_pack_start (GTK_BOX (GTK_DIALOG (preferences)->vbox),
header, FALSE, FALSE, 0); header, FALSE, FALSE, 0);
#if WEBKIT_CHECK_VERSION (1, 1, 15)
gtk_settings = parent ? gtk_widget_get_settings (GTK_WIDGET (parent)) : NULL;
#endif
preferences->notebook = gtk_notebook_new (); preferences->notebook = gtk_notebook_new ();
gtk_container_set_border_width (GTK_CONTAINER (preferences->notebook), 6); gtk_container_set_border_width (GTK_CONTAINER (preferences->notebook), 6);
@ -487,9 +493,14 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
gtk_widget_set_tooltip_text (button, _("Load and display images automatically")); gtk_widget_set_tooltip_text (button, _("Load and display images automatically"));
INDENTED_ADD (button, 0, 1, 0, 1); INDENTED_ADD (button, 0, 1, 0, 1);
#if WEBKIT_CHECK_VERSION (1, 1, 15) #if WEBKIT_CHECK_VERSION (1, 1, 15)
button = katze_property_proxy (settings, "auto-shrink-images", NULL); if (katze_object_get_boolean (gtk_settings, "gtk-touchscreen-mode"))
gtk_button_set_label (GTK_BUTTON (button), _("Shrink images automatically")); button = katze_property_proxy (settings, "kinetic-scrolling", NULL);
gtk_widget_set_tooltip_text (button, _("Automatically shrink standalone images to fit")); else
{
button = katze_property_proxy (settings, "auto-shrink-images", NULL);
gtk_button_set_label (GTK_BUTTON (button), _("Shrink images automatically"));
gtk_widget_set_tooltip_text (button, _("Automatically shrink standalone images to fit"));
}
#else #else
button = katze_property_proxy (settings, "middle-click-opens-selection", NULL); button = katze_property_proxy (settings, "middle-click-opens-selection", NULL);
#endif #endif

View file

@ -59,7 +59,7 @@ midori_view_item_meta_data_changed (KatzeItem* item,
struct _MidoriView struct _MidoriView
{ {
GtkScrolledWindow parent_instance; KatzeScrolled parent_instance;
gchar* uri; gchar* uri;
gchar* title; gchar* title;
@ -104,10 +104,10 @@ struct _MidoriView
struct _MidoriViewClass struct _MidoriViewClass
{ {
GtkScrolledWindowClass parent_class; KatzeScrolledClass parent_class;
}; };
G_DEFINE_TYPE (MidoriView, midori_view, GTK_TYPE_SCROLLED_WINDOW) G_DEFINE_TYPE (MidoriView, midori_view, KATZE_TYPE_SCROLLED);
GType GType
midori_load_status_get_type (void) midori_load_status_get_type (void)
@ -1525,6 +1525,9 @@ webkit_web_view_populate_popup_cb (WebKitWebView* web_view,
katze_object_assign (view->hit_test, katze_object_assign (view->hit_test,
webkit_web_view_get_hit_test_result (web_view, &event)); webkit_web_view_get_hit_test_result (web_view, &event));
context = katze_object_get_int (view->hit_test, "context"); context = katze_object_get_int (view->hit_test, "context");
/* Ensure view->link_uri is correct. */
katze_assign (view->link_uri,
katze_object_get_string (view->hit_test, "link-uri"));
has_selection = context & WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION; has_selection = context & WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION;
/* Ensure view->selected_text */ /* Ensure view->selected_text */
midori_view_has_selection (view); midori_view_has_selection (view);
@ -1533,6 +1536,8 @@ webkit_web_view_populate_popup_cb (WebKitWebView* web_view,
is_media = context & WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA; is_media = context & WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA;
is_document = !view->link_uri && !has_selection && !is_image && !is_media; is_document = !view->link_uri && !has_selection && !is_image && !is_media;
#else #else
/* There is no guarantee view->link_uri is correct in case
gtk-touchscreen-mode is enabled, nothing we can do. */
has_selection = midori_view_has_selection (view); has_selection = midori_view_has_selection (view);
is_document = !view->link_uri && !has_selection; is_document = !view->link_uri && !has_selection;
@ -2329,13 +2334,14 @@ midori_view_new (KatzeNet* net)
static void static void
_midori_view_update_settings (MidoriView* view) _midori_view_update_settings (MidoriView* view)
{ {
gboolean zoom_text_and_images; gboolean zoom_text_and_images, kinetic_scrolling;
g_object_get (view->settings, g_object_get (view->settings,
"speed-dial-in-new-tabs", &view->speed_dial_in_new_tabs, "speed-dial-in-new-tabs", &view->speed_dial_in_new_tabs,
"download-manager", &view->download_manager, "download-manager", &view->download_manager,
"news-aggregator", &view->news_aggregator, "news-aggregator", &view->news_aggregator,
"zoom-text-and-images", &zoom_text_and_images, "zoom-text-and-images", &zoom_text_and_images,
"kinetic-scrolling", &kinetic_scrolling,
"close-buttons-on-tabs", &view->close_buttons_on_tabs, "close-buttons-on-tabs", &view->close_buttons_on_tabs,
"open-new-pages-in", &view->open_new_pages_in, "open-new-pages-in", &view->open_new_pages_in,
"ask-for-destination-folder", &view->ask_for_destination_folder, "ask-for-destination-folder", &view->ask_for_destination_folder,
@ -2345,8 +2351,9 @@ _midori_view_update_settings (MidoriView* view)
NULL); NULL);
if (view->web_view) if (view->web_view)
g_object_set (view->web_view, "full-content-zoom", g_object_set (view->web_view,
zoom_text_and_images, NULL); "full-content-zoom", zoom_text_and_images, NULL);
g_object_set (view, "kinetic-scrolling", kinetic_scrolling, NULL);
} }
static void static void
@ -2379,6 +2386,11 @@ midori_view_settings_notify_cb (MidoriWebSettings* settings,
g_object_set (view->web_view, "full-content-zoom", g_object_set (view->web_view, "full-content-zoom",
g_value_get_boolean (&value), NULL); g_value_get_boolean (&value), NULL);
} }
else if (name == g_intern_string ("kinetic-scrolling"))
{
g_object_set (view, "kinetic-scrolling",
g_value_get_boolean (&value), NULL);
}
else if (name == g_intern_string ("close-buttons-on-tabs")) else if (name == g_intern_string ("close-buttons-on-tabs"))
{ {
view->close_buttons_on_tabs = g_value_get_boolean (&value); view->close_buttons_on_tabs = g_value_get_boolean (&value);

View file

@ -75,6 +75,7 @@ struct _MidoriWebSettings
gboolean zoom_text_and_images; gboolean zoom_text_and_images;
gboolean find_while_typing; gboolean find_while_typing;
gboolean kinetic_scrolling;
MidoriAcceptCookies accept_cookies; MidoriAcceptCookies accept_cookies;
gboolean original_cookies_only; gboolean original_cookies_only;
gint maximum_cookie_age; gint maximum_cookie_age;
@ -151,6 +152,7 @@ enum
PROP_ZOOM_TEXT_AND_IMAGES, PROP_ZOOM_TEXT_AND_IMAGES,
PROP_FIND_WHILE_TYPING, PROP_FIND_WHILE_TYPING,
PROP_KINETIC_SCROLLING,
PROP_ACCEPT_COOKIES, PROP_ACCEPT_COOKIES,
PROP_ORIGINAL_COOKIES_ONLY, PROP_ORIGINAL_COOKIES_ONLY,
PROP_MAXIMUM_COOKIE_AGE, PROP_MAXIMUM_COOKIE_AGE,
@ -833,6 +835,22 @@ midori_web_settings_class_init (MidoriWebSettingsClass* class)
FALSE, FALSE,
flags)); flags));
/**
* MidoriWebSettings:kinetic-scrolling:
*
* Whether scrolling should kinetically move according to speed.
*
* Since: 0.2.0
*/
g_object_class_install_property (gobject_class,
PROP_KINETIC_SCROLLING,
g_param_spec_boolean (
"kinetic-scrolling",
_("Kinetic scrolling"),
_("Whether scrolling should kinetically move according to speed"),
TRUE,
flags));
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_ACCEPT_COOKIES, PROP_ACCEPT_COOKIES,
g_param_spec_enum ( g_param_spec_enum (
@ -1025,6 +1043,7 @@ midori_web_settings_init (MidoriWebSettings* web_settings)
web_settings->open_popups_in_tabs = TRUE; web_settings->open_popups_in_tabs = TRUE;
web_settings->remember_last_form_inputs = TRUE; web_settings->remember_last_form_inputs = TRUE;
web_settings->remember_last_downloaded_files = TRUE; web_settings->remember_last_downloaded_files = TRUE;
web_settings->kinetic_scrolling = TRUE;
web_settings->auto_detect_proxy = TRUE; web_settings->auto_detect_proxy = TRUE;
g_signal_connect (web_settings, "notify::default-encoding", g_signal_connect (web_settings, "notify::default-encoding",
@ -1303,6 +1322,9 @@ midori_web_settings_set_property (GObject* object,
case PROP_FIND_WHILE_TYPING: case PROP_FIND_WHILE_TYPING:
web_settings->find_while_typing = g_value_get_boolean (value); web_settings->find_while_typing = g_value_get_boolean (value);
break; break;
case PROP_KINETIC_SCROLLING:
web_settings->kinetic_scrolling = g_value_get_boolean (value);
break;
case PROP_ACCEPT_COOKIES: case PROP_ACCEPT_COOKIES:
web_settings->accept_cookies = g_value_get_enum (value); web_settings->accept_cookies = g_value_get_enum (value);
break; break;
@ -1506,6 +1528,9 @@ midori_web_settings_get_property (GObject* object,
case PROP_FIND_WHILE_TYPING: case PROP_FIND_WHILE_TYPING:
g_value_set_boolean (value, web_settings->find_while_typing); g_value_set_boolean (value, web_settings->find_while_typing);
break; break;
case PROP_KINETIC_SCROLLING:
g_value_set_boolean (value, web_settings->kinetic_scrolling);
break;
case PROP_ACCEPT_COOKIES: case PROP_ACCEPT_COOKIES:
g_value_set_enum (value, web_settings->accept_cookies); g_value_set_enum (value, web_settings->accept_cookies);
break; break;