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"
18 #include "nsGkAtoms.h"
22 #include "nsIContent.h"
29 enum class StyleAppearance
: uint8_t;
31 } // namespace mozilla
33 class nsNativeTheme
: public nsITimerCallback
, public nsINamed
{
35 virtual ~nsNativeTheme() = default;
38 NS_DECL_NSITIMERCALLBACK
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
);
75 bool IsDefaultButton(nsIFrame
* aFrame
) {
76 return CheckBooleanAttr(aFrame
, nsGkAtoms::_default
);
79 bool IsButtonTypeMenu(nsIFrame
* aFrame
);
82 bool IsChecked(nsIFrame
* aFrame
) {
83 return GetCheckedOrSelected(aFrame
, false);
87 bool IsSelected(nsIFrame
* aFrame
) {
88 return GetCheckedOrSelected(aFrame
, true);
91 static bool IsFocused(nsIFrame
* aFrame
) {
92 return CheckBooleanAttr(aFrame
, nsGkAtoms::focused
);
96 int32_t GetScrollbarButtonType(nsIFrame
* aFrame
);
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
);
140 TreeSortDirection
GetTreeSortDirection(nsIFrame
* aFrame
);
141 bool IsLastTreeHeaderCell(nsIFrame
* aFrame
);
144 bool IsBottomTab(nsIFrame
* aFrame
);
145 bool IsFirstTab(nsIFrame
* aFrame
);
147 bool IsHorizontal(nsIFrame
* aFrame
);
150 bool IsIndeterminateProgress(nsIFrame
* aFrame
,
151 mozilla::EventStates aEventStates
);
152 bool IsVerticalProgress(nsIFrame
* aFrame
);
155 bool IsVerticalMeter(nsIFrame
* aFrame
);
158 bool IsReadOnly(nsIFrame
* aFrame
) {
159 return CheckBooleanAttr(aFrame
, nsGkAtoms::readonly
);
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
,
185 bool IsRangeHorizontal(nsIFrame
* aFrame
);
187 static bool IsDarkBackground(nsIFrame
* aFrame
);
188 static bool IsDarkColor(nscolor aColor
);
190 static bool IsWidgetScrollbarPart(mozilla::StyleAppearance aAppearance
);
193 uint32_t mAnimatedContentTimeout
;
194 nsCOMPtr
<nsITimer
> mAnimatedContentTimer
;
195 AutoTArray
<nsCOMPtr
<nsIContent
>, 20> mAnimatedContentList
;
198 #endif // _NSNATIVETHEME_H_