Bug 526394. Part 11: Convert nsGlobalWindow and nsDOMWindowUtils. r=mats

This commit is contained in:
Robert O'Callahan 2009-09-03 15:57:46 +12:00
Родитель 6202a9ce42
Коммит 9e00ae099f
4 изменённых файлов: 63 добавлений и 93 удалений

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

@ -47,7 +47,7 @@
#include "nsFocusManager.h"
#include "nsIEventStateManager.h"
#include "nsIScrollableView.h"
#include "nsIScrollableFrame.h"
#include "nsContentUtils.h"
@ -789,23 +789,17 @@ nsDOMWindowUtils::GetScrollXY(PRBool aFlushLayout, PRInt32* aScrollX, PRInt32* a
doc->FlushPendingNotifications(Flush_Layout);
}
nscoord xPos = 0, yPos = 0;
nsPoint scrollPos(0,0);
nsIPresShell *presShell = doc->GetPrimaryShell();
if (presShell) {
nsIViewManager *viewManager = presShell->GetViewManager();
if (viewManager) {
nsIScrollableView *view = nsnull;
viewManager->GetRootScrollableView(&view);
if (view) {
nsresult rv = view->GetScrollPosition(xPos, yPos);
NS_ENSURE_SUCCESS(rv, rv);
}
nsIScrollableFrame* sf = presShell->GetRootScrollFrameAsScrollable();
if (sf) {
scrollPos = sf->GetScrollPosition();
}
}
*aScrollX = nsPresContext::AppUnitsToIntCSSPixels(xPos);
*aScrollY = nsPresContext::AppUnitsToIntCSSPixels(yPos);
*aScrollX = nsPresContext::AppUnitsToIntCSSPixels(scrollPos.x);
*aScrollY = nsPresContext::AppUnitsToIntCSSPixels(scrollPos.y);
return NS_OK;
}

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

