checking in support for script block children on XBL <handler> elements. r=hyatt

This commit is contained in:
ben%netscape.com 2000-05-15 07:19:35 +00:00
Родитель 89bbe2e6ff
Коммит c1fb66d25c
6 изменённых файлов: 68 добавлений и 6 удалений

Просмотреть файл

@ -639,6 +639,9 @@ nsXBLBinding::InstallEventHandlers(nsIContent* aBoundElement)
// Call AddScriptEventListener for other IID types
nsAutoString value;
child->GetAttribute(kNameSpaceID_None, kValueAtom, value);
if (value.IsEmpty())
GetTextData(child, value);
AddScriptEventListener(mBoundElement, eventAtom, value, iid);
}
}

Просмотреть файл

@ -39,6 +39,7 @@
#include "nsIDOMXULElement.h"
#include "nsIDOMNSHTMLTextAreaElement.h"
#include "nsIDOMNSHTMLInputElement.h"
#include "nsIDOMText.h"
PRUint32 nsXBLEventHandler::gRefCnt = 0;
nsIAtom* nsXBLEventHandler::kKeyCodeAtom = nsnull;
@ -437,9 +438,12 @@ nsXBLEventHandler::ExecuteHandler(const nsString& aEventName, nsIDOMEvent* aEven
// Compile the event handler.
nsAutoString handlerText;
mHandlerElement->GetAttribute(kNameSpaceID_None, kValueAtom, handlerText);
if (handlerText.IsEmpty())
return NS_OK; // For whatever reason, they didn't give us anything to do.
if (handlerText.IsEmpty()) {
// look to see if action content is contained by the handler element
GetTextData(mHandlerElement, handlerText);
if (handlerText.IsEmpty())
return NS_OK; // For whatever reason, they didn't give us anything to do.
}
// Compile the handler and bind it to the element.
nsCOMPtr<nsIDocument> boundDocument;
@ -1080,6 +1084,28 @@ PRBool nsXBLEventHandler::IsMatchingKeyCode(const PRUint32 aChar, const nsString
return ret;
}
nsresult
nsXBLEventHandler::GetTextData(nsIContent *aParent, nsString& aResult)
{
aResult.Truncate(0);
nsCOMPtr<nsIContent> textChild;
PRInt32 textCount;
aParent->ChildCount(textCount);
nsAutoString answer;
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);
aResult += data;
}
}
return NS_OK;
}
PRBool
nsXBLEventHandler::IsMatchingCharCode(const PRUint32 aChar, const nsString& aKeyName)
{

Просмотреть файл

@ -95,6 +95,8 @@ protected:
static nsIAtom* kValueAtom;
static nsIAtom* kCommandAtom;
static nsresult GetTextData(nsIContent *aParent, nsString& aResult);
protected:
nsIContent* mBoundElement; // Both of these refs are weak.
nsIContent* mHandlerElement;

Просмотреть файл

@ -639,6 +639,9 @@ nsXBLBinding::InstallEventHandlers(nsIContent* aBoundElement)
// Call AddScriptEventListener for other IID types
nsAutoString value;
child->GetAttribute(kNameSpaceID_None, kValueAtom, value);
if (value.IsEmpty())
GetTextData(child, value);
AddScriptEventListener(mBoundElement, eventAtom, value, iid);
}
}

Просмотреть файл

@ -39,6 +39,7 @@
#include "nsIDOMXULElement.h"
#include "nsIDOMNSHTMLTextAreaElement.h"
#include "nsIDOMNSHTMLInputElement.h"
#include "nsIDOMText.h"
PRUint32 nsXBLEventHandler::gRefCnt = 0;
nsIAtom* nsXBLEventHandler::kKeyCodeAtom = nsnull;
@ -437,9 +438,12 @@ nsXBLEventHandler::ExecuteHandler(const nsString& aEventName, nsIDOMEvent* aEven
// Compile the event handler.
nsAutoString handlerText;
mHandlerElement->GetAttribute(kNameSpaceID_None, kValueAtom, handlerText);
if (handlerText.IsEmpty())
return NS_OK; // For whatever reason, they didn't give us anything to do.
if (handlerText.IsEmpty()) {
// look to see if action content is contained by the handler element
GetTextData(mHandlerElement, handlerText);
if (handlerText.IsEmpty())
return NS_OK; // For whatever reason, they didn't give us anything to do.
}
// Compile the handler and bind it to the element.
nsCOMPtr<nsIDocument> boundDocument;
@ -1080,6 +1084,28 @@ PRBool nsXBLEventHandler::IsMatchingKeyCode(const PRUint32 aChar, const nsString
return ret;
}
nsresult
nsXBLEventHandler::GetTextData(nsIContent *aParent, nsString& aResult)
{
aResult.Truncate(0);
nsCOMPtr<nsIContent> textChild;
PRInt32 textCount;
aParent->ChildCount(textCount);
nsAutoString answer;
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);
aResult += data;
}
}
return NS_OK;
}
PRBool
nsXBLEventHandler::IsMatchingCharCode(const PRUint32 aChar, const nsString& aKeyName)
{

Просмотреть файл

@ -95,6 +95,8 @@ protected:
static nsIAtom* kValueAtom;
static nsIAtom* kCommandAtom;
static nsresult GetTextData(nsIContent *aParent, nsString& aResult);
protected:
nsIContent* mBoundElement; // Both of these refs are weak.
nsIContent* mHandlerElement;