widget/qt/nsLookAndFeel.cpp

branch
TOR_BUG_9701
changeset 10
ac0c01689b40
equal deleted inserted replaced
-1:000000000000 0:c671f2230ce8
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* Copyright 2012 Mozilla Foundation and Mozilla contributors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <QGuiApplication>
18 #include <QFont>
19 #include <QScreen>
20
21 #include "nsLookAndFeel.h"
22 #include "nsStyleConsts.h"
23 #include "gfxFont.h"
24 #include "gfxFontConstants.h"
25 #include "mozilla/gfx/2D.h"
26
27 static const char16_t UNICODE_BULLET = 0x2022;
28
29 nsLookAndFeel::nsLookAndFeel()
30 : nsXPLookAndFeel()
31 {
32 }
33
34 nsLookAndFeel::~nsLookAndFeel()
35 {
36 }
37
38 nsresult
39 nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
40 {
41 nsresult rv = NS_OK;
42
43 #define BASE_ACTIVE_COLOR NS_RGB(0xaa,0xaa,0xaa)
44 #define BASE_NORMAL_COLOR NS_RGB(0xff,0xff,0xff)
45 #define BASE_SELECTED_COLOR NS_RGB(0xaa,0xaa,0xaa)
46 #define BG_ACTIVE_COLOR NS_RGB(0xff,0xff,0xff)
47 #define BG_INSENSITIVE_COLOR NS_RGB(0xaa,0xaa,0xaa)
48 #define BG_NORMAL_COLOR NS_RGB(0xff,0xff,0xff)
49 #define BG_PRELIGHT_COLOR NS_RGB(0xee,0xee,0xee)
50 #define BG_SELECTED_COLOR NS_RGB(0x99,0x99,0x99)
51 #define DARK_NORMAL_COLOR NS_RGB(0x88,0x88,0x88)
52 #define FG_INSENSITIVE_COLOR NS_RGB(0x44,0x44,0x44)
53 #define FG_NORMAL_COLOR NS_RGB(0x00,0x00,0x00)
54 #define FG_PRELIGHT_COLOR NS_RGB(0x77,0x77,0x77)
55 #define FG_SELECTED_COLOR NS_RGB(0xaa,0xaa,0xaa)
56 #define LIGHT_NORMAL_COLOR NS_RGB(0xaa,0xaa,0xaa)
57 #define TEXT_ACTIVE_COLOR NS_RGB(0x99,0x99,0x99)
58 #define TEXT_NORMAL_COLOR NS_RGB(0x00,0x00,0x00)
59 #define TEXT_SELECTED_COLOR NS_RGB(0x00,0x00,0x00)
60
61 switch (aID) {
62 // These colors don't seem to be used for anything anymore in Mozilla
63 // (except here at least TextSelectBackground and TextSelectForeground)
64 // The CSS2 colors below are used.
65 case eColorID_WindowBackground:
66 aColor = BASE_NORMAL_COLOR;
67 break;
68 case eColorID_WindowForeground:
69 aColor = TEXT_NORMAL_COLOR;
70 break;
71 case eColorID_WidgetBackground:
72 aColor = BG_NORMAL_COLOR;
73 break;
74 case eColorID_WidgetForeground:
75 aColor = FG_NORMAL_COLOR;
76 break;
77 case eColorID_WidgetSelectBackground:
78 aColor = BG_SELECTED_COLOR;
79 break;
80 case eColorID_WidgetSelectForeground:
81 aColor = FG_SELECTED_COLOR;
82 break;
83 case eColorID_Widget3DHighlight:
84 aColor = NS_RGB(0xa0,0xa0,0xa0);
85 break;
86 case eColorID_Widget3DShadow:
87 aColor = NS_RGB(0x40,0x40,0x40);
88 break;
89 case eColorID_TextBackground:
90 // not used?
91 aColor = BASE_NORMAL_COLOR;
92 break;
93 case eColorID_TextForeground:
94 // not used?
95 aColor = TEXT_NORMAL_COLOR;
96 break;
97 case eColorID_TextSelectBackground:
98 case eColorID_IMESelectedRawTextBackground:
99 case eColorID_IMESelectedConvertedTextBackground:
100 // still used
101 aColor = BASE_SELECTED_COLOR;
102 break;
103 case eColorID_TextSelectForeground:
104 case eColorID_IMESelectedRawTextForeground:
105 case eColorID_IMESelectedConvertedTextForeground:
106 // still used
107 aColor = TEXT_SELECTED_COLOR;
108 break;
109 case eColorID_IMERawInputBackground:
110 case eColorID_IMEConvertedTextBackground:
111 aColor = NS_TRANSPARENT;
112 break;
113 case eColorID_IMERawInputForeground:
114 case eColorID_IMEConvertedTextForeground:
115 aColor = NS_SAME_AS_FOREGROUND_COLOR;
116 break;
117 case eColorID_IMERawInputUnderline:
118 case eColorID_IMEConvertedTextUnderline:
119 aColor = NS_SAME_AS_FOREGROUND_COLOR;
120 break;
121 case eColorID_IMESelectedRawTextUnderline:
122 case eColorID_IMESelectedConvertedTextUnderline:
123 aColor = NS_TRANSPARENT;
124 break;
125 case eColorID_SpellCheckerUnderline:
126 aColor = NS_RGB(0xff, 0, 0);
127 break;
128
129 // css2 http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
130 case eColorID_activeborder:
131 // active window border
132 aColor = BG_NORMAL_COLOR;
133 break;
134 case eColorID_activecaption:
135 // active window caption background
136 aColor = BG_NORMAL_COLOR;
137 break;
138 case eColorID_appworkspace:
139 // MDI background color
140 aColor = BG_NORMAL_COLOR;
141 break;
142 case eColorID_background:
143 // desktop background
144 aColor = BG_NORMAL_COLOR;
145 break;
146 case eColorID_captiontext:
147 // text in active window caption, size box, and scrollbar arrow box (!)
148 aColor = FG_NORMAL_COLOR;
149 break;
150 case eColorID_graytext:
151 // disabled text in windows, menus, etc.
152 aColor = FG_INSENSITIVE_COLOR;
153 break;
154 case eColorID_highlight:
155 // background of selected item
156 aColor = BASE_SELECTED_COLOR;
157 break;
158 case eColorID_highlighttext:
159 // text of selected item
160 aColor = TEXT_SELECTED_COLOR;
161 break;
162 case eColorID_inactiveborder:
163 // inactive window border
164 aColor = BG_NORMAL_COLOR;
165 break;
166 case eColorID_inactivecaption:
167 // inactive window caption
168 aColor = BG_INSENSITIVE_COLOR;
169 break;
170 case eColorID_inactivecaptiontext:
171 // text in inactive window caption
172 aColor = FG_INSENSITIVE_COLOR;
173 break;
174 case eColorID_infobackground:
175 // tooltip background color
176 aColor = BG_NORMAL_COLOR;
177 break;
178 case eColorID_infotext:
179 // tooltip text color
180 aColor = TEXT_NORMAL_COLOR;
181 break;
182 case eColorID_menu:
183 // menu background
184 aColor = BG_NORMAL_COLOR;
185 break;
186 case eColorID_menutext:
187 // menu text
188 aColor = TEXT_NORMAL_COLOR;
189 break;
190 case eColorID_scrollbar:
191 // scrollbar gray area
192 aColor = BG_ACTIVE_COLOR;
193 break;
194
195 case eColorID_threedface:
196 case eColorID_buttonface:
197 // 3-D face color
198 aColor = BG_NORMAL_COLOR;
199 break;
200
201 case eColorID_buttontext:
202 // text on push buttons
203 aColor = TEXT_NORMAL_COLOR;
204 break;
205
206 case eColorID_buttonhighlight:
207 // 3-D highlighted edge color
208 case eColorID_threedhighlight:
209 // 3-D highlighted outer edge color
210 aColor = LIGHT_NORMAL_COLOR;
211 break;
212
213 case eColorID_threedlightshadow:
214 // 3-D highlighted inner edge color
215 aColor = BG_NORMAL_COLOR;
216 break;
217
218 case eColorID_buttonshadow:
219 // 3-D shadow edge color
220 case eColorID_threedshadow:
221 // 3-D shadow inner edge color
222 aColor = DARK_NORMAL_COLOR;
223 break;
224
225 case eColorID_threeddarkshadow:
226 // 3-D shadow outer edge color
227 aColor = NS_RGB(0,0,0);
228 break;
229
230 case eColorID_window:
231 case eColorID_windowframe:
232 aColor = BG_NORMAL_COLOR;
233 break;
234
235 case eColorID_windowtext:
236 aColor = FG_NORMAL_COLOR;
237 break;
238
239 case eColorID__moz_eventreerow:
240 case eColorID__moz_field:
241 aColor = BASE_NORMAL_COLOR;
242 break;
243 case eColorID__moz_fieldtext:
244 aColor = TEXT_NORMAL_COLOR;
245 break;
246 case eColorID__moz_dialog:
247 aColor = BG_NORMAL_COLOR;
248 break;
249 case eColorID__moz_dialogtext:
250 aColor = FG_NORMAL_COLOR;
251 break;
252 case eColorID__moz_dragtargetzone:
253 aColor = BG_SELECTED_COLOR;
254 break;
255 case eColorID__moz_buttondefault:
256 // default button border color
257 aColor = NS_RGB(0,0,0);
258 break;
259 case eColorID__moz_buttonhoverface:
260 aColor = BG_PRELIGHT_COLOR;
261 break;
262 case eColorID__moz_buttonhovertext:
263 aColor = FG_PRELIGHT_COLOR;
264 break;
265 case eColorID__moz_cellhighlight:
266 case eColorID__moz_html_cellhighlight:
267 aColor = BASE_ACTIVE_COLOR;
268 break;
269 case eColorID__moz_cellhighlighttext:
270 case eColorID__moz_html_cellhighlighttext:
271 aColor = TEXT_ACTIVE_COLOR;
272 break;
273 case eColorID__moz_menuhover:
274 aColor = BG_PRELIGHT_COLOR;
275 break;
276 case eColorID__moz_menuhovertext:
277 aColor = FG_PRELIGHT_COLOR;
278 break;
279 case eColorID__moz_oddtreerow:
280 aColor = NS_TRANSPARENT;
281 break;
282 case eColorID__moz_nativehyperlinktext:
283 aColor = NS_SAME_AS_FOREGROUND_COLOR;
284 break;
285 case eColorID__moz_comboboxtext:
286 aColor = TEXT_NORMAL_COLOR;
287 break;
288 case eColorID__moz_combobox:
289 aColor = BG_NORMAL_COLOR;
290 break;
291 case eColorID__moz_menubartext:
292 aColor = TEXT_NORMAL_COLOR;
293 break;
294 case eColorID__moz_menubarhovertext:
295 aColor = FG_PRELIGHT_COLOR;
296 break;
297 default:
298 /* default color is BLACK */
299 aColor = 0;
300 rv = NS_ERROR_FAILURE;
301 break;
302 }
303
304 return rv;
305 }
306
307 nsresult
308 nsLookAndFeel::GetIntImpl(IntID aID, int32_t &aResult)
309 {
310 nsresult rv = nsXPLookAndFeel::GetIntImpl(aID, aResult);
311 if (NS_SUCCEEDED(rv))
312 return rv;
313
314 rv = NS_OK;
315
316 switch (aID) {
317 case eIntID_CaretBlinkTime:
318 aResult = 500;
319 break;
320
321 case eIntID_CaretWidth:
322 aResult = 1;
323 break;
324
325 case eIntID_ShowCaretDuringSelection:
326 aResult = 0;
327 break;
328
329 case eIntID_SelectTextfieldsOnKeyFocus:
330 // Select textfield content when focused by kbd
331 // used by EventStateManager::sTextfieldSelectModel
332 aResult = 1;
333 break;
334
335 case eIntID_SubmenuDelay:
336 aResult = 200;
337 break;
338
339 case eIntID_TooltipDelay:
340 aResult = 500;
341 break;
342
343 case eIntID_MenusCanOverlapOSBar:
344 // we want XUL popups to be able to overlap the task bar.
345 aResult = 1;
346 break;
347
348 case eIntID_ScrollArrowStyle:
349 aResult = eScrollArrowStyle_Single;
350 break;
351
352 case eIntID_ScrollSliderStyle:
353 aResult = eScrollThumbStyle_Proportional;
354 break;
355
356 case eIntID_TouchEnabled:
357 aResult = 1;
358 break;
359
360 case eIntID_WindowsDefaultTheme:
361 case eIntID_WindowsThemeIdentifier:
362 case eIntID_OperatingSystemVersionIdentifier:
363 aResult = 0;
364 rv = NS_ERROR_NOT_IMPLEMENTED;
365 break;
366
367 case eIntID_IMERawInputUnderlineStyle:
368 case eIntID_IMEConvertedTextUnderlineStyle:
369 aResult = NS_STYLE_TEXT_DECORATION_STYLE_SOLID;
370 break;
371
372 case eIntID_IMESelectedRawTextUnderlineStyle:
373 case eIntID_IMESelectedConvertedTextUnderline:
374 aResult = NS_STYLE_TEXT_DECORATION_STYLE_NONE;
375 break;
376
377 case eIntID_SpellCheckerUnderlineStyle:
378 aResult = NS_STYLE_TEXT_DECORATION_STYLE_WAVY;
379 break;
380
381 case eIntID_ScrollbarButtonAutoRepeatBehavior:
382 aResult = 0;
383 break;
384
385 default:
386 aResult = 0;
387 rv = NS_ERROR_FAILURE;
388 }
389
390 return rv;
391 }
392
393 nsresult
394 nsLookAndFeel::GetFloatImpl(FloatID aID, float &aResult)
395 {
396 nsresult res = nsXPLookAndFeel::GetFloatImpl(aID, aResult);
397 if (NS_SUCCEEDED(res))
398 return res;
399 res = NS_OK;
400
401 switch (aID) {
402 case eFloatID_IMEUnderlineRelativeSize:
403 aResult = 1.0f;
404 break;
405 case eFloatID_SpellCheckerUnderlineRelativeSize:
406 aResult = 1.0f;
407 break;
408 default:
409 aResult = -1.0;
410 res = NS_ERROR_FAILURE;
411 }
412 return res;
413 }
414
415 /*virtual*/
416 bool
417 nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
418 gfxFontStyle& aFontStyle,
419 float aDevPixPerCSSPixel)
420 {
421 QFont qFont = QGuiApplication::font();
422
423 NS_NAMED_LITERAL_STRING(quote, "\"");
424 nsString family((char16_t*)qFont.family().data());
425 aFontName = quote + family + quote;
426
427 aFontStyle.systemFont = true;
428 aFontStyle.style = qFont.style();
429 aFontStyle.weight = qFont.weight();
430 aFontStyle.stretch = qFont.stretch();
431 // use pixel size directly if it is set, otherwise compute from point size
432 if (qFont.pixelSize() != -1) {
433 aFontStyle.size = qFont.pixelSize();
434 } else {
435 aFontStyle.size = qFont.pointSizeF() * qApp->primaryScreen()->logicalDotsPerInch() / 72.0f;
436 }
437
438 return true;
439 }
440
441 /*virtual*/
442 bool
443 nsLookAndFeel::GetEchoPasswordImpl() {
444 return true;
445 }
446
447 /*virtual*/
448 uint32_t
449 nsLookAndFeel::GetPasswordMaskDelayImpl()
450 {
451 // Same value on Android framework
452 return 1500;
453 }
454
455 /* virtual */
456 char16_t
457 nsLookAndFeel::GetPasswordCharacterImpl()
458 {
459 return UNICODE_BULLET;
460 }

mercurial