Backed out changeset 68ed52f7e45d (bug 1899241) for causing sccache misses (bug 19048...
[gecko.git] / intl / l10n / FluentBundle.h
blob5c28d30290c002635f27129f2e8da4a6a57938a8
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_intl_l10n_FluentBundle_h
8 #define mozilla_intl_l10n_FluentBundle_h
10 #include "mozilla/dom/BindingDeclarations.h"
11 #include "nsCycleCollectionParticipant.h"
12 #include "nsWrapperCache.h"
13 #include "mozilla/dom/FluentBinding.h"
14 #include "mozilla/dom/LocalizationBinding.h"
15 #include "mozilla/intl/FluentResource.h"
16 #include "mozilla/intl/FluentBindings.h"
18 class nsIGlobalObject;
20 namespace mozilla {
21 class ErrorResult;
23 namespace dom {
24 struct FluentMessage;
25 struct L10nMessage;
26 class OwningUTF8StringOrDouble;
27 class UTF8StringOrUTF8StringSequence;
28 struct FluentBundleOptions;
29 struct FluentBundleAddResourceOptions;
30 } // namespace dom
32 namespace intl {
34 class FluentResource;
36 using L10nArgs =
37 dom::Record<nsCString, dom::Nullable<dom::OwningUTF8StringOrDouble>>;
39 class FluentPattern : public nsWrapperCache {
40 public:
41 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(FluentPattern)
42 NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(FluentPattern)
44 FluentPattern(nsISupports* aParent, const nsACString& aId);
45 FluentPattern(nsISupports* aParent, const nsACString& aId,
46 const nsACString& aAttrName);
47 JSObject* WrapObject(JSContext* aCx,
48 JS::Handle<JSObject*> aGivenProto) override;
49 nsISupports* GetParentObject() const { return mParent; }
51 nsCString mId;
52 nsCString mAttrName;
54 protected:
55 virtual ~FluentPattern();
57 nsCOMPtr<nsISupports> mParent;
60 class FluentBundle final : public nsWrapperCache {
61 public:
62 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(FluentBundle)
63 NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(FluentBundle)
65 FluentBundle(nsISupports* aParent, UniquePtr<ffi::FluentBundleRc> aRaw);
67 static already_AddRefed<FluentBundle> Constructor(
68 const dom::GlobalObject& aGlobal,
69 const dom::UTF8StringOrUTF8StringSequence& aLocales,
70 const dom::FluentBundleOptions& aOptions, ErrorResult& aRv);
71 JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final;
72 nsISupports* GetParentObject() const { return mParent; }
74 void GetLocales(nsTArray<nsCString>& aLocales);
76 void AddResource(FluentResource& aResource,
77 const dom::FluentBundleAddResourceOptions& aOptions);
78 bool HasMessage(const nsACString& aId);
79 void GetMessage(const nsACString& aId,
80 dom::Nullable<dom::FluentMessage>& aRetVal);
81 void FormatPattern(JSContext* aCx, const FluentPattern& aPattern,
82 const dom::Nullable<L10nArgs>& aArgs,
83 const dom::Optional<JS::Handle<JSObject*>>& aErrors,
84 nsACString& aRetVal, ErrorResult& aRv);
86 static void ConvertArgs(const L10nArgs& aArgs,
87 nsTArray<ffi::L10nArg>& aRetVal);
89 protected:
90 virtual ~FluentBundle();
92 nsCOMPtr<nsISupports> mParent;
93 UniquePtr<ffi::FluentBundleRc> mRaw;
96 } // namespace intl
97 } // namespace mozilla
99 #endif