forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeadlessLookAndFeelGTK.cpp
355 lines (333 loc) · 9.43 KB
/
HeadlessLookAndFeelGTK.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
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "HeadlessLookAndFeel.h"
#include "nsIContent.h"
using mozilla::LookAndFeel;
namespace mozilla {
namespace widget {
static const char16_t UNICODE_BULLET = 0x2022;
HeadlessLookAndFeel::HeadlessLookAndFeel()
{
}
HeadlessLookAndFeel::~HeadlessLookAndFeel()
{
}
nsresult
HeadlessLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor)
{
// For headless mode, we use GetStandinForNativeColor for everything we can,
// and hardcoded values for everything else.
nsresult res = NS_OK;
switch (aID) {
// Override the solid black that GetStandinForNativeColor provides for
// -moz-FieldText, to match our behavior under the real GTK.
case eColorID__moz_fieldtext:
aColor = NS_RGB(0x21, 0x21, 0x21);
break;
// The rest are not provided by GetStandinForNativeColor.
case eColorID_IMESelectedRawTextBackground:
case eColorID_IMESelectedConvertedTextBackground:
case eColorID_IMERawInputBackground:
case eColorID_IMEConvertedTextBackground:
aColor = NS_TRANSPARENT;
break;
case eColorID_IMESelectedRawTextForeground:
case eColorID_IMESelectedConvertedTextForeground:
case eColorID_IMERawInputForeground:
case eColorID_IMEConvertedTextForeground:
aColor = NS_SAME_AS_FOREGROUND_COLOR;
break;
case eColorID_IMERawInputUnderline:
case eColorID_IMEConvertedTextUnderline:
aColor = NS_40PERCENT_FOREGROUND_COLOR;
break;
case eColorID_IMESelectedRawTextUnderline:
case eColorID_IMESelectedConvertedTextUnderline:
aColor = NS_SAME_AS_FOREGROUND_COLOR;
break;
case eColorID__moz_eventreerow:
aColor = NS_RGB(0xff,0xff,0xff);
break;
case eColorID__moz_gtk_info_bar_text:
aColor = NS_RGB(0x00,0x00,0x00);
break;
case eColorID__moz_mac_buttonactivetext:
case eColorID__moz_mac_defaultbuttontext:
aColor = NS_RGB(0xff,0xff,0xff);
break;
case eColorID_SpellCheckerUnderline:
aColor = NS_RGB(0xff, 0x00, 0x00);
break;
case eColorID_TextBackground:
aColor = NS_RGB(0xff,0xff,0xff);
break;
case eColorID_TextForeground:
aColor = NS_RGB(0x00,0x00,0x00);
break;
case eColorID_TextHighlightBackground:
aColor = NS_RGB(0xef, 0x0f, 0xff);
break;
case eColorID_TextHighlightForeground:
aColor = NS_RGB(0xff, 0xff, 0xff);
break;
case eColorID_TextSelectBackground:
aColor = NS_RGB(0xaa,0xaa,0xaa);
break;
case eColorID_TextSelectBackgroundAttention:
aColor = NS_TRANSPARENT;
break;
case eColorID_TextSelectBackgroundDisabled:
aColor = NS_RGB(0xaa,0xaa,0xaa);
break;
case eColorID_TextSelectForeground:
GetColor(eColorID_TextSelectBackground, aColor);
if (aColor == 0x000000)
aColor = NS_RGB(0xff,0xff,0xff);
else
aColor = NS_DONT_CHANGE_COLOR;
break;
case eColorID_Widget3DHighlight:
aColor = NS_RGB(0xa0,0xa0,0xa0);
break;
case eColorID_Widget3DShadow:
aColor = NS_RGB(0x40,0x40,0x40);
break;
case eColorID_WidgetBackground:
aColor = NS_RGB(0xdd,0xdd,0xdd);
break;
case eColorID_WidgetForeground:
aColor = NS_RGB(0x00,0x00,0x00);
break;
case eColorID_WidgetSelectBackground:
aColor = NS_RGB(0x80,0x80,0x80);
break;
case eColorID_WidgetSelectForeground:
aColor = NS_RGB(0x00,0x00,0x80);
break;
case eColorID_WindowBackground:
aColor = NS_RGB(0xff,0xff,0xff);
break;
case eColorID_WindowForeground:
aColor = NS_RGB(0x00,0x00,0x00);
break;
default:
aColor = GetStandinForNativeColor(aID);
break;
}
return res;
}
nsresult
HeadlessLookAndFeel::GetIntImpl(IntID aID, int32_t &aResult)
{
nsresult res = nsXPLookAndFeel::GetIntImpl(aID, aResult);
if (NS_SUCCEEDED(res))
return res;
res = NS_OK;
// These values should be sane defaults for headless mode under GTK.
switch (aID) {
case eIntID_CaretBlinkTime:
aResult = 567;
break;
case eIntID_CaretWidth:
aResult = 1;
break;
case eIntID_ShowCaretDuringSelection:
aResult = 0;
break;
case eIntID_SelectTextfieldsOnKeyFocus:
aResult = 1;
break;
case eIntID_SubmenuDelay:
aResult = 200;
break;
case eIntID_MenusCanOverlapOSBar:
aResult = 0;
break;
case eIntID_UseOverlayScrollbars:
aResult = 0;
break;
case eIntID_AllowOverlayScrollbarsOverlap:
aResult = 0;
break;
case eIntID_ShowHideScrollbars:
aResult = 0;
break;
case eIntID_SkipNavigatingDisabledMenuItem:
aResult = 1;
break;
case eIntID_DragThresholdX:
case eIntID_DragThresholdY:
aResult = 4;
break;
case eIntID_UseAccessibilityTheme:
aResult = 0;
break;
case eIntID_ScrollArrowStyle:
aResult = eScrollArrow_None;
break;
case eIntID_ScrollSliderStyle:
aResult = eScrollThumbStyle_Proportional;
break;
case eIntID_ScrollButtonLeftMouseButtonAction:
aResult = 0;
return NS_OK;
case eIntID_ScrollButtonMiddleMouseButtonAction:
aResult = 3;
return NS_OK;
case eIntID_ScrollButtonRightMouseButtonAction:
aResult = 3;
return NS_OK;
case eIntID_TreeOpenDelay:
aResult = 1000;
break;
case eIntID_TreeCloseDelay:
aResult = 1000;
break;
case eIntID_TreeLazyScrollDelay:
aResult = 150;
break;
case eIntID_TreeScrollDelay:
aResult = 100;
break;
case eIntID_TreeScrollLinesMax:
aResult = 3;
break;
case eIntID_TabFocusModel:
aResult = nsIContent::eTabFocus_textControlsMask;
break;
case eIntID_ChosenMenuItemsShouldBlink:
aResult = 1;
break;
case eIntID_WindowsAccentColorInTitlebar:
case eIntID_WindowsDefaultTheme:
case eIntID_DWMCompositor:
aResult = 0;
res = NS_ERROR_NOT_IMPLEMENTED;
break;
case eIntID_WindowsClassic:
case eIntID_WindowsGlass:
aResult = 0;
res = NS_ERROR_FAILURE;
break;
case eIntID_TouchEnabled:
case eIntID_MacGraphiteTheme:
case eIntID_MacYosemiteTheme:
aResult = 0;
res = NS_ERROR_NOT_IMPLEMENTED;
break;
case eIntID_AlertNotificationOrigin:
aResult = NS_ALERT_TOP;
break;
case eIntID_ScrollToClick:
aResult = 0;
break;
case eIntID_IMERawInputUnderlineStyle:
case eIntID_IMESelectedRawTextUnderlineStyle:
case eIntID_IMEConvertedTextUnderlineStyle:
case eIntID_IMESelectedConvertedTextUnderline:
aResult = NS_STYLE_TEXT_DECORATION_STYLE_SOLID;
break;
case eIntID_SpellCheckerUnderlineStyle:
aResult = NS_STYLE_TEXT_DECORATION_STYLE_DOTTED;
break;
case eIntID_MenuBarDrag:
aResult = 0;
break;
case eIntID_WindowsThemeIdentifier:
case eIntID_OperatingSystemVersionIdentifier:
aResult = 0;
res = NS_ERROR_NOT_IMPLEMENTED;
break;
case eIntID_ScrollbarButtonAutoRepeatBehavior:
aResult = 0;
break;
case eIntID_TooltipDelay:
aResult = 500;
break;
case eIntID_SwipeAnimationEnabled:
aResult = 0;
break;
case eIntID_ScrollbarDisplayOnMouseMove:
aResult = 0;
break;
case eIntID_ScrollbarFadeBeginDelay:
aResult = 0;
break;
case eIntID_ScrollbarFadeDuration:
aResult = 0;
break;
case eIntID_ContextMenuOffsetVertical:
aResult = -6;
break;
case eIntID_ContextMenuOffsetHorizontal:
aResult = 1;
break;
default:
NS_WARNING("HeadlessLookAndFeel::GetIntImpl called with an unrecognized aID");
aResult = 0;
res = NS_ERROR_FAILURE;
break;
}
return res;
}
nsresult
HeadlessLookAndFeel::GetFloatImpl(FloatID aID, float &aResult)
{
nsresult res = nsXPLookAndFeel::GetFloatImpl(aID, aResult);
if (NS_SUCCEEDED(res))
return res;
res = NS_OK;
// Hardcoded values for GTK.
switch (aID) {
case eFloatID_IMEUnderlineRelativeSize:
aResult = 1.0f;
break;
case eFloatID_SpellCheckerUnderlineRelativeSize:
aResult = 1.0f;
break;
case eFloatID_CaretAspectRatio:
// Intentionally failing to quietly indicate lack of support.
aResult = -1.0;
res = NS_ERROR_FAILURE;
break;
default:
NS_WARNING("HeadlessLookAndFeel::GetFloatImpl called with an unrecognized aID");
aResult = -1.0;
res = NS_ERROR_FAILURE;
break;
}
return res;
}
bool
HeadlessLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
gfxFontStyle& aFontStyle,
float aDevPixPerCSSPixel)
{
// Default to san-serif for everything.
aFontStyle.style = NS_FONT_STYLE_NORMAL;
aFontStyle.weight = NS_FONT_WEIGHT_NORMAL;
aFontStyle.stretch = NS_FONT_STRETCH_NORMAL;
aFontStyle.size = 14 * aDevPixPerCSSPixel;
aFontStyle.systemFont = true;
aFontName.AssignLiteral("sans-serif");
return true;
}
char16_t
HeadlessLookAndFeel::GetPasswordCharacterImpl()
{
return UNICODE_BULLET;
}
void
HeadlessLookAndFeel::RefreshImpl()
{
nsXPLookAndFeel::RefreshImpl();
}
bool
HeadlessLookAndFeel::GetEchoPasswordImpl() {
return false;
}
} // namespace widget
} // namespace mozilla