add Bar properties to DOMWindow

This commit is contained in:
danm%netscape.com 1999-06-09 19:04:18 +00:00
Родитель 150967b568
Коммит 219d5cf489
6 изменённых файлов: 373 добавлений и 36 удалений

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

@ -28,6 +28,7 @@
class nsIDOMNavigator;
class nsIDOMElement;
class nsIDOMDocument;
class nsIDOMBarProp;
class nsIDOMScreen;
class nsIDOMHistory;
class nsIDOMWindowCollection;
@ -57,6 +58,20 @@ public:
NS_IMETHOD GetTop(nsIDOMWindow** aTop)=0;
NS_IMETHOD GetMenubar(nsIDOMBarProp** aMenubar)=0;
NS_IMETHOD GetToolbar(nsIDOMBarProp** aToolbar)=0;
NS_IMETHOD GetLocationbar(nsIDOMBarProp** aLocationbar)=0;
NS_IMETHOD GetPersonalbar(nsIDOMBarProp** aPersonalbar)=0;
NS_IMETHOD GetStatusbar(nsIDOMBarProp** aStatusbar)=0;
NS_IMETHOD GetScrollbars(nsIDOMBarProp** aScrollbars)=0;
NS_IMETHOD GetDirectories(nsIDOMBarProp** aDirectories)=0;
NS_IMETHOD GetClosed(PRBool* aClosed)=0;
NS_IMETHOD GetFrames(nsIDOMWindowCollection** aFrames)=0;
@ -156,6 +171,13 @@ public:
NS_IMETHOD GetHistory(nsIDOMHistory** aHistory); \
NS_IMETHOD GetParent(nsIDOMWindow** aParent); \
NS_IMETHOD GetTop(nsIDOMWindow** aTop); \
NS_IMETHOD GetMenubar(nsIDOMBarProp** aMenubar); \
NS_IMETHOD GetToolbar(nsIDOMBarProp** aToolbar); \
NS_IMETHOD GetLocationbar(nsIDOMBarProp** aLocationbar); \
NS_IMETHOD GetPersonalbar(nsIDOMBarProp** aPersonalbar); \
NS_IMETHOD GetStatusbar(nsIDOMBarProp** aStatusbar); \
NS_IMETHOD GetScrollbars(nsIDOMBarProp** aScrollbars); \
NS_IMETHOD GetDirectories(nsIDOMBarProp** aDirectories); \
NS_IMETHOD GetClosed(PRBool* aClosed); \
NS_IMETHOD GetFrames(nsIDOMWindowCollection** aFrames); \
NS_IMETHOD GetOpener(nsIDOMWindow** aOpener); \
@ -218,6 +240,13 @@ public:
NS_IMETHOD GetHistory(nsIDOMHistory** aHistory) { return _to GetHistory(aHistory); } \
NS_IMETHOD GetParent(nsIDOMWindow** aParent) { return _to GetParent(aParent); } \
NS_IMETHOD GetTop(nsIDOMWindow** aTop) { return _to GetTop(aTop); } \
NS_IMETHOD GetMenubar(nsIDOMBarProp** aMenubar) { return _to GetMenubar(aMenubar); } \
NS_IMETHOD GetToolbar(nsIDOMBarProp** aToolbar) { return _to GetToolbar(aToolbar); } \
NS_IMETHOD GetLocationbar(nsIDOMBarProp** aLocationbar) { return _to GetLocationbar(aLocationbar); } \
NS_IMETHOD GetPersonalbar(nsIDOMBarProp** aPersonalbar) { return _to GetPersonalbar(aPersonalbar); } \
NS_IMETHOD GetStatusbar(nsIDOMBarProp** aStatusbar) { return _to GetStatusbar(aStatusbar); } \
NS_IMETHOD GetScrollbars(nsIDOMBarProp** aScrollbars) { return _to GetScrollbars(aScrollbars); } \
NS_IMETHOD GetDirectories(nsIDOMBarProp** aDirectories) { return _to GetDirectories(aDirectories); } \
NS_IMETHOD GetClosed(PRBool* aClosed) { return _to GetClosed(aClosed); } \
NS_IMETHOD GetFrames(nsIDOMWindowCollection** aFrames) { return _to GetFrames(aFrames); } \
NS_IMETHOD GetOpener(nsIDOMWindow** aOpener) { return _to GetOpener(aOpener); } \

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

