Bug 111432 [FIRST] Mouse wheel scrolling doesn't work in print preview on page margin or on frame page r+sr=roc

This commit is contained in:
masayuki%d-toybox.com 2005-12-21 14:37:24 +00:00
Родитель 9bf056b19d
Коммит 6f4d301ae9
1 изменённых файлов: 61 добавлений и 11 удалений

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

@ -1639,6 +1639,12 @@ nsEventStateManager::DoScrollTextsize(nsIFrame *aTargetFrame,
}
}
inline PRBool
ShouldScrollRootView(nsPresContext* aPresContext)
{
return (aPresContext->Type() == nsPresContext::eContext_PrintPreview);
}
nsresult
nsEventStateManager::DoScrollText(nsPresContext* aPresContext,
nsIFrame* aTargetFrame,
@ -1647,6 +1653,38 @@ nsEventStateManager::DoScrollText(nsPresContext* aPresContext,
PRBool aScrollHorizontal,
PRBool aScrollPage)
{
nsIScrollableView* scrollView = nsnull;
PRBool scrollRootView = ShouldScrollRootView(aPresContext);
if (scrollRootView) {
// Get root scroll view
nsIViewManager* vm = aPresContext->GetViewManager();
NS_ENSURE_TRUE(vm, NS_ERROR_FAILURE);
vm->GetRootScrollableView(&scrollView);
if (!scrollView) {
// We don't have root scrollable view in current document.
// Maybe, this is sub frame on Print Preview.
// Let's pass to parent document.
nsIFrame* newFrame = nsnull;
nsCOMPtr<nsPresContext> newPresContext = nsnull;
nsresult rv = GetParentScrollingView(aEvent, aPresContext, newFrame,
*getter_AddRefs(newPresContext));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(newFrame && newPresContext, NS_ERROR_FAILURE);
return DoScrollText(newPresContext, newFrame, aEvent, aNumLines,
aScrollHorizontal, aScrollPage);
}
// find target frame that is root scrollable content
nsIFrame* targetFrame = aTargetFrame;
for ( ;targetFrame; targetFrame = targetFrame->GetParent()) {
nsCOMPtr<nsIScrollableViewProvider> svp = do_QueryInterface(targetFrame);
if (svp && scrollView == svp->GetScrollableView())
break;
}
NS_ENSURE_TRUE(targetFrame, NS_ERROR_FAILURE);
aTargetFrame = targetFrame;
}
nsCOMPtr<nsIContent> targetContent = aTargetFrame->GetContent();
if (!targetContent)
GetFocusedContent(getter_AddRefs(targetContent));
@ -1694,21 +1732,24 @@ nsEventStateManager::DoScrollText(nsPresContext* aPresContext,
target->DispatchEvent(event, &defaultActionEnabled);
if (!defaultActionEnabled)
return NS_OK;
// Re-resolve |aTargetFrame| in case it was destroyed by the
// DOM event handler above, bug 257998.
aTargetFrame = aPresContext->GetPresShell()->GetPrimaryFrameFor(targetContent);
if (!aTargetFrame) {
// Without a frame we can't do the normal ancestor search for a view to scroll.
// Don't fall through to the "passToParent" code at the end because that will
// likely scroll the wrong view (in an enclosing document).
return NS_OK;
if (!scrollRootView) {
// Re-resolve |aTargetFrame| in case it was destroyed by the
// DOM event handler above, bug 257998.
aTargetFrame =
aPresContext->GetPresShell()->GetPrimaryFrameFor(targetContent);
if (!aTargetFrame) {
// Without a frame we can't do the normal ancestor search for a view
// to scroll. Don't fall through to the "passToParent" code at the end
// because that will likely scroll the wrong view (in an enclosing
// document).
return NS_OK;
}
}
}
}
nsIFrame* scrollFrame = aTargetFrame;
nsIScrollableView* scrollView = nsnull;
PRBool passToParent = PR_TRUE;
PRBool passToParent = !scrollRootView;
for( ; scrollFrame && passToParent; scrollFrame = scrollFrame->GetParent()) {
// Check whether the frame wants to provide us with a scrollable view.
@ -1815,7 +1856,16 @@ nsEventStateManager::GetParentScrollingView(nsInputEvent *aEvent,
return NS_OK;
}
nsIPresShell *pPresShell = parentDoc->GetShellAt(0);
nsIPresShell *pPresShell = nsnull;
for (PRUint32 i = 0; i < parentDoc->GetNumberOfShells(); i++) {
nsIPresShell *tmpPresShell = parentDoc->GetShellAt(i);
NS_ENSURE_TRUE(tmpPresShell, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(tmpPresShell->GetPresContext(), NS_ERROR_FAILURE);
if (tmpPresShell->GetPresContext()->Type() == aPresContext->Type()) {
pPresShell = tmpPresShell;
break;
}
}
NS_ENSURE_TRUE(pPresShell, NS_ERROR_FAILURE);
/* now find the content node in our parent docshell's document that