Add setstyle()

Regroup style uri setting application calls under one function.

Signed-off-by: Christoph Lohmann <20h@r-36.net>
This commit is contained in:
Quentin Rameau 2015-10-31 12:34:57 +01:00 committed by Christoph Lohmann
parent d84fe71094
commit 0290066b31

28
surf.c
View File

@ -155,6 +155,7 @@ static void gettogglestat(Client *c);
static void getpagestat(Client *c); static void getpagestat(Client *c);
static char *geturi(Client *c); static char *geturi(Client *c);
static const gchar *getstyle(const char *uri); static const gchar *getstyle(const char *uri);
static void setstyle(Client *c, const char *style);
static void handleplumb(Client *c, WebKitWebView *w, const gchar *uri); static void handleplumb(Client *c, WebKitWebView *w, const gchar *uri);
@ -662,6 +663,14 @@ getstyle(const char *uri)
return ""; return "";
} }
void
setstyle(Client *c, const char *style)
{
WebKitWebSettings *settings = webkit_web_view_get_settings(c->view);
g_object_set(G_OBJECT(settings), "user-stylesheet-uri", style, NULL);
}
void void
handleplumb(Client *c, WebKitWebView *w, const gchar *uri) handleplumb(Client *c, WebKitWebView *w, const gchar *uri)
{ {
@ -776,7 +785,6 @@ loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c)
WebKitWebFrame *frame; WebKitWebFrame *frame;
WebKitWebDataSource *src; WebKitWebDataSource *src;
WebKitNetworkRequest *request; WebKitNetworkRequest *request;
WebKitWebSettings *set = webkit_web_view_get_settings(c->view);
SoupMessage *msg; SoupMessage *msg;
char *uri; char *uri;
@ -793,10 +801,8 @@ loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c)
} }
setatom(c, AtomUri, uri); setatom(c, AtomUri, uri);
if (enablestyles) { if (enablestyles)
g_object_set(G_OBJECT(set), "user-stylesheet-uri", setstyle(c, getstyle(uri));
getstyle(uri), NULL);
}
break; break;
case WEBKIT_LOAD_FINISHED: case WEBKIT_LOAD_FINISHED:
c->progress = 100; c->progress = 100;
@ -997,11 +1003,6 @@ newclient(void)
if (!(ua = getenv("SURF_USERAGENT"))) if (!(ua = getenv("SURF_USERAGENT")))
ua = useragent; ua = useragent;
g_object_set(G_OBJECT(settings), "user-agent", ua, NULL); g_object_set(G_OBJECT(settings), "user-agent", ua, NULL);
if (enablestyles) {
g_object_set(G_OBJECT(settings),
"user-stylesheet-uri", getstyle("about:blank"),
NULL);
}
g_object_set(G_OBJECT(settings), g_object_set(G_OBJECT(settings),
"auto-load-images", loadimages, NULL); "auto-load-images", loadimages, NULL);
g_object_set(G_OBJECT(settings), g_object_set(G_OBJECT(settings),
@ -1018,6 +1019,8 @@ newclient(void)
"default-font-size", defaultfontsize, NULL); "default-font-size", defaultfontsize, NULL);
g_object_set(G_OBJECT(settings), g_object_set(G_OBJECT(settings),
"resizable-text-areas", 1, NULL); "resizable-text-areas", 1, NULL);
if (enablestyles)
setstyle(c, getstyle("about:blank"));
/* /*
* While stupid, CSS specifies that a pixel represents 1/96 of an inch. * While stupid, CSS specifies that a pixel represents 1/96 of an inch.
@ -1531,11 +1534,8 @@ togglescrollbars(Client *c, const Arg *arg)
void void
togglestyle(Client *c, const Arg *arg) togglestyle(Client *c, const Arg *arg)
{ {
WebKitWebSettings *settings = webkit_web_view_get_settings(c->view);
enablestyles = !enablestyles; enablestyles = !enablestyles;
g_object_set(G_OBJECT(settings), "user-stylesheet-uri", setstyle(c, enablestyles ? getstyle(geturi(c)) : "");
enablestyles ? getstyle(geturi(c)) : "", NULL);
updatetitle(c); updatetitle(c);
} }