зеркало из https://github.com/mozilla/pjs.git
oops, more files for bug 132175 (don't worry, these aren't bustage-inducing)
finish implementation of GetWindowForResource r=bnesse, rs=waterson
This commit is contained in:
Родитель
c2dc28217c
Коммит
8eb93929ba
|
@ -36,6 +36,7 @@ REQUIRES = xpcom \
|
|||
rdf \
|
||||
dom \
|
||||
content \
|
||||
docshell \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = nsWindowDataSource.cpp
|
||||
|
|
|
@ -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>
|
|
@ -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<nsISupports> sup =
|
||||
dont_AddRef(mWindowResources.Get(&key));
|
||||
|
@ -222,7 +225,7 @@ nsWindowDataSource::OnOpenWindow(nsIXULWindow *window)
|
|||
nsCOMPtr<nsIRDFResource> 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<nsIRDFResource> 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<nsIDocShell> docShell;
|
||||
closure.resultWindow->GetDocShell(getter_AddRefs(docShell));
|
||||
|
||||
if (docShell) {
|
||||
nsCOMPtr<nsIDOMWindowInternal> result =
|
||||
do_GetInterface(docShell);
|
||||
|
||||
*aResult = result;
|
||||
NS_IF_ADDREF(*aResult);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче