widget/cocoa/nsLookAndFeel.mm

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial