Bug 1250767 - Reorder Gecko EventState to match Servo's ElementState, and add an API to let Servo access it. r=heycam,r=bz
☠☠ backed out by 0b3ff4c722a6 ☠ ☠
authorBobby Holley <bobbyholley@gmail.com>
Tue, 23 Feb 2016 17:51:47 -0800
changeset 321798 796b681561a7ffabb200c57188e400082be7e85b
parent 321797 59ee7ae2519d2215096b83a67fe19f3f86e22748
child 321799 246e0ff966fccc52fac204aa2dea7767a8a54134
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam, bz
bugs1250767
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1250767 - Reorder Gecko EventState to match Servo's ElementState, and add an API to let Servo access it. r=heycam,r=bz
dom/events/EventStates.h
layout/style/ServoBindings.cpp
layout/style/ServoBindings.h
--- a/dom/events/EventStates.h
+++ b/dom/events/EventStates.h
@@ -167,73 +167,93 @@ private:
  * Ideally, EventStates instance with values different than 0 should only be
  * created that way.
  */
 
 // Helper to define a new EventStates macro.
 #define NS_DEFINE_EVENT_STATE_MACRO(_val)               \
   (mozilla::EventStates(mozilla::EventStates::InternalType(1) << _val))
 
+/*
+ * In order to efficiently convert Gecko EventState values into Servo
+ * ElementState values [1], we maintain the invariant that the low bits of
+ * EventState can be masked off to form an ElementState (this works so
+ * long as Servo never supports a state that Gecko doesn't).
+ *
+ * This is unfortunately rather fragile for now, but we should soon have
+ * the infrastructure to statically-assert that these match up. If you
+ * need to change these, please notify somebody involved with Stylo.
+ *
+ * [1] https://github.com/servo/servo/blob/master/components/style/element_state.rs
+ */
+
 // Mouse is down on content.
 #define NS_EVENT_STATE_ACTIVE        NS_DEFINE_EVENT_STATE_MACRO(0)
 // Content has focus.
 #define NS_EVENT_STATE_FOCUS         NS_DEFINE_EVENT_STATE_MACRO(1)
 // Mouse is hovering over content.
 #define NS_EVENT_STATE_HOVER         NS_DEFINE_EVENT_STATE_MACRO(2)
-// Drag is hovering over content.
-#define NS_EVENT_STATE_DRAGOVER      NS_DEFINE_EVENT_STATE_MACRO(3)
-// Content is URL's target (ref).
-#define NS_EVENT_STATE_URLTARGET     NS_DEFINE_EVENT_STATE_MACRO(4)
+// Content is enabled (and can be disabled).
+#define NS_EVENT_STATE_ENABLED       NS_DEFINE_EVENT_STATE_MACRO(3)
+// Content is disabled.
+#define NS_EVENT_STATE_DISABLED      NS_DEFINE_EVENT_STATE_MACRO(4)
 // Content is checked.
 #define NS_EVENT_STATE_CHECKED       NS_DEFINE_EVENT_STATE_MACRO(5)
-// Content is enabled (and can be disabled).
-#define NS_EVENT_STATE_ENABLED       NS_DEFINE_EVENT_STATE_MACRO(6)
-// Content is disabled.
-#define NS_EVENT_STATE_DISABLED      NS_DEFINE_EVENT_STATE_MACRO(7)
+// Content is in the indeterminate state.
+#define NS_EVENT_STATE_INDETERMINATE NS_DEFINE_EVENT_STATE_MACRO(6)
+
+#define NS_EVENT_STATE_HIGHEST_SERVO_BIT 6
+
+/*
+ * Bits below here do not have Servo-related ordering constraints.
+ */
+
+// Drag is hovering over content.
+#define NS_EVENT_STATE_DRAGOVER      NS_DEFINE_EVENT_STATE_MACRO(7)
+// Content is URL's target (ref).
+#define NS_EVENT_STATE_URLTARGET     NS_DEFINE_EVENT_STATE_MACRO(8)
 // Content is required.
-#define NS_EVENT_STATE_REQUIRED      NS_DEFINE_EVENT_STATE_MACRO(8)
+#define NS_EVENT_STATE_REQUIRED      NS_DEFINE_EVENT_STATE_MACRO(9)
 // Content is optional (and can be required).
