1/* 2 * Copyright (C) 2012 Samsung Electronics. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#include "config.h" 27#include "ewk_window_features.h" 28 29#include "EwkView.h" 30#include "WKDictionary.h" 31#include "WKNumber.h" 32#include "WKString.h" 33#include "ewk_window_features_private.h" 34 35using namespace WebKit; 36 37EwkWindowFeatures::EwkWindowFeatures(WKDictionaryRef windowFeatures, EwkView* view) 38 : m_view(view) 39 , m_toolbarVisible(getWindowFeatureBoolValue(windowFeatures, "toolBarVisible", true)) 40 , m_statusBarVisible(getWindowFeatureBoolValue(windowFeatures, "statusBarVisible", true)) 41 , m_scrollbarsVisible(getWindowFeatureBoolValue(windowFeatures, "scrollbarsVisible", true)) 42 , m_menuBarVisible(getWindowFeatureBoolValue(windowFeatures, "menuBarVisible", true)) 43 , m_locationBarVisible(getWindowFeatureBoolValue(windowFeatures, "locationBarVisible", true)) 44 , m_resizable(getWindowFeatureBoolValue(windowFeatures, "resizable", true)) 45 , m_fullScreen(getWindowFeatureBoolValue(windowFeatures, "fullscreen", false)) 46{ 47 m_geometry.x = getWindowFeatureDoubleValue(windowFeatures, "x", 0); 48 m_geometry.y = getWindowFeatureDoubleValue(windowFeatures, "y", 0); 49 m_geometry.w = getWindowFeatureDoubleValue(windowFeatures, "width", 0); 50 m_geometry.h = getWindowFeatureDoubleValue(windowFeatures, "height", 0); 51} 52 53static inline WKTypeRef getWindowFeatureValue(WKDictionaryRef windowFeatures, const char* featureName) 54{ 55 ASSERT(featureName); 56 if (!windowFeatures) 57 return 0; 58 59 WKRetainPtr<WKStringRef> key(AdoptWK, WKStringCreateWithUTF8CString(featureName)); 60 return WKDictionaryGetItemForKey(windowFeatures, key.get()); 61} 62 63bool EwkWindowFeatures::getWindowFeatureBoolValue(WKDictionaryRef windowFeatures, const char* featureName, bool defaultValue) 64{ 65 WKBooleanRef value = static_cast<WKBooleanRef>(getWindowFeatureValue(windowFeatures, featureName)); 66 67 return value ? WKBooleanGetValue(value) : defaultValue; 68} 69 70double EwkWindowFeatures::getWindowFeatureDoubleValue(WKDictionaryRef windowFeatures, const char* featureName, double defaultValue) 71{ 72 WKDoubleRef value = static_cast<WKDoubleRef>(getWindowFeatureValue(windowFeatures, featureName)); 73 74 return value ? WKDoubleGetValue(value) : defaultValue; 75} 76 77void EwkWindowFeatures::setToolbarVisible(bool toolbarVisible) 78{ 79 m_toolbarVisible = toolbarVisible; 80 m_view->smartCallback<EwkViewCallbacks::ToolbarVisible>().call(&toolbarVisible); 81} 82 83void EwkWindowFeatures::setStatusBarVisible(bool statusBarVisible) 84{ 85 m_statusBarVisible = statusBarVisible; 86 m_view->smartCallback<EwkViewCallbacks::StatusBarVisible>().call(&statusBarVisible); 87} 88 89void EwkWindowFeatures::setMenuBarVisible(bool menuBarVisible) 90{ 91 m_menuBarVisible = menuBarVisible; 92 m_view->smartCallback<EwkViewCallbacks::MenuBarVisible>().call(&menuBarVisible); 93} 94 95void EwkWindowFeatures::setResizable(bool resizable) 96{ 97 m_resizable = resizable; 98 m_view->smartCallback<EwkViewCallbacks::WindowResizable>().call(&resizable); 99} 100 101Eina_Bool ewk_window_features_toolbar_visible_get(const Ewk_Window_Features* window_features) 102{ 103 EWK_OBJ_GET_IMPL_OR_RETURN(const EwkWindowFeatures, window_features, impl, false); 104 105 return impl->toolbarVisible(); 106} 107 108Eina_Bool ewk_window_features_statusbar_visible_get(const Ewk_Window_Features* window_features) 109{ 110 EWK_OBJ_GET_IMPL_OR_RETURN(const EwkWindowFeatures, window_features, impl, false); 111 112 return impl->statusBarVisible(); 113} 114 115Eina_Bool ewk_window_features_scrollbars_visible_get(const Ewk_Window_Features* window_features) 116{ 117 EWK_OBJ_GET_IMPL_OR_RETURN(const EwkWindowFeatures, window_features, impl, false); 118 119 return impl->scrollbarsVisible(); 120} 121 122Eina_Bool ewk_window_features_menubar_visible_get(const Ewk_Window_Features* window_features) 123{ 124 EWK_OBJ_GET_IMPL_OR_RETURN(const EwkWindowFeatures, window_features, impl, false); 125 126 return impl->menuBarVisible(); 127} 128 129Eina_Bool ewk_window_features_locationbar_visible_get(const Ewk_Window_Features* window_features) 130{ 131 EWK_OBJ_GET_IMPL_OR_RETURN(const EwkWindowFeatures, window_features, impl, false); 132 133 return impl->locationBarVisible(); 134} 135 136Eina_Bool ewk_window_features_resizable_get(const Ewk_Window_Features* window_features) 137{ 138 EWK_OBJ_GET_IMPL_OR_RETURN(const EwkWindowFeatures, window_features, impl, false); 139 140 return impl->resizable(); 141} 142 143Eina_Bool ewk_window_features_fullscreen_get(const Ewk_Window_Features* window_features) 144{ 145 EWK_OBJ_GET_IMPL_OR_RETURN(const EwkWindowFeatures, window_features, impl, false); 146 147 return impl->fullScreen(); 148} 149 150void ewk_window_features_geometry_get(const Ewk_Window_Features* window_features, Evas_Coord* x, Evas_Coord* y, Evas_Coord* width, Evas_Coord* height) 151{ 152 EWK_OBJ_GET_IMPL_OR_RETURN(const EwkWindowFeatures, window_features, impl); 153 154 const Evas_Coord_Rectangle& geometry = impl->geometry(); 155 if (x) 156 *x = geometry.x; 157 158 if (y) 159 *y = geometry.y; 160 161 if (width) 162 *width = geometry.w; 163 164 if (height) 165 *height = geometry.h; 166} 167