Bug 1025824 - Fix mHwcLayerMap handling r=sushil
[gecko.git] / dom / events / EventStates.h
blob6890d31d13b3fcde89eff399ffdc897599223a07
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 #ifndef mozilla_EventStates_h_
7 #define mozilla_EventStates_h_
9 #include "mozilla/Attributes.h"
10 #include "nsDebug.h"
12 namespace mozilla {
14 /**
15 * EventStates is the class used to represent the event states of nsIContent
16 * instances. These states are calculated by IntrinsicState() and
17 * ContentStatesChanged() has to be called when one of them changes thus
18 * informing the layout/style engine of the change.
19 * Event states are associated with pseudo-classes.
21 class EventStates
23 public:
24 typedef uint64_t InternalType;
26 MOZ_CONSTEXPR EventStates()
27 : mStates(0)
31 // NOTE: the ideal scenario would be to have the default constructor public
32 // setting mStates to 0 and this constructor (without = 0) private.
33 // In that case, we could be sure that only macros at the end were creating
34 // EventStates instances with mStates set to something else than 0.
35 // Unfortunately, this constructor is needed at at least two places now.
36 explicit MOZ_CONSTEXPR EventStates(InternalType aStates)
37 : mStates(aStates)
41 EventStates MOZ_CONSTEXPR operator|(const EventStates& aEventStates) const
43 return EventStates(mStates | aEventStates.mStates);
46 EventStates& operator|=(const EventStates& aEventStates)
48 mStates |= aEventStates.mStates;
49 return *this;
52 // NOTE: calling if (eventStates1 & eventStates2) will not build.
53 // This might work correctly if operator bool() is defined
54 // but using HasState, HasAllStates or HasAtLeastOneOfStates is recommended.
55 EventStates MOZ_CONSTEXPR operator&(const EventStates& aEventStates) const
57 return EventStates(mStates & aEventStates.mStates);
60 EventStates& operator&=(const EventStates& aEventStates)
62 mStates &= aEventStates.mStates;
63 return *this;
66 bool operator==(const EventStates& aEventStates) const
68 return mStates == aEventStates.mStates;
71 bool operator!=(const EventStates& aEventStates) const
73 return mStates != aEventStates.mStates;
76 EventStates operator~() const
78 return EventStates(~mStates);
81 EventStates operator^(const EventStates& aEventStates) const
83 return EventStates(mStates ^ aEventStates.mStates);
86 EventStates& operator^=(const EventStates& aEventStates)
88 mStates ^= aEventStates.mStates;
89 return *this;
92 /**
93 * Returns true if the EventStates instance is empty.
94 * A EventStates instance is empty if it contains no state.
96 * @return Whether if the object is empty.
98 bool IsEmpty() const
100 return mStates == 0;
104 * Returns true if the EventStates instance contains the state
105 * contained in aEventStates.
106 * @note aEventStates should contain only one state.
108 * @param aEventStates The state to check.
110 * @return Whether the object has the state from aEventStates
112 bool HasState(EventStates aEventStates) const
114 #ifdef DEBUG
115 // If aEventStates.mStates is a power of two, it contains only one state
116 // (or none, but we don't really care).
117 if ((aEventStates.mStates & (aEventStates.mStates - 1))) {
118 NS_ERROR("When calling HasState, "
119 "EventStates object has to contain only one state!");
121 #endif // DEBUG
122 return mStates & aEventStates.mStates;
126 * Returns true if the EventStates instance contains one of the states
127 * contained in aEventStates.
129 * @param aEventStates The states to check.
131 * @return Whether the object has at least one state from aEventStates
133 bool HasAtLeastOneOfStates(EventStates aEventStates) const
135 return mStates & aEventStates.mStates;
139 * Returns true if the EventStates instance contains all states
140 * contained in aEventStates.
142 * @param aEventStates The states to check.
144 * @return Whether the object has all states from aEventStates
146 bool HasAllStates(EventStates aEventStates) const
148 return (mStates & aEventStates.mStates) == aEventStates.mStates;
151 // We only need that method for inDOMUtils::GetContentState.
152 // If inDOMUtils::GetContentState is removed, this method should be removed.
153 InternalType GetInternalValue() const {
154 return mStates;
157 private:
158 InternalType mStates;
161 } // namespace mozilla
164 * The following macros are creating EventStates instance with different
165 * values depending of their meaning.
166 * Ideally, EventStates instance with values different than 0 should only be
167 * created that way.
170 // Helper to define a new EventStates macro.
171 #define NS_DEFINE_EVENT_STATE_MACRO(_val) \
172 (mozilla::EventStates(mozilla::EventStates::InternalType(1) << _val))
174 // Mouse is down on content.
175 #define NS_EVENT_STATE_ACTIVE NS_DEFINE_EVENT_STATE_MACRO(0)
176 // Content has focus.
177 #define NS_EVENT_STATE_FOCUS NS_DEFINE_EVENT_STATE_MACRO(1)
178 // Mouse is hovering over content.
179 #define NS_EVENT_STATE_HOVER NS_DEFINE_EVENT_STATE_MACRO(2)
180 // Drag is hovering over content.
181 #define NS_EVENT_STATE_DRAGOVER NS_DEFINE_EVENT_STATE_MACRO(3)
182 // Content is URL's target (ref).
183 #define NS_EVENT_STATE_URLTARGET NS_DEFINE_EVENT_STATE_MACRO(4)
184 // Content is checked.
185 #define NS_EVENT_STATE_CHECKED NS_DEFINE_EVENT_STATE_MACRO(5)
186 // Content is enabled (and can be disabled).
187 #define NS_EVENT_STATE_ENABLED NS_DEFINE_EVENT_STATE_MACRO(6)
188 // Content is disabled.
189 #define NS_EVENT_STATE_DISABLED NS_DEFINE_EVENT_STATE_MACRO(7)
190 // Content is required.
191 #define NS_EVENT_STATE_REQUIRED NS_DEFINE_EVENT_STATE_MACRO(8)
192 // Content is optional (and can be required).
193 #define NS_EVENT_STATE_OPTIONAL NS_DEFINE_EVENT_STATE_MACRO(9)
194 // Link has been visited.
195 #define NS_EVENT_STATE_VISITED NS_DEFINE_EVENT_STATE_MACRO(10)
196 // Link hasn't been visited.
197 #define NS_EVENT_STATE_UNVISITED NS_DEFINE_EVENT_STATE_MACRO(11)
198 // Content is valid (and can be invalid).
199 #define NS_EVENT_STATE_VALID NS_DEFINE_EVENT_STATE_MACRO(12)
200 // Content is invalid.
201 #define NS_EVENT_STATE_INVALID NS_DEFINE_EVENT_STATE_MACRO(13)
202 // Content value is in-range (and can be out-of-range).
203 #define NS_EVENT_STATE_INRANGE NS_DEFINE_EVENT_STATE_MACRO(14)
204 // Content value is out-of-range.
205 #define NS_EVENT_STATE_OUTOFRANGE NS_DEFINE_EVENT_STATE_MACRO(15)
206 // These two are temporary (see bug 302188)
207 // Content is read-only.
208 #define NS_EVENT_STATE_MOZ_READONLY NS_DEFINE_EVENT_STATE_MACRO(16)
209 // Content is editable.
210 #define NS_EVENT_STATE_MOZ_READWRITE NS_DEFINE_EVENT_STATE_MACRO(17)
211 // Content is the default one (meaning depends of the context).
212 #define NS_EVENT_STATE_DEFAULT NS_DEFINE_EVENT_STATE_MACRO(18)
213 // Content could not be rendered (image/object/etc).
214 #define NS_EVENT_STATE_BROKEN NS_DEFINE_EVENT_STATE_MACRO(19)
215 // Content disabled by the user (images turned off, say).
216 #define NS_EVENT_STATE_USERDISABLED NS_DEFINE_EVENT_STATE_MACRO(20)
217 // Content suppressed by the user (ad blocking, etc).
218 #define NS_EVENT_STATE_SUPPRESSED NS_DEFINE_EVENT_STATE_MACRO(21)
219 // Content is still loading such that there is nothing to show the
220 // user (eg an image which hasn't started coming in yet).
221 #define NS_EVENT_STATE_LOADING NS_DEFINE_EVENT_STATE_MACRO(22)
222 // Content is of a type that gecko can't handle.
223 #define NS_EVENT_STATE_TYPE_UNSUPPORTED NS_DEFINE_EVENT_STATE_MACRO(23)
224 #define NS_EVENT_STATE_INCREMENT_SCRIPT_LEVEL NS_DEFINE_EVENT_STATE_MACRO(24)
225 // Handler for the content has been blocked.
226 #define NS_EVENT_STATE_HANDLER_BLOCKED NS_DEFINE_EVENT_STATE_MACRO(25)
227 // Handler for the content has been disabled.
228 #define NS_EVENT_STATE_HANDLER_DISABLED NS_DEFINE_EVENT_STATE_MACRO(26)
229 // Content is in the indeterminate state.
230 #define NS_EVENT_STATE_INDETERMINATE NS_DEFINE_EVENT_STATE_MACRO(27)
231 // Handler for the content has crashed
232 #define NS_EVENT_STATE_HANDLER_CRASHED NS_DEFINE_EVENT_STATE_MACRO(28)
233 // Content has focus and should show a ring.
234 #define NS_EVENT_STATE_FOCUSRING NS_DEFINE_EVENT_STATE_MACRO(29)
235 // Content is a submit control and the form isn't valid.
236 #define NS_EVENT_STATE_MOZ_SUBMITINVALID NS_DEFINE_EVENT_STATE_MACRO(30)
237 // UI friendly version of :invalid pseudo-class.
238 #define NS_EVENT_STATE_MOZ_UI_INVALID NS_DEFINE_EVENT_STATE_MACRO(31)
239 // UI friendly version of :valid pseudo-class.
240 #define NS_EVENT_STATE_MOZ_UI_VALID NS_DEFINE_EVENT_STATE_MACRO(32)
241 // Content is the full screen element, or a frame containing the
242 // current full-screen element.
243 #define NS_EVENT_STATE_FULL_SCREEN NS_DEFINE_EVENT_STATE_MACRO(33)
244 // Content is an ancestor of the DOM full-screen element.
245 #define NS_EVENT_STATE_FULL_SCREEN_ANCESTOR NS_DEFINE_EVENT_STATE_MACRO(34)
246 // Handler for click to play plugin
247 #define NS_EVENT_STATE_TYPE_CLICK_TO_PLAY NS_DEFINE_EVENT_STATE_MACRO(35)
248 // Content is in the optimum region.
249 #define NS_EVENT_STATE_OPTIMUM NS_DEFINE_EVENT_STATE_MACRO(36)
250 // Content is in the suboptimal region.
251 #define NS_EVENT_STATE_SUB_OPTIMUM NS_DEFINE_EVENT_STATE_MACRO(37)
252 // Content is in the sub-suboptimal region.
253 #define NS_EVENT_STATE_SUB_SUB_OPTIMUM NS_DEFINE_EVENT_STATE_MACRO(38)
254 // Handler for click to play plugin (vulnerable w/update)
255 #define NS_EVENT_STATE_VULNERABLE_UPDATABLE NS_DEFINE_EVENT_STATE_MACRO(39)
256 // Handler for click to play plugin (vulnerable w/no update)
257 #define NS_EVENT_STATE_VULNERABLE_NO_UPDATE NS_DEFINE_EVENT_STATE_MACRO(40)
258 // Platform does not support plugin content (some mobile platforms)
259 #define NS_EVENT_STATE_TYPE_UNSUPPORTED_PLATFORM NS_DEFINE_EVENT_STATE_MACRO(41)
260 // Element is ltr (for :dir pseudo-class)
261 #define NS_EVENT_STATE_LTR NS_DEFINE_EVENT_STATE_MACRO(42)
262 // Element is rtl (for :dir pseudo-class)
263 #define NS_EVENT_STATE_RTL NS_DEFINE_EVENT_STATE_MACRO(43)
264 // Handler for play preview plugin
265 #define NS_EVENT_STATE_TYPE_PLAY_PREVIEW NS_DEFINE_EVENT_STATE_MACRO(44)
266 // Element is highlighted (devtools inspector)
267 #define NS_EVENT_STATE_DEVTOOLS_HIGHLIGHTED NS_DEFINE_EVENT_STATE_MACRO(45)
269 // Event state that is used for values that need to be parsed but do nothing.
270 #define NS_EVENT_STATE_IGNORE NS_DEFINE_EVENT_STATE_MACRO(63)
273 * NOTE: do not go over 63 without updating EventStates::InternalType!
276 #define DIRECTION_STATES (NS_EVENT_STATE_LTR | NS_EVENT_STATE_RTL)
278 #define ESM_MANAGED_STATES (NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_FOCUS | \
279 NS_EVENT_STATE_HOVER | NS_EVENT_STATE_DRAGOVER | \
280 NS_EVENT_STATE_URLTARGET | NS_EVENT_STATE_FOCUSRING | \
281 NS_EVENT_STATE_FULL_SCREEN | NS_EVENT_STATE_FULL_SCREEN_ANCESTOR)
283 #define INTRINSIC_STATES (~ESM_MANAGED_STATES)
285 #endif // mozilla_EventStates_h_