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 namespace mozilla::widget {
12 
13 static const char16_t UNICODE_BULLET = 0x2022;
14 
15 HeadlessLookAndFeel::HeadlessLookAndFeel() = default;
16 
17 HeadlessLookAndFeel::~HeadlessLookAndFeel() = default;
18 
NativeGetColor(ColorID aID,ColorScheme aScheme,nscolor & aResult)19 nsresult HeadlessLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aScheme,
20                                              nscolor& aResult) {
21   aResult = GetStandinForNativeColor(aID, aScheme);
22   return NS_OK;
23 }
24 
NativeGetInt(IntID aID,int32_t & aResult)25 nsresult HeadlessLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) {
26   nsresult res = NS_OK;
27   // These values should be sane defaults for headless mode under GTK.
28   switch (aID) {
29     case IntID::CaretBlinkTime:
30       aResult = 567;
31       break;
32     case IntID::CaretWidth:
33       aResult = 1;
34       break;
35     case IntID::ShowCaretDuringSelection:
36       aResult = 0;
37       break;
38     case IntID::SelectTextfieldsOnKeyFocus:
39       aResult = 1;
40       break;
41     case IntID::SubmenuDelay:
42       aResult = 200;
43       break;
44     case IntID::MenusCanOverlapOSBar:
45       aResult = 0;
46       break;
47     case IntID::UseOverlayScrollbars:
48       aResult = 0;
49       break;
50     case IntID::AllowOverlayScrollbarsOverlap:
51       aResult = 0;
52       break;
53     case IntID::SkipNavigatingDisabledMenuItem:
54       aResult = 1;
55       break;
56     case IntID::DragThresholdX:
57     case IntID::DragThresholdY:
58       aResult = 4;
59       break;
60     case IntID::UseAccessibilityTheme:
61       aResult = 0;
62       break;
63     case IntID::ScrollArrowStyle:
64       aResult = eScrollArrow_None;
65       break;
66     case IntID::ScrollSliderStyle:
67       aResult = eScrollThumbStyle_Proportional;
68       break;
69     case IntID::ScrollButtonLeftMouseButtonAction:
70       aResult = 0;
71       return NS_OK;
72     case IntID::ScrollButtonMiddleMouseButtonAction:
73       aResult = 3;
74       return NS_OK;
75     case IntID::ScrollButtonRightMouseButtonAction:
76       aResult = 3;
77       return NS_OK;
78     case IntID::TreeOpenDelay:
79       aResult = 1000;
80       break;
81     case IntID::TreeCloseDelay:
82       aResult = 1000;
83       break;
84     case IntID::TreeLazyScrollDelay:
85       aResult = 150;
86       break;
87     case IntID::TreeScrollDelay:
88       aResult = 100;
89       break;
90     case IntID::TreeScrollLinesMax:
91       aResult = 3;
92       break;
93     case IntID::TabFocusModel:
94       aResult = nsIContent::eTabFocus_textControlsMask;
95       break;
96     case IntID::ChosenMenuItemsShouldBlink:
97       aResult = 1;
98       break;
99     case IntID::WindowsAccentColorInTitlebar:
100     case IntID::WindowsDefaultTheme:
101     case IntID::DWMCompositor:
102       aResult = 0;
103       res = NS_ERROR_NOT_IMPLEMENTED;
104       break;
105     case IntID::WindowsClassic:
106     case IntID::WindowsGlass:
107       aResult = 0;
108       res = NS_ERROR_FAILURE;
109       break;
110     case IntID::AlertNotificationOrigin:
111       aResult = NS_ALERT_TOP;
112       break;
113     case IntID::ScrollToClick:
114       aResult = 0;
115       break;
116     case IntID::IMERawInputUnderlineStyle:
117     case IntID::IMESelectedRawTextUnderlineStyle:
118     case IntID::IMEConvertedTextUnderlineStyle:
119     case IntID::IMESelectedConvertedTextUnderline:
120       aResult = NS_STYLE_TEXT_DECORATION_STYLE_SOLID;
121       break;
122     case IntID::SpellCheckerUnderlineStyle:
123       aResult = NS_STYLE_TEXT_DECORATION_STYLE_DOTTED;
124       break;
125     case IntID::MenuBarDrag:
126       aResult = 0;
127       break;
128     case IntID::ScrollbarButtonAutoRepeatBehavior:
129       aResult = 0;
130       break;
131     case IntID::TooltipDelay:
132       aResult = 500;
133       break;
134     case IntID::SwipeAnimationEnabled:
135       aResult = 0;
136       break;
137     case IntID::ScrollbarDisplayOnMouseMove:
138       aResult = 0;
139       break;
140     case IntID::ScrollbarFadeBeginDelay:
141       aResult = 0;
142       break;
143     case IntID::ScrollbarFadeDuration:
144       aResult = 0;
145       break;
146     case IntID::ContextMenuOffsetVertical:
147       aResult = -6;
148       break;
149     case IntID::ContextMenuOffsetHorizontal:
150       aResult = 1;
151       break;
152     case IntID::GTKCSDAvailable:
153       aResult = 0;
154       break;
155     case IntID::GTKCSDMinimizeButton:
156       aResult = 0;
157       break;
158     case IntID::GTKCSDMaximizeButton:
159       aResult = 0;
160       break;
161     case IntID::GTKCSDCloseButton:
162       aResult = 1;
163       break;
164     case IntID::GTKCSDReversedPlacement:
165       aResult = 0;
166       break;
167     case IntID::SystemUsesDarkTheme:
168       aResult = 0;
169       break;
170     case IntID::PrefersReducedMotion:
171       aResult = 0;
172       break;
173     case IntID::PrimaryPointerCapabilities:
174       aResult = 0;
175       break;
176     case IntID::AllPointerCapabilities:
177       aResult = 0;
178       break;
179     default:
180       aResult = 0;
181       res = NS_ERROR_FAILURE;
182       break;
183   }
184   return res;
185 }
186 
NativeGetFloat(FloatID aID,float & aResult)187 nsresult HeadlessLookAndFeel::NativeGetFloat(FloatID aID, float& aResult) {
188   nsresult res = NS_OK;
189 
190   // Hardcoded values for GTK.
191   switch (aID) {
192     case FloatID::IMEUnderlineRelativeSize:
193       aResult = 1.0f;
194       break;
195     case FloatID::SpellCheckerUnderlineRelativeSize:
196       aResult = 1.0f;
197       break;
198     case FloatID::CaretAspectRatio:
199       // Intentionally failing to quietly indicate lack of support.
200       aResult = -1.0;
201       res = NS_ERROR_FAILURE;
202       break;
203     default:
204       aResult = -1.0;
205       res = NS_ERROR_FAILURE;
206       break;
207   }
208 
209   return res;
210 }
211 
NativeGetFont(FontID aID,nsString & aFontName,gfxFontStyle & aFontStyle)212 bool HeadlessLookAndFeel::NativeGetFont(FontID aID, nsString& aFontName,
213                                         gfxFontStyle& aFontStyle) {
214   // Default to san-serif for everything.
215   aFontStyle.style = FontSlantStyle::Normal();
216   aFontStyle.weight = FontWeight::Normal();
217   aFontStyle.stretch = FontStretch::Normal();
218   aFontStyle.size = 14;
219   aFontStyle.systemFont = true;
220 
221   aFontName.AssignLiteral("sans-serif");
222   return true;
223 }
224 
GetPasswordCharacterImpl()225 char16_t HeadlessLookAndFeel::GetPasswordCharacterImpl() {
226   return UNICODE_BULLET;
227 }
228 
229 }  // namespace mozilla::widget
230