Ignore contiguous composition event.
[framework/web/webkit-efl.git] / Source / WebKit2 / Shared / WebPreferencesStore.cpp
1 /*
2  * Copyright (C) 2010, 2011 Apple Inc. 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 "WebPreferencesStore.h"
28
29 #include "FontSmoothingLevel.h"
30 #include "WebCoreArgumentCoders.h"
31 #include <WebCore/Settings.h>
32
33 namespace WebKit {
34
35 namespace WebPreferencesKey {
36
37 #define DEFINE_KEY_GETTERS(KeyUpper, KeyLower, TypeName, Type, DefaultValue) \
38         const String& KeyLower##Key() \
39         { \
40             DEFINE_STATIC_LOCAL(String, key, (#KeyUpper)); \
41             return key; \
42         }
43
44     FOR_EACH_WEBKIT_PREFERENCE(DEFINE_KEY_GETTERS)
45
46 #undef DEFINE_KEY_GETTERS
47
48 } // namespace WebPreferencesKey
49
50 typedef HashMap<String, bool> BoolOverridesMap;
51
52 static BoolOverridesMap& boolTestRunnerOverridesMap()
53 {
54     DEFINE_STATIC_LOCAL(BoolOverridesMap, map, ());
55     return map;
56 }
57
58 WebPreferencesStore::WebPreferencesStore()
59 {
60 }
61
62 void WebPreferencesStore::encode(CoreIPC::ArgumentEncoder* encoder) const
63 {
64     encoder->encode(m_stringValues);
65     encoder->encode(m_boolValues);
66     encoder->encode(m_uint32Values);
67     encoder->encode(m_doubleValues);
68 }
69
70 bool WebPreferencesStore::decode(CoreIPC::ArgumentDecoder* decoder, WebPreferencesStore& result)
71 {
72     if (!decoder->decode(result.m_stringValues))
73         return false;
74     if (!decoder->decode(result.m_boolValues))
75         return false;
76     if (!decoder->decode(result.m_uint32Values))
77         return false;
78     if (!decoder->decode(result.m_doubleValues))
79         return false;
80     return true;
81 }
82
83 void WebPreferencesStore::overrideBoolValueForKey(const String& key, bool value)
84 {
85     boolTestRunnerOverridesMap().set(key, value);
86 }
87
88 void WebPreferencesStore::removeTestRunnerOverrides()
89 {
90     boolTestRunnerOverridesMap().clear();
91 }
92
93
94 template<typename MappedType>
95 MappedType defaultValueForKey(const String&);
96
97 template<>
98 String defaultValueForKey(const String& key)
99 {
100     static HashMap<String, String>& defaults = *new HashMap<String, String>;
101     if (defaults.isEmpty()) {
102 #define DEFINE_STRING_DEFAULTS(KeyUpper, KeyLower, TypeName, Type, DefaultValue) defaults.set(WebPreferencesKey::KeyLower##Key(), DefaultValue);
103         FOR_EACH_WEBKIT_STRING_PREFERENCE(DEFINE_STRING_DEFAULTS)
104 #undef DEFINE_STRING_DEFAULTS
105     }
106
107     return defaults.get(key);
108 }
109
110 template<>
111 bool defaultValueForKey(const String& key)
112 {
113     static HashMap<String, bool>& defaults = *new HashMap<String, bool>;
114     if (defaults.isEmpty()) {
115 #define DEFINE_BOOL_DEFAULTS(KeyUpper, KeyLower, TypeName, Type, DefaultValue) defaults.set(WebPreferencesKey::KeyLower##Key(), DefaultValue);
116         FOR_EACH_WEBKIT_BOOL_PREFERENCE(DEFINE_BOOL_DEFAULTS)
117 #if ENABLE(TIZEN_PREFERENCE)
118         FOR_EACH_WEBKIT_TIZEN_BOOL_PREFERENCE(DEFINE_BOOL_DEFAULTS)
119 #endif
120 #undef DEFINE_BOOL_DEFAULTS
121     }
122
123     return defaults.get(key);
124 }
125
126 template<>
127 uint32_t defaultValueForKey(const String& key)
128 {
129     static HashMap<String, uint32_t>& defaults = *new HashMap<String, uint32_t>;
130     if (defaults.isEmpty()) {
131 #define DEFINE_UINT32_DEFAULTS(KeyUpper, KeyLower, TypeName, Type, DefaultValue) defaults.set(WebPreferencesKey::KeyLower##Key(), DefaultValue);
132         FOR_EACH_WEBKIT_UINT32_PREFERENCE(DEFINE_UINT32_DEFAULTS)
133 #undef DEFINE_UINT32_DEFAULTS
134     }
135
136     return defaults.get(key);
137 }
138
139 template<>
140 double defaultValueForKey(const String& key)
141 {
142     static HashMap<String, double>& defaults = *new HashMap<String, double>;
143     if (defaults.isEmpty()) {
144 #define DEFINE_DOUBLE_DEFAULTS(KeyUpper, KeyLower, TypeName, Type, DefaultValue) defaults.set(WebPreferencesKey::KeyLower##Key(), DefaultValue);
145         FOR_EACH_WEBKIT_DOUBLE_PREFERENCE(DEFINE_DOUBLE_DEFAULTS)
146 #if ENABLE(TIZEN_PREFERENCE)
147         FOR_EACH_WEBKIT_TIZEN_DOUBLE_PREFERENCE(DEFINE_DOUBLE_DEFAULTS)
148 #endif
149 #undef DEFINE_DOUBLE_DEFAULTS
150     }
151
152     return defaults.get(key);
153 }
154
155 template<typename MapType>
156 static typename MapType::MappedType valueForKey(const MapType& map, const typename MapType::KeyType& key)
157 {
158     typename MapType::const_iterator it = map.find(key);
159     if (it != map.end())
160         return it->second;
161
162     return defaultValueForKey<typename MapType::MappedType>(key);
163 }
164
165 template<typename MapType>
166 static bool setValueForKey(MapType& map, const typename MapType::KeyType& key, const typename MapType::MappedType& value)
167 {
168     typename MapType::MappedType existingValue = valueForKey(map, key);
169     if (existingValue == value)
170         return false;
171     
172     map.set(key, value);
173     return true;
174 }
175
176 bool WebPreferencesStore::setStringValueForKey(const String& key, const String& value)
177 {
178     return setValueForKey(m_stringValues, key, value);
179 }
180
181 String WebPreferencesStore::getStringValueForKey(const String& key) const
182 {
183     return valueForKey(m_stringValues, key);
184 }
185
186 bool WebPreferencesStore::setBoolValueForKey(const String& key, bool value)
187 {
188     return setValueForKey(m_boolValues, key, value);
189 }
190
191 bool WebPreferencesStore::getBoolValueForKey(const String& key) const
192 {
193     // FIXME: Extend overriding to other key types used from LayoutTestController.
194     BoolOverridesMap::const_iterator it = boolTestRunnerOverridesMap().find(key);
195     if (it != boolTestRunnerOverridesMap().end())
196         return it->second;
197     return valueForKey(m_boolValues, key);
198 }
199
200 bool WebPreferencesStore::setUInt32ValueForKey(const String& key, uint32_t value) 
201 {
202     return setValueForKey(m_uint32Values, key, value);
203 }
204
205 uint32_t WebPreferencesStore::getUInt32ValueForKey(const String& key) const
206 {
207     return valueForKey(m_uint32Values, key);
208 }
209
210 bool WebPreferencesStore::setDoubleValueForKey(const String& key, double value) 
211 {
212     return setValueForKey(m_doubleValues, key, value);
213 }
214
215 double WebPreferencesStore::getDoubleValueForKey(const String& key) const
216 {
217     return valueForKey(m_doubleValues, key);
218 }
219
220 } // namespace WebKit