From 19052f5fb1367615b9f7b727bf37bcea9e143f57 Mon Sep 17 00:00:00 2001 From: "heikki%netscape.com" Date: Tue, 29 Aug 2000 01:47:05 +0000 Subject: [PATCH] Fixed bug 46085. We were not firing the select event. This is the second half of the checkin... had some problems with CVS. jst is watching this checkin. r=mjudge. git-svn-id: svn://10.0.0.236/trunk@77435 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsSelection.cpp | 6 +++ mozilla/layout/base/nsPresShell.cpp | 22 ++++++++++- mozilla/layout/base/src/nsSelection.cpp | 6 +++ mozilla/layout/generic/nsSelection.cpp | 6 +++ mozilla/layout/html/base/src/nsPresShell.cpp | 22 ++++++++++- .../html/forms/src/nsGfxTextControlFrame2.cpp | 37 ++++++++++++++++++- 6 files changed, 94 insertions(+), 5 deletions(-) diff --git a/mozilla/content/base/src/nsSelection.cpp b/mozilla/content/base/src/nsSelection.cpp index f420e92bf9c..6265cc42239 100644 --- a/mozilla/content/base/src/nsSelection.cpp +++ b/mozilla/content/base/src/nsSelection.cpp @@ -1439,29 +1439,35 @@ nsSelection::MoveCaret(PRUint32 aKeycode, PRBool aContinue, nsSelectionAmount aA InvalidateDesiredX(); pos.mDirection = eDirNext; mHint = HINTLEFT;//stick to this line + PostReason(nsIDOMSelectionListener::KEYPRESS_REASON); break; case nsIDOMKeyEvent::DOM_VK_LEFT : //no break InvalidateDesiredX(); mHint = HINTRIGHT;//stick to opposite of movement + PostReason(nsIDOMSelectionListener::KEYPRESS_REASON); break; case nsIDOMKeyEvent::DOM_VK_DOWN : pos.mAmount = eSelectLine; pos.mDirection = eDirNext;//no break here + PostReason(nsIDOMSelectionListener::KEYPRESS_REASON); break; case nsIDOMKeyEvent::DOM_VK_UP : pos.mAmount = eSelectLine; + PostReason(nsIDOMSelectionListener::KEYPRESS_REASON); break; case nsIDOMKeyEvent::DOM_VK_HOME : InvalidateDesiredX(); pos.mAmount = eSelectBeginLine; InvalidateDesiredX(); mHint = HINTRIGHT;//stick to opposite of movement + PostReason(nsIDOMSelectionListener::KEYPRESS_REASON); break; case nsIDOMKeyEvent::DOM_VK_END : InvalidateDesiredX(); pos.mAmount = eSelectEndLine; InvalidateDesiredX(); mHint = HINTLEFT;//stick to this line + PostReason(nsIDOMSelectionListener::KEYPRESS_REASON); break; default :return NS_ERROR_FAILURE; } diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index ec1926adfc5..33211d42c97 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -2740,8 +2740,26 @@ PresShell::ScrollFrameIntoView(nsIFrame *aFrame, if (mViewManager) { // Get the viewport scroller - nsIScrollableView* scrollingView; - mViewManager->GetRootScrollableView(&scrollingView); + nsIScrollableView* rootscrollingView; + mViewManager->GetRootScrollableView(&rootscrollingView); + + nsIFrame *viewParent; + nsIScrollableView* scrollingView = nsnull; + aFrame->GetParentWithView(mPresContext,&viewParent); + if (viewParent) { + nsIView *view;//XXX COM ptr? + viewParent->GetView(mPresContext,&view); + if (view) { + nsIViewManager *vm = nsnull; + view->GetViewManager(vm); + if (vm){ + vm->GetRootScrollableView(&scrollingView); + } + } + } + if (!scrollingView) { + scrollingView = rootscrollingView; + } if (scrollingView) { nsIView* scrolledView; diff --git a/mozilla/layout/base/src/nsSelection.cpp b/mozilla/layout/base/src/nsSelection.cpp index f420e92bf9c..6265cc42239 100644 --- a/mozilla/layout/base/src/nsSelection.cpp +++ b/mozilla/layout/base/src/nsSelection.cpp @@ -1439,29 +1439,35 @@ nsSelection::MoveCaret(PRUint32 aKeycode, PRBool aContinue, nsSelectionAmount aA InvalidateDesiredX(); pos.mDirection = eDirNext; mHint = HINTLEFT;//stick to this line + PostReason(nsIDOMSelectionListener::KEYPRESS_REASON); break; case nsIDOMKeyEvent::DOM_VK_LEFT : //no break InvalidateDesiredX(); mHint = HINTRIGHT;//stick to opposite of movement + PostReason(nsIDOMSelectionListener::KEYPRESS_REASON); break; case nsIDOMKeyEvent::DOM_VK_DOWN : pos.mAmount = eSelectLine; pos.mDirection = eDirNext;//no break here + PostReason(nsIDOMSelectionListener::KEYPRESS_REASON); break; case nsIDOMKeyEvent::DOM_VK_UP : pos.mAmount = eSelectLine; + PostReason(nsIDOMSelectionListener::KEYPRESS_REASON); break; case nsIDOMKeyEvent::DOM_VK_HOME : InvalidateDesiredX(); pos.mAmount = eSelectBeginLine; InvalidateDesiredX(); mHint = HINTRIGHT;//stick to opposite of movement + PostReason(nsIDOMSelectionListener::KEYPRESS_REASON); break; case nsIDOMKeyEvent::DOM_VK_END : InvalidateDesiredX(); pos.mAmount = eSelectEndLine; InvalidateDesiredX(); mHint = HINTLEFT;//stick to this line + PostReason(nsIDOMSelectionListener::KEYPRESS_REASON); break; default :return NS_ERROR_FAILURE; } diff --git a/mozilla/layout/generic/nsSelection.cpp b/mozilla/layout/generic/nsSelection.cpp index f420e92bf9c..6265cc42239 100644 --- a/mozilla/layout/generic/nsSelection.cpp +++ b/mozilla/layout/generic/nsSelection.cpp @@ -1439,29 +1439,35 @@ nsSelection::MoveCaret(PRUint32 aKeycode, PRBool aContinue, nsSelectionAmount aA InvalidateDesiredX(); pos.mDirection = eDirNext; mHint = HINTLEFT;//stick to this line + PostReason(nsIDOMSelectionListener::KEYPRESS_REASON); break; case nsIDOMKeyEvent::DOM_VK_LEFT : //no break InvalidateDesiredX(); mHint = HINTRIGHT;//stick to opposite of movement + PostReason(nsIDOMSelectionListener::KEYPRESS_REASON); break; case nsIDOMKeyEvent::DOM_VK_DOWN : pos.mAmount = eSelectLine; pos.mDirection = eDirNext;//no break here + PostReason(nsIDOMSelectionListener::KEYPRESS_REASON); break; case nsIDOMKeyEvent::DOM_VK_UP : pos.mAmount = eSelectLine; + PostReason(nsIDOMSelectionListener::KEYPRESS_REASON); break; case nsIDOMKeyEvent::DOM_VK_HOME : InvalidateDesiredX(); pos.mAmount = eSelectBeginLine; InvalidateDesiredX(); mHint = HINTRIGHT;//stick to opposite of movement + PostReason(nsIDOMSelectionListener::KEYPRESS_REASON); break; case nsIDOMKeyEvent::DOM_VK_END : InvalidateDesiredX(); pos.mAmount = eSelectEndLine; InvalidateDesiredX(); mHint = HINTLEFT;//stick to this line + PostReason(nsIDOMSelectionListener::KEYPRESS_REASON); break; default :return NS_ERROR_FAILURE; } diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index ec1926adfc5..33211d42c97 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -2740,8 +2740,26 @@ PresShell::ScrollFrameIntoView(nsIFrame *aFrame, if (mViewManager) { // Get the viewport scroller - nsIScrollableView* scrollingView; - mViewManager->GetRootScrollableView(&scrollingView); + nsIScrollableView* rootscrollingView; + mViewManager->GetRootScrollableView(&rootscrollingView); + + nsIFrame *viewParent; + nsIScrollableView* scrollingView = nsnull; + aFrame->GetParentWithView(mPresContext,&viewParent); + if (viewParent) { + nsIView *view;//XXX COM ptr? + viewParent->GetView(mPresContext,&view); + if (view) { + nsIViewManager *vm = nsnull; + view->GetViewManager(vm); + if (vm){ + vm->GetRootScrollableView(&scrollingView); + } + } + } + if (!scrollingView) { + scrollingView = rootscrollingView; + } if (scrollingView) { nsIView* scrolledView; diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp index 6bea5bf58f2..1785148c3f4 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp @@ -203,7 +203,6 @@ protected: PRPackedBool mKnowSelectionCollapsed; PRPackedBool mFirstDoOfFirstUndo; - }; @@ -306,6 +305,42 @@ nsTextInputListener::NotifySelectionChanged(nsIDOMDocument* aDoc, nsIDOMSelectio if (!mFrame || !aDoc || !aSel || NS_FAILED(aSel->GetIsCollapsed(&collapsed))) return NS_OK; + // Fire the select event + // The specs don't exactly say when we should fire the select event. + // IE: Whenever you add/remove a character to/from the selection. Also + // if you get to the end of the text field you will get new event for each + // keypress or a continuous stream of events if you use the mouse. IE will + // fire select event when the selection collapses to nothing if you are holding down + // the shift or mouse button. + // Mozilla: If we have non-empty selection we will fire a new event for each + // keypress (or mouseup) if the selection changed. Mozilla will never + // create an event if the selection collapses to nothing. + if (!collapsed && ((aReason & MOUSEUP_REASON) || (aReason & KEYPRESS_REASON))) { + nsCOMPtr content; + mFrame->GetFormContent(*getter_AddRefs(content)); + if (content) { + nsEventStatus status = nsEventStatus_eIgnore; + nsGUIEvent event; + event.eventStructType = NS_GUI_EVENT; + event.widget = nsnull; + event.message = NS_FORM_SELECTED; + event.flags = NS_EVENT_FLAG_INIT; + + nsCOMPtr doc; + if (NS_SUCCEEDED(content->GetDocument(*getter_AddRefs(doc)))) { + if (doc) { + nsCOMPtr presShell = dont_AddRef(doc->GetShellAt(0)); + if (presShell) { + nsCOMPtr context; + if (NS_SUCCEEDED(presShell->GetPresContext(getter_AddRefs(context)))&& context) { + content->HandleDOMEvent(context, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + } + } + } + } + } + } + // if the collapsed state did not change, don't fire notifications if (mKnowSelectionCollapsed && collapsed == mSelectionWasCollapsed) return NS_OK;