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 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1279 m_title = canonicalizedTitle<UChar>(this, m_rawTitle); | 1279 m_title = canonicalizedTitle<UChar>(this, m_rawTitle); |
1280 | 1280 |
1281 if (!m_frame || oldTitle == m_title) | 1281 if (!m_frame || oldTitle == m_title) |
1282 return; | 1282 return; |
1283 m_frame->loader().client()->dispatchDidReceiveTitle(m_title); | 1283 m_frame->loader().client()->dispatchDidReceiveTitle(m_title); |
1284 } | 1284 } |
1285 | 1285 |
1286 void Document::setTitle(const String& title) | 1286 void Document::setTitle(const String& title) |
1287 { | 1287 { |
1288 // Title set by JavaScript -- overrides any title elements. | 1288 // Title set by JavaScript -- overrides any title elements. |
1289 if (!m_titleElement) { | 1289 if (!isHTMLDocument() && !isXHTMLDocument()) { |
1290 if (isHTMLDocument() || isXHTMLDocument()) { | 1290 m_titleElement = nullptr; |
1291 HTMLElement* headElement = head(); | 1291 } else if (!m_titleElement) { |
1292 if (!headElement) | 1292 HTMLElement* headElement = head(); |
1293 return; | 1293 if (!headElement) |
1294 m_titleElement = HTMLTitleElement::create(*this); | 1294 return; |
1295 headElement->appendChild(m_titleElement.get()); | 1295 m_titleElement = HTMLTitleElement::create(*this); |
1296 } else if (isSVGDocument()) { | 1296 headElement->appendChild(m_titleElement.get()); |
1297 Element* element = documentElement(); | |
1298 if (!isSVGSVGElement(element)) | |
1299 return; | |
1300 m_titleElement = SVGTitleElement::create(*this); | |
1301 element->insertBefore(m_titleElement.get(), element->firstChild()); | |
1302 } | |
1303 } else { | |
1304 if (!isHTMLDocument() && !isXHTMLDocument() && !isSVGDocument()) | |
1305 m_titleElement = nullptr; | |
1306 } | 1297 } |
1307 | 1298 |
1308 if (isHTMLTitleElement(m_titleElement)) | 1299 if (isHTMLTitleElement(m_titleElement)) |
1309 toHTMLTitleElement(m_titleElement)->setText(title); | 1300 toHTMLTitleElement(m_titleElement)->setText(title); |
1310 else if (isSVGTitleElement(m_titleElement)) | |
1311 toSVGTitleElement(m_titleElement)->setText(title); | |
1312 else | 1301 else |
1313 updateTitle(title); | 1302 updateTitle(title); |
1314 } | 1303 } |
1315 | 1304 |
1316 void Document::setTitleElement(Element* titleElement) | 1305 void Document::setTitleElement(Element* titleElement) |
1317 { | 1306 { |
1318 // Only allow the first title element to change the title -- others have no
effect. | 1307 // Only allow the first title element to change the title -- others have no
effect. |
1319 if (m_titleElement && m_titleElement != titleElement) { | 1308 if (m_titleElement && m_titleElement != titleElement) { |
1320 if (isHTMLDocument() || isXHTMLDocument()) { | 1309 if (isHTMLDocument() || isXHTMLDocument()) { |
1321 m_titleElement = Traversal<HTMLTitleElement>::firstWithin(*this); | 1310 m_titleElement = Traversal<HTMLTitleElement>::firstWithin(*this); |
1322 } else if (isSVGDocument()) { | 1311 } else if (isSVGDocument()) { |
1323 m_titleElement = Traversal<SVGTitleElement>::firstWithin(*this); | 1312 m_titleElement = Traversal<SVGTitleElement>::firstWithin(*this); |
1324 } | 1313 } |
1325 } else { | 1314 } else { |
1326 m_titleElement = titleElement; | 1315 m_titleElement = titleElement; |
1327 } | 1316 } |
1328 | 1317 |
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 if (isSVGSVGElement(documentElement()) && documentElement() != m_titleEl
ement->parentNode()) { | |
1334 m_titleElement = nullptr; | |
1335 return; | |
1336 } | |
1337 | |
1338 // If the root element is not <svg> element in the svg namespace and <ti
tle> element is in the svg namespace, | |
1339 // or the root element is <svg> element in the svg namespace and <title>
element is not in the svg namespace, | |
1340 // ignore <title> element. | |
1341 if ((!isSVGSVGElement(m_titleElement->parentNode()) && isSVGTitleElement
(m_titleElement)) | |
1342 || (isSVGSVGElement(m_titleElement->parentNode()) && !isSVGTitleElem
ent(m_titleElement))) { | |
1343 m_titleElement = nullptr; | |
1344 return; | |
1345 } | |
1346 } | |
1347 | |
1348 if (isHTMLTitleElement(m_titleElement)) | 1318 if (isHTMLTitleElement(m_titleElement)) |
1349 updateTitle(toHTMLTitleElement(m_titleElement)->text()); | 1319 updateTitle(toHTMLTitleElement(m_titleElement)->text()); |
1350 else if (isSVGTitleElement(m_titleElement)) | 1320 else if (isSVGTitleElement(m_titleElement)) |
1351 updateTitle(toSVGTitleElement(m_titleElement)->textContent()); | 1321 updateTitle(toSVGTitleElement(m_titleElement)->textContent()); |
1352 } | 1322 } |
1353 | 1323 |
1354 void Document::removeTitle(Element* titleElement) | 1324 void Document::removeTitle(Element* titleElement) |
1355 { | 1325 { |
1356 if (m_titleElement != titleElement) | 1326 if (m_titleElement != titleElement) |
1357 return; | 1327 return; |
(...skipping 4667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6025 #ifndef NDEBUG | 5995 #ifndef NDEBUG |
6026 using namespace blink; | 5996 using namespace blink; |
6027 void showLiveDocumentInstances() | 5997 void showLiveDocumentInstances() |
6028 { | 5998 { |
6029 Document::WeakDocumentSet& set = Document::liveDocumentSet(); | 5999 Document::WeakDocumentSet& set = Document::liveDocumentSet(); |
6030 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); | 6000 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); |
6031 for (Document* document : set) | 6001 for (Document* document : set) |
6032 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str
ing().utf8().data()); | 6002 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str
ing().utf8().data()); |
6033 } | 6003 } |
6034 #endif | 6004 #endif |
OLD | NEW |