Bug 1380133 - Part 1: Minor reformatting and encapsulation. r=emilio
☠☠ backed out by 79ce273e2150 ☠ ☠
authorCameron McCormack <cam@mcc.id.au>
Wed, 19 Jul 2017 13:14:53 +0800
changeset 418557 454d7232178da36dea2e8b9124864a9c369e2715
parent 418556 b10e6ba9cbdb409833226ac088eba7a719399ce5
child 418558 6f89b4ceda124e9d10690ceb1a88b7318f2277cb
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1380133
milestone56.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 1380133 - Part 1: Minor reformatting and encapsulation. r=emilio MozReview-Commit-ID: 3hmptLbxxok
layout/style/ServoBindings.cpp
layout/style/ServoStyleContext.cpp
layout/style/ServoStyleContext.h
layout/style/ServoTypes.h
layout/style/nsAnimationManager.h
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -204,31 +204,37 @@ Gecko_GetAnonymousContentForElement(RawG
 void
 Gecko_DestroyAnonymousContentList(nsTArray<nsIContent*>* aAnonContent)
 {
   MOZ_ASSERT(aAnonContent);
   delete aAnonContent;
 }
 
 void
-Gecko_ServoStyleContext_Init(ServoStyleContext* aContext,
-                             const ServoStyleContext* aParentContext,
-                             RawGeckoPresContextBorrowed aPresContext, const ServoComputedValues* aValues,
-                             mozilla::CSSPseudoElementType aPseudoType, nsIAtom* aPseudoTag)
+Gecko_ServoStyleContext_Init(
+    ServoStyleContext* aContext,
+    const ServoStyleContext* aParentContext,
+    RawGeckoPresContextBorrowed aPresContext,
+    const ServoComputedValues* aValues,
+    mozilla::CSSPseudoElementType aPseudoType,
+    nsIAtom* aPseudoTag)
 {
   // because it is within an Arc it is unsafe for the Rust side to ever
   // carry around a mutable non opaque reference to the context, so we
   // cast it here.
-  ServoStyleContext* parent = const_cast<ServoStyleContext*>(aParentContext);
-  nsPresContext* pres = const_cast<nsPresContext*>(aPresContext);
-  new (KnownNotNull, aContext) ServoStyleContext(parent, pres, aPseudoTag,
-                                                 aPseudoType, ServoComputedValuesForgotten(aValues));
+  auto parent = const_cast<ServoStyleContext*>(aParentContext);
+  auto presContext = const_cast<nsPresContext*>(aPresContext);
+  new (KnownNotNull, aContext) ServoStyleContext(
+      parent, presContext, aPseudoTag, aPseudoType,
+      ServoComputedValuesForgotten(aValues));
 }
 
-ServoComputedValues::ServoComputedValues(const ServoComputedValuesForgotten aValue) {
+ServoComputedValues::ServoComputedValues(
+    const ServoComputedValuesForgotten aValue)
+{
   PodAssign(this, aValue.mPtr);
 }
 
 const nsStyleVariables* ServoComputedValues::GetStyleVariables() const
 {
   return Servo_GetEmptyVariables();
 }
 
--- a/layout/style/ServoStyleContext.cpp
+++ b/layout/style/ServoStyleContext.cpp
@@ -8,25 +8,26 @@
 #include "nsStyleConsts.h"
 #include "nsStyleStruct.h"
 #include "nsPresContext.h"
 #include "nsCSSRuleProcessor.h"
 #include "mozilla/dom/HTMLBodyElement.h"
 
 #include "mozilla/ServoBindings.h"
 
-using namespace mozilla;
+namespace mozilla {
 
-ServoStyleContext::ServoStyleContext(nsStyleContext* aParent,
-                               nsPresContext* aPresContext,
-                               nsIAtom* aPseudoTag,
-                               CSSPseudoElementType aPseudoType,
-                              ServoComputedValuesForgotten aComputedValues)
-  : nsStyleContext(aParent, aPseudoTag, aPseudoType),
-    mSource(aComputedValues)
+ServoStyleContext::ServoStyleContext(
+    nsStyleContext* aParent,
+    nsPresContext* aPresContext,
+    nsIAtom* aPseudoTag,
+    CSSPseudoElementType aPseudoType,
+    ServoComputedValuesForgotten aComputedValues)
+  : nsStyleContext(aParent, aPseudoTag, aPseudoType)
+  , mSource(aComputedValues)
 {
   mPresContext = aPresContext;
   AddStyleBit(Servo_ComputedValues_GetStyleBits(&mSource));
 
   FinishConstruction();
 
   // No need to call ApplyStyleFixups here, since fixups are handled by Servo when
   // producing the ServoComputedValues.
@@ -63,9 +64,11 @@ ServoStyleContext::UpdateWithElementStat
       GetPseudoType() == CSSPseudoElementType::NotPseudo &&
       mPresContext->CompatibilityMode() == eCompatibility_NavQuirks) {
     nsIDocument* doc = aElementForAnimation->GetUncomposedDoc();
     if (doc && doc->GetBodyElement() == aElementForAnimation) {
       // Update the prescontext's body color
       mPresContext->SetBodyTextColor(StyleColor()->mColor);
     }
   }
-}
\ No newline at end of file
+}
+
+} // namespace mozilla
--- a/layout/style/ServoStyleContext.h
+++ b/layout/style/ServoStyleContext.h
@@ -7,55 +7,50 @@
 #ifndef mozilla_ServoStyleContext_h
 #define mozilla_ServoStyleContext_h
 
 #include "nsStyleContext.h"
 
 namespace mozilla {
 
 namespace dom {
-  class Element;
-}
+class Element;
+} // namespace dom
 
