widget/gonk/nsLookAndFeel.cpp

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

mercurial