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

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

Issue 1752713002: Fix SVGDocument return title that is not a child of the root element (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
Index: third_party/WebKit/Source/core/dom/Document.cpp
diff --git a/third_party/WebKit/Source/core/dom/Document.cpp b/third_party/WebKit/Source/core/dom/Document.cpp
index 64f72e837e40d3a5cb3d7d72c4b4a0cc95adb60d..40b91c947f5f2d8faff3ec3786cd1d4bbc613bd7 100644
--- a/third_party/WebKit/Source/core/dom/Document.cpp
+++ b/third_party/WebKit/Source/core/dom/Document.cpp
@@ -1286,20 +1286,33 @@ void Document::updateTitle(const String& title)
void Document::setTitle(const String& title)
{
// Title set by JavaScript -- overrides any title elements.
- if (!isHTMLDocument() && !isXHTMLDocument()) {
- m_titleElement = nullptr;
- } else if (!m_titleElement) {
- HTMLElement* headElement = head();
- if (!headElement)
- return;
- m_titleElement = HTMLTitleElement::create(*this);
- headElement->appendChild(m_titleElement.get());
+ if (!m_titleElement) {
+ if (isHTMLDocument() || isXHTMLDocument()) {
+ HTMLElement* headElement = head();
+ if (!headElement)
+ return;
+ m_titleElement = HTMLTitleElement::create(*this);
+ headElement->appendChild(m_titleElement.get());
+ } else if (isSVGDocument()) {
+ if (!isSVGSVGElement(documentElement()))
+ return;
+ if (documentElement()) {
fs 2016/03/03 15:49:44 Here we know that documentElement() is non-null al
hyunjunekim2 2016/03/04 11:29:32 Done.
+ m_titleElement = SVGTitleElement::create(*this);
+ documentElement()->insertBefore(m_titleElement.get(), documentElement()->firstChild());
+ }
+ }
+ } else {
+ if (!isHTMLDocument() && !isXHTMLDocument() && !isSVGDocument())
+ m_titleElement = nullptr;
}
- if (isHTMLTitleElement(m_titleElement))
+ if (isHTMLTitleElement(m_titleElement)) {
toHTMLTitleElement(m_titleElement)->setText(title);
- else
+ } else if (isSVGTitleElement(m_titleElement)) {
+ toSVGTitleElement(m_titleElement)->setText(title);
+ } else {
updateTitle(title);
+ }
}
void Document::setTitleElement(Element* titleElement)
@@ -1315,10 +1328,18 @@ void Document::setTitleElement(Element* titleElement)
m_titleElement = titleElement;
}
- if (isHTMLTitleElement(m_titleElement))
+ if (isHTMLTitleElement(m_titleElement)) {
+ if (isSVGDocument() && isSVGSVGElement(documentElement())) {
fs 2016/03/03 15:49:44 I'd suggest that you separate the calls to updateT
hyunjunekim2 2016/03/04 11:29:32 Done.
+ m_titleElement = nullptr;
+ return;
+ }
updateTitle(toHTMLTitleElement(m_titleElement)->text());
- else if (isSVGTitleElement(m_titleElement))
- updateTitle(toSVGTitleElement(m_titleElement)->textContent());
+ } else if (isSVGTitleElement(m_titleElement)) {
+ if (isSVGSVGElement(m_titleElement->parentNode()))
+ updateTitle(toSVGTitleElement(m_titleElement)->textContent());
+ else
+ m_titleElement = nullptr;
+ }
}
void Document::removeTitle(Element* titleElement)

Powered by Google App Engine
This is Rietveld 408576698