blob: d06f2117eed32e097bb34a4fef9221a3102b86c3 [file] [log] [blame]
kumarashishg826308d2023-06-23 13:21:22 +00001// Copyright 2014 The PDFium Authors
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#ifndef XFA_FXFA_PARSER_CXFA_LOCALEMGR_H_
8#define XFA_FXFA_PARSER_CXFA_LOCALEMGR_H_
9
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070010#include <vector>
11
Haibo Huang49cc9302020-04-27 16:14:24 -070012#include "core/fxcrt/unowned_ptr.h"
13#include "core/fxcrt/widestring.h"
kumarashishg826308d2023-06-23 13:21:22 +000014#include "fxjs/gc/heap.h"
15#include "third_party/abseil-cpp/absl/types/optional.h"
16#include "v8/include/cppgc/garbage-collected.h"
17#include "v8/include/cppgc/member.h"
Haibo Huang49cc9302020-04-27 16:14:24 -070018#include "xfa/fgas/crt/locale_mgr_iface.h"
kumarashishg826308d2023-06-23 13:21:22 +000019#include "xfa/fxfa/parser/gced_locale_iface.h"
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070020
21class CXFA_Node;
kumarashishg826308d2023-06-23 13:21:22 +000022class CXFA_NodeLocale;
23class CXFA_XMLLocale;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070024
kumarashishg826308d2023-06-23 13:21:22 +000025class CXFA_LocaleMgr final : public cppgc::GarbageCollected<CXFA_LocaleMgr>,
26 public LocaleMgrIface {
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070027 public:
kumarashishg826308d2023-06-23 13:21:22 +000028 enum class LangID : uint16_t {
29 k_zh_HK = 0x0c04,
30 k_zh_CN = 0x0804,
31 k_zh_TW = 0x0404,
32 k_nl_NL = 0x0413,
33 k_en_GB = 0x0809,
34 k_en_US = 0x0409,
35 k_fr_FR = 0x040c,
36 k_de_DE = 0x0407,
37 k_it_IT = 0x0410,
38 k_ja_JP = 0x0411,
39 k_ko_KR = 0x0412,
40 k_pt_BR = 0x0416,
41 k_ru_RU = 0x0419,
42 k_es_LA = 0x080a,
43 k_es_ES = 0x0c0a,
44 };
45
46 CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
Haibo Huang49cc9302020-04-27 16:14:24 -070047 ~CXFA_LocaleMgr() override;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070048
kumarashishg826308d2023-06-23 13:21:22 +000049 void Trace(cppgc::Visitor* visitor) const;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070050
kumarashishg826308d2023-06-23 13:21:22 +000051 GCedLocaleIface* GetDefLocale() override;
52 GCedLocaleIface* GetLocaleByName(const WideString& wsLocaleName) override;
53
54 void SetDefLocale(GCedLocaleIface* pLocale);
55 absl::optional<WideString> GetConfigLocaleName(CXFA_Node* pConfig) const;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070056
57 private:
kumarashishg826308d2023-06-23 13:21:22 +000058 CXFA_LocaleMgr(cppgc::Heap* pHeap,
59 CXFA_Node* pLocaleSet,
60 WideString wsDeflcid);
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070061
kumarashishg826308d2023-06-23 13:21:22 +000062 // May allocate a new object on the cppgc heap.
63 CXFA_XMLLocale* GetLocale(LangID lcid);
Haibo Huang49cc9302020-04-27 16:14:24 -070064
kumarashishg826308d2023-06-23 13:21:22 +000065 UnownedPtr<cppgc::Heap> m_pHeap;
66 std::vector<cppgc::Member<CXFA_NodeLocale>> m_LocaleArray;
67 std::vector<cppgc::Member<CXFA_XMLLocale>> m_XMLLocaleArray;
68 cppgc::Member<GCedLocaleIface> m_pDefLocale;
Haibo Huang49cc9302020-04-27 16:14:24 -070069
kumarashishg826308d2023-06-23 13:21:22 +000070 // Note: three possiblities
71 // 1. we might never have tried to determine |m_wsConfigLocale|.
72 // 2. we might have tried but gotten nothing and want to continue
73 // to return nothing without ever trying again.
74 // 3. we might have tried and gotten something.
75 // So |m_bConfigLocaleCached| indicates whether we've already tried,
76 // and |m_wsConfigLocale| is the possibly nothing we got if we tried.
77 mutable absl::optional<WideString> m_wsConfigLocale;
78 mutable bool m_bConfigLocaleCached = false;
79
80 LangID m_eDeflcid;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070081};
82
83#endif // XFA_FXFA_PARSER_CXFA_LOCALEMGR_H_