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-06-28 18:42:23 +03:00
|
|
|
#include "mozilla/gfx/Matrix.h"
|
2016-10-12 07:36:58 +03:00
|
|
|
#include "mozilla/EnumeratedArray.h"
|
Bug 1590639 part 4: Fix non-unified build issues in layout/style. r=emilio
This patch:
- Gives layout/generic/AnonymousContentKey.h an include for `<stdint.h>` to
provide the uint8_t type, and TypedEnumBits.h to provide the
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS macro. (This is a change in another
directory, but it's needed in order for layout/style/ServoStyleSet.cpp to
build successfully.)
- Adds a missing "nsINode" forward-decl to dom/base/IdentifierMapEntry.h,
because it uses that type in function declarations. (This change is needed
in order for layout/style/CachedInheritingStyles.cpp to build successfully.)
- Gives CSSStyleRule.cpp an include for PseudoStyleType.h,
nsCSSPseudoElements.h, and CSSEnabledState.h because it uses those types.
- Gives GeckoBindings.cpp an include for gfxTextRun.h, to provide the definition
of type gfxFontGroup (so GeckoBindings can call GetFirstValidFont() on an
object of that type).
- Gives Loader.h an include for nsIContentInlines.h, to provide the inline
function IsInUAWidget().
- Gives Rule.cpp an include for HoldDropJSObjects.h, to provide DropJSObjects().
- Gives nsImageLoader.cpp an include for DocumentInlines.h (and Document.h for
good measure), to provide the inline function GetPresContext().
- Gives nsStyleStruct.cpp an include for DocumentInlines.h, to provide inline
function Document::GetPresContext().
- Gives nsStyleTransformMatrix.h an include for Units.h (instead of gfxPoint.h,
which isn't useful) to provide the CSSPoint type.
- Gives nsStyleTransformMatrix.h an include for ServoStyleConsts.h, to provide
LengthPercentage and the various StyleRotate/StyleScale/StyleTransform/etc
types. (These can't be easily forward-declared, because some of them are
legitimate types whereas others are type aliases. We could theoretically
forward-declare all of the underlying types and then repeat the type aliases,
but that'd be verbose and unmaintainable.)
Depends on D50165
Differential Revision: https://phabricator.services.mozilla.com/D50166
--HG--
extra : moz-landing-system : lando
2019-10-23 11:14:54 +03:00
|
|
|
#include "mozilla/ServoStyleConsts.h"
|
2017-07-05 18:22:00 +03:00
|
|
|
#include "nsSize.h"
|
Bug 1590639 part 4: Fix non-unified build issues in layout/style. r=emilio
This patch:
- Gives layout/generic/AnonymousContentKey.h an include for `<stdint.h>` to
provide the uint8_t type, and TypedEnumBits.h to provide the
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS macro. (This is a change in another
directory, but it's needed in order for layout/style/ServoStyleSet.cpp to
build successfully.)
- Adds a missing "nsINode" forward-decl to dom/base/IdentifierMapEntry.h,
because it uses that type in function declarations. (This change is needed
in order for layout/style/CachedInheritingStyles.cpp to build successfully.)
- Gives CSSStyleRule.cpp an include for PseudoStyleType.h,
nsCSSPseudoElements.h, and CSSEnabledState.h because it uses those types.
- Gives GeckoBindings.cpp an include for gfxTextRun.h, to provide the definition
of type gfxFontGroup (so GeckoBindings can call GetFirstValidFont() on an
object of that type).
- Gives Loader.h an include for nsIContentInlines.h, to provide the inline
function IsInUAWidget().
- Gives Rule.cpp an include for HoldDropJSObjects.h, to provide DropJSObjects().
- Gives nsImageLoader.cpp an include for DocumentInlines.h (and Document.h for
good measure), to provide the inline function GetPresContext().
- Gives nsStyleStruct.cpp an include for DocumentInlines.h, to provide inline
function Document::GetPresContext().
- Gives nsStyleTransformMatrix.h an include for Units.h (instead of gfxPoint.h,
which isn't useful) to provide the CSSPoint type.
- Gives nsStyleTransformMatrix.h an include for ServoStyleConsts.h, to provide
LengthPercentage and the various StyleRotate/StyleScale/StyleTransform/etc
types. (These can't be easily forward-declared, because some of them are
legitimate types whereas others are type aliases. We could theoretically
forward-declare all of the underlying types and then repeat the type aliases,
but that'd be verbose and unmaintainable.)
Depends on D50165
Differential Revision: https://phabricator.services.mozilla.com/D50166
--HG--
extra : moz-landing-system : lando
2019-10-23 11:14:54 +03:00
|
|
|
#include "Units.h" // for CSSPoint
|
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 {
|
2020-01-08 12:02:38 +03:00
|
|
|
struct ResolvedMotionPathData;
|
2018-08-08 04:07:01 +03:00
|
|
|
}
|
|
|
|
|
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 };
|
2018-11-30 13:46:48 +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);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-01-20 04:45:33 +03:00
|
|
|
|
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)();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-04-28 21:55:42 +03:00
|
|
|
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) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-04-28 21:55:42 +03:00
|
|
|
explicit TransformReferenceBox(const nsIFrame* aFrame)
|
|
|
|
: mFrame(aFrame), mX(0), mY(0), mWidth(0), mHeight(0), 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);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-04-28 21:55:42 +03:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2015-04-28 21:55:42 +03:00
|
|
|
nscoord X() {
|
|
|
|
EnsureDimensionsAreCached();
|
|
|
|
return mX;
|
|
|
|
}
|
|
|
|
nscoord Y() {
|
|
|
|
EnsureDimensionsAreCached();
|
|
|
|
return mY;
|
|
|
|
}
|
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
/**
|
2016-10-05 10:36:16 +03:00
|
|
|
* The size of the reference box.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2016-10-05 10:36:16 +03:00
|
|
|
nscoord Width() {
|
|
|
|
EnsureDimensionsAreCached();
|
|
|
|
return mWidth;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-25 00:40:37 +03:00
|
|
|
nscoord Height() {
|
|
|
|
EnsureDimensionsAreCached();
|
2018-11-30 13:46:48 +03:00
|
|
|
return mHeight;
|
2016-10-05 10:36:16 +03:00
|
|
|
}
|
|
|
|
|
2015-04-28 21:55:42 +03:00
|
|
|
bool IsEmpty() { return !mFrame; }
|
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
private:
|
2015-04-28 21:55:42 +03:00
|
|
|
// 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();
|
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
const nsIFrame* mFrame;
|
|
|
|
nscoord mX, mY, mWidth, mHeight;
|
|
|
|
bool mIsCached;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
2010-07-03 08:18:56 +04:00
|
|
|
|
2015-07-11 03:05:47 +03:00
|
|
|
float ProcessTranslatePart(
|
2019-05-17 02:25:10 +03:00
|
|
|
const mozilla::LengthPercentage& aValue, TransformReferenceBox* aRefBox,
|
2018-11-08 05:25:28 +03:00
|
|
|
TransformReferenceBox::DimensionGetter aDimensionGetter = nullptr);
|
2012-12-12 01:12:43 +04:00
|
|
|
|
2016-11-16 14:32:33 +03:00
|
|
|
void ProcessInterpolateMatrix(mozilla::gfx::Matrix4x4& aMatrix,
|
2019-05-17 02:25:10 +03:00
|
|
|
const mozilla::StyleTransformOperation& aOp,
|
2018-11-08 05:25:28 +03:00
|
|
|
TransformReferenceBox& aBounds);
|
2016-11-16 14:32:33 +03:00
|
|
|
|
2015-07-11 03:05:47 +03:00
|
|
|
void ProcessAccumulateMatrix(mozilla::gfx::Matrix4x4& aMatrix,
|
2019-05-17 02:25:10 +03:00
|
|
|
const mozilla::StyleTransformOperation& aOp,
|
2015-07-11 03:05:47 +03:00
|
|
|
TransformReferenceBox& aBounds);
|
2018-03-22 21:20:41 +03:00
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
/**
|
2019-05-17 02:25:10 +03:00
|
|
|
* Given a StyleTransform containing transform functions, returns a matrix
|
|
|
|
* containing the value of those functions.
|
2008-09-13 13:42:11 +04:00
|
|
|
*
|
2019-05-17 02:25:10 +03:00
|
|
|
* @param aList the transform operation list.
|
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.
|
2008-09-13 13:42:11 +04:00
|
|
|
*/
|
2019-05-17 02:25:10 +03:00
|
|
|
mozilla::gfx::Matrix4x4 ReadTransforms(const mozilla::StyleTransform& aList,
|
2015-07-11 03:05:47 +03:00
|
|
|
TransformReferenceBox& aBounds,
|
2018-11-08 05:25:28 +03:00
|
|
|
float aAppUnitsPerMatrixUnit);
|
2018-11-30 13:46:48 +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(
|
2019-05-17 02:25:10 +03:00
|
|
|
const mozilla::StyleTranslate&, const mozilla::StyleRotate&,
|
|
|
|
const mozilla::StyleScale&,
|
2020-01-08 12:02:38 +03:00
|
|
|
const mozilla::Maybe<mozilla::ResolvedMotionPathData>& aMotion,
|
2019-05-17 02:25:10 +03:00
|
|
|
const mozilla::StyleTransform&, TransformReferenceBox& aRefBox,
|
2018-11-08 05:25:28 +03:00
|
|
|
float aAppUnitsPerMatrixUnit);
|
2018-08-08 04:07:01 +03:00
|
|
|
|
2019-10-31 23:07:30 +03:00
|
|
|
/**
|
|
|
|
* Given the x and y values, compute the 2d position with respect to the given
|
|
|
|
* a reference box size that these values describe, in CSS pixels.
|
|
|
|
*/
|
|
|
|
mozilla::CSSPoint Convert2DPosition(const mozilla::LengthPercentage& aX,
|
|
|
|
const mozilla::LengthPercentage& aY,
|
|
|
|
const mozilla::CSSSize& aSize);
|
|
|
|
|
2017-06-19 07:49:52 +03:00
|
|
|
/**
|
2019-02-19 23:28:47 +03:00
|
|
|
* Given the x and y values, compute the 2d position with respect to the given
|
|
|
|
* TransformReferenceBox that these values describe, in CSS pixels.
|
2017-06-19 07:49:52 +03:00
|
|
|
*/
|
2019-02-19 23:28:47 +03:00
|
|
|
mozilla::CSSPoint Convert2DPosition(const mozilla::LengthPercentage& aX,
|
|
|
|
const mozilla::LengthPercentage& aY,
|
|
|
|
TransformReferenceBox& aRefBox);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given the x and y values, compute the 2d position with respect to the given
|
|
|
|
* TransformReferenceBox that these values describe, in device pixels.
|
|
|
|
*/
|
|
|
|
mozilla::gfx::Point Convert2DPosition(const mozilla::LengthPercentage& aX,
|
|
|
|
const mozilla::LengthPercentage& aY,
|
2017-06-19 07:49:52 +03:00
|
|
|
TransformReferenceBox& aRefBox,
|
|
|
|
int32_t aAppUnitsPerDevPixel);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-10-04 10:00:31 +03:00
|
|
|
// Shear type for decomposition.
|
2019-04-26 02:03:04 +03:00
|
|
|
enum class ShearType { XY, XZ, YZ, Count };
|
2016-10-12 07:36:58 +03:00
|
|
|
using ShearArray = mozilla::EnumeratedArray<ShearType, ShearType::Count, float>;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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, ShearArray& aShear,
|
|
|
|
gfxQuaternion& aRotate,
|
|
|
|
mozilla::gfx::Point3D& aTranslate);
|
|
|
|
/*
|
|
|
|
* Implements the 3d transform matrix decomposition algorithm.
|
|
|
|
*/
|
|
|
|
bool Decompose3DMatrix(const mozilla::gfx::Matrix4x4& aMatrix,
|
|
|
|
mozilla::gfx::Point3D& aScale, ShearArray& aShear,
|
|
|
|
gfxQuaternion& aRotate,
|
|
|
|
mozilla::gfx::Point3D& aTranslate,
|
|
|
|
mozilla::gfx::Point4D& aPerspective);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
} // namespace nsStyleTransformMatrix
|
2008-09-13 13:42:11 +04:00
|
|
|
|
|
|
|
#endif
|