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 using Modifiers
= uint16_t;
28 struct StyleColorSchemeFlags
;
35 class FullLookAndFeel
;
38 enum class StyleSystemColor
: uint8_t;
39 enum class StyleSystemColorScheme
: uint8_t;
40 enum class StyleSystemFont
: uint8_t;
44 using ColorID
= StyleSystemColor
;
45 using ColorScheme
= mozilla::ColorScheme
;
47 // When modifying this list, also modify nsXPLookAndFeel::sIntPrefs
48 // in widget/xpwidgts/nsXPLookAndFeel.cpp.
50 // default, may be overriden by OS
52 // Amount of blinks that happen before the caret stops blinking.
54 // pixel width of caret
56 // show the caret when text is selected?
57 ShowCaretDuringSelection
,
58 // select textfields when focused via tab/accesskey?
59 SelectTextfieldsOnKeyFocus
,
60 // delay before submenus open
62 // can popups overlap menu/task bar?
64 // should overlay scrollbars be used?
66 // allow H and V overlay scrollbars to overlap?
67 AllowOverlayScrollbarsOverlap
,
68 // skip navigating to disabled menu item?
69 SkipNavigatingDisabledMenuItem
,
70 // begin a drag if the mouse is moved further than the threshold while the
74 // Accessibility theme being used?
75 UseAccessibilityTheme
,
77 // position of scroll arrows in a scrollbar
80 // each button can take one of four values:
81 ScrollButtonLeftMouseButtonAction
,
82 // 0 - scrolls one line, 1 - scrolls one page
83 ScrollButtonMiddleMouseButtonAction
,
84 // 2 - scrolls to end, 3 - button ignored
85 ScrollButtonRightMouseButtonAction
,
87 // delay for opening spring loaded folders
89 // delay for closing spring loaded folders
91 // delay for triggering the tree scrolling
93 // delay for scrolling the tree
95 // the maximum number of lines to be scrolled at ones
97 // What type of tab-order to use
99 // Should menu items blink when they're chosen?
100 ChosenMenuItemsShouldBlink
,
103 * A Boolean value to determine whether the Windows accent color
104 * should be applied to the title bar.
106 * The value of this metric is not used on other platforms. These platforms
107 * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
109 WindowsAccentColorInTitlebar
,
112 * A Boolean value to determine whether the macOS Big Sur-specific
113 * theming should be used.
118 * A Boolean value to determine whether macOS is in RTL mode or not.
123 * AlertNotificationOrigin indicates from which corner of the
124 * screen alerts slide in, and from which direction (horizontal/vertical).
125 * 0, the default, represents bottom right, sliding vertically.
126 * Use any bitwise combination of the following constants:
127 * NS_ALERT_HORIZONTAL (1), NS_ALERT_LEFT (2), NS_ALERT_TOP (4).
137 AlertNotificationOrigin
,
140 * If true, clicking on a scrollbar (not as in dragging the thumb) defaults
141 * to scrolling the view corresponding to the clicked point. Otherwise, we
142 * only do so if the scrollbar is clicked using the middle mouse button or
143 * if shift is pressed when the scrollbar is clicked.
148 * IME and spell checker underline styles, the values should be
149 * NS_DECORATION_LINE_STYLE_*. They are defined below.
151 IMERawInputUnderlineStyle
,
152 IMESelectedRawTextUnderlineStyle
,
153 IMEConvertedTextUnderlineStyle
,
154 IMESelectedConvertedTextUnderline
,
155 SpellCheckerUnderlineStyle
,
158 * If this metric != 0, support window dragging on the menubar.
162 * 0: scrollbar button repeats to scroll only when cursor is on the button.
163 * 1: scrollbar button repeats to scroll even if cursor is outside of it.
165 ScrollbarButtonAutoRepeatBehavior
,
167 * A Boolean value to determine whether swipe animations should be used.
169 SwipeAnimationEnabled
,
172 * Controls whether overlay scrollbars display when the user moves
173 * the mouse in a scrollable frame.
175 ScrollbarDisplayOnMouseMove
,
178 * Overlay scrollbar animation constants.
180 ScrollbarFadeBeginDelay
,
181 ScrollbarFadeDuration
,
184 * Distance in pixels to offset the context menu from the cursor
187 ContextMenuOffsetVertical
,
188 ContextMenuOffsetHorizontal
,
191 * A boolean value indicating whether client-side decorations are
192 * supported by the user's GTK version.
197 * A boolean value indicating whether client-side decorations should
198 * contain a minimize button.
200 GTKCSDMinimizeButton
,
203 * A boolean value indicating whether client-side decorations should
204 * contain a maximize button.
206 GTKCSDMaximizeButton
,
209 * A boolean value indicating whether client-side decorations should
210 * contain a close button.
215 * An Integer value that will represent the position of the Minimize button
216 * in GTK Client side decoration header.
218 GTKCSDMinimizeButtonPosition
,
221 * An Integer value that will represent the position of the Maximize button
222 * in GTK Client side decoration header.
224 GTKCSDMaximizeButtonPosition
,
227 * An Integer value that will represent the position of the Close button
228 * in GTK Client side decoration header.
230 GTKCSDCloseButtonPosition
,
233 * A boolean value indicating whether titlebar buttons are located
234 * in left titlebar corner.
236 GTKCSDReversedPlacement
,
239 * A boolean value indicating whether or not the OS is using a dark theme,
240 * which we may want to switch to as well if not overridden by the user.
245 * Corresponding to prefers-reduced-motion.
246 * https://drafts.csswg.org/mediaqueries-5/#prefers-reduced-motion
250 PrefersReducedMotion
,
253 * Corresponding to prefers-reduced-transparency.
254 * https://drafts.csswg.org/mediaqueries-5/#prefers-reduced-transparency
258 PrefersReducedTransparency
,
261 * Corresponding to inverted-colors.
262 * https://drafts.csswg.org/mediaqueries-5/#inverted
269 * Corresponding to PointerCapabilities in ServoTypes.h
275 PrimaryPointerCapabilities
,
277 * Corresponding to union of PointerCapabilities values in ServoTypes.h
278 * E.g. if there is a mouse and a digitizer, the value will be
279 * 'Coarse | Fine | Hover'.
281 AllPointerCapabilities
,
283 /** The scrollbar size, in CSS pixels. */
286 /** A boolean value to determine whether a touch device is present */
287 TouchDeviceSupportPresent
,
289 /** GTK titlebar radius */
293 * Corresponding to dynamic-range.
294 * https://drafts.csswg.org/mediaqueries-5/#dynamic-range
301 /** Whether XUL panel animations are enabled. */
304 /* Whether we should hide the cursor while typing */
305 HideCursorWhileTyping
,
307 /* The StyleGtkThemeFamily of the current GTK theme. */
311 * Not an ID; used to define the range of valid IDs. Must be last.
316 // This is a common enough integer that seems worth the shortcut.
317 static bool UseOverlayScrollbars() {
318 return GetInt(IntID::UseOverlayScrollbars
);
321 // Returns keyCode value of a modifier key which is used for accesskey.
322 // Returns 0 if the platform doesn't support access key.
323 static uint32_t GetMenuAccessKey();
324 // Modifier mask for the menu accesskey.
325 static Modifiers
GetMenuAccessKeyModifiers();
328 eScrollArrow_None
= 0,
329 eScrollArrow_StartBackward
= 0x1000,
330 eScrollArrow_StartForward
= 0x0100,
331 eScrollArrow_EndBackward
= 0x0010,
332 eScrollArrow_EndForward
= 0x0001
336 // single arrow at each end
337 eScrollArrowStyle_Single
=
338 eScrollArrow_StartBackward
| eScrollArrow_EndForward
,
339 // both arrows at bottom/right, none at top/left
340 eScrollArrowStyle_BothAtBottom
=
341 eScrollArrow_EndBackward
| eScrollArrow_EndForward
,
342 // both arrows at both ends
343 eScrollArrowStyle_BothAtEachEnd
=
344 eScrollArrow_EndBackward
| eScrollArrow_EndForward
|
345 eScrollArrow_StartBackward
| eScrollArrow_StartForward
,
346 // both arrows at top/left, none at bottom/right
347 eScrollArrowStyle_BothAtTop
=
348 eScrollArrow_StartBackward
| eScrollArrow_StartForward
351 // When modifying this list, also modify nsXPLookAndFeel::sFloatPrefs
352 // in widget/nsXPLookAndFeel.cpp.
354 IMEUnderlineRelativeSize
,
355 SpellCheckerUnderlineRelativeSize
,
357 // The width/height ratio of the cursor. If used, the CaretWidth int metric
358 // should be added to the calculated caret width.
361 // GTK text scale factor.
364 // Mouse pointer scaling factor.
367 // Not an ID; used to define the range of valid IDs. Must be last.
371 using FontID
= mozilla::StyleSystemFont
;
373 static ColorScheme
SystemColorScheme() {
374 return GetInt(IntID::SystemUsesDarkTheme
) ? ColorScheme::Dark
375 : ColorScheme::Light
;
378 static bool IsDarkColor(nscolor
);
380 static ColorScheme
ColorSchemeForStyle(
381 const dom::Document
&, const StyleColorSchemeFlags
&,
382 ColorSchemeMode
= ColorSchemeMode::Used
);
383 static ColorScheme
ColorSchemeForFrame(
384 const nsIFrame
*, ColorSchemeMode
= ColorSchemeMode::Used
);
386 // Whether standins for native colors should be used (that is, colors faked,
387 // taken from win7, mostly). This forces light appearance, effectively.
388 enum class UseStandins
: bool { No
, Yes
};
389 static UseStandins
ShouldUseStandins(const dom::Document
&, ColorID
);
391 // Returns a native color value (might be overwritten by prefs) for a given
395 // ColorID::TextSelectForeground might return NS_SAME_AS_FOREGROUND_COLOR.
396 // ColorID::IME* might return NS_TRANSPARENT, NS_SAME_AS_FOREGROUND_COLOR or
397 // NS_40PERCENT_FOREGROUND_COLOR.
398 // These values have particular meaning. Then, they are not an actual
400 static Maybe
<nscolor
> GetColor(ColorID
, ColorScheme
, UseStandins
);
402 // Gets the color with appropriate defaults for UseStandins, ColorScheme etc
403 // for a given frame.
404 static Maybe
<nscolor
> GetColor(ColorID
, const nsIFrame
*);
406 // Versions of the above which returns the color if found, or a default (which
407 // defaults to opaque black) otherwise.
408 static nscolor
Color(ColorID aId
, ColorScheme aScheme
,
409 UseStandins aUseStandins
,
410 nscolor aDefault
= NS_RGB(0, 0, 0)) {
411 return GetColor(aId
, aScheme
, aUseStandins
).valueOr(aDefault
);
414 static nscolor
Color(ColorID aId
, nsIFrame
* aFrame
,
415 nscolor aDefault
= NS_RGB(0, 0, 0)) {
416 return GetColor(aId
, aFrame
).valueOr(aDefault
);
419 static float GetTextScaleFactor() {
420 float f
= GetFloat(FloatID::TextScaleFactor
, 1.0f
);
421 if (MOZ_UNLIKELY(f
<= 0.0f
)) {
427 struct ZoomSettings
{
428 float mFullZoom
= 1.0f
;
429 float mTextZoom
= 1.0f
;
432 static ZoomSettings
SystemZoomSettings();
435 * GetInt() and GetFloat() return a int or float value for aID. The result
436 * might be distance, time, some flags or a int value which has particular
437 * meaning. See each document at definition of each ID for the detail.
438 * The result is always 0 when they return error. Therefore, if you want to
439 * use a value for the default value, you should use the other method which
440 * returns int or float directly.
442 static nsresult
GetInt(IntID
, int32_t* aResult
);
443 static nsresult
GetFloat(FloatID aID
, float* aResult
);
445 static int32_t GetInt(IntID aID
, int32_t aDefault
= 0) {
447 if (NS_FAILED(GetInt(aID
, &result
))) {
453 static float GetFloat(FloatID aID
, float aDefault
= 0.0f
) {
455 if (NS_FAILED(GetFloat(aID
, &result
))) {
462 * Retrieve the name and style of a system-theme font. Returns true
463 * if the system theme specifies this font, false if a default should
464 * be used. In the latter case neither aName nor aStyle is modified.
466 * Size of the font should be in CSS pixels, not device pixels.
468 * @param aID Which system-theme font is wanted.
469 * @param aName The name of the font to use.
470 * @param aStyle Styling to apply to the font.
472 static bool GetFont(FontID aID
, nsString
& aName
, gfxFontStyle
& aStyle
);
475 * GetPasswordCharacter() returns a unicode character which should be used
476 * for a masked character in password editor. E.g., '*'.
478 static char16_t
GetPasswordCharacter();
481 * If the latest character in password field shouldn't be hidden by the
482 * result of GetPasswordCharacter(), GetEchoPassword() returns TRUE.
485 static bool GetEchoPassword();
488 * Whether we should be drawing in the titlebar by default.
490 static bool DrawInTitlebar();
492 enum class TitlebarAction
{
498 WindowMaximizeToggle
,
499 // We don't support more actions (maximize-horizontal, maximize-vertical,..)
500 // as they're implemented as part of Wayland gtk_surface1 protocol
501 // which is not accessible to us.
504 enum class TitlebarEvent
{
510 * Get system defined action for titlebar events.
512 static TitlebarAction
GetTitlebarAction(TitlebarEvent aEvent
);
515 * The millisecond to mask password value.
516 * This value is only valid when GetEchoPassword() returns true.
518 static uint32_t GetPasswordMaskDelay();
520 /** Gets theme information for about:support */
521 static void GetThemeInfo(nsACString
&);
524 * When system look and feel is changed, Refresh() must be called. Then,
525 * cached data would be released.
527 static void Refresh();
530 * GTK's initialization code can't be run off main thread, call this
531 * if you plan on using LookAndFeel off main thread later.
533 * This initialized state may get reset due to theme changes, so it
534 * must be called prior to each potential off-main-thread LookAndFeel
535 * call, not just once.
537 static void NativeInit();
539 static void SetData(widget::FullLookAndFeel
&& aTables
);
540 static void NotifyChangedAllWindows(widget::ThemeChangeKind
);
541 static bool HasPendingGlobalThemeChange() { return sGlobalThemeChanged
; }
542 static void HandleGlobalThemeChange() {
543 if (MOZ_UNLIKELY(HasPendingGlobalThemeChange())) {
544 DoHandleGlobalThemeChange();
549 static void DoHandleGlobalThemeChange();
550 // Set to true when ThemeChanged needs to be called on mTheme (and other
551 // global LookAndFeel. This is used because mTheme is a service, so there's
552 // no need to notify it from more than one prescontext.
553 static bool sGlobalThemeChanged
;
556 } // namespace mozilla
558 // ---------------------------------------------------------------------
559 // Special colors for ColorID::IME* and ColorID::SpellCheckerUnderline
560 // ---------------------------------------------------------------------
562 // For background color only.
563 constexpr nscolor NS_TRANSPARENT
= NS_RGBA(0x01, 0x00, 0x00, 0x00);
564 // For foreground color only.
565 constexpr nscolor NS_SAME_AS_FOREGROUND_COLOR
= NS_RGBA(0x02, 0x00, 0x00, 0x00);
566 constexpr nscolor NS_40PERCENT_FOREGROUND_COLOR
=
567 NS_RGBA(0x03, 0x00, 0x00, 0x00);
569 #define NS_IS_SELECTION_SPECIAL_COLOR(c) \
570 ((c) == NS_TRANSPARENT || (c) == NS_SAME_AS_FOREGROUND_COLOR || \
571 (c) == NS_40PERCENT_FOREGROUND_COLOR)
573 // ------------------------------------------
574 // Bits for IntID::AlertNotificationOrigin
575 // ------------------------------------------
577 #define NS_ALERT_HORIZONTAL 1
578 #define NS_ALERT_LEFT 2
579 #define NS_ALERT_TOP 4
581 #endif /* __LookAndFeel */