summaryrefslogtreecommitdiffstats
path: root/dom/html/HTMLCanvasElement.cpp
diff options
context:
space:
mode:
authorGaming4JC <g4jc@bulletmail.org>2019-04-26 19:46:37 -0400
committerGaming4JC <g4jc@bulletmail.org>2019-04-26 19:46:37 -0400
commit1091fcac8ed5e698f59a293d7cf533707b1da137 (patch)
treedf451925c8dfbee82d8287020380bb6eaa454fd7 /dom/html/HTMLCanvasElement.cpp
parent3424afccaebc71c4acd4fa9eadf519c408c5965b (diff)
downloadUXP-1091fcac8ed5e698f59a293d7cf533707b1da137.tar
UXP-1091fcac8ed5e698f59a293d7cf533707b1da137.tar.gz
UXP-1091fcac8ed5e698f59a293d7cf533707b1da137.tar.lz
UXP-1091fcac8ed5e698f59a293d7cf533707b1da137.tar.xz
UXP-1091fcac8ed5e698f59a293d7cf533707b1da137.zip
Fix failure to print when pages contain zero-sized <canvas> element.
Fixes #1058
Diffstat (limited to 'dom/html/HTMLCanvasElement.cpp')
-rw-r--r--dom/html/HTMLCanvasElement.cpp28
1 files changed, 17 insertions, 11 deletions
diff --git a/dom/html/HTMLCanvasElement.cpp b/dom/html/HTMLCanvasElement.cpp
index a01795d9e..4b5deab18 100644
--- a/dom/html/HTMLCanvasElement.cpp
+++ b/dom/html/HTMLCanvasElement.cpp
@@ -552,17 +552,23 @@ HTMLCanvasElement::CopyInnerTo(Element* aDest)
HTMLCanvasElement* dest = static_cast<HTMLCanvasElement*>(aDest);
dest->mOriginalCanvas = this;
- nsCOMPtr<nsISupports> cxt;
- dest->GetContext(NS_LITERAL_STRING("2d"), getter_AddRefs(cxt));
- RefPtr<CanvasRenderingContext2D> context2d =
- static_cast<CanvasRenderingContext2D*>(cxt.get());
- if (context2d && !mPrintCallback) {
- CanvasImageSource source;
- source.SetAsHTMLCanvasElement() = this;
- ErrorResult err;
- context2d->DrawImage(source,
- 0.0, 0.0, err);
- rv = err.StealNSResult();
+ // We make sure that the canvas is not zero sized since that would cause
+ // the DrawImage call below to return an error, which would cause printing
+ // to fail.
+ nsIntSize size = GetWidthHeight();
+ if (size.height > 0 && size.width > 0) {
+ nsCOMPtr<nsISupports> cxt;
+ dest->GetContext(NS_LITERAL_STRING("2d"), getter_AddRefs(cxt));
+ RefPtr<CanvasRenderingContext2D> context2d =
+ static_cast<CanvasRenderingContext2D*>(cxt.get());
+ if (context2d && !mPrintCallback) {
+ CanvasImageSource source;
+ source.SetAsHTMLCanvasElement() = this;
+ ErrorResult err;
+ context2d->DrawImage(source,
+ 0.0, 0.0, err);
+ rv = err.StealNSResult();
+ }
}
}
return rv;