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

Unified Diff: Source/core/dom/Document.cpp

Issue 384413003: Document.title getter should return text of title element and setter should stop when head el… (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Take review comment into consideration Created 6 years, 5 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/dom/Document.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/Document.cpp
diff --git a/Source/core/dom/Document.cpp b/Source/core/dom/Document.cpp
index eba7ecdfb87d0d206d3d79923ba3816eb5daec3d..30f6f64edba8036be9b14cea787d22ef45e9aeb1 100644
--- a/Source/core/dom/Document.cpp
+++ b/Source/core/dom/Document.cpp
@@ -176,6 +176,7 @@
#include "core/rendering/compositing/RenderLayerCompositor.h"
#include "core/svg/SVGDocumentExtensions.h"
#include "core/svg/SVGFontFaceElement.h"
+#include "core/svg/SVGTitleElement.h"
#include "core/svg/SVGUseElement.h"
#include "core/workers/SharedWorkerRepositoryClient.h"
#include "core/xml/XSLTProcessor.h"
@@ -461,7 +462,6 @@ Document::Document(const DocumentInit& initializer, DocumentClassFlags documentC
, m_updateFocusAppearanceRestoresSelection(false)
, m_containsPlugins(false)
, m_ignoreDestructiveWriteCount(0)
- , m_titleSetExplicitly(false)
, m_markers(adoptPtrWillBeNoop(new DocumentMarkerController))
, m_updateFocusAppearanceTimer(this, &Document::updateFocusAppearanceTimerFired)
, m_cssTarget(nullptr)
@@ -1386,14 +1386,14 @@ void Document::updateTitle(const String& title)
void Document::setTitle(const String& title)
{
// Title set by JavaScript -- overrides any title elements.
- m_titleSetExplicitly = true;
if (!isHTMLDocument() && !isXHTMLDocument())
m_titleElement = nullptr;
else if (!m_titleElement) {
- if (HTMLElement* headElement = head()) {
- m_titleElement = HTMLTitleElement::create(*this);
- headElement->appendChild(m_titleElement.get());
- }
+ HTMLElement* headElement = head();
+ if (!headElement)
+ return;
+ m_titleElement = HTMLTitleElement::create(*this);
+ headElement->appendChild(m_titleElement.get());
}
if (isHTMLTitleElement(m_titleElement))
@@ -1404,14 +1404,21 @@ void Document::setTitle(const String& title)
void Document::setTitleElement(const String& title, Element* titleElement)
Inactive 2014/07/22 00:55:22 Hmm, this title argument is no longer used. We sho
{
- if (titleElement != m_titleElement) {
- if (m_titleElement || m_titleSetExplicitly)
- // Only allow the first title element to change the title -- others have no effect.
- return;
+ // Only allow the first title element to change the title -- others have no effect.
+ if (m_titleElement && m_titleElement != titleElement) {
+ if (isHTMLDocument() || isXHTMLDocument()) {
+ m_titleElement = Traversal<HTMLTitleElement>::firstWithin(*this);
+ } else if (isSVGDocument()) {
+ m_titleElement = Traversal<SVGTitleElement>::firstWithin(*this);
+ }
+ } else {
m_titleElement = titleElement;
}
- updateTitle(title);
+ if (isHTMLTitleElement(m_titleElement))
+ updateTitle(toHTMLTitleElement(m_titleElement)->text());
+ else if (isSVGTitleElement(m_titleElement))
+ updateTitle(toSVGTitleElement(m_titleElement)->textContent());
}
void Document::removeTitle(Element* titleElement)
@@ -1420,14 +1427,11 @@ void Document::removeTitle(Element* titleElement)
return;
m_titleElement = nullptr;
- m_titleSetExplicitly = false;
// FIXME: This is broken for SVG.
- // Update title based on first title element in the head, if one exists.
- if (HTMLElement* headElement = head()) {
- if (HTMLTitleElement* title = Traversal<HTMLTitleElement>::firstChild(*headElement))
- setTitleElement(title->text(), title);
- }
+ // Update title based on first title element in the document, if one exists.
+ if (HTMLTitleElement* title = Traversal<HTMLTitleElement>::firstWithin(*this))
+ setTitleElement(title->text(), title);
if (!m_titleElement)
updateTitle(String());
« no previous file with comments | « Source/core/dom/Document.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698