| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Adobe Systems Inc. All rights reserved. | 2 * Copyright (C) 2013 Adobe Systems Inc. All rights reserved. |
| 3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 4 * Copyright (C) 2011 Apple Inc. All rights reserved. | 4 * Copyright (C) 2011 Apple Inc. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #include "config.h" | 28 #include "config.h" |
| 29 #include "core/layout/svg/ReferenceFilterBuilder.h" | 29 #include "core/layout/svg/ReferenceFilterBuilder.h" |
| 30 | 30 |
| 31 #include "core/css/CSSPrimitiveValue.h" | |
| 32 #include "core/css/CSSPrimitiveValueMappings.h" | |
| 33 #include "core/css/StylePropertySet.h" | |
| 34 #include "core/dom/Element.h" | 31 #include "core/dom/Element.h" |
| 35 #include "core/dom/ElementTraversal.h" | |
| 36 #include "core/fetch/DocumentResource.h" | 32 #include "core/fetch/DocumentResource.h" |
| 37 #include "core/layout/LayoutBox.h" | 33 #include "core/layout/LayoutBox.h" |
| 38 #include "core/layout/svg/LayoutSVGResourceFilter.h" | |
| 39 #include "core/svg/SVGDocumentExtensions.h" | 34 #include "core/svg/SVGDocumentExtensions.h" |
| 40 #include "core/svg/SVGFilterPrimitiveStandardAttributes.h" | 35 #include "core/svg/SVGFilterElement.h" |
| 41 #include "core/svg/graphics/filters/SVGFilterBuilder.h" | 36 #include "core/svg/graphics/filters/SVGFilterBuilder.h" |
| 42 #include "platform/graphics/filters/Filter.h" | 37 #include "platform/graphics/filters/Filter.h" |
| 43 #include "platform/graphics/filters/SourceGraphic.h" | 38 #include "platform/graphics/filters/SourceGraphic.h" |
| 44 | 39 |
| 45 namespace blink { | 40 namespace blink { |
| 46 | 41 |
| 47 HashMap<const FilterOperation*, OwnPtr<DocumentResourceReference>>* ReferenceFil
terBuilder::documentResourceReferences = nullptr; | 42 HashMap<const FilterOperation*, OwnPtr<DocumentResourceReference>>* ReferenceFil
terBuilder::documentResourceReferences = nullptr; |
| 48 | 43 |
| 49 DocumentResourceReference* ReferenceFilterBuilder::documentResourceReference(con
st FilterOperation* filterOperation) | 44 DocumentResourceReference* ReferenceFilterBuilder::documentResourceReference(con
st FilterOperation* filterOperation) |
| 50 { | 45 { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 62 } | 57 } |
| 63 | 58 |
| 64 void ReferenceFilterBuilder::clearDocumentResourceReference(const FilterOperatio
n* filterOperation) | 59 void ReferenceFilterBuilder::clearDocumentResourceReference(const FilterOperatio
n* filterOperation) |
| 65 { | 60 { |
| 66 if (!documentResourceReferences) | 61 if (!documentResourceReferences) |
| 67 return; | 62 return; |
| 68 | 63 |
| 69 documentResourceReferences->remove(filterOperation); | 64 documentResourceReferences->remove(filterOperation); |
| 70 } | 65 } |
| 71 | 66 |
| 72 // Returns the color-interpolation-filters property of the element. | |
| 73 static EColorInterpolation colorInterpolationForElement(SVGElement& element, ECo
lorInterpolation parentColorInterpolation) | |
| 74 { | |
| 75 if (const LayoutObject* layoutObject = element.layoutObject()) | |
| 76 return layoutObject->styleRef().svgStyle().colorInterpolationFilters(); | |
| 77 | |
| 78 // No layout has been performed, try to determine the property value | |
| 79 // "manually" (used by external SVG files.) | |
| 80 if (const StylePropertySet* propertySet = element.presentationAttributeStyle
()) { | |
| 81 RefPtrWillBeRawPtr<CSSValue> cssValue = propertySet->getPropertyCSSValue
(CSSPropertyColorInterpolationFilters); | |
| 82 if (cssValue && cssValue->isPrimitiveValue()) { | |
| 83 const CSSPrimitiveValue& primitiveValue = *((CSSPrimitiveValue*)cssV
alue.get()); | |
| 84 return static_cast<EColorInterpolation>(primitiveValue); | |
| 85 } | |
| 86 } | |
| 87 // 'auto' is the default (per Filter Effects), but since the property is | |
| 88 // inherited, propagate the parent's value. | |
| 89 return parentColorInterpolation; | |
| 90 } | |
| 91 | |
| 92 PassRefPtrWillBeRawPtr<Filter> ReferenceFilterBuilder::build(float zoom, Element
* element, FilterEffect* previousEffect, const ReferenceFilterOperation& filterO
peration) | 67 PassRefPtrWillBeRawPtr<Filter> ReferenceFilterBuilder::build(float zoom, Element
* element, FilterEffect* previousEffect, const ReferenceFilterOperation& filterO
peration) |
| 93 { | 68 { |
| 94 TreeScope* treeScope = &element->treeScope(); | 69 TreeScope* treeScope = &element->treeScope(); |
| 95 | 70 |
| 96 if (DocumentResourceReference* documentResourceRef = documentResourceReferen
ce(&filterOperation)) { | 71 if (DocumentResourceReference* documentResourceRef = documentResourceReferen
ce(&filterOperation)) { |
| 97 DocumentResource* cachedSVGDocument = documentResourceRef->document(); | 72 DocumentResource* cachedSVGDocument = documentResourceRef->document(); |
| 98 | 73 |
| 99 // If we have an SVG document, this is an external reference. Otherwise | 74 // If we have an SVG document, this is an external reference. Otherwise |
| 100 // we look up the referenced node in the current document. | 75 // we look up the referenced node in the current document. |
| 101 if (cachedSVGDocument) | 76 if (cachedSVGDocument) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 122 FloatRect referenceBox; | 97 FloatRect referenceBox; |
| 123 if (element->inDocument() && element->layoutObject() && element->layoutObjec
t()->isBoxModelObject()) | 98 if (element->inDocument() && element->layoutObject() && element->layoutObjec
t()->isBoxModelObject()) |
| 124 referenceBox = toLayoutBoxModelObject(element->layoutObject())->borderBo
undingBox(); | 99 referenceBox = toLayoutBoxModelObject(element->layoutObject())->borderBo
undingBox(); |
| 125 referenceBox.scale(1.0f / zoom); | 100 referenceBox.scale(1.0f / zoom); |
| 126 FloatRect filterRegion = SVGLengthContext::resolveRectangle<SVGFilterElement
>(&filterElement, filterElement.filterUnits()->currentValue()->enumValue(), refe
renceBox); | 101 FloatRect filterRegion = SVGLengthContext::resolveRectangle<SVGFilterElement
>(&filterElement, filterElement.filterUnits()->currentValue()->enumValue(), refe
renceBox); |
| 127 bool primitiveBoundingBoxMode = filterElement.primitiveUnits()->currentValue
()->enumValue() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX; | 102 bool primitiveBoundingBoxMode = filterElement.primitiveUnits()->currentValue
()->enumValue() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX; |
| 128 Filter::UnitScaling unitScaling = primitiveBoundingBoxMode ? Filter::Boundin
gBox : Filter::UserSpace; | 103 Filter::UnitScaling unitScaling = primitiveBoundingBoxMode ? Filter::Boundin
gBox : Filter::UserSpace; |
| 129 RefPtrWillBeRawPtr<Filter> result(Filter::create(referenceBox, filterRegion,
zoom, unitScaling)); | 104 RefPtrWillBeRawPtr<Filter> result(Filter::create(referenceBox, filterRegion,
zoom, unitScaling)); |
| 130 if (!previousEffect) | 105 if (!previousEffect) |
| 131 previousEffect = result->sourceGraphic(); | 106 previousEffect = result->sourceGraphic(); |
| 132 RefPtrWillBeRawPtr<SVGFilterBuilder> builder = SVGFilterBuilder::create(prev
iousEffect); | |
| 133 | 107 |
| 134 EColorInterpolation filterColorInterpolation = colorInterpolationForElement(
filterElement, CI_AUTO); | 108 SVGFilterBuilder builder(previousEffect); |
| 109 builder.buildGraph(result.get(), filterElement, referenceBox); |
| 135 | 110 |
| 136 for (SVGElement* element = Traversal<SVGElement>::firstChild(filterElement);
element; element = Traversal<SVGElement>::nextSibling(*element)) { | 111 result->setLastEffect(builder.lastEffect()); |
| 137 if (!element->isFilterEffect()) | |
| 138 continue; | |
| 139 | |
| 140 SVGFilterPrimitiveStandardAttributes* effectElement = static_cast<SVGFil
terPrimitiveStandardAttributes*>(element); | |
| 141 RefPtrWillBeRawPtr<FilterEffect> effect = effectElement->build(builder.g
et(), result.get()); | |
| 142 if (!effect) | |
| 143 continue; | |
| 144 | |
| 145 effectElement->setStandardAttributes(effect.get()); | |
| 146 effect->setEffectBoundaries(SVGLengthContext::resolveRectangle<SVGFilter
PrimitiveStandardAttributes>(effectElement, filterElement.primitiveUnits()->curr
entValue()->enumValue(), referenceBox)); | |
| 147 EColorInterpolation colorInterpolation = colorInterpolationForElement(*e
ffectElement, filterColorInterpolation); | |
| 148 effect->setOperatingColorSpace(colorInterpolation == CI_LINEARRGB ? Colo
rSpaceLinearRGB : ColorSpaceDeviceRGB); | |
| 149 builder->add(AtomicString(effectElement->result()->currentValue()->value
()), effect); | |
| 150 } | |
| 151 result->setLastEffect(builder->lastEffect()); | |
| 152 return result.release(); | 112 return result.release(); |
| 153 } | 113 } |
| 154 | 114 |
| 155 } // namespace blink | 115 } // namespace blink |
| OLD | NEW |