Bug 1391438 - Move GECKOBUNDLE macros into their own header r=snorp

The GECKOBUNDLE macros are useful to more than just a11y code, so let's move them into the jni package so that all jni consumers may drink of their sweet nectar.

Differential Revision: https://phabricator.services.mozilla.com/D30585

--HG--
extra : moz-landing-system : lando
This commit is contained in:
J.C. Jones 2019-05-10 17:59:46 +00:00
parent a58a67412c
commit cad430cae6
5 changed files with 41 additions and 22 deletions

View File

@ -19,6 +19,7 @@
#include "nsTextEquivUtils.h"
#include "mozilla/a11y/PDocAccessibleChild.h"
#include "mozilla/jni/GeckoBundleUtils.h"
#define ROLE_STRINGS_URL "chrome://global/locale/AccessFu.properties"

View File

@ -19,6 +19,7 @@
#include "mozilla/dom/BrowserParent.h"
#include "mozilla/a11y/DocAccessibleParent.h"
#include "mozilla/a11y/DocManager.h"
#include "mozilla/jni/GeckoBundleUtils.h"
#ifdef DEBUG
# include <android/log.h>

View File

@ -12,28 +12,6 @@
#include "nsThreadUtils.h"
#include "nsWindow.h"
#define GECKOBUNDLE_START(name) \
nsTArray<jni::String::LocalRef> _##name##_keys; \
nsTArray<jni::Object::LocalRef> _##name##_values;
#define GECKOBUNDLE_PUT(name, key, value) \
_##name##_keys.AppendElement(jni::StringParam(NS_LITERAL_STRING(key))); \
_##name##_values.AppendElement(value);
#define GECKOBUNDLE_FINISH(name) \
MOZ_ASSERT(_##name##_keys.Length() == _##name##_values.Length()); \
auto _##name##_jkeys = \
jni::ObjectArray::New<jni::String>(_##name##_keys.Length()); \
auto _##name##_jvalues = \
jni::ObjectArray::New<jni::Object>(_##name##_values.Length()); \
for (size_t i = 0; \
i < _##name##_keys.Length() && i < _##name##_values.Length(); i++) { \
_##name##_jkeys->SetElement(i, _##name##_keys.ElementAt(i)); \
_##name##_jvalues->SetElement(i, _##name##_values.ElementAt(i)); \
} \
auto name = \
mozilla::java::GeckoBundle::New(_##name##_jkeys, _##name##_jvalues);
namespace mozilla {
namespace a11y {

View File

@ -0,0 +1,38 @@
/* -*- 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_jni_GeckoBundleUtils_h
#define mozilla_jni_GeckoBundleUtils_h
namespace mozilla {
namespace jni {
#define GECKOBUNDLE_START(name) \
nsTArray<jni::String::LocalRef> _##name##_keys; \
nsTArray<jni::Object::LocalRef> _##name##_values;
#define GECKOBUNDLE_PUT(name, key, value) \
_##name##_keys.AppendElement(jni::StringParam(NS_LITERAL_STRING(key))); \
_##name##_values.AppendElement(value);
#define GECKOBUNDLE_FINISH(name) \
MOZ_ASSERT(_##name##_keys.Length() == _##name##_values.Length()); \
auto _##name##_jkeys = \
jni::ObjectArray::New<jni::String>(_##name##_keys.Length()); \
auto _##name##_jvalues = \
jni::ObjectArray::New<jni::Object>(_##name##_values.Length()); \
for (size_t i = 0; \
i < _##name##_keys.Length() && i < _##name##_values.Length(); i++) { \
_##name##_jkeys->SetElement(i, _##name##_keys.ElementAt(i)); \
_##name##_jvalues->SetElement(i, _##name##_values.ElementAt(i)); \
} \
auto name = \
mozilla::java::GeckoBundle::New(_##name##_jkeys, _##name##_jvalues);
} // namespace jni
} // namespace mozilla
#endif // mozilla_jni_GeckoBundleUtils_h

View File

@ -9,6 +9,7 @@ with Files("**"):
EXPORTS.mozilla.jni += [
'Accessors.h',
'GeckoBundleUtils.h',
'Natives.h',
'Refs.h',
'Types.h',