Bug 878874 - Introduce CSSIntPoint and use it for HTMLImageElement::GetXY(); r=kats
authorMs2ger <ms2ger@gmail.com>
Wed, 12 Jun 2013 09:00:08 +0200
changeset 134708 67a6841cbe3d784191d9f4fd2557749b3a630e91
parent 134707 4eba1004b5ebaf48aef4cb96caab9d079fdd06b1
child 134709 d4187b2c17fbb29e0820472cb9f9ec7d30198541
push id24811
push userMs2ger@gmail.com
push dateWed, 12 Jun 2013 07:00:25 +0000
treeherdermozilla-central@0414d6d0f60d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs878874
milestone24.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 878874 - Introduce CSSIntPoint and use it for HTMLImageElement::GetXY(); r=kats
content/html/content/src/HTMLImageElement.cpp
content/html/content/src/HTMLImageElement.h
layout/base/Units.h
--- a/content/html/content/src/HTMLImageElement.cpp
+++ b/content/html/content/src/HTMLImageElement.cpp
@@ -153,34 +153,26 @@ HTMLImageElement::GetComplete(bool* aCom
 {
   NS_PRECONDITION(aComplete, "Null out param!");
 
   *aComplete = Complete();
 
   return NS_OK;
 }
 
-nsIntPoint
+CSSIntPoint
 HTMLImageElement::GetXY()
 {
-  nsIntPoint point(0, 0);
-
   nsIFrame* frame = GetPrimaryFrame(Flush_Layout);
-
   if (!frame) {
-    return point;
+    return CSSIntPoint(0, 0);
   }
 
   nsIFrame* layer = nsLayoutUtils::GetClosestLayer(frame->GetParent());
-  nsPoint origin(frame->GetOffsetTo(layer));
-  // Convert to pixels using that scale
-  point.x = nsPresContext::AppUnitsToIntCSSPixels(origin.x);
-  point.y = nsPresContext::AppUnitsToIntCSSPixels(origin.y);
-
-  return point;
+  return CSSIntPoint::FromAppUnitsRounded(frame->GetOffsetTo(layer));
 }
 
 int32_t
 HTMLImageElement::X()
 {
   return GetXY().x;
 }
 
--- a/content/html/content/src/HTMLImageElement.h
+++ b/content/html/content/src/HTMLImageElement.h
@@ -6,16 +6,17 @@
 #ifndef mozilla_dom_HTMLImageElement_h
 #define mozilla_dom_HTMLImageElement_h
 
 #include "mozilla/Attributes.h"
 #include "nsGenericHTMLElement.h"
 #include "nsImageLoadingContent.h"
 #include "nsIDOMHTMLImageElement.h"
 #include "imgRequestProxy.h"
+#include "Units.h"
 
 namespace mozilla {
 namespace dom {
 
 class HTMLImageElement MOZ_FINAL : public nsGenericHTMLElement,
                                    public nsImageLoadingContent,
                                    public nsIDOMHTMLImageElement
 {
@@ -169,17 +170,17 @@ public:
   int32_t Y();
   // Uses XPCOM GetLowsrc.
   void SetLowsrc(const nsAString& aLowsrc, ErrorResult& aError)
   {
     SetHTMLAttr(nsGkAtoms::lowsrc, aLowsrc, aError);
   }
 
 protected:
-  nsIntPoint GetXY();
+  CSSIntPoint GetXY();
   virtual void GetItemValueText(nsAString& text) MOZ_OVERRIDE;
   virtual void SetItemValueText(const nsAString& text) MOZ_OVERRIDE;
   virtual JSObject* WrapNode(JSContext *aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 };
 
 } // namespace dom
 } // namespace mozilla
--- a/layout/base/Units.h
+++ b/layout/base/Units.h
@@ -1,10 +1,11 @@
-/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- * This Source Code Form is subject to the terms of the Mozilla Public
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZ_UNITS_H_
 #define MOZ_UNITS_H_
 
 #include "mozilla/gfx/Point.h"
 #include "nsDeviceContext.h"
@@ -20,21 +21,32 @@ struct CSSPixel {
                                         NS_lround(aPoint.y));
   }
 
   static gfx::PointTyped<CSSPixel> FromAppUnits(const nsPoint& aPoint) {
     return gfx::PointTyped<CSSPixel>(NSAppUnitsToFloatPixels(aPoint.x, float(nsDeviceContext::AppUnitsPerCSSPixel())),
                                      NSAppUnitsToFloatPixels(aPoint.y, float(nsDeviceContext::AppUnitsPerCSSPixel())));
   }
 
+  static gfx::IntPointTyped<CSSPixel> FromAppUnitsRounded(const nsPoint& aPoint) {
+    return gfx::IntPointTyped<CSSPixel>(NSAppUnitsToIntPixels(aPoint.x, float(nsDeviceContext::AppUnitsPerCSSPixel())),
+                                        NSAppUnitsToIntPixels(aPoint.y, float(nsDeviceContext::AppUnitsPerCSSPixel())));
+  }
+
   static nsPoint ToAppUnits(const gfx::PointTyped<CSSPixel>& aPoint) {
     return nsPoint(NSFloatPixelsToAppUnits(aPoint.x, float(nsDeviceContext::AppUnitsPerCSSPixel())),
                    NSFloatPixelsToAppUnits(aPoint.y, float(nsDeviceContext::AppUnitsPerCSSPixel())));
   }
 
+  static nsPoint ToAppUnits(const gfx::IntPointTyped<CSSPixel>& aPoint)
+  {
+    return nsPoint(NSIntPixelsToAppUnits(aPoint.x, nsDeviceContext::AppUnitsPerCSSPixel()),
+                   NSIntPixelsToAppUnits(aPoint.y, nsDeviceContext::AppUnitsPerCSSPixel()));
+  }
+
   static gfx::RectTyped<CSSPixel> FromAppUnits(const nsRect& aRect) {
     return gfx::RectTyped<CSSPixel>(NSAppUnitsToFloatPixels(aRect.x, float(nsDeviceContext::AppUnitsPerCSSPixel())),
                                     NSAppUnitsToFloatPixels(aRect.y, float(nsDeviceContext::AppUnitsPerCSSPixel())),
                                     NSAppUnitsToFloatPixels(aRect.width, float(nsDeviceContext::AppUnitsPerCSSPixel())),
                                     NSAppUnitsToFloatPixels(aRect.height, float(nsDeviceContext::AppUnitsPerCSSPixel())));
   }
 
   static nsRect ToAppUnits(const gfx::RectTyped<CSSPixel>& aRect) {