2028: Get selection highlighting working on Linux

This commit is contained in:
akkana%netscape.com 1999-01-23 00:00:46 +00:00
Родитель cc72765ce6
Коммит 56752ba2ed
4 изменённых файлов: 74 добавлений и 46 удалений

Просмотреть файл

@ -477,6 +477,7 @@ PresShell::Init(nsIDocument* aDocument,
if (!NS_SUCCEEDED(result)) if (!NS_SUCCEEDED(result))
return result; return result;
selection->Clear();//clear all old selection selection->Clear();//clear all old selection
#if 0
nsCOMPtr<nsIDOMRange>range; nsCOMPtr<nsIDOMRange>range;
if (NS_SUCCEEDED(nsRepository::CreateInstance(kCRangeCID, nsnull, kIDOMRangeIID, getter_AddRefs(range)))){ //create an irange if (NS_SUCCEEDED(nsRepository::CreateInstance(kCRangeCID, nsnull, kIDOMRangeIID, getter_AddRefs(range)))){ //create an irange
nsCOMPtr<nsIDocument>doc(GetDocument()); nsCOMPtr<nsIDocument>doc(GetDocument());
@ -496,6 +497,7 @@ PresShell::Init(nsIDocument* aDocument,
} }
} }
} }
#endif
mSelection = selection; mSelection = selection;
return NS_OK; return NS_OK;
} }

Просмотреть файл

