Bug 932076 - Add check for MediaExtractor creation failure. r=doublec
[gecko.git] / widget / LookAndFeel.h
blob08de0709aebc334c5900c085ffa33970fb5c8ede
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_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
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,
227 * A Boolean value to determine whether the Windows default theme is
228 * being used.
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.
233 eIntID_WindowsDefaultTheme,
236 * A Boolean value to determine whether the DWM compositor is being used
238 * This metric is not used on non-Windows platforms. These platforms
239 * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
241 eIntID_DWMCompositor,
244 * A Boolean value to determine whether Windows is themed (Classic vs.
245 * uxtheme)
247 * This is Windows-specific and is not implemented on other platforms
248 * (will return the default of NS_ERROR_FAILURE).
250 eIntID_WindowsClassic,
253 * A Boolean value to determine whether the current Windows desktop theme
254 * supports Aero Glass.
256 * This is Windows-specific and is not implemented on other platforms
257 * (will return the default of NS_ERROR_FAILURE).
259 eIntID_WindowsGlass,
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.
265 * Platforms that do not support this metric should return
266 * NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
268 eIntID_TouchEnabled,
271 * A Boolean value to determine whether the Mac graphite theme is
272 * being used.
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.
277 eIntID_MacGraphiteTheme,
280 * A Boolean value to determine whether the Mac OS X Lion-specific theming
281 * should be used.
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.
287 eIntID_MacLionTheme,
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).
296 * 6 4
297 * +-----------+
298 * 7| |5
299 * | |
300 * 3| |1
301 * +-----------+
302 * 2 0
304 eIntID_AlertNotificationOrigin,
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.
312 eIntID_ScrollToClick,
315 * IME and spell checker underline styles, the values should be
316 * NS_DECORATION_LINE_STYLE_*. They are defined below.
318 eIntID_IMERawInputUnderlineStyle,
319 eIntID_IMESelectedRawTextUnderlineStyle,
320 eIntID_IMEConvertedTextUnderlineStyle,
321 eIntID_IMESelectedConvertedTextUnderline,
322 eIntID_SpellCheckerUnderlineStyle,
325 * If this metric != 0, show icons in menus.
327 eIntID_ImagesInMenus,
329 * If this metric != 0, show icons in buttons.
331 eIntID_ImagesInButtons,
333 * If this metric != 0, support window dragging on the menubar.
335 eIntID_MenuBarDrag,
337 * Return the appropriate WindowsThemeIdentifier for the current theme.
339 eIntID_WindowsThemeIdentifier,
341 * Return an appropriate os version identifier.
343 eIntID_OperatingSystemVersionIdentifier,
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.
348 eIntID_ScrollbarButtonAutoRepeatBehavior,
350 * Delay before showing a tooltip.
352 eIntID_TooltipDelay,
354 * A Boolean value to determine whether Mac OS X Lion style swipe animations
355 * should be used.
357 eIntID_SwipeAnimationEnabled,
360 * A boolean value indicating whether or not the device has a hardware
361 * home button. Used on gaia to determine whether a home button
362 * is shown.
364 eIntID_PhysicalHomeButton,
367 * Controls whether overlay scrollbars display when the user moves
368 * the mouse in a scrollable frame.
370 eIntID_ScrollbarDisplayOnMouseMove,
373 * Overlay scrollbar animation constants.
375 eIntID_ScrollbarFadeBeginDelay,
376 eIntID_ScrollbarFadeDuration
380 * Windows themes we currently detect.
382 enum WindowsTheme {
383 eWindowsTheme_Generic = 0, // unrecognized theme
384 eWindowsTheme_Classic,
385 eWindowsTheme_Aero,
386 eWindowsTheme_LunaBlue,
387 eWindowsTheme_LunaOlive,
388 eWindowsTheme_LunaSilver,
389 eWindowsTheme_Royale,
390 eWindowsTheme_Zune,
391 eWindowsTheme_AeroLite
395 * Operating system versions.
397 enum OperatingSystemVersion {
398 eOperatingSystemVersion_WindowsXP = 0,
399 eOperatingSystemVersion_WindowsVista,
400 eOperatingSystemVersion_Windows7,
401 eOperatingSystemVersion_Windows8,
402 eOperatingSystemVersion_Unknown
405 enum {
406 eScrollArrow_None = 0,
407 eScrollArrow_StartBackward = 0x1000,
408 eScrollArrow_StartForward = 0x0100,
409 eScrollArrow_EndBackward = 0x0010,
410 eScrollArrow_EndForward = 0x0001
413 enum {
414 // single arrow at each end
415 eScrollArrowStyle_Single =
416 eScrollArrow_StartBackward | eScrollArrow_EndForward,
417 // both arrows at bottom/right, none at top/left
418 eScrollArrowStyle_BothAtBottom =
419 eScrollArrow_EndBackward | eScrollArrow_EndForward,
420 // both arrows at both ends
421 eScrollArrowStyle_BothAtEachEnd =
422 eScrollArrow_EndBackward | eScrollArrow_EndForward |
423 eScrollArrow_StartBackward | eScrollArrow_StartForward,
424 // both arrows at top/left, none at bottom/right
425 eScrollArrowStyle_BothAtTop =
426 eScrollArrow_StartBackward | eScrollArrow_StartForward
429 enum {
430 eScrollThumbStyle_Normal,
431 eScrollThumbStyle_Proportional
434 // When modifying this list, also modify nsXPLookAndFeel::sFloatPrefs
435 // in widget/xpwidgts/nsXPLookAndFeel.cpp.
436 enum FloatID {
437 eFloatID_IMEUnderlineRelativeSize,
438 eFloatID_SpellCheckerUnderlineRelativeSize,
440 // The width/height ratio of the cursor. If used, the CaretWidth int metric
441 // should be added to the calculated caret width.
442 eFloatID_CaretAspectRatio
445 // These constants must be kept in 1:1 correspondence with the
446 // NS_STYLE_FONT_* system font constants.
447 enum FontID {
448 eFont_Caption = 1, // css2
449 eFont_Icon,
450 eFont_Menu,
451 eFont_MessageBox,
452 eFont_SmallCaption,
453 eFont_StatusBar,
455 eFont_Window, // css3
456 eFont_Document,
457 eFont_Workspace,
458 eFont_Desktop,
459 eFont_Info,
460 eFont_Dialog,
461 eFont_Button,
462 eFont_PullDownMenu,
463 eFont_List,
464 eFont_Field,
466 eFont_Tooltips, // moz
467 eFont_Widget
471 * GetColor() return a native color value (might be overwritten by prefs) for
472 * aID. Some platforms don't return an error even if the index doesn't
473 * match any system colors. And also some platforms may initialize the
474 * return value even when it returns an error. Therefore, if you want to
475 * use a color for the default value, you should use the other GetColor()
476 * which returns nscolor directly.
478 * NOTE:
479 * eColorID_TextSelectForeground might return NS_DONT_CHANGE_COLOR.
480 * eColorID_IME* might return NS_TRANSPARENT, NS_SAME_AS_FOREGROUND_COLOR or
481 * NS_40PERCENT_FOREGROUND_COLOR.
482 * These values have particular meaning. Then, they are not an actual
483 * color value.
485 static nsresult GetColor(ColorID aID, nscolor* aResult);
488 * GetInt() and GetFloat() return a int or float value for aID. The result
489 * might be distance, time, some flags or a int value which has particular
490 * meaning. See each document at definition of each ID for the detail.
491 * The result is always 0 when they return error. Therefore, if you want to
492 * use a value for the default value, you should use the other method which
493 * returns int or float directly.
495 static nsresult GetInt(IntID aID, int32_t* aResult);
496 static nsresult GetFloat(FloatID aID, float* aResult);
498 static nscolor GetColor(ColorID aID, nscolor aDefault = NS_RGB(0, 0, 0))
500 nscolor result = NS_RGB(0, 0, 0);
501 if (NS_FAILED(GetColor(aID, &result))) {
502 return aDefault;
504 return result;
507 static int32_t GetInt(IntID aID, int32_t aDefault = 0)
509 int32_t result;
510 if (NS_FAILED(GetInt(aID, &result))) {
511 return aDefault;
513 return result;
516 static float GetFloat(FloatID aID, float aDefault = 0.0f)
518 float result;
519 if (NS_FAILED(GetFloat(aID, &result))) {
520 return aDefault;
522 return result;
526 * Retrieve the name and style of a system-theme font. Returns true
527 * if the system theme specifies this font, false if a default should
528 * be used. In the latter case neither aName nor aStyle is modified.
530 * @param aID Which system-theme font is wanted.
531 * @param aName The name of the font to use.
532 * @param aStyle Styling to apply to the font.
533 * @param aDevPixPerCSSPixel Ratio of device pixels to CSS pixels
535 static bool GetFont(FontID aID, nsString& aName, gfxFontStyle& aStyle,
536 float aDevPixPerCSSPixel);
539 * GetPasswordCharacter() returns a unicode character which should be used
540 * for a masked character in password editor. E.g., '*'.
542 static PRUnichar GetPasswordCharacter();
545 * If the latest character in password field shouldn't be hidden by the
546 * result of GetPasswordCharacter(), GetEchoPassword() returns TRUE.
547 * Otherwise, FALSE.
549 static bool GetEchoPassword();
552 * The millisecond to mask password value.
553 * This value is only valid when GetEchoPassword() returns true.
555 static uint32_t GetPasswordMaskDelay();
558 * When system look and feel is changed, Refresh() must be called. Then,
559 * cached data would be released.
561 static void Refresh();
564 } // namespace mozilla
566 // On the Mac, GetColor(eColorID_TextSelectForeground, color) returns this
567 // constant to specify that the foreground color should not be changed
568 // (ie. a colored text keeps its colors when selected).
569 // Of course if other plaforms work like the Mac, they can use it too.
570 #define NS_DONT_CHANGE_COLOR NS_RGB(0x01, 0x01, 0x01)
572 // ---------------------------------------------------------------------
573 // Special colors for eColorID_IME* and eColorID_SpellCheckerUnderline
574 // ---------------------------------------------------------------------
576 // For background color only.
577 #define NS_TRANSPARENT NS_RGBA(0x01, 0x00, 0x00, 0x00)
578 // For foreground color only.
579 #define NS_SAME_AS_FOREGROUND_COLOR NS_RGBA(0x02, 0x00, 0x00, 0x00)
580 #define NS_40PERCENT_FOREGROUND_COLOR NS_RGBA(0x03, 0x00, 0x00, 0x00)
582 #define NS_IS_SELECTION_SPECIAL_COLOR(c) ((c) == NS_TRANSPARENT || \
583 (c) == NS_SAME_AS_FOREGROUND_COLOR || \
584 (c) == NS_40PERCENT_FOREGROUND_COLOR)
586 // ------------------------------------------
587 // Bits for eIntID_AlertNotificationOrigin
588 // ------------------------------------------
590 #define NS_ALERT_HORIZONTAL 1
591 #define NS_ALERT_LEFT 2
592 #define NS_ALERT_TOP 4
594 #endif /* __LookAndFeel */