mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 755200 - Simplify SetSelectionAroundHeadChildren; r=ehsan
This commit is contained in:
parent
533e5d71a6
commit
feba9c5092
@ -50,7 +50,7 @@ interface nsINode;
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
[scriptable, uuid(7f30b791-9f43-4bba-9ca3-079dc2ea7479)]
|
||||
[scriptable, uuid(dd40d5b8-1fe1-487f-b66e-28f4b837024f)]
|
||||
interface nsISelection : nsISupports
|
||||
{
|
||||
/**
|
||||
@ -107,6 +107,7 @@ interface nsISelection : nsISupports
|
||||
* @param offset Where in node to place the offset in the new selection end
|
||||
*/
|
||||
void extend(in nsIDOMNode parentNode, in long offset);
|
||||
[noscript] void extendNative(in nsINode parentNode, in long offset);
|
||||
|
||||
/**
|
||||
* Collapses the whole selection to a single point at the start
|
||||
|
@ -66,7 +66,7 @@ struct ScrollAxis;
|
||||
native nsDirection(nsDirection);
|
||||
native ScrollAxis(nsIPresShell::ScrollAxis);
|
||||
|
||||
[scriptable, uuid(0733a4dc-2801-4752-a489-b68c918a7ccb)]
|
||||
[scriptable, uuid(719a803f-aa1e-436c-8919-c42908f00599)]
|
||||
interface nsISelectionPrivate : nsISelection
|
||||
{
|
||||
const short ENDOFPRECEDINGLINE=0;
|
||||
|
@ -3584,40 +3584,24 @@ nsHTMLEditor::IsModifiableNode(nsINode *aNode)
|
||||
return !aNode || aNode->IsEditable();
|
||||
}
|
||||
|
||||
static nsresult SetSelectionAroundHeadChildren(nsCOMPtr<nsISelection> aSelection, nsWeakPtr aDocWeak)
|
||||
static nsresult
|
||||
SetSelectionAroundHeadChildren(nsISelection* aSelection,
|
||||
nsIWeakReference* aDocWeak)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
// Set selection around <head> node
|
||||
nsCOMPtr<nsIDOMDocument> doc = do_QueryReferent(aDocWeak);
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryReferent(aDocWeak);
|
||||
NS_ENSURE_TRUE(doc, NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
nsCOMPtr<nsIDOMNodeList>nodeList;
|
||||
res = doc->GetElementsByTagName(NS_LITERAL_STRING("head"), getter_AddRefs(nodeList));
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
NS_ENSURE_TRUE(nodeList, NS_ERROR_NULL_POINTER);
|
||||
|
||||
PRUint32 count;
|
||||
nodeList->GetLength(&count);
|
||||
if (count < 1) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> headNode;
|
||||
res = nodeList->Item(0, getter_AddRefs(headNode));
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
NS_ENSURE_TRUE(headNode, NS_ERROR_NULL_POINTER);
|
||||
dom::Element* headNode = doc->GetHeadElement();
|
||||
NS_ENSURE_STATE(headNode);
|
||||
|
||||
// Collapse selection to before first child of the head,
|
||||
res = aSelection->Collapse(headNode, 0);
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
nsresult rv = aSelection->CollapseNative(headNode, 0);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// then extend it to just after
|
||||
nsCOMPtr<nsIDOMNodeList> childNodes;
|
||||
res = headNode->GetChildNodes(getter_AddRefs(childNodes));
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
NS_ENSURE_TRUE(childNodes, NS_ERROR_NULL_POINTER);
|
||||
PRUint32 childCount;
|
||||
childNodes->GetLength(&childCount);
|
||||
|
||||
return aSelection->Extend(headNode, childCount+1);
|
||||
// Then extend it to just after.
|
||||
PRUint32 childCount = headNode->GetChildCount();
|
||||
return aSelection->ExtendNative(headNode, childCount + 1);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -4889,6 +4889,12 @@ nsTypedSelection::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset)
|
||||
return Extend(parentNode, aOffset);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTypedSelection::ExtendNative(nsINode* aParentNode, PRInt32 aOffset)
|
||||
{
|
||||
return Extend(aParentNode, aOffset);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTypedSelection::Extend(nsINode* aParentNode, PRInt32 aOffset)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user