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

Side by Side Diff: sky/engine/core/dom/Node.cpp

Issue 698123002: Remove more API from Node and ContainerNode. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 | « sky/engine/core/dom/Node.h ('k') | sky/engine/core/editing/markup.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 * (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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 #include "platform/TracedValue.h" 81 #include "platform/TracedValue.h"
82 #include "wtf/HashSet.h" 82 #include "wtf/HashSet.h"
83 #include "wtf/PassOwnPtr.h" 83 #include "wtf/PassOwnPtr.h"
84 #include "wtf/RefCountedLeakCounter.h" 84 #include "wtf/RefCountedLeakCounter.h"
85 #include "wtf/Vector.h" 85 #include "wtf/Vector.h"
86 #include "wtf/text/CString.h" 86 #include "wtf/text/CString.h"
87 #include "wtf/text/StringBuilder.h" 87 #include "wtf/text/StringBuilder.h"
88 88
89 namespace blink { 89 namespace blink {
90 90
91 struct SameSizeAsNode : NODE_BASE_CLASSES { 91 struct SameSizeAsNode : public EventTarget, public TreeShared<Node> {
92 uint32_t m_nodeFlags; 92 uint32_t m_nodeFlags;
93 void* m_pointer[5]; 93 void* m_pointer[5];
94 }; 94 };
95 95
96 COMPILE_ASSERT(sizeof(Node) <= sizeof(SameSizeAsNode), Node_should_stay_small); 96 COMPILE_ASSERT(sizeof(Node) <= sizeof(SameSizeAsNode), Node_should_stay_small);
97 97
98 #if !ENABLE(OILPAN) 98 #if !ENABLE(OILPAN)
99 void* Node::operator new(size_t size) 99 void* Node::operator new(size_t size)
100 { 100 {
101 ASSERT(isMainThread()); 101 ASSERT(isMainThread());
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 m_data.m_rareData = ElementRareData::create(m_data.m_renderer); 308 m_data.m_rareData = ElementRareData::create(m_data.m_renderer);
309 else 309 else
310 m_data.m_rareData = NodeRareData::create(m_data.m_renderer); 310 m_data.m_rareData = NodeRareData::create(m_data.m_renderer);
311 311
312 ASSERT(m_data.m_rareData); 312 ASSERT(m_data.m_rareData);
313 313
314 setFlag(HasRareDataFlag); 314 setFlag(HasRareDataFlag);
315 return *rareData(); 315 return *rareData();
316 } 316 }
317 317
318 #if !ENABLE(OILPAN)
319 void Node::clearRareData() 318 void Node::clearRareData()
320 { 319 {
321 ASSERT(hasRareData()); 320 ASSERT(hasRareData());
322 ASSERT(!transientMutationObserverRegistry() || transientMutationObserverRegi stry()->isEmpty()); 321 ASSERT(!transientMutationObserverRegistry() || transientMutationObserverRegi stry()->isEmpty());
323 322
324 RenderObject* renderer = m_data.m_rareData->renderer(); 323 RenderObject* renderer = m_data.m_rareData->renderer();
325 if (isElementNode()) 324 if (isElementNode())
326 delete static_cast<ElementRareData*>(m_data.m_rareData); 325 delete static_cast<ElementRareData*>(m_data.m_rareData);
327 else 326 else
328 delete static_cast<NodeRareData*>(m_data.m_rareData); 327 delete static_cast<NodeRareData*>(m_data.m_rareData);
329 m_data.m_renderer = renderer; 328 m_data.m_renderer = renderer;
330 clearFlag(HasRareDataFlag); 329 clearFlag(HasRareDataFlag);
331 } 330 }
332 #endif
333 331
334 Node* Node::toNode() 332 Node* Node::toNode()
335 { 333 {
336 return this; 334 return this;
337 } 335 }
338 336
339 short Node::tabIndex() const 337 short Node::tabIndex() const
340 { 338 {
341 return 0; 339 return 0;
342 } 340 }
343 341
344 String Node::nodeValue() const
345 {
346 return String();
347 }
348
349 void Node::setNodeValue(const String&)
350 {
351 // By default, setting nodeValue has no effect.
352 }
353
354 PassRefPtr<Node> Node::insertBefore(PassRefPtr<Node> newChild, Node* refChild, E xceptionState& exceptionState) 342 PassRefPtr<Node> Node::insertBefore(PassRefPtr<Node> newChild, Node* refChild, E xceptionState& exceptionState)
355 { 343 {
356 if (isContainerNode()) 344 if (isContainerNode())
357 return toContainerNode(this)->insertBefore(newChild, refChild, exception State); 345 return toContainerNode(this)->insertBefore(newChild, refChild, exception State);
358 346
359 exceptionState.throwDOMException(HierarchyRequestError, "This node type does not support this method."); 347 exceptionState.throwDOMException(HierarchyRequestError, "This node type does not support this method.");
360 return nullptr; 348 return nullptr;
361 } 349 }
362 350
363 PassRefPtr<Node> Node::replaceChild(PassRefPtr<Node> newChild, PassRefPtr<Node> oldChild, ExceptionState& exceptionState) 351 PassRefPtr<Node> Node::replaceChild(PassRefPtr<Node> newChild, PassRefPtr<Node> oldChild, ExceptionState& exceptionState)
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 NodeType nodeType = this->nodeType(); 1000 NodeType nodeType = this->nodeType();
1013 if (nodeType != other->nodeType()) 1001 if (nodeType != other->nodeType())
1014 return false; 1002 return false;
1015 1003
1016 if (nodeName() != other->nodeName()) 1004 if (nodeName() != other->nodeName())
1017 return false; 1005 return false;
1018 1006
1019 if (localName() != other->localName()) 1007 if (localName() != other->localName())
1020 return false; 1008 return false;
1021 1009
1022 if (nodeValue() != other->nodeValue())
1023 return false;
1024
1025 if (isElementNode() && !toElement(this)->hasEquivalentAttributes(toElement(o ther))) 1010 if (isElementNode() && !toElement(this)->hasEquivalentAttributes(toElement(o ther)))
1026 return false; 1011 return false;
1027 1012
1028 Node* child = firstChild(); 1013 Node* child = firstChild();
1029 Node* otherChild = other->firstChild(); 1014 Node* otherChild = other->firstChild();
1030 1015
1031 while (child) { 1016 while (child) {
1032 if (!child->isEqualNode(otherChild)) 1017 if (!child->isEqualNode(otherChild))
1033 return false; 1018 return false;
1034 1019
(...skipping 23 matching lines...) Expand all
1058 { 1043 {
1059 StringBuilder content; 1044 StringBuilder content;
1060 appendTextContent(this, convertBRsToNewlines, content); 1045 appendTextContent(this, convertBRsToNewlines, content);
1061 return content.toString(); 1046 return content.toString();
1062 } 1047 }
1063 1048
1064 void Node::setTextContent(const String& text) 1049 void Node::setTextContent(const String& text)
1065 { 1050 {
1066 switch (nodeType()) { 1051 switch (nodeType()) {
1067 case TEXT_NODE: 1052 case TEXT_NODE:
1068 setNodeValue(text); 1053 toText(this)->setData(text);
1069 return; 1054 return;
1070 case ELEMENT_NODE: 1055 case ELEMENT_NODE:
1071 case DOCUMENT_FRAGMENT_NODE: { 1056 case DOCUMENT_FRAGMENT_NODE: {
1072 // FIXME: Merge this logic into replaceChildrenWithText. 1057 // FIXME: Merge this logic into replaceChildrenWithText.
1073 RefPtr<ContainerNode> container = toContainerNode(this); 1058 RefPtr<ContainerNode> container = toContainerNode(this);
1074 1059
1075 // Note: This is an intentional optimization. 1060 // Note: This is an intentional optimization.
1076 // See crbug.com/352836 also. 1061 // See crbug.com/352836 also.
1077 // No need to do anything if the text is identical. 1062 // No need to do anything if the text is identical.
1078 if (container->hasOneTextChild() && toText(container->firstChild())- >data() == text) 1063 if (container->hasOneTextChild() && toText(container->firstChild())- >data() == text)
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1228 stringBuilder.appendLiteral("=\""); 1213 stringBuilder.appendLiteral("=\"");
1229 stringBuilder.append(attr); 1214 stringBuilder.append(attr);
1230 stringBuilder.appendLiteral("\""); 1215 stringBuilder.appendLiteral("\"");
1231 } 1216 }
1232 1217
1233 void Node::showNode(const char* prefix) const 1218 void Node::showNode(const char* prefix) const
1234 { 1219 {
1235 if (!prefix) 1220 if (!prefix)
1236 prefix = ""; 1221 prefix = "";
1237 if (isTextNode()) { 1222 if (isTextNode()) {
1238 String value = nodeValue(); 1223 String value = toText(this)->data();
1239 value.replaceWithLiteral('\\', "\\\\"); 1224 value.replaceWithLiteral('\\', "\\\\");
1240 value.replaceWithLiteral('\n', "\\n"); 1225 value.replaceWithLiteral('\n', "\\n");
1241 fprintf(stderr, "%s%s\t%p \"%s\"\n", prefix, nodeName().utf8().data(), t his, value.utf8().data()); 1226 fprintf(stderr, "%s%s\t%p \"%s\"\n", prefix, nodeName().utf8().data(), t his, value.utf8().data());
1242 } else { 1227 } else {
1243 StringBuilder attrs; 1228 StringBuilder attrs;
1244 appendAttributeDesc(this, attrs, HTMLNames::idAttr, " ID"); 1229 appendAttributeDesc(this, attrs, HTMLNames::idAttr, " ID");
1245 appendAttributeDesc(this, attrs, HTMLNames::classAttr, " CLASS"); 1230 appendAttributeDesc(this, attrs, HTMLNames::classAttr, " CLASS");
1246 appendAttributeDesc(this, attrs, HTMLNames::styleAttr, " STYLE"); 1231 appendAttributeDesc(this, attrs, HTMLNames::styleAttr, " STYLE");
1247 fprintf(stderr, "%s%s\t%p%s\n", prefix, nodeName().utf8().data(), this, attrs.toString().utf8().data()); 1232 fprintf(stderr, "%s%s\t%p%s\n", prefix, nodeName().utf8().data(), this, attrs.toString().utf8().data());
1248 } 1233 }
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1502 EventTargetData& Node::ensureEventTargetData() 1487 EventTargetData& Node::ensureEventTargetData()
1503 { 1488 {
1504 if (hasEventTargetData()) 1489 if (hasEventTargetData())
1505 return *eventTargetDataMap().get(this); 1490 return *eventTargetDataMap().get(this);
1506 setHasEventTargetData(true); 1491 setHasEventTargetData(true);
1507 EventTargetData* data = new EventTargetData; 1492 EventTargetData* data = new EventTargetData;
1508 eventTargetDataMap().set(this, adoptPtr(data)); 1493 eventTargetDataMap().set(this, adoptPtr(data));
1509 return *data; 1494 return *data;
1510 } 1495 }
1511 1496
1512 #if !ENABLE(OILPAN)
1513 void Node::clearEventTargetData() 1497 void Node::clearEventTargetData()
1514 { 1498 {
1515 eventTargetDataMap().remove(this); 1499 eventTargetDataMap().remove(this);
1516 } 1500 }
1517 #endif
1518 1501
1519 Vector<OwnPtr<MutationObserverRegistration> >* Node::mutationObserverRegistry() 1502 Vector<OwnPtr<MutationObserverRegistration> >* Node::mutationObserverRegistry()
1520 { 1503 {
1521 if (!hasRareData()) 1504 if (!hasRareData())
1522 return 0; 1505 return 0;
1523 NodeMutationObserverData* data = rareData()->mutationObserverData(); 1506 NodeMutationObserverData* data = rareData()->mutationObserverData();
1524 if (!data) 1507 if (!data)
1525 return 0; 1508 return 0;
1526 return &data->registry; 1509 return &data->registry;
1527 } 1510 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1591 1574
1592 size_t index = registry->find(registration); 1575 size_t index = registry->find(registration);
1593 ASSERT(index != kNotFound); 1576 ASSERT(index != kNotFound);
1594 if (index == kNotFound) 1577 if (index == kNotFound)
1595 return; 1578 return;
1596 1579
1597 // Deleting the registration may cause this node to be derefed, so we must m ake sure the Vector operation completes 1580 // Deleting the registration may cause this node to be derefed, so we must m ake sure the Vector operation completes
1598 // before that, in case |this| is destroyed (see MutationObserverRegistratio n::m_registrationNodeKeepAlive). 1581 // before that, in case |this| is destroyed (see MutationObserverRegistratio n::m_registrationNodeKeepAlive).
1599 // FIXME: Simplify the registration/transient registration logic to make thi s understandable by humans. 1582 // FIXME: Simplify the registration/transient registration logic to make thi s understandable by humans.
1600 RefPtr<Node> protect(this); 1583 RefPtr<Node> protect(this);
1601 #if ENABLE(OILPAN)
1602 // The explicit dispose() is needed to have the registration
1603 // object unregister itself promptly.
1604 registration->dispose();
1605 #endif
1606 registry->remove(index); 1584 registry->remove(index);
1607 } 1585 }
1608 1586
1609 void Node::registerTransientMutationObserver(MutationObserverRegistration* regis tration) 1587 void Node::registerTransientMutationObserver(MutationObserverRegistration* regis tration)
1610 { 1588 {
1611 ensureRareData().ensureMutationObserverData().transientRegistry.add(registra tion); 1589 ensureRareData().ensureMutationObserverData().transientRegistry.add(registra tion);
1612 } 1590 }
1613 1591
1614 void Node::unregisterTransientMutationObserver(MutationObserverRegistration* reg istration) 1592 void Node::unregisterTransientMutationObserver(MutationObserverRegistration* reg istration)
1615 { 1593 {
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1887 } 1865 }
1888 1866
1889 ASSERT(isHTMLElement()); 1867 ASSERT(isHTMLElement());
1890 setFlag(CustomElementFlag); 1868 setFlag(CustomElementFlag);
1891 setFlag(newState == Upgraded, CustomElementUpgradedFlag); 1869 setFlag(newState == Upgraded, CustomElementUpgradedFlag);
1892 1870
1893 if (oldState == NotCustomElement || newState == Upgraded) 1871 if (oldState == NotCustomElement || newState == Upgraded)
1894 setNeedsStyleRecalc(SubtreeStyleChange); // :unresolved has changed 1872 setNeedsStyleRecalc(SubtreeStyleChange); // :unresolved has changed
1895 } 1873 }
1896 1874
1897 void Node::trace(Visitor* visitor)
1898 {
1899 #if ENABLE(OILPAN)
1900 visitor->trace(m_parentOrShadowHostNode);
1901 visitor->trace(m_previous);
1902 visitor->trace(m_next);
1903 // rareData() and m_data.m_renderer share their storage. We have to trace
1904 // only one of them.
1905 if (hasRareData())
1906 visitor->trace(rareData());
1907 else
1908 visitor->trace(m_data.m_renderer);
1909 visitor->trace(m_treeScope);
1910 #endif
1911 EventTarget::trace(visitor);
1912 }
1913
1914 unsigned Node::lengthOfContents() const 1875 unsigned Node::lengthOfContents() const
1915 { 1876 {
1916 // This switch statement must be consistent with that of Range::processConte ntsBetweenOffsets. 1877 // This switch statement must be consistent with that of Range::processConte ntsBetweenOffsets.
1917 switch (nodeType()) { 1878 switch (nodeType()) {
1918 case Node::TEXT_NODE: 1879 case Node::TEXT_NODE:
1919 return toCharacterData(this)->length(); 1880 return toCharacterData(this)->length();
1920 case Node::ELEMENT_NODE: 1881 case Node::ELEMENT_NODE:
1921 case Node::DOCUMENT_NODE: 1882 case Node::DOCUMENT_NODE:
1922 case Node::DOCUMENT_FRAGMENT_NODE: 1883 case Node::DOCUMENT_FRAGMENT_NODE:
1923 return toContainerNode(this)->countChildren(); 1884 return toContainerNode(this)->countChildren();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1958 node->showTreeForThis(); 1919 node->showTreeForThis();
1959 } 1920 }
1960 1921
1961 void showNodePath(const blink::Node* node) 1922 void showNodePath(const blink::Node* node)
1962 { 1923 {
1963 if (node) 1924 if (node)
1964 node->showNodePathForThis(); 1925 node->showNodePathForThis();
1965 } 1926 }
1966 1927
1967 #endif 1928 #endif
OLDNEW
« no previous file with comments | « sky/engine/core/dom/Node.h ('k') | sky/engine/core/editing/markup.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698