Bug 1547126: Give nsIFrame::IntrinsicSize a convenience constructor that takes nscoord-valued width and height. r=TYLin
authorDaniel Holbert <dholbert@cs.stanford.edu>
Thu, 25 Apr 2019 23:44:53 +0000
changeset 530214 1a704e5e6a3c34f12e4a4ae8f9f02777923e6637
parent 530213 40ea57b797361a235108d15d7818ca2f34152e72
child 530215 719a4a6e31b29456e691a08c263fedeae81ab166
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersTYLin
bugs1547126
milestone68.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 1547126: Give nsIFrame::IntrinsicSize a convenience constructor that takes nscoord-valued width and height. r=TYLin This patch shouldn't affect behavior; it's just simplifying existing code with a new convenience constructor. Differential Revision: https://phabricator.services.mozilla.com/D28918
layout/generic/nsHTMLCanvasFrame.cpp
layout/generic/nsIFrame.h
layout/generic/nsVideoFrame.cpp
--- a/layout/generic/nsHTMLCanvasFrame.cpp
+++ b/layout/generic/nsHTMLCanvasFrame.cpp
@@ -34,23 +34,19 @@ using namespace mozilla::gfx;
  * indirect calls to GetCanvasSize().
  *
  * @param aCanvasSizeInPx The canvas's size in CSS pixels, as returned
  *                        by GetCanvasSize().
  * @return The canvas's intrinsic size, as an IntrinsicSize object.
  */
 static IntrinsicSize IntrinsicSizeFromCanvasSize(
     const nsIntSize& aCanvasSizeInPx) {
-  IntrinsicSize intrinsicSize;
-  intrinsicSize.width.SetCoordValue(
-      nsPresContext::CSSPixelsToAppUnits(aCanvasSizeInPx.width));
-  intrinsicSize.height.SetCoordValue(
+  return IntrinsicSize(
+      nsPresContext::CSSPixelsToAppUnits(aCanvasSizeInPx.width),
       nsPresContext::CSSPixelsToAppUnits(aCanvasSizeInPx.height));
-
-  return intrinsicSize;
 }
 
 /* Helper for our nsIFrame::GetIntrinsicRatio() impl. Takes the result of
  * "GetCanvasSize()" as a parameter, which may help avoid redundant
  * indirect calls to GetCanvasSize().
  *
  * @param aCanvasSizeInPx The canvas's size in CSS pixels, as returned
  *                        by GetCanvasSize().
--- a/layout/generic/nsIFrame.h
+++ b/layout/generic/nsIFrame.h
@@ -471,16 +471,20 @@ enum class AlignmentContext {
  *
  *   eStyleUnit_Coord   - a length in app units
  *   eStyleUnit_None    - the element has no intrinsic size in this dimension
  */
 struct IntrinsicSize {
   nsStyleCoord width, height;
 
   IntrinsicSize() : width(eStyleUnit_None), height(eStyleUnit_None) {}
+  IntrinsicSize(nscoord aWidth, nscoord aHeight)
+      : width(aWidth, nsStyleCoord::CoordConstructor),
+        height(aHeight, nsStyleCoord::CoordConstructor) {}
+
   IntrinsicSize(const IntrinsicSize& rhs)
       : width(rhs.width), height(rhs.height) {}
   IntrinsicSize& operator=(const IntrinsicSize& rhs) {
     width = rhs.width;
     height = rhs.height;
     return *this;
   }
   bool operator==(const IntrinsicSize& rhs) {
--- a/layout/generic/nsVideoFrame.cpp
+++ b/layout/generic/nsVideoFrame.cpp
@@ -186,19 +186,17 @@ already_AddRefed<Layer> nsVideoFrame::Bu
     return nullptr;
   }
 
   // Convert video size from pixel units into app units, to get an aspect-ratio
   // (which has to be represented as a nsSize) and an IntrinsicSize that we
   // can pass to ComputeObjectRenderRect.
   nsSize aspectRatio(nsPresContext::CSSPixelsToAppUnits(videoSizeInPx.width),
                      nsPresContext::CSSPixelsToAppUnits(videoSizeInPx.height));
-  IntrinsicSize intrinsicSize;
-  intrinsicSize.width.SetCoordValue(aspectRatio.width);
-  intrinsicSize.height.SetCoordValue(aspectRatio.height);
+  IntrinsicSize intrinsicSize(aspectRatio.width, aspectRatio.height);
 
   nsRect dest = nsLayoutUtils::ComputeObjectDestRect(
       area, intrinsicSize, aspectRatio, StylePosition());
 
   gfxRect destGFXRect = PresContext()->AppUnitsToGfxUnits(dest);
   destGFXRect.Round();
   if (destGFXRect.IsEmpty()) {
     return nullptr;
@@ -431,19 +429,17 @@ class nsDisplayVideo : public nsDisplayI
     }
 
     // Convert video size from pixel units into app units, to get an
     // aspect-ratio (which has to be represented as a nsSize) and an
     // IntrinsicSize that we can pass to ComputeObjectRenderRect.
     nsSize aspectRatio(
         nsPresContext::CSSPixelsToAppUnits(videoSizeInPx.width),
         nsPresContext::CSSPixelsToAppUnits(videoSizeInPx.height));
-    IntrinsicSize intrinsicSize;
-    intrinsicSize.width.SetCoordValue(aspectRatio.width);
-    intrinsicSize.height.SetCoordValue(aspectRatio.height);
+    IntrinsicSize intrinsicSize(aspectRatio.width, aspectRatio.height);
 
     nsRect dest = nsLayoutUtils::ComputeObjectDestRect(
         area, intrinsicSize, aspectRatio, Frame()->StylePosition());
 
     gfxRect destGFXRect = Frame()->PresContext()->AppUnitsToGfxUnits(dest);
     destGFXRect.Round();
     if (destGFXRect.IsEmpty()) {
       return true;
@@ -569,20 +565,17 @@ LogicalSize nsVideoFrame::ComputeSize(
     ComputeSizeFlags aFlags) {
   if (!HasVideoElement()) {
     return nsContainerFrame::ComputeSize(aRenderingContext, aWM, aCBSize,
                                          aAvailableISize, aMargin, aBorder,
                                          aPadding, aFlags);
   }
 
   nsSize size = GetVideoIntrinsicSize(aRenderingContext);
-
-  IntrinsicSize intrinsicSize;
-  intrinsicSize.width.SetCoordValue(size.width);
-  intrinsicSize.height.SetCoordValue(size.height);
+  IntrinsicSize intrinsicSize(size.width, size.height);
 
   // Only video elements have an intrinsic ratio.
   nsSize intrinsicRatio = HasVideoElement() ? size : nsSize(0, 0);
 
   return ComputeSizeWithIntrinsicDimensions(
       aRenderingContext, aWM, intrinsicSize, intrinsicRatio, aCBSize, aMargin,
       aBorder, aPadding, aFlags);
 }