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

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: Take review comment into consideration 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
« no previous file with comments | « Source/core/dom/Document.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 #include "core/page/PointerLockController.h" 169 #include "core/page/PointerLockController.h"
170 #include "core/page/scrolling/ScrollingCoordinator.h" 170 #include "core/page/scrolling/ScrollingCoordinator.h"
171 #include "core/rendering/FastTextAutosizer.h" 171 #include "core/rendering/FastTextAutosizer.h"
172 #include "core/rendering/HitTestResult.h" 172 #include "core/rendering/HitTestResult.h"
173 #include "core/rendering/RenderView.h" 173 #include "core/rendering/RenderView.h"
174 #include "core/rendering/RenderWidget.h" 174 #include "core/rendering/RenderWidget.h"
175 #include "core/rendering/TextAutosizer.h" 175 #include "core/rendering/TextAutosizer.h"
176 #include "core/rendering/compositing/RenderLayerCompositor.h" 176 #include "core/rendering/compositing/RenderLayerCompositor.h"
177 #include "core/svg/SVGDocumentExtensions.h" 177 #include "core/svg/SVGDocumentExtensions.h"
178 #include "core/svg/SVGFontFaceElement.h" 178 #include "core/svg/SVGFontFaceElement.h"
179 #include "core/svg/SVGTitleElement.h"
179 #include "core/svg/SVGUseElement.h" 180 #include "core/svg/SVGUseElement.h"
180 #include "core/workers/SharedWorkerRepositoryClient.h" 181 #include "core/workers/SharedWorkerRepositoryClient.h"
181 #include "core/xml/XSLTProcessor.h" 182 #include "core/xml/XSLTProcessor.h"
182 #include "core/xml/parser/XMLDocumentParser.h" 183 #include "core/xml/parser/XMLDocumentParser.h"
183 #include "platform/DateComponents.h" 184 #include "platform/DateComponents.h"
184 #include "platform/Language.h" 185 #include "platform/Language.h"
185 #include "platform/RuntimeEnabledFeatures.h" 186 #include "platform/RuntimeEnabledFeatures.h"
186 #include "platform/ScriptForbiddenScope.h" 187 #include "platform/ScriptForbiddenScope.h"
187 #include "platform/TraceEvent.h" 188 #include "platform/TraceEvent.h"
188 #include "platform/network/ContentSecurityPolicyParsers.h" 189 #include "platform/network/ContentSecurityPolicyParsers.h"
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 , m_mutationObserverTypes(0) 455 , m_mutationObserverTypes(0)
455 , m_visitedLinkState(VisitedLinkState::create(*this)) 456 , m_visitedLinkState(VisitedLinkState::create(*this))
456 , m_visuallyOrdered(false) 457 , m_visuallyOrdered(false)
457 , m_readyState(Complete) 458 , m_readyState(Complete)
458 , m_isParsing(false) 459 , m_isParsing(false)
459 , m_gotoAnchorNeededAfterStylesheetsLoad(false) 460 , m_gotoAnchorNeededAfterStylesheetsLoad(false)
460 , m_containsValidityStyleRules(false) 461 , m_containsValidityStyleRules(false)
461 , m_updateFocusAppearanceRestoresSelection(false) 462 , m_updateFocusAppearanceRestoresSelection(false)
462 , m_containsPlugins(false) 463 , m_containsPlugins(false)
463 , m_ignoreDestructiveWriteCount(0) 464 , m_ignoreDestructiveWriteCount(0)
464 , m_titleSetExplicitly(false)
465 , m_markers(adoptPtrWillBeNoop(new DocumentMarkerController)) 465 , m_markers(adoptPtrWillBeNoop(new DocumentMarkerController))
466 , m_updateFocusAppearanceTimer(this, &Document::updateFocusAppearanceTimerFi red) 466 , m_updateFocusAppearanceTimer(this, &Document::updateFocusAppearanceTimerFi red)
467 , m_cssTarget(nullptr) 467 , m_cssTarget(nullptr)
468 , m_loadEventProgress(LoadEventNotRun) 468 , m_loadEventProgress(LoadEventNotRun)
469 , m_startTime(currentTime()) 469 , m_startTime(currentTime())
470 , m_scriptRunner(ScriptRunner::create(this)) 470 , m_scriptRunner(ScriptRunner::create(this))
471 , m_xmlVersion("1.0") 471 , m_xmlVersion("1.0")
472 , m_xmlStandalone(StandaloneUnspecified) 472 , m_xmlStandalone(StandaloneUnspecified)
473 , m_hasXMLDeclaration(0) 473 , m_hasXMLDeclaration(0)
474 , m_designMode(inherit) 474 , m_designMode(inherit)
(...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 m_title = canonicalizedTitle<UChar>(this, m_rawTitle); 1379 m_title = canonicalizedTitle<UChar>(this, m_rawTitle);
1380 1380
1381 if (!m_frame || oldTitle == m_title) 1381 if (!m_frame || oldTitle == m_title)
1382 return; 1382 return;
1383 m_frame->loader().client()->dispatchDidReceiveTitle(m_title); 1383 m_frame->loader().client()->dispatchDidReceiveTitle(m_title);
1384 } 1384 }
1385 1385
1386 void Document::setTitle(const String& title) 1386 void Document::setTitle(const String& title)
1387 { 1387 {
1388 // Title set by JavaScript -- overrides any title elements. 1388 // Title set by JavaScript -- overrides any title elements.
1389 m_titleSetExplicitly = true;
1390 if (!isHTMLDocument() && !isXHTMLDocument()) 1389 if (!isHTMLDocument() && !isXHTMLDocument())
1391 m_titleElement = nullptr; 1390 m_titleElement = nullptr;
1392 else if (!m_titleElement) { 1391 else if (!m_titleElement) {
1393 if (HTMLElement* headElement = head()) { 1392 HTMLElement* headElement = head();
1394 m_titleElement = HTMLTitleElement::create(*this); 1393 if (!headElement)
1395 headElement->appendChild(m_titleElement.get()); 1394 return;
1396 } 1395 m_titleElement = HTMLTitleElement::create(*this);
1396 headElement->appendChild(m_titleElement.get());
1397 } 1397 }
1398 1398
1399 if (isHTMLTitleElement(m_titleElement)) 1399 if (isHTMLTitleElement(m_titleElement))
1400 toHTMLTitleElement(m_titleElement)->setText(title); 1400 toHTMLTitleElement(m_titleElement)->setText(title);
1401 else 1401 else
1402 updateTitle(title); 1402 updateTitle(title);
1403 } 1403 }
1404 1404
1405 void Document::setTitleElement(const String& title, Element* titleElement) 1405 void Document::setTitleElement(const String& title, Element* titleElement)
Inactive 2014/07/22 00:55:22 Hmm, this title argument is no longer used. We sho
1406 { 1406 {
1407 if (titleElement != m_titleElement) { 1407 // Only allow the first title element to change the title -- others have no effect.
1408 if (m_titleElement || m_titleSetExplicitly) 1408 if (m_titleElement && m_titleElement != titleElement) {
1409 // Only allow the first title element to change the title -- others have no effect. 1409 if (isHTMLDocument() || isXHTMLDocument()) {
1410 return; 1410 m_titleElement = Traversal<HTMLTitleElement>::firstWithin(*this);
1411 } else if (isSVGDocument()) {
1412 m_titleElement = Traversal<SVGTitleElement>::firstWithin(*this);
1413 }
1414 } else {
1411 m_titleElement = titleElement; 1415 m_titleElement = titleElement;
1412 } 1416 }
1413 1417
1414 updateTitle(title); 1418 if (isHTMLTitleElement(m_titleElement))
1419 updateTitle(toHTMLTitleElement(m_titleElement)->text());
1420 else if (isSVGTitleElement(m_titleElement))
1421 updateTitle(toSVGTitleElement(m_titleElement)->textContent());
1415 } 1422 }
1416 1423
1417 void Document::removeTitle(Element* titleElement) 1424 void Document::removeTitle(Element* titleElement)
1418 { 1425 {
1419 if (m_titleElement != titleElement) 1426 if (m_titleElement != titleElement)
1420 return; 1427 return;
1421 1428
1422 m_titleElement = nullptr; 1429 m_titleElement = nullptr;
1423 m_titleSetExplicitly = false;
1424 1430
1425 // FIXME: This is broken for SVG. 1431 // FIXME: This is broken for SVG.
1426 // Update title based on first title element in the head, if one exists. 1432 // Update title based on first title element in the document, if one exists.
1427 if (HTMLElement* headElement = head()) { 1433 if (HTMLTitleElement* title = Traversal<HTMLTitleElement>::firstWithin(*this ))
1428 if (HTMLTitleElement* title = Traversal<HTMLTitleElement>::firstChild(*h eadElement)) 1434 setTitleElement(title->text(), title);
1429 setTitleElement(title->text(), title);
1430 }
1431 1435
1432 if (!m_titleElement) 1436 if (!m_titleElement)
1433 updateTitle(String()); 1437 updateTitle(String());
1434 } 1438 }
1435 1439
1436 const AtomicString& Document::dir() 1440 const AtomicString& Document::dir()
1437 { 1441 {
1438 Element* rootElement = documentElement(); 1442 Element* rootElement = documentElement();
1439 if (isHTMLHtmlElement(rootElement)) 1443 if (isHTMLHtmlElement(rootElement))
1440 return toHTMLHtmlElement(rootElement)->dir(); 1444 return toHTMLHtmlElement(rootElement)->dir();
(...skipping 4446 matching lines...) Expand 10 before | Expand all | Expand 10 after
5887 using namespace WebCore; 5891 using namespace WebCore;
5888 void showLiveDocumentInstances() 5892 void showLiveDocumentInstances()
5889 { 5893 {
5890 WeakDocumentSet& set = liveDocumentSet(); 5894 WeakDocumentSet& set = liveDocumentSet();
5891 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 5895 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
5892 for (WeakDocumentSet::const_iterator it = set.begin(); it != set.end(); ++it ) { 5896 for (WeakDocumentSet::const_iterator it = set.begin(); it != set.end(); ++it ) {
5893 fprintf(stderr, "- Document %p URL: %s\n", *it, (*it)->url().string().ut f8().data()); 5897 fprintf(stderr, "- Document %p URL: %s\n", *it, (*it)->url().string().ut f8().data());
5894 } 5898 }
5895 } 5899 }
5896 #endif 5900 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/Document.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698