adding partial (for DOM elements) chromemask support to apprunner

This commit is contained in:
danm%netscape.com 1999-05-19 04:11:54 +00:00
Родитель dc1b16fd0a
Коммит f8b9684c67
6 изменённых файлов: 155 добавлений и 80 удалений

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

@ -1554,7 +1554,7 @@ GlobalWindowImpl::CalculateChromeFlags(char *aFeatures) {
PRUint32 chromeFlags = 0;
if (nsnull == aFeatures)
return (PRUint32)~0; // default is fully chromed (but don't copy history?)
return NS_CHROME_ALL_CHROME;
chromeFlags |= WinHasOption(aFeatures, "toolbar") ? NS_CHROME_TOOL_BAR_ON : 0;
chromeFlags |= WinHasOption(aFeatures, "location") ? NS_CHROME_LOCATION_BAR_ON : 0;

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

@ -36,17 +36,18 @@ struct nsRect;
{ 0xa6cf905d, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
// Chrome mask
#define NS_CHROME_WINDOW_BORDERS_ON 0x001
#define NS_CHROME_WINDOW_CLOSE_ON 0x002
#define NS_CHROME_WINDOW_RESIZE_ON 0x004
#define NS_CHROME_MENU_BAR_ON 0x008
#define NS_CHROME_TOOL_BAR_ON 0x010
#define NS_CHROME_LOCATION_BAR_ON 0x020
#define NS_CHROME_STATUS_BAR_ON 0x040
#define NS_CHROME_PERSONAL_TOOLBAR_ON 0x080
#define NS_CHROME_SCROLLBARS_ON 0x100
#define NS_CHROME_TITLEBAR_ON 0x200
#define NS_CHROME_OPEN_AS_CHROME 0x400
#define NS_CHROME_WINDOW_BORDERS_ON 0x00000001
#define NS_CHROME_WINDOW_CLOSE_ON 0x00000002
#define NS_CHROME_WINDOW_RESIZE_ON 0x00000004
#define NS_CHROME_MENU_BAR_ON 0x00000008
#define NS_CHROME_TOOL_BAR_ON 0x00000010
#define NS_CHROME_LOCATION_BAR_ON 0x00000020
#define NS_CHROME_STATUS_BAR_ON 0x00000040
#define NS_CHROME_PERSONAL_TOOLBAR_ON 0x00000080
#define NS_CHROME_SCROLLBARS_ON 0x00000100
#define NS_CHROME_TITLEBAR_ON 0x00000200
#define NS_CHROME_OPEN_AS_CHROME 0x80000000
#define NS_CHROME_ALL_CHROME 0x000003FF
/**
* API to a "browser window". A browser window contains a toolbar, a web shell

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

@ -187,8 +187,9 @@ nsWebShellWindow::nsWebShellWindow()
mCallbacks = nsnull;
mContinueModalLoop = PR_FALSE;
mChromeInitialized = PR_FALSE;
mLockedUntilChromeLoad = PR_FALSE;
mLockedUntilChromeLoad = PR_FALSE;
mContentShells = nsnull;
mChromeMask = NS_CHROME_ALL_CHROME;
}
@ -326,8 +327,8 @@ nsresult nsWebShellWindow::Initialize(nsIWebShellWindow* aParent,
mWebShell->SetObserver((nsIStreamObserver*)anObserver);
mWebShell->SetDocLoaderObserver(this);
// The outermost web shell is always considered to be chrome.
mWebShell->SetWebShellType(nsWebShellChrome);
// The outermost web shell is always considered to be chrome.
mWebShell->SetWebShellType(nsWebShellChrome);
/*
* XXX: How should preferences be supplied to the nsWebShellWindow?
@ -365,9 +366,9 @@ NS_METHOD
nsWebShellWindow::Close()
{
ExitModalLoop();
if ( mWebShell ) {
if (mWebShell) {
mWebShell->Destroy();
NS_IF_RELEASE(mWebShell);
NS_RELEASE(mWebShell);
}
NS_IF_RELEASE(mWindow);
@ -446,7 +447,7 @@ NS_IMETHODIMP
nsWebShellWindow::BeginLoadURL(nsIWebShell* aShell, const PRUnichar* aURL)
{
// If loading a new root .xul document, then redo chrome.
if ( aShell == mWebShell ) {
if (aShell == mWebShell) {
mChromeInitialized = PR_FALSE;
}
return NS_OK;
@ -1125,10 +1126,15 @@ nsWebShellWindow::NewWebShell(PRUint32 aChromeMask, PRBool aVisible,
if ((aChromeMask & NS_CHROME_OPEN_AS_CHROME) != 0) {
// Just do a nice normal create of a web shell and
// return it immediately.
appShell->CreateTopLevelWindow(nsnull, nsnull, PR_FALSE, *getter_AddRefs(newWindow),
rv = appShell->CreateTopLevelWindow(nsnull, nsnull, PR_FALSE, *getter_AddRefs(newWindow),
nsnull, nsnull, 615, 480);
newWindow->GetWebShell(aNewWebShell); // GetWebShell does the addref.
return NS_OK;
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIBrowserWindow> browser(do_QueryInterface(newWindow));
if (browser)
browser->SetChrome(aChromeMask);
newWindow->GetWebShell(aNewWebShell); // GetWebShell does the addref.
}
return rv;
}
#ifdef XP_PC // XXX: Won't work on any other platforms yet. Sigh.
@ -1148,53 +1154,63 @@ nsWebShellWindow::NewWebShell(PRUint32 aChromeMask, PRBool aVisible,
nsCOMPtr<nsIURL> urlObj;
rv = NS_NewURL(getter_AddRefs(urlObj), "chrome://navigator/content/");
if (NS_FAILED(rv))
return rv;
appShell->CreateTopLevelWindow(nsnull, urlObj, PR_FALSE, *getter_AddRefs(newWindow),
nsnull, nsnull, 615, 480);
if (NS_SUCCEEDED(rv))
rv = appShell->CreateTopLevelWindow(nsnull, urlObj, PR_FALSE, *getter_AddRefs(newWindow),
nsnull, nsnull, 615, 480);
// Spin into the modal loop.
nsIAppShell *subshell;
rv = nsComponentManager::CreateInstance(kAppShellCID, nsnull, kIAppShellIID, (void**)&subshell);
if (NS_FAILED(rv))
return rv;
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIBrowserWindow> browser(do_QueryInterface(newWindow));
if (browser)
browser->SetChrome(aChromeMask);
subshell->Create(0, nsnull);
subshell->Spinup(); // Spin up
// Specify that we want the window to remain locked until the chrome has loaded.
newWindow->LockUntilChromeLoad();
PRBool locked = PR_FALSE;
newWindow->GetLockedState(locked);
while (NS_SUCCEEDED(rv) && locked) {
void *data;
PRBool isRealEvent;
rv = subshell->GetNativeEvent(isRealEvent, data);
subshell->DispatchNativeEvent(isRealEvent, data);
newWindow->GetLockedState(locked);
// Spin into the modal loop.
rv = nsComponentManager::CreateInstance(kAppShellCID, nsnull, kIAppShellIID, (void**)&subshell);
}
// Get rid of the nested UI thread queue used for netlib, and release the event queue service.
eQueueService->PopThreadEventQueue();
if (NS_SUCCEEDED(rv)) {
subshell->Spindown();
NS_RELEASE(subshell);
subshell->Create(0, nsnull);
subshell->Spinup(); // Spin up
// Specify that we want the window to remain locked until the chrome has loaded.
newWindow->LockUntilChromeLoad();
PRBool locked = PR_FALSE;
nsresult looprv = NS_OK;
newWindow->GetLockedState(locked);
while (NS_SUCCEEDED(looprv) && locked) {
void *data;
PRBool isRealEvent;
looprv = subshell->GetNativeEvent(isRealEvent, data);
subshell->DispatchNativeEvent(isRealEvent, data);
newWindow->GetLockedState(locked);
}
// Get rid of the nested UI thread queue used for netlib, and release the event queue service.
eQueueService->PopThreadEventQueue();
subshell->Spindown();
NS_RELEASE(subshell);
}
// We're out of the nested loop.
// During the layout of the new window, all content shells were located and placed
// into the new window's content shell array. Locate the "content area" content
// shell.
if (NS_FAILED(rv = newWindow->GetContentShellById("content", &aNewWebShell))) {
NS_ERROR("Unable to obtain a browser content shell.");
return rv;
if (NS_SUCCEEDED(rv)) {
rv = newWindow->GetContentShellById("content", &aNewWebShell);
if (NS_FAILED(rv)) {
NS_ERROR("Unable to obtain a browser content shell.");
return rv;
}
}
#endif // XP_PC
return NS_OK;
return rv;
}
@ -1344,8 +1360,8 @@ nsWebShellWindow::OnEndDocumentLoad(nsIDocumentLoader* loader,
mChromeInitialized = PR_TRUE;
if (mLockedUntilChromeLoad) {
mLockedUntilChromeLoad = PR_FALSE;
if (mLockedUntilChromeLoad) {
mLockedUntilChromeLoad = PR_FALSE;
}
// register as document listener
@ -1377,12 +1393,12 @@ nsWebShellWindow::OnEndDocumentLoad(nsIDocumentLoader* loader,
#ifdef XP_MAC
LoadMenus(menubarDOMDoc, mWindow);
// Context Menu test
nsCOMPtr<nsIDOMElement> element;
menubarDOMDoc->GetDocumentElement(getter_AddRefs(element));
nsCOMPtr<nsIDOMNode> window(do_QueryInterface(element));
nsCOMPtr<nsIDOMElement> element;
menubarDOMDoc->GetDocumentElement(getter_AddRefs(element));
nsCOMPtr<nsIDOMNode> window(do_QueryInterface(element));
int endCount = 0;
contextMenuTest = FindNamedDOMNode(nsAutoString("contextmenu"), window, endCount, 1);
int endCount = 0;
contextMenuTest = FindNamedDOMNode(nsAutoString("contextmenu"), window, endCount, 1);
// End Context Menu test
#else
DynamicLoadMenus(menubarDOMDoc, mWindow);
@ -1391,6 +1407,7 @@ nsWebShellWindow::OnEndDocumentLoad(nsIDocumentLoader* loader,
SetSizeFromXUL();
SetTitleFromXUL();
ShowAppropriateChrome();
#if 0
nsCOMPtr<nsIDOMDocument> toolbarDOMDoc(GetNamedDOMDoc(nsAutoString("browser.toolbar")));
@ -1810,7 +1827,6 @@ void nsWebShellWindow::SetSizeFromXUL()
}
}
mWindow->GetBounds(currentSize);
windowWidget->Resize(currentSize.width, specHeight, PR_TRUE);
}
#endif
} // SetSizeFromXUL
@ -1831,6 +1847,66 @@ void nsWebShellWindow::SetTitleFromXUL()
} // SetTitleFromXUL
#include "nsIDOMXULElement.h"
// show/hide contents according to the current chrome mask
void nsWebShellWindow::ShowAppropriateChrome()
{
nsCOMPtr<nsIDOMElement> rootElement;
nsCOMPtr<nsIDOMXULElement> xulRoot;
nsCOMPtr<nsIDOMDocument> chromeDoc;
nsCOMPtr<nsIDOMWindow> domWindow;
// get this window's document
if (NS_FAILED(ConvertWebShellToDOMWindow(mWebShell, getter_AddRefs(domWindow))))
return;
if (NS_FAILED(domWindow->GetDocument(getter_AddRefs(chromeDoc))))
return;
if (NS_FAILED(chromeDoc->GetDocumentElement(getter_AddRefs(rootElement))))
return;
// get a list of this document's elements with the chromeclass attribute specified
xulRoot = do_QueryInterface(rootElement);
if (xulRoot) { // todo (maybe) the longer, straight DOM (not RDF) version?
nsCOMPtr<nsIDOMNodeList> chromeNodes;
if (NS_SUCCEEDED(xulRoot->GetElementsByAttribute("chromeclass", "*",
getter_AddRefs(chromeNodes)))) {
PRUint32 nodeCtr, nodeCount;
chromeNodes->GetLength(&nodeCount);
for (nodeCtr = 0; nodeCtr < nodeCount; nodeCtr++) {
nsCOMPtr<nsIDOMNode> domNode;
nsCOMPtr<nsIDOMElement> domElement;
chromeNodes->Item(nodeCtr, getter_AddRefs(domNode));
domElement = do_QueryInterface(domNode);
if (domElement) {
nsAutoString chromeClass;
PRBool makeChange;
PRUint32 flag;
// show or hide the element according to its chromeclass and the chromemask
domElement->GetAttribute("chromeclass", chromeClass);
makeChange = PR_FALSE;
if (chromeClass == "location") {
makeChange = PR_TRUE;
flag = mChromeMask & NS_CHROME_LOCATION_BAR_ON;
} else if (chromeClass == "menubar") {
makeChange = PR_TRUE;
flag = mChromeMask & NS_CHROME_MENU_BAR_ON;
} else if (chromeClass == "status") {
makeChange = PR_TRUE;
flag = mChromeMask & NS_CHROME_STATUS_BAR_ON;
} else if (chromeClass == "toolbar") {
makeChange = PR_TRUE;
flag = mChromeMask & NS_CHROME_TOOL_BAR_ON;
}
if (makeChange)
domElement->SetAttribute("chromehidden", "");
else
domElement->RemoveAttribute("chromehidden");
}
}
}
}
}
//----------------------------------------------------------------
//-- nsIDocumentObserver
//----------------------------------------------------------------
@ -2017,7 +2093,6 @@ NS_IMETHODIMP nsWebShellWindow::Init(nsIAppShell* aAppShell,
nsresult rv;
nsCOMPtr<nsIURL> urlObj;
// (temporary)
rv = NS_NewURL(getter_AddRefs(urlObj), "chrome://navigator/content/");
if (NS_FAILED(rv))
return rv;
@ -2027,6 +2102,7 @@ NS_IMETHODIMP nsWebShellWindow::Init(nsIAppShell* aAppShell,
// a generic browser appcore here someday.
rv = Initialize(nsnull, aAppShell, urlObj,
nsnull, nsnull, aBounds.width, aBounds.height);
mChromeMask = aChromeMask;
if (NS_SUCCEEDED(rv))
MoveTo(aBounds.x, aBounds.y);
return rv;
@ -2058,20 +2134,14 @@ NS_IMETHODIMP nsWebShellWindow::GetWindowBounds(nsRect& aResult)
NS_IMETHODIMP nsWebShellWindow::SetChrome(PRUint32 aNewChromeMask)
{
// yeah sure. we got your chrome changes.
mChromeMask = aNewChromeMask;
ShowAppropriateChrome();
return NS_OK;
}
NS_IMETHODIMP nsWebShellWindow::GetChrome(PRUint32& aChromeMaskResult)
{
// Do our best to fake an interesting, rather inapplicable concept from the old world.
// We can't tell what sort of chrome features we have until we invent a standard
// for XUL chrome elements, and then go looking for them. For now, take a guess...
aChromeMaskResult = NS_CHROME_WINDOW_BORDERS_ON | NS_CHROME_WINDOW_CLOSE_ON |
NS_CHROME_WINDOW_RESIZE_ON | NS_CHROME_MENU_BAR_ON |
NS_CHROME_TOOL_BAR_ON | NS_CHROME_LOCATION_BAR_ON |
NS_CHROME_STATUS_BAR_ON | NS_CHROME_PERSONAL_TOOLBAR_ON |
NS_CHROME_SCROLLBARS_ON | NS_CHROME_TITLEBAR_ON;
aChromeMaskResult = mChromeMask;
return NS_OK;
}

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

@ -55,7 +55,7 @@ class nsVoidArray;
class nsWebShellWindow : public nsIWebShellWindow,
public nsIWebShellContainer,
public nsIBrowserWindow,
public nsIBrowserWindow,
public nsIDocumentLoaderObserver,
public nsIDocumentObserver
{
@ -241,7 +241,7 @@ protected:
void ExecuteStartupCode();
void SetSizeFromXUL();
void SetTitleFromXUL();
void ShowAppropriateChrome();
virtual ~nsWebShellWindow();
@ -253,8 +253,9 @@ protected:
nsIWebShell* mWebShell;
nsIXULWindowCallbacks* mCallbacks;
PRBool mContinueModalLoop;
PRBool mLockedUntilChromeLoad;
PRBool mLockedUntilChromeLoad;
PRBool mChromeInitialized;
PRUint32 mChromeMask;
nsVoidArray mMenuDelegates;

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

@ -1,6 +1,10 @@
/** Contains style definitions for the navigator application
**/
[chromehidden] { /* what to do if chrome requests you be invisible */
display: none;
}
titledbutton#print-button {
list-style-image:url(resource:/res/toolbar/TB_Print.gif);
}

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

@ -265,8 +265,7 @@
<broadcaster id="Browser:Throbber" busy="false"/>
<broadcaster id="args" value="http://www.mozilla.org/quality/smoketests/"/>
<menubar>
<menubar chromeclass="menubar">
<menu name="&fileMenu.label;">
<menuitem name="&browserCmd.label;" onclick="BrowserNewWindow();"/>
<menu name="New">
@ -551,7 +550,7 @@
<box id="outer-box" align="vertical">
<toolbox>
<toolbar class="main-bar">
<toolbar class="main-bar" chromeclass="toolbar">
<titledbutton id="back-button" align="bottom" value="&backButton.label;" onclick="BrowserBack()">
<observes element="canGoBack" attribute="disabled" onChange="BrowserSetBack()"/>
</titledbutton>
@ -573,7 +572,7 @@
<box align="vertical" flex="100%">
<spring flex="100%"/>
<html:input id="urlbar" type="text" style="min-width: 100px; min-height: 25px"
<html:input id="urlbar" type="text" chromeclass="location" style="min-width: 100px; min-height: 25px"
onkeyup="if (event.which == 13) { BrowserLoadURL(); }"/>
<spring flex="100%"/>
</box>
@ -587,7 +586,7 @@
</titledbutton>
</toolbar>
<toolbar class="main-bar">
<toolbar class="main-bar" chromeclass="toolbar">
<titledbutton id="home-button" align="right" value="&homeButton.label;"
onclick="BrowserHome()"/>
<titledbutton id="netscape-button" align="right" value="&netscapeButton.label;"
@ -633,7 +632,7 @@
</box>
<toolbox>
<toolbar id="taskbar">
<toolbar id="taskbar" chromeclass="status">
<box align="horizontal">
<titledbutton align="left" class="popup" value="&webButton.label;" />
<titledbutton align="left" class="popup" value="&mailButton.label;" />