From d822833720abbe2fe587de295c7d3ee04696e5cd Mon Sep 17 00:00:00 2001 From: "smontagu%netscape.com" Date: Thu, 9 Jan 2003 01:01:38 +0000 Subject: [PATCH] Caret not displayed in empty right-aligned text input fields. Bug 105397, r=kin, sr=sfraser. git-svn-id: svn://10.0.0.236/trunk@136041 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/base/nsCaret.cpp | 36 ++++++++++++++++++++++++----- mozilla/layout/base/src/nsCaret.cpp | 36 ++++++++++++++++++++++++----- 2 files changed, 60 insertions(+), 12 deletions(-) diff --git a/mozilla/layout/base/nsCaret.cpp b/mozilla/layout/base/nsCaret.cpp index 25223d64e9a..73f35b14d87 100644 --- a/mozilla/layout/base/nsCaret.cpp +++ b/mozilla/layout/base/nsCaret.cpp @@ -1049,15 +1049,39 @@ void nsCaret::DrawCaret() // erased properly if the frame's right edge gets // invalidated. - nscoord cX = caretRect.x + caretRect.width; - nscoord fX = frameRect.x + frameRect.width; + nscoord caretXMost = caretRect.XMost(); + nscoord frameXMost = frameRect.XMost(); - if (caretRect.x <= fX && cX > fX) + if (caretRect.x <= frameXMost && caretXMost > frameXMost) { - caretRect.x -= cX - fX; + caretRect.x -= caretXMost - frameXMost; - if (caretRect.x < frameRect.x) - caretRect.x = frameRect.x; + const nsStyleVisibility* vis; + const nsStyleText* textStyle; + mLastCaretFrame->GetStyleData(eStyleStruct_Text, (const nsStyleStruct*&)textStyle); + mLastCaretFrame->GetStyleData(eStyleStruct_Visibility, (const nsStyleStruct*&)vis); + + if ((vis->mDirection == NS_STYLE_DIRECTION_LTR && + textStyle->mTextAlign == NS_STYLE_TEXT_ALIGN_RIGHT) || + (vis->mDirection == NS_STYLE_DIRECTION_RTL && + textStyle->mTextAlign == NS_STYLE_TEXT_ALIGN_DEFAULT)) + { + // If the frame is aligned right, stick the caret to the left + // edge of the frame. + if (caretRect.XMost() >= frameXMost) + { + caretRect.x = frameXMost - caretRect.width - 1; + } + } + else + { + // If the frame is aligned left, stick the caret to the right + // edge of the frame. + if (caretRect.x < frameRect.x) + { + caretRect.x = frameRect.x; + } + } } mCaretRect.IntersectRect(clipRect, caretRect); diff --git a/mozilla/layout/base/src/nsCaret.cpp b/mozilla/layout/base/src/nsCaret.cpp index 25223d64e9a..73f35b14d87 100644 --- a/mozilla/layout/base/src/nsCaret.cpp +++ b/mozilla/layout/base/src/nsCaret.cpp @@ -1049,15 +1049,39 @@ void nsCaret::DrawCaret() // erased properly if the frame's right edge gets // invalidated. - nscoord cX = caretRect.x + caretRect.width; - nscoord fX = frameRect.x + frameRect.width; + nscoord caretXMost = caretRect.XMost(); + nscoord frameXMost = frameRect.XMost(); - if (caretRect.x <= fX && cX > fX) + if (caretRect.x <= frameXMost && caretXMost > frameXMost) { - caretRect.x -= cX - fX; + caretRect.x -= caretXMost - frameXMost; - if (caretRect.x < frameRect.x) - caretRect.x = frameRect.x; + const nsStyleVisibility* vis; + const nsStyleText* textStyle; + mLastCaretFrame->GetStyleData(eStyleStruct_Text, (const nsStyleStruct*&)textStyle); + mLastCaretFrame->GetStyleData(eStyleStruct_Visibility, (const nsStyleStruct*&)vis); + + if ((vis->mDirection == NS_STYLE_DIRECTION_LTR && + textStyle->mTextAlign == NS_STYLE_TEXT_ALIGN_RIGHT) || + (vis->mDirection == NS_STYLE_DIRECTION_RTL && + textStyle->mTextAlign == NS_STYLE_TEXT_ALIGN_DEFAULT)) + { + // If the frame is aligned right, stick the caret to the left + // edge of the frame. + if (caretRect.XMost() >= frameXMost) + { + caretRect.x = frameXMost - caretRect.width - 1; + } + } + else + { + // If the frame is aligned left, stick the caret to the right + // edge of the frame. + if (caretRect.x < frameRect.x) + { + caretRect.x = frameRect.x; + } + } } mCaretRect.IntersectRect(clipRect, caretRect);