Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/widget/headless/HeadlessLookAndFeelGTK.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "HeadlessLookAndFeel.h"
8
#include "mozilla/FontPropertyTypes.h"
9
#include "nsIContent.h"
10
11
using mozilla::LookAndFeel;
12
13
namespace mozilla {
14
namespace widget {
15
16
static const char16_t UNICODE_BULLET = 0x2022;
17
18
HeadlessLookAndFeel::HeadlessLookAndFeel()
19
0
{
20
0
}
21
22
HeadlessLookAndFeel::~HeadlessLookAndFeel()
23
0
{
24
0
}
25
26
nsresult
27
HeadlessLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor)
28
0
{
29
0
  // For headless mode, we use GetStandinForNativeColor for everything we can,
30
0
  // and hardcoded values for everything else.
31
0
32
0
  nsresult res = NS_OK;
33
0
34
0
  switch (aID) {
35
0
    // Override the solid black that GetStandinForNativeColor provides for
36
0
    // -moz-FieldText, to match our behavior under the real GTK.
37
0
    case eColorID__moz_fieldtext:
38
0
      aColor = NS_RGB(0x21, 0x21, 0x21);
39
0
      break;
40
0
41
0
    // The rest are not provided by GetStandinForNativeColor.
42
0
    case eColorID_IMESelectedRawTextBackground:
43
0
    case eColorID_IMESelectedConvertedTextBackground:
44
0
    case eColorID_IMERawInputBackground:
45
0
    case eColorID_IMEConvertedTextBackground:
46
0
      aColor = NS_TRANSPARENT;
47
0
      break;
48
0
    case eColorID_IMESelectedRawTextForeground:
49
0
    case eColorID_IMESelectedConvertedTextForeground:
50
0
    case eColorID_IMERawInputForeground:
51
0
    case eColorID_IMEConvertedTextForeground:
52
0
      aColor = NS_SAME_AS_FOREGROUND_COLOR;
53
0
      break;
54
0
    case eColorID_IMERawInputUnderline:
55
0
    case eColorID_IMEConvertedTextUnderline:
56
0
      aColor = NS_40PERCENT_FOREGROUND_COLOR;
57
0
      break;
58
0
    case eColorID_IMESelectedRawTextUnderline:
59
0
    case eColorID_IMESelectedConvertedTextUnderline:
60
0
      aColor = NS_SAME_AS_FOREGROUND_COLOR;
61
0
      break;
62
0
    case eColorID__moz_eventreerow:
63
0
      aColor = NS_RGB(0xff,0xff,0xff);
64
0
      break;
65
0
    case eColorID__moz_gtk_info_bar_text:
66
0
      aColor = NS_RGB(0x00,0x00,0x00);
67
0
      break;
68
0
    case eColorID__moz_mac_buttonactivetext:
69
0
    case eColorID__moz_mac_defaultbuttontext:
70
0
      aColor = NS_RGB(0xff,0xff,0xff);
71
0
      break;
72
0
    case eColorID_SpellCheckerUnderline:
73
0
      aColor = NS_RGB(0xff, 0x00, 0x00);
74
0
      break;
75
0
    case eColorID_TextBackground:
76
0
      aColor = NS_RGB(0xff,0xff,0xff);
77
0
      break;
78
0
    case eColorID_TextForeground:
79
0
      aColor = NS_RGB(0x00,0x00,0x00);
80
0
      break;
81
0
    case eColorID_TextHighlightBackground:
82
0
      aColor = NS_RGB(0xef, 0x0f, 0xff);
83
0
      break;
84
0
    case eColorID_TextHighlightForeground:
85
0
      aColor = NS_RGB(0xff, 0xff, 0xff);
86
0
      break;
87
0
    case eColorID_TextSelectBackground:
88
0
      aColor = NS_RGB(0xaa,0xaa,0xaa);
89
0
      break;
90
0
    case eColorID_TextSelectBackgroundAttention:
91
0
      aColor = NS_TRANSPARENT;
92
0
      break;
93
0
    case eColorID_TextSelectBackgroundDisabled:
94
0
      aColor = NS_RGB(0xaa,0xaa,0xaa);
95
0
      break;
96
0
    case eColorID_TextSelectForeground:
97
0
      GetColor(eColorID_TextSelectBackground, aColor);
98
0
      if (aColor == 0x000000)
99
0
        aColor = NS_RGB(0xff,0xff,0xff);
100
0
      else
101
0
        aColor = NS_DONT_CHANGE_COLOR;
102
0
      break;
103
0
    case eColorID_Widget3DHighlight:
104
0
      aColor = NS_RGB(0xa0,0xa0,0xa0);
105
0
      break;
106
0
    case eColorID_Widget3DShadow:
107
0
      aColor = NS_RGB(0x40,0x40,0x40);
108
0
      break;
109
0
    case eColorID_WidgetBackground:
110
0
      aColor = NS_RGB(0xdd,0xdd,0xdd);
111
0
      break;
112
0
    case eColorID_WidgetForeground:
113
0
      aColor = NS_RGB(0x00,0x00,0x00);
114
0
      break;
115
0
    case eColorID_WidgetSelectBackground:
116
0
      aColor = NS_RGB(0x80,0x80,0x80);
117
0
      break;
118
0
    case eColorID_WidgetSelectForeground:
119
0
      aColor = NS_RGB(0x00,0x00,0x80);
120
0
      break;
121
0
    case eColorID_WindowBackground:
122
0
      aColor = NS_RGB(0xff,0xff,0xff);
123
0
      break;
124
0
    case eColorID_WindowForeground:
125
0
      aColor = NS_RGB(0x00,0x00,0x00);
126
0
      break;
127
0
    default:
128
0
      aColor = GetStandinForNativeColor(aID);
129
0
      break;
130
0
  }
131
0
132
0
  return res;
133
0
}
134
135
nsresult
136
HeadlessLookAndFeel::GetIntImpl(IntID aID, int32_t &aResult)
137
0
{
138
0
  nsresult res = nsXPLookAndFeel::GetIntImpl(aID, aResult);
139
0
  if (NS_SUCCEEDED(res))
140
0
    return res;
141
0
  res = NS_OK;
142
0
143
0
  // These values should be sane defaults for headless mode under GTK.
144
0
  switch (aID) {
145
0
    case eIntID_CaretBlinkTime:
146
0
      aResult = 567;
147
0
      break;
148
0
    case eIntID_CaretWidth:
149
0
      aResult = 1;
150
0
      break;
151
0
    case eIntID_ShowCaretDuringSelection:
152
0
      aResult = 0;
153
0
      break;
154
0
    case eIntID_SelectTextfieldsOnKeyFocus:
155
0
      aResult = 1;
156
0
      break;
157
0
    case eIntID_SubmenuDelay:
158
0
      aResult = 200;
159
0
      break;
160
0
    case eIntID_MenusCanOverlapOSBar:
161
0
      aResult = 0;
162
0
      break;
163
0
    case eIntID_UseOverlayScrollbars:
164
0
      aResult = 0;
165
0
      break;
166
0
    case eIntID_AllowOverlayScrollbarsOverlap:
167
0
      aResult = 0;
168
0
      break;
169
0
    case eIntID_ShowHideScrollbars:
170
0
      aResult = 0;
171
0
      break;
172
0
    case eIntID_SkipNavigatingDisabledMenuItem:
173
0
      aResult = 1;
174
0
      break;
175
0
    case eIntID_DragThresholdX:
176
0
    case eIntID_DragThresholdY:
177
0
      aResult = 4;
178
0
      break;
179
0
    case eIntID_UseAccessibilityTheme:
180
0
      aResult = 0;
181
0
      break;
182
0
    case eIntID_ScrollArrowStyle:
183
0
      aResult = eScrollArrow_None;
184
0
      break;
185
0
    case eIntID_ScrollSliderStyle:
186
0
      aResult = eScrollThumbStyle_Proportional;
187
0
      break;
188
0
    case eIntID_ScrollButtonLeftMouseButtonAction:
189
0
      aResult = 0;
190
0
      return NS_OK;
191
0
    case eIntID_ScrollButtonMiddleMouseButtonAction:
192
0
      aResult = 3;
193
0
      return NS_OK;
194
0
    case eIntID_ScrollButtonRightMouseButtonAction:
195
0
      aResult = 3;
196
0
      return NS_OK;
197
0
    case eIntID_TreeOpenDelay:
198
0
      aResult = 1000;
199
0
      break;
200
0
    case eIntID_TreeCloseDelay:
201
0
      aResult = 1000;
202
0
      break;
203
0
    case eIntID_TreeLazyScrollDelay:
204
0
      aResult = 150;
205
0
      break;
206
0
    case eIntID_TreeScrollDelay:
207
0
      aResult = 100;
208
0
      break;
209
0
    case eIntID_TreeScrollLinesMax:
210
0
      aResult = 3;
211
0
      break;
212
0
    case eIntID_TabFocusModel:
213
0
      aResult = nsIContent::eTabFocus_textControlsMask;
214
0
      break;
215
0
    case eIntID_ChosenMenuItemsShouldBlink:
216
0
      aResult = 1;
217
0
      break;
218
0
    case eIntID_WindowsAccentColorInTitlebar:
219
0
    case eIntID_WindowsDefaultTheme:
220
0
    case eIntID_DWMCompositor:
221
0
      aResult = 0;
222
0
      res = NS_ERROR_NOT_IMPLEMENTED;
223
0
      break;
224
0
    case eIntID_WindowsClassic:
225
0
    case eIntID_WindowsGlass:
226
0
      aResult = 0;
227
0
      res = NS_ERROR_FAILURE;
228
0
      break;
229
0
    case eIntID_TouchEnabled:
230
0
    case eIntID_MacGraphiteTheme:
231
0
    case eIntID_MacYosemiteTheme:
232
0
      aResult = 0;
233
0
      res = NS_ERROR_NOT_IMPLEMENTED;
234
0
      break;
235
0
    case eIntID_AlertNotificationOrigin:
236
0
      aResult = NS_ALERT_TOP;
237
0
      break;
238
0
    case eIntID_ScrollToClick:
239
0
      aResult = 0;
240
0
      break;
241
0
    case eIntID_IMERawInputUnderlineStyle:
242
0
    case eIntID_IMESelectedRawTextUnderlineStyle:
243
0
    case eIntID_IMEConvertedTextUnderlineStyle:
244
0
    case eIntID_IMESelectedConvertedTextUnderline:
245
0
      aResult = NS_STYLE_TEXT_DECORATION_STYLE_SOLID;
246
0
      break;
247
0
    case eIntID_SpellCheckerUnderlineStyle:
248
0
      aResult = NS_STYLE_TEXT_DECORATION_STYLE_DOTTED;
249
0
      break;
250
0
    case eIntID_MenuBarDrag:
251
0
      aResult = 0;
252
0
      break;
253
0
    case eIntID_WindowsThemeIdentifier:
254
0
    case eIntID_OperatingSystemVersionIdentifier:
255
0
      aResult = 0;
256
0
      res = NS_ERROR_NOT_IMPLEMENTED;
257
0
      break;
258
0
    case eIntID_ScrollbarButtonAutoRepeatBehavior:
259
0
      aResult = 0;
260
0
      break;
261
0
    case eIntID_TooltipDelay:
262
0
      aResult = 500;
263
0
      break;
264
0
    case eIntID_SwipeAnimationEnabled:
265
0
      aResult = 0;
266
0
      break;
267
0
    case eIntID_ScrollbarDisplayOnMouseMove:
268
0
      aResult = 0;
269
0
      break;
270
0
    case eIntID_ScrollbarFadeBeginDelay:
271
0
      aResult = 0;
272
0
      break;
273
0
    case eIntID_ScrollbarFadeDuration:
274
0
      aResult = 0;
275
0
      break;
276
0
    case eIntID_ContextMenuOffsetVertical:
277
0
      aResult = -6;
278
0
      break;
279
0
    case eIntID_ContextMenuOffsetHorizontal:
280
0
      aResult = 1;
281
0
      break;
282
0
    case eIntID_GTKCSDAvailable:
283
0
      aResult = 0;
284
0
      break;
285
0
    case eIntID_GTKCSDMinimizeButton:
286
0
      aResult = 0;
287
0
      break;
288
0
    case eIntID_GTKCSDMaximizeButton:
289
0
      aResult = 0;
290
0
      break;
291
0
    case eIntID_GTKCSDCloseButton:
292
0
      aResult = 1;
293
0
      break;
294
0
    default:
295
0
      NS_WARNING("HeadlessLookAndFeel::GetIntImpl called with an unrecognized aID");
296
0
      aResult = 0;
297
0
      res = NS_ERROR_FAILURE;
298
0
      break;
299
0
  }
300
0
  return res;
301
0
}
302
303
nsresult
304
HeadlessLookAndFeel::GetFloatImpl(FloatID aID, float &aResult)
305
0
{
306
0
  nsresult res = nsXPLookAndFeel::GetFloatImpl(aID, aResult);
307
0
  if (NS_SUCCEEDED(res))
308
0
    return res;
309
0
  res = NS_OK;
310
0
311
0
  // Hardcoded values for GTK.
312
0
  switch (aID) {
313
0
    case eFloatID_IMEUnderlineRelativeSize:
314
0
      aResult = 1.0f;
315
0
      break;
316
0
    case eFloatID_SpellCheckerUnderlineRelativeSize:
317
0
      aResult = 1.0f;
318
0
      break;
319
0
    case eFloatID_CaretAspectRatio:
320
0
      // Intentionally failing to quietly indicate lack of support.
321
0
      aResult = -1.0;
322
0
      res = NS_ERROR_FAILURE;
323
0
      break;
324
0
    default:
325
0
      NS_WARNING("HeadlessLookAndFeel::GetFloatImpl called with an unrecognized aID");
326
0
      aResult = -1.0;
327
0
      res = NS_ERROR_FAILURE;
328
0
      break;
329
0
  }
330
0
331
0
  return res;
332
0
}
333
334
bool
335
HeadlessLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
336
               gfxFontStyle& aFontStyle,
337
               float aDevPixPerCSSPixel)
338
0
{
339
0
  // Default to san-serif for everything.
340
0
  aFontStyle.style      = FontSlantStyle::Normal();
341
0
  aFontStyle.weight     = FontWeight::Normal();
342
0
  aFontStyle.stretch    = FontStretch::Normal();
343
0
  aFontStyle.size       = 14 * aDevPixPerCSSPixel;
344
0
  aFontStyle.systemFont = true;
345
0
346
0
  aFontName.AssignLiteral("sans-serif");
347
0
  return true;
348
0
}
349
350
char16_t
351
HeadlessLookAndFeel::GetPasswordCharacterImpl()
352
0
{
353
0
  return UNICODE_BULLET;
354
0
}
355
356
void
357
HeadlessLookAndFeel::RefreshImpl()
358
0
{
359
0
  nsXPLookAndFeel::RefreshImpl();
360
0
}
361
362
bool
363
0
HeadlessLookAndFeel::GetEchoPasswordImpl() {
364
0
  return false;
365
0
}
366
367
} // namespace widget
368
} // namespace mozilla