Bug 1680669 - part 2: Make point of CSSPixel and LayoutDevicePixel work within double coordinates r=botond
`MouseEvent` and its subclasses need to treat screen/client coordinates with `double` variables. Although for the backward compatibility, we'll keep rounding the value to integer, but we need to support lossless untrusted event creation. Therefore, they need to store the points with the new point types. Differential Revision: https://phabricator.services.mozilla.com/D222724
This commit is contained in:
@@ -85,23 +85,37 @@ struct MOZ_EMPTY_BASES IntPointTyped
|
|||||||
return IntPointTyped(int32_t(floorf(aX + 0.5f)),
|
return IntPointTyped(int32_t(floorf(aX + 0.5f)),
|
||||||
int32_t(floorf(aY + 0.5f)));
|
int32_t(floorf(aY + 0.5f)));
|
||||||
}
|
}
|
||||||
|
static IntPointTyped Round(double aX, double aY) {
|
||||||
|
return IntPointTyped(int32_t(floor(aX + 0.5)), int32_t(floor(aY + 0.5)));
|
||||||
|
}
|
||||||
|
|
||||||
static IntPointTyped Ceil(float aX, float aY) {
|
static IntPointTyped Ceil(float aX, float aY) {
|
||||||
return IntPointTyped(int32_t(ceilf(aX)), int32_t(ceilf(aY)));
|
return IntPointTyped(int32_t(ceilf(aX)), int32_t(ceilf(aY)));
|
||||||
}
|
}
|
||||||
|
static IntPointTyped Ceil(double aX, double aY) {
|
||||||
|
return IntPointTyped(int32_t(ceil(aX)), int32_t(ceil(aY)));
|
||||||
|
}
|
||||||
|
|
||||||
static IntPointTyped Floor(float aX, float aY) {
|
static IntPointTyped Floor(float aX, float aY) {
|
||||||
return IntPointTyped(int32_t(floorf(aX)), int32_t(floorf(aY)));
|
return IntPointTyped(int32_t(floorf(aX)), int32_t(floorf(aY)));
|
||||||
}
|
}
|
||||||
|
static IntPointTyped Floor(double aX, double aY) {
|
||||||
|
return IntPointTyped(int32_t(floor(aX)), int32_t(floor(aY)));
|
||||||
|
}
|
||||||
|
|
||||||
static IntPointTyped Truncate(float aX, float aY) {
|
template <typename F>
|
||||||
|
static IntPointTyped Truncate(F aX, F aY) {
|
||||||
return IntPointTyped(int32_t(aX), int32_t(aY));
|
return IntPointTyped(int32_t(aX), int32_t(aY));
|
||||||
}
|
}
|
||||||
|
|
||||||
static IntPointTyped Round(const PointTyped<Units, float>& aPoint);
|
template <typename F>
|
||||||
static IntPointTyped Ceil(const PointTyped<Units, float>& aPoint);
|
static IntPointTyped Round(const PointTyped<Units, F>& aPoint);
|
||||||
static IntPointTyped Floor(const PointTyped<Units, float>& aPoint);
|
template <typename F>
|
||||||
static IntPointTyped Truncate(const PointTyped<Units, float>& aPoint);
|
static IntPointTyped Ceil(const PointTyped<Units, F>& aPoint);
|
||||||
|
template <typename F>
|
||||||
|
static IntPointTyped Floor(const PointTyped<Units, F>& aPoint);
|
||||||
|
template <typename F>
|
||||||
|
static IntPointTyped Truncate(const PointTyped<Units, F>& aPoint);
|
||||||
|
|
||||||
// XXX When all of the code is ported, the following functions to convert to
|
// XXX When all of the code is ported, the following functions to convert to
|
||||||
// and from unknown types should be removed.
|
// and from unknown types should be removed.
|
||||||
@@ -165,13 +179,13 @@ struct MOZ_EMPTY_BASES PointTyped
|
|||||||
typedef PointTyped<UnknownUnits> Point;
|
typedef PointTyped<UnknownUnits> Point;
|
||||||
typedef PointTyped<UnknownUnits, double> PointDouble;
|
typedef PointTyped<UnknownUnits, double> PointDouble;
|
||||||
|
|
||||||
template <class Units>
|
template <class Units, class F>
|
||||||
IntPointTyped<Units> RoundedToInt(const PointTyped<Units>& aPoint) {
|
IntPointTyped<Units> RoundedToInt(const PointTyped<Units, F>& aPoint) {
|
||||||
return IntPointTyped<Units>::Round(aPoint.x, aPoint.y);
|
return IntPointTyped<Units>::Round(aPoint.x, aPoint.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Units>
|
template <class Units, class F>
|
||||||
IntPointTyped<Units> TruncatedToInt(const PointTyped<Units>& aPoint) {
|
IntPointTyped<Units> TruncatedToInt(const PointTyped<Units, F>& aPoint) {
|
||||||
return IntPointTyped<Units>::Truncate(aPoint.x, aPoint.y);
|
return IntPointTyped<Units>::Truncate(aPoint.x, aPoint.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,26 +218,30 @@ typedef Point3DTyped<UnknownUnits> Point3D;
|
|||||||
typedef Point3DTyped<UnknownUnits, double> PointDouble3D;
|
typedef Point3DTyped<UnknownUnits, double> PointDouble3D;
|
||||||
|
|
||||||
template <typename Units>
|
template <typename Units>
|
||||||
|
template <typename F>
|
||||||
IntPointTyped<Units> IntPointTyped<Units>::Round(
|
IntPointTyped<Units> IntPointTyped<Units>::Round(
|
||||||
const PointTyped<Units, float>& aPoint) {
|
const PointTyped<Units, F>& aPoint) {
|
||||||
return IntPointTyped::Round(aPoint.x, aPoint.y);
|
return IntPointTyped::Round(aPoint.x, aPoint.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Units>
|
template <typename Units>
|
||||||
|
template <typename F>
|
||||||
IntPointTyped<Units> IntPointTyped<Units>::Ceil(
|
IntPointTyped<Units> IntPointTyped<Units>::Ceil(
|
||||||
const PointTyped<Units, float>& aPoint) {
|
const PointTyped<Units, F>& aPoint) {
|
||||||
return IntPointTyped::Ceil(aPoint.x, aPoint.y);
|
return IntPointTyped::Ceil(aPoint.x, aPoint.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Units>
|
template <typename Units>
|
||||||
|
template <typename F>
|
||||||
IntPointTyped<Units> IntPointTyped<Units>::Floor(
|
IntPointTyped<Units> IntPointTyped<Units>::Floor(
|
||||||
const PointTyped<Units, float>& aPoint) {
|
const PointTyped<Units, F>& aPoint) {
|
||||||
return IntPointTyped::Floor(aPoint.x, aPoint.y);
|
return IntPointTyped::Floor(aPoint.x, aPoint.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Units>
|
template <typename Units>
|
||||||
|
template <typename F>
|
||||||
IntPointTyped<Units> IntPointTyped<Units>::Truncate(
|
IntPointTyped<Units> IntPointTyped<Units>::Truncate(
|
||||||
const PointTyped<Units, float>& aPoint) {
|
const PointTyped<Units, F>& aPoint) {
|
||||||
return IntPointTyped::Truncate(aPoint.x, aPoint.y);
|
return IntPointTyped::Truncate(aPoint.x, aPoint.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -319,6 +319,11 @@ inline nscoord NSFloatPixelsToAppUnits(float aPixels, float aAppUnitsPerPixel) {
|
|||||||
return NSToCoordRoundWithClamp(aPixels * aAppUnitsPerPixel);
|
return NSToCoordRoundWithClamp(aPixels * aAppUnitsPerPixel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline nscoord NSDoublePixelsToAppUnits(double aPixels,
|
||||||
|
double aAppUnitsPerPixel) {
|
||||||
|
return NSToCoordRoundWithClamp(aPixels * aAppUnitsPerPixel);
|
||||||
|
}
|
||||||
|
|
||||||
inline nscoord NSIntPixelsToAppUnits(int32_t aPixels,
|
inline nscoord NSIntPixelsToAppUnits(int32_t aPixels,
|
||||||
int32_t aAppUnitsPerPixel) {
|
int32_t aAppUnitsPerPixel) {
|
||||||
// The cast to nscoord makes sure we don't overflow if we ever change
|
// The cast to nscoord makes sure we don't overflow if we ever change
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ struct IsPixel<ExternalPixel> : std::true_type {};
|
|||||||
|
|
||||||
typedef gfx::CoordTyped<CSSPixel> CSSCoord;
|
typedef gfx::CoordTyped<CSSPixel> CSSCoord;
|
||||||
typedef gfx::IntCoordTyped<CSSPixel> CSSIntCoord;
|
typedef gfx::IntCoordTyped<CSSPixel> CSSIntCoord;
|
||||||
|
typedef gfx::PointTyped<CSSPixel, double> CSSDoublePoint;
|
||||||
typedef gfx::PointTyped<CSSPixel> CSSPoint;
|
typedef gfx::PointTyped<CSSPixel> CSSPoint;
|
||||||
typedef gfx::IntPointTyped<CSSPixel> CSSIntPoint;
|
typedef gfx::IntPointTyped<CSSPixel> CSSIntPoint;
|
||||||
typedef gfx::SizeTyped<CSSPixel> CSSSize;
|
typedef gfx::SizeTyped<CSSPixel> CSSSize;
|
||||||
@@ -85,8 +86,10 @@ typedef gfx::MarginTyped<OuterCSSPixel> OuterCSSMargin;
|
|||||||
typedef gfx::IntMarginTyped<OuterCSSPixel> OuterCSSIntMargin;
|
typedef gfx::IntMarginTyped<OuterCSSPixel> OuterCSSIntMargin;
|
||||||
typedef gfx::IntRegionTyped<OuterCSSPixel> OuterCSSIntRegion;
|
typedef gfx::IntRegionTyped<OuterCSSPixel> OuterCSSIntRegion;
|
||||||
|
|
||||||
|
typedef gfx::CoordTyped<LayoutDevicePixel, double> LayoutDeviceDoubleCoord;
|
||||||
typedef gfx::CoordTyped<LayoutDevicePixel> LayoutDeviceCoord;
|
typedef gfx::CoordTyped<LayoutDevicePixel> LayoutDeviceCoord;
|
||||||
typedef gfx::IntCoordTyped<LayoutDevicePixel> LayoutDeviceIntCoord;
|
typedef gfx::IntCoordTyped<LayoutDevicePixel> LayoutDeviceIntCoord;
|
||||||
|
typedef gfx::PointTyped<LayoutDevicePixel, double> LayoutDeviceDoublePoint;
|
||||||
typedef gfx::PointTyped<LayoutDevicePixel> LayoutDevicePoint;
|
typedef gfx::PointTyped<LayoutDevicePixel> LayoutDevicePoint;
|
||||||
typedef gfx::IntPointTyped<LayoutDevicePixel> LayoutDeviceIntPoint;
|
typedef gfx::IntPointTyped<LayoutDevicePixel> LayoutDeviceIntPoint;
|
||||||
typedef gfx::SizeTyped<LayoutDevicePixel> LayoutDeviceSize;
|
typedef gfx::SizeTyped<LayoutDevicePixel> LayoutDeviceSize;
|
||||||
@@ -548,12 +551,33 @@ struct LayoutDevicePixel {
|
|||||||
return ToAppUnits(LayoutDeviceCoord(aCoord), aAppUnitsPerDevPixel);
|
return ToAppUnits(LayoutDeviceCoord(aCoord), aAppUnitsPerDevPixel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static nscoord ToAppUnits(double aCoord, nscoord aAppUnitsPerDevPixel) {
|
||||||
|
return ToAppUnits(LayoutDeviceDoubleCoord(aCoord), aAppUnitsPerDevPixel);
|
||||||
|
}
|
||||||
|
|
||||||
|
static nscoord ToAppUnits(LayoutDeviceDoubleCoord aCoord,
|
||||||
|
nscoord aAppUnitsPerDevPixel) {
|
||||||
|
return NSDoublePixelsToAppUnits(aCoord, aAppUnitsPerDevPixel);
|
||||||
|
}
|
||||||
|
|
||||||
static nsPoint ToAppUnits(const LayoutDeviceIntPoint& aPoint,
|
static nsPoint ToAppUnits(const LayoutDeviceIntPoint& aPoint,
|
||||||
nscoord aAppUnitsPerDevPixel) {
|
nscoord aAppUnitsPerDevPixel) {
|
||||||
return nsPoint(ToAppUnits(aPoint.x, aAppUnitsPerDevPixel),
|
return nsPoint(ToAppUnits(aPoint.x, aAppUnitsPerDevPixel),
|
||||||
ToAppUnits(aPoint.y, aAppUnitsPerDevPixel));
|
ToAppUnits(aPoint.y, aAppUnitsPerDevPixel));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static nsPoint ToAppUnits(const LayoutDevicePoint& aPoint,
|
||||||
|
nscoord aAppUnitsPerDevPixel) {
|
||||||
|
return nsPoint(ToAppUnits(aPoint.x, aAppUnitsPerDevPixel),
|
||||||
|
ToAppUnits(aPoint.y, aAppUnitsPerDevPixel));
|
||||||
|
}
|
||||||
|
|
||||||
|
static nsPoint ToAppUnits(const LayoutDeviceDoublePoint& aPoint,
|
||||||
|
nscoord aAppUnitsPerDevPixel) {
|
||||||
|
return nsPoint(ToAppUnits(aPoint.x, aAppUnitsPerDevPixel),
|
||||||
|
ToAppUnits(aPoint.y, aAppUnitsPerDevPixel));
|
||||||
|
}
|
||||||
|
|
||||||
static nsSize ToAppUnits(const LayoutDeviceIntSize& aSize,
|
static nsSize ToAppUnits(const LayoutDeviceIntSize& aSize,
|
||||||
nscoord aAppUnitsPerDevPixel) {
|
nscoord aAppUnitsPerDevPixel) {
|
||||||
return nsSize(ToAppUnits(aSize.width, aAppUnitsPerDevPixel),
|
return nsSize(ToAppUnits(aSize.width, aAppUnitsPerDevPixel),
|
||||||
@@ -692,16 +716,18 @@ gfx::CoordTyped<Dst> operator/(const gfx::CoordTyped<Src>& aCoord,
|
|||||||
return gfx::CoordTyped<Dst>(aCoord.value / aScale.scale);
|
return gfx::CoordTyped<Dst>(aCoord.value / aScale.scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Src, class Dst>
|
template <class Src, class Dst, class F>
|
||||||
gfx::PointTyped<Dst> operator*(const gfx::PointTyped<Src>& aPoint,
|
gfx::PointTyped<Dst, F> operator*(const gfx::PointTyped<Src, F>& aPoint,
|
||||||
const gfx::ScaleFactor<Src, Dst>& aScale) {
|
const gfx::ScaleFactor<Src, Dst>& aScale) {
|
||||||
return gfx::PointTyped<Dst>(aPoint.x * aScale.scale, aPoint.y * aScale.scale);
|
return gfx::PointTyped<Dst, F>(aPoint.x * aScale.scale,
|
||||||
|
aPoint.y * aScale.scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Src, class Dst>
|
template <class Src, class Dst, class F>
|
||||||
gfx::PointTyped<Dst> operator/(const gfx::PointTyped<Src>& aPoint,
|
gfx::PointTyped<Dst, F> operator/(const gfx::PointTyped<Src, F>& aPoint,
|
||||||
const gfx::ScaleFactor<Dst, Src>& aScale) {
|
const gfx::ScaleFactor<Dst, Src>& aScale) {
|
||||||
return gfx::PointTyped<Dst>(aPoint.x / aScale.scale, aPoint.y / aScale.scale);
|
return gfx::PointTyped<Dst, F>(aPoint.x / aScale.scale,
|
||||||
|
aPoint.y / aScale.scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Src, class Dst, class F>
|
template <class Src, class Dst, class F>
|
||||||
|
|||||||
Reference in New Issue
Block a user