Home | History | Annotate | Download | only in ewk
      1 /*
      2     Copyright (C) 2010 ProFUSION embedded systems
      3     Copyright (C) 2010 Samsung Electronics
      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 #include "ewk_window_features.h"
     23 
     24 #include "WindowFeatures.h"
     25 #include "ewk_private.h"
     26 
     27 #include <Eina.h>
     28 
     29 /**
     30  * \struct  _Ewk_Window_Features
     31  * @brief   Contains the window features data.
     32  */
     33 struct _Ewk_Window_Features {
     34     unsigned int __ref;
     35     WebCore::WindowFeatures* core;
     36 };
     37 
     38 /**
     39  * Decreases the referece count of an Ewk_Window_Features, possibly freeing it.
     40  *
     41  * When the reference count of the object reaches 0, the one is freed.
     42  *
     43  * @param window_features the object to decrease reference count
     44  */
     45 EAPI void ewk_window_features_unref(Ewk_Window_Features* window_features)
     46 {
     47     EINA_SAFETY_ON_NULL_RETURN(window_features);
     48     EINA_SAFETY_ON_FALSE_RETURN(window_features->__ref > 0);
     49 
     50     if (--window_features->__ref)
     51         return;
     52 
     53     delete window_features->core;
     54     window_features->core = 0;
     55     free(window_features);
     56 }
     57 
     58 /**
     59  * Increases the reference count of an Ewk_Window_Features.
     60  *
     61  * @param window_features the object to increase reference count
     62  */
     63 EAPI void ewk_window_features_ref(Ewk_Window_Features* window_features)
     64 {
     65     EINA_SAFETY_ON_NULL_RETURN(window_features);
     66     window_features->__ref++;
     67 }
     68 
     69 /**
     70  * Gets boolean properties of an Ewk_Window_Features.
     71  *
     72  * Properties are returned in the respective pointers. Passing @c 0 to any of
     73  * these pointers will make that property to not be returned.
     74  *
     75  * @param window_features the object to get boolean properties
     76  * @param toolbar_visible the pointer to store if toolbar is visible
     77  * @param statusbar_visible the pointer to store if statusbar is visible
     78  * @param scrollbars_visible the pointer to store if scrollbars is visible
     79  * @param menubar_visible the pointer to store if menubar is visible
     80  * @param locationbar_visible the pointer to store if locationbar is visible
     81  * @param fullscreen the pointer to store if fullscreen is enabled
     82  *
     83  * @see ewk_window_features_int_property_get
     84  */
     85 EAPI 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)
     86 {
     87     EINA_SAFETY_ON_NULL_RETURN(window_features);
     88     EINA_SAFETY_ON_NULL_RETURN(window_features->core);
     89 
     90     if (toolbar_visible)
     91         *toolbar_visible = window_features->core->toolBarVisible;
     92 
     93     if (statusbar_visible)
     94         *statusbar_visible = window_features->core->statusBarVisible;
     95 
     96     if (scrollbars_visible)
     97         *scrollbars_visible = window_features->core->scrollbarsVisible;
     98 
     99     if (menubar_visible)
    100         *menubar_visible = window_features->core->menuBarVisible;
    101 
    102     if (locationbar_visible)
    103         *locationbar_visible = window_features->core->locationBarVisible;
    104 
    105     if (fullscreen)
    106         *fullscreen = window_features->core->fullscreen;
    107 }
    108 
    109 /**
    110  * Gets int properties of an Ewk_Window_Features.
    111  *
    112  * Properties are returned in the respective pointers. Passing @c 0 to any of
    113  * these pointers will make that property to not be returned.
    114  *
    115  * Make sure to check if the value returned is less than 0 before using it, since in
    116  * that case it means that property was not set in winwdow_features object.
    117  *
    118  * @param window_features the window's features
    119  * @param x the pointer to store x position
    120  * @param y the pointer to store y position
    121  * @param w the pointer to store width
    122  * @param h the pointer to store height
    123  *
    124  * @see ewk_window_features_bool_property_get
    125  */
    126 EAPI void ewk_window_features_int_property_get(Ewk_Window_Features* window_features, int* x, int* y, int* w, int* h)
    127 {
    128     EINA_SAFETY_ON_NULL_RETURN(window_features);
    129     EINA_SAFETY_ON_NULL_RETURN(window_features->core);
    130 
    131     if (x)
    132         *x = window_features->core->xSet ? static_cast<int>(window_features->core->x) : -1;
    133 
    134     if (y)
    135         *y = window_features->core->ySet ? static_cast<int>(window_features->core->y) : -1;
    136 
    137     if (w)
    138         *w = window_features->core->widthSet ? static_cast<int>(window_features->core->width) : -1;
    139 
    140     if (h)
    141         *h = window_features->core->heightSet ? static_cast<int>(window_features->core->height) : -1;
    142 }
    143 
    144 /* internal methods ****************************************************/
    145 
    146 /**
    147  * @internal
    148  *
    149  * Creates a new Ewk_Window_Features object.
    150  *
    151  * @param core if not @c 0 a new WebCore::WindowFeatures is allocated copying core features and
    152  * 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.
    153  * @returns a new allocated the Ewk_Window_Features object
    154  */
    155 Ewk_Window_Features* ewk_window_features_new_from_core(const WebCore::WindowFeatures* core)
    156 {
    157     Ewk_Window_Features* window_features = static_cast<Ewk_Window_Features*>(malloc(sizeof(*window_features)));
    158 
    159     if (core)
    160         window_features->core = new WebCore::WindowFeatures(*core);
    161     else
    162         window_features->core = new WebCore::WindowFeatures();
    163 
    164     window_features->__ref = 1;
    165 
    166     return window_features;
    167 }
    168