| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Rob Buis <buis@kde.org> |
| 4 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> | 4 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> |
| 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 "core/svg/SVGImageElement.h" | 22 #include "core/svg/SVGImageElement.h" |
| 23 | 23 |
| 24 #include "core/CSSPropertyNames.h" | 24 #include "core/CSSPropertyNames.h" |
| 25 #include "core/SVGNames.h" |
| 25 #include "core/dom/StyleChangeReason.h" | 26 #include "core/dom/StyleChangeReason.h" |
| 26 #include "core/frame/ImageBitmap.h" | |
| 27 #include "core/frame/LocalDOMWindow.h" | |
| 28 #include "core/layout/LayoutImageResource.h" | 27 #include "core/layout/LayoutImageResource.h" |
| 29 #include "core/layout/svg/LayoutSVGImage.h" | 28 #include "core/layout/svg/LayoutSVGImage.h" |
| 30 | 29 |
| 31 namespace blink { | 30 namespace blink { |
| 32 | 31 |
| 33 inline SVGImageElement::SVGImageElement(Document& document) | 32 inline SVGImageElement::SVGImageElement(Document& document) |
| 34 : SVGGraphicsElement(SVGNames::imageTag, document), | 33 : SVGGraphicsElement(SVGNames::imageTag, document), |
| 35 SVGURIReference(this), | 34 SVGURIReference(this), |
| 36 x_(SVGAnimatedLength::Create(this, | 35 x_(SVGAnimatedLength::Create(this, |
| 37 SVGNames::xAttr, | 36 SVGNames::xAttr, |
| 38 SVGLength::Create(SVGLengthMode::kWidth), | 37 SVGLength::Create(SVGLengthMode::kWidth), |
| 39 CSSPropertyX)), | 38 CSSPropertyX)), |
| 40 y_(SVGAnimatedLength::Create(this, | 39 y_(SVGAnimatedLength::Create(this, |
| 41 SVGNames::yAttr, | 40 SVGNames::yAttr, |
| 42 SVGLength::Create(SVGLengthMode::kHeight), | 41 SVGLength::Create(SVGLengthMode::kHeight), |
| 43 CSSPropertyY)), | 42 CSSPropertyY)), |
| 44 width_(SVGAnimatedLength::Create(this, | 43 width_(SVGAnimatedLength::Create(this, |
| 45 SVGNames::widthAttr, | 44 SVGNames::widthAttr, |
| 46 SVGLength::Create(SVGLengthMode::kWidth), | 45 SVGLength::Create(SVGLengthMode::kWidth), |
| 47 CSSPropertyWidth)), | 46 CSSPropertyWidth)), |
| 48 height_( | 47 height_( |
| 49 SVGAnimatedLength::Create(this, | 48 SVGAnimatedLength::Create(this, |
| 50 SVGNames::heightAttr, | 49 SVGNames::heightAttr, |
| 51 SVGLength::Create(SVGLengthMode::kHeight), | 50 SVGLength::Create(SVGLengthMode::kHeight), |
| 52 CSSPropertyHeight)), | 51 CSSPropertyHeight)), |
| 53 preserve_aspect_ratio_(SVGAnimatedPreserveAspectRatio::Create( | 52 preserve_aspect_ratio_(SVGAnimatedPreserveAspectRatio::Create( |
| 54 this, | 53 this, |
| 55 SVGNames::preserveAspectRatioAttr)), | 54 SVGNames::preserveAspectRatioAttr)), |
| 56 image_loader_(SVGImageLoader::Create(this)), | 55 image_loader_(SVGImageLoader::Create(this)) { |
| 57 needs_loader_uri_update_(true) { | |
| 58 AddToPropertyMap(x_); | 56 AddToPropertyMap(x_); |
| 59 AddToPropertyMap(y_); | 57 AddToPropertyMap(y_); |
| 60 AddToPropertyMap(width_); | 58 AddToPropertyMap(width_); |
| 61 AddToPropertyMap(height_); | 59 AddToPropertyMap(height_); |
| 62 AddToPropertyMap(preserve_aspect_ratio_); | 60 AddToPropertyMap(preserve_aspect_ratio_); |
| 63 } | 61 } |
| 64 | 62 |
| 65 DEFINE_NODE_FACTORY(SVGImageElement) | 63 DEFINE_NODE_FACTORY(SVGImageElement) |
| 66 | 64 |
| 67 DEFINE_TRACE(SVGImageElement) { | 65 DEFINE_TRACE(SVGImageElement) { |
| 68 visitor->Trace(x_); | 66 visitor->Trace(x_); |
| 69 visitor->Trace(y_); | 67 visitor->Trace(y_); |
| 70 visitor->Trace(width_); | 68 visitor->Trace(width_); |
| 71 visitor->Trace(height_); | 69 visitor->Trace(height_); |
| 72 visitor->Trace(preserve_aspect_ratio_); | 70 visitor->Trace(preserve_aspect_ratio_); |
| 73 visitor->Trace(image_loader_); | 71 visitor->Trace(image_loader_); |
| 74 SVGGraphicsElement::Trace(visitor); | 72 SVGGraphicsElement::Trace(visitor); |
| 75 SVGURIReference::Trace(visitor); | 73 SVGURIReference::Trace(visitor); |
| 76 } | 74 } |
| 77 | 75 |
| 78 bool SVGImageElement::CurrentFrameHasSingleSecurityOrigin() const { | 76 bool SVGImageElement::CurrentFrameHasSingleSecurityOrigin() const { |
| 79 if (LayoutSVGImage* layout_svg_image = ToLayoutSVGImage(GetLayoutObject())) { | 77 if (LayoutSVGImage* layout_svg_image = ToLayoutSVGImage(GetLayoutObject())) { |
| 80 if (layout_svg_image->ImageResource()->HasImage()) { | 78 LayoutImageResource* layout_image_resource = |
| 81 if (Image* image = | 79 layout_svg_image->ImageResource(); |
| 82 layout_svg_image->ImageResource()->CachedImage()->GetImage()) | 80 if (layout_image_resource->HasImage()) { |
| 81 if (Image* image = layout_image_resource->CachedImage()->GetImage()) |
| 83 return image->CurrentFrameHasSingleSecurityOrigin(); | 82 return image->CurrentFrameHasSingleSecurityOrigin(); |
| 84 } | 83 } |
| 85 } | 84 } |
| 86 | |
| 87 return true; | 85 return true; |
| 88 } | 86 } |
| 89 | 87 |
| 90 void SVGImageElement::CollectStyleForPresentationAttribute( | 88 void SVGImageElement::CollectStyleForPresentationAttribute( |
| 91 const QualifiedName& name, | 89 const QualifiedName& name, |
| 92 const AtomicString& value, | 90 const AtomicString& value, |
| 93 MutableStylePropertySet* style) { | 91 MutableStylePropertySet* style) { |
| 94 SVGAnimatedPropertyBase* property = PropertyFromAttribute(name); | 92 SVGAnimatedPropertyBase* property = PropertyFromAttribute(name); |
| 95 if (property == width_) { | 93 if (property == width_) { |
| 96 AddPropertyToPresentationAttributeStyle(style, property->CssPropertyId(), | 94 AddPropertyToPresentationAttributeStyle(style, property->CssPropertyId(), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 // FIXME: if isLengthAttribute then we should avoid this call if the | 131 // FIXME: if isLengthAttribute then we should avoid this call if the |
| 134 // viewport didn't change, however since we don't have the computed | 132 // viewport didn't change, however since we don't have the computed |
| 135 // style yet we can't use updateBoundingBox/updateImageContainerSize. | 133 // style yet we can't use updateBoundingBox/updateImageContainerSize. |
| 136 // See http://crbug.com/466200. | 134 // See http://crbug.com/466200. |
| 137 MarkForLayoutAndParentResourceInvalidation(object); | 135 MarkForLayoutAndParentResourceInvalidation(object); |
| 138 return; | 136 return; |
| 139 } | 137 } |
| 140 | 138 |
| 141 if (SVGURIReference::IsKnownAttribute(attr_name)) { | 139 if (SVGURIReference::IsKnownAttribute(attr_name)) { |
| 142 SVGElement::InvalidationGuard invalidation_guard(this); | 140 SVGElement::InvalidationGuard invalidation_guard(this); |
| 143 if (isConnected()) | 141 GetImageLoader().UpdateFromElement(ImageLoader::kUpdateIgnorePreviousError); |
| 144 GetImageLoader().UpdateFromElement( | |
| 145 ImageLoader::kUpdateIgnorePreviousError); | |
| 146 else | |
| 147 needs_loader_uri_update_ = true; | |
| 148 return; | 142 return; |
| 149 } | 143 } |
| 150 | 144 |
| 151 SVGGraphicsElement::SvgAttributeChanged(attr_name); | 145 SVGGraphicsElement::SvgAttributeChanged(attr_name); |
| 152 } | 146 } |
| 153 | 147 |
| 154 bool SVGImageElement::SelfHasRelativeLengths() const { | 148 bool SVGImageElement::SelfHasRelativeLengths() const { |
| 155 return x_->CurrentValue()->IsRelative() || y_->CurrentValue()->IsRelative() || | 149 return x_->CurrentValue()->IsRelative() || y_->CurrentValue()->IsRelative() || |
| 156 width_->CurrentValue()->IsRelative() || | 150 width_->CurrentValue()->IsRelative() || |
| 157 height_->CurrentValue()->IsRelative(); | 151 height_->CurrentValue()->IsRelative(); |
| 158 } | 152 } |
| 159 | 153 |
| 160 LayoutObject* SVGImageElement::CreateLayoutObject(const ComputedStyle&) { | 154 LayoutObject* SVGImageElement::CreateLayoutObject(const ComputedStyle&) { |
| 161 return new LayoutSVGImage(this); | 155 return new LayoutSVGImage(this); |
| 162 } | 156 } |
| 163 | 157 |
| 164 bool SVGImageElement::HaveLoadedRequiredResources() { | 158 bool SVGImageElement::HaveLoadedRequiredResources() { |
| 165 return !needs_loader_uri_update_ && !GetImageLoader().HasPendingActivity(); | 159 return !GetImageLoader().HasPendingActivity(); |
| 166 } | 160 } |
| 167 | 161 |
| 168 void SVGImageElement::AttachLayoutTree(const AttachContext& context) { | 162 void SVGImageElement::AttachLayoutTree(const AttachContext& context) { |
| 169 SVGGraphicsElement::AttachLayoutTree(context); | 163 SVGGraphicsElement::AttachLayoutTree(context); |
| 170 | 164 |
| 171 if (LayoutSVGImage* image_obj = ToLayoutSVGImage(GetLayoutObject())) { | 165 if (LayoutSVGImage* image_obj = ToLayoutSVGImage(GetLayoutObject())) { |
| 172 if (image_obj->ImageResource()->HasImage()) | 166 LayoutImageResource* layout_image_resource = image_obj->ImageResource(); |
| 167 if (layout_image_resource->HasImage()) |
| 173 return; | 168 return; |
| 174 | 169 layout_image_resource->SetImageResource(GetImageLoader().GetImage()); |
| 175 image_obj->ImageResource()->SetImageResource(GetImageLoader().GetImage()); | |
| 176 } | 170 } |
| 177 } | 171 } |
| 178 | 172 |
| 179 Node::InsertionNotificationRequest SVGImageElement::InsertedInto( | 173 Node::InsertionNotificationRequest SVGImageElement::InsertedInto( |
| 180 ContainerNode* root_parent) { | 174 ContainerNode* root_parent) { |
| 181 SVGGraphicsElement::InsertedInto(root_parent); | 175 // A previous loader update may have failed to actually fetch the image if |
| 182 if (!root_parent->isConnected()) | 176 // the document was inactive. In that case, force a re-update (but don't |
| 183 return kInsertionDone; | 177 // clear previous errors). |
| 178 if (root_parent->isConnected() && !GetImageLoader().GetImage()) |
| 179 GetImageLoader().UpdateFromElement(ImageLoader::kUpdateNormal); |
| 184 | 180 |
| 185 // We can only resolve base URIs properly after tree insertion - hence, URI | 181 return SVGGraphicsElement::InsertedInto(root_parent); |
| 186 // mutations while detached are deferred until this point. | |
| 187 if (needs_loader_uri_update_) { | |
| 188 GetImageLoader().UpdateFromElement(ImageLoader::kUpdateIgnorePreviousError); | |
| 189 needs_loader_uri_update_ = false; | |
| 190 } else { | |
| 191 // A previous loader update may have failed to actually fetch the image if | |
| 192 // the document was inactive. In that case, force a re-update (but don't | |
| 193 // clear previous errors). | |
| 194 if (!GetImageLoader().GetImage()) | |
| 195 GetImageLoader().UpdateFromElement(); | |
| 196 } | |
| 197 | |
| 198 return kInsertionDone; | |
| 199 } | 182 } |
| 200 | 183 |
| 201 FloatSize SVGImageElement::SourceDefaultObjectSize() { | 184 FloatSize SVGImageElement::SourceDefaultObjectSize() { |
| 202 if (GetLayoutObject()) | 185 if (GetLayoutObject()) |
| 203 return ToLayoutSVGImage(GetLayoutObject())->ObjectBoundingBox().Size(); | 186 return ToLayoutSVGImage(GetLayoutObject())->ObjectBoundingBox().Size(); |
| 204 SVGLengthContext length_context(this); | 187 SVGLengthContext length_context(this); |
| 205 return FloatSize(width_->CurrentValue()->Value(length_context), | 188 return FloatSize(width_->CurrentValue()->Value(length_context), |
| 206 height_->CurrentValue()->Value(length_context)); | 189 height_->CurrentValue()->Value(length_context)); |
| 207 } | 190 } |
| 208 | 191 |
| 209 const AtomicString SVGImageElement::ImageSourceURL() const { | 192 const AtomicString SVGImageElement::ImageSourceURL() const { |
| 210 return AtomicString(HrefString()); | 193 return AtomicString(HrefString()); |
| 211 } | 194 } |
| 212 | 195 |
| 213 void SVGImageElement::DidMoveToNewDocument(Document& old_document) { | 196 void SVGImageElement::DidMoveToNewDocument(Document& old_document) { |
| 197 // TODO(fs): Initiate a new load (like HTMLImageElement.) |
| 214 GetImageLoader().ElementDidMoveToNewDocument(); | 198 GetImageLoader().ElementDidMoveToNewDocument(); |
| 215 SVGGraphicsElement::DidMoveToNewDocument(old_document); | 199 SVGGraphicsElement::DidMoveToNewDocument(old_document); |
| 216 } | 200 } |
| 217 | 201 |
| 218 } // namespace blink | 202 } // namespace blink |
| OLD | NEW |