Bug 1408310 - Part 3: Store mIsServo into DOMMatrixReadOnly. draft
authorBoris Chiou <boris.chiou@gmail.com>
Tue, 14 Nov 2017 16:47:07 +0800
changeset 700509 c70fabe7bf4eb88a0067053d8bab58044162d905
parent 700508 39c83944bbb5777d3479d819e36c768d09873ba9
child 700510 3a4d454e1e8f34d9c1f3d899ef0c82793a102c34
push id89871
push userbmo:boris.chiou@gmail.com
push dateMon, 20 Nov 2017 09:30:43 +0000
bugs1408310
milestone59.0a1
Bug 1408310 - Part 3: Store mIsServo into DOMMatrixReadOnly. So we can know which backend we are using. MozReview-Commit-ID: Jfpt82lv0hw
dom/base/DOMMatrix.cpp
dom/base/DOMMatrix.h
dom/base/Element.cpp
dom/base/WebKitCSSMatrix.cpp
dom/base/WebKitCSSMatrix.h
--- a/dom/base/DOMMatrix.cpp
+++ b/dom/base/DOMMatrix.cpp
@@ -336,27 +336,37 @@ DOMMatrixReadOnly::Stringify(nsAString& 
     AppendFloat(matrixStr, E()); matrixStr.AppendLiteral(", ");
     AppendFloat(matrixStr, F());
     matrixStr.AppendLiteral(")");
   }
 
   aResult = matrixStr;
 }
 