-class ServoStyleContext final : public nsStyleContext {
+class ServoStyleContext final : public nsStyleContext
+{
 public:
   ServoStyleContext(nsStyleContext* aParent,
                     nsPresContext* aPresContext,
                     nsIAtom* aPseudoTag,
                     CSSPseudoElementType aPseudoType,
                     ServoComputedValuesForgotten aComputedValues);
 
-  nsPresContext* PresContext() const {
-    return mPresContext;
-  }
-
-  const ServoComputedValues* ComputedValues() const {
-    return &mSource;
-  }
+  nsPresContext* PresContext() const { return mPresContext; }
+  const ServoComputedValues* ComputedValues() const { return &mSource; }
 
-  void AddRef() {
-    Servo_StyleContext_AddRef(this);
-  }
+  void AddRef() { Servo_StyleContext_AddRef(this); }
+  void Release() { Servo_StyleContext_Release(this); }
 
-  void Release() {
-    Servo_StyleContext_Release(this);
+  ServoStyleContext* GetStyleIfVisited() const
+  {
+    return ComputedValues()->visited_style.mPtr;
   }
 
-  ServoStyleContext* GetStyleIfVisited() const { return ComputedValues()->visited_style.mPtr; }
-
   // Update visited state for a given element, and set the prescontext's
   // body text color if applicable.
   void UpdateWithElementState(dom::Element* aElement);
 
   /**
    * Makes this context match |aOther| in terms of which style structs have
    * been resolved.
    */
-  inline void ResolveSameStructsAs(nsPresContext* aPresContext, const ServoStyleContext* aOther);
+  inline void ResolveSameStructsAs(nsPresContext* aPresContext,
+                                   const ServoStyleContext* aOther);
 
 private:
   nsPresContext* mPresContext;
   ServoComputedValues mSource;
 };
 
-}
+} // namespace mozilla
 
 #endif // mozilla_ServoStyleContext_h
--- a/layout/style/ServoTypes.h
+++ b/layout/style/ServoTypes.h
@@ -175,40 +175,49 @@ struct ServoComputedValueFlags {
 #define STYLE_STRUCT(name_, checkdata_cb_) struct Gecko##name_;
 #define STYLE_STRUCT_LIST_IGNORE_VARIABLES
 #include "nsStyleStructList.h"
 #undef STYLE_STRUCT
 #undef STYLE_STRUCT_LIST_IGNORE_VARIABLES
 
 } // namespace mozilla
 
