Bug 1341230 - Part 2: Add C++ API to add/remove manually managed EventStates bits. r=smaug draft
authorCameron McCormack <cam@mcc.id.au>
Mon, 06 Mar 2017 10:44:13 +0800
changeset 493793 6881181ab9e8bfd9559a4f92d77a8b2796daa9dc
parent 493792 6d5f7ecff2d41d66cbc23ea12e08dc6295e29875
child 493794 6a9aae7f63992a74620126bf626963b3dcc00e41
child 493833 f532dde551e347deae7b9f5a4d678658c5dc0c70
push id47842
push userbmo:cam@mcc.id.au
push dateMon, 06 Mar 2017 02:44:49 +0000
reviewerssmaug
bugs1341230
milestone54.0a1
Bug 1341230 - Part 2: Add C++ API to add/remove manually managed EventStates bits. r=smaug MozReview-Commit-ID: 11886pRRXSq
dom/base/Element.h
dom/events/EventStates.h
--- 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 |                 \