From d3e0848c19053c6f86be60242b444a9039b96b25 Mon Sep 17 00:00:00 2001 From: "hyatt%netscape.com" Date: Sat, 18 Dec 1999 04:02:28 +0000 Subject: [PATCH] Fixes for 3 PDT+ bugs (THAT'S RIGHT). Bugs 21895, 21832, and 21610. r=mjudge, a=i'm leaving now for vacation, and i can't find anyone around, but i'm assuming that you actually want them before January 3rd, so I'm checking them in. --- content/events/src/nsEventStateManager.cpp | 99 ++++++++++++------- content/events/src/nsEventStateManager.h | 2 + .../document/src/nsXULCommandDispatcher.cpp | 4 - layout/events/src/nsEventStateManager.cpp | 99 ++++++++++++------- layout/events/src/nsEventStateManager.h | 2 + layout/forms/nsITextControlFrame.h | 2 + .../forms/public/nsIGfxTextControlFrame.h | 2 + .../html/forms/public/nsITextControlFrame.h | 2 + .../html/forms/src/nsGfxTextControlFrame.cpp | 42 ++++++-- layout/html/forms/src/nsGfxTextControlFrame.h | 5 + rdf/content/src/nsXULCommandDispatcher.cpp | 4 - rdf/content/src/nsXULKeyListener.cpp | 35 +++++-- 12 files changed, 209 insertions(+), 89 deletions(-) diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index ad11876ff64c..4c416d5e4f29 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -48,6 +48,8 @@ #include "nsIScriptGlobalObject.h" #include "nsISelfScrollingFrame.h" #include "nsIPrivateDOMEvent.h" +#include "nsIGfxTextControlFrame.h" +#include "nsPIDOMWindow.h" #undef DEBUG_scroll // define to see ugly mousewheel messages @@ -87,6 +89,8 @@ nsEventStateManager::nsEventStateManager() mLastMiddleMouseDownContent = nsnull; mLastRightMouseDownContent = nsnull; + mConsumeFocusEvents = PR_FALSE; + // init d&d gesture state machine variables mIsTrackingDragGesture = PR_FALSE; mGestureDownFrame = nsnull; @@ -194,35 +198,18 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, break; case NS_GOTFOCUS: { - if (!mDocument) { - nsCOMPtr presShell; - aPresContext->GetShell(getter_AddRefs(presShell)); + nsCOMPtr presShell; + aPresContext->GetShell(getter_AddRefs(presShell)); + + if (!mDocument) { if (presShell) { presShell->GetDocument(&mDocument); } } if (gLastFocusedDocument == mDocument) - break; - - if (gLastFocusedDocument) { - nsCOMPtr globalObject; - gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); - if(globalObject) { - - nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event; - event.eventStructType = NS_EVENT; - event.message = NS_BLUR_CONTENT; - - nsCOMPtr esm; - gLastFocusedPresContext->GetEventStateManager(getter_AddRefs(esm)); - esm->SetFocusedContent(nsnull); - gLastFocusedDocument->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); - globalObject->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); - } - } - + break; + //fire focus nsEventStatus status = nsEventStatus_eIgnore; nsEvent focusevent; @@ -241,6 +228,7 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, mCurrentFocus = currentFocus; } + NS_IF_RELEASE(gLastFocusedDocument); gLastFocusedDocument = mDocument; gLastFocusedPresContext = aPresContext; @@ -477,6 +465,11 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, case NS_MOUSE_MIDDLE_BUTTON_DOWN: case NS_MOUSE_RIGHT_BUTTON_DOWN: { + if (mConsumeFocusEvents) { + mConsumeFocusEvents = PR_FALSE; + break; + } + if (nsEventStatus_eConsumeNoDefault != *aStatus) { nsCOMPtr newFocus; mCurrentTarget->GetContent(getter_AddRefs(newFocus)); @@ -1924,18 +1917,56 @@ nsEventStateManager::SendFocusBlur(nsIPresContext* aPresContext, nsIContent *aCo } } - if (nsnull != gLastFocusedPresContext && gLastFocusedContent) { - //fire blur - nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event; - event.eventStructType = NS_EVENT; - event.message = NS_BLUR_CONTENT; + if (nsnull != gLastFocusedPresContext) { + + if (gLastFocusedContent) { - nsCOMPtr esm; - gLastFocusedPresContext->GetEventStateManager(getter_AddRefs(esm)); - esm->SetFocusedContent(gLastFocusedContent); - gLastFocusedContent->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); - esm->SetFocusedContent(nsnull); + // Retrieve this content node's pres context. it can be out of sync in + // the Ender widget case. + nsCOMPtr doc; + gLastFocusedContent->GetDocument(*getter_AddRefs(doc)); + nsCOMPtr shell = getter_AddRefs(doc->GetShellAt(0)); + nsCOMPtr oldPresContext; + shell->GetPresContext(getter_AddRefs(oldPresContext)); + + //fire blur + nsEventStatus status = nsEventStatus_eIgnore; + nsEvent event; + event.eventStructType = NS_EVENT; + event.message = NS_BLUR_CONTENT; + + nsCOMPtr esm; + oldPresContext->GetEventStateManager(getter_AddRefs(esm)); + esm->SetFocusedContent(gLastFocusedContent); + gLastFocusedContent->HandleDOMEvent(oldPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + esm->SetFocusedContent(nsnull); + } + + // Go ahead and fire a blur on the window. + nsCOMPtr globalObject; + gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); + + nsCOMPtr presShell; + aPresContext->GetShell(getter_AddRefs(presShell)); + + if (!mDocument) { + if (presShell) { + presShell->GetDocument(&mDocument); + } + } + + if ((gLastFocusedDocument != mDocument) && globalObject) { + nsEventStatus status = nsEventStatus_eIgnore; + nsEvent event; + event.eventStructType = NS_EVENT; + event.message = NS_BLUR_CONTENT; + + nsCOMPtr esm; + gLastFocusedPresContext->GetEventStateManager(getter_AddRefs(esm)); + esm->SetFocusedContent(nsnull); + gLastFocusedDocument->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + globalObject->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + } } NS_IF_RELEASE(gLastFocusedContent); diff --git a/content/events/src/nsEventStateManager.h b/content/events/src/nsEventStateManager.h index 8657e2e22c1e..903895ab5946 100644 --- a/content/events/src/nsEventStateManager.h +++ b/content/events/src/nsEventStateManager.h @@ -107,6 +107,8 @@ protected: void GenerateDragGesture ( nsIPresContext* aPresContext, nsGUIEvent *aEvent ) ; PRBool IsTrackingDragGesture ( ) const { return mIsTrackingDragGesture; } + PRBool mSuppressFocusChange; // Used only for Ender text fields to suppress a focus firing on mouse down + //Any frames here must be checked for validity in ClearFrameRefs nsIFrame* mCurrentTarget; nsIContent* mCurrentTargetContent; diff --git a/content/xul/document/src/nsXULCommandDispatcher.cpp b/content/xul/document/src/nsXULCommandDispatcher.cpp index cbcc50210156..c6cacd50e2a4 100644 --- a/content/xul/document/src/nsXULCommandDispatcher.cpp +++ b/content/xul/document/src/nsXULCommandDispatcher.cpp @@ -333,7 +333,6 @@ nsXULCommandDispatcher::Focus(nsIDOMEvent* aEvent) nsCOMPtr t; aEvent->GetTarget(getter_AddRefs(t)); -/* printf("%d : Focus occurred on: ", this); nsCOMPtr domDebugElement = do_QueryInterface(t); if (domDebugElement) { @@ -348,7 +347,6 @@ nsXULCommandDispatcher::Focus(nsIDOMEvent* aEvent) else printf("Window with a XUL doc (happens twice)"); } printf("\n"); -*/ nsCOMPtr domElement = do_QueryInterface(t); if (domElement && (domElement != mCurrentElement)) { @@ -388,7 +386,6 @@ nsXULCommandDispatcher::Blur(nsIDOMEvent* aEvent) nsCOMPtr t; aEvent->GetTarget(getter_AddRefs(t)); -/* printf("%d : Blur occurred on: ", this); nsCOMPtr domDebugElement = do_QueryInterface(t); if (domDebugElement) { @@ -403,7 +400,6 @@ nsXULCommandDispatcher::Blur(nsIDOMEvent* aEvent) else printf("Window with a XUL doc (happens twice)"); } printf("\n"); -*/ nsCOMPtr domElement = do_QueryInterface(t); if (domElement) { diff --git a/layout/events/src/nsEventStateManager.cpp b/layout/events/src/nsEventStateManager.cpp index ad11876ff64c..4c416d5e4f29 100644 --- a/layout/events/src/nsEventStateManager.cpp +++ b/layout/events/src/nsEventStateManager.cpp @@ -48,6 +48,8 @@ #include "nsIScriptGlobalObject.h" #include "nsISelfScrollingFrame.h" #include "nsIPrivateDOMEvent.h" +#include "nsIGfxTextControlFrame.h" +#include "nsPIDOMWindow.h" #undef DEBUG_scroll // define to see ugly mousewheel messages @@ -87,6 +89,8 @@ nsEventStateManager::nsEventStateManager() mLastMiddleMouseDownContent = nsnull; mLastRightMouseDownContent = nsnull; + mConsumeFocusEvents = PR_FALSE; + // init d&d gesture state machine variables mIsTrackingDragGesture = PR_FALSE; mGestureDownFrame = nsnull; @@ -194,35 +198,18 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, break; case NS_GOTFOCUS: { - if (!mDocument) { - nsCOMPtr presShell; - aPresContext->GetShell(getter_AddRefs(presShell)); + nsCOMPtr presShell; + aPresContext->GetShell(getter_AddRefs(presShell)); + + if (!mDocument) { if (presShell) { presShell->GetDocument(&mDocument); } } if (gLastFocusedDocument == mDocument) - break; - - if (gLastFocusedDocument) { - nsCOMPtr globalObject; - gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); - if(globalObject) { - - nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event; - event.eventStructType = NS_EVENT; - event.message = NS_BLUR_CONTENT; - - nsCOMPtr esm; - gLastFocusedPresContext->GetEventStateManager(getter_AddRefs(esm)); - esm->SetFocusedContent(nsnull); - gLastFocusedDocument->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); - globalObject->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); - } - } - + break; + //fire focus nsEventStatus status = nsEventStatus_eIgnore; nsEvent focusevent; @@ -241,6 +228,7 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, mCurrentFocus = currentFocus; } + NS_IF_RELEASE(gLastFocusedDocument); gLastFocusedDocument = mDocument; gLastFocusedPresContext = aPresContext; @@ -477,6 +465,11 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, case NS_MOUSE_MIDDLE_BUTTON_DOWN: case NS_MOUSE_RIGHT_BUTTON_DOWN: { + if (mConsumeFocusEvents) { + mConsumeFocusEvents = PR_FALSE; + break; + } + if (nsEventStatus_eConsumeNoDefault != *aStatus) { nsCOMPtr newFocus; mCurrentTarget->GetContent(getter_AddRefs(newFocus)); @@ -1924,18 +1917,56 @@ nsEventStateManager::SendFocusBlur(nsIPresContext* aPresContext, nsIContent *aCo } } - if (nsnull != gLastFocusedPresContext && gLastFocusedContent) { - //fire blur - nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event; - event.eventStructType = NS_EVENT; - event.message = NS_BLUR_CONTENT; + if (nsnull != gLastFocusedPresContext) { + + if (gLastFocusedContent) { - nsCOMPtr esm; - gLastFocusedPresContext->GetEventStateManager(getter_AddRefs(esm)); - esm->SetFocusedContent(gLastFocusedContent); - gLastFocusedContent->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); - esm->SetFocusedContent(nsnull); + // Retrieve this content node's pres context. it can be out of sync in + // the Ender widget case. + nsCOMPtr doc; + gLastFocusedContent->GetDocument(*getter_AddRefs(doc)); + nsCOMPtr shell = getter_AddRefs(doc->GetShellAt(0)); + nsCOMPtr oldPresContext; + shell->GetPresContext(getter_AddRefs(oldPresContext)); + + //fire blur + nsEventStatus status = nsEventStatus_eIgnore; + nsEvent event; + event.eventStructType = NS_EVENT; + event.message = NS_BLUR_CONTENT; + + nsCOMPtr esm; + oldPresContext->GetEventStateManager(getter_AddRefs(esm)); + esm->SetFocusedContent(gLastFocusedContent); + gLastFocusedContent->HandleDOMEvent(oldPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + esm->SetFocusedContent(nsnull); + } + + // Go ahead and fire a blur on the window. + nsCOMPtr globalObject; + gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); + + nsCOMPtr presShell; + aPresContext->GetShell(getter_AddRefs(presShell)); + + if (!mDocument) { + if (presShell) { + presShell->GetDocument(&mDocument); + } + } + + if ((gLastFocusedDocument != mDocument) && globalObject) { + nsEventStatus status = nsEventStatus_eIgnore; + nsEvent event; + event.eventStructType = NS_EVENT; + event.message = NS_BLUR_CONTENT; + + nsCOMPtr esm; + gLastFocusedPresContext->GetEventStateManager(getter_AddRefs(esm)); + esm->SetFocusedContent(nsnull); + gLastFocusedDocument->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + globalObject->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + } } NS_IF_RELEASE(gLastFocusedContent); diff --git a/layout/events/src/nsEventStateManager.h b/layout/events/src/nsEventStateManager.h index 8657e2e22c1e..903895ab5946 100644 --- a/layout/events/src/nsEventStateManager.h +++ b/layout/events/src/nsEventStateManager.h @@ -107,6 +107,8 @@ protected: void GenerateDragGesture ( nsIPresContext* aPresContext, nsGUIEvent *aEvent ) ; PRBool IsTrackingDragGesture ( ) const { return mIsTrackingDragGesture; } + PRBool mSuppressFocusChange; // Used only for Ender text fields to suppress a focus firing on mouse down + //Any frames here must be checked for validity in ClearFrameRefs nsIFrame* mCurrentTarget; nsIContent* mCurrentTargetContent; diff --git a/layout/forms/nsITextControlFrame.h b/layout/forms/nsITextControlFrame.h index dafea340a1a4..a15465cf1654 100644 --- a/layout/forms/nsITextControlFrame.h +++ b/layout/forms/nsITextControlFrame.h @@ -23,6 +23,7 @@ #include "nsISupports.h" class nsIEditor; +class nsIWebShell; #define NS_IGFXTEXTCONTROLFRAME_IID \ {/* d3ea33ea-9e00-11d3-bccc-0060b0fc76bd*/ \ @@ -35,4 +36,5 @@ public: static const nsIID& GetIID() { static nsIID iid = NS_IGFXTEXTCONTROLFRAME_IID; return iid; } NS_IMETHOD GetEditor(nsIEditor **aEditor) = 0; + NS_IMETHOD GetWebShell(nsIWebShell** aWebShell) = 0; }; diff --git a/layout/html/forms/public/nsIGfxTextControlFrame.h b/layout/html/forms/public/nsIGfxTextControlFrame.h index dafea340a1a4..a15465cf1654 100644 --- a/layout/html/forms/public/nsIGfxTextControlFrame.h +++ b/layout/html/forms/public/nsIGfxTextControlFrame.h @@ -23,6 +23,7 @@ #include "nsISupports.h" class nsIEditor; +class nsIWebShell; #define NS_IGFXTEXTCONTROLFRAME_IID \ {/* d3ea33ea-9e00-11d3-bccc-0060b0fc76bd*/ \ @@ -35,4 +36,5 @@ public: static const nsIID& GetIID() { static nsIID iid = NS_IGFXTEXTCONTROLFRAME_IID; return iid; } NS_IMETHOD GetEditor(nsIEditor **aEditor) = 0; + NS_IMETHOD GetWebShell(nsIWebShell** aWebShell) = 0; }; diff --git a/layout/html/forms/public/nsITextControlFrame.h b/layout/html/forms/public/nsITextControlFrame.h index dafea340a1a4..a15465cf1654 100644 --- a/layout/html/forms/public/nsITextControlFrame.h +++ b/layout/html/forms/public/nsITextControlFrame.h @@ -23,6 +23,7 @@ #include "nsISupports.h" class nsIEditor; +class nsIWebShell; #define NS_IGFXTEXTCONTROLFRAME_IID \ {/* d3ea33ea-9e00-11d3-bccc-0060b0fc76bd*/ \ @@ -35,4 +36,5 @@ public: static const nsIID& GetIID() { static nsIID iid = NS_IGFXTEXTCONTROLFRAME_IID; return iid; } NS_IMETHOD GetEditor(nsIEditor **aEditor) = 0; + NS_IMETHOD GetWebShell(nsIWebShell** aWebShell) = 0; }; diff --git a/layout/html/forms/src/nsGfxTextControlFrame.cpp b/layout/html/forms/src/nsGfxTextControlFrame.cpp index 1149fe2d89a9..a2f00a8c22fd 100644 --- a/layout/html/forms/src/nsGfxTextControlFrame.cpp +++ b/layout/html/forms/src/nsGfxTextControlFrame.cpp @@ -208,6 +208,16 @@ nsGfxTextControlFrame::Init(nsIPresContext* aPresContext, return (nsTextControlFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow)); } +NS_IMETHODIMP +nsGfxTextControlFrame::GetEditor(nsIEditor **aEditor) +{ + NS_ENSURE_ARG_POINTER(aEditor); + + *aEditor = mEditor; + NS_IF_ADDREF(*aEditor); + return NS_OK; +} + NS_IMETHODIMP nsGfxTextControlFrame::GetFrameType(nsIAtom** aType) const { @@ -219,12 +229,12 @@ nsGfxTextControlFrame::GetFrameType(nsIAtom** aType) const NS_IMETHODIMP -nsGfxTextControlFrame::GetEditor(nsIEditor **aEditor) +nsGfxTextControlFrame::GetWebShell(nsIWebShell **aWebShell) { - NS_ENSURE_ARG_POINTER(aEditor); + NS_ENSURE_ARG_POINTER(aWebShell); - *aEditor = mEditor; - NS_IF_ADDREF(*aEditor); + *aWebShell = mWebShell; + NS_IF_ADDREF(*aWebShell); return NS_OK; } @@ -2483,6 +2493,7 @@ nsGfxTextControlFrame::InstallEventListeners() if (NS_FAILED(result)) { return result ; } if (!mEventListener) { return NS_ERROR_NULL_POINTER; } mEventListener->SetFrame(this); + mEventListener->SetInnerPresShell(presShell); mEventListener->SetPresContext(mFramePresContext); mEventListener->SetView(view); @@ -3413,6 +3424,22 @@ nsEnderEventListener::DispatchMouseEvent(nsIDOMMouseEvent *aEvent, PRInt32 aEven result = manager->PostHandleEvent(mContext, &event, gfxFrame, &status, mView); } NS_IF_RELEASE(manager); + + if ((aEventType == NS_MOUSE_LEFT_BUTTON_DOWN) || + (aEventType == NS_MOUSE_MIDDLE_BUTTON_DOWN) || + (aEventType == NS_MOUSE_RIGHT_BUTTON_DOWN)) + { + // Call consume focus events on the inner event state manager to prevent its + // PostHandleEvent from immediately blurring us. + nsCOMPtr pc; + mInnerShell->GetPresContext(getter_AddRefs(pc)); + + nsCOMPtr esm; + pc->GetEventStateManager(getter_AddRefs(esm)); + esm->ConsumeFocusEvents(PR_TRUE); + // Now set the focus in to the widget. + mFrame->SetFocus(); + } } } } @@ -3625,6 +3652,7 @@ nsEnderEventListener::MouseOut(nsIDOMEvent* aEvent) nsresult nsEnderEventListener::Focus(nsIDOMEvent* aEvent) { + /* // In this case, the focus has all ready been set because of the mouse down // and setting it on the native widget causes an event to be dispatched // and this listener then gets call. So we want to skip it here @@ -3684,14 +3712,14 @@ nsEnderEventListener::Focus(nsIDOMEvent* aEvent) NS_RELEASE(manager); } } - +*/ return NS_OK; } nsresult nsEnderEventListener::Blur(nsIDOMEvent* aEvent) { - +/* nsCOMPtruiEvent; uiEvent = do_QueryInterface(aEvent); if (!uiEvent) { @@ -3737,7 +3765,7 @@ nsEnderEventListener::Blur(nsIDOMEvent* aEvent) mContent->HandleDOMEvent(mContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); } - +*/ return NS_OK; } diff --git a/layout/html/forms/src/nsGfxTextControlFrame.h b/layout/html/forms/src/nsGfxTextControlFrame.h index c464c9f80bb5..bd8ecef0fd26 100644 --- a/layout/html/forms/src/nsGfxTextControlFrame.h +++ b/layout/html/forms/src/nsGfxTextControlFrame.h @@ -202,6 +202,8 @@ public: /** set the view associated with this listener instance */ NS_IMETHOD SetView(nsIView *aView)=0; + + NS_IMETHOD SetInnerPresShell(nsIPresShell* aPresShell)=0; // Weak ref }; /****************************************************************************** @@ -236,6 +238,7 @@ public: NS_IMETHOD SetFrame(nsGfxTextControlFrame *aFrame); NS_IMETHOD SetPresContext(nsIPresContext *aCx) {mContext = do_QueryInterface(aCx); return NS_OK;} NS_IMETHOD SetView(nsIView *aView) {mView = aView; return NS_OK;} // views are not ref counted + NS_IMETHOD SetInnerPresShell(nsIPresShell* aPresShell) { mInnerShell = aPresShell; return NS_OK; } /** nsIDOMKeyListener interfaces * @see nsIDOMKeyListener @@ -287,6 +290,7 @@ protected: nsCWeakReference mFrame; nsIView *mView; // not ref counted nsCOMPtr mContext; // ref counted + nsIPresShell* mInnerShell; // not ref counted nsCOMPtr mContent; // ref counted nsString mTextValue; // the value of the text field at focus PRBool mSkipFocusDispatch; // On Mouse down we don't want to dispatch @@ -505,6 +509,7 @@ public: /* ============= nsIGfxTextControlFrame ================= */ NS_IMETHOD GetEditor(nsIEditor **aEditor); + NS_IMETHOD GetWebShell(nsIWebShell **aWebShell); protected: diff --git a/rdf/content/src/nsXULCommandDispatcher.cpp b/rdf/content/src/nsXULCommandDispatcher.cpp index cbcc50210156..c6cacd50e2a4 100644 --- a/rdf/content/src/nsXULCommandDispatcher.cpp +++ b/rdf/content/src/nsXULCommandDispatcher.cpp @@ -333,7 +333,6 @@ nsXULCommandDispatcher::Focus(nsIDOMEvent* aEvent) nsCOMPtr t; aEvent->GetTarget(getter_AddRefs(t)); -/* printf("%d : Focus occurred on: ", this); nsCOMPtr domDebugElement = do_QueryInterface(t); if (domDebugElement) { @@ -348,7 +347,6 @@ nsXULCommandDispatcher::Focus(nsIDOMEvent* aEvent) else printf("Window with a XUL doc (happens twice)"); } printf("\n"); -*/ nsCOMPtr domElement = do_QueryInterface(t); if (domElement && (domElement != mCurrentElement)) { @@ -388,7 +386,6 @@ nsXULCommandDispatcher::Blur(nsIDOMEvent* aEvent) nsCOMPtr t; aEvent->GetTarget(getter_AddRefs(t)); -/* printf("%d : Blur occurred on: ", this); nsCOMPtr domDebugElement = do_QueryInterface(t); if (domDebugElement) { @@ -403,7 +400,6 @@ nsXULCommandDispatcher::Blur(nsIDOMEvent* aEvent) else printf("Window with a XUL doc (happens twice)"); } printf("\n"); -*/ nsCOMPtr domElement = do_QueryInterface(t); if (domElement) { diff --git a/rdf/content/src/nsXULKeyListener.cpp b/rdf/content/src/nsXULKeyListener.cpp index 8e9efd953b4b..c15b77730b41 100644 --- a/rdf/content/src/nsXULKeyListener.cpp +++ b/rdf/content/src/nsXULKeyListener.cpp @@ -500,7 +500,7 @@ nsresult nsXULKeyListenerImpl::DoKey(nsIDOMEvent* aKeyEvent, eEventType aEventTy commandDispatcher->GetFocusedWindow(getter_AddRefs(domWindow)); piWindow = do_QueryInterface(domWindow); - nsCAutoString keyFile; + nsCAutoString keyFile, platformKeyFile; if (focusedElement) { // See if it's a textarea or input field. // XXX Check to see if the "key-bindings" CSS property points us to a file. @@ -511,23 +511,37 @@ nsresult nsXULKeyListenerImpl::DoKey(nsIDOMEvent* aKeyEvent, eEventType aEventTy if (tagName.EqualsIgnoreCase("input")) { nsAutoString type; focusedElement->GetAttribute(nsAutoString("type"), type); - if (type == "" || type.EqualsIgnoreCase("text")) + if (type == "" || type.EqualsIgnoreCase("text") || + type.EqualsIgnoreCase("password")) { keyFile = "chrome://global/content/inputBindings.xul"; + platformKeyFile = "chrome://global/content/platformInputBindings.xul"; + } } - else if (tagName.EqualsIgnoreCase("textarea")) + else if (tagName.EqualsIgnoreCase("textarea")) { keyFile = "chrome://global/content/textAreaBindings.xul"; + platformKeyFile = "chrome://global/content/platformTextAreaBindings.xul"; + } } nsCOMPtr document; - GetKeyBindingDocument(keyFile, getter_AddRefs(document)); + GetKeyBindingDocument(platformKeyFile, getter_AddRefs(document)); // Locate the key node and execute the JS on a match. PRBool handled = PR_FALSE; if (document) // Local focused ELEMENT handling stage. LocateAndExecuteKeyBinding(keyEvent, aEventType, document, handled); + if (!handled) { + GetKeyBindingDocument(keyFile, getter_AddRefs(document)); + if (document) // Local focused ELEMENT handling stage. + LocateAndExecuteKeyBinding(keyEvent, aEventType, document, handled); + } + nsCAutoString browserFile = "chrome://global/content/browserBindings.xul"; nsCAutoString editorFile = "chrome://global/content/editorBindings.xul"; + nsCAutoString browserPlatformFile = "chrome://global/content/platformBrowserBindings.xul"; + nsCAutoString editorPlatformFile = "chrome://global/content/platformEditorBindings.xul"; + nsresult result; if (!handled) { @@ -568,19 +582,26 @@ nsresult nsXULKeyListenerImpl::DoKey(nsIDOMEvent* aKeyEvent, eEventType aEventTy PRBool editorHasBindings = PR_FALSE; + nsCOMPtr platformDoc; if (presShell) { PRBool isEditor; if (NS_SUCCEEDED(presShell->GetDisplayNonTextSelection(&isEditor)) && isEditor) { editorHasBindings = PR_TRUE; + GetKeyBindingDocument(editorPlatformFile, getter_AddRefs(platformDoc)); GetKeyBindingDocument(editorFile, getter_AddRefs(document)); } } - if (!editorHasBindings) + if (!editorHasBindings) { + GetKeyBindingDocument(browserPlatformFile, getter_AddRefs(platformDoc)); GetKeyBindingDocument(browserFile, getter_AddRefs(document)); + } - if (document) + if (platformDoc) + LocateAndExecuteKeyBinding(keyEvent, aEventType, platformDoc, handled); + + if (!handled && document) LocateAndExecuteKeyBinding(keyEvent, aEventType, document, handled); } @@ -1559,6 +1580,8 @@ nsXULKeyListenerImpl::HandleEventUsingKeyset(nsIDOMElement* aKeysetElement, nsID masterContext->BindCompiledEventHandler(scriptObject, eventName, nsnull); + aKeyEvent->PreventBubble(); + aKeyEvent->PreventCapture(); return NS_OK; } }