widget/LookAndFeel.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial