зеркало из https://github.com/mozilla/pjs.git
Bug 495002 - nsPresContext ought to have CSSPixelsToDevPixels and DevPixelsToCSSPixels methods
r=bz, sr=roc
This commit is contained in:
Родитель
fa91f9695a
Коммит
073d4da625
|
@ -3115,9 +3115,8 @@ nsGlobalWindow::DevToCSSIntPixels(PRInt32 px)
|
|||
mDocShell->GetPresContext(getter_AddRefs(presContext));
|
||||
if (!presContext)
|
||||
return px;
|
||||
|
||||
return nsPresContext::AppUnitsToIntCSSPixels(
|
||||
presContext->DevPixelsToAppUnits(px));
|
||||
|
||||
return presContext->DevPixelsToIntCSSPixels(px);
|
||||
}
|
||||
|
||||
PRInt32
|
||||
|
@ -3130,9 +3129,8 @@ nsGlobalWindow::CSSToDevIntPixels(PRInt32 px)
|
|||
mDocShell->GetPresContext(getter_AddRefs(presContext));
|
||||
if (!presContext)
|
||||
return px;
|
||||
|
||||
return presContext->AppUnitsToDevPixels(
|
||||
nsPresContext::CSSPixelsToAppUnits(px));
|
||||
|
||||
return presContext->CSSPixelsToDevPixels(px);
|
||||
}
|
||||
|
||||
nsIntSize
|
||||
|
@ -3147,10 +3145,8 @@ nsGlobalWindow::DevToCSSIntPixels(nsIntSize px)
|
|||
return px;
|
||||
|
||||
return nsIntSize(
|
||||
nsPresContext::AppUnitsToIntCSSPixels(
|
||||
presContext->DevPixelsToAppUnits(px.width)),
|
||||
nsPresContext::AppUnitsToIntCSSPixels(
|
||||
presContext->DevPixelsToAppUnits(px.height)));
|
||||
presContext->DevPixelsToIntCSSPixels(px.width),
|
||||
presContext->DevPixelsToIntCSSPixels(px.height));
|
||||
}
|
||||
|
||||
nsIntSize
|
||||
|
@ -3165,10 +3161,8 @@ nsGlobalWindow::CSSToDevIntPixels(nsIntSize px)
|
|||
return px;
|
||||
|
||||
return nsIntSize(
|
||||
presContext->AppUnitsToDevPixels(
|
||||
nsPresContext::CSSPixelsToAppUnits(px.width)),
|
||||
presContext->AppUnitsToDevPixels(
|
||||
nsPresContext::CSSPixelsToAppUnits(px.height)));
|
||||
presContext->CSSPixelsToDevPixels(px.width),
|
||||
presContext->CSSPixelsToDevPixels(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,
|
||||
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.
|
||||
nscoord GfxUnitsToAppUnits(gfxFloat aGfxUnits) const
|
||||
{ return mDeviceContext->GfxUnitsToAppUnits(aGfxUnits); }
|
||||
|
|
|
@ -361,8 +361,8 @@ nsXULPopupManager::SetTriggerEvent(nsIDOMEvent* aEvent, nsIContent* aPopup)
|
|||
mouseEvent->GetClientY(&mCachedMousePoint.y);
|
||||
|
||||
// convert to device pixels
|
||||
mCachedMousePoint.x = presContext->AppUnitsToDevPixels(nsPresContext::CSSPixelsToAppUnits(mCachedMousePoint.x));
|
||||
mCachedMousePoint.y = presContext->AppUnitsToDevPixels(nsPresContext::CSSPixelsToAppUnits(mCachedMousePoint.y));
|
||||
mCachedMousePoint.x = presContext->CSSPixelsToDevPixels(mCachedMousePoint.x);
|
||||
mCachedMousePoint.y = presContext->CSSPixelsToDevPixels(mCachedMousePoint.y);
|
||||
}
|
||||
else if (rootFrame) {
|
||||
nsPoint pnt =
|
||||
|
|
Загрузка…
Ссылка в новой задаче