Bug 1408310 - Part 4: Store mIsServo into DOMMatrixReadOnly. draft
authorBoris Chiou <boris.chiou@gmail.com>
Tue, 14 Nov 2017 16:47:07 +0800
changeset 703607 50ef50b6abd05a753e5d6432e89341d8d56c0d9d
parent 703606 06c7a1137de1756b79716bf008d46741d3b5dc74
child 703608 97723086e40fcf30131506ba8847180eacec730d
push id90886
push userbmo:boris.chiou@gmail.com
push dateMon, 27 Nov 2017 07:09:53 +0000
bugs1408310
milestone59.0a1
Bug 1408310 - Part 4: 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
@@ -3817,49 +3817,49 @@ 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);
+  DOMMatrixReadOnly* matrix = new DOMMatrix(this, transform, IsStyledByServo());
   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);
+  DOMMatrixReadOnly* matrix = new DOMMatrix(this, transform, IsStyledByServo());
   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);
+  DOMMatrixReadOnly* matrix = new DOMMatrix(this, transform, IsStyledByServo());
   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);