Bug 1839316: part 5) Guard the "fetchpriority" attribute behind a pref. r=kershaw...
[gecko.git] / widget / nsNativeTheme.h
blob28a8c0cc3fad6cfd1a12baf8e523e252573e6b12
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 // This defines a common base class for nsITheme implementations, to reduce
7 // code duplication.
9 #ifndef _NSNATIVETHEME_H_
10 #define _NSNATIVETHEME_H_
12 #include "nsAlgorithm.h"
13 #include "nsAtom.h"
14 #include "nsColor.h"
15 #include "nsCOMPtr.h"
16 #include "nsString.h"
17 #include "nsMargin.h"
18 #include "nsGkAtoms.h"
19 #include "nsTArray.h"
20 #include "nsINamed.h"
21 #include "nsITimer.h"
22 #include "nsIContent.h"
23 #include "mozilla/dom/RustTypes.h"
25 class nsIFrame;
26 class nsPresContext;
28 namespace mozilla {
29 class ComputedStyle;
30 enum class StyleAppearance : uint8_t;
31 } // namespace mozilla
33 class nsNativeTheme : public nsITimerCallback, public nsINamed {
34 protected:
35 virtual ~nsNativeTheme() = default;
37 NS_DECL_ISUPPORTS
38 NS_DECL_NSITIMERCALLBACK
39 NS_DECL_NSINAMED
41 nsNativeTheme();
43 public:
44 enum ScrollbarButtonType {
45 eScrollbarButton_UpTop = 0,
46 eScrollbarButton_Down = 1 << 0,
47 eScrollbarButton_Bottom = 1 << 1
50 enum TreeSortDirection {
51 eTreeSortDirection_Descending,
52 eTreeSortDirection_Natural,
53 eTreeSortDirection_Ascending
55 // Returns the content state (hover, focus, etc), see EventStateManager.h
56 static mozilla::dom::ElementState GetContentState(
57 nsIFrame* aFrame, mozilla::StyleAppearance aAppearance);
59 // Returns whether the widget is already styled by content
60 // Normally called from ThemeSupportsWidget to turn off native theming
61 // for elements that are already styled.
62 bool IsWidgetStyled(nsPresContext* aPresContext, nsIFrame* aFrame,
63 mozilla::StyleAppearance aAppearance);
65 // RTL chrome direction
66 static bool IsFrameRTL(nsIFrame* aFrame);
68 static bool IsHTMLContent(nsIFrame* aFrame);
70 // button:
71 bool IsDefaultButton(nsIFrame* aFrame) {
72 return CheckBooleanAttr(aFrame, nsGkAtoms::_default);
75 bool IsButtonTypeMenu(nsIFrame* aFrame);
77 // tab:
78 bool IsSelectedTab(nsIFrame* aFrame) {
79 return CheckBooleanAttr(aFrame, nsGkAtoms::visuallyselected);
82 bool IsNextToSelectedTab(nsIFrame* aFrame, int32_t aOffset);
84 bool IsBeforeSelectedTab(nsIFrame* aFrame) {
85 return IsNextToSelectedTab(aFrame, -1);
88 bool IsAfterSelectedTab(nsIFrame* aFrame) {
89 return IsNextToSelectedTab(aFrame, 1);
92 bool IsLeftToSelectedTab(nsIFrame* aFrame) {
93 return IsFrameRTL(aFrame) ? IsAfterSelectedTab(aFrame)
94 : IsBeforeSelectedTab(aFrame);
97 bool IsRightToSelectedTab(nsIFrame* aFrame) {
98 return IsFrameRTL(aFrame) ? IsBeforeSelectedTab(aFrame)
99 : IsAfterSelectedTab(aFrame);
102 // button / toolbarbutton:
103 bool IsCheckedButton(nsIFrame* aFrame) {
104 return CheckBooleanAttr(aFrame, nsGkAtoms::checked);
107 bool IsSelectedButton(nsIFrame* aFrame) {
108 return CheckBooleanAttr(aFrame, nsGkAtoms::checked) ||
109 CheckBooleanAttr(aFrame, nsGkAtoms::selected);
112 bool IsOpenButton(nsIFrame* aFrame) {
113 return CheckBooleanAttr(aFrame, nsGkAtoms::open);
116 bool IsPressedButton(nsIFrame* aFrame);
118 // treeheadercell:
119 TreeSortDirection GetTreeSortDirection(nsIFrame* aFrame);
120 bool IsLastTreeHeaderCell(nsIFrame* aFrame);
122 // tab:
123 bool IsBottomTab(nsIFrame* aFrame);
124 bool IsFirstTab(nsIFrame* aFrame);
126 bool IsHorizontal(nsIFrame* aFrame);
128 // progressbar:
129 bool IsVerticalProgress(nsIFrame* aFrame);
131 // meter:
132 bool IsVerticalMeter(nsIFrame* aFrame);
134 // textfield:
135 bool IsReadOnly(nsIFrame* aFrame) {
136 return CheckBooleanAttr(aFrame, nsGkAtoms::readonly);
139 // menupopup:
140 bool IsSubmenu(nsIFrame* aFrame, bool* aLeftOfParent);
142 static bool CheckBooleanAttr(nsIFrame* aFrame, nsAtom* aAtom);
143 static int32_t CheckIntAttr(nsIFrame* aFrame, nsAtom* aAtom,
144 int32_t defaultValue);
146 // Helpers for progressbar.
147 static double GetProgressValue(nsIFrame* aFrame);
148 static double GetProgressMaxValue(nsIFrame* aFrame);
150 bool QueueAnimatedContentForRefresh(nsIContent* aContent,
151 uint32_t aMinimumFrameRate);
153 nsIFrame* GetAdjacentSiblingFrameWithSameAppearance(nsIFrame* aFrame,
154 bool aNextSibling);
156 bool IsRangeHorizontal(nsIFrame* aFrame);
158 static bool IsDarkBackgroundForScrollbar(nsIFrame*);
159 static bool IsDarkBackground(nsIFrame*);
161 static bool IsWidgetScrollbarPart(mozilla::StyleAppearance);
162 static bool IsWidgetAlwaysNonNative(nsIFrame*, mozilla::StyleAppearance);
164 private:
165 uint32_t mAnimatedContentTimeout;
166 nsCOMPtr<nsITimer> mAnimatedContentTimer;
167 AutoTArray<nsCOMPtr<nsIContent>, 20> mAnimatedContentList;
170 #endif // _NSNATIVETHEME_H_