Fix typo in 9b54bd30006c008b4a951331b273613d5bac3abf
[pm.git] / widget / LookAndFeel.h
blobf5753efbb3f12e08f843102a2b20dba10e322077
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 // accent color for title bar
155 eColorID__moz_win_accentcolor,
156 // color from drawing text over the accent color
157 eColorID__moz_win_accentcolortext,
158 // media rebar text
159 eColorID__moz_win_mediatext,
160 // communications rebar text
161 eColorID__moz_win_communicationstext,
163 // Hyperlink color extracted from the system, not affected by the
164 // browser.anchor_color user pref.
165 // There is no OS-specified safe background color for this text,
166 // but it is used regularly within Windows and the Gnome DE on Dialog and
167 // Window colors.
168 eColorID__moz_nativehyperlinktext,
170 // Combo box widgets
171 eColorID__moz_comboboxtext,
172 eColorID__moz_combobox,
174 // keep this one last, please
175 eColorID_LAST_COLOR
178 // When modifying this list, also modify nsXPLookAndFeel::sIntPrefs
179 // in widget/xpwidgts/nsXPLookAndFeel.cpp.
180 enum IntID {
181 // default, may be overriden by OS
182 eIntID_CaretBlinkTime,
183 // pixel width of caret
184 eIntID_CaretWidth,
185 // show the caret when text is selected?
186 eIntID_ShowCaretDuringSelection,
187 // select textfields when focused via tab/accesskey?
188 eIntID_SelectTextfieldsOnKeyFocus,
189 // delay before submenus open
190 eIntID_SubmenuDelay,
191 // can popups overlap menu/task bar?
192 eIntID_MenusCanOverlapOSBar,
193 // should overlay scrollbars be used?
194 eIntID_UseOverlayScrollbars,
195 // allow H and V overlay scrollbars to overlap?
196 eIntID_AllowOverlayScrollbarsOverlap,
197 // show/hide scrollbars based on activity
198 eIntID_ShowHideScrollbars,
199 // skip navigating to disabled menu item?
200 eIntID_SkipNavigatingDisabledMenuItem,
201 // begin a drag if the mouse is moved further than the threshold while the
202 // button is down
203 eIntID_DragThresholdX,
204 eIntID_DragThresholdY,
205 // Accessibility theme being used?
206 eIntID_UseAccessibilityTheme,
208 // position of scroll arrows in a scrollbar
209 eIntID_ScrollArrowStyle,
210 // is scroll thumb proportional or fixed?
211 eIntID_ScrollSliderStyle,
213 // each button can take one of four values:
214 eIntID_ScrollButtonLeftMouseButtonAction,
215 // 0 - scrolls one line, 1 - scrolls one page
216 eIntID_ScrollButtonMiddleMouseButtonAction,
217 // 2 - scrolls to end, 3 - button ignored
218 eIntID_ScrollButtonRightMouseButtonAction,
220 // delay for opening spring loaded folders
221 eIntID_TreeOpenDelay,
222 // delay for closing spring loaded folders
223 eIntID_TreeCloseDelay,
224 // delay for triggering the tree scrolling
225 eIntID_TreeLazyScrollDelay,
226 // delay for scrolling the tree
227 eIntID_TreeScrollDelay,
228 // the maximum number of lines to be scrolled at ones
229 eIntID_TreeScrollLinesMax,
230 // What type of tab-order to use
231 eIntID_TabFocusModel,
232 // Should menu items blink when they're chosen?
233 eIntID_ChosenMenuItemsShouldBlink,
236 * A Boolean value to determine whether the Windows accent color
237 * should be applied to the title bar.
239 * The value of this metric is not used on other platforms. These platforms
240 * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
242 eIntID_WindowsAccentColorApplies,
245 * A Boolean value to determine whether the Windows accent color
246 * is considered dark and should get bright text/controls.
248 * The value of this metric is not used on other platforms. These platforms
249 * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
251 eIntID_WindowsAccentColorIsDark,
254 * A Boolean value to determine whether the Windows default theme is
255 * being used.
257 * The value of this metric is not used on other platforms. These platforms
258 * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
260 eIntID_WindowsDefaultTheme,
263 * A Boolean value to determine whether the DWM compositor is being used
265 * This metric is not used on non-Windows platforms. These platforms
266 * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
268 eIntID_DWMCompositor,
271 * A Boolean value to determine whether Windows is themed (Classic vs.
272 * uxtheme)
274 * This is Windows-specific and is not implemented on other platforms
275 * (will return the default of NS_ERROR_FAILURE).
277 eIntID_WindowsClassic,
280 * A Boolean value to determine whether the current Windows desktop theme
281 * supports Aero Glass.
283 * This is Windows-specific and is not implemented on other platforms
284 * (will return the default of NS_ERROR_FAILURE).
286 eIntID_WindowsGlass,
289 * A Boolean value to determine whether the device is a touch enabled
290 * device. Currently this is only supported by the Windows 7 Touch API.
292 * Platforms that do not support this metric should return
293 * NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
295 eIntID_TouchEnabled,
298 * A Boolean value to determine whether the Mac graphite theme is
299 * being used.
301 * The value of this metric is not used on other platforms. These platforms
302 * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
304 eIntID_MacGraphiteTheme,
307 * A Boolean value to determine whether the Mac OS X Lion-specific theming
308 * should be used.
310 * The value of this metric is not used on non-Mac platforms. These
311 * platforms should return NS_ERROR_NOT_IMPLEMENTED when queried for this
312 * metric.
314 eIntID_MacLionTheme,
317 * A Boolean value to determine whether the Mac OS X Yosemite-specific theming
318 * should be used.
320 * The value of this metric is not used on non-Mac platforms. These
321 * platforms should return NS_ERROR_NOT_IMPLEMENTED when queried for this
322 * metric.
324 eIntID_MacYosemiteTheme,
327 * eIntID_AlertNotificationOrigin indicates from which corner of the
328 * screen alerts slide in, and from which direction (horizontal/vertical).
329 * 0, the default, represents bottom right, sliding vertically.
330 * Use any bitwise combination of the following constants:
331 * NS_ALERT_HORIZONTAL (1), NS_ALERT_LEFT (2), NS_ALERT_TOP (4).
333 * 6 4
334 * +-----------+
335 * 7| |5
336 * | |
337 * 3| |1
338 * +-----------+
339 * 2 0
341 eIntID_AlertNotificationOrigin,
344 * If true, clicking on a scrollbar (not as in dragging the thumb) defaults
345 * to scrolling the view corresponding to the clicked point. Otherwise, we
346 * only do so if the scrollbar is clicked using the middle mouse button or
347 * if shift is pressed when the scrollbar is clicked.
349 eIntID_ScrollToClick,
352 * IME and spell checker underline styles, the values should be
353 * NS_DECORATION_LINE_STYLE_*. They are defined below.
355 eIntID_IMERawInputUnderlineStyle,
356 eIntID_IMESelectedRawTextUnderlineStyle,
357 eIntID_IMEConvertedTextUnderlineStyle,
358 eIntID_IMESelectedConvertedTextUnderline,
359 eIntID_SpellCheckerUnderlineStyle,
362 * If this metric != 0, show icons in menus.
364 eIntID_ImagesInMenus,
366 * If this metric != 0, show icons in buttons.
368 eIntID_ImagesInButtons,
370 * If this metric != 0, support window dragging on the menubar.
372 eIntID_MenuBarDrag,
374 * Return the appropriate WindowsThemeIdentifier for the current theme.
376 eIntID_WindowsThemeIdentifier,
378 * Return an appropriate os version identifier.
380 eIntID_OperatingSystemVersionIdentifier,
382 * 0: scrollbar button repeats to scroll only when cursor is on the button.
383 * 1: scrollbar button repeats to scroll even if cursor is outside of it.
385 eIntID_ScrollbarButtonAutoRepeatBehavior,
387 * Delay before showing a tooltip.
389 eIntID_TooltipDelay,
391 * A Boolean value to determine whether Mac OS X Lion style swipe animations
392 * should be used.
394 eIntID_SwipeAnimationEnabled,
397 * A Boolean value to determine whether we have a color picker available
398 * for <input type="color"> to hook into.
400 * This lets us selectively enable the style for <input type="color">
401 * based on whether it's functional or not.
403 eIntID_ColorPickerAvailable,
406 * A boolean value indicating whether or not the device has a hardware
407 * home button. Used on gaia to determine whether a home button
408 * is shown.
410 eIntID_PhysicalHomeButton,
413 * Controls whether overlay scrollbars display when the user moves
414 * the mouse in a scrollable frame.
416 eIntID_ScrollbarDisplayOnMouseMove,
419 * Overlay scrollbar animation constants.
421 eIntID_ScrollbarFadeBeginDelay,
422 eIntID_ScrollbarFadeDuration
426 * Windows themes we currently detect.
428 enum WindowsTheme {
429 eWindowsTheme_Generic = 0, // unrecognized theme
430 eWindowsTheme_Classic,
431 eWindowsTheme_Aero,
432 eWindowsTheme_AeroLite
436 * Operating system versions.
438 enum OperatingSystemVersion {
439 eOperatingSystemVersion_WindowsXP = 0,
440 eOperatingSystemVersion_WindowsVista,
441 eOperatingSystemVersion_Windows7,
442 eOperatingSystemVersion_Windows8,
443 eOperatingSystemVersion_Windows10,
444 eOperatingSystemVersion_Unknown
447 enum {
448 eScrollArrow_None = 0,
449 eScrollArrow_StartBackward = 0x1000,
450 eScrollArrow_StartForward = 0x0100,
451 eScrollArrow_EndBackward = 0x0010,
452 eScrollArrow_EndForward = 0x0001
455 enum {
456 // single arrow at each end
457 eScrollArrowStyle_Single =
458 eScrollArrow_StartBackward | eScrollArrow_EndForward,
459 // both arrows at bottom/right, none at top/left
460 eScrollArrowStyle_BothAtBottom =
461 eScrollArrow_EndBackward | eScrollArrow_EndForward,
462 // both arrows at both ends
463 eScrollArrowStyle_BothAtEachEnd =
464 eScrollArrow_EndBackward | eScrollArrow_EndForward |
465 eScrollArrow_StartBackward | eScrollArrow_StartForward,
466 // both arrows at top/left, none at bottom/right
467 eScrollArrowStyle_BothAtTop =
468 eScrollArrow_StartBackward | eScrollArrow_StartForward
471 enum {
472 eScrollThumbStyle_Normal,
473 eScrollThumbStyle_Proportional
476 // When modifying this list, also modify nsXPLookAndFeel::sFloatPrefs
477 // in widget/xpwidgts/nsXPLookAndFeel.cpp.
478 enum FloatID {
479 eFloatID_IMEUnderlineRelativeSize,
480 eFloatID_SpellCheckerUnderlineRelativeSize,
482 // The width/height ratio of the cursor. If used, the CaretWidth int metric
483 // should be added to the calculated caret width.
484 eFloatID_CaretAspectRatio
487 // These constants must be kept in 1:1 correspondence with the
488 // NS_STYLE_FONT_* system font constants.
489 enum FontID {
490 eFont_Caption = 1, // css2
491 eFont_Icon,
492 eFont_Menu,
493 eFont_MessageBox,
494 eFont_SmallCaption,
495 eFont_StatusBar,
497 eFont_Window, // css3
498 eFont_Document,
499 eFont_Workspace,
500 eFont_Desktop,
501 eFont_Info,
502 eFont_Dialog,
503 eFont_Button,
504 eFont_PullDownMenu,
505 eFont_List,
506 eFont_Field,
508 eFont_Tooltips, // moz
509 eFont_Widget
513 * GetColor() return a native color value (might be overwritten by prefs) for
514 * aID. Some platforms don't return an error even if the index doesn't
515 * match any system colors. And also some platforms may initialize the
516 * return value even when it returns an error. Therefore, if you want to
517 * use a color for the default value, you should use the other GetColor()
518 * which returns nscolor directly.
520 * NOTE:
521 * eColorID_TextSelectForeground might return NS_DONT_CHANGE_COLOR.
522 * eColorID_IME* might return NS_TRANSPARENT, NS_SAME_AS_FOREGROUND_COLOR or
523 * NS_40PERCENT_FOREGROUND_COLOR.
524 * These values have particular meaning. Then, they are not an actual
525 * color value.
527 static nsresult GetColor(ColorID aID, nscolor* aResult);
530 * GetInt() and GetFloat() return a int or float value for aID. The result
531 * might be distance, time, some flags or a int value which has particular
532 * meaning. See each document at definition of each ID for the detail.
533 * The result is always 0 when they return error. Therefore, if you want to
534 * use a value for the default value, you should use the other method which
535 * returns int or float directly.
537 static nsresult GetInt(IntID aID, int32_t* aResult);
538 static nsresult GetFloat(FloatID aID, float* aResult);
540 static nscolor GetColor(ColorID aID, nscolor aDefault = NS_RGB(0, 0, 0))
542 nscolor result = NS_RGB(0, 0, 0);
543 if (NS_FAILED(GetColor(aID, &result))) {
544 return aDefault;
546 return result;
549 static int32_t GetInt(IntID aID, int32_t aDefault = 0)
551 int32_t result;
552 if (NS_FAILED(GetInt(aID, &result))) {
553 return aDefault;
555 return result;
558 static float GetFloat(FloatID aID, float aDefault = 0.0f)
560 float result;
561 if (NS_FAILED(GetFloat(aID, &result))) {
562 return aDefault;
564 return result;
568 * Retrieve the name and style of a system-theme font. Returns true
569 * if the system theme specifies this font, false if a default should
570 * be used. In the latter case neither aName nor aStyle is modified.
572 * @param aID Which system-theme font is wanted.
573 * @param aName The name of the font to use.
574 * @param aStyle Styling to apply to the font.
575 * @param aDevPixPerCSSPixel Ratio of device pixels to CSS pixels
577 static bool GetFont(FontID aID, nsString& aName, gfxFontStyle& aStyle,
578 float aDevPixPerCSSPixel);
581 * GetPasswordCharacter() returns a unicode character which should be used
582 * for a masked character in password editor. E.g., '*'.
584 static char16_t GetPasswordCharacter();
587 * If the latest character in password field shouldn't be hidden by the
588 * result of GetPasswordCharacter(), GetEchoPassword() returns TRUE.
589 * Otherwise, FALSE.
591 static bool GetEchoPassword();
594 * The millisecond to mask password value.
595 * This value is only valid when GetEchoPassword() returns true.
597 static uint32_t GetPasswordMaskDelay();
600 * When system look and feel is changed, Refresh() must be called. Then,
601 * cached data would be released.
603 static void Refresh();
606 } // namespace mozilla
608 // On the Mac, GetColor(eColorID_TextSelectForeground, color) returns this
609 // constant to specify that the foreground color should not be changed
610 // (ie. a colored text keeps its colors when selected).
611 // Of course if other plaforms work like the Mac, they can use it too.
612 #define NS_DONT_CHANGE_COLOR NS_RGB(0x01, 0x01, 0x01)
614 // Similar with NS_DONT_CHANGE_COLOR, except NS_DONT_CHANGE_COLOR would returns
615 // complementary color if fg color is same as bg color.
616 // NS_CHANGE_COLOR_IF_SAME_AS_BG would returns eColorID_TextSelectForegroundCustom if
617 // fg and bg color are the same.
618 #define NS_CHANGE_COLOR_IF_SAME_AS_BG NS_RGB(0x02, 0x02, 0x02)
620 // ---------------------------------------------------------------------
621 // Special colors for eColorID_IME* and eColorID_SpellCheckerUnderline
622 // ---------------------------------------------------------------------
624 // For background color only.
625 #define NS_TRANSPARENT NS_RGBA(0x01, 0x00, 0x00, 0x00)
626 // For foreground color only.
627 #define NS_SAME_AS_FOREGROUND_COLOR NS_RGBA(0x02, 0x00, 0x00, 0x00)
628 #define NS_40PERCENT_FOREGROUND_COLOR NS_RGBA(0x03, 0x00, 0x00, 0x00)
630 #define NS_IS_SELECTION_SPECIAL_COLOR(c) ((c) == NS_TRANSPARENT || \
631 (c) == NS_SAME_AS_FOREGROUND_COLOR || \
632 (c) == NS_40PERCENT_FOREGROUND_COLOR)
634 // ------------------------------------------
635 // Bits for eIntID_AlertNotificationOrigin
636 // ------------------------------------------
638 #define NS_ALERT_HORIZONTAL 1
639 #define NS_ALERT_LEFT 2
640 #define NS_ALERT_TOP 4
642 #endif /* __LookAndFeel */