Bug 1321885 - Add CSSPixel::FromAppUnits(nscoord) and CSSPixel::ToAppUnits(CSSCoord). r=kats
authorBotond Ballo <botond@mozilla.com>
Wed, 24 Aug 2016 13:42:57 -0400
changeset 326196 ec3c08351f9e283508524457577a92d18f85ddb7
parent 326195 c11569440ccc1e5410dfd1c31be411b3ef46cc03
child 326197 9a5631f0b921b2caa9911f0c95ee970538332a6f
push id35173
push userbballo@mozilla.com
push dateFri, 16 Dec 2016 21:18:50 +0000
treeherderautoland@9e2e68bf4103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1321885
milestone53.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 1321885 - Add CSSPixel::FromAppUnits(nscoord) and CSSPixel::ToAppUnits(CSSCoord). r=kats MozReview-Commit-ID: 8V9gjVf35bC
layout/base/Units.h
--- a/layout/base/Units.h
+++ b/layout/base/Units.h
@@ -189,16 +189,20 @@ typedef gfx::Matrix4x4Typed<ParentLayerP
 
 /*
  * The pixels that content authors use to specify sizes in.
  */
 struct CSSPixel {
 
   // Conversions from app units
 
+  static CSSCoord FromAppUnits(nscoord aCoord) {
+    return NSAppUnitsToFloatPixels(aCoord, float(AppUnitsPerCSSPixel()));
+  }
+
   static CSSPoint FromAppUnits(const nsPoint& aPoint) {
     return CSSPoint(NSAppUnitsToFloatPixels(aPoint.x, float(AppUnitsPerCSSPixel())),
                     NSAppUnitsToFloatPixels(aPoint.y, float(AppUnitsPerCSSPixel())));
   }
 
   static CSSSize FromAppUnits(const nsSize& aSize) {
     return CSSSize(NSAppUnitsToFloatPixels(aSize.width, float(AppUnitsPerCSSPixel())),
                    NSAppUnitsToFloatPixels(aSize.height, float(AppUnitsPerCSSPixel())));
@@ -233,16 +237,20 @@ struct CSSPixel {
     return CSSIntRect(NSAppUnitsToIntPixels(aRect.x, float(AppUnitsPerCSSPixel())),
                       NSAppUnitsToIntPixels(aRect.y, float(AppUnitsPerCSSPixel())),
                       NSAppUnitsToIntPixels(aRect.width, float(AppUnitsPerCSSPixel())),
                       NSAppUnitsToIntPixels(aRect.height, float(AppUnitsPerCSSPixel())));
   }
 
   // Conversions to app units
 
+  static nscoord ToAppUnits(CSSCoord aCoord) {
+    return NSToCoordRoundWithClamp(aCoord * float(AppUnitsPerCSSPixel()));
+  }
+
   static nsPoint ToAppUnits(const CSSPoint& aPoint) {
     return nsPoint(NSToCoordRoundWithClamp(aPoint.x * float(AppUnitsPerCSSPixel())),
                    NSToCoordRoundWithClamp(aPoint.y * float(AppUnitsPerCSSPixel())));
   }
 
   static nsPoint ToAppUnits(const CSSIntPoint& aPoint) {
     return nsPoint(NSToCoordRoundWithClamp(float(aPoint.x) * float(AppUnitsPerCSSPixel())),
                    NSToCoordRoundWithClamp(float(aPoint.y) * float(AppUnitsPerCSSPixel())));