Bug 336162. Don't fire DOM events from layout. r+sr=bz

This commit is contained in:
aaronleventhal%moonset.net 2006-05-03 17:02:37 +00:00
parent 74c52378a7
commit e4210b85b2
6 changed files with 21 additions and 41 deletions

View File

@ -2409,20 +2409,7 @@ nsListControlFrame::FireMenuItemActiveEvent()
return;
}
nsCOMPtr<nsIDOMEvent> event;
nsPresContext* presContext = GetPresContext();
nsEventDispatcher::CreateEvent(presContext, nsnull,
NS_LITERAL_STRING("Events"),
getter_AddRefs(event));
if (event) {
event->InitEvent(NS_LITERAL_STRING("DOMMenuItemActive"), PR_TRUE, PR_TRUE);
nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(event));
privateEvent->SetTrusted(PR_TRUE);
nsEventDispatcher::DispatchDOMEvent(optionContent, nsnull, event, nsnull,
nsnull);
}
FireDOMEvent(NS_LITERAL_STRING("DOMMenuItemActive"), optionContent);
}
#endif

View File

@ -59,6 +59,7 @@
#include "nsCRT.h"
#include "nsGUIEvent.h"
#include "nsIDOMEvent.h"
#include "nsPLDOMEvent.h"
#include "nsStyleConsts.h"
#include "nsIPresShell.h"
#include "prlog.h"
@ -1480,6 +1481,19 @@ nsFrame::GetContentForEvent(nsPresContext* aPresContext,
return NS_OK;
}
void
nsFrame::FireDOMEvent(const nsAString& aDOMEventName, nsIContent *aContent)
{
nsCOMPtr<nsIDOMNode> domNode = do_QueryInterface(aContent ? aContent : mContent);
if (domNode) {
nsPLDOMEvent *event = new nsPLDOMEvent(domNode, aDOMEventName);
if (event && NS_FAILED(event->PostDOMEvent())) {
PL_DestroyEvent(event);
}
}
}
/**
*
*/

View File

@ -531,6 +531,9 @@ protected:
void InitBoxMetrics(PRBool aClear);
nsBoxLayoutMetrics* BoxMetrics() const;
// Fire DOM event. If no aContent argument use frame's mContent.
void FireDOMEvent(const nsAString& aDOMEventName, nsIContent *aContent = nsnull);
private:
nsresult BoxReflow(nsBoxLayoutState& aState,
nsPresContext* aPresContext,

View File

@ -2207,27 +2207,6 @@ nsBoxFrame::RegUnregAccessKey(PRBool aDoReg)
}
void
nsBoxFrame::FireDOMEvent(const nsAString& aDOMEventName, nsIContent *aContent)
{
nsIContent *content = aContent ? aContent : mContent;
nsPresContext *presContext = GetPresContext();
if (content && presContext) {
// Fire a DOM event
nsCOMPtr<nsIDOMEvent> event;
if (nsEventDispatcher::CreateEvent(presContext, nsnull,
NS_LITERAL_STRING("Events"),
getter_AddRefs(event))) {
event->InitEvent(aDOMEventName, PR_TRUE, PR_TRUE);
nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(event));
privateEvent->SetTrusted(PR_TRUE);
nsEventDispatcher::DispatchDOMEvent(content, nsnull, event, nsnull,
nsnull);
}
}
}
void
nsBoxFrame::CheckBoxOrder(nsBoxLayoutState& aState)
{

View File

@ -199,9 +199,6 @@ public:
static nsresult LayoutChildAt(nsBoxLayoutState& aState, nsIBox* aBox, const nsRect& aRect);
// Fire DOM event. If no aContent argument use frame's mContent.
void FireDOMEvent(const nsAString& aDOMEventName, nsIContent *aContent = nsnull);
/**
* Utility method to redirect events on descendants to this frame.
* Supports 'allowevents' attribute on descendant elements to allow those

View File

@ -173,7 +173,7 @@ DestroyImagePLEvent(PLEvent* aEvent)
// asynchronously.
void
FireDOMEvent(nsIContent* aContent, PRUint32 aMessage)
FireImageDOMEvent(nsIContent* aContent, PRUint32 aMessage)
{
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
@ -638,13 +638,13 @@ NS_IMETHODIMP nsImageBoxFrame::OnStopDecode(imgIRequest *request,
{
if (NS_SUCCEEDED(aStatus))
// Fire an onload DOM event.
FireDOMEvent(mContent, NS_IMAGE_LOAD);
FireImageDOMEvent(mContent, NS_IMAGE_LOAD);
else {
// Fire an onerror DOM event.
mIntrinsicSize.SizeTo(0, 0);
nsBoxLayoutState state(GetPresContext());
MarkDirty(state);
FireDOMEvent(mContent, NS_IMAGE_ERROR);
FireImageDOMEvent(mContent, NS_IMAGE_ERROR);
}
return NS_OK;