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 } // namespace mozilla
31 class nsNativeTheme
: public nsITimerCallback
, public nsINamed
34 virtual ~nsNativeTheme() {}
37 NS_DECL_NSITIMERCALLBACK
40 enum ScrollbarButtonType
{
41 eScrollbarButton_UpTop
= 0,
42 eScrollbarButton_Down
= 1 << 0,
43 eScrollbarButton_Bottom
= 1 << 1
46 enum TreeSortDirection
{
47 eTreeSortDirection_Descending
,
48 eTreeSortDirection_Natural
,
49 eTreeSortDirection_Ascending
54 // Returns the content state (hover, focus, etc), see EventStateManager.h
55 mozilla::EventStates
GetContentState(nsIFrame
* aFrame
, uint8_t aWidgetType
);
57 // Returns whether the widget is already styled by content
58 // Normally called from ThemeSupportsWidget to turn off native theming
59 // for elements that are already styled.
60 bool IsWidgetStyled(nsPresContext
* aPresContext
, nsIFrame
* aFrame
,
63 // Accessors to widget-specific state information
65 bool IsDisabled(nsIFrame
* aFrame
, mozilla::EventStates aEventStates
);
67 // RTL chrome direction
68 static bool IsFrameRTL(nsIFrame
* aFrame
);
70 bool IsHTMLContent(nsIFrame
*aFrame
);
73 bool IsDefaultButton(nsIFrame
* aFrame
) {
74 return CheckBooleanAttr(aFrame
, nsGkAtoms::_default
);
77 bool IsButtonTypeMenu(nsIFrame
* aFrame
);
80 bool IsChecked(nsIFrame
* aFrame
) {
81 return GetCheckedOrSelected(aFrame
, false);
85 bool IsSelected(nsIFrame
* aFrame
) {
86 return GetCheckedOrSelected(aFrame
, true);
89 bool IsFocused(nsIFrame
* aFrame
) {
90 return CheckBooleanAttr(aFrame
, nsGkAtoms::focused
);
94 int32_t GetScrollbarButtonType(nsIFrame
* aFrame
);
97 bool IsSelectedTab(nsIFrame
* aFrame
) {
98 return CheckBooleanAttr(aFrame
, nsGkAtoms::visuallyselected
);
101 bool IsNextToSelectedTab(nsIFrame
* aFrame
, int32_t aOffset
);
103 bool IsBeforeSelectedTab(nsIFrame
* aFrame
) {
104 return IsNextToSelectedTab(aFrame
, -1);
107 bool IsAfterSelectedTab(nsIFrame
* aFrame
) {
108 return IsNextToSelectedTab(aFrame
, 1);
111 bool IsLeftToSelectedTab(nsIFrame
* aFrame
) {
112 return IsFrameRTL(aFrame
) ? IsAfterSelectedTab(aFrame
) : IsBeforeSelectedTab(aFrame
);
115 bool IsRightToSelectedTab(nsIFrame
* aFrame
) {
116 return IsFrameRTL(aFrame
) ? IsBeforeSelectedTab(aFrame
) : IsAfterSelectedTab(aFrame
);
119 // button / toolbarbutton:
120 bool IsCheckedButton(nsIFrame
* aFrame
) {
121 return CheckBooleanAttr(aFrame
, nsGkAtoms::checked
);
124 bool IsSelectedButton(nsIFrame
* aFrame
) {
125 return CheckBooleanAttr(aFrame
, nsGkAtoms::checked
) ||
126 CheckBooleanAttr(aFrame
, nsGkAtoms::selected
);
129 bool IsOpenButton(nsIFrame
* aFrame
) {
130 return CheckBooleanAttr(aFrame
, nsGkAtoms::open
);
133 bool IsPressedButton(nsIFrame
* aFrame
);
136 TreeSortDirection
GetTreeSortDirection(nsIFrame
* aFrame
);
137 bool IsLastTreeHeaderCell(nsIFrame
* aFrame
);
140 bool IsBottomTab(nsIFrame
* aFrame
);
141 bool IsFirstTab(nsIFrame
* aFrame
);
143 bool IsHorizontal(nsIFrame
* aFrame
);
146 bool IsIndeterminateProgress(nsIFrame
* aFrame
,
147 mozilla::EventStates aEventStates
);
148 bool IsVerticalProgress(nsIFrame
* aFrame
);
151 bool IsVerticalMeter(nsIFrame
* aFrame
);
154 bool IsReadOnly(nsIFrame
* aFrame
) {
155 return CheckBooleanAttr(aFrame
, nsGkAtoms::readonly
);
159 bool IsSubmenu(nsIFrame
* aFrame
, bool* aLeftOfParent
);
161 // True if it's not a menubar item or menulist item
162 bool IsRegularMenuItem(nsIFrame
*aFrame
);
164 bool IsMenuListEditable(nsIFrame
*aFrame
);
166 nsIPresShell
*GetPresShell(nsIFrame
* aFrame
);
167 static bool CheckBooleanAttr(nsIFrame
* aFrame
, nsAtom
* aAtom
);
168 static int32_t CheckIntAttr(nsIFrame
* aFrame
, nsAtom
* aAtom
, int32_t defaultValue
);
170 // Helpers for progressbar.
171 static double GetProgressValue(nsIFrame
* aFrame
);
172 static double GetProgressMaxValue(nsIFrame
* aFrame
);
174 bool GetCheckedOrSelected(nsIFrame
* aFrame
, bool aCheckSelected
);
175 bool GetIndeterminate(nsIFrame
* aFrame
);
177 bool QueueAnimatedContentForRefresh(nsIContent
* aContent
,
178 uint32_t aMinimumFrameRate
);
180 nsIFrame
* GetAdjacentSiblingFrameWithSameAppearance(nsIFrame
* aFrame
,
183 bool IsRangeHorizontal(nsIFrame
* aFrame
);
186 bool IsDarkBackground(nsIFrame
* aFrame
);
189 uint32_t mAnimatedContentTimeout
;
190 nsCOMPtr
<nsITimer
> mAnimatedContentTimer
;
191 AutoTArray
<nsCOMPtr
<nsIContent
>, 20> mAnimatedContentList
;
194 #endif // _NSNATIVETHEME_H_