From ac439774344869a3686cc6cc1225736686936a1c Mon Sep 17 00:00:00 2001 From: "Olli.Pettay%helsinki.fi" Date: Thu, 10 Jan 2008 21:55:39 +0000 Subject: [PATCH] Bug 411212, cannot prevent file-picker from showing on , r+sr=roc+bzbarsky, a=mtschrep git-svn-id: svn://10.0.0.236/trunk@242859 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/forms/nsFileControlFrame.cpp | 69 +++++++++---- mozilla/layout/forms/test/Makefile.in | 1 + mozilla/layout/forms/test/test_bug411236.html | 98 +++++++++++++++++++ 3 files changed, 149 insertions(+), 19 deletions(-) create mode 100644 mozilla/layout/forms/test/test_bug411236.html diff --git a/mozilla/layout/forms/nsFileControlFrame.cpp b/mozilla/layout/forms/nsFileControlFrame.cpp index 04fe2cb7277..b171c16039c 100644 --- a/mozilla/layout/forms/nsFileControlFrame.cpp +++ b/mozilla/layout/forms/nsFileControlFrame.cpp @@ -70,6 +70,9 @@ #include "nsContentCreatorFunctions.h" #include "nsContentUtils.h" #include "nsDisplayList.h" +#include "nsIDOMNSUIEvent.h" +#include "nsIDOMEventGroup.h" +#include "nsIDOM3EventTarget.h" #ifdef ACCESSIBILITY #include "nsIAccessibilityService.h" #endif @@ -117,15 +120,25 @@ void nsFileControlFrame::Destroy() { mTextFrame = nsnull; + ENSURE_TRUE(mContent); + // remove mMouseListener as a mouse event listener (bug 40533, bug 355931) - if (mBrowse) { - mBrowse->RemoveEventListenerByIID(mMouseListener, - NS_GET_IID(nsIDOMMouseListener)); + NS_NAMED_LITERAL_STRING(click, "click"); + + nsCOMPtr systemGroup; + mContent->GetSystemEventGroup(getter_AddRefs(systemGroup)); + + nsCOMPtr dom3Browse = do_QueryInterface(mBrowse); + if (dom3Browse) { + dom3Browse->RemoveGroupedEventListener(click, mMouseListener, PR_FALSE, + systemGroup); nsContentUtils::DestroyAnonymousContent(&mBrowse); } - if (mTextContent) { - mTextContent->RemoveEventListenerByIID(mMouseListener, - NS_GET_IID(nsIDOMMouseListener)); + nsCOMPtr dom3TextContent = + do_QueryInterface(mTextContent); + if (dom3TextContent) { + dom3TextContent->RemoveGroupedEventListener(click, mMouseListener, PR_FALSE, + systemGroup); nsContentUtils::DestroyAnonymousContent(&mTextContent); } @@ -170,9 +183,16 @@ nsFileControlFrame::CreateAnonymousContent(nsTArray& aElements) if (!aElements.AppendElement(mTextContent)) return NS_ERROR_OUT_OF_MEMORY; - // register as an event listener of the textbox to open file dialog on mouse click - mTextContent->AddEventListenerByIID(mMouseListener, - NS_GET_IID(nsIDOMMouseListener)); + NS_NAMED_LITERAL_STRING(click, "click"); + nsCOMPtr systemGroup; + mContent->GetSystemEventGroup(getter_AddRefs(systemGroup)); + nsCOMPtr dom3TextContent = + do_QueryInterface(mTextContent); + NS_ENSURE_STATE(dom3TextContent); + // Register as an event listener of the textbox + // to open file dialog on mouse click + dom3TextContent->AddGroupedEventListener(click, mMouseListener, PR_FALSE, + systemGroup); // Create the browse button NS_NewHTMLElement(getter_AddRefs(mBrowse), nodeInfo); @@ -196,9 +216,12 @@ nsFileControlFrame::CreateAnonymousContent(nsTArray& aElements) if (!aElements.AppendElement(mBrowse)) return NS_ERROR_OUT_OF_MEMORY; - // register as an event listener of the button to open file dialog on mouse click - mBrowse->AddEventListenerByIID(mMouseListener, - NS_GET_IID(nsIDOMMouseListener)); + nsCOMPtr dom3Browse = do_QueryInterface(mBrowse); + NS_ENSURE_STATE(dom3Browse); + // Register as an event listener of the button + // to open file dialog on mouse click + dom3Browse->AddGroupedEventListener(click, mMouseListener, PR_FALSE, + systemGroup); SyncAttr(kNameSpaceID_None, nsGkAtoms::size, SYNC_TEXT); SyncAttr(kNameSpaceID_None, nsGkAtoms::disabled, SYNC_BOTH); @@ -244,15 +267,23 @@ nsFileControlFrame::MouseClick(nsIDOMEvent* aMouseEvent) { // only allow the left button nsCOMPtr mouseEvent = do_QueryInterface(aMouseEvent); - if (mouseEvent) { - PRUint16 whichButton; - if (NS_SUCCEEDED(mouseEvent->GetButton(&whichButton))) { - if (whichButton != 0) { - return NS_OK; - } - } + nsCOMPtr uiEvent = do_QueryInterface(aMouseEvent); + NS_ENSURE_STATE(uiEvent); + PRBool defaultPrevented = PR_FALSE; + uiEvent->GetPreventDefault(&defaultPrevented); + if (defaultPrevented) { + return NS_OK; } + PRUint16 whichButton; + if (NS_FAILED(mouseEvent->GetButton(&whichButton)) || whichButton != 0) { + return NS_OK; + } + + PRInt32 clickCount; + if (NS_FAILED(mouseEvent->GetDetail(&clickCount)) || clickCount > 1) { + return NS_OK; + } nsresult result; diff --git a/mozilla/layout/forms/test/Makefile.in b/mozilla/layout/forms/test/Makefile.in index 3c3cf9e1e98..66ad53d2834 100644 --- a/mozilla/layout/forms/test/Makefile.in +++ b/mozilla/layout/forms/test/Makefile.in @@ -46,6 +46,7 @@ include $(topsrcdir)/config/rules.mk _TEST_FILES = test_bug345267.html \ test_bug402198.html \ + test_bug411236.html \ $(NULL) libs:: $(_TEST_FILES) diff --git a/mozilla/layout/forms/test/test_bug411236.html b/mozilla/layout/forms/test/test_bug411236.html new file mode 100644 index 00000000000..cd61a4325c2 --- /dev/null +++ b/mozilla/layout/forms/test/test_bug411236.html @@ -0,0 +1,98 @@ + + + + + Test for Bug 411236 + + + + + +Mozilla Bug 411236 +

+
+ +
+
+
+
+ + +