106ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen/*
206ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    Copyright (C) 2010 ProFUSION embedded systems
306ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    Copyright (C) 2010 Samsung Electronics
406ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
506ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    This library is free software; you can redistribute it and/or
606ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    modify it under the terms of the GNU Library General Public
706ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    License as published by the Free Software Foundation; either
806ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    version 2 of the License, or (at your option) any later version.
906ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
1006ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    This library is distributed in the hope that it will be useful,
1106ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    but WITHOUT ANY WARRANTY; without even the implied warranty of
1206ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1306ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    Library General Public License for more details.
1406ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
1506ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    You should have received a copy of the GNU Library General Public License
1606ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    along with this library; see the file COPYING.LIB.  If not, write to
1706ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
1806ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    Boston, MA 02110-1301, USA.
1906ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen*/
2006ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
2106ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen#include "config.h"
2206ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen#include "ewk_window_features.h"
2306ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
2406ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen#include "WindowFeatures.h"
2506ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen#include "ewk_private.h"
2606ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
2706ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen#include <Eina.h>
2806ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
292bde8e466a4451c7319e3a072d118917957d6554Steve Block/**
302bde8e466a4451c7319e3a072d118917957d6554Steve Block * \struct  _Ewk_Window_Features
312bde8e466a4451c7319e3a072d118917957d6554Steve Block * @brief   Contains the window features data.
322bde8e466a4451c7319e3a072d118917957d6554Steve Block */
3306ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsenstruct _Ewk_Window_Features {
3406ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    unsigned int __ref;
3506ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    WebCore::WindowFeatures* core;
3606ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen};
3706ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
3806ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen/**
392bde8e466a4451c7319e3a072d118917957d6554Steve Block * Decreases the referece count of an Ewk_Window_Features, possibly freeing it.
4006ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen *
412bde8e466a4451c7319e3a072d118917957d6554Steve Block * When the reference count of the object reaches 0, the one is freed.
4206ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen *
432bde8e466a4451c7319e3a072d118917957d6554Steve Block * @param window_features the object to decrease reference count
4406ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen */
4506ea8e899e48f1f2f396b70e63fae369f2f23232Kristian MonsenEAPI void ewk_window_features_unref(Ewk_Window_Features* window_features)
4606ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen{
4706ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    EINA_SAFETY_ON_NULL_RETURN(window_features);
4806ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    EINA_SAFETY_ON_FALSE_RETURN(window_features->__ref > 0);
4906ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
5006ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    if (--window_features->__ref)
5106ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen        return;
5206ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
5306ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    delete window_features->core;
5406ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    window_features->core = 0;
5506ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    free(window_features);
5606ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen}
5706ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
5806ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen/**
592bde8e466a4451c7319e3a072d118917957d6554Steve Block * Increases the reference count of an Ewk_Window_Features.
6006ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen *
612bde8e466a4451c7319e3a072d118917957d6554Steve Block * @param window_features the object to increase reference count
6206ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen */
6306ea8e899e48f1f2f396b70e63fae369f2f23232Kristian MonsenEAPI void ewk_window_features_ref(Ewk_Window_Features* window_features)
6406ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen{
6506ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    EINA_SAFETY_ON_NULL_RETURN(window_features);
6606ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    window_features->__ref++;
6706ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen}
6806ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
6906ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen/**
702bde8e466a4451c7319e3a072d118917957d6554Steve Block * Gets boolean properties of an Ewk_Window_Features.
712bde8e466a4451c7319e3a072d118917957d6554Steve Block *
722bde8e466a4451c7319e3a072d118917957d6554Steve Block * Properties are returned in the respective pointers. Passing @c 0 to any of
732bde8e466a4451c7319e3a072d118917957d6554Steve Block * these pointers will make that property to not be returned.
7406ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen *
752bde8e466a4451c7319e3a072d118917957d6554Steve Block * @param window_features the object to get boolean properties
762bde8e466a4451c7319e3a072d118917957d6554Steve Block * @param toolbar_visible the pointer to store if toolbar is visible
772bde8e466a4451c7319e3a072d118917957d6554Steve Block * @param statusbar_visible the pointer to store if statusbar is visible
782bde8e466a4451c7319e3a072d118917957d6554Steve Block * @param scrollbars_visible the pointer to store if scrollbars is visible
792bde8e466a4451c7319e3a072d118917957d6554Steve Block * @param menubar_visible the pointer to store if menubar is visible
802bde8e466a4451c7319e3a072d118917957d6554Steve Block * @param locationbar_visible the pointer to store if locationbar is visible
812bde8e466a4451c7319e3a072d118917957d6554Steve Block * @param fullscreen the pointer to store if fullscreen is enabled
822bde8e466a4451c7319e3a072d118917957d6554Steve Block *
832bde8e466a4451c7319e3a072d118917957d6554Steve Block * @see ewk_window_features_int_property_get
8406ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen */
8506ea8e899e48f1f2f396b70e63fae369f2f23232Kristian MonsenEAPI void ewk_window_features_bool_property_get(Ewk_Window_Features* window_features, Eina_Bool* toolbar_visible, Eina_Bool* statusbar_visible, Eina_Bool* scrollbars_visible, Eina_Bool* menubar_visible, Eina_Bool* locationbar_visible, Eina_Bool* fullscreen)
8606ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen{
8706ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    EINA_SAFETY_ON_NULL_RETURN(window_features);
8806ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    EINA_SAFETY_ON_NULL_RETURN(window_features->core);
8906ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
9006ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    if (toolbar_visible)
9106ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen        *toolbar_visible = window_features->core->toolBarVisible;
9206ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
9306ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    if (statusbar_visible)
9406ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen        *statusbar_visible = window_features->core->statusBarVisible;
9506ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
9606ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    if (scrollbars_visible)
9706ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen        *scrollbars_visible = window_features->core->scrollbarsVisible;
9806ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
9906ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    if (menubar_visible)
10006ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen        *menubar_visible = window_features->core->menuBarVisible;
10106ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
10206ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    if (locationbar_visible)
10306ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen        *locationbar_visible = window_features->core->locationBarVisible;
10406ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
10506ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    if (fullscreen)
10606ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen        *fullscreen = window_features->core->fullscreen;
10706ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen}
10806ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
10906ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen/**
1102bde8e466a4451c7319e3a072d118917957d6554Steve Block * Gets int properties of an Ewk_Window_Features.
1112bde8e466a4451c7319e3a072d118917957d6554Steve Block *
1122bde8e466a4451c7319e3a072d118917957d6554Steve Block * Properties are returned in the respective pointers. Passing @c 0 to any of
1132bde8e466a4451c7319e3a072d118917957d6554Steve Block * these pointers will make that property to not be returned.
1142bde8e466a4451c7319e3a072d118917957d6554Steve Block *
1152bde8e466a4451c7319e3a072d118917957d6554Steve Block * Make sure to check if the value returned is less than 0 before using it, since in
1162bde8e466a4451c7319e3a072d118917957d6554Steve Block * that case it means that property was not set in winwdow_features object.
11706ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen *
1182bde8e466a4451c7319e3a072d118917957d6554Steve Block * @param window_features the window's features
1192bde8e466a4451c7319e3a072d118917957d6554Steve Block * @param x the pointer to store x position
1202bde8e466a4451c7319e3a072d118917957d6554Steve Block * @param y the pointer to store y position
1212bde8e466a4451c7319e3a072d118917957d6554Steve Block * @param w the pointer to store width
1222bde8e466a4451c7319e3a072d118917957d6554Steve Block * @param h the pointer to store height
12306ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen *
1242bde8e466a4451c7319e3a072d118917957d6554Steve Block * @see ewk_window_features_bool_property_get
12506ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen */
12606ea8e899e48f1f2f396b70e63fae369f2f23232Kristian MonsenEAPI void ewk_window_features_int_property_get(Ewk_Window_Features* window_features, int* x, int* y, int* w, int* h)
12706ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen{
12806ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    EINA_SAFETY_ON_NULL_RETURN(window_features);
12906ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    EINA_SAFETY_ON_NULL_RETURN(window_features->core);
13006ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
13106ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    if (x)
13206ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen        *x = window_features->core->xSet ? static_cast<int>(window_features->core->x) : -1;
13306ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
13406ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    if (y)
13506ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen        *y = window_features->core->ySet ? static_cast<int>(window_features->core->y) : -1;
13606ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
13706ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    if (w)
13806ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen        *w = window_features->core->widthSet ? static_cast<int>(window_features->core->width) : -1;
13906ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
14006ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    if (h)
14106ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen        *h = window_features->core->heightSet ? static_cast<int>(window_features->core->height) : -1;
14206ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen}
14306ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
14406ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen/* internal methods ****************************************************/
14506ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
14606ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen/**
14706ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen * @internal
14806ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen *
1492bde8e466a4451c7319e3a072d118917957d6554Steve Block * Creates a new Ewk_Window_Features object.
15006ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen *
1512bde8e466a4451c7319e3a072d118917957d6554Steve Block * @param core if not @c 0 a new WebCore::WindowFeatures is allocated copying core features and
1522bde8e466a4451c7319e3a072d118917957d6554Steve Block * it is embedded inside the Ewk_Window_Features whose ref count is initialized, if core is @c 0 a new one is created with the default features.
1532bde8e466a4451c7319e3a072d118917957d6554Steve Block * @returns a new allocated the Ewk_Window_Features object
15406ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen */
15506ea8e899e48f1f2f396b70e63fae369f2f23232Kristian MonsenEwk_Window_Features* ewk_window_features_new_from_core(const WebCore::WindowFeatures* core)
15606ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen{
15706ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    Ewk_Window_Features* window_features = static_cast<Ewk_Window_Features*>(malloc(sizeof(*window_features)));
15806ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
15906ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    if (core)
16006ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen        window_features->core = new WebCore::WindowFeatures(*core);
16106ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    else
16206ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen        window_features->core = new WebCore::WindowFeatures();
16306ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
16406ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    window_features->__ref = 1;
16506ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen
16606ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    return window_features;
16706ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen}
168