diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp index 049a400328f4..95d895590686 100644 --- a/layout/generic/nsFrame.cpp +++ b/layout/generic/nsFrame.cpp @@ -730,182 +730,6 @@ nsFrame::HandlePress(nsIPresContext& aPresContext, } } } - -#if 0 -//DEBUG MJUDGE - nsFrame * currentFrame = this; - nsIPresShell * shell = aPresContext.GetShell(); - nsMouseEvent * mouseEvent = (nsMouseEvent *)aEvent; - nsIRenderingContext * acx; - - gDoc = shell->GetDocument(); - - nsISelection * selection; - gDoc->GetSelection(selection); - - shell->CreateRenderingContext(this, acx); - - mSelectionRange = selection->GetRange(); - - PRUint32 actualOffset = 0; - - mDoingSelection = PR_TRUE; - mDidDrag = PR_FALSE; - mCurrentFrame = currentFrame; - - GetPosition(aPresContext, acx, aEvent, currentFrame, actualOffset, mStartPos); - - // Click count is 1 - nsIContent * newContent; - currentFrame->GetContent(newContent); - - mCurrentFrame = currentFrame; - - if (mStartSelectionPoint == nsnull) { - mStartSelectionPoint = new nsSelectionPoint(nsnull, -1, PR_TRUE); - } - if (mEndSelectionPoint == nsnull) { - mEndSelectionPoint = new nsSelectionPoint(nsnull, -1, PR_TRUE); - } - - mSelectionRange->GetStartPoint(mStartSelectionPoint); - mSelectionRange->GetEndPoint(mEndSelectionPoint); - - resetContentTrackers(); - - // Get the Current Start and End Content Pointers - nsIContent * selStartContent = mSelectionRange->GetStartContent(); // ref counted - nsIContent * selEndContent = mSelectionRange->GetEndContent(); // ref counted - - if (SELECTION_DEBUG) printf("****** Shift[%s]\n", (mouseEvent->isShift?"Down":"Up")); - - PRBool inRange = gDoc->IsInRange(selStartContent, selEndContent, newContent); - - if (inRange) { - //resetContentTrackers(); - if (TRACKER_DEBUG) printf("Adding split range to removed selection. Shift[%s]\n", (mouseEvent->isShift?"Down":"Up")); - - if (mouseEvent->isShift) { - if (newContent == selStartContent && newContent == selEndContent) { - addRangeToSelectionTrackers(newContent, newContent, kInsertInAddList); - } else { - if (selStartContent == newContent) { - // Trackers just do painting so add all the content nodes in the remove list - // even though you might think you shouldn't put the start content node there - addRangeToSelectionTrackers(selStartContent, selEndContent, kInsertInRemoveList); - } else if (selEndContent == newContent) { - // just repaint the end content node - addRangeToSelectionTrackers(selEndContent, selEndContent, kInsertInAddList); - } else { - if (gDoc->IsBefore(newContent, selEndContent)) { - addRangeToSelectionTrackers(newContent, selEndContent, kInsertInRemoveList); - } else { - addRangeToSelectionTrackers(selEndContent, newContent, kInsertInRemoveList); - } - } - } - mEndSelectionPoint->SetPoint(newContent, mStartPos, PR_FALSE); - } else { - addRangeToSelectionTrackers(selStartContent, selEndContent, kInsertInRemoveList); // removed from selection - - mStartSelectionPoint->SetPoint(newContent, mStartPos, PR_TRUE); - mEndSelectionPoint->SetPoint(newContent, mStartPos, PR_TRUE); - - addRangeToSelectionTrackers(newContent, newContent, kInsertInAddList); // add to selection - } - - } else if (gDoc->IsBefore(newContent, selStartContent)) { - if (mouseEvent->isShift) { - if (mStartSelectionPoint->IsAnchor()) { - if (SELECTION_DEBUG) printf("New Content is before, Start will now be end\n"); - - addRangeToSelectionTrackers(selStartContent, selEndContent, kInsertInRemoveList); // removed from selection - - mEndSelectionPoint->SetPoint(selStartContent, mStartSelectionPoint->GetOffset(), PR_TRUE); - mStartSelectionPoint->SetPoint(newContent, mStartPos, PR_FALSE); - - // End Point has changed - nsIContent * endcontent = mEndSelectionPoint->GetContent(); // ref counted - addRangeToSelectionTrackers(newContent, endcontent, kInsertInAddList); // add to selection - NS_RELEASE(endcontent); - } else { - if (SELECTION_DEBUG) printf("New Content is before, Appending to Beginning\n"); - addRangeToSelectionTrackers(newContent, selEndContent, kInsertInAddList); // add to selection - mStartSelectionPoint->SetPoint(newContent, mStartPos, PR_FALSE); - } - } else { - if (SELECTION_DEBUG) printf("Adding full range to removed selection. (insert selection)\n"); - addRangeToSelectionTrackers(selStartContent, selEndContent, kInsertInRemoveList); // removed from selection - - mEndSelectionPoint->SetPoint(newContent, mStartPos, PR_TRUE); - - mStartSelectionPoint->SetPoint(newContent, mStartPos, PR_TRUE); - - addRangeToSelectionTrackers(newContent, newContent, kInsertInAddList); // add to selection - } - } else { // Content is After End - - if (mouseEvent->isShift) { - if (selStartContent == nsnull && selEndContent == nsnull) { - // Shift Click without first clicking in the window - // is interpreted the same as just clicking in a window - mEndSelectionPoint->SetPoint(newContent, mStartPos, PR_TRUE); - mStartSelectionPoint->SetPoint(newContent, mStartPos, PR_TRUE); - addRangeToSelectionTrackers(newContent, newContent, kInsertInAddList); // add to selection - - } else if (mStartSelectionPoint->IsAnchor()) { - if (SELECTION_DEBUG) printf("New Content is after, Append new content\n"); - addRangeToSelectionTrackers(selEndContent, newContent, kInsertInAddList); // add to selection - mEndSelectionPoint->SetPoint(newContent, mStartPos, PR_FALSE); - - } else { - if (SELECTION_DEBUG) printf("New Content is after, End will now be Start\n"); - - addRangeToSelectionTrackers(selStartContent, selEndContent, kInsertInRemoveList); // removed from selection - mStartSelectionPoint->SetPoint(selEndContent, mEndSelectionPoint->GetOffset(), PR_TRUE); - mEndSelectionPoint->SetPoint(newContent, mStartPos, PR_FALSE); - addRangeToSelectionTrackers(newContent, newContent, kInsertInAddList); // add to selection - } - - } else { - if (TRACKER_DEBUG) printf("Adding full range to removed selection.\n"); - addRangeToSelectionTrackers(selStartContent, selEndContent, kInsertInRemoveList); // removed from selection - - mEndSelectionPoint->SetPoint(newContent, mStartPos, PR_TRUE); - - mStartSelectionPoint->SetPoint(newContent, mStartPos, PR_TRUE); - - addRangeToSelectionTrackers(newContent, newContent, kInsertInAddList); // add to selection - } - } - - - mSelectionRange->SetStartPoint(mStartSelectionPoint); - mSelectionRange->SetEndPoint(mEndSelectionPoint); - - //if (selStartContent) printf("selStartContent count %d\n", selStartContent->Release()); - //if (selEndContent) printf("selEndContent count %d\n", selEndContent->Release()); - //if (newContent) printf("newContent count %d\n", newContent->Release()); - - NS_IF_RELEASE(selStartContent); - NS_IF_RELEASE(selEndContent); - NS_IF_RELEASE(newContent); - - RefreshFromContentTrackers(aPresContext); - - - if (SELECTION_DEBUG) printf("HandleEvent::mSelectionRange %s\n", mSelectionRange->ToString()); - - NS_IF_RELEASE(acx); - - // Force Update - ForceDrawFrame(this); - - NS_RELEASE(shell); - NS_RELEASE(selection); - - aEventStatus = nsEventStatus_eIgnore; -#endif //0 return NS_OK; } @@ -947,126 +771,6 @@ NS_IMETHODIMP nsFrame::HandleDrag(nsIPresContext& aPresContext, } } } -#if 0 -//DEBUG MJUDGE - if (DisplaySelection(aPresContext) == PR_FALSE) - { - aEventStatus = nsEventStatus_eIgnore; - return NS_OK; - } - - // Keep old start and end - nsIContent * startContent = mSelectionRange->GetStartContent(); // ref counted - nsIContent * endContent = mSelectionRange->GetEndContent(); // ref counted - - mDidDrag = PR_TRUE; - - nsIPresShell *ps = aPresContext.GetShell(); - nsIRenderingContext *acx; - - ps->CreateRenderingContext(this, acx); - NS_RELEASE(ps); - - //if (aFrame != nsnull) { - //printf("nsFrame::HandleDrag\n"); - - // Check to see if we have changed frame - if (this != mCurrentFrame) { - // We are in a new Frame! - if (SELECTION_DEBUG) printf("HandleDrag::Different Frame in selection!\n"); - - // Get Content for current Frame - nsIContent * currentContent; - mCurrentFrame->GetContent(currentContent); - - // Get Content for New Frame - nsIContent * newContent; - this->GetContent(newContent); - - // Check to see if we are still in the same Content - if (currentContent == newContent) { - if (SELECTION_DEBUG) printf("HandleDrag::New Frame, same content.\n"); - - AdjustPointsInSameContent(aPresContext, acx, aEvent); - addRangeToSelectionTrackers(currentContent, currentContent, kInsertInAddList); - - } else if (gDoc->IsBefore(newContent, currentContent)) { - if (SELECTION_DEBUG) printf("HandleDrag::New Frame, is Before.\n"); - - resetContentTrackers(); - NewContentIsBefore(aPresContext, acx, aEvent, newContent, currentContent, this); - - } else { // Content is AFTER - if (SELECTION_DEBUG) printf("HandleDrag::New Frame, is After.\n"); - - resetContentTrackers(); - NewContentIsAfter(aPresContext, acx, aEvent, newContent, currentContent, this); - } - mCurrentFrame = this; - - NS_IF_RELEASE(currentContent); - NS_IF_RELEASE(newContent); - } else if ((nsnull != mStartSelectionPoint) && (nsnull != mEndSelectionPoint)) { - if (SELECTION_DEBUG) printf("HandleDrag::Same Frame.\n"); - - // Same Frame as before - //if (SELECTION_DEBUG) printf("\nSame Start: %s\n", mStartSelectionPoint->ToString()); - //if (SELECTION_DEBUG) printf("Same End: %s\n", mEndSelectionPoint->ToString()); - // [TODO] Uncomment these soon - - nsIContent * selStartContent = mStartSelectionPoint->GetContent(); - nsIContent * selEndContent = mEndSelectionPoint->GetContent(); - - if (selStartContent == selEndContent) { - if (SELECTION_DEBUG) printf("Start & End Frame are the same: \n"); - AdjustPointsInSameContent(aPresContext, acx, aEvent); - } else { - if (SELECTION_DEBUG) printf("Start & End Frame are different: \n"); - - // Get Content for New Frame - nsIContent * newContent; - this->GetContent(newContent); - PRInt32 newPos = -1; - PRUint32 actualOffset = 0; - - GetPosition(aPresContext, acx, aEvent, this, actualOffset, newPos); - - if (newContent == selStartContent) { - if (SELECTION_DEBUG) printf("New Content equals Start Content\n"); - mStartSelectionPoint->SetOffset(newPos); - mSelectionRange->SetStartPoint(mStartSelectionPoint); - } else if (newContent == selEndContent) { - if (SELECTION_DEBUG) printf("New Content equals End Content\n"); - mEndSelectionPoint->SetOffset(newPos); - mSelectionRange->SetEndPoint(mEndSelectionPoint); - } else { - if (SELECTION_DEBUG) printf("=====\n=====\n=====\n=====\n=====\n=====\n Should NOT be here.\n"); - } - - //if (SELECTION_DEBUG) printf("*Same Start: "+mStartSelectionPoint->GetOffset()+ - // " "+mStartSelectionPoint->IsAnchor()+ - // " End: "+mEndSelectionPoint->GetOffset() + - // " "+mEndSelectionPoint->IsAnchor()); - NS_IF_RELEASE(newContent); - } - NS_IF_RELEASE(selStartContent); - NS_IF_RELEASE(selEndContent); - } - //} - - - NS_IF_RELEASE(startContent); - NS_IF_RELEASE(endContent); - - NS_IF_RELEASE(acx); - - // Force Update - ForceDrawFrame(this); - //RefreshContentFrames(aPresContext, startContent, endContent); - RefreshFromContentTrackers(aPresContext); - - aEventStatus = nsEventStatus_eIgnore; -#endif //0 return NS_OK; } @@ -1813,13 +1517,19 @@ nsFrame::VerifyTree() const return NS_OK; } +/*this method may.. invalidate if the state was changed or if aForceRedraw is PR_TRUE + it will not update immediately.*/ NS_IMETHODIMP nsFrame::SetSelected(PRBool aSelected, PRInt32 aBeginOffset, PRInt32 aEndOffset, PRBool aForceRedraw) { if (mSelected != aSelected || aForceRedraw) { mSelected = aSelected; - ForceDrawFrame(this); + + nsRect rect; + GetRect(rect); + ForceDrawFrame(this);//invalidate does not work in all cases. + //Invalidate(rect,PR_FALSE); //false is for not immediate } return NS_OK; } @@ -1915,88 +1625,6 @@ nsFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 a //----------------------------------------------------------------------------------- -/******************************************************** -* Handles a when the cursor enters new content that is before -* the content that the cursor is currently in -*********************************************************/ -void nsFrame::NewContentIsBefore(nsIPresContext& aPresContext, - nsIRenderingContext * aRendContext, - nsGUIEvent * aEvent, - nsIContent * aNewContent, - nsIContent * aCurrentContent, - nsIFrame * aNewFrame) -{ -#if 0 -//DEBUG MJUDGE - if (SELECTION_DEBUG) printf("New Frame, New content is before.\n"); - // Dragging mouse to the left or backward in content - // - // 1) The cursor is being dragged backward in the content - // and the mouse is "after" the anchor in the content - // and the current piece of content is being removed from the selection - // - // This section cover two cases: - // 2) The cursor is being dragged backward in the content - // and the mouse is "before" the anchor in the content - // and each new piece of content is being added to the selection - - if ((nsnull == mStartSelectionPoint) || (nsnull == mEndSelectionPoint)) { - return; - } - nsIPresShell * shell = aPresContext.GetShell(); - nsIDocument * doc = shell->GetDocument(); - nsIContent * selStartContent = mStartSelectionPoint->GetContent(); - nsIContent * selEndContent = mEndSelectionPoint->GetContent(); - - PRBool inRange = doc->IsInRange(selStartContent, selEndContent, aNewContent); - - // Check to see if the new content is in the selection - if (inRange) { - - // Case #1 - Remove Current Content from Selection (at End) - if (SELECTION_DEBUG) printf("Case #1 - (Before) New Content is in selected Range.\n"); - - - if (aNewContent == selStartContent) { - // [TODO] This is where we might have to delete from end to new content - - // Returns the new End Point, if Start and End are on the - // same content then End Point's Cursor is set to Start's - mEndSelectionPoint->SetContent(selStartContent); - AdjustPointsInNewContent(aPresContext, aRendContext, aEvent, aNewFrame); - - } else { - PRUint32 actualOffset = 0; - PRInt32 newPos; - GetPosition(aPresContext, aRendContext, aEvent, aNewFrame, actualOffset, newPos); - mEndSelectionPoint->SetPoint(aNewContent, newPos, PR_FALSE); - mSelectionRange->SetEndPoint(mEndSelectionPoint); - } - - // The current content is being removed from Selection - addRangeToSelectionTrackers(aNewContent, aCurrentContent, kInsertInRemoveList); - } else { - // Case #2 - Add new content to selection (At Start) - if (SELECTION_DEBUG) printf("Case #2 - (Before) New Content is NOT in selected Range. Moving Start Backward.\n"); - - PRUint32 actualOffset = 0; - PRInt32 newPos; - - GetPosition(aPresContext, aRendContext, aEvent, aNewFrame, actualOffset, newPos); - - // Create new TextPoint and move Start Point backward - mStartSelectionPoint->SetPoint(aNewContent, newPos, PR_FALSE); // position is set correctly in adjustTextPoints - mSelectionRange->SetStartPoint(mStartSelectionPoint); - - // The New Content is added to Tracker - addRangeToSelectionTrackers(aNewContent, aCurrentContent, kInsertInAddList); - } - NS_RELEASE(selStartContent); - NS_RELEASE(selEndContent); - NS_RELEASE(doc); - NS_RELEASE(shell); -#endif //0 -} /******************************************************** * Refreshes each content's frame @@ -2058,139 +1686,6 @@ static void RefreshContentFrames(nsIPresContext& aPresContext, } #endif -/******************************************************** -* Handles a when the cursor enters new content that is After -* the content that the cursor is currently in -*********************************************************/ -void nsFrame::NewContentIsAfter(nsIPresContext& aPresContext, - nsIRenderingContext * aRendContext, - nsGUIEvent * aEvent, - nsIContent * aNewContent, - nsIContent * aCurrentContent, - nsIFrame * aNewFrame) -{ -#if 0 -//DEBUG MJUDGE - - if (SELECTION_DEBUG) printf("New Frame, New content is after.\n"); - - - // Dragging Mouse to the Right - // - // 3) The cursor is being dragged foward in the content - // and the mouse is "before" the anchor in the content - // and the current piece of content is being removed from the selection - // - // This section cover two cases: - // 4) The cursor is being dragged foward in the content - // and the mouse is "after" the anchor in the content - // and each new piece of content is being added to the selection - // - - // Check to see if the new content is in the selection - nsIPresShell * shell = aPresContext.GetShell(); - nsIDocument * doc = shell->GetDocument(); - nsIContent * selStartContent = mStartSelectionPoint->GetContent(); - nsIContent * selEndContent = mEndSelectionPoint->GetContent(); - - PRBool inRange = doc->IsInRange(selStartContent, selEndContent, aNewContent); - - if (inRange) { - // Case #3 - Remove Content (from Start) - if (SELECTION_DEBUG) printf("Case #3 - (After) New Content is in selected Range.\n"); - - // Remove Current Content in Tracker, but leave New Content in Selection - addRangeToSelectionTrackers(mStartSelectionPoint->GetContent(), aNewContent, kInsertInRemoveList); - - PRUint32 actualOffset = 0; - // [TODO] Always get nearest Text content - PRInt32 newPos; - GetPosition(aPresContext, aRendContext, aEvent, aNewFrame, actualOffset, newPos); - - // Check to see if the new Content is the same as the End Point's - if (aNewContent == selEndContent) { - if (SELECTION_DEBUG) printf("New Content matches End Point\n"); - - mStartSelectionPoint->SetContent(aNewContent); - AdjustPointsInNewContent(aPresContext, aRendContext, aEvent, aNewFrame); - - } else { - if (SELECTION_DEBUG) printf("New Content does NOT matches End Point\n"); - mStartSelectionPoint->SetPoint(aNewContent, newPos, PR_FALSE); - mSelectionRange->SetStartPoint(mStartSelectionPoint); - } - - } else { - if (SELECTION_DEBUG) - printf("Case #4 - (After) Adding New Content\n"); - - // Case #2 - Adding Content (at End) - PRUint32 actualOffset = 0; - // The new content is not in the selection - PRInt32 newPos; - GetPosition(aPresContext, aRendContext, aEvent, aNewFrame, actualOffset, newPos); - - // Check to see if we need to create a new SelectionPoint and add it - // or do we simply move the existing start or end point - if (selStartContent == selEndContent) { - if (SELECTION_DEBUG) printf("Case #4 - Start & End Content the Same\n"); - // Move start or end point - // Get new Cursor Poition in the new content - - if (mStartSelectionPoint->IsAnchor()) { - if (SELECTION_DEBUG) printf("Case #4 - Start is Anchor\n"); - // Since the Start is the Anchor just adjust the end - - // XXX Note this includes the current End point (it should be end->nextContent) - addRangeToSelectionTrackers(selEndContent, aNewContent, kInsertInAddList); - - mEndSelectionPoint->SetPoint(aNewContent, newPos, PR_FALSE); - mSelectionRange->SetEndPoint(mEndSelectionPoint); - - } else { - if (SELECTION_DEBUG) printf("Case #4 - Start is NOT Anchor\n"); - // Because End was the anchor, we need to set the Start Point to - // the End's Offset and set it to be the new anchor - addRangeToSelectionTrackers(selStartContent,selEndContent, kInsertInRemoveList); - - int endPos = mEndSelectionPoint->GetOffset(); - mStartSelectionPoint->SetOffset(endPos); - mStartSelectionPoint->SetAnchor(PR_TRUE); - - // The Start point was being moved so when it jumped to the new frame - // we needed to make it the new End Point - mEndSelectionPoint->SetPoint(aNewContent, newPos, PR_FALSE); - mSelectionRange->SetRange(mStartSelectionPoint, mEndSelectionPoint); - - // The Content values have changed so go get new contents - nsIContent * startContent = mStartSelectionPoint->GetContent(); - nsIContent * endContent = mEndSelectionPoint->GetContent(); - addRangeToSelectionTrackers(startContent, endContent, kInsertInRemoveList); - NS_RELEASE(startContent); - NS_RELEASE(endContent); - } - } else { - if (SELECTION_DEBUG) printf("Case #4 - Start & End Content NOT the Same\n"); - // Adjust the end point - mEndSelectionPoint->SetPoint(aNewContent, newPos, PR_FALSE); - mSelectionRange->SetRange(mStartSelectionPoint, mEndSelectionPoint); - - // Add New Content to Selection Tracker - // The Content values have changed so go get new contents - // NOTE: selEndContent holds the "old" end content pointer - // and endContent hold the "new" content pointer - nsIContent * endContent = mEndSelectionPoint->GetContent(); - addRangeToSelectionTrackers(selEndContent, endContent, kInsertInAddList); - NS_RELEASE(endContent); - } - } - - NS_RELEASE(selStartContent); - NS_RELEASE(selEndContent); - NS_RELEASE(doc); - NS_RELEASE(shell); -#endif //0 -} /** * @@ -2220,92 +1715,6 @@ void ForceDrawFrame(nsFrame * aFrame)//, PRBool) } -///////////////////////////////////////////////// -// Selection Tracker Methods -///////////////////////////////////////////////// - -//---------------------------- -// -//---------------------------- -#if 0 -static void resetContentTrackers() { - PRInt32 i; - for (i=0;iGetRootFrame(rootFrame); - for (i=0;iFindFrameWithContent(fTrackerContentArrayRemoveList[i])); - if (SELECTION_DEBUG) printf("ForceDrawFrame (remove) content %p\n", fTrackerContentArrayRemoveList[i]); - } - for (i=0;iFindFrameWithContent(fTrackerContentArrayAddList[i]); - //ForceDrawFrame((nsFrame *)frame); - RefreshAllContentFrames(rootFrame, fTrackerContentArrayAddList[i]); - if (SELECTION_DEBUG) printf("ForceDrawFrame (add) content %p\n", fTrackerContentArrayAddList[i]); - } - NS_RELEASE(shell); - resetContentTrackers(); -} -#endif - -//---------------------------- -// -//---------------------------- -#if 0 -static void addRangeToSelectionTrackers(nsIContent * aStartContent, nsIContent * aEndContent, PRUint32 aType) -{ - if (aStartContent == nsnull || aEndContent == nsnull) { - return; - } - nsIContent ** contentList = (aType == kInsertInRemoveList?fTrackerContentArrayRemoveList:fTrackerContentArrayAddList); - int inx = (aType == kInsertInRemoveList?fTrackerRemoveListMax:fTrackerAddListMax); - - NS_ADDREF(aStartContent); - nsIContent * contentPtr = aStartContent; - while (contentPtr != aEndContent) { - contentList[inx++] = contentPtr; - contentPtr = gDoc->GetNextContent(contentPtr); // This does an AddRef - if (nsnull == contentPtr) { - // XXX We didn't find the end content... - if (aType == kInsertInRemoveList) { - fTrackerRemoveListMax = inx; - } else { // kInsertInAddList - fTrackerAddListMax = inx; - } - return; - } - } - contentList[inx++] = aEndContent; - - if (SELECTION_DEBUG) printf("Adding to %s %d\n", (aType == kInsertInRemoveList?"Remove Array":"Add Array"), inx); - - if (aType == kInsertInRemoveList) { - fTrackerRemoveListMax = inx; - } else { // kInsertInAddList - fTrackerAddListMax = inx; - } -} -#endif - #ifdef NS_DEBUG static void diff --git a/layout/generic/nsFrame.h b/layout/generic/nsFrame.h index e084bb5bc624..d9e5a8d3367f 100644 --- a/layout/generic/nsFrame.h +++ b/layout/generic/nsFrame.h @@ -323,19 +323,6 @@ protected: nsFrame(); virtual ~nsFrame(); - virtual void NewContentIsBefore(nsIPresContext& aPresContext, - nsIRenderingContext * aRendContext, - nsGUIEvent * aEvent, - nsIContent * aNewContent, - nsIContent * aCurrentContent, - nsIFrame * aNewFrame); - - virtual void NewContentIsAfter(nsIPresContext& aPresContext, - nsIRenderingContext * aRendContext, - nsGUIEvent * aEvent, - nsIContent * aNewContent, - nsIContent * aCurrentContent, - nsIFrame * aNewFrame); virtual void AdjustPointsInNewContent(nsIPresContext& aPresContext, nsIRenderingContext * aRendContext, diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index c4fd479f8ce2..8ea73f0c363d 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -904,15 +904,17 @@ TextFrame::PaintUnicodeText(nsIPresContext& aPresContext, if (textLength != selectionEnd) { PRInt32 thirdLen = textLength - selectionEnd; - NS_ASSERTION(thirdLen >= 0, "Text length is negative"); + if (thirdLen > 0) //Text length is not negative or zero + { - // Render third (unselected) section - aRenderingContext.GetWidth(text + selectionEnd, PRUint32(thirdLen), - textWidth); - aRenderingContext.DrawString(text + selectionEnd, - PRUint32(thirdLen), x, dy); - PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle, - x, dy, textWidth); + // Render third (unselected) section + aRenderingContext.GetWidth(text + selectionEnd, PRUint32(thirdLen), + textWidth); + aRenderingContext.DrawString(text + selectionEnd, + PRUint32(thirdLen), x, dy); + PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle, + x, dy, textWidth); + } } } } @@ -1773,11 +1775,11 @@ TextFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 nsresult result(NS_OK); switch (aAmount){ case eSelectNoAmount : { - *aResultFrame = this; - if (aStartOffset > mContentLength) - aStartOffset = mContentLength; //not ok normaly, but eNone means dont leave this frame - *aFrameOffset = aStartOffset; - } + *aResultFrame = this; + if (aStartOffset > mContentLength) + aStartOffset = mContentLength; //not ok normaly, but eNone means dont leave this frame + *aFrameOffset = aStartOffset; + } break; case eSelectCharacter : { if (aDirection == eDirPrevious){ @@ -1792,11 +1794,11 @@ TextFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 if (i <0){ nsIFrame *prev = GetPrevInFlow(); if (prev){ - return prev->PeekOffset(eSelectNoAmount, aDirection, -1, aResultFrame, + return prev->PeekOffset(eSelectCharacter, aDirection, -1, aResultFrame, aFrameOffset, aContentOffset); } else {//reached end ask the frame for help - return nsFrame::PeekOffset(eSelectNoAmount, aDirection, -1, aResultFrame, + return nsFrame::PeekOffset(eSelectCharacter, aDirection, -1, aResultFrame, aFrameOffset, aContentOffset); } } @@ -1816,11 +1818,11 @@ TextFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 if (i > mContentLength){ nsIFrame *next = GetNextInFlow(); if (next){ - return next->PeekOffset(eSelectNoAmount, aDirection, 0, aResultFrame, + return next->PeekOffset(eSelectCharacter, aDirection, 0, aResultFrame, aFrameOffset, aContentOffset); } else {//reached end ask the frame for help - return nsFrame::PeekOffset(eSelectNoAmount, aDirection, 0, aResultFrame, + return nsFrame::PeekOffset(eSelectCharacter, aDirection, 0, aResultFrame, aFrameOffset, aContentOffset); } } diff --git a/layout/html/base/src/nsFrame.cpp b/layout/html/base/src/nsFrame.cpp index 049a400328f4..95d895590686 100644 --- a/layout/html/base/src/nsFrame.cpp +++ b/layout/html/base/src/nsFrame.cpp @@ -730,182 +730,6 @@ nsFrame::HandlePress(nsIPresContext& aPresContext, } } } - -#if 0 -//DEBUG MJUDGE - nsFrame * currentFrame = this; - nsIPresShell * shell = aPresContext.GetShell(); - nsMouseEvent * mouseEvent = (nsMouseEvent *)aEvent; - nsIRenderingContext * acx; - - gDoc = shell->GetDocument(); - - nsISelection * selection; - gDoc->GetSelection(selection); - - shell->CreateRenderingContext(this, acx); - - mSelectionRange = selection->GetRange(); - - PRUint32 actualOffset = 0; - - mDoingSelection = PR_TRUE; - mDidDrag = PR_FALSE; - mCurrentFrame = currentFrame; - - GetPosition(aPresContext, acx, aEvent, currentFrame, actualOffset, mStartPos); - - // Click count is 1 - nsIContent * newContent; - currentFrame->GetContent(newContent); - - mCurrentFrame = currentFrame; - - if (mStartSelectionPoint == nsnull) { - mStartSelectionPoint = new nsSelectionPoint(nsnull, -1, PR_TRUE); - } - if (mEndSelectionPoint == nsnull) { - mEndSelectionPoint = new nsSelectionPoint(nsnull, -1, PR_TRUE); - } - - mSelectionRange->GetStartPoint(mStartSelectionPoint); - mSelectionRange->GetEndPoint(mEndSelectionPoint); - - resetContentTrackers(); - - // Get the Current Start and End Content Pointers - nsIContent * selStartContent = mSelectionRange->GetStartContent(); // ref counted - nsIContent * selEndContent = mSelectionRange->GetEndContent(); // ref counted - - if (SELECTION_DEBUG) printf("****** Shift[%s]\n", (mouseEvent->isShift?"Down":"Up")); - - PRBool inRange = gDoc->IsInRange(selStartContent, selEndContent, newContent); - - if (inRange) { - //resetContentTrackers(); - if (TRACKER_DEBUG) printf("Adding split range to removed selection. Shift[%s]\n", (mouseEvent->isShift?"Down":"Up")); - - if (mouseEvent->isShift) { - if (newContent == selStartContent && newContent == selEndContent) { - addRangeToSelectionTrackers(newContent, newContent, kInsertInAddList); - } else { - if (selStartContent == newContent) { - // Trackers just do painting so add all the content nodes in the remove list - // even though you might think you shouldn't put the start content node there - addRangeToSelectionTrackers(selStartContent, selEndContent, kInsertInRemoveList); - } else if (selEndContent == newContent) { - // just repaint the end content node - addRangeToSelectionTrackers(selEndContent, selEndContent, kInsertInAddList); - } else { - if (gDoc->IsBefore(newContent, selEndContent)) { - addRangeToSelectionTrackers(newContent, selEndContent, kInsertInRemoveList); - } else { - addRangeToSelectionTrackers(selEndContent, newContent, kInsertInRemoveList); - } - } - } - mEndSelectionPoint->SetPoint(newContent, mStartPos, PR_FALSE); - } else { - addRangeToSelectionTrackers(selStartContent, selEndContent, kInsertInRemoveList); // removed from selection - - mStartSelectionPoint->SetPoint(newContent, mStartPos, PR_TRUE); - mEndSelectionPoint->SetPoint(newContent, mStartPos, PR_TRUE); - - addRangeToSelectionTrackers(newContent, newContent, kInsertInAddList); // add to selection - } - - } else if (gDoc->IsBefore(newContent, selStartContent)) { - if (mouseEvent->isShift) { - if (mStartSelectionPoint->IsAnchor()) { - if (SELECTION_DEBUG) printf("New Content is before, Start will now be end\n"); - - addRangeToSelectionTrackers(selStartContent, selEndContent, kInsertInRemoveList); // removed from selection - - mEndSelectionPoint->SetPoint(selStartContent, mStartSelectionPoint->GetOffset(), PR_TRUE); - mStartSelectionPoint->SetPoint(newContent, mStartPos, PR_FALSE); - - // End Point has changed - nsIContent * endcontent = mEndSelectionPoint->GetContent(); // ref counted - addRangeToSelectionTrackers(newContent, endcontent, kInsertInAddList); // add to selection - NS_RELEASE(endcontent); - } else { - if (SELECTION_DEBUG) printf("New Content is before, Appending to Beginning\n"); - addRangeToSelectionTrackers(newContent, selEndContent, kInsertInAddList); // add to selection - mStartSelectionPoint->SetPoint(newContent, mStartPos, PR_FALSE); - } - } else { - if (SELECTION_DEBUG) printf("Adding full range to removed selection. (insert selection)\n"); - addRangeToSelectionTrackers(selStartContent, selEndContent, kInsertInRemoveList); // removed from selection - - mEndSelectionPoint->SetPoint(newContent, mStartPos, PR_TRUE); - - mStartSelectionPoint->SetPoint(newContent, mStartPos, PR_TRUE); - - addRangeToSelectionTrackers(newContent, newContent, kInsertInAddList); // add to selection - } - } else { // Content is After End - - if (mouseEvent->isShift) { - if (selStartContent == nsnull && selEndContent == nsnull) { - // Shift Click without first clicking in the window - // is interpreted the same as just clicking in a window - mEndSelectionPoint->SetPoint(newContent, mStartPos, PR_TRUE); - mStartSelectionPoint->SetPoint(newContent, mStartPos, PR_TRUE); - addRangeToSelectionTrackers(newContent, newContent, kInsertInAddList); // add to selection - - } else if (mStartSelectionPoint->IsAnchor()) { - if (SELECTION_DEBUG) printf("New Content is after, Append new content\n"); - addRangeToSelectionTrackers(selEndContent, newContent, kInsertInAddList); // add to selection - mEndSelectionPoint->SetPoint(newContent, mStartPos, PR_FALSE); - - } else { - if (SELECTION_DEBUG) printf("New Content is after, End will now be Start\n"); - - addRangeToSelectionTrackers(selStartContent, selEndContent, kInsertInRemoveList); // removed from selection - mStartSelectionPoint->SetPoint(selEndContent, mEndSelectionPoint->GetOffset(), PR_TRUE); - mEndSelectionPoint->SetPoint(newContent, mStartPos, PR_FALSE); - addRangeToSelectionTrackers(newContent, newContent, kInsertInAddList); // add to selection - } - - } else { - if (TRACKER_DEBUG) printf("Adding full range to removed selection.\n"); - addRangeToSelectionTrackers(selStartContent, selEndContent, kInsertInRemoveList); // removed from selection - - mEndSelectionPoint->SetPoint(newContent, mStartPos, PR_TRUE); - - mStartSelectionPoint->SetPoint(newContent, mStartPos, PR_TRUE); - - addRangeToSelectionTrackers(newContent, newContent, kInsertInAddList); // add to selection - } - } - - - mSelectionRange->SetStartPoint(mStartSelectionPoint); - mSelectionRange->SetEndPoint(mEndSelectionPoint); - - //if (selStartContent) printf("selStartContent count %d\n", selStartContent->Release()); - //if (selEndContent) printf("selEndContent count %d\n", selEndContent->Release()); - //if (newContent) printf("newContent count %d\n", newContent->Release()); - - NS_IF_RELEASE(selStartContent); - NS_IF_RELEASE(selEndContent); - NS_IF_RELEASE(newContent); - - RefreshFromContentTrackers(aPresContext); - - - if (SELECTION_DEBUG) printf("HandleEvent::mSelectionRange %s\n", mSelectionRange->ToString()); - - NS_IF_RELEASE(acx); - - // Force Update - ForceDrawFrame(this); - - NS_RELEASE(shell); - NS_RELEASE(selection); - - aEventStatus = nsEventStatus_eIgnore; -#endif //0 return NS_OK; } @@ -947,126 +771,6 @@ NS_IMETHODIMP nsFrame::HandleDrag(nsIPresContext& aPresContext, } } } -#if 0 -//DEBUG MJUDGE - if (DisplaySelection(aPresContext) == PR_FALSE) - { - aEventStatus = nsEventStatus_eIgnore; - return NS_OK; - } - - // Keep old start and end - nsIContent * startContent = mSelectionRange->GetStartContent(); // ref counted - nsIContent * endContent = mSelectionRange->GetEndContent(); // ref counted - - mDidDrag = PR_TRUE; - - nsIPresShell *ps = aPresContext.GetShell(); - nsIRenderingContext *acx; - - ps->CreateRenderingContext(this, acx); - NS_RELEASE(ps); - - //if (aFrame != nsnull) { - //printf("nsFrame::HandleDrag\n"); - - // Check to see if we have changed frame - if (this != mCurrentFrame) { - // We are in a new Frame! - if (SELECTION_DEBUG) printf("HandleDrag::Different Frame in selection!\n"); - - // Get Content for current Frame - nsIContent * currentContent; - mCurrentFrame->GetContent(currentContent); - - // Get Content for New Frame - nsIContent * newContent; - this->GetContent(newContent); - - // Check to see if we are still in the same Content - if (currentContent == newContent) { - if (SELECTION_DEBUG) printf("HandleDrag::New Frame, same content.\n"); - - AdjustPointsInSameContent(aPresContext, acx, aEvent); - addRangeToSelectionTrackers(currentContent, currentContent, kInsertInAddList); - - } else if (gDoc->IsBefore(newContent, currentContent)) { - if (SELECTION_DEBUG) printf("HandleDrag::New Frame, is Before.\n"); - - resetContentTrackers(); - NewContentIsBefore(aPresContext, acx, aEvent, newContent, currentContent, this); - - } else { // Content is AFTER - if (SELECTION_DEBUG) printf("HandleDrag::New Frame, is After.\n"); - - resetContentTrackers(); - NewContentIsAfter(aPresContext, acx, aEvent, newContent, currentContent, this); - } - mCurrentFrame = this; - - NS_IF_RELEASE(currentContent); - NS_IF_RELEASE(newContent); - } else if ((nsnull != mStartSelectionPoint) && (nsnull != mEndSelectionPoint)) { - if (SELECTION_DEBUG) printf("HandleDrag::Same Frame.\n"); - - // Same Frame as before - //if (SELECTION_DEBUG) printf("\nSame Start: %s\n", mStartSelectionPoint->ToString()); - //if (SELECTION_DEBUG) printf("Same End: %s\n", mEndSelectionPoint->ToString()); - // [TODO] Uncomment these soon - - nsIContent * selStartContent = mStartSelectionPoint->GetContent(); - nsIContent * selEndContent = mEndSelectionPoint->GetContent(); - - if (selStartContent == selEndContent) { - if (SELECTION_DEBUG) printf("Start & End Frame are the same: \n"); - AdjustPointsInSameContent(aPresContext, acx, aEvent); - } else { - if (SELECTION_DEBUG) printf("Start & End Frame are different: \n"); - - // Get Content for New Frame - nsIContent * newContent; - this->GetContent(newContent); - PRInt32 newPos = -1; - PRUint32 actualOffset = 0; - - GetPosition(aPresContext, acx, aEvent, this, actualOffset, newPos); - - if (newContent == selStartContent) { - if (SELECTION_DEBUG) printf("New Content equals Start Content\n"); - mStartSelectionPoint->SetOffset(newPos); - mSelectionRange->SetStartPoint(mStartSelectionPoint); - } else if (newContent == selEndContent) { - if (SELECTION_DEBUG) printf("New Content equals End Content\n"); - mEndSelectionPoint->SetOffset(newPos); - mSelectionRange->SetEndPoint(mEndSelectionPoint); - } else { - if (SELECTION_DEBUG) printf("=====\n=====\n=====\n=====\n=====\n=====\n Should NOT be here.\n"); - } - - //if (SELECTION_DEBUG) printf("*Same Start: "+mStartSelectionPoint->GetOffset()+ - // " "+mStartSelectionPoint->IsAnchor()+ - // " End: "+mEndSelectionPoint->GetOffset() + - // " "+mEndSelectionPoint->IsAnchor()); - NS_IF_RELEASE(newContent); - } - NS_IF_RELEASE(selStartContent); - NS_IF_RELEASE(selEndContent); - } - //} - - - NS_IF_RELEASE(startContent); - NS_IF_RELEASE(endContent); - - NS_IF_RELEASE(acx); - - // Force Update - ForceDrawFrame(this); - //RefreshContentFrames(aPresContext, startContent, endContent); - RefreshFromContentTrackers(aPresContext); - - aEventStatus = nsEventStatus_eIgnore; -#endif //0 return NS_OK; } @@ -1813,13 +1517,19 @@ nsFrame::VerifyTree() const return NS_OK; } +/*this method may.. invalidate if the state was changed or if aForceRedraw is PR_TRUE + it will not update immediately.*/ NS_IMETHODIMP nsFrame::SetSelected(PRBool aSelected, PRInt32 aBeginOffset, PRInt32 aEndOffset, PRBool aForceRedraw) { if (mSelected != aSelected || aForceRedraw) { mSelected = aSelected; - ForceDrawFrame(this); + + nsRect rect; + GetRect(rect); + ForceDrawFrame(this);//invalidate does not work in all cases. + //Invalidate(rect,PR_FALSE); //false is for not immediate } return NS_OK; } @@ -1915,88 +1625,6 @@ nsFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 a //----------------------------------------------------------------------------------- -/******************************************************** -* Handles a when the cursor enters new content that is before -* the content that the cursor is currently in -*********************************************************/ -void nsFrame::NewContentIsBefore(nsIPresContext& aPresContext, - nsIRenderingContext * aRendContext, - nsGUIEvent * aEvent, - nsIContent * aNewContent, - nsIContent * aCurrentContent, - nsIFrame * aNewFrame) -{ -#if 0 -//DEBUG MJUDGE - if (SELECTION_DEBUG) printf("New Frame, New content is before.\n"); - // Dragging mouse to the left or backward in content - // - // 1) The cursor is being dragged backward in the content - // and the mouse is "after" the anchor in the content - // and the current piece of content is being removed from the selection - // - // This section cover two cases: - // 2) The cursor is being dragged backward in the content - // and the mouse is "before" the anchor in the content - // and each new piece of content is being added to the selection - - if ((nsnull == mStartSelectionPoint) || (nsnull == mEndSelectionPoint)) { - return; - } - nsIPresShell * shell = aPresContext.GetShell(); - nsIDocument * doc = shell->GetDocument(); - nsIContent * selStartContent = mStartSelectionPoint->GetContent(); - nsIContent * selEndContent = mEndSelectionPoint->GetContent(); - - PRBool inRange = doc->IsInRange(selStartContent, selEndContent, aNewContent); - - // Check to see if the new content is in the selection - if (inRange) { - - // Case #1 - Remove Current Content from Selection (at End) - if (SELECTION_DEBUG) printf("Case #1 - (Before) New Content is in selected Range.\n"); - - - if (aNewContent == selStartContent) { - // [TODO] This is where we might have to delete from end to new content - - // Returns the new End Point, if Start and End are on the - // same content then End Point's Cursor is set to Start's - mEndSelectionPoint->SetContent(selStartContent); - AdjustPointsInNewContent(aPresContext, aRendContext, aEvent, aNewFrame); - - } else { - PRUint32 actualOffset = 0; - PRInt32 newPos; - GetPosition(aPresContext, aRendContext, aEvent, aNewFrame, actualOffset, newPos); - mEndSelectionPoint->SetPoint(aNewContent, newPos, PR_FALSE); - mSelectionRange->SetEndPoint(mEndSelectionPoint); - } - - // The current content is being removed from Selection - addRangeToSelectionTrackers(aNewContent, aCurrentContent, kInsertInRemoveList); - } else { - // Case #2 - Add new content to selection (At Start) - if (SELECTION_DEBUG) printf("Case #2 - (Before) New Content is NOT in selected Range. Moving Start Backward.\n"); - - PRUint32 actualOffset = 0; - PRInt32 newPos; - - GetPosition(aPresContext, aRendContext, aEvent, aNewFrame, actualOffset, newPos); - - // Create new TextPoint and move Start Point backward - mStartSelectionPoint->SetPoint(aNewContent, newPos, PR_FALSE); // position is set correctly in adjustTextPoints - mSelectionRange->SetStartPoint(mStartSelectionPoint); - - // The New Content is added to Tracker - addRangeToSelectionTrackers(aNewContent, aCurrentContent, kInsertInAddList); - } - NS_RELEASE(selStartContent); - NS_RELEASE(selEndContent); - NS_RELEASE(doc); - NS_RELEASE(shell); -#endif //0 -} /******************************************************** * Refreshes each content's frame @@ -2058,139 +1686,6 @@ static void RefreshContentFrames(nsIPresContext& aPresContext, } #endif -/******************************************************** -* Handles a when the cursor enters new content that is After -* the content that the cursor is currently in -*********************************************************/ -void nsFrame::NewContentIsAfter(nsIPresContext& aPresContext, - nsIRenderingContext * aRendContext, - nsGUIEvent * aEvent, - nsIContent * aNewContent, - nsIContent * aCurrentContent, - nsIFrame * aNewFrame) -{ -#if 0 -//DEBUG MJUDGE - - if (SELECTION_DEBUG) printf("New Frame, New content is after.\n"); - - - // Dragging Mouse to the Right - // - // 3) The cursor is being dragged foward in the content - // and the mouse is "before" the anchor in the content - // and the current piece of content is being removed from the selection - // - // This section cover two cases: - // 4) The cursor is being dragged foward in the content - // and the mouse is "after" the anchor in the content - // and each new piece of content is being added to the selection - // - - // Check to see if the new content is in the selection - nsIPresShell * shell = aPresContext.GetShell(); - nsIDocument * doc = shell->GetDocument(); - nsIContent * selStartContent = mStartSelectionPoint->GetContent(); - nsIContent * selEndContent = mEndSelectionPoint->GetContent(); - - PRBool inRange = doc->IsInRange(selStartContent, selEndContent, aNewContent); - - if (inRange) { - // Case #3 - Remove Content (from Start) - if (SELECTION_DEBUG) printf("Case #3 - (After) New Content is in selected Range.\n"); - - // Remove Current Content in Tracker, but leave New Content in Selection - addRangeToSelectionTrackers(mStartSelectionPoint->GetContent(), aNewContent, kInsertInRemoveList); - - PRUint32 actualOffset = 0; - // [TODO] Always get nearest Text content - PRInt32 newPos; - GetPosition(aPresContext, aRendContext, aEvent, aNewFrame, actualOffset, newPos); - - // Check to see if the new Content is the same as the End Point's - if (aNewContent == selEndContent) { - if (SELECTION_DEBUG) printf("New Content matches End Point\n"); - - mStartSelectionPoint->SetContent(aNewContent); - AdjustPointsInNewContent(aPresContext, aRendContext, aEvent, aNewFrame); - - } else { - if (SELECTION_DEBUG) printf("New Content does NOT matches End Point\n"); - mStartSelectionPoint->SetPoint(aNewContent, newPos, PR_FALSE); - mSelectionRange->SetStartPoint(mStartSelectionPoint); - } - - } else { - if (SELECTION_DEBUG) - printf("Case #4 - (After) Adding New Content\n"); - - // Case #2 - Adding Content (at End) - PRUint32 actualOffset = 0; - // The new content is not in the selection - PRInt32 newPos; - GetPosition(aPresContext, aRendContext, aEvent, aNewFrame, actualOffset, newPos); - - // Check to see if we need to create a new SelectionPoint and add it - // or do we simply move the existing start or end point - if (selStartContent == selEndContent) { - if (SELECTION_DEBUG) printf("Case #4 - Start & End Content the Same\n"); - // Move start or end point - // Get new Cursor Poition in the new content - - if (mStartSelectionPoint->IsAnchor()) { - if (SELECTION_DEBUG) printf("Case #4 - Start is Anchor\n"); - // Since the Start is the Anchor just adjust the end - - // XXX Note this includes the current End point (it should be end->nextContent) - addRangeToSelectionTrackers(selEndContent, aNewContent, kInsertInAddList); - - mEndSelectionPoint->SetPoint(aNewContent, newPos, PR_FALSE); - mSelectionRange->SetEndPoint(mEndSelectionPoint); - - } else { - if (SELECTION_DEBUG) printf("Case #4 - Start is NOT Anchor\n"); - // Because End was the anchor, we need to set the Start Point to - // the End's Offset and set it to be the new anchor - addRangeToSelectionTrackers(selStartContent,selEndContent, kInsertInRemoveList); - - int endPos = mEndSelectionPoint->GetOffset(); - mStartSelectionPoint->SetOffset(endPos); - mStartSelectionPoint->SetAnchor(PR_TRUE); - - // The Start point was being moved so when it jumped to the new frame - // we needed to make it the new End Point - mEndSelectionPoint->SetPoint(aNewContent, newPos, PR_FALSE); - mSelectionRange->SetRange(mStartSelectionPoint, mEndSelectionPoint); - - // The Content values have changed so go get new contents - nsIContent * startContent = mStartSelectionPoint->GetContent(); - nsIContent * endContent = mEndSelectionPoint->GetContent(); - addRangeToSelectionTrackers(startContent, endContent, kInsertInRemoveList); - NS_RELEASE(startContent); - NS_RELEASE(endContent); - } - } else { - if (SELECTION_DEBUG) printf("Case #4 - Start & End Content NOT the Same\n"); - // Adjust the end point - mEndSelectionPoint->SetPoint(aNewContent, newPos, PR_FALSE); - mSelectionRange->SetRange(mStartSelectionPoint, mEndSelectionPoint); - - // Add New Content to Selection Tracker - // The Content values have changed so go get new contents - // NOTE: selEndContent holds the "old" end content pointer - // and endContent hold the "new" content pointer - nsIContent * endContent = mEndSelectionPoint->GetContent(); - addRangeToSelectionTrackers(selEndContent, endContent, kInsertInAddList); - NS_RELEASE(endContent); - } - } - - NS_RELEASE(selStartContent); - NS_RELEASE(selEndContent); - NS_RELEASE(doc); - NS_RELEASE(shell); -#endif //0 -} /** * @@ -2220,92 +1715,6 @@ void ForceDrawFrame(nsFrame * aFrame)//, PRBool) } -///////////////////////////////////////////////// -// Selection Tracker Methods -///////////////////////////////////////////////// - -//---------------------------- -// -//---------------------------- -#if 0 -static void resetContentTrackers() { - PRInt32 i; - for (i=0;iGetRootFrame(rootFrame); - for (i=0;iFindFrameWithContent(fTrackerContentArrayRemoveList[i])); - if (SELECTION_DEBUG) printf("ForceDrawFrame (remove) content %p\n", fTrackerContentArrayRemoveList[i]); - } - for (i=0;iFindFrameWithContent(fTrackerContentArrayAddList[i]); - //ForceDrawFrame((nsFrame *)frame); - RefreshAllContentFrames(rootFrame, fTrackerContentArrayAddList[i]); - if (SELECTION_DEBUG) printf("ForceDrawFrame (add) content %p\n", fTrackerContentArrayAddList[i]); - } - NS_RELEASE(shell); - resetContentTrackers(); -} -#endif - -//---------------------------- -// -//---------------------------- -#if 0 -static void addRangeToSelectionTrackers(nsIContent * aStartContent, nsIContent * aEndContent, PRUint32 aType) -{ - if (aStartContent == nsnull || aEndContent == nsnull) { - return; - } - nsIContent ** contentList = (aType == kInsertInRemoveList?fTrackerContentArrayRemoveList:fTrackerContentArrayAddList); - int inx = (aType == kInsertInRemoveList?fTrackerRemoveListMax:fTrackerAddListMax); - - NS_ADDREF(aStartContent); - nsIContent * contentPtr = aStartContent; - while (contentPtr != aEndContent) { - contentList[inx++] = contentPtr; - contentPtr = gDoc->GetNextContent(contentPtr); // This does an AddRef - if (nsnull == contentPtr) { - // XXX We didn't find the end content... - if (aType == kInsertInRemoveList) { - fTrackerRemoveListMax = inx; - } else { // kInsertInAddList - fTrackerAddListMax = inx; - } - return; - } - } - contentList[inx++] = aEndContent; - - if (SELECTION_DEBUG) printf("Adding to %s %d\n", (aType == kInsertInRemoveList?"Remove Array":"Add Array"), inx); - - if (aType == kInsertInRemoveList) { - fTrackerRemoveListMax = inx; - } else { // kInsertInAddList - fTrackerAddListMax = inx; - } -} -#endif - #ifdef NS_DEBUG static void diff --git a/layout/html/base/src/nsFrame.h b/layout/html/base/src/nsFrame.h index e084bb5bc624..d9e5a8d3367f 100644 --- a/layout/html/base/src/nsFrame.h +++ b/layout/html/base/src/nsFrame.h @@ -323,19 +323,6 @@ protected: nsFrame(); virtual ~nsFrame(); - virtual void NewContentIsBefore(nsIPresContext& aPresContext, - nsIRenderingContext * aRendContext, - nsGUIEvent * aEvent, - nsIContent * aNewContent, - nsIContent * aCurrentContent, - nsIFrame * aNewFrame); - - virtual void NewContentIsAfter(nsIPresContext& aPresContext, - nsIRenderingContext * aRendContext, - nsGUIEvent * aEvent, - nsIContent * aNewContent, - nsIContent * aCurrentContent, - nsIFrame * aNewFrame); virtual void AdjustPointsInNewContent(nsIPresContext& aPresContext, nsIRenderingContext * aRendContext, diff --git a/layout/html/base/src/nsTextFrame.cpp b/layout/html/base/src/nsTextFrame.cpp index c4fd479f8ce2..8ea73f0c363d 100644 --- a/layout/html/base/src/nsTextFrame.cpp +++ b/layout/html/base/src/nsTextFrame.cpp @@ -904,15 +904,17 @@ TextFrame::PaintUnicodeText(nsIPresContext& aPresContext, if (textLength != selectionEnd) { PRInt32 thirdLen = textLength - selectionEnd; - NS_ASSERTION(thirdLen >= 0, "Text length is negative"); + if (thirdLen > 0) //Text length is not negative or zero + { - // Render third (unselected) section - aRenderingContext.GetWidth(text + selectionEnd, PRUint32(thirdLen), - textWidth); - aRenderingContext.DrawString(text + selectionEnd, - PRUint32(thirdLen), x, dy); - PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle, - x, dy, textWidth); + // Render third (unselected) section + aRenderingContext.GetWidth(text + selectionEnd, PRUint32(thirdLen), + textWidth); + aRenderingContext.DrawString(text + selectionEnd, + PRUint32(thirdLen), x, dy); + PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle, + x, dy, textWidth); + } } } } @@ -1773,11 +1775,11 @@ TextFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 nsresult result(NS_OK); switch (aAmount){ case eSelectNoAmount : { - *aResultFrame = this; - if (aStartOffset > mContentLength) - aStartOffset = mContentLength; //not ok normaly, but eNone means dont leave this frame - *aFrameOffset = aStartOffset; - } + *aResultFrame = this; + if (aStartOffset > mContentLength) + aStartOffset = mContentLength; //not ok normaly, but eNone means dont leave this frame + *aFrameOffset = aStartOffset; + } break; case eSelectCharacter : { if (aDirection == eDirPrevious){ @@ -1792,11 +1794,11 @@ TextFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 if (i <0){ nsIFrame *prev = GetPrevInFlow(); if (prev){ - return prev->PeekOffset(eSelectNoAmount, aDirection, -1, aResultFrame, + return prev->PeekOffset(eSelectCharacter, aDirection, -1, aResultFrame, aFrameOffset, aContentOffset); } else {//reached end ask the frame for help - return nsFrame::PeekOffset(eSelectNoAmount, aDirection, -1, aResultFrame, + return nsFrame::PeekOffset(eSelectCharacter, aDirection, -1, aResultFrame, aFrameOffset, aContentOffset); } } @@ -1816,11 +1818,11 @@ TextFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 if (i > mContentLength){ nsIFrame *next = GetNextInFlow(); if (next){ - return next->PeekOffset(eSelectNoAmount, aDirection, 0, aResultFrame, + return next->PeekOffset(eSelectCharacter, aDirection, 0, aResultFrame, aFrameOffset, aContentOffset); } else {//reached end ask the frame for help - return nsFrame::PeekOffset(eSelectNoAmount, aDirection, 0, aResultFrame, + return nsFrame::PeekOffset(eSelectCharacter, aDirection, 0, aResultFrame, aFrameOffset, aContentOffset); } }