1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
|
/*
* Copyright (C) 2008 Christian Dywan <christian@imendio.com>
* Copyright (C) 2008 Nuanti Ltd.
* Copyright (C) 2008 Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "webkitwebsettings.h"
#include "webkitprivate.h"
extern "C" {
G_DEFINE_TYPE(WebKitWebSettings, webkit_web_settings, G_TYPE_OBJECT)
struct _WebKitWebSettingsPrivate {
gchar* default_encoding;
gchar* cursive_font_family;
gchar* default_font_family;
gchar* fantasy_font_family;
gchar* monospace_font_family;
gchar* sans_serif_font_family;
gchar* serif_font_family;
guint default_font_size;
guint default_monospace_font_size;
guint minimum_font_size;
guint minimum_logical_font_size;
gboolean auto_load_images;
gboolean auto_shrink_images;
gboolean print_backgrounds;
gboolean enable_scripts;
gboolean enable_plugins;
gboolean resizable_text_areas;
gchar* user_stylesheet_uri;
gfloat zoom_step;
gboolean enable_developer_extras;
};
#define WEBKIT_WEB_SETTINGS_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_WEB_SETTINGS, WebKitWebSettingsPrivate))
enum {
PROP_0,
PROP_DEFAULT_ENCODING,
PROP_CURSIVE_FONT_FAMILY,
PROP_DEFAULT_FONT_FAMILY,
PROP_FANTASY_FONT_FAMILY,
PROP_MONOSPACE_FONT_FAMILY,
PROP_SANS_SERIF_FONT_FAMILY,
PROP_SERIF_FONT_FAMILY,
PROP_DEFAULT_FONT_SIZE,
PROP_DEFAULT_MONOSPACE_FONT_SIZE,
PROP_MINIMUM_FONT_SIZE,
PROP_MINIMUM_LOGICAL_FONT_SIZE,
PROP_AUTO_LOAD_IMAGES,
PROP_AUTO_SHRINK_IMAGES,
PROP_PRINT_BACKGROUNDS,
PROP_ENABLE_SCRIPTS,
PROP_ENABLE_PLUGINS,
PROP_RESIZABLE_TEXT_AREAS,
PROP_USER_STYLESHEET_URI,
PROP_ZOOM_STEP,
PROP_ENABLE_DEVELOPER_EXTRAS
};
static void webkit_web_settings_finalize(GObject* object);
static void webkit_web_settings_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec);
static void webkit_web_settings_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec);
static void webkit_web_settings_class_init(WebKitWebSettingsClass* klass)
{
GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
gobject_class->finalize = webkit_web_settings_finalize;
gobject_class->set_property = webkit_web_settings_set_property;
gobject_class->get_property = webkit_web_settings_get_property;
GParamFlags flags = (GParamFlags)(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT);
g_object_class_install_property(gobject_class,
PROP_DEFAULT_ENCODING,
g_param_spec_string(
"default-encoding",
"Default Encoding",
"The default encoding used to display text.",
"iso-8859-1",
flags));
g_object_class_install_property(gobject_class,
PROP_CURSIVE_FONT_FAMILY,
g_param_spec_string(
"cursive-font-family",
"Cursive Font Family",
"The default Cursive font family used to display text.",
"serif",
flags));
g_object_class_install_property(gobject_class,
PROP_DEFAULT_FONT_FAMILY,
g_param_spec_string(
"default-font-family",
"Default Font Family",
"The default font family used to display text.",
"sans-serif",
flags));
g_object_class_install_property(gobject_class,
PROP_FANTASY_FONT_FAMILY,
g_param_spec_string(
"fantasy-font-family",
"Fantasy Font Family",
"The default Fantasy font family used to display text.",
"serif",
flags));
g_object_class_install_property(gobject_class,
PROP_MONOSPACE_FONT_FAMILY,
g_param_spec_string(
"monospace-font-family",
"Monospace Font Family",
"The default font family used to display monospace text.",
"monospace",
flags));
g_object_class_install_property(gobject_class,
PROP_SANS_SERIF_FONT_FAMILY,
g_param_spec_string(
"sans-serif-font-family",
"Sans Serif Font Family",
"The default Sans Serif font family used to display text.",
"sans-serif",
flags));
g_object_class_install_property(gobject_class,
PROP_SERIF_FONT_FAMILY,
g_param_spec_string(
"serif-font-family",
"Serif Font Family",
"The default Serif font family used to display text.",
"serif",
flags));
g_object_class_install_property(gobject_class,
PROP_DEFAULT_FONT_SIZE,
g_param_spec_int(
"default-font-size",
"Default Font Size",
"The default font size used to display text.",
5, G_MAXINT, 10,
flags));
g_object_class_install_property(gobject_class,
PROP_DEFAULT_MONOSPACE_FONT_SIZE,
g_param_spec_int(
"default-monospace-font-size",
"Default Monospace Font Size",
"The default font size used to display monospace text.",
5, G_MAXINT, 10,
flags));
g_object_class_install_property(gobject_class,
PROP_MINIMUM_FONT_SIZE,
g_param_spec_int(
"minimum-font-size",
"Minimum Font Size",
"The minimum font size used to display text.",
1, G_MAXINT, 5,
flags));
g_object_class_install_property(gobject_class,
PROP_MINIMUM_LOGICAL_FONT_SIZE,
g_param_spec_int(
"minimum-logical-font-size",
"Minimum Logical Font Size",
"The minimum logical font size used to display text.",
1, G_MAXINT, 5,
flags));
g_object_class_install_property(gobject_class,
PROP_AUTO_LOAD_IMAGES,
g_param_spec_boolean(
"auto-load-images",
"Auto Load Images",
"Load images automatically.",
TRUE,
flags));
g_object_class_install_property(gobject_class,
PROP_AUTO_SHRINK_IMAGES,
g_param_spec_boolean(
"auto-shrink-images",
"Auto Shrink Images",
"Automatically shrink standalone images to fit.",
TRUE,
flags));
g_object_class_install_property(gobject_class,
PROP_PRINT_BACKGROUNDS,
g_param_spec_boolean(
"print-backgrounds",
"Print Backgrounds",
"Whether background images should be printed.",
TRUE,
flags));
g_object_class_install_property(gobject_class,
PROP_ENABLE_SCRIPTS,
g_param_spec_boolean(
"enable-scripts",
"Enable Scripts",
"Enable embedded scripting languages.",
TRUE,
flags));
g_object_class_install_property(gobject_class,
PROP_ENABLE_PLUGINS,
g_param_spec_boolean(
"enable-plugins",
"Enable Plugins",
"Enable embedded plugin objects.",
TRUE,
flags));
g_object_class_install_property(gobject_class,
PROP_RESIZABLE_TEXT_AREAS,
g_param_spec_boolean(
"resizable-text-areas",
"Resizable Text Areas",
"Whether text areas are resizable.",
TRUE,
flags));
g_object_class_install_property(gobject_class,
PROP_USER_STYLESHEET_URI,
g_param_spec_string("user-stylesheet-uri",
"User Stylesheet URI",
"The URI of a stylesheet that is applied to every page.",
0,
flags));
/**
* WebKitWebSettings:zoom-step:
*
* The value by which the zoom level is changed when zooming in or out.
*
* Since: 1.0.1
*/
g_object_class_install_property(gobject_class,
PROP_ZOOM_STEP,
g_param_spec_float(
"zoom-step",
"Zoom Stepping Value",
"The value by which the zoom level is changed when zooming in or out.",
0.0f, G_MAXFLOAT, 0.1f,
flags));
/**
* WebKitWebSettings:enable-developer-extras:
*
* Whether developer extensions should be enabled. This enables,
* for now, the Web Inspector, which can be controlled using the
* #WebKitWebInspector instance held by the #WebKitWebView this
* setting is enabled for.
*
* Since: 1.0.3
*/
g_object_class_install_property(gobject_class,
PROP_ENABLE_DEVELOPER_EXTRAS,
g_param_spec_boolean(
"enable-developer-extras",
"Enable Developer Extras",
"Enables special extensions that help developers",
FALSE,
flags));
g_type_class_add_private(klass, sizeof(WebKitWebSettingsPrivate));
}
static void webkit_web_settings_init(WebKitWebSettings* web_settings)
{
web_settings->priv = WEBKIT_WEB_SETTINGS_GET_PRIVATE(web_settings);
}
static void webkit_web_settings_finalize(GObject* object)
{
WebKitWebSettings* web_settings = WEBKIT_WEB_SETTINGS(object);
WebKitWebSettingsPrivate* priv = web_settings->priv;
g_free(priv->default_encoding);
g_free(priv->cursive_font_family);
g_free(priv->default_font_family);
g_free(priv->fantasy_font_family);
g_free(priv->monospace_font_family);
g_free(priv->sans_serif_font_family);
g_free(priv->serif_font_family);
g_free(priv->user_stylesheet_uri);
G_OBJECT_CLASS(webkit_web_settings_parent_class)->finalize(object);
}
static void webkit_web_settings_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec)
{
WebKitWebSettings* web_settings = WEBKIT_WEB_SETTINGS(object);
WebKitWebSettingsPrivate* priv = web_settings->priv;
switch(prop_id) {
case PROP_DEFAULT_ENCODING:
g_free(priv->default_encoding);
priv->default_encoding = g_strdup(g_value_get_string(value));
break;
case PROP_CURSIVE_FONT_FAMILY:
g_free(priv->cursive_font_family);
priv->cursive_font_family = g_strdup(g_value_get_string(value));
break;
case PROP_DEFAULT_FONT_FAMILY:
g_free(priv->default_font_family);
priv->default_font_family = g_strdup(g_value_get_string(value));
break;
case PROP_FANTASY_FONT_FAMILY:
g_free(priv->fantasy_font_family);
priv->fantasy_font_family = g_strdup(g_value_get_string(value));
break;
case PROP_MONOSPACE_FONT_FAMILY:
g_free(priv->monospace_font_family);
priv->monospace_font_family = g_strdup(g_value_get_string(value));
break;
case PROP_SANS_SERIF_FONT_FAMILY:
g_free(priv->sans_serif_font_family);
priv->sans_serif_font_family = g_strdup(g_value_get_string(value));
break;
case PROP_SERIF_FONT_FAMILY:
g_free(priv->serif_font_family);
priv->serif_font_family = g_strdup(g_value_get_string(value));
break;
case PROP_DEFAULT_FONT_SIZE:
priv->default_font_size = g_value_get_int(value);
break;
case PROP_DEFAULT_MONOSPACE_FONT_SIZE:
priv->default_monospace_font_size = g_value_get_int(value);
break;
case PROP_MINIMUM_FONT_SIZE:
priv->minimum_font_size = g_value_get_int(value);
break;
case PROP_MINIMUM_LOGICAL_FONT_SIZE:
priv->minimum_logical_font_size = g_value_get_int(value);
break;
case PROP_AUTO_LOAD_IMAGES:
priv->auto_load_images = g_value_get_boolean(value);
break;
case PROP_AUTO_SHRINK_IMAGES:
priv->auto_shrink_images = g_value_get_boolean(value);
break;
case PROP_PRINT_BACKGROUNDS:
priv->print_backgrounds = g_value_get_boolean(value);
break;
case PROP_ENABLE_SCRIPTS:
priv->enable_scripts = g_value_get_boolean(value);
break;
case PROP_ENABLE_PLUGINS:
priv->enable_plugins = g_value_get_boolean(value);
break;
case PROP_RESIZABLE_TEXT_AREAS:
priv->resizable_text_areas = g_value_get_boolean(value);
break;
case PROP_USER_STYLESHEET_URI:
g_free(priv->user_stylesheet_uri);
priv->user_stylesheet_uri = g_strdup(g_value_get_string(value));
break;
case PROP_ZOOM_STEP:
priv->zoom_step = g_value_get_float(value);
break;
case PROP_ENABLE_DEVELOPER_EXTRAS:
priv->enable_developer_extras = g_value_get_boolean(value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
static void webkit_web_settings_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec)
{
WebKitWebSettings* web_settings = WEBKIT_WEB_SETTINGS(object);
WebKitWebSettingsPrivate* priv = web_settings->priv;
switch (prop_id) {
case PROP_DEFAULT_ENCODING:
g_value_set_string(value, priv->default_encoding);
break;
case PROP_CURSIVE_FONT_FAMILY:
g_value_set_string(value, priv->cursive_font_family);
break;
case PROP_DEFAULT_FONT_FAMILY:
g_value_set_string(value, priv->default_font_family);
break;
case PROP_FANTASY_FONT_FAMILY:
g_value_set_string(value, priv->fantasy_font_family);
break;
case PROP_MONOSPACE_FONT_FAMILY:
g_value_set_string(value, priv->monospace_font_family);
break;
case PROP_SANS_SERIF_FONT_FAMILY:
g_value_set_string(value, priv->sans_serif_font_family);
break;
case PROP_SERIF_FONT_FAMILY:
g_value_set_string(value, priv->serif_font_family);
break;
case PROP_DEFAULT_FONT_SIZE:
g_value_set_int(value, priv->default_font_size);
break;
case PROP_DEFAULT_MONOSPACE_FONT_SIZE:
g_value_set_int(value, priv->default_monospace_font_size);
break;
case PROP_MINIMUM_FONT_SIZE:
g_value_set_int(value, priv->minimum_font_size);
break;
case PROP_MINIMUM_LOGICAL_FONT_SIZE:
g_value_set_int(value, priv->minimum_logical_font_size);
break;
case PROP_AUTO_LOAD_IMAGES:
g_value_set_boolean(value, priv->auto_load_images);
break;
case PROP_AUTO_SHRINK_IMAGES:
g_value_set_boolean(value, priv->auto_shrink_images);
break;
case PROP_PRINT_BACKGROUNDS:
g_value_set_boolean(value, priv->print_backgrounds);
break;
case PROP_ENABLE_SCRIPTS:
g_value_set_boolean(value, priv->enable_scripts);
break;
case PROP_ENABLE_PLUGINS:
g_value_set_boolean(value, priv->enable_plugins);
break;
case PROP_RESIZABLE_TEXT_AREAS:
g_value_set_boolean(value, priv->resizable_text_areas);
break;
case PROP_USER_STYLESHEET_URI:
g_value_set_string(value, priv->user_stylesheet_uri);
break;
case PROP_ZOOM_STEP:
g_value_set_float(value, priv->zoom_step);
break;
case PROP_ENABLE_DEVELOPER_EXTRAS:
g_value_set_boolean(value, priv->enable_developer_extras);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
/**
* webkit_web_settings_new:
*
* Creates a new #WebKitWebSettings instance with default values. It must
* be manually attached to a WebView.
*
* Returns: a new #WebKitWebSettings instance
**/
WebKitWebSettings* webkit_web_settings_new()
{
return WEBKIT_WEB_SETTINGS(g_object_new(WEBKIT_TYPE_WEB_SETTINGS, NULL));
}
/**
* webkit_web_settings_copy:
*
* Copies an existing #WebKitWebSettings instance.
*
* Returns: a new #WebKitWebSettings instance
**/
WebKitWebSettings* webkit_web_settings_copy(WebKitWebSettings* web_settings)
{
WebKitWebSettingsPrivate* priv = web_settings->priv;
WebKitWebSettings* copy = WEBKIT_WEB_SETTINGS(g_object_new(WEBKIT_TYPE_WEB_SETTINGS,
"default-encoding", priv->default_encoding,
"cursive-font-family", priv->cursive_font_family,
"default-font-family", priv->default_font_family,
"fantasy-font-family", priv->fantasy_font_family,
"monospace-font-family", priv->monospace_font_family,
"sans-serif-font-family", priv->sans_serif_font_family,
"serif-font-family", priv->serif_font_family,
"default-font-size", priv->default_font_size,
"default-monospace-font-size", priv->default_monospace_font_size,
"minimum-font-size", priv->minimum_font_size,
"minimum-logical-font-size", priv->minimum_logical_font_size,
"auto-load-images", priv->auto_load_images,
"auto-shrink-images", priv->auto_shrink_images,
"print-backgrounds", priv->print_backgrounds,
"enable-scripts", priv->enable_scripts,
"enable-plugins", priv->enable_plugins,
"resizable-text-areas", priv->resizable_text_areas,
"user-stylesheet-uri", priv->user_stylesheet_uri,
"zoom-step", priv->zoom_step,
"enable-developer-extras", priv->enable_developer_extras,
NULL));
return copy;
}
}
|