forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
/
TSFTextStore.cpp
7513 lines (6812 loc) · 269 KB
/
TSFTextStore.cpp
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#define INPUTSCOPE_INIT_GUID
#define TEXTATTRS_INIT_GUID
#include "TSFTextStore.h"
#include <algorithm>
#include <comutil.h> // for _bstr_t
#include <oleauto.h> // for SysAllocString
#include <olectl.h>
#include "nscore.h"
#include "IMMHandler.h"
#include "KeyboardLayout.h"
#include "WinIMEHandler.h"
#include "WinUtils.h"
#include "mozilla/AutoRestore.h"
#include "mozilla/Logging.h"
#include "mozilla/StaticPrefs_intl.h"
#include "mozilla/Telemetry.h"
#include "mozilla/TextEventDispatcher.h"
#include "mozilla/TextEvents.h"
#include "mozilla/ToString.h"
#include "mozilla/WindowsVersion.h"
#include "mozilla/widget/WinRegistry.h"
#include "nsWindow.h"
#include "nsPrintfCString.h"
// For collecting other people's log, tell `MOZ_LOG=IMEHandler:4,sync`
// rather than `MOZ_LOG=IMEHandler:5,sync` since using `5` may create too
// big file.
// Therefore you shouldn't use `LogLevel::Verbose` for logging usual behavior.
mozilla::LazyLogModule gIMELog("IMEHandler");
// TODO: GUID_PROP_URL has not been declared in the SDK yet. We should drop the
// `s` prefix after it's released by a new SDK and define it with #if.
static const GUID sGUID_PROP_URL = {
0xd5138268,
0xa1bf,
0x4308,
{0xbc, 0xbf, 0x2e, 0x73, 0x93, 0x98, 0xe2, 0x34}};
namespace mozilla {
namespace widget {
/**
* TSF related code should log its behavior even on release build especially
* in the interface methods.
*
* In interface methods, use LogLevel::Info.
* In internal methods, use LogLevel::Debug for logging normal behavior.
* For logging error, use LogLevel::Error.
*
* When an instance method is called, start with following text:
* "0x%p TSFFoo::Bar(", the 0x%p should be the "this" of the nsFoo.
* after that, start with:
* "0x%p TSFFoo::Bar("
* In an internal method, start with following text:
* "0x%p TSFFoo::Bar("
* When a static method is called, start with following text:
* "TSFFoo::Bar("
*/
enum class TextInputProcessorID {
// Internal use only. This won't be returned by TSFStaticSink::ActiveTIP().
eNotComputed,
// Not a TIP. E.g., simple keyboard layout or IMM-IME.
eNone,
// Used for other TIPs, i.e., any TIPs which we don't support specifically.
eUnknown,
// TIP for Japanese.
eMicrosoftIMEForJapanese,
eMicrosoftOfficeIME2010ForJapanese,
eGoogleJapaneseInput,
eATOK2011,
eATOK2012,
eATOK2013,
eATOK2014,
eATOK2015,
eATOK2016,
eATOKUnknown,
eJapanist10,
// TIP for Traditional Chinese.
eMicrosoftBopomofo,
eMicrosoftChangJie,
eMicrosoftPhonetic,
eMicrosoftQuick,
eMicrosoftNewChangJie,
eMicrosoftNewPhonetic,
eMicrosoftNewQuick,
eFreeChangJie,
// TIP for Simplified Chinese.
eMicrosoftPinyin,
eMicrosoftPinyinNewExperienceInputStyle,
eMicrosoftWubi,
// TIP for Korean.
eMicrosoftIMEForKorean,
eMicrosoftOldHangul,
// Keyman Desktop, which can install various language keyboards.
eKeymanDesktop,
};
static const char* GetBoolName(bool aBool) { return aBool ? "true" : "false"; }
static void HandleSeparator(nsCString& aDesc) {
if (!aDesc.IsEmpty()) {
aDesc.AppendLiteral(" | ");
}
}
static const nsCString GetFindFlagName(DWORD aFindFlag) {
nsCString description;
if (!aFindFlag) {
description.AppendLiteral("no flags (0)");
return description;
}
if (aFindFlag & TS_ATTR_FIND_BACKWARDS) {
description.AppendLiteral("TS_ATTR_FIND_BACKWARDS");
}
if (aFindFlag & TS_ATTR_FIND_WANT_OFFSET) {
HandleSeparator(description);
description.AppendLiteral("TS_ATTR_FIND_WANT_OFFSET");
}
if (aFindFlag & TS_ATTR_FIND_UPDATESTART) {
HandleSeparator(description);
description.AppendLiteral("TS_ATTR_FIND_UPDATESTART");
}
if (aFindFlag & TS_ATTR_FIND_WANT_VALUE) {
HandleSeparator(description);
description.AppendLiteral("TS_ATTR_FIND_WANT_VALUE");
}
if (aFindFlag & TS_ATTR_FIND_WANT_END) {
HandleSeparator(description);
description.AppendLiteral("TS_ATTR_FIND_WANT_END");
}
if (aFindFlag & TS_ATTR_FIND_HIDDEN) {
HandleSeparator(description);
description.AppendLiteral("TS_ATTR_FIND_HIDDEN");
}
if (description.IsEmpty()) {
description.AppendLiteral("Unknown (");
description.AppendInt(static_cast<uint32_t>(aFindFlag));
description.Append(')');
}
return description;
}
class GetACPFromPointFlagName : public nsAutoCString {
public:
explicit GetACPFromPointFlagName(DWORD aFlags) {
if (!aFlags) {
AppendLiteral("no flags (0)");
return;
}
if (aFlags & GXFPF_ROUND_NEAREST) {
AppendLiteral("GXFPF_ROUND_NEAREST");
aFlags &= ~GXFPF_ROUND_NEAREST;
}
if (aFlags & GXFPF_NEAREST) {
HandleSeparator(*this);
AppendLiteral("GXFPF_NEAREST");
aFlags &= ~GXFPF_NEAREST;
}
if (aFlags) {
HandleSeparator(*this);
AppendLiteral("Unknown(");
AppendInt(static_cast<uint32_t>(aFlags));
Append(')');
}
}
virtual ~GetACPFromPointFlagName() {}
};
static const char* GetFocusChangeName(
InputContextAction::FocusChange aFocusChange) {
switch (aFocusChange) {
case InputContextAction::FOCUS_NOT_CHANGED:
return "FOCUS_NOT_CHANGED";
case InputContextAction::GOT_FOCUS:
return "GOT_FOCUS";
case InputContextAction::LOST_FOCUS:
return "LOST_FOCUS";
case InputContextAction::MENU_GOT_PSEUDO_FOCUS:
return "MENU_GOT_PSEUDO_FOCUS";
case InputContextAction::MENU_LOST_PSEUDO_FOCUS:
return "MENU_LOST_PSEUDO_FOCUS";
case InputContextAction::WIDGET_CREATED:
return "WIDGET_CREATED";
default:
return "Unknown";
}
}
static nsCString GetCLSIDNameStr(REFCLSID aCLSID) {
LPOLESTR str = nullptr;
HRESULT hr = ::StringFromCLSID(aCLSID, &str);
if (FAILED(hr) || !str || !str[0]) {
return ""_ns;
}
nsCString result;
result = NS_ConvertUTF16toUTF8(str);
::CoTaskMemFree(str);
return result;
}
static nsCString GetGUIDNameStr(REFGUID aGUID) {
OLECHAR str[40];
int len = ::StringFromGUID2(aGUID, str, ArrayLength(str));
if (!len || !str[0]) {
return ""_ns;
}
return NS_ConvertUTF16toUTF8(str);
}
static nsCString GetGUIDNameStrWithTable(REFGUID aGUID) {
#define RETURN_GUID_NAME(aNamedGUID) \
if (IsEqualGUID(aGUID, aNamedGUID)) { \
return nsLiteralCString(#aNamedGUID); \
}
RETURN_GUID_NAME(GUID_PROP_INPUTSCOPE)
RETURN_GUID_NAME(sGUID_PROP_URL)
RETURN_GUID_NAME(TSATTRID_OTHERS)
RETURN_GUID_NAME(TSATTRID_Font)
RETURN_GUID_NAME(TSATTRID_Font_FaceName)
RETURN_GUID_NAME(TSATTRID_Font_SizePts)
RETURN_GUID_NAME(TSATTRID_Font_Style)
RETURN_GUID_NAME(TSATTRID_Font_Style_Bold)
RETURN_GUID_NAME(TSATTRID_Font_Style_Italic)
RETURN_GUID_NAME(TSATTRID_Font_Style_SmallCaps)
RETURN_GUID_NAME(TSATTRID_Font_Style_Capitalize)
RETURN_GUID_NAME(TSATTRID_Font_Style_Uppercase)
RETURN_GUID_NAME(TSATTRID_Font_Style_Lowercase)
RETURN_GUID_NAME(TSATTRID_Font_Style_Animation)
RETURN_GUID_NAME(TSATTRID_Font_Style_Animation_LasVegasLights)
RETURN_GUID_NAME(TSATTRID_Font_Style_Animation_BlinkingBackground)
RETURN_GUID_NAME(TSATTRID_Font_Style_Animation_SparkleText)
RETURN_GUID_NAME(TSATTRID_Font_Style_Animation_MarchingBlackAnts)
RETURN_GUID_NAME(TSATTRID_Font_Style_Animation_MarchingRedAnts)
RETURN_GUID_NAME(TSATTRID_Font_Style_Animation_Shimmer)
RETURN_GUID_NAME(TSATTRID_Font_Style_Animation_WipeDown)
RETURN_GUID_NAME(TSATTRID_Font_Style_Animation_WipeRight)
RETURN_GUID_NAME(TSATTRID_Font_Style_Emboss)
RETURN_GUID_NAME(TSATTRID_Font_Style_Engrave)
RETURN_GUID_NAME(TSATTRID_Font_Style_Hidden)
RETURN_GUID_NAME(TSATTRID_Font_Style_Kerning)
RETURN_GUID_NAME(TSATTRID_Font_Style_Outlined)
RETURN_GUID_NAME(TSATTRID_Font_Style_Position)
RETURN_GUID_NAME(TSATTRID_Font_Style_Protected)
RETURN_GUID_NAME(TSATTRID_Font_Style_Shadow)
RETURN_GUID_NAME(TSATTRID_Font_Style_Spacing)
RETURN_GUID_NAME(TSATTRID_Font_Style_Weight)
RETURN_GUID_NAME(TSATTRID_Font_Style_Height)
RETURN_GUID_NAME(TSATTRID_Font_Style_Underline)
RETURN_GUID_NAME(TSATTRID_Font_Style_Underline_Single)
RETURN_GUID_NAME(TSATTRID_Font_Style_Underline_Double)
RETURN_GUID_NAME(TSATTRID_Font_Style_Strikethrough)
RETURN_GUID_NAME(TSATTRID_Font_Style_Strikethrough_Single)
RETURN_GUID_NAME(TSATTRID_Font_Style_Strikethrough_Double)
RETURN_GUID_NAME(TSATTRID_Font_Style_Overline)
RETURN_GUID_NAME(TSATTRID_Font_Style_Overline_Single)
RETURN_GUID_NAME(TSATTRID_Font_Style_Overline_Double)
RETURN_GUID_NAME(TSATTRID_Font_Style_Blink)
RETURN_GUID_NAME(TSATTRID_Font_Style_Subscript)
RETURN_GUID_NAME(TSATTRID_Font_Style_Superscript)
RETURN_GUID_NAME(TSATTRID_Font_Style_Color)
RETURN_GUID_NAME(TSATTRID_Font_Style_BackgroundColor)
RETURN_GUID_NAME(TSATTRID_Text)
RETURN_GUID_NAME(TSATTRID_Text_VerticalWriting)
RETURN_GUID_NAME(TSATTRID_Text_RightToLeft)
RETURN_GUID_NAME(TSATTRID_Text_Orientation)
RETURN_GUID_NAME(TSATTRID_Text_Language)
RETURN_GUID_NAME(TSATTRID_Text_ReadOnly)
RETURN_GUID_NAME(TSATTRID_Text_EmbeddedObject)
RETURN_GUID_NAME(TSATTRID_Text_Alignment)
RETURN_GUID_NAME(TSATTRID_Text_Alignment_Left)
RETURN_GUID_NAME(TSATTRID_Text_Alignment_Right)
RETURN_GUID_NAME(TSATTRID_Text_Alignment_Center)
RETURN_GUID_NAME(TSATTRID_Text_Alignment_Justify)
RETURN_GUID_NAME(TSATTRID_Text_Link)
RETURN_GUID_NAME(TSATTRID_Text_Hyphenation)
RETURN_GUID_NAME(TSATTRID_Text_Para)
RETURN_GUID_NAME(TSATTRID_Text_Para_FirstLineIndent)
RETURN_GUID_NAME(TSATTRID_Text_Para_LeftIndent)
RETURN_GUID_NAME(TSATTRID_Text_Para_RightIndent)
RETURN_GUID_NAME(TSATTRID_Text_Para_SpaceAfter)
RETURN_GUID_NAME(TSATTRID_Text_Para_SpaceBefore)
RETURN_GUID_NAME(TSATTRID_Text_Para_LineSpacing)
RETURN_GUID_NAME(TSATTRID_Text_Para_LineSpacing_Single)
RETURN_GUID_NAME(TSATTRID_Text_Para_LineSpacing_OnePtFive)
RETURN_GUID_NAME(TSATTRID_Text_Para_LineSpacing_Double)
RETURN_GUID_NAME(TSATTRID_Text_Para_LineSpacing_AtLeast)
RETURN_GUID_NAME(TSATTRID_Text_Para_LineSpacing_Exactly)
RETURN_GUID_NAME(TSATTRID_Text_Para_LineSpacing_Multiple)
RETURN_GUID_NAME(TSATTRID_List)
RETURN_GUID_NAME(TSATTRID_List_LevelIndel)
RETURN_GUID_NAME(TSATTRID_List_Type)
RETURN_GUID_NAME(TSATTRID_List_Type_Bullet)
RETURN_GUID_NAME(TSATTRID_List_Type_Arabic)
RETURN_GUID_NAME(TSATTRID_List_Type_LowerLetter)
RETURN_GUID_NAME(TSATTRID_List_Type_UpperLetter)
RETURN_GUID_NAME(TSATTRID_List_Type_LowerRoman)
RETURN_GUID_NAME(TSATTRID_List_Type_UpperRoman)
RETURN_GUID_NAME(TSATTRID_App)
RETURN_GUID_NAME(TSATTRID_App_IncorrectSpelling)
RETURN_GUID_NAME(TSATTRID_App_IncorrectGrammar)
#undef RETURN_GUID_NAME
return GetGUIDNameStr(aGUID);
}
static nsCString GetRIIDNameStr(REFIID aRIID) {
LPOLESTR str = nullptr;
HRESULT hr = ::StringFromIID(aRIID, &str);
if (FAILED(hr) || !str || !str[0]) {
return ""_ns;
}
nsAutoString key(L"Interface\\");
key += str;
nsCString result;
wchar_t buf[256];
if (WinRegistry::GetString(HKEY_CLASSES_ROOT, key, u""_ns, buf,
WinRegistry::kLegacyWinUtilsStringFlags)) {
result = NS_ConvertUTF16toUTF8(buf);
} else {
result = NS_ConvertUTF16toUTF8(str);
}
::CoTaskMemFree(str);
return result;
}
static const char* GetCommonReturnValueName(HRESULT aResult) {
switch (aResult) {
case S_OK:
return "S_OK";
case E_ABORT:
return "E_ABORT";
case E_ACCESSDENIED:
return "E_ACCESSDENIED";
case E_FAIL:
return "E_FAIL";
case E_HANDLE:
return "E_HANDLE";
case E_INVALIDARG:
return "E_INVALIDARG";
case E_NOINTERFACE:
return "E_NOINTERFACE";
case E_NOTIMPL:
return "E_NOTIMPL";
case E_OUTOFMEMORY:
return "E_OUTOFMEMORY";
case E_POINTER:
return "E_POINTER";
case E_UNEXPECTED:
return "E_UNEXPECTED";
default:
return SUCCEEDED(aResult) ? "Succeeded" : "Failed";
}
}
static const char* GetTextStoreReturnValueName(HRESULT aResult) {
switch (aResult) {
case TS_E_FORMAT:
return "TS_E_FORMAT";
case TS_E_INVALIDPOINT:
return "TS_E_INVALIDPOINT";
case TS_E_INVALIDPOS:
return "TS_E_INVALIDPOS";
case TS_E_NOINTERFACE:
return "TS_E_NOINTERFACE";
case TS_E_NOLAYOUT:
return "TS_E_NOLAYOUT";
case TS_E_NOLOCK:
return "TS_E_NOLOCK";
case TS_E_NOOBJECT:
return "TS_E_NOOBJECT";
case TS_E_NOSELECTION:
return "TS_E_NOSELECTION";
case TS_E_NOSERVICE:
return "TS_E_NOSERVICE";
case TS_E_READONLY:
return "TS_E_READONLY";
case TS_E_SYNCHRONOUS:
return "TS_E_SYNCHRONOUS";
case TS_S_ASYNC:
return "TS_S_ASYNC";
default:
return GetCommonReturnValueName(aResult);
}
}
static const nsCString GetSinkMaskNameStr(DWORD aSinkMask) {
nsCString description;
if (aSinkMask & TS_AS_TEXT_CHANGE) {
description.AppendLiteral("TS_AS_TEXT_CHANGE");
}
if (aSinkMask & TS_AS_SEL_CHANGE) {
HandleSeparator(description);
description.AppendLiteral("TS_AS_SEL_CHANGE");
}
if (aSinkMask & TS_AS_LAYOUT_CHANGE) {
HandleSeparator(description);
description.AppendLiteral("TS_AS_LAYOUT_CHANGE");
}
if (aSinkMask & TS_AS_ATTR_CHANGE) {
HandleSeparator(description);
description.AppendLiteral("TS_AS_ATTR_CHANGE");
}
if (aSinkMask & TS_AS_STATUS_CHANGE) {
HandleSeparator(description);
description.AppendLiteral("TS_AS_STATUS_CHANGE");
}
if (description.IsEmpty()) {
description.AppendLiteral("not-specified");
}
return description;
}
static const nsCString GetLockFlagNameStr(DWORD aLockFlags) {
nsCString description;
if ((aLockFlags & TS_LF_READWRITE) == TS_LF_READWRITE) {
description.AppendLiteral("TS_LF_READWRITE");
} else if (aLockFlags & TS_LF_READ) {
description.AppendLiteral("TS_LF_READ");
}
if (aLockFlags & TS_LF_SYNC) {
if (!description.IsEmpty()) {
description.AppendLiteral(" | ");
}
description.AppendLiteral("TS_LF_SYNC");
}
if (description.IsEmpty()) {
description.AppendLiteral("not-specified");
}
return description;
}
static const char* GetTextRunTypeName(TsRunType aRunType) {
switch (aRunType) {
case TS_RT_PLAIN:
return "TS_RT_PLAIN";
case TS_RT_HIDDEN:
return "TS_RT_HIDDEN";
case TS_RT_OPAQUE:
return "TS_RT_OPAQUE";
default:
return "Unknown";
}
}
static nsCString GetColorName(const TF_DA_COLOR& aColor) {
switch (aColor.type) {
case TF_CT_NONE:
return "TF_CT_NONE"_ns;
case TF_CT_SYSCOLOR:
return nsPrintfCString("TF_CT_SYSCOLOR, nIndex:0x%08X",
static_cast<int32_t>(aColor.nIndex));
case TF_CT_COLORREF:
return nsPrintfCString("TF_CT_COLORREF, cr:0x%08X",
static_cast<int32_t>(aColor.cr));
break;
default:
return nsPrintfCString("Unknown(%08X)",
static_cast<int32_t>(aColor.type));
}
}
static nsCString GetLineStyleName(TF_DA_LINESTYLE aLineStyle) {
switch (aLineStyle) {
case TF_LS_NONE:
return "TF_LS_NONE"_ns;
case TF_LS_SOLID:
return "TF_LS_SOLID"_ns;
case TF_LS_DOT:
return "TF_LS_DOT"_ns;
case TF_LS_DASH:
return "TF_LS_DASH"_ns;
case TF_LS_SQUIGGLE:
return "TF_LS_SQUIGGLE"_ns;
default: {
return nsPrintfCString("Unknown(%08X)", static_cast<int32_t>(aLineStyle));
}
}
}
static nsCString GetClauseAttrName(TF_DA_ATTR_INFO aAttr) {
switch (aAttr) {
case TF_ATTR_INPUT:
return "TF_ATTR_INPUT"_ns;
case TF_ATTR_TARGET_CONVERTED:
return "TF_ATTR_TARGET_CONVERTED"_ns;
case TF_ATTR_CONVERTED:
return "TF_ATTR_CONVERTED"_ns;
case TF_ATTR_TARGET_NOTCONVERTED:
return "TF_ATTR_TARGET_NOTCONVERTED"_ns;
case TF_ATTR_INPUT_ERROR:
return "TF_ATTR_INPUT_ERROR"_ns;
case TF_ATTR_FIXEDCONVERTED:
return "TF_ATTR_FIXEDCONVERTED"_ns;
case TF_ATTR_OTHER:
return "TF_ATTR_OTHER"_ns;
default: {
return nsPrintfCString("Unknown(%08X)", static_cast<int32_t>(aAttr));
}
}
}
static nsCString GetDisplayAttrStr(const TF_DISPLAYATTRIBUTE& aDispAttr) {
nsCString str;
str = "crText:{ ";
str += GetColorName(aDispAttr.crText);
str += " }, crBk:{ ";
str += GetColorName(aDispAttr.crBk);
str += " }, lsStyle: ";
str += GetLineStyleName(aDispAttr.lsStyle);
str += ", fBoldLine: ";
str += GetBoolName(aDispAttr.fBoldLine);
str += ", crLine:{ ";
str += GetColorName(aDispAttr.crLine);
str += " }, bAttr: ";
str += GetClauseAttrName(aDispAttr.bAttr);
return str;
}
static const char* GetMouseButtonName(int16_t aButton) {
switch (aButton) {
case MouseButton::ePrimary:
return "LeftButton";
case MouseButton::eMiddle:
return "MiddleButton";
case MouseButton::eSecondary:
return "RightButton";
default:
return "UnknownButton";
}
}
#define ADD_SEPARATOR_IF_NECESSARY(aStr) \
if (!aStr.IsEmpty()) { \
aStr.AppendLiteral(", "); \
}
static nsCString GetMouseButtonsName(int16_t aButtons) {
if (!aButtons) {
return "no buttons"_ns;
}
nsCString names;
if (aButtons & MouseButtonsFlag::ePrimaryFlag) {
names = "LeftButton";
}
if (aButtons & MouseButtonsFlag::eSecondaryFlag) {
ADD_SEPARATOR_IF_NECESSARY(names);
names += "RightButton";
}
if (aButtons & MouseButtonsFlag::eMiddleFlag) {
ADD_SEPARATOR_IF_NECESSARY(names);
names += "MiddleButton";
}
if (aButtons & MouseButtonsFlag::e4thFlag) {
ADD_SEPARATOR_IF_NECESSARY(names);
names += "4thButton";
}
if (aButtons & MouseButtonsFlag::e5thFlag) {
ADD_SEPARATOR_IF_NECESSARY(names);
names += "5thButton";
}
return names;
}
static nsCString GetModifiersName(Modifiers aModifiers) {
if (aModifiers == MODIFIER_NONE) {
return "no modifiers"_ns;
}
nsCString names;
if (aModifiers & MODIFIER_ALT) {
names = NS_DOM_KEYNAME_ALT;
}
if (aModifiers & MODIFIER_ALTGRAPH) {
ADD_SEPARATOR_IF_NECESSARY(names);
names += NS_DOM_KEYNAME_ALTGRAPH;
}
if (aModifiers & MODIFIER_CAPSLOCK) {
ADD_SEPARATOR_IF_NECESSARY(names);
names += NS_DOM_KEYNAME_CAPSLOCK;
}
if (aModifiers & MODIFIER_CONTROL) {
ADD_SEPARATOR_IF_NECESSARY(names);
names += NS_DOM_KEYNAME_CONTROL;
}
if (aModifiers & MODIFIER_FN) {
ADD_SEPARATOR_IF_NECESSARY(names);
names += NS_DOM_KEYNAME_FN;
}
if (aModifiers & MODIFIER_FNLOCK) {
ADD_SEPARATOR_IF_NECESSARY(names);
names += NS_DOM_KEYNAME_FNLOCK;
}
if (aModifiers & MODIFIER_META) {
ADD_SEPARATOR_IF_NECESSARY(names);
names += NS_DOM_KEYNAME_META;
}
if (aModifiers & MODIFIER_NUMLOCK) {
ADD_SEPARATOR_IF_NECESSARY(names);
names += NS_DOM_KEYNAME_NUMLOCK;
}
if (aModifiers & MODIFIER_SCROLLLOCK) {
ADD_SEPARATOR_IF_NECESSARY(names);
names += NS_DOM_KEYNAME_SCROLLLOCK;
}
if (aModifiers & MODIFIER_SHIFT) {
ADD_SEPARATOR_IF_NECESSARY(names);
names += NS_DOM_KEYNAME_SHIFT;
}
if (aModifiers & MODIFIER_SYMBOL) {
ADD_SEPARATOR_IF_NECESSARY(names);
names += NS_DOM_KEYNAME_SYMBOL;
}
if (aModifiers & MODIFIER_SYMBOLLOCK) {
ADD_SEPARATOR_IF_NECESSARY(names);
names += NS_DOM_KEYNAME_SYMBOLLOCK;
}
return names;
}
class GetWritingModeName : public nsAutoCString {
public:
explicit GetWritingModeName(const WritingMode& aWritingMode) {
if (!aWritingMode.IsVertical()) {
AssignLiteral("Horizontal");
return;
}
if (aWritingMode.IsVerticalLR()) {
AssignLiteral("Vertical (LR)");
return;
}
AssignLiteral("Vertical (RL)");
}
virtual ~GetWritingModeName() {}
};
class GetEscapedUTF8String final : public NS_ConvertUTF16toUTF8 {
public:
explicit GetEscapedUTF8String(const nsAString& aString)
: NS_ConvertUTF16toUTF8(aString) {
Escape();
}
explicit GetEscapedUTF8String(const char16ptr_t aString)
: NS_ConvertUTF16toUTF8(aString) {
Escape();
}
GetEscapedUTF8String(const char16ptr_t aString, uint32_t aLength)
: NS_ConvertUTF16toUTF8(aString, aLength) {
Escape();
}
private:
void Escape() {
ReplaceSubstring("\r", "\\r");
ReplaceSubstring("\n", "\\n");
ReplaceSubstring("\t", "\\t");
}
};
class GetInputScopeString : public nsAutoCString {
public:
explicit GetInputScopeString(const nsTArray<InputScope>& aList) {
for (InputScope inputScope : aList) {
if (!IsEmpty()) {
AppendLiteral(", ");
}
switch (inputScope) {
case IS_DEFAULT:
AppendLiteral("IS_DEFAULT");
break;
case IS_URL:
AppendLiteral("IS_URL");
break;
case IS_FILE_FULLFILEPATH:
AppendLiteral("IS_FILE_FULLFILEPATH");
break;
case IS_FILE_FILENAME:
AppendLiteral("IS_FILE_FILENAME");
break;
case IS_EMAIL_USERNAME:
AppendLiteral("IS_EMAIL_USERNAME");
break;
case IS_EMAIL_SMTPEMAILADDRESS:
AppendLiteral("IS_EMAIL_SMTPEMAILADDRESS");
break;
case IS_LOGINNAME:
AppendLiteral("IS_LOGINNAME");
break;
case IS_PERSONALNAME_FULLNAME:
AppendLiteral("IS_PERSONALNAME_FULLNAME");
break;
case IS_PERSONALNAME_PREFIX:
AppendLiteral("IS_PERSONALNAME_PREFIX");
break;
case IS_PERSONALNAME_GIVENNAME:
AppendLiteral("IS_PERSONALNAME_GIVENNAME");
break;
case IS_PERSONALNAME_MIDDLENAME:
AppendLiteral("IS_PERSONALNAME_MIDDLENAME");
break;
case IS_PERSONALNAME_SURNAME:
AppendLiteral("IS_PERSONALNAME_SURNAME");
break;
case IS_PERSONALNAME_SUFFIX:
AppendLiteral("IS_PERSONALNAME_SUFFIX");
break;
case IS_ADDRESS_FULLPOSTALADDRESS:
AppendLiteral("IS_ADDRESS_FULLPOSTALADDRESS");
break;
case IS_ADDRESS_POSTALCODE:
AppendLiteral("IS_ADDRESS_POSTALCODE");
break;
case IS_ADDRESS_STREET:
AppendLiteral("IS_ADDRESS_STREET");
break;
case IS_ADDRESS_STATEORPROVINCE:
AppendLiteral("IS_ADDRESS_STATEORPROVINCE");
break;
case IS_ADDRESS_CITY:
AppendLiteral("IS_ADDRESS_CITY");
break;
case IS_ADDRESS_COUNTRYNAME:
AppendLiteral("IS_ADDRESS_COUNTRYNAME");
break;
case IS_ADDRESS_COUNTRYSHORTNAME:
AppendLiteral("IS_ADDRESS_COUNTRYSHORTNAME");
break;
case IS_CURRENCY_AMOUNTANDSYMBOL:
AppendLiteral("IS_CURRENCY_AMOUNTANDSYMBOL");
break;
case IS_CURRENCY_AMOUNT:
AppendLiteral("IS_CURRENCY_AMOUNT");
break;
case IS_DATE_FULLDATE:
AppendLiteral("IS_DATE_FULLDATE");
break;
case IS_DATE_MONTH:
AppendLiteral("IS_DATE_MONTH");
break;
case IS_DATE_DAY:
AppendLiteral("IS_DATE_DAY");
break;
case IS_DATE_YEAR:
AppendLiteral("IS_DATE_YEAR");
break;
case IS_DATE_MONTHNAME:
AppendLiteral("IS_DATE_MONTHNAME");
break;
case IS_DATE_DAYNAME:
AppendLiteral("IS_DATE_DAYNAME");
break;
case IS_DIGITS:
AppendLiteral("IS_DIGITS");
break;
case IS_NUMBER:
AppendLiteral("IS_NUMBER");
break;
case IS_ONECHAR:
AppendLiteral("IS_ONECHAR");
break;
case IS_PASSWORD:
AppendLiteral("IS_PASSWORD");
break;
case IS_TELEPHONE_FULLTELEPHONENUMBER:
AppendLiteral("IS_TELEPHONE_FULLTELEPHONENUMBER");
break;
case IS_TELEPHONE_COUNTRYCODE:
AppendLiteral("IS_TELEPHONE_COUNTRYCODE");
break;
case IS_TELEPHONE_AREACODE:
AppendLiteral("IS_TELEPHONE_AREACODE");
break;
case IS_TELEPHONE_LOCALNUMBER:
AppendLiteral("IS_TELEPHONE_LOCALNUMBER");
break;
case IS_TIME_FULLTIME:
AppendLiteral("IS_TIME_FULLTIME");
break;
case IS_TIME_HOUR:
AppendLiteral("IS_TIME_HOUR");
break;
case IS_TIME_MINORSEC:
AppendLiteral("IS_TIME_MINORSEC");
break;
case IS_NUMBER_FULLWIDTH:
AppendLiteral("IS_NUMBER_FULLWIDTH");
break;
case IS_ALPHANUMERIC_HALFWIDTH:
AppendLiteral("IS_ALPHANUMERIC_HALFWIDTH");
break;
case IS_ALPHANUMERIC_FULLWIDTH:
AppendLiteral("IS_ALPHANUMERIC_FULLWIDTH");
break;
case IS_CURRENCY_CHINESE:
AppendLiteral("IS_CURRENCY_CHINESE");
break;
case IS_BOPOMOFO:
AppendLiteral("IS_BOPOMOFO");
break;
case IS_HIRAGANA:
AppendLiteral("IS_HIRAGANA");
break;
case IS_KATAKANA_HALFWIDTH:
AppendLiteral("IS_KATAKANA_HALFWIDTH");
break;
case IS_KATAKANA_FULLWIDTH:
AppendLiteral("IS_KATAKANA_FULLWIDTH");
break;
case IS_HANJA:
AppendLiteral("IS_HANJA");
break;
case IS_PHRASELIST:
AppendLiteral("IS_PHRASELIST");
break;
case IS_REGULAREXPRESSION:
AppendLiteral("IS_REGULAREXPRESSION");
break;
case IS_SRGS:
AppendLiteral("IS_SRGS");
break;
case IS_XML:
AppendLiteral("IS_XML");
break;
case IS_PRIVATE:
AppendLiteral("IS_PRIVATE");
break;
default:
AppendPrintf("Unknown Value(%d)", inputScope);
break;
}
}
}
};
/******************************************************************/
/* InputScopeImpl */
/******************************************************************/
class InputScopeImpl final : public ITfInputScope {
~InputScopeImpl() {}
public:
explicit InputScopeImpl(const nsTArray<InputScope>& aList)
: mInputScopes(aList.Clone()) {
MOZ_LOG(
gIMELog, LogLevel::Info,
("0x%p InputScopeImpl(%s)", this, GetInputScopeString(aList).get()));
}
NS_INLINE_DECL_IUNKNOWN_REFCOUNTING(InputScopeImpl)
STDMETHODIMP QueryInterface(REFIID riid, void** ppv) {
*ppv = nullptr;
if ((IID_IUnknown == riid) || (IID_ITfInputScope == riid)) {
*ppv = static_cast<ITfInputScope*>(this);
}
if (*ppv) {
AddRef();
return S_OK;
}
return E_NOINTERFACE;
}
STDMETHODIMP GetInputScopes(InputScope** pprgInputScopes, UINT* pcCount) {
uint32_t count = (mInputScopes.IsEmpty() ? 1 : mInputScopes.Length());
InputScope* pScope =
(InputScope*)CoTaskMemAlloc(sizeof(InputScope) * count);
NS_ENSURE_TRUE(pScope, E_OUTOFMEMORY);
if (mInputScopes.IsEmpty()) {
*pScope = IS_DEFAULT;
*pcCount = 1;
*pprgInputScopes = pScope;
return S_OK;
}
*pcCount = 0;
for (uint32_t idx = 0; idx < count; idx++) {
*(pScope + idx) = mInputScopes[idx];
(*pcCount)++;
}
*pprgInputScopes = pScope;
return S_OK;
}
STDMETHODIMP GetPhrase(BSTR** ppbstrPhrases, UINT* pcCount) {
return E_NOTIMPL;
}
STDMETHODIMP GetRegularExpression(BSTR* pbstrRegExp) { return E_NOTIMPL; }
STDMETHODIMP GetSRGS(BSTR* pbstrSRGS) { return E_NOTIMPL; }
STDMETHODIMP GetXML(BSTR* pbstrXML) { return E_NOTIMPL; }
private:
nsTArray<InputScope> mInputScopes;
};
/******************************************************************/
/* TSFStaticSink */
/******************************************************************/
class TSFStaticSink final : public ITfInputProcessorProfileActivationSink {
public:
static TSFStaticSink* GetInstance() {
if (!sInstance) {
RefPtr<ITfThreadMgr> threadMgr = TSFTextStore::GetThreadMgr();
if (NS_WARN_IF(!threadMgr)) {
MOZ_LOG(
gIMELog, LogLevel::Error,
("TSFStaticSink::GetInstance() FAILED to initialize TSFStaticSink "
"instance due to no ThreadMgr instance"));
return nullptr;
}
RefPtr<ITfInputProcessorProfiles> inputProcessorProfiles =
TSFTextStore::GetInputProcessorProfiles();
if (NS_WARN_IF(!inputProcessorProfiles)) {
MOZ_LOG(
gIMELog, LogLevel::Error,
("TSFStaticSink::GetInstance() FAILED to initialize TSFStaticSink "
"instance due to no InputProcessorProfiles instance"));
return nullptr;
}
RefPtr<TSFStaticSink> staticSink = new TSFStaticSink();
if (NS_WARN_IF(!staticSink->Init(threadMgr, inputProcessorProfiles))) {
staticSink->Destroy();
MOZ_LOG(
gIMELog, LogLevel::Error,
("TSFStaticSink::GetInstance() FAILED to initialize TSFStaticSink "
"instance"));
return nullptr;
}
sInstance = staticSink.forget();
}
return sInstance;
}
static void Shutdown() {
if (sInstance) {
sInstance->Destroy();
sInstance = nullptr;
}
}
bool Init(ITfThreadMgr* aThreadMgr,
ITfInputProcessorProfiles* aInputProcessorProfiles);
STDMETHODIMP QueryInterface(REFIID riid, void** ppv) {
*ppv = nullptr;
if (IID_IUnknown == riid ||
IID_ITfInputProcessorProfileActivationSink == riid) {
*ppv = static_cast<ITfInputProcessorProfileActivationSink*>(this);
}
if (*ppv) {
AddRef();
return S_OK;
}
return E_NOINTERFACE;
}
NS_INLINE_DECL_IUNKNOWN_REFCOUNTING(TSFStaticSink)
const nsString& GetActiveTIPKeyboardDescription() const {
return mActiveTIPKeyboardDescription;
}
static bool IsIMM_IMEActive() {
// Use IMM API until TSFStaticSink starts to work.
if (!sInstance || !sInstance->EnsureInitActiveTIPKeyboard()) {
return IsIMM_IME(::GetKeyboardLayout(0));
}
return sInstance->mIsIMM_IME;
}
static bool IsIMM_IME(HKL aHKL) {
return (::ImmGetIMEFileNameW(aHKL, nullptr, 0) > 0);
}
static bool IsTraditionalChinese() {
EnsureInstance();