Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * 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.
| |
| 3 * | |
| 4 * This library is free software; you can redistribute it and/or | |
| 5 * modify it under the terms of the GNU Library General Public | |
| 6 * License as published by the Free Software Foundation; either | |
| 7 * version 2 of the License, or (at your option) any later version. | |
| 8 * | |
| 9 * This library is distributed in the hope that it will be useful, | |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 12 * Library General Public License for more details. | |
| 13 * You should have received a copy of the GNU Library General Public License | |
| 14 * along with this library; see the file COPYING.LIB. If not, write to | |
| 15 * | |
| 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
| 17 * Boston, MA 02110-1301, USA. | |
| 18 * | |
| 19 */ | |
| 20 | |
| 21 #include "core/html/canvas/CanvasHTMLSVGImage.h" | |
| 22 | |
| 23 #include "core/html/HTMLImageLoader.h" | |
| 24 #include "core/layout/LayoutObject.h" | |
| 25 #include "core/svg/graphics/SVGImageForContainer.h" | |
| 26 | |
| 27 namespace blink { | |
| 28 | |
| 29 bool CanvasHTMLSVGImage::isSVGSource() const { | |
| 30 return cachedImage() && cachedImage()->getImage()->isSVGImage(); | |
| 31 } | |
| 32 | |
| 33 PassRefPtr<Image> CanvasHTMLSVGImage::getSourceImageForCanvas( | |
| 34 SourceImageStatus* status, | |
| 35 AccelerationHint, | |
| 36 SnapshotReason, | |
| 37 const FloatSize& defaultObjectSize) const { | |
| 38 if (!imageLoaded() || !cachedImage()) { | |
| 39 *status = IncompleteSourceImageStatus; | |
| 40 return nullptr; | |
| 41 } | |
| 42 | |
| 43 if (cachedImage()->errorOccurred()) { | |
| 44 *status = UndecodableSourceImageStatus; | |
| 45 return nullptr; | |
| 46 } | |
| 47 | |
| 48 RefPtr<Image> sourceImage; | |
| 49 if (cachedImage()->getImage()->isSVGImage()) { | |
| 50 UseCounter::count(element()->document(), UseCounter::SVGInCanvas2D); | |
| 51 SVGImage* svgImage = toSVGImage(cachedImage()->getImage()); | |
| 52 IntSize imageSize = | |
| 53 roundedIntSize(svgImage->concreteObjectSize(defaultObjectSize)); | |
| 54 sourceImage = SVGImageForContainer::create( | |
| 55 svgImage, imageSize, 1, | |
| 56 element()->document().completeURL(element()->imageSourceURL())); | |
| 57 } else { | |
| 58 sourceImage = cachedImage()->getImage(); | |
| 59 } | |
| 60 | |
| 61 *status = NormalSourceImageStatus; | |
| 62 return sourceImage->imageForDefaultFrame(); | |
| 63 } | |
| 64 | |
| 65 bool CanvasHTMLSVGImage::wouldTaintOrigin( | |
| 66 SecurityOrigin* destinationSecurityOrigin) const { | |
| 67 return cachedImage() && | |
| 68 !cachedImage()->isAccessAllowed(destinationSecurityOrigin); | |
| 69 } | |
| 70 | |
| 71 FloatSize CanvasHTMLSVGImage::elementSize( | |
| 72 const FloatSize& defaultObjectSize) const { | |
| 73 ImageResourceContent* image = cachedImage(); | |
| 74 if (!image) | |
| 75 return FloatSize(); | |
| 76 | |
| 77 if (image->getImage() && image->getImage()->isSVGImage()) { | |
| 78 return toSVGImage(cachedImage()->getImage()) | |
| 79 ->concreteObjectSize(defaultObjectSize); | |
| 80 } | |
| 81 | |
| 82 return FloatSize(image->imageSize( | |
| 83 LayoutObject::shouldRespectImageOrientation(element()->layoutObject()), | |
| 84 1.0f)); | |
| 85 } | |
| 86 | |
| 87 FloatSize CanvasHTMLSVGImage::defaultDestinationSize( | |
| 88 const FloatSize& defaultObjectSize) const { | |
| 89 ImageResourceContent* image = cachedImage(); | |
| 90 if (!image) | |
| 91 return FloatSize(); | |
| 92 | |
| 93 if (image->getImage() && image->getImage()->isSVGImage()) { | |
| 94 return toSVGImage(cachedImage()->getImage()) | |
| 95 ->concreteObjectSize(defaultObjectSize); | |
| 96 } | |
| 97 | |
| 98 LayoutSize size; | |
| 99 size = image->imageSize( | |
| 100 LayoutObject::shouldRespectImageOrientation(element()->layoutObject()), | |
| 101 1.0f); | |
| 102 return FloatSize(size); | |
| 103 } | |
| 104 | |
| 105 bool CanvasHTMLSVGImage::isAccelerated() const { | |
| 106 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
| |
| 107 } | |
| 108 | |
| 109 const KURL& CanvasHTMLSVGImage::sourceURL() const { | |
| 110 return cachedImage()->response().url(); | |
| 111 } | |
| 112 | |
| 113 int CanvasHTMLSVGImage::sourceWidth() { | |
| 114 SourceImageStatus status; | |
| 115 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
| |
| 116 RefPtr<Image> image = getSourceImageForCanvas( | |
| 117 &status, PreferNoAcceleration, SnapshotReasonUnknown, defaultObjectSize); | |
| 118 return image->width(); | |
| 119 } | |
| 120 | |
| 121 int CanvasHTMLSVGImage::sourceHeight() { | |
| 122 SourceImageStatus status; | |
| 123 FloatSize defaultObjectSize; | |
| 124 RefPtr<Image> image = getSourceImageForCanvas( | |
| 125 &status, PreferNoAcceleration, SnapshotReasonUnknown, defaultObjectSize); | |
| 126 return image->height(); | |
| 127 } | |
| 128 | |
| 129 bool CanvasHTMLSVGImage::isOpaque() const { | |
| 130 Image* image = const_cast<Element*>(element())->imageContents(); | |
| 131 return image && image->currentFrameKnownToBeOpaque(); | |
| 132 } | |
| 133 | |
| 134 } // namespace blink | |
| OLD | NEW |