Bug 1321885 - Add CSSPixel::FromAppUnits(nscoord) and CSSPixel::ToAppUnits(CSSCoord). r=kats draft
authorBotond Ballo <botond@mozilla.com>
Wed, 24 Aug 2016 13:42:57 -0400
changeset 447178 7fc17e00fddbdbe4856c08a78729e8467a1f9571
parent 447177 d7433ab7cdb949194e494568f0bf94b91639e27e
child 447179 b601b7e605c7ad0ba0d09c9c1e2405282fe0d700
push id38008
push userbballo@mozilla.com
push dateFri, 02 Dec 2016 22:13:11 +0000
reviewerskats
bugs1321885
milestone53.0a1
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())));