2 Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
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.
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.
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.
21 #include "qwkpreferences.h"
23 #include "WKPageGroup.h"
24 #include "WKPreferences.h"
25 #include "WKStringQt.h"
26 #include "WKRetainPtr.h"
27 #include "qwkpreferences_p.h"
30 QWKPreferences* QWKPreferencesPrivate::createPreferences(WKPageGroupRef pageGroupRef)
32 QWKPreferences* prefs = new QWKPreferences;
33 prefs->d->ref = WKPageGroupGetPreferences(pageGroupRef);
37 QWKPreferences* QWKPreferencesPrivate::createSharedPreferences()
39 QWKPreferences* prefs = new QWKPreferences;
40 prefs->d->ref = WKPreferencesCreate();
44 QWKPreferences* QWKPreferences::sharedPreferences()
46 static QWKPreferences* instance = 0;
49 instance = QWKPreferencesPrivate::createSharedPreferences();
53 QWKPreferences::QWKPreferences()
54 : d(new QWKPreferencesPrivate)
58 QWKPreferences::~QWKPreferences()
63 void QWKPreferences::setFontFamily(FontFamily which, const QString& family)
67 WKPreferencesSetStandardFontFamily(d->ref, WKStringCreateWithQString(family));
70 WKPreferencesSetFixedFontFamily(d->ref, WKStringCreateWithQString(family));
73 WKPreferencesSetSerifFontFamily(d->ref, WKStringCreateWithQString(family));
76 WKPreferencesSetSansSerifFontFamily(d->ref, WKStringCreateWithQString(family));
79 WKPreferencesSetCursiveFontFamily(d->ref, WKStringCreateWithQString(family));
82 WKPreferencesSetFantasyFontFamily(d->ref, WKStringCreateWithQString(family));
89 QString QWKPreferences::fontFamily(FontFamily which) const
93 WKRetainPtr<WKStringRef> stringRef(AdoptWK, WKPreferencesCopyStandardFontFamily(d->ref));
94 return WKStringCopyQString(stringRef.get());
97 WKRetainPtr<WKStringRef> stringRef(AdoptWK, WKPreferencesCopyFixedFontFamily(d->ref));
98 return WKStringCopyQString(stringRef.get());
101 WKRetainPtr<WKStringRef> stringRef(AdoptWK, WKPreferencesCopySerifFontFamily(d->ref));
102 return WKStringCopyQString(stringRef.get());
104 case SansSerifFont: {
105 WKRetainPtr<WKStringRef> stringRef(AdoptWK, WKPreferencesCopySansSerifFontFamily(d->ref));
106 return WKStringCopyQString(stringRef.get());
109 WKRetainPtr<WKStringRef> stringRef(AdoptWK, WKPreferencesCopyCursiveFontFamily(d->ref));
110 return WKStringCopyQString(stringRef.get());
113 WKRetainPtr<WKStringRef> stringRef(AdoptWK, WKPreferencesCopyFantasyFontFamily(d->ref));
114 return WKStringCopyQString(stringRef.get());
121 bool QWKPreferences::testAttribute(WebAttribute attr) const
125 return WKPreferencesGetLoadsImagesAutomatically(d->ref);
126 case JavascriptEnabled:
127 return WKPreferencesGetJavaScriptEnabled(d->ref);
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);
145 ASSERT_NOT_REACHED();
150 void QWKPreferences::setAttribute(WebAttribute attr, bool on)
154 WKPreferencesSetLoadsImagesAutomatically(d->ref, on);
156 case JavascriptEnabled:
157 WKPreferencesSetJavaScriptEnabled(d->ref, on);
160 WKPreferencesSetPluginsEnabled(d->ref, on);
162 case OfflineWebApplicationCacheEnabled:
163 WKPreferencesSetOfflineWebApplicationCacheEnabled(d->ref, on);
165 case LocalStorageEnabled:
166 WKPreferencesSetLocalStorageEnabled(d->ref, on);
168 case XSSAuditingEnabled:
169 WKPreferencesSetXSSAuditorEnabled(d->ref, on);
171 case FrameFlatteningEnabled:
172 WKPreferencesSetFrameFlatteningEnabled(d->ref, on);
174 case PrivateBrowsingEnabled:
175 WKPreferencesSetPrivateBrowsingEnabled(d->ref, on);
177 case DeveloperExtrasEnabled:
178 WKPreferencesSetDeveloperExtrasEnabled(d->ref, on);
180 case DnsPrefetchEnabled:
181 WKPreferencesSetDNSPrefetchingEnabled(d->ref, on);
184 ASSERT_NOT_REACHED();
188 void QWKPreferences::setFontSize(FontSize type, int size)
191 case MinimumFontSize:
192 WKPreferencesSetMinimumFontSize(d->ref, size);
194 case DefaultFontSize:
195 WKPreferencesSetDefaultFontSize(d->ref, size);
197 case DefaultFixedFontSize:
198 WKPreferencesSetDefaultFixedFontSize(d->ref, size);
201 ASSERT_NOT_REACHED();
205 int QWKPreferences::fontSize(FontSize type) const
208 case MinimumFontSize:
209 return WKPreferencesGetMinimumFontSize(d->ref);
210 case DefaultFontSize:
211 return WKPreferencesGetDefaultFontSize(d->ref);
212 case DefaultFixedFontSize:
213 return WKPreferencesGetDefaultFixedFontSize(d->ref);
215 ASSERT_NOT_REACHED();