Chromium Code Reviews| 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 93a13ab219b2a1740691546634dd51c213453042..d8a257eadc813bc20762b6781f64119d62e4732a 100644 |
| --- a/third_party/WebKit/Source/core/dom/Document.cpp |
| +++ b/third_party/WebKit/Source/core/dom/Document.cpp |
| @@ -1287,33 +1287,57 @@ 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()) { |
| + Element* element = documentElement(); |
| + if (!isSVGSVGElement(element)) |
| + return; |
| + m_titleElement = SVGTitleElement::create(*this); |
| + element->insertBefore(m_titleElement.get(), element->firstChild()); |
| + } |
| + } else { |
| + if (!isHTMLDocument() && !isXHTMLDocument() && !isSVGDocument()) |
| + m_titleElement = nullptr; |
| } |
| if (isHTMLTitleElement(m_titleElement)) |
| toHTMLTitleElement(m_titleElement)->setText(title); |
| + else if (isSVGTitleElement(m_titleElement)) |
| + toSVGTitleElement(m_titleElement)->setText(title); |
| else |
| updateTitle(title); |
| } |
| void Document::setTitleElement(Element* titleElement) |
| { |
| - // 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); |
| + // If the root element is an svg element in the SVG namespace, then let value be the child text content |
| + // of the first title element in the SVG namespace that is a child of the root element. |
| + if (isSVGSVGElement(documentElement())) { |
| + m_titleElement = Traversal<SVGTitleElement>::firstChild(*documentElement()); |
| + if (m_titleElement && documentElement() == m_titleElement->parentNode()) { |
|
fs
2016/03/10 16:47:01
Traversal<SVGTitleElement>::firstChild guarantees
hyunjunekim2
2016/03/10 17:04:39
Done.
|
| + if (!isSVGTitleElement(m_titleElement)) { |
| + m_titleElement = nullptr; |
| + return; |
| + } |
| } |
| } else { |
| - m_titleElement = titleElement; |
| + if (m_titleElement && m_titleElement != titleElement) |
| + m_titleElement = Traversal<HTMLTitleElement>::firstWithin(*this); |
| + else |
| + m_titleElement = titleElement; |
| + |
| + // If the root element isn't an svg element in the SVG namespace and the title element is |
| + // in the SVG namespace, it is ignored. |
| + if (isSVGTitleElement(m_titleElement)) { |
| + m_titleElement = nullptr; |
| + return; |
| + } |
| } |
| if (isHTMLTitleElement(m_titleElement)) |