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/. */
9 #ifndef MOZILLA_INTERNAL_API
10 # error "This header is only usable from within libxul (MOZILLA_INTERNAL_API)."
17 #include "mozilla/Maybe.h"
18 #include "mozilla/widget/ThemeChangeKind.h"
19 #include "mozilla/ColorScheme.h"
27 struct StyleColorSchemeFlags
;
34 class FullLookAndFeel
;
37 enum class StyleSystemColor
: uint8_t;
38 enum class StyleSystemColorScheme
: uint8_t;
39 enum class StyleSystemFont
: uint8_t;
43 using ColorID
= StyleSystemColor
;
44 using ColorScheme
= mozilla::ColorScheme
;
46 // When modifying this list, also modify nsXPLookAndFeel::sIntPrefs
47 // in widget/xpwidgts/nsXPLookAndFeel.cpp.
49 // default, may be overriden by OS
51 // Amount of blinks that happen before the caret stops blinking.
53 // pixel width of caret
55 // show the caret when text is selected?
56 ShowCaretDuringSelection
,
57 // select textfields when focused via tab/accesskey?
58 SelectTextfieldsOnKeyFocus
,
59 // delay before submenus open
61 // can popups overlap menu/task bar?
63 // should overlay scrollbars be used?
65 // allow H and V overlay scrollbars to overlap?
66 AllowOverlayScrollbarsOverlap
,
67 // skip navigating to disabled menu item?
68 SkipNavigatingDisabledMenuItem
,
69 // begin a drag if the mouse is moved further than the threshold while the
73 // Accessibility theme being used?
74 UseAccessibilityTheme
,
76 // position of scroll arrows in a scrollbar
78 // is scroll thumb proportional or fixed?
81 // each button can take one of four values:
82 ScrollButtonLeftMouseButtonAction
,
83 // 0 - scrolls one line, 1 - scrolls one page
84 ScrollButtonMiddleMouseButtonAction
,
85 // 2 - scrolls to end, 3 - button ignored
86 ScrollButtonRightMouseButtonAction
,
88 // delay for opening spring loaded folders
90 // delay for closing spring loaded folders
92 // delay for triggering the tree scrolling
94 // delay for scrolling the tree
96 // the maximum number of lines to be scrolled at ones
98 // What type of tab-order to use
100 // Should menu items blink when they're chosen?
101 ChosenMenuItemsShouldBlink
,
104 * A Boolean value to determine whether the Windows accent color
105 * should be applied to the title bar.
107 * The value of this metric is not used on other platforms. These platforms
108 * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
110 WindowsAccentColorInTitlebar
,
113 * A Boolean value to determine whether the Windows default theme is
116 * The value of this metric is not used on other platforms. These platforms
117 * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
122 * A Boolean value to determine whether the DWM compositor is being used
124 * This metric is not used on non-Windows platforms. These platforms
125 * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
130 * A Boolean value to determine whether Windows is themed (Classic vs.
133 * This is Windows-specific and is not implemented on other platforms
134 * (will return the default of NS_ERROR_FAILURE).
139 * A Boolean value to determine whether the current Windows desktop theme
140 * supports Aero Glass.
142 * This is Windows-specific and is not implemented on other platforms
143 * (will return the default of NS_ERROR_FAILURE).
148 * A Boolean value to determine whether the Mac graphite theme is
154 * A Boolean value to determine whether the macOS Big Sur-specific
155 * theming should be used.
160 * A Boolean value to determine whether macOS is in RTL mode or not.
165 * AlertNotificationOrigin indicates from which corner of the
166 * screen alerts slide in, and from which direction (horizontal/vertical).
167 * 0, the default, represents bottom right, sliding vertically.
168 * Use any bitwise combination of the following constants:
169 * NS_ALERT_HORIZONTAL (1), NS_ALERT_LEFT (2), NS_ALERT_TOP (4).
179 AlertNotificationOrigin
,
182 * If true, clicking on a scrollbar (not as in dragging the thumb) defaults
183 * to scrolling the view corresponding to the clicked point. Otherwise, we
184 * only do so if the scrollbar is clicked using the middle mouse button or
185 * if shift is pressed when the scrollbar is clicked.
190 * IME and spell checker underline styles, the values should be
191 * NS_DECORATION_LINE_STYLE_*. They are defined below.
193 IMERawInputUnderlineStyle
,
194 IMESelectedRawTextUnderlineStyle
,
195 IMEConvertedTextUnderlineStyle
,
196 IMESelectedConvertedTextUnderline
,
197 SpellCheckerUnderlineStyle
,
200 * If this metric != 0, support window dragging on the menubar.
204 * 0: scrollbar button repeats to scroll only when cursor is on the button.
205 * 1: scrollbar button repeats to scroll even if cursor is outside of it.
207 ScrollbarButtonAutoRepeatBehavior
,
209 * Delay before showing a tooltip.
213 * A Boolean value to determine whether swipe animations should be used.
215 SwipeAnimationEnabled
,
218 * Controls whether overlay scrollbars display when the user moves
219 * the mouse in a scrollable frame.
221 ScrollbarDisplayOnMouseMove
,
224 * Overlay scrollbar animation constants.
226 ScrollbarFadeBeginDelay
,
227 ScrollbarFadeDuration
,
230 * Distance in pixels to offset the context menu from the cursor
233 ContextMenuOffsetVertical
,
234 ContextMenuOffsetHorizontal
,
237 * A boolean value indicating whether client-side decorations are
238 * supported by the user's GTK version.
243 * A boolean value indicating whether client-side decorations should
244 * contain a minimize button.
246 GTKCSDMinimizeButton
,
249 * A boolean value indicating whether client-side decorations should
250 * contain a maximize button.
252 GTKCSDMaximizeButton
,
255 * A boolean value indicating whether client-side decorations should
256 * contain a close button.
261 * An Integer value that will represent the position of the Minimize button
262 * in GTK Client side decoration header.
264 GTKCSDMinimizeButtonPosition
,
267 * An Integer value that will represent the position of the Maximize button
268 * in GTK Client side decoration header.
270 GTKCSDMaximizeButtonPosition
,
273 * An Integer value that will represent the position of the Close button
274 * in GTK Client side decoration header.
276 GTKCSDCloseButtonPosition
,
279 * A boolean value indicating whether titlebar buttons are located
280 * in left titlebar corner.
282 GTKCSDReversedPlacement
,
285 * A boolean value indicating whether or not the OS is using a dark theme,
286 * which we may want to switch to as well if not overridden by the user.
291 * Corresponding to prefers-reduced-motion.
292 * https://drafts.csswg.org/mediaqueries-5/#prefers-reduced-motion
297 PrefersReducedMotion
,
299 * Corresponding to PointerCapabilities in ServoTypes.h
305 PrimaryPointerCapabilities
,
307 * Corresponding to union of PointerCapabilities values in ServoTypes.h
308 * E.g. if there is a mouse and a digitizer, the value will be
309 * 'Coarse | Fine | Hover'.
311 AllPointerCapabilities
,
312 /** The vertical scrollbar width, in CSS pixels. */
313 SystemVerticalScrollbarWidth
,
315 /** The horizontal scrollbar height, in CSS pixels. */
316 SystemHorizontalScrollbarHeight
,
318 /** A boolean value to determine whether a touch device is present */
319 TouchDeviceSupportPresent
,
321 /** GTK titlebar radius */
324 /** GTK menu radius */
328 * Corresponding to dynamic-range.
329 * https://drafts.csswg.org/mediaqueries-5/#dynamic-range
337 * Not an ID; used to define the range of valid IDs. Must be last.
342 // This is a common enough integer that seems worth the shortcut.
343 static bool UseOverlayScrollbars() {
344 return GetInt(IntID::UseOverlayScrollbars
);
348 eScrollArrow_None
= 0,
349 eScrollArrow_StartBackward
= 0x1000,
350 eScrollArrow_StartForward
= 0x0100,
351 eScrollArrow_EndBackward
= 0x0010,
352 eScrollArrow_EndForward
= 0x0001
356 // single arrow at each end
357 eScrollArrowStyle_Single
=
358 eScrollArrow_StartBackward
| eScrollArrow_EndForward
,
359 // both arrows at bottom/right, none at top/left
360 eScrollArrowStyle_BothAtBottom
=
361 eScrollArrow_EndBackward
| eScrollArrow_EndForward
,
362 // both arrows at both ends
363 eScrollArrowStyle_BothAtEachEnd
=
364 eScrollArrow_EndBackward
| eScrollArrow_EndForward
|
365 eScrollArrow_StartBackward
| eScrollArrow_StartForward
,
366 // both arrows at top/left, none at bottom/right
367 eScrollArrowStyle_BothAtTop
=
368 eScrollArrow_StartBackward
| eScrollArrow_StartForward
371 enum { eScrollThumbStyle_Normal
, eScrollThumbStyle_Proportional
};
373 // When modifying this list, also modify nsXPLookAndFeel::sFloatPrefs
374 // in widget/nsXPLookAndFeel.cpp.
376 IMEUnderlineRelativeSize
,
377 SpellCheckerUnderlineRelativeSize
,
379 // The width/height ratio of the cursor. If used, the CaretWidth int metric
380 // should be added to the calculated caret width.
383 // GTK text scale factor.
386 // Mouse pointer scaling factor.
389 // Not an ID; used to define the range of valid IDs. Must be last.
393 using FontID
= mozilla::StyleSystemFont
;
395 static ColorScheme
SystemColorScheme() {
396 return GetInt(IntID::SystemUsesDarkTheme
) ? ColorScheme::Dark
397 : ColorScheme::Light
;
400 static bool IsDarkColor(nscolor
);
402 enum class ChromeColorSchemeSetting
{ Light
, Dark
, System
};
403 static ChromeColorSchemeSetting
ColorSchemeSettingForChrome();
404 static ColorScheme
ThemeDerivedColorSchemeForContent();
406 static ColorScheme
ColorSchemeForChrome() {
407 MOZ_ASSERT(sColorSchemeInitialized
);
408 return sChromeColorScheme
;
410 static ColorScheme
PreferredColorSchemeForContent() {
411 MOZ_ASSERT(sColorSchemeInitialized
);
412 return sContentColorScheme
;
415 static ColorScheme
ColorSchemeForStyle(const dom::Document
&,
416 const StyleColorSchemeFlags
&);
417 static ColorScheme
ColorSchemeForFrame(const nsIFrame
*);
419 // Whether standins for native colors should be used (that is, colors faked,
420 // taken from win7, mostly). This forces light appearance, effectively.
421 enum class UseStandins
: bool { No
, Yes
};
422 static UseStandins
ShouldUseStandins(const dom::Document
&, ColorID
);
424 // Returns a native color value (might be overwritten by prefs) for a given
428 // ColorID::TextSelectForeground might return NS_SAME_AS_FOREGROUND_COLOR.
429 // ColorID::IME* might return NS_TRANSPARENT, NS_SAME_AS_FOREGROUND_COLOR or
430 // NS_40PERCENT_FOREGROUND_COLOR.
431 // These values have particular meaning. Then, they are not an actual
433 static Maybe
<nscolor
> GetColor(ColorID
, ColorScheme
, UseStandins
);
435 // Gets the color with appropriate defaults for UseStandins, ColorScheme etc
436 // for a given frame.
437 static Maybe
<nscolor
> GetColor(ColorID
, const nsIFrame
*);
439 // Versions of the above which returns the color if found, or a default (which
440 // defaults to opaque black) otherwise.
441 static nscolor
Color(ColorID aId
, ColorScheme aScheme
,
442 UseStandins aUseStandins
,
443 nscolor aDefault
= NS_RGB(0, 0, 0)) {
444 return GetColor(aId
, aScheme
, aUseStandins
).valueOr(aDefault
);
447 static nscolor
Color(ColorID aId
, nsIFrame
* aFrame
,
448 nscolor aDefault
= NS_RGB(0, 0, 0)) {
449 return GetColor(aId
, aFrame
).valueOr(aDefault
);
453 * GetInt() and GetFloat() return a int or float value for aID. The result
454 * might be distance, time, some flags or a int value which has particular
455 * meaning. See each document at definition of each ID for the detail.
456 * The result is always 0 when they return error. Therefore, if you want to
457 * use a value for the default value, you should use the other method which
458 * returns int or float directly.
460 static nsresult
GetInt(IntID
, int32_t* aResult
);
461 static nsresult
GetFloat(FloatID aID
, float* aResult
);
463 static int32_t GetInt(IntID aID
, int32_t aDefault
= 0) {
465 if (NS_FAILED(GetInt(aID
, &result
))) {
471 static float GetFloat(FloatID aID
, float aDefault
= 0.0f
) {
473 if (NS_FAILED(GetFloat(aID
, &result
))) {
480 * Retrieve the name and style of a system-theme font. Returns true
481 * if the system theme specifies this font, false if a default should
482 * be used. In the latter case neither aName nor aStyle is modified.
484 * Size of the font should be in CSS pixels, not device pixels.
486 * @param aID Which system-theme font is wanted.
487 * @param aName The name of the font to use.
488 * @param aStyle Styling to apply to the font.
490 static bool GetFont(FontID aID
, nsString
& aName
, gfxFontStyle
& aStyle
);
493 * GetPasswordCharacter() returns a unicode character which should be used
494 * for a masked character in password editor. E.g., '*'.
496 static char16_t
GetPasswordCharacter();
499 * If the latest character in password field shouldn't be hidden by the
500 * result of GetPasswordCharacter(), GetEchoPassword() returns TRUE.
503 static bool GetEchoPassword();
506 * Whether we should be drawing in the titlebar by default.
508 static bool DrawInTitlebar();
511 * The millisecond to mask password value.
512 * This value is only valid when GetEchoPassword() returns true.
514 static uint32_t GetPasswordMaskDelay();
516 /** Gets theme information for about:support */
517 static void GetThemeInfo(nsACString
&);
520 * When system look and feel is changed, Refresh() must be called. Then,
521 * cached data would be released.
523 static void Refresh();
526 * GTK's initialization code can't be run off main thread, call this
527 * if you plan on using LookAndFeel off main thread later.
529 * This initialized state may get reset due to theme changes, so it
530 * must be called prior to each potential off-main-thread LookAndFeel
531 * call, not just once.
533 static void NativeInit();
535 static void SetData(widget::FullLookAndFeel
&& aTables
);
536 static void NotifyChangedAllWindows(widget::ThemeChangeKind
);
537 static bool HasPendingGlobalThemeChange() { return sGlobalThemeChanged
; }
538 static void HandleGlobalThemeChange() {
539 if (MOZ_UNLIKELY(HasPendingGlobalThemeChange())) {
540 DoHandleGlobalThemeChange();
543 static void EnsureColorSchemesInitialized() {
544 if (!sColorSchemeInitialized
) {
545 RecomputeColorSchemes();
547 MOZ_ASSERT(sColorSchemeInitialized
);
550 static ColorScheme sChromeColorScheme
;
551 static ColorScheme sContentColorScheme
;
554 static void RecomputeColorSchemes();
555 static bool sColorSchemeInitialized
;
557 static void DoHandleGlobalThemeChange();
558 // Set to true when ThemeChanged needs to be called on mTheme (and other
559 // global LookAndFeel. This is used because mTheme is a service, so there's
560 // no need to notify it from more than one prescontext.
561 static bool sGlobalThemeChanged
;
564 } // namespace mozilla
566 // ---------------------------------------------------------------------
567 // Special colors for ColorID::IME* and ColorID::SpellCheckerUnderline
568 // ---------------------------------------------------------------------
570 // For background color only.
571 constexpr nscolor NS_TRANSPARENT
= NS_RGBA(0x01, 0x00, 0x00, 0x00);
572 // For foreground color only.
573 constexpr nscolor NS_SAME_AS_FOREGROUND_COLOR
= NS_RGBA(0x02, 0x00, 0x00, 0x00);
574 constexpr nscolor NS_40PERCENT_FOREGROUND_COLOR
=
575 NS_RGBA(0x03, 0x00, 0x00, 0x00);
577 #define NS_IS_SELECTION_SPECIAL_COLOR(c) \
578 ((c) == NS_TRANSPARENT || (c) == NS_SAME_AS_FOREGROUND_COLOR || \
579 (c) == NS_40PERCENT_FOREGROUND_COLOR)
581 // ------------------------------------------
582 // Bits for IntID::AlertNotificationOrigin
583 // ------------------------------------------
585 #define NS_ALERT_HORIZONTAL 1
586 #define NS_ALERT_LEFT 2
587 #define NS_ALERT_TOP 4
589 #endif /* __LookAndFeel */