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
9 #ifndef _NSNATIVETHEME_H_
10 #define _NSNATIVETHEME_H_
12 #include "nsAlgorithm.h"
17 #include "nsGkAtoms.h"
21 #include "nsIContent.h"
29 enum class StyleAppearance
: uint8_t;
31 } // namespace mozilla
33 class nsNativeTheme
: public nsITimerCallback
, public nsINamed
36 virtual ~nsNativeTheme() {}
39 NS_DECL_NSITIMERCALLBACK
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
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
);
76 bool IsDefaultButton(nsIFrame
* aFrame
) {
77 return CheckBooleanAttr(aFrame
, nsGkAtoms::_default
);
80 bool IsButtonTypeMenu(nsIFrame
* aFrame
);
83 bool IsChecked(nsIFrame
* aFrame
) {
84 return GetCheckedOrSelected(aFrame
, false);
88 bool IsSelected(nsIFrame
* aFrame
) {
89 return GetCheckedOrSelected(aFrame
, true);
92 bool IsFocused(nsIFrame
* aFrame
) {
93 return CheckBooleanAttr(aFrame
, nsGkAtoms::focused
);
97 int32_t GetScrollbarButtonType(nsIFrame
* aFrame
);
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
);
139 TreeSortDirection
GetTreeSortDirection(nsIFrame
* aFrame
);
140 bool IsLastTreeHeaderCell(nsIFrame
* aFrame
);
143 bool IsBottomTab(nsIFrame
* aFrame
);
144 bool IsFirstTab(nsIFrame
* aFrame
);
146 bool IsHorizontal(nsIFrame
* aFrame
);
149 bool IsIndeterminateProgress(nsIFrame
* aFrame
,
150 mozilla::EventStates aEventStates
);
151 bool IsVerticalProgress(nsIFrame
* aFrame
);
154 bool IsVerticalMeter(nsIFrame
* aFrame
);
157 bool IsReadOnly(nsIFrame
* aFrame
) {
158 return CheckBooleanAttr(aFrame
, nsGkAtoms::readonly
);
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
,
184 bool IsRangeHorizontal(nsIFrame
* aFrame
);
187 bool IsDarkBackground(nsIFrame
* aFrame
);
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
);
197 uint32_t mAnimatedContentTimeout
;
198 nsCOMPtr
<nsITimer
> mAnimatedContentTimer
;
199 AutoTArray
<nsCOMPtr
<nsIContent
>, 20> mAnimatedContentList
;
202 #endif // _NSNATIVETHEME_H_