diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-04-10 09:28:39 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-04-10 09:28:39 +0000 |
commit | 32761a6cee1d0dee366b885b7b9c777e67885688 (patch) | |
tree | d6bec92bebfb216f4126356e55518842c2f476a1 /Source/WebCore/css/TransformFunctions.cpp | |
parent | a4e969f4965059196ca948db781e52f7cfebf19e (diff) | |
download | WebKitGtk-tarball-32761a6cee1d0dee366b885b7b9c777e67885688.tar.gz |
webkitgtk-2.4.11webkitgtk-2.4.11
Diffstat (limited to 'Source/WebCore/css/TransformFunctions.cpp')
-rw-r--r-- | Source/WebCore/css/TransformFunctions.cpp | 209 |
1 files changed, 106 insertions, 103 deletions
diff --git a/Source/WebCore/css/TransformFunctions.cpp b/Source/WebCore/css/TransformFunctions.cpp index 1edbc26d6..b24e5f95c 100644 --- a/Source/WebCore/css/TransformFunctions.cpp +++ b/Source/WebCore/css/TransformFunctions.cpp @@ -76,30 +76,33 @@ static TransformOperation::OperationType transformOperationType(WebKitCSSTransfo return TransformOperation::NONE; } -Length convertToFloatLength(const CSSPrimitiveValue* primitiveValue, const CSSToLengthConversionData& conversionData) +static Length convertToFloatLength(const CSSPrimitiveValue* primitiveValue, const RenderStyle* style, const RenderStyle* rootStyle, double multiplier) { - return primitiveValue ? primitiveValue->convertToLength<FixedFloatConversion | PercentConversion | CalculatedConversion>(conversionData) : Length(Undefined); + return primitiveValue ? primitiveValue->convertToLength<FixedFloatConversion | PercentConversion | CalculatedConversion | FractionConversion | ViewportPercentageConversion>(style, rootStyle, multiplier) : Length(Undefined); } -bool transformsForValue(const CSSValue& value, const CSSToLengthConversionData& conversionData, TransformOperations& outOperations) +bool transformsForValue(const RenderStyle* style, const RenderStyle* rootStyle, CSSValue* value, TransformOperations& outOperations) { - if (!is<CSSValueList>(value)) { + if (!value || !value->isValueList()) { outOperations.clear(); return false; } + float zoomFactor = style ? style->effectiveZoom() : 1; TransformOperations operations; - for (auto& currentValue : downcast<CSSValueList>(value)) { - if (!is<WebKitCSSTransformValue>(currentValue.get())) + for (CSSValueListIterator i = value; i.hasMore(); i.advance()) { + CSSValue* currValue = i.value(); + + if (!currValue->isWebKitCSSTransformValue()) continue; - auto& transformValue = downcast<WebKitCSSTransformValue>(currentValue.get()); - if (!transformValue.length()) + WebKitCSSTransformValue* transformValue = toWebKitCSSTransformValue(i.value()); + if (!transformValue->length()) continue; bool haveNonPrimitiveValue = false; - for (unsigned j = 0; j < transformValue.length(); ++j) { - if (!is<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(j))) { + for (unsigned j = 0; j < transformValue->length(); ++j) { + if (!transformValue->itemWithoutBoundsCheck(j)->isPrimitiveValue()) { haveNonPrimitiveValue = true; break; } @@ -107,27 +110,27 @@ bool transformsForValue(const CSSValue& value, const CSSToLengthConversionData& if (haveNonPrimitiveValue) continue; - auto& firstValue = downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(0)); + CSSPrimitiveValue* firstValue = toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(0)); - switch (transformValue.operationType()) { + switch (transformValue->operationType()) { case WebKitCSSTransformValue::ScaleTransformOperation: case WebKitCSSTransformValue::ScaleXTransformOperation: case WebKitCSSTransformValue::ScaleYTransformOperation: { double sx = 1.0; double sy = 1.0; - if (transformValue.operationType() == WebKitCSSTransformValue::ScaleYTransformOperation) - sy = firstValue.getDoubleValue(); + if (transformValue->operationType() == WebKitCSSTransformValue::ScaleYTransformOperation) + sy = firstValue->getDoubleValue(); else { - sx = firstValue.getDoubleValue(); - if (transformValue.operationType() != WebKitCSSTransformValue::ScaleXTransformOperation) { - if (transformValue.length() > 1) { - auto& secondValue = downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(1)); - sy = secondValue.getDoubleValue(); + sx = firstValue->getDoubleValue(); + if (transformValue->operationType() != WebKitCSSTransformValue::ScaleXTransformOperation) { + if (transformValue->length() > 1) { + CSSPrimitiveValue* secondValue = toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(1)); + sy = secondValue->getDoubleValue(); } else sy = sx; } } - operations.operations().append(ScaleTransformOperation::create(sx, sy, 1.0, transformOperationType(transformValue.operationType()))); + operations.operations().append(ScaleTransformOperation::create(sx, sy, 1.0, transformOperationType(transformValue->operationType()))); break; } case WebKitCSSTransformValue::ScaleZTransformOperation: @@ -135,25 +138,25 @@ bool transformsForValue(const CSSValue& value, const CSSToLengthConversionData& double sx = 1.0; double sy = 1.0; double sz = 1.0; - if (transformValue.operationType() == WebKitCSSTransformValue::ScaleZTransformOperation) - sz = firstValue.getDoubleValue(); - else if (transformValue.operationType() == WebKitCSSTransformValue::ScaleYTransformOperation) - sy = firstValue.getDoubleValue(); + if (transformValue->operationType() == WebKitCSSTransformValue::ScaleZTransformOperation) + sz = firstValue->getDoubleValue(); + else if (transformValue->operationType() == WebKitCSSTransformValue::ScaleYTransformOperation) + sy = firstValue->getDoubleValue(); else { - sx = firstValue.getDoubleValue(); - if (transformValue.operationType() != WebKitCSSTransformValue::ScaleXTransformOperation) { - if (transformValue.length() > 2) { - auto& thirdValue = downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(2)); - sz = thirdValue.getDoubleValue(); + sx = firstValue->getDoubleValue(); + if (transformValue->operationType() != WebKitCSSTransformValue::ScaleXTransformOperation) { + if (transformValue->length() > 2) { + CSSPrimitiveValue* thirdValue = toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(2)); + sz = thirdValue->getDoubleValue(); } - if (transformValue.length() > 1) { - auto& secondValue = downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(1)); - sy = secondValue.getDoubleValue(); + if (transformValue->length() > 1) { + CSSPrimitiveValue* secondValue = toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(1)); + sy = secondValue->getDoubleValue(); } else sy = sx; } } - operations.operations().append(ScaleTransformOperation::create(sx, sy, sz, transformOperationType(transformValue.operationType()))); + operations.operations().append(ScaleTransformOperation::create(sx, sy, sz, transformOperationType(transformValue->operationType()))); break; } case WebKitCSSTransformValue::TranslateTransformOperation: @@ -161,14 +164,14 @@ bool transformsForValue(const CSSValue& value, const CSSToLengthConversionData& case WebKitCSSTransformValue::TranslateYTransformOperation: { Length tx = Length(0, Fixed); Length ty = Length(0, Fixed); - if (transformValue.operationType() == WebKitCSSTransformValue::TranslateYTransformOperation) - ty = convertToFloatLength(&firstValue, conversionData); + if (transformValue->operationType() == WebKitCSSTransformValue::TranslateYTransformOperation) + ty = convertToFloatLength(firstValue, style, rootStyle, zoomFactor); else { - tx = convertToFloatLength(&firstValue, conversionData); - if (transformValue.operationType() != WebKitCSSTransformValue::TranslateXTransformOperation) { - if (transformValue.length() > 1) { - auto& secondValue = downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(1)); - ty = convertToFloatLength(&secondValue, conversionData); + tx = convertToFloatLength(firstValue, style, rootStyle, zoomFactor); + if (transformValue->operationType() != WebKitCSSTransformValue::TranslateXTransformOperation) { + if (transformValue->length() > 1) { + CSSPrimitiveValue* secondValue = toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(1)); + ty = convertToFloatLength(secondValue, style, rootStyle, zoomFactor); } } } @@ -176,7 +179,7 @@ bool transformsForValue(const CSSValue& value, const CSSToLengthConversionData& if (tx.isUndefined() || ty.isUndefined()) return false; - operations.operations().append(TranslateTransformOperation::create(tx, ty, Length(0, Fixed), transformOperationType(transformValue.operationType()))); + operations.operations().append(TranslateTransformOperation::create(tx, ty, Length(0, Fixed), transformOperationType(transformValue->operationType()))); break; } case WebKitCSSTransformValue::TranslateZTransformOperation: @@ -184,20 +187,20 @@ bool transformsForValue(const CSSValue& value, const CSSToLengthConversionData& Length tx = Length(0, Fixed); Length ty = Length(0, Fixed); Length tz = Length(0, Fixed); - if (transformValue.operationType() == WebKitCSSTransformValue::TranslateZTransformOperation) - tz = convertToFloatLength(&firstValue, conversionData); - else if (transformValue.operationType() == WebKitCSSTransformValue::TranslateYTransformOperation) - ty = convertToFloatLength(&firstValue, conversionData); + if (transformValue->operationType() == WebKitCSSTransformValue::TranslateZTransformOperation) + tz = convertToFloatLength(firstValue, style, rootStyle, zoomFactor); + else if (transformValue->operationType() == WebKitCSSTransformValue::TranslateYTransformOperation) + ty = convertToFloatLength(firstValue, style, rootStyle, zoomFactor); else { - tx = convertToFloatLength(&firstValue, conversionData); - if (transformValue.operationType() != WebKitCSSTransformValue::TranslateXTransformOperation) { - if (transformValue.length() > 2) { - auto& thirdValue = downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(2)); - tz = convertToFloatLength(&thirdValue, conversionData); + tx = convertToFloatLength(firstValue, style, rootStyle, zoomFactor); + if (transformValue->operationType() != WebKitCSSTransformValue::TranslateXTransformOperation) { + if (transformValue->length() > 2) { + CSSPrimitiveValue* thirdValue = toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(2)); + tz = convertToFloatLength(thirdValue, style, rootStyle, zoomFactor); } - if (transformValue.length() > 1) { - auto& secondValue = downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(1)); - ty = convertToFloatLength(&secondValue, conversionData); + if (transformValue->length() > 1) { + CSSPrimitiveValue* secondValue = toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(1)); + ty = convertToFloatLength(secondValue, style, rootStyle, zoomFactor); } } } @@ -205,12 +208,12 @@ bool transformsForValue(const CSSValue& value, const CSSToLengthConversionData& if (tx.isUndefined() || ty.isUndefined() || tz.isUndefined()) return false; - operations.operations().append(TranslateTransformOperation::create(tx, ty, tz, transformOperationType(transformValue.operationType()))); + operations.operations().append(TranslateTransformOperation::create(tx, ty, tz, transformOperationType(transformValue->operationType()))); break; } case WebKitCSSTransformValue::RotateTransformOperation: { - double angle = firstValue.computeDegrees(); - operations.operations().append(RotateTransformOperation::create(0, 0, 1, angle, transformOperationType(transformValue.operationType()))); + double angle = firstValue->computeDegrees(); + operations.operations().append(RotateTransformOperation::create(0, 0, 1, angle, transformOperationType(transformValue->operationType()))); break; } case WebKitCSSTransformValue::RotateXTransformOperation: @@ -219,28 +222,28 @@ bool transformsForValue(const CSSValue& value, const CSSToLengthConversionData& double x = 0; double y = 0; double z = 0; - double angle = firstValue.computeDegrees(); + double angle = firstValue->computeDegrees(); - if (transformValue.operationType() == WebKitCSSTransformValue::RotateXTransformOperation) + if (transformValue->operationType() == WebKitCSSTransformValue::RotateXTransformOperation) x = 1; - else if (transformValue.operationType() == WebKitCSSTransformValue::RotateYTransformOperation) + else if (transformValue->operationType() == WebKitCSSTransformValue::RotateYTransformOperation) y = 1; else z = 1; - operations.operations().append(RotateTransformOperation::create(x, y, z, angle, transformOperationType(transformValue.operationType()))); + operations.operations().append(RotateTransformOperation::create(x, y, z, angle, transformOperationType(transformValue->operationType()))); break; } case WebKitCSSTransformValue::Rotate3DTransformOperation: { - if (transformValue.length() < 4) + if (transformValue->length() < 4) break; - auto& secondValue = downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(1)); - auto& thirdValue = downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(2)); - auto& fourthValue = downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(3)); - double x = firstValue.getDoubleValue(); - double y = secondValue.getDoubleValue(); - double z = thirdValue.getDoubleValue(); - double angle = fourthValue.computeDegrees(); - operations.operations().append(RotateTransformOperation::create(x, y, z, angle, transformOperationType(transformValue.operationType()))); + CSSPrimitiveValue* secondValue = toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(1)); + CSSPrimitiveValue* thirdValue = toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(2)); + CSSPrimitiveValue* fourthValue = toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(3)); + double x = firstValue->getDoubleValue(); + double y = secondValue->getDoubleValue(); + double z = thirdValue->getDoubleValue(); + double angle = fourthValue->computeDegrees(); + operations.operations().append(RotateTransformOperation::create(x, y, z, angle, transformOperationType(transformValue->operationType()))); break; } case WebKitCSSTransformValue::SkewTransformOperation: @@ -248,62 +251,62 @@ bool transformsForValue(const CSSValue& value, const CSSToLengthConversionData& case WebKitCSSTransformValue::SkewYTransformOperation: { double angleX = 0; double angleY = 0; - double angle = firstValue.computeDegrees(); - if (transformValue.operationType() == WebKitCSSTransformValue::SkewYTransformOperation) + double angle = firstValue->computeDegrees(); + if (transformValue->operationType() == WebKitCSSTransformValue::SkewYTransformOperation) angleY = angle; else { angleX = angle; - if (transformValue.operationType() == WebKitCSSTransformValue::SkewTransformOperation) { - if (transformValue.length() > 1) { - auto& secondValue = downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(1)); - angleY = secondValue.computeDegrees(); + if (transformValue->operationType() == WebKitCSSTransformValue::SkewTransformOperation) { + if (transformValue->length() > 1) { + CSSPrimitiveValue* secondValue = toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(1)); + angleY = secondValue->computeDegrees(); } } } - operations.operations().append(SkewTransformOperation::create(angleX, angleY, transformOperationType(transformValue.operationType()))); + operations.operations().append(SkewTransformOperation::create(angleX, angleY, transformOperationType(transformValue->operationType()))); break; } case WebKitCSSTransformValue::MatrixTransformOperation: { - if (transformValue.length() < 6) + if (transformValue->length() < 6) break; - double a = firstValue.getDoubleValue(); - double b = downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(1)).getDoubleValue(); - double c = downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(2)).getDoubleValue(); - double d = downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(3)).getDoubleValue(); - double e = conversionData.zoom() * downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(4)).getDoubleValue(); - double f = conversionData.zoom() * downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(5)).getDoubleValue(); + double a = firstValue->getDoubleValue(); + double b = toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(1))->getDoubleValue(); + double c = toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(2))->getDoubleValue(); + double d = toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(3))->getDoubleValue(); + double e = zoomFactor * toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(4))->getDoubleValue(); + double f = zoomFactor * toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(5))->getDoubleValue(); operations.operations().append(MatrixTransformOperation::create(a, b, c, d, e, f)); break; } case WebKitCSSTransformValue::Matrix3DTransformOperation: { - if (transformValue.length() < 16) + if (transformValue->length() < 16) break; - TransformationMatrix matrix(downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(0)).getDoubleValue(), - downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(1)).getDoubleValue(), - downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(2)).getDoubleValue(), - downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(3)).getDoubleValue(), - downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(4)).getDoubleValue(), - downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(5)).getDoubleValue(), - downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(6)).getDoubleValue(), - downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(7)).getDoubleValue(), - downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(8)).getDoubleValue(), - downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(9)).getDoubleValue(), - downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(10)).getDoubleValue(), - downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(11)).getDoubleValue(), - conversionData.zoom() * downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(12)).getDoubleValue(), - conversionData.zoom() * downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(13)).getDoubleValue(), - downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(14)).getDoubleValue(), - downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(15)).getDoubleValue()); + TransformationMatrix matrix(toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(0))->getDoubleValue(), + toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(1))->getDoubleValue(), + toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(2))->getDoubleValue(), + toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(3))->getDoubleValue(), + toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(4))->getDoubleValue(), + toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(5))->getDoubleValue(), + toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(6))->getDoubleValue(), + toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(7))->getDoubleValue(), + toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(8))->getDoubleValue(), + toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(9))->getDoubleValue(), + toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(10))->getDoubleValue(), + toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(11))->getDoubleValue(), + zoomFactor * toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(12))->getDoubleValue(), + zoomFactor * toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(13))->getDoubleValue(), + toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(14))->getDoubleValue(), + toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(15))->getDoubleValue()); operations.operations().append(Matrix3DTransformOperation::create(matrix)); break; } case WebKitCSSTransformValue::PerspectiveTransformOperation: { Length p = Length(0, Fixed); - if (firstValue.isLength()) - p = convertToFloatLength(&firstValue, conversionData); + if (firstValue->isLength()) + p = convertToFloatLength(firstValue, style, rootStyle, zoomFactor); else { // This is a quirk that should go away when 3d transforms are finalized. - double val = firstValue.getDoubleValue(); + double val = firstValue->getDoubleValue(); p = val >= 0 ? Length(clampToPositiveInteger(val), Fixed) : Length(Undefined); } |