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

Side by Side Diff: Source/core/html/HTMLElement.h

Issue 471173003: Introduce HasHTMLTagName functor and use it with ElementTraversal (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add comment Created 6 years, 4 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 | « no previous file | Source/core/html/HTMLTableElement.cpp » ('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 * Copyright (C) 2004-2007, 2009, 2014 Apple Inc. All rights reserved. 4 * Copyright (C) 2004-2007, 2009, 2014 Apple Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 { 142 {
143 ASSERT(!tagName.localName().isNull()); 143 ASSERT(!tagName.localName().isNull());
144 ScriptWrappable::init(this); 144 ScriptWrappable::init(this);
145 } 145 }
146 146
147 inline bool Node::hasTagName(const HTMLQualifiedName& name) const 147 inline bool Node::hasTagName(const HTMLQualifiedName& name) const
148 { 148 {
149 return isHTMLElement() && toHTMLElement(*this).hasTagName(name); 149 return isHTMLElement() && toHTMLElement(*this).hasTagName(name);
150 } 150 }
151 151
152 // Functor used to match HTMLElements with a specific HTML tag when using the El ementTraversal API.
153 class HasHTMLTagName {
154 public:
155 explicit HasHTMLTagName(const HTMLQualifiedName& tagName): m_tagName(tagName ) { }
156 bool operator() (const HTMLElement& element) const { return element.hasTagNa me(m_tagName); }
157 private:
158 const HTMLQualifiedName& m_tagName;
159 };
160
152 // This requires isHTML*Element(const Element&) and isHTML*Element(const HTMLEle ment&). 161 // This requires isHTML*Element(const Element&) and isHTML*Element(const HTMLEle ment&).
153 // When the input element is an HTMLElement, we don't need to check the namespac e URI, just the local name. 162 // When the input element is an HTMLElement, we don't need to check the namespac e URI, just the local name.
154 #define DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(thisType) \ 163 #define DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(thisType) \
155 inline bool is##thisType(const thisType* element); \ 164 inline bool is##thisType(const thisType* element); \
156 inline bool is##thisType(const thisType& element); \ 165 inline bool is##thisType(const thisType& element); \
157 inline bool is##thisType(const HTMLElement* element) { return element && is# #thisType(*element); } \ 166 inline bool is##thisType(const HTMLElement* element) { return element && is# #thisType(*element); } \
158 inline bool is##thisType(const Node& node) { return node.isHTMLElement() ? i s##thisType(toHTMLElement(node)) : false; } \ 167 inline bool is##thisType(const Node& node) { return node.isHTMLElement() ? i s##thisType(toHTMLElement(node)) : false; } \
159 inline bool is##thisType(const Node* node) { return node && is##thisType(*no de); } \ 168 inline bool is##thisType(const Node* node) { return node && is##thisType(*no de); } \
160 inline bool is##thisType(const Element* element) { return element && is##thi sType(*element); } \ 169 inline bool is##thisType(const Element* element) { return element && is##thi sType(*element); } \
161 template<typename T> inline bool is##thisType(const PassRefPtr<T>& node) { r eturn is##thisType(node.get()); } \ 170 template<typename T> inline bool is##thisType(const PassRefPtr<T>& node) { r eturn is##thisType(node.get()); } \
162 template<typename T> inline bool is##thisType(const RefPtr<T>& node) { retur n is##thisType(node.get()); } \ 171 template<typename T> inline bool is##thisType(const RefPtr<T>& node) { retur n is##thisType(node.get()); } \
163 template <> inline bool isElementOfType<const thisType>(const HTMLElement& e lement) { return is##thisType(element); } \ 172 template <> inline bool isElementOfType<const thisType>(const HTMLElement& e lement) { return is##thisType(element); } \
164 DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(thisType) 173 DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(thisType)
165 174
166 } // namespace blink 175 } // namespace blink
167 176
168 #include "core/HTMLElementTypeHelpers.h" 177 #include "core/HTMLElementTypeHelpers.h"
169 178
170 #endif // HTMLElement_h 179 #endif // HTMLElement_h
OLDNEW
« no previous file with comments | « no previous file | Source/core/html/HTMLTableElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698