Bug 1341230 - Part 2: Add C++ API to add/remove manually managed EventStates bits. r=smaug
MozReview-Commit-ID: 11886pRRXSq
--- a/dom/base/Element.h
+++ b/dom/base/Element.h
@@ -529,16 +529,30 @@ protected:
virtual void RemoveStates(EventStates aStates)
{
NS_PRECONDITION(!aStates.HasAtLeastOneOfStates(INTRINSIC_STATES),
"Should only be removing externally-managed states here");
RemoveStatesSilently(aStates);
NotifyStateChange(aStates);
}
public:
+ // Public methods to manage state bits in MANUALLY_MANAGED_STATES.
+ void AddManuallyManagedStates(EventStates aStates)
+ {
+ MOZ_ASSERT(MANUALLY_MANAGED_STATES.HasAllStates(aStates),
+ "Should only be adding manually-managed states here");
+ AddStates(aStates);
+ }
+ void RemoveManuallyManagedStates(EventStates aStates)
+ {
+ MOZ_ASSERT(MANUALLY_MANAGED_STATES.HasAllStates(aStates),
+ "Should only be removing manually-managed states here");
+ RemoveStates(aStates);
+ }
+
virtual void UpdateEditableState(bool aNotify) override;
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
nsIContent* aBindingParent,
bool aCompileEventHandlers) override;
virtual void UnbindFromTree(bool aDeep = true,
bool aNullParent = true) override;
--- a/dom/events/EventStates.h
+++ b/dom/events/EventStates.h
@@ -309,21 +309,33 @@ private:
#define NS_EVENT_STATE_IGNORE NS_DEFINE_EVENT_STATE_MACRO(63)
/**
* NOTE: do not go over 63 without updating EventStates::InternalType!
*/
#define DIRECTION_STATES (NS_EVENT_STATE_LTR | NS_EVENT_STATE_RTL)
+// Event states that can be added and removed through
+// Element::{Add,Remove}ManuallyManagedStates.
+//
+// Take care when manually managing state bits. You are responsible for
+// setting or clearing the bit when an Element is added or removed from a
+// document (e.g. in BindToTree and UnbindFromTree), if that is an
+// appropriate thing to do for your state bit.
+#define MANUALLY_MANAGED_STATES ( \
+ mozilla::EventStates() /* none so far */ \
+)
+
// Event states that are managed externally to an element (by the
// EventStateManager, or by other code). As opposed to those in
// INTRINSIC_STATES, which are are computed by the element itself
// and returned from Element::IntrinsicState.
#define EXTERNALLY_MANAGED_STATES ( \
+ MANUALLY_MANAGED_STATES | \
NS_EVENT_STATE_ACTIVE | \
NS_EVENT_STATE_DRAGOVER | \
NS_EVENT_STATE_FOCUS | \
NS_EVENT_STATE_FOCUSRING | \
NS_EVENT_STATE_FOCUS_WITHIN | \
NS_EVENT_STATE_FULL_SCREEN | \
NS_EVENT_STATE_HOVER | \
NS_EVENT_STATE_UNRESOLVED | \