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"
23 #include "mozilla/dom/RustTypes.h"
30 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::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
);
71 bool IsDefaultButton(nsIFrame
* aFrame
) {
72 return CheckBooleanAttr(aFrame
, nsGkAtoms::_default
);
75 bool IsButtonTypeMenu(nsIFrame
* aFrame
);
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
);
119 TreeSortDirection
GetTreeSortDirection(nsIFrame
* aFrame
);
120 bool IsLastTreeHeaderCell(nsIFrame
* aFrame
);
123 bool IsBottomTab(nsIFrame
* aFrame
);
124 bool IsFirstTab(nsIFrame
* aFrame
);
126 bool IsHorizontal(nsIFrame
* aFrame
);
129 bool IsVerticalProgress(nsIFrame
* aFrame
);
132 bool IsVerticalMeter(nsIFrame
* aFrame
);
135 bool IsReadOnly(nsIFrame
* aFrame
) {
136 return CheckBooleanAttr(aFrame
, nsGkAtoms::readonly
);
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
,
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
);
165 uint32_t mAnimatedContentTimeout
;
166 nsCOMPtr
<nsITimer
> mAnimatedContentTimer
;
167 AutoTArray
<nsCOMPtr
<nsIContent
>, 20> mAnimatedContentList
;
170 #endif // _NSNATIVETHEME_H_