Chromium Code Reviews| Index: third_party/WebKit/Source/core/html/canvas/CanvasHTMLSVGImage.cpp |
| diff --git a/third_party/WebKit/Source/core/html/canvas/CanvasHTMLSVGImage.cpp b/third_party/WebKit/Source/core/html/canvas/CanvasHTMLSVGImage.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f456c0f022825151a0751342598cf6b4fc801191 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/html/canvas/CanvasHTMLSVGImage.cpp |
| @@ -0,0 +1,134 @@ |
| +/* |
| + * Copyright (C) 2017 Google Inc. All rights reserved. |
|
fs
2017/03/06 22:46:15
Same comment as in the header.
fserb
2017/03/07 20:44:02
done. sorry for that.
|
| + * |
| + * This library is free software; you can redistribute it and/or |
| + * modify it under the terms of the GNU Library General Public |
| + * License as published by the Free Software Foundation; either |
| + * version 2 of the License, or (at your option) any later version. |
| + * |
| + * This library is distributed in the hope that it will be useful, |
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| + * Library General Public License for more details. |
| + * You should have received a copy of the GNU Library General Public License |
| + * along with this library; see the file COPYING.LIB. If not, write to |
| + * |
| + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| + * Boston, MA 02110-1301, USA. |
| + * |
| + */ |
| + |
| +#include "core/html/canvas/CanvasHTMLSVGImage.h" |
| + |
| +#include "core/html/HTMLImageLoader.h" |
| +#include "core/layout/LayoutObject.h" |
| +#include "core/svg/graphics/SVGImageForContainer.h" |
| + |
| +namespace blink { |
| + |
| +bool CanvasHTMLSVGImage::isSVGSource() const { |
| + return cachedImage() && cachedImage()->getImage()->isSVGImage(); |
| +} |
| + |
| +PassRefPtr<Image> CanvasHTMLSVGImage::getSourceImageForCanvas( |
| + SourceImageStatus* status, |
| + AccelerationHint, |
| + SnapshotReason, |
| + const FloatSize& defaultObjectSize) const { |
| + if (!imageLoaded() || !cachedImage()) { |
| + *status = IncompleteSourceImageStatus; |
| + return nullptr; |
| + } |
| + |
| + if (cachedImage()->errorOccurred()) { |
| + *status = UndecodableSourceImageStatus; |
| + return nullptr; |
| + } |
| + |
| + RefPtr<Image> sourceImage; |
| + if (cachedImage()->getImage()->isSVGImage()) { |
| + UseCounter::count(element()->document(), UseCounter::SVGInCanvas2D); |
| + SVGImage* svgImage = toSVGImage(cachedImage()->getImage()); |
| + IntSize imageSize = |
| + roundedIntSize(svgImage->concreteObjectSize(defaultObjectSize)); |
| + sourceImage = SVGImageForContainer::create( |
| + svgImage, imageSize, 1, |
| + element()->document().completeURL(element()->imageSourceURL())); |
| + } else { |
| + sourceImage = cachedImage()->getImage(); |
| + } |
| + |
| + *status = NormalSourceImageStatus; |
| + return sourceImage->imageForDefaultFrame(); |
| +} |
| + |
| +bool CanvasHTMLSVGImage::wouldTaintOrigin( |
| + SecurityOrigin* destinationSecurityOrigin) const { |
| + return cachedImage() && |
| + !cachedImage()->isAccessAllowed(destinationSecurityOrigin); |
| +} |
| + |
| +FloatSize CanvasHTMLSVGImage::elementSize( |
| + const FloatSize& defaultObjectSize) const { |
| + ImageResourceContent* image = cachedImage(); |
| + if (!image) |
| + return FloatSize(); |
| + |
| + if (image->getImage() && image->getImage()->isSVGImage()) { |
| + return toSVGImage(cachedImage()->getImage()) |
| + ->concreteObjectSize(defaultObjectSize); |
| + } |
| + |
| + return FloatSize(image->imageSize( |
| + LayoutObject::shouldRespectImageOrientation(element()->layoutObject()), |
| + 1.0f)); |
| +} |
| + |
| +FloatSize CanvasHTMLSVGImage::defaultDestinationSize( |
| + const FloatSize& defaultObjectSize) const { |
| + ImageResourceContent* image = cachedImage(); |
| + if (!image) |
| + return FloatSize(); |
| + |
| + if (image->getImage() && image->getImage()->isSVGImage()) { |
| + return toSVGImage(cachedImage()->getImage()) |
| + ->concreteObjectSize(defaultObjectSize); |
| + } |
| + |
| + LayoutSize size; |
| + size = image->imageSize( |
| + LayoutObject::shouldRespectImageOrientation(element()->layoutObject()), |
| + 1.0f); |
| + return FloatSize(size); |
| +} |
| + |
| +bool CanvasHTMLSVGImage::isAccelerated() const { |
| + return false; |
|
fs
2017/03/06 22:46:15
Isn't this what the base-class has?
fserb
2017/03/07 20:44:02
pure virtual on base class, do you want me to chan
fs
2017/03/07 22:01:24
Sorry, maybe I quick-scanned too quickly and got i
|
| +} |
| + |
| +const KURL& CanvasHTMLSVGImage::sourceURL() const { |
| + return cachedImage()->response().url(); |
| +} |
| + |
| +int CanvasHTMLSVGImage::sourceWidth() { |
| + SourceImageStatus status; |
| + FloatSize defaultObjectSize; // (width(), height()) ?? |
|
fs
2017/03/06 22:46:15
Yes, looks like this needs to move down to *ImageE
fserb
2017/03/07 20:44:02
did something like that. sourceDefaultSize() and l
|
| + RefPtr<Image> image = getSourceImageForCanvas( |
| + &status, PreferNoAcceleration, SnapshotReasonUnknown, defaultObjectSize); |
| + return image->width(); |
| +} |
| + |
| +int CanvasHTMLSVGImage::sourceHeight() { |
| + SourceImageStatus status; |
| + FloatSize defaultObjectSize; |
| + RefPtr<Image> image = getSourceImageForCanvas( |
| + &status, PreferNoAcceleration, SnapshotReasonUnknown, defaultObjectSize); |
| + return image->height(); |
| +} |
| + |
| +bool CanvasHTMLSVGImage::isOpaque() const { |
| + Image* image = const_cast<Element*>(element())->imageContents(); |
| + return image && image->currentFrameKnownToBeOpaque(); |
| +} |
| + |
| +} // namespace blink |