Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(939)

Unified Diff: Source/core/html/HTMLTitleElement.cpp

Issue 138213005: Revert "Remove children of title node before updating" (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/HTMLTitleElement.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLTitleElement.cpp
diff --git a/Source/core/html/HTMLTitleElement.cpp b/Source/core/html/HTMLTitleElement.cpp
index ff62d1c92a0824c76b4ba392ea626248a62fec5d..872ca280e1356f5134c9bc1c04d0ee49e34acffe 100644
--- a/Source/core/html/HTMLTitleElement.cpp
+++ b/Source/core/html/HTMLTitleElement.cpp
@@ -25,7 +25,6 @@
#include "HTMLNames.h"
#include "bindings/v8/ExceptionStatePlaceholder.h"
-#include "core/dom/ChildListMutationScope.h"
#include "core/dom/Document.h"
#include "core/dom/Text.h"
#include "core/rendering/style/RenderStyle.h"
@@ -38,7 +37,6 @@ using namespace HTMLNames;
inline HTMLTitleElement::HTMLTitleElement(Document& document)
: HTMLElement(titleTag, document)
- , m_ignoreTitleUpdatesWhenChildrenChange(false)
{
setHasCustomStyleCallbacks();
ScriptWrappable::init(this);
@@ -67,7 +65,7 @@ void HTMLTitleElement::removedFrom(ContainerNode* insertionPoint)
void HTMLTitleElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
{
HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
- if (inDocument() && !isInShadowTree() && !m_ignoreTitleUpdatesWhenChildrenChange)
+ if (inDocument() && !isInShadowTree())
document().setTitleElement(text(), this);
}
@@ -86,14 +84,23 @@ String HTMLTitleElement::text() const
void HTMLTitleElement::setText(const String &value)
{
RefPtr<Node> protectFromMutationEvents(this);
- ChildListMutationScope mutation(*this);
- // Avoid calling Document::setTitleElement() during intermediate steps.
- m_ignoreTitleUpdatesWhenChildrenChange = true;
- removeChildren();
- m_ignoreTitleUpdatesWhenChildrenChange = false;
+ int numChildren = childNodeCount();
+
+ if (numChildren == 1 && firstChild()->isTextNode()) {
+ toText(firstChild())->setData(value);
+ document().setTitleElement(text(), this);
+ } else {
+ // We make a copy here because entity of "value" argument can be Document::m_title,
+ // which goes empty during removeChildren() invocation below,
+ // which causes HTMLTitleElement::childrenChanged(), which ends up Document::setTitle().
+ String valueCopy(value);
- appendChild(document().createTextNode(value.impl()), IGNORE_EXCEPTION);
+ if (numChildren > 0)
+ removeChildren();
+
+ appendChild(document().createTextNode(valueCopy.impl()), IGNORE_EXCEPTION);
+ }
}
}
« no previous file with comments | « Source/core/html/HTMLTitleElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698