| 1 | /* |
| 2 | * This file is part of the WebKit open source project. |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Library General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Library General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Library General Public License |
| 15 | * along with this library; see the file COPYING.LIB. If not, write to |
| 16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | * Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | |
| 20 | #include "config.h" |
| 21 | #include "WebKitDOMStyleSheet.h" |
| 22 | |
| 23 | #include <WebCore/CSSImportRule.h> |
| 24 | #include "DOMObjectCache.h" |
| 25 | #include <WebCore/Document.h> |
| 26 | #include <WebCore/ExceptionCode.h> |
| 27 | #include <WebCore/JSExecState.h> |
| 28 | #include "WebKitDOMMediaListPrivate.h" |
| 29 | #include "WebKitDOMNodePrivate.h" |
| 30 | #include "WebKitDOMPrivate.h" |
| 31 | #include "WebKitDOMStyleSheetPrivate.h" |
| 32 | #include "ConvertToUTF8String.h" |
| 33 | #include <wtf/GetPtr.h> |
| 34 | #include <wtf/RefPtr.h> |
| 35 | |
| 36 | #define WEBKIT_DOM_STYLE_SHEET_GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE(obj, WEBKIT_DOM_TYPE_STYLE_SHEET, WebKitDOMStyleSheetPrivate) |
| 37 | |
| 38 | typedef struct _WebKitDOMStyleSheetPrivate { |
| 39 | RefPtr<WebCore::StyleSheet> coreObject; |
| 40 | } WebKitDOMStyleSheetPrivate; |
| 41 | |
| 42 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
| 43 | |
| 44 | namespace WebKit { |
| 45 | |
| 46 | WebKitDOMStyleSheet* kit(WebCore::StyleSheet* obj) |
| 47 | { |
| 48 | if (!obj) |
| 49 | return 0; |
| 50 | |
| 51 | if (gpointer ret = DOMObjectCache::get(obj)) |
| 52 | return WEBKIT_DOM_STYLE_SHEET(ret); |
| 53 | |
| 54 | return wrap(obj); |
| 55 | } |
| 56 | |
| 57 | WebCore::StyleSheet* core(WebKitDOMStyleSheet* request) |
| 58 | { |
| 59 | return request ? static_cast<WebCore::StyleSheet*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0; |
| 60 | } |
| 61 | |
| 62 | WebKitDOMStyleSheet* wrapStyleSheet(WebCore::StyleSheet* coreObject) |
| 63 | { |
| 64 | ASSERT(coreObject); |
| 65 | return WEBKIT_DOM_STYLE_SHEET(g_object_new(WEBKIT_DOM_TYPE_STYLE_SHEET, "core-object" , coreObject, nullptr)); |
| 66 | } |
| 67 | |
| 68 | } // namespace WebKit |
| 69 | |
| 70 | G_DEFINE_TYPE(WebKitDOMStyleSheet, webkit_dom_style_sheet, WEBKIT_DOM_TYPE_OBJECT) |
| 71 | |
| 72 | enum { |
| 73 | DOM_STYLE_SHEET_PROP_0, |
| 74 | DOM_STYLE_SHEET_PROP_TYPE, |
| 75 | DOM_STYLE_SHEET_PROP_DISABLED, |
| 76 | DOM_STYLE_SHEET_PROP_OWNER_NODE, |
| 77 | DOM_STYLE_SHEET_PROP_PARENT_STYLE_SHEET, |
| 78 | DOM_STYLE_SHEET_PROP_HREF, |
| 79 | DOM_STYLE_SHEET_PROP_TITLE, |
| 80 | DOM_STYLE_SHEET_PROP_MEDIA, |
| 81 | }; |
| 82 | |
| 83 | static void webkit_dom_style_sheet_finalize(GObject* object) |
| 84 | { |
| 85 | WebKitDOMStyleSheetPrivate* priv = WEBKIT_DOM_STYLE_SHEET_GET_PRIVATE(object); |
| 86 | |
| 87 | WebKit::DOMObjectCache::forget(priv->coreObject.get()); |
| 88 | |
| 89 | priv->~WebKitDOMStyleSheetPrivate(); |
| 90 | G_OBJECT_CLASS(webkit_dom_style_sheet_parent_class)->finalize(object); |
| 91 | } |
| 92 | |
| 93 | static void webkit_dom_style_sheet_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec) |
| 94 | { |
| 95 | WebKitDOMStyleSheet* self = WEBKIT_DOM_STYLE_SHEET(object); |
| 96 | |
| 97 | switch (propertyId) { |
| 98 | case DOM_STYLE_SHEET_PROP_DISABLED: |
| 99 | webkit_dom_style_sheet_set_disabled(self, g_value_get_boolean(value)); |
| 100 | break; |
| 101 | default: |
| 102 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
| 103 | break; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | static void webkit_dom_style_sheet_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec) |
| 108 | { |
| 109 | WebKitDOMStyleSheet* self = WEBKIT_DOM_STYLE_SHEET(object); |
| 110 | |
| 111 | switch (propertyId) { |
| 112 | case DOM_STYLE_SHEET_PROP_TYPE: |
| 113 | g_value_take_string(value, webkit_dom_style_sheet_get_content_type(self)); |
| 114 | break; |
| 115 | case DOM_STYLE_SHEET_PROP_DISABLED: |
| 116 | g_value_set_boolean(value, webkit_dom_style_sheet_get_disabled(self)); |
| 117 | break; |
| 118 | case DOM_STYLE_SHEET_PROP_OWNER_NODE: |
| 119 | g_value_set_object(value, webkit_dom_style_sheet_get_owner_node(self)); |
| 120 | break; |
| 121 | case DOM_STYLE_SHEET_PROP_PARENT_STYLE_SHEET: |
| 122 | g_value_set_object(value, webkit_dom_style_sheet_get_parent_style_sheet(self)); |
| 123 | break; |
| 124 | case DOM_STYLE_SHEET_PROP_HREF: |
| 125 | g_value_take_string(value, webkit_dom_style_sheet_get_href(self)); |
| 126 | break; |
| 127 | case DOM_STYLE_SHEET_PROP_TITLE: |
| 128 | g_value_take_string(value, webkit_dom_style_sheet_get_title(self)); |
| 129 | break; |
| 130 | case DOM_STYLE_SHEET_PROP_MEDIA: |
| 131 | g_value_set_object(value, webkit_dom_style_sheet_get_media(self)); |
| 132 | break; |
| 133 | default: |
| 134 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
| 135 | break; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | static GObject* webkit_dom_style_sheet_constructor(GType type, guint constructPropertiesCount, GObjectConstructParam* constructProperties) |
| 140 | { |
| 141 | GObject* object = G_OBJECT_CLASS(webkit_dom_style_sheet_parent_class)->constructor(type, constructPropertiesCount, constructProperties); |
| 142 | |
| 143 | WebKitDOMStyleSheetPrivate* priv = WEBKIT_DOM_STYLE_SHEET_GET_PRIVATE(object); |
| 144 | priv->coreObject = static_cast<WebCore::StyleSheet*>(WEBKIT_DOM_OBJECT(object)->coreObject); |
| 145 | WebKit::DOMObjectCache::put(priv->coreObject.get(), object); |
| 146 | |
| 147 | return object; |
| 148 | } |
| 149 | |
| 150 | static void webkit_dom_style_sheet_class_init(WebKitDOMStyleSheetClass* requestClass) |
| 151 | { |
| 152 | GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass); |
| 153 | g_type_class_add_private(gobjectClass, sizeof(WebKitDOMStyleSheetPrivate)); |
| 154 | gobjectClass->constructor = webkit_dom_style_sheet_constructor; |
| 155 | gobjectClass->finalize = webkit_dom_style_sheet_finalize; |
| 156 | gobjectClass->set_property = webkit_dom_style_sheet_set_property; |
| 157 | gobjectClass->get_property = webkit_dom_style_sheet_get_property; |
| 158 | |
| 159 | g_object_class_install_property( |
| 160 | gobjectClass, |
| 161 | DOM_STYLE_SHEET_PROP_TYPE, |
| 162 | g_param_spec_string( |
| 163 | "type" , |
| 164 | "StyleSheet:type" , |
| 165 | "read-only gchar* StyleSheet:type" , |
| 166 | "" , |
| 167 | WEBKIT_PARAM_READABLE)); |
| 168 | |
| 169 | g_object_class_install_property( |
| 170 | gobjectClass, |
| 171 | DOM_STYLE_SHEET_PROP_DISABLED, |
| 172 | g_param_spec_boolean( |
| 173 | "disabled" , |
| 174 | "StyleSheet:disabled" , |
| 175 | "read-write gboolean StyleSheet:disabled" , |
| 176 | FALSE, |
| 177 | WEBKIT_PARAM_READWRITE)); |
| 178 | |
| 179 | g_object_class_install_property( |
| 180 | gobjectClass, |
| 181 | DOM_STYLE_SHEET_PROP_OWNER_NODE, |
| 182 | g_param_spec_object( |
| 183 | "owner-node" , |
| 184 | "StyleSheet:owner-node" , |
| 185 | "read-only WebKitDOMNode* StyleSheet:owner-node" , |
| 186 | WEBKIT_DOM_TYPE_NODE, |
| 187 | WEBKIT_PARAM_READABLE)); |
| 188 | |
| 189 | g_object_class_install_property( |
| 190 | gobjectClass, |
| 191 | DOM_STYLE_SHEET_PROP_PARENT_STYLE_SHEET, |
| 192 | g_param_spec_object( |
| 193 | "parent-style-sheet" , |
| 194 | "StyleSheet:parent-style-sheet" , |
| 195 | "read-only WebKitDOMStyleSheet* StyleSheet:parent-style-sheet" , |
| 196 | WEBKIT_DOM_TYPE_STYLE_SHEET, |
| 197 | WEBKIT_PARAM_READABLE)); |
| 198 | |
| 199 | g_object_class_install_property( |
| 200 | gobjectClass, |
| 201 | DOM_STYLE_SHEET_PROP_HREF, |
| 202 | g_param_spec_string( |
| 203 | "href" , |
| 204 | "StyleSheet:href" , |
| 205 | "read-only gchar* StyleSheet:href" , |
| 206 | "" , |
| 207 | WEBKIT_PARAM_READABLE)); |
| 208 | |
| 209 | g_object_class_install_property( |
| 210 | gobjectClass, |
| 211 | DOM_STYLE_SHEET_PROP_TITLE, |
| 212 | g_param_spec_string( |
| 213 | "title" , |
| 214 | "StyleSheet:title" , |
| 215 | "read-only gchar* StyleSheet:title" , |
| 216 | "" , |
| 217 | WEBKIT_PARAM_READABLE)); |
| 218 | |
| 219 | g_object_class_install_property( |
| 220 | gobjectClass, |
| 221 | DOM_STYLE_SHEET_PROP_MEDIA, |
| 222 | g_param_spec_object( |
| 223 | "media" , |
| 224 | "StyleSheet:media" , |
| 225 | "read-only WebKitDOMMediaList* StyleSheet:media" , |
| 226 | WEBKIT_DOM_TYPE_MEDIA_LIST, |
| 227 | WEBKIT_PARAM_READABLE)); |
| 228 | |
| 229 | } |
| 230 | |
| 231 | static void webkit_dom_style_sheet_init(WebKitDOMStyleSheet* request) |
| 232 | { |
| 233 | WebKitDOMStyleSheetPrivate* priv = WEBKIT_DOM_STYLE_SHEET_GET_PRIVATE(request); |
| 234 | new (priv) WebKitDOMStyleSheetPrivate(); |
| 235 | } |
| 236 | |
| 237 | gchar* webkit_dom_style_sheet_get_content_type(WebKitDOMStyleSheet* self) |
| 238 | { |
| 239 | WebCore::JSMainThreadNullState state; |
| 240 | g_return_val_if_fail(WEBKIT_DOM_IS_STYLE_SHEET(self), 0); |
| 241 | WebCore::StyleSheet* item = WebKit::core(self); |
| 242 | gchar* result = convertToUTF8String(item->type()); |
| 243 | return result; |
| 244 | } |
| 245 | |
| 246 | gboolean webkit_dom_style_sheet_get_disabled(WebKitDOMStyleSheet* self) |
| 247 | { |
| 248 | WebCore::JSMainThreadNullState state; |
| 249 | g_return_val_if_fail(WEBKIT_DOM_IS_STYLE_SHEET(self), FALSE); |
| 250 | WebCore::StyleSheet* item = WebKit::core(self); |
| 251 | gboolean result = item->disabled(); |
| 252 | return result; |
| 253 | } |
| 254 | |
| 255 | void webkit_dom_style_sheet_set_disabled(WebKitDOMStyleSheet* self, gboolean value) |
| 256 | { |
| 257 | WebCore::JSMainThreadNullState state; |
| 258 | g_return_if_fail(WEBKIT_DOM_IS_STYLE_SHEET(self)); |
| 259 | WebCore::StyleSheet* item = WebKit::core(self); |
| 260 | item->setDisabled(value); |
| 261 | } |
| 262 | |
| 263 | WebKitDOMNode* webkit_dom_style_sheet_get_owner_node(WebKitDOMStyleSheet* self) |
| 264 | { |
| 265 | WebCore::JSMainThreadNullState state; |
| 266 | g_return_val_if_fail(WEBKIT_DOM_IS_STYLE_SHEET(self), 0); |
| 267 | WebCore::StyleSheet* item = WebKit::core(self); |
| 268 | RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->ownerNode()); |
| 269 | return WebKit::kit(gobjectResult.get()); |
| 270 | } |
| 271 | |
| 272 | WebKitDOMStyleSheet* webkit_dom_style_sheet_get_parent_style_sheet(WebKitDOMStyleSheet* self) |
| 273 | { |
| 274 | WebCore::JSMainThreadNullState state; |
| 275 | g_return_val_if_fail(WEBKIT_DOM_IS_STYLE_SHEET(self), 0); |
| 276 | WebCore::StyleSheet* item = WebKit::core(self); |
| 277 | RefPtr<WebCore::StyleSheet> gobjectResult = WTF::getPtr(item->parentStyleSheet()); |
| 278 | return WebKit::kit(gobjectResult.get()); |
| 279 | } |
| 280 | |
| 281 | gchar* webkit_dom_style_sheet_get_href(WebKitDOMStyleSheet* self) |
| 282 | { |
| 283 | WebCore::JSMainThreadNullState state; |
| 284 | g_return_val_if_fail(WEBKIT_DOM_IS_STYLE_SHEET(self), 0); |
| 285 | WebCore::StyleSheet* item = WebKit::core(self); |
| 286 | gchar* result = convertToUTF8String(item->href()); |
| 287 | return result; |
| 288 | } |
| 289 | |
| 290 | gchar* webkit_dom_style_sheet_get_title(WebKitDOMStyleSheet* self) |
| 291 | { |
| 292 | WebCore::JSMainThreadNullState state; |
| 293 | g_return_val_if_fail(WEBKIT_DOM_IS_STYLE_SHEET(self), 0); |
| 294 | WebCore::StyleSheet* item = WebKit::core(self); |
| 295 | gchar* result = convertToUTF8String(item->title()); |
| 296 | return result; |
| 297 | } |
| 298 | |
| 299 | WebKitDOMMediaList* webkit_dom_style_sheet_get_media(WebKitDOMStyleSheet* self) |
| 300 | { |
| 301 | WebCore::JSMainThreadNullState state; |
| 302 | g_return_val_if_fail(WEBKIT_DOM_IS_STYLE_SHEET(self), 0); |
| 303 | WebCore::StyleSheet* item = WebKit::core(self); |
| 304 | RefPtr<WebCore::MediaList> gobjectResult = WTF::getPtr(item->media()); |
| 305 | return WebKit::kit(gobjectResult.get()); |
| 306 | } |
| 307 | |
| 308 | G_GNUC_END_IGNORE_DEPRECATIONS; |
| 309 | |