+class ServoComputedValues;
 
-struct ServoComputedValues;
-struct ServoComputedValuesForgotten {
+struct ServoComputedValuesForgotten
+{
   // Make sure you manually mem::forget the backing ServoComputedValues
   // after calling this
   explicit ServoComputedValuesForgotten(const ServoComputedValues* aValue) : mPtr(aValue) {}
   const ServoComputedValues* mPtr;
 };
 
 /**
- * We want C++ to be abe to read the style struct fields of ComputedValues
+ * We want C++ to be able to read the style struct fields of ComputedValues
  * so we define this type on the C++ side and use the bindgenned version
  * on the Rust side.
- *
  */
-struct ServoComputedValues {
+class ServoComputedValues
+{
+  friend class mozilla::ServoStyleContext;
+
+public:
+  // Constructs via memcpy.  Will not move out of aValue.
+  explicit ServoComputedValues(const ServoComputedValuesForgotten aValue);
+
 #define STYLE_STRUCT(name_, checkdata_cb_)                 \
   mozilla::ServoRawOffsetArc<mozilla::Gecko##name_> name_; \
   inline const nsStyle##name_* GetStyle##name_() const;
   #define STYLE_STRUCT_LIST_IGNORE_VARIABLES
 #include "nsStyleStructList.h"
 #undef STYLE_STRUCT
 #undef STYLE_STRUCT_LIST_IGNORE_VARIABLES
   const nsStyleVariables* GetStyleVariables() const;
+
+private:
   mozilla::ServoCustomPropertiesMap custom_properties;
   mozilla::ServoWritingMode writing_mode;
   mozilla::ServoFontComputationData font_computation_data;
   /// The rule node representing the ordered list of rules matched for this
   /// node.  Can be None for default values and text nodes.  This is
   /// essentially an optimization to avoid referencing the root rule node.
   mozilla::ServoRuleNode rules;
   /// The element's computed values if visited, only computed if there's a
@@ -223,16 +232,11 @@ struct ServoComputedValues {
   //
   // We remove the move ctor/assignment operator as well, because
   // moves in C++ don't prevent destructors from being called,
   // which will lead to double frees.
   ServoComputedValues& operator=(const ServoComputedValues&) = delete;
   ServoComputedValues(const ServoComputedValues&) = delete;
   ServoComputedValues&& operator=(const ServoComputedValues&&) = delete;
   ServoComputedValues(const ServoComputedValues&&) = delete;
-
-  // Constructs via memcpy. Will not invalidate old struct
-  explicit ServoComputedValues(const ServoComputedValuesForgotten aValue);
 };
 
-
-
 #endif // mozilla_ServoTypes_h
--- a/layout/style/nsAnimationManager.h
+++ b/layout/style/nsAnimationManager.h
@@ -12,34 +12,33 @@
 #include "mozilla/dom/Animation.h"
 #include "mozilla/Keyframe.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/TimeStamp.h"
 #include "nsRFPService.h"
 
 class nsIGlobalObject;
 class nsStyleContext;
+class ServoComputedValues;
 struct nsStyleDisplay;
-struct ServoComputedValues;
 
 namespace mozilla {
 namespace css {
 class Declaration;
 } /* namespace css */
 namespace dom {
 class KeyframeEffectReadOnly;
 class Promise;
 } /* namespace dom */
 
+class GeckoStyleContext;
+class ServoStyleContext;
 enum class CSSPseudoElementType : uint8_t;
 struct NonOwningAnimationTarget;
 
-class GeckoStyleContext;
-class ServoStyleContext;
-
 struct AnimationEventInfo {
   RefPtr<dom::Element> mElement;
   RefPtr<dom::Animation> mAnimation;
   InternalAnimationEvent mEvent;
   TimeStamp mTimeStamp;
 
   AnimationEventInfo(dom::Element* aElement,
                      CSSPseudoElementType aPseudoType,