2008-09-13 13:42:11 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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 used for intermediate representations of the -moz-transform property.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsStyleTransformMatrix.h"
|
|
|
|
#include "nsCSSValue.h"
|
2015-05-25 00:40:37 +03:00
|
|
|
#include "nsLayoutUtils.h"
|
2008-09-13 13:42:11 +04:00
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsRuleNode.h"
|
2015-05-25 00:40:37 +03:00
|
|
|
#include "nsSVGUtils.h"
|
2008-09-13 13:42:11 +04:00
|
|
|
#include "nsCSSKeywords.h"
|
2014-06-24 10:29:54 +04:00
|
|
|
#include "mozilla/StyleAnimationValue.h"
|
2013-09-16 05:06:52 +04:00
|
|
|
#include "gfxMatrix.h"
|
2010-07-03 08:18:56 +04:00
|
|
|
|
2013-11-15 06:42:57 +04:00
|
|
|
using namespace mozilla;
|
2014-08-29 22:47:30 +04:00
|
|
|
using namespace mozilla::gfx;
|
2008-09-13 13:42:11 +04:00
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
namespace nsStyleTransformMatrix {
|
|
|
|
|
2009-11-02 22:36:43 +03:00
|
|
|
/* Note on floating point precision: The transform matrix is an array
|
|
|
|
* of single precision 'float's, and so are most of the input values
|
|
|
|
* we get from the style system, but intermediate calculations
|
|
|
|
* involving angles need to be done in 'double'.
|
|
|
|
*/
|
2008-09-13 13:42:11 +04:00
|
|
|
|
2015-04-28 21:55:42 +03:00
|
|
|
|
|
|
|
// Define UNIFIED_CONTINUATIONS here and in nsDisplayList.cpp
|
|
|
|
// to have the transform property try
|
|
|
|
// to transform content with continuations as one unified block instead of
|
|
|
|
// several smaller ones. This is currently disabled because it doesn't work
|
|
|
|
// correctly, since when the frames are initially being reflowed, their
|
|
|
|
// continuations all compute their bounding rects independently of each other
|
|
|
|
// and consequently get the wrong value.
|
|
|
|
//#define UNIFIED_CONTINUATIONS
|
|
|
|
|
|
|
|
void
|
|
|
|
TransformReferenceBox::EnsureDimensionsAreCached()
|
|
|
|
{
|
|
|
|
if (mIsCached) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mFrame);
|
|
|
|
|
|
|
|
mIsCached = true;
|
|
|
|
|
|
|
|
if (mFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT) {
|
2015-05-25 00:40:37 +03:00
|
|
|
if (!nsLayoutUtils::SVGTransformOriginEnabled()) {
|
|
|
|
mX = -mFrame->GetPosition().x;
|
|
|
|
mY = -mFrame->GetPosition().y;
|
|
|
|
mWidth = 0;
|
|
|
|
mHeight = 0;
|
|
|
|
} else
|
|
|
|
if (mFrame->StyleDisplay()->mTransformBox ==
|
|
|
|
NS_STYLE_TRANSFORM_BOX_FILL_BOX) {
|
|
|
|
// Percentages in transforms resolve against the SVG bbox, and the
|
|
|
|
// transform is relative to the top-left of the SVG bbox.
|
|
|
|
gfxRect bbox = nsSVGUtils::GetBBox(const_cast<nsIFrame*>(mFrame));
|
|
|
|
nsRect bboxInAppUnits =
|
|
|
|
nsLayoutUtils::RoundGfxRectToAppRect(bbox,
|
|
|
|
mFrame->PresContext()->AppUnitsPerCSSPixel());
|
|
|
|
// The mRect of an SVG nsIFrame is its user space bounds *including*
|
|
|
|
// stroke and markers, whereas bboxInAppUnits is its user space bounds
|
|
|
|
// including fill only. We need to note the offset of the reference box
|
|
|
|
// from the frame's mRect in mX/mY.
|
|
|
|
mX = bboxInAppUnits.x - mFrame->GetPosition().x;
|
|
|
|
mY = bboxInAppUnits.y - mFrame->GetPosition().y;
|
|
|
|
mWidth = bboxInAppUnits.width;
|
|
|
|
mHeight = bboxInAppUnits.height;
|
|
|
|
} else {
|
|
|
|
// The value 'border-box' is treated as 'view-box' for SVG content.
|
|
|
|
MOZ_ASSERT(mFrame->StyleDisplay()->mTransformBox ==
|
|
|
|
NS_STYLE_TRANSFORM_BOX_VIEW_BOX ||
|
|
|
|
mFrame->StyleDisplay()->mTransformBox ==
|
|
|
|
NS_STYLE_TRANSFORM_BOX_BORDER_BOX,
|
|
|
|
"Unexpected value for 'transform-box'");
|
|
|
|
// Percentages in transforms resolve against the width/height of the
|
|
|
|
// nearest viewport (or it's viewBox if one is applied), and the
|
|
|
|
// transform is relative to {0,0} in current user space.
|
|
|
|
mX = -mFrame->GetPosition().x;
|
|
|
|
mY = -mFrame->GetPosition().y;
|
|
|
|
Size contextSize = nsSVGUtils::GetContextSize(mFrame);
|
|
|
|
mWidth = nsPresContext::CSSPixelsToAppUnits(contextSize.width);
|
|
|
|
mHeight = nsPresContext::CSSPixelsToAppUnits(contextSize.height);
|
|
|
|
}
|
2015-04-28 21:55:42 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If UNIFIED_CONTINUATIONS is not defined, this is simply the frame's
|
|
|
|
// bounding rectangle, translated to the origin. Otherwise, it is 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.
|
|
|
|
|
|
|
|
nsRect rect;
|
|
|
|
|
|
|
|
#ifndef UNIFIED_CONTINUATIONS
|
|
|
|
rect = mFrame->GetRect();
|
|
|
|
#else
|
|
|
|
// Iterate the continuation list, unioning together the bounding rects:
|
|
|
|
for (const nsIFrame *currFrame = mFrame->FirstContinuation();
|
|
|
|
currFrame != nullptr;
|
|
|
|
currFrame = currFrame->GetNextContinuation())
|
|
|
|
{
|
|
|
|
// Get the frame rect in local coordinates, then translate back to the
|
|
|
|
// original coordinates:
|
|
|
|
rect.UnionRect(result, nsRect(currFrame->GetOffsetTo(mFrame),
|
|
|
|
currFrame->GetSize()));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-05-25 00:40:37 +03:00
|
|
|
mX = 0;
|
|
|
|
mY = 0;
|
2015-04-28 21:55:42 +03:00
|
|
|
mWidth = rect.Width();
|
|
|
|
mHeight = rect.Height();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TransformReferenceBox::Init(const nsSize& aDimensions)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mFrame && !mIsCached);
|
|
|
|
|
2015-05-25 00:40:37 +03:00
|
|
|
mX = 0;
|
|
|
|
mY = 0;
|
2015-04-28 21:55:42 +03:00
|
|
|
mWidth = aDimensions.width;
|
|
|
|
mHeight = aDimensions.height;
|
|
|
|
mIsCached = true;
|
|
|
|
}
|
|
|
|
|
2009-11-03 08:00:46 +03:00
|
|
|
/* Force small values to zero. We do this to avoid having sin(360deg)
|
|
|
|
* evaluate to a tiny but nonzero value.
|
|
|
|
*/
|
|
|
|
static double FlushToZero(double aVal)
|
|
|
|
{
|
|
|
|
if (-FLT_EPSILON < aVal && aVal < FLT_EPSILON)
|
|
|
|
return 0.0f;
|
|
|
|
else
|
|
|
|
return aVal;
|
|
|
|
}
|
|
|
|
|
2012-07-31 21:28:21 +04:00
|
|
|
float
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessTranslatePart(const nsCSSValue& aValue,
|
2011-07-23 02:28:07 +04:00
|
|
|
nsStyleContext* aContext,
|
|
|
|
nsPresContext* aPresContext,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool& aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
TransformReferenceBox* aRefBox,
|
|
|
|
TransformReferenceBox::DimensionGetter aDimensionGetter)
|
2010-07-03 08:18:56 +04:00
|
|
|
{
|
2011-07-23 02:28:07 +04:00
|
|
|
nscoord offset = 0;
|
|
|
|
float percent = 0.0f;
|
|
|
|
|
2010-07-03 08:18:56 +04:00
|
|
|
if (aValue.GetUnit() == eCSSUnit_Percent) {
|
2011-07-23 02:28:07 +04:00
|
|
|
percent = aValue.GetPercentValue();
|
2012-03-06 22:47:13 +04:00
|
|
|
} else if (aValue.GetUnit() == eCSSUnit_Pixel ||
|
|
|
|
aValue.GetUnit() == eCSSUnit_Number) {
|
|
|
|
// Handle this here (even though nsRuleNode::CalcLength handles it
|
|
|
|
// fine) so that callers are allowed to pass a null style context
|
|
|
|
// and pres context to SetToTransformFunction if they know (as
|
2014-06-24 10:29:54 +04:00
|
|
|
// StyleAnimationValue does) that all lengths within the transform
|
2012-03-06 22:47:13 +04:00
|
|
|
// function have already been computed to pixels and percents.
|
|
|
|
//
|
|
|
|
// Raw numbers are treated as being pixels.
|
|
|
|
//
|
|
|
|
// Don't convert to aValue to AppUnits here to avoid precision issues.
|
2014-05-08 09:35:00 +04:00
|
|
|
return aValue.GetFloatValue();
|
2010-07-03 08:18:56 +04:00
|
|
|
} else if (aValue.IsCalcUnit()) {
|
2010-09-11 20:27:13 +04:00
|
|
|
nsRuleNode::ComputedCalc result =
|
|
|
|
nsRuleNode::SpecifiedCalcToComputedCalc(aValue, aContext, aPresContext,
|
|
|
|
aCanStoreInRuleTree);
|
2011-07-23 02:28:07 +04:00
|
|
|
percent = result.mPercent;
|
|
|
|
offset = result.mLength;
|
2010-07-03 08:18:56 +04:00
|
|
|
} else {
|
2012-03-06 22:47:13 +04:00
|
|
|
offset = nsRuleNode::CalcLength(aValue, aContext, aPresContext,
|
|
|
|
aCanStoreInRuleTree);
|
2010-07-03 08:18:56 +04:00
|
|
|
}
|
2011-07-23 02:28:07 +04:00
|
|
|
|
2015-04-28 21:55:42 +03:00
|
|
|
float translation = NSAppUnitsToFloatPixels(offset,
|
|
|
|
nsPresContext::AppUnitsPerCSSPixel());
|
|
|
|
// We want to avoid calling aDimensionGetter if there's no percentage to be
|
|
|
|
// resolved (for performance reasons - see TransformReferenceBox).
|
|
|
|
if (percent != 0.0f && aRefBox) {
|
|
|
|
translation += percent *
|
|
|
|
NSAppUnitsToFloatPixels((aRefBox->*aDimensionGetter)(),
|
|
|
|
nsPresContext::AppUnitsPerCSSPixel());
|
|
|
|
}
|
|
|
|
return translation;
|
2010-07-03 08:18:56 +04:00
|
|
|
}
|
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
/**
|
|
|
|
* Helper functions to process all the transformation function types.
|
|
|
|
*
|
|
|
|
* These take a matrix parameter to accumulate the current matrix.
|
|
|
|
*/
|
|
|
|
|
2010-08-06 08:59:18 +04:00
|
|
|
/* Helper function to process a matrix entry. */
|
2011-09-27 01:54:45 +04:00
|
|
|
static void
|
|
|
|
ProcessMatrix(gfx3DMatrix& aMatrix,
|
|
|
|
const nsCSSValue::Array* aData,
|
|
|
|
nsStyleContext* aContext,
|
|
|
|
nsPresContext* aPresContext,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool& aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
TransformReferenceBox& aRefBox)
|
2010-08-06 08:59:18 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aData->Count() == 7, "Invalid array!");
|
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
gfxMatrix result;
|
2011-07-23 02:28:07 +04:00
|
|
|
|
2010-08-06 08:59:18 +04:00
|
|
|
/* Take the first four elements out of the array as floats and store
|
2011-07-23 02:28:07 +04:00
|
|
|
* them.
|
2010-08-06 08:59:18 +04:00
|
|
|
*/
|
2014-06-17 21:35:51 +04:00
|
|
|
result._11 = aData->Item(1).GetFloatValue();
|
|
|
|
result._12 = aData->Item(2).GetFloatValue();
|
|
|
|
result._21 = aData->Item(3).GetFloatValue();
|
|
|
|
result._22 = aData->Item(4).GetFloatValue();
|
2010-08-06 08:59:18 +04:00
|
|
|
|
|
|
|
/* The last two elements have their length parts stored in aDelta
|
|
|
|
* and their percent parts stored in aX[0] and aY[1].
|
|
|
|
*/
|
2014-06-17 21:35:51 +04:00
|
|
|
result._31 = ProcessTranslatePart(aData->Item(5),
|
2011-09-27 01:54:45 +04:00
|
|
|
aContext, aPresContext, aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
&aRefBox, &TransformReferenceBox::Width);
|
2014-06-17 21:35:51 +04:00
|
|
|
result._32 = ProcessTranslatePart(aData->Item(6),
|
2011-09-27 01:54:45 +04:00
|
|
|
aContext, aPresContext, aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
&aRefBox, &TransformReferenceBox::Height);
|
2011-09-27 01:54:45 +04:00
|
|
|
|
|
|
|
aMatrix.PreMultiply(result);
|
2011-07-23 02:28:07 +04:00
|
|
|
}
|
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
static void
|
|
|
|
ProcessMatrix3D(gfx3DMatrix& aMatrix,
|
|
|
|
const nsCSSValue::Array* aData,
|
|
|
|
nsStyleContext* aContext,
|
|
|
|
nsPresContext* aPresContext,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool& aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
TransformReferenceBox& aRefBox)
|
2011-08-03 07:04:19 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aData->Count() == 17, "Invalid array!");
|
|
|
|
|
|
|
|
gfx3DMatrix temp;
|
|
|
|
|
|
|
|
temp._11 = aData->Item(1).GetFloatValue();
|
|
|
|
temp._12 = aData->Item(2).GetFloatValue();
|
|
|
|
temp._13 = aData->Item(3).GetFloatValue();
|
|
|
|
temp._14 = aData->Item(4).GetFloatValue();
|
|
|
|
temp._21 = aData->Item(5).GetFloatValue();
|
|
|
|
temp._22 = aData->Item(6).GetFloatValue();
|
|
|
|
temp._23 = aData->Item(7).GetFloatValue();
|
|
|
|
temp._24 = aData->Item(8).GetFloatValue();
|
|
|
|
temp._31 = aData->Item(9).GetFloatValue();
|
|
|
|
temp._32 = aData->Item(10).GetFloatValue();
|
|
|
|
temp._33 = aData->Item(11).GetFloatValue();
|
|
|
|
temp._34 = aData->Item(12).GetFloatValue();
|
|
|
|
temp._44 = aData->Item(16).GetFloatValue();
|
2011-09-27 01:54:30 +04:00
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
temp._41 = ProcessTranslatePart(aData->Item(13),
|
|
|
|
aContext, aPresContext, aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
&aRefBox, &TransformReferenceBox::Width);
|
2011-09-27 01:54:45 +04:00
|
|
|
temp._42 = ProcessTranslatePart(aData->Item(14),
|
|
|
|
aContext, aPresContext, aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
&aRefBox, &TransformReferenceBox::Height);
|
2011-09-27 01:54:45 +04:00
|
|
|
temp._43 = ProcessTranslatePart(aData->Item(15),
|
|
|
|
aContext, aPresContext, aCanStoreInRuleTree,
|
2015-05-25 13:13:42 +03:00
|
|
|
nullptr);
|
2011-09-27 01:54:45 +04:00
|
|
|
|
|
|
|
aMatrix.PreMultiply(temp);
|
2011-08-03 07:04:19 +04:00
|
|
|
}
|
|
|
|
|
2011-07-23 02:28:07 +04:00
|
|
|
/* Helper function to process two matrices that we need to interpolate between */
|
2012-12-12 01:12:43 +04:00
|
|
|
void
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessInterpolateMatrix(gfx3DMatrix& aMatrix,
|
|
|
|
const nsCSSValue::Array* aData,
|
|
|
|
nsStyleContext* aContext,
|
|
|
|
nsPresContext* aPresContext,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool& aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
TransformReferenceBox& aRefBox)
|
2011-07-23 02:28:07 +04:00
|
|
|
{
|
2011-09-27 01:53:33 +04:00
|
|
|
NS_PRECONDITION(aData->Count() == 4, "Invalid array!");
|
|
|
|
|
|
|
|
gfx3DMatrix matrix1, matrix2;
|
|
|
|
if (aData->Item(1).GetUnit() == eCSSUnit_List) {
|
2011-09-27 01:54:45 +04:00
|
|
|
matrix1 = nsStyleTransformMatrix::ReadTransforms(aData->Item(1).GetListValue(),
|
2011-09-27 01:53:33 +04:00
|
|
|
aContext, aPresContext,
|
|
|
|
aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
aRefBox, nsPresContext::AppUnitsPerCSSPixel());
|
2011-09-27 01:53:33 +04:00
|
|
|
}
|
|
|
|
if (aData->Item(2).GetUnit() == eCSSUnit_List) {
|
|
|
|
matrix2 = ReadTransforms(aData->Item(2).GetListValue(),
|
|
|
|
aContext, aPresContext,
|
|
|
|
aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
aRefBox, nsPresContext::AppUnitsPerCSSPixel());
|
2011-09-27 01:53:33 +04:00
|
|
|
}
|
|
|
|
double progress = aData->Item(3).GetPercentValue();
|
2011-07-23 02:28:07 +04:00
|
|
|
|
2014-06-24 10:29:54 +04:00
|
|
|
aMatrix =
|
|
|
|
StyleAnimationValue::InterpolateTransformMatrix(matrix1, matrix2, progress)
|
|
|
|
* aMatrix;
|
2010-08-06 08:59:18 +04:00
|
|
|
}
|
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
/* Helper function to process a translatex function. */
|
2011-09-27 01:54:45 +04:00
|
|
|
static void
|
2014-06-24 10:29:54 +04:00
|
|
|
ProcessTranslateX(gfx3DMatrix& aMatrix,
|
2011-09-27 01:54:45 +04:00
|
|
|
const nsCSSValue::Array* aData,
|
|
|
|
nsStyleContext* aContext,
|
|
|
|
nsPresContext* aPresContext,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool& aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
TransformReferenceBox& aRefBox)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aData->Count() == 2, "Invalid array!");
|
|
|
|
|
2014-08-29 22:47:30 +04:00
|
|
|
Point3D temp;
|
2011-07-23 02:28:07 +04:00
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
temp.x = ProcessTranslatePart(aData->Item(1),
|
|
|
|
aContext, aPresContext, aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
&aRefBox, &TransformReferenceBox::Width);
|
2011-09-27 01:54:45 +04:00
|
|
|
aMatrix.Translate(temp);
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Helper function to process a translatey function. */
|
2011-09-27 01:54:45 +04:00
|
|
|
static void
|
|
|
|
ProcessTranslateY(gfx3DMatrix& aMatrix,
|
|
|
|
const nsCSSValue::Array* aData,
|
|
|
|
nsStyleContext* aContext,
|
|
|
|
nsPresContext* aPresContext,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool& aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
TransformReferenceBox& aRefBox)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aData->Count() == 2, "Invalid array!");
|
|
|
|
|
2014-08-29 22:47:30 +04:00
|
|
|
Point3D temp;
|
2011-07-23 02:28:07 +04:00
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
temp.y = ProcessTranslatePart(aData->Item(1),
|
|
|
|
aContext, aPresContext, aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
&aRefBox, &TransformReferenceBox::Height);
|
2011-09-27 01:54:45 +04:00
|
|
|
aMatrix.Translate(temp);
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
static void
|
|
|
|
ProcessTranslateZ(gfx3DMatrix& aMatrix,
|
|
|
|
const nsCSSValue::Array* aData,
|
|
|
|
nsStyleContext* aContext,
|
2014-05-08 09:35:00 +04:00
|
|
|
nsPresContext* aPresContext,
|
|
|
|
bool& aCanStoreInRuleTree)
|
2011-08-03 07:04:19 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aData->Count() == 2, "Invalid array!");
|
|
|
|
|
2014-08-29 22:47:30 +04:00
|
|
|
Point3D temp;
|
2011-08-03 07:04:19 +04:00
|
|
|
|
2014-05-08 09:35:00 +04:00
|
|
|
temp.z = ProcessTranslatePart(aData->Item(1), aContext,
|
2015-04-28 21:55:42 +03:00
|
|
|
aPresContext, aCanStoreInRuleTree,
|
|
|
|
nullptr);
|
2011-09-27 01:54:45 +04:00
|
|
|
aMatrix.Translate(temp);
|
2011-08-03 07:04:19 +04:00
|
|
|
}
|
|
|
|
|
2008-09-20 20:55:27 +04:00
|
|
|
/* Helper function to process a translate function. */
|
2011-09-27 01:54:45 +04:00
|
|
|
static void
|
|
|
|
ProcessTranslate(gfx3DMatrix& aMatrix,
|
|
|
|
const nsCSSValue::Array* aData,
|
|
|
|
nsStyleContext* aContext,
|
|
|
|
nsPresContext* aPresContext,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool& aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
TransformReferenceBox& aRefBox)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aData->Count() == 2 || aData->Count() == 3, "Invalid array!");
|
|
|
|
|
2014-08-29 22:47:30 +04:00
|
|
|
Point3D temp;
|
2011-07-23 02:28:07 +04:00
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
temp.x = ProcessTranslatePart(aData->Item(1),
|
|
|
|
aContext, aPresContext, aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
&aRefBox, &TransformReferenceBox::Width);
|
2008-09-13 13:42:11 +04:00
|
|
|
|
2008-09-20 20:52:12 +04:00
|
|
|
/* If we read in a Y component, set it appropriately */
|
|
|
|
if (aData->Count() == 3) {
|
2011-09-27 01:54:45 +04:00
|
|
|
temp.y = ProcessTranslatePart(aData->Item(2),
|
|
|
|
aContext, aPresContext, aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
&aRefBox, &TransformReferenceBox::Height);
|
2008-09-20 20:52:12 +04:00
|
|
|
}
|
2011-09-27 01:54:45 +04:00
|
|
|
aMatrix.Translate(temp);
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
static void
|
|
|
|
ProcessTranslate3D(gfx3DMatrix& aMatrix,
|
|
|
|
const nsCSSValue::Array* aData,
|
|
|
|
nsStyleContext* aContext,
|
|
|
|
nsPresContext* aPresContext,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool& aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
TransformReferenceBox& aRefBox)
|
2011-08-03 07:04:19 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aData->Count() == 4, "Invalid array!");
|
|
|
|
|
2014-08-29 22:47:30 +04:00
|
|
|
Point3D temp;
|
2011-08-03 07:04:19 +04:00
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
temp.x = ProcessTranslatePart(aData->Item(1),
|
|
|
|
aContext, aPresContext, aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
&aRefBox, &TransformReferenceBox::Width);
|
2011-08-03 07:04:19 +04:00
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
temp.y = ProcessTranslatePart(aData->Item(2),
|
|
|
|
aContext, aPresContext, aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
&aRefBox, &TransformReferenceBox::Height);
|
2011-08-03 07:04:19 +04:00
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
temp.z = ProcessTranslatePart(aData->Item(3),
|
|
|
|
aContext, aPresContext, aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
nullptr);
|
2011-08-03 07:04:19 +04:00
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
aMatrix.Translate(temp);
|
2011-08-03 07:04:19 +04:00
|
|
|
}
|
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
/* Helper function to set up a scale matrix. */
|
2011-09-27 01:54:45 +04:00
|
|
|
static void
|
|
|
|
ProcessScaleHelper(gfx3DMatrix& aMatrix,
|
|
|
|
float aXScale,
|
|
|
|
float aYScale,
|
|
|
|
float aZScale)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
2011-09-27 01:54:45 +04:00
|
|
|
aMatrix.Scale(aXScale, aYScale, aZScale);
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Process a scalex function. */
|
2011-09-27 01:54:45 +04:00
|
|
|
static void
|
|
|
|
ProcessScaleX(gfx3DMatrix& aMatrix, const nsCSSValue::Array* aData)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aData->Count() == 2, "Bad array!");
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessScaleHelper(aMatrix, aData->Item(1).GetFloatValue(), 1.0f, 1.0f);
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Process a scaley function. */
|
2011-09-27 01:54:45 +04:00
|
|
|
static void
|
|
|
|
ProcessScaleY(gfx3DMatrix& aMatrix, const nsCSSValue::Array* aData)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aData->Count() == 2, "Bad array!");
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessScaleHelper(aMatrix, 1.0f, aData->Item(1).GetFloatValue(), 1.0f);
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
static void
|
|
|
|
ProcessScaleZ(gfx3DMatrix& aMatrix, const nsCSSValue::Array* aData)
|
2011-08-03 07:04:19 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aData->Count() == 2, "Bad array!");
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessScaleHelper(aMatrix, 1.0f, 1.0f, aData->Item(1).GetFloatValue());
|
2011-08-03 07:04:19 +04:00
|
|
|
}
|
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
static void
|
|
|
|
ProcessScale3D(gfx3DMatrix& aMatrix, const nsCSSValue::Array* aData)
|
2011-08-03 07:04:19 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aData->Count() == 4, "Bad array!");
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessScaleHelper(aMatrix,
|
|
|
|
aData->Item(1).GetFloatValue(),
|
|
|
|
aData->Item(2).GetFloatValue(),
|
|
|
|
aData->Item(3).GetFloatValue());
|
2011-08-03 07:04:19 +04:00
|
|
|
}
|
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
/* Process a scale function. */
|
2011-09-27 01:54:45 +04:00
|
|
|
static void
|
|
|
|
ProcessScale(gfx3DMatrix& aMatrix, const nsCSSValue::Array* aData)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aData->Count() == 2 || aData->Count() == 3, "Bad array!");
|
|
|
|
/* We either have one element or two. If we have one, it's for both X and Y.
|
|
|
|
* Otherwise it's one for each.
|
|
|
|
*/
|
|
|
|
const nsCSSValue& scaleX = aData->Item(1);
|
|
|
|
const nsCSSValue& scaleY = (aData->Count() == 2 ? scaleX :
|
2008-10-20 16:07:09 +04:00
|
|
|
aData->Item(2));
|
2008-09-13 13:42:11 +04:00
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessScaleHelper(aMatrix,
|
|
|
|
scaleX.GetFloatValue(),
|
|
|
|
scaleY.GetFloatValue(),
|
|
|
|
1.0f);
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Helper function that, given a set of angles, constructs the appropriate
|
|
|
|
* skew matrix.
|
|
|
|
*/
|
2011-09-27 01:54:45 +04:00
|
|
|
static void
|
|
|
|
ProcessSkewHelper(gfx3DMatrix& aMatrix, double aXAngle, double aYAngle)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
2011-09-27 01:54:45 +04:00
|
|
|
aMatrix.SkewXY(aXAngle, aYAngle);
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Function that converts a skewx transform into a matrix. */
|
2011-09-27 01:54:45 +04:00
|
|
|
static void
|
|
|
|
ProcessSkewX(gfx3DMatrix& aMatrix, const nsCSSValue::Array* aData)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aData->Count() == 2, "Bad array!");
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessSkewHelper(aMatrix, aData->Item(1).GetAngleValueInRadians(), 0.0);
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Function that converts a skewy transform into a matrix. */
|
2011-09-27 01:54:45 +04:00
|
|
|
static void
|
|
|
|
ProcessSkewY(gfx3DMatrix& aMatrix, const nsCSSValue::Array* aData)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aData->Count() == 2, "Bad array!");
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessSkewHelper(aMatrix, 0.0, aData->Item(1).GetAngleValueInRadians());
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
2012-07-30 17:48:02 +04:00
|
|
|
/* Function that converts a skew transform into a matrix. */
|
|
|
|
static void
|
|
|
|
ProcessSkew(gfx3DMatrix& aMatrix, const nsCSSValue::Array* aData)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aData->Count() == 2 || aData->Count() == 3, "Bad array!");
|
|
|
|
|
|
|
|
double xSkew = aData->Item(1).GetAngleValueInRadians();
|
|
|
|
double ySkew = (aData->Count() == 2
|
|
|
|
? 0.0 : aData->Item(2).GetAngleValueInRadians());
|
|
|
|
|
|
|
|
ProcessSkewHelper(aMatrix, xSkew, ySkew);
|
|
|
|
}
|
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
/* Function that converts a rotate transform into a matrix. */
|
2011-09-27 01:54:45 +04:00
|
|
|
static void
|
|
|
|
ProcessRotateZ(gfx3DMatrix& aMatrix, const nsCSSValue::Array* aData)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aData->Count() == 2, "Invalid array!");
|
2009-11-02 22:36:43 +03:00
|
|
|
double theta = aData->Item(1).GetAngleValueInRadians();
|
2011-09-27 01:54:45 +04:00
|
|
|
aMatrix.RotateZ(theta);
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
static void
|
|
|
|
ProcessRotateX(gfx3DMatrix& aMatrix, const nsCSSValue::Array* aData)
|
2011-08-03 07:04:19 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aData->Count() == 2, "Invalid array!");
|
|
|
|
double theta = aData->Item(1).GetAngleValueInRadians();
|
2011-09-27 01:54:45 +04:00
|
|
|
aMatrix.RotateX(theta);
|
2011-08-03 07:04:19 +04:00
|
|
|
}
|
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
static void
|
|
|
|
ProcessRotateY(gfx3DMatrix& aMatrix, const nsCSSValue::Array* aData)
|
2011-08-03 07:04:19 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aData->Count() == 2, "Invalid array!");
|
|
|
|
double theta = aData->Item(1).GetAngleValueInRadians();
|
2011-09-27 01:54:45 +04:00
|
|
|
aMatrix.RotateY(theta);
|
2011-08-03 07:04:19 +04:00
|
|
|
}
|
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
static void
|
|
|
|
ProcessRotate3D(gfx3DMatrix& aMatrix, const nsCSSValue::Array* aData)
|
2011-08-03 07:04:19 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aData->Count() == 5, "Invalid array!");
|
|
|
|
|
|
|
|
/* We want our matrix to look like this:
|
|
|
|
* | 1 + (1-cos(angle))*(x*x-1) -z*sin(angle)+(1-cos(angle))*x*y y*sin(angle)+(1-cos(angle))*x*z 0 |
|
|
|
|
* | z*sin(angle)+(1-cos(angle))*x*y 1 + (1-cos(angle))*(y*y-1) -x*sin(angle)+(1-cos(angle))*y*z 0 |
|
|
|
|
* | -y*sin(angle)+(1-cos(angle))*x*z x*sin(angle)+(1-cos(angle))*y*z 1 + (1-cos(angle))*(z*z-1) 0 |
|
|
|
|
* | 0 0 0 1 |
|
|
|
|
* (see http://www.w3.org/TR/css3-3d-transforms/#transform-functions)
|
|
|
|
*/
|
2011-12-05 02:53:38 +04:00
|
|
|
|
|
|
|
/* The current spec specifies a matrix that rotates in the wrong direction. For now we just negate
|
|
|
|
* the angle provided to get the correct rotation direction until the spec is updated.
|
|
|
|
* See bug 704468.
|
|
|
|
*/
|
|
|
|
double theta = -aData->Item(4).GetAngleValueInRadians();
|
2011-08-03 07:04:19 +04:00
|
|
|
float cosTheta = FlushToZero(cos(theta));
|
|
|
|
float sinTheta = FlushToZero(sin(theta));
|
|
|
|
|
2014-08-29 22:47:30 +04:00
|
|
|
Point3D vector(aData->Item(1).GetFloatValue(),
|
|
|
|
aData->Item(2).GetFloatValue(),
|
|
|
|
aData->Item(3).GetFloatValue());
|
2011-08-03 07:04:19 +04:00
|
|
|
|
2014-08-19 07:58:17 +04:00
|
|
|
if (!vector.Length()) {
|
2011-09-27 01:54:45 +04:00
|
|
|
return;
|
2011-08-03 07:04:19 +04:00
|
|
|
}
|
2014-08-19 07:58:17 +04:00
|
|
|
vector.Normalize();
|
2011-08-03 07:04:19 +04:00
|
|
|
|
|
|
|
gfx3DMatrix temp;
|
|
|
|
|
|
|
|
/* Create our matrix */
|
2014-08-19 07:58:17 +04:00
|
|
|
temp._11 = 1 + (1 - cosTheta) * (vector.x * vector.x - 1);
|
|
|
|
temp._12 = -vector.z * sinTheta + (1 - cosTheta) * vector.x * vector.y;
|
|
|
|
temp._13 = vector.y * sinTheta + (1 - cosTheta) * vector.x * vector.z;
|
2011-08-03 07:04:19 +04:00
|
|
|
temp._14 = 0.0f;
|
2014-08-19 07:58:17 +04:00
|
|
|
temp._21 = vector.z * sinTheta + (1 - cosTheta) * vector.x * vector.y;
|
|
|
|
temp._22 = 1 + (1 - cosTheta) * (vector.y * vector.y - 1);
|
|
|
|
temp._23 = -vector.x * sinTheta + (1 - cosTheta) * vector.y * vector.z;
|
2011-08-03 07:04:19 +04:00
|
|
|
temp._24 = 0.0f;
|
2014-08-19 07:58:17 +04:00
|
|
|
temp._31 = -vector.y * sinTheta + (1 - cosTheta) * vector.x * vector.z;
|
|
|
|
temp._32 = vector.x * sinTheta + (1 - cosTheta) * vector.y * vector.z;
|
|
|
|
temp._33 = 1 + (1 - cosTheta) * (vector.z * vector.z - 1);
|
2011-08-03 07:04:19 +04:00
|
|
|
temp._34 = 0.0f;
|
|
|
|
temp._41 = 0.0f;
|
|
|
|
temp._42 = 0.0f;
|
|
|
|
temp._43 = 0.0f;
|
|
|
|
temp._44 = 1.0f;
|
2011-09-27 01:54:45 +04:00
|
|
|
|
|
|
|
aMatrix = temp * aMatrix;
|
2011-08-03 07:04:19 +04:00
|
|
|
}
|
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
static void
|
|
|
|
ProcessPerspective(gfx3DMatrix& aMatrix,
|
|
|
|
const nsCSSValue::Array* aData,
|
|
|
|
nsStyleContext *aContext,
|
|
|
|
nsPresContext *aPresContext,
|
2014-05-08 09:35:00 +04:00
|
|
|
bool &aCanStoreInRuleTree)
|
2011-08-03 07:04:22 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aData->Count() == 2, "Invalid array!");
|
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
float depth = ProcessTranslatePart(aData->Item(1), aContext,
|
|
|
|
aPresContext, aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
nullptr);
|
2011-09-27 01:54:45 +04:00
|
|
|
aMatrix.Perspective(depth);
|
2011-08-03 07:04:22 +04:00
|
|
|
}
|
|
|
|
|
2010-07-03 08:18:56 +04:00
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
/**
|
|
|
|
* SetToTransformFunction is essentially a giant switch statement that fans
|
|
|
|
* out to many smaller helper functions.
|
|
|
|
*/
|
2011-09-27 01:54:45 +04:00
|
|
|
static void
|
|
|
|
MatrixForTransformFunction(gfx3DMatrix& aMatrix,
|
|
|
|
const nsCSSValue::Array * aData,
|
|
|
|
nsStyleContext* aContext,
|
|
|
|
nsPresContext* aPresContext,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool& aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
TransformReferenceBox& aRefBox)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aData, "Why did you want to get data from a null array?");
|
2010-07-03 08:18:56 +04:00
|
|
|
// It's OK if aContext and aPresContext are null if the caller already
|
|
|
|
// knows that all length units have been converted to pixels (as
|
2014-06-24 10:29:54 +04:00
|
|
|
// StyleAnimationValue does).
|
2010-07-03 08:18:56 +04:00
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
|
|
|
|
/* Get the keyword for the transform. */
|
2010-07-03 08:18:56 +04:00
|
|
|
switch (TransformFunctionOf(aData)) {
|
2008-09-13 13:42:11 +04:00
|
|
|
case eCSSKeyword_translatex:
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessTranslateX(aMatrix, aData, aContext, aPresContext,
|
2015-04-28 21:55:42 +03:00
|
|
|
aCanStoreInRuleTree, aRefBox);
|
2011-09-27 01:54:45 +04:00
|
|
|
break;
|
2008-09-13 13:42:11 +04:00
|
|
|
case eCSSKeyword_translatey:
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessTranslateY(aMatrix, aData, aContext, aPresContext,
|
2015-04-28 21:55:42 +03:00
|
|
|
aCanStoreInRuleTree, aRefBox);
|
2011-09-27 01:54:45 +04:00
|
|
|
break;
|
2011-08-03 07:04:19 +04:00
|
|
|
case eCSSKeyword_translatez:
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessTranslateZ(aMatrix, aData, aContext, aPresContext,
|
2014-05-08 09:35:00 +04:00
|
|
|
aCanStoreInRuleTree);
|
2011-09-27 01:54:45 +04:00
|
|
|
break;
|
2008-09-13 13:42:11 +04:00
|
|
|
case eCSSKeyword_translate:
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessTranslate(aMatrix, aData, aContext, aPresContext,
|
2015-04-28 21:55:42 +03:00
|
|
|
aCanStoreInRuleTree, aRefBox);
|
2011-09-27 01:54:45 +04:00
|
|
|
break;
|
2011-08-03 07:04:19 +04:00
|
|
|
case eCSSKeyword_translate3d:
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessTranslate3D(aMatrix, aData, aContext, aPresContext,
|
2015-04-28 21:55:42 +03:00
|
|
|
aCanStoreInRuleTree, aRefBox);
|
2011-09-27 01:54:45 +04:00
|
|
|
break;
|
2008-09-13 13:42:11 +04:00
|
|
|
case eCSSKeyword_scalex:
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessScaleX(aMatrix, aData);
|
|
|
|
break;
|
2008-09-13 13:42:11 +04:00
|
|
|
case eCSSKeyword_scaley:
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessScaleY(aMatrix, aData);
|
|
|
|
break;
|
2011-08-03 07:04:19 +04:00
|
|
|
case eCSSKeyword_scalez:
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessScaleZ(aMatrix, aData);
|
|
|
|
break;
|
2008-09-13 13:42:11 +04:00
|
|
|
case eCSSKeyword_scale:
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessScale(aMatrix, aData);
|
|
|
|
break;
|
2011-08-03 07:04:19 +04:00
|
|
|
case eCSSKeyword_scale3d:
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessScale3D(aMatrix, aData);
|
|
|
|
break;
|
2008-09-13 13:42:11 +04:00
|
|
|
case eCSSKeyword_skewx:
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessSkewX(aMatrix, aData);
|
|
|
|
break;
|
2008-09-13 13:42:11 +04:00
|
|
|
case eCSSKeyword_skewy:
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessSkewY(aMatrix, aData);
|
|
|
|
break;
|
2012-07-30 17:48:02 +04:00
|
|
|
case eCSSKeyword_skew:
|
|
|
|
ProcessSkew(aMatrix, aData);
|
|
|
|
break;
|
2011-08-03 07:04:19 +04:00
|
|
|
case eCSSKeyword_rotatex:
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessRotateX(aMatrix, aData);
|
|
|
|
break;
|
2011-08-03 07:04:19 +04:00
|
|
|
case eCSSKeyword_rotatey:
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessRotateY(aMatrix, aData);
|
|
|
|
break;
|
2011-08-03 07:04:19 +04:00
|
|
|
case eCSSKeyword_rotatez:
|
2008-09-13 13:42:11 +04:00
|
|
|
case eCSSKeyword_rotate:
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessRotateZ(aMatrix, aData);
|
|
|
|
break;
|
2011-08-03 07:04:19 +04:00
|
|
|
case eCSSKeyword_rotate3d:
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessRotate3D(aMatrix, aData);
|
|
|
|
break;
|
2008-09-13 13:42:11 +04:00
|
|
|
case eCSSKeyword_matrix:
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessMatrix(aMatrix, aData, aContext, aPresContext,
|
2015-04-28 21:55:42 +03:00
|
|
|
aCanStoreInRuleTree, aRefBox);
|
2011-09-27 01:54:45 +04:00
|
|
|
break;
|
2011-08-03 07:04:19 +04:00
|
|
|
case eCSSKeyword_matrix3d:
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessMatrix3D(aMatrix, aData, aContext, aPresContext,
|
2015-04-28 21:55:42 +03:00
|
|
|
aCanStoreInRuleTree, aRefBox);
|
2011-09-27 01:54:45 +04:00
|
|
|
break;
|
2011-07-23 02:28:07 +04:00
|
|
|
case eCSSKeyword_interpolatematrix:
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessInterpolateMatrix(aMatrix, aData, aContext, aPresContext,
|
2015-04-28 21:55:42 +03:00
|
|
|
aCanStoreInRuleTree, aRefBox);
|
2011-09-27 01:54:45 +04:00
|
|
|
break;
|
2011-08-03 07:04:22 +04:00
|
|
|
case eCSSKeyword_perspective:
|
2011-09-27 01:54:45 +04:00
|
|
|
ProcessPerspective(aMatrix, aData, aContext, aPresContext,
|
2014-05-08 09:35:00 +04:00
|
|
|
aCanStoreInRuleTree);
|
2011-09-27 01:54:45 +04:00
|
|
|
break;
|
2008-09-13 13:42:11 +04:00
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown transform function!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
/**
|
|
|
|
* Return the transform function, as an nsCSSKeyword, for the given
|
|
|
|
* nsCSSValue::Array from a transform list.
|
|
|
|
*/
|
|
|
|
nsCSSKeyword
|
|
|
|
TransformFunctionOf(const nsCSSValue::Array* aData)
|
|
|
|
{
|
2013-05-23 05:08:29 +04:00
|
|
|
MOZ_ASSERT(aData->Item(0).GetUnit() == eCSSUnit_Enumerated);
|
|
|
|
return aData->Item(0).GetKeywordValue();
|
2011-09-27 01:54:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx3DMatrix
|
|
|
|
ReadTransforms(const nsCSSValueList* aList,
|
|
|
|
nsStyleContext* aContext,
|
|
|
|
nsPresContext* aPresContext,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool &aCanStoreInRuleTree,
|
2015-04-28 21:55:42 +03:00
|
|
|
TransformReferenceBox& aRefBox,
|
2011-09-27 01:54:45 +04:00
|
|
|
float aAppUnitsPerMatrixUnit)
|
2010-07-03 08:18:56 +04:00
|
|
|
{
|
2011-07-23 02:28:07 +04:00
|
|
|
gfx3DMatrix result;
|
2010-07-03 08:18:56 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
for (const nsCSSValueList* curr = aList; curr != nullptr; curr = curr->mNext) {
|
2010-07-03 08:18:56 +04:00
|
|
|
const nsCSSValue &currElem = curr->mValue;
|
2015-04-17 04:13:15 +03:00
|
|
|
if (currElem.GetUnit() != eCSSUnit_Function) {
|
|
|
|
NS_ASSERTION(currElem.GetUnit() == eCSSUnit_None &&
|
|
|
|
!aList->mNext,
|
|
|
|
"stream should either be a list of functions or a "
|
|
|
|
"lone None");
|
|
|
|
continue;
|
|
|
|
}
|
2010-07-03 08:18:56 +04:00
|
|
|
NS_ASSERTION(currElem.GetArrayValue()->Count() >= 1,
|
|
|
|
"Incoming function is too short!");
|
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
/* Read in a single transform matrix. */
|
|
|
|
MatrixForTransformFunction(result, currElem.GetArrayValue(), aContext,
|
2015-04-28 21:55:42 +03:00
|
|
|
aPresContext, aCanStoreInRuleTree, aRefBox);
|
2010-07-03 08:18:56 +04:00
|
|
|
}
|
2014-05-08 09:35:00 +04:00
|
|
|
|
|
|
|
float scale = float(nsPresContext::AppUnitsPerCSSPixel()) / aAppUnitsPerMatrixUnit;
|
|
|
|
result.Scale(1/scale, 1/scale, 1/scale);
|
|
|
|
result.ScalePost(scale, scale, scale);
|
2011-07-23 02:28:07 +04:00
|
|
|
|
2011-07-23 02:28:51 +04:00
|
|
|
return result;
|
2010-07-03 08:18:56 +04:00
|
|
|
}
|
|
|
|
|
2011-09-27 01:54:45 +04:00
|
|
|
} // namespace nsStyleTransformMatrix
|