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
4 : *
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/
9 : *
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.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
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.
21 : *
22 : * Contributor(s):
23 : * Brian Ryner <bryner@brianryner.com> (Original Author)
24 : *
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.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : // This defines a common base class for nsITheme implementations, to reduce
40 : // code duplication.
41 :
42 : #include "prtypes.h"
43 : #include "nsAlgorithm.h"
44 : #include "nsIAtom.h"
45 : #include "nsCOMPtr.h"
46 : #include "nsString.h"
47 : #include "nsMargin.h"
48 : #include "nsGkAtoms.h"
49 : #include "nsEventStates.h"
50 : #include "nsTArray.h"
51 : #include "nsITimer.h"
52 :
53 : class nsIContent;
54 : class nsIFrame;
55 : class nsIPresShell;
56 : class nsPresContext;
57 :
58 : class nsNativeTheme : public nsITimerCallback
59 0 : {
60 : protected:
61 :
62 : NS_DECL_ISUPPORTS
63 : NS_DECL_NSITIMERCALLBACK
64 :
65 : enum ScrollbarButtonType {
66 : eScrollbarButton_UpTop = 0,
67 : eScrollbarButton_Down = 1 << 0,
68 : eScrollbarButton_Bottom = 1 << 1
69 : };
70 :
71 : enum TreeSortDirection {
72 : eTreeSortDirection_Descending,
73 : eTreeSortDirection_Natural,
74 : eTreeSortDirection_Ascending
75 : };
76 :
77 : nsNativeTheme();
78 :
79 : // Returns the content state (hover, focus, etc), see nsEventStateManager.h
80 : nsEventStates GetContentState(nsIFrame* aFrame, PRUint8 aWidgetType);
81 :
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 : bool IsWidgetStyled(nsPresContext* aPresContext, nsIFrame* aFrame,
86 : PRUint8 aWidgetType);
87 :
88 : // Accessors to widget-specific state information
89 :
90 : bool IsDisabled(nsIFrame* aFrame, nsEventStates aEventStates);
91 :
92 : // RTL chrome direction
93 : bool IsFrameRTL(nsIFrame* aFrame);
94 :
95 : // button:
96 0 : bool IsDefaultButton(nsIFrame* aFrame) {
97 0 : return CheckBooleanAttr(aFrame, nsGkAtoms::_default);
98 : }
99 :
100 : bool IsButtonTypeMenu(nsIFrame* aFrame);
101 :
102 : // checkbox:
103 : bool IsChecked(nsIFrame* aFrame) {
104 : return GetCheckedOrSelected(aFrame, false);
105 : }
106 :
107 : // radiobutton:
108 : bool IsSelected(nsIFrame* aFrame) {
109 : return GetCheckedOrSelected(aFrame, true);
110 : }
111 :
112 0 : bool IsFocused(nsIFrame* aFrame) {
113 0 : return CheckBooleanAttr(aFrame, nsGkAtoms::focused);
114 : }
115 :
116 : // scrollbar button:
117 : PRInt32 GetScrollbarButtonType(nsIFrame* aFrame);
118 :
119 : // tab:
120 0 : bool IsSelectedTab(nsIFrame* aFrame) {
121 0 : return CheckBooleanAttr(aFrame, nsGkAtoms::selected);
122 : }
123 :
124 : bool IsNextToSelectedTab(nsIFrame* aFrame, PRInt32 aOffset);
125 :
126 : bool IsBeforeSelectedTab(nsIFrame* aFrame) {
127 : return IsNextToSelectedTab(aFrame, -1);
128 : }
129 :
130 : bool IsAfterSelectedTab(nsIFrame* aFrame) {
131 : return IsNextToSelectedTab(aFrame, 1);
132 : }
133 :
134 : bool IsLeftToSelectedTab(nsIFrame* aFrame) {
135 : return IsFrameRTL(aFrame) ? IsAfterSelectedTab(aFrame) : IsBeforeSelectedTab(aFrame);
136 : }
137 :
138 : bool IsRightToSelectedTab(nsIFrame* aFrame) {
139 : return IsFrameRTL(aFrame) ? IsBeforeSelectedTab(aFrame) : IsAfterSelectedTab(aFrame);
140 : }
141 :
142 : // button / toolbarbutton:
143 0 : bool IsCheckedButton(nsIFrame* aFrame) {
144 0 : return CheckBooleanAttr(aFrame, nsGkAtoms::checked);
145 : }
146 :
147 : bool IsSelectedButton(nsIFrame* aFrame) {
148 : return CheckBooleanAttr(aFrame, nsGkAtoms::checked) ||
149 : CheckBooleanAttr(aFrame, nsGkAtoms::selected);
150 : }
151 :
152 0 : bool IsOpenButton(nsIFrame* aFrame) {
153 0 : return CheckBooleanAttr(aFrame, nsGkAtoms::open);
154 : }
155 :
156 : bool IsPressedButton(nsIFrame* aFrame);
157 :
158 : // treeheadercell:
159 : TreeSortDirection GetTreeSortDirection(nsIFrame* aFrame);
160 : bool IsLastTreeHeaderCell(nsIFrame* aFrame);
161 :
162 : // tab:
163 : bool IsBottomTab(nsIFrame* aFrame);
164 : bool IsFirstTab(nsIFrame* aFrame);
165 :
166 : bool IsHorizontal(nsIFrame* aFrame);
167 :
168 : // progressbar:
169 : bool IsIndeterminateProgress(nsIFrame* aFrame, nsEventStates aEventStates);
170 : bool IsVerticalProgress(nsIFrame* aFrame);
171 :
172 : // textfield:
173 0 : bool IsReadOnly(nsIFrame* aFrame) {
174 0 : return CheckBooleanAttr(aFrame, nsGkAtoms::readonly);
175 : }
176 :
177 : // menupopup:
178 : bool IsSubmenu(nsIFrame* aFrame, bool* aLeftOfParent);
179 :
180 : // True if it's not a menubar item or menulist item
181 : bool IsRegularMenuItem(nsIFrame *aFrame);
182 :
183 : bool IsMenuListEditable(nsIFrame *aFrame);
184 :
185 : nsIPresShell *GetPresShell(nsIFrame* aFrame);
186 : PRInt32 CheckIntAttr(nsIFrame* aFrame, nsIAtom* aAtom, PRInt32 defaultValue);
187 : bool CheckBooleanAttr(nsIFrame* aFrame, nsIAtom* aAtom);
188 :
189 : bool GetCheckedOrSelected(nsIFrame* aFrame, bool aCheckSelected);
190 : bool GetIndeterminate(nsIFrame* aFrame);
191 :
192 : bool QueueAnimatedContentForRefresh(nsIContent* aContent,
193 : PRUint32 aMinimumFrameRate);
194 :
195 : nsIFrame* GetAdjacentSiblingFrameWithSameAppearance(nsIFrame* aFrame,
196 : bool aNextSibling);
197 :
198 : private:
199 : PRUint32 mAnimatedContentTimeout;
200 : nsCOMPtr<nsITimer> mAnimatedContentTimer;
201 : nsAutoTArray<nsCOMPtr<nsIContent>, 20> mAnimatedContentList;
202 : };
|