1 /* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #include "gfxFontUtils.h"
11 #include "mozilla/WritingModes.h"
13 #include "nsPrintfCString.h"
18 PrintStringDetail::PrintStringDetail(const nsAString
& aString
,
19 uint32_t aMaxLength
/* = UINT32_MAX */) {
21 const uint32_t kFirstHalf
=
22 aString
.Length() <= aMaxLength
? UINT32_MAX
: (aMaxLength
+ 1) / 2;
23 const uint32_t kSecondHalf
=
24 aString
.Length() <= aMaxLength
? 0 : aMaxLength
/ 2;
25 for (uint32_t i
= 0; i
< aString
.Length(); i
++) {
29 char32_t ch
= aString
.CharAt(i
);
30 if (NS_IS_HIGH_SURROGATE(ch
) && i
+ 1 < aString
.Length() &&
31 NS_IS_LOW_SURROGATE(aString
.CharAt(i
+ 1))) {
32 ch
= SURROGATE_TO_UCS4(ch
, aString
.CharAt(i
+ 1));
34 Append(PrintCharData(ch
));
35 if (i
+ 1 == kFirstHalf
) {
37 i
= aString
.Length() - kSecondHalf
- 1;
38 if (NS_IS_LOW_SURROGATE(aString
.CharAt(i
)) &&
39 NS_IS_HIGH_SURROGATE(aString
.CharAt(i
- 1))) {
40 if (i
- 1 <= kFirstHalf
) {
46 } else if (!IS_IN_BMP(ch
)) {
54 nsCString
PrintStringDetail::PrintCharData(char32_t aChar
) {
57 return "NULL (0x0000)"_ns
;
59 return "BACKSPACE (0x0008)"_ns
;
61 return "CHARACTER TABULATION (0x0009)"_ns
;
63 return "LINE FEED (0x000A)"_ns
;
65 return "LINE TABULATION (0x000B)"_ns
;
67 return "FORM FEED (0x000C)"_ns
;
69 return "CARRIAGE RETURN (0x000D)"_ns
;
71 return "CANCEL (0x0018)"_ns
;
73 return "ESCAPE (0x001B)"_ns
;
75 return "SPACE (0x0020)"_ns
;
77 return "DELETE (0x007F)"_ns
;
79 return "NO-BREAK SPACE (0x00A0)"_ns
;
81 return "SOFT HYPHEN (0x00AD)"_ns
;
83 return "EN QUAD (0x2000)"_ns
;
85 return "EM QUAD (0x2001)"_ns
;
87 return "EN SPACE (0x2002)"_ns
;
89 return "EM SPACE (0x2003)"_ns
;
91 return "THREE-PER-EM SPACE (0x2004)"_ns
;
93 return "FOUR-PER-EM SPACE (0x2005)"_ns
;
95 return "SIX-PER-EM SPACE (0x2006)"_ns
;
97 return "FIGURE SPACE (0x2007)"_ns
;
99 return "PUNCTUATION SPACE (0x2008)"_ns
;
101 return "THIN SPACE (0x2009)"_ns
;
103 return "HAIR SPACE (0x200A)"_ns
;
105 return "ZERO WIDTH SPACE (0x200B)"_ns
;
107 return "ZERO WIDTH NON-JOINER (0x200C)"_ns
;
109 return "ZERO WIDTH JOINER (0x200D)"_ns
;
111 return "LEFT-TO-RIGHT MARK (0x200E)"_ns
;
113 return "RIGHT-TO-LEFT MARK (0x200F)"_ns
;
115 return "PARAGRAPH SEPARATOR (0x2029)"_ns
;
117 return "LEFT-TO-RIGHT EMBEDDING (0x202A)"_ns
;
119 return "RIGHT-TO-LEFT EMBEDDING (0x202B)"_ns
;
121 return "LEFT-TO-RIGHT OVERRIDE (0x202D)"_ns
;
123 return "RIGHT-TO-LEFT OVERRIDE (0x202E)"_ns
;
125 return "NARROW NO-BREAK SPACE (0x202F)"_ns
;
127 return "MEDIUM MATHEMATICAL SPACE (0x205F)"_ns
;
129 return "WORD JOINER (0x2060)"_ns
;
131 return "LEFT-TO-RIGHT ISOLATE (0x2066)"_ns
;
133 return "RIGHT-TO-LEFT ISOLATE (0x2067)"_ns
;
135 return "IDEOGRAPHIC SPACE (0x3000)"_ns
;
137 return "ZERO WIDTH NO-BREAK SPACE (0xFEFF)"_ns
;
139 if (aChar
< ' ' || (aChar
>= 0x80 && aChar
< 0xA0)) {
140 return nsPrintfCString("Control (0x%04X)", aChar
);
142 if (NS_IS_HIGH_SURROGATE(aChar
)) {
143 return nsPrintfCString("High Surrogate (0x%04X)", aChar
);
145 if (NS_IS_LOW_SURROGATE(aChar
)) {
146 return nsPrintfCString("Low Surrogate (0x%04X)", aChar
);
148 if (gfxFontUtils::IsVarSelector(aChar
)) {
149 return IS_IN_BMP(aChar
)
150 ? nsPrintfCString("Variant Selector (0x%04X)", aChar
)
151 : nsPrintfCString("Variant Selector (0x%08X)", aChar
);
153 nsAutoString utf16Str
;
154 AppendUCS4ToUTF16(aChar
, utf16Str
);
155 return IS_IN_BMP(aChar
)
156 ? nsPrintfCString("'%s' (0x%04X)",
157 NS_ConvertUTF16toUTF8(utf16Str
).get(), aChar
)
158 : nsPrintfCString("'%s' (0x%08X)",
159 NS_ConvertUTF16toUTF8(utf16Str
).get(),
167 std::ostream
& operator<<(std::ostream
& aStream
, const IMEEnabled
& aEnabled
) {
169 case IMEEnabled::Disabled
:
170 return aStream
<< "DISABLED";
171 case IMEEnabled::Enabled
:
172 return aStream
<< "ENABLED";
173 case IMEEnabled::Password
:
174 return aStream
<< "PASSWORD";
175 case IMEEnabled::Unknown
:
176 return aStream
<< "illegal value";
178 MOZ_ASSERT_UNREACHABLE("Add a case to handle your new IMEEnabled value");
182 std::ostream
& operator<<(std::ostream
& aStream
, const IMEState::Open
& aOpen
) {
184 case IMEState::DONT_CHANGE_OPEN_STATE
:
185 aStream
<< "DONT_CHANGE_OPEN_STATE";
190 case IMEState::CLOSED
:
194 aStream
<< "illegal value";
200 std::ostream
& operator<<(std::ostream
& aStream
, const IMEState
& aState
) {
201 aStream
<< "{ mEnabled=" << aState
.mEnabled
<< ", mOpen=" << aState
.mOpen
206 std::ostream
& operator<<(std::ostream
& aStream
,
207 const InputContext::Origin
& aOrigin
) {
209 case InputContext::ORIGIN_MAIN
:
210 aStream
<< "ORIGIN_MAIN";
212 case InputContext::ORIGIN_CONTENT
:
213 aStream
<< "ORIGIN_CONTENT";
216 aStream
<< "illegal value";
222 std::ostream
& operator<<(std::ostream
& aStream
, const InputContext
& aContext
) {
223 aStream
<< "{ mIMEState=" << aContext
.mIMEState
224 << ", mOrigin=" << aContext
.mOrigin
<< ", mHTMLInputType=\""
225 << aContext
.mHTMLInputType
<< "\", mHTMLInputInputmode=\""
226 << aContext
.mHTMLInputInputmode
<< "\", mActionHint=\""
227 << aContext
.mActionHint
<< "\", mAutocapitalize=\""
228 << aContext
.mAutocapitalize
<< "\", mMayBeIMEUnaware="
229 << (aContext
.mMayBeIMEUnaware
? "true" : "false")
230 << ", mIsPrivateBrowsing="
231 << (aContext
.mInPrivateBrowsing
? "true" : "false") << " }";
235 std::ostream
& operator<<(std::ostream
& aStream
,
236 const InputContextAction::Cause
& aCause
) {
238 case InputContextAction::CAUSE_UNKNOWN
:
239 aStream
<< "CAUSE_UNKNOWN";
241 case InputContextAction::CAUSE_UNKNOWN_CHROME
:
242 aStream
<< "CAUSE_UNKNOWN_CHROME";
244 case InputContextAction::CAUSE_KEY
:
245 aStream
<< "CAUSE_KEY";
247 case InputContextAction::CAUSE_MOUSE
:
248 aStream
<< "CAUSE_MOUSE";
250 case InputContextAction::CAUSE_TOUCH
:
251 aStream
<< "CAUSE_TOUCH";
253 case InputContextAction::CAUSE_LONGPRESS
:
254 aStream
<< "CAUSE_LONGPRESS";
256 case InputContextAction::CAUSE_UNKNOWN_DURING_NON_KEYBOARD_INPUT
:
257 aStream
<< "CAUSE_UNKNOWN_DURING_NON_KEYBOARD_INPUT";
259 case InputContextAction::CAUSE_UNKNOWN_DURING_KEYBOARD_INPUT
:
260 aStream
<< "CAUSE_UNKNOWN_DURING_KEYBOARD_INPUT";
263 aStream
<< "illegal value";
269 std::ostream
& operator<<(std::ostream
& aStream
,
270 const InputContextAction::FocusChange
& aFocusChange
) {
271 switch (aFocusChange
) {
272 case InputContextAction::FOCUS_NOT_CHANGED
:
273 aStream
<< "FOCUS_NOT_CHANGED";
275 case InputContextAction::GOT_FOCUS
:
276 aStream
<< "GOT_FOCUS";
278 case InputContextAction::LOST_FOCUS
:
279 aStream
<< "LOST_FOCUS";
281 case InputContextAction::MENU_GOT_PSEUDO_FOCUS
:
282 aStream
<< "MENU_GOT_PSEUDO_FOCUS";
284 case InputContextAction::MENU_LOST_PSEUDO_FOCUS
:
285 aStream
<< "MENU_LOST_PSEUDO_FOCUS";
287 case InputContextAction::WIDGET_CREATED
:
288 aStream
<< "WIDGET_CREATED";
291 aStream
<< "illegal value";
297 std::ostream
& operator<<(
298 std::ostream
& aStream
,
299 const IMENotification::SelectionChangeDataBase
& aData
) {
300 if (!aData
.IsValid()) {
301 aStream
<< "{ IsValid()=false }";
304 aStream
<< "{ mOffset=" << aData
.mOffset
;
305 if (aData
.mString
->Length() > 20) {
306 aStream
<< ", mString.Length()=" << aData
.mString
->Length();
308 aStream
<< ", mString=\"" << NS_ConvertUTF16toUTF8(*aData
.mString
)
309 << "\" (Length()=" << aData
.mString
->Length() << ")";
312 aStream
<< ", GetWritingMode()=" << aData
.GetWritingMode()
313 << ", mReversed=" << (aData
.mReversed
? "true" : "false")
314 << ", mCausedByComposition="
315 << (aData
.mCausedByComposition
? "true" : "false")
316 << ", mCausedBySelectionEvent="
317 << (aData
.mCausedBySelectionEvent
? "true" : "false")
318 << ", mOccurredDuringComposition="
319 << (aData
.mOccurredDuringComposition
? "true" : "false") << " }";
323 std::ostream
& operator<<(std::ostream
& aStream
,
324 const IMENotification::TextChangeDataBase
& aData
) {
325 if (!aData
.IsValid()) {
326 aStream
<< "{ IsValid()=false }";
329 aStream
<< "{ mStartOffset=" << aData
.mStartOffset
330 << ", mRemoveEndOffset=" << aData
.mRemovedEndOffset
331 << ", mAddedEndOffset=" << aData
.mAddedEndOffset
332 << ", mCausedOnlyByComposition="
333 << (aData
.mCausedOnlyByComposition
? "true" : "false")
334 << ", mIncludingChangesDuringComposition="
335 << (aData
.mIncludingChangesDuringComposition
? "true" : "false")
336 << ", mIncludingChangesWithoutComposition="
337 << (aData
.mIncludingChangesWithoutComposition
? "true" : "false")
342 } // namespace widget
343 } // namespace mozilla