1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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 #ifndef __LookAndFeel 7 #define __LookAndFeel 8 9 #ifndef MOZILLA_INTERNAL_API 10 #error "This header is only usable from within libxul (MOZILLA_INTERNAL_API)." 11 #endif 12 13 #include "nsDebug.h" 14 #include "nsColor.h" 15 #include "nsTArray.h" 16 17 struct gfxFontStyle; 18 19 struct LookAndFeelInt 20 { 21 int32_t id; 22 int32_t value; 23 }; 24 25 namespace mozilla { 26 27 class LookAndFeel 28 { 29 public: 30 // When modifying this list, also modify nsXPLookAndFeel::sColorPrefs 31 // in widget/xpwidgts/nsXPLookAndFeel.cpp. 32 enum ColorID : uint8_t { 33 34 // WARNING : NO NEGATIVE VALUE IN THIS ENUMERATION 35 // see patch in bug 57757 for more information 36 37 eColorID_WindowBackground, 38 eColorID_WindowForeground, 39 eColorID_WidgetBackground, 40 eColorID_WidgetForeground, 41 eColorID_WidgetSelectBackground, 42 eColorID_WidgetSelectForeground, 43 eColorID_Widget3DHighlight, 44 eColorID_Widget3DShadow, 45 eColorID_TextBackground, 46 eColorID_TextForeground, 47 eColorID_TextSelectBackground, 48 eColorID_TextSelectForeground, 49 eColorID_TextSelectForegroundCustom, 50 eColorID_TextSelectBackgroundDisabled, 51 eColorID_TextSelectBackgroundAttention, 52 eColorID_TextHighlightBackground, 53 eColorID_TextHighlightForeground, 54 55 eColorID_IMERawInputBackground, 56 eColorID_IMERawInputForeground, 57 eColorID_IMERawInputUnderline, 58 eColorID_IMESelectedRawTextBackground, 59 eColorID_IMESelectedRawTextForeground, 60 eColorID_IMESelectedRawTextUnderline, 61 eColorID_IMEConvertedTextBackground, 62 eColorID_IMEConvertedTextForeground, 63 eColorID_IMEConvertedTextUnderline, 64 eColorID_IMESelectedConvertedTextBackground, 65 eColorID_IMESelectedConvertedTextForeground, 66 eColorID_IMESelectedConvertedTextUnderline, 67 68 eColorID_SpellCheckerUnderline, 69 70 // New CSS 2 color definitions 71 eColorID_activeborder, 72 eColorID_activecaption, 73 eColorID_appworkspace, 74 eColorID_background, 75 eColorID_buttonface, 76 eColorID_buttonhighlight, 77 eColorID_buttonshadow, 78 eColorID_buttontext, 79 eColorID_captiontext, 80 eColorID_graytext, 81 eColorID_highlight, 82 eColorID_highlighttext, 83 eColorID_inactiveborder, 84 eColorID_inactivecaption, 85 eColorID_inactivecaptiontext, 86 eColorID_infobackground, 87 eColorID_infotext, 88 eColorID_menu, 89 eColorID_menutext, 90 eColorID_scrollbar, 91 eColorID_threeddarkshadow, 92 eColorID_threedface, 93 eColorID_threedhighlight, 94 eColorID_threedlightshadow, 95 eColorID_threedshadow, 96 eColorID_window, 97 eColorID_windowframe, 98 eColorID_windowtext, 99 100 eColorID__moz_buttondefault, 101 // Colors which will hopefully become CSS3 102 eColorID__moz_field, 103 eColorID__moz_fieldtext, 104 eColorID__moz_dialog, 105 eColorID__moz_dialogtext, 106 // used to highlight valid regions to drop something onto 107 eColorID__moz_dragtargetzone, 108 109 // used to cell text background, selected but not focus 110 eColorID__moz_cellhighlight, 111 // used to cell text, selected but not focus 112 eColorID__moz_cellhighlighttext, 113 // used to html select cell text background, selected but not focus 114 eColorID__moz_html_cellhighlight, 115 // used to html select cell text, selected but not focus 116 eColorID__moz_html_cellhighlighttext, 117 // used to button text background, when mouse is over 118 eColorID__moz_buttonhoverface, 119 // used to button text, when mouse is over 120 eColorID__moz_buttonhovertext, 121 // used to menu item background, when mouse is over 122 eColorID__moz_menuhover, 123 // used to menu item text, when mouse is over 124 eColorID__moz_menuhovertext, 125 // used to menu bar item text 126 eColorID__moz_menubartext, 127 // used to menu bar item text, when mouse is over 128 eColorID__moz_menubarhovertext, 129 // On platforms where these colors are the same as 130 // -moz-field, use -moz-fieldtext as foreground color 131 eColorID__moz_eventreerow, 132 eColorID__moz_oddtreerow, 133 134 // colors needed by the Mac OS X theme 135 136 // foreground color of :hover:active buttons 137 eColorID__moz_mac_buttonactivetext, 138 // background color of chrome toolbars in active windows 139 eColorID__moz_mac_chrome_active, 140 // background color of chrome toolbars in inactive windows 141 eColorID__moz_mac_chrome_inactive, 142 // foreground color of default buttons 143 eColorID__moz_mac_defaultbuttontext, 144 //ring around text fields and lists 145 eColorID__moz_mac_focusring, 146 //colour used when mouse is over a menu item 147 eColorID__moz_mac_menuselect, 148 //colour used to do shadows on menu items 149 eColorID__moz_mac_menushadow, 150 // color used to display text for disabled menu items 151 eColorID__moz_mac_menutextdisable, 152 //colour used to display text while mouse is over a menu item 153 eColorID__moz_mac_menutextselect, 154 // text color of disabled text on toolbars 155 eColorID__moz_mac_disabledtoolbartext, 156 //inactive light hightlight 157 eColorID__moz_mac_secondaryhighlight, 158 159 // vista rebars 160 161 // media rebar text 162 eColorID__moz_win_mediatext, 163 // communications rebar text 164 eColorID__moz_win_communicationstext, 165 166 // Hyperlink color extracted from the system, not affected by the 167 // browser.anchor_color user pref. 168 // There is no OS-specified safe background color for this text, 169 // but it is used regularly within Windows and the Gnome DE on Dialog and 170 // Window colors. 171 eColorID__moz_nativehyperlinktext, 172 173 // Combo box widgets 174 eColorID__moz_comboboxtext, 175 eColorID__moz_combobox, 176 177 // GtkInfoBar 178 eColorID__moz_gtk_info_bar_text, 179 180 // keep this one last, please 181 eColorID_LAST_COLOR 182 }; 183 184 // When modifying this list, also modify nsXPLookAndFeel::sIntPrefs 185 // in widget/xpwidgts/nsXPLookAndFeel.cpp. 186 enum IntID { 187 // default, may be overriden by OS 188 eIntID_CaretBlinkTime, 189 // pixel width of caret 190 eIntID_CaretWidth, 191 // show the caret when text is selected? 192 eIntID_ShowCaretDuringSelection, 193 // select textfields when focused via tab/accesskey? 194 eIntID_SelectTextfieldsOnKeyFocus, 195 // delay before submenus open 196 eIntID_SubmenuDelay, 197 // can popups overlap menu/task bar? 198 eIntID_MenusCanOverlapOSBar, 199 // should overlay scrollbars be used? 200 eIntID_UseOverlayScrollbars, 201 // allow H and V overlay scrollbars to overlap? 202 eIntID_AllowOverlayScrollbarsOverlap, 203 // show/hide scrollbars based on activity 204 eIntID_ShowHideScrollbars, 205 // skip navigating to disabled menu item? 206 eIntID_SkipNavigatingDisabledMenuItem, 207 // begin a drag if the mouse is moved further than the threshold while the 208 // button is down 209 eIntID_DragThresholdX, 210 eIntID_DragThresholdY, 211 // Accessibility theme being used? 212 eIntID_UseAccessibilityTheme, 213 214 // position of scroll arrows in a scrollbar 215 eIntID_ScrollArrowStyle, 216 // is scroll thumb proportional or fixed? 217 eIntID_ScrollSliderStyle, 218 219 // each button can take one of four values: 220 eIntID_ScrollButtonLeftMouseButtonAction, 221 // 0 - scrolls one line, 1 - scrolls one page 222 eIntID_ScrollButtonMiddleMouseButtonAction, 223 // 2 - scrolls to end, 3 - button ignored 224 eIntID_ScrollButtonRightMouseButtonAction, 225 226 // delay for opening spring loaded folders 227 eIntID_TreeOpenDelay, 228 // delay for closing spring loaded folders 229 eIntID_TreeCloseDelay, 230 // delay for triggering the tree scrolling 231 eIntID_TreeLazyScrollDelay, 232 // delay for scrolling the tree 233 eIntID_TreeScrollDelay, 234 // the maximum number of lines to be scrolled at ones 235 eIntID_TreeScrollLinesMax, 236 // What type of tab-order to use 237 eIntID_TabFocusModel, 238 // Should menu items blink when they're chosen? 239 eIntID_ChosenMenuItemsShouldBlink, 240 241 /* 242 * A Boolean value to determine whether the Windows default theme is 243 * being used. 244 * 245 * The value of this metric is not used on other platforms. These platforms 246 * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric. 247 */ 248 eIntID_WindowsDefaultTheme, 249 250 /* 251 * A Boolean value to determine whether the DWM compositor is being used 252 * 253 * This metric is not used on non-Windows platforms. These platforms 254 * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric. 255 */ 256 eIntID_DWMCompositor, 257 258 /* 259 * A Boolean value to determine whether Windows is themed (Classic vs. 260 * uxtheme) 261 * 262 * This is Windows-specific and is not implemented on other platforms 263 * (will return the default of NS_ERROR_FAILURE). 264 */ 265 eIntID_WindowsClassic, 266 267 /* 268 * A Boolean value to determine whether the current Windows desktop theme 269 * supports Aero Glass. 270 * 271 * This is Windows-specific and is not implemented on other platforms 272 * (will return the default of NS_ERROR_FAILURE). 273 */ 274 eIntID_WindowsGlass, 275 276 /* 277 * A Boolean value to determine whether the device is a touch enabled 278 * device. Currently this is only supported by the Windows 7 Touch API. 279 * 280 * Platforms that do not support this metric should return 281 * NS_ERROR_NOT_IMPLEMENTED when queried for this metric. 282 */ 283 eIntID_TouchEnabled, 284 285 /* 286 * A Boolean value to determine whether the Mac graphite theme is 287 * being used. 288 * 289 * The value of this metric is not used on other platforms. These platforms 290 * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric. 291 */ 292 eIntID_MacGraphiteTheme, 293 294 /* 295 * A Boolean value to determine whether the Mac OS X Yosemite-specific theming 296 * should be used. 297 * 298 * The value of this metric is not used on non-Mac platforms. These 299 * platforms should return NS_ERROR_NOT_IMPLEMENTED when queried for this 300 * metric. 301 */ 302 eIntID_MacYosemiteTheme, 303 304 /* 305 * eIntID_AlertNotificationOrigin indicates from which corner of the 306 * screen alerts slide in, and from which direction (horizontal/vertical). 307 * 0, the default, represents bottom right, sliding vertically. 308 * Use any bitwise combination of the following constants: 309 * NS_ALERT_HORIZONTAL (1), NS_ALERT_LEFT (2), NS_ALERT_TOP (4). 310 * 311 * 6 4 312 * +-----------+ 313 * 7| |5 314 * | | 315 * 3| |1 316 * +-----------+ 317 * 2 0 318 */ 319 eIntID_AlertNotificationOrigin, 320 321 /** 322 * If true, clicking on a scrollbar (not as in dragging the thumb) defaults 323 * to scrolling the view corresponding to the clicked point. Otherwise, we 324 * only do so if the scrollbar is clicked using the middle mouse button or 325 * if shift is pressed when the scrollbar is clicked. 326 */ 327 eIntID_ScrollToClick, 328 329 /** 330 * IME and spell checker underline styles, the values should be 331 * NS_DECORATION_LINE_STYLE_*. They are defined below. 332 */ 333 eIntID_IMERawInputUnderlineStyle, 334 eIntID_IMESelectedRawTextUnderlineStyle, 335 eIntID_IMEConvertedTextUnderlineStyle, 336 eIntID_IMESelectedConvertedTextUnderline, 337 eIntID_SpellCheckerUnderlineStyle, 338 339 /** 340 * If this metric != 0, support window dragging on the menubar. 341 */ 342 eIntID_MenuBarDrag, 343 /** 344 * Return the appropriate WindowsThemeIdentifier for the current theme. 345 */ 346 eIntID_WindowsThemeIdentifier, 347 /** 348 * Return an appropriate os version identifier. 349 */ 350 eIntID_OperatingSystemVersionIdentifier, 351 /** 352 * 0: scrollbar button repeats to scroll only when cursor is on the button. 353 * 1: scrollbar button repeats to scroll even if cursor is outside of it. 354 */ 355 eIntID_ScrollbarButtonAutoRepeatBehavior, 356 /** 357 * Delay before showing a tooltip. 358 */ 359 eIntID_TooltipDelay, 360 /* 361 * A Boolean value to determine whether Mac OS X Lion style swipe animations 362 * should be used. 363 */ 364 eIntID_SwipeAnimationEnabled, 365 366 /* 367 * A Boolean value to determine whether we have a color picker available 368 * for <input type="color"> to hook into. 369 * 370 * This lets us selectively enable the style for <input type="color"> 371 * based on whether it's functional or not. 372 */ 373 eIntID_ColorPickerAvailable, 374 375 /* 376 * A boolean value indicating whether or not the device has a hardware 377 * home button. Used on gaia to determine whether a home button 378 * is shown. 379 */ 380 eIntID_PhysicalHomeButton, 381 382 /* 383 * Controls whether overlay scrollbars display when the user moves 384 * the mouse in a scrollable frame. 385 */ 386 eIntID_ScrollbarDisplayOnMouseMove, 387 388 /* 389 * Overlay scrollbar animation constants. 390 */ 391 eIntID_ScrollbarFadeBeginDelay, 392 eIntID_ScrollbarFadeDuration, 393 394 /** 395 * Distance in pixels to offset the context menu from the cursor 396 * on open. 397 */ 398 eIntID_ContextMenuOffsetVertical, 399 eIntID_ContextMenuOffsetHorizontal 400 }; 401 402 /** 403 * Windows themes we currently detect. 404 */ 405 enum WindowsTheme { 406 eWindowsTheme_Generic = 0, // unrecognized theme 407 eWindowsTheme_Classic, 408 eWindowsTheme_Aero, 409 eWindowsTheme_LunaBlue, 410 eWindowsTheme_LunaOlive, 411 eWindowsTheme_LunaSilver, 412 eWindowsTheme_Royale, 413 eWindowsTheme_Zune, 414 eWindowsTheme_AeroLite 415 }; 416 417 /** 418 * Operating system versions. 419 */ 420 enum OperatingSystemVersion { 421 eOperatingSystemVersion_WindowsXP = 0, 422 eOperatingSystemVersion_WindowsVista, 423 eOperatingSystemVersion_Windows7, 424 eOperatingSystemVersion_Windows8, 425 eOperatingSystemVersion_Windows10, 426 eOperatingSystemVersion_Unknown 427 }; 428 429 enum { 430 eScrollArrow_None = 0, 431 eScrollArrow_StartBackward = 0x1000, 432 eScrollArrow_StartForward = 0x0100, 433 eScrollArrow_EndBackward = 0x0010, 434 eScrollArrow_EndForward = 0x0001 435 }; 436 437 enum { 438 // single arrow at each end 439 eScrollArrowStyle_Single = 440 eScrollArrow_StartBackward | eScrollArrow_EndForward, 441 // both arrows at bottom/right, none at top/left 442 eScrollArrowStyle_BothAtBottom = 443 eScrollArrow_EndBackward | eScrollArrow_EndForward, 444 // both arrows at both ends 445 eScrollArrowStyle_BothAtEachEnd = 446 eScrollArrow_EndBackward | eScrollArrow_EndForward | 447 eScrollArrow_StartBackward | eScrollArrow_StartForward, 448 // both arrows at top/left, none at bottom/right 449 eScrollArrowStyle_BothAtTop = 450 eScrollArrow_StartBackward | eScrollArrow_StartForward 451 }; 452 453 enum { 454 eScrollThumbStyle_Normal, 455 eScrollThumbStyle_Proportional 456 }; 457 458 // When modifying this list, also modify nsXPLookAndFeel::sFloatPrefs 459 // in widget/xpwidgts/nsXPLookAndFeel.cpp. 460 enum FloatID { 461 eFloatID_IMEUnderlineRelativeSize, 462 eFloatID_SpellCheckerUnderlineRelativeSize, 463 464 // The width/height ratio of the cursor. If used, the CaretWidth int metric 465 // should be added to the calculated caret width. 466 eFloatID_CaretAspectRatio 467 }; 468 469 // These constants must be kept in 1:1 correspondence with the 470 // NS_STYLE_FONT_* system font constants. 471 enum FontID { 472 eFont_Caption = 1, // css2 473 eFont_Icon, 474 eFont_Menu, 475 eFont_MessageBox, 476 eFont_SmallCaption, 477 eFont_StatusBar, 478 479 eFont_Window, // css3 480 eFont_Document, 481 eFont_Workspace, 482 eFont_Desktop, 483 eFont_Info, 484 eFont_Dialog, 485 eFont_Button, 486 eFont_PullDownMenu, 487 eFont_List, 488 eFont_Field, 489 490 eFont_Tooltips, // moz 491 eFont_Widget 492 }; 493 494 /** 495 * GetColor() return a native color value (might be overwritten by prefs) for 496 * aID. Some platforms don't return an error even if the index doesn't 497 * match any system colors. And also some platforms may initialize the 498 * return value even when it returns an error. Therefore, if you want to 499 * use a color for the default value, you should use the other GetColor() 500 * which returns nscolor directly. 501 * 502 * NOTE: 503 * eColorID_TextSelectForeground might return NS_DONT_CHANGE_COLOR. 504 * eColorID_IME* might return NS_TRANSPARENT, NS_SAME_AS_FOREGROUND_COLOR or 505 * NS_40PERCENT_FOREGROUND_COLOR. 506 * These values have particular meaning. Then, they are not an actual 507 * color value. 508 */ 509 static nsresult GetColor(ColorID aID, nscolor* aResult); 510 511 /** 512 * This variant of GetColor() takes an extra Boolean parameter that allows 513 * the caller to ask that hard-coded color values be substituted for 514 * native colors (used when it is desireable to hide system colors to 515 * avoid system fingerprinting). 516 */ 517 static nsresult GetColor(ColorID aID, bool aUseStandinsForNativeColors, 518 nscolor* aResult); 519 520 /** 521 * GetInt() and GetFloat() return a int or float value for aID. The result 522 * might be distance, time, some flags or a int value which has particular 523 * meaning. See each document at definition of each ID for the detail. 524 * The result is always 0 when they return error. Therefore, if you want to 525 * use a value for the default value, you should use the other method which 526 * returns int or float directly. 527 */ 528 static nsresult GetInt(IntID aID, int32_t* aResult); 529 static nsresult GetFloat(FloatID aID, float* aResult); 530 531 static nscolor GetColor(ColorID aID, nscolor aDefault = NS_RGB(0, 0, 0)) 532 { 533 nscolor result = NS_RGB(0, 0, 0); 534 if (NS_FAILED(GetColor(aID, &result))) { 535 return aDefault; 536 } 537 return result; 538 } 539 540 static int32_t GetInt(IntID aID, int32_t aDefault = 0) 541 { 542 int32_t result; 543 if (NS_FAILED(GetInt(aID, &result))) { 544 return aDefault; 545 } 546 return result; 547 } 548 549 static float GetFloat(FloatID aID, float aDefault = 0.0f) 550 { 551 float result; 552 if (NS_FAILED(GetFloat(aID, &result))) { 553 return aDefault; 554 } 555 return result; 556 } 557 558 /** 559 * Retrieve the name and style of a system-theme font. Returns true 560 * if the system theme specifies this font, false if a default should 561 * be used. In the latter case neither aName nor aStyle is modified. 562 * 563 * @param aID Which system-theme font is wanted. 564 * @param aName The name of the font to use. 565 * @param aStyle Styling to apply to the font. 566 * @param aDevPixPerCSSPixel Ratio of device pixels to CSS pixels 567 */ 568 static bool GetFont(FontID aID, nsString& aName, gfxFontStyle& aStyle, 569 float aDevPixPerCSSPixel); 570 571 /** 572 * GetPasswordCharacter() returns a unicode character which should be used 573 * for a masked character in password editor. E.g., '*'. 574 */ 575 static char16_t GetPasswordCharacter(); 576 577 /** 578 * If the latest character in password field shouldn't be hidden by the 579 * result of GetPasswordCharacter(), GetEchoPassword() returns TRUE. 580 * Otherwise, FALSE. 581 */ 582 static bool GetEchoPassword(); 583 584 /** 585 * The millisecond to mask password value. 586 * This value is only valid when GetEchoPassword() returns true. 587 */ 588 static uint32_t GetPasswordMaskDelay(); 589 590 /** 591 * When system look and feel is changed, Refresh() must be called. Then, 592 * cached data would be released. 593 */ 594 static void Refresh(); 595 596 /** 597 * If the implementation is caching values, these accessors allow the 598 * cache to be exported and imported. 599 */ 600 static nsTArray<LookAndFeelInt> GetIntCache(); 601 static void SetIntCache(const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache); 602 }; 603 604 } // namespace mozilla 605 606 // On the Mac, GetColor(eColorID_TextSelectForeground, color) returns this 607 // constant to specify that the foreground color should not be changed 608 // (ie. a colored text keeps its colors when selected). 609 // Of course if other plaforms work like the Mac, they can use it too. 610 #define NS_DONT_CHANGE_COLOR NS_RGB(0x01, 0x01, 0x01) 611 612 // Similar with NS_DONT_CHANGE_COLOR, except NS_DONT_CHANGE_COLOR would returns 613 // complementary color if fg color is same as bg color. 614 // NS_CHANGE_COLOR_IF_SAME_AS_BG would returns eColorID_TextSelectForegroundCustom if 615 // fg and bg color are the same. 616 #define NS_CHANGE_COLOR_IF_SAME_AS_BG NS_RGB(0x02, 0x02, 0x02) 617 618 // --------------------------------------------------------------------- 619 // Special colors for eColorID_IME* and eColorID_SpellCheckerUnderline 620 // --------------------------------------------------------------------- 621 622 // For background color only. 623 #define NS_TRANSPARENT NS_RGBA(0x01, 0x00, 0x00, 0x00) 624 // For foreground color only. 625 #define NS_SAME_AS_FOREGROUND_COLOR NS_RGBA(0x02, 0x00, 0x00, 0x00) 626 #define NS_40PERCENT_FOREGROUND_COLOR NS_RGBA(0x03, 0x00, 0x00, 0x00) 627 628 #define NS_IS_SELECTION_SPECIAL_COLOR(c) ((c) == NS_TRANSPARENT || \ 629 (c) == NS_SAME_AS_FOREGROUND_COLOR || \ 630 (c) == NS_40PERCENT_FOREGROUND_COLOR) 631 632 // ------------------------------------------ 633 // Bits for eIntID_AlertNotificationOrigin 634 // ------------------------------------------ 635 636 #define NS_ALERT_HORIZONTAL 1 637 #define NS_ALERT_LEFT 2 638 #define NS_ALERT_TOP 4 639 640 #endif /* __LookAndFeel */ 641