+static bool
+IsStyledByServo(JSContext* aContext)
+{
+  nsGlobalWindowInner* win = xpc::CurrentWindowOrNull(aContext);
+  nsIDocument* doc = win ? win->GetDoc() : nullptr;
+  return doc ? doc->IsStyledByServo() : false;
+}
+
 already_AddRefed<DOMMatrix>
 DOMMatrix::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
 {
-  RefPtr<DOMMatrix> obj = new DOMMatrix(aGlobal.GetAsSupports());
+  RefPtr<DOMMatrix> obj = new DOMMatrix(aGlobal.GetAsSupports(),
+                                        IsStyledByServo(aGlobal.Context()));
   return obj.forget();
 }
 
 already_AddRefed<DOMMatrix>
 DOMMatrix::Constructor(const GlobalObject& aGlobal, const nsAString& aTransformList, ErrorResult& aRv)
 {
-  RefPtr<DOMMatrix> obj = new DOMMatrix(aGlobal.GetAsSupports());
+  RefPtr<DOMMatrix> obj = new DOMMatrix(aGlobal.GetAsSupports(),
+                                        IsStyledByServo(aGlobal.Context()));
 
   obj = obj->SetMatrixValue(aTransformList, aRv);
   return obj.forget();
 }
 
 already_AddRefed<DOMMatrix>
 DOMMatrix::Constructor(const GlobalObject& aGlobal, const DOMMatrixReadOnly& aOther, ErrorResult& aRv)
 {
@@ -393,37 +403,40 @@ template <typename T> void SetDataInMatr
   } else {
     aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
   }
 }
 
 already_AddRefed<DOMMatrix>
 DOMMatrix::Constructor(const GlobalObject& aGlobal, const Float32Array& aArray32, ErrorResult& aRv)
 {
-  RefPtr<DOMMatrix> obj = new DOMMatrix(aGlobal.GetAsSupports());
+  RefPtr<DOMMatrix> obj = new DOMMatrix(aGlobal.GetAsSupports(),
+                                        IsStyledByServo(aGlobal.Context()));
   aArray32.ComputeLengthAndData();
   SetDataInMatrix(obj, aArray32.Data(), aArray32.Length(), aRv);
 
   return obj.forget();
 }
 
 already_AddRefed<DOMMatrix>
 DOMMatrix::Constructor(const GlobalObject& aGlobal, const Float64Array& aArray64, ErrorResult& aRv)
 {
-  RefPtr<DOMMatrix> obj = new DOMMatrix(aGlobal.GetAsSupports());
+  RefPtr<DOMMatrix> obj = new DOMMatrix(aGlobal.GetAsSupports(),
+                                        IsStyledByServo(aGlobal.Context()));
   aArray64.ComputeLengthAndData();
   SetDataInMatrix(obj, aArray64.Data(), aArray64.Length(), aRv);
 
   return obj.forget();
 }
 
 already_AddRefed<DOMMatrix>
 DOMMatrix::Constructor(const GlobalObject& aGlobal, const Sequence<double>& aNumberSequence, ErrorResult& aRv)
 {
-  RefPtr<DOMMatrix> obj = new DOMMatrix(aGlobal.GetAsSupports());
+  RefPtr<DOMMatrix> obj = new DOMMatrix(aGlobal.GetAsSupports(),
+                                        IsStyledByServo(aGlobal.Context()));
   SetDataInMatrix(obj, aNumberSequence.Elements(), aNumberSequence.Length(), aRv);
 
   return obj.forget();
 }
 
 void DOMMatrix::Ensure3DMatrix()
 {
   if (!mMatrix3D) {
--- a/dom/base/DOMMatrix.h
+++ b/dom/base/DOMMatrix.h
@@ -23,33 +23,35 @@ namespace dom {
 class GlobalObject;
 class DOMMatrix;
 class DOMPoint;
 struct DOMPointInit;
 
 class DOMMatrixReadOnly : public nsWrapperCache
 {
 public:
-  explicit DOMMatrixReadOnly(nsISupports* aParent)
-    : mParent(aParent), mMatrix2D(new gfx::Matrix())
+  DOMMatrixReadOnly(nsISupports* aParent, bool aIsServo)
+    : mParent(aParent), mMatrix2D(new gfx::Matrix()), mIsServo(aIsServo)
   {
   }
 
   DOMMatrixReadOnly(nsISupports* aParent, const DOMMatrixReadOnly& other)
-    : mParent(aParent)
+    : mParent(aParent), mIsServo(other.mIsServo)
   {
     if (other.mMatrix2D) {
       mMatrix2D = new gfx::Matrix(*other.mMatrix2D);
     } else {
       mMatrix3D = new gfx::Matrix4x4(*other.mMatrix3D);
     }
   }
 
-  DOMMatrixReadOnly(nsISupports* aParent, const gfx::Matrix4x4& aMatrix)
-    : mParent(aParent)
+  DOMMatrixReadOnly(nsISupports* aParent,
+                    const gfx::Matrix4x4& aMatrix,
+                    bool aIsServo)
+    : mParent(aParent), mIsServo(aIsServo)
   {
     mMatrix3D = new gfx::Matrix4x4(aMatrix);
   }
 
   NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DOMMatrixReadOnly)
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(DOMMatrixReadOnly)
 
 #define GetMatrixMember(entry2D, entry3D, default) \
@@ -136,38 +138,39 @@ public:
   void                        ToFloat64Array(JSContext* aCx,
                                              JS::MutableHandle<JSObject*> aResult,
                                              ErrorResult& aRv) const;
   void                        Stringify(nsAString& aResult);
 protected:
   nsCOMPtr<nsISupports>     mParent;
   nsAutoPtr<gfx::Matrix>    mMatrix2D;
   nsAutoPtr<gfx::Matrix4x4> mMatrix3D;
+  bool mIsServo;
 
   virtual ~DOMMatrixReadOnly() {}
 
 private:
   DOMMatrixReadOnly() = delete;
   DOMMatrixReadOnly(const DOMMatrixReadOnly&) = delete;
   DOMMatrixReadOnly& operator=(const DOMMatrixReadOnly&) = delete;
 };
 
 class DOMMatrix : public DOMMatrixReadOnly
 {
 public:
-  explicit DOMMatrix(nsISupports* aParent)
-    : DOMMatrixReadOnly(aParent)
+  DOMMatrix(nsISupports* aParent, bool aIsServo)
+    : DOMMatrixReadOnly(aParent, aIsServo)
   {}
 
   DOMMatrix(nsISupports* aParent, const DOMMatrixReadOnly& other)
     : DOMMatrixReadOnly(aParent, other)
   {}
 
-  DOMMatrix(nsISupports* aParent, const gfx::Matrix4x4& aMatrix)
-    : DOMMatrixReadOnly(aParent, aMatrix)
+  DOMMatrix(nsISupports* aParent, const gfx::Matrix4x4& aMatrix, bool aIsServo)
+    : DOMMatrixReadOnly(aParent, aMatrix, aIsServo)
   {}
 
   static already_AddRefed<DOMMatrix>
   Constructor(const GlobalObject& aGlobal, ErrorResult& aRv);
   static already_AddRefed<DOMMatrix>
   Constructor(const GlobalObject& aGlobal, const nsAString& aTransformList, ErrorResult& aRv);
   static already_AddRefed<DOMMatrix>
   Constructor(const GlobalObject& aGlobal, const DOMMatrixReadOnly& aOther, ErrorResult& aRv);
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -3763,49 +3763,52 @@ Element::GetTransformToAncestor(Element&
   if (primaryFrame) {
     // If aAncestor is not actually an ancestor of this (including nullptr),
     // then the call to GetTransformToAncestor will return the transform
     // all the way up through the parent chain.
     transform = nsLayoutUtils::GetTransformToAncestor(primaryFrame,
       ancestorFrame, nsIFrame::IN_CSS_UNITS);
   }
 
-  DOMMatrixReadOnly* matrix = new DOMMatrix(this, transform);
+  bool isServo = primaryFrame->StyleContext()->IsServo();
+  DOMMatrixReadOnly* matrix = new DOMMatrix(this, transform, isServo);
   RefPtr<DOMMatrixReadOnly> result(matrix);
   return result.forget();
 }
 
 already_AddRefed<DOMMatrixReadOnly>
 Element::GetTransformToParent()
 {
   nsIFrame* primaryFrame = GetPrimaryFrame();
 
   Matrix4x4 transform;
   if (primaryFrame) {
     nsIFrame* parentFrame = primaryFrame->GetParent();
     transform = nsLayoutUtils::GetTransformToAncestor(primaryFrame,
       parentFrame, nsIFrame::IN_CSS_UNITS);
   }
 
-  DOMMatrixReadOnly* matrix = new DOMMatrix(this, transform);
+  bool isServo = primaryFrame->StyleContext()->IsServo();
+  DOMMatrixReadOnly* matrix = new DOMMatrix(this, transform, isServo);
   RefPtr<DOMMatrixReadOnly> result(matrix);
   return result.forget();
 }
 
 already_AddRefed<DOMMatrixReadOnly>
 Element::GetTransformToViewport()
 {
   nsIFrame* primaryFrame = GetPrimaryFrame();
   Matrix4x4 transform;
   if (primaryFrame) {
     transform = nsLayoutUtils::GetTransformToAncestor(primaryFrame,
       nsLayoutUtils::GetDisplayRootFrame(primaryFrame), nsIFrame::IN_CSS_UNITS);
   }
 
-  DOMMatrixReadOnly* matrix = new DOMMatrix(this, transform);
+  bool isServo = primaryFrame->StyleContext()->IsServo();
+  DOMMatrixReadOnly* matrix = new DOMMatrix(this, transform, isServo);
   RefPtr<DOMMatrixReadOnly> result(matrix);
   return result.forget();
 }
 
 already_AddRefed<Animation>
 Element::Animate(JSContext* aContext,
                  JS::Handle<JSObject*> aKeyframes,
                  const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
--- a/dom/base/WebKitCSSMatrix.cpp
+++ b/dom/base/WebKitCSSMatrix.cpp
@@ -12,35 +12,47 @@
 #include "nsPresContext.h"
 #include "RuleNodeCacheConditions.h"
 
 namespace mozilla {
 namespace dom {
 
 static const double sRadPerDegree = 2.0 * M_PI / 360.0;
 
+static bool
+IsStyledByServo(JSContext* aContext)
+{
+  nsGlobalWindowInner* win = xpc::CurrentWindowOrNull(aContext);
+  nsIDocument* doc = win ? win->GetDoc() : nullptr;
+  return doc ? doc->IsStyledByServo() : false;
+}
+
 bool
 WebKitCSSMatrix::FeatureEnabled(JSContext* aCx, JSObject* aObj)
 {
   return Preferences::GetBool("layout.css.DOMMatrix.enabled", false) &&
          Preferences::GetBool("layout.css.prefixes.webkit", false);
 }
 
 already_AddRefed<WebKitCSSMatrix>
 WebKitCSSMatrix::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
 {
-  RefPtr<WebKitCSSMatrix> obj = new WebKitCSSMatrix(aGlobal.GetAsSupports());
+  RefPtr<WebKitCSSMatrix> obj =
+    new WebKitCSSMatrix(aGlobal.GetAsSupports(),
+                        IsStyledByServo(aGlobal.Context()));
   return obj.forget();
 }
 
 already_AddRefed<WebKitCSSMatrix>
 WebKitCSSMatrix::Constructor(const GlobalObject& aGlobal,
                              const nsAString& aTransformList, ErrorResult& aRv)
 {
-  RefPtr<WebKitCSSMatrix> obj = new WebKitCSSMatrix(aGlobal.GetAsSupports());
+  RefPtr<WebKitCSSMatrix> obj =
+    new WebKitCSSMatrix(aGlobal.GetAsSupports(),
+                        IsStyledByServo(aGlobal.Context()));
   obj = obj->SetMatrixValue(aTransformList, aRv);
   return obj.forget();
 }
 
 already_AddRefed<WebKitCSSMatrix>
 WebKitCSSMatrix::Constructor(const GlobalObject& aGlobal,
                              const DOMMatrixReadOnly& aOther, ErrorResult& aRv)
 {
--- a/dom/base/WebKitCSSMatrix.h
+++ b/dom/base/WebKitCSSMatrix.h
@@ -10,18 +10,18 @@
 #include "mozilla/dom/DOMMatrix.h"
 
 namespace mozilla {
 namespace dom {
 
 class WebKitCSSMatrix final : public DOMMatrix
 {
 public:
-  explicit WebKitCSSMatrix(nsISupports* aParent)
-    : DOMMatrix(aParent)
+  WebKitCSSMatrix(nsISupports* aParent, bool aIsServo)
+    : DOMMatrix(aParent, aIsServo)
   {}
 
   WebKitCSSMatrix(nsISupports* aParent, const DOMMatrixReadOnly& other)
     : DOMMatrix(aParent, other)
   {}
 
   static bool FeatureEnabled(JSContext* aCx, JSObject* aObj);