widget/cocoa/nsLookAndFeel.mm

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/cocoa/nsLookAndFeel.mm	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,625 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "nsLookAndFeel.h"
    1.10 +#include "nsCocoaFeatures.h"
    1.11 +#include "nsIServiceManager.h"
    1.12 +#include "nsNativeThemeColors.h"
    1.13 +#include "nsStyleConsts.h"
    1.14 +#include "nsCocoaFeatures.h"
    1.15 +#include "gfxFont.h"
    1.16 +#include "gfxFontConstants.h"
    1.17 +#include "mozilla/gfx/2D.h"
    1.18 +
    1.19 +#import <Cocoa/Cocoa.h>
    1.20 +
    1.21 +// This must be included last:
    1.22 +#include "nsObjCExceptions.h"
    1.23 +
    1.24 +enum {
    1.25 +  mozNSScrollerStyleLegacy       = 0,
    1.26 +  mozNSScrollerStyleOverlay      = 1
    1.27 +};
    1.28 +typedef NSInteger mozNSScrollerStyle;
    1.29 +
    1.30 +@interface NSScroller(AvailableSinceLion)
    1.31 ++ (mozNSScrollerStyle)preferredScrollerStyle;
    1.32 +@end
    1.33 +
    1.34 +nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel()
    1.35 +{
    1.36 +}
    1.37 +
    1.38 +nsLookAndFeel::~nsLookAndFeel()
    1.39 +{
    1.40 +}
    1.41 +
    1.42 +static nscolor GetColorFromNSColor(NSColor* aColor)
    1.43 +{
    1.44 +  NSColor* deviceColor = [aColor colorUsingColorSpaceName:NSDeviceRGBColorSpace];
    1.45 +  return NS_RGB((unsigned int)([deviceColor redComponent] * 255.0),
    1.46 +                (unsigned int)([deviceColor greenComponent] * 255.0),
    1.47 +                (unsigned int)([deviceColor blueComponent] * 255.0));
    1.48 +}
    1.49 +
    1.50 +nsresult
    1.51 +nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
    1.52 +{
    1.53 +  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
    1.54 +
    1.55 +  nsresult res = NS_OK;
    1.56 +  
    1.57 +  switch (aID) {
    1.58 +    case eColorID_WindowBackground:
    1.59 +      aColor = NS_RGB(0xff,0xff,0xff);
    1.60 +      break;
    1.61 +    case eColorID_WindowForeground:
    1.62 +      aColor = NS_RGB(0x00,0x00,0x00);        
    1.63 +      break;
    1.64 +    case eColorID_WidgetBackground:
    1.65 +      aColor = NS_RGB(0xdd,0xdd,0xdd);
    1.66 +      break;
    1.67 +    case eColorID_WidgetForeground:
    1.68 +      aColor = NS_RGB(0x00,0x00,0x00);        
    1.69 +      break;
    1.70 +    case eColorID_WidgetSelectBackground:
    1.71 +      aColor = NS_RGB(0x80,0x80,0x80);
    1.72 +      break;
    1.73 +    case eColorID_WidgetSelectForeground:
    1.74 +      aColor = NS_RGB(0x00,0x00,0x80);
    1.75 +      break;
    1.76 +    case eColorID_Widget3DHighlight:
    1.77 +      aColor = NS_RGB(0xa0,0xa0,0xa0);
    1.78 +      break;
    1.79 +    case eColorID_Widget3DShadow:
    1.80 +      aColor = NS_RGB(0x40,0x40,0x40);
    1.81 +      break;
    1.82 +    case eColorID_TextBackground:
    1.83 +      aColor = NS_RGB(0xff,0xff,0xff);
    1.84 +      break;
    1.85 +    case eColorID_TextForeground:
    1.86 +      aColor = NS_RGB(0x00,0x00,0x00);
    1.87 +      break;
    1.88 +    case eColorID_TextSelectBackground:
    1.89 +      aColor = GetColorFromNSColor([NSColor selectedTextBackgroundColor]);
    1.90 +      break;
    1.91 +    case eColorID_highlight: // CSS2 color
    1.92 +      aColor = GetColorFromNSColor([NSColor alternateSelectedControlColor]);
    1.93 +      break;
    1.94 +    case eColorID__moz_menuhover:
    1.95 +      aColor = GetColorFromNSColor([NSColor alternateSelectedControlColor]);
    1.96 +      break;      
    1.97 +    case eColorID_TextSelectForeground:
    1.98 +      GetColor(eColorID_TextSelectBackground, aColor);
    1.99 +      if (aColor == 0x000000)
   1.100 +        aColor = NS_RGB(0xff,0xff,0xff);
   1.101 +      else
   1.102 +        aColor = NS_DONT_CHANGE_COLOR;
   1.103 +      break;
   1.104 +    case eColorID_highlighttext:  // CSS2 color
   1.105 +    case eColorID__moz_menuhovertext:
   1.106 +      aColor = GetColorFromNSColor([NSColor alternateSelectedControlTextColor]);
   1.107 +      break;
   1.108 +    case eColorID_IMESelectedRawTextBackground:
   1.109 +    case eColorID_IMESelectedConvertedTextBackground:
   1.110 +    case eColorID_IMERawInputBackground:
   1.111 +    case eColorID_IMEConvertedTextBackground:
   1.112 +      aColor = NS_TRANSPARENT;
   1.113 +      break;
   1.114 +    case eColorID_IMESelectedRawTextForeground:
   1.115 +    case eColorID_IMESelectedConvertedTextForeground:
   1.116 +    case eColorID_IMERawInputForeground:
   1.117 +    case eColorID_IMEConvertedTextForeground:
   1.118 +      aColor = NS_SAME_AS_FOREGROUND_COLOR;
   1.119 +      break;
   1.120 +    case eColorID_IMERawInputUnderline:
   1.121 +    case eColorID_IMEConvertedTextUnderline:
   1.122 +      aColor = NS_40PERCENT_FOREGROUND_COLOR;
   1.123 +      break;
   1.124 +    case eColorID_IMESelectedRawTextUnderline:
   1.125 +    case eColorID_IMESelectedConvertedTextUnderline:
   1.126 +      aColor = NS_SAME_AS_FOREGROUND_COLOR;
   1.127 +      break;
   1.128 +    case eColorID_SpellCheckerUnderline:
   1.129 +      aColor = NS_RGB(0xff, 0, 0);
   1.130 +      break;
   1.131 +
   1.132 +      //
   1.133 +      // css2 system colors http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
   1.134 +      //
   1.135 +      // It's really hard to effectively map these to the Appearance Manager properly,
   1.136 +      // since they are modeled word for word after the win32 system colors and don't have any 
   1.137 +      // real counterparts in the Mac world. I'm sure we'll be tweaking these for 
   1.138 +      // years to come. 
   1.139 +      //
   1.140 +      // Thanks to mpt26@student.canterbury.ac.nz for the hardcoded values that form the defaults
   1.141 +      //  if querying the Appearance Manager fails ;)
   1.142 +      //
   1.143 +      
   1.144 +    case eColorID_buttontext:
   1.145 +    case eColorID__moz_buttonhovertext:
   1.146 +      aColor = GetColorFromNSColor([NSColor controlTextColor]);
   1.147 +      break;
   1.148 +    case eColorID_captiontext:
   1.149 +    case eColorID_menutext:
   1.150 +    case eColorID_infotext:
   1.151 +    case eColorID__moz_menubartext:
   1.152 +      aColor = GetColorFromNSColor([NSColor textColor]);
   1.153 +      break;
   1.154 +    case eColorID_windowtext:
   1.155 +      aColor = GetColorFromNSColor([NSColor windowFrameTextColor]);
   1.156 +      break;
   1.157 +    case eColorID_activecaption:
   1.158 +      aColor = GetColorFromNSColor([NSColor gridColor]);
   1.159 +      break;
   1.160 +    case eColorID_activeborder:
   1.161 +      aColor = NS_RGB(0x00,0x00,0x00);
   1.162 +      break;
   1.163 +     case eColorID_appworkspace:
   1.164 +      aColor = NS_RGB(0xFF,0xFF,0xFF);
   1.165 +      break;
   1.166 +    case eColorID_background:
   1.167 +      aColor = NS_RGB(0x63,0x63,0xCE);
   1.168 +      break;
   1.169 +    case eColorID_buttonface:
   1.170 +    case eColorID__moz_buttonhoverface:
   1.171 +      aColor = NS_RGB(0xF0,0xF0,0xF0);
   1.172 +      break;
   1.173 +    case eColorID_buttonhighlight:
   1.174 +      aColor = NS_RGB(0xFF,0xFF,0xFF);
   1.175 +      break;
   1.176 +    case eColorID_buttonshadow:
   1.177 +      aColor = NS_RGB(0xDC,0xDC,0xDC);
   1.178 +      break;
   1.179 +    case eColorID_graytext:
   1.180 +      aColor = GetColorFromNSColor([NSColor disabledControlTextColor]);
   1.181 +      break;
   1.182 +    case eColorID_inactiveborder:
   1.183 +      aColor = GetColorFromNSColor([NSColor controlBackgroundColor]);
   1.184 +      break;
   1.185 +    case eColorID_inactivecaption:
   1.186 +      aColor = GetColorFromNSColor([NSColor controlBackgroundColor]);
   1.187 +      break;
   1.188 +    case eColorID_inactivecaptiontext:
   1.189 +      aColor = NS_RGB(0x45,0x45,0x45);
   1.190 +      break;
   1.191 +    case eColorID_scrollbar:
   1.192 +      aColor = GetColorFromNSColor([NSColor scrollBarColor]);
   1.193 +      break;
   1.194 +    case eColorID_threeddarkshadow:
   1.195 +      aColor = NS_RGB(0xDC,0xDC,0xDC);
   1.196 +      break;
   1.197 +    case eColorID_threedshadow:
   1.198 +      aColor = NS_RGB(0xE0,0xE0,0xE0);
   1.199 +      break;
   1.200 +    case eColorID_threedface:
   1.201 +      aColor = NS_RGB(0xF0,0xF0,0xF0);
   1.202 +      break;
   1.203 +    case eColorID_threedhighlight:
   1.204 +      aColor = GetColorFromNSColor([NSColor highlightColor]);
   1.205 +      break;
   1.206 +    case eColorID_threedlightshadow:
   1.207 +      aColor = NS_RGB(0xDA,0xDA,0xDA);
   1.208 +      break;
   1.209 +    case eColorID_menu:
   1.210 +      aColor = GetColorFromNSColor([NSColor alternateSelectedControlTextColor]);
   1.211 +      break;
   1.212 +    case eColorID_infobackground:
   1.213 +      aColor = NS_RGB(0xFF,0xFF,0xC7);
   1.214 +      break;
   1.215 +    case eColorID_windowframe:
   1.216 +      aColor = GetColorFromNSColor([NSColor gridColor]);
   1.217 +      break;
   1.218 +    case eColorID_window:
   1.219 +    case eColorID__moz_field:
   1.220 +    case eColorID__moz_combobox:
   1.221 +      aColor = NS_RGB(0xff,0xff,0xff);
   1.222 +      break;
   1.223 +    case eColorID__moz_fieldtext:
   1.224 +    case eColorID__moz_comboboxtext:
   1.225 +      aColor = GetColorFromNSColor([NSColor controlTextColor]);
   1.226 +      break;
   1.227 +    case eColorID__moz_dialog:
   1.228 +      aColor = GetColorFromNSColor([NSColor controlHighlightColor]);
   1.229 +      break;
   1.230 +    case eColorID__moz_dialogtext:
   1.231 +    case eColorID__moz_cellhighlighttext:
   1.232 +    case eColorID__moz_html_cellhighlighttext:
   1.233 +      aColor = GetColorFromNSColor([NSColor controlTextColor]);
   1.234 +      break;
   1.235 +    case eColorID__moz_dragtargetzone:
   1.236 +      aColor = GetColorFromNSColor([NSColor selectedControlColor]);
   1.237 +      break;
   1.238 +    case eColorID__moz_mac_chrome_active:
   1.239 +    case eColorID__moz_mac_chrome_inactive: {
   1.240 +      int grey = NativeGreyColorAsInt(toolbarFillGrey, (aID == eColorID__moz_mac_chrome_active));
   1.241 +      aColor = NS_RGB(grey, grey, grey);
   1.242 +    }
   1.243 +      break;
   1.244 +    case eColorID__moz_mac_focusring:
   1.245 +      aColor = GetColorFromNSColor([NSColor keyboardFocusIndicatorColor]);
   1.246 +      break;
   1.247 +    case eColorID__moz_mac_menushadow:
   1.248 +      aColor = NS_RGB(0xA3,0xA3,0xA3);
   1.249 +      break;          
   1.250 +    case eColorID__moz_mac_menutextdisable:
   1.251 +      aColor = NS_RGB(0x88,0x88,0x88);
   1.252 +      break;      
   1.253 +    case eColorID__moz_mac_menutextselect:
   1.254 +      aColor = GetColorFromNSColor([NSColor selectedMenuItemTextColor]);
   1.255 +      break;      
   1.256 +    case eColorID__moz_mac_disabledtoolbartext:
   1.257 +      aColor = GetColorFromNSColor([NSColor disabledControlTextColor]);
   1.258 +      break;
   1.259 +    case eColorID__moz_mac_menuselect:
   1.260 +      aColor = GetColorFromNSColor([NSColor alternateSelectedControlColor]);
   1.261 +      break;
   1.262 +    case eColorID__moz_buttondefault:
   1.263 +      aColor = NS_RGB(0xDC,0xDC,0xDC);
   1.264 +      break;
   1.265 +    case eColorID__moz_cellhighlight:
   1.266 +    case eColorID__moz_html_cellhighlight:
   1.267 +    case eColorID__moz_mac_secondaryhighlight:
   1.268 +      // For inactive list selection
   1.269 +      aColor = GetColorFromNSColor([NSColor secondarySelectedControlColor]);
   1.270 +      break;
   1.271 +    case eColorID__moz_eventreerow:
   1.272 +      // Background color of even list rows.
   1.273 +      aColor = GetColorFromNSColor([[NSColor controlAlternatingRowBackgroundColors] objectAtIndex:0]);
   1.274 +      break;
   1.275 +    case eColorID__moz_oddtreerow:
   1.276 +      // Background color of odd list rows.
   1.277 +      aColor = GetColorFromNSColor([[NSColor controlAlternatingRowBackgroundColors] objectAtIndex:1]);
   1.278 +      break;
   1.279 +    case eColorID__moz_nativehyperlinktext:
   1.280 +      // There appears to be no available system defined color. HARDCODING to the appropriate color.
   1.281 +      aColor = NS_RGB(0x14,0x4F,0xAE);
   1.282 +      break;
   1.283 +    default:
   1.284 +      NS_WARNING("Someone asked nsILookAndFeel for a color I don't know about");
   1.285 +      aColor = NS_RGB(0xff,0xff,0xff);
   1.286 +      res = NS_ERROR_FAILURE;
   1.287 +      break;
   1.288 +    }
   1.289 +  
   1.290 +  return res;
   1.291 +
   1.292 +  NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
   1.293 +}
   1.294 +
   1.295 +nsresult
   1.296 +nsLookAndFeel::GetIntImpl(IntID aID, int32_t &aResult)
   1.297 +{
   1.298 +  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
   1.299 +
   1.300 +  nsresult res = nsXPLookAndFeel::GetIntImpl(aID, aResult);
   1.301 +  if (NS_SUCCEEDED(res))
   1.302 +    return res;
   1.303 +  res = NS_OK;
   1.304 +  
   1.305 +  switch (aID) {
   1.306 +    case eIntID_CaretBlinkTime:
   1.307 +      aResult = 567;
   1.308 +      break;
   1.309 +    case eIntID_CaretWidth:
   1.310 +      aResult = 1;
   1.311 +      break;
   1.312 +    case eIntID_ShowCaretDuringSelection:
   1.313 +      aResult = 0;
   1.314 +      break;
   1.315 +    case eIntID_SelectTextfieldsOnKeyFocus:
   1.316 +      // Select textfield content when focused by kbd
   1.317 +      // used by EventStateManager::sTextfieldSelectModel
   1.318 +      aResult = 1;
   1.319 +      break;
   1.320 +    case eIntID_SubmenuDelay:
   1.321 +      aResult = 200;
   1.322 +      break;
   1.323 +    case eIntID_TooltipDelay:
   1.324 +      aResult = 500;
   1.325 +      break;
   1.326 +    case eIntID_MenusCanOverlapOSBar:
   1.327 +      // xul popups are not allowed to overlap the menubar.
   1.328 +      aResult = 0;
   1.329 +      break;
   1.330 +    case eIntID_SkipNavigatingDisabledMenuItem:
   1.331 +      aResult = 1;
   1.332 +      break;
   1.333 +    case eIntID_DragThresholdX:
   1.334 +    case eIntID_DragThresholdY:
   1.335 +      aResult = 4;
   1.336 +      break;
   1.337 +    case eIntID_ScrollArrowStyle:
   1.338 +      if (nsCocoaFeatures::OnLionOrLater()) {
   1.339 +        // OS X Lion's scrollbars have no arrows
   1.340 +        aResult = eScrollArrow_None;
   1.341 +      } else {
   1.342 +        NSString *buttonPlacement = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleScrollBarVariant"];
   1.343 +        if ([buttonPlacement isEqualToString:@"Single"]) {
   1.344 +          aResult = eScrollArrowStyle_Single;
   1.345 +        } else if ([buttonPlacement isEqualToString:@"DoubleMin"]) {
   1.346 +          aResult = eScrollArrowStyle_BothAtTop;
   1.347 +        } else if ([buttonPlacement isEqualToString:@"DoubleBoth"]) {
   1.348 +          aResult = eScrollArrowStyle_BothAtEachEnd;
   1.349 +        } else {
   1.350 +          aResult = eScrollArrowStyle_BothAtBottom; // The default is BothAtBottom.
   1.351 +        }
   1.352 +      }
   1.353 +      break;
   1.354 +    case eIntID_ScrollSliderStyle:
   1.355 +      aResult = eScrollThumbStyle_Proportional;
   1.356 +      break;
   1.357 +    case eIntID_UseOverlayScrollbars:
   1.358 +      aResult = SystemWantsOverlayScrollbars() ? 1 : 0;
   1.359 +      break;
   1.360 +    case eIntID_AllowOverlayScrollbarsOverlap:
   1.361 +      aResult = AllowOverlayScrollbarsOverlap() ? 1 : 0;
   1.362 +      break;
   1.363 +    case eIntID_ScrollbarDisplayOnMouseMove:
   1.364 +      aResult = 0;
   1.365 +      break;
   1.366 +    case eIntID_ScrollbarFadeBeginDelay:
   1.367 +      aResult = 450;
   1.368 +      break;
   1.369 +    case eIntID_ScrollbarFadeDuration:
   1.370 +      aResult = 200;
   1.371 +      break;
   1.372 +    case eIntID_TreeOpenDelay:
   1.373 +      aResult = 1000;
   1.374 +      break;
   1.375 +    case eIntID_TreeCloseDelay:
   1.376 +      aResult = 1000;
   1.377 +      break;
   1.378 +    case eIntID_TreeLazyScrollDelay:
   1.379 +      aResult = 150;
   1.380 +      break;
   1.381 +    case eIntID_TreeScrollDelay:
   1.382 +      aResult = 100;
   1.383 +      break;
   1.384 +    case eIntID_TreeScrollLinesMax:
   1.385 +      aResult = 3;
   1.386 +      break;
   1.387 +    case eIntID_DWMCompositor:
   1.388 +    case eIntID_WindowsClassic:
   1.389 +    case eIntID_WindowsDefaultTheme:
   1.390 +    case eIntID_TouchEnabled:
   1.391 +    case eIntID_WindowsThemeIdentifier:
   1.392 +    case eIntID_OperatingSystemVersionIdentifier:
   1.393 +      aResult = 0;
   1.394 +      res = NS_ERROR_NOT_IMPLEMENTED;
   1.395 +      break;
   1.396 +    case eIntID_MacGraphiteTheme:
   1.397 +      aResult = [NSColor currentControlTint] == NSGraphiteControlTint;
   1.398 +      break;
   1.399 +    case eIntID_MacLionTheme:
   1.400 +      aResult = nsCocoaFeatures::OnLionOrLater();
   1.401 +      break;
   1.402 +    case eIntID_AlertNotificationOrigin:
   1.403 +      aResult = NS_ALERT_TOP;
   1.404 +      break;
   1.405 +    case eIntID_TabFocusModel:
   1.406 +    {
   1.407 +      // we should probably cache this
   1.408 +      CFPropertyListRef fullKeyboardAccessProperty;
   1.409 +      fullKeyboardAccessProperty = ::CFPreferencesCopyValue(CFSTR("AppleKeyboardUIMode"),
   1.410 +                                                            kCFPreferencesAnyApplication,
   1.411 +                                                            kCFPreferencesCurrentUser,
   1.412 +                                                            kCFPreferencesAnyHost);
   1.413 +      aResult = 1;    // default to just textboxes
   1.414 +      if (fullKeyboardAccessProperty) {
   1.415 +        int32_t fullKeyboardAccessPrefVal;
   1.416 +        if (::CFNumberGetValue((CFNumberRef) fullKeyboardAccessProperty, kCFNumberIntType, &fullKeyboardAccessPrefVal)) {
   1.417 +          // the second bit means  "Full keyboard access" is on
   1.418 +          if (fullKeyboardAccessPrefVal & (1 << 1))
   1.419 +            aResult = 7; // everything that can be focused
   1.420 +        }
   1.421 +        ::CFRelease(fullKeyboardAccessProperty);
   1.422 +      }
   1.423 +    }
   1.424 +      break;
   1.425 +    case eIntID_ScrollToClick:
   1.426 +    {
   1.427 +      aResult = [[NSUserDefaults standardUserDefaults] boolForKey:@"AppleScrollerPagingBehavior"];
   1.428 +    }
   1.429 +      break;
   1.430 +    case eIntID_ChosenMenuItemsShouldBlink:
   1.431 +      aResult = 1;
   1.432 +      break;
   1.433 +    case eIntID_IMERawInputUnderlineStyle:
   1.434 +    case eIntID_IMEConvertedTextUnderlineStyle:
   1.435 +    case eIntID_IMESelectedRawTextUnderlineStyle:
   1.436 +    case eIntID_IMESelectedConvertedTextUnderline:
   1.437 +      aResult = NS_STYLE_TEXT_DECORATION_STYLE_SOLID;
   1.438 +      break;
   1.439 +    case eIntID_SpellCheckerUnderlineStyle:
   1.440 +      aResult = NS_STYLE_TEXT_DECORATION_STYLE_DOTTED;
   1.441 +      break;
   1.442 +    case eIntID_ScrollbarButtonAutoRepeatBehavior:
   1.443 +      aResult = 0;
   1.444 +      break;
   1.445 +    case eIntID_SwipeAnimationEnabled:
   1.446 +      aResult = 0;
   1.447 +      if ([NSEvent respondsToSelector:@selector(
   1.448 +            isSwipeTrackingFromScrollEventsEnabled)]) {
   1.449 +        aResult = [NSEvent isSwipeTrackingFromScrollEventsEnabled] ? 1 : 0;
   1.450 +      }
   1.451 +      break;
   1.452 +    case eIntID_ColorPickerAvailable:
   1.453 +      aResult = 1;
   1.454 +      break;
   1.455 +    default:
   1.456 +      aResult = 0;
   1.457 +      res = NS_ERROR_FAILURE;
   1.458 +  }
   1.459 +  return res;
   1.460 +
   1.461 +  NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
   1.462 +}
   1.463 +
   1.464 +nsresult
   1.465 +nsLookAndFeel::GetFloatImpl(FloatID aID, float &aResult)
   1.466 +{
   1.467 +  nsresult res = nsXPLookAndFeel::GetFloatImpl(aID, aResult);
   1.468 +  if (NS_SUCCEEDED(res))
   1.469 +    return res;
   1.470 +  res = NS_OK;
   1.471 +  
   1.472 +  switch (aID) {
   1.473 +    case eFloatID_IMEUnderlineRelativeSize:
   1.474 +      aResult = 2.0f;
   1.475 +      break;
   1.476 +    case eFloatID_SpellCheckerUnderlineRelativeSize:
   1.477 +      aResult = 2.0f;
   1.478 +      break;
   1.479 +    default:
   1.480 +      aResult = -1.0;
   1.481 +      res = NS_ERROR_FAILURE;
   1.482 +  }
   1.483 +
   1.484 +  return res;
   1.485 +}
   1.486 +
   1.487 +bool nsLookAndFeel::UseOverlayScrollbars()
   1.488 +{
   1.489 +  return GetInt(eIntID_UseOverlayScrollbars) != 0;
   1.490 +}
   1.491 +
   1.492 +bool nsLookAndFeel::SystemWantsOverlayScrollbars()
   1.493 +{
   1.494 +  return ([NSScroller respondsToSelector:@selector(preferredScrollerStyle)] &&
   1.495 +          [NSScroller preferredScrollerStyle] == mozNSScrollerStyleOverlay);
   1.496 +}
   1.497 +
   1.498 +bool nsLookAndFeel::AllowOverlayScrollbarsOverlap()
   1.499 +{
   1.500 +  return (UseOverlayScrollbars() && nsCocoaFeatures::OnMountainLionOrLater());
   1.501 +}
   1.502 +
   1.503 +// copied from gfxQuartzFontCache.mm, maybe should go in a Cocoa utils
   1.504 +// file somewhere
   1.505 +static void GetStringForNSString(const NSString *aSrc, nsAString& aDest)
   1.506 +{
   1.507 +    aDest.SetLength([aSrc length]);
   1.508 +    [aSrc getCharacters:reinterpret_cast<unichar*>(aDest.BeginWriting())];
   1.509 +}
   1.510 +
   1.511 +bool
   1.512 +nsLookAndFeel::GetFontImpl(FontID aID, nsString &aFontName,
   1.513 +                           gfxFontStyle &aFontStyle,
   1.514 +                           float aDevPixPerCSSPixel)
   1.515 +{
   1.516 +    NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
   1.517 +
   1.518 +    // hack for now
   1.519 +    if (aID == eFont_Window || aID == eFont_Document) {
   1.520 +        aFontStyle.style      = NS_FONT_STYLE_NORMAL;
   1.521 +        aFontStyle.weight     = NS_FONT_WEIGHT_NORMAL;
   1.522 +        aFontStyle.stretch    = NS_FONT_STRETCH_NORMAL;
   1.523 +        aFontStyle.size       = 14 * aDevPixPerCSSPixel;
   1.524 +        aFontStyle.systemFont = true;
   1.525 +
   1.526 +        aFontName.AssignLiteral("sans-serif");
   1.527 +        return true;
   1.528 +    }
   1.529 +
   1.530 +/* possibilities, see NSFont Class Reference:
   1.531 +    [NSFont boldSystemFontOfSize:     0.0]
   1.532 +    [NSFont controlContentFontOfSize: 0.0]
   1.533 +    [NSFont labelFontOfSize:          0.0]
   1.534 +    [NSFont menuBarFontOfSize:        0.0]
   1.535 +    [NSFont menuFontOfSize:           0.0]
   1.536 +    [NSFont messageFontOfSize:        0.0]
   1.537 +    [NSFont paletteFontOfSize:        0.0]
   1.538 +    [NSFont systemFontOfSize:         0.0]
   1.539 +    [NSFont titleBarFontOfSize:       0.0]
   1.540 +    [NSFont toolTipsFontOfSize:       0.0]
   1.541 +    [NSFont userFixedPitchFontOfSize: 0.0]
   1.542 +    [NSFont userFontOfSize:           0.0]
   1.543 +    [NSFont systemFontOfSize:         [NSFont smallSystemFontSize]]
   1.544 +    [NSFont boldSystemFontOfSize:     [NSFont smallSystemFontSize]]
   1.545 +*/
   1.546 +
   1.547 +    NSFont *font = nullptr;
   1.548 +    switch (aID) {
   1.549 +        // css2
   1.550 +        case eFont_Caption:
   1.551 +            font = [NSFont systemFontOfSize:0.0];
   1.552 +            break;
   1.553 +        case eFont_Icon: // used in urlbar; tried labelFont, but too small
   1.554 +            font = [NSFont controlContentFontOfSize:0.0];
   1.555 +            break;
   1.556 +        case eFont_Menu:
   1.557 +            font = [NSFont systemFontOfSize:0.0];
   1.558 +            break;
   1.559 +        case eFont_MessageBox:
   1.560 +            font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
   1.561 +            break;
   1.562 +        case eFont_SmallCaption:
   1.563 +            font = [NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]];
   1.564 +            break;
   1.565 +        case eFont_StatusBar:
   1.566 +            font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
   1.567 +            break;
   1.568 +        // css3
   1.569 +        //case eFont_Window:     = 'sans-serif'
   1.570 +        //case eFont_Document:   = 'sans-serif'
   1.571 +        case eFont_Workspace:
   1.572 +            font = [NSFont controlContentFontOfSize:0.0];
   1.573 +            break;
   1.574 +        case eFont_Desktop:
   1.575 +            font = [NSFont controlContentFontOfSize:0.0];
   1.576 +            break;
   1.577 +        case eFont_Info:
   1.578 +            font = [NSFont controlContentFontOfSize:0.0];
   1.579 +            break;
   1.580 +        case eFont_Dialog:
   1.581 +            font = [NSFont systemFontOfSize:0.0];
   1.582 +            break;
   1.583 +        case eFont_Button:
   1.584 +            font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
   1.585 +            break;
   1.586 +        case eFont_PullDownMenu:
   1.587 +            font = [NSFont menuBarFontOfSize:0.0];
   1.588 +            break;
   1.589 +        case eFont_List:
   1.590 +            font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
   1.591 +            break;
   1.592 +        case eFont_Field:
   1.593 +            font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
   1.594 +            break;
   1.595 +        // moz
   1.596 +        case eFont_Tooltips:
   1.597 +            font = [NSFont toolTipsFontOfSize:0.0];
   1.598 +            break;
   1.599 +        case eFont_Widget:
   1.600 +            font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
   1.601 +            break;
   1.602 +        default:
   1.603 +            break;
   1.604 +    }
   1.605 +
   1.606 +    if (!font) {
   1.607 +        NS_WARNING("failed to find a system font!");
   1.608 +        return false;
   1.609 +    }
   1.610 +
   1.611 +    NSFontSymbolicTraits traits = [[font fontDescriptor] symbolicTraits];
   1.612 +    aFontStyle.style =
   1.613 +        (traits & NSFontItalicTrait) ?  NS_FONT_STYLE_ITALIC : NS_FONT_STYLE_NORMAL;
   1.614 +    aFontStyle.weight =
   1.615 +        (traits & NSFontBoldTrait) ? NS_FONT_WEIGHT_BOLD : NS_FONT_WEIGHT_NORMAL;
   1.616 +    aFontStyle.stretch =
   1.617 +        (traits & NSFontExpandedTrait) ?
   1.618 +            NS_FONT_STRETCH_EXPANDED : (traits & NSFontCondensedTrait) ?
   1.619 +                NS_FONT_STRETCH_CONDENSED : NS_FONT_STRETCH_NORMAL;
   1.620 +    // convert size from css pixels to device pixels
   1.621 +    aFontStyle.size = [font pointSize] * aDevPixPerCSSPixel;
   1.622 +    aFontStyle.systemFont = true;
   1.623 +
   1.624 +    GetStringForNSString([font familyName], aFontName);
   1.625 +    return true;
   1.626 +
   1.627 +    NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(false);
   1.628 +}

mercurial