summaryrefslogtreecommitdiffstats
path: root/accessible/ipc/IPCTypes.h
blob: c044523551316ba7408511ade78eb49c77bc196a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_a11y_IPCTypes_h
#define mozilla_a11y_IPCTypes_h

#ifdef ACCESSIBILITY
#  include "mozilla/a11y/AccAttributes.h"
#  include "mozilla/a11y/AccTypes.h"
#  include "mozilla/a11y/CacheConstants.h"
#  include "mozilla/a11y/Role.h"
#  include "mozilla/a11y/AccGroupInfo.h"
#  include "mozilla/GfxMessageUtils.h"
#  include "ipc/EnumSerializer.h"
#  include "ipc/IPCMessageUtilsSpecializations.h"

namespace IPC {

template <>
struct ParamTraits<mozilla::a11y::role>
    : public ContiguousEnumSerializerInclusive<mozilla::a11y::role,
                                               mozilla::a11y::role::NOTHING,
                                               mozilla::a11y::role::LAST_ROLE> {
};

template <>
struct ParamTraits<mozilla::a11y::AccType>
    : public ContiguousEnumSerializerInclusive<
          mozilla::a11y::AccType, mozilla::a11y::AccType::eNoType,
          mozilla::a11y::AccType::eLastAccType> {};

template <>
struct ParamTraits<mozilla::a11y::AccGenericType>
    : public BitFlagsEnumSerializer<
          mozilla::a11y::AccGenericType,
          mozilla::a11y::AccGenericType::eAllGenericTypes> {};

template <>
struct ParamTraits<mozilla::a11y::CacheUpdateType>
    : public ContiguousEnumSerializerInclusive<
          mozilla::a11y::CacheUpdateType,
          mozilla::a11y::CacheUpdateType::Initial,
          mozilla::a11y::CacheUpdateType::Update> {};

template <>
struct ParamTraits<mozilla::a11y::FontSize> {
  typedef mozilla::a11y::FontSize paramType;

  static void Write(MessageWriter* aWriter, const paramType& aParam) {
    WriteParam(aWriter, aParam.mValue);
  }

  static bool Read(MessageReader* aReader, paramType* aResult) {
    return ReadParam(aReader, &(aResult->mValue));
  }
};

template <>
struct ParamTraits<mozilla::a11y::DeleteEntry> {
  typedef mozilla::a11y::DeleteEntry paramType;

  static void Write(MessageWriter* aWriter, const paramType& aParam) {
    WriteParam(aWriter, aParam.mValue);
  }

  static bool Read(MessageReader* aReader, paramType* aResult) {
    return ReadParam(aReader, &(aResult->mValue));
  }
};

template <>
struct ParamTraits<mozilla::a11y::AccGroupInfo> {
  typedef mozilla::a11y::AccGroupInfo paramType;

  static void Write(MessageWriter* aWriter, const paramType& aParam) {
    MOZ_ASSERT_UNREACHABLE("Cannot serialize AccGroupInfo");
  }

  static bool Read(MessageReader* aReader, paramType* aResult) {
    MOZ_ASSERT_UNREACHABLE("Cannot de-serialize AccGroupInfo");
    return false;
  }
};

template <>
struct ParamTraits<mozilla::a11y::Color> {
  typedef mozilla::a11y::Color paramType;

  static void Write(MessageWriter* aWriter, const paramType& aParam) {
    WriteParam(aWriter, aParam.mValue);
  }

  static bool Read(MessageReader* aReader, paramType* aResult) {
    return ReadParam(aReader, &(aResult->mValue));
  }
};

template <>
struct ParamTraits<mozilla::a11y::AccAttributes*> {
  typedef mozilla::a11y::AccAttributes paramType;

