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

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

Issue 384413003: Document.title getter should return text of title element and setter should stop when head el… (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add test case for this CL Created 6 years, 5 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 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 , m_mutationObserverTypes(0) 452 , m_mutationObserverTypes(0)
453 , m_visitedLinkState(VisitedLinkState::create(*this)) 453 , m_visitedLinkState(VisitedLinkState::create(*this))
454 , m_visuallyOrdered(false) 454 , m_visuallyOrdered(false)
455 , m_readyState(Complete) 455 , m_readyState(Complete)
456 , m_isParsing(false) 456 , m_isParsing(false)
457 , m_gotoAnchorNeededAfterStylesheetsLoad(false) 457 , m_gotoAnchorNeededAfterStylesheetsLoad(false)
458 , m_containsValidityStyleRules(false) 458 , m_containsValidityStyleRules(false)
459 , m_updateFocusAppearanceRestoresSelection(false) 459 , m_updateFocusAppearanceRestoresSelection(false)
460 , m_containsPlugins(false) 460 , m_containsPlugins(false)
461 , m_ignoreDestructiveWriteCount(0) 461 , m_ignoreDestructiveWriteCount(0)
462 , m_titleSetExplicitly(false)
463 , m_markers(adoptPtrWillBeNoop(new DocumentMarkerController)) 462 , m_markers(adoptPtrWillBeNoop(new DocumentMarkerController))
464 , m_updateFocusAppearanceTimer(this, &Document::updateFocusAppearanceTimerFi red) 463 , m_updateFocusAppearanceTimer(this, &Document::updateFocusAppearanceTimerFi red)
465 , m_cssTarget(nullptr) 464 , m_cssTarget(nullptr)
466 , m_loadEventProgress(LoadEventNotRun) 465 , m_loadEventProgress(LoadEventNotRun)
467 , m_startTime(currentTime()) 466 , m_startTime(currentTime())
468 , m_scriptRunner(ScriptRunner::create(this)) 467 , m_scriptRunner(ScriptRunner::create(this))
469 , m_xmlVersion("1.0") 468 , m_xmlVersion("1.0")
470 , m_xmlStandalone(StandaloneUnspecified) 469 , m_xmlStandalone(StandaloneUnspecified)
471 , m_hasXMLDeclaration(0) 470 , m_hasXMLDeclaration(0)
472 , m_designMode(inherit) 471 , m_designMode(inherit)
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
1380 m_title = canonicalizedTitle<UChar>(this, m_rawTitle); 1379 m_title = canonicalizedTitle<UChar>(this, m_rawTitle);
1381 1380
1382 if (!m_frame || oldTitle == m_title) 1381 if (!m_frame || oldTitle == m_title)
1383 return; 1382 return;
1384 m_frame->loader().client()->dispatchDidReceiveTitle(m_title); 1383 m_frame->loader().client()->dispatchDidReceiveTitle(m_title);
1385 } 1384 }
1386 1385
1387 void Document::setTitle(const String& title) 1386 void Document::setTitle(const String& title)
1388 { 1387 {
1389 // Title set by JavaScript -- overrides any title elements. 1388 // Title set by JavaScript -- overrides any title elements.
1390 m_titleSetExplicitly = true;
1391 if (!isHTMLDocument() && !isXHTMLDocument()) 1389 if (!isHTMLDocument() && !isXHTMLDocument())
1392 m_titleElement = nullptr; 1390 m_titleElement = nullptr;
1393 else if (!m_titleElement) { 1391 else if (!m_titleElement) {
1394 if (HTMLElement* headElement = head()) { 1392 HTMLElement* headElement = head();
1395 m_titleElement = HTMLTitleElement::create(*this); 1393 if (!isSVGDocument() && !headElement)
Inactive 2014/07/16 14:42:05 This !isSVGDocument() check seems superfluous. If
kangil_ 2014/07/18 06:55:58 Done.
1396 headElement->appendChild(m_titleElement.get()); 1394 return;
1397 } 1395 m_titleElement = HTMLTitleElement::create(*this);
1396 headElement->appendChild(m_titleElement.get());
1398 } 1397 }
1399 1398
1400 if (isHTMLTitleElement(m_titleElement)) 1399 if (isHTMLTitleElement(m_titleElement))
1401 toHTMLTitleElement(m_titleElement)->setText(title); 1400 toHTMLTitleElement(m_titleElement)->setText(title);
1402 else 1401 else
1403 updateTitle(title); 1402 updateTitle(title);
1404 } 1403 }
1405 1404
1406 void Document::setTitleElement(const String& title, Element* titleElement) 1405 void Document::setTitleElement(const String& title, Element* titleElement)
Inactive 2014/07/16 14:42:05 It looks like you broke the SVG case in this metho
kangil_ 2014/07/18 06:55:58 Done.
1407 { 1406 {
1408 if (titleElement != m_titleElement) { 1407 // Only allow the first title element to change the title -- others have no effect.
1409 if (m_titleElement || m_titleSetExplicitly) 1408 if (m_titleElement && m_titleElement != titleElement)
1410 // Only allow the first title element to change the title -- others have no effect. 1409 m_titleElement = Traversal<HTMLTitleElement>::next(*this);
Inactive 2014/07/16 14:42:05 Wouldn't Traversal<HTMLTitleElement>::firstWithin(
kangil_ 2014/07/18 06:55:58 Done.
1411 return; 1410 else
1412 m_titleElement = titleElement; 1411 m_titleElement = titleElement;
1413 }
1414 1412
1415 updateTitle(title); 1413 if (isHTMLTitleElement(m_titleElement))
1414 updateTitle(toHTMLTitleElement(m_titleElement)->text());
1416 } 1415 }
1417 1416
1418 void Document::removeTitle(Element* titleElement) 1417 void Document::removeTitle(Element* titleElement)
1419 { 1418 {
1420 if (m_titleElement != titleElement) 1419 if (m_titleElement != titleElement)
1421 return; 1420 return;
1422 1421
1423 m_titleElement = nullptr; 1422 m_titleElement = nullptr;
1424 m_titleSetExplicitly = false;
1425 1423
1426 // FIXME: This is broken for SVG. 1424 // FIXME: This is broken for SVG.
1427 // Update title based on first title element in the head, if one exists. 1425 // Update title based on first title element in the document, if one exists.
1428 if (HTMLElement* headElement = head()) { 1426 if (HTMLTitleElement* title = Traversal<HTMLTitleElement>::next(*this))
Inactive 2014/07/16 14:42:05 firstWithin?
kangil_ 2014/07/18 06:55:58 Done.
1429 if (HTMLTitleElement* title = Traversal<HTMLTitleElement>::firstChild(*h eadElement)) 1427 setTitleElement(title->text(), title);
1430 setTitleElement(title->text(), title);
1431 }
1432 1428
1433 if (!m_titleElement) 1429 if (!m_titleElement)
1434 updateTitle(String()); 1430 updateTitle(String());
1435 } 1431 }
1436 1432
1437 const AtomicString& Document::dir() 1433 const AtomicString& Document::dir()
1438 { 1434 {
1439 Element* rootElement = documentElement(); 1435 Element* rootElement = documentElement();
1440 if (isHTMLHtmlElement(rootElement)) 1436 if (isHTMLHtmlElement(rootElement))
1441 return toHTMLHtmlElement(rootElement)->dir(); 1437 return toHTMLHtmlElement(rootElement)->dir();
(...skipping 4409 matching lines...) Expand 10 before | Expand all | Expand 10 after
5851 using namespace WebCore; 5847 using namespace WebCore;
5852 void showLiveDocumentInstances() 5848 void showLiveDocumentInstances()
5853 { 5849 {
5854 WeakDocumentSet& set = liveDocumentSet(); 5850 WeakDocumentSet& set = liveDocumentSet();
5855 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 5851 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
5856 for (WeakDocumentSet::const_iterator it = set.begin(); it != set.end(); ++it ) { 5852 for (WeakDocumentSet::const_iterator it = set.begin(); it != set.end(); ++it ) {
5857 fprintf(stderr, "- Document %p URL: %s\n", *it, (*it)->url().string().ut f8().data()); 5853 fprintf(stderr, "- Document %p URL: %s\n", *it, (*it)->url().string().ut f8().data());
5858 } 5854 }
5859 } 5855 }
5860 #endif 5856 #endif
OLDNEW
« LayoutTests/svg/custom/multiple-title-elements.svg ('K') | « Source/core/dom/Document.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698