initial import
[vuplus_webkit] / Source / WebKit2 / UIProcess / qt / qwkpreferences.cpp
1 /*
2     Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
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 "qwkpreferences.h"
22
23 #include "WKPageGroup.h"
24 #include "WKPreferences.h"
25 #include "WKStringQt.h"
26 #include "WKRetainPtr.h"
27 #include "qwkpreferences_p.h"
28
29
30 QWKPreferences* QWKPreferencesPrivate::createPreferences(WKPageGroupRef pageGroupRef)
31 {
32     QWKPreferences* prefs = new QWKPreferences;
33     prefs->d->ref = WKPageGroupGetPreferences(pageGroupRef);
34     return prefs;
35 }
36
37 QWKPreferences* QWKPreferencesPrivate::createSharedPreferences()
38 {
39     QWKPreferences* prefs = new QWKPreferences;
40     prefs->d->ref = WKPreferencesCreate();
41     return prefs;
42 }
43
44 QWKPreferences* QWKPreferences::sharedPreferences()
45 {
46     static QWKPreferences* instance = 0;
47
48     if (!instance)
49         instance = QWKPreferencesPrivate::createSharedPreferences();
50     return instance;
51 }
52
53 QWKPreferences::QWKPreferences()
54     : d(new QWKPreferencesPrivate)
55 {
56 }
57
58 QWKPreferences::~QWKPreferences()
59 {
60     delete d;
61 }
62
63 void QWKPreferences::setFontFamily(FontFamily which, const QString& family)
64 {
65     switch (which) {
66     case StandardFont:
67         WKPreferencesSetStandardFontFamily(d->ref, WKStringCreateWithQString(family));
68         break;
69     case FixedFont:
70         WKPreferencesSetFixedFontFamily(d->ref, WKStringCreateWithQString(family));
71         break;
72     case SerifFont:
73         WKPreferencesSetSerifFontFamily(d->ref, WKStringCreateWithQString(family));
74         break;
75     case SansSerifFont:
76         WKPreferencesSetSansSerifFontFamily(d->ref, WKStringCreateWithQString(family));
77         break;
78     case CursiveFont:
79         WKPreferencesSetCursiveFontFamily(d->ref, WKStringCreateWithQString(family));
80         break;
81     case FantasyFont:
82         WKPreferencesSetFantasyFontFamily(d->ref, WKStringCreateWithQString(family));
83         break;
84     default:
85         break;
86     }
87 }
88
89 QString QWKPreferences::fontFamily(FontFamily which) const
90 {
91     switch (which) {
92     case StandardFont: {
93         WKRetainPtr<WKStringRef> stringRef(AdoptWK, WKPreferencesCopyStandardFontFamily(d->ref));
94         return WKStringCopyQString(stringRef.get());
95     }
96     case FixedFont: {
97         WKRetainPtr<WKStringRef> stringRef(AdoptWK, WKPreferencesCopyFixedFontFamily(d->ref));
98         return WKStringCopyQString(stringRef.get());
99     }
100     case SerifFont: {
101         WKRetainPtr<WKStringRef> stringRef(AdoptWK, WKPreferencesCopySerifFontFamily(d->ref));
102         return WKStringCopyQString(stringRef.get());
103     }
104     case SansSerifFont: {
105         WKRetainPtr<WKStringRef> stringRef(AdoptWK, WKPreferencesCopySansSerifFontFamily(d->ref));
106         return WKStringCopyQString(stringRef.get());
107     }
108     case CursiveFont: {
109         WKRetainPtr<WKStringRef> stringRef(AdoptWK, WKPreferencesCopyCursiveFontFamily(d->ref));
110         return WKStringCopyQString(stringRef.get());
111     }
112     case FantasyFont: {
113         WKRetainPtr<WKStringRef> stringRef(AdoptWK, WKPreferencesCopyFantasyFontFamily(d->ref));
114         return WKStringCopyQString(stringRef.get());
115     }
116     default:
117         return QString();
118     }
119 }
120
121 bool QWKPreferences::testAttribute(WebAttribute attr) const
122 {
123     switch (attr) {
124     case AutoLoadImages:
125         return WKPreferencesGetLoadsImagesAutomatically(d->ref);
126     case JavascriptEnabled:
127         return WKPreferencesGetJavaScriptEnabled(d->ref);
128     case PluginsEnabled:
129         return WKPreferencesGetPluginsEnabled(d->ref);
130     case OfflineWebApplicationCacheEnabled:
131         return WKPreferencesGetOfflineWebApplicationCacheEnabled(d->ref);
132     case LocalStorageEnabled:
133         return WKPreferencesGetLocalStorageEnabled(d->ref);
134     case XSSAuditingEnabled:
135         return WKPreferencesGetXSSAuditorEnabled(d->ref);
136     case FrameFlatteningEnabled:
137         return WKPreferencesGetFrameFlatteningEnabled(d->ref);
138     case PrivateBrowsingEnabled:
139         return WKPreferencesGetPrivateBrowsingEnabled(d->ref);
140     case DeveloperExtrasEnabled:
141         return WKPreferencesGetDeveloperExtrasEnabled(d->ref);
142     case DnsPrefetchEnabled:
143         return WKPreferencesGetDNSPrefetchingEnabled(d->ref);
144     default:
145         ASSERT_NOT_REACHED();
146         return false;
147     }
148 }
149
150 void QWKPreferences::setAttribute(WebAttribute attr, bool on)
151 {
152     switch (attr) {
153     case AutoLoadImages:
154         WKPreferencesSetLoadsImagesAutomatically(d->ref, on);
155         break;
156     case JavascriptEnabled:
157         WKPreferencesSetJavaScriptEnabled(d->ref, on);
158         break;
159     case PluginsEnabled:
160         WKPreferencesSetPluginsEnabled(d->ref, on);
161         break;
162     case OfflineWebApplicationCacheEnabled:
163         WKPreferencesSetOfflineWebApplicationCacheEnabled(d->ref, on);
164         break;
165     case LocalStorageEnabled:
166         WKPreferencesSetLocalStorageEnabled(d->ref, on);
167         break;
168     case XSSAuditingEnabled:
169         WKPreferencesSetXSSAuditorEnabled(d->ref, on);
170         break;
171     case FrameFlatteningEnabled:
172         WKPreferencesSetFrameFlatteningEnabled(d->ref, on);
173         break;
174     case PrivateBrowsingEnabled:
175         WKPreferencesSetPrivateBrowsingEnabled(d->ref, on);
176         break;
177     case DeveloperExtrasEnabled:
178         WKPreferencesSetDeveloperExtrasEnabled(d->ref, on);
179         break;
180     case DnsPrefetchEnabled:
181         WKPreferencesSetDNSPrefetchingEnabled(d->ref, on);
182         break;
183     default:
184         ASSERT_NOT_REACHED();
185     }
186 }
187
188 void QWKPreferences::setFontSize(FontSize type, int size)
189 {
190     switch (type) {
191     case MinimumFontSize:
192          WKPreferencesSetMinimumFontSize(d->ref, size);
193          break;
194     case DefaultFontSize:
195          WKPreferencesSetDefaultFontSize(d->ref, size);
196          break;
197     case DefaultFixedFontSize:
198          WKPreferencesSetDefaultFixedFontSize(d->ref, size);
199          break;
200     default:
201         ASSERT_NOT_REACHED();
202     }
203 }
204
205 int QWKPreferences::fontSize(FontSize type) const
206 {
207     switch (type) {
208     case MinimumFontSize:
209          return WKPreferencesGetMinimumFontSize(d->ref);
210     case DefaultFontSize:
211          return WKPreferencesGetDefaultFontSize(d->ref);
212     case DefaultFixedFontSize:
213          return WKPreferencesGetDefaultFixedFontSize(d->ref);
214     default:
215         ASSERT_NOT_REACHED();
216         return false;
217     }
218 }
219