diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index d69c77cade4..7efff0bdfa6 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -38,6 +38,8 @@ #include "nsIWebShell.h" #include "nsIFocusableContent.h" #include "nsIScrollableView.h" +#include "nsIDOMSelection.h" +#include "nsIFrameSelection.h" static NS_DEFINE_IID(kIEventStateManagerIID, NS_IEVENTSTATEMANAGER_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); @@ -159,8 +161,22 @@ nsEventStateManager::PostHandleEvent(nsIPresContext& aPresContext, case NS_MOUSE_LEFT_BUTTON_UP: case NS_MOUSE_MIDDLE_BUTTON_UP: case NS_MOUSE_RIGHT_BUTTON_UP: - ret = CheckForAndDispatchClick(aPresContext, (nsMouseEvent*)aEvent, aStatus); - SetContentState(nsnull, NS_EVENT_STATE_ACTIVE); + { + ret = CheckForAndDispatchClick(aPresContext, (nsMouseEvent*)aEvent, aStatus); + SetContentState(nsnull, NS_EVENT_STATE_ACTIVE); + nsCOMPtr shell; + nsresult rv = aPresContext.GetShell(getter_AddRefs(shell)); + if (NS_SUCCEEDED(rv) && shell){ + nsCOMPtr selection; + rv = shell->GetSelection(getter_AddRefs(selection)); + if (NS_SUCCEEDED(rv) && selection){ + nsCOMPtr frameSel; + frameSel = do_QueryInterface(selection); + if (frameSel) + frameSel->SetMouseDownState(PR_FALSE); + } + } + } break; case NS_KEY_DOWN: ret = DispatchKeyPressEvent(aPresContext, (nsKeyEvent*)aEvent, aStatus); diff --git a/mozilla/layout/base/nsIFrameSelection.h b/mozilla/layout/base/nsIFrameSelection.h index 988029d2a53..465dd7cb0fa 100644 --- a/mozilla/layout/base/nsIFrameSelection.h +++ b/mozilla/layout/base/nsIFrameSelection.h @@ -98,6 +98,19 @@ public: */ NS_IMETHOD LookUpSelection(nsIContent *aContent, PRInt32 aContentOffset, PRInt32 aContentLength, PRInt32 *aStart, PRInt32 *aEnd, PRBool *aDrawSelected, PRUint32 aFlag/*not used*/) = 0; + + /** SetMouseDownState(PRBool); + * sets the mouse state to aState for resons of drag state. + * @param aState is the new state of mousedown + */ + NS_IMETHOD SetMouseDownState(PRBool aState)=0; + + /** GetMouseDownState(PRBool *); + * gets the mouse state to aState for resons of drag state. + * @param aState will hold the state of mousedown + */ + NS_IMETHOD GetMouseDownState(PRBool *aState)=0; + }; diff --git a/mozilla/layout/base/public/nsIFrame.h b/mozilla/layout/base/public/nsIFrame.h index a4c88dda639..ab57cabc4a4 100644 --- a/mozilla/layout/base/public/nsIFrame.h +++ b/mozilla/layout/base/public/nsIFrame.h @@ -590,6 +590,9 @@ public: NS_IMETHOD GetSelected(PRBool *aSelected) const = 0; + /** EndSelection related calls + */ + /** * called to find the previous/next character, word, or line returns the actual * nsIFrame and the frame offset. THIS DOES NOT CHANGE SELECTION STATE @@ -598,13 +601,12 @@ public: * @param aAmount eWord, eCharacter, eLine * @param aDirection enum defined in this file to be eForward or eBackward * @param aStartOffset start offset to start the peek. 0 == beginning -1 = end - * @param aResultFrame frame that actually is the next/previous - * @param aFrameOffset offset from frame of the frame results - * @param aContentOffset offset from content of the frame results + * @param aResultContent content that actually is the next/previous + * @param aResultOffset offset for result content * @param aEatingWS boolean to tell us the state of our search for Next/Prev */ NS_IMETHOD PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, - nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset, PRBool aEatingWS) const = 0; + nsIContent **aResultContent, PRInt32 *aResultOffset, PRBool aEatingWS) const = 0; /** * See if tree verification is enabled. To enable tree verification add diff --git a/mozilla/layout/base/public/nsIFrameSelection.h b/mozilla/layout/base/public/nsIFrameSelection.h index 988029d2a53..465dd7cb0fa 100644 --- a/mozilla/layout/base/public/nsIFrameSelection.h +++ b/mozilla/layout/base/public/nsIFrameSelection.h @@ -98,6 +98,19 @@ public: */ NS_IMETHOD LookUpSelection(nsIContent *aContent, PRInt32 aContentOffset, PRInt32 aContentLength, PRInt32 *aStart, PRInt32 *aEnd, PRBool *aDrawSelected, PRUint32 aFlag/*not used*/) = 0; + + /** SetMouseDownState(PRBool); + * sets the mouse state to aState for resons of drag state. + * @param aState is the new state of mousedown + */ + NS_IMETHOD SetMouseDownState(PRBool aState)=0; + + /** GetMouseDownState(PRBool *); + * gets the mouse state to aState for resons of drag state. + * @param aState will hold the state of mousedown + */ + NS_IMETHOD GetMouseDownState(PRBool *aState)=0; + }; diff --git a/mozilla/layout/base/src/nsRangeList.cpp b/mozilla/layout/base/src/nsRangeList.cpp index a76c682a9ed..585aec29bde 100644 --- a/mozilla/layout/base/src/nsRangeList.cpp +++ b/mozilla/layout/base/src/nsRangeList.cpp @@ -92,6 +92,9 @@ public: NS_IMETHOD EnableFrameNotification(PRBool aEnable){mNotifyFrames = aEnable; return NS_OK;} NS_IMETHOD LookUpSelection(nsIContent *aContent, PRInt32 aContentOffset, PRInt32 aContentLength, PRInt32 *aStart, PRInt32 *aEnd, PRBool *aDrawSelected , PRUint32 aFlag/*not used*/); + NS_IMETHOD SetMouseDownState(PRBool aState); + NS_IMETHOD GetMouseDownState(PRBool *aState); + /*END nsIFrameSelection interfacse*/ /*BEGIN nsIDOMSelection interface implementations*/ @@ -152,15 +155,15 @@ private: void SetDirty(PRBool aDirty=PR_TRUE){if (mBatching) mChangesDuringBatching = aDirty;} nsresult NotifySelectionListeners(); // add parameters to say collapsed etc? - PRBool GetDirection(){return mDirection;} - void SetDirection(PRBool aDir){mDirection = aDir;} + nsDirection GetDirection(){return mDirection;} + void SetDirection(nsDirection aDir){mDirection = aDir;} NS_IMETHOD selectFrames(nsIDOMRange *aRange, PRBool aSelect); nsCOMPtr mRangeArray; nsCOMPtr mAnchorFocusRange; - PRBool mDirection; //FALSE = focus, anchor; TRUE = anchor,focus + nsDirection mDirection; //FALSE = focus, anchor; TRUE = anchor,focus //batching PRUint32 mBatching; @@ -172,6 +175,7 @@ private: // for nsIScriptContextOwner void* mScriptObject; nsIFocusTracker *mTracker; + PRBool mMouseDownState; //for drag purposes }; class nsRangeListIterator : public nsIBidirectionalEnumerator @@ -395,6 +399,7 @@ nsRangeList::nsRangeList() mChangesDuringBatching = PR_FALSE; mNotifyFrames = PR_TRUE; mScriptObject = nsnull; + mDirection = PR_TRUE; } @@ -476,7 +481,7 @@ NS_METHOD nsRangeList::GetAnchorNode(nsIDOMNode** aAnchorNode) if (!aAnchorNode || !mAnchorFocusRange) return NS_ERROR_NULL_POINTER; nsresult result; - if (mDirection){ + if (GetDirection() == eDirNext){ result = mAnchorFocusRange->GetStartParent(aAnchorNode); } else{ @@ -490,7 +495,7 @@ NS_METHOD nsRangeList::GetAnchorOffset(PRInt32* aAnchorOffset) if (!aAnchorOffset || !mAnchorFocusRange) return NS_ERROR_NULL_POINTER; nsresult result; - if (mDirection){ + if (GetDirection() == eDirNext){ result = mAnchorFocusRange->GetStartOffset(aAnchorOffset); } else{ @@ -505,7 +510,7 @@ NS_METHOD nsRangeList::GetFocusNode(nsIDOMNode** aFocusNode) if (!aFocusNode || !mAnchorFocusRange) return NS_ERROR_NULL_POINTER; nsresult result; - if (mDirection){ + if (GetDirection() == eDirNext){ result = mAnchorFocusRange->GetEndParent(aFocusNode); } else{ @@ -520,7 +525,7 @@ NS_METHOD nsRangeList::GetFocusOffset(PRInt32* aFocusOffset) if (!aFocusOffset || !mAnchorFocusRange) return NS_ERROR_NULL_POINTER; nsresult result; - if (mDirection){ + if (GetDirection() == eDirNext){ result = mAnchorFocusRange->GetEndOffset(aFocusOffset); } else{ @@ -682,6 +687,7 @@ NS_IMETHODIMP nsRangeList::Init(nsIFocusTracker *aTracker) { mTracker = aTracker; + mMouseDownState = PR_FALSE; return NS_OK; } @@ -723,33 +729,14 @@ nsRangeList::HandleKeyEvent(nsGUIEvent *aGuiEvent) if (!aGuiEvent) return NS_ERROR_NULL_POINTER; STATUS_CHECK_RETURN_MACRO(); -return NS_OK; -#if 0 - - nsIFrame *anchor; - nsIFrame *frame; - nsresult result = mTracker->GetFocus(&frame, &anchor); - if (NS_FAILED(result)) - return result; + nsresult result = NS_OK; if (NS_KEY_DOWN == aGuiEvent->message) { - - PRBool selected; - PRInt32 beginoffset = 0; - PRInt32 endoffset; - PRInt32 contentoffset; - nsresult result = NS_OK; - nsKeyEvent *keyEvent = (nsKeyEvent *)aGuiEvent; //this is ok. It really is a keyevent + nsCOMPtr weakNodeUsed; + nsIDOMNode *weakNodeUsed; + PRInt32 offsetused = 0; nsIFrame *resultFrame; - PRInt32 frameOffset; - PRInt32 contentOffset; - PRInt32 offsetused = beginoffset; - nsIFrame *frameused; nsSelectionAmount amount = eSelectCharacter; - result = frame->GetSelected(&selected); - if (NS_FAILED(result)){ - return result; - } if (keyEvent->isControl) amount = eSelectWord; switch (keyEvent->keyCode){ @@ -758,24 +745,25 @@ return NS_OK; #ifdef DEBUG_NAVIGATION printf("debug vk left\n"); #endif - if (keyEvent->isShift || (endoffset < beginoffset)){ //f,a - offsetused = endoffset; - frameused = frame; + if (keyEvent->isShift || (GetDirection() == eDirPrevious)) { //f,a + offsetused = fetchFocusOffset(); + weakNodeUsed = dont_QueryInterface(fetchFocusNode()); } else { - result = anchor->GetSelected(&selected,&beginoffset,&endoffset, &contentoffset); - if (NS_FAILED(result)){ - return result; + offsetused = fetchAnchorOffset(); + weakNodeUsed = dont_QueryInterface(fetchAnchorNode()); + } + if (weakNodeUsed && offsetused >=0){ + nsIFrame *frame; + nsCOMPtr content = do_QueryInterface(node); + result = mTracker->GetPrimaryFrameFor(content, &frame); + if (NS_SUCCEEDED(result) && NS_SUCCEEDED(frame->PeekOffset(amount, eDirPrevious, offsetused, &resultContent, &offsetused, PR_FALSE)) && resultFrame){ + result = TakeFocus(resultContent, offsetused, keyEvent->isShift); } - offsetused = beginoffset; - frameused = anchor; + result = ScrollIntoView(); } - if (NS_SUCCEEDED(frameused->PeekOffset(amount, eDirPrevious, offsetused, &resultFrame, &frameOffset, &contentOffset, PR_FALSE)) && resultFrame){ - result = TakeFocus(resultFrame, frameOffset, contentOffset, keyEvent->isShift); - } - result = ScrollIntoView(); break; - case nsIDOMEvent::VK_RIGHT : +/* case nsIDOMEvent::VK_RIGHT : //we need to look for the next PAINTED location to move the cursor to. #ifdef DEBUG_NAVIGATION printf("debug vk right\n"); @@ -802,11 +790,15 @@ return NS_OK; printf("debug vk up\n"); #endif break; + case nsIDOMEvent::VK_DOWN : +#ifdef DEBUG_NAVIGATION + printf("debug vk down\n"); +#endif + break;*/ default :break; } } return result; -#endif } #ifdef DEBUG @@ -996,6 +988,27 @@ nsRangeList::LookUpSelection(nsIContent *aContent, PRInt32 aContentOffset, PRInt +NS_METHOD +nsRangeList::SetMouseDownState(PRBool aState) +{ + mMouseDownState = aState; + return NS_OK; +} + + + +NS_METHOD +nsRangeList::GetMouseDownState(PRBool *aState) +{ + if (!aState) + return NS_ERROR_NULL_POINTER; + *aState = mMouseDownState; + return NS_OK; +} + + + +//////////END FRAMESELECTION NS_METHOD nsRangeList::AddSelectionListener(nsIDOMSelectionListener* inNewListener) { @@ -1355,7 +1368,7 @@ nsRangeList::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset) res |= difRange->SetStart(FetchFocusNode(), FetchFocusOffset()); if (NS_FAILED(res)) return res; - SetDirection(PR_TRUE); + SetDirection(eDirNext); res = range->SetEnd(aParentNode,aOffset); if (NS_FAILED(res)) return res; @@ -1367,7 +1380,7 @@ nsRangeList::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset) res |= difRange->SetStart(aParentNode, aOffset); if (NS_FAILED(res)) return res; - SetDirection(PR_FALSE); + SetDirection(eDirPrevious); res = range->SetStart(aParentNode,aOffset); if (NS_FAILED(res)) return res; @@ -1380,7 +1393,7 @@ nsRangeList::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset) res |= difRange->SetStart(aParentNode, aOffset); if (NS_FAILED(res)) return res; - SetDirection(PR_TRUE); + SetDirection(eDirNext); res = range->SetEnd(aParentNode,aOffset); if (NS_FAILED(res)) return res; @@ -1402,12 +1415,12 @@ nsRangeList::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset) res |= difRange->SetStart(FetchAnchorNode(), FetchAnchorOffset()); if (NS_FAILED(res)) return res; - if (GetDirection() == PR_FALSE){ + if (GetDirection() == eDirPrevious){ res = range->SetStart(endNode,endOffset); if (NS_FAILED(res)) return res; } - SetDirection(PR_TRUE); + SetDirection(eDirNext); res = range->SetEnd(aParentNode,aOffset); if (NS_FAILED(res)) return res; @@ -1419,7 +1432,7 @@ nsRangeList::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset) res |= difRange->SetStart(FetchFocusNode(), FetchFocusOffset()); if (NS_FAILED(res)) return res; - SetDirection(PR_FALSE); + SetDirection(eDirPrevious); res = range->SetStart(aParentNode,aOffset); if (NS_FAILED(res)) return res; @@ -1439,10 +1452,10 @@ nsRangeList::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset) res |= difRange->SetStart(aParentNode, aOffset); if (NS_FAILED(res)) return res; - if (GetDirection() == PR_TRUE){ + if (GetDirection() == eDirNext){ range->SetEnd(startNode,startOffset); } - SetDirection(PR_FALSE); + SetDirection(eDirPrevious); res = range->SetStart(aParentNode,aOffset); if (NS_FAILED(res)) return res; @@ -1452,7 +1465,7 @@ nsRangeList::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset) //select from 2 to 1 res = difRange->SetEnd(FetchFocusNode(), FetchFocusOffset()); res |= difRange->SetStart(aParentNode, aOffset); - SetDirection(PR_FALSE); + SetDirection(eDirPrevious); res = range->SetStart(aParentNode,aOffset); if (NS_FAILED(res)) return res; @@ -1465,11 +1478,7 @@ nsRangeList::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset) } - // If we get here, the focus wasn't contained in any of the ranges. -#ifdef DEBUG_mjudge - printf("nsRangeList::Extend: focus not contained in any ranges\n"); -#endif - return NS_ERROR_UNEXPECTED; + return NS_OK; } diff --git a/mozilla/layout/events/src/nsEventStateManager.cpp b/mozilla/layout/events/src/nsEventStateManager.cpp index d69c77cade4..7efff0bdfa6 100644 --- a/mozilla/layout/events/src/nsEventStateManager.cpp +++ b/mozilla/layout/events/src/nsEventStateManager.cpp @@ -38,6 +38,8 @@ #include "nsIWebShell.h" #include "nsIFocusableContent.h" #include "nsIScrollableView.h" +#include "nsIDOMSelection.h" +#include "nsIFrameSelection.h" static NS_DEFINE_IID(kIEventStateManagerIID, NS_IEVENTSTATEMANAGER_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); @@ -159,8 +161,22 @@ nsEventStateManager::PostHandleEvent(nsIPresContext& aPresContext, case NS_MOUSE_LEFT_BUTTON_UP: case NS_MOUSE_MIDDLE_BUTTON_UP: case NS_MOUSE_RIGHT_BUTTON_UP: - ret = CheckForAndDispatchClick(aPresContext, (nsMouseEvent*)aEvent, aStatus); - SetContentState(nsnull, NS_EVENT_STATE_ACTIVE); + { + ret = CheckForAndDispatchClick(aPresContext, (nsMouseEvent*)aEvent, aStatus); + SetContentState(nsnull, NS_EVENT_STATE_ACTIVE); + nsCOMPtr shell; + nsresult rv = aPresContext.GetShell(getter_AddRefs(shell)); + if (NS_SUCCEEDED(rv) && shell){ + nsCOMPtr selection; + rv = shell->GetSelection(getter_AddRefs(selection)); + if (NS_SUCCEEDED(rv) && selection){ + nsCOMPtr frameSel; + frameSel = do_QueryInterface(selection); + if (frameSel) + frameSel->SetMouseDownState(PR_FALSE); + } + } + } break; case NS_KEY_DOWN: ret = DispatchKeyPressEvent(aPresContext, (nsKeyEvent*)aEvent, aStatus); diff --git a/mozilla/layout/forms/nsComboboxControlFrame.cpp b/mozilla/layout/forms/nsComboboxControlFrame.cpp index 1a8f5d8e416..338c2f37a5c 100644 --- a/mozilla/layout/forms/nsComboboxControlFrame.cpp +++ b/mozilla/layout/forms/nsComboboxControlFrame.cpp @@ -722,30 +722,18 @@ NS_IMETHODIMP nsComboboxControlFrame::HandleEvent(nsIPresContext& aPresContext, if (nsEventStatus_eConsumeNoDefault == aEventStatus) { return NS_OK; - } - if(nsEventStatus_eConsumeNoDefault != aEventStatus) { - if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) { - } else if (aEvent->message == NS_MOUSE_MOVE && mDoingSelection || - aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) { - // no-op - } else { - return NS_OK; - } + aEventStatus = nsEventStatus_eConsumeNoDefault; - aEventStatus = nsEventStatus_eConsumeNoDefault; - - if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) { - mArrowStyle = mBtnOutStyleContext; - nsFormControlHelper::ForceDrawFrame(this); - } else if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) { - mArrowStyle = mBtnPressedStyleContext; - nsFormControlHelper::ForceDrawFrame(this); - MouseClicked(&aPresContext); - } + if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) { + mArrowStyle = mBtnOutStyleContext; + nsFormControlHelper::ForceDrawFrame(this); + } else if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) { + mArrowStyle = mBtnPressedStyleContext; + nsFormControlHelper::ForceDrawFrame(this); + MouseClicked(&aPresContext); } - return NS_OK; } diff --git a/mozilla/layout/generic/nsFrame.cpp b/mozilla/layout/generic/nsFrame.cpp index c9586806280..ac610311e60 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -72,7 +72,6 @@ PRInt32 fTrackerRemoveListMax = 0; nsIContent * fTrackerContentArrayAddList[1024]; PRInt32 fTrackerAddListMax = 0; -nsIDocument *gDoc = nsnull; // [HACK] Foward Declarations void ForceDrawFrame(nsFrame * aFrame); @@ -80,8 +79,6 @@ void ForceDrawFrame(nsFrame * aFrame); static void RefreshContentFrames(nsIPresContext& aPresContext, nsIContent * aStartContent, nsIContent * aEndContent); #endif -PRBool nsFrame::mDoingSelection = PR_FALSE; -PRBool nsFrame::mDidDrag = PR_FALSE; //---------------------------------------------------------------------- @@ -728,36 +725,32 @@ nsFrame::HandleEvent(nsIPresContext& aPresContext, return NS_OK; } +/*i have no idea why this is here keeping incase.. if (DisplaySelection(aPresContext) == PR_FALSE) { if (aEvent->message != NS_MOUSE_LEFT_BUTTON_DOWN) { return NS_OK; } } - - if(nsEventStatus_eConsumeNoDefault != aEventStatus) { - if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) { - } - else if (aEvent->message == NS_MOUSE_MOVE && mDoingSelection || - aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) { - // no-op - } - else { - return NS_OK; - } - if (SELECTION_DEBUG) printf("Message: %d-------------------------------------------------------------\n",aEvent->message); - - - if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) { - if (mDoingSelection) { - HandleRelease(aPresContext, aEvent, aEventStatus); +*/ + if (aEvent->message == NS_MOUSE_MOVE) { + nsCOMPtr shell; + nsresult rv = aPresContext.GetShell(getter_AddRefs(shell)); + if (NS_SUCCEEDED(rv)){ + nsCOMPtr selection; + if (NS_SUCCEEDED(shell->GetSelection(getter_AddRefs(selection)))){ + nsCOMPtr frameselection; + frameselection = do_QueryInterface(selection); + if (frameselection) { + PRBool mouseDown = PR_FALSE; + if (NS_SUCCEEDED(frameselection->GetMouseDownState(&mouseDown)) && mouseDown){ + HandleDrag(aPresContext, aEvent, aEventStatus); + } + } } - } else if (aEvent->message == NS_MOUSE_MOVE) { - mDidDrag = PR_TRUE; - HandleDrag(aPresContext, aEvent, aEventStatus); -//DEBUG MJUDGE DEBUG MESSAGE FOR DRAGGING FROM SELECTION - } else if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) { - HandlePress(aPresContext, aEvent, aEventStatus); } + } + else if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) { + HandlePress(aPresContext, aEvent, aEventStatus); } return NS_OK; @@ -775,8 +768,6 @@ nsFrame::HandlePress(nsIPresContext& aPresContext, return NS_OK; } - mDoingSelection = PR_TRUE; - mDidDrag = PR_FALSE; nsCOMPtr shell; nsresult rv = aPresContext.GetShell(getter_AddRefs(shell)); nsInputEvent *inputEvent = (nsInputEvent *)aEvent; @@ -787,20 +778,18 @@ nsFrame::HandlePress(nsIPresContext& aPresContext, PRInt32 startPos = 0; PRUint32 contentOffset = 0; if (NS_SUCCEEDED(GetPosition(aPresContext, acx, aEvent, this, contentOffset, startPos))){ - nsIDOMSelection *selection = nsnull; - if (NS_SUCCEEDED(shell->GetSelection(&selection))){ - nsIFrameSelection *frameselection = nsnull; - if (NS_SUCCEEDED(selection->QueryInterface(kIFrameSelection, (void **)&frameselection))) { + nsCOMPtr selection; + if (NS_SUCCEEDED(shell->GetSelection(getter_AddRefs(selection)))){ + nsCOMPtr frameselection; + frameselection = do_QueryInterface(selection); + if (frameselection) { nsCOMPtr content; rv = GetContent(getter_AddRefs(content)); if (NS_SUCCEEDED( rv )){ - frameselection->EnableFrameNotification(PR_FALSE); + frameselection->SetMouseDownState(PR_TRUE);//not important if it fails here frameselection->TakeFocus(content, startPos + contentOffset, inputEvent->isShift); - frameselection->EnableFrameNotification(PR_TRUE);//prevent cyclic call to reset selection. } - NS_RELEASE(frameselection); } - NS_RELEASE(selection); } //no release } @@ -818,8 +807,6 @@ NS_IMETHODIMP nsFrame::HandleDrag(nsIPresContext& aPresContext, return NS_OK; } - mDoingSelection = PR_TRUE; - mDidDrag = PR_FALSE; nsCOMPtr shell; nsresult rv = aPresContext.GetShell(getter_AddRefs(shell)); if (NS_SUCCEEDED(rv) && shell) { @@ -836,9 +823,7 @@ NS_IMETHODIMP nsFrame::HandleDrag(nsIPresContext& aPresContext, nsCOMPtr content; rv = GetContent(getter_AddRefs(content)); if (NS_SUCCEEDED( rv )){ - frameselection->EnableFrameNotification(PR_FALSE); frameselection->TakeFocus(content, startPos + contentOffset, PR_TRUE); //TRUE IS THE DIFFERENCE - frameselection->EnableFrameNotification(PR_TRUE);//prevent cyclic call to reset selection. } NS_RELEASE(frameselection); } @@ -855,8 +840,6 @@ NS_IMETHODIMP nsFrame::HandleRelease(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsEventStatus& aEventStatus) { - mDoingSelection = PR_FALSE; - NS_IF_RELEASE(gDoc); return NS_OK; } @@ -1609,9 +1592,9 @@ nsFrame::GetChildFrameContainingOffset(PRInt32 inContentOffset, PRInt32* outFram } NS_IMETHODIMP -nsFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, - nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset, - PRBool aEatingWS) const +nsFrame::PeekOffsetPeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, + PRInt32 aStartOffset, nsIContent **aResultContent, + PRInt32 *aResultOffset, PRBool aEatingWS) const { /* //this will use the nsFrameTraversal as the default peek method. //this should change to use geometry and also look to ALL the child lists diff --git a/mozilla/layout/generic/nsFrame.h b/mozilla/layout/generic/nsFrame.h index ba6c6ccc557..e05bcf94e99 100644 --- a/mozilla/layout/generic/nsFrame.h +++ b/mozilla/layout/generic/nsFrame.h @@ -210,9 +210,8 @@ public: NS_IMETHOD VerifyTree() const; NS_IMETHOD SetSelected(nsIDOMRange *aRange,PRBool aSelected, PRBool aSpread); NS_IMETHOD GetSelected(PRBool *aSelected) const; - NS_IMETHOD PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, - nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset, - PRBool aEatingWS)const; + NS_IMETHOD PeekOffsetPeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, + nsIContent **aResultContent, PRInt32 *aResultOffset, PRBool aEatingWS) const; NS_IMETHOD GetOffsets(PRInt32 &aStart, PRInt32 &aEnd) const; @@ -350,12 +349,6 @@ protected: nsIFrame* mNextSibling; // singly linked list of frames nsFrameState mState; - /////////////////////////////////// - // Important Selection Variables - /////////////////////////////////// - static PRBool mDoingSelection; - static PRBool mDidDrag; - static PRInt32 mStartPos; // Selection data is valid only from the Mouse Press to the Mouse Release /////////////////////////////////// diff --git a/mozilla/layout/generic/nsIFrame.h b/mozilla/layout/generic/nsIFrame.h index a4c88dda639..ab57cabc4a4 100644 --- a/mozilla/layout/generic/nsIFrame.h +++ b/mozilla/layout/generic/nsIFrame.h @@ -590,6 +590,9 @@ public: NS_IMETHOD GetSelected(PRBool *aSelected) const = 0; + /** EndSelection related calls + */ + /** * called to find the previous/next character, word, or line returns the actual * nsIFrame and the frame offset. THIS DOES NOT CHANGE SELECTION STATE @@ -598,13 +601,12 @@ public: * @param aAmount eWord, eCharacter, eLine * @param aDirection enum defined in this file to be eForward or eBackward * @param aStartOffset start offset to start the peek. 0 == beginning -1 = end - * @param aResultFrame frame that actually is the next/previous - * @param aFrameOffset offset from frame of the frame results - * @param aContentOffset offset from content of the frame results + * @param aResultContent content that actually is the next/previous + * @param aResultOffset offset for result content * @param aEatingWS boolean to tell us the state of our search for Next/Prev */ NS_IMETHOD PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, - nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset, PRBool aEatingWS) const = 0; + nsIContent **aResultContent, PRInt32 *aResultOffset, PRBool aEatingWS) const = 0; /** * See if tree verification is enabled. To enable tree verification add diff --git a/mozilla/layout/html/base/src/nsFrame.cpp b/mozilla/layout/html/base/src/nsFrame.cpp index c9586806280..ac610311e60 100644 --- a/mozilla/layout/html/base/src/nsFrame.cpp +++ b/mozilla/layout/html/base/src/nsFrame.cpp @@ -72,7 +72,6 @@ PRInt32 fTrackerRemoveListMax = 0; nsIContent * fTrackerContentArrayAddList[1024]; PRInt32 fTrackerAddListMax = 0; -nsIDocument *gDoc = nsnull; // [HACK] Foward Declarations void ForceDrawFrame(nsFrame * aFrame); @@ -80,8 +79,6 @@ void ForceDrawFrame(nsFrame * aFrame); static void RefreshContentFrames(nsIPresContext& aPresContext, nsIContent * aStartContent, nsIContent * aEndContent); #endif -PRBool nsFrame::mDoingSelection = PR_FALSE; -PRBool nsFrame::mDidDrag = PR_FALSE; //---------------------------------------------------------------------- @@ -728,36 +725,32 @@ nsFrame::HandleEvent(nsIPresContext& aPresContext, return NS_OK; } +/*i have no idea why this is here keeping incase.. if (DisplaySelection(aPresContext) == PR_FALSE) { if (aEvent->message != NS_MOUSE_LEFT_BUTTON_DOWN) { return NS_OK; } } - - if(nsEventStatus_eConsumeNoDefault != aEventStatus) { - if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) { - } - else if (aEvent->message == NS_MOUSE_MOVE && mDoingSelection || - aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) { - // no-op - } - else { - return NS_OK; - } - if (SELECTION_DEBUG) printf("Message: %d-------------------------------------------------------------\n",aEvent->message); - - - if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) { - if (mDoingSelection) { - HandleRelease(aPresContext, aEvent, aEventStatus); +*/ + if (aEvent->message == NS_MOUSE_MOVE) { + nsCOMPtr shell; + nsresult rv = aPresContext.GetShell(getter_AddRefs(shell)); + if (NS_SUCCEEDED(rv)){ + nsCOMPtr selection; + if (NS_SUCCEEDED(shell->GetSelection(getter_AddRefs(selection)))){ + nsCOMPtr frameselection; + frameselection = do_QueryInterface(selection); + if (frameselection) { + PRBool mouseDown = PR_FALSE; + if (NS_SUCCEEDED(frameselection->GetMouseDownState(&mouseDown)) && mouseDown){ + HandleDrag(aPresContext, aEvent, aEventStatus); + } + } } - } else if (aEvent->message == NS_MOUSE_MOVE) { - mDidDrag = PR_TRUE; - HandleDrag(aPresContext, aEvent, aEventStatus); -//DEBUG MJUDGE DEBUG MESSAGE FOR DRAGGING FROM SELECTION - } else if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) { - HandlePress(aPresContext, aEvent, aEventStatus); } + } + else if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) { + HandlePress(aPresContext, aEvent, aEventStatus); } return NS_OK; @@ -775,8 +768,6 @@ nsFrame::HandlePress(nsIPresContext& aPresContext, return NS_OK; } - mDoingSelection = PR_TRUE; - mDidDrag = PR_FALSE; nsCOMPtr shell; nsresult rv = aPresContext.GetShell(getter_AddRefs(shell)); nsInputEvent *inputEvent = (nsInputEvent *)aEvent; @@ -787,20 +778,18 @@ nsFrame::HandlePress(nsIPresContext& aPresContext, PRInt32 startPos = 0; PRUint32 contentOffset = 0; if (NS_SUCCEEDED(GetPosition(aPresContext, acx, aEvent, this, contentOffset, startPos))){ - nsIDOMSelection *selection = nsnull; - if (NS_SUCCEEDED(shell->GetSelection(&selection))){ - nsIFrameSelection *frameselection = nsnull; - if (NS_SUCCEEDED(selection->QueryInterface(kIFrameSelection, (void **)&frameselection))) { + nsCOMPtr selection; + if (NS_SUCCEEDED(shell->GetSelection(getter_AddRefs(selection)))){ + nsCOMPtr frameselection; + frameselection = do_QueryInterface(selection); + if (frameselection) { nsCOMPtr content; rv = GetContent(getter_AddRefs(content)); if (NS_SUCCEEDED( rv )){ - frameselection->EnableFrameNotification(PR_FALSE); + frameselection->SetMouseDownState(PR_TRUE);//not important if it fails here frameselection->TakeFocus(content, startPos + contentOffset, inputEvent->isShift); - frameselection->EnableFrameNotification(PR_TRUE);//prevent cyclic call to reset selection. } - NS_RELEASE(frameselection); } - NS_RELEASE(selection); } //no release } @@ -818,8 +807,6 @@ NS_IMETHODIMP nsFrame::HandleDrag(nsIPresContext& aPresContext, return NS_OK; } - mDoingSelection = PR_TRUE; - mDidDrag = PR_FALSE; nsCOMPtr shell; nsresult rv = aPresContext.GetShell(getter_AddRefs(shell)); if (NS_SUCCEEDED(rv) && shell) { @@ -836,9 +823,7 @@ NS_IMETHODIMP nsFrame::HandleDrag(nsIPresContext& aPresContext, nsCOMPtr content; rv = GetContent(getter_AddRefs(content)); if (NS_SUCCEEDED( rv )){ - frameselection->EnableFrameNotification(PR_FALSE); frameselection->TakeFocus(content, startPos + contentOffset, PR_TRUE); //TRUE IS THE DIFFERENCE - frameselection->EnableFrameNotification(PR_TRUE);//prevent cyclic call to reset selection. } NS_RELEASE(frameselection); } @@ -855,8 +840,6 @@ NS_IMETHODIMP nsFrame::HandleRelease(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsEventStatus& aEventStatus) { - mDoingSelection = PR_FALSE; - NS_IF_RELEASE(gDoc); return NS_OK; } @@ -1609,9 +1592,9 @@ nsFrame::GetChildFrameContainingOffset(PRInt32 inContentOffset, PRInt32* outFram } NS_IMETHODIMP -nsFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, - nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset, - PRBool aEatingWS) const +nsFrame::PeekOffsetPeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, + PRInt32 aStartOffset, nsIContent **aResultContent, + PRInt32 *aResultOffset, PRBool aEatingWS) const { /* //this will use the nsFrameTraversal as the default peek method. //this should change to use geometry and also look to ALL the child lists diff --git a/mozilla/layout/html/base/src/nsFrame.h b/mozilla/layout/html/base/src/nsFrame.h index ba6c6ccc557..e05bcf94e99 100644 --- a/mozilla/layout/html/base/src/nsFrame.h +++ b/mozilla/layout/html/base/src/nsFrame.h @@ -210,9 +210,8 @@ public: NS_IMETHOD VerifyTree() const; NS_IMETHOD SetSelected(nsIDOMRange *aRange,PRBool aSelected, PRBool aSpread); NS_IMETHOD GetSelected(PRBool *aSelected) const; - NS_IMETHOD PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, - nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset, - PRBool aEatingWS)const; + NS_IMETHOD PeekOffsetPeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, + nsIContent **aResultContent, PRInt32 *aResultOffset, PRBool aEatingWS) const; NS_IMETHOD GetOffsets(PRInt32 &aStart, PRInt32 &aEnd) const; @@ -350,12 +349,6 @@ protected: nsIFrame* mNextSibling; // singly linked list of frames nsFrameState mState; - /////////////////////////////////// - // Important Selection Variables - /////////////////////////////////// - static PRBool mDoingSelection; - static PRBool mDidDrag; - static PRInt32 mStartPos; // Selection data is valid only from the Mouse Press to the Mouse Release /////////////////////////////////// diff --git a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp index 1a8f5d8e416..338c2f37a5c 100644 --- a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp @@ -722,30 +722,18 @@ NS_IMETHODIMP nsComboboxControlFrame::HandleEvent(nsIPresContext& aPresContext, if (nsEventStatus_eConsumeNoDefault == aEventStatus) { return NS_OK; - } - if(nsEventStatus_eConsumeNoDefault != aEventStatus) { - if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) { - } else if (aEvent->message == NS_MOUSE_MOVE && mDoingSelection || - aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) { - // no-op - } else { - return NS_OK; - } + aEventStatus = nsEventStatus_eConsumeNoDefault; - aEventStatus = nsEventStatus_eConsumeNoDefault; - - if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) { - mArrowStyle = mBtnOutStyleContext; - nsFormControlHelper::ForceDrawFrame(this); - } else if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) { - mArrowStyle = mBtnPressedStyleContext; - nsFormControlHelper::ForceDrawFrame(this); - MouseClicked(&aPresContext); - } + if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) { + mArrowStyle = mBtnOutStyleContext; + nsFormControlHelper::ForceDrawFrame(this); + } else if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) { + mArrowStyle = mBtnPressedStyleContext; + nsFormControlHelper::ForceDrawFrame(this); + MouseClicked(&aPresContext); } - return NS_OK; }