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

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

Issue 192293002: Use new is*Element() helper functions in DOM code (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add is*Element(PassRefPtr) helper 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
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 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved.
6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 Element *Node::enclosingBlockFlowElement() const 1181 Element *Node::enclosingBlockFlowElement() const
1182 { 1182 {
1183 Node *n = const_cast<Node *>(this); 1183 Node *n = const_cast<Node *>(this);
1184 if (isBlockFlowElement()) 1184 if (isBlockFlowElement())
1185 return toElement(n); 1185 return toElement(n);
1186 1186
1187 while (1) { 1187 while (1) {
1188 n = n->parentNode(); 1188 n = n->parentNode();
1189 if (!n) 1189 if (!n)
1190 break; 1190 break;
1191 if (n->isBlockFlowElement() || n->hasTagName(bodyTag)) 1191 if (n->isBlockFlowElement() || isHTMLBodyElement(*n))
1192 return toElement(n); 1192 return toElement(n);
1193 } 1193 }
1194 return 0; 1194 return 0;
1195 } 1195 }
1196 1196
1197 bool Node::isRootEditableElement() const 1197 bool Node::isRootEditableElement() const
1198 { 1198 {
1199 return rendererIsEditable() && isElementNode() && (!parentNode() || !parentN ode()->rendererIsEditable() 1199 return rendererIsEditable() && isElementNode() && (!parentNode() || !parentN ode()->rendererIsEditable()
1200 || !parentNode()->isElementNode() || hasTagName(bodyTag)); 1200 || !parentNode()->isElementNode() || isHTMLBodyElement((*this)));
1201 } 1201 }
1202 1202
1203 Element* Node::rootEditableElement(EditableType editableType) const 1203 Element* Node::rootEditableElement(EditableType editableType) const
1204 { 1204 {
1205 if (editableType == HasEditableAXRole) { 1205 if (editableType == HasEditableAXRole) {
1206 if (AXObjectCache* cache = document().existingAXObjectCache()) 1206 if (AXObjectCache* cache = document().existingAXObjectCache())
1207 return const_cast<Element*>(cache->rootAXEditableElement(this)); 1207 return const_cast<Element*>(cache->rootAXEditableElement(this));
1208 } 1208 }
1209 1209
1210 return rootEditableElement(); 1210 return rootEditableElement();
1211 } 1211 }
1212 1212
1213 Element* Node::rootEditableElement() const 1213 Element* Node::rootEditableElement() const
1214 { 1214 {
1215 Element* result = 0; 1215 Element* result = 0;
1216 for (Node* n = const_cast<Node*>(this); n && n->rendererIsEditable(); n = n- >parentNode()) { 1216 for (Node* n = const_cast<Node*>(this); n && n->rendererIsEditable(); n = n- >parentNode()) {
1217 if (n->isElementNode()) 1217 if (n->isElementNode())
1218 result = toElement(n); 1218 result = toElement(n);
1219 if (n->hasTagName(bodyTag)) 1219 if (isHTMLBodyElement(*n))
1220 break; 1220 break;
1221 } 1221 }
1222 return result; 1222 return result;
1223 } 1223 }
1224 1224
1225 bool Node::inSameContainingBlockFlowElement(Node *n) 1225 bool Node::inSameContainingBlockFlowElement(Node *n)
1226 { 1226 {
1227 return n ? enclosingBlockFlowElement() == n->enclosingBlockFlowElement() : f alse; 1227 return n ? enclosingBlockFlowElement() == n->enclosingBlockFlowElement() : f alse;
1228 } 1228 }
1229 1229
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 isNullString = false; 1445 isNullString = false;
1446 content.append(toCharacterData(node)->data()); 1446 content.append(toCharacterData(node)->data());
1447 break; 1447 break;
1448 1448
1449 case Node::PROCESSING_INSTRUCTION_NODE: 1449 case Node::PROCESSING_INSTRUCTION_NODE:
1450 isNullString = false; 1450 isNullString = false;
1451 content.append(toProcessingInstruction(node)->data()); 1451 content.append(toProcessingInstruction(node)->data());
1452 break; 1452 break;
1453 1453
1454 case Node::ELEMENT_NODE: 1454 case Node::ELEMENT_NODE:
1455 if (node->hasTagName(brTag) && convertBRsToNewlines) { 1455 if (isHTMLBRElement(*node) && convertBRsToNewlines) {
1456 isNullString = false; 1456 isNullString = false;
1457 content.append('\n'); 1457 content.append('\n');
1458 break; 1458 break;
1459 } 1459 }
1460 // Fall through. 1460 // Fall through.
1461 case Node::ATTRIBUTE_NODE: 1461 case Node::ATTRIBUTE_NODE:
1462 case Node::DOCUMENT_FRAGMENT_NODE: 1462 case Node::DOCUMENT_FRAGMENT_NODE:
1463 isNullString = false; 1463 isNullString = false;
1464 for (Node* child = node->firstChild(); child; child = child->nextSibling ()) { 1464 for (Node* child = node->firstChild(); child; child = child->nextSibling ()) {
1465 if (child->nodeType() == Node::COMMENT_NODE || child->nodeType() == Node::PROCESSING_INSTRUCTION_NODE) 1465 if (child->nodeType() == Node::COMMENT_NODE || child->nodeType() == Node::PROCESSING_INSTRUCTION_NODE)
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1806 traverseTreeAndMark(indent.toString(), youngerShadowRoot, marked Node1, markedLabel1, markedNode2, markedLabel2); 1806 traverseTreeAndMark(indent.toString(), youngerShadowRoot, marked Node1, markedLabel1, markedNode2, markedLabel2);
1807 } else if (ShadowRoot* oldestShadowRoot = oldestShadowRootFor(node)) 1807 } else if (ShadowRoot* oldestShadowRoot = oldestShadowRootFor(node))
1808 traverseTreeAndMark(indent.toString(), oldestShadowRoot, markedNode1 , markedLabel1, markedNode2, markedLabel2); 1808 traverseTreeAndMark(indent.toString(), oldestShadowRoot, markedNode1 , markedLabel1, markedNode2, markedLabel2);
1809 } 1809 }
1810 } 1810 }
1811 1811
1812 void Node::showTreeAndMark(const Node* markedNode1, const char* markedLabel1, co nst Node* markedNode2, const char* markedLabel2) const 1812 void Node::showTreeAndMark(const Node* markedNode1, const char* markedLabel1, co nst Node* markedNode2, const char* markedLabel2) const
1813 { 1813 {
1814 const Node* rootNode; 1814 const Node* rootNode;
1815 const Node* node = this; 1815 const Node* node = this;
1816 while (node->parentOrShadowHostNode() && !node->hasTagName(bodyTag)) 1816 while (node->parentOrShadowHostNode() && !isHTMLBodyElement(*node))
1817 node = node->parentOrShadowHostNode(); 1817 node = node->parentOrShadowHostNode();
1818 rootNode = node; 1818 rootNode = node;
1819 1819
1820 String startingIndent; 1820 String startingIndent;
1821 traverseTreeAndMark(startingIndent, rootNode, markedNode1, markedLabel1, mar kedNode2, markedLabel2); 1821 traverseTreeAndMark(startingIndent, rootNode, markedNode1, markedLabel1, mar kedNode2, markedLabel2);
1822 } 1822 }
1823 1823
1824 void Node::formatForDebugger(char* buffer, unsigned length) const 1824 void Node::formatForDebugger(char* buffer, unsigned length) const
1825 { 1825 {
1826 String result; 1826 String result;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1873 #endif 1873 #endif
1874 1874
1875 // -------- 1875 // --------
1876 1876
1877 Node* Node::enclosingLinkEventParentOrSelf() 1877 Node* Node::enclosingLinkEventParentOrSelf()
1878 { 1878 {
1879 for (Node* node = this; node; node = node->parentOrShadowHostNode()) { 1879 for (Node* node = this; node; node = node->parentOrShadowHostNode()) {
1880 // For imagemaps, the enclosing link node is the associated area element not the image itself. 1880 // For imagemaps, the enclosing link node is the associated area element not the image itself.
1881 // So we don't let images be the enclosingLinkNode, even though isLink s ometimes returns true 1881 // So we don't let images be the enclosingLinkNode, even though isLink s ometimes returns true
1882 // for them. 1882 // for them.
1883 if (node->isLink() && !node->hasTagName(imgTag)) 1883 if (node->isLink() && !isHTMLImageElement(*node))
1884 return node; 1884 return node;
1885 } 1885 }
1886 1886
1887 return 0; 1887 return 0;
1888 } 1888 }
1889 1889
1890 const AtomicString& Node::interfaceName() const 1890 const AtomicString& Node::interfaceName() const
1891 { 1891 {
1892 return EventTargetNames::Node; 1892 return EventTargetNames::Node;
1893 } 1893 }
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
2532 node->showTreeForThis(); 2532 node->showTreeForThis();
2533 } 2533 }
2534 2534
2535 void showNodePath(const WebCore::Node* node) 2535 void showNodePath(const WebCore::Node* node)
2536 { 2536 {
2537 if (node) 2537 if (node)
2538 node->showNodePathForThis(); 2538 node->showNodePathForThis();
2539 } 2539 }
2540 2540
2541 #endif 2541 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698