Bumping manifests a=b2g-bump
[gecko.git] / widget / LookAndFeel.h
blobe0283eaa4b7e89923277c3221f7320904b9b0aae
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
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_TextSelectForegroundCustom,
43 eColorID_TextSelectBackgroundDisabled,
44 eColorID_TextSelectBackgroundAttention,
45 eColorID_TextHighlightBackground,
46 eColorID_TextHighlightForeground,
48 eColorID_IMERawInputBackground,
49 eColorID_IMERawInputForeground,
50 eColorID_IMERawInputUnderline,
51 eColorID_IMESelectedRawTextBackground,
52 eColorID_IMESelectedRawTextForeground,
53 eColorID_IMESelectedRawTextUnderline,
54 eColorID_IMEConvertedTextBackground,
55 eColorID_IMEConvertedTextForeground,
56 eColorID_IMEConvertedTextUnderline,
57 eColorID_IMESelectedConvertedTextBackground,
58 eColorID_IMESelectedConvertedTextForeground,
59 eColorID_IMESelectedConvertedTextUnderline,
61 eColorID_SpellCheckerUnderline,
63 // New CSS 2 color definitions
64 eColorID_activeborder,
65 eColorID_activecaption,
66 eColorID_appworkspace,
67 eColorID_background,
68 eColorID_buttonface,
69 eColorID_buttonhighlight,
70 eColorID_buttonshadow,
71 eColorID_buttontext,
72 eColorID_captiontext,
73 eColorID_graytext,
74 eColorID_highlight,
75 eColorID_highlighttext,
76 eColorID_inactiveborder,
77 eColorID_inactivecaption,
78 eColorID_inactivecaptiontext,
79 eColorID_infobackground,
80 eColorID_infotext,
81 eColorID_menu,
82 eColorID_menutext,
83 eColorID_scrollbar,
84 eColorID_threeddarkshadow,
85 eColorID_threedface,
86 eColorID_threedhighlight,
87 eColorID_threedlightshadow,
88 eColorID_threedshadow,
89 eColorID_window,
90 eColorID_windowframe,
91 eColorID_windowtext,
93 eColorID__moz_buttondefault,
94 // Colors which will hopefully become CSS3
95 eColorID__moz_field,
96 eColorID__moz_fieldtext,
97 eColorID__moz_dialog,
98 eColorID__moz_dialogtext,
99 // used to highlight valid regions to drop something onto
100 eColorID__moz_dragtargetzone,
102 // used to cell text background, selected but not focus
103 eColorID__moz_cellhighlight,
104 // used to cell text, selected but not focus
105 eColorID__moz_cellhighlighttext,
106 // used to html select cell text background, selected but not focus
107 eColorID__moz_html_cellhighlight,
108 // used to html select cell text, selected but not focus
109 eColorID__moz_html_cellhighlighttext,
110 // used to button text background, when mouse is over
111 eColorID__moz_buttonhoverface,
112 // used to button text, when mouse is over
113 eColorID__moz_buttonhovertext,
114 // used to menu item background, when mouse is over
115 eColorID__moz_menuhover,
116 // used to menu item text, when mouse is over
117 eColorID__moz_menuhovertext,
118 // used to menu bar item text
119 eColorID__moz_menubartext,
120 // used to menu bar item text, when mouse is over
121 eColorID__moz_menubarhovertext,
122 // On platforms where these colors are the same as
123 // -moz-field, use -moz-fieldtext as foreground color
124 eColorID__moz_eventreerow,
125 eColorID__moz_oddtreerow,
127 // colors needed by the Mac OS X theme
129 // foreground color of :hover:active buttons
130 eColorID__moz_mac_buttonactivetext,
131 // background color of chrome toolbars in active windows
132 eColorID__moz_mac_chrome_active,
133 // background color of chrome toolbars in inactive windows
134 eColorID__moz_mac_chrome_inactive,
135 // foreground color of default buttons
136 eColorID__moz_mac_defaultbuttontext,
137 //ring around text fields and lists
138 eColorID__moz_mac_focusring,
139 //colour used when mouse is over a menu item
140 eColorID__moz_mac_menuselect,
141 //colour used to do shadows on menu items
142 eColorID__moz_mac_menushadow,
143 // color used to display text for disabled menu items
144 eColorID__moz_mac_menutextdisable,
145 //colour used to display text while mouse is over a menu item
146 eColorID__moz_mac_menutextselect,
147 // text color of disabled text on toolbars
148 eColorID__moz_mac_disabledtoolbartext,
149 //inactive light hightlight
150 eColorID__moz_mac_secondaryhighlight,
152 // vista rebars
154 // media rebar text
155 eColorID__moz_win_mediatext,
156 // communications rebar text
157 eColorID__moz_win_communicationstext,
159 // Hyperlink color extracted from the system, not affected by the
160 // browser.anchor_color user pref.
161 // There is no OS-specified safe background color for this text,
162 // but it is used regularly within Windows and the Gnome DE on Dialog and
163 // Window colors.
164 eColorID__moz_nativehyperlinktext,
166 // Combo box widgets
167 eColorID__moz_comboboxtext,
168 eColorID__moz_combobox,
170 // keep this one last, please
171 eColorID_LAST_COLOR
174 // When modifying this list, also modify nsXPLookAndFeel::sIntPrefs
175 // in widget/xpwidgts/nsXPLookAndFeel.cpp.
176 enum IntID {
177 // default, may be overriden by OS
178 eIntID_CaretBlinkTime,
179 // pixel width of caret
180 eIntID_CaretWidth,
181 // show the caret when text is selected?
182 eIntID_ShowCaretDuringSelection,
183 // select textfields when focused via tab/accesskey?
184 eIntID_SelectTextfieldsOnKeyFocus,
185 // delay before submenus open
186 eIntID_SubmenuDelay,
187 // can popups overlap menu/task bar?
188 eIntID_MenusCanOverlapOSBar,
189 // should overlay scrollbars be used?
190 eIntID_UseOverlayScrollbars,
191 // allow H and V overlay scrollbars to overlap?
192 eIntID_AllowOverlayScrollbarsOverlap,
193 // show/hide scrollbars based on activity
194 eIntID_ShowHideScrollbars,
195 // skip navigating to disabled menu item?
196 eIntID_SkipNavigatingDisabledMenuItem,
197 // begin a drag if the mouse is moved further than the threshold while the
198 // button is down
199 eIntID_DragThresholdX,
200 eIntID_DragThresholdY,
201 // Accessibility theme being used?
202 eIntID_UseAccessibilityTheme,
204 // position of scroll arrows in a scrollbar
205 eIntID_ScrollArrowStyle,
206 // is scroll thumb proportional or fixed?
207 eIntID_ScrollSliderStyle,
209 // each button can take one of four values:
210 eIntID_ScrollButtonLeftMouseButtonAction,
211 // 0 - scrolls one line, 1 - scrolls one page
212 eIntID_ScrollButtonMiddleMouseButtonAction,
213 // 2 - scrolls to end, 3 - button ignored
214 eIntID_ScrollButtonRightMouseButtonAction,
216 // delay for opening spring loaded folders
217 eIntID_TreeOpenDelay,
218 // delay for closing spring loaded folders
219 eIntID_TreeCloseDelay,
220 // delay for triggering the tree scrolling
221 eIntID_TreeLazyScrollDelay,
222 // delay for scrolling the tree
223 eIntID_TreeScrollDelay,
224 // the maximum number of lines to be scrolled at ones
225 eIntID_TreeScrollLinesMax,
226 // What type of tab-order to use
227 eIntID_TabFocusModel,
228 // Should menu items blink when they're chosen?
229 eIntID_ChosenMenuItemsShouldBlink,
232 * A Boolean value to determine whether the Windows default theme is
233 * being used.
235 * The value of this metric is not used on other platforms. These platforms
236 * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
238 eIntID_WindowsDefaultTheme,
241 * A Boolean value to determine whether the DWM compositor is being used
243 * This metric is not used on non-Windows platforms. These platforms
244 * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
246 eIntID_DWMCompositor,
249 * A Boolean value to determine whether Windows is themed (Classic vs.
250 * uxtheme)
252 * This is Windows-specific and is not implemented on other platforms
253 * (will return the default of NS_ERROR_FAILURE).
255 eIntID_WindowsClassic,
258 * A Boolean value to determine whether the current Windows desktop theme
259 * supports Aero Glass.
261 * This is Windows-specific and is not implemented on other platforms
262 * (will return the default of NS_ERROR_FAILURE).
264 eIntID_WindowsGlass,
267 * A Boolean value to determine whether the device is a touch enabled
268 * device. Currently this is only supported by the Windows 7 Touch API.
270 * Platforms that do not support this metric should return
271 * NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
273 eIntID_TouchEnabled,
276 * A Boolean value to determine whether the Mac graphite theme is
277 * being used.
279 * The value of this metric is not used on other platforms. These platforms
280 * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
282 eIntID_MacGraphiteTheme,
285 * A Boolean value to determine whether the Mac OS X Lion-specific theming
286 * should be used.
288 * The value of this metric is not used on non-Mac platforms. These
289 * platforms should return NS_ERROR_NOT_IMPLEMENTED when queried for this
290 * metric.
292 eIntID_MacLionTheme,
295 * A Boolean value to determine whether the Mac OS X Yosemite-specific theming
296 * should be used.
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.
302 eIntID_MacYosemiteTheme,
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).
311 * 6 4
312 * +-----------+
313 * 7| |5
314 * | |
315 * 3| |1
316 * +-----------+
317 * 2 0
319 eIntID_AlertNotificationOrigin,
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.
327 eIntID_ScrollToClick,
330 * IME and spell checker underline styles, the values should be
331 * NS_DECORATION_LINE_STYLE_*. They are defined below.
333 eIntID_IMERawInputUnderlineStyle,
334 eIntID_IMESelectedRawTextUnderlineStyle,
335 eIntID_IMEConvertedTextUnderlineStyle,
336 eIntID_IMESelectedConvertedTextUnderline,
337 eIntID_SpellCheckerUnderlineStyle,
340 * If this metric != 0, show icons in menus.
342 eIntID_ImagesInMenus,
344 * If this metric != 0, show icons in buttons.
346 eIntID_ImagesInButtons,
348 * If this metric != 0, support window dragging on the menubar.
350 eIntID_MenuBarDrag,
352 * Return the appropriate WindowsThemeIdentifier for the current theme.
354 eIntID_WindowsThemeIdentifier,
356 * Return an appropriate os version identifier.
358 eIntID_OperatingSystemVersionIdentifier,
360 * 0: scrollbar button repeats to scroll only when cursor is on the button.
361 * 1: scrollbar button repeats to scroll even if cursor is outside of it.
363 eIntID_ScrollbarButtonAutoRepeatBehavior,
365 * Delay before showing a tooltip.
367 eIntID_TooltipDelay,
369 * A Boolean value to determine whether Mac OS X Lion style swipe animations
370 * should be used.
372 eIntID_SwipeAnimationEnabled,
375 * A Boolean value to determine whether we have a color picker available
376 * for <input type="color"> to hook into.
378 * This lets us selectively enable the style for <input type="color">
379 * based on whether it's functional or not.
381 eIntID_ColorPickerAvailable,
384 * A boolean value indicating whether or not the device has a hardware
385 * home button. Used on gaia to determine whether a home button
386 * is shown.
388 eIntID_PhysicalHomeButton,
391 * Controls whether overlay scrollbars display when the user moves
392 * the mouse in a scrollable frame.
394 eIntID_ScrollbarDisplayOnMouseMove,
397 * Overlay scrollbar animation constants.
399 eIntID_ScrollbarFadeBeginDelay,
400 eIntID_ScrollbarFadeDuration
404 * Windows themes we currently detect.
406 enum WindowsTheme {
407 eWindowsTheme_Generic = 0, // unrecognized theme
408 eWindowsTheme_Classic,
409 eWindowsTheme_Aero,
410 eWindowsTheme_LunaBlue,
411 eWindowsTheme_LunaOlive,
412 eWindowsTheme_LunaSilver,
413 eWindowsTheme_Royale,
414 eWindowsTheme_Zune,
415 eWindowsTheme_AeroLite
419 * Operating system versions.
421 enum OperatingSystemVersion {
422 eOperatingSystemVersion_WindowsXP = 0,
423 eOperatingSystemVersion_WindowsVista,
424 eOperatingSystemVersion_Windows7,
425 eOperatingSystemVersion_Windows8,
426 eOperatingSystemVersion_Unknown
429 enum {
430 eScrollArrow_None = 0,
431 eScrollArrow_StartBackward = 0x1000,
432 eScrollArrow_StartForward = 0x0100,
433 eScrollArrow_EndBackward = 0x0010,
434 eScrollArrow_EndForward = 0x0001
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
453 enum {
454 eScrollThumbStyle_Normal,
455 eScrollThumbStyle_Proportional
458 // When modifying this list, also modify nsXPLookAndFeel::sFloatPrefs
459 // in widget/xpwidgts/nsXPLookAndFeel.cpp.
460 enum FloatID {
461 eFloatID_IMEUnderlineRelativeSize,
462 eFloatID_SpellCheckerUnderlineRelativeSize,
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
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,
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,
490 eFont_Tooltips, // moz
491 eFont_Widget
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.
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.
509 static nsresult GetColor(ColorID aID, nscolor* aResult);
512 * GetInt() and GetFloat() return a int or float value for aID. The result
513 * might be distance, time, some flags or a int value which has particular
514 * meaning. See each document at definition of each ID for the detail.
515 * The result is always 0 when they return error. Therefore, if you want to
516 * use a value for the default value, you should use the other method which
517 * returns int or float directly.
519 static nsresult GetInt(IntID aID, int32_t* aResult);
520 static nsresult GetFloat(FloatID aID, float* aResult);
522 static nscolor GetColor(ColorID aID, nscolor aDefault = NS_RGB(0, 0, 0))
524 nscolor result = NS_RGB(0, 0, 0);
525 if (NS_FAILED(GetColor(aID, &result))) {
526 return aDefault;
528 return result;
531 static int32_t GetInt(IntID aID, int32_t aDefault = 0)
533 int32_t result;
534 if (NS_FAILED(GetInt(aID, &result))) {
535 return aDefault;
537 return result;
540 static float GetFloat(FloatID aID, float aDefault = 0.0f)
542 float result;
543 if (NS_FAILED(GetFloat(aID, &result))) {
544 return aDefault;
546 return result;
550 * Retrieve the name and style of a system-theme font. Returns true
551 * if the system theme specifies this font, false if a default should
552 * be used. In the latter case neither aName nor aStyle is modified.
554 * @param aID Which system-theme font is wanted.
555 * @param aName The name of the font to use.
556 * @param aStyle Styling to apply to the font.
557 * @param aDevPixPerCSSPixel Ratio of device pixels to CSS pixels
559 static bool GetFont(FontID aID, nsString& aName, gfxFontStyle& aStyle,
560 float aDevPixPerCSSPixel);
563 * GetPasswordCharacter() returns a unicode character which should be used
564 * for a masked character in password editor. E.g., '*'.
566 static char16_t GetPasswordCharacter();
569 * If the latest character in password field shouldn't be hidden by the
570 * result of GetPasswordCharacter(), GetEchoPassword() returns TRUE.
571 * Otherwise, FALSE.
573 static bool GetEchoPassword();
576 * The millisecond to mask password value.
577 * This value is only valid when GetEchoPassword() returns true.
579 static uint32_t GetPasswordMaskDelay();
582 * When system look and feel is changed, Refresh() must be called. Then,
583 * cached data would be released.
585 static void Refresh();
588 } // namespace mozilla
590 // On the Mac, GetColor(eColorID_TextSelectForeground, color) returns this
591 // constant to specify that the foreground color should not be changed
592 // (ie. a colored text keeps its colors when selected).
593 // Of course if other plaforms work like the Mac, they can use it too.
594 #define NS_DONT_CHANGE_COLOR NS_RGB(0x01, 0x01, 0x01)
596 // Similar with NS_DONT_CHANGE_COLOR, except NS_DONT_CHANGE_COLOR would returns
597 // complementary color if fg color is same as bg color.
598 // NS_CHANGE_COLOR_IF_SAME_AS_BG would returns eColorID_TextSelectForegroundCustom if
599 // fg and bg color are the same.
600 #define NS_CHANGE_COLOR_IF_SAME_AS_BG NS_RGB(0x02, 0x02, 0x02)
602 // ---------------------------------------------------------------------
603 // Special colors for eColorID_IME* and eColorID_SpellCheckerUnderline
604 // ---------------------------------------------------------------------
606 // For background color only.
607 #define NS_TRANSPARENT NS_RGBA(0x01, 0x00, 0x00, 0x00)
608 // For foreground color only.
609 #define NS_SAME_AS_FOREGROUND_COLOR NS_RGBA(0x02, 0x00, 0x00, 0x00)
610 #define NS_40PERCENT_FOREGROUND_COLOR NS_RGBA(0x03, 0x00, 0x00, 0x00)
612 #define NS_IS_SELECTION_SPECIAL_COLOR(c) ((c) == NS_TRANSPARENT || \
613 (c) == NS_SAME_AS_FOREGROUND_COLOR || \
614 (c) == NS_40PERCENT_FOREGROUND_COLOR)
616 // ------------------------------------------
617 // Bits for eIntID_AlertNotificationOrigin
618 // ------------------------------------------
620 #define NS_ALERT_HORIZONTAL 1
621 #define NS_ALERT_LEFT 2
622 #define NS_ALERT_TOP 4
624 #endif /* __LookAndFeel */