2001-09-26 04:40:45 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2000-05-03 03:04:35 +04:00
|
|
|
|
2015-04-03 22:39:23 +03:00
|
|
|
/*
|
|
|
|
* The nsILanguageAtomService provides a mapping from languages or charsets
|
|
|
|
* to language groups, and access to the system locale language.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef nsLanguageAtomService_h_
|
|
|
|
#define nsLanguageAtomService_h_
|
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
#include "mozilla/NotNull.h"
|
2000-05-03 03:04:35 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h"
|
2017-09-26 01:33:21 +03:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2000-05-03 03:04:35 +04:00
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
namespace mozilla {
|
|
|
|
class Encoding;
|
|
|
|
}
|
|
|
|
|
|
|
|
class nsLanguageAtomService final
|
2000-05-03 03:04:35 +04:00
|
|
|
{
|
2017-06-18 14:37:50 +03:00
|
|
|
using Encoding = mozilla::Encoding;
|
|
|
|
template <typename T> using NotNull = mozilla::NotNull<T>;
|
2000-05-03 03:04:35 +04:00
|
|
|
public:
|
2015-04-03 22:39:23 +03:00
|
|
|
static nsLanguageAtomService* GetService();
|
2004-06-09 03:53:59 +04:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* LookupLanguage(const nsACString &aLanguage);
|
|
|
|
already_AddRefed<nsAtom> LookupCharSet(NotNull<const Encoding*> aCharSet);
|
|
|
|
nsAtom* GetLocaleLanguage();
|
2017-05-26 01:04:13 +03:00
|
|
|
|
|
|
|
// Returns the language group that the specified language is a part of.
|
|
|
|
//
|
|
|
|
// aNeedsToCache is used for two things. If null, it indicates that
|
|
|
|
// the nsLanguageAtomService is safe to cache the result of the
|
|
|
|
// language group lookup, either because we're on the main thread,
|
|
|
|
// or because we're on a style worker thread but the font lock has
|
|
|
|
// been acquired. If non-null, it indicates that it's not safe to
|
|
|
|
// cache the result of the language group lookup (because we're on
|
|
|
|
// a style worker thread without the lock acquired). In this case,
|
|
|
|
// GetLanguageGroup will store true in *aNeedsToCache true if we
|
|
|
|
// would have cached the result of a new lookup, and false if we
|
|
|
|
// were able to use an existing cached result. Thus, callers that
|
|
|
|
// get a true *aNeedsToCache outparam value should make an effort
|
|
|
|
// to re-call GetLanguageGroup when it is safe to cache, to avoid
|
|
|
|
// recomputing the language group again later.
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* GetLanguageGroup(nsAtom* aLanguage, bool* aNeedsToCache = nullptr);
|
|
|
|
already_AddRefed<nsAtom> GetUncachedLanguageGroup(nsAtom* aLanguage) const;
|
2004-06-09 03:53:59 +04:00
|
|
|
|
|
|
|
private:
|
2017-10-03 01:05:19 +03:00
|
|
|
nsRefPtrHashtable<nsRefPtrHashKey<nsAtom>, nsAtom> mLangToGroup;
|
|
|
|
RefPtr<nsAtom> mLocaleLanguage;
|
2000-05-03 03:04:35 +04:00
|
|
|
};
|
2015-04-03 22:39:23 +03:00
|
|
|
|
|
|
|
#endif
|