-#define NS_EVENT_STATE_OPTIONAL      NS_DEFINE_EVENT_STATE_MACRO(9)
+#define NS_EVENT_STATE_OPTIONAL      NS_DEFINE_EVENT_STATE_MACRO(10)
 // Link has been visited.
-#define NS_EVENT_STATE_VISITED       NS_DEFINE_EVENT_STATE_MACRO(10)
+#define NS_EVENT_STATE_VISITED       NS_DEFINE_EVENT_STATE_MACRO(11)
 // Link hasn't been visited.
-#define NS_EVENT_STATE_UNVISITED     NS_DEFINE_EVENT_STATE_MACRO(11)
+#define NS_EVENT_STATE_UNVISITED     NS_DEFINE_EVENT_STATE_MACRO(12)
 // Content is valid (and can be invalid).
-#define NS_EVENT_STATE_VALID         NS_DEFINE_EVENT_STATE_MACRO(12)
+#define NS_EVENT_STATE_VALID         NS_DEFINE_EVENT_STATE_MACRO(13)
 // Content is invalid.
-#define NS_EVENT_STATE_INVALID       NS_DEFINE_EVENT_STATE_MACRO(13)
+#define NS_EVENT_STATE_INVALID       NS_DEFINE_EVENT_STATE_MACRO(14)
 // Content value is in-range (and can be out-of-range).
-#define NS_EVENT_STATE_INRANGE       NS_DEFINE_EVENT_STATE_MACRO(14)
+#define NS_EVENT_STATE_INRANGE       NS_DEFINE_EVENT_STATE_MACRO(15)
 // Content value is out-of-range.
-#define NS_EVENT_STATE_OUTOFRANGE    NS_DEFINE_EVENT_STATE_MACRO(15)
+#define NS_EVENT_STATE_OUTOFRANGE    NS_DEFINE_EVENT_STATE_MACRO(16)
 // These two are temporary (see bug 302188)
 // Content is read-only.
-#define NS_EVENT_STATE_MOZ_READONLY  NS_DEFINE_EVENT_STATE_MACRO(16)
+#define NS_EVENT_STATE_MOZ_READONLY  NS_DEFINE_EVENT_STATE_MACRO(17)
 // Content is editable.
-#define NS_EVENT_STATE_MOZ_READWRITE NS_DEFINE_EVENT_STATE_MACRO(17)
+#define NS_EVENT_STATE_MOZ_READWRITE NS_DEFINE_EVENT_STATE_MACRO(18)
 // Content is the default one (meaning depends of the context).
-#define NS_EVENT_STATE_DEFAULT       NS_DEFINE_EVENT_STATE_MACRO(18)
+#define NS_EVENT_STATE_DEFAULT       NS_DEFINE_EVENT_STATE_MACRO(19)
 // Content could not be rendered (image/object/etc).
-#define NS_EVENT_STATE_BROKEN        NS_DEFINE_EVENT_STATE_MACRO(19)
+#define NS_EVENT_STATE_BROKEN        NS_DEFINE_EVENT_STATE_MACRO(20)
 // Content disabled by the user (images turned off, say).
-#define NS_EVENT_STATE_USERDISABLED  NS_DEFINE_EVENT_STATE_MACRO(20)
+#define NS_EVENT_STATE_USERDISABLED  NS_DEFINE_EVENT_STATE_MACRO(21)
 // Content suppressed by the user (ad blocking, etc).
-#define NS_EVENT_STATE_SUPPRESSED    NS_DEFINE_EVENT_STATE_MACRO(21)
+#define NS_EVENT_STATE_SUPPRESSED    NS_DEFINE_EVENT_STATE_MACRO(22)
 // Content is still loading such that there is nothing to show the
 // user (eg an image which hasn't started coming in yet).
-#define NS_EVENT_STATE_LOADING       NS_DEFINE_EVENT_STATE_MACRO(22)
+#define NS_EVENT_STATE_LOADING       NS_DEFINE_EVENT_STATE_MACRO(23)
 // Content is of a type that gecko can't handle.
