Bug 1355675 Part 3: Add some Chrome-only getTransformTo... methods to Element.
MozReview-Commit-ID: 5H2DXKJzE8H
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -149,16 +149,18 @@
#include "mozilla/IntegerPrintfMacros.h"
#include "mozilla/Preferences.h"
#include "nsComputedDOMStyle.h"
#include "nsDOMStringMap.h"
#include "DOMIntersectionObserver.h"
#include "nsISpeculativeConnect.h"
+#include "DOMMatrix.h"
+
using namespace mozilla;
using namespace mozilla::dom;
//
// Verify sizes of elements on 64-bit platforms. This should catch most memory
// regressions, and is easy to verify locally since most developers are on
// 64-bit machines. We use a template rather than a direct static assert so
// that the error message actually displays the sizes.
@@ -3426,16 +3428,68 @@ Element::GetGridFragments(nsTArray<RefPt
while (frame) {
aResult.AppendElement(
new Grid(this, frame)
);
frame = static_cast<nsGridContainerFrame*>(frame->GetNextInFlow());
}
}
+already_AddRefed<DOMMatrixReadOnly>
+Element::GetTransformToAncestor(Element& aAncestor)
+{
+ nsIFrame* primaryFrame = GetPrimaryFrame();
+ nsIFrame* ancestorFrame = aAncestor.GetPrimaryFrame();
+
+ Matrix4x4 transform;
+ 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, true);
+ }
+
+ DOMMatrixReadOnly* matrix = new DOMMatrix(this, transform);
+ 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, true);
+ }
+
+ DOMMatrixReadOnly* matrix = new DOMMatrix(this, transform);
+ 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), true);
+ }
+
+ DOMMatrixReadOnly* matrix = new DOMMatrix(this, transform);
+ RefPtr<DOMMatrixReadOnly> result(matrix);
+ return result.forget();
+}
+
already_AddRefed<Animation>
Element::Animate(JSContext* aContext,
JS::Handle<JSObject*> aKeyframes,
const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
ErrorResult& aError)
{
Nullable<ElementOrCSSPseudoElement> target;
target.SetValue().SetAsElement() = this;
--- a/dom/base/Element.h
+++ b/dom/base/Element.h
@@ -62,16 +62,17 @@ class nsDOMStringMap;
namespace mozilla {
class DeclarationBlock;
namespace dom {
struct AnimationFilter;
struct ScrollIntoViewOptions;
struct ScrollToOptions;
class DOMIntersectionObserver;
+ class DOMMatrixReadOnly;
class ElementOrCSSPseudoElement;
class UnrestrictedDoubleOrKeyframeAnimationOptions;
enum class CallerType : uint32_t;
} // namespace dom
} // namespace mozilla
already_AddRefed<nsContentList>
@@ -1061,16 +1062,20 @@ public:
nsIScrollableFrame* sf = GetScrollFrame();
return sf ?
nsPresContext::AppUnitsToIntCSSPixels(sf->GetScrollRange().XMost()) :
0;
}
void GetGridFragments(nsTArray<RefPtr<Grid>>& aResult);
+ already_AddRefed<DOMMatrixReadOnly> GetTransformToAncestor(Element& aAncestor);
+ already_AddRefed<DOMMatrixReadOnly> GetTransformToParent();
+ already_AddRefed<DOMMatrixReadOnly> GetTransformToViewport();
+
already_AddRefed<Animation>
Animate(JSContext* aContext,
JS::Handle<JSObject*> aKeyframes,
const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
ErrorResult& aError);
// A helper method that factors out the common functionality needed by
// Element::Animate and CSSPseudoElement::Animate
--- a/dom/webidl/Element.webidl
+++ b/dom/webidl/Element.webidl
@@ -160,16 +160,23 @@ interface Element : Node {
/**
* If this element has a display:grid or display:inline-grid style,
* this property returns an object with computed values for grid
* tracks and lines.
*/
[ChromeOnly, Pure]
sequence<Grid> getGridFragments();
+
+ [ChromeOnly]
+ DOMMatrixReadOnly getTransformToAncestor(Element ancestor);
+ [ChromeOnly]
+ DOMMatrixReadOnly getTransformToParent();
+ [ChromeOnly]
+ DOMMatrixReadOnly getTransformToViewport();
};
// http://dev.w3.org/csswg/cssom-view/
enum ScrollLogicalPosition { "start", "end" };
dictionary ScrollIntoViewOptions : ScrollOptions {
ScrollLogicalPosition block = "start";
};