зеркало из https://github.com/mozilla/pjs.git
Moved GetTextSelectionOffsets and GetDocumentLength from nsTextEditRules to
nsTextEditor. Added GetDocumentLength to nsITextEditor public interface.
This commit is contained in:
Родитель
0607a1d128
Коммит
02532a080a
|
@ -243,7 +243,7 @@ nsTextEditRules::WillInsertText(nsIDOMSelection *aSelection,
|
||||||
// if len(doc) is at or over max, cancel the insert
|
// if len(doc) is at or over max, cancel the insert
|
||||||
// if l(doc) + l(input) > max, set aOutString to subset of inString so length = max
|
// if l(doc) + l(input) > max, set aOutString to subset of inString so length = max
|
||||||
PRInt32 docLength;
|
PRInt32 docLength;
|
||||||
result = GetLengthOfDocumentInCharacters(docLength);
|
result = mEditor->GetDocumentLength(&docLength);
|
||||||
if (NS_SUCCEEDED(result))
|
if (NS_SUCCEEDED(result))
|
||||||
{
|
{
|
||||||
if (docLength >= aMaxLength)
|
if (docLength >= aMaxLength)
|
||||||
|
@ -272,7 +272,7 @@ nsTextEditRules::WillInsertText(nsIDOMSelection *aSelection,
|
||||||
{
|
{
|
||||||
// manage the password buffer
|
// manage the password buffer
|
||||||
PRInt32 start, end;
|
PRInt32 start, end;
|
||||||
result = GetTextSelectionOffsets(aSelection, start, end);
|
result = mEditor->GetTextSelectionOffsets(aSelection, start, end);
|
||||||
NS_ASSERTION((NS_SUCCEEDED(result)), "getTextSelectionOffsets failed!");
|
NS_ASSERTION((NS_SUCCEEDED(result)), "getTextSelectionOffsets failed!");
|
||||||
mPasswordText.Insert(inString, start);
|
mPasswordText.Insert(inString, start);
|
||||||
|
|
||||||
|
@ -346,7 +346,7 @@ nsTextEditRules::CreateStyleForInsertText(nsIDOMSelection *aSelection, TypeInSta
|
||||||
{
|
{
|
||||||
PRUint32 length;
|
PRUint32 length;
|
||||||
anchorAsText->GetLength(&length);
|
anchorAsText->GetLength(&length);
|
||||||
if (length==offset)
|
if (length==(PRUint32)offset)
|
||||||
{
|
{
|
||||||
// newTextNode will be the left node
|
// newTextNode will be the left node
|
||||||
result = mEditor->SplitNode(anchorAsText, offset, getter_AddRefs(newTextNode));
|
result = mEditor->SplitNode(anchorAsText, offset, getter_AddRefs(newTextNode));
|
||||||
|
@ -626,7 +626,7 @@ nsTextEditRules::WillDeleteSelection(nsIDOMSelection *aSelection,
|
||||||
{
|
{
|
||||||
// manage the password buffer
|
// manage the password buffer
|
||||||
PRInt32 start, end;
|
PRInt32 start, end;
|
||||||
GetTextSelectionOffsets(aSelection, start, end);
|
mEditor->GetTextSelectionOffsets(aSelection, start, end);
|
||||||
if (end==start)
|
if (end==start)
|
||||||
{ // collapsed selection
|
{ // collapsed selection
|
||||||
if (nsIEditor::eDeleteLeft==aCollapsedAction && 0<start) { // del back
|
if (nsIEditor::eDeleteLeft==aCollapsedAction && 0<start) { // del back
|
||||||
|
@ -925,116 +925,3 @@ nsTextEditRules::CreateBogusNodeIfNeeded(nsIDOMSelection *aSelection)
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult nsTextEditRules::GetLengthOfDocumentInCharacters(PRInt32 &aCount)
|
|
||||||
{
|
|
||||||
nsresult result;
|
|
||||||
// initialize out params
|
|
||||||
aCount = 0;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMSelection> sel;
|
|
||||||
mEditor->GetSelection(getter_AddRefs(sel));
|
|
||||||
if ((NS_SUCCEEDED(result)) && sel)
|
|
||||||
{
|
|
||||||
nsAutoSelectionReset selectionResetter(sel);
|
|
||||||
result = mEditor->SelectAll();
|
|
||||||
if (NS_SUCCEEDED(result))
|
|
||||||
{
|
|
||||||
PRInt32 start, end;
|
|
||||||
result = GetTextSelectionOffsets(sel, start, end);
|
|
||||||
if (NS_SUCCEEDED(result))
|
|
||||||
{
|
|
||||||
NS_ASSERTION(0==start, "GetTextSelectionOffsets failed to set start correctly.");
|
|
||||||
NS_ASSERTION(0<=end, "GetTextSelectionOffsets failed to set end correctly.");
|
|
||||||
if (0<=end) {
|
|
||||||
aCount = end;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// this is a complete ripoff from nsTextEditor::GetTextSelectionOffsetsForRange
|
|
||||||
// the two should use common code, or even just be one method
|
|
||||||
nsresult nsTextEditRules::GetTextSelectionOffsets(nsIDOMSelection *aSelection,
|
|
||||||
PRInt32 &aStartOffset,
|
|
||||||
PRInt32 &aEndOffset)
|
|
||||||
{
|
|
||||||
nsresult result;
|
|
||||||
// initialize out params
|
|
||||||
aStartOffset = 0; // default to first char in selection
|
|
||||||
aEndOffset = -1; // default to total length of text in selection
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> startNode, endNode, parentNode;
|
|
||||||
PRInt32 startOffset, endOffset;
|
|
||||||
aSelection->GetAnchorNode(getter_AddRefs(startNode));
|
|
||||||
aSelection->GetAnchorOffset(&startOffset);
|
|
||||||
aSelection->GetFocusNode(getter_AddRefs(endNode));
|
|
||||||
aSelection->GetFocusOffset(&endOffset);
|
|
||||||
|
|
||||||
nsCOMPtr<nsIEnumerator> enumerator;
|
|
||||||
enumerator = do_QueryInterface(aSelection);
|
|
||||||
if (enumerator)
|
|
||||||
{
|
|
||||||
// don't use "result" in this block
|
|
||||||
enumerator->First();
|
|
||||||
nsISupports *currentItem;
|
|
||||||
nsresult findParentResult = enumerator->CurrentItem(¤tItem);
|
|
||||||
if ((NS_SUCCEEDED(findParentResult)) && (nsnull!=currentItem))
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
|
|
||||||
range->GetCommonParent(getter_AddRefs(parentNode));
|
|
||||||
}
|
|
||||||
else parentNode = do_QueryInterface(startNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIContentIterator> iter;
|
|
||||||
result = nsComponentManager::CreateInstance(kCContentIteratorCID, nsnull,
|
|
||||||
nsIContentIterator::GetIID(),
|
|
||||||
getter_AddRefs(iter));
|
|
||||||
if ((NS_SUCCEEDED(result)) && iter)
|
|
||||||
{
|
|
||||||
PRUint32 totalLength=0;
|
|
||||||
nsCOMPtr<nsIDOMCharacterData>textNode;
|
|
||||||
nsCOMPtr<nsIContent>blockParentContent = do_QueryInterface(parentNode);
|
|
||||||
iter->Init(blockParentContent);
|
|
||||||
// loop through the content iterator for each content node
|
|
||||||
nsCOMPtr<nsIContent> content;
|
|
||||||
result = iter->CurrentNode(getter_AddRefs(content));
|
|
||||||
while (NS_COMFALSE == iter->IsDone())
|
|
||||||
{
|
|
||||||
textNode = do_QueryInterface(content);
|
|
||||||
if (textNode)
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIDOMNode>currentNode = do_QueryInterface(textNode);
|
|
||||||
if (!currentNode) {return NS_ERROR_NO_INTERFACE;}
|
|
||||||
if (PR_TRUE==mEditor->IsEditable(currentNode))
|
|
||||||
{
|
|
||||||
if (currentNode.get() == startNode.get())
|
|
||||||
{
|
|
||||||
aStartOffset = totalLength + startOffset;
|
|
||||||
}
|
|
||||||
if (currentNode.get() == endNode.get())
|
|
||||||
{
|
|
||||||
aEndOffset = totalLength + endOffset;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
PRUint32 length;
|
|
||||||
textNode->GetLength(&length);
|
|
||||||
totalLength += length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
iter->Next();
|
|
||||||
iter->CurrentNode(getter_AddRefs(content));
|
|
||||||
}
|
|
||||||
if (-1==aEndOffset) {
|
|
||||||
aEndOffset = totalLength;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -150,16 +150,6 @@ protected:
|
||||||
/** creates a bogus text node if the document has no editable content */
|
/** creates a bogus text node if the document has no editable content */
|
||||||
nsresult CreateBogusNodeIfNeeded(nsIDOMSelection *aSelection);
|
nsresult CreateBogusNodeIfNeeded(nsIDOMSelection *aSelection);
|
||||||
|
|
||||||
/** set aCount to the number of characters in the document. */
|
|
||||||
nsresult GetLengthOfDocumentInCharacters(PRInt32 &aCount);
|
|
||||||
|
|
||||||
/** returns the absolute position of the end points of aSelection
|
|
||||||
* in the document as a text stream.
|
|
||||||
*/
|
|
||||||
nsresult GetTextSelectionOffsets(nsIDOMSelection *aSelection,
|
|
||||||
PRInt32 &aStartOffset,
|
|
||||||
PRInt32 &aEndOffset);
|
|
||||||
|
|
||||||
// data
|
// data
|
||||||
nsTextEditor *mEditor; // note that we do not refcount the editor
|
nsTextEditor *mEditor; // note that we do not refcount the editor
|
||||||
nsString mPasswordText; // a buffer we use to store the real value of password editors
|
nsString mPasswordText; // a buffer we use to store the real value of password editors
|
||||||
|
|
|
@ -2817,3 +2817,120 @@ nsTextEditor::StopLogging()
|
||||||
return nsEditor::StopLogging();
|
return nsEditor::StopLogging();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsTextEditor::GetDocumentLength(PRInt32 *aCount)
|
||||||
|
{
|
||||||
|
if (!aCount) { return NS_ERROR_NULL_POINTER; }
|
||||||
|
nsresult result;
|
||||||
|
// initialize out params
|
||||||
|
*aCount = 0;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIDOMSelection> sel;
|
||||||
|
GetSelection(getter_AddRefs(sel));
|
||||||
|
if ((NS_SUCCEEDED(result)) && sel)
|
||||||
|
{
|
||||||
|
nsAutoSelectionReset selectionResetter(sel);
|
||||||
|
result = SelectAll();
|
||||||
|
if (NS_SUCCEEDED(result))
|
||||||
|
{
|
||||||
|
PRInt32 start, end;
|
||||||
|
result = GetTextSelectionOffsets(sel, start, end);
|
||||||
|
if (NS_SUCCEEDED(result))
|
||||||
|
{
|
||||||
|
NS_ASSERTION(0==start, "GetTextSelectionOffsets failed to set start correctly.");
|
||||||
|
NS_ASSERTION(0<=end, "GetTextSelectionOffsets failed to set end correctly.");
|
||||||
|
if (0<=end) {
|
||||||
|
*aCount = end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// this is a complete ripoff from nsTextEditor::GetTextSelectionOffsetsForRange
|
||||||
|
// the two should use common code, or even just be one method
|
||||||
|
nsresult nsTextEditor::GetTextSelectionOffsets(nsIDOMSelection *aSelection,
|
||||||
|
PRInt32 &aStartOffset,
|
||||||
|
PRInt32 &aEndOffset)
|
||||||
|
{
|
||||||
|
nsresult result;
|
||||||
|
// initialize out params
|
||||||
|
aStartOffset = 0; // default to first char in selection
|
||||||
|
aEndOffset = -1; // default to total length of text in selection
|
||||||
|
|
||||||
|
nsCOMPtr<nsIDOMNode> startNode, endNode, parentNode;
|
||||||
|
PRInt32 startOffset, endOffset;
|
||||||
|
aSelection->GetAnchorNode(getter_AddRefs(startNode));
|
||||||
|
aSelection->GetAnchorOffset(&startOffset);
|
||||||
|
aSelection->GetFocusNode(getter_AddRefs(endNode));
|
||||||
|
aSelection->GetFocusOffset(&endOffset);
|
||||||
|
|
||||||
|
nsCOMPtr<nsIEnumerator> enumerator;
|
||||||
|
enumerator = do_QueryInterface(aSelection);
|
||||||
|
if (enumerator)
|
||||||
|
{
|
||||||
|
// don't use "result" in this block
|
||||||
|
enumerator->First();
|
||||||
|
nsISupports *currentItem;
|
||||||
|
nsresult findParentResult = enumerator->CurrentItem(¤tItem);
|
||||||
|
if ((NS_SUCCEEDED(findParentResult)) && (nsnull!=currentItem))
|
||||||
|
{
|
||||||
|
nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
|
||||||
|
range->GetCommonParent(getter_AddRefs(parentNode));
|
||||||
|
}
|
||||||
|
else parentNode = do_QueryInterface(startNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIContentIterator> iter;
|
||||||
|
result = nsComponentManager::CreateInstance(kCContentIteratorCID, nsnull,
|
||||||
|
nsIContentIterator::GetIID(),
|
||||||
|
getter_AddRefs(iter));
|
||||||
|
if ((NS_SUCCEEDED(result)) && iter)
|
||||||
|
{
|
||||||
|
PRUint32 totalLength=0;
|
||||||
|
nsCOMPtr<nsIDOMCharacterData>textNode;
|
||||||
|
nsCOMPtr<nsIContent>blockParentContent = do_QueryInterface(parentNode);
|
||||||
|
iter->Init(blockParentContent);
|
||||||
|
// loop through the content iterator for each content node
|
||||||
|
nsCOMPtr<nsIContent> content;
|
||||||
|
result = iter->CurrentNode(getter_AddRefs(content));
|
||||||
|
while (NS_COMFALSE == iter->IsDone())
|
||||||
|
{
|
||||||
|
textNode = do_QueryInterface(content);
|
||||||
|
if (textNode)
|
||||||
|
{
|
||||||
|
nsCOMPtr<nsIDOMNode>currentNode = do_QueryInterface(textNode);
|
||||||
|
if (!currentNode) {return NS_ERROR_NO_INTERFACE;}
|
||||||
|
if (PR_TRUE==IsEditable(currentNode))
|
||||||
|
{
|
||||||
|
if (currentNode.get() == startNode.get())
|
||||||
|
{
|
||||||
|
aStartOffset = totalLength + startOffset;
|
||||||
|
}
|
||||||
|
if (currentNode.get() == endNode.get())
|
||||||
|
{
|
||||||
|
aEndOffset = totalLength + endOffset;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
PRUint32 length;
|
||||||
|
textNode->GetLength(&length);
|
||||||
|
totalLength += length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
iter->Next();
|
||||||
|
iter->CurrentNode(getter_AddRefs(content));
|
||||||
|
}
|
||||||
|
if (-1==aEndOffset) {
|
||||||
|
aEndOffset = totalLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,8 @@ public:
|
||||||
|
|
||||||
NS_IMETHOD GetFlags(PRUint32 *aFlags);
|
NS_IMETHOD GetFlags(PRUint32 *aFlags);
|
||||||
NS_IMETHOD SetFlags(PRUint32 aFlags);
|
NS_IMETHOD SetFlags(PRUint32 aFlags);
|
||||||
|
NS_IMETHOD GetDocumentLength(PRInt32 *aCount);
|
||||||
|
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
// Methods that are duplicates of nsEditor -- exposed here for convenience
|
// Methods that are duplicates of nsEditor -- exposed here for convenience
|
||||||
|
@ -273,6 +275,13 @@ protected:
|
||||||
PRInt32 aStartOffset,
|
PRInt32 aStartOffset,
|
||||||
PRInt32 aEndOffset,
|
PRInt32 aEndOffset,
|
||||||
nsIDOMSelection *aSelection);
|
nsIDOMSelection *aSelection);
|
||||||
|
|
||||||
|
/** returns the absolute position of the end points of aSelection
|
||||||
|
* in the document as a text stream.
|
||||||
|
*/
|
||||||
|
nsresult GetTextSelectionOffsets(nsIDOMSelection *aSelection,
|
||||||
|
PRInt32 &aStartOffset,
|
||||||
|
PRInt32 &aEndOffset);
|
||||||
|
|
||||||
|
|
||||||
TypeInState *GetTypeInState();
|
TypeInState *GetTypeInState();
|
||||||
|
|
|
@ -243,7 +243,7 @@ nsTextEditRules::WillInsertText(nsIDOMSelection *aSelection,
|
||||||
// if len(doc) is at or over max, cancel the insert
|
// if len(doc) is at or over max, cancel the insert
|
||||||
// if l(doc) + l(input) > max, set aOutString to subset of inString so length = max
|
// if l(doc) + l(input) > max, set aOutString to subset of inString so length = max
|
||||||
PRInt32 docLength;
|
PRInt32 docLength;
|
||||||
result = GetLengthOfDocumentInCharacters(docLength);
|
result = mEditor->GetDocumentLength(&docLength);
|
||||||
if (NS_SUCCEEDED(result))
|
if (NS_SUCCEEDED(result))
|
||||||
{
|
{
|
||||||
if (docLength >= aMaxLength)
|
if (docLength >= aMaxLength)
|
||||||
|
@ -272,7 +272,7 @@ nsTextEditRules::WillInsertText(nsIDOMSelection *aSelection,
|
||||||
{
|
{
|
||||||
// manage the password buffer
|
// manage the password buffer
|
||||||
PRInt32 start, end;
|
PRInt32 start, end;
|
||||||
result = GetTextSelectionOffsets(aSelection, start, end);
|
result = mEditor->GetTextSelectionOffsets(aSelection, start, end);
|
||||||
NS_ASSERTION((NS_SUCCEEDED(result)), "getTextSelectionOffsets failed!");
|
NS_ASSERTION((NS_SUCCEEDED(result)), "getTextSelectionOffsets failed!");
|
||||||
mPasswordText.Insert(inString, start);
|
mPasswordText.Insert(inString, start);
|
||||||
|
|
||||||
|
@ -346,7 +346,7 @@ nsTextEditRules::CreateStyleForInsertText(nsIDOMSelection *aSelection, TypeInSta
|
||||||
{
|
{
|
||||||
PRUint32 length;
|
PRUint32 length;
|
||||||
anchorAsText->GetLength(&length);
|
anchorAsText->GetLength(&length);
|
||||||
if (length==offset)
|
if (length==(PRUint32)offset)
|
||||||
{
|
{
|
||||||
// newTextNode will be the left node
|
// newTextNode will be the left node
|
||||||
result = mEditor->SplitNode(anchorAsText, offset, getter_AddRefs(newTextNode));
|
result = mEditor->SplitNode(anchorAsText, offset, getter_AddRefs(newTextNode));
|
||||||
|
@ -626,7 +626,7 @@ nsTextEditRules::WillDeleteSelection(nsIDOMSelection *aSelection,
|
||||||
{
|
{
|
||||||
// manage the password buffer
|
// manage the password buffer
|
||||||
PRInt32 start, end;
|
PRInt32 start, end;
|
||||||
GetTextSelectionOffsets(aSelection, start, end);
|
mEditor->GetTextSelectionOffsets(aSelection, start, end);
|
||||||
if (end==start)
|
if (end==start)
|
||||||
{ // collapsed selection
|
{ // collapsed selection
|
||||||
if (nsIEditor::eDeleteLeft==aCollapsedAction && 0<start) { // del back
|
if (nsIEditor::eDeleteLeft==aCollapsedAction && 0<start) { // del back
|
||||||
|
@ -925,116 +925,3 @@ nsTextEditRules::CreateBogusNodeIfNeeded(nsIDOMSelection *aSelection)
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult nsTextEditRules::GetLengthOfDocumentInCharacters(PRInt32 &aCount)
|
|
||||||
{
|
|
||||||
nsresult result;
|
|
||||||
// initialize out params
|
|
||||||
aCount = 0;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMSelection> sel;
|
|
||||||
mEditor->GetSelection(getter_AddRefs(sel));
|
|
||||||
if ((NS_SUCCEEDED(result)) && sel)
|
|
||||||
{
|
|
||||||
nsAutoSelectionReset selectionResetter(sel);
|
|
||||||
result = mEditor->SelectAll();
|
|
||||||
if (NS_SUCCEEDED(result))
|
|
||||||
{
|
|
||||||
PRInt32 start, end;
|
|
||||||
result = GetTextSelectionOffsets(sel, start, end);
|
|
||||||
if (NS_SUCCEEDED(result))
|
|
||||||
{
|
|
||||||
NS_ASSERTION(0==start, "GetTextSelectionOffsets failed to set start correctly.");
|
|
||||||
NS_ASSERTION(0<=end, "GetTextSelectionOffsets failed to set end correctly.");
|
|
||||||
if (0<=end) {
|
|
||||||
aCount = end;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// this is a complete ripoff from nsTextEditor::GetTextSelectionOffsetsForRange
|
|
||||||
// the two should use common code, or even just be one method
|
|
||||||
nsresult nsTextEditRules::GetTextSelectionOffsets(nsIDOMSelection *aSelection,
|
|
||||||
PRInt32 &aStartOffset,
|
|
||||||
PRInt32 &aEndOffset)
|
|
||||||
{
|
|
||||||
nsresult result;
|
|
||||||
// initialize out params
|
|
||||||
aStartOffset = 0; // default to first char in selection
|
|
||||||
aEndOffset = -1; // default to total length of text in selection
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> startNode, endNode, parentNode;
|
|
||||||
PRInt32 startOffset, endOffset;
|
|
||||||
aSelection->GetAnchorNode(getter_AddRefs(startNode));
|
|
||||||
aSelection->GetAnchorOffset(&startOffset);
|
|
||||||
aSelection->GetFocusNode(getter_AddRefs(endNode));
|
|
||||||
aSelection->GetFocusOffset(&endOffset);
|
|
||||||
|
|
||||||
nsCOMPtr<nsIEnumerator> enumerator;
|
|
||||||
enumerator = do_QueryInterface(aSelection);
|
|
||||||
if (enumerator)
|
|
||||||
{
|
|
||||||
// don't use "result" in this block
|
|
||||||
enumerator->First();
|
|
||||||
nsISupports *currentItem;
|
|
||||||
nsresult findParentResult = enumerator->CurrentItem(¤tItem);
|
|
||||||
if ((NS_SUCCEEDED(findParentResult)) && (nsnull!=currentItem))
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
|
|
||||||
range->GetCommonParent(getter_AddRefs(parentNode));
|
|
||||||
}
|
|
||||||
else parentNode = do_QueryInterface(startNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIContentIterator> iter;
|
|
||||||
result = nsComponentManager::CreateInstance(kCContentIteratorCID, nsnull,
|
|
||||||
nsIContentIterator::GetIID(),
|
|
||||||
getter_AddRefs(iter));
|
|
||||||
if ((NS_SUCCEEDED(result)) && iter)
|
|
||||||
{
|
|
||||||
PRUint32 totalLength=0;
|
|
||||||
nsCOMPtr<nsIDOMCharacterData>textNode;
|
|
||||||
nsCOMPtr<nsIContent>blockParentContent = do_QueryInterface(parentNode);
|
|
||||||
iter->Init(blockParentContent);
|
|
||||||
// loop through the content iterator for each content node
|
|
||||||
nsCOMPtr<nsIContent> content;
|
|
||||||
result = iter->CurrentNode(getter_AddRefs(content));
|
|
||||||
while (NS_COMFALSE == iter->IsDone())
|
|
||||||
{
|
|
||||||
textNode = do_QueryInterface(content);
|
|
||||||
if (textNode)
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIDOMNode>currentNode = do_QueryInterface(textNode);
|
|
||||||
if (!currentNode) {return NS_ERROR_NO_INTERFACE;}
|
|
||||||
if (PR_TRUE==mEditor->IsEditable(currentNode))
|
|
||||||
{
|
|
||||||
if (currentNode.get() == startNode.get())
|
|
||||||
{
|
|
||||||
aStartOffset = totalLength + startOffset;
|
|
||||||
}
|
|
||||||
if (currentNode.get() == endNode.get())
|
|
||||||
{
|
|
||||||
aEndOffset = totalLength + endOffset;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
PRUint32 length;
|
|
||||||
textNode->GetLength(&length);
|
|
||||||
totalLength += length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
iter->Next();
|
|
||||||
iter->CurrentNode(getter_AddRefs(content));
|
|
||||||
}
|
|
||||||
if (-1==aEndOffset) {
|
|
||||||
aEndOffset = totalLength;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -150,16 +150,6 @@ protected:
|
||||||
/** creates a bogus text node if the document has no editable content */
|
/** creates a bogus text node if the document has no editable content */
|
||||||
nsresult CreateBogusNodeIfNeeded(nsIDOMSelection *aSelection);
|
nsresult CreateBogusNodeIfNeeded(nsIDOMSelection *aSelection);
|
||||||
|
|
||||||
/** set aCount to the number of characters in the document. */
|
|
||||||
nsresult GetLengthOfDocumentInCharacters(PRInt32 &aCount);
|
|
||||||
|
|
||||||
/** returns the absolute position of the end points of aSelection
|
|
||||||
* in the document as a text stream.
|
|
||||||
*/
|
|
||||||
nsresult GetTextSelectionOffsets(nsIDOMSelection *aSelection,
|
|
||||||
PRInt32 &aStartOffset,
|
|
||||||
PRInt32 &aEndOffset);
|
|
||||||
|
|
||||||
// data
|
// data
|
||||||
nsTextEditor *mEditor; // note that we do not refcount the editor
|
nsTextEditor *mEditor; // note that we do not refcount the editor
|
||||||
nsString mPasswordText; // a buffer we use to store the real value of password editors
|
nsString mPasswordText; // a buffer we use to store the real value of password editors
|
||||||
|
|
|
@ -76,6 +76,9 @@ public:
|
||||||
/** set the edit flags for this editor. May be called at any time. */
|
/** set the edit flags for this editor. May be called at any time. */
|
||||||
NS_IMETHOD SetFlags(PRUint32 aFlags)=0;
|
NS_IMETHOD SetFlags(PRUint32 aFlags)=0;
|
||||||
|
|
||||||
|
/** get the length of the document in characters */
|
||||||
|
NS_IMETHOD GetDocumentLength(PRInt32 *aCount)=0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SetTextProperties() sets the aggregate properties on the current selection
|
* SetTextProperties() sets the aggregate properties on the current selection
|
||||||
*
|
*
|
||||||
|
|
Загрузка…
Ссылка в новой задаче