Bug 845010 - turn nsIDOMWindowUtils.getScrollbarWidth() into .getScrollbarSize(); r=roc

--HG--
rename : dom/tests/mochitest/general/file_domWindowUtils_scrollbarWidth.html => dom/tests/mochitest/general/file_domWindowUtils_scrollbarSize.html
rename : dom/tests/mochitest/general/test_domWindowUtils_scrollbarWidth.html => dom/tests/mochitest/general/test_domWindowUtils_scrollbarSize.html
This commit is contained in:
Tim Taubert 2013-02-25 23:13:36 +01:00
Родитель 28b96c9ccd
Коммит 69f42d1be4
6 изменённых файлов: 75 добавлений и 55 удалений

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

@ -1440,13 +1440,15 @@ nsDOMWindowUtils::GetScrollXY(bool aFlushLayout, int32_t* aScrollX, int32_t* aSc
}
NS_IMETHODIMP
nsDOMWindowUtils::GetScrollbarWidth(bool aFlushLayout, int32_t* aResult)
nsDOMWindowUtils::GetScrollbarSize(bool aFlushLayout, int32_t* aWidth,
int32_t* aHeight)
{
if (!nsContentUtils::IsCallerChrome()) {
return NS_ERROR_DOM_SECURITY_ERR;
}
*aResult = 0;
*aWidth = 0;
*aHeight = 0;
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
NS_ENSURE_STATE(window);
@ -1465,7 +1467,8 @@ nsDOMWindowUtils::GetScrollbarWidth(bool aFlushLayout, int32_t* aResult)
NS_ENSURE_TRUE(scrollFrame, NS_OK);
nsMargin sizes = scrollFrame->GetActualScrollbarSizes();
*aResult = nsPresContext::AppUnitsToIntCSSPixels(sizes.LeftRight());
*aWidth = nsPresContext::AppUnitsToIntCSSPixels(sizes.LeftRight());
*aHeight = nsPresContext::AppUnitsToIntCSSPixels(sizes.TopBottom());
return NS_OK;
}

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

@ -41,7 +41,7 @@ interface nsIDOMClientRect;
interface nsIURI;
interface nsIDOMEventTarget;
[scriptable, uuid(16b3bdcc-75d4-11e2-8a20-aaff78957a39)]
[scriptable, uuid(9ab64e24-7f8d-11e2-9a5f-a24379957a39)]
interface nsIDOMWindowUtils : nsISupports {
/**
@ -652,7 +652,7 @@ interface nsIDOMWindowUtils : nsISupports {
*
* @param aFlushLayout flushes layout if true. Otherwise, no flush occurs.
*/
long getScrollbarWidth(in boolean aFlushLayout);
void getScrollbarSize(in boolean aFlushLayout, out long aWidth, out long aHeight);
/**
* Returns the bounds of the window's currently loaded document. This will

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

@ -29,8 +29,8 @@ MOCHITEST_FILES = \
test_consoleAPI.html \
test_domWindowUtils.html \
test_domWindowUtils_scrollXY.html \
test_domWindowUtils_scrollbarWidth.html \
file_domWindowUtils_scrollbarWidth.html \
test_domWindowUtils_scrollbarSize.html \
file_domWindowUtils_scrollbarSize.html \
test_offsets.html \
test_offsets.js \
test_windowProperties.html \

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

@ -0,0 +1,65 @@
<!DOCTYPE HTML>
<html>
<head>
<title>nsIDOMWindowUtils::getScrollbarSize test</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
</head>
<body id="body">
<script type="application/javascript;version=1.8">
function doTests() {
let iframe = document.getElementById("iframe");
let cwindow = iframe.contentWindow;
let utils = SpecialPowers.getDOMWindowUtils(cwindow);
let doc = cwindow.document;
function haveNonFloatingScrollbars() {
return doc.getElementById("float").offsetWidth > 200;
}
checkScrollbarSizeFlush(utils, function (w, h) w == 0 && h == 0,
"[overflow=hidden] corrrect scrollbar size after flushing");
// Some platforms (esp. mobile) may have floating scrollbars that don't
// affect layout. Thus getScrollbarSize() would always return zeros.
if (haveNonFloatingScrollbars()) {
let body = doc.querySelector("body");
body.style.overflowY = "scroll";
checkScrollbarSize(utils, function (w, h) w == 0 && h == 0,
"[overflowY=scroll] correct scrollbar size w/o flushing");
checkScrollbarSizeFlush(utils, function (w, h) w > 0 && h == 0,
"[overflowY=scroll] correct scrollbar size after flushing");
body.style.overflowX = "scroll";
checkScrollbarSize(utils, function (w, h) w > 0 && h == 0,
"[overflowXY=scroll] correct scrollbar size w/o flushing");
checkScrollbarSizeFlush(utils, function (w, h) w > 0 && h > 0,
"[overflowXY=scroll] correct scrollbar size after flushing");
}
SimpleTest.finish();
}
function checkScrollbarSize(utils, check, msg, flush = false) {
let width = {}, height = {};
utils.getScrollbarSize(flush, width, height);
ok(check(width.value, height.value), msg);
}
function checkScrollbarSizeFlush(utils, check, msg) {
checkScrollbarSize(utils, check, msg, true);
}
SimpleTest.waitForExplicitFinish();
</script>
<iframe src="http://mochi.test:8888/tests/dom/tests/mochitest/general/file_domWindowUtils_scrollbarSize.html"
id="iframe" onload="doTests();">
</iframe>
</body>
</html>

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

@ -1,48 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>nsIDOMWindowUtils::getScrollbarWidth test</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
</head>
<body id="body">
<script type="application/javascript;version=1.8">
function doTests() {
let iframe = document.getElementById("iframe");
let cwindow = iframe.contentWindow;
let utils = SpecialPowers.getDOMWindowUtils(cwindow);
let doc = cwindow.document;
function haveNonFloatingScrollbars() {
return doc.getElementById("float").offsetWidth > 200;
}
is(utils.getScrollbarWidth(true), 0,
"getScrollbarWidth returns zero without a scrollbar");
// Some platforms (esp. mobile) may have floating scrollbars that don't
// affect layout. Thus getScrollbarWidth() would always return 0.
if (haveNonFloatingScrollbars()) {
let body = doc.querySelector("body");
body.style.overflowY = "scroll";
is(utils.getScrollbarWidth(false), 0,
"getScrollbarWidth returns zero with a vertical scrollbar w/o flushing");
ok(utils.getScrollbarWidth(true) > 0,
"getScrollbarWidth returns non-zero with a vertical scrollbar with flushing");
}
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
</script>
<iframe src="http://mochi.test:8888/tests/dom/tests/mochitest/general/file_domWindowUtils_scrollbarWidth.html"
id="iframe" onload="doTests();">
</iframe>
</body>
</html>