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 "WebKitDOMCSSValue.h" |
22 | |
23 | #include <WebCore/CSSImportRule.h> |
24 | #include "DOMObjectCache.h" |
25 | #include <WebCore/DOMException.h> |
26 | #include <WebCore/Document.h> |
27 | #include <WebCore/JSExecState.h> |
28 | #include "WebKitDOMCSSValuePrivate.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_VALUE_GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE(obj, WEBKIT_DOM_TYPE_CSS_VALUE, WebKitDOMCSSValuePrivate) |
35 | |
36 | typedef struct _WebKitDOMCSSValuePrivate { |
37 | RefPtr<WebCore::DeprecatedCSSOMValue> coreObject; |
38 | } WebKitDOMCSSValuePrivate; |
39 | |
40 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
41 | |
42 | namespace WebKit { |
43 | |
44 | WebKitDOMCSSValue* kit(WebCore::DeprecatedCSSOMValue* obj) |
45 | { |
46 | if (!obj) |
47 | return 0; |
48 | |
49 | if (gpointer ret = DOMObjectCache::get(obj)) |
50 | return WEBKIT_DOM_CSS_VALUE(ret); |
51 | |
52 | return wrapCSSValue(obj); |
53 | } |
54 | |
55 | WebCore::DeprecatedCSSOMValue* core(WebKitDOMCSSValue* request) |
56 | { |
57 | return request ? static_cast<WebCore::DeprecatedCSSOMValue*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0; |
58 | } |
59 | |
60 | WebKitDOMCSSValue* wrapCSSValue(WebCore::DeprecatedCSSOMValue* coreObject) |
61 | { |
62 | ASSERT(coreObject); |
63 | return WEBKIT_DOM_CSS_VALUE(g_object_new(WEBKIT_DOM_TYPE_CSS_VALUE, "core-object" , coreObject, nullptr)); |
64 | } |
65 | |
66 | } // namespace WebKit |
67 | |
68 | G_DEFINE_TYPE(WebKitDOMCSSValue, webkit_dom_css_value, WEBKIT_DOM_TYPE_OBJECT) |
69 | |
70 | enum { |
71 | DOM_CSS_VALUE_PROP_0, |
72 | DOM_CSS_VALUE_PROP_CSS_TEXT, |
73 | DOM_CSS_VALUE_PROP_CSS_VALUE_TYPE, |
74 | }; |
75 | |
76 | static void webkit_dom_css_value_finalize(GObject* object) |
77 | { |
78 | WebKitDOMCSSValuePrivate* priv = WEBKIT_DOM_CSS_VALUE_GET_PRIVATE(object); |
79 | |
80 | WebKit::DOMObjectCache::forget(priv->coreObject.get()); |
81 | |
82 | priv->~WebKitDOMCSSValuePrivate(); |
83 | G_OBJECT_CLASS(webkit_dom_css_value_parent_class)->finalize(object); |
84 | } |
85 | |
86 | static void webkit_dom_css_value_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec) |
87 | { |
88 | WebKitDOMCSSValue* self = WEBKIT_DOM_CSS_VALUE(object); |
89 | |
90 | switch (propertyId) { |
91 | case DOM_CSS_VALUE_PROP_CSS_TEXT: |
92 | webkit_dom_css_value_set_css_text(self, g_value_get_string(value), nullptr); |
93 | break; |
94 | default: |
95 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
96 | break; |
97 | } |
98 | } |
99 | |
100 | static void webkit_dom_css_value_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec) |
101 | { |
102 | WebKitDOMCSSValue* self = WEBKIT_DOM_CSS_VALUE(object); |
103 | |
104 | switch (propertyId) { |
105 | case DOM_CSS_VALUE_PROP_CSS_TEXT: |
106 | g_value_take_string(value, webkit_dom_css_value_get_css_text(self)); |
107 | break; |
108 | case DOM_CSS_VALUE_PROP_CSS_VALUE_TYPE: |
109 | g_value_set_uint(value, webkit_dom_css_value_get_css_value_type(self)); |
110 | break; |
111 | default: |
112 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
113 | break; |
114 | } |
115 | } |
116 | |
117 | static GObject* webkit_dom_css_value_constructor(GType type, guint constructPropertiesCount, GObjectConstructParam* constructProperties) |
118 | { |
119 | GObject* object = G_OBJECT_CLASS(webkit_dom_css_value_parent_class)->constructor(type, constructPropertiesCount, constructProperties); |
120 | |
121 | WebKitDOMCSSValuePrivate* priv = WEBKIT_DOM_CSS_VALUE_GET_PRIVATE(object); |
122 | priv->coreObject = static_cast<WebCore::DeprecatedCSSOMValue*>(WEBKIT_DOM_OBJECT(object)->coreObject); |
123 | WebKit::DOMObjectCache::put(priv->coreObject.get(), object); |
124 | |
125 | return object; |
126 | } |
127 | |
128 | static void webkit_dom_css_value_class_init(WebKitDOMCSSValueClass* requestClass) |
129 | { |
130 | GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass); |
131 | g_type_class_add_private(gobjectClass, sizeof(WebKitDOMCSSValuePrivate)); |
132 | gobjectClass->constructor = webkit_dom_css_value_constructor; |
133 | gobjectClass->finalize = webkit_dom_css_value_finalize; |
134 | gobjectClass->set_property = webkit_dom_css_value_set_property; |
135 | gobjectClass->get_property = webkit_dom_css_value_get_property; |
136 | |
137 | g_object_class_install_property( |
138 | gobjectClass, |
139 | DOM_CSS_VALUE_PROP_CSS_TEXT, |
140 | g_param_spec_string( |
141 | "css-text" , |
142 | "CSSValue:css-text" , |
143 | "read-write gchar* CSSValue:css-text" , |
144 | "" , |
145 | WEBKIT_PARAM_READWRITE)); |
146 | |
147 | g_object_class_install_property( |
148 | gobjectClass, |
149 | DOM_CSS_VALUE_PROP_CSS_VALUE_TYPE, |
150 | g_param_spec_uint( |
151 | "css-value-type" , |
152 | "CSSValue:css-value-type" , |
153 | "read-only gushort CSSValue:css-value-type" , |
154 | 0, G_MAXUINT, 0, |
155 | WEBKIT_PARAM_READABLE)); |
156 | |
157 | } |
158 | |
159 | static void webkit_dom_css_value_init(WebKitDOMCSSValue* request) |
160 | { |
161 | WebKitDOMCSSValuePrivate* priv = WEBKIT_DOM_CSS_VALUE_GET_PRIVATE(request); |
162 | new (priv) WebKitDOMCSSValuePrivate(); |
163 | } |
164 | |
165 | gchar* webkit_dom_css_value_get_css_text(WebKitDOMCSSValue* self) |
166 | { |
167 | WebCore::JSMainThreadNullState state; |
168 | g_return_val_if_fail(WEBKIT_DOM_IS_CSS_VALUE(self), 0); |
169 | WebCore::DeprecatedCSSOMValue* item = WebKit::core(self); |
170 | gchar* result = convertToUTF8String(item->cssText()); |
171 | return result; |
172 | } |
173 | |
174 | void webkit_dom_css_value_set_css_text(WebKitDOMCSSValue* self, const gchar* value, GError** error) |
175 | { |
176 | WebCore::JSMainThreadNullState state; |
177 | g_return_if_fail(WEBKIT_DOM_IS_CSS_VALUE(self)); |
178 | g_return_if_fail(value); |
179 | g_return_if_fail(!error || !*error); |
180 | WebCore::DeprecatedCSSOMValue* item = WebKit::core(self); |
181 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
182 | auto result = item->setCssText(convertedValue); |
183 | if (result.hasException()) { |
184 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
185 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
186 | } |
187 | } |
188 | |
189 | gushort webkit_dom_css_value_get_css_value_type(WebKitDOMCSSValue* self) |
190 | { |
191 | WebCore::JSMainThreadNullState state; |
192 | g_return_val_if_fail(WEBKIT_DOM_IS_CSS_VALUE(self), 0); |
193 | WebCore::DeprecatedCSSOMValue* item = WebKit::core(self); |
194 | gushort result = item->cssValueType(); |
195 | return result; |
196 | } |
197 | |
198 | G_GNUC_END_IGNORE_DEPRECATIONS; |
199 | |