Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/widget/headless/HeadlessThemeGTK.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; 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/. */
5
6
#include "HeadlessThemeGTK.h"
7
8
#include "mozilla/StaticPrefs.h"
9
#include "nsStyleConsts.h"
10
#include "nsIFrame.h"
11
12
13
namespace mozilla {
14
namespace widget {
15
16
NS_IMPL_ISUPPORTS_INHERITED(HeadlessThemeGTK, nsNativeTheme, nsITheme)
17
18
NS_IMETHODIMP
19
HeadlessThemeGTK::DrawWidgetBackground(gfxContext* aContext,
20
                                       nsIFrame* aFrame,
21
                                       WidgetType aWidgetType,
22
                                       const nsRect& aRect,
23
                                       const nsRect& aDirtyRect)
24
0
{
25
0
  return NS_OK;
26
0
}
27
28
LayoutDeviceIntMargin
29
HeadlessThemeGTK::GetWidgetBorder(nsDeviceContext* aContext, nsIFrame* aFrame,
30
                                  WidgetType aWidgetType)
31
0
{
32
0
  if (aWidgetType == StyleAppearance::MenulistButton &&
33
0
      StaticPrefs::layout_css_webkit_appearance_enabled()) {
34
0
    aWidgetType = StyleAppearance::Menulist;
35
0
  }
36
0
37
0
  LayoutDeviceIntMargin result;
38
0
  // The following values are generated from the Ubuntu GTK theme.
39
0
  switch (aWidgetType) {
40
0
    case StyleAppearance::Button:
41
0
    case StyleAppearance::Toolbarbutton:
42
0
      result.top = 6;
43
0
      result.right = 7;
44
0
      result.bottom = 6;
45
0
      result.left = 7;
46
0
      break;
47
0
    case StyleAppearance::FocusOutline:
48
0
    case StyleAppearance::NumberInput:
49
0
    case StyleAppearance::Textfield:
50
0
      result.top = 5;
51
0
      result.right = 7;
52
0
      result.bottom = 5;
53
0
      result.left = 7;
54
0
      break;
55
0
    case StyleAppearance::Statusbarpanel:
56
0
    case StyleAppearance::Resizerpanel:
57
0
    case StyleAppearance::Listbox:
58
0
    case StyleAppearance::Treeview:
59
0
    case StyleAppearance::Treeheadersortarrow:
60
0
    case StyleAppearance::Progressbar:
61
0
    case StyleAppearance::ProgressbarVertical:
62
0
    case StyleAppearance::SpinnerUpbutton:
63
0
    case StyleAppearance::SpinnerDownbutton:
64
0
    case StyleAppearance::SpinnerTextfield:
65
0
    case StyleAppearance::TextfieldMultiline:
66
0
    case StyleAppearance::Menupopup:
67
0
    case StyleAppearance::MozGtkInfoBar:
68
0
      result.top = 1;
69
0
      result.right = 1;
70
0
      result.bottom = 1;
71
0
      result.left = 1;
72
0
      break;
73
0
    case StyleAppearance::Treeheadercell:
74
0
      result.top = 5;
75
0
      result.right = 7;
76
0
      result.bottom = 6;
77
0
      result.left = 6;
78
0
      break;
79
0
    case StyleAppearance::Tab:
80
0
      result.top = 4;
81
0
      result.right = 7;
82
0
      result.bottom = 2;
83
0
      result.left = 7;
84
0
      break;
85
0
    case StyleAppearance::Tooltip:
86
0
      result.top = 6;
87
0
      result.right = 6;
88
0
      result.bottom = 6;
89
0
      result.left = 6;
90
0
      break;
91
0
    case StyleAppearance::Menulist:
92
0
      result.top = 6;
93
0
      result.right = 22;
94
0
      result.bottom = 6;
95
0
      result.left = 7;
96
0
      break;
97
0
    case StyleAppearance::MenulistButton:
98
0
    case StyleAppearance::MozMenulistButton:
99
0
      result.top = 1;
100
0
      result.right = 1;
101
0
      result.bottom = 1;
102
0
      result.left = 0;
103
0
      break;
104
0
    case StyleAppearance::MenulistTextfield:
105
0
      result.top = 1;
106
0
      result.right = 0;
107
0
      result.bottom = 1;
108
0
      result.left = 1;
109
0
      break;
110
0
    case StyleAppearance::Menuitem:
111
0
    case StyleAppearance::Checkmenuitem:
112
0
    case StyleAppearance::Radiomenuitem:
113
0
      if (IsRegularMenuItem(aFrame)) {
114
0
        break;
115
0
      }
116
0
      result.top = 3;
117
0
      result.right = 5;
118
0
      result.bottom = 3;
119
0
      result.left = 5;
120
0
      break;
121
0
    default:
122
0
      break;
123
0
  }
124
0
  return result;
125
0
}
126
127
bool
128
HeadlessThemeGTK::GetWidgetPadding(nsDeviceContext* aContext,
129
                                   nsIFrame* aFrame, WidgetType aWidgetType,
130
                                   LayoutDeviceIntMargin* aResult)
131
0
{
132
0
  if (aWidgetType == StyleAppearance::MenulistButton &&
133
0
      StaticPrefs::layout_css_webkit_appearance_enabled()) {
134
0
    aWidgetType = StyleAppearance::Menulist;
135
0
  }
136
0
137
0
  // The following values are generated from the Ubuntu GTK theme.
138
0
  switch (aWidgetType) {
139
0
    case StyleAppearance::Radio:
140
0
    case StyleAppearance::Checkbox:
141
0
    case StyleAppearance::Toolbarbutton:
142
0
    case StyleAppearance::Dualbutton:
143
0
    case StyleAppearance::ToolbarbuttonDropdown:
144
0
    case StyleAppearance::ButtonArrowUp:
145
0
    case StyleAppearance::ButtonArrowDown:
146
0
    case StyleAppearance::ButtonArrowNext:
147
0
    case StyleAppearance::ButtonArrowPrevious:
148
0
    case StyleAppearance::TabScrollArrowBack:
149
0
    case StyleAppearance::TabScrollArrowForward:
150
0
    case StyleAppearance::MenulistButton:
151
0
    case StyleAppearance::MozMenulistButton:
152
0
    case StyleAppearance::RangeThumb:
153
0
    case StyleAppearance::ButtonFocus:
154
0
      aResult->top = 0;
155
0
      aResult->right = 0;
156
0
      aResult->bottom = 0;
157
0
      aResult->left = 0;
158
0
      return true;
159
0
    case StyleAppearance::Menuitem:
160
0
    case StyleAppearance::Checkmenuitem:
161
0
    case StyleAppearance::Radiomenuitem:
162
0
      if (!IsRegularMenuItem(aFrame)) {
163
0
        return false;
164
0
      }
165
0
      aResult->top = 3;
166
0
      aResult->right = 5;
167
0
      aResult->bottom = 3;
168
0
      aResult->left = 5;
169
0
      return true;
170
0
    default:
171
0
      break;
172
0
  }
173
0
  return false;
174
0
}
175
176
177
NS_IMETHODIMP
178
HeadlessThemeGTK::GetMinimumWidgetSize(nsPresContext* aPresContext,
179
                                       nsIFrame* aFrame, WidgetType aWidgetType,
180
                                       LayoutDeviceIntSize* aResult,
181
                                       bool* aIsOverridable)
182
0
{
183
0
  aResult->width = aResult->height = 0;
184
0
  *aIsOverridable = true;
185
0
186
0
  if (aWidgetType == StyleAppearance::MenulistButton &&
187
0
      StaticPrefs::layout_css_webkit_appearance_enabled()) {
188
0
    aWidgetType = StyleAppearance::Menulist;
189
0
  }
190
0
191
0
  // The following values are generated from the Ubuntu GTK theme.
192
0
  switch (aWidgetType) {
193
0
    case StyleAppearance::Splitter:
194
0
      if (IsHorizontal(aFrame)) {
195
0
        aResult->width = 6;
196
0
        aResult->height = 0;
197
0
      } else {
198
0
        aResult->width = 0;
199
0
        aResult->height = 6;
200
0
      }
201
0
      *aIsOverridable = false;
202
0
      break;
203
0
    case StyleAppearance::Button:
204
0
    case StyleAppearance::Toolbarbutton:
205
0
      aResult->width = 14;
206
0
      aResult->height = 12;
207
0
      break;
208
0
    case StyleAppearance::Radio:
209
0
    case StyleAppearance::Checkbox:
210
0
      aResult->width = 18;
211
0
      aResult->height = 18;
212
0
      break;
213
0
    case StyleAppearance::ToolbarbuttonDropdown:
214
0
    case StyleAppearance::ButtonArrowUp:
215
0
    case StyleAppearance::ButtonArrowDown:
216
0
    case StyleAppearance::ButtonArrowNext:
217
0
    case StyleAppearance::ButtonArrowPrevious:
218
0
    case StyleAppearance::Resizer:
219
0
      aResult->width = 15;
220
0
      aResult->height = 15;
221
0
      *aIsOverridable = false;
222
0
      break;
223
0
    case StyleAppearance::Separator:
224
0
      aResult->width = 12;
225
0
      aResult->height = 0;
226
0
      break;
227
0
    case StyleAppearance::Treetwisty:
228
0
    case StyleAppearance::Treetwistyopen:
229
0
      aResult->width = 8;
230
0
      aResult->height = 8;
231
0
      *aIsOverridable = false;
232
0
      break;
233
0
    case StyleAppearance::Treeheadercell:
234
0
      aResult->width = 13;
235
0
      aResult->height = 11;
236
0
      break;
237
0
    case StyleAppearance::Treeheadersortarrow:
238
0
    case StyleAppearance::SpinnerUpbutton:
239
0
    case StyleAppearance::SpinnerDownbutton:
240
0
      aResult->width = 14;
241
0
      aResult->height = 13;
242
0
      break;
243
0
    case StyleAppearance::TabScrollArrowBack:
244
0
    case StyleAppearance::TabScrollArrowForward:
245
0
      aResult->width = 16;
246
0
      aResult->height = 16;
247
0
      *aIsOverridable = false;
248
0
      break;
249
0
    case StyleAppearance::InnerSpinButton:
250
0
    case StyleAppearance::Spinner:
251
0
      aResult->width = 14;
252
0
      aResult->height = 26;
253
0
      break;
254
0
    case StyleAppearance::NumberInput:
255
0
    case StyleAppearance::Textfield:
256
0
      aResult->width = 0;
257
0
      aResult->height = 12;
258
0
      break;
259
0
    case StyleAppearance::ScrollbarHorizontal:
260
0
      aResult->width = 31;
261
0
      aResult->height = 10;
262
0
      break;
263
0
    case StyleAppearance::ScrollbarVertical:
264
0
      aResult->width = 10;
265
0
      aResult->height = 31;
266
0
      break;
267
0
    case StyleAppearance::ScrollbarbuttonUp:
268
0
    case StyleAppearance::ScrollbarbuttonDown:
269
0
      aResult->width = 10;
270
0
      aResult->height = 13;
271
0
      *aIsOverridable = false;
272
0
      break;
273
0
    case StyleAppearance::ScrollbarbuttonLeft:
274
0
    case StyleAppearance::ScrollbarbuttonRight:
275
0
      aResult->width = 13;
276
0
      aResult->height = 10;
277
0
      *aIsOverridable = false;
278
0
      break;
279
0
    case StyleAppearance::ScrollbarthumbHorizontal:
280
0
      aResult->width = 31;
281
0
      aResult->height = 10;
282
0
      *aIsOverridable = false;
283
0
      break;
284
0
    case StyleAppearance::ScrollbarthumbVertical:
285
0
      aResult->width = 10;
286
0
      aResult->height = 31;
287
0
      *aIsOverridable = false;
288
0
      break;
289
0
    case StyleAppearance::Menulist:
290
0
      aResult->width = 44;
291
0
      aResult->height = 27;
292
0
      break;
293
0
    case StyleAppearance::MenulistButton:
294
0
    case StyleAppearance::MozMenulistButton:
295
0
      aResult->width = 29;
296
0
      aResult->height = 28;
297
0
      *aIsOverridable = false;
298
0
      break;
299
0
    case StyleAppearance::ScalethumbHorizontal:
300
0
    case StyleAppearance::RangeThumb:
301
0
      aResult->width = 14;
302
0
      aResult->height = 18;
303
0
      *aIsOverridable = false;
304
0
      break;
305
0
    case StyleAppearance::ScalethumbVertical:
306
0
      aResult->width = 18;
307
0
      aResult->height = 13;
308
0
      *aIsOverridable = false;
309
0
      break;
310
0
    case StyleAppearance::Range:
311
0
      aResult->width = 14;
312
0
      aResult->height = 18;
313
0
      break;
314
0
    case StyleAppearance::Menuseparator:
315
0
      aResult->width = 0;
316
0
      aResult->height = 8;
317
0
      *aIsOverridable = false;
318
0
      break;
319
0
    default:
320
0
      break;
321
0
  }
322
0
  return NS_OK;
323
0
}
324
325
NS_IMETHODIMP
326
HeadlessThemeGTK::WidgetStateChanged(nsIFrame* aFrame, WidgetType aWidgetType,
327
                                     nsAtom* aAttribute, bool* aShouldRepaint,
328
                                     const nsAttrValue* aOldValue)
329
0
{
330
0
  return NS_OK;
331
0
}
332
333
NS_IMETHODIMP
334
HeadlessThemeGTK::ThemeChanged()
335
0
{
336
0
  return NS_OK;
337
0
}
338
339
static bool IsFrameContentNodeInNamespace(nsIFrame *aFrame, uint32_t aNamespace)
340
0
{
341
0
  nsIContent *content = aFrame ? aFrame->GetContent() : nullptr;
342
0
  if (!content)
343
0
    return false;
344
0
  return content->IsInNamespace(aNamespace);
345
0
}
346
347
NS_IMETHODIMP_(bool)
348
HeadlessThemeGTK::ThemeSupportsWidget(nsPresContext* aPresContext,
349
                                      nsIFrame* aFrame,
350
                                      WidgetType aWidgetType)
351
0
{
352
0
  if (aWidgetType == StyleAppearance::MenulistButton &&
353
0
      StaticPrefs::layout_css_webkit_appearance_enabled()) {
354
0
    aWidgetType = StyleAppearance::Menulist;
355
0
  }
356
0
357
0
  switch (aWidgetType) {
358
0
    case StyleAppearance::Button:
359
0
    case StyleAppearance::Radio:
360
0
    case StyleAppearance::Checkbox:
361
0
    case StyleAppearance::FocusOutline:
362
0
    case StyleAppearance::Toolbox:
363
0
    case StyleAppearance::Toolbar:
364
0
    case StyleAppearance::Toolbarbutton:
365
0
    case StyleAppearance::Dualbutton:
366
0
    case StyleAppearance::ToolbarbuttonDropdown:
367
0
    case StyleAppearance::ButtonArrowUp:
368
0
    case StyleAppearance::ButtonArrowDown:
369
0
    case StyleAppearance::ButtonArrowNext:
370
0
    case StyleAppearance::ButtonArrowPrevious:
371
0
    case StyleAppearance::Separator:
372
0
    case StyleAppearance::Toolbargripper:
373
0
    case StyleAppearance::Splitter:
374
0
    case StyleAppearance::Statusbar:
375
0
    case StyleAppearance::Statusbarpanel:
376
0
    case StyleAppearance::Resizerpanel:
377
0
    case StyleAppearance::Resizer:
378
0
    case StyleAppearance::Listbox:
379
0
    case StyleAppearance::Treeview:
380
0
    case StyleAppearance::Treetwisty:
381
0
    case StyleAppearance::Treeheadercell:
382
0
    case StyleAppearance::Treeheadersortarrow:
383
0
    case StyleAppearance::Treetwistyopen:
384
0
    case StyleAppearance::Progressbar:
385
0
    case StyleAppearance::Progresschunk:
386
0
    case StyleAppearance::ProgressbarVertical:
387
0
    case StyleAppearance::ProgresschunkVertical:
388
0
    case StyleAppearance::Tab:
389
0
    case StyleAppearance::Tabpanels:
390
0
    case StyleAppearance::TabScrollArrowBack:
391
0
    case StyleAppearance::TabScrollArrowForward:
392
0
    case StyleAppearance::Tooltip:
393
0
    case StyleAppearance::InnerSpinButton:
394
0
    case StyleAppearance::Spinner:
395
0
    case StyleAppearance::SpinnerUpbutton:
396
0
    case StyleAppearance::SpinnerDownbutton:
397
0
    case StyleAppearance::SpinnerTextfield:
398
0
    case StyleAppearance::NumberInput:
399
0
    case StyleAppearance::ScrollbarHorizontal:
400
0
    case StyleAppearance::ScrollbarVertical:
401
0
    case StyleAppearance::ScrollbarbuttonUp:
402
0
    case StyleAppearance::ScrollbarbuttonDown:
403
0
    case StyleAppearance::ScrollbarbuttonLeft:
404
0
    case StyleAppearance::ScrollbarbuttonRight:
405
0
    case StyleAppearance::ScrollbartrackHorizontal:
406
0
    case StyleAppearance::ScrollbartrackVertical:
407
0
    case StyleAppearance::ScrollbarthumbHorizontal:
408
0
    case StyleAppearance::ScrollbarthumbVertical:
409
0
    case StyleAppearance::Textfield:
410
0
    case StyleAppearance::TextfieldMultiline:
411
0
    case StyleAppearance::Menulist:
412
0
    case StyleAppearance::MenulistText:
413
0
    case StyleAppearance::MenulistTextfield:
414
0
    case StyleAppearance::ScaleHorizontal:
415
0
    case StyleAppearance::ScaleVertical:
416
0
    case StyleAppearance::ScalethumbHorizontal:
417
0
    case StyleAppearance::ScalethumbVertical:
418
0
    case StyleAppearance::Range:
419
0
    case StyleAppearance::RangeThumb:
420
0
    case StyleAppearance::CheckboxContainer:
421
0
    case StyleAppearance::RadioContainer:
422
0
    case StyleAppearance::CheckboxLabel:
423
0
    case StyleAppearance::RadioLabel:
424
0
    case StyleAppearance::ButtonFocus:
425
0
    case StyleAppearance::Window:
426
0
    case StyleAppearance::Dialog:
427
0
    case StyleAppearance::Menubar:
428
0
    case StyleAppearance::Menupopup:
429
0
    case StyleAppearance::Menuitem:
430
0
    case StyleAppearance::Checkmenuitem:
431
0
    case StyleAppearance::Radiomenuitem:
432
0
    case StyleAppearance::Menuseparator:
433
0
    case StyleAppearance::Menuarrow:
434
0
    case StyleAppearance::MozGtkInfoBar:
435
0
      return !IsWidgetStyled(aPresContext, aFrame, aWidgetType);
436
0
    case StyleAppearance::MenulistButton:
437
0
    case StyleAppearance::MozMenulistButton:
438
0
      return (!aFrame || IsFrameContentNodeInNamespace(aFrame, kNameSpaceID_XUL)) &&
439
0
              !IsWidgetStyled(aPresContext, aFrame, aWidgetType);
440
0
    default:
441
0
      break;
442
0
  }
443
0
  return false;
444
0
}
445
446
NS_IMETHODIMP_(bool)
447
HeadlessThemeGTK::WidgetIsContainer(WidgetType aWidgetType)
448
0
{
449
0
  if (aWidgetType == StyleAppearance::MenulistButton &&
450
0
      StaticPrefs::layout_css_webkit_appearance_enabled()) {
451
0
    aWidgetType = StyleAppearance::Menulist;
452
0
  }
453
0
454
0
    if (aWidgetType == StyleAppearance::MenulistButton ||
455
0
        aWidgetType == StyleAppearance::MozMenulistButton ||
456
0
        aWidgetType == StyleAppearance::Radio ||
457
0
        aWidgetType == StyleAppearance::RangeThumb ||
458
0
        aWidgetType == StyleAppearance::Checkbox ||
459
0
        aWidgetType == StyleAppearance::TabScrollArrowBack ||
460
0
        aWidgetType == StyleAppearance::TabScrollArrowForward ||
461
0
        aWidgetType == StyleAppearance::ButtonArrowUp ||
462
0
        aWidgetType == StyleAppearance::ButtonArrowDown ||
463
0
        aWidgetType == StyleAppearance::ButtonArrowNext ||
464
0
        aWidgetType == StyleAppearance::ButtonArrowPrevious) {
465
0
466
0
    return false;
467
0
  }
468
0
  return true;
469
0
}
470
471
bool
472
HeadlessThemeGTK::ThemeDrawsFocusForWidget(WidgetType aWidgetType)
473
0
{
474
0
   if (aWidgetType == StyleAppearance::Menulist ||
475
0
       aWidgetType == StyleAppearance::Button ||
476
0
       aWidgetType == StyleAppearance::Treeheadercell) {
477
0
    return true;
478
0
  }
479
0
  return false;
480
0
}
481
482
bool
483
HeadlessThemeGTK::ThemeNeedsComboboxDropmarker()
484
0
{
485
0
  return false;
486
0
}
487
488
489
} // namespace widget
490
} // namespace mozilla