66318 bug for api change of editor unicode not needed. nsAReadableString is what we need now.

This commit is contained in:
mjudge%netscape.com 2001-04-07 00:48:44 +00:00
parent aa665a57f4
commit c950145d10
2 changed files with 90 additions and 36 deletions

View File

@ -22,7 +22,6 @@
* Blake Ross <blakeross@telocity.com>
*/
#ifdef ENDER_LITE
#include "nsCOMPtr.h"
#include "nsGfxTextControlFrame2.h"
@ -99,6 +98,8 @@
#include "nsITransactionManager.h"
#include "nsITransactionListener.h"
#include "nsIDOMText.h" //for multiline getselection
#ifdef IBMBIDI
#include "nsIBidiKeyboard.h"
@ -934,7 +935,7 @@ NS_IMETHODIMP
nsTextInputSelectionImpl::HandleTableSelection(nsIContent *aParentContent, PRInt32 aContentOffset, PRInt32 aTarget, nsMouseEvent *aMouseEvent)
{
// We should never have a table inside a text control frame!
NS_ASSERTION(PR_TRUE, "Calling HandleTableSelection inside nsGfxTextControlFrame!");
NS_ASSERTION(PR_TRUE, "Calling HandleTableSelection inside nsGfxTextControlFrame2!");
return NS_OK;
}
@ -2666,42 +2667,97 @@ nsGfxTextControlFrame2::SetSelectionEnd(PRInt32 aSelectionEnd)
NS_IMETHODIMP
nsGfxTextControlFrame2::GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd)
{
if (!IsSingleLineTextControl()) return NS_ERROR_NOT_IMPLEMENTED;
NS_ENSURE_ARG_POINTER((aSelectionStart && aSelectionEnd));
NS_ENSURE_ARG_POINTER((aSelectionStart && aSelectionEnd));
// make sure we have an editor
if (!mEditor)
return NS_ERROR_NOT_INITIALIZED;
// make sure we have an editor
if (!mEditor)
return NS_ERROR_NOT_INITIALIZED;
nsCOMPtr<nsISelection> selection;
mTextSelImpl->GetSelection(nsISelectionController::SELECTION_NORMAL,getter_AddRefs(selection));
if (!selection) return NS_ERROR_FAILURE;
// we should have only zero or one range
PRInt32 numRanges = 0;
selection->GetRangeCount(&numRanges);
if (numRanges > 1)
{
NS_ASSERTION(0, "Found more than on range in GetSelectionRange");
}
if (numRanges == 0)
{
*aSelectionStart = 0;
*aSelectionEnd = 0;
}
else
{
nsCOMPtr<nsIDOMRange> firstRange;
selection->GetRangeAt(0, getter_AddRefs(firstRange));
if (!firstRange)
return NS_ERROR_FAILURE;
firstRange->GetStartOffset(aSelectionStart);
firstRange->GetEndOffset(aSelectionEnd);
}
nsCOMPtr<nsISelection> selection;
mTextSelImpl->GetSelection(nsISelectionController::SELECTION_NORMAL,getter_AddRefs(selection));
if (!selection) return NS_ERROR_FAILURE;
// we should have only zero or one range
PRInt32 numRanges = 0;
selection->GetRangeCount(&numRanges);
if (numRanges > 1)
{
NS_ASSERTION(0, "Found more than on range in GetSelectionRange");
}
return NS_OK;
if (numRanges != 0)
{
nsCOMPtr<nsIDOMRange> firstRange;
selection->GetRangeAt(0, getter_AddRefs(firstRange));
if (!firstRange)
return NS_ERROR_FAILURE;
if (IsSingleLineTextControl())
{
firstRange->GetStartOffset(aSelectionStart);
firstRange->GetEndOffset(aSelectionEnd);
}
else//multiline
{
//mContent = parent. iterate over each child.
//when text nodes are reached add text length.
//if you find range-startoffset,startnode then mark aSelecitonStart
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMNode> contentNode;
nsCOMPtr<nsIDOMNode> curNode;
contentNode = do_QueryInterface(mContent);
if (!contentNode || NS_FAILED(rv = contentNode->GetFirstChild(getter_AddRefs(curNode))) || !curNode)
return rv;
nsCOMPtr<nsIDOMNode> startParent;
nsCOMPtr<nsIDOMNode> endParent;
PRInt32 startOffset;
PRInt32 endOffset;
firstRange->GetStartContainer(getter_AddRefs(startParent));
firstRange->GetStartOffset(&startOffset);
firstRange->GetEndContainer(getter_AddRefs(endParent));
firstRange->GetEndOffset(&endOffset);
PRInt32 currentTextOffset = 0;
while(curNode)
{
nsCOMPtr<nsIDOMText> domText;
domText = do_QueryInterface(curNode);
if (contentNode == startParent)
{
if (domText)
*aSelectionStart = currentTextOffset + startOffset;
else
*aSelectionStart = currentTextOffset;
}
if (curNode == endParent)
{
if (domText)
*aSelectionEnd = currentTextOffset + endOffset;
else
*aSelectionEnd = currentTextOffset;
break;
}
if (domText)
{
PRUint32 length;
if (NS_SUCCEEDED(domText->GetLength(&length)))
currentTextOffset += length;
}
else
++currentTextOffset;
}
if (!curNode) //something went very wrong...
{
*aSelectionEnd = *aSelectionStart;//couldnt find the end
}
}
}
return NS_OK;
}
@ -3097,7 +3153,7 @@ nsGfxTextControlFrame2::SetTextControlFrameState(const nsAReadableString& aValue
else {
nsCOMPtr<nsIPlaintextEditor> textEditor = do_QueryInterface(mEditor);
if (textEditor)
textEditor->InsertText(currentValue.GetUnicode());
textEditor->InsertText(currentValue);
}
mEditor->SetFlags(savedFlags);
if (selPriv)
@ -3303,4 +3359,3 @@ nsGfxTextControlFrame2::IsScrollable() const
return PR_FALSE;
}
#endif

View File

@ -38,7 +38,6 @@
#include "nsIScrollableViewProvider.h"
class nsIPresState;
class nsGfxTextControlFrame;
class nsFormFrame;
class nsISupportsArray;
class nsIHTMLContent;