Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 // Only allow the first title element to change the title -- others have no effect. |
| 1309 if (m_titleElement && m_titleElement != titleElement) { | 1320 if (m_titleElement && m_titleElement != titleElement) { |
| 1310 if (isHTMLDocument() || isXHTMLDocument()) { | 1321 if (isHTMLDocument() || isXHTMLDocument()) { |
| 1311 m_titleElement = Traversal<HTMLTitleElement>::firstWithin(*this); | 1322 m_titleElement = Traversal<HTMLTitleElement>::firstWithin(*this); |
| 1312 } else if (isSVGDocument()) { | 1323 } else if (isSVGDocument()) { |
| 1313 m_titleElement = Traversal<SVGTitleElement>::firstWithin(*this); | 1324 m_titleElement = Traversal<SVGTitleElement>::firstWithin(*this); |
| 1325 if (!m_titleElement) | |
| 1326 m_titleElement = titleElement; | |
| 1314 } | 1327 } |
| 1315 } else { | 1328 } else { |
| 1316 m_titleElement = titleElement; | 1329 m_titleElement = titleElement; |
| 1317 } | 1330 } |
| 1318 | 1331 |
| 1332 if (isSVGDocument()) { | |
| 1333 if (!m_titleElement) | |
| 1334 return; | |
| 1335 // If the root element that is <svg> element in the svg namespace is not the parent of <title> element, | |
| 1336 // ignore <title> element. | |
| 1337 Node* parent = m_titleElement->parentNode(); | |
| 1338 while (parent) { | |
|
fs
2016/03/09 16:06:48
I don't think you need this while-loop.
| |
| 1339 if (isSVGSVGElement(parent) && toSVGElement(parent)->isOutermostSVGS VGElement()) { | |
| 1340 if (documentElement() != parent || m_titleElement->parentNode() != parent) { | |
| 1341 m_titleElement = nullptr; | |
| 1342 return; | |
| 1343 } | |
| 1344 break; | |
| 1345 } | |
| 1346 parent = parent->parentNode(); | |
| 1347 } | |
| 1348 | |
| 1349 // If the root element is not <svg> element in the svg namespace and <ti tle> element is in the svg namespace, | |
| 1350 // or the root element is <svg> element in the svg namespace and <title> element is not in the svg namespace, | |
| 1351 // ignore <title> element. | |
| 1352 if ((!isSVGSVGElement(m_titleElement->parentNode()) && isSVGTitleElement (m_titleElement)) | |
| 1353 || (isSVGSVGElement(m_titleElement->parentNode()) && !isSVGTitleElem ent(m_titleElement))) { | |
| 1354 m_titleElement = nullptr; | |
| 1355 return; | |
| 1356 } | |
| 1357 } | |
| 1358 | |
| 1319 if (isHTMLTitleElement(m_titleElement)) | 1359 if (isHTMLTitleElement(m_titleElement)) |
| 1320 updateTitle(toHTMLTitleElement(m_titleElement)->text()); | 1360 updateTitle(toHTMLTitleElement(m_titleElement)->text()); |
| 1321 else if (isSVGTitleElement(m_titleElement)) | 1361 else if (isSVGTitleElement(m_titleElement)) |
| 1322 updateTitle(toSVGTitleElement(m_titleElement)->textContent()); | 1362 updateTitle(toSVGTitleElement(m_titleElement)->textContent()); |
| 1323 } | 1363 } |
| 1324 | 1364 |
| 1325 void Document::removeTitle(Element* titleElement) | 1365 void Document::removeTitle(Element* titleElement) |
| 1326 { | 1366 { |
| 1327 if (m_titleElement != titleElement) | 1367 if (m_titleElement != titleElement) |
| 1328 return; | 1368 return; |
| (...skipping 4661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5990 #ifndef NDEBUG | 6030 #ifndef NDEBUG |
| 5991 using namespace blink; | 6031 using namespace blink; |
| 5992 void showLiveDocumentInstances() | 6032 void showLiveDocumentInstances() |
| 5993 { | 6033 { |
| 5994 Document::WeakDocumentSet& set = Document::liveDocumentSet(); | 6034 Document::WeakDocumentSet& set = Document::liveDocumentSet(); |
| 5995 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); | 6035 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); |
| 5996 for (Document* document : set) | 6036 for (Document* document : set) |
| 5997 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get String().utf8().data()); | 6037 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get String().utf8().data()); |
| 5998 } | 6038 } |
| 5999 #endif | 6039 #endif |
| OLD | NEW |