author | Masayuki Nakano <masayuki@d-toybox.com> |
Fri, 14 Oct 2016 18:43:25 +0900 | |
changeset 319154 | d2aefe65689c1fe670389e2da3d0c092bf836721 |
parent 319153 | b398efe8d73ae1e4592539bd0b48cafb538c73a5 |
child 319155 | 918cb92107ecc8e0bf7c8c26b8649028cb19d90d |
push id | 30862 |
push user | cbook@mozilla.com |
push date | Mon, 24 Oct 2016 14:55:55 +0000 |
treeherder | mozilla-central@c845bfd0accb [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | ehsan |
bugs | 1309413 |
milestone | 52.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/editor/libeditor/SetDocumentTitleTransaction.cpp +++ b/editor/libeditor/SetDocumentTitleTransaction.cpp @@ -30,17 +30,19 @@ SetDocumentTitleTransaction::SetDocument } NS_IMETHODIMP SetDocumentTitleTransaction::Init(nsIHTMLEditor* aEditor, const nsAString* aValue) { NS_ASSERTION(aEditor && aValue, "null args"); - if (!aEditor || !aValue) { return NS_ERROR_NULL_POINTER; } + if (!aEditor || !aValue) { + return NS_ERROR_NULL_POINTER; + } mEditor = aEditor; mValue = *aValue; return NS_OK; } NS_IMETHODIMP @@ -76,42 +78,39 @@ SetDocumentTitleTransaction::SetDomTitle rv = domDoc->GetElementsByTagName(NS_LITERAL_STRING("title"), getter_AddRefs(titleList)); NS_ENSURE_SUCCESS(rv, rv); // First assume we will NOT really do anything // (transaction will not be pushed on stack) mIsTransient = true; - nsCOMPtr<nsIDOMNode>titleNode; - if(titleList) - { + nsCOMPtr<nsIDOMNode> titleNode; + if(titleList) { rv = titleList->Item(0, getter_AddRefs(titleNode)); NS_ENSURE_SUCCESS(rv, rv); - if (titleNode) - { + if (titleNode) { // Delete existing child textnode of title node // (Note: all contents under a TITLE node are always in a single text node) nsCOMPtr<nsIDOMNode> child; rv = titleNode->GetFirstChild(getter_AddRefs(child)); if (NS_FAILED(rv)) { return rv; } - if(child) - { + if(child) { // Save current text as the undo value nsCOMPtr<nsIDOMCharacterData> textNode = do_QueryInterface(child); - if(textNode) - { + if(textNode) { textNode->GetData(mUndoValue); // If title text is identical to what already exists, // quit now (mIsTransient is now TRUE) - if (mUndoValue == aTitle) + if (mUndoValue == aTitle) { return NS_OK; + } } rv = editor->DeleteNode(child); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } } } } @@ -123,64 +122,57 @@ SetDocumentTitleTransaction::SetDomTitle nsCOMPtr<nsIDocument> document = do_QueryInterface(domDoc); NS_ENSURE_STATE(document); RefPtr<dom::Element> headElement = document->GetHeadElement(); if (NS_WARN_IF(!headElement)) { return NS_ERROR_UNEXPECTED; } - bool newTitleNode = false; + bool newTitleNode = false; uint32_t newTitleIndex = 0; - if (!titleNode) - { + if (!titleNode) { // Didn't find one above: Create a new one nsCOMPtr<nsIDOMElement>titleElement; rv = domDoc->CreateElement(NS_LITERAL_STRING("title"), getter_AddRefs(titleElement)); NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_TRUE(titleElement, NS_ERROR_FAILURE); titleNode = do_QueryInterface(titleElement); newTitleNode = true; // Get index so we append new title node after all existing HEAD children. newTitleIndex = headElement->GetChildCount(); } - // Append a text node under the TITLE - // only if the title text isn't empty - if (titleNode && !aTitle.IsEmpty()) - { + // Append a text node under the TITLE only if the title text isn't empty. + if (titleNode && !aTitle.IsEmpty()) { nsCOMPtr<nsIDOMText> textNode; rv = domDoc->CreateTextNode(aTitle, getter_AddRefs(textNode)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIDOMNode> newNode = do_QueryInterface(textNode); NS_ENSURE_TRUE(newNode, NS_ERROR_FAILURE); - if (newTitleNode) - { + if (newTitleNode) { // Not undoable: We will insert newTitleNode below nsCOMPtr<nsIDOMNode> resultNode; rv = titleNode->AppendChild(newNode, getter_AddRefs(resultNode)); - } - else - { + } else { // This is an undoable transaction rv = editor->InsertNode(newNode, titleNode, 0); } NS_ENSURE_SUCCESS(rv, rv); // Calling AppendChild() or InsertNode() could cause removing the head // element. So, let's mark it dirty. headElement = nullptr; } - if (newTitleNode) - { + if (newTitleNode) { if (!headElement) { headElement = document->GetHeadElement(); if (NS_WARN_IF(!headElement)) { // XXX Can we return NS_OK when there is no head element? return NS_ERROR_UNEXPECTED; } } // Undoable transaction to insert title+text together