mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 22:32:46 +00:00
Bug 755311 - Simplify SetDocTitleTxn::SetDomTitle; r=ehsan
This commit is contained in:
parent
a03ec842c1
commit
9d1522ebbc
@ -43,6 +43,9 @@
|
|||||||
#include "nsIDOMHTMLDocument.h"
|
#include "nsIDOMHTMLDocument.h"
|
||||||
#include "nsIDOMText.h"
|
#include "nsIDOMText.h"
|
||||||
#include "nsIDOMElement.h"
|
#include "nsIDOMElement.h"
|
||||||
|
#include "mozilla/dom/Element.h"
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
|
|
||||||
// note that aEditor is not refcounted
|
// note that aEditor is not refcounted
|
||||||
SetDocTitleTxn::SetDocTitleTxn()
|
SetDocTitleTxn::SetDocTitleTxn()
|
||||||
@ -132,14 +135,11 @@ nsresult SetDocTitleTxn::SetDomTitle(const nsAString& aTitle)
|
|||||||
mIsTransient = false;
|
mIsTransient = false;
|
||||||
|
|
||||||
// Get the <HEAD> node, create a <TITLE> and insert it under the HEAD
|
// Get the <HEAD> node, create a <TITLE> and insert it under the HEAD
|
||||||
nsCOMPtr<nsIDOMNodeList> headList;
|
nsCOMPtr<nsIDocument> document = do_QueryInterface(domDoc);
|
||||||
res = domDoc->GetElementsByTagName(NS_LITERAL_STRING("head"),getter_AddRefs(headList));
|
NS_ENSURE_STATE(document);
|
||||||
NS_ENSURE_SUCCESS(res, res);
|
|
||||||
NS_ENSURE_TRUE(headList, NS_ERROR_FAILURE);
|
dom::Element* head = document->GetHeadElement();
|
||||||
|
NS_ENSURE_STATE(head);
|
||||||
nsCOMPtr<nsIDOMNode>headNode;
|
|
||||||
headList->Item(0, getter_AddRefs(headNode));
|
|
||||||
NS_ENSURE_TRUE(headNode, NS_ERROR_FAILURE);
|
|
||||||
|
|
||||||
bool newTitleNode = false;
|
bool newTitleNode = false;
|
||||||
PRUint32 newTitleIndex = 0;
|
PRUint32 newTitleIndex = 0;
|
||||||
@ -155,13 +155,8 @@ nsresult SetDocTitleTxn::SetDomTitle(const nsAString& aTitle)
|
|||||||
titleNode = do_QueryInterface(titleElement);
|
titleNode = do_QueryInterface(titleElement);
|
||||||
newTitleNode = true;
|
newTitleNode = true;
|
||||||
|
|
||||||
// Get index so we append new title node
|
// Get index so we append new title node after all existing HEAD children.
|
||||||
// after all existing HEAD children
|
newTitleIndex = head->GetChildCount();
|
||||||
nsCOMPtr<nsIDOMNodeList> children;
|
|
||||||
res = headNode->GetChildNodes(getter_AddRefs(children));
|
|
||||||
NS_ENSURE_SUCCESS(res, res);
|
|
||||||
if (children)
|
|
||||||
children->GetLength(&newTitleIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append a text node under the TITLE
|
// Append a text node under the TITLE
|
||||||
@ -191,7 +186,7 @@ nsresult SetDocTitleTxn::SetDomTitle(const nsAString& aTitle)
|
|||||||
if (newTitleNode)
|
if (newTitleNode)
|
||||||
{
|
{
|
||||||
// Undoable transaction to insert title+text together
|
// Undoable transaction to insert title+text together
|
||||||
res = editor->InsertNode(titleNode, headNode, newTitleIndex);
|
res = editor->InsertNode(titleNode, head->AsDOMNode(), newTitleIndex);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user