| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2010 Rob Buis <buis@kde.org> | 2 * Copyright (C) 2007, 2010 Rob Buis <buis@kde.org> |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 SVGViewSpec::SVGViewSpec(SVGSVGElement* contextElement) | 32 SVGViewSpec::SVGViewSpec(SVGSVGElement* contextElement) |
| 33 // Note: addToPropertyMap is not needed, as SVGViewSpec do not correspond to | 33 // Note: addToPropertyMap is not needed, as SVGViewSpec do not correspond to |
| 34 // an element. We make tear-offs' contextElement the target element of | 34 // an element. We make tear-offs' contextElement the target element of |
| 35 // SVGViewSpec. This contextElement will be only used for keeping this | 35 // SVGViewSpec. This contextElement will be only used for keeping this |
| 36 // alive from the tearoff. SVGSVGElement holds a strong-ref to this | 36 // alive from the tearoff. SVGSVGElement holds a strong-ref to this |
| 37 // SVGViewSpec, so this is kept alive as: | 37 // SVGViewSpec, so this is kept alive as: |
| 38 // AnimatedProperty tearoff -(contextElement)-> SVGSVGElement -(RefPtr)-> | 38 // AnimatedProperty tearoff -(contextElement)-> SVGSVGElement -(RefPtr)-> |
| 39 // SVGViewSpec. | 39 // SVGViewSpec. |
| 40 : SVGFitToViewBox(contextElement, PropertyMapPolicySkip), | 40 : SVGFitToViewBox(contextElement, PropertyMapPolicySkip), |
| 41 m_contextElement(this, contextElement), | 41 m_contextElement(contextElement), |
| 42 m_transform(SVGAnimatedTransformList::create(contextElement, | 42 m_transform(SVGAnimatedTransformList::create(contextElement, |
| 43 SVGNames::transformAttr)) { | 43 SVGNames::transformAttr)) { |
| 44 ASSERT(m_contextElement); | 44 ASSERT(m_contextElement); |
| 45 | 45 |
| 46 viewBox()->setReadOnly(); | 46 viewBox()->setReadOnly(); |
| 47 preserveAspectRatio()->setReadOnly(); | 47 preserveAspectRatio()->setReadOnly(); |
| 48 m_transform->setReadOnly(); | 48 m_transform->setReadOnly(); |
| 49 // Note: addToPropertyMap is not needed, as SVGViewSpec do not correspond to | 49 // Note: addToPropertyMap is not needed, as SVGViewSpec do not correspond to |
| 50 // an element. | 50 // an element. |
| 51 } | 51 } |
| 52 | 52 |
| 53 DEFINE_TRACE(SVGViewSpec) { | 53 DEFINE_TRACE(SVGViewSpec) { |
| 54 visitor->trace(m_contextElement); | 54 visitor->trace(m_contextElement); |
| 55 visitor->trace(m_transform); | 55 visitor->trace(m_transform); |
| 56 SVGFitToViewBox::trace(visitor); | 56 SVGFitToViewBox::trace(visitor); |
| 57 } | 57 } |
| 58 | 58 |
| 59 DEFINE_TRACE_WRAPPERS(SVGViewSpec) { | |
| 60 visitor->traceWrappers(m_contextElement); | |
| 61 } | |
| 62 | |
| 63 bool SVGViewSpec::parseViewSpec(const String& spec) { | 59 bool SVGViewSpec::parseViewSpec(const String& spec) { |
| 64 if (spec.isEmpty() || !m_contextElement) | 60 if (spec.isEmpty() || !m_contextElement) |
| 65 return false; | 61 return false; |
| 66 if (spec.is8Bit()) { | 62 if (spec.is8Bit()) { |
| 67 const LChar* ptr = spec.characters8(); | 63 const LChar* ptr = spec.characters8(); |
| 68 const LChar* end = ptr + spec.length(); | 64 const LChar* end = ptr + spec.length(); |
| 69 return parseViewSpecInternal(ptr, end); | 65 return parseViewSpecInternal(ptr, end); |
| 70 } | 66 } |
| 71 const UChar* ptr = spec.characters16(); | 67 const UChar* ptr = spec.characters16(); |
| 72 const UChar* end = ptr + spec.length(); | 68 const UChar* end = ptr + spec.length(); |
| 73 return parseViewSpecInternal(ptr, end); | 69 return parseViewSpecInternal(ptr, end); |
| 74 } | 70 } |
| 75 | 71 |
| 76 void SVGViewSpec::reset() { | 72 void SVGViewSpec::reset() { |
| 77 resetZoomAndPan(); | 73 resetZoomAndPan(); |
| 78 m_transform->baseValue()->clear(); | 74 m_transform->baseValue()->clear(); |
| 79 updateViewBox(FloatRect()); | 75 updateViewBox(FloatRect()); |
| 80 ASSERT(preserveAspectRatio()); | 76 ASSERT(preserveAspectRatio()); |
| 81 preserveAspectRatio()->baseValue()->setAlign( | 77 preserveAspectRatio()->baseValue()->setAlign( |
| 82 SVGPreserveAspectRatio::kSvgPreserveaspectratioXmidymid); | 78 SVGPreserveAspectRatio::kSvgPreserveaspectratioXmidymid); |
| 83 preserveAspectRatio()->baseValue()->setMeetOrSlice( | 79 preserveAspectRatio()->baseValue()->setMeetOrSlice( |
| 84 SVGPreserveAspectRatio::kSvgMeetorsliceMeet); | 80 SVGPreserveAspectRatio::kSvgMeetorsliceMeet); |
| 85 m_viewTargetString = emptyString(); | 81 m_viewTargetString = emptyString(); |
| 86 } | 82 } |
| 87 | 83 |
| 88 void SVGViewSpec::detachContextElement() { | |
| 89 m_transform = nullptr; | |
| 90 clearViewBox(); | |
| 91 clearPreserveAspectRatio(); | |
| 92 m_contextElement = nullptr; | |
| 93 } | |
| 94 | |
| 95 SVGElement* SVGViewSpec::viewTarget() const { | |
| 96 if (!m_contextElement) | |
| 97 return nullptr; | |
| 98 Element* element = m_contextElement->treeScope().getElementById( | |
| 99 AtomicString(m_viewTargetString)); | |
| 100 if (!element || !element->isSVGElement()) | |
| 101 return nullptr; | |
| 102 return toSVGElement(element); | |
| 103 } | |
| 104 | |
| 105 String SVGViewSpec::viewBoxString() const { | |
| 106 if (!viewBox()) | |
| 107 return String(); | |
| 108 | |
| 109 return viewBox()->currentValue()->valueAsString(); | |
| 110 } | |
| 111 | |
| 112 String SVGViewSpec::preserveAspectRatioString() const { | |
| 113 if (!preserveAspectRatio()) | |
| 114 return String(); | |
| 115 | |
| 116 return preserveAspectRatio()->baseValue()->valueAsString(); | |
| 117 } | |
| 118 | |
| 119 String SVGViewSpec::transformString() const { | |
| 120 if (!m_transform) | |
| 121 return String(); | |
| 122 | |
| 123 return m_transform->baseValue()->valueAsString(); | |
| 124 } | |
| 125 | |
| 126 void SVGViewSpec::setZoomAndPan(unsigned short, | |
| 127 ExceptionState& exceptionState) { | |
| 128 // SVGViewSpec and all of its content is read-only. | |
| 129 exceptionState.throwDOMException(NoModificationAllowedError, | |
| 130 ExceptionMessages::readOnly()); | |
| 131 } | |
| 132 | |
| 133 namespace { | 84 namespace { |
| 134 | 85 |
| 135 enum ViewSpecFunctionType { | 86 enum ViewSpecFunctionType { |
| 136 Unknown, | 87 Unknown, |
| 137 PreserveAspectRatio, | 88 PreserveAspectRatio, |
| 138 Transform, | 89 Transform, |
| 139 ViewBox, | 90 ViewBox, |
| 140 ViewTarget, | 91 ViewTarget, |
| 141 ZoomAndPan, | 92 ZoomAndPan, |
| 142 }; | 93 }; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 | 177 |
| 227 if (!skipExactly<CharType>(ptr, end, ')')) | 178 if (!skipExactly<CharType>(ptr, end, ')')) |
| 228 return false; | 179 return false; |
| 229 | 180 |
| 230 skipExactly<CharType>(ptr, end, ';'); | 181 skipExactly<CharType>(ptr, end, ';'); |
| 231 } | 182 } |
| 232 return skipExactly<CharType>(ptr, end, ')'); | 183 return skipExactly<CharType>(ptr, end, ')'); |
| 233 } | 184 } |
| 234 | 185 |
| 235 } // namespace blink | 186 } // namespace blink |
| OLD | NEW |