Bug 1013392 - Adjust the search algorithm for async scrollbar thumb shifting. r=kats

This commit is contained in:
Markus Stange 2014-05-28 16:14:43 +02:00
parent 1ccabb9ab2
commit 709cb5dac4

View File

@ -610,6 +610,12 @@ ApplyAsyncTransformToScrollbarForContent(TimeStamp aCurrentFrame, ContainerLayer
Layer* aContent, bool aScrollbarIsChild) Layer* aContent, bool aScrollbarIsChild)
{ {
ContainerLayer* content = aContent->AsContainerLayer(); ContainerLayer* content = aContent->AsContainerLayer();
// We only apply the transform if the scroll-target layer has non-container
// children (i.e. when it has some possibly-visible content). This is to
// avoid moving scroll-bars in the situation that only a scroll information
// layer has been built for a scroll frame, as this would result in a
// disparity between scrollbars and visible content.
if (!LayerHasNonContainerDescendants(content)) { if (!LayerHasNonContainerDescendants(content)) {
return; return;
} }
@ -683,6 +689,32 @@ ApplyAsyncTransformToScrollbarForContent(TimeStamp aCurrentFrame, ContainerLayer
aScrollbar->AsLayerComposite()->SetShadowTransform(transform); aScrollbar->AsLayerComposite()->SetShadowTransform(transform);
} }
static Layer*
FindScrolledLayerForScrollbar(ContainerLayer* aLayer, bool* aOutIsAncestor)
{
// Search all siblings of aLayer and of its ancestors.
for (Layer* ancestor = aLayer; ancestor; ancestor = ancestor->GetParent()) {
for (Layer* scrollTarget = ancestor;
scrollTarget;
scrollTarget = scrollTarget->GetPrevSibling()) {
if (scrollTarget != aLayer &&
LayerIsContainerForScrollbarTarget(scrollTarget, aLayer)) {
*aOutIsAncestor = (scrollTarget == ancestor);
return scrollTarget;
}
}
for (Layer* scrollTarget = ancestor->GetNextSibling();
scrollTarget;
scrollTarget = scrollTarget->GetNextSibling()) {
if (LayerIsContainerForScrollbarTarget(scrollTarget, aLayer)) {
*aOutIsAncestor = false;
return scrollTarget;
}
}
}
return nullptr;
}
void void
AsyncCompositionManager::ApplyAsyncTransformToScrollbar(TimeStamp aCurrentFrame, ContainerLayer* aLayer) AsyncCompositionManager::ApplyAsyncTransformToScrollbar(TimeStamp aCurrentFrame, ContainerLayer* aLayer)
{ {
@ -693,25 +725,11 @@ AsyncCompositionManager::ApplyAsyncTransformToScrollbar(TimeStamp aCurrentFrame,
// Note that it is possible that the content layer is no longer there; in // Note that it is possible that the content layer is no longer there; in
// this case we don't need to do anything because there can't be an async // this case we don't need to do anything because there can't be an async
// transform on the content. // transform on the content.
// We only apply the transform if the scroll-target layer has non-container bool isAncestor = false;
// children (i.e. when it has some possibly-visible content). This is to Layer* scrollTarget = FindScrolledLayerForScrollbar(aLayer, &isAncestor);
// avoid moving scroll-bars in the situation that only a scroll information if (scrollTarget) {
// layer has been built for a scroll frame, as this would result in a ApplyAsyncTransformToScrollbarForContent(aCurrentFrame, aLayer, scrollTarget,
// disparity between scrollbars and visible content. isAncestor);
for (Layer* scrollTarget = aLayer->GetPrevSibling();
scrollTarget;
scrollTarget = scrollTarget->GetPrevSibling()) {
if (LayerIsContainerForScrollbarTarget(scrollTarget, aLayer)) {
// Found a sibling that matches our criteria
ApplyAsyncTransformToScrollbarForContent(aCurrentFrame, aLayer, scrollTarget, false);
return;
}
}
// If we didn't find a sibling, look for a parent
Layer* scrollTarget = aLayer->GetParent();
if (scrollTarget && LayerIsContainerForScrollbarTarget(scrollTarget, aLayer)) {
ApplyAsyncTransformToScrollbarForContent(aCurrentFrame, aLayer, scrollTarget, true);
} }
} }