1 /*
2 * Copyright (C) 2008 Gustavo Noronha Silva <gns@gnome.org>
3 * Copyright (C) 2008 Holger Hans Peter Freyther
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 #include "config.h"
22 #include "webkitwebwindowfeatures.h"
23
24 #include "WindowFeatures.h"
25 #include "webkitglobalsprivate.h"
26 #include "webkitwebwindowfeaturesprivate.h"
27
28 /**
29 * SECTION:webkitwebwindowfeatures
30 * @short_description: Window properties of a #WebKitWebView
31 * @see_also: #WebKitWebView::web-view-ready
32 *
33 * The content of a #WebKitWebView can request to change certain
34 * properties of a #WebKitWebView. This can include the x, y position
35 * of the window, the width and height but also if a toolbar,
36 * scrollbar, statusbar, locationbar should be visible to the user,
37 * the request to show the #WebKitWebView fullscreen.
38 *
39 * In the normal case one will use #webkit_web_view_get_window_features
40 * to get the #WebKitWebWindowFeatures and then monitor the property
41 * changes. Be aware that the #WebKitWebWindowFeatures might change
42 * before #WebKitWebView::web-view-ready signal is emitted.
43 * To be safe listen to the notify::window-features signal of the #WebKitWebView
44 * and reconnect the signals whenever the #WebKitWebWindowFeatures of
45 * a #WebKitWebView changes.
46 *
47 * <informalexample><programlisting>
48 * /<!-- -->* Get the current WebKitWebWindowFeatures *<!-- -->/
49 * WebKitWebWindowFeatures *features = webkit_web_view_get_window_features (my_webview);
50 *
51 * /<!-- -->* Connect to the property changes *<!-- -->/
52 * g_signal_connect (G_OBJECT(features), "notify::menubar-visible", G_CALLBACK(make_menu_bar_visible), NULL);
53 * g_signal_connect (G_OBJECT(features), "notify::statusbar-visible", G_CALLBACK(make_status_bar_visible), NULL);
54 *
55 * </programlisting></informalexample>
56 */
57
58 enum {
59 PROP_0,
60
61 PROP_X,
62 PROP_Y,
63 PROP_WIDTH,
64 PROP_HEIGHT,
65 PROP_TOOLBAR_VISIBLE,
66 PROP_STATUSBAR_VISIBLE,
67 PROP_SCROLLBAR_VISIBLE,
68 PROP_MENUBAR_VISIBLE,
69 PROP_LOCATIONBAR_VISIBLE,
70 PROP_FULLSCREEN,
71 };
72
73 G_DEFINE_TYPE(WebKitWebWindowFeatures, webkit_web_window_features, G_TYPE_OBJECT)
74
75 struct _WebKitWebWindowFeaturesPrivate {
76 gint x;
77 gint y;
78 gint width;
79 gint height;
80
81 gboolean toolbar_visible;
82 gboolean statusbar_visible;
83 gboolean scrollbar_visible;
84 gboolean menubar_visible;
85 gboolean locationbar_visible;
86
87 gboolean fullscreen;
88 };
89
90 #define WEBKIT_WEB_WINDOW_FEATURES_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_WEB_WINDOW_FEATURES, WebKitWebWindowFeaturesPrivate))
91
92 static void webkit_web_window_features_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec);
93
94 static void webkit_web_window_features_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec);
95
webkit_web_window_features_class_init(WebKitWebWindowFeaturesClass * klass)96 static void webkit_web_window_features_class_init(WebKitWebWindowFeaturesClass* klass)
97 {
98 GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
99 gobject_class->set_property = webkit_web_window_features_set_property;
100 gobject_class->get_property = webkit_web_window_features_get_property;
101
102 GParamFlags flags = (GParamFlags)(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT);
103
104 webkitInit();
105
106 /**
107 * WebKitWebWindowFeatures:x:
108 *
109 * The starting x position of the window on the screen.
110 *
111 * Since: 1.0.3
112 */
113 g_object_class_install_property(gobject_class,
114 PROP_X,
115 g_param_spec_int(
116 "x",
117 "x",
118 "The starting x position of the window on the screen.",
119 -1,
120 G_MAXINT,
121 -1,
122 flags));
123
124 /**
125 * WebKitWebWindowFeatures:y:
126 *
127 * The starting y position of the window on the screen.
128 *
129 * Since: 1.0.3
130 */
131 g_object_class_install_property(gobject_class,
132 PROP_Y,
133 g_param_spec_int(
134 "y",
135 "y",
136 "The starting y position of the window on the screen.",
137 -1,
138 G_MAXINT,
139 -1,
140 flags));
141
142 /**
143 * WebKitWebWindowFeatures:width:
144 *
145 * The width of the window on the screen.
146 *
147 * Since: 1.0.3
148 */
149 g_object_class_install_property(gobject_class,
150 PROP_WIDTH,
151 g_param_spec_int(
152 "width",
153 "Width",
154 "The width of the window on the screen.",
155 -1,
156 G_MAXINT,
157 -1,
158 flags));
159
160 /**
161 * WebKitWebWindowFeatures:height:
162 *
163 * The height of the window on the screen.
164 *
165 * Since: 1.0.3
166 */
167 g_object_class_install_property(gobject_class,
168 PROP_HEIGHT,
169 g_param_spec_int(
170 "height",
171 "Height",
172 "The height of the window on the screen.",
173 -1,
174 G_MAXINT,
175 -1,
176 flags));
177
178 /**
179 * WebKitWebWindowFeatures:toolbar-visible:
180 *
181 * Controls whether the toolbar should be visible for the window.
182 *
183 * Since: 1.0.3
184 */
185 g_object_class_install_property(gobject_class,
186 PROP_TOOLBAR_VISIBLE,
187 g_param_spec_boolean(
188 "toolbar-visible",
189 "Toolbar Visible",
190 "Controls whether the toolbar should be visible for the window.",
191 TRUE,
192 flags));
193
194 /**
195 * WebKitWebWindowFeatures:statusbar-visible:
196 *
197 * Controls whether the statusbar should be visible for the window.
198 *
199 * Since: 1.0.3
200 */
201 g_object_class_install_property(gobject_class,
202 PROP_STATUSBAR_VISIBLE,
203 g_param_spec_boolean(
204 "statusbar-visible",
205 "Statusbar Visible",
206 "Controls whether the statusbar should be visible for the window.",
207 TRUE,
208 flags));
209
210 /**
211 * WebKitWebWindowFeatures:scrollbar-visible:
212 *
213 * Controls whether the scrollbars should be visible for the window.
214 *
215 * Since: 1.0.3
216 */
217 g_object_class_install_property(gobject_class,
218 PROP_SCROLLBAR_VISIBLE,
219 g_param_spec_boolean(
220 "scrollbar-visible",
221 "Scrollbar Visible",
222 "Controls whether the scrollbars should be visible for the window.",
223 TRUE,
224 flags));
225
226 /**
227 * WebKitWebWindowFeatures:menubar-visible:
228 *
229 * Controls whether the menubar should be visible for the window.
230 *
231 * Since: 1.0.3
232 */
233 g_object_class_install_property(gobject_class,
234 PROP_MENUBAR_VISIBLE,
235 g_param_spec_boolean(
236 "menubar-visible",
237 "Menubar Visible",
238 "Controls whether the menubar should be visible for the window.",
239 TRUE,
240 flags));
241
242 /**
243 * WebKitWebWindowFeatures:locationbar-visible:
244 *
245 * Controls whether the locationbar should be visible for the window.
246 *
247 * Since: 1.0.3
248 */
249 g_object_class_install_property(gobject_class,
250 PROP_LOCATIONBAR_VISIBLE,
251 g_param_spec_boolean(
252 "locationbar-visible",
253 "Locationbar Visible",
254 "Controls whether the locationbar should be visible for the window.",
255 TRUE,
256 flags));
257
258 /**
259 * WebKitWebWindowFeatures:fullscreen:
260 *
261 * Controls whether window will be displayed fullscreen.
262 *
263 * Since: 1.0.3
264 */
265 g_object_class_install_property(gobject_class,
266 PROP_FULLSCREEN,
267 g_param_spec_boolean(
268 "fullscreen",
269 "Fullscreen",
270 "Controls whether window will be displayed fullscreen.",
271 FALSE,
272 flags));
273
274
275 g_type_class_add_private(klass, sizeof(WebKitWebWindowFeaturesPrivate));
276 }
277
webkit_web_window_features_init(WebKitWebWindowFeatures * web_window_features)278 static void webkit_web_window_features_init(WebKitWebWindowFeatures* web_window_features)
279 {
280 web_window_features->priv = G_TYPE_INSTANCE_GET_PRIVATE(web_window_features, WEBKIT_TYPE_WEB_WINDOW_FEATURES, WebKitWebWindowFeaturesPrivate);
281 }
282
webkit_web_window_features_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)283 static void webkit_web_window_features_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec)
284 {
285 WebKitWebWindowFeatures* web_window_features = WEBKIT_WEB_WINDOW_FEATURES(object);
286 WebKitWebWindowFeaturesPrivate* priv = web_window_features->priv;
287
288 switch(prop_id) {
289 case PROP_X:
290 priv->x = g_value_get_int(value);
291 break;
292 case PROP_Y:
293 priv->y = g_value_get_int(value);
294 break;
295 case PROP_WIDTH:
296 priv->width = g_value_get_int(value);
297 break;
298 case PROP_HEIGHT:
299 priv->height = g_value_get_int(value);
300 break;
301 case PROP_TOOLBAR_VISIBLE:
302 priv->toolbar_visible = g_value_get_boolean(value);
303 break;
304 case PROP_STATUSBAR_VISIBLE:
305 priv->statusbar_visible = g_value_get_boolean(value);
306 break;
307 case PROP_SCROLLBAR_VISIBLE:
308 priv->scrollbar_visible = g_value_get_boolean(value);
309 break;
310 case PROP_MENUBAR_VISIBLE:
311 priv->menubar_visible = g_value_get_boolean(value);
312 break;
313 case PROP_LOCATIONBAR_VISIBLE:
314 priv->locationbar_visible = g_value_get_boolean(value);
315 break;
316 case PROP_FULLSCREEN:
317 priv->fullscreen = g_value_get_boolean(value);
318 break;
319 default:
320 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
321 break;
322 }
323 }
324
webkit_web_window_features_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)325 static void webkit_web_window_features_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec)
326 {
327 WebKitWebWindowFeatures* web_window_features = WEBKIT_WEB_WINDOW_FEATURES(object);
328 WebKitWebWindowFeaturesPrivate* priv = web_window_features->priv;
329
330 switch (prop_id) {
331 case PROP_X:
332 g_value_set_int(value, priv->x);
333 break;
334 case PROP_Y:
335 g_value_set_int(value, priv->y);
336 break;
337 case PROP_WIDTH:
338 g_value_set_int(value, priv->width);
339 break;
340 case PROP_HEIGHT:
341 g_value_set_int(value, priv->height);
342 break;
343 case PROP_TOOLBAR_VISIBLE:
344 g_value_set_boolean(value, priv->toolbar_visible);
345 break;
346 case PROP_STATUSBAR_VISIBLE:
347 g_value_set_boolean(value, priv->statusbar_visible);
348 break;
349 case PROP_SCROLLBAR_VISIBLE:
350 g_value_set_boolean(value, priv->scrollbar_visible);
351 break;
352 case PROP_MENUBAR_VISIBLE:
353 g_value_set_boolean(value, priv->menubar_visible);
354 break;
355 case PROP_LOCATIONBAR_VISIBLE:
356 g_value_set_boolean(value, priv->locationbar_visible);
357 break;
358 case PROP_FULLSCREEN:
359 g_value_set_boolean(value, priv->fullscreen);
360 break;
361 default:
362 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
363 break;
364 }
365 }
366
367 /**
368 * webkit_web_window_features_new:
369 *
370 * Creates a new #WebKitWebWindowFeatures instance with default values. It must
371 * be manually attached to a WebView.
372 *
373 * Returns: a new #WebKitWebWindowFeatures instance
374 *
375 * Since: 1.0.3
376 */
webkit_web_window_features_new()377 WebKitWebWindowFeatures* webkit_web_window_features_new()
378 {
379 return WEBKIT_WEB_WINDOW_FEATURES(g_object_new(WEBKIT_TYPE_WEB_WINDOW_FEATURES, NULL));
380 }
381
382 /**
383 * webkit_web_window_features_equal:
384 * @features1: a #WebKitWebWindowFeatures instance
385 * @features2: another #WebKitWebWindowFeatures instance
386 *
387 * Decides if a #WebKitWebWindowFeatures instance equals another, as
388 * in has the same values.
389 *
390 * Returns: %TRUE if the instances have the same values, %FALSE
391 * otherwise
392 *
393 * Since: 1.0.3
394 */
webkit_web_window_features_equal(WebKitWebWindowFeatures * features1,WebKitWebWindowFeatures * features2)395 gboolean webkit_web_window_features_equal(WebKitWebWindowFeatures* features1, WebKitWebWindowFeatures* features2)
396 {
397 if (features1 == features2)
398 return TRUE;
399 if (!features1 || !features2)
400 return FALSE;
401
402 WebKitWebWindowFeaturesPrivate* priv1 = features1->priv;
403 WebKitWebWindowFeaturesPrivate* priv2 = features2->priv;
404
405 if ((priv1->x == priv2->x)
406 && (priv1->y == priv2->y)
407 && (priv1->width == priv2->width)
408 && (priv1->height == priv2->height)
409 && (priv1->toolbar_visible == priv2->toolbar_visible)
410 && (priv1->statusbar_visible == priv2->statusbar_visible)
411 && (priv1->scrollbar_visible == priv2->scrollbar_visible)
412 && (priv1->menubar_visible == priv2->menubar_visible)
413 && (priv1->locationbar_visible == priv2->locationbar_visible)
414 && (priv1->fullscreen == priv2->fullscreen))
415 return TRUE;
416 return FALSE;
417 }
418
419 namespace WebKit {
420
kitNew(const WebCore::WindowFeatures & features)421 WebKitWebWindowFeatures* kitNew(const WebCore::WindowFeatures& features)
422 {
423 WebKitWebWindowFeatures *webWindowFeatures = webkit_web_window_features_new();
424
425 if(features.xSet)
426 g_object_set(webWindowFeatures, "x", static_cast<int>(features.x), NULL);
427
428 if(features.ySet)
429 g_object_set(webWindowFeatures, "y", static_cast<int>(features.y), NULL);
430
431 if(features.widthSet)
432 g_object_set(webWindowFeatures, "width", static_cast<int>(features.width), NULL);
433
434 if(features.heightSet)
435 g_object_set(webWindowFeatures, "height", static_cast<int>(features.height), NULL);
436
437 g_object_set(webWindowFeatures,
438 "toolbar-visible", features.toolBarVisible,
439 "statusbar-visible", features.statusBarVisible,
440 "scrollbar-visible", features.scrollbarsVisible,
441 "menubar-visible", features.menuBarVisible,
442 "locationbar-visible", features.locationBarVisible,
443 "fullscreen", features.fullscreen,
444 NULL);
445
446 return webWindowFeatures;
447 }
448
449 }
450