2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-09-13 13:42:11 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A class representing three matrices that can be used for style transforms.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef nsStyleTransformMatrix_h_
|
|
|
|
#define nsStyleTransformMatrix_h_
|
|
|
|
|
2017-07-05 18:22:00 +03:00
|
|
|
#include "gfxPoint.h"
|
2017-06-28 18:42:23 +03:00
|
|
|
#include "mozilla/gfx/Matrix.h"
|
2016-10-12 07:36:58 +03:00
|
|
|
#include "mozilla/EnumeratedArray.h"
|
2008-09-13 13:42:11 +04:00
|
|
|
#include "nsCSSValue.h"
|
2017-07-05 18:22:00 +03:00
|
|
|
#include "nsSize.h"
|
2008-09-13 13:42:11 +04:00
|
|
|
|
2017-01-20 04:45:33 +03:00
|
|
|
#include <limits>
|
|
|
|
|
2015-04-28 21:55:42 +03:00
|
|
|
class nsIFrame;
|
2011-05-25 12:01:11 +04:00
|
|
|
class nsPresContext;
|
2016-10-04 10:00:31 +03:00
|
|
|
struct gfxQuaternion;
|
2013-03-03 04:31:48 +04:00
|
|
|
struct nsRect;
|
2010-07-03 08:18:56 +04:00
|
|
|
|
2018-08-08 04:07:01 +03:00
|
|
|
namespace mozilla {
|
|
|
|
struct MotionPathData;
|
|
|
|
}
|
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
/**
|
2011-09-27 01:54:45 +04:00
|
|
|
* A helper to generate gfxMatrixes from css transform functions.
|
2008-09-13 13:42:11 +04:00
|
|
|
*/
|
2011-09-27 01:54:45 +04:00
|
|
|
namespace nsStyleTransformMatrix {
|
2017-06-07 06:25:14 +03:00
|
|
|
// The operator passed to Servo backend.
|
|
|
|
enum class MatrixTransformOperator: uint8_t {
|
|
|
|
Interpolate,
|
|
|
|
Accumulate
|
|
|
|
};
|
2015-04-28 21:55:42 +03:00
|
|
|
|
2017-01-20 04:45:33 +03:00
|
|
|
// Function for applying perspective() transform function. We treat
|
|
|
|
// any value smaller than epsilon as perspective(infinity), which
|
|
|
|
// follows CSSWG's resolution on perspective(0). See bug 1316236.
|
|
|
|
inline void ApplyPerspectiveToMatrix(mozilla::gfx::Matrix4x4& aMatrix,
|
|
|
|
float aDepth)
|
|
|
|
{
|
|
|
|
if (aDepth >= std::numeric_limits<float>::epsilon()) {
|
|
|
|
aMatrix.Perspective(aDepth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-28 21:55:42 +03:00
|
|
|
/**
|
|
|
|
* This class provides on-demand access to the 'reference box' for CSS
|
|
|
|
* transforms (needed to resolve percentage values in 'transform',
|
|
|
|
* 'transform-origin', etc.):
|
|
|
|
*
|
|
|
|
* http://dev.w3.org/csswg/css-transforms/#reference-box
|
|
|
|
*
|
|
|
|
* This class helps us to avoid calculating the reference box unless and
|
|
|
|
* until it is actually needed. This is important for performance when
|
|
|
|
* transforms are applied to SVG elements since the reference box for SVG is
|
|
|
|
* much more expensive to calculate (than for elements with a CSS layout box
|
|
|
|
* where we can use the nsIFrame's cached mRect), much more common (than on
|
|
|
|
* HTML), and yet very rarely have percentage values that require the
|
|
|
|
* reference box to be resolved. We also don't want to cause SVG frames to
|
|
|
|
* cache lots of ObjectBoundingBoxProperty objects that aren't needed.
|
|
|
|
*
|
|
|
|
* If UNIFIED_CONTINUATIONS (experimental, and currently broke) is defined,
|
|
|
|
* we consider the reference box for non-SVG frames to be the smallest
|
|
|
|
* rectangle containing a frame and all of its continuations. For example,
|
|
|
|
* if there is a <span> element with several continuations split over
|
|
|
|
* several lines, this function will return the rectangle containing all of
|
|
|
|
* those continuations. (This behavior is not currently in a spec.)
|
|
|
|
*/
|
|
|
|
class MOZ_STACK_CLASS TransformReferenceBox final {
|
|
|
|
public:
|
|
|
|
typedef nscoord (TransformReferenceBox::*DimensionGetter)();
|
|
|
|
|
|
|
|
explicit TransformReferenceBox()
|
|
|
|
: mFrame(nullptr)
|
2018-06-14 12:54:03 +03:00
|
|
|
, mX(0)
|
|
|
|
, mY(0)
|
|
|
|
, mWidth(0)
|
|
|
|
, mHeight(0)
|
2015-04-28 21:55:42 +03:00
|
|
|
, mIsCached(false)
|
|
|
|
{}
|
|
|
|
|
|
|
|
explicit TransformReferenceBox(const nsIFrame* aFrame)
|
|
|
|
: mFrame(aFrame)
|
2018-06-14 12:54:03 +03:00
|
|
|
, mX(0)
|
|
|
|
, mY(0)
|
|
|
|
, mWidth(0)
|
|
|
|
, mHeight(0)
|
2015-04-28 21:55:42 +03:00
|
|
|
, mIsCached(false)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit TransformReferenceBox(const nsIFrame* aFrame,
|
|
|
|
const nsSize& aFallbackDimensions)
|
2018-06-14 12:54:03 +03:00
|
|
|
: mX(0)
|
|
|
|
, mY(0)
|
|
|
|
, mWidth(0)
|
|
|
|
, mHeight(0)
|
2015-04-28 21:55:42 +03:00
|
|
|
{
|
|
|
|
mFrame = aFrame;
|
|
|
|
mIsCached = false;
|
|
|
|
if (!mFrame) {
|
|
|
|
Init(aFallbackDimensions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Init(const nsIFrame* aFrame) {
|
|
|
|
MOZ_ASSERT(!mFrame && !mIsCached);
|
|
|
|
mFrame = aFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Init(const nsSize& aDimensions);
|
|
|
|
|
2015-05-25 00:40:37 +03:00
|
|
|
/**
|
|
|
|
* The offset of the reference box from the nsIFrame's TopLeft(). This
|
|
|
|
* is non-zero only in the case of SVG content. If we can successfully
|
|
|
|
* implement UNIFIED_CONTINUATIONS at some point in the future then it
|
|
|
|
* may also be non-zero for non-SVG content.
|
|
|
|
*/
|
|
|
|
nscoord X() {
|
|
|
|
EnsureDimensionsAreCached();
|
|
|
|
return mX;
|
|
|
|
}
|
|
|
|
nscoord Y() {
|
|
|
|
EnsureDimensionsAreCached();
|
|
|
|
return mY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The size of the reference box.
|
|
|
|
*/
|
2015-04-28 21:55:42 +03:00
|
|
|
nscoord Width() {
|
|
|
|
EnsureDimensionsAreCached();
|
|
|
|
return mWidth;
|
|
|
|
}
|
|
|
|
nscoord Height() {
|
|
|
|
EnsureDimensionsAreCached();
|
|
|
|
return mHeight;
|
|
|
|
}
|
|
|
|
|
2016-10-05 10:36:16 +03:00
|
|
|
bool IsEmpty() {
|
|
|
|
return !mFrame;
|
|
|
|
}
|
|
|
|
|
2015-04-28 21:55:42 +03:00
|
|
|
private:
|
|
|
|
// We don't really need to prevent copying, but since none of our consumers
|
|
|
|
// currently need to copy, preventing copying may allow us to catch some
|
|
|
|
// cases where we use pass-by-value instead of pass-by-reference.
|
|
|
|
TransformReferenceBox(const TransformReferenceBox&) = delete;
|
|
|
|
|
|
|
|
void EnsureDimensionsAreCached();
|
|
|
|
|
|
|
|
const nsIFrame* mFrame;
|
2015-05-25 00:40:37 +03:00
|
|
|
nscoord mX, mY, mWidth, mHeight;
|
2015-04-28 21:55:42 +03:00
|
|
|
bool mIsCached;
|
|
|
|
};
|
|
|
|
|
2010-07-03 08:18:56 +04:00
|
|
|
/**
|
|
|
|
* Return the transform function, as an nsCSSKeyword, for the given
|
|
|
|
* nsCSSValue::Array from a transform list.
|
|
|
|
*/
|
2011-09-27 01:54:45 +04:00
|
|
|
nsCSSKeyword TransformFunctionOf(const nsCSSValue::Array* aData);
|
2010-07-03 08:18:56 +04:00
|
|
|
|
2016-10-03 12:43:20 +03:00
|
|
|
void SetIdentityMatrix(nsCSSValue::Array* aMatrix);
|
|
|
|
|
2012-07-31 21:28:21 +04:00
|
|
|
float ProcessTranslatePart(const nsCSSValue& aValue,
|
2015-04-28 21:55:42 +03:00
|
|
|
TransformReferenceBox* aRefBox,
|
|
|
|
TransformReferenceBox::DimensionGetter aDimensionGetter = nullptr);
|
2012-07-31 21:28:21 +04:00
|
|
|
|
2012-12-12 01:12:43 +04:00
|
|
|
void
|
2015-07-11 03:05:47 +03:00
|
|
|
ProcessInterpolateMatrix(mozilla::gfx::Matrix4x4& aMatrix,
|
|
|
|
const nsCSSValue::Array* aData,
|
2018-11-08 05:25:28 +03:00
|
|
|
TransformReferenceBox& aBounds);
|
2012-12-12 01:12:43 +04:00
|
|
|
|
2016-11-16 14:32:33 +03:00
|
|
|
void
|
|
|
|
ProcessAccumulateMatrix(mozilla::gfx::Matrix4x4& aMatrix,
|
|
|
|
const nsCSSValue::Array* aData,
|
2018-11-08 05:25:28 +03:00
|
|
|
TransformReferenceBox& aBounds);
|
2016-11-16 14:32:33 +03:00
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
/**
|
2011-09-27 01:54:45 +04:00
|
|
|
* Given an nsCSSValueList containing -moz-transform functions,
|
|
|
|
* returns a matrix containing the value of those functions.
|
2008-09-13 13:42:11 +04:00
|
|
|
*
|
2011-09-27 01:54:45 +04:00
|
|
|
* @param aData The nsCSSValueList containing the transform functions
|
2011-07-23 02:28:07 +04:00
|
|
|
* @param aBounds The frame's bounding rectangle.
|
|
|
|
* @param aAppUnitsPerMatrixUnit The number of app units per device pixel.
|
2010-07-03 08:18:56 +04:00
|
|
|
*
|
2014-06-24 10:29:54 +04:00
|
|
|
* eCSSUnit_Pixel (as they are in an StyleAnimationValue)
|
2008-09-13 13:42:11 +04:00
|
|
|
*/
|
2015-07-11 03:05:47 +03:00
|
|
|
mozilla::gfx::Matrix4x4 ReadTransforms(const nsCSSValueList* aList,
|
|
|
|
TransformReferenceBox& aBounds,
|
2018-11-08 05:25:28 +03:00
|
|
|
float aAppUnitsPerMatrixUnit);
|
2016-10-04 10:00:31 +03:00
|
|
|
|
2018-08-08 04:07:01 +03:00
|
|
|
// Generate the gfx::Matrix for CSS Transform Module Level 2.
|
|
|
|
// https://drafts.csswg.org/css-transforms-2/#ctm
|
|
|
|
mozilla::gfx::Matrix4x4
|
|
|
|
ReadTransforms(const nsCSSValueList* aIndividualTransforms,
|
|
|
|
const mozilla::Maybe<mozilla::MotionPathData>& aMotion,
|
|
|
|
const nsCSSValueList* aTransform,
|
|
|
|
TransformReferenceBox& aRefBox,
|
2018-11-08 05:25:28 +03:00
|
|
|
float aAppUnitsPerMatrixUnit);
|
2018-08-08 04:07:01 +03:00
|
|
|
|
2017-06-19 07:49:52 +03:00
|
|
|
/**
|
|
|
|
* Given two nsStyleCoord values, compute the 2d position with respect to the
|
|
|
|
* given TransformReferenceBox that these values describe, in device pixels.
|
|
|
|
*/
|
|
|
|
mozilla::gfx::Point Convert2DPosition(nsStyleCoord const (&aValue)[2],
|
|
|
|
TransformReferenceBox& aRefBox,
|
|
|
|
int32_t aAppUnitsPerDevPixel);
|
|
|
|
|
2016-10-04 10:00:31 +03:00
|
|
|
// Shear type for decomposition.
|
2016-10-12 07:36:58 +03:00
|
|
|
enum class ShearType {
|
|
|
|
XYSHEAR,
|
|
|
|
XZSHEAR,
|
|
|
|
YZSHEAR,
|
|
|
|
Count
|
|
|
|
};
|
|
|
|
using ShearArray =
|
|
|
|
mozilla::EnumeratedArray<ShearType, ShearType::Count, float>;
|
2016-10-04 10:00:31 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Implements the 2d transform matrix decomposition algorithm.
|
|
|
|
*/
|
|
|
|
bool Decompose2DMatrix(const mozilla::gfx::Matrix& aMatrix,
|
|
|
|
mozilla::gfx::Point3D& aScale,
|
2016-10-12 07:36:58 +03:00
|
|
|
ShearArray& aShear,
|
2016-10-04 10:00:31 +03:00
|
|
|
gfxQuaternion& aRotate,
|
|
|
|
mozilla::gfx::Point3D& aTranslate);
|
|
|
|
/*
|
|
|
|
* Implements the 3d transform matrix decomposition algorithm.
|
|
|
|
*/
|
|
|
|
bool Decompose3DMatrix(const mozilla::gfx::Matrix4x4& aMatrix,
|
|
|
|
mozilla::gfx::Point3D& aScale,
|
2016-10-12 07:36:58 +03:00
|
|
|
ShearArray& aShear,
|
2016-10-04 10:00:31 +03:00
|
|
|
gfxQuaternion& aRotate,
|
|
|
|
mozilla::gfx::Point3D& aTranslate,
|
|
|
|
mozilla::gfx::Point4D& aPerspective);
|
2016-10-04 13:32:20 +03:00
|
|
|
|
|
|
|
mozilla::gfx::Matrix CSSValueArrayTo2DMatrix(nsCSSValue::Array* aArray);
|
|
|
|
mozilla::gfx::Matrix4x4 CSSValueArrayTo3DMatrix(nsCSSValue::Array* aArray);
|
2017-02-06 11:32:21 +03:00
|
|
|
|
2017-11-13 02:37:33 +03:00
|
|
|
mozilla::gfx::Size GetScaleValue(const nsCSSValueSharedList* aList,
|
|
|
|
const nsIFrame* aForFrame);
|
2011-09-27 01:54:45 +04:00
|
|
|
} // namespace nsStyleTransformMatrix
|
2008-09-13 13:42:11 +04:00
|
|
|
|
|
|
|
#endif
|