From bbd3667ca9768e484826185b51712478a4f6116f Mon Sep 17 00:00:00 2001 From: "mjudge%netscape.com" Date: Sat, 20 Feb 1999 23:52:05 +0000 Subject: [PATCH] Extra parameter in nsIFrameSeleciton HandleKeyEvent not necessary. nsRangeList mod now allows SHIFT-Key selection. currently bound directly to VK_LEFT,RIGHT should be changed eventually to something more internationaly friendly --- layout/base/nsIFrameSelection.h | 2 +- layout/base/nsPresShell.cpp | 2 +- layout/base/public/nsIFrameSelection.h | 2 +- layout/base/src/nsRangeList.cpp | 55 ++++++++++++++++++-------- layout/html/base/src/nsPresShell.cpp | 2 +- 5 files changed, 42 insertions(+), 21 deletions(-) diff --git a/layout/base/nsIFrameSelection.h b/layout/base/nsIFrameSelection.h index b6a3288a262a..982801db7931 100644 --- a/layout/base/nsIFrameSelection.h +++ b/layout/base/nsIFrameSelection.h @@ -49,7 +49,7 @@ public: * @param aGuiEvent is the event that should be dealt with by aFocusFrame * @param aFrame is the frame that MAY handle the event */ - NS_IMETHOD HandleKeyEvent(nsIFocusTracker *aTracker, nsGUIEvent *aGuiEvent, nsIFrame *aFrame) = 0; + NS_IMETHOD HandleKeyEvent(nsIFocusTracker *aTracker, nsGUIEvent *aGuiEvent) = 0; /** TakeFocus will take the focus to the new frame at the new offset and * will either extend the selection from the old anchor, or replace the old anchor. diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 8ddb2d5aa544..601bd74dcdd9 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -1801,7 +1801,7 @@ PresShell::HandleEvent(nsIView *aView, if (mSelection && mFocusEventFrame && aEvent->eventStructType == NS_KEY_EVENT) { mSelection->EnableFrameNotification(PR_FALSE); - mSelection->HandleKeyEvent((nsIFocusTracker *)this, aEvent, mFocusEventFrame); + mSelection->HandleKeyEvent((nsIFocusTracker *)this, aEvent); mSelection->EnableFrameNotification(PR_TRUE); //prevents secondary reset selection called since //we are a listener now. } diff --git a/layout/base/public/nsIFrameSelection.h b/layout/base/public/nsIFrameSelection.h index b6a3288a262a..982801db7931 100644 --- a/layout/base/public/nsIFrameSelection.h +++ b/layout/base/public/nsIFrameSelection.h @@ -49,7 +49,7 @@ public: * @param aGuiEvent is the event that should be dealt with by aFocusFrame * @param aFrame is the frame that MAY handle the event */ - NS_IMETHOD HandleKeyEvent(nsIFocusTracker *aTracker, nsGUIEvent *aGuiEvent, nsIFrame *aFrame) = 0; + NS_IMETHOD HandleKeyEvent(nsIFocusTracker *aTracker, nsGUIEvent *aGuiEvent) = 0; /** TakeFocus will take the focus to the new frame at the new offset and * will either extend the selection from the old anchor, or replace the old anchor. diff --git a/layout/base/src/nsRangeList.cpp b/layout/base/src/nsRangeList.cpp index df6b5d996d05..4fcee15c8f53 100644 --- a/layout/base/src/nsRangeList.cpp +++ b/layout/base/src/nsRangeList.cpp @@ -71,7 +71,7 @@ public: NS_DECL_ISUPPORTS /*BEGIN nsIFrameSelection interfaces*/ - NS_IMETHOD HandleKeyEvent(nsIFocusTracker *aTracker, nsGUIEvent *aGuiEvent, nsIFrame *aFrame); + NS_IMETHOD HandleKeyEvent(nsIFocusTracker *aTracker, nsGUIEvent *aGuiEvent); NS_IMETHOD TakeFocus(nsIFocusTracker *aTracker, nsIFrame *aFrame, PRInt32 aOffset, PRInt32 aContentOffset, PRBool aContinueSelection); NS_IMETHOD ResetSelection(nsIFocusTracker *aTracker, nsIFrame *aStartFrame); NS_IMETHOD EnableFrameNotification(PRBool aEnable){mNotifyFrames = aEnable; return NS_OK;} @@ -534,49 +534,70 @@ void printRange(nsIDOMRange *aDomRange) * focus DomNode, it is invalid? The answer now is yes. */ NS_IMETHODIMP -nsRangeList::HandleKeyEvent(nsIFocusTracker *aTracker, nsGUIEvent *aGuiEvent, nsIFrame *aFrame) +nsRangeList::HandleKeyEvent(nsIFocusTracker *aTracker, nsGUIEvent *aGuiEvent) { - if (!aGuiEvent || !aFrame) + if (!aGuiEvent ||!aTracker) return NS_ERROR_NULL_POINTER; + + nsIFrame *anchor; + nsIFrame *frame; + nsresult result = aTracker->GetFocus(&frame, &anchor); + if (NS_FAILED(result)) + return result; if (NS_KEY_DOWN == aGuiEvent->message) { - nsCOMPtr content; - if (NS_FAILED(aFrame->GetContent(getter_AddRefs(content))) || !content) - return NS_ERROR_NULL_POINTER; - nsCOMPtr domnode(do_QueryInterface(content)); - if (!domnode) - return NS_ERROR_FAILURE; PRBool selected; PRInt32 beginoffset; PRInt32 endoffset; PRInt32 contentoffset; nsresult result = NS_OK; - result = aFrame->GetSelected(&selected,&beginoffset,&endoffset, &contentoffset); - if (NS_FAILED(result)){ - return result; - } nsKeyEvent *keyEvent = (nsKeyEvent *)aGuiEvent; //this is ok. It really is a keyevent nsIFrame *resultFrame; PRInt32 frameOffset; PRInt32 contentOffset; PRInt32 offsetused = beginoffset; + nsIFrame *frameused; + result = frame->GetSelected(&selected,&beginoffset,&endoffset, &contentoffset); + if (NS_FAILED(result)){ + return result; + } switch (keyEvent->keyCode){ case nsIDOMEvent::VK_LEFT : //we need to look for the previous PAINTED location to move the cursor to. printf("debug vk left\n"); - if (endoffset < beginoffset) + if (keyEvent->isShift || (endoffset < beginoffset)){ //f,a offsetused = endoffset; - if (NS_SUCCEEDED(aFrame->PeekOffset(eSelectCharacter, eDirPrevious, offsetused, &resultFrame, &frameOffset, &contentOffset)) && resultFrame){ + frameused = frame; + } + else { + result = anchor->GetSelected(&selected,&beginoffset,&endoffset, &contentoffset); + if (NS_FAILED(result)){ + return result; + } + offsetused = beginoffset; + frameused = anchor; + } + if (NS_SUCCEEDED(frameused->PeekOffset(eSelectCharacter, eDirPrevious, offsetused, &resultFrame, &frameOffset, &contentOffset)) && resultFrame){ return TakeFocus(aTracker, resultFrame, frameOffset, contentOffset, keyEvent->isShift); } break; case nsIDOMEvent::VK_RIGHT : //we need to look for the next PAINTED location to move the cursor to. printf("debug vk right\n"); - if (endoffset > beginoffset) + if (!keyEvent->isShift && (endoffset < beginoffset)){ //f,a + result = anchor->GetSelected(&selected,&beginoffset,&endoffset, &contentoffset); + if (NS_FAILED(result)){ + return result; + } + offsetused = beginoffset; + frameused = anchor; + } + else { offsetused = endoffset; - if (NS_SUCCEEDED(aFrame->PeekOffset(eSelectCharacter, eDirNext, offsetused, &resultFrame, &frameOffset, &contentOffset)) && resultFrame){ + frameused = frame; + } + if (NS_SUCCEEDED(frameused->PeekOffset(eSelectCharacter, eDirNext, offsetused, &resultFrame, &frameOffset, &contentOffset)) && resultFrame){ return TakeFocus(aTracker, resultFrame, frameOffset, contentOffset, keyEvent->isShift); } case nsIDOMEvent::VK_UP : diff --git a/layout/html/base/src/nsPresShell.cpp b/layout/html/base/src/nsPresShell.cpp index 8ddb2d5aa544..601bd74dcdd9 100644 --- a/layout/html/base/src/nsPresShell.cpp +++ b/layout/html/base/src/nsPresShell.cpp @@ -1801,7 +1801,7 @@ PresShell::HandleEvent(nsIView *aView, if (mSelection && mFocusEventFrame && aEvent->eventStructType == NS_KEY_EVENT) { mSelection->EnableFrameNotification(PR_FALSE); - mSelection->HandleKeyEvent((nsIFocusTracker *)this, aEvent, mFocusEventFrame); + mSelection->HandleKeyEvent((nsIFocusTracker *)this, aEvent); mSelection->EnableFrameNotification(PR_TRUE); //prevents secondary reset selection called since //we are a listener now. }