Bug 1522724 - Add scroll update type for nsIDOMWindowUtils.scrollToVisual(). r=botond

Depends on D17582

Differential Revision: https://phabricator.services.mozilla.com/D17583

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Hiroyuki Ikezoe 2019-01-28 21:48:43 +00:00
Родитель bc455f0e52
Коммит 532e1252a3
4 изменённых файлов: 25 добавлений и 10 удалений

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

@ -1395,7 +1395,8 @@ nsDOMWindowUtils::GetScrollXYFloat(bool aFlushLayout, float* aScrollX,
}
NS_IMETHODIMP
nsDOMWindowUtils::ScrollToVisual(float aOffsetX, float aOffsetY) {
nsDOMWindowUtils::ScrollToVisual(float aOffsetX, float aOffsetY,
int32_t aUpdateType) {
nsCOMPtr<Document> doc = GetDocument();
NS_ENSURE_STATE(doc);
@ -1405,12 +1406,20 @@ nsDOMWindowUtils::ScrollToVisual(float aOffsetX, float aOffsetY) {
// This should only be called on the root content document.
NS_ENSURE_TRUE(presContext->IsRootContentDocument(), NS_ERROR_INVALID_ARG);
// Use |eRestore| as the priority for now, as it's the conservative choice.
// If a JS call site needs higher priority, we can expose the update type
// as a parameter.
FrameMetrics::ScrollOffsetUpdateType updateType;
switch (aUpdateType) {
case UPDATE_TYPE_RESTORE:
updateType = FrameMetrics::eRestore;
break;
case UPDATE_TYPE_MAIN_THREAD:
updateType = FrameMetrics::eMainThread;
break;
default:
return NS_ERROR_INVALID_ARG;
}
presContext->PresShell()->SetPendingVisualScrollUpdate(
CSSPoint::ToAppUnits(CSSPoint(aOffsetX, aOffsetY)),
FrameMetrics::eRestore);
CSSPoint::ToAppUnits(CSSPoint(aOffsetX, aOffsetY)), updateType);
return NS_OK;
}

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

@ -839,8 +839,10 @@ interface nsIDOMWindowUtils : nsISupports {
* SetPendingVisualViewportOffset(), and request APZ review if adding a new
* call to this.
*/
void scrollToVisual(in float aOffsetX, in float aOffsetY);
const long UPDATE_TYPE_RESTORE = 0;
const long UPDATE_TYPE_MAIN_THREAD = 1;
void scrollToVisual(in float aOffsetX, in float aOffsetY, in long aUpdateType);
/**
* Returns the offset of the window's visual viewport relative to the
* layout viewport.

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

@ -19,6 +19,8 @@
<div style="background: red; width: 200%; height: 100px;">overflowed element</div>
<div id="target" style="background: green; width: 100px; height: 100px;"></div>
<script type="application/javascript">
const utils = SpecialPowers.getDOMWindowUtils(window);
function waitForFullscreenChange() {
return new Promise(resolve => {
document.addEventListener("fullscreenchange", resolve);
@ -34,7 +36,7 @@
"The target element should have been fullscreen-ed");
// Try to move rightward, but it should NOT happen.
SpecialPowers.getDOMWindowUtils(window).scrollToVisual(200, 0);
utils.scrollToVisual(200, 0, utils.UPDATE_TYPE_MAIN_THREAD);
await waitUntilApzStable();

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

@ -20,8 +20,10 @@
<div style="width: 200%; height: 200%; background-color: green"></div>
<div style="width: 100%; height: 100%; background-color: blue"></div>
<script type="application/javascript">
const utils = SpecialPowers.getDOMWindowUtils(window);
async function test(testDriver) {
SpecialPowers.getDOMWindowUtils(window).scrollToVisual(100, 0);
utils.scrollToVisual(100, 0, utils.UPDATE_TYPE_MAIN_THREAD);
const promiseForVisualViewportScroll = new Promise(resolve => {
window.visualViewport.addEventListener("scroll", () => {