no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / accessible / ipc / IPCTypes.h
blob2e911724bbab063b203a36e46f7c5634abb8bc88
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_a11y_IPCTypes_h
8 #define mozilla_a11y_IPCTypes_h
10 #ifdef ACCESSIBILITY
11 # include "mozilla/a11y/AccAttributes.h"
12 # include "mozilla/a11y/AccTypes.h"
13 # include "mozilla/a11y/CacheConstants.h"
14 # include "mozilla/a11y/Role.h"
15 # include "mozilla/a11y/AccGroupInfo.h"
16 # include "mozilla/GfxMessageUtils.h"
17 # include "ipc/EnumSerializer.h"
18 # include "ipc/IPCMessageUtilsSpecializations.h"
20 namespace IPC {
22 template <>
23 struct ParamTraits<mozilla::a11y::role>
24 : public ContiguousEnumSerializerInclusive<mozilla::a11y::role,
25 mozilla::a11y::role::NOTHING,
26 mozilla::a11y::role::LAST_ROLE> {
29 template <>
30 struct ParamTraits<mozilla::a11y::AccType>
31 : public ContiguousEnumSerializerInclusive<
32 mozilla::a11y::AccType, mozilla::a11y::AccType::eNoType,
33 mozilla::a11y::AccType::eLastAccType> {};
35 template <>
36 struct ParamTraits<mozilla::a11y::AccGenericType>
37 : public BitFlagsEnumSerializer<
38 mozilla::a11y::AccGenericType,
39 mozilla::a11y::AccGenericType::eAllGenericTypes> {};
41 template <>
42 struct ParamTraits<mozilla::a11y::CacheUpdateType>
43 : public ContiguousEnumSerializerInclusive<
44 mozilla::a11y::CacheUpdateType,
45 mozilla::a11y::CacheUpdateType::Initial,
46 mozilla::a11y::CacheUpdateType::Update> {};
48 template <>
49 struct ParamTraits<mozilla::a11y::FontSize> {
50 typedef mozilla::a11y::FontSize paramType;
52 static void Write(MessageWriter* aWriter, const paramType& aParam) {
53 WriteParam(aWriter, aParam.mValue);
56 static bool Read(MessageReader* aReader, paramType* aResult) {
57 return ReadParam(aReader, &(aResult->mValue));
61 template <>
62 struct ParamTraits<mozilla::a11y::DeleteEntry> {
63 typedef mozilla::a11y::DeleteEntry paramType;
65 static void Write(MessageWriter* aWriter, const paramType& aParam) {
66 WriteParam(aWriter, aParam.mValue);
69 static bool Read(MessageReader* aReader, paramType* aResult) {
70 return ReadParam(aReader, &(aResult->mValue));
74 template <>
75 struct ParamTraits<mozilla::a11y::AccGroupInfo> {
76 typedef mozilla::a11y::AccGroupInfo paramType;
78 static void Write(MessageWriter* aWriter, const paramType& aParam) {
79 MOZ_ASSERT_UNREACHABLE("Cannot serialize AccGroupInfo");
82 static bool Read(MessageReader* aReader, paramType* aResult) {
83 MOZ_ASSERT_UNREACHABLE("Cannot de-serialize AccGroupInfo");
84 return false;
88 template <>
89 struct ParamTraits<mozilla::a11y::Color> {
90 typedef mozilla::a11y::Color paramType;
92 static void Write(MessageWriter* aWriter, const paramType& aParam) {
93 WriteParam(aWriter, aParam.mValue);
96 static bool Read(MessageReader* aReader, paramType* aResult) {
97 return ReadParam(aReader, &(aResult->mValue));
101 template <>
102 struct ParamTraits<mozilla::a11y::AccAttributes*> {
103 typedef mozilla::a11y::AccAttributes paramType;
105 static void Write(MessageWriter* aWriter, const paramType* aParam) {
106 if (!aParam) {
107 WriteParam(aWriter, true);
108 return;
111 WriteParam(aWriter, false);
112 uint32_t count = aParam->mData.Count();
113 WriteParam(aWriter, count);
114 for (auto iter = aParam->mData.ConstIter(); !iter.Done(); iter.Next()) {
115 RefPtr<nsAtom> key = iter.Key();
116 WriteParam(aWriter, key);
117 const paramType::AttrValueType& data = iter.Data();
118 WriteParam(aWriter, data);
122 static bool Read(MessageReader* aReader, RefPtr<paramType>* aResult) {
123 bool isNull = false;
124 if (!ReadParam(aReader, &isNull)) {
125 return false;
128 if (isNull) {
129 *aResult = nullptr;
130 return true;
133 *aResult = mozilla::MakeRefPtr<mozilla::a11y::AccAttributes>();
134 uint32_t count;
135 if (!ReadParam(aReader, &count)) {
136 return false;
138 for (uint32_t i = 0; i < count; ++i) {
139 RefPtr<nsAtom> key;
140 if (!ReadParam(aReader, &key)) {
141 return false;
143 paramType::AttrValueType val(0);
144 if (!ReadParam(aReader, &val)) {
145 return false;
147 (*aResult)->mData.InsertOrUpdate(key, std::move(val));
149 return true;
153 } // namespace IPC
154 #else
155 namespace mozilla {
156 namespace a11y {
157 typedef uint32_t role;
158 } // namespace a11y
159 } // namespace mozilla
160 #endif // ACCESSIBILITY
163 * Since IPDL does not support preprocessing, this header file allows us to
164 * define types used by PDocAccessible differently depending on platform.
167 #if defined(MOZ_WIDGET_COCOA)
168 # if defined(ACCESSIBILITY)
169 # include "mozilla/a11y/PlatformExtTypes.h"
170 namespace IPC {
172 template <>
173 struct ParamTraits<mozilla::a11y::EWhichRange>
174 : public ContiguousEnumSerializerInclusive<
175 mozilla::a11y::EWhichRange, mozilla::a11y::EWhichRange::eLeftWord,
176 mozilla::a11y::EWhichRange::eStyle> {};
178 } // namespace IPC
180 # else
181 namespace mozilla {
182 namespace a11y {
183 typedef uint32_t EWhichRange;
184 } // namespace a11y
185 } // namespace mozilla
186 # endif // defined(ACCESSIBILITY)
187 #endif // defined(MOZ_WIDGET_COCOA)
189 #endif // mozilla_a11y_IPCTypes_h