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
This commit is contained in:
@@ -210,13 +210,14 @@ NS_IMETHODIMP nsCaret::GetWindowRelativeCoordinates(nsPoint& outCoordinates, PRB
|
||||
if (NS_FAILED(err))
|
||||
return err;
|
||||
|
||||
/*
|
||||
// is this a text node?
|
||||
nsCOMPtr<nsIDOMCharacterData> 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;
|
||||
|
||||
*/
|
||||
nsCOMPtr<nsIContent>contentNode = do_QueryInterface(focusNode);
|
||||
if (!contentNode)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
@@ -210,13 +210,14 @@ NS_IMETHODIMP nsCaret::GetWindowRelativeCoordinates(nsPoint& outCoordinates, PRB
|
||||
if (NS_FAILED(err))
|
||||
return err;
|
||||
|
||||
/*
|
||||
// is this a text node?
|
||||
nsCOMPtr<nsIDOMCharacterData> 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;
|
||||
|
||||
*/
|
||||
nsCOMPtr<nsIContent>contentNode = do_QueryInterface(focusNode);
|
||||
if (!contentNode)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
@@ -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<nsIContent> 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.
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<nsIContent> 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.
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user