Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: third_party/WebKit/Source/core/svg/SVGPath.cpp

Issue 1425913004: [SVG] Shared <use> path geometry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde .org> 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde .org>
3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
5 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 5 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 14 matching lines...) Expand all
25 25
26 #include "bindings/core/v8/ExceptionState.h" 26 #include "bindings/core/v8/ExceptionState.h"
27 #include "core/SVGNames.h" 27 #include "core/SVGNames.h"
28 #include "core/svg/SVGAnimationElement.h" 28 #include "core/svg/SVGAnimationElement.h"
29 #include "core/svg/SVGPathBlender.h" 29 #include "core/svg/SVGPathBlender.h"
30 #include "core/svg/SVGPathByteStream.h" 30 #include "core/svg/SVGPathByteStream.h"
31 #include "core/svg/SVGPathByteStreamBuilder.h" 31 #include "core/svg/SVGPathByteStreamBuilder.h"
32 #include "core/svg/SVGPathByteStreamSource.h" 32 #include "core/svg/SVGPathByteStreamSource.h"
33 #include "core/svg/SVGPathParser.h" 33 #include "core/svg/SVGPathParser.h"
34 #include "core/svg/SVGPathUtilities.h" 34 #include "core/svg/SVGPathUtilities.h"
35 #include "platform/graphics/Path.h"
35 36
36 namespace blink { 37 namespace blink {
37 38
38 SVGPath::SVGPath() 39 SVGPath::SVGPath()
39 : SVGPropertyBase(classType()) 40 : SVGPropertyBase(classType())
40 { 41 {
41 } 42 }
42 43
43 SVGPath::SVGPath(PassOwnPtr<SVGPathByteStream> byteStream) 44 SVGPath::SVGPath(PassOwnPtr<SVGPathByteStream> byteStream)
44 : SVGPropertyBase(classType()) 45 : SVGPropertyBase(classType())
45 , m_byteStream(byteStream) 46 , m_byteStream(byteStream)
46 { 47 {
47 } 48 }
48 49
49 SVGPath::~SVGPath() 50 SVGPath::~SVGPath()
50 { 51 {
51 } 52 }
52 53
54 const Path& SVGPath::path() const
55 {
56 if (!m_cachedPath) {
57 m_cachedPath = adoptPtr(new Path);
58 buildPathFromByteStream(byteStream(), *m_cachedPath);
59 }
60
61 return *m_cachedPath;
62 }
63
53 PassRefPtrWillBeRawPtr<SVGPath> SVGPath::clone() const 64 PassRefPtrWillBeRawPtr<SVGPath> SVGPath::clone() const
54 { 65 {
55 return adoptRefWillBeNoop(new SVGPath(byteStream().copy())); 66 return adoptRefWillBeNoop(new SVGPath(byteStream().copy()));
56 } 67 }
57 68
58 PassRefPtrWillBeRawPtr<SVGPropertyBase> SVGPath::cloneForAnimation(const String& value) const 69 PassRefPtrWillBeRawPtr<SVGPropertyBase> SVGPath::cloneForAnimation(const String& value) const
59 { 70 {
60 RefPtrWillBeRawPtr<SVGPath> svgPath = SVGPath::create(); 71 RefPtrWillBeRawPtr<SVGPath> svgPath = SVGPath::create();
61 svgPath->setValueAsString(value, IGNORE_EXCEPTION); 72 svgPath->setValueAsString(value, IGNORE_EXCEPTION);
62 return svgPath; 73 return svgPath;
63 } 74 }
64 75
76 SVGPathByteStream& SVGPath::ensureByteStream()
77 {
78 if (!m_byteStream)
79 m_byteStream = SVGPathByteStream::create();
80
81 return *m_byteStream.get();
82 }
83
84 void SVGPath::byteStreamWillChange()
85 {
86 m_cachedPath.clear();
87 }
88
65 const SVGPathByteStream& SVGPath::byteStream() const 89 const SVGPathByteStream& SVGPath::byteStream() const
66 { 90 {
67 return const_cast<SVGPath*>(this)->mutableByteStream(); 91 return const_cast<SVGPath*>(this)->ensureByteStream();
68 } 92 }
69 93
70 SVGPathByteStream& SVGPath::mutableByteStream() 94 SVGPathByteStream& SVGPath::mutableByteStream()
71 { 95 {
72 if (!m_byteStream) 96 byteStreamWillChange();
73 m_byteStream = SVGPathByteStream::create(); 97 return ensureByteStream();
74 return *m_byteStream.get();
75 } 98 }
76 99
77 String SVGPath::valueAsString() const 100 String SVGPath::valueAsString() const
78 { 101 {
79 String string; 102 String string;
80 buildStringFromByteStream(byteStream(), string, UnalteredParsing); 103 buildStringFromByteStream(byteStream(), string, UnalteredParsing);
81 return string; 104 return string;
82 } 105 }
83 106
84 void SVGPath::setValueAsString(const String& string, ExceptionState& exceptionSt ate) 107 void SVGPath::setValueAsString(const String& string, ExceptionState& exceptionSt ate)
(...skipping 26 matching lines...) Expand all
111 134
112 // If no 'to' value is given, nothing to animate. 135 // If no 'to' value is given, nothing to animate.
113 if (!toStream.size()) 136 if (!toStream.size())
114 return; 137 return;
115 138
116 if (isToAnimation) { 139 if (isToAnimation) {
117 copy = byteStream().copy(); 140 copy = byteStream().copy();
118 fromStream = copy.get(); 141 fromStream = copy.get();
119 } 142 }
120 143
144 byteStreamWillChange();
145
121 // If the 'from' value is given and it's length doesn't match the 'to' value list length, fallback to a discrete animation. 146 // If the 'from' value is given and it's length doesn't match the 'to' value list length, fallback to a discrete animation.
122 if (fromStream->size() != toStream.size() && fromStream->size()) { 147 if (fromStream->size() != toStream.size() && fromStream->size()) {
123 if (percentage < 0.5) { 148 if (percentage < 0.5) {
124 if (!isToAnimation) { 149 if (!isToAnimation) {
125 m_byteStream = fromStream->copy(); 150 m_byteStream = fromStream->copy();
126 return; 151 return;
127 } 152 }
128 } else { 153 } else {
129 m_byteStream = toStream.copy(); 154 m_byteStream = toStream.copy();
130 return; 155 return;
(...skipping 20 matching lines...) Expand all
151 addToSVGPathByteStream(*m_byteStream, toAtEndOfDuration->byteStream(), r epeatCount); 176 addToSVGPathByteStream(*m_byteStream, toAtEndOfDuration->byteStream(), r epeatCount);
152 } 177 }
153 178
154 float SVGPath::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> to, SVG Element*) 179 float SVGPath::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> to, SVG Element*)
155 { 180 {
156 // FIXME: Support paced animations. 181 // FIXME: Support paced animations.
157 return -1; 182 return -1;
158 } 183 }
159 184
160 } 185 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698