2000-03-21 13:14:34 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* 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 Communicator client 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.
|
|
|
|
*
|
|
|
|
* Original Author: David W. Hyatt (hyatt@netscape.com)
|
|
|
|
*
|
2000-07-01 02:36:18 +00:00
|
|
|
* Contributor(s): Brendan Eich (brendan@mozilla.org)
|
2000-03-21 13:14:34 +00:00
|
|
|
*/
|
|
|
|
|
2000-01-26 10:06:30 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2000-09-02 01:09:47 +00:00
|
|
|
#include "nsIXBLPrototypeHandler.h"
|
2000-01-26 10:06:30 +00:00
|
|
|
#include "nsXBLEventHandler.h"
|
|
|
|
#include "nsIContent.h"
|
2000-01-26 10:25:55 +00:00
|
|
|
#include "nsIAtom.h"
|
2000-01-26 10:06:30 +00:00
|
|
|
#include "nsIDOMKeyEvent.h"
|
2000-05-21 06:58:15 +00:00
|
|
|
#include "nsIDOMMouseEvent.h"
|
2000-01-26 10:25:55 +00:00
|
|
|
#include "nsINameSpaceManager.h"
|
2000-01-26 11:05:44 +00:00
|
|
|
#include "nsIScriptContext.h"
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIJSEventListener.h"
|
2000-01-27 07:49:50 +00:00
|
|
|
#include "nsIController.h"
|
2000-09-20 07:16:04 +00:00
|
|
|
#include "nsIControllers.h"
|
2000-01-27 07:57:29 +00:00
|
|
|
#include "nsIDOMXULElement.h"
|
|
|
|
#include "nsIDOMNSHTMLTextAreaElement.h"
|
|
|
|
#include "nsIDOMNSHTMLInputElement.h"
|
2000-05-15 07:19:35 +00:00
|
|
|
#include "nsIDOMText.h"
|
2000-06-22 00:36:19 +00:00
|
|
|
#include "nsIEventListenerManager.h"
|
|
|
|
#include "nsIDOMEventReceiver.h"
|
2000-09-20 07:16:04 +00:00
|
|
|
#include "nsIDOMEventListener.h"
|
2000-06-22 00:36:19 +00:00
|
|
|
#include "nsXBLBinding.h"
|
2000-07-20 14:32:30 +00:00
|
|
|
#include "nsIPrivateDOMEvent.h"
|
2000-09-01 08:40:38 +00:00
|
|
|
#include "nsIDOMWindowInternal.h"
|
2000-08-17 00:09:16 +00:00
|
|
|
#include "nsIPref.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2000-09-15 23:28:29 +00:00
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsXPIDLString.h"
|
2000-08-17 00:09:16 +00:00
|
|
|
|
2000-09-20 07:16:04 +00:00
|
|
|
#include "nsIDOMFocusListener.h"
|
|
|
|
#include "nsIDOMKeyListener.h"
|
2001-08-06 21:49:35 +00:00
|
|
|
#include "nsIDOMXULListener.h"
|
2000-09-20 07:16:04 +00:00
|
|
|
#include "nsIDOMMouseListener.h"
|
|
|
|
#include "nsIDOMDragListener.h"
|
|
|
|
#include "nsIDOMScrollListener.h"
|
|
|
|
#include "nsIDOMFormListener.h"
|
2000-01-26 10:25:55 +00:00
|
|
|
|
|
|
|
PRUint32 nsXBLEventHandler::gRefCnt = 0;
|
|
|
|
nsIAtom* nsXBLEventHandler::kKeyCodeAtom = nsnull;
|
|
|
|
nsIAtom* nsXBLEventHandler::kCharCodeAtom = nsnull;
|
|
|
|
nsIAtom* nsXBLEventHandler::kKeyAtom = nsnull;
|
2000-09-01 01:38:04 +00:00
|
|
|
nsIAtom* nsXBLEventHandler::kActionAtom = nsnull;
|
2000-01-27 07:49:50 +00:00
|
|
|
nsIAtom* nsXBLEventHandler::kCommandAtom = nsnull;
|
2000-05-21 06:58:15 +00:00
|
|
|
nsIAtom* nsXBLEventHandler::kClickCountAtom = nsnull;
|
|
|
|
nsIAtom* nsXBLEventHandler::kButtonAtom = nsnull;
|
2000-09-01 08:07:07 +00:00
|
|
|
nsIAtom* nsXBLEventHandler::kModifiersAtom = nsnull;
|
2000-01-26 10:06:30 +00:00
|
|
|
|
2000-09-22 05:02:20 +00:00
|
|
|
nsXBLEventHandler::nsXBLEventHandler(nsIDOMEventReceiver* aEventReceiver, nsIXBLPrototypeHandler* aHandler)
|
2000-01-26 10:06:30 +00:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
2000-09-01 08:07:07 +00:00
|
|
|
mEventReceiver = aEventReceiver;
|
2000-09-02 01:09:47 +00:00
|
|
|
mProtoHandler = aHandler;
|
2000-06-22 00:36:19 +00:00
|
|
|
mNextHandler = nsnull;
|
2000-01-26 10:25:55 +00:00
|
|
|
gRefCnt++;
|
|
|
|
if (gRefCnt == 1) {
|
|
|
|
kKeyCodeAtom = NS_NewAtom("keycode");
|
|
|
|
kKeyAtom = NS_NewAtom("key");
|
|
|
|
kCharCodeAtom = NS_NewAtom("charcode");
|
2000-09-01 08:07:07 +00:00
|
|
|
kModifiersAtom = NS_NewAtom("modifiers");
|
2000-09-01 01:38:04 +00:00
|
|
|
kActionAtom = NS_NewAtom("action");
|
2000-01-27 07:49:50 +00:00
|
|
|
kCommandAtom = NS_NewAtom("command");
|
2000-05-21 06:58:15 +00:00
|
|
|
kClickCountAtom = NS_NewAtom("clickcount");
|
|
|
|
kButtonAtom = NS_NewAtom("button");
|
2000-01-26 10:25:55 +00:00
|
|
|
}
|
2000-01-26 10:06:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXBLEventHandler::~nsXBLEventHandler()
|
|
|
|
{
|
2000-01-26 10:25:55 +00:00
|
|
|
gRefCnt--;
|
|
|
|
if (gRefCnt == 0) {
|
|
|
|
NS_RELEASE(kKeyAtom);
|
|
|
|
NS_RELEASE(kKeyCodeAtom);
|
|
|
|
NS_RELEASE(kCharCodeAtom);
|
2000-09-01 08:07:07 +00:00
|
|
|
NS_RELEASE(kModifiersAtom);
|
2000-09-01 01:38:04 +00:00
|
|
|
NS_RELEASE(kActionAtom);
|
2000-01-27 07:49:50 +00:00
|
|
|
NS_RELEASE(kCommandAtom);
|
2000-05-21 06:58:15 +00:00
|
|
|
NS_RELEASE(kButtonAtom);
|
|
|
|
NS_RELEASE(kClickCountAtom);
|
2000-01-26 10:25:55 +00:00
|
|
|
}
|
2000-01-26 10:06:30 +00:00
|
|
|
}
|
|
|
|
|
2000-09-20 07:16:04 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(nsXBLEventHandler, nsISupports)
|
2000-01-26 10:06:30 +00:00
|
|
|
|
2000-06-22 00:36:19 +00:00
|
|
|
void
|
|
|
|
nsXBLEventHandler::RemoveEventHandlers()
|
|
|
|
{
|
2000-09-01 08:07:07 +00:00
|
|
|
if (mNextHandler)
|
|
|
|
mNextHandler->RemoveEventHandlers();
|
2000-07-28 00:35:02 +00:00
|
|
|
|
2000-09-03 06:00:09 +00:00
|
|
|
// Figure out if we're using capturing or not.
|
|
|
|
if (!mProtoHandler)
|
|
|
|
return;
|
|
|
|
|
2000-09-22 05:02:20 +00:00
|
|
|
nsCOMPtr<nsIAtom> eventName;
|
|
|
|
mProtoHandler->GetEventName(getter_AddRefs(eventName));
|
|
|
|
|
2000-09-02 01:09:47 +00:00
|
|
|
nsCOMPtr<nsIContent> handlerElement;
|
|
|
|
mProtoHandler->GetHandlerElement(getter_AddRefs(handlerElement));
|
2000-09-03 06:00:09 +00:00
|
|
|
mProtoHandler = nsnull;
|
2000-09-02 01:09:47 +00:00
|
|
|
if (!handlerElement)
|
|
|
|
return;
|
|
|
|
|
2000-09-01 08:07:07 +00:00
|
|
|
PRBool useCapture = PR_FALSE;
|
|
|
|
nsAutoString capturer;
|
2001-08-17 08:14:14 +00:00
|
|
|
handlerElement->GetAttr(kNameSpaceID_None, nsXBLBinding::kPhaseAtom, capturer);
|
2000-09-01 08:07:07 +00:00
|
|
|
if (capturer == NS_LITERAL_STRING("capturing"))
|
|
|
|
useCapture = PR_TRUE;
|
|
|
|
|
|
|
|
nsAutoString type;
|
2001-08-17 08:14:14 +00:00
|
|
|
handlerElement->GetAttr(kNameSpaceID_None, nsXBLBinding::kEventAtom, type);
|
2000-09-01 08:07:07 +00:00
|
|
|
|
2000-09-15 23:28:29 +00:00
|
|
|
PRBool found = PR_FALSE;
|
|
|
|
nsIID iid;
|
2000-09-22 05:02:20 +00:00
|
|
|
nsXBLBinding::GetEventHandlerIID(eventName, &iid, &found);
|
2000-09-15 23:28:29 +00:00
|
|
|
|
2000-09-20 07:16:04 +00:00
|
|
|
nsCOMPtr<nsIDOMEventListener> listener(do_QueryInterface(this));
|
|
|
|
|
|
|
|
if (found && listener)
|
|
|
|
mEventReceiver->RemoveEventListener(type, listener, useCapture);
|
2000-06-22 00:36:19 +00:00
|
|
|
}
|
|
|
|
|
2000-01-26 10:06:30 +00:00
|
|
|
/// Helpers that are relegated to the end of the file /////////////////////////////
|
|
|
|
|
2000-05-15 07:19:35 +00:00
|
|
|
nsresult
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
nsXBLEventHandler::GetTextData(nsIContent *aParent, nsAWritableString& aResult)
|
2000-05-15 07:19:35 +00:00
|
|
|
{
|
|
|
|
aResult.Truncate(0);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> textChild;
|
|
|
|
PRInt32 textCount;
|
|
|
|
aParent->ChildCount(textCount);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
|
2000-05-15 07:19:35 +00:00
|
|
|
for (PRInt32 j = 0; j < textCount; j++) {
|
|
|
|
// Get the child.
|
|
|
|
aParent->ChildAt(j, *getter_AddRefs(textChild));
|
|
|
|
nsCOMPtr<nsIDOMText> text(do_QueryInterface(textChild));
|
|
|
|
if (text) {
|
|
|
|
nsAutoString data;
|
|
|
|
text->GetData(data);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
aResult.Append(data);
|
2000-05-15 07:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-01-26 10:06:30 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsresult
|
2000-09-02 01:09:47 +00:00
|
|
|
NS_NewXBLEventHandler(nsIDOMEventReceiver* aRec, nsIXBLPrototypeHandler* aHandler,
|
2000-01-26 10:06:30 +00:00
|
|
|
nsXBLEventHandler** aResult)
|
|
|
|
{
|
2000-09-22 05:02:20 +00:00
|
|
|
*aResult = new nsXBLEventHandler(aRec, aHandler);
|
2000-01-26 10:06:30 +00:00
|
|
|
if (!*aResult)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|