Add zoom functionality, if webkit supports it

This commit is contained in:
Christian Dywan 2008-06-01 11:26:10 +02:00
parent 8e494ba206
commit a61568c16a
6 changed files with 113 additions and 33 deletions

View file

@ -118,11 +118,18 @@ settings_new_from_file (const gchar* filename)
}
else if (type == G_TYPE_PARAM_INT)
{
guint integer = sokoke_key_file_get_integer_default (key_file,
gint integer = sokoke_key_file_get_integer_default (key_file,
"settings", property,
G_PARAM_SPEC_INT (pspec)->default_value, NULL);
g_object_set (settings, property, integer, NULL);
}
else if (type == G_TYPE_PARAM_FLOAT)
{
gdouble number = sokoke_key_file_get_double_default (key_file,
"settings", property,
G_PARAM_SPEC_FLOAT (pspec)->default_value, NULL);
g_object_set (settings, property, number, NULL);
}
else if (type == G_TYPE_PARAM_BOOLEAN)
{
gboolean boolean = sokoke_key_file_get_boolean_default (key_file,
@ -189,6 +196,12 @@ settings_save_to_file (MidoriWebSettings* settings,
g_object_get (settings, property, &integer, NULL);
g_key_file_set_integer (key_file, "settings", property, integer);
}
else if (type == G_TYPE_PARAM_FLOAT)
{
gdouble number;
g_object_get (settings, property, &number, NULL);
g_key_file_set_double (key_file, "settings", property, number);
}
else if (type == G_TYPE_PARAM_BOOLEAN)
{
gboolean boolean;

View file

@ -173,20 +173,26 @@ _midori_browser_update_interface (MidoriBrowser* browser)
{
MidoriBrowserPrivate* priv = browser->priv;
gboolean loading = FALSE;
GtkWidget* web_view = midori_browser_get_current_web_view (browser);
gboolean loading = midori_web_view_is_loading (MIDORI_WEB_VIEW (web_view));
/*_action_set_sensitive (browser, "ZoomIn",
webkit_web_view_can_increase_text_size (WEBKIT_WEB_VIEW (web_view)));
_action_set_sensitive (browser, "ZoomOut",
webkit_web_view_can_decrease_text_size (WEBKIT_WEB_VIEW (web_view)));
if (web_view)
{
loading = midori_web_view_is_loading (MIDORI_WEB_VIEW (web_view));
_action_set_sensitive (browser, "ZoomNormal",
webkit_web_view_get_text_size (WEBKIT_WEB_VIEW (web_view)) != 1);*/
midori_web_view_get_zoom_level (MIDORI_WEB_VIEW (web_view)) != 1.0);
if (!g_object_class_find_property (G_OBJECT_GET_CLASS (web_view),
"zoom-level"))
{
_action_set_sensitive (browser, "ZoomIn", FALSE);
_action_set_sensitive (browser, "ZoomOut", FALSE);
}
_action_set_sensitive (browser, "Back",
webkit_web_view_can_go_back (WEBKIT_WEB_VIEW (web_view)));
_action_set_sensitive (browser, "Forward",
webkit_web_view_can_go_forward (WEBKIT_WEB_VIEW (web_view)));
_action_set_sensitive (browser, "Reload", !loading);
_action_set_sensitive (browser, "Stop", loading);
}
GtkAction* action = gtk_action_group_get_action (priv->action_group,
"ReloadStop");
@ -1230,33 +1236,49 @@ _action_reload_stop_activate (GtkAction* action,
g_free (stock_id);
}
/*static void
static void
_action_zoom_in_activate (GtkAction* action,
MidoriBrowser* browser)
{
GtkWidget* web_view = midori_browser_get_current_web_view (browser);
const gfloat zoom = webkit_web_view_get_text_multiplier (
WEBKIT_WEB_VIEW (web_view));
webkit_web_view_set_text_multiplier (WEBKIT_WEB_VIEW (web_view), zoom + 0.1);
}*/
if (web_view && g_object_class_find_property (
G_OBJECT_GET_CLASS (web_view), "zoom-level"))
{
MidoriBrowserPrivate* priv = browser->priv;
/*static void
gfloat zoom_level, zoom_step;
g_object_get (web_view, "zoom-level", &zoom_level, NULL);
g_object_get (priv->settings, "zoom-step", &zoom_step, NULL);
g_object_set (web_view, "zoom-level", zoom_level + zoom_step, NULL);
}
}
static void
_action_zoom_out_activate (GtkAction* action,
MidoriBrowser* browser)
{
GtkWidget* web_view = midori_browser_get_current_web_view (browser);
const gfloat zoom = webkit_web_view_get_text_multiplier (
WEBKIT_WEB_VIEW (web_view));
webkit_web_view_set_text_multiplier (WEBKIT_WEB_VIEW (web_view), zoom - 0.1);
}*/
if (web_view && g_object_class_find_property (
G_OBJECT_GET_CLASS (web_view), "zoom-level"))
{
MidoriBrowserPrivate* priv = browser->priv;
/*static void
gfloat zoom_level, zoom_step;
g_object_get (web_view, "zoom-level", &zoom_level, NULL);
g_object_get (priv->settings, "zoom-step", &zoom_step, NULL);
g_object_set (web_view, "zoom-level", zoom_level - zoom_step, NULL);
}
}
static void
_action_zoom_normal_activate (GtkAction* action,
MidoriBrowser* browser)
{
GtkWidget* web_view = midori_browser_get_current_web_view (browser);
webkit_web_view_set_text_multiplier (WEBKIT_WEB_VIEW (web_View, 1));
}*/
if (web_view && g_object_class_find_property (
G_OBJECT_GET_CLASS (web_view), "zoom-level"))
g_object_set (web_view, "zoom-level", 1.0, NULL);
}
/*static void
_action_source_view_activate (GtkAction* action,
@ -2228,13 +2250,13 @@ static const GtkActionEntry entries[] = {
N_("Reload the current page"), G_CALLBACK (_action_reload_stop_activate) },
{ "ZoomIn", GTK_STOCK_ZOOM_IN,
NULL, "<Ctrl>plus",
"hm?", NULL/*G_CALLBACK (_action_zoom_in_activate)*/ },
"hm?", G_CALLBACK (_action_zoom_in_activate) },
{ "ZoomOut", GTK_STOCK_ZOOM_OUT,
NULL, "<Ctrl>minus",
"hm?", NULL/*G_CALLBACK (_action_zoom_out_activate)*/ },
"hm?", G_CALLBACK (_action_zoom_out_activate) },
{ "ZoomNormal", GTK_STOCK_ZOOM_100,
NULL, "<Ctrl>0",
"hm?", NULL/*G_CALLBACK (_action_zoom_normal_activate)*/ },
"hm?", G_CALLBACK (_action_zoom_normal_activate) },
{ "SourceView", NULL,
N_("View Source"), "",
"hm?", /*G_CALLBACK (_action_source_view_activate)*/ },

