Bug 1735754 [wpt PR 31232] - Make the higher-order comparisons in the structured...
[gecko.git] / widget / nsNativeTheme.h
blobd7f6bcef4fd934c3447aff43aed0e7fb31267d94
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"
24 class nsIFrame;
25 class nsPresContext;
27 namespace mozilla {
28 class ComputedStyle;
29 enum class StyleAppearance : uint8_t;
30 class EventStates;
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::EventStates 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 // Accessors to widget-specific state information
67 bool IsDisabled(nsIFrame* aFrame, mozilla::EventStates aEventStates);
69 // RTL chrome direction
70 static bool IsFrameRTL(nsIFrame* aFrame);
72 static bool IsHTMLContent(nsIFrame* aFrame);
74 // button:
75 bool IsDefaultButton(nsIFrame* aFrame) {
76 return CheckBooleanAttr(aFrame, nsGkAtoms::_default);
79 bool IsButtonTypeMenu(nsIFrame* aFrame);
81 // checkbox:
82 bool IsChecked(nsIFrame* aFrame) {
83 return GetCheckedOrSelected(aFrame, false);
86 // radiobutton:
87 bool IsSelected(nsIFrame* aFrame) {
88 return GetCheckedOrSelected(aFrame, true);
91 static bool IsFocused(nsIFrame* aFrame) {
92 return CheckBooleanAttr(aFrame, nsGkAtoms::focused);
95 // scrollbar button:
96 int32_t GetScrollbarButtonType(nsIFrame* aFrame);
98 // tab:
99 bool IsSelectedTab(nsIFrame* aFrame) {
100 return CheckBooleanAttr(aFrame, nsGkAtoms::visuallyselected);
103 bool IsNextToSelectedTab(nsIFrame* aFrame, int32_t aOffset);
105 bool IsBeforeSelectedTab(nsIFrame* aFrame) {
106 return IsNextToSelectedTab(aFrame, -1);
109 bool IsAfterSelectedTab(nsIFrame* aFrame) {
110 return IsNextToSelectedTab(aFrame, 1);
113 bool IsLeftToSelectedTab(nsIFrame* aFrame) {
114 return IsFrameRTL(aFrame) ? IsAfterSelectedTab(aFrame)
115 : IsBeforeSelectedTab(aFrame);
118 bool IsRightToSelectedTab(nsIFrame* aFrame) {
119 return IsFrameRTL(aFrame) ? IsBeforeSelectedTab(aFrame)
120 : IsAfterSelectedTab(aFrame);
123 // button / toolbarbutton:
124 bool IsCheckedButton(nsIFrame* aFrame) {
125 return CheckBooleanAttr(aFrame, nsGkAtoms::checked);
128 bool IsSelectedButton(nsIFrame* aFrame) {
129 return CheckBooleanAttr(aFrame, nsGkAtoms::checked) ||
130 CheckBooleanAttr(aFrame, nsGkAtoms::selected);
133 bool IsOpenButton(nsIFrame* aFrame) {
134 return CheckBooleanAttr(aFrame, nsGkAtoms::open);
137 bool IsPressedButton(nsIFrame* aFrame);
139 // treeheadercell:
140 TreeSortDirection GetTreeSortDirection(nsIFrame* aFrame);
141 bool IsLastTreeHeaderCell(nsIFrame* aFrame);
143 // tab:
144 bool IsBottomTab(nsIFrame* aFrame);
145 bool IsFirstTab(nsIFrame* aFrame);
147 bool IsHorizontal(nsIFrame* aFrame);
149 // progressbar:
150 bool IsIndeterminateProgress(nsIFrame* aFrame,
151 mozilla::EventStates aEventStates);
152 bool IsVerticalProgress(nsIFrame* aFrame);
154 // meter:
155 bool IsVerticalMeter(nsIFrame* aFrame);
157 // textfield:
158 bool IsReadOnly(nsIFrame* aFrame) {
159 return CheckBooleanAttr(aFrame, nsGkAtoms::readonly);
162 // menupopup:
163 bool IsSubmenu(nsIFrame* aFrame, bool* aLeftOfParent);
165 // True if it's not a menubar item or menulist item
166 bool IsRegularMenuItem(nsIFrame* aFrame);
168 static bool CheckBooleanAttr(nsIFrame* aFrame, nsAtom* aAtom);
169 static int32_t CheckIntAttr(nsIFrame* aFrame, nsAtom* aAtom,
170 int32_t defaultValue);
172 // Helpers for progressbar.
173 static double GetProgressValue(nsIFrame* aFrame);
174 static double GetProgressMaxValue(nsIFrame* aFrame);
176 bool GetCheckedOrSelected(nsIFrame* aFrame, bool aCheckSelected);
177 bool GetIndeterminate(nsIFrame* aFrame);
179 bool QueueAnimatedContentForRefresh(nsIContent* aContent,
180 uint32_t aMinimumFrameRate);
182 nsIFrame* GetAdjacentSiblingFrameWithSameAppearance(nsIFrame* aFrame,
183 bool aNextSibling);
185 bool IsRangeHorizontal(nsIFrame* aFrame);
187 static bool IsDarkBackground(nsIFrame* aFrame);
188 static bool IsDarkColor(nscolor aColor);
190 static bool IsWidgetScrollbarPart(mozilla::StyleAppearance aAppearance);
192 private:
193 uint32_t mAnimatedContentTimeout;
194 nsCOMPtr<nsITimer> mAnimatedContentTimer;
195 AutoTArray<nsCOMPtr<nsIContent>, 20> mAnimatedContentList;
198 #endif // _NSNATIVETHEME_H_