hterm: use screen rather than body size for displayImage sizing

This CL is preparation to allow padding within x-screen.
With padding, screen size can be less than document.body size
and images should be using screen element for sizing.

Bug: 267654
Change-Id: I75507ba88ea7c17e46d181b298242dbec5a340b9
Reviewed-on: https://chromium-review.googlesource.com/c/apps/libapps/+/2160615
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
diff --git a/hterm/js/hterm_terminal.js b/hterm/js/hterm_terminal.js
index 85f3496..2b1d851 100644
--- a/hterm/js/hterm_terminal.js
+++ b/hterm/js/hterm_terminal.js
@@ -3478,9 +3478,10 @@
     // right place in the terminal.
     img.onload = () => {
       // Now that we have the image dimensions, figure out how to show it.
+      const screenSize = this.scrollPort_.getScreenSize();
       img.style.objectFit = options.preserveAspectRatio ? 'scale-down' : 'fill';
-      img.style.maxWidth = `${this.document_.body.clientWidth}px`;
-      img.style.maxHeight = `${this.document_.body.clientHeight}px`;
+      img.style.maxWidth = `${screenSize.width}px`;
+      img.style.maxHeight = `${screenSize.height}px`;
 
       // Parse a width/height specification.
       const parseDim = (dim, maxDim, cssVar) => {
@@ -3501,12 +3502,10 @@
 
         return '';
       };
-      img.style.width =
-          parseDim(options.width, this.document_.body.clientWidth,
-                   '--hterm-charsize-width');
-      img.style.height =
-          parseDim(options.height,  this.document_.body.clientHeight,
-                   '--hterm-charsize-height');
+      img.style.width = parseDim(
+          options.width, screenSize.width, '--hterm-charsize-width');
+      img.style.height = parseDim(
+          options.height,  screenSize.height, '--hterm-charsize-height');
 
       // Figure out how many rows the image occupies, then add that many.
       // Note: This count will be inaccurate if the font size changes on us.