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); |
1314 } | 1325 } |
1315 } else { | 1326 } else { |
1316 m_titleElement = titleElement; | 1327 m_titleElement = titleElement; |
1317 } | 1328 } |
1318 | 1329 |
| 1330 if (isSVGDocument()) { |
| 1331 // If the root element that is <svg> element in the svg namespace is not
the parent of <title> element, |
| 1332 // ignore <title> element. |
| 1333 Node* parent = m_titleElement->parentNode(); |
| 1334 while (parent) { |
| 1335 if (isSVGSVGElement(parent) && toSVGElement(parent)->isOutermostSVGS
VGElement()) { |
| 1336 if (documentElement() != parent || m_titleElement->parentNode()
!= parent) { |
| 1337 m_titleElement = nullptr; |
| 1338 return; |
| 1339 } |
| 1340 break; |
| 1341 } |
| 1342 parent = parent->parentNode(); |
| 1343 } |
| 1344 |
| 1345 // If the root element is not <svg> element in the svg namespace and <ti
tle> element is in the svg namespace, |
| 1346 // or the root element is <svg> element in the svg namespace and <title>
element is not in the svg namespace, |
| 1347 // ignore <title> element. |
| 1348 if ((!isSVGSVGElement(m_titleElement->parentNode()) && isSVGTitleElement
(m_titleElement)) |
| 1349 || (isSVGSVGElement(m_titleElement->parentNode()) && !isSVGTitleElem
ent(m_titleElement))) { |
| 1350 m_titleElement = nullptr; |
| 1351 return; |
| 1352 } |
| 1353 } |
| 1354 |
1319 if (isHTMLTitleElement(m_titleElement)) | 1355 if (isHTMLTitleElement(m_titleElement)) |
1320 updateTitle(toHTMLTitleElement(m_titleElement)->text()); | 1356 updateTitle(toHTMLTitleElement(m_titleElement)->text()); |
1321 else if (isSVGTitleElement(m_titleElement)) | 1357 else if (isSVGTitleElement(m_titleElement)) |
1322 updateTitle(toSVGTitleElement(m_titleElement)->textContent()); | 1358 updateTitle(toSVGTitleElement(m_titleElement)->textContent()); |
1323 } | 1359 } |
1324 | 1360 |
1325 void Document::removeTitle(Element* titleElement) | 1361 void Document::removeTitle(Element* titleElement) |
1326 { | 1362 { |
1327 if (m_titleElement != titleElement) | 1363 if (m_titleElement != titleElement) |
1328 return; | 1364 return; |
(...skipping 4661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5990 #ifndef NDEBUG | 6026 #ifndef NDEBUG |
5991 using namespace blink; | 6027 using namespace blink; |
5992 void showLiveDocumentInstances() | 6028 void showLiveDocumentInstances() |
5993 { | 6029 { |
5994 Document::WeakDocumentSet& set = Document::liveDocumentSet(); | 6030 Document::WeakDocumentSet& set = Document::liveDocumentSet(); |
5995 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); | 6031 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); |
5996 for (Document* document : set) | 6032 for (Document* document : set) |
5997 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get
String().utf8().data()); | 6033 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get
String().utf8().data()); |
5998 } | 6034 } |
5999 #endif | 6035 #endif |
OLD | NEW |