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 "WebKitDOMCSSRuleList.h" |
22 | |
23 | #include <WebCore/CSSImportRule.h> |
24 | #include "DOMObjectCache.h" |
25 | #include <WebCore/Document.h> |
26 | #include <WebCore/JSExecState.h> |
27 | #include "WebKitDOMCSSRuleListPrivate.h" |
28 | #include "WebKitDOMCSSRulePrivate.h" |
29 | #include "WebKitDOMPrivate.h" |
30 | #include "ConvertToUTF8String.h" |
31 | #include <wtf/GetPtr.h> |
32 | #include <wtf/RefPtr.h> |
33 | |
34 | #define WEBKIT_DOM_CSS_RULE_LIST_GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE(obj, WEBKIT_DOM_TYPE_CSS_RULE_LIST, WebKitDOMCSSRuleListPrivate) |
35 | |
36 | typedef struct _WebKitDOMCSSRuleListPrivate { |
37 | RefPtr<WebCore::CSSRuleList> coreObject; |
38 | } WebKitDOMCSSRuleListPrivate; |
39 | |
40 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
41 | |
42 | namespace WebKit { |
43 | |
44 | WebKitDOMCSSRuleList* kit(WebCore::CSSRuleList* obj) |
45 | { |
46 | if (!obj) |
47 | return 0; |
48 | |
49 | if (gpointer ret = DOMObjectCache::get(obj)) |
50 | return WEBKIT_DOM_CSS_RULE_LIST(ret); |
51 | |
52 | return wrapCSSRuleList(obj); |
53 | } |
54 | |
55 | WebCore::CSSRuleList* core(WebKitDOMCSSRuleList* request) |
56 | { |
57 | return request ? static_cast<WebCore::CSSRuleList*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0; |
58 | } |
59 | |
60 | WebKitDOMCSSRuleList* wrapCSSRuleList(WebCore::CSSRuleList* coreObject) |
61 | { |
62 | ASSERT(coreObject); |
63 | return WEBKIT_DOM_CSS_RULE_LIST(g_object_new(WEBKIT_DOM_TYPE_CSS_RULE_LIST, "core-object" , coreObject, nullptr)); |
64 | } |
65 | |
66 | } // namespace WebKit |
67 | |
68 | G_DEFINE_TYPE(WebKitDOMCSSRuleList, webkit_dom_css_rule_list, WEBKIT_DOM_TYPE_OBJECT) |
69 | |
70 | enum { |
71 | DOM_CSS_RULE_LIST_PROP_0, |
72 | DOM_CSS_RULE_LIST_PROP_LENGTH, |
73 | }; |
74 | |
75 | static void webkit_dom_css_rule_list_finalize(GObject* object) |
76 | { |
77 | WebKitDOMCSSRuleListPrivate* priv = WEBKIT_DOM_CSS_RULE_LIST_GET_PRIVATE(object); |
78 | |
79 | WebKit::DOMObjectCache::forget(priv->coreObject.get()); |
80 | |
81 | priv->~WebKitDOMCSSRuleListPrivate(); |
82 | G_OBJECT_CLASS(webkit_dom_css_rule_list_parent_class)->finalize(object); |
83 | } |
84 | |
85 | static void webkit_dom_css_rule_list_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec) |
86 | { |
87 | WebKitDOMCSSRuleList* self = WEBKIT_DOM_CSS_RULE_LIST(object); |
88 | |
89 | switch (propertyId) { |
90 | case DOM_CSS_RULE_LIST_PROP_LENGTH: |
91 | g_value_set_ulong(value, webkit_dom_css_rule_list_get_length(self)); |
92 | break; |
93 | default: |
94 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
95 | break; |
96 | } |
97 | } |
98 | |
99 | static GObject* webkit_dom_css_rule_list_constructor(GType type, guint constructPropertiesCount, GObjectConstructParam* constructProperties) |
100 | { |
101 | GObject* object = G_OBJECT_CLASS(webkit_dom_css_rule_list_parent_class)->constructor(type, constructPropertiesCount, constructProperties); |
102 | |
103 | WebKitDOMCSSRuleListPrivate* priv = WEBKIT_DOM_CSS_RULE_LIST_GET_PRIVATE(object); |
104 | priv->coreObject = static_cast<WebCore::CSSRuleList*>(WEBKIT_DOM_OBJECT(object)->coreObject); |
105 | WebKit::DOMObjectCache::put(priv->coreObject.get(), object); |
106 | |
107 | return object; |
108 | } |
109 | |
110 | static void webkit_dom_css_rule_list_class_init(WebKitDOMCSSRuleListClass* requestClass) |
111 | { |
112 | GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass); |
113 | g_type_class_add_private(gobjectClass, sizeof(WebKitDOMCSSRuleListPrivate)); |
114 | gobjectClass->constructor = webkit_dom_css_rule_list_constructor; |
115 | gobjectClass->finalize = webkit_dom_css_rule_list_finalize; |
116 | gobjectClass->get_property = webkit_dom_css_rule_list_get_property; |
117 | |
118 | g_object_class_install_property( |
119 | gobjectClass, |
120 | DOM_CSS_RULE_LIST_PROP_LENGTH, |
121 | g_param_spec_ulong( |
122 | "length" , |
123 | "CSSRuleList:length" , |
124 | "read-only gulong CSSRuleList:length" , |
125 | 0, G_MAXULONG, 0, |
126 | WEBKIT_PARAM_READABLE)); |
127 | |
128 | } |
129 | |
130 | static void webkit_dom_css_rule_list_init(WebKitDOMCSSRuleList* request) |
131 | { |
132 | WebKitDOMCSSRuleListPrivate* priv = WEBKIT_DOM_CSS_RULE_LIST_GET_PRIVATE(request); |
133 | new (priv) WebKitDOMCSSRuleListPrivate(); |
134 | } |
135 | |
136 | WebKitDOMCSSRule* webkit_dom_css_rule_list_item(WebKitDOMCSSRuleList* self, gulong index) |
137 | { |
138 | WebCore::JSMainThreadNullState state; |
139 | g_return_val_if_fail(WEBKIT_DOM_IS_CSS_RULE_LIST(self), 0); |
140 | WebCore::CSSRuleList* item = WebKit::core(self); |
141 | RefPtr<WebCore::CSSRule> gobjectResult = WTF::getPtr(item->item(index)); |
142 | return WebKit::kit(gobjectResult.get()); |
143 | } |
144 | |
145 | gulong webkit_dom_css_rule_list_get_length(WebKitDOMCSSRuleList* self) |
146 | { |
147 | WebCore::JSMainThreadNullState state; |
148 | g_return_val_if_fail(WEBKIT_DOM_IS_CSS_RULE_LIST(self), 0); |
149 | WebCore::CSSRuleList* item = WebKit::core(self); |
150 | gulong result = item->length(); |
151 | return result; |
152 | } |
153 | |
154 | G_GNUC_END_IGNORE_DEPRECATIONS; |
155 | |