landing v1.1 patch for 257162 "core changes required to enable XULRunner functionality" r=biesi,sr=blizzard

This commit is contained in:
darin%meer.net 2004-09-07 18:59:27 +00:00
parent b853169d42
commit 77f38a74b2
8 changed files with 160 additions and 185 deletions

View File

@ -2257,7 +2257,7 @@ NS_IMETHODIMP nsWindow::SetTitle(const nsAString& aTitle)
PRInt32 platformLen;
// Set UTF8_STRING title for NET_WM-supporting window managers
NS_ConvertUCS2toUTF8 utf8_title(aTitle);
NS_ConvertUTF16toUTF8 utf8_title(aTitle);
XChangeProperty(GDK_DISPLAY(), GDK_WINDOW_XWINDOW(mShell->window),
XInternAtom(GDK_DISPLAY(), "_NET_WM_NAME", False),
XInternAtom(GDK_DISPLAY(), "UTF8_STRING", False),
@ -2320,11 +2320,11 @@ NS_IMETHODIMP nsWindow::SetTitle(const nsAString& aTitle)
}
NS_IMETHODIMP
nsWindow::SetIcon(const nsAString& aIcon)
nsWindow::SetIcon(const nsAString& aIconSpec)
{
// See if we have a cached icon set for this window type.
// Note that icon specs must be UTF8.
NS_ConvertUCS2toUTF8 iconKey(aIcon);
NS_ConvertUTF16toUTF8 iconKey(aIconSpec);
IconEntry* entry = NS_STATIC_CAST(IconEntry*,
PL_DHashTableOperate(sIconCache,
iconKey.get(),
@ -2338,70 +2338,40 @@ nsWindow::SetIcon(const nsAString& aIcon)
PRUint32 generation = sIconCache->generation;
#endif
// Have necko resolve this to a file for us.
nsCOMPtr<nsIIOService> ioService = do_GetIOService();
nsCOMPtr<nsIURI> iconURI;
NS_NewURI(getter_AddRefs(iconURI), aIcon);
nsCAutoString scheme;
iconURI->GetScheme(scheme);
nsCOMPtr<nsIProtocolHandler> handler;
ioService->GetProtocolHandler(scheme.get(), getter_AddRefs(handler));
nsCOMPtr<nsIResProtocolHandler> resHandler = do_QueryInterface(handler);
nsCAutoString fileURLSpec;
resHandler->ResolveURI(iconURI, fileURLSpec);
// We now have the file path as a file URL. Resolve to a filesystem path.
NS_NewURI(getter_AddRefs(iconURI), fileURLSpec);
nsCOMPtr<nsIFileURL> iconFileURL = do_QueryInterface(iconURI);
NS_ENSURE_TRUE(iconFileURL, NS_ERROR_UNEXPECTED);
nsCOMPtr<nsIFile> fileTarget;
iconFileURL->GetFile(getter_AddRefs(fileTarget));
nsCAutoString fileTargetPath;
fileTarget->GetNativePath(fileTargetPath);
GtkStyle* w_style;
GdkPixmap* w_pixmap = NULL, *w_minipixmap = NULL;
GdkBitmap* w_mask = NULL, *w_minimask = NULL;
w_style = gtk_widget_get_style(mShell);
nsCAutoString largeIconPath(fileTargetPath);
largeIconPath.Append(".xpm");
nsCOMPtr<nsILocalFile> largeIconFile;
NS_NewNativeLocalFile(largeIconPath, PR_TRUE, getter_AddRefs(largeIconFile));
#ifdef DEBUG_ICONS
printf("Looking for large icon file: %s\n", largeIconPath.get());
#endif
PRBool exists;
if (NS_SUCCEEDED(largeIconFile->Exists(&exists)) && exists) {
nsCAutoString nativePath;
largeIconFile->GetNativePath(nativePath);
nsCOMPtr<nsILocalFile> iconFile;
ResolveIconName(aIconSpec, NS_LITERAL_STRING(".xpm"),
getter_AddRefs(iconFile));
if (iconFile) {
nsCAutoString path;
iconFile->GetNativePath(path);
w_pixmap = gdk_pixmap_create_from_xpm(mShell->window,
&w_mask,
&w_style->bg[GTK_STATE_NORMAL],
nativePath.get());
path.get());
#ifdef DEBUG_ICONS
printf("Loaded large icon file: %s\n", largeIconPath.get());
printf("Loaded large icon file: %s\n", path.get());
#endif
}
nsCAutoString smallIconPath(fileTargetPath);
smallIconPath.Append("16.xpm");
nsCOMPtr<nsILocalFile> smallIconFile;
NS_NewNativeLocalFile(smallIconPath, PR_TRUE, getter_AddRefs(smallIconFile));
#ifdef DEBUG_ICONS
printf("Looking for small icon file: %s\n", smallIconPath.get());
#endif
if (NS_SUCCEEDED(smallIconFile->Exists(&exists)) && exists) {
nsCAutoString nativePath;
smallIconFile->GetNativePath(nativePath);
ResolveIconName(aIconSpec, NS_LITERAL_STRING("16.xpm"),
getter_AddRefs(iconFile));
if (iconFile) {
nsCAutoString path;
iconFile->GetNativePath(path);
w_minipixmap = gdk_pixmap_create_from_xpm(mShell->window,
&w_minimask,
&w_style->bg[GTK_STATE_NORMAL],
nativePath.get());
path.get());
#ifdef DEBUG_ICONS
printf("Loaded small icon file: %s\n", smallIconPath.get());
printf("Loaded small icon file: %s\n", path.get());
#endif
}

View File

@ -936,55 +936,30 @@ nsWindow::SetIcon(const nsAString& aIconSpec)
if (!mShell)
return NS_OK;
// Start at the app chrome directory.
nsCOMPtr<nsIFile> chromeDir;
nsresult rv = NS_GetSpecialDirectory(NS_APP_CHROME_DIR,
getter_AddRefs(chromeDir));
if (NS_FAILED(rv))
return rv;
// Get the native file name of that directory.
nsAutoString iconPath;
chromeDir->GetPath(iconPath);
// Now take input path...
nsAutoString iconSpec(aIconSpec);
// ...append ".xpm" to it
iconSpec.AppendLiteral(".xpm");
// ...and figure out where /chrome/... is within that
// (and skip the "resource:///chrome" part).
nsAutoString key(NS_LITERAL_STRING("/chrome/"));
PRInt32 n = iconSpec.Find(key) + key.Length();
// Append that to icon resource path.
iconPath.Append(iconSpec.get() + n - 1);
nsCOMPtr<nsILocalFile> pathConverter;
rv = NS_NewLocalFile(iconPath, PR_TRUE,
getter_AddRefs(pathConverter));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsILocalFile> iconFile;
nsCAutoString path;
pathConverter->GetNativePath(path);
nsCStringArray iconList;
iconList.AppendCString(path);
// Assume the given string is a local identifier for an icon file.
ResolveIconName(aIconSpec, NS_LITERAL_STRING(".xpm"),
getter_AddRefs(iconFile));
if (iconFile) {
iconFile->GetNativePath(path);
iconList.AppendCString(path);
}
// Get the 16px icon path as well
iconSpec = aIconSpec + NS_LITERAL_STRING("16.xpm");
ResolveIconName(aIconSpec, NS_LITERAL_STRING("16.xpm"),
getter_AddRefs(iconFile));
if (iconFile) {
iconFile->GetNativePath(path);
iconList.AppendCString(path);
}
chromeDir->GetPath(iconPath);
iconPath.Append(iconSpec.get() + n - 1);
rv = NS_NewLocalFile(iconPath, PR_TRUE,
getter_AddRefs(pathConverter));
if (NS_FAILED(rv))
return rv;
pathConverter->GetNativePath(path);
iconList.AppendCString(path);
// leave the default icon intact if no matching icons were found
if (iconList.Count() == 0)
return NS_OK;
return SetWindowIconList(iconList);
}
@ -2872,26 +2847,17 @@ void
nsWindow::SetDefaultIcon(void)
{
// Set up the default window icon
nsresult rv;
nsCOMPtr<nsIFile> chromeDir;
rv = NS_GetSpecialDirectory(NS_APP_CHROME_DIR,
getter_AddRefs(chromeDir));
if (NS_FAILED(rv))
return;
nsAutoString defaultPath;
chromeDir->GetPath(defaultPath);
defaultPath.AppendLiteral("/icons/default/default.xpm");
nsCOMPtr<nsILocalFile> defaultPathConverter;
rv = NS_NewLocalFile(defaultPath, PR_TRUE,
getter_AddRefs(defaultPathConverter));
if (NS_FAILED(rv))
nsCOMPtr<nsILocalFile> iconFile;
ResolveIconName(NS_LITERAL_STRING("default"),
NS_LITERAL_STRING(".xpm"),
getter_AddRefs(iconFile));
if (!iconFile) {
NS_WARNING("default.xpm not found");
return;
}
nsCAutoString path;
defaultPathConverter->GetNativePath(path);
iconFile->GetNativePath(path);
nsCStringArray iconList;
iconList.AppendCString(path);

View File

@ -3343,47 +3343,26 @@ NS_METHOD nsWindow::SetTitle(const nsAString& aTitle)
NS_METHOD nsWindow::SetIcon(const nsAString& anIconSpec)
{
// Start at app chrome directory.
nsCOMPtr<nsIFile> chromeDir;
if ( NS_FAILED( NS_GetSpecialDirectory( NS_APP_CHROME_DIR,
getter_AddRefs( chromeDir ) ) ) ) {
return NS_ERROR_FAILURE;
// Assume the given string is a local identifier for an icon file.
nsCOMPtr<nsILocalFile> iconFile;
ResolveIconName(aIconSpec, NS_LITERAL_STRING(".ico"),
getter_AddRefs(iconFile));
if (!iconFile)
return NS_OK; // not an error if icon is not found
// Now try the char* path.
nsCAutoString path;
iconFile->GetNativePath( path );
if (mFrameIcon) {
WinFreeFileIcon(mFrameIcon);
mFrameIcon = NULLHANDLE;
}
// Get native file name of that directory.
nsAutoString iconPath;
chromeDir->GetPath( iconPath );
mFrameIcon = WinLoadFileIcon(path.get(), FALSE);
if (mFrameIcon)
WinSendMsg(mFrameWnd, WM_SETICON, (MPARAM)mFrameIcon, (MPARAM)0);
// Now take input path...
nsAutoString iconSpec( anIconSpec );
// ...append ".ico" to that.
iconSpec.Append( NS_LITERAL_STRING(".ico") );
// ...and figure out where /chrome/... is within that
// (and skip the "resource:///chrome" part).
nsAutoString key(NS_LITERAL_STRING("/chrome/"));
PRInt32 n = iconSpec.Find( key ) + key.Length();
// Convert / to \.
nsAutoString slash(NS_LITERAL_STRING("/"));
nsAutoString bslash(NS_LITERAL_STRING("\\"));
iconSpec.ReplaceChar( *(slash.get()), *(bslash.get()) );
// Append that to icon resource path.
iconPath.Append( iconSpec.get() + n - 1 );
nsCOMPtr<nsILocalFile> pathConverter;
if ( NS_SUCCEEDED( NS_NewLocalFile( iconPath,
PR_FALSE,
getter_AddRefs( pathConverter ) ) ) ) {
// Now try the char* path.
nsCAutoString aPath;
pathConverter->GetNativePath( aPath );
if (mFrameIcon) {
WinFreeFileIcon(mFrameIcon);
mFrameIcon = NULLHANDLE;
}
mFrameIcon = WinLoadFileIcon(aPath.get(), FALSE);
if (mFrameIcon)
WinSendMsg(mFrameWnd, WM_SETICON, (MPARAM)mFrameIcon, (MPARAM)0);
}
return NS_OK;
}

View File

@ -5629,32 +5629,20 @@ NS_METHOD nsWindow::SetTitle(const nsAString& aTitle)
return NS_OK;
}
NS_METHOD nsWindow::SetIcon(const nsAString& anIconSpec)
NS_METHOD nsWindow::SetIcon(const nsAString& aIconSpec)
{
// Start at app chrome directory.
nsCOMPtr<nsIFile> chromeDir;
if (NS_FAILED(NS_GetSpecialDirectory(NS_APP_CHROME_DIR, getter_AddRefs(chromeDir)))) {
return NS_ERROR_FAILURE;
}
// Get native file name of that directory.
// Assume the given string is a local identifier for an icon file.
nsCOMPtr<nsILocalFile> iconFile;
ResolveIconName(aIconSpec, NS_LITERAL_STRING(".ico"),
getter_AddRefs(iconFile));
if (!iconFile)
return NS_OK; // not an error if icon is not found
nsAutoString iconPath;
chromeDir->GetPath(iconPath);
iconFile->GetPath(iconPath);
// Now take input path...
nsAutoString iconSpec(anIconSpec);
// ...append ".ico" to that.
iconSpec.Append(NS_LITERAL_STRING(".ico"));
// ...and figure out where /chrome/... is within that
// (and skip the "resource:///chrome" part).
nsAutoString key(NS_LITERAL_STRING("/chrome/"));
PRInt32 n = iconSpec.Find(key) + key.Length();
// Convert / to \.
nsAutoString slash(NS_LITERAL_STRING("/"));
nsAutoString bslash(NS_LITERAL_STRING("\\"));
iconSpec.ReplaceChar(*(slash.get()), *(bslash.get()));
// Append that to icon resource path.
iconPath.Append(iconSpec.get() + n - 1);
// XXX this should use MZLU (see bug 239279)
::SetLastError(0);
HICON bigIcon = (HICON)::LoadImageW(NULL,
@ -5698,10 +5686,10 @@ NS_METHOD nsWindow::SetIcon(const nsAString& anIconSpec)
if (icon)
::DestroyIcon(icon);
}
#ifdef DEBUG_law
#ifdef DEBUG_SetIcon
else {
nsCAutoString cPath; cPath.AssignWithConversion(iconPath);
printf("\nIcon load error; icon=%s, rc=0x%08X\n\n", (const char*)cPath, ::GetLastError());
NS_LossyConvertUTF16toASCII cPath(iconPath);
printf( "\nIcon load error; icon=%s, rc=0x%08X\n\n", cPath.get(), ::GetLastError() );
}
#endif
if (smallIcon) {
@ -5709,12 +5697,13 @@ NS_METHOD nsWindow::SetIcon(const nsAString& anIconSpec)
if (icon)
::DestroyIcon(icon);
}
#ifdef DEBUG_law
#ifdef DEBUG_SetIcon
else {
nsCAutoString cPath; cPath.AssignWithConversion(iconPath);
printf("\nSmall icon load error; icon=%s, rc=0x%08X\n\n", (const char*)cPath, ::GetLastError());
NS_LossyConvertUTF16toASCII cPath(iconPath);
printf( "\nSmall icon load error; icon=%s, rc=0x%08X\n\n", cPath.get(), ::GetLastError() );
}
#endif
return NS_OK;
}

View File

@ -62,6 +62,7 @@ class nsNativeDragTarget;
class nsIRollupListener;
class nsIMenuBar;
class nsIFile;
#ifdef ACCESSIBILITY
#include "OLEACC.H"

View File

@ -46,6 +46,7 @@
#include "nsIFullScreen.h"
#include "nsIServiceManagerUtils.h"
#include "nsIScreenManager.h"
#include "nsAppDirectoryServiceDefs.h"
#ifdef DEBUG
#include "nsIServiceManager.h"
@ -933,6 +934,76 @@ nsBaseWidget::SetIcon(const nsAString&)
return NS_OK;
}
/**
* Modifies aFile to point at an icon file with the given name and suffix. The
* suffix may correspond to a file extension with leading '.' if appropriate.
* Returns true if the icon file exists and can be read.
*/
static PRBool
ResolveIconNameHelper(nsILocalFile *aFile,
const nsAString &aIconName,
const nsAString &aIconSuffix)
{
aFile->Append(NS_LITERAL_STRING("icons"));
aFile->Append(NS_LITERAL_STRING("default"));
aFile->Append(aIconName + aIconSuffix);
PRBool readable;
return NS_SUCCEEDED(aFile->IsReadable(&readable)) && readable;
}
/**
* Resolve the given icon name into a local file object. This method is
* intended to be called by subclasses of nsBaseWidget. aIconSuffix is a
* platform specific icon file suffix (e.g., ".ico" under Win32).
*
* If no file is found matching the given parameters, then null is returned.
*/
void
nsBaseWidget::ResolveIconName(const nsAString &aIconName,
const nsAString &aIconSuffix,
nsILocalFile **aResult)
{
*aResult = nsnull;
nsCOMPtr<nsIProperties> dirSvc = do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID);
if (!dirSvc)
return;
// first check auxilary chrome directories
nsCOMPtr<nsISimpleEnumerator> dirs;
dirSvc->Get(NS_APP_CHROME_DIR_LIST, NS_GET_IID(nsISimpleEnumerator),
getter_AddRefs(dirs));
if (!dirs)
return;
PRBool hasMore;
while (NS_SUCCEEDED(dirs->HasMoreElements(&hasMore)) && hasMore) {
nsCOMPtr<nsISupports> element;
dirs->GetNext(getter_AddRefs(element));
if (!element)
continue;
nsCOMPtr<nsILocalFile> file = do_QueryInterface(element);
if (!file)
continue;
if (ResolveIconNameHelper(file, aIconName, aIconSuffix)) {
NS_ADDREF(*aResult = file);
return;
}
}
// then check the main app chrome directory
nsCOMPtr<nsILocalFile> file;
dirSvc->Get(NS_APP_CHROME_DIR, NS_GET_IID(nsILocalFile),
getter_AddRefs(file));
if (!file)
return;
if (ResolveIconNameHelper(file, aIconName, aIconSuffix))
NS_ADDREF(*aResult = file);
}
#ifdef DEBUG
//////////////////////////////////////////////////////////////
//

View File

@ -44,6 +44,7 @@
#include "nsIMenuListener.h"
#include "nsIToolkit.h"
#include "nsIAppShell.h"
#include "nsILocalFile.h"
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsCOMPtr.h"
@ -133,6 +134,9 @@ public:
protected:
virtual void ResolveIconName(const nsAString &aIconName,
const nsAString &aIconSuffix,
nsILocalFile **aResult);
virtual void DrawScaledRect(nsIRenderingContext& aRenderingContext,
const nsRect & aRect,
float aScale,

View File

@ -1425,9 +1425,6 @@ NS_IMETHODIMP nsXULWindow::LoadIconFromXUL()
cssDecl->GetPropertyValue(windowIcon, icon);
#endif
nsAutoString icon;
icon.AssignLiteral("resource:///chrome/icons/default/");
nsAutoString id;
windowElement->GetAttribute(NS_LITERAL_STRING("id"), id);
@ -1435,9 +1432,7 @@ NS_IMETHODIMP nsXULWindow::LoadIconFromXUL()
id.AssignLiteral("default");
}
icon.Append(id);
mWindow->SetIcon(icon);
mWindow->SetIcon(id);
return NS_OK;
}