2 * Copyright (C) 2008 Gustavo Noronha Silva <gns@gnome.org>
3 * Copyright (C) 2008 Holger Hans Peter Freyther
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.
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.
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.
22 #include "webkitwebwindowfeatures.h"
24 #include "WindowFeatures.h"
25 #include "webkitglobalsprivate.h"
26 #include "webkitwebwindowfeaturesprivate.h"
29 * SECTION:webkitwebwindowfeatures
30 * @short_description: Window properties of a #WebKitWebView
31 * @see_also: #WebKitWebView::web-view-ready
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.
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.
47 * <informalexample><programlisting>
48 * /<!-- -->* Get the current WebKitWebWindowFeatures *<!-- -->/
49 * WebKitWebWindowFeatures *features = webkit_web_view_get_window_features (my_webview);
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);
55 * </programlisting></informalexample>
66 PROP_STATUSBAR_VISIBLE,
67 PROP_SCROLLBAR_VISIBLE,
69 PROP_LOCATIONBAR_VISIBLE,
73 G_DEFINE_TYPE(WebKitWebWindowFeatures, webkit_web_window_features, G_TYPE_OBJECT)
75 struct _WebKitWebWindowFeaturesPrivate {
81 gboolean toolbar_visible;
82 gboolean statusbar_visible;
83 gboolean scrollbar_visible;
84 gboolean menubar_visible;
85 gboolean locationbar_visible;
90 #define WEBKIT_WEB_WINDOW_FEATURES_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_WEB_WINDOW_FEATURES, WebKitWebWindowFeaturesPrivate))
92 static void webkit_web_window_features_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec);
94 static void webkit_web_window_features_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec);
96 static void webkit_web_window_features_class_init(WebKitWebWindowFeaturesClass* klass)
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;
102 GParamFlags flags = (GParamFlags)(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT);
107 * WebKitWebWindowFeatures:x:
109 * The starting x position of the window on the screen.
113 g_object_class_install_property(gobject_class,
118 "The starting x position of the window on the screen.",
125 * WebKitWebWindowFeatures:y:
127 * The starting y position of the window on the screen.
131 g_object_class_install_property(gobject_class,
136 "The starting y position of the window on the screen.",
143 * WebKitWebWindowFeatures:width:
145 * The width of the window on the screen.
149 g_object_class_install_property(gobject_class,
154 "The width of the window on the screen.",
161 * WebKitWebWindowFeatures:height:
163 * The height of the window on the screen.
167 g_object_class_install_property(gobject_class,
172 "The height of the window on the screen.",
179 * WebKitWebWindowFeatures:toolbar-visible:
181 * Controls whether the toolbar should be visible for the window.
185 g_object_class_install_property(gobject_class,
186 PROP_TOOLBAR_VISIBLE,
187 g_param_spec_boolean(
190 "Controls whether the toolbar should be visible for the window.",
195 * WebKitWebWindowFeatures:statusbar-visible:
197 * Controls whether the statusbar should be visible for the window.
201 g_object_class_install_property(gobject_class,
202 PROP_STATUSBAR_VISIBLE,
203 g_param_spec_boolean(
206 "Controls whether the statusbar should be visible for the window.",
211 * WebKitWebWindowFeatures:scrollbar-visible:
213 * Controls whether the scrollbars should be visible for the window.
217 g_object_class_install_property(gobject_class,
218 PROP_SCROLLBAR_VISIBLE,
219 g_param_spec_boolean(
222 "Controls whether the scrollbars should be visible for the window.",
227 * WebKitWebWindowFeatures:menubar-visible:
229 * Controls whether the menubar should be visible for the window.
233 g_object_class_install_property(gobject_class,
234 PROP_MENUBAR_VISIBLE,
235 g_param_spec_boolean(
238 "Controls whether the menubar should be visible for the window.",
243 * WebKitWebWindowFeatures:locationbar-visible:
245 * Controls whether the locationbar should be visible for the window.
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.",
259 * WebKitWebWindowFeatures:fullscreen:
261 * Controls whether window will be displayed fullscreen.
265 g_object_class_install_property(gobject_class,
267 g_param_spec_boolean(
270 "Controls whether window will be displayed fullscreen.",
275 g_type_class_add_private(klass, sizeof(WebKitWebWindowFeaturesPrivate));
278 static void webkit_web_window_features_init(WebKitWebWindowFeatures* web_window_features)
280 web_window_features->priv = G_TYPE_INSTANCE_GET_PRIVATE(web_window_features, WEBKIT_TYPE_WEB_WINDOW_FEATURES, WebKitWebWindowFeaturesPrivate);
283 static void webkit_web_window_features_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec)
285 WebKitWebWindowFeatures* web_window_features = WEBKIT_WEB_WINDOW_FEATURES(object);
286 WebKitWebWindowFeaturesPrivate* priv = web_window_features->priv;
290 priv->x = g_value_get_int(value);
293 priv->y = g_value_get_int(value);
296 priv->width = g_value_get_int(value);
299 priv->height = g_value_get_int(value);
301 case PROP_TOOLBAR_VISIBLE:
302 priv->toolbar_visible = g_value_get_boolean(value);
304 case PROP_STATUSBAR_VISIBLE:
305 priv->statusbar_visible = g_value_get_boolean(value);
307 case PROP_SCROLLBAR_VISIBLE:
308 priv->scrollbar_visible = g_value_get_boolean(value);
310 case PROP_MENUBAR_VISIBLE:
311 priv->menubar_visible = g_value_get_boolean(value);
313 case PROP_LOCATIONBAR_VISIBLE:
314 priv->locationbar_visible = g_value_get_boolean(value);
316 case PROP_FULLSCREEN:
317 priv->fullscreen = g_value_get_boolean(value);
320 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
325 static void webkit_web_window_features_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec)
327 WebKitWebWindowFeatures* web_window_features = WEBKIT_WEB_WINDOW_FEATURES(object);
328 WebKitWebWindowFeaturesPrivate* priv = web_window_features->priv;
332 g_value_set_int(value, priv->x);
335 g_value_set_int(value, priv->y);
338 g_value_set_int(value, priv->width);
341 g_value_set_int(value, priv->height);
343 case PROP_TOOLBAR_VISIBLE:
344 g_value_set_boolean(value, priv->toolbar_visible);
346 case PROP_STATUSBAR_VISIBLE:
347 g_value_set_boolean(value, priv->statusbar_visible);
349 case PROP_SCROLLBAR_VISIBLE:
350 g_value_set_boolean(value, priv->scrollbar_visible);
352 case PROP_MENUBAR_VISIBLE:
353 g_value_set_boolean(value, priv->menubar_visible);
355 case PROP_LOCATIONBAR_VISIBLE:
356 g_value_set_boolean(value, priv->locationbar_visible);
358 case PROP_FULLSCREEN:
359 g_value_set_boolean(value, priv->fullscreen);
362 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
368 * webkit_web_window_features_new:
370 * Creates a new #WebKitWebWindowFeatures instance with default values. It must
371 * be manually attached to a WebView.
373 * Returns: a new #WebKitWebWindowFeatures instance
377 WebKitWebWindowFeatures* webkit_web_window_features_new()
379 return WEBKIT_WEB_WINDOW_FEATURES(g_object_new(WEBKIT_TYPE_WEB_WINDOW_FEATURES, NULL));
383 * webkit_web_window_features_equal:
384 * @features1: a #WebKitWebWindowFeatures instance
385 * @features2: another #WebKitWebWindowFeatures instance
387 * Decides if a #WebKitWebWindowFeatures instance equals another, as
388 * in has the same values.
390 * Returns: %TRUE if the instances have the same values, %FALSE
395 gboolean webkit_web_window_features_equal(WebKitWebWindowFeatures* features1, WebKitWebWindowFeatures* features2)
397 if (features1 == features2)
399 if (!features1 || !features2)
402 WebKitWebWindowFeaturesPrivate* priv1 = features1->priv;
403 WebKitWebWindowFeaturesPrivate* priv2 = features2->priv;
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))
421 WebKitWebWindowFeatures* kitNew(const WebCore::WindowFeatures& features)
423 WebKitWebWindowFeatures *webWindowFeatures = webkit_web_window_features_new();
426 g_object_set(webWindowFeatures, "x", static_cast<int>(features.x), NULL);
429 g_object_set(webWindowFeatures, "y", static_cast<int>(features.y), NULL);
431 if(features.widthSet)
432 g_object_set(webWindowFeatures, "width", static_cast<int>(features.width), NULL);
434 if(features.heightSet)
435 g_object_set(webWindowFeatures, "height", static_cast<int>(features.height), NULL);
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,
446 return webWindowFeatures;