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 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
|
/*
* Copyright (C) 2011 Igalia S.L.
*
* 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 "WebKitWindowProperties.h"
#include "ImmutableDictionary.h"
#include "WebKitPrivate.h"
#include "WebKitWindowPropertiesPrivate.h"
#include "WebNumber.h"
#include "WebURLRequest.h"
#include <WebCore/IntRect.h>
#include <glib/gi18n-lib.h>
using namespace WebKit;
using namespace WebCore;
/**
* SECTION: WebKitWindowProperties
* @short_description: Window properties of a #WebKitWebView
* @title: WebKitWindowProperties
* @see_also: #WebKitWebView::ready-to-show
*
* The content of a #WebKitWebView can request to change certain
* properties of the window containing the view. This can include the x, y position
* of the window, the width and height but also if a toolbar,
* scrollbar, statusbar, locationbar should be visible to the user,
* and the request to show the #WebKitWebView fullscreen.
*
* The #WebKitWebView::ready-to-show signal handler is the proper place
* to apply the initial window properties. Then you can monitor the
* #WebKitWindowProperties by connecting to ::notify signal.
*
* <informalexample><programlisting>
* static void ready_to_show_cb (WebKitWebView *web_view, gpointer user_data)
* {
* GtkWidget *window;
* WebKitWindowProperties *window_properties;
* gboolean visible;
*
* /<!-- -->* Create the window to contain the WebKitWebView *<!-- -->/
* window = browser_window_new ();
* gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (web_view));
* gtk_widget_show (GTK_WIDGET (web_view));
*
* /<!-- -->* Get the WebKitWindowProperties of the web view and monitor it *<!-- -->/
* window_properties = webkit_web_view_get_window_properties (web_view);
* g_signal_connect (window_properties, "notify::geometry",
* G_CALLBACK (window_geometry_changed), window);
* g_signal_connect (window_properties, "notify::toolbar-visible",
* G_CALLBACK (window_toolbar_visibility_changed), window);
* g_signal_connect (window_properties, "notify::menubar-visible",
* G_CALLBACK (window_menubar_visibility_changed), window);
* ....
*
* /<!-- -->* Apply the window properties before showing the window *<!-- -->/
* visible = webkit_window_properties_get_toolbar_visible (window_properties);
* browser_window_set_toolbar_visible (BROWSER_WINDOW (window), visible);
* visible = webkit_window_properties_get_menubar_visible (window_properties);
* browser_window_set_menubar_visible (BROWSER_WINDOW (window), visible);
* ....
*
* if (webkit_window_properties_get_fullscreen (window_properties)) {
* gtk_window_fullscreen (GTK_WINDOW (window));
* } else {
* GdkRectangle geometry;
*
* gtk_window_set_resizable (GTK_WINDOW (window),
* webkit_window_properties_get_resizable (window_properties));
* webkit_window_properties_get_geometry (window_properties, &geometry);
* gtk_window_move (GTK_WINDOW (window), geometry.x, geometry.y);
* gtk_window_resize (GTK_WINDOW (window), geometry.width, geometry.height);
* }
*
* gtk_widget_show (window);
* }
* </programlisting></informalexample>
*/
enum {
PROP_0,
PROP_GEOMETRY,
PROP_TOOLBAR_VISIBLE,
PROP_STATUSBAR_VISIBLE,
PROP_SCROLLBARS_VISIBLE,
PROP_MENUBAR_VISIBLE,
PROP_LOCATIONBAR_VISIBLE,
PROP_RESIZABLE,
PROP_FULLSCREEN
};
struct _WebKitWindowPropertiesPrivate {
GdkRectangle geometry;
bool toolbarVisible : 1;
bool statusbarVisible : 1;
bool scrollbarsVisible : 1;
bool menubarVisible : 1;
bool locationbarVisible : 1;
bool resizable : 1;
bool fullscreen : 1;
};
WEBKIT_DEFINE_TYPE(WebKitWindowProperties, webkit_window_properties, G_TYPE_OBJECT)
static void webkitWindowPropertiesGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec)
{
WebKitWindowProperties* windowProperties = WEBKIT_WINDOW_PROPERTIES(object);
switch (propId) {
case PROP_GEOMETRY:
g_value_set_boxed(value, &windowProperties->priv->geometry);
break;
case PROP_TOOLBAR_VISIBLE:
g_value_set_boolean(value, webkit_window_properties_get_toolbar_visible(windowProperties));
break;
case PROP_STATUSBAR_VISIBLE:
g_value_set_boolean(value, webkit_window_properties_get_statusbar_visible(windowProperties));
break;
case PROP_SCROLLBARS_VISIBLE:
g_value_set_boolean(value, webkit_window_properties_get_scrollbars_visible(windowProperties));
break;
case PROP_MENUBAR_VISIBLE:
g_value_set_boolean(value, webkit_window_properties_get_menubar_visible(windowProperties));
break;
case PROP_LOCATIONBAR_VISIBLE:
g_value_set_boolean(value, webkit_window_properties_get_locationbar_visible(windowProperties));
break;
case PROP_RESIZABLE:
g_value_set_boolean(value, webkit_window_properties_get_resizable(windowProperties));
break;
case PROP_FULLSCREEN:
g_value_set_boolean(value, webkit_window_properties_get_fullscreen(windowProperties));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
}
}
static void webkitWindowPropertiesSetProperty(GObject* object, guint propId, const GValue* value, GParamSpec* paramSpec)
{
WebKitWindowProperties* windowProperties = WEBKIT_WINDOW_PROPERTIES(object);
switch (propId) {
case PROP_GEOMETRY:
if (GdkRectangle* geometry = static_cast<GdkRectangle*>(g_value_get_boxed(value)))
windowProperties->priv->geometry = *geometry;
break;
case PROP_TOOLBAR_VISIBLE:
windowProperties->priv->toolbarVisible = g_value_get_boolean(value);
break;
case PROP_STATUSBAR_VISIBLE:
windowProperties->priv->statusbarVisible = g_value_get_boolean(value);
break;
case PROP_SCROLLBARS_VISIBLE:
windowProperties->priv->scrollbarsVisible = g_value_get_boolean(value);
break;
case PROP_MENUBAR_VISIBLE:
windowProperties->priv->menubarVisible = g_value_get_boolean(value);
break;
case PROP_LOCATIONBAR_VISIBLE:
windowProperties->priv->locationbarVisible = g_value_get_boolean(value);
break;
case PROP_RESIZABLE:
windowProperties->priv->resizable = g_value_get_boolean(value);
break;
case PROP_FULLSCREEN:
windowProperties->priv->fullscreen = g_value_get_boolean(value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
}
}
static void webkit_window_properties_class_init(WebKitWindowPropertiesClass* requestClass)
{
GObjectClass* objectClass = G_OBJECT_CLASS(requestClass);
objectClass->get_property = webkitWindowPropertiesGetProperty;
objectClass->set_property = webkitWindowPropertiesSetProperty;
GParamFlags paramFlags = static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
/**
* WebKitWebWindowProperties:geometry:
*
* The size and position of the window on the screen.
*/
g_object_class_install_property(objectClass,
PROP_GEOMETRY,
g_param_spec_boxed("geometry",
_("Geometry"),
_("The size and position of the window on the screen."),
GDK_TYPE_RECTANGLE,
paramFlags));
/**
* WebKitWebWindowProperties:toolbar-visible:
*
* Whether the toolbar should be visible for the window.
*/
g_object_class_install_property(objectClass,
PROP_TOOLBAR_VISIBLE,
g_param_spec_boolean("toolbar-visible",
_("Toolbar Visible"),
_("Whether the toolbar should be visible for the window."),
TRUE,
paramFlags));
/**
* WebKitWebWindowProperties:statusbar-visible:
*
* Whether the statusbar should be visible for the window.
*/
g_object_class_install_property(objectClass,
PROP_STATUSBAR_VISIBLE,
g_param_spec_boolean("statusbar-visible",
_("Statusbar Visible"),
_("Whether the statusbar should be visible for the window."),
TRUE,
paramFlags));
/**
* WebKitWebWindowProperties:scrollbars-visible:
*
* Whether the scrollbars should be visible for the window.
*/
g_object_class_install_property(objectClass,
PROP_SCROLLBARS_VISIBLE,
g_param_spec_boolean("scrollbars-visible",
_("Scrollbars Visible"),
_("Whether the scrollbars should be visible for the window."),
TRUE,
paramFlags));
/**
* WebKitWebWindowProperties:menubar-visible:
*
* Whether the menubar should be visible for the window.
*/
g_object_class_install_property(objectClass,
PROP_MENUBAR_VISIBLE,
g_param_spec_boolean("menubar-visible",
_("Menubar Visible"),
_("Whether the menubar should be visible for the window."),
TRUE,
paramFlags));
/**
* WebKitWebWindowProperties:locationbar-visible:
*
* Whether the locationbar should be visible for the window.
*/
g_object_class_install_property(objectClass,
PROP_LOCATIONBAR_VISIBLE,
g_param_spec_boolean("locationbar-visible",
_("Locationbar Visible"),
_("Whether the locationbar should be visible for the window."),
TRUE,
paramFlags));
/**
* WebKitWebWindowProperties:resizable:
*
* Whether the window can be resized.
*/
g_object_class_install_property(objectClass,
PROP_RESIZABLE,
g_param_spec_boolean("resizable",
_("Resizable"),
_("Whether the window can be resized."),
TRUE,
paramFlags));
/**
* WebKitWebWindowProperties:fullscreen:
*
* Whether window will be displayed fullscreen.
*/
g_object_class_install_property(objectClass,
PROP_FULLSCREEN,
g_param_spec_boolean("fullscreen",
_("Fullscreen"),
_("Whether window will be displayed fullscreen."),
FALSE,
paramFlags));
}
WebKitWindowProperties* webkitWindowPropertiesCreate()
{
return WEBKIT_WINDOW_PROPERTIES(g_object_new(WEBKIT_TYPE_WINDOW_PROPERTIES, NULL));
}
void webkitWindowPropertiesSetGeometry(WebKitWindowProperties* windowProperties, GdkRectangle* geometry)
{
if (windowProperties->priv->geometry.x == geometry->x
&& windowProperties->priv->geometry.y == geometry->y
&& windowProperties->priv->geometry.width == geometry->width
&& windowProperties->priv->geometry.height == geometry->height)
return;
windowProperties->priv->geometry = *geometry;
g_object_notify(G_OBJECT(windowProperties), "geometry");
}
void webkitWindowPropertiesSetToolbarVisible(WebKitWindowProperties* windowProperties, bool toolbarsVisible)
{
if (windowProperties->priv->toolbarVisible == toolbarsVisible)
return;
windowProperties->priv->toolbarVisible = toolbarsVisible;
g_object_notify(G_OBJECT(windowProperties), "toolbar-visible");
}
void webkitWindowPropertiesSetMenubarVisible(WebKitWindowProperties* windowProperties, bool menuBarVisible)
{
if (windowProperties->priv->menubarVisible == menuBarVisible)
return;
windowProperties->priv->menubarVisible = menuBarVisible;
g_object_notify(G_OBJECT(windowProperties), "menubar-visible");
}
void webkitWindowPropertiesSetStatusbarVisible(WebKitWindowProperties* windowProperties, bool statusBarVisible)
{
if (windowProperties->priv->statusbarVisible == statusBarVisible)
return;
windowProperties->priv->statusbarVisible = statusBarVisible;
g_object_notify(G_OBJECT(windowProperties), "statusbar-visible");
}
void webkitWindowPropertiesSetLocationbarVisible(WebKitWindowProperties* windowProperties, bool locationBarVisible)
{
if (windowProperties->priv->locationbarVisible == locationBarVisible)
return;
windowProperties->priv->locationbarVisible = locationBarVisible;
g_object_notify(G_OBJECT(windowProperties), "locationbar-visible");
}
void webkitWindowPropertiesSetScrollbarsVisible(WebKitWindowProperties* windowProperties, bool scrollBarsVisible)
{
if (windowProperties->priv->scrollbarsVisible == scrollBarsVisible)
return;
windowProperties->priv->scrollbarsVisible = scrollBarsVisible;
g_object_notify(G_OBJECT(windowProperties), "scrollbars-visible");
}
void webkitWindowPropertiesSetResizable(WebKitWindowProperties* windowProperties, bool resizable)
{
if (windowProperties->priv->resizable == resizable)
return;
windowProperties->priv->resizable = resizable;
g_object_notify(G_OBJECT(windowProperties), "resizable");
}
void webkitWindowPropertiesSetFullscreen(WebKitWindowProperties* windowProperties, bool fullscreen)
{
if (windowProperties->priv->fullscreen == fullscreen)
return;
windowProperties->priv->fullscreen = fullscreen;
g_object_notify(G_OBJECT(windowProperties), "fullscreen");
}
void webkitWindowPropertiesUpdateFromWebWindowFeatures(WebKitWindowProperties* windowProperties, ImmutableDictionary* features)
{
GdkRectangle geometry = windowProperties->priv->geometry;
WebDouble* doubleValue = static_cast<WebDouble*>(features->get("x"));
if (doubleValue)
geometry.x = doubleValue->value();
doubleValue = static_cast<WebDouble*>(features->get("y"));
if (doubleValue)
geometry.y = doubleValue->value();
doubleValue = static_cast<WebDouble*>(features->get("width"));
if (doubleValue)
geometry.width = doubleValue->value();
doubleValue = static_cast<WebDouble*>(features->get("height"));
if (doubleValue)
geometry.height = doubleValue->value();
webkitWindowPropertiesSetGeometry(windowProperties, &geometry);
WebBoolean* booleanValue = static_cast<WebBoolean*>(features->get("menuBarVisible"));
if (booleanValue)
webkitWindowPropertiesSetMenubarVisible(windowProperties, booleanValue->value());
booleanValue = static_cast<WebBoolean*>(features->get("statusBarVisible"));
if (booleanValue)
webkitWindowPropertiesSetStatusbarVisible(windowProperties, booleanValue->value());
booleanValue = static_cast<WebBoolean*>(features->get("toolBarVisible"));
if (booleanValue)
webkitWindowPropertiesSetToolbarVisible(windowProperties, booleanValue->value());
booleanValue = static_cast<WebBoolean*>(features->get("locationBarVisible"));
if (booleanValue)
webkitWindowPropertiesSetLocationbarVisible(windowProperties, booleanValue->value());
booleanValue = static_cast<WebBoolean*>(features->get("scrollbarsVisible"));
if (booleanValue)
webkitWindowPropertiesSetScrollbarsVisible(windowProperties, booleanValue->value());
booleanValue = static_cast<WebBoolean*>(features->get("resizable"));
if (booleanValue)
webkitWindowPropertiesSetResizable(windowProperties, booleanValue->value());
booleanValue = static_cast<WebBoolean*>(features->get("fullscreen"));
if (booleanValue)
webkitWindowPropertiesSetFullscreen(windowProperties, booleanValue->value());
}
/**
* webkit_window_properties_get_geometry:
* @window_properties: a #WebKitWindowProperties
* @geometry: (out): return location for the window geometry
*
* Get the geometry the window should have on the screen when shown.
*/
void webkit_window_properties_get_geometry(WebKitWindowProperties* windowProperties, GdkRectangle* geometry)
{
g_return_if_fail(WEBKIT_IS_WINDOW_PROPERTIES(windowProperties));
g_return_if_fail(geometry);
*geometry = windowProperties->priv->geometry;
}
/**
* webkit_window_properties_get_toolbar_visible:
* @window_properties: a #WebKitWindowProperties
*
* Get whether the window should have the toolbar visible or not.
*
* Returns: %TRUE if toolbar should be visible or %FALSE otherwise.
*/
gboolean webkit_window_properties_get_toolbar_visible(WebKitWindowProperties* windowProperties)
{
g_return_val_if_fail(WEBKIT_IS_WINDOW_PROPERTIES(windowProperties), TRUE);
return windowProperties->priv->toolbarVisible;
}
/**
* webkit_window_properties_get_statusbar_visible:
* @window_properties: a #WebKitWindowProperties
*
* Get whether the window should have the statusbar visible or not.
*
* Returns: %TRUE if statusbar should be visible or %FALSE otherwise.
*/
gboolean webkit_window_properties_get_statusbar_visible(WebKitWindowProperties* windowProperties)
{
g_return_val_if_fail(WEBKIT_IS_WINDOW_PROPERTIES(windowProperties), TRUE);
return windowProperties->priv->statusbarVisible;
}
/**
* webkit_window_properties_get_scrollbars_visible:
* @window_properties: a #WebKitWindowProperties
*
* Get whether the window should have the scrollbars visible or not.
*
* Returns: %TRUE if scrollbars should be visible or %FALSE otherwise.
*/
gboolean webkit_window_properties_get_scrollbars_visible(WebKitWindowProperties* windowProperties)
{
g_return_val_if_fail(WEBKIT_IS_WINDOW_PROPERTIES(windowProperties), TRUE);
return windowProperties->priv->scrollbarsVisible;
}
/**
* webkit_window_properties_get_menubar_visible:
* @window_properties: a #WebKitWindowProperties
*
* Get whether the window should have the menubar visible or not.
*
* Returns: %TRUE if menubar should be visible or %FALSE otherwise.
*/
gboolean webkit_window_properties_get_menubar_visible(WebKitWindowProperties* windowProperties)
{
g_return_val_if_fail(WEBKIT_IS_WINDOW_PROPERTIES(windowProperties), TRUE);
return windowProperties->priv->menubarVisible;
}
/**
* webkit_window_properties_get_locationbar_visible:
* @window_properties: a #WebKitWindowProperties
*
* Get whether the window should have the locationbar visible or not.
*
* Returns: %TRUE if locationbar should be visible or %FALSE otherwise.
*/
gboolean webkit_window_properties_get_locationbar_visible(WebKitWindowProperties* windowProperties)
{
g_return_val_if_fail(WEBKIT_IS_WINDOW_PROPERTIES(windowProperties), TRUE);
return windowProperties->priv->locationbarVisible;
}
/**
* webkit_window_properties_get_resizable:
* @window_properties: a #WebKitWindowProperties
*
* Get whether the window should be resizable by the user or not.
*
* Returns: %TRUE if the window should be resizable or %FALSE otherwise.
*/
gboolean webkit_window_properties_get_resizable(WebKitWindowProperties* windowProperties)
{
g_return_val_if_fail(WEBKIT_IS_WINDOW_PROPERTIES(windowProperties), TRUE);
return windowProperties->priv->resizable;
}
/**
* webkit_window_properties_get_fullscreen:
* @window_properties: a #WebKitWindowProperties
*
* Get whether the window should be shown in fullscreen state or not.
*
* Returns: %TRUE if the window should be fullscreen or %FALSE otherwise.
*/
gboolean webkit_window_properties_get_fullscreen(WebKitWindowProperties* windowProperties)
{
g_return_val_if_fail(WEBKIT_IS_WINDOW_PROPERTIES(windowProperties), FALSE);
return windowProperties->priv->fullscreen;
}
|