WebKitWindowProperties.cpp [plain text]
#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;
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);
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));
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));
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));
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));
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));
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));
g_object_class_install_property(objectClass,
PROP_RESIZABLE,
g_param_spec_boolean("resizable",
_("Resizable"),
_("Whether the window can be resized."),
TRUE,
paramFlags));
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());
}
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;
}
gboolean webkit_window_properties_get_toolbar_visible(WebKitWindowProperties* windowProperties)
{
g_return_val_if_fail(WEBKIT_IS_WINDOW_PROPERTIES(windowProperties), TRUE);
return windowProperties->priv->toolbarVisible;
}
gboolean webkit_window_properties_get_statusbar_visible(WebKitWindowProperties* windowProperties)
{
g_return_val_if_fail(WEBKIT_IS_WINDOW_PROPERTIES(windowProperties), TRUE);
return windowProperties->priv->statusbarVisible;
}
gboolean webkit_window_properties_get_scrollbars_visible(WebKitWindowProperties* windowProperties)
{
g_return_val_if_fail(WEBKIT_IS_WINDOW_PROPERTIES(windowProperties), TRUE);
return windowProperties->priv->scrollbarsVisible;
}
gboolean webkit_window_properties_get_menubar_visible(WebKitWindowProperties* windowProperties)
{
g_return_val_if_fail(WEBKIT_IS_WINDOW_PROPERTIES(windowProperties), TRUE);
return windowProperties->priv->menubarVisible;
}
gboolean webkit_window_properties_get_locationbar_visible(WebKitWindowProperties* windowProperties)
{
g_return_val_if_fail(WEBKIT_IS_WINDOW_PROPERTIES(windowProperties), TRUE);
return windowProperties->priv->locationbarVisible;
}
gboolean webkit_window_properties_get_resizable(WebKitWindowProperties* windowProperties)
{
g_return_val_if_fail(WEBKIT_IS_WINDOW_PROPERTIES(windowProperties), TRUE);
return windowProperties->priv->resizable;
}
gboolean webkit_window_properties_get_fullscreen(WebKitWindowProperties* windowProperties)
{
g_return_val_if_fail(WEBKIT_IS_WINDOW_PROPERTIES(windowProperties), FALSE);
return windowProperties->priv->fullscreen;
}