Bug 495002 - nsPresContext ought to have CSSPixelsToDevPixels and DevPixelsToCSSPixels methods

r=bz, sr=roc
This commit is contained in:
Daniel Brooks 2009-06-18 03:35:11 -05:00
Родитель fa91f9695a
Коммит 073d4da625
5 изменённых файлов: 70 добавлений и 16 удалений

Просмотреть файл

@ -3115,9 +3115,8 @@ nsGlobalWindow::DevToCSSIntPixels(PRInt32 px)
mDocShell->GetPresContext(getter_AddRefs(presContext)); mDocShell->GetPresContext(getter_AddRefs(presContext));
if (!presContext) if (!presContext)
return px; return px;
return nsPresContext::AppUnitsToIntCSSPixels( return presContext->DevPixelsToIntCSSPixels(px);
presContext->DevPixelsToAppUnits(px));
} }
PRInt32 PRInt32
@ -3130,9 +3129,8 @@ nsGlobalWindow::CSSToDevIntPixels(PRInt32 px)
mDocShell->GetPresContext(getter_AddRefs(presContext)); mDocShell->GetPresContext(getter_AddRefs(presContext));
if (!presContext) if (!presContext)
return px; return px;
return presContext->AppUnitsToDevPixels( return presContext->CSSPixelsToDevPixels(px);
nsPresContext::CSSPixelsToAppUnits(px));
} }
nsIntSize nsIntSize
@ -3147,10 +3145,8 @@ nsGlobalWindow::DevToCSSIntPixels(nsIntSize px)
return px; return px;
return nsIntSize( return nsIntSize(
nsPresContext::AppUnitsToIntCSSPixels( presContext->DevPixelsToIntCSSPixels(px.width),
presContext->DevPixelsToAppUnits(px.width)), presContext->DevPixelsToIntCSSPixels(px.height));
nsPresContext::AppUnitsToIntCSSPixels(
presContext->DevPixelsToAppUnits(px.height)));
} }
nsIntSize nsIntSize
@ -3165,10 +3161,8 @@ nsGlobalWindow::CSSToDevIntPixels(nsIntSize px)
return px; return px;
return nsIntSize( return nsIntSize(
presContext->AppUnitsToDevPixels( presContext->CSSPixelsToDevPixels(px.width),
nsPresContext::CSSPixelsToAppUnits(px.width)), presContext->CSSPixelsToDevPixels(px.height));
presContext->AppUnitsToDevPixels(
nsPresContext::CSSPixelsToAppUnits(px.height)));
} }

Просмотреть файл

@ -0,0 +1,6 @@
include("simple-match.js");
var patterns = {CSSPixelsToDevPixels: ['AppUnitsToDevPixels', 'CSSPixelsToAppUnits'],
DevPixelsToIntCSSPixels: ['AppUnitsToIntCSSPixels', 'DevPixelsToAppUnits'],
DevPixelsToFloatCSSPixels: ['AppUnitsToFloatCSSPixels', 'DevPixelsToAppUnits'],
};

Просмотреть файл

@ -0,0 +1,39 @@
// This executes a very simple search for all functions that call a
// given set of functions. It's intended to be the simplest possible
// way of refactoring a common pattern of function calls. Of course,
// it's still up to a human to decide if the replacement is truely
// suitable, but this gets the low-hanging fruit.
// Expects the variable 'patterns' to hold an object with replacement
// function names as keys and function lists as values. Any function
// in the tested source that calls all of the functions named in the
// list will be listed in the output as being likely candidates to
// instead call the replacement function.
include("unstable/lazy_types.js");
var matches = {};
function identity(x) x;
function process_cp_pre_genericize(fndecl)
{
var c = [];
function calls(t, stack)
{
try {
t.tree_check(CALL_EXPR);
var fn = callable_arg_function_decl(CALL_EXPR_FN(t));
if (fn)
c.push(decl_name_string(fn));
}
catch (e if e.TreeCheckError) { }
}
walk_tree(DECL_SAVED_TREE(fndecl), calls);
for (let [fnreplace, pattern] in patterns)
if (pattern.map(function(e){ return c.some(function(f) { return e == f; }); }).every(identity))
if (fnreplace != (n = decl_name_string(fndecl)))
print(fnreplace +" could probably be used in "+ n);
}

Просмотреть файл

@ -568,6 +568,21 @@ public:
{ return NSAppUnitsToIntPixels(aAppUnits, { return NSAppUnitsToIntPixels(aAppUnits,
float(mDeviceContext->AppUnitsPerDevPixel())); } float(mDeviceContext->AppUnitsPerDevPixel())); }
PRInt32 CSSPixelsToDevPixels(PRInt32 aPixels)
{ return AppUnitsToDevPixels(CSSPixelsToAppUnits(aPixels)); }
float CSSPixelsToDevPixels(float aPixels)
{
return NSAppUnitsToFloatPixels(CSSPixelsToAppUnits(aPixels),
float(mDeviceContext->AppUnitsPerDevPixel()));
}
PRInt32 DevPixelsToIntCSSPixels(PRInt32 aPixels)
{ return AppUnitsToIntCSSPixels(DevPixelsToAppUnits(aPixels)); }
float DevPixelsToFloatCSSPixels(PRInt32 aPixels)
{ return AppUnitsToFloatCSSPixels(DevPixelsToAppUnits(aPixels)); }
// If there is a remainder, it is rounded to nearest app units. // If there is a remainder, it is rounded to nearest app units.
nscoord GfxUnitsToAppUnits(gfxFloat aGfxUnits) const nscoord GfxUnitsToAppUnits(gfxFloat aGfxUnits) const
{ return mDeviceContext->GfxUnitsToAppUnits(aGfxUnits); } { return mDeviceContext->GfxUnitsToAppUnits(aGfxUnits); }

Просмотреть файл

@ -361,8 +361,8 @@ nsXULPopupManager::SetTriggerEvent(nsIDOMEvent* aEvent, nsIContent* aPopup)
mouseEvent->GetClientY(&mCachedMousePoint.y); mouseEvent->GetClientY(&mCachedMousePoint.y);
// convert to device pixels // convert to device pixels
mCachedMousePoint.x = presContext->AppUnitsToDevPixels(nsPresContext::CSSPixelsToAppUnits(mCachedMousePoint.x)); mCachedMousePoint.x = presContext->CSSPixelsToDevPixels(mCachedMousePoint.x);
mCachedMousePoint.y = presContext->AppUnitsToDevPixels(nsPresContext::CSSPixelsToAppUnits(mCachedMousePoint.y)); mCachedMousePoint.y = presContext->CSSPixelsToDevPixels(mCachedMousePoint.y);
} }
else if (rootFrame) { else if (rootFrame) {
nsPoint pnt = nsPoint pnt =