View file

@ -1097,3 +1097,26 @@ midori_web_view_get_link_uri (MidoriWebView* web_view)
MidoriWebViewPrivate* priv = web_view->priv;
return priv->link_uri;
}
/**
* midori_web_view_get_zoom_level:
* @web_view: a #MidoriWebView
*
* Retrieves the current zoom level.
*
* Return value: the zoom level, always 1 if not supported
**/
gfloat
midori_web_view_get_zoom_level (MidoriWebView* web_view)
{
g_return_val_if_fail (MIDORI_IS_WEB_VIEW (web_view), 1);
if (g_object_class_find_property (G_OBJECT_GET_CLASS (web_view),
"zoom-level"))
{
gfloat zoom_level;
g_object_get (web_view, "zoom-level", &zoom_level, NULL);
return zoom_level;
}
return 1;
}

View file

@ -113,6 +113,9 @@ midori_web_view_get_display_title (MidoriWebView* web_view);
const gchar*
midori_web_view_get_link_uri (MidoriWebView* web_view);
gfloat
midori_web_view_get_zoom_level (MidoriWebView* web_view);
G_END_DECLS
#endif /* __MIDORI_WEB_VIEW_H__ */

View file

@ -403,6 +403,18 @@ gint sokoke_key_file_get_integer_default(GKeyFile* keyFile
return g_key_file_get_integer(keyFile, group, key, error);
}
gdouble
sokoke_key_file_get_double_default (GKeyFile* key_file,
const gchar* group,
const gchar* key,
const gdouble default_value,
GError** error)
{
if (!g_key_file_has_key (key_file, group, key, NULL))
return default_value;
return g_key_file_get_double (key_file, group, key, error);
}
gboolean
sokoke_key_file_get_boolean_default (GKeyFile* key_file,
const gchar* group,

View file

@ -75,6 +75,13 @@ gint
sokoke_key_file_get_integer_default(GKeyFile*, const gchar*, const gchar*
, const gint, GError**);
gdouble
sokoke_key_file_get_double_default (GKeyFile* key_file,
const gchar* group,
const gchar* key,
gdouble default_value,
GError** error);
gboolean
sokoke_key_file_get_boolean_default (GKeyFile* key_file,
const gchar* group,