Bug 1145903 - Use CSS to shrinkToFit instead of a racy set of width/height on the image frame. r=tnikkel
☠☠ backed out by 34c4f2fb86e9 ☠ ☠
authorBenoit Girard <b56girard@gmail.com>
Mon, 22 Feb 2016 19:02:26 -0500
changeset 285740 93f722efcdecf28ac74eddf36abd17697c06cfc7
parent 285739 aea0d27779b26d90a12efcf2b7627805ac5f022a
child 285741 96077e578f26548b467e1ebc2decad451e9be467
push id72507
push userb56girard@gmail.com
push dateFri, 26 Feb 2016 16:49:10 +0000
treeherdermozilla-inbound@93f722efcdec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstnikkel
bugs1145903
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1145903 - Use CSS to shrinkToFit instead of a racy set of width/height on the image frame. r=tnikkel 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
@@ -334,22 +334,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