@ -1359,7 +1359,6 @@ TextFrame::PaintAsciiText(nsIPresContext& aPresContext,
nsIDocument* doc = shell->GetDocument(); nsIDocument* doc = shell->GetDocument();
PRBool displaySelection; PRBool displaySelection;
displaySelection = doc->GetDisplaySelection(); displaySelection = doc->GetDisplaySelection();
displaySelection = PR_FALSE;
// Make enough space to transform // Make enough space to transform
PRUnichar wordBufMem[WORD_BUF_SIZE]; PRUnichar wordBufMem[WORD_BUF_SIZE];
@ -1393,7 +1392,7 @@ TextFrame::PaintAsciiText(nsIPresContext& aPresContext,
char* text = paintBuf; char* text = paintBuf;
if (0 != textLength) { if (0 != textLength) {
if (!displaySelection) { if (!displaySelection || !mSelected) {
// When there is no selection showing, use the fastest and // When there is no selection showing, use the fastest and
// simplest rendering approach // simplest rendering approach
aRenderingContext.DrawString(text, textLength, dx, dy, width); aRenderingContext.DrawString(text, textLength, dx, dy, width);
@ -1401,56 +1400,72 @@ TextFrame::PaintAsciiText(nsIPresContext& aPresContext,
dx, dy, width); dx, dy, width);
} }
else { else {
SelectionInfo si; /* SelectionInfo si;
// ComputeSelectionInfo(aRenderingContext, doc, ip, textLength, si); ComputeSelectionInfo(aRenderingContext, doc, ip, textLength, si);*/
nscoord textWidth; nscoord textWidth;
if (si.mEmptySelection) { if (mSelectionOffset < 0)
mSelectionOffset = 0;
if (mSelectionEnd < 0)
mSelectionEnd = mContentLength;
if (mSelectionOffset >= mContentLength)
mSelectionOffset = mContentLength;
PRInt32 selectionEnd = mSelectionEnd;
PRInt32 selectionOffset = mSelectionOffset;
if (mSelectionEnd < mSelectionOffset)
{
selectionEnd = mSelectionOffset;
selectionOffset = mSelectionEnd;
}
if (selectionOffset == selectionEnd){
aRenderingContext.DrawString(text, textLength, dx, dy, width); aRenderingContext.DrawString(text, textLength, dx, dy, width);
PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle, PaintTextDecorations(aRenderingContext, aStyleContext,
dx, dy, width); aTextStyle, dx, dy, width);
aRenderingContext.GetWidth(text, PRUint32(si.mStartOffset), textWidth); // aRenderingContext.GetWidth(text, PRUint32(si.mStartOffset), textWidth);
aRenderingContext.GetWidth(text, PRUint32(selectionOffset), textWidth);
RenderSelectionCursor(aRenderingContext, RenderSelectionCursor(aRenderingContext,
dx + textWidth, dy, mRect.height, dx + textWidth, dy, mRect.height,
CURSOR_COLOR); CURSOR_COLOR);
} }
else { else
{
nscoord x = dx; nscoord x = dx;
if (0 != si.mStartOffset) { if (selectionOffset) {
// Render first (unselected) section // Render first (unselected) section
aRenderingContext.GetWidth(text, PRUint32(si.mStartOffset), aRenderingContext.GetWidth(text, PRUint32(selectionOffset),//si.mStartOffset),
textWidth); textWidth);
aRenderingContext.DrawString(text, si.mStartOffset, aRenderingContext.DrawString(text, selectionOffset,
x, dy, textWidth); x, dy, textWidth);
PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle, PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle,
x, dy, textWidth); x, dy, textWidth);
x += textWidth; x += textWidth;
} }
PRInt32 secondLen = si.mEndOffset - si.mStartOffset; PRInt32 secondLen = selectionEnd - selectionOffset;
if (0 != secondLen) { if (0 != secondLen) {
// Get the width of the second (selected) section // Get the width of the second (selected) section
aRenderingContext.GetWidth(text + si.mStartOffset, aRenderingContext.GetWidth(text + selectionOffset,
PRUint32(secondLen), textWidth); PRUint32(secondLen), textWidth);
// Render second (selected) section // Render second (selected) section
aRenderingContext.SetColor(aTextStyle.mSelectionBGColor); aRenderingContext.SetColor(aTextStyle.mSelectionBGColor);
aRenderingContext.FillRect(x, dy, textWidth, mRect.height); aRenderingContext.FillRect(x, dy, textWidth, mRect.height);
aRenderingContext.SetColor(aTextStyle.mSelectionTextColor); aRenderingContext.SetColor(aTextStyle.mSelectionTextColor);
aRenderingContext.DrawString(text + si.mStartOffset, secondLen, aRenderingContext.DrawString(text + selectionOffset,
x, dy, textWidth); secondLen, x, dy, textWidth);
PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle, PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle,
x, dy, textWidth); x, dy, textWidth);
aRenderingContext.SetColor(aTextStyle.mColor->mColor); aRenderingContext.SetColor(aTextStyle.mColor->mColor);
x += textWidth; x += textWidth;
} }
if (textLength != si.mEndOffset) { if (textLength != selectionEnd) {
PRInt32 thirdLen = textLength - si.mEndOffset; PRInt32 thirdLen = textLength - selectionEnd;
// Render third (unselected) section // Render third (unselected) section
aRenderingContext.GetWidth(text + si.mEndOffset, PRUint32(thirdLen), aRenderingContext.GetWidth(text + selectionEnd, PRUint32(thirdLen),
textWidth); textWidth);
aRenderingContext.DrawString(text + si.mEndOffset, aRenderingContext.DrawString(text + selectionEnd,
thirdLen, x, dy, textWidth); thirdLen, x, dy, textWidth);
PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle, PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle,
x, dy, textWidth); x, dy, textWidth);
@ -1463,9 +1478,6 @@ TextFrame::PaintAsciiText(nsIPresContext& aPresContext,
if (paintBuf != paintBufMem) { if (paintBuf != paintBufMem) {
delete [] paintBuf; delete [] paintBuf;
} }
if (rawPaintBuf != rawPaintBufMem) {
delete [] rawPaintBuf;
}
if (ip != indicies) { if (ip != indicies) {
delete [] ip; delete [] ip;
} }

Просмотреть файл

@ -477,6 +477,7 @@ PresShell::Init(nsIDocument* aDocument,
if (!NS_SUCCEEDED(result)) if (!NS_SUCCEEDED(result))
return result; return result;
selection->Clear();//clear all old selection selection->Clear();//clear all old selection
#if 0
nsCOMPtr<nsIDOMRange>range; nsCOMPtr<nsIDOMRange>range;
if (NS_SUCCEEDED(nsRepository::CreateInstance(kCRangeCID, nsnull, kIDOMRangeIID, getter_AddRefs(range)))){ //create an irange if (NS_SUCCEEDED(nsRepository::CreateInstance(kCRangeCID, nsnull, kIDOMRangeIID, getter_AddRefs(range)))){ //create an irange
nsCOMPtr<nsIDocument>doc(GetDocument()); nsCOMPtr<nsIDocument>doc(GetDocument());
@ -496,6 +497,7 @@ PresShell::Init(nsIDocument* aDocument,
} }
} }
} }
#endif
mSelection = selection; mSelection = selection;
return NS_OK; return NS_OK;
} }

Просмотреть файл

