|
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/. */ |
|
5 |
|
6 // This defines a common base class for nsITheme implementations, to reduce |
|
7 // code duplication. |
|
8 |
|
9 #include "nsAlgorithm.h" |
|
10 #include "nsIAtom.h" |
|
11 #include "nsCOMPtr.h" |
|
12 #include "nsString.h" |
|
13 #include "nsMargin.h" |
|
14 #include "nsGkAtoms.h" |
|
15 #include "nsTArray.h" |
|
16 #include "nsITimer.h" |
|
17 #include "nsIContent.h" |
|
18 |
|
19 class nsIFrame; |
|
20 class nsIPresShell; |
|
21 class nsPresContext; |
|
22 |
|
23 namespace mozilla { |
|
24 class EventStates; |
|
25 } // namespace mozilla |
|
26 |
|
27 class nsNativeTheme : public nsITimerCallback |
|
28 { |
|
29 protected: |
|
30 |
|
31 NS_DECL_ISUPPORTS |
|
32 NS_DECL_NSITIMERCALLBACK |
|
33 |
|
34 enum ScrollbarButtonType { |
|
35 eScrollbarButton_UpTop = 0, |
|
36 eScrollbarButton_Down = 1 << 0, |
|
37 eScrollbarButton_Bottom = 1 << 1 |
|
38 }; |
|
39 |
|
40 enum TreeSortDirection { |
|
41 eTreeSortDirection_Descending, |
|
42 eTreeSortDirection_Natural, |
|
43 eTreeSortDirection_Ascending |
|
44 }; |
|
45 |
|
46 nsNativeTheme(); |
|
47 virtual ~nsNativeTheme() {} |
|
48 |
|
49 // Returns the content state (hover, focus, etc), see EventStateManager.h |
|
50 mozilla::EventStates GetContentState(nsIFrame* aFrame, uint8_t aWidgetType); |
|
51 |
|
52 // Returns whether the widget is already styled by content |
|
53 // Normally called from ThemeSupportsWidget to turn off native theming |
|
54 // for elements that are already styled. |
|
55 bool IsWidgetStyled(nsPresContext* aPresContext, nsIFrame* aFrame, |
|
56 uint8_t aWidgetType); |
|
57 |
|
58 // Accessors to widget-specific state information |
|
59 |
|
60 bool IsDisabled(nsIFrame* aFrame, mozilla::EventStates aEventStates); |
|
61 |
|
62 // RTL chrome direction |
|
63 bool IsFrameRTL(nsIFrame* aFrame); |
|
64 |
|
65 bool IsHTMLContent(nsIFrame *aFrame); |
|
66 |
|
67 // button: |
|
68 bool IsDefaultButton(nsIFrame* aFrame) { |
|
69 return CheckBooleanAttr(aFrame, nsGkAtoms::_default); |
|
70 } |
|
71 |
|
72 bool IsButtonTypeMenu(nsIFrame* aFrame); |
|
73 |
|
74 // checkbox: |
|
75 bool IsChecked(nsIFrame* aFrame) { |
|
76 return GetCheckedOrSelected(aFrame, false); |
|
77 } |
|
78 |
|
79 // radiobutton: |
|
80 bool IsSelected(nsIFrame* aFrame) { |
|
81 return GetCheckedOrSelected(aFrame, true); |
|
82 } |
|
83 |
|
84 bool IsFocused(nsIFrame* aFrame) { |
|
85 return CheckBooleanAttr(aFrame, nsGkAtoms::focused); |
|
86 } |
|
87 |
|
88 // scrollbar button: |
|
89 int32_t GetScrollbarButtonType(nsIFrame* aFrame); |
|
90 |
|
91 // tab: |
|
92 bool IsSelectedTab(nsIFrame* aFrame) { |
|
93 return CheckBooleanAttr(aFrame, nsGkAtoms::selected); |
|
94 } |
|
95 |
|
96 bool IsNextToSelectedTab(nsIFrame* aFrame, int32_t aOffset); |
|
97 |
|
98 bool IsBeforeSelectedTab(nsIFrame* aFrame) { |
|
99 return IsNextToSelectedTab(aFrame, -1); |
|
100 } |
|
101 |
|
102 bool IsAfterSelectedTab(nsIFrame* aFrame) { |
|
103 return IsNextToSelectedTab(aFrame, 1); |
|
104 } |
|
105 |
|
106 bool IsLeftToSelectedTab(nsIFrame* aFrame) { |
|
107 return IsFrameRTL(aFrame) ? IsAfterSelectedTab(aFrame) : IsBeforeSelectedTab(aFrame); |
|
108 } |
|
109 |
|
110 bool IsRightToSelectedTab(nsIFrame* aFrame) { |
|
111 return IsFrameRTL(aFrame) ? IsBeforeSelectedTab(aFrame) : IsAfterSelectedTab(aFrame); |
|
112 } |
|
113 |
|
114 // button / toolbarbutton: |
|
115 bool IsCheckedButton(nsIFrame* aFrame) { |
|
116 return CheckBooleanAttr(aFrame, nsGkAtoms::checked); |
|
117 } |
|
118 |
|
119 bool IsSelectedButton(nsIFrame* aFrame) { |
|
120 return CheckBooleanAttr(aFrame, nsGkAtoms::checked) || |
|
121 CheckBooleanAttr(aFrame, nsGkAtoms::selected); |
|
122 } |
|
123 |
|
124 bool IsOpenButton(nsIFrame* aFrame) { |
|
125 return CheckBooleanAttr(aFrame, nsGkAtoms::open); |
|
126 } |
|
127 |
|
128 bool IsPressedButton(nsIFrame* aFrame); |
|
129 |
|
130 // treeheadercell: |
|
131 TreeSortDirection GetTreeSortDirection(nsIFrame* aFrame); |
|
132 bool IsLastTreeHeaderCell(nsIFrame* aFrame); |
|
133 |
|
134 // tab: |
|
135 bool IsBottomTab(nsIFrame* aFrame); |
|
136 bool IsFirstTab(nsIFrame* aFrame); |
|
137 |
|
138 bool IsHorizontal(nsIFrame* aFrame); |
|
139 |
|
140 // progressbar: |
|
141 bool IsIndeterminateProgress(nsIFrame* aFrame, |
|
142 mozilla::EventStates aEventStates); |
|
143 bool IsVerticalProgress(nsIFrame* aFrame); |
|
144 |
|
145 // meter: |
|
146 bool IsVerticalMeter(nsIFrame* aFrame); |
|
147 |
|
148 // textfield: |
|
149 bool IsReadOnly(nsIFrame* aFrame) { |
|
150 return CheckBooleanAttr(aFrame, nsGkAtoms::readonly); |
|
151 } |
|
152 |
|
153 // menupopup: |
|
154 bool IsSubmenu(nsIFrame* aFrame, bool* aLeftOfParent); |
|
155 |
|
156 // True if it's not a menubar item or menulist item |
|
157 bool IsRegularMenuItem(nsIFrame *aFrame); |
|
158 |
|
159 bool IsMenuListEditable(nsIFrame *aFrame); |
|
160 |
|
161 nsIPresShell *GetPresShell(nsIFrame* aFrame); |
|
162 static bool CheckBooleanAttr(nsIFrame* aFrame, nsIAtom* aAtom); |
|
163 static int32_t CheckIntAttr(nsIFrame* aFrame, nsIAtom* aAtom, int32_t defaultValue); |
|
164 |
|
165 // Helpers for progressbar. |
|
166 static double GetProgressValue(nsIFrame* aFrame); |
|
167 static double GetProgressMaxValue(nsIFrame* aFrame); |
|
168 |
|
169 bool GetCheckedOrSelected(nsIFrame* aFrame, bool aCheckSelected); |
|
170 bool GetIndeterminate(nsIFrame* aFrame); |
|
171 |
|
172 bool QueueAnimatedContentForRefresh(nsIContent* aContent, |
|
173 uint32_t aMinimumFrameRate); |
|
174 |
|
175 nsIFrame* GetAdjacentSiblingFrameWithSameAppearance(nsIFrame* aFrame, |
|
176 bool aNextSibling); |
|
177 |
|
178 bool IsRangeHorizontal(nsIFrame* aFrame); |
|
179 |
|
180 // scrollbar |
|
181 bool IsDarkBackground(nsIFrame* aFrame); |
|
182 |
|
183 private: |
|
184 uint32_t mAnimatedContentTimeout; |
|
185 nsCOMPtr<nsITimer> mAnimatedContentTimer; |
|
186 nsAutoTArray<nsCOMPtr<nsIContent>, 20> mAnimatedContentList; |
|
187 }; |