michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsLookAndFeel.h" michael@0: #include "nsCocoaFeatures.h" michael@0: #include "nsIServiceManager.h" michael@0: #include "nsNativeThemeColors.h" michael@0: #include "nsStyleConsts.h" michael@0: #include "nsCocoaFeatures.h" michael@0: #include "gfxFont.h" michael@0: #include "gfxFontConstants.h" michael@0: #include "mozilla/gfx/2D.h" michael@0: michael@0: #import michael@0: michael@0: // This must be included last: michael@0: #include "nsObjCExceptions.h" michael@0: michael@0: enum { michael@0: mozNSScrollerStyleLegacy = 0, michael@0: mozNSScrollerStyleOverlay = 1 michael@0: }; michael@0: typedef NSInteger mozNSScrollerStyle; michael@0: michael@0: @interface NSScroller(AvailableSinceLion) michael@0: + (mozNSScrollerStyle)preferredScrollerStyle; michael@0: @end michael@0: michael@0: nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel() michael@0: { michael@0: } michael@0: michael@0: nsLookAndFeel::~nsLookAndFeel() michael@0: { michael@0: } michael@0: michael@0: static nscolor GetColorFromNSColor(NSColor* aColor) michael@0: { michael@0: NSColor* deviceColor = [aColor colorUsingColorSpaceName:NSDeviceRGBColorSpace]; michael@0: return NS_RGB((unsigned int)([deviceColor redComponent] * 255.0), michael@0: (unsigned int)([deviceColor greenComponent] * 255.0), michael@0: (unsigned int)([deviceColor blueComponent] * 255.0)); michael@0: } michael@0: michael@0: nsresult michael@0: nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor) michael@0: { michael@0: NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; michael@0: michael@0: nsresult res = NS_OK; michael@0: michael@0: switch (aID) { michael@0: case eColorID_WindowBackground: michael@0: aColor = NS_RGB(0xff,0xff,0xff); michael@0: break; michael@0: case eColorID_WindowForeground: michael@0: aColor = NS_RGB(0x00,0x00,0x00); michael@0: break; michael@0: case eColorID_WidgetBackground: michael@0: aColor = NS_RGB(0xdd,0xdd,0xdd); michael@0: break; michael@0: case eColorID_WidgetForeground: michael@0: aColor = NS_RGB(0x00,0x00,0x00); michael@0: break; michael@0: case eColorID_WidgetSelectBackground: michael@0: aColor = NS_RGB(0x80,0x80,0x80); michael@0: break; michael@0: case eColorID_WidgetSelectForeground: michael@0: aColor = NS_RGB(0x00,0x00,0x80); michael@0: break; michael@0: case eColorID_Widget3DHighlight: michael@0: aColor = NS_RGB(0xa0,0xa0,0xa0); michael@0: break; michael@0: case eColorID_Widget3DShadow: michael@0: aColor = NS_RGB(0x40,0x40,0x40); michael@0: break; michael@0: case eColorID_TextBackground: michael@0: aColor = NS_RGB(0xff,0xff,0xff); michael@0: break; michael@0: case eColorID_TextForeground: michael@0: aColor = NS_RGB(0x00,0x00,0x00); michael@0: break; michael@0: case eColorID_TextSelectBackground: michael@0: aColor = GetColorFromNSColor([NSColor selectedTextBackgroundColor]); michael@0: break; michael@0: case eColorID_highlight: // CSS2 color michael@0: aColor = GetColorFromNSColor([NSColor alternateSelectedControlColor]); michael@0: break; michael@0: case eColorID__moz_menuhover: michael@0: aColor = GetColorFromNSColor([NSColor alternateSelectedControlColor]); michael@0: break; michael@0: case eColorID_TextSelectForeground: michael@0: GetColor(eColorID_TextSelectBackground, aColor); michael@0: if (aColor == 0x000000) michael@0: aColor = NS_RGB(0xff,0xff,0xff); michael@0: else michael@0: aColor = NS_DONT_CHANGE_COLOR; michael@0: break; michael@0: case eColorID_highlighttext: // CSS2 color michael@0: case eColorID__moz_menuhovertext: michael@0: aColor = GetColorFromNSColor([NSColor alternateSelectedControlTextColor]); michael@0: break; michael@0: case eColorID_IMESelectedRawTextBackground: michael@0: case eColorID_IMESelectedConvertedTextBackground: michael@0: case eColorID_IMERawInputBackground: michael@0: case eColorID_IMEConvertedTextBackground: michael@0: aColor = NS_TRANSPARENT; michael@0: break; michael@0: case eColorID_IMESelectedRawTextForeground: michael@0: case eColorID_IMESelectedConvertedTextForeground: michael@0: case eColorID_IMERawInputForeground: michael@0: case eColorID_IMEConvertedTextForeground: michael@0: aColor = NS_SAME_AS_FOREGROUND_COLOR; michael@0: break; michael@0: case eColorID_IMERawInputUnderline: michael@0: case eColorID_IMEConvertedTextUnderline: michael@0: aColor = NS_40PERCENT_FOREGROUND_COLOR; michael@0: break; michael@0: case eColorID_IMESelectedRawTextUnderline: michael@0: case eColorID_IMESelectedConvertedTextUnderline: michael@0: aColor = NS_SAME_AS_FOREGROUND_COLOR; michael@0: break; michael@0: case eColorID_SpellCheckerUnderline: michael@0: aColor = NS_RGB(0xff, 0, 0); michael@0: break; michael@0: michael@0: // michael@0: // css2 system colors http://www.w3.org/TR/REC-CSS2/ui.html#system-colors michael@0: // michael@0: // It's really hard to effectively map these to the Appearance Manager properly, michael@0: // since they are modeled word for word after the win32 system colors and don't have any michael@0: // real counterparts in the Mac world. I'm sure we'll be tweaking these for michael@0: // years to come. michael@0: // michael@0: // Thanks to mpt26@student.canterbury.ac.nz for the hardcoded values that form the defaults michael@0: // if querying the Appearance Manager fails ;) michael@0: // michael@0: michael@0: case eColorID_buttontext: michael@0: case eColorID__moz_buttonhovertext: michael@0: aColor = GetColorFromNSColor([NSColor controlTextColor]); michael@0: break; michael@0: case eColorID_captiontext: michael@0: case eColorID_menutext: michael@0: case eColorID_infotext: michael@0: case eColorID__moz_menubartext: michael@0: aColor = GetColorFromNSColor([NSColor textColor]); michael@0: break; michael@0: case eColorID_windowtext: michael@0: aColor = GetColorFromNSColor([NSColor windowFrameTextColor]); michael@0: break; michael@0: case eColorID_activecaption: michael@0: aColor = GetColorFromNSColor([NSColor gridColor]); michael@0: break; michael@0: case eColorID_activeborder: michael@0: aColor = NS_RGB(0x00,0x00,0x00); michael@0: break; michael@0: case eColorID_appworkspace: michael@0: aColor = NS_RGB(0xFF,0xFF,0xFF); michael@0: break; michael@0: case eColorID_background: michael@0: aColor = NS_RGB(0x63,0x63,0xCE); michael@0: break; michael@0: case eColorID_buttonface: michael@0: case eColorID__moz_buttonhoverface: michael@0: aColor = NS_RGB(0xF0,0xF0,0xF0); michael@0: break; michael@0: case eColorID_buttonhighlight: michael@0: aColor = NS_RGB(0xFF,0xFF,0xFF); michael@0: break; michael@0: case eColorID_buttonshadow: michael@0: aColor = NS_RGB(0xDC,0xDC,0xDC); michael@0: break; michael@0: case eColorID_graytext: michael@0: aColor = GetColorFromNSColor([NSColor disabledControlTextColor]); michael@0: break; michael@0: case eColorID_inactiveborder: michael@0: aColor = GetColorFromNSColor([NSColor controlBackgroundColor]); michael@0: break; michael@0: case eColorID_inactivecaption: michael@0: aColor = GetColorFromNSColor([NSColor controlBackgroundColor]); michael@0: break; michael@0: case eColorID_inactivecaptiontext: michael@0: aColor = NS_RGB(0x45,0x45,0x45); michael@0: break; michael@0: case eColorID_scrollbar: michael@0: aColor = GetColorFromNSColor([NSColor scrollBarColor]); michael@0: break; michael@0: case eColorID_threeddarkshadow: michael@0: aColor = NS_RGB(0xDC,0xDC,0xDC); michael@0: break; michael@0: case eColorID_threedshadow: michael@0: aColor = NS_RGB(0xE0,0xE0,0xE0); michael@0: break; michael@0: case eColorID_threedface: michael@0: aColor = NS_RGB(0xF0,0xF0,0xF0); michael@0: break; michael@0: case eColorID_threedhighlight: michael@0: aColor = GetColorFromNSColor([NSColor highlightColor]); michael@0: break; michael@0: case eColorID_threedlightshadow: michael@0: aColor = NS_RGB(0xDA,0xDA,0xDA); michael@0: break; michael@0: case eColorID_menu: michael@0: aColor = GetColorFromNSColor([NSColor alternateSelectedControlTextColor]); michael@0: break; michael@0: case eColorID_infobackground: michael@0: aColor = NS_RGB(0xFF,0xFF,0xC7); michael@0: break; michael@0: case eColorID_windowframe: michael@0: aColor = GetColorFromNSColor([NSColor gridColor]); michael@0: break; michael@0: case eColorID_window: michael@0: case eColorID__moz_field: michael@0: case eColorID__moz_combobox: michael@0: aColor = NS_RGB(0xff,0xff,0xff); michael@0: break; michael@0: case eColorID__moz_fieldtext: michael@0: case eColorID__moz_comboboxtext: michael@0: aColor = GetColorFromNSColor([NSColor controlTextColor]); michael@0: break; michael@0: case eColorID__moz_dialog: michael@0: aColor = GetColorFromNSColor([NSColor controlHighlightColor]); michael@0: break; michael@0: case eColorID__moz_dialogtext: michael@0: case eColorID__moz_cellhighlighttext: michael@0: case eColorID__moz_html_cellhighlighttext: michael@0: aColor = GetColorFromNSColor([NSColor controlTextColor]); michael@0: break; michael@0: case eColorID__moz_dragtargetzone: michael@0: aColor = GetColorFromNSColor([NSColor selectedControlColor]); michael@0: break; michael@0: case eColorID__moz_mac_chrome_active: michael@0: case eColorID__moz_mac_chrome_inactive: { michael@0: int grey = NativeGreyColorAsInt(toolbarFillGrey, (aID == eColorID__moz_mac_chrome_active)); michael@0: aColor = NS_RGB(grey, grey, grey); michael@0: } michael@0: break; michael@0: case eColorID__moz_mac_focusring: michael@0: aColor = GetColorFromNSColor([NSColor keyboardFocusIndicatorColor]); michael@0: break; michael@0: case eColorID__moz_mac_menushadow: michael@0: aColor = NS_RGB(0xA3,0xA3,0xA3); michael@0: break; michael@0: case eColorID__moz_mac_menutextdisable: michael@0: aColor = NS_RGB(0x88,0x88,0x88); michael@0: break; michael@0: case eColorID__moz_mac_menutextselect: michael@0: aColor = GetColorFromNSColor([NSColor selectedMenuItemTextColor]); michael@0: break; michael@0: case eColorID__moz_mac_disabledtoolbartext: michael@0: aColor = GetColorFromNSColor([NSColor disabledControlTextColor]); michael@0: break; michael@0: case eColorID__moz_mac_menuselect: michael@0: aColor = GetColorFromNSColor([NSColor alternateSelectedControlColor]); michael@0: break; michael@0: case eColorID__moz_buttondefault: michael@0: aColor = NS_RGB(0xDC,0xDC,0xDC); michael@0: break; michael@0: case eColorID__moz_cellhighlight: michael@0: case eColorID__moz_html_cellhighlight: michael@0: case eColorID__moz_mac_secondaryhighlight: michael@0: // For inactive list selection michael@0: aColor = GetColorFromNSColor([NSColor secondarySelectedControlColor]); michael@0: break; michael@0: case eColorID__moz_eventreerow: michael@0: // Background color of even list rows. michael@0: aColor = GetColorFromNSColor([[NSColor controlAlternatingRowBackgroundColors] objectAtIndex:0]); michael@0: break; michael@0: case eColorID__moz_oddtreerow: michael@0: // Background color of odd list rows. michael@0: aColor = GetColorFromNSColor([[NSColor controlAlternatingRowBackgroundColors] objectAtIndex:1]); michael@0: break; michael@0: case eColorID__moz_nativehyperlinktext: michael@0: // There appears to be no available system defined color. HARDCODING to the appropriate color. michael@0: aColor = NS_RGB(0x14,0x4F,0xAE); michael@0: break; michael@0: default: michael@0: NS_WARNING("Someone asked nsILookAndFeel for a color I don't know about"); michael@0: aColor = NS_RGB(0xff,0xff,0xff); michael@0: res = NS_ERROR_FAILURE; michael@0: break; michael@0: } michael@0: michael@0: return res; michael@0: michael@0: NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; michael@0: } michael@0: michael@0: nsresult michael@0: nsLookAndFeel::GetIntImpl(IntID aID, int32_t &aResult) michael@0: { michael@0: NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; michael@0: michael@0: nsresult res = nsXPLookAndFeel::GetIntImpl(aID, aResult); michael@0: if (NS_SUCCEEDED(res)) michael@0: return res; michael@0: res = NS_OK; michael@0: michael@0: switch (aID) { michael@0: case eIntID_CaretBlinkTime: michael@0: aResult = 567; michael@0: break; michael@0: case eIntID_CaretWidth: michael@0: aResult = 1; michael@0: break; michael@0: case eIntID_ShowCaretDuringSelection: michael@0: aResult = 0; michael@0: break; michael@0: case eIntID_SelectTextfieldsOnKeyFocus: michael@0: // Select textfield content when focused by kbd michael@0: // used by EventStateManager::sTextfieldSelectModel michael@0: aResult = 1; michael@0: break; michael@0: case eIntID_SubmenuDelay: michael@0: aResult = 200; michael@0: break; michael@0: case eIntID_TooltipDelay: michael@0: aResult = 500; michael@0: break; michael@0: case eIntID_MenusCanOverlapOSBar: michael@0: // xul popups are not allowed to overlap the menubar. michael@0: aResult = 0; michael@0: break; michael@0: case eIntID_SkipNavigatingDisabledMenuItem: michael@0: aResult = 1; michael@0: break; michael@0: case eIntID_DragThresholdX: michael@0: case eIntID_DragThresholdY: michael@0: aResult = 4; michael@0: break; michael@0: case eIntID_ScrollArrowStyle: michael@0: if (nsCocoaFeatures::OnLionOrLater()) { michael@0: // OS X Lion's scrollbars have no arrows michael@0: aResult = eScrollArrow_None; michael@0: } else { michael@0: NSString *buttonPlacement = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleScrollBarVariant"]; michael@0: if ([buttonPlacement isEqualToString:@"Single"]) { michael@0: aResult = eScrollArrowStyle_Single; michael@0: } else if ([buttonPlacement isEqualToString:@"DoubleMin"]) { michael@0: aResult = eScrollArrowStyle_BothAtTop; michael@0: } else if ([buttonPlacement isEqualToString:@"DoubleBoth"]) { michael@0: aResult = eScrollArrowStyle_BothAtEachEnd; michael@0: } else { michael@0: aResult = eScrollArrowStyle_BothAtBottom; // The default is BothAtBottom. michael@0: } michael@0: } michael@0: break; michael@0: case eIntID_ScrollSliderStyle: michael@0: aResult = eScrollThumbStyle_Proportional; michael@0: break; michael@0: case eIntID_UseOverlayScrollbars: michael@0: aResult = SystemWantsOverlayScrollbars() ? 1 : 0; michael@0: break; michael@0: case eIntID_AllowOverlayScrollbarsOverlap: michael@0: aResult = AllowOverlayScrollbarsOverlap() ? 1 : 0; michael@0: break; michael@0: case eIntID_ScrollbarDisplayOnMouseMove: michael@0: aResult = 0; michael@0: break; michael@0: case eIntID_ScrollbarFadeBeginDelay: michael@0: aResult = 450; michael@0: break; michael@0: case eIntID_ScrollbarFadeDuration: michael@0: aResult = 200; michael@0: break; michael@0: case eIntID_TreeOpenDelay: michael@0: aResult = 1000; michael@0: break; michael@0: case eIntID_TreeCloseDelay: michael@0: aResult = 1000; michael@0: break; michael@0: case eIntID_TreeLazyScrollDelay: michael@0: aResult = 150; michael@0: break; michael@0: case eIntID_TreeScrollDelay: michael@0: aResult = 100; michael@0: break; michael@0: case eIntID_TreeScrollLinesMax: michael@0: aResult = 3; michael@0: break; michael@0: case eIntID_DWMCompositor: michael@0: case eIntID_WindowsClassic: michael@0: case eIntID_WindowsDefaultTheme: michael@0: case eIntID_TouchEnabled: michael@0: case eIntID_WindowsThemeIdentifier: michael@0: case eIntID_OperatingSystemVersionIdentifier: michael@0: aResult = 0; michael@0: res = NS_ERROR_NOT_IMPLEMENTED; michael@0: break; michael@0: case eIntID_MacGraphiteTheme: michael@0: aResult = [NSColor currentControlTint] == NSGraphiteControlTint; michael@0: break; michael@0: case eIntID_MacLionTheme: michael@0: aResult = nsCocoaFeatures::OnLionOrLater(); michael@0: break; michael@0: case eIntID_AlertNotificationOrigin: michael@0: aResult = NS_ALERT_TOP; michael@0: break; michael@0: case eIntID_TabFocusModel: michael@0: { michael@0: // we should probably cache this michael@0: CFPropertyListRef fullKeyboardAccessProperty; michael@0: fullKeyboardAccessProperty = ::CFPreferencesCopyValue(CFSTR("AppleKeyboardUIMode"), michael@0: kCFPreferencesAnyApplication, michael@0: kCFPreferencesCurrentUser, michael@0: kCFPreferencesAnyHost); michael@0: aResult = 1; // default to just textboxes michael@0: if (fullKeyboardAccessProperty) { michael@0: int32_t fullKeyboardAccessPrefVal; michael@0: if (::CFNumberGetValue((CFNumberRef) fullKeyboardAccessProperty, kCFNumberIntType, &fullKeyboardAccessPrefVal)) { michael@0: // the second bit means "Full keyboard access" is on michael@0: if (fullKeyboardAccessPrefVal & (1 << 1)) michael@0: aResult = 7; // everything that can be focused michael@0: } michael@0: ::CFRelease(fullKeyboardAccessProperty); michael@0: } michael@0: } michael@0: break; michael@0: case eIntID_ScrollToClick: michael@0: { michael@0: aResult = [[NSUserDefaults standardUserDefaults] boolForKey:@"AppleScrollerPagingBehavior"]; michael@0: } michael@0: break; michael@0: case eIntID_ChosenMenuItemsShouldBlink: michael@0: aResult = 1; michael@0: break; michael@0: case eIntID_IMERawInputUnderlineStyle: michael@0: case eIntID_IMEConvertedTextUnderlineStyle: michael@0: case eIntID_IMESelectedRawTextUnderlineStyle: michael@0: case eIntID_IMESelectedConvertedTextUnderline: michael@0: aResult = NS_STYLE_TEXT_DECORATION_STYLE_SOLID; michael@0: break; michael@0: case eIntID_SpellCheckerUnderlineStyle: michael@0: aResult = NS_STYLE_TEXT_DECORATION_STYLE_DOTTED; michael@0: break; michael@0: case eIntID_ScrollbarButtonAutoRepeatBehavior: michael@0: aResult = 0; michael@0: break; michael@0: case eIntID_SwipeAnimationEnabled: michael@0: aResult = 0; michael@0: if ([NSEvent respondsToSelector:@selector( michael@0: isSwipeTrackingFromScrollEventsEnabled)]) { michael@0: aResult = [NSEvent isSwipeTrackingFromScrollEventsEnabled] ? 1 : 0; michael@0: } michael@0: break; michael@0: case eIntID_ColorPickerAvailable: michael@0: aResult = 1; michael@0: break; michael@0: default: michael@0: aResult = 0; michael@0: res = NS_ERROR_FAILURE; michael@0: } michael@0: return res; michael@0: michael@0: NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; michael@0: } michael@0: michael@0: nsresult michael@0: nsLookAndFeel::GetFloatImpl(FloatID aID, float &aResult) michael@0: { michael@0: nsresult res = nsXPLookAndFeel::GetFloatImpl(aID, aResult); michael@0: if (NS_SUCCEEDED(res)) michael@0: return res; michael@0: res = NS_OK; michael@0: michael@0: switch (aID) { michael@0: case eFloatID_IMEUnderlineRelativeSize: michael@0: aResult = 2.0f; michael@0: break; michael@0: case eFloatID_SpellCheckerUnderlineRelativeSize: michael@0: aResult = 2.0f; michael@0: break; michael@0: default: michael@0: aResult = -1.0; michael@0: res = NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: return res; michael@0: } michael@0: michael@0: bool nsLookAndFeel::UseOverlayScrollbars() michael@0: { michael@0: return GetInt(eIntID_UseOverlayScrollbars) != 0; michael@0: } michael@0: michael@0: bool nsLookAndFeel::SystemWantsOverlayScrollbars() michael@0: { michael@0: return ([NSScroller respondsToSelector:@selector(preferredScrollerStyle)] && michael@0: [NSScroller preferredScrollerStyle] == mozNSScrollerStyleOverlay); michael@0: } michael@0: michael@0: bool nsLookAndFeel::AllowOverlayScrollbarsOverlap() michael@0: { michael@0: return (UseOverlayScrollbars() && nsCocoaFeatures::OnMountainLionOrLater()); michael@0: } michael@0: michael@0: // copied from gfxQuartzFontCache.mm, maybe should go in a Cocoa utils michael@0: // file somewhere michael@0: static void GetStringForNSString(const NSString *aSrc, nsAString& aDest) michael@0: { michael@0: aDest.SetLength([aSrc length]); michael@0: [aSrc getCharacters:reinterpret_cast(aDest.BeginWriting())]; michael@0: } michael@0: michael@0: bool michael@0: nsLookAndFeel::GetFontImpl(FontID aID, nsString &aFontName, michael@0: gfxFontStyle &aFontStyle, michael@0: float aDevPixPerCSSPixel) michael@0: { michael@0: NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN; michael@0: michael@0: // hack for now michael@0: if (aID == eFont_Window || aID == eFont_Document) { michael@0: aFontStyle.style = NS_FONT_STYLE_NORMAL; michael@0: aFontStyle.weight = NS_FONT_WEIGHT_NORMAL; michael@0: aFontStyle.stretch = NS_FONT_STRETCH_NORMAL; michael@0: aFontStyle.size = 14 * aDevPixPerCSSPixel; michael@0: aFontStyle.systemFont = true; michael@0: michael@0: aFontName.AssignLiteral("sans-serif"); michael@0: return true; michael@0: } michael@0: michael@0: /* possibilities, see NSFont Class Reference: michael@0: [NSFont boldSystemFontOfSize: 0.0] michael@0: [NSFont controlContentFontOfSize: 0.0] michael@0: [NSFont labelFontOfSize: 0.0] michael@0: [NSFont menuBarFontOfSize: 0.0] michael@0: [NSFont menuFontOfSize: 0.0] michael@0: [NSFont messageFontOfSize: 0.0] michael@0: [NSFont paletteFontOfSize: 0.0] michael@0: [NSFont systemFontOfSize: 0.0] michael@0: [NSFont titleBarFontOfSize: 0.0] michael@0: [NSFont toolTipsFontOfSize: 0.0] michael@0: [NSFont userFixedPitchFontOfSize: 0.0] michael@0: [NSFont userFontOfSize: 0.0] michael@0: [NSFont systemFontOfSize: [NSFont smallSystemFontSize]] michael@0: [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]] michael@0: */ michael@0: michael@0: NSFont *font = nullptr; michael@0: switch (aID) { michael@0: // css2 michael@0: case eFont_Caption: michael@0: font = [NSFont systemFontOfSize:0.0]; michael@0: break; michael@0: case eFont_Icon: // used in urlbar; tried labelFont, but too small michael@0: font = [NSFont controlContentFontOfSize:0.0]; michael@0: break; michael@0: case eFont_Menu: michael@0: font = [NSFont systemFontOfSize:0.0]; michael@0: break; michael@0: case eFont_MessageBox: michael@0: font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; michael@0: break; michael@0: case eFont_SmallCaption: michael@0: font = [NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]]; michael@0: break; michael@0: case eFont_StatusBar: michael@0: font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; michael@0: break; michael@0: // css3 michael@0: //case eFont_Window: = 'sans-serif' michael@0: //case eFont_Document: = 'sans-serif' michael@0: case eFont_Workspace: michael@0: font = [NSFont controlContentFontOfSize:0.0]; michael@0: break; michael@0: case eFont_Desktop: michael@0: font = [NSFont controlContentFontOfSize:0.0]; michael@0: break; michael@0: case eFont_Info: michael@0: font = [NSFont controlContentFontOfSize:0.0]; michael@0: break; michael@0: case eFont_Dialog: michael@0: font = [NSFont systemFontOfSize:0.0]; michael@0: break; michael@0: case eFont_Button: michael@0: font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; michael@0: break; michael@0: case eFont_PullDownMenu: michael@0: font = [NSFont menuBarFontOfSize:0.0]; michael@0: break; michael@0: case eFont_List: michael@0: font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; michael@0: break; michael@0: case eFont_Field: michael@0: font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; michael@0: break; michael@0: // moz michael@0: case eFont_Tooltips: michael@0: font = [NSFont toolTipsFontOfSize:0.0]; michael@0: break; michael@0: case eFont_Widget: michael@0: font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; michael@0: break; michael@0: default: michael@0: break; michael@0: } michael@0: michael@0: if (!font) { michael@0: NS_WARNING("failed to find a system font!"); michael@0: return false; michael@0: } michael@0: michael@0: NSFontSymbolicTraits traits = [[font fontDescriptor] symbolicTraits]; michael@0: aFontStyle.style = michael@0: (traits & NSFontItalicTrait) ? NS_FONT_STYLE_ITALIC : NS_FONT_STYLE_NORMAL; michael@0: aFontStyle.weight = michael@0: (traits & NSFontBoldTrait) ? NS_FONT_WEIGHT_BOLD : NS_FONT_WEIGHT_NORMAL; michael@0: aFontStyle.stretch = michael@0: (traits & NSFontExpandedTrait) ? michael@0: NS_FONT_STRETCH_EXPANDED : (traits & NSFontCondensedTrait) ? michael@0: NS_FONT_STRETCH_CONDENSED : NS_FONT_STRETCH_NORMAL; michael@0: // convert size from css pixels to device pixels michael@0: aFontStyle.size = [font pointSize] * aDevPixPerCSSPixel; michael@0: aFontStyle.systemFont = true; michael@0: michael@0: GetStringForNSString([font familyName], aFontName); michael@0: return true; michael@0: michael@0: NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(false); michael@0: }