Bug 1376625 - Updating meta data for newly added tests r=ato
[gecko.git] / widget / LookAndFeel.h
blob7c4d1006bcb882d154a4c93713b72f32ecf95cdc
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"
15 #include "nsTArray.h"
17 struct gfxFontStyle;
19 struct LookAndFeelInt
21 int32_t id;
22 int32_t value;
25 namespace mozilla {
27 class LookAndFeel
29 public:
30 // When modifying this list, also modify nsXPLookAndFeel::sColorPrefs
31 // in widget/xpwidgts/nsXPLookAndFeel.cpp.
32 enum ColorID : uint8_t {
34 // WARNING : NO NEGATIVE VALUE IN THIS ENUMERATION
35 // see patch in bug 57757 for more information
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,
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,
68 eColorID_SpellCheckerUnderline,
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,
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,
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,
134 // colors needed by the Mac OS X theme
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,
159 // vista rebars
161 // accent color for title bar
162 eColorID__moz_win_accentcolor,
163 // color from drawing text over the accent color
164 eColorID__moz_win_accentcolortext,
165 // media rebar text
166 eColorID__moz_win_mediatext,
167 // communications rebar text
168 eColorID__moz_win_communicationstext,
170 // Hyperlink color extracted from the system, not affected by the
171 // browser.anchor_color user pref.
172 // There is no OS-specified safe background color for this text,
173 // but it is used regularly within Windows and the Gnome DE on Dialog and
174 // Window colors.
175 eColorID__moz_nativehyperlinktext,
177 // Combo box widgets
178 eColorID__moz_comboboxtext,
179 eColorID__moz_combobox,
181 // GtkInfoBar
182 eColorID__moz_gtk_info_bar_text,
184 // keep this one last, please
185 eColorID_LAST_COLOR
188 // When modifying this list, also modify nsXPLookAndFeel::sIntPrefs
189 // in widget/xpwidgts/nsXPLookAndFeel.cpp.
190 enum IntID {
191 // default, may be overriden by OS
192 eIntID_CaretBlinkTime,
193 // pixel width of caret
194 eIntID_CaretWidth,
195 // show the caret when text is selected?
196 eIntID_ShowCaretDuringSelection,
197 // select textfields when focused via tab/accesskey?
198 eIntID_SelectTextfieldsOnKeyFocus,
199 // delay before submenus open
200 eIntID_SubmenuDelay,
201 // can popups overlap menu/task bar?
202 eIntID_MenusCanOverlapOSBar,
203 // should overlay scrollbars be used?
204 eIntID_UseOverlayScrollbars,
205 // allow H and V overlay scrollbars to overlap?
206 eIntID_AllowOverlayScrollbarsOverlap,
207 // show/hide scrollbars based on activity
208 eIntID_ShowHideScrollbars,
209 // skip navigating to disabled menu item?
210 eIntID_SkipNavigatingDisabledMenuItem,
211 // begin a drag if the mouse is moved further than the threshold while the
212 // button is down
213 eIntID_DragThresholdX,
214 eIntID_DragThresholdY,
215 // Accessibility theme being used?
216 eIntID_UseAccessibilityTheme,
218 // position of scroll arrows in a scrollbar
219 eIntID_ScrollArrowStyle,
220 // is scroll thumb proportional or fixed?
221 eIntID_ScrollSliderStyle,
223 // each button can take one of four values:
224 eIntID_ScrollButtonLeftMouseButtonAction,
225 // 0 - scrolls one line, 1 - scrolls one page
226 eIntID_ScrollButtonMiddleMouseButtonAction,
227 // 2 - scrolls to end, 3 - button ignored
228 eIntID_ScrollButtonRightMouseButtonAction,
230 // delay for opening spring loaded folders
231 eIntID_TreeOpenDelay,
232 // delay for closing spring loaded folders
233 eIntID_TreeCloseDelay,
234 // delay for triggering the tree scrolling
235 eIntID_TreeLazyScrollDelay,
236 // delay for scrolling the tree
237 eIntID_TreeScrollDelay,
238 // the maximum number of lines to be scrolled at ones
239 eIntID_TreeScrollLinesMax,
240 // What type of tab-order to use
241 eIntID_TabFocusModel,
242 // Should menu items blink when they're chosen?
243 eIntID_ChosenMenuItemsShouldBlink,
246 * A Boolean value to determine whether the Windows accent color
247 * should be applied to the title bar.
249 * The value of this metric is not used on other platforms. These platforms
250 * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
252 eIntID_WindowsAccentColorInTitlebar,
255 * A Boolean value to determine whether the Windows default theme is
256 * being used.
258 * The value of this metric is not used on other platforms. These platforms
259 * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
261 eIntID_WindowsDefaultTheme,
264 * A Boolean value to determine whether the DWM compositor is being used
266 * This metric is not used on non-Windows platforms. These platforms
267 * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
269 eIntID_DWMCompositor,
272 * A Boolean value to determine whether Windows is themed (Classic vs.
273 * uxtheme)
275 * This is Windows-specific and is not implemented on other platforms
276 * (will return the default of NS_ERROR_FAILURE).
278 eIntID_WindowsClassic,
281 * A Boolean value to determine whether the current Windows desktop theme
282 * supports Aero Glass.
284 * This is Windows-specific and is not implemented on other platforms
285 * (will return the default of NS_ERROR_FAILURE).
287 eIntID_WindowsGlass,
290 * A Boolean value to determine whether the device is a touch enabled
291 * device. Currently this is only supported by the Windows 7 Touch API.
293 * Platforms that do not support this metric should return
294 * NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
296 eIntID_TouchEnabled,
299 * A Boolean value to determine whether the Mac graphite theme is
300 * being used.
302 * The value of this metric is not used on other platforms. These platforms
303 * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
305 eIntID_MacGraphiteTheme,
308 * A Boolean value to determine whether the Mac OS X Yosemite-specific theming
309 * should be used.
311 * The value of this metric is not used on non-Mac platforms. These
312 * platforms should return NS_ERROR_NOT_IMPLEMENTED when queried for this
313 * metric.
315 eIntID_MacYosemiteTheme,
318 * eIntID_AlertNotificationOrigin indicates from which corner of the
319 * screen alerts slide in, and from which direction (horizontal/vertical).
320 * 0, the default, represents bottom right, sliding vertically.
321 * Use any bitwise combination of the following constants:
322 * NS_ALERT_HORIZONTAL (1), NS_ALERT_LEFT (2), NS_ALERT_TOP (4).
324 * 6 4
325 * +-----------+
326 * 7| |5
327 * | |
328 * 3| |1
329 * +-----------+
330 * 2 0
332 eIntID_AlertNotificationOrigin,
335 * If true, clicking on a scrollbar (not as in dragging the thumb) defaults
336 * to scrolling the view corresponding to the clicked point. Otherwise, we
337 * only do so if the scrollbar is clicked using the middle mouse button or
338 * if shift is pressed when the scrollbar is clicked.
340 eIntID_ScrollToClick,
343 * IME and spell checker underline styles, the values should be
344 * NS_DECORATION_LINE_STYLE_*. They are defined below.
346 eIntID_IMERawInputUnderlineStyle,
347 eIntID_IMESelectedRawTextUnderlineStyle,
348 eIntID_IMEConvertedTextUnderlineStyle,
349 eIntID_IMESelectedConvertedTextUnderline,
350 eIntID_SpellCheckerUnderlineStyle,
353 * If this metric != 0, support window dragging on the menubar.
355 eIntID_MenuBarDrag,
357 * Return the appropriate WindowsThemeIdentifier for the current theme.
359 eIntID_WindowsThemeIdentifier,
361 * Return an appropriate os version identifier.
363 eIntID_OperatingSystemVersionIdentifier,
365 * 0: scrollbar button repeats to scroll only when cursor is on the button.
366 * 1: scrollbar button repeats to scroll even if cursor is outside of it.
368 eIntID_ScrollbarButtonAutoRepeatBehavior,
370 * Delay before showing a tooltip.
372 eIntID_TooltipDelay,
374 * A Boolean value to determine whether Mac OS X Lion style swipe animations
375 * should be used.
377 eIntID_SwipeAnimationEnabled,
380 * A Boolean value to determine whether we have a color picker available
381 * for <input type="color"> to hook into.
383 * This lets us selectively enable the style for <input type="color">
384 * based on whether it's functional or not.
386 eIntID_ColorPickerAvailable,
389 * A boolean value indicating whether or not the device has a hardware
390 * home button. Used on gaia to determine whether a home button
391 * is shown.
393 eIntID_PhysicalHomeButton,
396 * Controls whether overlay scrollbars display when the user moves
397 * the mouse in a scrollable frame.
399 eIntID_ScrollbarDisplayOnMouseMove,
402 * Overlay scrollbar animation constants.
404 eIntID_ScrollbarFadeBeginDelay,
405 eIntID_ScrollbarFadeDuration,
408 * Distance in pixels to offset the context menu from the cursor
409 * on open.
411 eIntID_ContextMenuOffsetVertical,
412 eIntID_ContextMenuOffsetHorizontal
416 * Windows themes we currently detect.
418 enum WindowsTheme {
419 eWindowsTheme_Generic = 0, // unrecognized theme
420 eWindowsTheme_Classic,
421 eWindowsTheme_Aero,
422 eWindowsTheme_LunaBlue,
423 eWindowsTheme_LunaOlive,
424 eWindowsTheme_LunaSilver,
425 eWindowsTheme_Royale,
426 eWindowsTheme_Zune,
427 eWindowsTheme_AeroLite
431 * Operating system versions.
433 enum OperatingSystemVersion {
434 eOperatingSystemVersion_Windows7 = 2,
435 eOperatingSystemVersion_Windows8,
436 eOperatingSystemVersion_Windows10,
437 eOperatingSystemVersion_Unknown
440 enum {
441 eScrollArrow_None = 0,
442 eScrollArrow_StartBackward = 0x1000,
443 eScrollArrow_StartForward = 0x0100,
444 eScrollArrow_EndBackward = 0x0010,
445 eScrollArrow_EndForward = 0x0001
448 enum {
449 // single arrow at each end
450 eScrollArrowStyle_Single =
451 eScrollArrow_StartBackward | eScrollArrow_EndForward,
452 // both arrows at bottom/right, none at top/left
453 eScrollArrowStyle_BothAtBottom =
454 eScrollArrow_EndBackward | eScrollArrow_EndForward,
455 // both arrows at both ends
456 eScrollArrowStyle_BothAtEachEnd =
457 eScrollArrow_EndBackward | eScrollArrow_EndForward |
458 eScrollArrow_StartBackward | eScrollArrow_StartForward,
459 // both arrows at top/left, none at bottom/right
460 eScrollArrowStyle_BothAtTop =
461 eScrollArrow_StartBackward | eScrollArrow_StartForward
464 enum {
465 eScrollThumbStyle_Normal,
466 eScrollThumbStyle_Proportional
469 // When modifying this list, also modify nsXPLookAndFeel::sFloatPrefs
470 // in widget/xpwidgts/nsXPLookAndFeel.cpp.
471 enum FloatID {
472 eFloatID_IMEUnderlineRelativeSize,
473 eFloatID_SpellCheckerUnderlineRelativeSize,
475 // The width/height ratio of the cursor. If used, the CaretWidth int metric
476 // should be added to the calculated caret width.
477 eFloatID_CaretAspectRatio
480 // These constants must be kept in 1:1 correspondence with the
481 // NS_STYLE_FONT_* system font constants.
482 enum FontID {
483 eFont_Caption = 1, // css2
484 FontID_MINIMUM = eFont_Caption,
485 eFont_Icon,
486 eFont_Menu,
487 eFont_MessageBox,
488 eFont_SmallCaption,
489 eFont_StatusBar,
491 eFont_Window, // css3
492 eFont_Document,
493 eFont_Workspace,
494 eFont_Desktop,
495 eFont_Info,
496 eFont_Dialog,
497 eFont_Button,
498 eFont_PullDownMenu,
499 eFont_List,
500 eFont_Field,
502 eFont_Tooltips, // moz
503 eFont_Widget,
504 FontID_MAXIMUM = eFont_Widget
508 * GetColor() return a native color value (might be overwritten by prefs) for
509 * aID. Some platforms don't return an error even if the index doesn't
510 * match any system colors. And also some platforms may initialize the
511 * return value even when it returns an error. Therefore, if you want to
512 * use a color for the default value, you should use the other GetColor()
513 * which returns nscolor directly.
515 * NOTE:
516 * eColorID_TextSelectForeground might return NS_DONT_CHANGE_COLOR.
517 * eColorID_IME* might return NS_TRANSPARENT, NS_SAME_AS_FOREGROUND_COLOR or
518 * NS_40PERCENT_FOREGROUND_COLOR.
519 * These values have particular meaning. Then, they are not an actual
520 * color value.
522 static nsresult GetColor(ColorID aID, nscolor* aResult);
525 * This variant of GetColor() takes an extra Boolean parameter that allows
526 * the caller to ask that hard-coded color values be substituted for
527 * native colors (used when it is desireable to hide system colors to
528 * avoid system fingerprinting).
530 static nsresult GetColor(ColorID aID, bool aUseStandinsForNativeColors,
531 nscolor* aResult);
534 * GetInt() and GetFloat() return a int or float value for aID. The result
535 * might be distance, time, some flags or a int value which has particular
536 * meaning. See each document at definition of each ID for the detail.
537 * The result is always 0 when they return error. Therefore, if you want to
538 * use a value for the default value, you should use the other method which
539 * returns int or float directly.
541 static nsresult GetInt(IntID aID, int32_t* aResult);
542 static nsresult GetFloat(FloatID aID, float* aResult);
544 static nscolor GetColor(ColorID aID, nscolor aDefault = NS_RGB(0, 0, 0))
546 nscolor result = NS_RGB(0, 0, 0);
547 if (NS_FAILED(GetColor(aID, &result))) {
548 return aDefault;
550 return result;
553 static nscolor GetColorUsingStandins(ColorID aID,
554 nscolor aDefault = NS_RGB(0, 0, 0))
556 nscolor result = NS_RGB(0, 0, 0);
557 if (NS_FAILED(GetColor(aID,
558 true, // aUseStandinsForNativeColors
559 &result))) {
560 return aDefault;
562 return result;
565 static int32_t GetInt(IntID aID, int32_t aDefault = 0)
567 int32_t result;
568 if (NS_FAILED(GetInt(aID, &result))) {
569 return aDefault;
571 return result;
574 static float GetFloat(FloatID aID, float aDefault = 0.0f)
576 float result;
577 if (NS_FAILED(GetFloat(aID, &result))) {
578 return aDefault;
580 return result;
584 * Retrieve the name and style of a system-theme font. Returns true
585 * if the system theme specifies this font, false if a default should
586 * be used. In the latter case neither aName nor aStyle is modified.
588 * @param aID Which system-theme font is wanted.
589 * @param aName The name of the font to use.
590 * @param aStyle Styling to apply to the font.
591 * @param aDevPixPerCSSPixel Ratio of device pixels to CSS pixels
593 static bool GetFont(FontID aID, nsString& aName, gfxFontStyle& aStyle,
594 float aDevPixPerCSSPixel);
597 * GetPasswordCharacter() returns a unicode character which should be used
598 * for a masked character in password editor. E.g., '*'.
600 static char16_t GetPasswordCharacter();
603 * If the latest character in password field shouldn't be hidden by the
604 * result of GetPasswordCharacter(), GetEchoPassword() returns TRUE.
605 * Otherwise, FALSE.
607 static bool GetEchoPassword();
610 * The millisecond to mask password value.
611 * This value is only valid when GetEchoPassword() returns true.
613 static uint32_t GetPasswordMaskDelay();
616 * When system look and feel is changed, Refresh() must be called. Then,
617 * cached data would be released.
619 static void Refresh();
622 * GTK's initialization code can't be run off main thread, call this
623 * if you plan on using LookAndFeel off main thread later.
625 * This initialized state may get reset due to theme changes, so it
626 * must be called prior to each potential off-main-thread LookAndFeel
627 * call, not just once.
629 static void NativeInit();
632 * If the implementation is caching values, these accessors allow the
633 * cache to be exported and imported.
635 static nsTArray<LookAndFeelInt> GetIntCache();
636 static void SetIntCache(const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache);
639 } // namespace mozilla
641 // On the Mac, GetColor(eColorID_TextSelectForeground, color) returns this
642 // constant to specify that the foreground color should not be changed
643 // (ie. a colored text keeps its colors when selected).
644 // Of course if other plaforms work like the Mac, they can use it too.
645 #define NS_DONT_CHANGE_COLOR NS_RGB(0x01, 0x01, 0x01)
647 // Similar with NS_DONT_CHANGE_COLOR, except NS_DONT_CHANGE_COLOR would returns
648 // complementary color if fg color is same as bg color.
649 // NS_CHANGE_COLOR_IF_SAME_AS_BG would returns eColorID_TextSelectForegroundCustom if
650 // fg and bg color are the same.
651 #define NS_CHANGE_COLOR_IF_SAME_AS_BG NS_RGB(0x02, 0x02, 0x02)
653 // ---------------------------------------------------------------------
654 // Special colors for eColorID_IME* and eColorID_SpellCheckerUnderline
655 // ---------------------------------------------------------------------
657 // For background color only.
658 #define NS_TRANSPARENT NS_RGBA(0x01, 0x00, 0x00, 0x00)
659 // For foreground color only.
660 #define NS_SAME_AS_FOREGROUND_COLOR NS_RGBA(0x02, 0x00, 0x00, 0x00)
661 #define NS_40PERCENT_FOREGROUND_COLOR NS_RGBA(0x03, 0x00, 0x00, 0x00)
663 #define NS_IS_SELECTION_SPECIAL_COLOR(c) ((c) == NS_TRANSPARENT || \
664 (c) == NS_SAME_AS_FOREGROUND_COLOR || \
665 (c) == NS_40PERCENT_FOREGROUND_COLOR)
667 // ------------------------------------------
668 // Bits for eIntID_AlertNotificationOrigin
669 // ------------------------------------------
671 #define NS_ALERT_HORIZONTAL 1
672 #define NS_ALERT_LEFT 2
673 #define NS_ALERT_TOP 4
675 #endif /* __LookAndFeel */