WebSettings_p.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. #ifndef WebSettings_p_h
  19. #define WebSettings_p_h
  20. #include "WebSettings.h"
  21. #include <wtf/HashMap.h>
  22. #include <wtf/text/StringHash.h>
  23. #define synthesizeAccessorsForPrimitiveValuePrefixAndType(prefix, type) \
  24. void set##prefix(const String& key, type newValue) { \
  25. ASSERT(impl); \
  26. if (get##prefix(key) == newValue) \
  27. return; \
  28. if (copyOnWrite) { \
  29. copyOnWrite = false; \
  30. impl = new WebSettingsPrivateImpl(*impl); \
  31. } \
  32. PrimitiveValue primitiveValue; \
  33. primitiveValue.prefix##Value = newValue; \
  34. impl->primitiveValues.set(key, primitiveValue); \
  35. if (delegate) \
  36. delegate->didChangeSettings(sender); \
  37. } \
  38. type get##prefix(const String& key) const { \
  39. ASSERT(impl); \
  40. if (!impl->primitiveValues.contains(key)) \
  41. return static_cast<type>(false); \
  42. return impl->primitiveValues.get(key).prefix##Value; \
  43. }
  44. namespace BlackBerry {
  45. namespace WebKit {
  46. struct WebSettingsPrivate {
  47. union PrimitiveValue {
  48. WebSettings::TextReflowMode TextReflowModeValue;
  49. bool BooleanValue;
  50. double DoubleValue;
  51. int IntegerValue;
  52. unsigned UnsignedValue;
  53. unsigned long long UnsignedLongLongValue;
  54. };
  55. struct WebSettingsPrivateImpl {
  56. HashMap<String, PrimitiveValue> primitiveValues;
  57. HashMap<String, String> stringValues;
  58. };
  59. WebSettingsPrivateImpl* impl;
  60. WebSettingsDelegate* delegate;
  61. WebSettings* sender;
  62. bool copyOnWrite;
  63. WebSettingsPrivate();
  64. synthesizeAccessorsForPrimitiveValuePrefixAndType(TextReflowMode, WebSettings::TextReflowMode);
  65. synthesizeAccessorsForPrimitiveValuePrefixAndType(Boolean, bool);
  66. synthesizeAccessorsForPrimitiveValuePrefixAndType(Double, double);
  67. synthesizeAccessorsForPrimitiveValuePrefixAndType(Integer, int);
  68. synthesizeAccessorsForPrimitiveValuePrefixAndType(Unsigned, unsigned);
  69. synthesizeAccessorsForPrimitiveValuePrefixAndType(UnsignedLongLong, unsigned long long);
  70. String getString(const String& key) const
  71. {
  72. ASSERT(impl);
  73. if (!impl->stringValues.contains(key))
  74. return String();
  75. return impl->stringValues.get(key);
  76. }
  77. void setString(const String& key, const String& newValue)
  78. {
  79. ASSERT(impl);
  80. if (getString(key) == newValue)
  81. return;
  82. if (copyOnWrite) {
  83. copyOnWrite = false;
  84. impl = new WebSettingsPrivateImpl(*impl);
  85. }
  86. impl->stringValues.set(key, newValue);
  87. if (delegate)
  88. delegate->didChangeSettings(sender);
  89. }
  90. };
  91. } // namespace WebKit
  92. } // namespace BlackBerry
  93. #endif // WebSettings_p_h