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