зеркало из https://github.com/mozilla/pjs.git
Bug 20470. Add weak reference from 'controllers' object back to command dispatcher. Miscellaneous cleanup. r=hyatt
This commit is contained in:
Родитель
7e6c5acc96
Коммит
57e9111db3
|
@ -50,6 +50,7 @@
|
|||
#include "nsIDOMEventListener.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
#include "nsIDOMScriptObjectFactory.h"
|
||||
#include "nsIDOMXULCommandDispatcher.h"
|
||||
#include "nsIDOMXULElement.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIEventListenerManager.h"
|
||||
|
@ -82,6 +83,7 @@
|
|||
#include "nsIURL.h"
|
||||
#include "nsIXULContent.h"
|
||||
#include "nsIXULDocument.h"
|
||||
#include "nsXULControllers.h"
|
||||
#include "nsXULTreeElement.h"
|
||||
#include "nsXULEditorElement.h"
|
||||
#include "rdfutil.h"
|
||||
|
@ -132,8 +134,6 @@ static NS_DEFINE_CID(kXULContentUtilsCID, NS_XULCONTENTUTILS_CID);
|
|||
static NS_DEFINE_IID(kIXULPopupListenerIID, NS_IXULPOPUPLISTENER_IID);
|
||||
static NS_DEFINE_CID(kXULPopupListenerCID, NS_XULPOPUPLISTENER_CID);
|
||||
|
||||
static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
struct XULBroadcastListener
|
||||
|
@ -3245,16 +3245,30 @@ NS_IMETHODIMP
|
|||
nsXULElement::GetControllers(nsIControllers** aResult)
|
||||
{
|
||||
if (! Controllers()) {
|
||||
NS_PRECONDITION(mDocument != nsnull, "no document");
|
||||
if (! mDocument)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
nsresult rv;
|
||||
rv = EnsureSlots();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = nsComponentManager::CreateInstance(kXULControllersCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIControllers),
|
||||
getter_AddRefs(mSlots->mControllers));
|
||||
rv = NS_NewXULControllers(nsnull, NS_GET_IID(nsIControllers), getter_AddRefs(mSlots->mControllers));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create a controllers");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Set the command dispatcher on the new controllers object
|
||||
nsCOMPtr<nsIDOMXULDocument> domxuldoc = do_QueryInterface(mDocument);
|
||||
NS_ASSERTION(domxuldoc != nsnull, "not an nsIDOMXULDocument");
|
||||
if (! domxuldoc)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsCOMPtr<nsIDOMXULCommandDispatcher> dispatcher;
|
||||
rv = domxuldoc->GetCommandDispatcher(getter_AddRefs(dispatcher));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mSlots->mControllers->SetCommandDispatcher(dispatcher);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
*aResult = Controllers();
|
||||
|
|
|
@ -22,9 +22,12 @@
|
|||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIController.idl"
|
||||
interface nsIDOMXULCommandDispatcher;
|
||||
|
||||
[scriptable, uuid(A5ED3A01-7CC7-11d3-BF87-00105A1B0627)]
|
||||
interface nsIControllers : nsISupports {
|
||||
attribute nsIDOMXULCommandDispatcher commandDispatcher;
|
||||
|
||||
nsIController getControllerForCommand(in wstring command);
|
||||
|
||||
void insertControllerAt(in unsigned long index, in nsIController controller);
|
||||
|
|
|
@ -21,119 +21,36 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
|
||||
This file provides the implementation for the XUL Command Dispatcher.
|
||||
|
||||
*/
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMXULCommandDispatcher.h"
|
||||
#include "nsIXULCommandDispatcher.h"
|
||||
#include "nsIDOMFocusListener.h"
|
||||
#include "nsRDFCID.h"
|
||||
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIDOMXULDocument.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIDOMUIEvent.h"
|
||||
|
||||
#include "nsIDOMXULElement.h"
|
||||
#include "nsIDOMNSHTMLTextAreaElement.h"
|
||||
#include "nsIDOMNSHTMLInputElement.h"
|
||||
#include "nsIControllers.h"
|
||||
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMNSHTMLInputElement.h"
|
||||
#include "nsIDOMNSHTMLTextAreaElement.h"
|
||||
#include "nsIDOMUIEvent.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIDOMXULElement.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsXULCommandDispatcher.h"
|
||||
#include "prlog.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
static NS_DEFINE_IID(kIDomNodeIID, NS_IDOMNODE_IID);
|
||||
static NS_DEFINE_IID(kIDomElementIID, NS_IDOMELEMENT_IID);
|
||||
static NS_DEFINE_IID(kIDomEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
static PRLogModuleInfo* gLog;
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// XULCommandDispatcherImpl
|
||||
//
|
||||
// This is the focus manager for XUL documents.
|
||||
//
|
||||
class XULCommandDispatcherImpl : public nsIDOMXULCommandDispatcher,
|
||||
public nsIXULCommandDispatcher,
|
||||
public nsIDOMFocusListener,
|
||||
public nsIScriptObjectOwner
|
||||
{
|
||||
public:
|
||||
XULCommandDispatcherImpl(void);
|
||||
virtual ~XULCommandDispatcherImpl(void);
|
||||
|
||||
public:
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIDOMXULCommandDispatcher interface
|
||||
NS_DECL_IDOMXULCOMMANDDISPATCHER
|
||||
|
||||
// nsIDOMFocusListener
|
||||
virtual nsresult Focus(nsIDOMEvent* aEvent);
|
||||
virtual nsresult Blur(nsIDOMEvent* aEvent);
|
||||
|
||||
// nsIDOMEventListener
|
||||
virtual nsresult HandleEvent(nsIDOMEvent* anEvent) { return NS_OK; };
|
||||
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void *aScriptObject);
|
||||
|
||||
protected:
|
||||
NS_IMETHOD GetParentWindowFromElement(nsIDOMElement* aElement, nsPIDOMWindow** aPWindow);
|
||||
|
||||
void* mScriptObject; // ????
|
||||
|
||||
// XXX THis was supposed to be WEAK, but c'mon, that's an accident
|
||||
// waiting to happen! If somebody deletes the node, then asks us
|
||||
// for the focus, we'll get killed!
|
||||
nsCOMPtr<nsIDOMNode> mCurrentNode; // [OWNER]
|
||||
|
||||
class Updater {
|
||||
public:
|
||||
Updater(nsIDOMElement* aElement,
|
||||
const nsString& aEvents,
|
||||
const nsString& aTargets)
|
||||
: mElement(aElement),
|
||||
mEvents(aEvents),
|
||||
mTargets(aTargets),
|
||||
mNext(nsnull)
|
||||
{}
|
||||
|
||||
nsIDOMElement* mElement; // [WEAK]
|
||||
nsString mEvents;
|
||||
nsString mTargets;
|
||||
Updater* mNext;
|
||||
};
|
||||
|
||||
Updater* mUpdaters;
|
||||
|
||||
PRBool Matches(const nsString& aList, const nsString& aElement);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
XULCommandDispatcherImpl::XULCommandDispatcherImpl(void)
|
||||
nsXULCommandDispatcher::nsXULCommandDispatcher(void)
|
||||
: mScriptObject(nsnull), mCurrentNode(nsnull), mUpdaters(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
@ -144,7 +61,7 @@ XULCommandDispatcherImpl::XULCommandDispatcherImpl(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
XULCommandDispatcherImpl::~XULCommandDispatcherImpl(void)
|
||||
nsXULCommandDispatcher::~nsXULCommandDispatcher(void)
|
||||
{
|
||||
while (mUpdaters) {
|
||||
Updater* doomed = mUpdaters;
|
||||
|
@ -153,48 +70,49 @@ XULCommandDispatcherImpl::~XULCommandDispatcherImpl(void)
|
|||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(XULCommandDispatcherImpl)
|
||||
NS_IMPL_RELEASE(XULCommandDispatcherImpl)
|
||||
NS_IMPL_ADDREF(nsXULCommandDispatcher)
|
||||
NS_IMPL_RELEASE(nsXULCommandDispatcher)
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULCommandDispatcherImpl::QueryInterface(REFNSIID iid, void** result)
|
||||
nsXULCommandDispatcher::QueryInterface(REFNSIID iid, void** result)
|
||||
{
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*result = nsnull;
|
||||
if (iid.Equals(kISupportsIID)) {
|
||||
*result = (nsISupports*)(nsIXULCommandDispatcher*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
else if (iid.Equals(nsIXULCommandDispatcher::GetIID())) {
|
||||
*result = NS_STATIC_CAST(nsIXULCommandDispatcher*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
else if (iid.Equals(nsIDOMXULCommandDispatcher::GetIID())) {
|
||||
if (iid.Equals(NS_GET_IID(nsISupports)) ||
|
||||
iid.Equals(NS_GET_IID(nsIDOMXULCommandDispatcher))) {
|
||||
*result = NS_STATIC_CAST(nsIDOMXULCommandDispatcher*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
else if (iid.Equals(nsIDOMFocusListener::GetIID())) {
|
||||
else if (iid.Equals(NS_GET_IID(nsIDOMFocusListener)) ||
|
||||
iid.Equals(NS_GET_IID(nsIDOMEventListener))) {
|
||||
*result = NS_STATIC_CAST(nsIDOMFocusListener*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
else if (iid.Equals(kIDomEventListenerIID)) {
|
||||
*result = (nsIDOMEventListener*)(nsIDOMFocusListener*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
else if (iid.Equals(kIScriptObjectOwnerIID)) {
|
||||
else if (iid.Equals(NS_GET_IID(nsIScriptObjectOwner))) {
|
||||
*result = NS_STATIC_CAST(nsIScriptObjectOwner*, this);
|
||||
}
|
||||
else if (iid.Equals(NS_GET_IID(nsISupportsWeakReference))) {
|
||||
*result = NS_STATIC_CAST(nsISupportsWeakReference*, this);
|
||||
}
|
||||
else {
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXULCommandDispatcher::Create(nsIDOMXULCommandDispatcher** aResult)
|
||||
{
|
||||
nsXULCommandDispatcher* dispatcher = new nsXULCommandDispatcher();
|
||||
if (! dispatcher)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
*aResult = dispatcher;
|
||||
NS_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -202,7 +120,7 @@ XULCommandDispatcherImpl::QueryInterface(REFNSIID iid, void** result)
|
|||
// nsIDOMXULTracker Interface
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULCommandDispatcherImpl::GetFocusedNode(nsIDOMNode** aNode)
|
||||
nsXULCommandDispatcher::GetFocusedNode(nsIDOMNode** aNode)
|
||||
{
|
||||
*aNode = mCurrentNode;
|
||||
NS_IF_ADDREF(*aNode);
|
||||
|
@ -210,7 +128,7 @@ XULCommandDispatcherImpl::GetFocusedNode(nsIDOMNode** aNode)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULCommandDispatcherImpl::SetFocusedNode(nsIDOMNode* aNode)
|
||||
nsXULCommandDispatcher::SetFocusedNode(nsIDOMNode* aNode)
|
||||
{
|
||||
// XXX On a blur, will need to fire an updatecommands (focus) on the
|
||||
// parent window.
|
||||
|
@ -221,7 +139,7 @@ XULCommandDispatcherImpl::SetFocusedNode(nsIDOMNode* aNode)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULCommandDispatcherImpl::AddCommandUpdater(nsIDOMElement* aElement,
|
||||
nsXULCommandDispatcher::AddCommandUpdater(nsIDOMElement* aElement,
|
||||
const nsString& aEvents,
|
||||
const nsString& aTargets)
|
||||
{
|
||||
|
@ -270,7 +188,7 @@ XULCommandDispatcherImpl::AddCommandUpdater(nsIDOMElement* aElement,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULCommandDispatcherImpl::RemoveCommandUpdater(nsIDOMElement* aElement)
|
||||
nsXULCommandDispatcher::RemoveCommandUpdater(nsIDOMElement* aElement)
|
||||
{
|
||||
NS_PRECONDITION(aElement != nsnull, "null ptr");
|
||||
if (! aElement)
|
||||
|
@ -301,7 +219,7 @@ XULCommandDispatcherImpl::RemoveCommandUpdater(nsIDOMElement* aElement)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULCommandDispatcherImpl::UpdateCommands(const nsString& aEventName)
|
||||
nsXULCommandDispatcher::UpdateCommands(const nsString& aEventName)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
|
@ -364,7 +282,7 @@ XULCommandDispatcherImpl::UpdateCommands(const nsString& aEventName)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULCommandDispatcherImpl::GetControllers(nsIControllers** aResult)
|
||||
nsXULCommandDispatcher::GetControllers(nsIControllers** aResult)
|
||||
{
|
||||
//XXX: we should fix this so there's a generic interface that describes controllers,
|
||||
// so this code would have no special knowledge of what object might have controllers.
|
||||
|
@ -395,7 +313,7 @@ XULCommandDispatcherImpl::GetControllers(nsIControllers** aResult)
|
|||
/////
|
||||
|
||||
nsresult
|
||||
XULCommandDispatcherImpl::Focus(nsIDOMEvent* aEvent)
|
||||
nsXULCommandDispatcher::Focus(nsIDOMEvent* aEvent)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> t;
|
||||
aEvent->GetTarget(getter_AddRefs(t));
|
||||
|
@ -410,7 +328,7 @@ XULCommandDispatcherImpl::Focus(nsIDOMEvent* aEvent)
|
|||
}
|
||||
|
||||
nsresult
|
||||
XULCommandDispatcherImpl::Blur(nsIDOMEvent* aEvent)
|
||||
nsXULCommandDispatcher::Blur(nsIDOMEvent* aEvent)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> t;
|
||||
aEvent->GetTarget(getter_AddRefs(t));
|
||||
|
@ -424,7 +342,7 @@ XULCommandDispatcherImpl::Blur(nsIDOMEvent* aEvent)
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHODIMP
|
||||
XULCommandDispatcherImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
||||
nsXULCommandDispatcher::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
|
||||
|
@ -440,7 +358,7 @@ XULCommandDispatcherImpl::GetScriptObject(nsIScriptContext *aContext, void** aSc
|
|||
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULCommandDispatcherImpl::SetScriptObject(void *aScriptObject)
|
||||
nsXULCommandDispatcher::SetScriptObject(void *aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
|
@ -448,7 +366,7 @@ XULCommandDispatcherImpl::SetScriptObject(void *aScriptObject)
|
|||
|
||||
|
||||
PRBool
|
||||
XULCommandDispatcherImpl::Matches(const nsString& aList, const nsString& aElement)
|
||||
nsXULCommandDispatcher::Matches(const nsString& aList, const nsString& aElement)
|
||||
{
|
||||
if (aList == "*")
|
||||
return PR_TRUE; // match _everything_!
|
||||
|
@ -475,7 +393,8 @@ XULCommandDispatcherImpl::Matches(const nsString& aList, const nsString& aElemen
|
|||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP XULCommandDispatcherImpl::GetParentWindowFromElement(nsIDOMElement* aElement, nsPIDOMWindow** aPWindow)
|
||||
NS_IMETHODIMP
|
||||
nsXULCommandDispatcher::GetParentWindowFromElement(nsIDOMElement* aElement, nsPIDOMWindow** aPWindow)
|
||||
{
|
||||
nsCOMPtr<nsIDOMDocument> document;
|
||||
aElement->GetOwnerDocument(getter_AddRefs(document));
|
||||
|
@ -496,7 +415,8 @@ XULCommandDispatcherImpl::Matches(const nsString& aList, const nsString& aElemen
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP XULCommandDispatcherImpl::GetControllerForCommand(const nsString& command, nsIController** _retval)
|
||||
NS_IMETHODIMP
|
||||
nsXULCommandDispatcher::GetControllerForCommand(const nsString& command, nsIController** _retval)
|
||||
{
|
||||
*_retval = nsnull;
|
||||
|
||||
|
@ -548,15 +468,3 @@ XULCommandDispatcherImpl::Matches(const nsString& aList, const nsString& aElemen
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
NS_NewXULCommandDispatcher(nsIXULCommandDispatcher** CommandDispatcher)
|
||||
{
|
||||
XULCommandDispatcherImpl* focus = new XULCommandDispatcherImpl();
|
||||
if (!focus)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(focus);
|
||||
*CommandDispatcher = focus;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
|
||||
This is the focus manager for XUL documents.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef nsXULCommandDispatcher_h__
|
||||
#define nsXULCommandDispatcher_h__
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDOMXULCommandDispatcher.h"
|
||||
#include "nsIDOMFocusListener.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsString.h"
|
||||
|
||||
class nsIDOMElement;
|
||||
class nsPIDOMWindow;
|
||||
|
||||
|
||||
class nsXULCommandDispatcher : public nsIDOMXULCommandDispatcher,
|
||||
public nsIDOMFocusListener,
|
||||
public nsIScriptObjectOwner,
|
||||
public nsSupportsWeakReference
|
||||
{
|
||||
protected:
|
||||
nsXULCommandDispatcher(void);
|
||||
virtual ~nsXULCommandDispatcher(void);
|
||||
|
||||
public:
|
||||
|
||||
static NS_IMETHODIMP
|
||||
Create(nsIDOMXULCommandDispatcher** aResult);
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIDOMXULCommandDispatcher interface
|
||||
NS_DECL_IDOMXULCOMMANDDISPATCHER
|
||||
|
||||
// nsIDOMFocusListener
|
||||
virtual nsresult Focus(nsIDOMEvent* aEvent);
|
||||
virtual nsresult Blur(nsIDOMEvent* aEvent);
|
||||
|
||||
// nsIDOMEventListener
|
||||
virtual nsresult HandleEvent(nsIDOMEvent* anEvent) { return NS_OK; };
|
||||
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void *aScriptObject);
|
||||
|
||||
protected:
|
||||
NS_IMETHOD GetParentWindowFromElement(nsIDOMElement* aElement, nsPIDOMWindow** aPWindow);
|
||||
|
||||
void* mScriptObject; // ????
|
||||
|
||||
// XXX THis was supposed to be WEAK, but c'mon, that's an accident
|
||||
// waiting to happen! If somebody deletes the node, then asks us
|
||||
// for the focus, we'll get killed!
|
||||
nsCOMPtr<nsIDOMNode> mCurrentNode; // [OWNER]
|
||||
|
||||
class Updater {
|
||||
public:
|
||||
Updater(nsIDOMElement* aElement,
|
||||
const nsString& aEvents,
|
||||
const nsString& aTargets)
|
||||
: mElement(aElement),
|
||||
mEvents(aEvents),
|
||||
mTargets(aTargets),
|
||||
mNext(nsnull)
|
||||
{}
|
||||
|
||||
nsIDOMElement* mElement; // [WEAK]
|
||||
nsString mEvents;
|
||||
nsString mTargets;
|
||||
Updater* mNext;
|
||||
};
|
||||
|
||||
Updater* mUpdaters;
|
||||
|
||||
PRBool Matches(const nsString& aList, const nsString& aElement);
|
||||
};
|
||||
|
||||
#endif // nsXULCommandDispatcher_h__
|
|
@ -21,105 +21,69 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
This file provides the implementation for the XUL Command Dispatcher.
|
||||
|
||||
This file provides the implementation for the XUL "controllers"
|
||||
object.
|
||||
|
||||
*/
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsISupportsArray.h"
|
||||
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIXULCommandDispatcher.h"
|
||||
#include "nsIDOMFocusListener.h"
|
||||
#include "nsRDFCID.h"
|
||||
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIDOMXULDocument.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIDOMUIEvent.h"
|
||||
|
||||
#include "nsIDOMXULElement.h"
|
||||
#include "nsIControllers.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMXULCommandDispatcher.h"
|
||||
#include "nsXULControllers.h"
|
||||
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIPresShell.h"
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
static NS_DEFINE_IID(kIDomNodeIID, NS_IDOMNODE_IID);
|
||||
static NS_DEFINE_IID(kIDomElementIID, NS_IDOMELEMENT_IID);
|
||||
static NS_DEFINE_IID(kIDomEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// XULControllersImpl
|
||||
//
|
||||
// This is the focus manager for XUL documents.
|
||||
//
|
||||
class XULControllersImpl : public nsIControllers
|
||||
{
|
||||
public:
|
||||
XULControllersImpl(void);
|
||||
virtual ~XULControllersImpl(void);
|
||||
|
||||
public:
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSICONTROLLERS
|
||||
|
||||
|
||||
protected:
|
||||
nsISupportsArray* mControllers;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
XULControllersImpl::XULControllersImpl(void) :
|
||||
mControllers(nsnull)
|
||||
nsXULControllers::nsXULControllers()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
XULControllersImpl::~XULControllersImpl(void)
|
||||
nsXULControllers::~nsXULControllers(void)
|
||||
{
|
||||
NS_IF_RELEASE(mControllers);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(XULControllersImpl)
|
||||
NS_IMPL_RELEASE(XULControllersImpl)
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULControllersImpl::QueryInterface(REFNSIID iid, void** result)
|
||||
NS_NewXULControllers(nsISupports* aOuter, REFNSIID aIID, void** aResult)
|
||||
{
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
NS_PRECONDITION(aOuter == nsnull, "no aggregation");
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
*result = nsnull;
|
||||
if (iid.Equals(kISupportsIID)) {
|
||||
*result = (nsISupports*)(nsIControllers*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
nsXULControllers* controllers = new nsXULControllers();
|
||||
if (! controllers)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult rv;
|
||||
NS_ADDREF(controllers);
|
||||
rv = controllers->QueryInterface(aIID, aResult);
|
||||
NS_RELEASE(controllers);
|
||||
return rv;
|
||||
}
|
||||
else if (iid.Equals(nsIControllers::GetIID())) {
|
||||
*result = NS_STATIC_CAST(nsIControllers*, this);
|
||||
NS_ADDREF_THIS();
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsXULControllers, NS_GET_IID(nsIControllers));
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXULControllers::GetCommandDispatcher(nsIDOMXULCommandDispatcher** _result)
|
||||
{
|
||||
nsCOMPtr<nsIDOMXULCommandDispatcher> dispatcher = do_QueryReferent(mCommandDispatcher);
|
||||
*_result = dispatcher;
|
||||
NS_IF_ADDREF(*_result);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXULControllers::SetCommandDispatcher(nsIDOMXULCommandDispatcher* aCommandDispatcher)
|
||||
{
|
||||
mCommandDispatcher = getter_AddRefs(NS_GetWeakReference(aCommandDispatcher));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/* boolean SupportsCommand (in string command); */
|
||||
NS_IMETHODIMP XULControllersImpl::GetControllerForCommand(const PRUnichar *command, nsIController** _retval)
|
||||
NS_IMETHODIMP
|
||||
nsXULControllers::GetControllerForCommand(const PRUnichar *command, nsIController** _retval)
|
||||
{
|
||||
*_retval = nsnull;
|
||||
if(!mControllers)
|
||||
|
@ -145,18 +109,21 @@ XULControllersImpl::QueryInterface(REFNSIID iid, void** result)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void InsertControllerAt (in short index, in nsIController controller); */
|
||||
NS_IMETHODIMP XULControllersImpl::InsertControllerAt(PRUint32 index, nsIController *controller)
|
||||
NS_IMETHODIMP
|
||||
nsXULControllers::InsertControllerAt(PRUint32 index, nsIController *controller)
|
||||
{
|
||||
if(! mControllers )
|
||||
NS_NewISupportsArray(&mControllers);
|
||||
if(! mControllers ) {
|
||||
nsresult rv;
|
||||
rv = NS_NewISupportsArray(getter_AddRefs(mControllers));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
mControllers->InsertElementAt(controller, index);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* nsIController RemoveControllerAt (in short index); */
|
||||
NS_IMETHODIMP XULControllersImpl::RemoveControllerAt(PRUint32 index, nsIController **_retval)
|
||||
NS_IMETHODIMP
|
||||
nsXULControllers::RemoveControllerAt(PRUint32 index, nsIController **_retval)
|
||||
{
|
||||
if(mControllers) {
|
||||
nsCOMPtr<nsISupports> supports;
|
||||
|
@ -169,8 +136,9 @@ XULControllersImpl::QueryInterface(REFNSIID iid, void** result)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/* nsIController GetControllerAt (in short index); */
|
||||
NS_IMETHODIMP XULControllersImpl::GetControllerAt(PRUint32 index, nsIController **_retval)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXULControllers::GetControllerAt(PRUint32 index, nsIController **_retval)
|
||||
{
|
||||
if(mControllers) {
|
||||
nsCOMPtr<nsISupports> supports;
|
||||
|
@ -182,18 +150,21 @@ XULControllersImpl::QueryInterface(REFNSIID iid, void** result)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void AppendController (in nsIController controller); */
|
||||
NS_IMETHODIMP XULControllersImpl::AppendController(nsIController *controller)
|
||||
NS_IMETHODIMP
|
||||
nsXULControllers::AppendController(nsIController *controller)
|
||||
{
|
||||
if(! mControllers )
|
||||
NS_NewISupportsArray(&mControllers);
|
||||
if(! mControllers ) {
|
||||
nsresult rv;
|
||||
rv = NS_NewISupportsArray(getter_AddRefs(mControllers));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
mControllers->AppendElement(controller);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void RemoveController (in nsIController controller); */
|
||||
NS_IMETHODIMP XULControllersImpl::RemoveController(nsIController *controller)
|
||||
NS_IMETHODIMP
|
||||
nsXULControllers::RemoveController(nsIController *controller)
|
||||
{
|
||||
if(mControllers) {
|
||||
nsCOMPtr<nsISupports> supports = do_QueryInterface(controller);
|
||||
|
@ -203,8 +174,8 @@ XULControllersImpl::QueryInterface(REFNSIID iid, void** result)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/* short GetControllerCount (); */
|
||||
NS_IMETHODIMP XULControllersImpl::GetControllerCount(PRUint32 *_retval)
|
||||
NS_IMETHODIMP
|
||||
nsXULControllers::GetControllerCount(PRUint32 *_retval)
|
||||
{
|
||||
*_retval = 0;
|
||||
if(mControllers)
|
||||
|
@ -213,15 +184,3 @@ XULControllersImpl::QueryInterface(REFNSIID iid, void** result)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
NS_NewXULControllers(nsIControllers** aControllers)
|
||||
{
|
||||
nsIControllers* impl = new XULControllersImpl();
|
||||
if (!impl)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(impl);
|
||||
*aControllers = impl;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
The XUL "controllers" object.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef nsXULControllers_h__
|
||||
#define nsXULControllers_h__
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsWeakPtr.h"
|
||||
#include "nsIControllers.h"
|
||||
#include "nsISupportsArray.h"
|
||||
|
||||
class nsIDOMXULCommandDispatcher;
|
||||
|
||||
class nsXULControllers : public nsIControllers
|
||||
{
|
||||
public:
|
||||
friend NS_IMETHODIMP
|
||||
NS_NewXULControllers(nsISupports* aOuter, REFNSIID aIID, void** aResult);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICONTROLLERS
|
||||
|
||||
protected:
|
||||
nsXULControllers();
|
||||
virtual ~nsXULControllers(void);
|
||||
|
||||
nsCOMPtr<nsISupportsArray> mControllers;
|
||||
nsWeakPtr mCommandDispatcher;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // nsXULControllers_h__
|
|
@ -95,7 +95,6 @@
|
|||
#include "nsIBaseWindow.h"
|
||||
#include "nsIXMLContent.h"
|
||||
#include "nsIXMLElementFactory.h"
|
||||
#include "nsIXULCommandDispatcher.h"
|
||||
#include "nsIXULContent.h"
|
||||
#include "nsIXULContentSink.h"
|
||||
#include "nsIXULContentUtils.h"
|
||||
|
@ -108,6 +107,7 @@
|
|||
#include "nsRDFCID.h"
|
||||
#include "nsRDFDOMNodeList.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsXULCommandDispatcher.h"
|
||||
#include "nsXULDocument.h"
|
||||
#include "nsXULElement.h"
|
||||
#include "plstr.h"
|
||||
|
@ -143,7 +143,6 @@ static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
|
|||
static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID);
|
||||
static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
|
||||
static NS_DEFINE_CID(kXMLElementFactoryCID, NS_XML_ELEMENT_FACTORY_CID);
|
||||
static NS_DEFINE_CID(kXULCommandDispatcherCID, NS_XULCOMMANDDISPATCHER_CID);
|
||||
static NS_DEFINE_CID(kXULContentSinkCID, NS_XULCONTENTSINK_CID);
|
||||
static NS_DEFINE_CID(kXULContentUtilsCID, NS_XULCONTENTUTILS_CID);
|
||||
static NS_DEFINE_CID(kXULKeyListenerCID, NS_XULKEYLISTENER_CID);
|
||||
|
@ -3162,16 +3161,10 @@ nsXULDocument::Init()
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Create our focus tracker and hook it up.
|
||||
nsCOMPtr<nsIXULCommandDispatcher> commandDis;
|
||||
rv = nsComponentManager::CreateInstance(kXULCommandDispatcherCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIXULCommandDispatcher),
|
||||
getter_AddRefs(commandDis));
|
||||
rv = nsXULCommandDispatcher::Create(getter_AddRefs(mCommandDispatcher));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create a focus tracker");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mCommandDispatcher = do_QueryInterface(commandDis);
|
||||
|
||||
nsCOMPtr<nsIDOMEventListener> CommandDispatcher =
|
||||
do_QueryInterface(mCommandDispatcher);
|
||||
|
||||
|
|
|
@ -22,9 +22,12 @@
|
|||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIController.idl"
|
||||
interface nsIDOMXULCommandDispatcher;
|
||||
|
||||
[scriptable, uuid(A5ED3A01-7CC7-11d3-BF87-00105A1B0627)]
|
||||
interface nsIControllers : nsISupports {
|
||||
attribute nsIDOMXULCommandDispatcher commandDispatcher;
|
||||
|
||||
nsIController getControllerForCommand(in wstring command);
|
||||
|
||||
void insertControllerAt(in unsigned long index, in nsIController controller);
|
||||
|
|
|
@ -111,10 +111,6 @@
|
|||
#define NS_XULKEYLISTENER_CID \
|
||||
{ 0x3986b301, 0x97c, 0x11d3, { 0xbf, 0x87, 0x0, 0x11, 0x5a, 0x1b, 0x6, 0x27 } }
|
||||
|
||||
// {FE71D561-1501-11d3-BF87-00105A1B0627}
|
||||
#define NS_XULCOMMANDDISPATCHER_CID \
|
||||
{ 0xfe71d561, 0x1501, 0x11d3, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
|
||||
|
||||
// {1F5C1721-7DC3-11d3-BF87-00105A1B0627}
|
||||
#define NS_XULCONTROLLERS_CID \
|
||||
{ 0x1f5c1721, 0x7dc3, 0x11d3, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
|
||||
|
|
|
@ -44,8 +44,6 @@
|
|||
#include "nsIXULSortService.h"
|
||||
#include "nsIXULPopupListener.h"
|
||||
#include "nsIXULKeyListener.h"
|
||||
#include "nsIXULCommandDispatcher.h"
|
||||
#include "nsIControllers.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
||||
|
@ -72,7 +70,6 @@ static NS_DEFINE_CID(kXULSortServiceCID, NS_XULSORTSERVICE_CID)
|
|||
static NS_DEFINE_CID(kXULPopupListenerCID, NS_XULPOPUPLISTENER_CID);
|
||||
static NS_DEFINE_CID(kXULPrototypeCacheCID, NS_XULPROTOTYPECACHE_CID);
|
||||
static NS_DEFINE_CID(kXULKeyListenerCID, NS_XULKEYLISTENER_CID);
|
||||
static NS_DEFINE_CID(kXULCommandDispatcherCID, NS_XULCOMMANDDISPATCHER_CID);
|
||||
static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID);
|
||||
static NS_DEFINE_CID(kXULTemplateBuilderCID, NS_XULTEMPLATEBUILDER_CID);
|
||||
|
||||
|
@ -109,16 +106,14 @@ CreateNew##_func(nsISupports* aOuter, REFNSIID aIID, void **aResult) \
|
|||
extern nsresult
|
||||
NS_NewDefaultResource(nsIRDFResource** aResult);
|
||||
|
||||
extern nsresult
|
||||
NS_NewXULControllers(nsIControllers** result);
|
||||
extern NS_IMETHODIMP
|
||||
NS_NewXULControllers(nsISupports* aOuter, REFNSIID aIID, void** aResult);
|
||||
|
||||
|
||||
MAKE_CTOR(RDFService,RDFService,RDFService)
|
||||
MAKE_CTOR(XULSortService,XULSortService,XULSortService)
|
||||
MAKE_CTOR(XULPopupListener,XULPopupListener,XULPopupListener)
|
||||
MAKE_CTOR(XULKeyListener,XULKeyListener,XULKeyListener)
|
||||
MAKE_CTOR(XULCommandDispatcher,XULCommandDispatcher,XULCommandDispatcher)
|
||||
MAKE_CTOR(XULControllers,XULControllers,Controllers)
|
||||
|
||||
MAKE_CTOR(RDFXMLDataSource,RDFXMLDataSource,RDFDataSource)
|
||||
MAKE_CTOR(RDFFileSystemDataSource,RDFFileSystemDataSource,RDFDataSource)
|
||||
|
@ -242,11 +237,8 @@ nsRDFModule::GetClassObject(nsIComponentManager *aCompMgr,
|
|||
else if (aClass.Equals(kXULKeyListenerCID)) {
|
||||
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewXULKeyListener);
|
||||
}
|
||||
else if (aClass.Equals(kXULCommandDispatcherCID)) {
|
||||
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewXULCommandDispatcher);
|
||||
}
|
||||
else if (aClass.Equals(kXULControllersCID)) {
|
||||
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewXULControllers);
|
||||
rv = NS_NewGenericFactory(getter_AddRefs(fact), NS_NewXULControllers);
|
||||
}
|
||||
else if (aClass.Equals(kXULContentUtilsCID)) {
|
||||
rv = NS_NewGenericFactory(getter_AddRefs(fact), NS_NewXULContentUtils);
|
||||
|
@ -318,8 +310,6 @@ static Components gComponents[] = {
|
|||
NS_RDF_PROGID "/xul-popup-listener", },
|
||||
{ "XUL KeyListener", &kXULKeyListenerCID,
|
||||
NS_RDF_PROGID "/xul-key-listener", },
|
||||
{ "XUL CommandDispatcher", &kXULCommandDispatcherCID,
|
||||
NS_RDF_PROGID "/xul-command-dispatcher", },
|
||||
{ "XUL Controllers", &kXULControllersCID,
|
||||
NS_RDF_PROGID "/xul-controllers", },
|
||||
{ "XUL Content Utilities", &kXULContentUtilsCID,
|
||||
|
|
|
@ -4,7 +4,6 @@ nsIDOMXULEditorElement.h
|
|||
nsIDOMXULElement.h
|
||||
nsIDOMXULTreeElement.h
|
||||
nsIStreamLoadableDocument.h
|
||||
nsIXULCommandDispatcher.h
|
||||
nsIXULContentSink.h
|
||||
nsIXULContentUtils.h
|
||||
nsIXULDocument.h
|
||||
|
|
|
@ -35,7 +35,6 @@ EXPORTS = \
|
|||
nsIDOMXULElement.h \
|
||||
nsIDOMXULTreeElement.h \
|
||||
nsIStreamLoadableDocument.h \
|
||||
nsIXULCommandDispatcher.h \
|
||||
nsIXULContentSink.h \
|
||||
nsIXULContentUtils.h \
|
||||
nsIXULDocument.h \
|
||||
|
|
|
@ -27,7 +27,6 @@ DEPTH=..\..\..
|
|||
EXPORTS = \
|
||||
nsIDOMXULCommandDispatcher.h \
|
||||
nsIStreamLoadableDocument.h \
|
||||
nsIXULCommandDispatcher.h \
|
||||
nsIXULKeyListener.h \
|
||||
nsIXULPopupListener.h \
|
||||
nsIDOMXULDocument.h \
|
||||
|
|
|
@ -21,119 +21,36 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
|
||||
This file provides the implementation for the XUL Command Dispatcher.
|
||||
|
||||
*/
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMXULCommandDispatcher.h"
|
||||
#include "nsIXULCommandDispatcher.h"
|
||||
#include "nsIDOMFocusListener.h"
|
||||
#include "nsRDFCID.h"
|
||||
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIDOMXULDocument.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIDOMUIEvent.h"
|
||||
|
||||
#include "nsIDOMXULElement.h"
|
||||
#include "nsIDOMNSHTMLTextAreaElement.h"
|
||||
#include "nsIDOMNSHTMLInputElement.h"
|
||||
#include "nsIControllers.h"
|
||||
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMNSHTMLInputElement.h"
|
||||
#include "nsIDOMNSHTMLTextAreaElement.h"
|
||||
#include "nsIDOMUIEvent.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIDOMXULElement.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsXULCommandDispatcher.h"
|
||||
#include "prlog.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
static NS_DEFINE_IID(kIDomNodeIID, NS_IDOMNODE_IID);
|
||||
static NS_DEFINE_IID(kIDomElementIID, NS_IDOMELEMENT_IID);
|
||||
static NS_DEFINE_IID(kIDomEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
static PRLogModuleInfo* gLog;
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// XULCommandDispatcherImpl
|
||||
//
|
||||
// This is the focus manager for XUL documents.
|
||||
//
|
||||
class XULCommandDispatcherImpl : public nsIDOMXULCommandDispatcher,
|
||||
public nsIXULCommandDispatcher,
|
||||
public nsIDOMFocusListener,
|
||||
public nsIScriptObjectOwner
|
||||
{
|
||||
public:
|
||||
XULCommandDispatcherImpl(void);
|
||||
virtual ~XULCommandDispatcherImpl(void);
|
||||
|
||||
public:
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIDOMXULCommandDispatcher interface
|
||||
NS_DECL_IDOMXULCOMMANDDISPATCHER
|
||||
|
||||
// nsIDOMFocusListener
|
||||
virtual nsresult Focus(nsIDOMEvent* aEvent);
|
||||
virtual nsresult Blur(nsIDOMEvent* aEvent);
|
||||
|
||||
// nsIDOMEventListener
|
||||
virtual nsresult HandleEvent(nsIDOMEvent* anEvent) { return NS_OK; };
|
||||
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void *aScriptObject);
|
||||
|
||||
protected:
|
||||
NS_IMETHOD GetParentWindowFromElement(nsIDOMElement* aElement, nsPIDOMWindow** aPWindow);
|
||||
|
||||
void* mScriptObject; // ????
|
||||
|
||||
// XXX THis was supposed to be WEAK, but c'mon, that's an accident
|
||||
// waiting to happen! If somebody deletes the node, then asks us
|
||||
// for the focus, we'll get killed!
|
||||
nsCOMPtr<nsIDOMNode> mCurrentNode; // [OWNER]
|
||||
|
||||
class Updater {
|
||||
public:
|
||||
Updater(nsIDOMElement* aElement,
|
||||
const nsString& aEvents,
|
||||
const nsString& aTargets)
|
||||
: mElement(aElement),
|
||||
mEvents(aEvents),
|
||||
mTargets(aTargets),
|
||||
mNext(nsnull)
|
||||
{}
|
||||
|
||||
nsIDOMElement* mElement; // [WEAK]
|
||||
nsString mEvents;
|
||||
nsString mTargets;
|
||||
Updater* mNext;
|
||||
};
|
||||
|
||||
Updater* mUpdaters;
|
||||
|
||||
PRBool Matches(const nsString& aList, const nsString& aElement);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
XULCommandDispatcherImpl::XULCommandDispatcherImpl(void)
|
||||
nsXULCommandDispatcher::nsXULCommandDispatcher(void)
|
||||
: mScriptObject(nsnull), mCurrentNode(nsnull), mUpdaters(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
@ -144,7 +61,7 @@ XULCommandDispatcherImpl::XULCommandDispatcherImpl(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
XULCommandDispatcherImpl::~XULCommandDispatcherImpl(void)
|
||||
nsXULCommandDispatcher::~nsXULCommandDispatcher(void)
|
||||
{
|
||||
while (mUpdaters) {
|
||||
Updater* doomed = mUpdaters;
|
||||
|
@ -153,48 +70,49 @@ XULCommandDispatcherImpl::~XULCommandDispatcherImpl(void)
|
|||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(XULCommandDispatcherImpl)
|
||||
NS_IMPL_RELEASE(XULCommandDispatcherImpl)
|
||||
NS_IMPL_ADDREF(nsXULCommandDispatcher)
|
||||
NS_IMPL_RELEASE(nsXULCommandDispatcher)
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULCommandDispatcherImpl::QueryInterface(REFNSIID iid, void** result)
|
||||
nsXULCommandDispatcher::QueryInterface(REFNSIID iid, void** result)
|
||||
{
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*result = nsnull;
|
||||
if (iid.Equals(kISupportsIID)) {
|
||||
*result = (nsISupports*)(nsIXULCommandDispatcher*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
else if (iid.Equals(nsIXULCommandDispatcher::GetIID())) {
|
||||
*result = NS_STATIC_CAST(nsIXULCommandDispatcher*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
else if (iid.Equals(nsIDOMXULCommandDispatcher::GetIID())) {
|
||||
if (iid.Equals(NS_GET_IID(nsISupports)) ||
|
||||
iid.Equals(NS_GET_IID(nsIDOMXULCommandDispatcher))) {
|
||||
*result = NS_STATIC_CAST(nsIDOMXULCommandDispatcher*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
else if (iid.Equals(nsIDOMFocusListener::GetIID())) {
|
||||
else if (iid.Equals(NS_GET_IID(nsIDOMFocusListener)) ||
|
||||
iid.Equals(NS_GET_IID(nsIDOMEventListener))) {
|
||||
*result = NS_STATIC_CAST(nsIDOMFocusListener*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
else if (iid.Equals(kIDomEventListenerIID)) {
|
||||
*result = (nsIDOMEventListener*)(nsIDOMFocusListener*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
else if (iid.Equals(kIScriptObjectOwnerIID)) {
|
||||
else if (iid.Equals(NS_GET_IID(nsIScriptObjectOwner))) {
|
||||
*result = NS_STATIC_CAST(nsIScriptObjectOwner*, this);
|
||||
}
|
||||
else if (iid.Equals(NS_GET_IID(nsISupportsWeakReference))) {
|
||||
*result = NS_STATIC_CAST(nsISupportsWeakReference*, this);
|
||||
}
|
||||
else {
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXULCommandDispatcher::Create(nsIDOMXULCommandDispatcher** aResult)
|
||||
{
|
||||
nsXULCommandDispatcher* dispatcher = new nsXULCommandDispatcher();
|
||||
if (! dispatcher)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
*aResult = dispatcher;
|
||||
NS_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -202,7 +120,7 @@ XULCommandDispatcherImpl::QueryInterface(REFNSIID iid, void** result)
|
|||
// nsIDOMXULTracker Interface
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULCommandDispatcherImpl::GetFocusedNode(nsIDOMNode** aNode)
|
||||
nsXULCommandDispatcher::GetFocusedNode(nsIDOMNode** aNode)
|
||||
{
|
||||
*aNode = mCurrentNode;
|
||||
NS_IF_ADDREF(*aNode);
|
||||
|
@ -210,7 +128,7 @@ XULCommandDispatcherImpl::GetFocusedNode(nsIDOMNode** aNode)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULCommandDispatcherImpl::SetFocusedNode(nsIDOMNode* aNode)
|
||||
nsXULCommandDispatcher::SetFocusedNode(nsIDOMNode* aNode)
|
||||
{
|
||||
// XXX On a blur, will need to fire an updatecommands (focus) on the
|
||||
// parent window.
|
||||
|
@ -221,7 +139,7 @@ XULCommandDispatcherImpl::SetFocusedNode(nsIDOMNode* aNode)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULCommandDispatcherImpl::AddCommandUpdater(nsIDOMElement* aElement,
|
||||
nsXULCommandDispatcher::AddCommandUpdater(nsIDOMElement* aElement,
|
||||
const nsString& aEvents,
|
||||
const nsString& aTargets)
|
||||
{
|
||||
|
@ -270,7 +188,7 @@ XULCommandDispatcherImpl::AddCommandUpdater(nsIDOMElement* aElement,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULCommandDispatcherImpl::RemoveCommandUpdater(nsIDOMElement* aElement)
|
||||
nsXULCommandDispatcher::RemoveCommandUpdater(nsIDOMElement* aElement)
|
||||
{
|
||||
NS_PRECONDITION(aElement != nsnull, "null ptr");
|
||||
if (! aElement)
|
||||
|
@ -301,7 +219,7 @@ XULCommandDispatcherImpl::RemoveCommandUpdater(nsIDOMElement* aElement)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULCommandDispatcherImpl::UpdateCommands(const nsString& aEventName)
|
||||
nsXULCommandDispatcher::UpdateCommands(const nsString& aEventName)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
|
@ -364,7 +282,7 @@ XULCommandDispatcherImpl::UpdateCommands(const nsString& aEventName)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULCommandDispatcherImpl::GetControllers(nsIControllers** aResult)
|
||||
nsXULCommandDispatcher::GetControllers(nsIControllers** aResult)
|
||||
{
|
||||
//XXX: we should fix this so there's a generic interface that describes controllers,
|
||||
// so this code would have no special knowledge of what object might have controllers.
|
||||
|
@ -395,7 +313,7 @@ XULCommandDispatcherImpl::GetControllers(nsIControllers** aResult)
|
|||
/////
|
||||
|
||||
nsresult
|
||||
XULCommandDispatcherImpl::Focus(nsIDOMEvent* aEvent)
|
||||
nsXULCommandDispatcher::Focus(nsIDOMEvent* aEvent)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> t;
|
||||
aEvent->GetTarget(getter_AddRefs(t));
|
||||
|
@ -410,7 +328,7 @@ XULCommandDispatcherImpl::Focus(nsIDOMEvent* aEvent)
|
|||
}
|
||||
|
||||
nsresult
|
||||
XULCommandDispatcherImpl::Blur(nsIDOMEvent* aEvent)
|
||||
nsXULCommandDispatcher::Blur(nsIDOMEvent* aEvent)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> t;
|
||||
aEvent->GetTarget(getter_AddRefs(t));
|
||||
|
@ -424,7 +342,7 @@ XULCommandDispatcherImpl::Blur(nsIDOMEvent* aEvent)
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHODIMP
|
||||
XULCommandDispatcherImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
||||
nsXULCommandDispatcher::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
|
||||
|
@ -440,7 +358,7 @@ XULCommandDispatcherImpl::GetScriptObject(nsIScriptContext *aContext, void** aSc
|
|||
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULCommandDispatcherImpl::SetScriptObject(void *aScriptObject)
|
||||
nsXULCommandDispatcher::SetScriptObject(void *aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
|
@ -448,7 +366,7 @@ XULCommandDispatcherImpl::SetScriptObject(void *aScriptObject)
|
|||
|
||||
|
||||
PRBool
|
||||
XULCommandDispatcherImpl::Matches(const nsString& aList, const nsString& aElement)
|
||||
nsXULCommandDispatcher::Matches(const nsString& aList, const nsString& aElement)
|
||||
{
|
||||
if (aList == "*")
|
||||
return PR_TRUE; // match _everything_!
|
||||
|
@ -475,7 +393,8 @@ XULCommandDispatcherImpl::Matches(const nsString& aList, const nsString& aElemen
|
|||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP XULCommandDispatcherImpl::GetParentWindowFromElement(nsIDOMElement* aElement, nsPIDOMWindow** aPWindow)
|
||||
NS_IMETHODIMP
|
||||
nsXULCommandDispatcher::GetParentWindowFromElement(nsIDOMElement* aElement, nsPIDOMWindow** aPWindow)
|
||||
{
|
||||
nsCOMPtr<nsIDOMDocument> document;
|
||||
aElement->GetOwnerDocument(getter_AddRefs(document));
|
||||
|
@ -496,7 +415,8 @@ XULCommandDispatcherImpl::Matches(const nsString& aList, const nsString& aElemen
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP XULCommandDispatcherImpl::GetControllerForCommand(const nsString& command, nsIController** _retval)
|
||||
NS_IMETHODIMP
|
||||
nsXULCommandDispatcher::GetControllerForCommand(const nsString& command, nsIController** _retval)
|
||||
{
|
||||
*_retval = nsnull;
|
||||
|
||||
|
@ -548,15 +468,3 @@ XULCommandDispatcherImpl::Matches(const nsString& aList, const nsString& aElemen
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
NS_NewXULCommandDispatcher(nsIXULCommandDispatcher** CommandDispatcher)
|
||||
{
|
||||
XULCommandDispatcherImpl* focus = new XULCommandDispatcherImpl();
|
||||
if (!focus)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(focus);
|
||||
*CommandDispatcher = focus;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
|
||||
This is the focus manager for XUL documents.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef nsXULCommandDispatcher_h__
|
||||
#define nsXULCommandDispatcher_h__
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDOMXULCommandDispatcher.h"
|
||||
#include "nsIDOMFocusListener.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsString.h"
|
||||
|
||||
class nsIDOMElement;
|
||||
class nsPIDOMWindow;
|
||||
|
||||
|
||||
class nsXULCommandDispatcher : public nsIDOMXULCommandDispatcher,
|
||||
public nsIDOMFocusListener,
|
||||
public nsIScriptObjectOwner,
|
||||
public nsSupportsWeakReference
|
||||
{
|
||||
protected:
|
||||
nsXULCommandDispatcher(void);
|
||||
virtual ~nsXULCommandDispatcher(void);
|
||||
|
||||
public:
|
||||
|
||||
static NS_IMETHODIMP
|
||||
Create(nsIDOMXULCommandDispatcher** aResult);
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIDOMXULCommandDispatcher interface
|
||||
NS_DECL_IDOMXULCOMMANDDISPATCHER
|
||||
|
||||
// nsIDOMFocusListener
|
||||
virtual nsresult Focus(nsIDOMEvent* aEvent);
|
||||
virtual nsresult Blur(nsIDOMEvent* aEvent);
|
||||
|
||||
// nsIDOMEventListener
|
||||
virtual nsresult HandleEvent(nsIDOMEvent* anEvent) { return NS_OK; };
|
||||
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void *aScriptObject);
|
||||
|
||||
protected:
|
||||
NS_IMETHOD GetParentWindowFromElement(nsIDOMElement* aElement, nsPIDOMWindow** aPWindow);
|
||||
|
||||
void* mScriptObject; // ????
|
||||
|
||||
// XXX THis was supposed to be WEAK, but c'mon, that's an accident
|
||||
// waiting to happen! If somebody deletes the node, then asks us
|
||||
// for the focus, we'll get killed!
|
||||
nsCOMPtr<nsIDOMNode> mCurrentNode; // [OWNER]
|
||||
|
||||
class Updater {
|
||||
public:
|
||||
Updater(nsIDOMElement* aElement,
|
||||
const nsString& aEvents,
|
||||
const nsString& aTargets)
|
||||
: mElement(aElement),
|
||||
mEvents(aEvents),
|
||||
mTargets(aTargets),
|
||||
mNext(nsnull)
|
||||
{}
|
||||
|
||||
nsIDOMElement* mElement; // [WEAK]
|
||||
nsString mEvents;
|
||||
nsString mTargets;
|
||||
Updater* mNext;
|
||||
};
|
||||
|
||||
Updater* mUpdaters;
|
||||
|
||||
PRBool Matches(const nsString& aList, const nsString& aElement);
|
||||
};
|
||||
|
||||
#endif // nsXULCommandDispatcher_h__
|
|
@ -21,105 +21,69 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
This file provides the implementation for the XUL Command Dispatcher.
|
||||
|
||||
This file provides the implementation for the XUL "controllers"
|
||||
object.
|
||||
|
||||
*/
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsISupportsArray.h"
|
||||
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIXULCommandDispatcher.h"
|
||||
#include "nsIDOMFocusListener.h"
|
||||
#include "nsRDFCID.h"
|
||||
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIDOMXULDocument.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIDOMUIEvent.h"
|
||||
|
||||
#include "nsIDOMXULElement.h"
|
||||
#include "nsIControllers.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMXULCommandDispatcher.h"
|
||||
#include "nsXULControllers.h"
|
||||
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIPresShell.h"
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
static NS_DEFINE_IID(kIDomNodeIID, NS_IDOMNODE_IID);
|
||||
static NS_DEFINE_IID(kIDomElementIID, NS_IDOMELEMENT_IID);
|
||||
static NS_DEFINE_IID(kIDomEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// XULControllersImpl
|
||||
//
|
||||
// This is the focus manager for XUL documents.
|
||||
//
|
||||
class XULControllersImpl : public nsIControllers
|
||||
{
|
||||
public:
|
||||
XULControllersImpl(void);
|
||||
virtual ~XULControllersImpl(void);
|
||||
|
||||
public:
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSICONTROLLERS
|
||||
|
||||
|
||||
protected:
|
||||
nsISupportsArray* mControllers;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
XULControllersImpl::XULControllersImpl(void) :
|
||||
mControllers(nsnull)
|
||||
nsXULControllers::nsXULControllers()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
XULControllersImpl::~XULControllersImpl(void)
|
||||
nsXULControllers::~nsXULControllers(void)
|
||||
{
|
||||
NS_IF_RELEASE(mControllers);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(XULControllersImpl)
|
||||
NS_IMPL_RELEASE(XULControllersImpl)
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULControllersImpl::QueryInterface(REFNSIID iid, void** result)
|
||||
NS_NewXULControllers(nsISupports* aOuter, REFNSIID aIID, void** aResult)
|
||||
{
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
NS_PRECONDITION(aOuter == nsnull, "no aggregation");
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
*result = nsnull;
|
||||
if (iid.Equals(kISupportsIID)) {
|
||||
*result = (nsISupports*)(nsIControllers*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
nsXULControllers* controllers = new nsXULControllers();
|
||||
if (! controllers)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult rv;
|
||||
NS_ADDREF(controllers);
|
||||
rv = controllers->QueryInterface(aIID, aResult);
|
||||
NS_RELEASE(controllers);
|
||||
return rv;
|
||||
}
|
||||
else if (iid.Equals(nsIControllers::GetIID())) {
|
||||
*result = NS_STATIC_CAST(nsIControllers*, this);
|
||||
NS_ADDREF_THIS();
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsXULControllers, NS_GET_IID(nsIControllers));
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXULControllers::GetCommandDispatcher(nsIDOMXULCommandDispatcher** _result)
|
||||
{
|
||||
nsCOMPtr<nsIDOMXULCommandDispatcher> dispatcher = do_QueryReferent(mCommandDispatcher);
|
||||
*_result = dispatcher;
|
||||
NS_IF_ADDREF(*_result);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXULControllers::SetCommandDispatcher(nsIDOMXULCommandDispatcher* aCommandDispatcher)
|
||||
{
|
||||
mCommandDispatcher = getter_AddRefs(NS_GetWeakReference(aCommandDispatcher));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/* boolean SupportsCommand (in string command); */
|
||||
NS_IMETHODIMP XULControllersImpl::GetControllerForCommand(const PRUnichar *command, nsIController** _retval)
|
||||
NS_IMETHODIMP
|
||||
nsXULControllers::GetControllerForCommand(const PRUnichar *command, nsIController** _retval)
|
||||
{
|
||||
*_retval = nsnull;
|
||||
if(!mControllers)
|
||||
|
@ -145,18 +109,21 @@ XULControllersImpl::QueryInterface(REFNSIID iid, void** result)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void InsertControllerAt (in short index, in nsIController controller); */
|
||||
NS_IMETHODIMP XULControllersImpl::InsertControllerAt(PRUint32 index, nsIController *controller)
|
||||
NS_IMETHODIMP
|
||||
nsXULControllers::InsertControllerAt(PRUint32 index, nsIController *controller)
|
||||
{
|
||||
if(! mControllers )
|
||||
NS_NewISupportsArray(&mControllers);
|
||||
if(! mControllers ) {
|
||||
nsresult rv;
|
||||
rv = NS_NewISupportsArray(getter_AddRefs(mControllers));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
mControllers->InsertElementAt(controller, index);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* nsIController RemoveControllerAt (in short index); */
|
||||
NS_IMETHODIMP XULControllersImpl::RemoveControllerAt(PRUint32 index, nsIController **_retval)
|
||||
NS_IMETHODIMP
|
||||
nsXULControllers::RemoveControllerAt(PRUint32 index, nsIController **_retval)
|
||||
{
|
||||
if(mControllers) {
|
||||
nsCOMPtr<nsISupports> supports;
|
||||
|
@ -169,8 +136,9 @@ XULControllersImpl::QueryInterface(REFNSIID iid, void** result)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/* nsIController GetControllerAt (in short index); */
|
||||
NS_IMETHODIMP XULControllersImpl::GetControllerAt(PRUint32 index, nsIController **_retval)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXULControllers::GetControllerAt(PRUint32 index, nsIController **_retval)
|
||||
{
|
||||
if(mControllers) {
|
||||
nsCOMPtr<nsISupports> supports;
|
||||
|
@ -182,18 +150,21 @@ XULControllersImpl::QueryInterface(REFNSIID iid, void** result)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void AppendController (in nsIController controller); */
|
||||
NS_IMETHODIMP XULControllersImpl::AppendController(nsIController *controller)
|
||||
NS_IMETHODIMP
|
||||
nsXULControllers::AppendController(nsIController *controller)
|
||||
{
|
||||
if(! mControllers )
|
||||
NS_NewISupportsArray(&mControllers);
|
||||
if(! mControllers ) {
|
||||
nsresult rv;
|
||||
rv = NS_NewISupportsArray(getter_AddRefs(mControllers));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
mControllers->AppendElement(controller);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void RemoveController (in nsIController controller); */
|
||||
NS_IMETHODIMP XULControllersImpl::RemoveController(nsIController *controller)
|
||||
NS_IMETHODIMP
|
||||
nsXULControllers::RemoveController(nsIController *controller)
|
||||
{
|
||||
if(mControllers) {
|
||||
nsCOMPtr<nsISupports> supports = do_QueryInterface(controller);
|
||||
|
@ -203,8 +174,8 @@ XULControllersImpl::QueryInterface(REFNSIID iid, void** result)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/* short GetControllerCount (); */
|
||||
NS_IMETHODIMP XULControllersImpl::GetControllerCount(PRUint32 *_retval)
|
||||
NS_IMETHODIMP
|
||||
nsXULControllers::GetControllerCount(PRUint32 *_retval)
|
||||
{
|
||||
*_retval = 0;
|
||||
if(mControllers)
|
||||
|
@ -213,15 +184,3 @@ XULControllersImpl::QueryInterface(REFNSIID iid, void** result)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
NS_NewXULControllers(nsIControllers** aControllers)
|
||||
{
|
||||
nsIControllers* impl = new XULControllersImpl();
|
||||
if (!impl)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(impl);
|
||||
*aControllers = impl;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
The XUL "controllers" object.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef nsXULControllers_h__
|
||||
#define nsXULControllers_h__
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsWeakPtr.h"
|
||||
#include "nsIControllers.h"
|
||||
#include "nsISupportsArray.h"
|
||||
|
||||
class nsIDOMXULCommandDispatcher;
|
||||
|
||||
class nsXULControllers : public nsIControllers
|
||||
{
|
||||
public:
|
||||
friend NS_IMETHODIMP
|
||||
NS_NewXULControllers(nsISupports* aOuter, REFNSIID aIID, void** aResult);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICONTROLLERS
|
||||
|
||||
protected:
|
||||
nsXULControllers();
|
||||
virtual ~nsXULControllers(void);
|
||||
|
||||
nsCOMPtr<nsISupportsArray> mControllers;
|
||||
nsWeakPtr mCommandDispatcher;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // nsXULControllers_h__
|
|
@ -95,7 +95,6 @@
|
|||
#include "nsIBaseWindow.h"
|
||||
#include "nsIXMLContent.h"
|
||||
#include "nsIXMLElementFactory.h"
|
||||
#include "nsIXULCommandDispatcher.h"
|
||||
#include "nsIXULContent.h"
|
||||
#include "nsIXULContentSink.h"
|
||||
#include "nsIXULContentUtils.h"
|
||||
|
@ -108,6 +107,7 @@
|
|||
#include "nsRDFCID.h"
|
||||
#include "nsRDFDOMNodeList.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsXULCommandDispatcher.h"
|
||||
#include "nsXULDocument.h"
|
||||
#include "nsXULElement.h"
|
||||
#include "plstr.h"
|
||||
|
@ -143,7 +143,6 @@ static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
|
|||
static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID);
|
||||
static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
|
||||
static NS_DEFINE_CID(kXMLElementFactoryCID, NS_XML_ELEMENT_FACTORY_CID);
|
||||
static NS_DEFINE_CID(kXULCommandDispatcherCID, NS_XULCOMMANDDISPATCHER_CID);
|
||||
static NS_DEFINE_CID(kXULContentSinkCID, NS_XULCONTENTSINK_CID);
|
||||
static NS_DEFINE_CID(kXULContentUtilsCID, NS_XULCONTENTUTILS_CID);
|
||||
static NS_DEFINE_CID(kXULKeyListenerCID, NS_XULKEYLISTENER_CID);
|
||||
|
@ -3162,16 +3161,10 @@ nsXULDocument::Init()
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Create our focus tracker and hook it up.
|
||||
nsCOMPtr<nsIXULCommandDispatcher> commandDis;
|
||||
rv = nsComponentManager::CreateInstance(kXULCommandDispatcherCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIXULCommandDispatcher),
|
||||
getter_AddRefs(commandDis));
|
||||
rv = nsXULCommandDispatcher::Create(getter_AddRefs(mCommandDispatcher));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create a focus tracker");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mCommandDispatcher = do_QueryInterface(commandDis);
|
||||
|
||||
nsCOMPtr<nsIDOMEventListener> CommandDispatcher =
|
||||
do_QueryInterface(mCommandDispatcher);
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include "nsIDOMEventListener.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
#include "nsIDOMScriptObjectFactory.h"
|
||||
#include "nsIDOMXULCommandDispatcher.h"
|
||||
#include "nsIDOMXULElement.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIEventListenerManager.h"
|
||||
|
@ -82,6 +83,7 @@
|
|||
#include "nsIURL.h"
|
||||
#include "nsIXULContent.h"
|
||||
#include "nsIXULDocument.h"
|
||||
#include "nsXULControllers.h"
|
||||
#include "nsXULTreeElement.h"
|
||||
#include "nsXULEditorElement.h"
|
||||
#include "rdfutil.h"
|
||||
|
@ -132,8 +134,6 @@ static NS_DEFINE_CID(kXULContentUtilsCID, NS_XULCONTENTUTILS_CID);
|
|||
static NS_DEFINE_IID(kIXULPopupListenerIID, NS_IXULPOPUPLISTENER_IID);
|
||||
static NS_DEFINE_CID(kXULPopupListenerCID, NS_XULPOPUPLISTENER_CID);
|
||||
|
||||
static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
struct XULBroadcastListener
|
||||
|
@ -3245,16 +3245,30 @@ NS_IMETHODIMP
|
|||
nsXULElement::GetControllers(nsIControllers** aResult)
|
||||
{
|
||||
if (! Controllers()) {
|
||||
NS_PRECONDITION(mDocument != nsnull, "no document");
|
||||
if (! mDocument)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
nsresult rv;
|
||||
rv = EnsureSlots();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = nsComponentManager::CreateInstance(kXULControllersCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIControllers),
|
||||
getter_AddRefs(mSlots->mControllers));
|
||||
rv = NS_NewXULControllers(nsnull, NS_GET_IID(nsIControllers), getter_AddRefs(mSlots->mControllers));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create a controllers");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Set the command dispatcher on the new controllers object
|
||||
nsCOMPtr<nsIDOMXULDocument> domxuldoc = do_QueryInterface(mDocument);
|
||||
NS_ASSERTION(domxuldoc != nsnull, "not an nsIDOMXULDocument");
|
||||
if (! domxuldoc)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsCOMPtr<nsIDOMXULCommandDispatcher> dispatcher;
|
||||
rv = domxuldoc->GetCommandDispatcher(getter_AddRefs(dispatcher));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mSlots->mControllers->SetCommandDispatcher(dispatcher);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
*aResult = Controllers();
|
||||
|
|
Загрузка…
Ссылка в новой задаче