widget/xpwidgets/nsNativeTheme.h

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

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

mercurial