From 8e2f31db681e933dfa18204a13a2a03ab93935bc 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. --- content/base/src/nsSelection.cpp | 6 +++ layout/base/nsPresShell.cpp | 22 ++++++++++- layout/base/src/nsSelection.cpp | 6 +++ layout/generic/nsSelection.cpp | 6 +++ layout/html/base/src/nsPresShell.cpp | 22 ++++++++++- .../html/forms/src/nsGfxTextControlFrame2.cpp | 37 ++++++++++++++++++- 6 files changed, 94 insertions(+), 5 deletions(-) diff --git a/content/base/src/nsSelection.cpp b/content/base/src/nsSelection.cpp index f420e92bf9ca..6265cc422390 100644 --- a/content/base/src/nsSelection.cpp +++ b/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/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index ec1926adfc5a..33211d42c977 100644 --- a/layout/base/nsPresShell.cpp +++ b/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/layout/base/src/nsSelection.cpp b/layout/base/src/nsSelection.cpp index f420e92bf9ca..6265cc422390 100644 --- a/layout/base/src/nsSelection.cpp +++ b/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/layout/generic/nsSelection.cpp b/layout/generic/nsSelection.cpp index f420e92bf9ca..6265cc422390 100644 --- a/layout/generic/nsSelection.cpp +++ b/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/layout/html/base/src/nsPresShell.cpp b/layout/html/base/src/nsPresShell.cpp index ec1926adfc5a..33211d42c977 100644 --- a/layout/html/base/src/nsPresShell.cpp +++ b/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/layout/html/forms/src/nsGfxTextControlFrame2.cpp b/layout/html/forms/src/nsGfxTextControlFrame2.cpp index 6bea5bf58f28..1785148c3f42 100644 --- a/layout/html/forms/src/nsGfxTextControlFrame2.cpp +++ b/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;