@ -1359,7 +1359,6 @@ TextFrame::PaintAsciiText(nsIPresContext& aPresContext,
nsIDocument* doc = shell->GetDocument(); nsIDocument* doc = shell->GetDocument();
PRBool displaySelection; PRBool displaySelection;
displaySelection = doc->GetDisplaySelection(); displaySelection = doc->GetDisplaySelection();
displaySelection = PR_FALSE;
// Make enough space to transform // Make enough space to transform
PRUnichar wordBufMem[WORD_BUF_SIZE]; PRUnichar wordBufMem[WORD_BUF_SIZE];
@ -1393,7 +1392,7 @@ TextFrame::PaintAsciiText(nsIPresContext& aPresContext,
char* text = paintBuf; char* text = paintBuf;
if (0 != textLength) { if (0 != textLength) {
if (!displaySelection) { if (!displaySelection || !mSelected) {
// When there is no selection showing, use the fastest and // When there is no selection showing, use the fastest and
// simplest rendering approach // simplest rendering approach
aRenderingContext.DrawString(text, textLength, dx, dy, width); aRenderingContext.DrawString(text, textLength, dx, dy, width);
@ -1401,56 +1400,72 @@ TextFrame::PaintAsciiText(nsIPresContext& aPresContext,
dx, dy, width); dx, dy, width);
} }
else { else {
SelectionInfo si; /* SelectionInfo si;
// ComputeSelectionInfo(aRenderingContext, doc, ip, textLength, si); ComputeSelectionInfo(aRenderingContext, doc, ip, textLength, si);*/
nscoord textWidth; nscoord textWidth;
if (si.mEmptySelection) { if (mSelectionOffset < 0)
mSelectionOffset = 0;
if (mSelectionEnd < 0)
mSelectionEnd = mContentLength;
if (mSelectionOffset >= mContentLength)
mSelectionOffset = mContentLength;
PRInt32 selectionEnd = mSelectionEnd;
PRInt32 selectionOffset = mSelectionOffset;
if (mSelectionEnd < mSelectionOffset)
{
selectionEnd = mSelectionOffset;
selectionOffset = mSelectionEnd;
}
if (selectionOffset == selectionEnd){
aRenderingContext.DrawString(text, textLength, dx, dy, width); aRenderingContext.DrawString(text, textLength, dx, dy, width);
PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle, PaintTextDecorations(aRenderingContext, aStyleContext,
dx, dy, width); aTextStyle, dx, dy, width);
aRenderingContext.GetWidth(text, PRUint32(si.mStartOffset), textWidth); // aRenderingContext.GetWidth(text, PRUint32(si.mStartOffset), textWidth);
aRenderingContext.GetWidth(text, PRUint32(selectionOffset), textWidth);
RenderSelectionCursor(aRenderingContext, RenderSelectionCursor(aRenderingContext,
dx + textWidth, dy, mRect.height, dx + textWidth, dy, mRect.height,
CURSOR_COLOR); CURSOR_COLOR);
} }
else { else
{
nscoord x = dx; nscoord x = dx;
if (0 != si.mStartOffset) { if (selectionOffset) {
// Render first (unselected) section // Render first (unselected) section
aRenderingContext.GetWidth(text, PRUint32(si.mStartOffset), aRenderingContext.GetWidth(text, PRUint32(selectionOffset),//si.mStartOffset),
textWidth); textWidth);
aRenderingContext.DrawString(text, si.mStartOffset, aRenderingContext.DrawString(text, selectionOffset,
x, dy, textWidth); x, dy, textWidth);
PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle, PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle,
x, dy, textWidth); x, dy, textWidth);
x += textWidth; x += textWidth;
} }
PRInt32 secondLen = si.mEndOffset - si.mStartOffset; PRInt32 secondLen = selectionEnd - selectionOffset;
if (0 != secondLen) { if (0 != secondLen) {
// Get the width of the second (selected) section // Get the width of the second (selected) section
aRenderingContext.GetWidth(text + si.mStartOffset, aRenderingContext.GetWidth(text + selectionOffset,
PRUint32(secondLen), textWidth); PRUint32(secondLen), textWidth);
// Render second (selected) section // Render second (selected) section
aRenderingContext.SetColor(aTextStyle.mSelectionBGColor); aRenderingContext.SetColor(aTextStyle.mSelectionBGColor);
aRenderingContext.FillRect(x, dy, textWidth, mRect.height); aRenderingContext.FillRect(x, dy, textWidth, mRect.height);
aRenderingContext.SetColor(aTextStyle.mSelectionTextColor); aRenderingContext.SetColor(aTextStyle.mSelectionTextColor);
aRenderingContext.DrawString(text + si.mStartOffset, secondLen, aRenderingContext.DrawString(text + selectionOffset,
x, dy, textWidth); secondLen, x, dy, textWidth);
PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle, PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle,
x, dy, textWidth); x, dy, textWidth);
aRenderingContext.SetColor(aTextStyle.mColor->mColor); aRenderingContext.SetColor(aTextStyle.mColor->mColor);
x += textWidth; x += textWidth;
} }
if (textLength != si.mEndOffset) { if (textLength != selectionEnd) {
PRInt32 thirdLen = textLength - si.mEndOffset; PRInt32 thirdLen = textLength - selectionEnd;
// Render third (unselected) section // Render third (unselected) section
aRenderingContext.GetWidth(text + si.mEndOffset, PRUint32(thirdLen), aRenderingContext.GetWidth(text + selectionEnd, PRUint32(thirdLen),
textWidth); textWidth);
aRenderingContext.DrawString(text + si.mEndOffset, aRenderingContext.DrawString(text + selectionEnd,
thirdLen, x, dy, textWidth); thirdLen, x, dy, textWidth);
PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle, PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle,
x, dy, textWidth); x, dy, textWidth);
@ -1463,9 +1478,6 @@ TextFrame::PaintAsciiText(nsIPresContext& aPresContext,
if (paintBuf != paintBufMem) { if (paintBuf != paintBufMem) {
delete [] paintBuf; delete [] paintBuf;
} }
if (rawPaintBuf != rawPaintBufMem) {
delete [] rawPaintBuf;
}
if (ip != indicies) { if (ip != indicies) {
delete [] ip; delete [] ip;
} }