From 8eb93929ba577868f7363e59beecd3c45265f915 Mon Sep 17 00:00:00 2001 From: "alecf%netscape.com" Date: Wed, 26 Jun 2002 23:54:31 +0000 Subject: [PATCH] oops, more files for bug 132175 (don't worry, these aren't bustage-inducing) finish implementation of GetWindowForResource r=bnesse, rs=waterson --- xpfe/components/windowds/Makefile.in | 1 + xpfe/components/windowds/makefile.win | 44 ---------------- .../windowds/nsWindowDataSource.cpp | 52 +++++++++++++++++-- 3 files changed, 49 insertions(+), 48 deletions(-) diff --git a/xpfe/components/windowds/Makefile.in b/xpfe/components/windowds/Makefile.in index 3da71c878ab..8308707dc2c 100644 --- a/xpfe/components/windowds/Makefile.in +++ b/xpfe/components/windowds/Makefile.in @@ -36,6 +36,7 @@ REQUIRES = xpcom \ rdf \ dom \ content \ + docshell \ $(NULL) CPPSRCS = nsWindowDataSource.cpp diff --git a/xpfe/components/windowds/makefile.win b/xpfe/components/windowds/makefile.win index 58e227c09a3..e69de29bb2d 100644 --- a/xpfe/components/windowds/makefile.win +++ b/xpfe/components/windowds/makefile.win @@ -1,44 +0,0 @@ -#!nmake -# -# The contents of this file are subject to the Netscape Public -# License Version 1.1 (the "License"); you may not use this file -# except in compliance with the License. You may obtain a copy of -# the License at http://www.mozilla.org/NPL/ -# -# Software distributed under the License is distributed on an "AS -# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or -# implied. See the License for the specific language governing -# rights and limitations under the License. -# -# The Original Code is mozilla.org code. -# -# The Initial Developer of the Original Code is Netscape -# Communications Corporation. Portions created by Netscape are -# Copyright (C) 1998 Netscape Communications Corporation. All -# Rights Reserved. -# -# Contributor(s): - -DEPTH=..\..\.. -MODULE=appcomps -LIBRARY_NAME=windowds_s - -REQUIRES= xpcom \ - string \ - appshell \ - rdf \ - dom \ - content \ - $(NULL) - - -CPP_OBJS=\ - .\$(OBJDIR)\nsWindowDataSource.obj \ - $(NULL) - -XPIDLSRCS = \ - .\nsIWindowDataSource.idl \ - $(NULL) - -include <$(DEPTH)\config\config.mak> -include <$(DEPTH)\config\rules.mak> diff --git a/xpfe/components/windowds/nsWindowDataSource.cpp b/xpfe/components/windowds/nsWindowDataSource.cpp index 53199d8f0b0..130f1af72cd 100644 --- a/xpfe/components/windowds/nsWindowDataSource.cpp +++ b/xpfe/components/windowds/nsWindowDataSource.cpp @@ -42,9 +42,12 @@ #include "nsIServiceManager.h" #include "nsReadableUtils.h" #include "nsObserverService.h" - #include "nsIWindowMediator.h" +// just to do the reverse-lookup! sheesh. +#include "nsIInterfaceRequestorUtils.h" +#include "nsIDocShell.h" + PRUint32 nsWindowDataSource::windowCount = 0; nsIRDFResource* nsWindowDataSource::kNC_Name = nsnull; @@ -171,7 +174,7 @@ nsWindowDataSource::OnWindowTitleChange(nsIXULWindow *window, { nsresult rv; - nsISupportsKey key(window); + nsPRUint32Key key(NS_PTR_TO_INT32(window)); nsCOMPtr sup = dont_AddRef(mWindowResources.Get(&key)); @@ -222,7 +225,7 @@ nsWindowDataSource::OnOpenWindow(nsIXULWindow *window) nsCOMPtr windowResource; gRDFService->GetResource(windowId.get(), getter_AddRefs(windowResource)); - nsISupportsKey key(window); + nsPRUint32Key key(NS_PTR_TO_INT32(window)); mWindowResources.Put(&key, windowResource); // assert the new window @@ -236,7 +239,7 @@ nsWindowDataSource::OnOpenWindow(nsIXULWindow *window) NS_IMETHODIMP nsWindowDataSource::OnCloseWindow(nsIXULWindow *window) { - nsISupportsKey key(window); + nsPRUint32Key key(NS_PTR_TO_INT32(window)); nsCOMPtr resource; nsresult rv; @@ -318,6 +321,30 @@ nsWindowDataSource::OnCloseWindow(nsIXULWindow *window) return NS_OK; } +struct findWindowClosure { + nsIRDFResource* targetResource; + nsIXULWindow *resultWindow; +}; + +static PRBool findWindow(nsHashKey* aKey, void *aData, void* aClosure) +{ + nsPRUint32Key *thisKey = NS_STATIC_CAST(nsPRUint32Key*, aKey); + + nsIRDFResource *resource = + NS_STATIC_CAST(nsIRDFResource*, aData); + + findWindowClosure* closure = + NS_STATIC_CAST(findWindowClosure*, aClosure); + + if (resource == closure->targetResource) { + closure->resultWindow = + NS_STATIC_CAST(nsIXULWindow*, + NS_INT32_TO_PTR(thisKey->GetValue())); + return PR_TRUE; // stop enumerating + } + return PR_FALSE; +} + // nsIWindowDataSource implementation NS_IMETHODIMP @@ -328,6 +355,23 @@ nsWindowDataSource::GetWindowForResource(const char *aResourceString, gRDFService->GetResource(aResourceString, getter_AddRefs(windowResource)); // now reverse-lookup in the hashtable + findWindowClosure closure = { windowResource.get(), nsnull }; + mWindowResources.Enumerate(findWindow, (void*)&closure); + if (closure.resultWindow) { + + // this sucks, we have to jump through docshell to go from + // nsIXULWindow -> nsIDOMWindowInternal + nsCOMPtr docShell; + closure.resultWindow->GetDocShell(getter_AddRefs(docShell)); + + if (docShell) { + nsCOMPtr result = + do_GetInterface(docShell); + + *aResult = result; + NS_IF_ADDREF(*aResult); + } + } return NS_OK; }