  static void Write(MessageWriter* aWriter, const paramType* aParam) {
    if (!aParam) {
      WriteParam(aWriter, true);
      return;
    }

    WriteParam(aWriter, false);
    uint32_t count = aParam->mData.Count();
    WriteParam(aWriter, count);
    for (auto iter = aParam->mData.ConstIter(); !iter.Done(); iter.Next()) {
      RefPtr<nsAtom> key = iter.Key();
      WriteParam(aWriter, key);
      const paramType::AttrValueType& data = iter.Data();
      WriteParam(aWriter, data);
    }
  }

  static bool Read(MessageReader* aReader, RefPtr<paramType>* aResult) {
    bool isNull = false;
    if (!ReadParam(aReader, &isNull)) {
      return false;
    }

    if (isNull) {
      *aResult = nullptr;
      return true;
    }

    *aResult = mozilla::MakeRefPtr<mozilla::a11y::AccAttributes>();
    uint32_t count;
    if (!ReadParam(aReader, &count)) {
      return false;
    }
    for (uint32_t i = 0; i < count; ++i) {
      RefPtr<nsAtom> key;
      if (!ReadParam(aReader, &key)) {
        return false;
      }
      paramType::AttrValueType val(0);
      if (!ReadParam(aReader, &val)) {
        return false;
      }
      (*aResult)->mData.InsertOrUpdate(key, std::move(val));
    }
    return true;
  }
};

}  // namespace IPC
#else
namespace mozilla {
namespace a11y {
typedef uint32_t role;
}  // namespace a11y
}  // namespace mozilla
#endif  // ACCESSIBILITY

/**
 * Since IPDL does not support preprocessing, this header file allows us to
 * define types used by PDocAccessible differently depending on platform.
 */

#if defined(XP_WIN) && defined(ACCESSIBILITY)

// So that we don't include a bunch of other Windows junk.
#  if !defined(COM_NO_WINDOWS_H)
#    define COM_NO_WINDOWS_H
#  endif  // !defined(COM_NO_WINDOWS_H)

// COM headers pull in MSXML which conflicts with our own XMLDocument class.
// This define excludes those conflicting definitions.
#  if !defined(__XMLDocument_FWD_DEFINED__)
#    define __XMLDocument_FWD_DEFINED__
#  endif  // !defined(__XMLDocument_FWD_DEFINED__)

#  include <combaseapi.h>

#  include "mozilla/a11y/COMPtrTypes.h"

// This define in rpcndr.h messes up our code, so we must undefine it after
// COMPtrTypes.h has been included.
#  if defined(small)
#    undef small
#  endif  // defined(small)

#else

namespace mozilla {
namespace a11y {

typedef uint32_t IAccessibleHolder;
typedef uint32_t IDispatchHolder;
typedef uint32_t IHandlerControlHolder;

}  // namespace a11y
}  // namespace mozilla

#endif  // defined(XP_WIN) && defined(ACCESSIBILITY)

#if defined(MOZ_WIDGET_COCOA)
#  if defined(ACCESSIBILITY)
#    include "mozilla/a11y/PlatformExtTypes.h"
namespace IPC {

template <>
struct ParamTraits<mozilla::a11y::EWhichRange>
    : public ContiguousEnumSerializerInclusive<
          mozilla::a11y::EWhichRange, mozilla::a11y::EWhichRange::eLeftWord,
          mozilla::a11y::EWhichRange::eStyle> {};

template <>
struct ParamTraits<mozilla::a11y::EWhichPostFilter>
    : public ContiguousEnumSerializerInclusive<
          mozilla::a11y::EWhichPostFilter,
          mozilla::a11y::EWhichPostFilter::eContainsText,
          mozilla::a11y::EWhichPostFilter::eContainsText> {};

}  // namespace IPC

#  else
namespace mozilla {
namespace a11y {
typedef uint32_t EWhichRange;
}  // namespace a11y
}  // namespace mozilla
#  endif  // defined(ACCESSIBILITY)
#endif    // defined(MOZ_WIDGET_COCOA)

#endif  // mozilla_a11y_IPCTypes_h