1 /* 2 * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All rights reserved. 3 * (C) 2006 Graham Dennis (graham.dennis (at) gmail.com) 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #ifndef Settings_h 28 #define Settings_h 29 30 #include "SettingsMacros.h" 31 #include "core/editing/EditingBehaviorTypes.h" 32 #include "core/platform/Timer.h" 33 #include "core/platform/graphics/IntSize.h" 34 #include "weborigin/KURL.h" 35 #include "wtf/HashMap.h" 36 #include "wtf/text/AtomicString.h" 37 #include "wtf/text/AtomicStringHash.h" 38 39 namespace WebCore { 40 41 class Page; 42 43 enum EditableLinkBehavior { 44 EditableLinkDefaultBehavior, 45 EditableLinkAlwaysLive, 46 EditableLinkOnlyLiveWithShiftKey, 47 EditableLinkLiveWhenNotFocused, 48 EditableLinkNeverLive 49 }; 50 51 // UScriptCode uses -1 and 0 for UScriptInvalidCode and UScriptCommon. 52 // We need to use -2 and -3 for empty value and deleted value. 53 struct UScriptCodeHashTraits : WTF::GenericHashTraits<int> { 54 static const bool emptyValueIsZero = false; 55 static int emptyValue() { return -2; } 56 static void constructDeletedValue(int& slot) { slot = -3; } 57 static bool isDeletedValue(int value) { return value == -3; } 58 }; 59 60 typedef HashMap<int, AtomicString, DefaultHash<int>::Hash, UScriptCodeHashTraits> ScriptFontFamilyMap; 61 62 class Settings { 63 WTF_MAKE_NONCOPYABLE(Settings); WTF_MAKE_FAST_ALLOCATED; 64 public: 65 static PassOwnPtr<Settings> create(Page*); 66 67 void setStandardFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON); 68 const AtomicString& standardFontFamily(UScriptCode = USCRIPT_COMMON) const; 69 70 void setFixedFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON); 71 const AtomicString& fixedFontFamily(UScriptCode = USCRIPT_COMMON) const; 72 73 void setSerifFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON); 74 const AtomicString& serifFontFamily(UScriptCode = USCRIPT_COMMON) const; 75 76 void setSansSerifFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON); 77 const AtomicString& sansSerifFontFamily(UScriptCode = USCRIPT_COMMON) const; 78 79 void setCursiveFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON); 80 const AtomicString& cursiveFontFamily(UScriptCode = USCRIPT_COMMON) const; 81 82 void setFantasyFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON); 83 const AtomicString& fantasyFontFamily(UScriptCode = USCRIPT_COMMON) const; 84 85 void setPictographFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON); 86 const AtomicString& pictographFontFamily(UScriptCode = USCRIPT_COMMON) const; 87 88 void setTextAutosizingEnabled(bool); 89 bool textAutosizingEnabled() const { return m_textAutosizingEnabled; } 90 91 void setTextAutosizingFontScaleFactor(float); 92 float textAutosizingFontScaleFactor() const { return m_textAutosizingFontScaleFactor; } 93 94 // Only set by Layout Tests, and only used if textAutosizingEnabled() returns true. 95 void setTextAutosizingWindowSizeOverride(const IntSize&); 96 const IntSize& textAutosizingWindowSizeOverride() const { return m_textAutosizingWindowSizeOverride; } 97 98 void setUseWideViewport(bool); 99 bool useWideViewport() const { return m_useWideViewport; } 100 101 void setLoadWithOverviewMode(bool); 102 bool loadWithOverviewMode() const { return m_loadWithOverviewMode; } 103 104 // Only set by Layout Tests. 105 void setMediaTypeOverride(const String&); 106 const String& mediaTypeOverride() const { return m_mediaTypeOverride; } 107 108 // Unlike areImagesEnabled, this only suppresses the network load of 109 // the image URL. A cached image will still be rendered if requested. 110 void setLoadsImagesAutomatically(bool); 111 bool loadsImagesAutomatically() const { return m_loadsImagesAutomatically; } 112 113 // Clients that execute script should call ScriptController::canExecuteScripts() 114 // instead of this function. ScriptController::canExecuteScripts() checks the 115 // HTML sandbox, plug-in sandboxing, and other important details. 116 bool isScriptEnabled() const { return m_isScriptEnabled; } 117 void setScriptEnabled(bool); 118 119 SETTINGS_GETTERS_AND_SETTERS 120 121 void setJavaEnabled(bool); 122 bool isJavaEnabled() const { return m_isJavaEnabled; } 123 124 void setImagesEnabled(bool); 125 bool areImagesEnabled() const { return m_areImagesEnabled; } 126 127 void setPluginsEnabled(bool); 128 bool arePluginsEnabled() const { return m_arePluginsEnabled; } 129 130 void setDNSPrefetchingEnabled(bool); 131 bool dnsPrefetchingEnabled() const { return m_dnsPrefetchingEnabled; } 132 133 void setUserStyleSheetLocation(const KURL&); 134 const KURL& userStyleSheetLocation() const { return m_userStyleSheetLocation; } 135 136 void setCSSCustomFilterEnabled(bool enabled) { m_isCSSCustomFilterEnabled = enabled; } 137 bool isCSSCustomFilterEnabled() const { return m_isCSSCustomFilterEnabled; } 138 139 void setCSSStickyPositionEnabled(bool enabled) { m_cssStickyPositionEnabled = enabled; } 140 bool cssStickyPositionEnabled() const { return m_cssStickyPositionEnabled; } 141 142 static void setMockScrollbarsEnabled(bool flag); 143 static bool mockScrollbarsEnabled(); 144 145 static void setUsesOverlayScrollbars(bool flag); 146 static bool usesOverlayScrollbars(); 147 148 void setTouchEventEmulationEnabled(bool enabled) { m_touchEventEmulationEnabled = enabled; } 149 bool isTouchEventEmulationEnabled() const { return m_touchEventEmulationEnabled; } 150 151 void setOpenGLMultisamplingEnabled(bool flag); 152 bool openGLMultisamplingEnabled(); 153 154 // FIXME: This is a temporary flag and should be removed once accelerated 155 // overflow scroll is ready (crbug.com/254111). 156 void setCompositorDrivenAcceleratedScrollingEnabled(bool enabled) { m_compositorDrivenAcceleratedScrollingEnabled = enabled; } 157 bool isCompositorDrivenAcceleratedScrollingEnabled() const { return m_compositorDrivenAcceleratedScrollingEnabled; } 158 159 private: 160 explicit Settings(Page*); 161 162 Page* m_page; 163 164 String m_mediaTypeOverride; 165 KURL m_userStyleSheetLocation; 166 ScriptFontFamilyMap m_standardFontFamilyMap; 167 ScriptFontFamilyMap m_serifFontFamilyMap; 168 ScriptFontFamilyMap m_fixedFontFamilyMap; 169 ScriptFontFamilyMap m_sansSerifFontFamilyMap; 170 ScriptFontFamilyMap m_cursiveFontFamilyMap; 171 ScriptFontFamilyMap m_fantasyFontFamilyMap; 172 ScriptFontFamilyMap m_pictographFontFamilyMap; 173 float m_textAutosizingFontScaleFactor; 174 IntSize m_textAutosizingWindowSizeOverride; 175 bool m_textAutosizingEnabled : 1; 176 bool m_useWideViewport : 1; 177 bool m_loadWithOverviewMode : 1; 178 179 SETTINGS_MEMBER_VARIABLES 180 181 bool m_isJavaEnabled : 1; 182 bool m_loadsImagesAutomatically : 1; 183 bool m_areImagesEnabled : 1; 184 bool m_arePluginsEnabled : 1; 185 bool m_isScriptEnabled : 1; 186 bool m_isCSSCustomFilterEnabled : 1; 187 bool m_cssStickyPositionEnabled : 1; 188 bool m_dnsPrefetchingEnabled : 1; 189 190 bool m_touchEventEmulationEnabled : 1; 191 bool m_openGLMultisamplingEnabled : 1; 192 193 // FIXME: This is a temporary flag and should be removed once accelerated 194 // overflow scroll is ready (crbug.com/254111). 195 bool m_compositorDrivenAcceleratedScrollingEnabled : 1; 196 197 Timer<Settings> m_setImageLoadingSettingsTimer; 198 void imageLoadingSettingsTimerFired(Timer<Settings>*); 199 200 static bool gMockScrollbarsEnabled; 201 static bool gUsesOverlayScrollbars; 202 }; 203 204 } // namespace WebCore 205 206 #endif // Settings_h 207