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

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

Issue 179333004: Add template parameter to ElementTraversal to iterate over Elements of a specific type (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix failures and port more code to the new API Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/dom/Element.h » ('j') | 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 #include "core/frame/ContentSecurityPolicy.h" 112 #include "core/frame/ContentSecurityPolicy.h"
113 #include "core/frame/DOMWindow.h" 113 #include "core/frame/DOMWindow.h"
114 #include "core/frame/FrameHost.h" 114 #include "core/frame/FrameHost.h"
115 #include "core/frame/FrameView.h" 115 #include "core/frame/FrameView.h"
116 #include "core/frame/History.h" 116 #include "core/frame/History.h"
117 #include "core/frame/LocalFrame.h" 117 #include "core/frame/LocalFrame.h"
118 #include "core/frame/PageConsole.h" 118 #include "core/frame/PageConsole.h"
119 #include "core/frame/Settings.h" 119 #include "core/frame/Settings.h"
120 #include "core/html/HTMLAllCollection.h" 120 #include "core/html/HTMLAllCollection.h"
121 #include "core/html/HTMLAnchorElement.h" 121 #include "core/html/HTMLAnchorElement.h"
122 #include "core/html/HTMLBaseElement.h"
122 #include "core/html/HTMLCanvasElement.h" 123 #include "core/html/HTMLCanvasElement.h"
123 #include "core/html/HTMLCollection.h" 124 #include "core/html/HTMLCollection.h"
124 #include "core/html/HTMLDialogElement.h" 125 #include "core/html/HTMLDialogElement.h"
125 #include "core/html/HTMLDocument.h" 126 #include "core/html/HTMLDocument.h"
126 #include "core/html/HTMLFrameOwnerElement.h" 127 #include "core/html/HTMLFrameOwnerElement.h"
127 #include "core/html/HTMLHeadElement.h" 128 #include "core/html/HTMLHeadElement.h"
128 #include "core/html/HTMLIFrameElement.h" 129 #include "core/html/HTMLIFrameElement.h"
129 #include "core/html/HTMLInputElement.h" 130 #include "core/html/HTMLInputElement.h"
130 #include "core/html/HTMLLinkElement.h" 131 #include "core/html/HTMLLinkElement.h"
131 #include "core/html/HTMLMetaElement.h" 132 #include "core/html/HTMLMetaElement.h"
(...skipping 1219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 { 1352 {
1352 if (m_titleElement != titleElement) 1353 if (m_titleElement != titleElement)
1353 return; 1354 return;
1354 1355
1355 m_titleElement = nullptr; 1356 m_titleElement = nullptr;
1356 m_titleSetExplicitly = false; 1357 m_titleSetExplicitly = false;
1357 1358
1358 // FIXME: This is broken for SVG. 1359 // FIXME: This is broken for SVG.
1359 // Update title based on first title element in the head, if one exists. 1360 // Update title based on first title element in the head, if one exists.
1360 if (HTMLElement* headElement = head()) { 1361 if (HTMLElement* headElement = head()) {
1361 for (Element* element = ElementTraversal::firstWithin(*headElement); ele ment; element = ElementTraversal::nextSibling(*element)) { 1362 if (HTMLTitleElement* title = Traversal<HTMLTitleElement>::firstChild(*h eadElement))
1362 if (!element->hasTagName(titleTag))
1363 continue;
1364 HTMLTitleElement* title = toHTMLTitleElement(element);
1365 setTitleElement(title->text(), title); 1363 setTitleElement(title->text(), title);
1366 break;
1367 }
1368 } 1364 }
1369 1365
1370 if (!m_titleElement) 1366 if (!m_titleElement)
1371 updateTitle(String()); 1367 updateTitle(String());
1372 } 1368 }
1373 1369
1374 PageVisibilityState Document::pageVisibilityState() const 1370 PageVisibilityState Document::pageVisibilityState() const
1375 { 1371 {
1376 // The visibility of the document is inherited from the visibility of the 1372 // The visibility of the document is inherited from the visibility of the
1377 // page. If there is no page associated with the document, we will assume 1373 // page. If there is no page associated with the document, we will assume
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after
2352 else 2348 else
2353 documentElement()->appendChild(newBody.release(), exceptionState); 2349 documentElement()->appendChild(newBody.release(), exceptionState);
2354 } 2350 }
2355 2351
2356 HTMLHeadElement* Document::head() 2352 HTMLHeadElement* Document::head()
2357 { 2353 {
2358 Node* de = documentElement(); 2354 Node* de = documentElement();
2359 if (!de) 2355 if (!de)
2360 return 0; 2356 return 0;
2361 2357
2362 for (Element* child = ElementTraversal::firstWithin(*de); child; child = Ele mentTraversal::nextSibling(*child)) { 2358 return Traversal<HTMLHeadElement>::firstChild(*de);
2363 if (child->hasTagName(headTag))
2364 return toHTMLHeadElement(child);
2365 }
2366 return 0;
2367 } 2359 }
2368 2360
2369 Element* Document::viewportDefiningElement(RenderStyle* rootStyle) const 2361 Element* Document::viewportDefiningElement(RenderStyle* rootStyle) const
2370 { 2362 {
2371 // If a BODY element sets non-visible overflow, it is to be propagated to th e viewport, as long 2363 // If a BODY element sets non-visible overflow, it is to be propagated to th e viewport, as long
2372 // as the following conditions are all met: 2364 // as the following conditions are all met:
2373 // (1) The root element is HTML. 2365 // (1) The root element is HTML.
2374 // (2) It is the primary BODY element (we only assert for this, expecting ca llers to behave). 2366 // (2) It is the primary BODY element (we only assert for this, expecting ca llers to behave).
2375 // (3) The root element has visible overflow. 2367 // (3) The root element has visible overflow.
2376 // Otherwise it's the root element's properties that are to be propagated. 2368 // Otherwise it's the root element's properties that are to be propagated.
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
2733 ASSERT(!m_elemSheet->contents()->ruleCount()); 2725 ASSERT(!m_elemSheet->contents()->ruleCount());
2734 bool usesRemUnits = m_elemSheet->contents()->usesRemUnits(); 2726 bool usesRemUnits = m_elemSheet->contents()->usesRemUnits();
2735 m_elemSheet = CSSStyleSheet::createInline(this, m_baseURL); 2727 m_elemSheet = CSSStyleSheet::createInline(this, m_baseURL);
2736 // FIXME: So we are not really the parser. The right fix is to eliminate the element sheet completely. 2728 // FIXME: So we are not really the parser. The right fix is to eliminate the element sheet completely.
2737 m_elemSheet->contents()->parserSetUsesRemUnits(usesRemUnits); 2729 m_elemSheet->contents()->parserSetUsesRemUnits(usesRemUnits);
2738 } 2730 }
2739 2731
2740 if (!equalIgnoringFragmentIdentifier(oldBaseURL, m_baseURL)) { 2732 if (!equalIgnoringFragmentIdentifier(oldBaseURL, m_baseURL)) {
2741 // Base URL change changes any relative visited links. 2733 // Base URL change changes any relative visited links.
2742 // FIXME: There are other URLs in the tree that would need to be re-eval uated on dynamic base URL change. Style should be invalidated too. 2734 // FIXME: There are other URLs in the tree that would need to be re-eval uated on dynamic base URL change. Style should be invalidated too.
2743 for (Element* element = ElementTraversal::firstWithin(*this); element; e lement = ElementTraversal::next(*element)) { 2735 for (HTMLAnchorElement* anchor = Traversal<HTMLAnchorElement>::firstWith in(*this); anchor; anchor = Traversal<HTMLAnchorElement>::next(*anchor))
2744 if (element->hasTagName(aTag)) 2736 anchor->invalidateCachedVisitedLinkHash();
2745 toHTMLAnchorElement(element)->invalidateCachedVisitedLinkHash();
2746 }
2747 } 2737 }
2748 } 2738 }
2749 2739
2750 void Document::setBaseURLOverride(const KURL& url) 2740 void Document::setBaseURLOverride(const KURL& url)
2751 { 2741 {
2752 m_baseURLOverride = url; 2742 m_baseURLOverride = url;
2753 updateBaseURL(); 2743 updateBaseURL();
2754 } 2744 }
2755 2745
2756 void Document::processBaseElement() 2746 void Document::processBaseElement()
2757 { 2747 {
2758 // Find the first href attribute in a base element and the first target attr ibute in a base element. 2748 // Find the first href attribute in a base element and the first target attr ibute in a base element.
2759 const AtomicString* href = 0; 2749 const AtomicString* href = 0;
2760 const AtomicString* target = 0; 2750 const AtomicString* target = 0;
2761 for (Element* element = ElementTraversal::firstWithin(*this); element && (!h ref || !target); element = ElementTraversal::next(*element)) { 2751 for (HTMLBaseElement* base = Traversal<HTMLBaseElement>::firstWithin(*this); base && (!href || !target); base = Traversal<HTMLBaseElement>::next(*base)) {
2762 if (element->hasTagName(baseTag)) { 2752 if (!href) {
2763 if (!href) { 2753 const AtomicString& value = base->fastGetAttribute(hrefAttr);
2764 const AtomicString& value = element->fastGetAttribute(hrefAttr); 2754 if (!value.isNull())
2765 if (!value.isNull()) 2755 href = &value;
2766 href = &value;
2767 }
2768 if (!target) {
2769 const AtomicString& value = element->fastGetAttribute(targetAttr );
2770 if (!value.isNull())
2771 target = &value;
2772 }
2773 if (contentSecurityPolicy()->isActive())
2774 UseCounter::count(*this, UseCounter::ContentSecurityPolicyWithBa seElement);
2775 } 2756 }
2757 if (!target) {
2758 const AtomicString& value = base->fastGetAttribute(targetAttr);
2759 if (!value.isNull())
2760 target = &value;
2761 }
2762 if (contentSecurityPolicy()->isActive())
2763 UseCounter::count(*this, UseCounter::ContentSecurityPolicyWithBaseEl ement);
2776 } 2764 }
2777 2765
2778 // FIXME: Since this doesn't share code with completeURL it may not handle e ncodings correctly. 2766 // FIXME: Since this doesn't share code with completeURL it may not handle e ncodings correctly.
2779 KURL baseElementURL; 2767 KURL baseElementURL;
2780 if (href) { 2768 if (href) {
2781 String strippedHref = stripLeadingAndTrailingHTMLSpaces(*href); 2769 String strippedHref = stripLeadingAndTrailingHTMLSpaces(*href);
2782 if (!strippedHref.isEmpty()) 2770 if (!strippedHref.isEmpty())
2783 baseElementURL = KURL(url(), strippedHref); 2771 baseElementURL = KURL(url(), strippedHref);
2784 } 2772 }
2785 if (m_baseElementURL != baseElementURL && contentSecurityPolicy()->allowBase URI(baseElementURL)) { 2773 if (m_baseElementURL != baseElementURL && contentSecurityPolicy()->allowBase URI(baseElementURL)) {
(...skipping 2648 matching lines...) Expand 10 before | Expand all | Expand 10 after
5434 void Document::defaultEventHandler(Event* event) 5422 void Document::defaultEventHandler(Event* event)
5435 { 5423 {
5436 if (frame() && frame()->remotePlatformLayer()) { 5424 if (frame() && frame()->remotePlatformLayer()) {
5437 frame()->chromeClient().forwardInputEvent(this, event); 5425 frame()->chromeClient().forwardInputEvent(this, event);
5438 return; 5426 return;
5439 } 5427 }
5440 Node::defaultEventHandler(event); 5428 Node::defaultEventHandler(event);
5441 } 5429 }
5442 5430
5443 } // namespace WebCore 5431 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/dom/Element.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698