Bug 1454293 [wpt PR 10484] - null is not the correct origin for createDocument()...
[gecko.git] / widget / nsNativeTheme.h
blob93b3ac2d2c75b34248d5138a3c76f1ba8062f8ef
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
7 // code duplication.
9 #ifndef _NSNATIVETHEME_H_
10 #define _NSNATIVETHEME_H_
12 #include "nsAlgorithm.h"
13 #include "nsAtom.h"
14 #include "nsCOMPtr.h"
15 #include "nsString.h"
16 #include "nsMargin.h"
17 #include "nsGkAtoms.h"
18 #include "nsTArray.h"
19 #include "nsINamed.h"
20 #include "nsITimer.h"
21 #include "nsIContent.h"
23 class nsIFrame;
24 class nsIPresShell;
25 class nsPresContext;
27 namespace mozilla {
28 class EventStates;
29 } // namespace mozilla
31 class nsNativeTheme : public nsITimerCallback, public nsINamed
33 protected:
34 virtual ~nsNativeTheme() {}
36 NS_DECL_ISUPPORTS
37 NS_DECL_NSITIMERCALLBACK
38 NS_DECL_NSINAMED
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
52 nsNativeTheme();
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,
61 uint8_t aWidgetType);
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);
72 // button:
73 bool IsDefaultButton(nsIFrame* aFrame) {
74 return CheckBooleanAttr(aFrame, nsGkAtoms::_default);
77 bool IsButtonTypeMenu(nsIFrame* aFrame);
79 // checkbox:
80 bool IsChecked(nsIFrame* aFrame) {
81 return GetCheckedOrSelected(aFrame, false);
84 // radiobutton:
85 bool IsSelected(nsIFrame* aFrame) {
86 return GetCheckedOrSelected(aFrame, true);
89 bool IsFocused(nsIFrame* aFrame) {
90 return CheckBooleanAttr(aFrame, nsGkAtoms::focused);
93 // scrollbar button:
94 int32_t GetScrollbarButtonType(nsIFrame* aFrame);
96 // tab:
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);
135 // treeheadercell:
136 TreeSortDirection GetTreeSortDirection(nsIFrame* aFrame);
137 bool IsLastTreeHeaderCell(nsIFrame* aFrame);
139 // tab:
140 bool IsBottomTab(nsIFrame* aFrame);
141 bool IsFirstTab(nsIFrame* aFrame);
143 bool IsHorizontal(nsIFrame* aFrame);
145 // progressbar:
146 bool IsIndeterminateProgress(nsIFrame* aFrame,
147 mozilla::EventStates aEventStates);
148 bool IsVerticalProgress(nsIFrame* aFrame);
150 // meter:
151 bool IsVerticalMeter(nsIFrame* aFrame);
153 // textfield:
154 bool IsReadOnly(nsIFrame* aFrame) {
155 return CheckBooleanAttr(aFrame, nsGkAtoms::readonly);
158 // menupopup:
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,
181 bool aNextSibling);
183 bool IsRangeHorizontal(nsIFrame* aFrame);
185 // scrollbar
186 bool IsDarkBackground(nsIFrame* aFrame);
188 private:
189 uint32_t mAnimatedContentTimeout;
190 nsCOMPtr<nsITimer> mAnimatedContentTimer;
191 AutoTArray<nsCOMPtr<nsIContent>, 20> mAnimatedContentList;
194 #endif // _NSNATIVETHEME_H_