зеркало из https://github.com/mozilla/pjs.git
Added window.scrollBy/scrollTo/scrollX/scrollY. Scopus bug 361046. R=troy
This commit is contained in:
Родитель
fdd101c1ad
Коммит
c043ed0abd
|
@ -115,6 +115,10 @@ public:
|
||||||
NS_IMETHOD GetPageYOffset(PRInt32* aPageYOffset)=0;
|
NS_IMETHOD GetPageYOffset(PRInt32* aPageYOffset)=0;
|
||||||
NS_IMETHOD SetPageYOffset(PRInt32 aPageYOffset)=0;
|
NS_IMETHOD SetPageYOffset(PRInt32 aPageYOffset)=0;
|
||||||
|
|
||||||
|
NS_IMETHOD GetScrollX(PRInt32* aScrollX)=0;
|
||||||
|
|
||||||
|
NS_IMETHOD GetScrollY(PRInt32* aScrollY)=0;
|
||||||
|
|
||||||
NS_IMETHOD Dump(const nsString& aStr)=0;
|
NS_IMETHOD Dump(const nsString& aStr)=0;
|
||||||
|
|
||||||
NS_IMETHOD Alert(JSContext* cx, jsval* argv, PRUint32 argc)=0;
|
NS_IMETHOD Alert(JSContext* cx, jsval* argv, PRUint32 argc)=0;
|
||||||
|
@ -222,6 +226,8 @@ public:
|
||||||
NS_IMETHOD SetPageXOffset(PRInt32 aPageXOffset); \
|
NS_IMETHOD SetPageXOffset(PRInt32 aPageXOffset); \
|
||||||
NS_IMETHOD GetPageYOffset(PRInt32* aPageYOffset); \
|
NS_IMETHOD GetPageYOffset(PRInt32* aPageYOffset); \
|
||||||
NS_IMETHOD SetPageYOffset(PRInt32 aPageYOffset); \
|
NS_IMETHOD SetPageYOffset(PRInt32 aPageYOffset); \
|
||||||
|
NS_IMETHOD GetScrollX(PRInt32* aScrollX); \
|
||||||
|
NS_IMETHOD GetScrollY(PRInt32* aScrollY); \
|
||||||
NS_IMETHOD Dump(const nsString& aStr); \
|
NS_IMETHOD Dump(const nsString& aStr); \
|
||||||
NS_IMETHOD Alert(JSContext* cx, jsval* argv, PRUint32 argc); \
|
NS_IMETHOD Alert(JSContext* cx, jsval* argv, PRUint32 argc); \
|
||||||
NS_IMETHOD Confirm(JSContext* cx, jsval* argv, PRUint32 argc, PRBool* aReturn); \
|
NS_IMETHOD Confirm(JSContext* cx, jsval* argv, PRUint32 argc, PRBool* aReturn); \
|
||||||
|
@ -299,6 +305,8 @@ public:
|
||||||
NS_IMETHOD SetPageXOffset(PRInt32 aPageXOffset) { return _to SetPageXOffset(aPageXOffset); } \
|
NS_IMETHOD SetPageXOffset(PRInt32 aPageXOffset) { return _to SetPageXOffset(aPageXOffset); } \
|
||||||
NS_IMETHOD GetPageYOffset(PRInt32* aPageYOffset) { return _to GetPageYOffset(aPageYOffset); } \
|
NS_IMETHOD GetPageYOffset(PRInt32* aPageYOffset) { return _to GetPageYOffset(aPageYOffset); } \
|
||||||
NS_IMETHOD SetPageYOffset(PRInt32 aPageYOffset) { return _to SetPageYOffset(aPageYOffset); } \
|
NS_IMETHOD SetPageYOffset(PRInt32 aPageYOffset) { return _to SetPageYOffset(aPageYOffset); } \
|
||||||
|
NS_IMETHOD GetScrollX(PRInt32* aScrollX) { return _to GetScrollX(aScrollX); } \
|
||||||
|
NS_IMETHOD GetScrollY(PRInt32* aScrollY) { return _to GetScrollY(aScrollY); } \
|
||||||
NS_IMETHOD Dump(const nsString& aStr) { return _to Dump(aStr); } \
|
NS_IMETHOD Dump(const nsString& aStr) { return _to Dump(aStr); } \
|
||||||
NS_IMETHOD Alert(JSContext* cx, jsval* argv, PRUint32 argc) { return _to Alert(cx, argv, argc); } \
|
NS_IMETHOD Alert(JSContext* cx, jsval* argv, PRUint32 argc) { return _to Alert(cx, argv, argc); } \
|
||||||
NS_IMETHOD Confirm(JSContext* cx, jsval* argv, PRUint32 argc, PRBool* aReturn) { return _to Confirm(cx, argv, argc, aReturn); } \
|
NS_IMETHOD Confirm(JSContext* cx, jsval* argv, PRUint32 argc, PRBool* aReturn) { return _to Confirm(cx, argv, argc, aReturn); } \
|
||||||
|
|
|
@ -31,6 +31,8 @@
|
||||||
attribute long screenY;
|
attribute long screenY;
|
||||||
attribute long pageXOffset;
|
attribute long pageXOffset;
|
||||||
attribute long pageYOffset;
|
attribute long pageYOffset;
|
||||||
|
readonly attribute long scrollX;
|
||||||
|
readonly attribute long scrollY;
|
||||||
|
|
||||||
void dump(in wstring str);
|
void dump(in wstring str);
|
||||||
void alert(/* ... */);
|
void alert(/* ... */);
|
||||||
|
|
|
@ -59,6 +59,8 @@
|
||||||
#include "nsIContentViewer.h"
|
#include "nsIContentViewer.h"
|
||||||
#include "nsIDocumentViewer.h"
|
#include "nsIDocumentViewer.h"
|
||||||
#include "nsIPresShell.h"
|
#include "nsIPresShell.h"
|
||||||
|
#include "nsIScrollableView.h"
|
||||||
|
#include "nsIDeviceContext.h"
|
||||||
#include "nsScreen.h"
|
#include "nsScreen.h"
|
||||||
#include "nsHistory.h"
|
#include "nsHistory.h"
|
||||||
#include "nsBarProps.h"
|
#include "nsBarProps.h"
|
||||||
|
@ -1419,18 +1421,113 @@ GlobalWindowImpl::SizeToContent()
|
||||||
return NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_INITIALIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
GlobalWindowImpl::GetScrollInfo(nsIScrollableView** aScrollableView,
|
||||||
|
float* aP2T, float* aT2P)
|
||||||
|
{
|
||||||
|
nsresult result = NS_OK;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIContentViewer> viewer;
|
||||||
|
result = mWebShell->GetContentViewer(getter_AddRefs(viewer));
|
||||||
|
if (NS_SUCCEEDED(result) && viewer) {
|
||||||
|
nsCOMPtr<nsIDocumentViewer> docv = do_QueryInterface(viewer, &result);
|
||||||
|
if (NS_SUCCEEDED(result)) {
|
||||||
|
nsCOMPtr<nsIPresContext> cx;
|
||||||
|
result = docv->GetPresContext(*getter_AddRefs(cx));
|
||||||
|
if (NS_SUCCEEDED(result)) {
|
||||||
|
|
||||||
|
cx->GetPixelsToTwips(aP2T);
|
||||||
|
cx->GetTwipsToPixels(aT2P);
|
||||||
|
|
||||||
|
nsCOMPtr<nsIPresShell> shell;
|
||||||
|
result = cx->GetShell(getter_AddRefs(shell));
|
||||||
|
if (NS_SUCCEEDED(result)) {
|
||||||
|
nsCOMPtr<nsIViewManager> vm;
|
||||||
|
result = shell->GetViewManager(getter_AddRefs(vm));
|
||||||
|
if (NS_SUCCEEDED(result)) {
|
||||||
|
result = vm->GetRootScrollableView(aScrollableView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
GlobalWindowImpl::ScrollTo(PRInt32 aXScroll, PRInt32 aYScroll)
|
GlobalWindowImpl::ScrollTo(PRInt32 aXScroll, PRInt32 aYScroll)
|
||||||
{
|
{
|
||||||
return NS_OK;
|
nsresult result;
|
||||||
|
nsIScrollableView* view;
|
||||||
|
float p2t, t2p;
|
||||||
|
|
||||||
|
result = GetScrollInfo(&view, &p2t, &t2p);
|
||||||
|
if (NS_SUCCEEDED(result) && view) {
|
||||||
|
result = view->ScrollTo(NSIntPixelsToTwips(aXScroll, p2t),
|
||||||
|
NSIntPixelsToTwips(aYScroll, p2t),
|
||||||
|
NS_VMREFRESH_IMMEDIATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
GlobalWindowImpl::ScrollBy(PRInt32 aXScrollDif, PRInt32 aYScrollDif)
|
GlobalWindowImpl::ScrollBy(PRInt32 aXScrollDif, PRInt32 aYScrollDif)
|
||||||
{
|
{
|
||||||
return NS_OK;
|
nsresult result;
|
||||||
|
nsIScrollableView* view;
|
||||||
|
float p2t, t2p;
|
||||||
|
|
||||||
|
result = GetScrollInfo(&view, &p2t, &t2p);
|
||||||
|
if (NS_SUCCEEDED(result) && view) {
|
||||||
|
nscoord xPos, yPos;
|
||||||
|
result = view->GetScrollPosition(xPos, yPos);
|
||||||
|
if (NS_SUCCEEDED(result)) {
|
||||||
|
result = view->ScrollTo(xPos + NSIntPixelsToTwips(aXScrollDif, p2t),
|
||||||
|
yPos + NSIntPixelsToTwips(aYScrollDif, p2t),
|
||||||
|
NS_VMREFRESH_IMMEDIATE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
GlobalWindowImpl::GetScrollX(PRInt32* aScrollX)
|
||||||
|
{
|
||||||
|
nsresult result;
|
||||||
|
nsIScrollableView* view;
|
||||||
|
float p2t, t2p;
|
||||||
|
|
||||||
|
result = GetScrollInfo(&view, &p2t, &t2p);
|
||||||
|
if (NS_SUCCEEDED(result) && view) {
|
||||||
|
nscoord xPos, yPos;
|
||||||
|
result = view->GetScrollPosition(xPos, yPos);
|
||||||
|
*aScrollX = NSTwipsToIntPixels(xPos, t2p);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
GlobalWindowImpl::GetScrollY(PRInt32* aScrollY)
|
||||||
|
{
|
||||||
|
nsresult result;
|
||||||
|
nsIScrollableView* view;
|
||||||
|
float p2t, t2p;
|
||||||
|
|
||||||
|
result = GetScrollInfo(&view, &p2t, &t2p);
|
||||||
|
if (NS_SUCCEEDED(result) && view) {
|
||||||
|
nscoord xPos, yPos;
|
||||||
|
result = view->GetScrollPosition(xPos, yPos);
|
||||||
|
*aScrollY = NSTwipsToIntPixels(yPos, t2p);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
GlobalWindowImpl::ClearTimeoutOrInterval(PRInt32 aTimerID)
|
GlobalWindowImpl::ClearTimeoutOrInterval(PRInt32 aTimerID)
|
||||||
{
|
{
|
||||||
|
|
|
@ -51,6 +51,7 @@ class nsIPresContext;
|
||||||
class nsIDOMEvent;
|
class nsIDOMEvent;
|
||||||
class nsIBrowserWindow;
|
class nsIBrowserWindow;
|
||||||
class nsIModalWindowSupport;
|
class nsIModalWindowSupport;
|
||||||
|
class nsIScrollableView;
|
||||||
|
|
||||||
#include "jsapi.h"
|
#include "jsapi.h"
|
||||||
|
|
||||||
|
@ -157,6 +158,8 @@ public:
|
||||||
NS_IMETHOD SizeToContent();
|
NS_IMETHOD SizeToContent();
|
||||||
NS_IMETHOD ScrollTo(PRInt32 aXScroll, PRInt32 aYScroll);
|
NS_IMETHOD ScrollTo(PRInt32 aXScroll, PRInt32 aYScroll);
|
||||||
NS_IMETHOD ScrollBy(PRInt32 aXScrollDif, PRInt32 aYScrollDif);
|
NS_IMETHOD ScrollBy(PRInt32 aXScrollDif, PRInt32 aYScrollDif);
|
||||||
|
NS_IMETHOD GetScrollX(PRInt32* aScrollX);
|
||||||
|
NS_IMETHOD GetScrollY(PRInt32* aScrollY);
|
||||||
|
|
||||||
NS_IMETHOD ClearTimeout(PRInt32 aTimerID);
|
NS_IMETHOD ClearTimeout(PRInt32 aTimerID);
|
||||||
NS_IMETHOD ClearInterval(PRInt32 aTimerID);
|
NS_IMETHOD ClearInterval(PRInt32 aTimerID);
|
||||||
|
@ -241,6 +244,8 @@ protected:
|
||||||
char *aFeatures, PRBool aNewWindow, PRBool aDialog);
|
char *aFeatures, PRBool aNewWindow, PRBool aDialog);
|
||||||
nsresult ReadyOpenedWebShell(nsIWebShell *aWebShell, nsIDOMWindow **aDOMWindow);
|
nsresult ReadyOpenedWebShell(nsIWebShell *aWebShell, nsIDOMWindow **aDOMWindow);
|
||||||
nsresult GetModalWindowSupport(nsIModalWindowSupport **msw);
|
nsresult GetModalWindowSupport(nsIModalWindowSupport **msw);
|
||||||
|
nsresult GetScrollInfo(nsIScrollableView** aScrollableView,
|
||||||
|
float* aP2T, float* aT2P);
|
||||||
|
|
||||||
static nsresult WebShellToDOMWindow(nsIWebShell *aWebShell, nsIDOMWindow **aDOMWindow);
|
static nsresult WebShellToDOMWindow(nsIWebShell *aWebShell, nsIDOMWindow **aDOMWindow);
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,9 @@ enum Window_slots {
|
||||||
WINDOW_SCREENX = -27,
|
WINDOW_SCREENX = -27,
|
||||||
WINDOW_SCREENY = -28,
|
WINDOW_SCREENY = -28,
|
||||||
WINDOW_PAGEXOFFSET = -29,
|
WINDOW_PAGEXOFFSET = -29,
|
||||||
WINDOW_PAGEYOFFSET = -30
|
WINDOW_PAGEYOFFSET = -30,
|
||||||
|
WINDOW_SCROLLX = -31,
|
||||||
|
WINDOW_SCROLLY = -32
|
||||||
};
|
};
|
||||||
|
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
|
@ -684,6 +686,42 @@ GetWindowProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case WINDOW_SCROLLX:
|
||||||
|
{
|
||||||
|
PRBool ok = PR_FALSE;
|
||||||
|
secMan->CheckScriptAccess(scriptCX, obj, "window.scrollx", PR_FALSE, &ok);
|
||||||
|
if (!ok) {
|
||||||
|
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
|
||||||
|
}
|
||||||
|
PRInt32 prop;
|
||||||
|
nsresult result = NS_OK;
|
||||||
|
result = a->GetScrollX(&prop);
|
||||||
|
if (NS_SUCCEEDED(result)) {
|
||||||
|
*vp = INT_TO_JSVAL(prop);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return nsJSUtils::nsReportError(cx, result);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case WINDOW_SCROLLY:
|
||||||
|
{
|
||||||
|
PRBool ok = PR_FALSE;
|
||||||
|
secMan->CheckScriptAccess(scriptCX, obj, "window.scrolly", PR_FALSE, &ok);
|
||||||
|
if (!ok) {
|
||||||
|
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
|
||||||
|
}
|
||||||
|
PRInt32 prop;
|
||||||
|
nsresult result = NS_OK;
|
||||||
|
result = a->GetScrollY(&prop);
|
||||||
|
if (NS_SUCCEEDED(result)) {
|
||||||
|
*vp = INT_TO_JSVAL(prop);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return nsJSUtils::nsReportError(cx, result);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
|
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
|
||||||
}
|
}
|
||||||
|
@ -2657,6 +2695,8 @@ static JSPropertySpec WindowProperties[] =
|
||||||
{"screenY", WINDOW_SCREENY, JSPROP_ENUMERATE},
|
{"screenY", WINDOW_SCREENY, JSPROP_ENUMERATE},
|
||||||
{"pageXOffset", WINDOW_PAGEXOFFSET, JSPROP_ENUMERATE},
|
{"pageXOffset", WINDOW_PAGEXOFFSET, JSPROP_ENUMERATE},
|
||||||
{"pageYOffset", WINDOW_PAGEYOFFSET, JSPROP_ENUMERATE},
|
{"pageYOffset", WINDOW_PAGEYOFFSET, JSPROP_ENUMERATE},
|
||||||
|
{"scrollX", WINDOW_SCROLLX, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||||
|
{"scrollY", WINDOW_SCROLLY, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||||
{0}
|
{0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче