зеркало из https://github.com/mozilla/gecko-dev.git
Bug 4821: Implement page zoom (backend). r+sr=roc.
This commit is contained in:
Родитель
b58e3e6cf1
Коммит
0881e734d3
|
@ -135,12 +135,13 @@ nsPoint nsDOMUIEvent::GetScreenPoint() {
|
|||
if (!((nsGUIEvent*)mEvent)->widget ) {
|
||||
return mEvent->refPoint;
|
||||
}
|
||||
|
||||
|
||||
nsRect bounds(mEvent->refPoint, nsSize(1, 1));
|
||||
nsRect offset;
|
||||
((nsGUIEvent*)mEvent)->widget->WidgetToScreen ( bounds, offset );
|
||||
return nsPoint(nsPresContext::AppUnitsToIntCSSPixels(mPresContext->DevPixelsToAppUnits(offset.x)),
|
||||
nsPresContext::AppUnitsToIntCSSPixels(mPresContext->DevPixelsToAppUnits(offset.y)));
|
||||
PRInt32 factor = mPresContext->DeviceContext()->UnscaledAppUnitsPerDevPixel();
|
||||
return nsPoint(nsPresContext::AppUnitsToIntCSSPixels(offset.x * factor),
|
||||
nsPresContext::AppUnitsToIntCSSPixels(offset.y * factor));
|
||||
}
|
||||
|
||||
nsPoint nsDOMUIEvent::GetClientPoint() {
|
||||
|
|
|
@ -64,6 +64,9 @@ interface nsIMarkupDocumentViewer : nsISupports
|
|||
/** The amount by which to scale all text. Default is 1.0. */
|
||||
attribute float textZoom;
|
||||
|
||||
/** The amount by which to scale all lengths. Default is 1.0. */
|
||||
attribute float fullZoom;
|
||||
|
||||
/** Disable entire author style level (including HTML presentation hints) */
|
||||
attribute boolean authorStyleDisabled;
|
||||
|
||||
|
|
|
@ -465,9 +465,30 @@ public:
|
|||
*/
|
||||
virtual PRBool CheckDPIChange() = 0;
|
||||
|
||||
/**
|
||||
* Set the pixel scaling factor: all lengths are multiplied by this factor
|
||||
* when we convert them to device pixels. Returns whether the ratio of
|
||||
* app units to dev pixels changed because of the scale factor.
|
||||
*/
|
||||
virtual PRBool SetPixelScale(float aScale) = 0;
|
||||
|
||||
/**
|
||||
* Get the pixel scaling factor; defaults to 1.0, but can be changed with
|
||||
* SetPixelScale.
|
||||
*/
|
||||
float GetPixelScale() const { return mPixelScale; }
|
||||
|
||||
/**
|
||||
* Get the unscaled ratio of app units to dev pixels; useful if something
|
||||
* needs to be converted from to unscaled pixels
|
||||
*/
|
||||
PRInt32 UnscaledAppUnitsPerDevPixel() { return mAppUnitsPerDevNotScaledPixel; }
|
||||
|
||||
protected:
|
||||
PRInt32 mAppUnitsPerDevPixel;
|
||||
PRInt32 mAppUnitsPerInch;
|
||||
PRInt32 mAppUnitsPerDevNotScaledPixel;
|
||||
float mPixelScale;
|
||||
};
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsIDeviceContext, NS_IDEVICE_CONTEXT_IID)
|
||||
|
|
|
@ -57,6 +57,9 @@ DeviceContextImpl::DeviceContextImpl()
|
|||
{
|
||||
mAppUnitsPerDevPixel = -1;
|
||||
mAppUnitsPerInch = -1;
|
||||
mAppUnitsPerDevNotScaledPixel = -1;
|
||||
mPixelScale = 1.0f;
|
||||
|
||||
mFontCache = nsnull;
|
||||
mWidget = nsnull;
|
||||
mFontAliasTable = nsnull;
|
||||
|
|
|
@ -230,18 +230,20 @@ nsThebesDeviceContext::SetDPI()
|
|||
// dev pixels per CSS pixel. Then, divide that into AppUnitsPerCSSPixel()
|
||||
// to get the number of app units per dev pixel. The PR_MAXes are to
|
||||
// make sure we don't end up dividing by zero.
|
||||
mAppUnitsPerDevPixel = PR_MAX(1, AppUnitsPerCSSPixel() /
|
||||
PR_MAX(1, (dpi + 48) / 96));
|
||||
mAppUnitsPerDevNotScaledPixel = PR_MAX(1, AppUnitsPerCSSPixel() /
|
||||
PR_MAX(1, (dpi + 48) / 96));
|
||||
|
||||
} else {
|
||||
/* set mAppUnitsPerDevPixel so we're using exactly 72 dpi, even
|
||||
* though that means we have a non-integer number of device "pixels"
|
||||
* per CSS pixel
|
||||
*/
|
||||
mAppUnitsPerDevPixel = (AppUnitsPerCSSPixel() * 96) / dpi;
|
||||
mAppUnitsPerDevNotScaledPixel = (AppUnitsPerCSSPixel() * 96) / dpi;
|
||||
}
|
||||
|
||||
mAppUnitsPerInch = NSIntPixelsToAppUnits(dpi, mAppUnitsPerDevPixel);
|
||||
mAppUnitsPerInch = NSIntPixelsToAppUnits(dpi, mAppUnitsPerDevNotScaledPixel);
|
||||
|
||||
UpdateScaledAppUnits();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -727,11 +729,30 @@ nsThebesDeviceContext::CalcPrintingSize()
|
|||
}
|
||||
|
||||
PRBool nsThebesDeviceContext::CheckDPIChange() {
|
||||
PRInt32 oldDevPixels = mAppUnitsPerDevPixel;
|
||||
PRInt32 oldDevPixels = mAppUnitsPerDevNotScaledPixel;
|
||||
PRInt32 oldInches = mAppUnitsPerInch;
|
||||
|
||||
SetDPI();
|
||||
|
||||
return oldDevPixels != mAppUnitsPerDevPixel ||
|
||||
return oldDevPixels != mAppUnitsPerDevNotScaledPixel ||
|
||||
oldInches != mAppUnitsPerInch;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsThebesDeviceContext::SetPixelScale(float aScale)
|
||||
{
|
||||
if (aScale <= 0) {
|
||||
NS_NOTREACHED("Invalid pixel scale value");
|
||||
return PR_FALSE;
|
||||
}
|
||||
PRInt32 oldAppUnitsPerDevPixel = mAppUnitsPerDevPixel;
|
||||
mPixelScale = aScale;
|
||||
UpdateScaledAppUnits();
|
||||
return oldAppUnitsPerDevPixel != mAppUnitsPerDevPixel;
|
||||
}
|
||||
|
||||
void
|
||||
nsThebesDeviceContext::UpdateScaledAppUnits()
|
||||
{
|
||||
mAppUnitsPerDevPixel = PR_MAX(1, PRInt32(float(mAppUnitsPerDevNotScaledPixel) / mPixelScale));
|
||||
}
|
||||
|
|
|
@ -116,6 +116,8 @@ public:
|
|||
|
||||
virtual PRBool CheckDPIChange();
|
||||
|
||||
virtual PRBool SetPixelScale(float aScale);
|
||||
|
||||
nsNativeWidget GetWidget() { return mWidget; }
|
||||
#ifdef XP_WIN
|
||||
HDC GetPrintHDC() {
|
||||
|
@ -142,6 +144,7 @@ protected:
|
|||
void ComputeFullAreaUsingScreen(nsRect *outRect);
|
||||
void FindScreen(nsIScreen **outScreen);
|
||||
void CalcPrintingSize();
|
||||
void UpdateScaledAppUnits();
|
||||
|
||||
PRUint32 mDepth;
|
||||
|
||||
|
|
|
@ -2572,6 +2572,24 @@ DocumentViewerImpl::GetTextZoom(float* aTextZoom)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DocumentViewerImpl::SetFullZoom(float aFullZoom)
|
||||
{
|
||||
if (mPresContext) {
|
||||
mPresContext->SetFullZoom(aFullZoom);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DocumentViewerImpl::GetFullZoom(float* aFullZoom)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFullZoom);
|
||||
*aFullZoom = mPresContext ? mPresContext->GetFullZoom() : 1.0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static void
|
||||
SetChildAuthorStyleDisabled(nsIMarkupDocumentViewer* aChild, void* aClosure)
|
||||
{
|
||||
|
|
|
@ -1073,9 +1073,23 @@ nsPresContext::GetDefaultFontExternal(PRUint8 aFontID) const
|
|||
}
|
||||
|
||||
void
|
||||
nsPresContext::SetTextZoomExternal(float aZoom)
|
||||
nsPresContext::SetFullZoom(float aZoom)
|
||||
{
|
||||
SetTextZoomInternal(aZoom);
|
||||
nsPresContext* rootPresContext = RootPresContext();
|
||||
if (rootPresContext != this) {
|
||||
NS_WARNING("Zoom set on non-root prescontext");
|
||||
rootPresContext->SetFullZoom(aZoom);
|
||||
return;
|
||||
}
|
||||
nsRect bounds(mVisibleArea);
|
||||
bounds.ScaleRoundPreservingCentersInverse(AppUnitsPerDevPixel());
|
||||
if (!mShell || !mDeviceContext->SetPixelScale(aZoom))
|
||||
return;
|
||||
mDeviceContext->FlushFontCache();
|
||||
nscoord width = DevPixelsToAppUnits(bounds.width);
|
||||
nscoord height = DevPixelsToAppUnits(bounds.height);
|
||||
GetViewManager()->SetWindowDimensions(width, height);
|
||||
ClearStyleDataAndReflow();
|
||||
}
|
||||
|
||||
imgIRequest*
|
||||
|
|
|
@ -462,16 +462,13 @@ public:
|
|||
nsIAtom* GetLangGroup() { return mLangGroup; }
|
||||
|
||||
float TextZoom() { return mTextZoom; }
|
||||
void SetTextZoomInternal(float aZoom) {
|
||||
void SetTextZoom(float aZoom) {
|
||||
mTextZoom = aZoom;
|
||||
ClearStyleDataAndReflow();
|
||||
}
|
||||
virtual NS_HIDDEN_(void) SetTextZoomExternal(float aZoom);
|
||||
#ifdef _IMPL_NS_LAYOUT
|
||||
void SetTextZoom(float aZoom) { SetTextZoomInternal(aZoom); }
|
||||
#else
|
||||
void SetTextZoom(float aZoom) { SetTextZoomExternal(aZoom); }
|
||||
#endif
|
||||
|
||||
float GetFullZoom() {return mDeviceContext->GetPixelScale();}
|
||||
void SetFullZoom(float aZoom);
|
||||
|
||||
static PRInt32 AppUnitsPerCSSPixel() { return nsIDeviceContext::AppUnitsPerCSSPixel(); }
|
||||
PRInt32 AppUnitsPerDevPixel() const { return mDeviceContext->AppUnitsPerDevPixel(); }
|
||||
|
|
Загрузка…
Ссылка в новой задаче