From 43a63010d13df4711b41a6ed3fe360ea9fc5dcdf Mon Sep 17 00:00:00 2001 From: "mjudge%netscape.com" Date: Tue, 23 Nov 1999 20:30:21 +0000 Subject: [PATCH] small fixes for BR frames getting correct offset. also one case of textframe not returning proper location (simply a missed change of a regressed call in PeekOffset) nsCaret was also too stringent on the limitation of text frames as the only frames to get the caret position. these were reviewed by a few people and i just dont remember. r=simon,cmanske,akkana and hyatt? git-svn-id: svn://10.0.0.236/trunk@54299 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/base/nsCaret.cpp | 3 +- mozilla/layout/base/src/nsCaret.cpp | 3 +- mozilla/layout/generic/nsBRFrame.cpp | 58 +++++++++++++++----- mozilla/layout/generic/nsFrame.cpp | 9 ++- mozilla/layout/generic/nsTextFrame.cpp | 4 +- mozilla/layout/html/base/src/nsBRFrame.cpp | 58 +++++++++++++++----- mozilla/layout/html/base/src/nsFrame.cpp | 9 ++- mozilla/layout/html/base/src/nsTextFrame.cpp | 4 +- 8 files changed, 106 insertions(+), 42 deletions(-) diff --git a/mozilla/layout/base/nsCaret.cpp b/mozilla/layout/base/nsCaret.cpp index a7f90e49daa..7238f6d77b0 100644 --- a/mozilla/layout/base/nsCaret.cpp +++ b/mozilla/layout/base/nsCaret.cpp @@ -210,13 +210,14 @@ NS_IMETHODIMP nsCaret::GetWindowRelativeCoordinates(nsPoint& outCoordinates, PRB if (NS_FAILED(err)) return err; +/* // is this a text node? nsCOMPtr nodeAsText = do_QueryInterface(focusNode); // note that we only work with text nodes here, unlike when drawing the caret. // this is because this routine is intended for IME support, which only cares about text. if (!nodeAsText) return NS_ERROR_UNEXPECTED; - +*/ nsCOMPtrcontentNode = do_QueryInterface(focusNode); if (!contentNode) return NS_ERROR_FAILURE; diff --git a/mozilla/layout/base/src/nsCaret.cpp b/mozilla/layout/base/src/nsCaret.cpp index a7f90e49daa..7238f6d77b0 100644 --- a/mozilla/layout/base/src/nsCaret.cpp +++ b/mozilla/layout/base/src/nsCaret.cpp @@ -210,13 +210,14 @@ NS_IMETHODIMP nsCaret::GetWindowRelativeCoordinates(nsPoint& outCoordinates, PRB if (NS_FAILED(err)) return err; +/* // is this a text node? nsCOMPtr nodeAsText = do_QueryInterface(focusNode); // note that we only work with text nodes here, unlike when drawing the caret. // this is because this routine is intended for IME support, which only cares about text. if (!nodeAsText) return NS_ERROR_UNEXPECTED; - +*/ nsCOMPtrcontentNode = do_QueryInterface(focusNode); if (!contentNode) return NS_ERROR_FAILURE; diff --git a/mozilla/layout/generic/nsBRFrame.cpp b/mozilla/layout/generic/nsBRFrame.cpp index d4ad1c6feb1..10c443ddc58 100644 --- a/mozilla/layout/generic/nsBRFrame.cpp +++ b/mozilla/layout/generic/nsBRFrame.cpp @@ -31,6 +31,11 @@ #include "nsIFontMetrics.h" #include "nsIRenderingContext.h" +//FOR SELECTION +#include "nsIContent.h" +#include "nsIFrameSelection.h" +//END INCLUDES FOR SELECTION + class BRFrame : public nsFrame { public: // nsIFrame @@ -40,19 +45,20 @@ public: const nsRect& aDirtyRect, nsFramePaintLayer aWhichLayer); #endif - - // nsIHTMLReflow - NS_IMETHOD Reflow(nsIPresContext& aPresContext, - nsHTMLReflowMetrics& aDesiredSize, - const nsHTMLReflowState& aReflowState, - nsReflowStatus& aStatus); NS_IMETHOD GetContentAndOffsetsFromPoint(nsIPresContext& aCX, const nsPoint& aPoint, nsIContent** aNewContent, PRInt32& aContentOffset, PRInt32& aContentOffsetEnd, PRBool& aBeginFrameContent); + NS_IMETHOD PeekOffset(nsIPresContext* aPresContext, + nsPeekOffsetStruct *aPos); + // nsIHTMLReflow + NS_IMETHOD Reflow(nsIPresContext& aPresContext, + nsHTMLReflowMetrics& aDesiredSize, + const nsHTMLReflowState& aReflowState, + nsReflowStatus& aStatus); protected: virtual ~BRFrame(); }; @@ -176,13 +182,37 @@ NS_IMETHODIMP BRFrame::GetContentAndOffsetsFromPoint(nsIPresContext& aCX, PRInt32& aOffsetEnd, PRBool& aBeginFrameContent) { - nsresult result = nsFrame::GetContentAndOffsetsFromPoint(aCX,aPoint,aContent,aOffsetBegin,aOffsetEnd,aBeginFrameContent); - - if (NS_SUCCEEDED(result)) - { - // BRFrames should return a collapsed selection before itself - aOffsetEnd = aOffsetBegin; - } - + if (!mContent) + return NS_ERROR_NULL_POINTER; + nsresult result = mContent->GetParent(*aContent); + if (NS_SUCCEEDED(result) && *aContent) + result = (*aContent)->IndexOf(mContent, aOffsetBegin); + aOffsetEnd = aOffsetBegin; + aBeginFrameContent = PR_TRUE; return result; } + +NS_IMETHODIMP BRFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos) +{ + if (!aPos) + return NS_ERROR_NULL_POINTER; + + nsCOMPtr parentContent; + PRInt32 offsetBegin; //offset of this content in its parents child list. base 0 + + nsresult result = mContent->GetParent(*getter_AddRefs(parentContent)); + + + if (NS_SUCCEEDED(result) && parentContent) + result = parentContent->IndexOf(mContent, offsetBegin); + + if (aPos->mAmount != eSelectLine && aPos->mAmount != eSelectBeginLine + && aPos->mAmount != eSelectEndLine) //then we must do the adjustment to make sure we leave this frame + { + if (aPos->mDirection == eDirNext) + aPos->mStartOffset = offsetBegin +1;//go to end to make sure we jump to next node. + else + aPos->mStartOffset = offsetBegin; //we start at beginning to make sure we leave this frame. + } + return nsFrame::PeekOffset(aPresContext, aPos);//now we let the default take over. +} diff --git a/mozilla/layout/generic/nsFrame.cpp b/mozilla/layout/generic/nsFrame.cpp index 93e768bf843..b8e7106f262 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -663,11 +663,10 @@ nsFrame::Paint(nsIPresContext& aPresContext, if (NS_FAILED(result)) return result; - PRBool displaySelection; - //result = shell->GetDisplayNonTextSelection(&displaySelection); - //if (NS_FAILED(result)) - //return result; - displaySelection = PR_TRUE; + PRBool displaySelection = PR_TRUE; + result = shell->GetDisplayNonTextSelection(&displaySelection); + if (NS_FAILED(result)) + return result; if (!displaySelection) return NS_OK; if (mContent) { diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index acc6f8852f3..020ec56be15 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -2285,7 +2285,9 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos) else { aPos->mAmount = eSelectDir;//go to "next" or previous frame based on direction not THIS frame - return nsFrame::PeekOffset(aPresContext, aPos);//no matter what this is not a valid frame to end up on + result = GetFrameFromDirection(aPos); + if (NS_SUCCEEDED(result) && aPos->mResultFrame && aPos->mResultFrame!= this) + return aPos->mResultFrame->PeekOffset(aPresContext, aPos); } } break; diff --git a/mozilla/layout/html/base/src/nsBRFrame.cpp b/mozilla/layout/html/base/src/nsBRFrame.cpp index d4ad1c6feb1..10c443ddc58 100644 --- a/mozilla/layout/html/base/src/nsBRFrame.cpp +++ b/mozilla/layout/html/base/src/nsBRFrame.cpp @@ -31,6 +31,11 @@ #include "nsIFontMetrics.h" #include "nsIRenderingContext.h" +//FOR SELECTION +#include "nsIContent.h" +#include "nsIFrameSelection.h" +//END INCLUDES FOR SELECTION + class BRFrame : public nsFrame { public: // nsIFrame @@ -40,19 +45,20 @@ public: const nsRect& aDirtyRect, nsFramePaintLayer aWhichLayer); #endif - - // nsIHTMLReflow - NS_IMETHOD Reflow(nsIPresContext& aPresContext, - nsHTMLReflowMetrics& aDesiredSize, - const nsHTMLReflowState& aReflowState, - nsReflowStatus& aStatus); NS_IMETHOD GetContentAndOffsetsFromPoint(nsIPresContext& aCX, const nsPoint& aPoint, nsIContent** aNewContent, PRInt32& aContentOffset, PRInt32& aContentOffsetEnd, PRBool& aBeginFrameContent); + NS_IMETHOD PeekOffset(nsIPresContext* aPresContext, + nsPeekOffsetStruct *aPos); + // nsIHTMLReflow + NS_IMETHOD Reflow(nsIPresContext& aPresContext, + nsHTMLReflowMetrics& aDesiredSize, + const nsHTMLReflowState& aReflowState, + nsReflowStatus& aStatus); protected: virtual ~BRFrame(); }; @@ -176,13 +182,37 @@ NS_IMETHODIMP BRFrame::GetContentAndOffsetsFromPoint(nsIPresContext& aCX, PRInt32& aOffsetEnd, PRBool& aBeginFrameContent) { - nsresult result = nsFrame::GetContentAndOffsetsFromPoint(aCX,aPoint,aContent,aOffsetBegin,aOffsetEnd,aBeginFrameContent); - - if (NS_SUCCEEDED(result)) - { - // BRFrames should return a collapsed selection before itself - aOffsetEnd = aOffsetBegin; - } - + if (!mContent) + return NS_ERROR_NULL_POINTER; + nsresult result = mContent->GetParent(*aContent); + if (NS_SUCCEEDED(result) && *aContent) + result = (*aContent)->IndexOf(mContent, aOffsetBegin); + aOffsetEnd = aOffsetBegin; + aBeginFrameContent = PR_TRUE; return result; } + +NS_IMETHODIMP BRFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos) +{ + if (!aPos) + return NS_ERROR_NULL_POINTER; + + nsCOMPtr parentContent; + PRInt32 offsetBegin; //offset of this content in its parents child list. base 0 + + nsresult result = mContent->GetParent(*getter_AddRefs(parentContent)); + + + if (NS_SUCCEEDED(result) && parentContent) + result = parentContent->IndexOf(mContent, offsetBegin); + + if (aPos->mAmount != eSelectLine && aPos->mAmount != eSelectBeginLine + && aPos->mAmount != eSelectEndLine) //then we must do the adjustment to make sure we leave this frame + { + if (aPos->mDirection == eDirNext) + aPos->mStartOffset = offsetBegin +1;//go to end to make sure we jump to next node. + else + aPos->mStartOffset = offsetBegin; //we start at beginning to make sure we leave this frame. + } + return nsFrame::PeekOffset(aPresContext, aPos);//now we let the default take over. +} diff --git a/mozilla/layout/html/base/src/nsFrame.cpp b/mozilla/layout/html/base/src/nsFrame.cpp index 93e768bf843..b8e7106f262 100644 --- a/mozilla/layout/html/base/src/nsFrame.cpp +++ b/mozilla/layout/html/base/src/nsFrame.cpp @@ -663,11 +663,10 @@ nsFrame::Paint(nsIPresContext& aPresContext, if (NS_FAILED(result)) return result; - PRBool displaySelection; - //result = shell->GetDisplayNonTextSelection(&displaySelection); - //if (NS_FAILED(result)) - //return result; - displaySelection = PR_TRUE; + PRBool displaySelection = PR_TRUE; + result = shell->GetDisplayNonTextSelection(&displaySelection); + if (NS_FAILED(result)) + return result; if (!displaySelection) return NS_OK; if (mContent) { diff --git a/mozilla/layout/html/base/src/nsTextFrame.cpp b/mozilla/layout/html/base/src/nsTextFrame.cpp index acc6f8852f3..020ec56be15 100644 --- a/mozilla/layout/html/base/src/nsTextFrame.cpp +++ b/mozilla/layout/html/base/src/nsTextFrame.cpp @@ -2285,7 +2285,9 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos) else { aPos->mAmount = eSelectDir;//go to "next" or previous frame based on direction not THIS frame - return nsFrame::PeekOffset(aPresContext, aPos);//no matter what this is not a valid frame to end up on + result = GetFrameFromDirection(aPos); + if (NS_SUCCEEDED(result) && aPos->mResultFrame && aPos->mResultFrame!= this) + return aPos->mResultFrame->PeekOffset(aPresContext, aPos); } } break;