Bug 1145903 - Use CSS to shrinkToFit instead of a racy set of width/height on the image frame. r=seth draft
authorBenoit Girard <b56girard@gmail.com>
Mon, 22 Feb 2016 19:02:26 -0500
changeset 333214 a00159d1d2dbe11cb336de11fc36fc57b4a2272e
parent 331542 709f559b5406e8555cf84dd09bdc747b076f142c
child 336192 c8145f7b6099daa71920b9b71bcec7e12508804a
push id11296
push userb56girard@gmail.com
push dateTue, 23 Feb 2016 00:03:37 +0000
reviewersseth
bugs1145903
milestone47.0a1
Bug 1145903 - Use CSS to shrinkToFit instead of a racy set of width/height on the image frame. r=seth MozReview-Commit-ID: GnBcPLMGKDS
dom/html/ImageDocument.cpp
dom/html/ImageDocument.h
layout/style/ImageDocument.css
--- a/dom/html/ImageDocument.cpp
+++ b/dom/html/ImageDocument.cpp
@@ -335,22 +335,16 @@ ImageDocument::ShrinkToFit()
   if (!mImageContent) {
     return;
   }
   if (GetZoomLevel() != mOriginalZoomLevel && mImageIsResized &&
       !nsContentUtils::IsChildOfSameType(this)) {
     return;
   }
 
-  // Keep image content alive while changing the attributes.
-  nsCOMPtr<nsIContent> imageContent = mImageContent;
-  nsCOMPtr<nsIDOMHTMLImageElement> image = do_QueryInterface(mImageContent);
-  image->SetWidth(std::max(1, NSToCoordFloor(GetRatio() * mImageWidth)));
-  image->SetHeight(std::max(1, NSToCoordFloor(GetRatio() * mImageHeight)));
-  
   // The view might have been scrolled when zooming in, scroll back to the
   // origin now that we're showing a shrunk-to-window version.
   ScrollImageTo(0, 0, false);
 
   if (!mImageContent) {
     // ScrollImageTo flush destroyed our content.
     return;
   }
--- a/dom/html/ImageDocument.h
+++ b/dom/html/ImageDocument.h
@@ -109,16 +109,19 @@ protected:
   nsresult OnSizeAvailable(imgIRequest* aRequest, imgIContainer* aImage);
   nsresult OnLoadComplete(imgIRequest* aRequest, nsresult aStatus);
   void OnHasTransparency();
 
   nsCOMPtr<nsIContent>          mImageContent;
 
   float                         mVisibleWidth;
   float                         mVisibleHeight;
+  // XXX: The image width/height isn't invalidated to reflect the up-to-date
+  //      width/height of the image frame. In particular when the
+  //      StyleVisibility orientation changes this value isn't updated.
   int32_t                       mImageWidth;
   int32_t                       mImageHeight;
 
   bool                          mResizeImageByDefault;
   bool                          mClickResizingEnabled;
   bool                          mImageIsOverflowingHorizontally;
   bool                          mImageIsOverflowingVertically;
   // mImageIsResized is true if the image is currently resized
--- a/layout/style/ImageDocument.css
+++ b/layout/style/ImageDocument.css
@@ -10,16 +10,19 @@
 
 @media not print {
   .overflowingVertical, .overflowingHorizontalOnly {
     cursor: zoom-out;
   }
 
   .shrinkToFit {
     cursor: zoom-in;
+    width: 100%;
+    height: 100%;
+    object-fit: contain;
   }
 }
 
 @media print {
   /* We must declare the image as a block element. If we stay as
   an inline element, our parent LineBox will be inline too and
   ignore the available height during reflow.
   This is bad during printing, it means tall image frames won't know