-#define NS_EVENT_STATE_TYPE_UNSUPPORTED NS_DEFINE_EVENT_STATE_MACRO(23)
-#define NS_EVENT_STATE_INCREMENT_SCRIPT_LEVEL NS_DEFINE_EVENT_STATE_MACRO(24)
+#define NS_EVENT_STATE_TYPE_UNSUPPORTED NS_DEFINE_EVENT_STATE_MACRO(24)
+#define NS_EVENT_STATE_INCREMENT_SCRIPT_LEVEL NS_DEFINE_EVENT_STATE_MACRO(25)
 // Handler for the content has been blocked.
-#define NS_EVENT_STATE_HANDLER_BLOCKED NS_DEFINE_EVENT_STATE_MACRO(25)
+#define NS_EVENT_STATE_HANDLER_BLOCKED NS_DEFINE_EVENT_STATE_MACRO(26)
 // Handler for the content has been disabled.
-#define NS_EVENT_STATE_HANDLER_DISABLED NS_DEFINE_EVENT_STATE_MACRO(26)
-// Content is in the indeterminate state.
-#define NS_EVENT_STATE_INDETERMINATE NS_DEFINE_EVENT_STATE_MACRO(27)
+#define NS_EVENT_STATE_HANDLER_DISABLED NS_DEFINE_EVENT_STATE_MACRO(27)
 // Handler for the content has crashed
 #define NS_EVENT_STATE_HANDLER_CRASHED NS_DEFINE_EVENT_STATE_MACRO(28)
 // Content has focus and should show a ring.
 #define NS_EVENT_STATE_FOCUSRING     NS_DEFINE_EVENT_STATE_MACRO(29)
 // Content is a submit control and the form isn't valid.
 #define NS_EVENT_STATE_MOZ_SUBMITINVALID NS_DEFINE_EVENT_STATE_MACRO(30)
 // UI friendly version of :invalid pseudo-class.
 #define NS_EVENT_STATE_MOZ_UI_INVALID NS_DEFINE_EVENT_STATE_MACRO(31)
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -89,16 +89,23 @@ Gecko_GetNextSiblingElement(RawGeckoElem
 }
 
 RawGeckoElement*
 Gecko_GetDocumentElement(RawGeckoDocument* aDoc)
 {
   return aDoc->GetDocumentElement();
 }
 
+uint8_t
+Gecko_ElementState(RawGeckoElement* aElement)
+{
+  return aElement->StyleState().GetInternalValue() &
+         ((1 << (NS_EVENT_STATE_HIGHEST_SERVO_BIT + 1)) - 1);
+}
+
 int
 Gecko_IsHTMLElementInHTMLDocument(RawGeckoElement* aElement)
 {
   return aElement->IsHTMLElement() && aElement->OwnerDoc()->IsHTMLDocument();
 }
 
 int
 Gecko_IsLink(RawGeckoElement* aElement)
--- a/layout/style/ServoBindings.h
+++ b/layout/style/ServoBindings.h
@@ -52,16 +52,17 @@ RawGeckoNode* Gecko_GetNextSibling(RawGe
 RawGeckoElement* Gecko_GetParentElement(RawGeckoElement* element);
 RawGeckoElement* Gecko_GetFirstChildElement(RawGeckoElement* element);
 RawGeckoElement* Gecko_GetLastChildElement(RawGeckoElement* element);
 RawGeckoElement* Gecko_GetPrevSiblingElement(RawGeckoElement* element);
 RawGeckoElement* Gecko_GetNextSiblingElement(RawGeckoElement* element);
 RawGeckoElement* Gecko_GetDocumentElement(RawGeckoDocument* document);
 
 // Selector Matching.
+uint8_t Gecko_ElementState(RawGeckoElement* element);
 int Gecko_IsHTMLElementInHTMLDocument(RawGeckoElement* element);
 int Gecko_IsLink(RawGeckoElement* element);
 int Gecko_IsTextNode(RawGeckoNode* node);
 int Gecko_IsVisitedLink(RawGeckoElement* element);
 int Gecko_IsUnvisitedLink(RawGeckoElement* element);
 int Gecko_IsRootElement(RawGeckoElement* element);
 
 // Node data.