CLOSED TREE: TraceMonkey merge head. (a=blockers)
[mozilla-central.git] / widget / src / xpwidgets / nsNativeTheme.h
blob72abbce13651a0fd7738709c5a1aaf35d6203dc4
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 2002
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Brian Ryner <bryner@brianryner.com> (Original Author)
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 // This defines a common base class for nsITheme implementations, to reduce
40 // code duplication.
42 #include "prtypes.h"
43 #include "nsIAtom.h"
44 #include "nsCOMPtr.h"
45 #include "nsString.h"
46 #include "nsMargin.h"
47 #include "nsILookAndFeel.h"
48 #include "nsWidgetAtoms.h"
49 #include "nsEventStates.h"
50 #include "nsTArray.h"
51 #include "nsITimer.h"
53 class nsIContent;
54 class nsIFrame;
55 class nsIPresShell;
56 class nsPresContext;
58 class nsNativeTheme : public nsITimerCallback
60 protected:
62 NS_DECL_ISUPPORTS
63 NS_DECL_NSITIMERCALLBACK
65 enum ScrollbarButtonType {
66 eScrollbarButton_UpTop = 0,
67 eScrollbarButton_Down = 1 << 0,
68 eScrollbarButton_Bottom = 1 << 1
71 enum TreeSortDirection {
72 eTreeSortDirection_Descending,
73 eTreeSortDirection_Natural,
74 eTreeSortDirection_Ascending
77 nsNativeTheme();
79 // Returns the content state (hover, focus, etc), see nsIEventStateManager.h
80 nsEventStates GetContentState(nsIFrame* aFrame, PRUint8 aWidgetType);
82 // Returns whether the widget is already styled by content
83 // Normally called from ThemeSupportsWidget to turn off native theming
84 // for elements that are already styled.
85 PRBool IsWidgetStyled(nsPresContext* aPresContext, nsIFrame* aFrame,
86 PRUint8 aWidgetType);
88 // Accessors to widget-specific state information
90 bool IsDisabled(nsIFrame* aFrame, nsEventStates aEventStates);
92 // RTL chrome direction
93 PRBool IsFrameRTL(nsIFrame* aFrame);
95 // button:
96 PRBool IsDefaultButton(nsIFrame* aFrame) {
97 return CheckBooleanAttr(aFrame, nsWidgetAtoms::_default);
100 PRBool IsButtonTypeMenu(nsIFrame* aFrame);
102 // checkbox:
103 PRBool IsChecked(nsIFrame* aFrame) {
104 return GetCheckedOrSelected(aFrame, PR_FALSE);
107 // radiobutton:
108 PRBool IsSelected(nsIFrame* aFrame) {
109 return GetCheckedOrSelected(aFrame, PR_TRUE);
112 PRBool IsFocused(nsIFrame* aFrame) {
113 return CheckBooleanAttr(aFrame, nsWidgetAtoms::focused);
116 // scrollbar button:
117 PRInt32 GetScrollbarButtonType(nsIFrame* aFrame);
119 // tab:
120 PRBool IsSelectedTab(nsIFrame* aFrame) {
121 return CheckBooleanAttr(aFrame, nsWidgetAtoms::selected);
124 PRBool IsNextToSelectedTab(nsIFrame* aFrame, PRInt32 aOffset);
126 PRBool IsBeforeSelectedTab(nsIFrame* aFrame) {
127 return IsNextToSelectedTab(aFrame, -1);
130 PRBool IsAfterSelectedTab(nsIFrame* aFrame) {
131 return IsNextToSelectedTab(aFrame, 1);
134 PRBool IsLeftToSelectedTab(nsIFrame* aFrame) {
135 return IsFrameRTL(aFrame) ? IsAfterSelectedTab(aFrame) : IsBeforeSelectedTab(aFrame);
138 PRBool IsRightToSelectedTab(nsIFrame* aFrame) {
139 return IsFrameRTL(aFrame) ? IsBeforeSelectedTab(aFrame) : IsAfterSelectedTab(aFrame);
142 // button / toolbarbutton:
143 PRBool IsCheckedButton(nsIFrame* aFrame) {
144 return CheckBooleanAttr(aFrame, nsWidgetAtoms::checked);
147 PRBool IsOpenButton(nsIFrame* aFrame) {
148 return CheckBooleanAttr(aFrame, nsWidgetAtoms::open);
151 // treeheadercell:
152 TreeSortDirection GetTreeSortDirection(nsIFrame* aFrame);
153 PRBool IsLastTreeHeaderCell(nsIFrame* aFrame);
155 // tab:
156 PRBool IsBottomTab(nsIFrame* aFrame);
157 PRBool IsFirstTab(nsIFrame* aFrame);
158 PRBool IsLastTab(nsIFrame* aFrame);
160 PRBool IsHorizontal(nsIFrame* aFrame);
162 // progressbar:
163 PRBool IsIndeterminateProgress(nsIFrame* aFrame);
165 PRInt32 GetProgressValue(nsIFrame* aFrame) {
166 return CheckIntAttr(aFrame, nsWidgetAtoms::value, 0);
169 PRInt32 GetProgressMaxValue(nsIFrame* aFrame) {
170 return PR_MAX(CheckIntAttr(aFrame, nsWidgetAtoms::max, 100), 1);
173 // textfield:
174 PRBool IsReadOnly(nsIFrame* aFrame) {
175 return CheckBooleanAttr(aFrame, nsWidgetAtoms::readonly);
178 // menupopup:
179 PRBool IsSubmenu(nsIFrame* aFrame, PRBool* aLeftOfParent);
181 nsIPresShell *GetPresShell(nsIFrame* aFrame);
182 PRInt32 CheckIntAttr(nsIFrame* aFrame, nsIAtom* aAtom, PRInt32 defaultValue);
183 PRBool CheckBooleanAttr(nsIFrame* aFrame, nsIAtom* aAtom);
185 PRBool GetCheckedOrSelected(nsIFrame* aFrame, PRBool aCheckSelected);
186 PRBool GetIndeterminate(nsIFrame* aFrame);
188 PRBool QueueAnimatedContentForRefresh(nsIContent* aContent,
189 PRUint32 aMinimumFrameRate);
191 private:
192 PRUint32 mAnimatedContentTimeout;
193 nsCOMPtr<nsITimer> mAnimatedContentTimer;
194 nsAutoTArray<nsCOMPtr<nsIContent>, 20> mAnimatedContentList;