@ -129,7 +129,7 @@
#include "nsIServiceManager.h"
#include "nsIScriptGlobalObjectOwner.h"
#include "nsIScriptSecurityManager.h"
#include "nsIScrollableView.h"
#include "nsIScrollableFrame.h"
#include "nsIView.h"
#include "nsIViewManager.h"
#include "nsISelectionController.h"
@ -3730,26 +3730,19 @@ nsGlobalWindow::GetScrollMaxXY(PRInt32* aScrollMaxX, PRInt32* aScrollMaxY)
FORWARD_TO_OUTER(GetScrollMaxXY, (aScrollMaxX, aScrollMaxY),
NS_ERROR_NOT_INITIALIZED);
nsresult rv;
nsIScrollableView *view = nsnull; // no addref/release for views
FlushPendingNotifications(Flush_Layout);
GetScrollInfo(&view);
if (!view)
return NS_OK; // bug 230965 changed from NS_ERROR_FAILURE
nsIScrollableFrame *sf = GetScrollFrame();
if (!sf)
return NS_OK;
nsSize scrolledSize;
rv = view->GetContainerSize(&scrolledSize.width, &scrolledSize.height);
NS_ENSURE_SUCCESS(rv, rv);
nsRect portRect = view->View()->GetBounds();
nsRect scrollRange = sf->GetScrollRange();
if (aScrollMaxX)
*aScrollMaxX = PR_MAX(0,
(PRInt32)floor(nsPresContext::AppUnitsToFloatCSSPixels(scrolledSize.width - portRect.width)));
(PRInt32)floor(nsPresContext::AppUnitsToFloatCSSPixels(scrollRange.XMost())));
if (aScrollMaxY)
*aScrollMaxY = PR_MAX(0,
(PRInt32)floor(nsPresContext::AppUnitsToFloatCSSPixels(scrolledSize.height - portRect.height)));
(PRInt32)floor(nsPresContext::AppUnitsToFloatCSSPixels(scrollRange.YMost())));
return NS_OK;
}
@ -3777,34 +3770,28 @@ nsGlobalWindow::GetScrollXY(PRInt32* aScrollX, PRInt32* aScrollY,
FORWARD_TO_OUTER(GetScrollXY, (aScrollX, aScrollY, aDoFlush),
NS_ERROR_NOT_INITIALIZED);
nsresult rv;
nsIScrollableView *view = nsnull; // no addref/release for views
if (aDoFlush) {
FlushPendingNotifications(Flush_Layout);
} else {
EnsureSizeUpToDate();
}
GetScrollInfo(&view);
if (!view)
return NS_OK; // bug 202206 changed from NS_ERROR_FAILURE
nscoord xPos, yPos;
rv = view->GetScrollPosition(xPos, yPos);
NS_ENSURE_SUCCESS(rv, rv);
nsIScrollableFrame *sf = GetScrollFrame();
if (!sf)
return NS_OK;
if ((xPos != 0 || yPos != 0) && !aDoFlush) {
nsPoint scrollPos = sf->GetScrollPosition();
if (scrollPos != nsPoint(0,0) && !aDoFlush) {
// Oh, well. This is the expensive case -- the window is scrolled and we
// didn't actually flush yet. Repeat, but with a flush, since the content
// may get shorter and hence our scroll position may decrease.
return GetScrollXY(aScrollX, aScrollY, PR_TRUE);
}
if (aScrollX)
*aScrollX = nsPresContext::AppUnitsToIntCSSPixels(xPos);
*aScrollX = nsPresContext::AppUnitsToIntCSSPixels(scrollPos.x);
if (aScrollY)
*aScrollY = nsPresContext::AppUnitsToIntCSSPixels(yPos);
*aScrollY = nsPresContext::AppUnitsToIntCSSPixels(scrollPos.y);
return NS_OK;
}
@ -4801,13 +4788,10 @@ nsGlobalWindow::Scroll(PRInt32 aXScroll, PRInt32 aYScroll)
NS_IMETHODIMP
nsGlobalWindow::ScrollTo(PRInt32 aXScroll, PRInt32 aYScroll)
{
nsresult result;
nsIScrollableView *view = nsnull; // no addref/release for views
FlushPendingNotifications(Flush_Layout);
result = GetScrollInfo(&view);
nsIScrollableFrame *sf = GetScrollFrame();
if (view) {
if (sf) {
// Here we calculate what the max pixel value is that we can
// scroll to, we do this by dividing maxint with the pixel to
// twips conversion factor, and substracting 4, the 4 comes from
@ -4822,64 +4806,62 @@ nsGlobalWindow::ScrollTo(PRInt32 aXScroll, PRInt32 aYScroll)
if (aYScroll > maxpx) {
aYScroll = maxpx;
}
result = view->ScrollTo(nsPresContext::CSSPixelsToAppUnits(aXScroll),
nsPresContext::CSSPixelsToAppUnits(aYScroll),
0);
sf->ScrollTo(nsPoint(nsPresContext::CSSPixelsToAppUnits(aXScroll),
nsPresContext::CSSPixelsToAppUnits(aYScroll)),
nsIScrollableFrame::INSTANT);
}
return result;
return NS_OK;
}
NS_IMETHODIMP
nsGlobalWindow::ScrollBy(PRInt32 aXScrollDif, PRInt32 aYScrollDif)
{
nsresult result;
nsIScrollableView *view = nsnull; // no addref/release for views
FlushPendingNotifications(Flush_Layout);
result = GetScrollInfo(&view);
nsIScrollableFrame *sf = GetScrollFrame();
if (view) {
nscoord xPos, yPos;
result = view->GetScrollPosition(xPos, yPos);
if (NS_SUCCEEDED(result)) {
result = ScrollTo(nsPresContext::AppUnitsToIntCSSPixels(xPos) + aXScrollDif,
nsPresContext::AppUnitsToIntCSSPixels(yPos) + aYScrollDif);
}
if (sf) {
nsPoint scrollPos = sf->GetScrollPosition();
// It seems like it would make more sense for ScrollBy to use
// SMOOTH mode, but tests seem to depend on the synchronous behaviour.
// Perhaps Web content does too.
return ScrollTo(nsPresContext::AppUnitsToIntCSSPixels(scrollPos.x) + aXScrollDif,
nsPresContext::AppUnitsToIntCSSPixels(scrollPos.y) + aYScrollDif);
}
return result;
return NS_OK;
}
NS_IMETHODIMP
nsGlobalWindow::ScrollByLines(PRInt32 numLines)
{
nsresult result;
nsIScrollableView *view = nsnull; // no addref/release for views
FlushPendingNotifications(Flush_Layout);
result = GetScrollInfo(&view);
if (view) {
result = view->ScrollByLines(0, numLines);
nsIScrollableFrame *sf = GetScrollFrame();
if (sf) {
// It seems like it would make more sense for ScrollByLines to use
// SMOOTH mode, but tests seem to depend on the synchronous behaviour.
// Perhaps Web content does too.
sf->ScrollBy(nsIntPoint(0, numLines), nsIScrollableFrame::LINES,
nsIScrollableFrame::INSTANT);
}
return result;
return NS_OK;
}
NS_IMETHODIMP
nsGlobalWindow::ScrollByPages(PRInt32 numPages)
{
nsresult result;
nsIScrollableView *view = nsnull; // no addref/release for views
FlushPendingNotifications(Flush_Layout);
result = GetScrollInfo(&view);
if (view) {
result = view->ScrollByPages(0, numPages);
nsIScrollableFrame *sf = GetScrollFrame();
if (sf) {
// It seems like it would make more sense for ScrollByPages to use
// SMOOTH mode, but tests seem to depend on the synchronous behaviour.
// Perhaps Web content does too.
sf->ScrollBy(nsIntPoint(0, numPages), nsIScrollableFrame::PAGES,
nsIScrollableFrame::INSTANT);
}
return result;
return NS_OK;
}
NS_IMETHODIMP
@ -8516,26 +8498,21 @@ nsGlobalWindow::GetWebBrowserChrome(nsIWebBrowserChrome **aBrowserChrome)
return NS_OK;
}
nsresult
nsGlobalWindow::GetScrollInfo(nsIScrollableView **aScrollableView)
nsIScrollableFrame *
nsGlobalWindow::GetScrollFrame()
{
FORWARD_TO_OUTER(GetScrollInfo, (aScrollableView),
NS_ERROR_NOT_INITIALIZED);
*aScrollableView = nsnull;
FORWARD_TO_OUTER(GetScrollFrame, (), nsnull);
if (!mDocShell) {
return NS_OK;
return nsnull;
}
nsCOMPtr<nsIPresShell> presShell;
mDocShell->GetPresShell(getter_AddRefs(presShell));
if (presShell) {
nsIViewManager* vm = presShell->GetViewManager();
if (vm)
return vm->GetRootScrollableView(aScrollableView);
return presShell->GetRootScrollFrameAsScrollable();
}
return NS_OK;
return nsnull;
}
nsresult

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

@ -108,7 +108,7 @@ class nsIDOMBarProp;
class nsIDocument;
class nsPresContext;
class nsIDOMEvent;
class nsIScrollableView;
class nsIScrollableFrame;
class nsIControllers;
class nsBarProp;
@ -560,9 +560,9 @@ protected:
nsresult GetTreeOwner(nsIDocShellTreeOwner** aTreeOwner);
nsresult GetTreeOwner(nsIBaseWindow** aTreeOwner);
nsresult GetWebBrowserChrome(nsIWebBrowserChrome** aBrowserChrome);
// GetScrollInfo does not flush. Callers should do it themselves as needed,
// depending on which info they actually want off the scrollable view.
nsresult GetScrollInfo(nsIScrollableView** aScrollableView);
// GetScrollFrame does not flush. Callers should do it themselves as needed,
// depending on which info they actually want off the scrollable frame.
nsIScrollableFrame *GetScrollFrame();
nsresult SecurityCheckURL(const char *aURL);
nsresult BuildURIfromBase(const char *aURL,
nsIURI **aBuiltURI,

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

@ -53,7 +53,6 @@
#include "nsIContent.h"
#include "nsIPresShell.h"
#include "nsIViewManager.h"
#include "nsIScrollableView.h"
#include "nsIDOMNode.h"
#include "nsIDOMDragEvent.h"
#include "nsISelection.h"