2
* Copyright (C) 2011 Igalia S.L.
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Library General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Library General Public License for more details.
14
* You should have received a copy of the GNU Library General Public License
15
* along with this library; see the file COPYING.LIB. If not, write to
16
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301, USA.
21
#include "WebKitWindowProperties.h"
23
#include "ImmutableDictionary.h"
24
#include "WebKitPrivate.h"
25
#include "WebKitWindowPropertiesPrivate.h"
26
#include "WebNumber.h"
27
#include "WebURLRequest.h"
28
#include <WebCore/IntRect.h>
29
#include <glib/gi18n-lib.h>
31
using namespace WebKit;
32
using namespace WebCore;
35
* SECTION: WebKitWindowProperties
36
* @short_description: Window properties of a #WebKitWebView
37
* @title: WebKitWindowProperties
38
* @see_also: #WebKitWebView::ready-to-show
40
* The content of a #WebKitWebView can request to change certain
41
* properties of the window containing the view. This can include the x, y position
42
* of the window, the width and height but also if a toolbar,
43
* scrollbar, statusbar, locationbar should be visible to the user,
44
* and the request to show the #WebKitWebView fullscreen.
46
* The #WebKitWebView::ready-to-show signal handler is the proper place
47
* to apply the initial window properties. Then you can monitor the
48
* #WebKitWindowProperties by connecting to ::notify signal.
50
* <informalexample><programlisting>
51
* static void ready_to_show_cb (WebKitWebView *web_view, gpointer user_data)
54
* WebKitWindowProperties *window_properties;
57
* /<!-- -->* Create the window to contain the WebKitWebView *<!-- -->/
58
* window = browser_window_new ();
59
* gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (web_view));
60
* gtk_widget_show (GTK_WIDGET (web_view));
62
* /<!-- -->* Get the WebKitWindowProperties of the web view and monitor it *<!-- -->/
63
* window_properties = webkit_web_view_get_window_properties (web_view);
64
* g_signal_connect (window_properties, "notify::geometry",
65
* G_CALLBACK (window_geometry_changed), window);
66
* g_signal_connect (window_properties, "notify::toolbar-visible",
67
* G_CALLBACK (window_toolbar_visibility_changed), window);
68
* g_signal_connect (window_properties, "notify::menubar-visible",
69
* G_CALLBACK (window_menubar_visibility_changed), window);
72
* /<!-- -->* Apply the window properties before showing the window *<!-- -->/
73
* visible = webkit_window_properties_get_toolbar_visible (window_properties);
74
* browser_window_set_toolbar_visible (BROWSER_WINDOW (window), visible);
75
* visible = webkit_window_properties_get_menubar_visible (window_properties);
76
* browser_window_set_menubar_visible (BROWSER_WINDOW (window), visible);
79
* if (webkit_window_properties_get_fullscreen (window_properties)) {
80
* gtk_window_fullscreen (GTK_WINDOW (window));
82
* GdkRectangle geometry;
84
* gtk_window_set_resizable (GTK_WINDOW (window),
85
* webkit_window_properties_get_resizable (window_properties));
86
* webkit_window_properties_get_geometry (window_properties, &geometry);
87
* gtk_window_move (GTK_WINDOW (window), geometry.x, geometry.y);
88
* gtk_window_resize (GTK_WINDOW (window), geometry.width, geometry.height);
91
* gtk_widget_show (window);
93
* </programlisting></informalexample>
100
PROP_TOOLBAR_VISIBLE,
101
PROP_STATUSBAR_VISIBLE,
102
PROP_SCROLLBARS_VISIBLE,
103
PROP_MENUBAR_VISIBLE,
104
PROP_LOCATIONBAR_VISIBLE,
109
struct _WebKitWindowPropertiesPrivate {
110
GdkRectangle geometry;
112
bool toolbarVisible : 1;
113
bool statusbarVisible : 1;
114
bool scrollbarsVisible : 1;
115
bool menubarVisible : 1;
116
bool locationbarVisible : 1;
122
WEBKIT_DEFINE_TYPE(WebKitWindowProperties, webkit_window_properties, G_TYPE_OBJECT)
124
static void webkitWindowPropertiesGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec)
126
WebKitWindowProperties* windowProperties = WEBKIT_WINDOW_PROPERTIES(object);
130
g_value_set_boxed(value, &windowProperties->priv->geometry);
132
case PROP_TOOLBAR_VISIBLE:
133
g_value_set_boolean(value, webkit_window_properties_get_toolbar_visible(windowProperties));
135
case PROP_STATUSBAR_VISIBLE:
136
g_value_set_boolean(value, webkit_window_properties_get_statusbar_visible(windowProperties));
138
case PROP_SCROLLBARS_VISIBLE:
139
g_value_set_boolean(value, webkit_window_properties_get_scrollbars_visible(windowProperties));
141
case PROP_MENUBAR_VISIBLE:
142
g_value_set_boolean(value, webkit_window_properties_get_menubar_visible(windowProperties));
144
case PROP_LOCATIONBAR_VISIBLE:
145
g_value_set_boolean(value, webkit_window_properties_get_locationbar_visible(windowProperties));
148
g_value_set_boolean(value, webkit_window_properties_get_resizable(windowProperties));
150
case PROP_FULLSCREEN:
151
g_value_set_boolean(value, webkit_window_properties_get_fullscreen(windowProperties));
154
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
158
static void webkitWindowPropertiesSetProperty(GObject* object, guint propId, const GValue* value, GParamSpec* paramSpec)
160
WebKitWindowProperties* windowProperties = WEBKIT_WINDOW_PROPERTIES(object);
164
if (GdkRectangle* geometry = static_cast<GdkRectangle*>(g_value_get_boxed(value)))
165
windowProperties->priv->geometry = *geometry;
167
case PROP_TOOLBAR_VISIBLE:
168
windowProperties->priv->toolbarVisible = g_value_get_boolean(value);
170
case PROP_STATUSBAR_VISIBLE:
171
windowProperties->priv->statusbarVisible = g_value_get_boolean(value);
173
case PROP_SCROLLBARS_VISIBLE:
174
windowProperties->priv->scrollbarsVisible = g_value_get_boolean(value);
176
case PROP_MENUBAR_VISIBLE:
177
windowProperties->priv->menubarVisible = g_value_get_boolean(value);
179
case PROP_LOCATIONBAR_VISIBLE:
180
windowProperties->priv->locationbarVisible = g_value_get_boolean(value);
183
windowProperties->priv->resizable = g_value_get_boolean(value);
185
case PROP_FULLSCREEN:
186
windowProperties->priv->fullscreen = g_value_get_boolean(value);
189
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
193
static void webkit_window_properties_class_init(WebKitWindowPropertiesClass* requestClass)
195
GObjectClass* objectClass = G_OBJECT_CLASS(requestClass);
196
objectClass->get_property = webkitWindowPropertiesGetProperty;
197
objectClass->set_property = webkitWindowPropertiesSetProperty;
199
GParamFlags paramFlags = static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
202
* WebKitWebWindowProperties:geometry:
204
* The size and position of the window on the screen.
206
g_object_class_install_property(objectClass,
208
g_param_spec_boxed("geometry",
210
_("The size and position of the window on the screen."),
215
* WebKitWebWindowProperties:toolbar-visible:
217
* Whether the toolbar should be visible for the window.
219
g_object_class_install_property(objectClass,
220
PROP_TOOLBAR_VISIBLE,
221
g_param_spec_boolean("toolbar-visible",
222
_("Toolbar Visible"),
223
_("Whether the toolbar should be visible for the window."),
228
* WebKitWebWindowProperties:statusbar-visible:
230
* Whether the statusbar should be visible for the window.
232
g_object_class_install_property(objectClass,
233
PROP_STATUSBAR_VISIBLE,
234
g_param_spec_boolean("statusbar-visible",
235
_("Statusbar Visible"),
236
_("Whether the statusbar should be visible for the window."),
241
* WebKitWebWindowProperties:scrollbars-visible:
243
* Whether the scrollbars should be visible for the window.
245
g_object_class_install_property(objectClass,
246
PROP_SCROLLBARS_VISIBLE,
247
g_param_spec_boolean("scrollbars-visible",
248
_("Scrollbars Visible"),
249
_("Whether the scrollbars should be visible for the window."),
254
* WebKitWebWindowProperties:menubar-visible:
256
* Whether the menubar should be visible for the window.
258
g_object_class_install_property(objectClass,
259
PROP_MENUBAR_VISIBLE,
260
g_param_spec_boolean("menubar-visible",
261
_("Menubar Visible"),
262
_("Whether the menubar should be visible for the window."),
267
* WebKitWebWindowProperties:locationbar-visible:
269
* Whether the locationbar should be visible for the window.
271
g_object_class_install_property(objectClass,
272
PROP_LOCATIONBAR_VISIBLE,
273
g_param_spec_boolean("locationbar-visible",
274
_("Locationbar Visible"),
275
_("Whether the locationbar should be visible for the window."),
279
* WebKitWebWindowProperties:resizable:
281
* Whether the window can be resized.
283
g_object_class_install_property(objectClass,
285
g_param_spec_boolean("resizable",
287
_("Whether the window can be resized."),
292
* WebKitWebWindowProperties:fullscreen:
294
* Whether window will be displayed fullscreen.
296
g_object_class_install_property(objectClass,
298
g_param_spec_boolean("fullscreen",
300
_("Whether window will be displayed fullscreen."),
305
WebKitWindowProperties* webkitWindowPropertiesCreate()
307
return WEBKIT_WINDOW_PROPERTIES(g_object_new(WEBKIT_TYPE_WINDOW_PROPERTIES, NULL));
310
void webkitWindowPropertiesSetGeometry(WebKitWindowProperties* windowProperties, GdkRectangle* geometry)
312
if (windowProperties->priv->geometry.x == geometry->x
313
&& windowProperties->priv->geometry.y == geometry->y
314
&& windowProperties->priv->geometry.width == geometry->width
315
&& windowProperties->priv->geometry.height == geometry->height)
317
windowProperties->priv->geometry = *geometry;
318
g_object_notify(G_OBJECT(windowProperties), "geometry");
321
void webkitWindowPropertiesSetToolbarVisible(WebKitWindowProperties* windowProperties, bool toolbarsVisible)
323
if (windowProperties->priv->toolbarVisible == toolbarsVisible)
325
windowProperties->priv->toolbarVisible = toolbarsVisible;
326
g_object_notify(G_OBJECT(windowProperties), "toolbar-visible");
329
void webkitWindowPropertiesSetMenubarVisible(WebKitWindowProperties* windowProperties, bool menuBarVisible)
331
if (windowProperties->priv->menubarVisible == menuBarVisible)
333
windowProperties->priv->menubarVisible = menuBarVisible;
334
g_object_notify(G_OBJECT(windowProperties), "menubar-visible");
337
void webkitWindowPropertiesSetStatusbarVisible(WebKitWindowProperties* windowProperties, bool statusBarVisible)
339
if (windowProperties->priv->statusbarVisible == statusBarVisible)
341
windowProperties->priv->statusbarVisible = statusBarVisible;
342
g_object_notify(G_OBJECT(windowProperties), "statusbar-visible");
345
void webkitWindowPropertiesSetLocationbarVisible(WebKitWindowProperties* windowProperties, bool locationBarVisible)
347
if (windowProperties->priv->locationbarVisible == locationBarVisible)
349
windowProperties->priv->locationbarVisible = locationBarVisible;
350
g_object_notify(G_OBJECT(windowProperties), "locationbar-visible");
353
void webkitWindowPropertiesSetScrollbarsVisible(WebKitWindowProperties* windowProperties, bool scrollBarsVisible)
355
if (windowProperties->priv->scrollbarsVisible == scrollBarsVisible)
357
windowProperties->priv->scrollbarsVisible = scrollBarsVisible;
358
g_object_notify(G_OBJECT(windowProperties), "scrollbars-visible");
361
void webkitWindowPropertiesSetResizable(WebKitWindowProperties* windowProperties, bool resizable)
363
if (windowProperties->priv->resizable == resizable)
365
windowProperties->priv->resizable = resizable;
366
g_object_notify(G_OBJECT(windowProperties), "resizable");
369
void webkitWindowPropertiesSetFullscreen(WebKitWindowProperties* windowProperties, bool fullscreen)
371
if (windowProperties->priv->fullscreen == fullscreen)
373
windowProperties->priv->fullscreen = fullscreen;
374
g_object_notify(G_OBJECT(windowProperties), "fullscreen");
377
void webkitWindowPropertiesUpdateFromWebWindowFeatures(WebKitWindowProperties* windowProperties, ImmutableDictionary* features)
379
GdkRectangle geometry = windowProperties->priv->geometry;
381
WebDouble* doubleValue = static_cast<WebDouble*>(features->get("x"));
383
geometry.x = doubleValue->value();
385
doubleValue = static_cast<WebDouble*>(features->get("y"));
387
geometry.y = doubleValue->value();
389
doubleValue = static_cast<WebDouble*>(features->get("width"));
391
geometry.width = doubleValue->value();
393
doubleValue = static_cast<WebDouble*>(features->get("height"));
395
geometry.height = doubleValue->value();
396
webkitWindowPropertiesSetGeometry(windowProperties, &geometry);
398
WebBoolean* booleanValue = static_cast<WebBoolean*>(features->get("menuBarVisible"));
400
webkitWindowPropertiesSetMenubarVisible(windowProperties, booleanValue->value());
402
booleanValue = static_cast<WebBoolean*>(features->get("statusBarVisible"));
404
webkitWindowPropertiesSetStatusbarVisible(windowProperties, booleanValue->value());
406
booleanValue = static_cast<WebBoolean*>(features->get("toolBarVisible"));
408
webkitWindowPropertiesSetToolbarVisible(windowProperties, booleanValue->value());
410
booleanValue = static_cast<WebBoolean*>(features->get("locationBarVisible"));
412
webkitWindowPropertiesSetLocationbarVisible(windowProperties, booleanValue->value());
414
booleanValue = static_cast<WebBoolean*>(features->get("scrollbarsVisible"));
416
webkitWindowPropertiesSetScrollbarsVisible(windowProperties, booleanValue->value());
418
booleanValue = static_cast<WebBoolean*>(features->get("resizable"));
420
webkitWindowPropertiesSetResizable(windowProperties, booleanValue->value());
422
booleanValue = static_cast<WebBoolean*>(features->get("fullscreen"));
424
webkitWindowPropertiesSetFullscreen(windowProperties, booleanValue->value());
428
* webkit_window_properties_get_geometry:
429
* @window_properties: a #WebKitWindowProperties
430
* @geometry: (out): return location for the window geometry
432
* Get the geometry the window should have on the screen when shown.
434
void webkit_window_properties_get_geometry(WebKitWindowProperties* windowProperties, GdkRectangle* geometry)
436
g_return_if_fail(WEBKIT_IS_WINDOW_PROPERTIES(windowProperties));
437
g_return_if_fail(geometry);
439
*geometry = windowProperties->priv->geometry;
443
* webkit_window_properties_get_toolbar_visible:
444
* @window_properties: a #WebKitWindowProperties
446
* Get whether the window should have the toolbar visible or not.
448
* Returns: %TRUE if toolbar should be visible or %FALSE otherwise.
450
gboolean webkit_window_properties_get_toolbar_visible(WebKitWindowProperties* windowProperties)
452
g_return_val_if_fail(WEBKIT_IS_WINDOW_PROPERTIES(windowProperties), TRUE);
454
return windowProperties->priv->toolbarVisible;
458
* webkit_window_properties_get_statusbar_visible:
459
* @window_properties: a #WebKitWindowProperties
461
* Get whether the window should have the statusbar visible or not.
463
* Returns: %TRUE if statusbar should be visible or %FALSE otherwise.
465
gboolean webkit_window_properties_get_statusbar_visible(WebKitWindowProperties* windowProperties)
467
g_return_val_if_fail(WEBKIT_IS_WINDOW_PROPERTIES(windowProperties), TRUE);
469
return windowProperties->priv->statusbarVisible;
473
* webkit_window_properties_get_scrollbars_visible:
474
* @window_properties: a #WebKitWindowProperties
476
* Get whether the window should have the scrollbars visible or not.
478
* Returns: %TRUE if scrollbars should be visible or %FALSE otherwise.
480
gboolean webkit_window_properties_get_scrollbars_visible(WebKitWindowProperties* windowProperties)
482
g_return_val_if_fail(WEBKIT_IS_WINDOW_PROPERTIES(windowProperties), TRUE);
484
return windowProperties->priv->scrollbarsVisible;
488
* webkit_window_properties_get_menubar_visible:
489
* @window_properties: a #WebKitWindowProperties
491
* Get whether the window should have the menubar visible or not.
493
* Returns: %TRUE if menubar should be visible or %FALSE otherwise.
495
gboolean webkit_window_properties_get_menubar_visible(WebKitWindowProperties* windowProperties)
497
g_return_val_if_fail(WEBKIT_IS_WINDOW_PROPERTIES(windowProperties), TRUE);
499
return windowProperties->priv->menubarVisible;
503
* webkit_window_properties_get_locationbar_visible:
504
* @window_properties: a #WebKitWindowProperties
506
* Get whether the window should have the locationbar visible or not.
508
* Returns: %TRUE if locationbar should be visible or %FALSE otherwise.
510
gboolean webkit_window_properties_get_locationbar_visible(WebKitWindowProperties* windowProperties)
512
g_return_val_if_fail(WEBKIT_IS_WINDOW_PROPERTIES(windowProperties), TRUE);
514
return windowProperties->priv->locationbarVisible;
518
* webkit_window_properties_get_resizable:
519
* @window_properties: a #WebKitWindowProperties
521
* Get whether the window should be resizable by the user or not.
523
* Returns: %TRUE if the window should be resizable or %FALSE otherwise.
525
gboolean webkit_window_properties_get_resizable(WebKitWindowProperties* windowProperties)
527
g_return_val_if_fail(WEBKIT_IS_WINDOW_PROPERTIES(windowProperties), TRUE);
529
return windowProperties->priv->resizable;
533
* webkit_window_properties_get_fullscreen:
534
* @window_properties: a #WebKitWindowProperties
536
* Get whether the window should be shown in fullscreen state or not.
538
* Returns: %TRUE if the window should be fullscreen or %FALSE otherwise.
540
gboolean webkit_window_properties_get_fullscreen(WebKitWindowProperties* windowProperties)
542
g_return_val_if_fail(WEBKIT_IS_WINDOW_PROPERTIES(windowProperties), FALSE);
544
return windowProperties->priv->fullscreen;