зеркало из https://github.com/mozilla/gecko-dev.git
Adding CollapseToStart and CollapseToEnd to selection
This commit is contained in:
Родитель
647a559bfd
Коммит
e05647c6dd
|
@ -98,6 +98,8 @@ public:
|
|||
NS_IMETHOD GetRangeAt(PRInt32 aIndex, nsIDOMRange** aReturn);
|
||||
NS_IMETHOD ClearSelection();
|
||||
NS_IMETHOD Collapse(nsIDOMNode* aParentNode, PRInt32 aOffset);
|
||||
NS_IMETHOD CollapseToStart();
|
||||
NS_IMETHOD CollapseToEnd();
|
||||
NS_IMETHOD Extend(nsIDOMNode* aParentNode, PRInt32 aOffset);
|
||||
NS_IMETHOD ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aAYes);
|
||||
NS_IMETHOD DeleteFromDocument();
|
||||
|
@ -2037,6 +2039,76 @@ nsDOMSelection::Collapse(nsIDOMNode* aParentNode, PRInt32 aOffset)
|
|||
return mRangeList->NotifySelectionListeners();
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets the whole selection to be one point
|
||||
* at the start of the current selection
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsDOMSelection::CollapseToStart()
|
||||
{
|
||||
PRInt32 cnt;
|
||||
nsresult rv = GetRangeCount(&cnt);
|
||||
if (NS_FAILED(rv) || cnt<=0 || !mRangeArray)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Get the first range (from GetRangeAt)
|
||||
nsISupports* element = mRangeArray->ElementAt(0);
|
||||
nsCOMPtr<nsIDOMRange> firstRange = do_QueryInterface(element);
|
||||
if (!firstRange)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> parent;
|
||||
rv = firstRange->GetStartParent(getter_AddRefs(parent));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
if (parent)
|
||||
{
|
||||
PRInt32 startOffset;
|
||||
firstRange->GetStartOffset(&startOffset);
|
||||
rv = Collapse(parent, startOffset);
|
||||
} else {
|
||||
// not very likely!
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets the whole selection to be one point
|
||||
* at the end of the current selection
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsDOMSelection::CollapseToEnd()
|
||||
{
|
||||
PRInt32 cnt;
|
||||
nsresult rv = GetRangeCount(&cnt);
|
||||
if (NS_FAILED(rv) || cnt<=0 || !mRangeArray)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Get the last range (from GetRangeAt)
|
||||
nsISupports* element = mRangeArray->ElementAt(cnt-1);
|
||||
nsCOMPtr<nsIDOMRange> lastRange = do_QueryInterface(element);
|
||||
if (!lastRange)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> parent;
|
||||
rv = lastRange->GetEndParent(getter_AddRefs(parent));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
if (parent)
|
||||
{
|
||||
PRInt32 endOffset;
|
||||
lastRange->GetEndOffset(&endOffset);
|
||||
rv = Collapse(parent, endOffset);
|
||||
} else {
|
||||
// not very likely!
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* IsCollapsed -- is the whole selection just one point, or unset?
|
||||
*/
|
||||
|
|
Загрузка…
Ссылка в новой задаче