Bug 908726. Add AppUnits.h so we don't need nsDeviceContext.h for AppUnitsPerCSSPixel(). r=ehsan

This commit is contained in:
Jeff Muizelaar 2013-09-06 16:15:04 -04:00
parent 7a1dc33163
commit c18eea3d30
6 changed files with 49 additions and 30 deletions

View File

@ -8,6 +8,7 @@
#include "mozilla/Attributes.h"
#include "nsWrapperCache.h"
#include "nsAutoPtr.h"
#include "Units.h"
class nsPresContext;

11
gfx/src/AppUnits.h Normal file
View File

@ -0,0 +1,11 @@
/* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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 _NS_APPUNITS_H_
#define _NS_APPUNITS_H_
namespace mozilla {
static int32_t AppUnitsPerCSSPixel() { return 60; }
}
#endif /* _NS_APPUNITS_H_ */

View File

@ -34,6 +34,10 @@ EXPORTS += [
'nsTransform2D.h',
]
EXPORTS.mozilla += [
'AppUnits.h',
]
if CONFIG['MOZ_X11']:
EXPORTS.mozilla += ['X11Util.h']
CPP_SOURCES += [

View File

@ -17,6 +17,7 @@
#include "nsISupports.h" // for NS_INLINE_DECL_REFCOUNTING
#include "nsMathUtils.h" // for NS_round
#include "nscore.h" // for PRUnichar, nsAString
#include "mozilla/AppUnits.h" // for AppUnits
class gfxASurface;
class gfxUserFontSet;
@ -65,7 +66,7 @@ public:
* Gets the number of app units in one CSS pixel; this number is global,
* not unique to each device context.
*/
static int32_t AppUnitsPerCSSPixel() { return 60; }
static int32_t AppUnitsPerCSSPixel() { return mozilla::AppUnitsPerCSSPixel(); }
/**
* Gets the number of app units in one device pixel; this number

View File

@ -12,6 +12,7 @@
#include "mozilla/gfx/ScaleFactor.h"
#include "nsDeviceContext.h"
#include "nsRect.h"
#include "mozilla/AppUnits.h"
namespace mozilla {
@ -78,59 +79,59 @@ struct CSSPixel {
// Conversions from app units
static CSSPoint FromAppUnits(const nsPoint& aPoint) {
return CSSPoint(NSAppUnitsToFloatPixels(aPoint.x, float(nsDeviceContext::AppUnitsPerCSSPixel())),
NSAppUnitsToFloatPixels(aPoint.y, float(nsDeviceContext::AppUnitsPerCSSPixel())));
return CSSPoint(NSAppUnitsToFloatPixels(aPoint.x, float(AppUnitsPerCSSPixel())),
NSAppUnitsToFloatPixels(aPoint.y, float(AppUnitsPerCSSPixel())));
}
static CSSRect FromAppUnits(const nsRect& aRect) {
return CSSRect(NSAppUnitsToFloatPixels(aRect.x, float(nsDeviceContext::AppUnitsPerCSSPixel())),
NSAppUnitsToFloatPixels(aRect.y, float(nsDeviceContext::AppUnitsPerCSSPixel())),
NSAppUnitsToFloatPixels(aRect.width, float(nsDeviceContext::AppUnitsPerCSSPixel())),
NSAppUnitsToFloatPixels(aRect.height, float(nsDeviceContext::AppUnitsPerCSSPixel())));
return CSSRect(NSAppUnitsToFloatPixels(aRect.x, float(AppUnitsPerCSSPixel())),
NSAppUnitsToFloatPixels(aRect.y, float(AppUnitsPerCSSPixel())),
NSAppUnitsToFloatPixels(aRect.width, float(AppUnitsPerCSSPixel())),
NSAppUnitsToFloatPixels(aRect.height, float(AppUnitsPerCSSPixel())));
}
static CSSIntPoint FromAppUnitsRounded(const nsPoint& aPoint) {
return CSSIntPoint(NSAppUnitsToIntPixels(aPoint.x, float(nsDeviceContext::AppUnitsPerCSSPixel())),
NSAppUnitsToIntPixels(aPoint.y, float(nsDeviceContext::AppUnitsPerCSSPixel())));
return CSSIntPoint(NSAppUnitsToIntPixels(aPoint.x, float(AppUnitsPerCSSPixel())),
NSAppUnitsToIntPixels(aPoint.y, float(AppUnitsPerCSSPixel())));
}
static CSSIntSize FromAppUnitsRounded(const nsSize& aSize)
{
return CSSIntSize(NSAppUnitsToIntPixels(aSize.width, float(nsDeviceContext::AppUnitsPerCSSPixel())),
NSAppUnitsToIntPixels(aSize.height, float(nsDeviceContext::AppUnitsPerCSSPixel())));
return CSSIntSize(NSAppUnitsToIntPixels(aSize.width, float(AppUnitsPerCSSPixel())),
NSAppUnitsToIntPixels(aSize.height, float(AppUnitsPerCSSPixel())));
}
static CSSIntRect FromAppUnitsRounded(const nsRect& aRect) {
return CSSIntRect(NSAppUnitsToIntPixels(aRect.x, float(nsDeviceContext::AppUnitsPerCSSPixel())),
NSAppUnitsToIntPixels(aRect.y, float(nsDeviceContext::AppUnitsPerCSSPixel())),
NSAppUnitsToIntPixels(aRect.width, float(nsDeviceContext::AppUnitsPerCSSPixel())),
NSAppUnitsToIntPixels(aRect.height, float(nsDeviceContext::AppUnitsPerCSSPixel())));
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 nsPoint ToAppUnits(const CSSPoint& aPoint) {
return nsPoint(NSToCoordRoundWithClamp(aPoint.x * float(nsDeviceContext::AppUnitsPerCSSPixel())),
NSToCoordRoundWithClamp(aPoint.y * float(nsDeviceContext::AppUnitsPerCSSPixel())));
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(nsDeviceContext::AppUnitsPerCSSPixel())),
NSToCoordRoundWithClamp(float(aPoint.y) * float(nsDeviceContext::AppUnitsPerCSSPixel())));
return nsPoint(NSToCoordRoundWithClamp(float(aPoint.x) * float(AppUnitsPerCSSPixel())),
NSToCoordRoundWithClamp(float(aPoint.y) * float(AppUnitsPerCSSPixel())));
}
static nsRect ToAppUnits(const CSSRect& aRect) {
return nsRect(NSToCoordRoundWithClamp(aRect.x * float(nsDeviceContext::AppUnitsPerCSSPixel())),
NSToCoordRoundWithClamp(aRect.y * float(nsDeviceContext::AppUnitsPerCSSPixel())),
NSToCoordRoundWithClamp(aRect.width * float(nsDeviceContext::AppUnitsPerCSSPixel())),
NSToCoordRoundWithClamp(aRect.height * float(nsDeviceContext::AppUnitsPerCSSPixel())));
return nsRect(NSToCoordRoundWithClamp(aRect.x * float(AppUnitsPerCSSPixel())),
NSToCoordRoundWithClamp(aRect.y * float(AppUnitsPerCSSPixel())),
NSToCoordRoundWithClamp(aRect.width * float(AppUnitsPerCSSPixel())),
NSToCoordRoundWithClamp(aRect.height * float(AppUnitsPerCSSPixel())));
}
};
/*
* The pixels that are referred to as "device pixels" in layout code. In
* general this is obtained by converting a value in app units value by the
* nsDeviceContext::AppUnitsPerDevPixel() value. The size of these pixels
* AppUnitsPerDevPixel() value. The size of these pixels
* are affected by:
* 1) the "full zoom" (see nsPresContext::SetFullZoom)
* 2) the "widget scale" (see nsIWidget::GetDefaultScale)

View File

@ -32,6 +32,7 @@
#include "nsAutoPtr.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/AppUnits.h"
#include "prclist.h"
#include "nsThreadUtils.h"
#include "ScrollbarStyles.h"
@ -556,25 +557,25 @@ public:
*/
float ScreenWidthInchesForFontInflation(bool* aChanged = nullptr);
static int32_t AppUnitsPerCSSPixel() { return nsDeviceContext::AppUnitsPerCSSPixel(); }
static int32_t AppUnitsPerCSSPixel() { return mozilla::AppUnitsPerCSSPixel(); }
int32_t AppUnitsPerDevPixel() const { return mDeviceContext->AppUnitsPerDevPixel(); }
static int32_t AppUnitsPerCSSInch() { return nsDeviceContext::AppUnitsPerCSSInch(); }
static nscoord CSSPixelsToAppUnits(int32_t aPixels)
{ return NSToCoordRoundWithClamp(float(aPixels) *
float(nsDeviceContext::AppUnitsPerCSSPixel())); }
float(AppUnitsPerCSSPixel())); }
static nscoord CSSPixelsToAppUnits(float aPixels)
{ return NSToCoordRoundWithClamp(aPixels *
float(nsDeviceContext::AppUnitsPerCSSPixel())); }
float(AppUnitsPerCSSPixel())); }
static int32_t AppUnitsToIntCSSPixels(nscoord aAppUnits)
{ return NSAppUnitsToIntPixels(aAppUnits,
float(nsDeviceContext::AppUnitsPerCSSPixel())); }
float(AppUnitsPerCSSPixel())); }
static float AppUnitsToFloatCSSPixels(nscoord aAppUnits)
{ return NSAppUnitsToFloatPixels(aAppUnits,
float(nsDeviceContext::AppUnitsPerCSSPixel())); }
float(AppUnitsPerCSSPixel())); }
nscoord DevPixelsToAppUnits(int32_t aPixels) const
{ return NSIntPixelsToAppUnits(aPixels,
@ -582,7 +583,7 @@ public:
int32_t AppUnitsToDevPixels(nscoord aAppUnits) const
{ return NSAppUnitsToIntPixels(aAppUnits,
float(mDeviceContext->AppUnitsPerDevPixel())); }
float(AppUnitsPerDevPixel())); }
int32_t CSSPixelsToDevPixels(int32_t aPixels)
{ return AppUnitsToDevPixels(CSSPixelsToAppUnits(aPixels)); }