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

Side by Side Diff: third_party/WebKit/Source/core/dom/Document.cpp

Issue 1774913003: (Re-commit) 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, 9 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
(...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 m_title = canonicalizedTitle<UChar>(this, m_rawTitle); 1280 m_title = canonicalizedTitle<UChar>(this, m_rawTitle);
1281 1281
1282 if (!m_frame || oldTitle == m_title) 1282 if (!m_frame || oldTitle == m_title)
1283 return; 1283 return;
1284 m_frame->loader().client()->dispatchDidReceiveTitle(m_title); 1284 m_frame->loader().client()->dispatchDidReceiveTitle(m_title);
1285 } 1285 }
1286 1286
1287 void Document::setTitle(const String& title) 1287 void Document::setTitle(const String& title)
1288 { 1288 {
1289 // Title set by JavaScript -- overrides any title elements. 1289 // Title set by JavaScript -- overrides any title elements.
1290 if (!isHTMLDocument() && !isXHTMLDocument()) { 1290 if (!m_titleElement) {
1291 m_titleElement = nullptr; 1291 if (isHTMLDocument() || isXHTMLDocument()) {
1292 } else if (!m_titleElement) { 1292 HTMLElement* headElement = head();
1293 HTMLElement* headElement = head(); 1293 if (!headElement)
1294 if (!headElement) 1294 return;
1295 return; 1295 m_titleElement = HTMLTitleElement::create(*this);
1296 m_titleElement = HTMLTitleElement::create(*this); 1296 headElement->appendChild(m_titleElement.get());
1297 headElement->appendChild(m_titleElement.get()); 1297 } else if (isSVGDocument()) {
1298 Element* element = documentElement();
1299 if (!isSVGSVGElement(element))
1300 return;
1301 m_titleElement = SVGTitleElement::create(*this);
1302 element->insertBefore(m_titleElement.get(), element->firstChild());
1303 }
1304 } else {
1305 if (!isHTMLDocument() && !isXHTMLDocument() && !isSVGDocument())
1306 m_titleElement = nullptr;
1298 } 1307 }
1299 1308
1300 if (isHTMLTitleElement(m_titleElement)) 1309 if (isHTMLTitleElement(m_titleElement))
1301 toHTMLTitleElement(m_titleElement)->setText(title); 1310 toHTMLTitleElement(m_titleElement)->setText(title);
1311 else if (isSVGTitleElement(m_titleElement))
1312 toSVGTitleElement(m_titleElement)->setText(title);
1302 else 1313 else
1303 updateTitle(title); 1314 updateTitle(title);
1304 } 1315 }
1305 1316
1306 void Document::setTitleElement(Element* titleElement) 1317 void Document::setTitleElement(Element* titleElement)
1307 { 1318 {
1308 // Only allow the first title element to change the title -- others have no effect. 1319 // If the root element is an svg element in the SVG namespace, then let valu e be the child text content
1309 if (m_titleElement && m_titleElement != titleElement) { 1320 // of the first title element in the SVG namespace that is a child of the ro ot element.
1310 if (isHTMLDocument() || isXHTMLDocument()) { 1321 if (isSVGSVGElement(documentElement())) {
1322 m_titleElement = Traversal<SVGTitleElement>::firstChild(*documentElement ());
1323 } else {
1324 if (m_titleElement && m_titleElement != titleElement)
1311 m_titleElement = Traversal<HTMLTitleElement>::firstWithin(*this); 1325 m_titleElement = Traversal<HTMLTitleElement>::firstWithin(*this);
1312 } else if (isSVGDocument()) { 1326 else
1313 m_titleElement = Traversal<SVGTitleElement>::firstWithin(*this); 1327 m_titleElement = titleElement;
1328
1329 // If the root element isn't an svg element in the SVG namespace and the title element is
1330 // in the SVG namespace, it is ignored.
1331 if (isSVGTitleElement(m_titleElement)) {
1332 m_titleElement = nullptr;
1333 return;
1314 } 1334 }
1315 } else {
1316 m_titleElement = titleElement;
1317 } 1335 }
1318 1336
1319 if (isHTMLTitleElement(m_titleElement)) 1337 if (isHTMLTitleElement(m_titleElement))
1320 updateTitle(toHTMLTitleElement(m_titleElement)->text()); 1338 updateTitle(toHTMLTitleElement(m_titleElement)->text());
1321 else if (isSVGTitleElement(m_titleElement)) 1339 else if (isSVGTitleElement(m_titleElement))
1322 updateTitle(toSVGTitleElement(m_titleElement)->textContent()); 1340 updateTitle(toSVGTitleElement(m_titleElement)->textContent());
1323 } 1341 }
1324 1342
1325 void Document::removeTitle(Element* titleElement) 1343 void Document::removeTitle(Element* titleElement)
1326 { 1344 {
(...skipping 4663 matching lines...) Expand 10 before | Expand all | Expand 10 after
5990 #ifndef NDEBUG 6008 #ifndef NDEBUG
5991 using namespace blink; 6009 using namespace blink;
5992 void showLiveDocumentInstances() 6010 void showLiveDocumentInstances()
5993 { 6011 {
5994 Document::WeakDocumentSet& set = Document::liveDocumentSet(); 6012 Document::WeakDocumentSet& set = Document::liveDocumentSet();
5995 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 6013 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
5996 for (Document* document : set) 6014 for (Document* document : set)
5997 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get String().utf8().data()); 6015 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get String().utf8().data());
5998 } 6016 }
5999 #endif 6017 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698