Bug 840693 - Add ZoomScale; r=Bas

This commit is contained in:
Anthony Jones 2013-03-04 13:25:22 +13:00
parent 2b1c72f15c
commit a2f7f5b486
7 changed files with 131 additions and 6 deletions

View File

@ -9,6 +9,7 @@
#include "Types.h"
#include "Point.h"
#include "Rect.h"
#include "ZoomScale.h"
#include "Matrix.h"
#include "UserData.h"
// This RefPtr class isn't ideal for usage in Azure, as it doesn't allow T**

View File

@ -33,6 +33,7 @@ EXPORTS_mozilla/gfx = \
Types.h \
Tools.h \
UserData.h \
ZoomScale.h \
$(NULL)
CPPSRCS = \

View File

@ -27,7 +27,7 @@ struct Point :
Point() : Super() {}
Point(Float aX, Float aY) : Super(aX, aY) {}
Point(const IntPoint& point) : Super(float(point.x), float(point.y)) {}
Point(const IntPoint& point) : Super(Float(point.x), Float(point.y)) {}
};
struct IntSize :
@ -45,7 +45,7 @@ struct Size :
Size() : Super() {}
Size(Float aWidth, Float aHeight) : Super(aWidth, aHeight) {}
explicit Size(const IntSize& size) :
Super(float(size.width), float(size.height)) {}
Super(Float(size.width), Float(size.height)) {}
};
}

View File

@ -25,7 +25,7 @@ struct Margin :
struct IntRect :
public BaseRect<int32_t, IntRect, IntPoint, IntSize, Margin> {
typedef BaseRect<int32_t, IntRect, IntPoint, mozilla::gfx::IntSize, Margin> Super;
typedef BaseRect<int32_t, IntRect, IntPoint, IntSize, Margin> Super;
IntRect() : Super() {}
IntRect(IntPoint aPos, mozilla::gfx::IntSize aSize) :
@ -49,15 +49,15 @@ struct Rect :
Rect(Float _x, Float _y, Float _width, Float _height) :
Super(_x, _y, _width, _height) {}
explicit Rect(const IntRect& rect) :
Super(float(rect.x), float(rect.y),
float(rect.width), float(rect.height)) {}
Super(Float(rect.x), Float(rect.y),
Float(rect.width), Float(rect.height)) {}
GFX2D_API void NudgeToIntegers();
bool ToIntRect(IntRect *aOut)
{
*aOut = IntRect(int32_t(X()), int32_t(Y()),
int32_t(Width()), int32_t(Height()));
int32_t(Width()), int32_t(Height()));
return Rect(Float(aOut->x), Float(aOut->y),
Float(aOut->width), Float(aOut->height)).IsEqualEdges(*this);
}

63
gfx/2d/ZoomScale.h Normal file
View File

@ -0,0 +1,63 @@
/* -*- 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
* 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 MOZILLA_GFX_ZOOM_SCALE_H_
#define MOZILLA_GFX_ZOOM_SCALE_H_
#include "Point.h"
#include "Rect.h"
namespace mozilla {
namespace gfx {
struct ZoomScale :
public BaseSize<Float, ZoomScale> {
typedef BaseSize<Float, ZoomScale> Super;
ZoomScale() : Super(1, 1) {}
ZoomScale(Float aWidth, Float aHeight) : Super(aWidth, aHeight) {}
};
inline Point
operator*(const Point& aPoint, const ZoomScale& aSize)
{
return Point(aPoint.x * aSize.width, aPoint.y * aSize.height);
}
inline Rect
operator*(const Rect& aValue, const ZoomScale& aScale)
{
return Rect(aValue.x * aScale.width,
aValue.y * aScale.height,
aValue.width * aScale.width,
aValue.height * aScale.height);
}
inline Point
operator/(const Point& aPoint, const ZoomScale& aSize)
{
return Point(aPoint.x / aSize.width, aPoint.y / aSize.height);
}
inline ZoomScale
operator/(Float aValue, const ZoomScale& aSize)
{
return ZoomScale(aValue / aSize.width, aValue / aSize.height);
}
inline Rect
operator/(const Rect& aValue, const ZoomScale& aScale)
{
return Rect(aValue.x / aScale.width,
aValue.y / aScale.height,
aValue.width / aScale.width,
aValue.height / aScale.height);
}
}
}
#endif /* MOZILLA_GFX_ZOOMSCALE_H_ */

View File

@ -30,6 +30,11 @@ inline Rect ToRect(const gfxRect &aRect)
Float(aRect.width), Float(aRect.height));
}
inline IntRect ToIntRect(const nsIntRect &aRect)
{
return IntRect(aRect.x, aRect.y, aRect.width, aRect.height);
}
inline Color ToColor(const gfxRGBA &aRGBA)
{
return Color(Float(aRGBA.r), Float(aRGBA.g),
@ -47,11 +52,21 @@ inline Point ToPoint(const gfxPoint &aPoint)
return Point(Float(aPoint.x), Float(aPoint.y));
}
inline IntPoint ToIntPoint(const nsIntPoint &aPoint)
{
return IntPoint(aPoint.x, aPoint.y);
}
inline Size ToSize(const gfxSize &aSize)
{
return Size(Float(aSize.width), Float(aSize.height));
}
inline IntSize ToIntSize(const nsIntSize &aSize)
{
return IntSize(aSize.width, aSize.height);
}
inline Filter ToFilter(gfxPattern::GraphicsFilter aFilter)
{
switch (aFilter) {
@ -116,6 +131,11 @@ inline gfxRect ThebesRect(const Rect &aRect)
return gfxRect(aRect.x, aRect.y, aRect.width, aRect.height);
}
inline gfxRect ThebesRect(const IntRect &aRect)
{
return gfxRect(aRect.x, aRect.y, aRect.width, aRect.height);
}
inline gfxRGBA ThebesRGBA(const Color &aColor)
{
return gfxRGBA(aColor.r, aColor.g, aColor.b, aColor.a);

View File

@ -814,6 +814,24 @@ struct ParamTraits<mozilla::gfx::Size>
}
};
template<>
struct ParamTraits<mozilla::gfx::ZoomScale>
{
typedef mozilla::gfx::ZoomScale paramType;
static void Write(Message* msg, const paramType& param)
{
WriteParam(msg, param.width);
WriteParam(msg, param.height);
}
static bool Read(const Message* msg, void** iter, paramType* result)
{
return (ReadParam(msg, iter, &result->width) &&
ReadParam(msg, iter, &result->height));
}
};
template<>
struct ParamTraits<mozilla::gfx::Rect>
{
@ -836,6 +854,28 @@ struct ParamTraits<mozilla::gfx::Rect>
}
};
template<>
struct ParamTraits<mozilla::gfx::IntRect>
{
typedef mozilla::gfx::IntRect paramType;
static void Write(Message* msg, const paramType& param)
{
WriteParam(msg, param.x);
WriteParam(msg, param.y);
WriteParam(msg, param.width);
WriteParam(msg, param.height);
}
static bool Read(const Message* msg, void** iter, paramType* result)
{
return (ReadParam(msg, iter, &result->x) &&
ReadParam(msg, iter, &result->y) &&
ReadParam(msg, iter, &result->width) &&
ReadParam(msg, iter, &result->height));
}
};
template<>
struct ParamTraits<nsRect>
{