Index: third_party/WebKit/Source/core/html/canvas/HTMLAndSVGImageElementSource.cpp |
diff --git a/third_party/WebKit/Source/core/html/canvas/CanvasImageElementSource.cpp b/third_party/WebKit/Source/core/html/canvas/HTMLAndSVGImageElementSource.cpp |
similarity index 59% |
rename from third_party/WebKit/Source/core/html/canvas/CanvasImageElementSource.cpp |
rename to third_party/WebKit/Source/core/html/canvas/HTMLAndSVGImageElementSource.cpp |
index 57f78597d6cdd385ee38a767f328240924c8a0ef..1b65cb8c08fc8b1ce6336bdd85c1c8e6ff059b14 100644 |
--- a/third_party/WebKit/Source/core/html/canvas/CanvasImageElementSource.cpp |
+++ b/third_party/WebKit/Source/core/html/canvas/HTMLAndSVGImageElementSource.cpp |
@@ -2,27 +2,29 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "core/html/canvas/CanvasImageElementSource.h" |
+#include "core/html/canvas/HTMLAndSVGImageElementSource.h" |
+#include "core/frame/ImageBitmap.h" |
+#include "core/frame/LocalDOMWindow.h" |
#include "core/layout/LayoutObject.h" |
#include "core/loader/ImageLoader.h" |
#include "core/svg/graphics/SVGImageForContainer.h" |
namespace blink { |
-ImageResourceContent* CanvasImageElementSource::cachedImage() const { |
+ImageResourceContent* HTMLAndSVGImageElementSource::cachedImage() const { |
return imageLoader().image(); |
} |
-const Element& CanvasImageElementSource::element() const { |
+const Element& HTMLAndSVGImageElementSource::element() const { |
return *imageLoader().element(); |
} |
-bool CanvasImageElementSource::isSVGSource() const { |
+bool HTMLAndSVGImageElementSource::isSVGSource() const { |
return cachedImage() && cachedImage()->getImage()->isSVGImage(); |
} |
-PassRefPtr<Image> CanvasImageElementSource::getSourceImageForCanvas( |
+PassRefPtr<Image> HTMLAndSVGImageElementSource::getSourceImageForCanvas( |
SourceImageStatus* status, |
AccelerationHint, |
SnapshotReason, |
@@ -54,13 +56,13 @@ PassRefPtr<Image> CanvasImageElementSource::getSourceImageForCanvas( |
return sourceImage->imageForDefaultFrame(); |
} |
-bool CanvasImageElementSource::wouldTaintOrigin( |
+bool HTMLAndSVGImageElementSource::wouldTaintOrigin( |
SecurityOrigin* destinationSecurityOrigin) const { |
return cachedImage() && |
!cachedImage()->isAccessAllowed(destinationSecurityOrigin); |
} |
-FloatSize CanvasImageElementSource::elementSize( |
+FloatSize HTMLAndSVGImageElementSource::elementSize( |
const FloatSize& defaultObjectSize) const { |
ImageResourceContent* image = cachedImage(); |
if (!image) |
@@ -76,7 +78,7 @@ FloatSize CanvasImageElementSource::elementSize( |
1.0f)); |
} |
-FloatSize CanvasImageElementSource::defaultDestinationSize( |
+FloatSize HTMLAndSVGImageElementSource::defaultDestinationSize( |
const FloatSize& defaultObjectSize) const { |
ImageResourceContent* image = cachedImage(); |
if (!image) |
@@ -94,15 +96,15 @@ FloatSize CanvasImageElementSource::defaultDestinationSize( |
return FloatSize(size); |
} |
-bool CanvasImageElementSource::isAccelerated() const { |
+bool HTMLAndSVGImageElementSource::isAccelerated() const { |
return false; |
} |
-const KURL& CanvasImageElementSource::sourceURL() const { |
+const KURL& HTMLAndSVGImageElementSource::sourceURL() const { |
return cachedImage()->response().url(); |
} |
-int CanvasImageElementSource::sourceWidth() { |
+int HTMLAndSVGImageElementSource::sourceWidth() { |
SourceImageStatus status; |
RefPtr<Image> image = |
getSourceImageForCanvas(&status, PreferNoAcceleration, |
@@ -110,7 +112,7 @@ int CanvasImageElementSource::sourceWidth() { |
return image->width(); |
} |
-int CanvasImageElementSource::sourceHeight() { |
+int HTMLAndSVGImageElementSource::sourceHeight() { |
SourceImageStatus status; |
RefPtr<Image> image = |
getSourceImageForCanvas(&status, PreferNoAcceleration, |
@@ -118,9 +120,42 @@ int CanvasImageElementSource::sourceHeight() { |
return image->height(); |
} |
-bool CanvasImageElementSource::isOpaque() const { |
+bool HTMLAndSVGImageElementSource::isOpaque() const { |
Image* image = const_cast<Element&>(element()).imageContents(); |
return image && image->currentFrameKnownToBeOpaque(); |
} |
+IntSize HTMLAndSVGImageElementSource::bitmapSourceSize() const { |
+ ImageResourceContent* image = cachedImage(); |
+ if (!image) |
+ return IntSize(); |
+ LayoutSize lSize = image->imageSize( |
+ LayoutObject::shouldRespectImageOrientation(element().layoutObject()), |
+ 1.0f); |
+ DCHECK(lSize.fraction().isZero()); |
+ return IntSize(lSize.width().toInt(), lSize.height().toInt()); |
+} |
+ |
+ScriptPromise HTMLAndSVGImageElementSource::createImageBitmap( |
+ ScriptState* scriptState, |
+ EventTarget& eventTarget, |
+ Optional<IntRect> cropRect, |
+ const ImageBitmapOptions& options, |
+ ExceptionState& exceptionState) { |
+ DCHECK(eventTarget.toLocalDOMWindow()); |
+ if ((cropRect && |
+ !ImageBitmap::isSourceSizeValid(cropRect->width(), cropRect->height(), |
+ exceptionState)) || |
+ !ImageBitmap::isSourceSizeValid(bitmapSourceSize().width(), |
+ bitmapSourceSize().height(), |
+ exceptionState)) |
+ return ScriptPromise(); |
+ if (!ImageBitmap::isResizeOptionValid(options, exceptionState)) |
+ return ScriptPromise(); |
+ return ImageBitmapSource::fulfillImageBitmap( |
+ scriptState, |
+ ImageBitmap::create(this, cropRect, |
+ eventTarget.toLocalDOMWindow()->document(), options)); |
+} |
+ |
} // namespace blink |