@ -53,6 +53,9 @@ interface nsIDOMScreen : nsISupports {};
[scriptable, uuid(896d1d20-b4c4-11d2-bd93-00805f8ae3f4)]
interface nsIDOMHistory : nsISupports {};
[scriptable, uuid(9eb2c150-1d56-11d3-8221-0060083a0bcf)]
interface nsIDOMBarProp : nsISupports {};
[scriptable, uuid(a6cf906f-15b3-11d2-932e-00805f8add32)]
interface nsIDOMWindowCollection : nsISupports {};
@ -66,6 +69,13 @@ interface nsIDOMWindow : nsISupports {
readonly attribute nsIDOMHistory history;
readonly attribute nsIDOMWindow parent;
readonly attribute nsIDOMWindow top;
readonly attribute nsIDOMBarProp menubar;
readonly attribute nsIDOMBarProp toolbar;
readonly attribute nsIDOMBarProp locationbar;
readonly attribute nsIDOMBarProp personalbar;
readonly attribute nsIDOMBarProp statusbar;
readonly attribute nsIDOMBarProp scrollbars;
readonly attribute nsIDOMBarProp directories;
readonly attribute boolean closed;
readonly attribute nsIDOMWindowCollection frames;
attribute nsIDOMWindow opener;

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

@ -9,6 +9,13 @@
readonly attribute History history;
readonly attribute Window parent;
readonly attribute Window top;
readonly attribute BarProp menubar;
readonly attribute BarProp toolbar;
readonly attribute BarProp locationbar;
readonly attribute BarProp personalbar;
readonly attribute BarProp statusbar;
readonly attribute BarProp scrollbars;
readonly attribute BarProp directories;
readonly attribute boolean closed;
readonly attribute WindowCollection frames;
attribute Window opener;

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

@ -34,6 +34,7 @@
#include "nsEventListenerManager.h"
#include "nsIEventStateManager.h"
#include "nsDOMEvent.h"
#include "nsIDOMBarProp.h"
#include "nsIDOMMouseListener.h"
#include "nsIDOMKeyListener.h"
#include "nsIDOMMouseMotionListener.h"
@ -56,6 +57,7 @@
#include "nsIContentViewer.h"
#include "nsScreen.h"
#include "nsHistory.h"
#include "nsBarProps.h"
#if defined(OJI)
#include "nsIJVMManager.h"
@ -105,6 +107,12 @@ GlobalWindowImpl::GlobalWindowImpl()
mNavigator = nsnull;
mScreen = nsnull;
mHistory = nsnull;
mMenubar = nsnull;
mToolbar = nsnull;
mLocationbar = nsnull;
mPersonalbar = nsnull;
mStatusbar = nsnull;
mScrollbars = nsnull;
mLocation = nsnull;
mFrames = nsnull;
mOpener = nsnull;
@ -132,6 +140,12 @@ GlobalWindowImpl::~GlobalWindowImpl()
NS_IF_RELEASE(mNavigator);
NS_IF_RELEASE(mScreen);
NS_IF_RELEASE(mHistory);
NS_IF_RELEASE(mMenubar);
NS_IF_RELEASE(mToolbar);
NS_IF_RELEASE(mLocationbar);
NS_IF_RELEASE(mPersonalbar);
NS_IF_RELEASE(mStatusbar);
NS_IF_RELEASE(mScrollbars);
NS_IF_RELEASE(mLocation);
NS_IF_RELEASE(mFrames);
NS_IF_RELEASE(mOpener);
@ -282,28 +296,34 @@ GlobalWindowImpl::SetWebShell(nsIWebShell *aWebShell)
mFrames->SetWebShell(aWebShell);
}
if (mWebShell)
{
// Get our enclosing chrome shell and retrieve its global window impl, so that we can
// do some forwarding to the chrome document.
nsCOMPtr<nsIWebShell> chromeShell;
mWebShell->GetContainingChromeShell(getter_AddRefs(chromeShell));
if (chromeShell) {
// Convert the chrome shell to a DOM window.
nsCOMPtr<nsIScriptContextOwner> contextOwner = do_QueryInterface(chromeShell);
if (contextOwner) {
nsCOMPtr<nsIScriptGlobalObject> globalObject;
if (NS_OK == contextOwner->GetScriptGlobalObject(getter_AddRefs(globalObject))) {
nsCOMPtr<nsIDOMWindow> chromeWindow = do_QueryInterface(globalObject);
if (chromeWindow) {
nsCOMPtr<nsIDOMDocument> chromeDoc;
chromeWindow->GetDocument(getter_AddRefs(chromeDoc));
nsCOMPtr<nsIDocument> realDoc = do_QueryInterface(chromeDoc);
mChromeDocument = realDoc.get(); // Don't addref it
}
}
}
}
if (mWebShell) {
// tell our member elements about the new browserwindow
nsIBrowserWindow *browser = nsnull;
GetBrowserWindowInterface(browser);
if (nsnull != mMenubar)
mMenubar->SetBrowserWindow(browser);
// Get our enclosing chrome shell and retrieve its global window impl, so that we can
// do some forwarding to the chrome document.
nsCOMPtr<nsIWebShell> chromeShell;
mWebShell->GetContainingChromeShell(getter_AddRefs(chromeShell));
if (chromeShell) {
// Convert the chrome shell to a DOM window.
nsCOMPtr<nsIScriptContextOwner> contextOwner = do_QueryInterface(chromeShell);
if (contextOwner) {
nsCOMPtr<nsIScriptGlobalObject> globalObject;
if (NS_OK == contextOwner->GetScriptGlobalObject(getter_AddRefs(globalObject))) {
nsCOMPtr<nsIDOMWindow> chromeWindow = do_QueryInterface(globalObject);
if (chromeWindow) {
nsCOMPtr<nsIDOMDocument> chromeDoc;
chromeWindow->GetDocument(getter_AddRefs(chromeDoc));
nsCOMPtr<nsIDocument> realDoc = do_QueryInterface(chromeDoc);
mChromeDocument = realDoc.get(); // Don't addref it
}
}
}
}
}
}
@ -399,6 +419,126 @@ GlobalWindowImpl::GetHistory(nsIDOMHistory** aHistory)
return NS_OK;
}
NS_IMETHODIMP
GlobalWindowImpl::GetMenubar(nsIDOMBarProp** aMenubar)
{
nsIBrowserWindow *browser;
if (nsnull == mMenubar) {
mMenubar = new MenubarPropImpl();
if (nsnull != mMenubar) {
NS_ADDREF(mMenubar);
if (nsnull != mWebShell && NS_OK == GetBrowserWindowInterface(browser))
mMenubar->SetBrowserWindow(browser);
}
}
*aMenubar = mMenubar;
NS_IF_ADDREF(mMenubar);
return NS_OK;
}
NS_IMETHODIMP
GlobalWindowImpl::GetToolbar(nsIDOMBarProp** aToolbar)
{
nsIBrowserWindow *browser;
if (nsnull == mToolbar) {
mToolbar = new ToolbarPropImpl();
if (nsnull != mToolbar) {
NS_ADDREF(mToolbar);
if (nsnull != mWebShell && NS_OK == GetBrowserWindowInterface(browser))
mToolbar->SetBrowserWindow(browser);
}
}
*aToolbar = mToolbar;
NS_IF_ADDREF(mToolbar);
return NS_OK;
}
NS_IMETHODIMP
GlobalWindowImpl::GetLocationbar(nsIDOMBarProp** aLocationbar)
{
nsIBrowserWindow *browser;
if (nsnull == mLocationbar) {
mLocationbar = new LocationbarPropImpl();
if (nsnull != mLocationbar) {
NS_ADDREF(mLocationbar);
if (nsnull != mWebShell && NS_OK == GetBrowserWindowInterface(browser))
mLocationbar->SetBrowserWindow(browser);
}
}
*aLocationbar = mLocationbar;
NS_IF_ADDREF(mLocationbar);
return NS_OK;
}
NS_IMETHODIMP
GlobalWindowImpl::GetPersonalbar(nsIDOMBarProp** aPersonalbar)
{
nsIBrowserWindow *browser;
if (nsnull == mPersonalbar) {
mPersonalbar = new PersonalbarPropImpl();
if (nsnull != mPersonalbar) {
NS_ADDREF(mPersonalbar);
if (nsnull != mWebShell && NS_OK == GetBrowserWindowInterface(browser))
mPersonalbar->SetBrowserWindow(browser);
}
}
*aPersonalbar = mPersonalbar;
NS_IF_ADDREF(mPersonalbar);
return NS_OK;
}
NS_IMETHODIMP
GlobalWindowImpl::GetStatusbar(nsIDOMBarProp** aStatusbar)
{
nsIBrowserWindow *browser;
if (nsnull == mStatusbar) {
mStatusbar = new StatusbarPropImpl();
if (nsnull != mStatusbar) {
NS_ADDREF(mStatusbar);
if (nsnull != mWebShell && NS_OK == GetBrowserWindowInterface(browser))
mStatusbar->SetBrowserWindow(browser);
}
}
*aStatusbar = mStatusbar;
NS_IF_ADDREF(mStatusbar);
return NS_OK;
}
NS_IMETHODIMP
GlobalWindowImpl::GetScrollbars(nsIDOMBarProp** aScrollbars)
{
nsIBrowserWindow *browser;
if (nsnull == mScrollbars) {
mScrollbars = new ScrollbarsPropImpl();
if (nsnull != mScrollbars) {
NS_ADDREF(mScrollbars);
if (nsnull != mWebShell && NS_OK == GetBrowserWindowInterface(browser))
mScrollbars->SetBrowserWindow(browser);
}
}
*aScrollbars = mScrollbars;
NS_IF_ADDREF(mScrollbars);
return NS_OK;
}
NS_IMETHODIMP
GlobalWindowImpl::GetDirectories(nsIDOMBarProp** aDirectories)
{
return GetPersonalbar(aDirectories);
}
NS_IMETHODIMP
GlobalWindowImpl::GetOpener(nsIDOMWindow** aOpener)
{

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

@ -39,6 +39,7 @@
#define PREF_BROWSER_STARTUP_HOMEPAGE "browser.startup.homepage"
class nsIEventListenerManager;
class nsIDOMBarProp;
class nsIDOMDocument;
class nsIDocument;
class nsIPresContext;
@ -49,6 +50,7 @@ class nsIBrowserWindow;
typedef struct nsTimeoutImpl nsTimeoutImpl;
class BarPropImpl;
class LocationImpl;
class NavigatorImpl;
class ScreenImpl;
@ -84,6 +86,13 @@ public:
NS_IMETHOD GetParent(nsIDOMWindow** aOpener);
NS_IMETHOD GetTop(nsIDOMWindow** aTop);
NS_IMETHOD GetClosed(PRBool* aClosed);
NS_IMETHOD GetMenubar(nsIDOMBarProp** aMenubar);
NS_IMETHOD GetToolbar(nsIDOMBarProp** aToolbar);
NS_IMETHOD GetLocationbar(nsIDOMBarProp** aLocationbar);
NS_IMETHOD GetPersonalbar(nsIDOMBarProp** aPersonalbar);
NS_IMETHOD GetStatusbar(nsIDOMBarProp** aStatusbar);
NS_IMETHOD GetScrollbars(nsIDOMBarProp** aScrollbars);
NS_IMETHOD GetDirectories(nsIDOMBarProp** aDirectories);
NS_IMETHOD GetFrames(nsIDOMWindowCollection** aFrames);
NS_IMETHOD GetOpener(nsIDOMWindow** aOpener);
@ -225,6 +234,12 @@ protected:
HistoryImpl *mHistory;
nsIWebShell *mWebShell;
nsIDOMWindow *mOpener;
BarPropImpl *mMenubar;
BarPropImpl *mToolbar;
BarPropImpl *mLocationbar;
BarPropImpl *mPersonalbar;
BarPropImpl *mStatusbar;
BarPropImpl *mScrollbars;
nsIDocument* mChromeDocument;

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

@ -30,6 +30,7 @@
#include "nsIDOMNavigator.h"
#include "nsIDOMElement.h"
#include "nsIDOMDocument.h"
#include "nsIDOMBarProp.h"
#include "nsIDOMScreen.h"
#include "nsIDOMHistory.h"
#include "nsIDOMEventListener.h"
@ -45,6 +46,7 @@ static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kINavigatorIID, NS_IDOMNAVIGATOR_IID);
static NS_DEFINE_IID(kIElementIID, NS_IDOMELEMENT_IID);
static NS_DEFINE_IID(kIDocumentIID, NS_IDOMDOCUMENT_IID);
static NS_DEFINE_IID(kIBarPropIID, NS_IDOMBARPROP_IID);
static NS_DEFINE_IID(kIScreenIID, NS_IDOMSCREEN_IID);
static NS_DEFINE_IID(kIHistoryIID, NS_IDOMHISTORY_IID);
static NS_DEFINE_IID(kIEventListenerIID, NS_IDOMEVENTLISTENER_IID);
@ -56,6 +58,7 @@ static NS_DEFINE_IID(kIWindowIID, NS_IDOMWINDOW_IID);
NS_DEF_PTR(nsIDOMNavigator);
NS_DEF_PTR(nsIDOMElement);
NS_DEF_PTR(nsIDOMDocument);
NS_DEF_PTR(nsIDOMBarProp);
NS_DEF_PTR(nsIDOMScreen);
NS_DEF_PTR(nsIDOMHistory);
NS_DEF_PTR(nsIDOMEventListener);
@ -76,20 +79,27 @@ enum Window_slots {
WINDOW_HISTORY = -6,
WINDOW_PARENT = -7,
WINDOW_TOP = -8,
WINDOW_CLOSED = -9,
WINDOW_FRAMES = -10,
WINDOW_OPENER = -11,
WINDOW_STATUS = -12,
WINDOW_DEFAULTSTATUS = -13,
WINDOW_NAME = -14,
WINDOW_INNERWIDTH = -15,
WINDOW_INNERHEIGHT = -16,
WINDOW_OUTERWIDTH = -17,
WINDOW_OUTERHEIGHT = -18,
WINDOW_SCREENX = -19,
WINDOW_SCREENY = -20,
WINDOW_PAGEXOFFSET = -21,
WINDOW_PAGEYOFFSET = -22
WINDOW_MENUBAR = -9,
WINDOW_TOOLBAR = -10,
WINDOW_LOCATIONBAR = -11,
WINDOW_PERSONALBAR = -12,
WINDOW_STATUSBAR = -13,
WINDOW_SCROLLBARS = -14,
WINDOW_DIRECTORIES = -15,
WINDOW_CLOSED = -16,
WINDOW_FRAMES = -17,
WINDOW_OPENER = -18,
WINDOW_STATUS = -19,
WINDOW_DEFAULTSTATUS = -20,
WINDOW_NAME = -21,
WINDOW_INNERWIDTH = -22,
WINDOW_INNERHEIGHT = -23,
WINDOW_OUTERWIDTH = -24,
WINDOW_OUTERHEIGHT = -25,
WINDOW_SCREENX = -26,
WINDOW_SCREENY = -27,
WINDOW_PAGEXOFFSET = -28,
WINDOW_PAGEYOFFSET = -29
};
/***********************************************************************/
@ -250,6 +260,125 @@ GetWindowProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
}
break;
}
case WINDOW_MENUBAR:
{
secMan->CheckScriptAccess(scriptCX, obj, "window.menubar", &ok);
if (!ok) {
//Need to throw error here
return JS_FALSE;
}
nsIDOMBarProp* prop;
if (NS_OK == a->GetMenubar(&prop)) {
// get the js object
nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp);
}
else {
return JS_FALSE;
}
break;
}
case WINDOW_TOOLBAR:
{
secMan->CheckScriptAccess(scriptCX, obj, "window.toolbar", &ok);
if (!ok) {
//Need to throw error here
return JS_FALSE;
}
nsIDOMBarProp* prop;
if (NS_OK == a->GetToolbar(&prop)) {
// get the js object
nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp);
}
else {
return JS_FALSE;
}
break;
}
case WINDOW_LOCATIONBAR:
{
secMan->CheckScriptAccess(scriptCX, obj, "window.locationbar", &ok);
if (!ok) {
//Need to throw error here
return JS_FALSE;
}
nsIDOMBarProp* prop;
if (NS_OK == a->GetLocationbar(&prop)) {
// get the js object
nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp);
}
else {
return JS_FALSE;
}
break;
}
case WINDOW_PERSONALBAR:
{
secMan->CheckScriptAccess(scriptCX, obj, "window.personalbar", &ok);
if (!ok) {
//Need to throw error here
return JS_FALSE;
}
nsIDOMBarProp* prop;
if (NS_OK == a->GetPersonalbar(&prop)) {
// get the js object
nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp);
}
else {
return JS_FALSE;
}
break;
}
case WINDOW_STATUSBAR:
{
secMan->CheckScriptAccess(scriptCX, obj, "window.statusbar", &ok);
if (!ok) {
//Need to throw error here
return JS_FALSE;
}
nsIDOMBarProp* prop;
if (NS_OK == a->GetStatusbar(&prop)) {
// get the js object
nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp);
}
else {
return JS_FALSE;
}
break;
}
case WINDOW_SCROLLBARS:
{
secMan->CheckScriptAccess(scriptCX, obj, "window.scrollbars", &ok);
if (!ok) {
//Need to throw error here
return JS_FALSE;
}
nsIDOMBarProp* prop;
if (NS_OK == a->GetScrollbars(&prop)) {
// get the js object
nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp);
}
else {
return JS_FALSE;
}
break;
}
case WINDOW_DIRECTORIES:
{
secMan->CheckScriptAccess(scriptCX, obj, "window.directories", &ok);
if (!ok) {
//Need to throw error here
return JS_FALSE;
}
nsIDOMBarProp* prop;
if (NS_OK == a->GetDirectories(&prop)) {
// get the js object
nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp);
}
else {
return JS_FALSE;
}
break;
}
case WINDOW_CLOSED:
{
secMan->CheckScriptAccess(scriptCX, obj, "window.closed", &ok);
@ -2370,6 +2499,13 @@ static JSPropertySpec WindowProperties[] =
{"history", WINDOW_HISTORY, JSPROP_ENUMERATE | JSPROP_READONLY},
{"parent", WINDOW_PARENT, JSPROP_ENUMERATE | JSPROP_READONLY},
{"top", WINDOW_TOP, JSPROP_ENUMERATE | JSPROP_READONLY},
{"menubar", WINDOW_MENUBAR, JSPROP_ENUMERATE | JSPROP_READONLY},
{"toolbar", WINDOW_TOOLBAR, JSPROP_ENUMERATE | JSPROP_READONLY},
{"locationbar", WINDOW_LOCATIONBAR, JSPROP_ENUMERATE | JSPROP_READONLY},
{"personalbar", WINDOW_PERSONALBAR, JSPROP_ENUMERATE | JSPROP_READONLY},
{"statusbar", WINDOW_STATUSBAR, JSPROP_ENUMERATE | JSPROP_READONLY},
{"scrollbars", WINDOW_SCROLLBARS, JSPROP_ENUMERATE | JSPROP_READONLY},
{"directories", WINDOW_DIRECTORIES, JSPROP_ENUMERATE | JSPROP_READONLY},
{"closed", WINDOW_CLOSED, JSPROP_ENUMERATE | JSPROP_READONLY},
{"frames", WINDOW_FRAMES, JSPROP_ENUMERATE | JSPROP_READONLY},
{"opener", WINDOW_OPENER, JSPROP_ENUMERATE},