~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebKit/blackberry/Api/WebSettings_p.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2009, 2010, 2011, 2012 Research In Motion Limited. All rights reserved.
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Lesser 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
 * Lesser General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Lesser General Public
 
15
 * License along with this library; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
17
 */
 
18
 
 
19
#ifndef WebSettings_p_h
 
20
#define WebSettings_p_h
 
21
 
 
22
#include "WebSettings.h"
 
23
 
 
24
#include <wtf/HashMap.h>
 
25
#include <wtf/text/StringHash.h>
 
26
 
 
27
#define synthesizeAccessorsForPrimitiveValuePrefixAndType(prefix, type) \
 
28
     void set##prefix(const String& key, type newValue) { \
 
29
         ASSERT(impl); \
 
30
         if (get##prefix(key) == newValue) \
 
31
            return; \
 
32
         if (copyOnWrite) { \
 
33
            copyOnWrite = false; \
 
34
            impl = new WebSettingsPrivateImpl(*impl); \
 
35
         } \
 
36
         PrimitiveValue primitiveValue; \
 
37
         primitiveValue.prefix##Value = newValue; \
 
38
         impl->primitiveValues.set(key, primitiveValue); \
 
39
         if (delegate) \
 
40
            delegate->didChangeSettings(sender); \
 
41
     } \
 
42
     type get##prefix(const String& key) const { \
 
43
          ASSERT(impl); \
 
44
          if (!impl->primitiveValues.contains(key)) \
 
45
              return static_cast<type>(false); \
 
46
          return impl->primitiveValues.get(key).prefix##Value; \
 
47
      }
 
48
 
 
49
namespace BlackBerry {
 
50
namespace WebKit {
 
51
 
 
52
struct WebSettingsPrivate {
 
53
    union PrimitiveValue {
 
54
        WebSettings::TextReflowMode TextReflowModeValue;
 
55
        bool BooleanValue;
 
56
        double DoubleValue;
 
57
        int IntegerValue;
 
58
        unsigned UnsignedValue;
 
59
        unsigned long long UnsignedLongLongValue;
 
60
    };
 
61
 
 
62
    struct WebSettingsPrivateImpl {
 
63
        HashMap<String, PrimitiveValue> primitiveValues;
 
64
        HashMap<String, String> stringValues;
 
65
    };
 
66
 
 
67
    WebSettingsPrivateImpl* impl;
 
68
    WebSettingsDelegate* delegate;
 
69
    WebSettings* sender;
 
70
    bool copyOnWrite;
 
71
 
 
72
    WebSettingsPrivate();
 
73
 
 
74
    synthesizeAccessorsForPrimitiveValuePrefixAndType(TextReflowMode, WebSettings::TextReflowMode);
 
75
 
 
76
    synthesizeAccessorsForPrimitiveValuePrefixAndType(Boolean, bool);
 
77
 
 
78
    synthesizeAccessorsForPrimitiveValuePrefixAndType(Double, double);
 
79
 
 
80
    synthesizeAccessorsForPrimitiveValuePrefixAndType(Integer, int);
 
81
 
 
82
    synthesizeAccessorsForPrimitiveValuePrefixAndType(Unsigned, unsigned);
 
83
 
 
84
    synthesizeAccessorsForPrimitiveValuePrefixAndType(UnsignedLongLong, unsigned long long);
 
85
 
 
86
    String getString(const String& key) const
 
87
    {
 
88
        ASSERT(impl);
 
89
        if (!impl->stringValues.contains(key))
 
90
            return String();
 
91
        return impl->stringValues.get(key);
 
92
    }
 
93
 
 
94
    void setString(const String& key, const String& newValue)
 
95
    {
 
96
        ASSERT(impl);
 
97
        if (getString(key) == newValue)
 
98
            return;
 
99
 
 
100
        if (copyOnWrite) {
 
101
            copyOnWrite = false;
 
102
            impl = new WebSettingsPrivateImpl(*impl);
 
103
        }
 
104
 
 
105
        impl->stringValues.set(key, newValue);
 
106
        if (delegate)
 
107
            delegate->didChangeSettings(sender);
 
108
    }
 
109
};
 
110
 
 
111
} // namespace WebKit
 
112
} // namespace BlackBerry
 
113
 
 
114
#endif // WebSettings_p_h