| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 3 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
| 4 * Copyright 2014 The Chromium Authors. All rights reserved. | 4 * Copyright 2014 The Chromium Authors. All rights reserved. |
| 5 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
| 10 * | 10 * |
| 11 * This library is distributed in the hope that it will be useful, | 11 * This library is distributed in the hope that it will be useful, |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 * Library General Public License for more details. | 14 * Library General Public License for more details. |
| 15 * | 15 * |
| 16 * You should have received a copy of the GNU Library General Public License | 16 * You should have received a copy of the GNU Library General Public License |
| 17 * along with this library; see the file COPYING.LIB. If not, write to | 17 * along with this library; see the file COPYING.LIB. If not, write to |
| 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 * Boston, MA 02110-1301, USA. | 19 * Boston, MA 02110-1301, USA. |
| 20 */ | 20 */ |
| 21 | 21 |
| 22 #include "config.h" | 22 #include "config.h" |
| 23 #include "core/layout/svg/LayoutSVGResourcePattern.h" | 23 #include "core/layout/svg/LayoutSVGResourcePattern.h" |
| 24 | 24 |
| 25 #include "core/dom/ElementTraversal.h" | |
| 26 #include "core/layout/svg/SVGLayoutSupport.h" | 25 #include "core/layout/svg/SVGLayoutSupport.h" |
| 26 #include "core/layout/svg/SVGResources.h" |
| 27 #include "core/paint/SVGPaintContext.h" | 27 #include "core/paint/SVGPaintContext.h" |
| 28 #include "core/paint/TransformRecorder.h" | 28 #include "core/paint/TransformRecorder.h" |
| 29 #include "core/svg/SVGFitToViewBox.h" | 29 #include "core/svg/SVGFitToViewBox.h" |
| 30 #include "core/svg/SVGPatternElement.h" | 30 #include "core/svg/SVGPatternElement.h" |
| 31 #include "platform/graphics/GraphicsContext.h" | 31 #include "platform/graphics/GraphicsContext.h" |
| 32 #include "platform/graphics/paint/DisplayItemList.h" | 32 #include "platform/graphics/paint/DisplayItemList.h" |
| 33 #include "platform/graphics/paint/SkPictureBuilder.h" | 33 #include "platform/graphics/paint/SkPictureBuilder.h" |
| 34 #include "third_party/skia/include/core/SkPicture.h" | 34 #include "third_party/skia/include/core/SkPicture.h" |
| 35 | 35 |
| 36 namespace blink { | 36 namespace blink { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 | 148 |
| 149 PatternData* patternData = patternForLayoutObject(object); | 149 PatternData* patternData = patternForLayoutObject(object); |
| 150 if (!patternData || !patternData->pattern) | 150 if (!patternData || !patternData->pattern) |
| 151 return SVGPaintServer::invalid(); | 151 return SVGPaintServer::invalid(); |
| 152 | 152 |
| 153 patternData->pattern->setPatternSpaceTransform(patternData->transform); | 153 patternData->pattern->setPatternSpaceTransform(patternData->transform); |
| 154 | 154 |
| 155 return SVGPaintServer(patternData->pattern); | 155 return SVGPaintServer(patternData->pattern); |
| 156 } | 156 } |
| 157 | 157 |
| 158 const LayoutSVGResourceContainer* LayoutSVGResourcePattern::resolveContentElemen
t() const |
| 159 { |
| 160 ASSERT(attributes().patternContentElement()); |
| 161 LayoutSVGResourceContainer* expectedLayoutObject = |
| 162 toLayoutSVGResourceContainer(attributes().patternContentElement()->layou
tObject()); |
| 163 // No content inheritance - avoid walking the inheritance chain. |
| 164 if (this == expectedLayoutObject) |
| 165 return this; |
| 166 // Walk the inheritance chain on the LayoutObject-side. If we reach the |
| 167 // expected LayoutObject, all is fine. If we don't, there's a cycle that |
| 168 // the cycle resolver did break, and the resource will be content-less. |
| 169 const LayoutSVGResourceContainer* contentLayoutObject = this; |
| 170 while (SVGResources* resources = SVGResourcesCache::cachedResourcesForLayout
Object(contentLayoutObject)) { |
| 171 LayoutSVGResourceContainer* linkedResource = resources->linkedResource()
; |
| 172 if (!linkedResource) |
| 173 break; |
| 174 if (linkedResource == expectedLayoutObject) |
| 175 return expectedLayoutObject; |
| 176 contentLayoutObject = linkedResource; |
| 177 } |
| 178 // There was a cycle, just use this resource as the "content resource" even |
| 179 // though it will be empty (have no children). |
| 180 return this; |
| 181 } |
| 182 |
| 158 PassRefPtr<const SkPicture> LayoutSVGResourcePattern::asPicture(const FloatRect&
tileBounds, | 183 PassRefPtr<const SkPicture> LayoutSVGResourcePattern::asPicture(const FloatRect&
tileBounds, |
| 159 const AffineTransform& tileTransform) const | 184 const AffineTransform& tileTransform) const |
| 160 { | 185 { |
| 161 ASSERT(!m_shouldCollectPatternAttributes); | 186 ASSERT(!m_shouldCollectPatternAttributes); |
| 162 | 187 |
| 163 AffineTransform contentTransform; | 188 AffineTransform contentTransform; |
| 164 if (attributes().patternContentUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECT
BOUNDINGBOX) | 189 if (attributes().patternContentUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECT
BOUNDINGBOX) |
| 165 contentTransform = tileTransform; | 190 contentTransform = tileTransform; |
| 166 | 191 |
| 167 FloatRect bounds(FloatPoint(), tileBounds.size()); | 192 FloatRect bounds(FloatPoint(), tileBounds.size()); |
| 168 SkPictureBuilder pictureBuilder(bounds); | 193 SkPictureBuilder pictureBuilder(bounds); |
| 169 | 194 |
| 170 ASSERT(attributes().patternContentElement()); | 195 const LayoutSVGResourceContainer* patternLayoutObject = resolveContentElemen
t(); |
| 171 LayoutSVGResourceContainer* patternLayoutObject = | 196 ASSERT(patternLayoutObject && !patternLayoutObject->needsLayout()); |
| 172 toLayoutSVGResourceContainer(attributes().patternContentElement()->layou
tObject()); | |
| 173 ASSERT(patternLayoutObject); | |
| 174 ASSERT(!patternLayoutObject->needsLayout()); | |
| 175 | 197 |
| 176 SubtreeContentTransformScope contentTransformScope(contentTransform); | 198 SubtreeContentTransformScope contentTransformScope(contentTransform); |
| 177 | 199 |
| 178 { | 200 { |
| 179 TransformRecorder transformRecorder(pictureBuilder.context(), *patternLa
youtObject, tileTransform); | 201 TransformRecorder transformRecorder(pictureBuilder.context(), *patternLa
youtObject, tileTransform); |
| 180 for (LayoutObject* child = patternLayoutObject->firstChild(); child; chi
ld = child->nextSibling()) | 202 for (LayoutObject* child = patternLayoutObject->firstChild(); child; chi
ld = child->nextSibling()) |
| 181 SVGPaintContext::paintSubtree(&pictureBuilder.context(), child); | 203 SVGPaintContext::paintSubtree(&pictureBuilder.context(), child); |
| 182 } | 204 } |
| 183 | 205 |
| 184 return pictureBuilder.endRecording(); | 206 return pictureBuilder.endRecording(); |
| 185 } | 207 } |
| 186 | 208 |
| 187 } | 209 } |
| OLD | NEW |