Bug 1487655 [wpt PR 12775] - [css-properties-values-api] Typify CSSStyleValue.parse...
[gecko.git] / widget / nsNativeTheme.h
blob41749dd891c2360567628801e24812af2496390f
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 "nsCOMPtr.h"
15 #include "nsString.h"
16 #include "nsMargin.h"
17 #include "nsGkAtoms.h"
18 #include "nsTArray.h"
19 #include "nsINamed.h"
20 #include "nsITimer.h"
21 #include "nsIContent.h"
23 class nsIFrame;
24 class nsIPresShell;
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
35 protected:
36 virtual ~nsNativeTheme() {}
38 NS_DECL_ISUPPORTS
39 NS_DECL_NSITIMERCALLBACK
40 NS_DECL_NSINAMED
42 enum ScrollbarButtonType {
43 eScrollbarButton_UpTop = 0,
44 eScrollbarButton_Down = 1 << 0,
45 eScrollbarButton_Bottom = 1 << 1
48 enum TreeSortDirection {
49 eTreeSortDirection_Descending,
50 eTreeSortDirection_Natural,
51 eTreeSortDirection_Ascending
54 nsNativeTheme();
56 // Returns the content state (hover, focus, etc), see EventStateManager.h
57 mozilla::EventStates GetContentState(nsIFrame* aFrame,
58 mozilla::StyleAppearance aWidgetType);
60 // Returns whether the widget is already styled by content
61 // Normally called from ThemeSupportsWidget to turn off native theming
62 // for elements that are already styled.
63 bool IsWidgetStyled(nsPresContext* aPresContext, nsIFrame* aFrame,
64 mozilla::StyleAppearance aWidgetType);
66 // Accessors to widget-specific state information
68 bool IsDisabled(nsIFrame* aFrame, mozilla::EventStates aEventStates);
70 // RTL chrome direction
71 static bool IsFrameRTL(nsIFrame* aFrame);
73 bool IsHTMLContent(nsIFrame *aFrame);
75 // button:
76 bool IsDefaultButton(nsIFrame* aFrame) {
77 return CheckBooleanAttr(aFrame, nsGkAtoms::_default);
80 bool IsButtonTypeMenu(nsIFrame* aFrame);
82 // checkbox:
83 bool IsChecked(nsIFrame* aFrame) {
84 return GetCheckedOrSelected(aFrame, false);
87 // radiobutton:
88 bool IsSelected(nsIFrame* aFrame) {
89 return GetCheckedOrSelected(aFrame, true);
92 bool IsFocused(nsIFrame* aFrame) {
93 return CheckBooleanAttr(aFrame, nsGkAtoms::focused);
96 // scrollbar button:
97 int32_t GetScrollbarButtonType(nsIFrame* aFrame);
99 // tab:
100 bool IsSelectedTab(nsIFrame* aFrame) {
101 return CheckBooleanAttr(aFrame, nsGkAtoms::visuallyselected);
104 bool IsNextToSelectedTab(nsIFrame* aFrame, int32_t aOffset);
106 bool IsBeforeSelectedTab(nsIFrame* aFrame) {
107 return IsNextToSelectedTab(aFrame, -1);
110 bool IsAfterSelectedTab(nsIFrame* aFrame) {
111 return IsNextToSelectedTab(aFrame, 1);
114 bool IsLeftToSelectedTab(nsIFrame* aFrame) {
115 return IsFrameRTL(aFrame) ? IsAfterSelectedTab(aFrame) : IsBeforeSelectedTab(aFrame);
118 bool IsRightToSelectedTab(nsIFrame* aFrame) {
119 return IsFrameRTL(aFrame) ? IsBeforeSelectedTab(aFrame) : IsAfterSelectedTab(aFrame);
122 // button / toolbarbutton:
123 bool IsCheckedButton(nsIFrame* aFrame) {
124 return CheckBooleanAttr(aFrame, nsGkAtoms::checked);
127 bool IsSelectedButton(nsIFrame* aFrame) {
128 return CheckBooleanAttr(aFrame, nsGkAtoms::checked) ||
129 CheckBooleanAttr(aFrame, nsGkAtoms::selected);
132 bool IsOpenButton(nsIFrame* aFrame) {
133 return CheckBooleanAttr(aFrame, nsGkAtoms::open);
136 bool IsPressedButton(nsIFrame* aFrame);
138 // treeheadercell:
139 TreeSortDirection GetTreeSortDirection(nsIFrame* aFrame);
140 bool IsLastTreeHeaderCell(nsIFrame* aFrame);
142 // tab:
143 bool IsBottomTab(nsIFrame* aFrame);
144 bool IsFirstTab(nsIFrame* aFrame);
146 bool IsHorizontal(nsIFrame* aFrame);
148 // progressbar:
149 bool IsIndeterminateProgress(nsIFrame* aFrame,
150 mozilla::EventStates aEventStates);
151 bool IsVerticalProgress(nsIFrame* aFrame);
153 // meter:
154 bool IsVerticalMeter(nsIFrame* aFrame);
156 // textfield:
157 bool IsReadOnly(nsIFrame* aFrame) {
158 return CheckBooleanAttr(aFrame, nsGkAtoms::readonly);
161 // menupopup:
162 bool IsSubmenu(nsIFrame* aFrame, bool* aLeftOfParent);
164 // True if it's not a menubar item or menulist item
165 bool IsRegularMenuItem(nsIFrame *aFrame);
167 nsIPresShell *GetPresShell(nsIFrame* aFrame);
168 static bool CheckBooleanAttr(nsIFrame* aFrame, nsAtom* aAtom);
169 static int32_t CheckIntAttr(nsIFrame* aFrame, nsAtom* aAtom, int32_t defaultValue);
171 // Helpers for progressbar.
172 static double GetProgressValue(nsIFrame* aFrame);
173 static double GetProgressMaxValue(nsIFrame* aFrame);
175 bool GetCheckedOrSelected(nsIFrame* aFrame, bool aCheckSelected);
176 bool GetIndeterminate(nsIFrame* aFrame);
178 bool QueueAnimatedContentForRefresh(nsIContent* aContent,
179 uint32_t aMinimumFrameRate);
181 nsIFrame* GetAdjacentSiblingFrameWithSameAppearance(nsIFrame* aFrame,
182 bool aNextSibling);
184 bool IsRangeHorizontal(nsIFrame* aFrame);
186 // scrollbar
187 bool IsDarkBackground(nsIFrame* aFrame);
188 // custom scrollbar
189 typedef nscolor (*AutoColorGetter)(mozilla::ComputedStyle*);
190 bool IsWidgetScrollbarPart(mozilla::StyleAppearance aWidgetType);
191 nscolor GetScrollbarFaceColor(mozilla::ComputedStyle* aStyle,
192 AutoColorGetter aAutoGetter);
193 nscolor GetScrollbarTrackColor(mozilla::ComputedStyle* aStyle,
194 AutoColorGetter aAutoGetter);
196 private:
197 uint32_t mAnimatedContentTimeout;
198 nsCOMPtr<nsITimer> mAnimatedContentTimer;
199 AutoTArray<nsCOMPtr<nsIContent>, 20> mAnimatedContentList;
202 #endif // _NSNATIVETHEME_H_