|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
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 "nsLookAndFeel.h" |
|
7 #include "nsCocoaFeatures.h" |
|
8 #include "nsIServiceManager.h" |
|
9 #include "nsNativeThemeColors.h" |
|
10 #include "nsStyleConsts.h" |
|
11 #include "nsCocoaFeatures.h" |
|
12 #include "gfxFont.h" |
|
13 #include "gfxFontConstants.h" |
|
14 #include "mozilla/gfx/2D.h" |
|
15 |
|
16 #import <Cocoa/Cocoa.h> |
|
17 |
|
18 // This must be included last: |
|
19 #include "nsObjCExceptions.h" |
|
20 |
|
21 enum { |
|
22 mozNSScrollerStyleLegacy = 0, |
|
23 mozNSScrollerStyleOverlay = 1 |
|
24 }; |
|
25 typedef NSInteger mozNSScrollerStyle; |
|
26 |
|
27 @interface NSScroller(AvailableSinceLion) |
|
28 + (mozNSScrollerStyle)preferredScrollerStyle; |
|
29 @end |
|
30 |
|
31 nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel() |
|
32 { |
|
33 } |
|
34 |
|
35 nsLookAndFeel::~nsLookAndFeel() |
|
36 { |
|
37 } |
|
38 |
|
39 static nscolor GetColorFromNSColor(NSColor* aColor) |
|
40 { |
|
41 NSColor* deviceColor = [aColor colorUsingColorSpaceName:NSDeviceRGBColorSpace]; |
|
42 return NS_RGB((unsigned int)([deviceColor redComponent] * 255.0), |
|
43 (unsigned int)([deviceColor greenComponent] * 255.0), |
|
44 (unsigned int)([deviceColor blueComponent] * 255.0)); |
|
45 } |
|
46 |
|
47 nsresult |
|
48 nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor) |
|
49 { |
|
50 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; |
|
51 |
|
52 nsresult res = NS_OK; |
|
53 |
|
54 switch (aID) { |
|
55 case eColorID_WindowBackground: |
|
56 aColor = NS_RGB(0xff,0xff,0xff); |
|
57 break; |
|
58 case eColorID_WindowForeground: |
|
59 aColor = NS_RGB(0x00,0x00,0x00); |
|
60 break; |
|
61 case eColorID_WidgetBackground: |
|
62 aColor = NS_RGB(0xdd,0xdd,0xdd); |
|
63 break; |
|
64 case eColorID_WidgetForeground: |
|
65 aColor = NS_RGB(0x00,0x00,0x00); |
|
66 break; |
|
67 case eColorID_WidgetSelectBackground: |
|
68 aColor = NS_RGB(0x80,0x80,0x80); |
|
69 break; |
|
70 case eColorID_WidgetSelectForeground: |
|
71 aColor = NS_RGB(0x00,0x00,0x80); |
|
72 break; |
|
73 case eColorID_Widget3DHighlight: |
|
74 aColor = NS_RGB(0xa0,0xa0,0xa0); |
|
75 break; |
|
76 case eColorID_Widget3DShadow: |
|
77 aColor = NS_RGB(0x40,0x40,0x40); |
|
78 break; |
|
79 case eColorID_TextBackground: |
|
80 aColor = NS_RGB(0xff,0xff,0xff); |
|
81 break; |
|
82 case eColorID_TextForeground: |
|
83 aColor = NS_RGB(0x00,0x00,0x00); |
|
84 break; |
|
85 case eColorID_TextSelectBackground: |
|
86 aColor = GetColorFromNSColor([NSColor selectedTextBackgroundColor]); |
|
87 break; |
|
88 case eColorID_highlight: // CSS2 color |
|
89 aColor = GetColorFromNSColor([NSColor alternateSelectedControlColor]); |
|
90 break; |
|
91 case eColorID__moz_menuhover: |
|
92 aColor = GetColorFromNSColor([NSColor alternateSelectedControlColor]); |
|
93 break; |
|
94 case eColorID_TextSelectForeground: |
|
95 GetColor(eColorID_TextSelectBackground, aColor); |
|
96 if (aColor == 0x000000) |
|
97 aColor = NS_RGB(0xff,0xff,0xff); |
|
98 else |
|
99 aColor = NS_DONT_CHANGE_COLOR; |
|
100 break; |
|
101 case eColorID_highlighttext: // CSS2 color |
|
102 case eColorID__moz_menuhovertext: |
|
103 aColor = GetColorFromNSColor([NSColor alternateSelectedControlTextColor]); |
|
104 break; |
|
105 case eColorID_IMESelectedRawTextBackground: |
|
106 case eColorID_IMESelectedConvertedTextBackground: |
|
107 case eColorID_IMERawInputBackground: |
|
108 case eColorID_IMEConvertedTextBackground: |
|
109 aColor = NS_TRANSPARENT; |
|
110 break; |
|
111 case eColorID_IMESelectedRawTextForeground: |
|
112 case eColorID_IMESelectedConvertedTextForeground: |
|
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_40PERCENT_FOREGROUND_COLOR; |
|
120 break; |
|
121 case eColorID_IMESelectedRawTextUnderline: |
|
122 case eColorID_IMESelectedConvertedTextUnderline: |
|
123 aColor = NS_SAME_AS_FOREGROUND_COLOR; |
|
124 break; |
|
125 case eColorID_SpellCheckerUnderline: |
|
126 aColor = NS_RGB(0xff, 0, 0); |
|
127 break; |
|
128 |
|
129 // |
|
130 // css2 system colors http://www.w3.org/TR/REC-CSS2/ui.html#system-colors |
|
131 // |
|
132 // It's really hard to effectively map these to the Appearance Manager properly, |
|
133 // since they are modeled word for word after the win32 system colors and don't have any |
|
134 // real counterparts in the Mac world. I'm sure we'll be tweaking these for |
|
135 // years to come. |
|
136 // |
|
137 // Thanks to mpt26@student.canterbury.ac.nz for the hardcoded values that form the defaults |
|
138 // if querying the Appearance Manager fails ;) |
|
139 // |
|
140 |
|
141 case eColorID_buttontext: |
|
142 case eColorID__moz_buttonhovertext: |
|
143 aColor = GetColorFromNSColor([NSColor controlTextColor]); |
|
144 break; |
|
145 case eColorID_captiontext: |
|
146 case eColorID_menutext: |
|
147 case eColorID_infotext: |
|
148 case eColorID__moz_menubartext: |
|
149 aColor = GetColorFromNSColor([NSColor textColor]); |
|
150 break; |
|
151 case eColorID_windowtext: |
|
152 aColor = GetColorFromNSColor([NSColor windowFrameTextColor]); |
|
153 break; |
|
154 case eColorID_activecaption: |
|
155 aColor = GetColorFromNSColor([NSColor gridColor]); |
|
156 break; |
|
157 case eColorID_activeborder: |
|
158 aColor = NS_RGB(0x00,0x00,0x00); |
|
159 break; |
|
160 case eColorID_appworkspace: |
|
161 aColor = NS_RGB(0xFF,0xFF,0xFF); |
|
162 break; |
|
163 case eColorID_background: |
|
164 aColor = NS_RGB(0x63,0x63,0xCE); |
|
165 break; |
|
166 case eColorID_buttonface: |
|
167 case eColorID__moz_buttonhoverface: |
|
168 aColor = NS_RGB(0xF0,0xF0,0xF0); |
|
169 break; |
|
170 case eColorID_buttonhighlight: |
|
171 aColor = NS_RGB(0xFF,0xFF,0xFF); |
|
172 break; |
|
173 case eColorID_buttonshadow: |
|
174 aColor = NS_RGB(0xDC,0xDC,0xDC); |
|
175 break; |
|
176 case eColorID_graytext: |
|
177 aColor = GetColorFromNSColor([NSColor disabledControlTextColor]); |
|
178 break; |
|
179 case eColorID_inactiveborder: |
|
180 aColor = GetColorFromNSColor([NSColor controlBackgroundColor]); |
|
181 break; |
|
182 case eColorID_inactivecaption: |
|
183 aColor = GetColorFromNSColor([NSColor controlBackgroundColor]); |
|
184 break; |
|
185 case eColorID_inactivecaptiontext: |
|
186 aColor = NS_RGB(0x45,0x45,0x45); |
|
187 break; |
|
188 case eColorID_scrollbar: |
|
189 aColor = GetColorFromNSColor([NSColor scrollBarColor]); |
|
190 break; |
|
191 case eColorID_threeddarkshadow: |
|
192 aColor = NS_RGB(0xDC,0xDC,0xDC); |
|
193 break; |
|
194 case eColorID_threedshadow: |
|
195 aColor = NS_RGB(0xE0,0xE0,0xE0); |
|
196 break; |
|
197 case eColorID_threedface: |
|
198 aColor = NS_RGB(0xF0,0xF0,0xF0); |
|
199 break; |
|
200 case eColorID_threedhighlight: |
|
201 aColor = GetColorFromNSColor([NSColor highlightColor]); |
|
202 break; |
|
203 case eColorID_threedlightshadow: |
|
204 aColor = NS_RGB(0xDA,0xDA,0xDA); |
|
205 break; |
|
206 case eColorID_menu: |
|
207 aColor = GetColorFromNSColor([NSColor alternateSelectedControlTextColor]); |
|
208 break; |
|
209 case eColorID_infobackground: |
|
210 aColor = NS_RGB(0xFF,0xFF,0xC7); |
|
211 break; |
|
212 case eColorID_windowframe: |
|
213 aColor = GetColorFromNSColor([NSColor gridColor]); |
|
214 break; |
|
215 case eColorID_window: |
|
216 case eColorID__moz_field: |
|
217 case eColorID__moz_combobox: |
|
218 aColor = NS_RGB(0xff,0xff,0xff); |
|
219 break; |
|
220 case eColorID__moz_fieldtext: |
|
221 case eColorID__moz_comboboxtext: |
|
222 aColor = GetColorFromNSColor([NSColor controlTextColor]); |
|
223 break; |
|
224 case eColorID__moz_dialog: |
|
225 aColor = GetColorFromNSColor([NSColor controlHighlightColor]); |
|
226 break; |
|
227 case eColorID__moz_dialogtext: |
|
228 case eColorID__moz_cellhighlighttext: |
|
229 case eColorID__moz_html_cellhighlighttext: |
|
230 aColor = GetColorFromNSColor([NSColor controlTextColor]); |
|
231 break; |
|
232 case eColorID__moz_dragtargetzone: |
|
233 aColor = GetColorFromNSColor([NSColor selectedControlColor]); |
|
234 break; |
|
235 case eColorID__moz_mac_chrome_active: |
|
236 case eColorID__moz_mac_chrome_inactive: { |
|
237 int grey = NativeGreyColorAsInt(toolbarFillGrey, (aID == eColorID__moz_mac_chrome_active)); |
|
238 aColor = NS_RGB(grey, grey, grey); |
|
239 } |
|
240 break; |
|
241 case eColorID__moz_mac_focusring: |
|
242 aColor = GetColorFromNSColor([NSColor keyboardFocusIndicatorColor]); |
|
243 break; |
|
244 case eColorID__moz_mac_menushadow: |
|
245 aColor = NS_RGB(0xA3,0xA3,0xA3); |
|
246 break; |
|
247 case eColorID__moz_mac_menutextdisable: |
|
248 aColor = NS_RGB(0x88,0x88,0x88); |
|
249 break; |
|
250 case eColorID__moz_mac_menutextselect: |
|
251 aColor = GetColorFromNSColor([NSColor selectedMenuItemTextColor]); |
|
252 break; |
|
253 case eColorID__moz_mac_disabledtoolbartext: |
|
254 aColor = GetColorFromNSColor([NSColor disabledControlTextColor]); |
|
255 break; |
|
256 case eColorID__moz_mac_menuselect: |
|
257 aColor = GetColorFromNSColor([NSColor alternateSelectedControlColor]); |
|
258 break; |
|
259 case eColorID__moz_buttondefault: |
|
260 aColor = NS_RGB(0xDC,0xDC,0xDC); |
|
261 break; |
|
262 case eColorID__moz_cellhighlight: |
|
263 case eColorID__moz_html_cellhighlight: |
|
264 case eColorID__moz_mac_secondaryhighlight: |
|
265 // For inactive list selection |
|
266 aColor = GetColorFromNSColor([NSColor secondarySelectedControlColor]); |
|
267 break; |
|
268 case eColorID__moz_eventreerow: |
|
269 // Background color of even list rows. |
|
270 aColor = GetColorFromNSColor([[NSColor controlAlternatingRowBackgroundColors] objectAtIndex:0]); |
|
271 break; |
|
272 case eColorID__moz_oddtreerow: |
|
273 // Background color of odd list rows. |
|
274 aColor = GetColorFromNSColor([[NSColor controlAlternatingRowBackgroundColors] objectAtIndex:1]); |
|
275 break; |
|
276 case eColorID__moz_nativehyperlinktext: |
|
277 // There appears to be no available system defined color. HARDCODING to the appropriate color. |
|
278 aColor = NS_RGB(0x14,0x4F,0xAE); |
|
279 break; |
|
280 default: |
|
281 NS_WARNING("Someone asked nsILookAndFeel for a color I don't know about"); |
|
282 aColor = NS_RGB(0xff,0xff,0xff); |
|
283 res = NS_ERROR_FAILURE; |
|
284 break; |
|
285 } |
|
286 |
|
287 return res; |
|
288 |
|
289 NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; |
|
290 } |
|
291 |
|
292 nsresult |
|
293 nsLookAndFeel::GetIntImpl(IntID aID, int32_t &aResult) |
|
294 { |
|
295 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; |
|
296 |
|
297 nsresult res = nsXPLookAndFeel::GetIntImpl(aID, aResult); |
|
298 if (NS_SUCCEEDED(res)) |
|
299 return res; |
|
300 res = NS_OK; |
|
301 |
|
302 switch (aID) { |
|
303 case eIntID_CaretBlinkTime: |
|
304 aResult = 567; |
|
305 break; |
|
306 case eIntID_CaretWidth: |
|
307 aResult = 1; |
|
308 break; |
|
309 case eIntID_ShowCaretDuringSelection: |
|
310 aResult = 0; |
|
311 break; |
|
312 case eIntID_SelectTextfieldsOnKeyFocus: |
|
313 // Select textfield content when focused by kbd |
|
314 // used by EventStateManager::sTextfieldSelectModel |
|
315 aResult = 1; |
|
316 break; |
|
317 case eIntID_SubmenuDelay: |
|
318 aResult = 200; |
|
319 break; |
|
320 case eIntID_TooltipDelay: |
|
321 aResult = 500; |
|
322 break; |
|
323 case eIntID_MenusCanOverlapOSBar: |
|
324 // xul popups are not allowed to overlap the menubar. |
|
325 aResult = 0; |
|
326 break; |
|
327 case eIntID_SkipNavigatingDisabledMenuItem: |
|
328 aResult = 1; |
|
329 break; |
|
330 case eIntID_DragThresholdX: |
|
331 case eIntID_DragThresholdY: |
|
332 aResult = 4; |
|
333 break; |
|
334 case eIntID_ScrollArrowStyle: |
|
335 if (nsCocoaFeatures::OnLionOrLater()) { |
|
336 // OS X Lion's scrollbars have no arrows |
|
337 aResult = eScrollArrow_None; |
|
338 } else { |
|
339 NSString *buttonPlacement = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleScrollBarVariant"]; |
|
340 if ([buttonPlacement isEqualToString:@"Single"]) { |
|
341 aResult = eScrollArrowStyle_Single; |
|
342 } else if ([buttonPlacement isEqualToString:@"DoubleMin"]) { |
|
343 aResult = eScrollArrowStyle_BothAtTop; |
|
344 } else if ([buttonPlacement isEqualToString:@"DoubleBoth"]) { |
|
345 aResult = eScrollArrowStyle_BothAtEachEnd; |
|
346 } else { |
|
347 aResult = eScrollArrowStyle_BothAtBottom; // The default is BothAtBottom. |
|
348 } |
|
349 } |
|
350 break; |
|
351 case eIntID_ScrollSliderStyle: |
|
352 aResult = eScrollThumbStyle_Proportional; |
|
353 break; |
|
354 case eIntID_UseOverlayScrollbars: |
|
355 aResult = SystemWantsOverlayScrollbars() ? 1 : 0; |
|
356 break; |
|
357 case eIntID_AllowOverlayScrollbarsOverlap: |
|
358 aResult = AllowOverlayScrollbarsOverlap() ? 1 : 0; |
|
359 break; |
|
360 case eIntID_ScrollbarDisplayOnMouseMove: |
|
361 aResult = 0; |
|
362 break; |
|
363 case eIntID_ScrollbarFadeBeginDelay: |
|
364 aResult = 450; |
|
365 break; |
|
366 case eIntID_ScrollbarFadeDuration: |
|
367 aResult = 200; |
|
368 break; |
|
369 case eIntID_TreeOpenDelay: |
|
370 aResult = 1000; |
|
371 break; |
|
372 case eIntID_TreeCloseDelay: |
|
373 aResult = 1000; |
|
374 break; |
|
375 case eIntID_TreeLazyScrollDelay: |
|
376 aResult = 150; |
|
377 break; |
|
378 case eIntID_TreeScrollDelay: |
|
379 aResult = 100; |
|
380 break; |
|
381 case eIntID_TreeScrollLinesMax: |
|
382 aResult = 3; |
|
383 break; |
|
384 case eIntID_DWMCompositor: |
|
385 case eIntID_WindowsClassic: |
|
386 case eIntID_WindowsDefaultTheme: |
|
387 case eIntID_TouchEnabled: |
|
388 case eIntID_WindowsThemeIdentifier: |
|
389 case eIntID_OperatingSystemVersionIdentifier: |
|
390 aResult = 0; |
|
391 res = NS_ERROR_NOT_IMPLEMENTED; |
|
392 break; |
|
393 case eIntID_MacGraphiteTheme: |
|
394 aResult = [NSColor currentControlTint] == NSGraphiteControlTint; |
|
395 break; |
|
396 case eIntID_MacLionTheme: |
|
397 aResult = nsCocoaFeatures::OnLionOrLater(); |
|
398 break; |
|
399 case eIntID_AlertNotificationOrigin: |
|
400 aResult = NS_ALERT_TOP; |
|
401 break; |
|
402 case eIntID_TabFocusModel: |
|
403 { |
|
404 // we should probably cache this |
|
405 CFPropertyListRef fullKeyboardAccessProperty; |
|
406 fullKeyboardAccessProperty = ::CFPreferencesCopyValue(CFSTR("AppleKeyboardUIMode"), |
|
407 kCFPreferencesAnyApplication, |
|
408 kCFPreferencesCurrentUser, |
|
409 kCFPreferencesAnyHost); |
|
410 aResult = 1; // default to just textboxes |
|
411 if (fullKeyboardAccessProperty) { |
|
412 int32_t fullKeyboardAccessPrefVal; |
|
413 if (::CFNumberGetValue((CFNumberRef) fullKeyboardAccessProperty, kCFNumberIntType, &fullKeyboardAccessPrefVal)) { |
|
414 // the second bit means "Full keyboard access" is on |
|
415 if (fullKeyboardAccessPrefVal & (1 << 1)) |
|
416 aResult = 7; // everything that can be focused |
|
417 } |
|
418 ::CFRelease(fullKeyboardAccessProperty); |
|
419 } |
|
420 } |
|
421 break; |
|
422 case eIntID_ScrollToClick: |
|
423 { |
|
424 aResult = [[NSUserDefaults standardUserDefaults] boolForKey:@"AppleScrollerPagingBehavior"]; |
|
425 } |
|
426 break; |
|
427 case eIntID_ChosenMenuItemsShouldBlink: |
|
428 aResult = 1; |
|
429 break; |
|
430 case eIntID_IMERawInputUnderlineStyle: |
|
431 case eIntID_IMEConvertedTextUnderlineStyle: |
|
432 case eIntID_IMESelectedRawTextUnderlineStyle: |
|
433 case eIntID_IMESelectedConvertedTextUnderline: |
|
434 aResult = NS_STYLE_TEXT_DECORATION_STYLE_SOLID; |
|
435 break; |
|
436 case eIntID_SpellCheckerUnderlineStyle: |
|
437 aResult = NS_STYLE_TEXT_DECORATION_STYLE_DOTTED; |
|
438 break; |
|
439 case eIntID_ScrollbarButtonAutoRepeatBehavior: |
|
440 aResult = 0; |
|
441 break; |
|
442 case eIntID_SwipeAnimationEnabled: |
|
443 aResult = 0; |
|
444 if ([NSEvent respondsToSelector:@selector( |
|
445 isSwipeTrackingFromScrollEventsEnabled)]) { |
|
446 aResult = [NSEvent isSwipeTrackingFromScrollEventsEnabled] ? 1 : 0; |
|
447 } |
|
448 break; |
|
449 case eIntID_ColorPickerAvailable: |
|
450 aResult = 1; |
|
451 break; |
|
452 default: |
|
453 aResult = 0; |
|
454 res = NS_ERROR_FAILURE; |
|
455 } |
|
456 return res; |
|
457 |
|
458 NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; |
|
459 } |
|
460 |
|
461 nsresult |
|
462 nsLookAndFeel::GetFloatImpl(FloatID aID, float &aResult) |
|
463 { |
|
464 nsresult res = nsXPLookAndFeel::GetFloatImpl(aID, aResult); |
|
465 if (NS_SUCCEEDED(res)) |
|
466 return res; |
|
467 res = NS_OK; |
|
468 |
|
469 switch (aID) { |
|
470 case eFloatID_IMEUnderlineRelativeSize: |
|
471 aResult = 2.0f; |
|
472 break; |
|
473 case eFloatID_SpellCheckerUnderlineRelativeSize: |
|
474 aResult = 2.0f; |
|
475 break; |
|
476 default: |
|
477 aResult = -1.0; |
|
478 res = NS_ERROR_FAILURE; |
|
479 } |
|
480 |
|
481 return res; |
|
482 } |
|
483 |
|
484 bool nsLookAndFeel::UseOverlayScrollbars() |
|
485 { |
|
486 return GetInt(eIntID_UseOverlayScrollbars) != 0; |
|
487 } |
|
488 |
|
489 bool nsLookAndFeel::SystemWantsOverlayScrollbars() |
|
490 { |
|
491 return ([NSScroller respondsToSelector:@selector(preferredScrollerStyle)] && |
|
492 [NSScroller preferredScrollerStyle] == mozNSScrollerStyleOverlay); |
|
493 } |
|
494 |
|
495 bool nsLookAndFeel::AllowOverlayScrollbarsOverlap() |
|
496 { |
|
497 return (UseOverlayScrollbars() && nsCocoaFeatures::OnMountainLionOrLater()); |
|
498 } |
|
499 |
|
500 // copied from gfxQuartzFontCache.mm, maybe should go in a Cocoa utils |
|
501 // file somewhere |
|
502 static void GetStringForNSString(const NSString *aSrc, nsAString& aDest) |
|
503 { |
|
504 aDest.SetLength([aSrc length]); |
|
505 [aSrc getCharacters:reinterpret_cast<unichar*>(aDest.BeginWriting())]; |
|
506 } |
|
507 |
|
508 bool |
|
509 nsLookAndFeel::GetFontImpl(FontID aID, nsString &aFontName, |
|
510 gfxFontStyle &aFontStyle, |
|
511 float aDevPixPerCSSPixel) |
|
512 { |
|
513 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN; |
|
514 |
|
515 // hack for now |
|
516 if (aID == eFont_Window || aID == eFont_Document) { |
|
517 aFontStyle.style = NS_FONT_STYLE_NORMAL; |
|
518 aFontStyle.weight = NS_FONT_WEIGHT_NORMAL; |
|
519 aFontStyle.stretch = NS_FONT_STRETCH_NORMAL; |
|
520 aFontStyle.size = 14 * aDevPixPerCSSPixel; |
|
521 aFontStyle.systemFont = true; |
|
522 |
|
523 aFontName.AssignLiteral("sans-serif"); |
|
524 return true; |
|
525 } |
|
526 |
|
527 /* possibilities, see NSFont Class Reference: |
|
528 [NSFont boldSystemFontOfSize: 0.0] |
|
529 [NSFont controlContentFontOfSize: 0.0] |
|
530 [NSFont labelFontOfSize: 0.0] |
|
531 [NSFont menuBarFontOfSize: 0.0] |
|
532 [NSFont menuFontOfSize: 0.0] |
|
533 [NSFont messageFontOfSize: 0.0] |
|
534 [NSFont paletteFontOfSize: 0.0] |
|
535 [NSFont systemFontOfSize: 0.0] |
|
536 [NSFont titleBarFontOfSize: 0.0] |
|
537 [NSFont toolTipsFontOfSize: 0.0] |
|
538 [NSFont userFixedPitchFontOfSize: 0.0] |
|
539 [NSFont userFontOfSize: 0.0] |
|
540 [NSFont systemFontOfSize: [NSFont smallSystemFontSize]] |
|
541 [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]] |
|
542 */ |
|
543 |
|
544 NSFont *font = nullptr; |
|
545 switch (aID) { |
|
546 // css2 |
|
547 case eFont_Caption: |
|
548 font = [NSFont systemFontOfSize:0.0]; |
|
549 break; |
|
550 case eFont_Icon: // used in urlbar; tried labelFont, but too small |
|
551 font = [NSFont controlContentFontOfSize:0.0]; |
|
552 break; |
|
553 case eFont_Menu: |
|
554 font = [NSFont systemFontOfSize:0.0]; |
|
555 break; |
|
556 case eFont_MessageBox: |
|
557 font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; |
|
558 break; |
|
559 case eFont_SmallCaption: |
|
560 font = [NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]]; |
|
561 break; |
|
562 case eFont_StatusBar: |
|
563 font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; |
|
564 break; |
|
565 // css3 |
|
566 //case eFont_Window: = 'sans-serif' |
|
567 //case eFont_Document: = 'sans-serif' |
|
568 case eFont_Workspace: |
|
569 font = [NSFont controlContentFontOfSize:0.0]; |
|
570 break; |
|
571 case eFont_Desktop: |
|
572 font = [NSFont controlContentFontOfSize:0.0]; |
|
573 break; |
|
574 case eFont_Info: |
|
575 font = [NSFont controlContentFontOfSize:0.0]; |
|
576 break; |
|
577 case eFont_Dialog: |
|
578 font = [NSFont systemFontOfSize:0.0]; |
|
579 break; |
|
580 case eFont_Button: |
|
581 font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; |
|
582 break; |
|
583 case eFont_PullDownMenu: |
|
584 font = [NSFont menuBarFontOfSize:0.0]; |
|
585 break; |
|
586 case eFont_List: |
|
587 font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; |
|
588 break; |
|
589 case eFont_Field: |
|
590 font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; |
|
591 break; |
|
592 // moz |
|
593 case eFont_Tooltips: |
|
594 font = [NSFont toolTipsFontOfSize:0.0]; |
|
595 break; |
|
596 case eFont_Widget: |
|
597 font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; |
|
598 break; |
|
599 default: |
|
600 break; |
|
601 } |
|
602 |
|
603 if (!font) { |
|
604 NS_WARNING("failed to find a system font!"); |
|
605 return false; |
|
606 } |
|
607 |
|
608 NSFontSymbolicTraits traits = [[font fontDescriptor] symbolicTraits]; |
|
609 aFontStyle.style = |
|
610 (traits & NSFontItalicTrait) ? NS_FONT_STYLE_ITALIC : NS_FONT_STYLE_NORMAL; |
|
611 aFontStyle.weight = |
|
612 (traits & NSFontBoldTrait) ? NS_FONT_WEIGHT_BOLD : NS_FONT_WEIGHT_NORMAL; |
|
613 aFontStyle.stretch = |
|
614 (traits & NSFontExpandedTrait) ? |
|
615 NS_FONT_STRETCH_EXPANDED : (traits & NSFontCondensedTrait) ? |
|
616 NS_FONT_STRETCH_CONDENSED : NS_FONT_STRETCH_NORMAL; |
|
617 // convert size from css pixels to device pixels |
|
618 aFontStyle.size = [font pointSize] * aDevPixPerCSSPixel; |
|
619 aFontStyle.systemFont = true; |
|
620 |
|
621 GetStringForNSString([font familyName], aFontName); |
|
622 return true; |
|
623 |
|
624 NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(false); |
|
625 } |