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

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

Issue 200763006: Node::setTextContent should avoid work when nothing changes (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Updated to actually wokr 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "core/dom/StaticNodeList.h" 52 #include "core/dom/StaticNodeList.h"
53 #include "core/dom/TemplateContentDocumentFragment.h" 53 #include "core/dom/TemplateContentDocumentFragment.h"
54 #include "core/dom/Text.h" 54 #include "core/dom/Text.h"
55 #include "core/dom/TreeScopeAdopter.h" 55 #include "core/dom/TreeScopeAdopter.h"
56 #include "core/dom/UserActionElementSet.h" 56 #include "core/dom/UserActionElementSet.h"
57 #include "core/dom/WheelController.h" 57 #include "core/dom/WheelController.h"
58 #include "core/dom/shadow/ElementShadow.h" 58 #include "core/dom/shadow/ElementShadow.h"
59 #include "core/dom/shadow/InsertionPoint.h" 59 #include "core/dom/shadow/InsertionPoint.h"
60 #include "core/dom/shadow/ShadowRoot.h" 60 #include "core/dom/shadow/ShadowRoot.h"
61 #include "core/editing/htmlediting.h" 61 #include "core/editing/htmlediting.h"
62 #include "core/editing/markup.h"
62 #include "core/events/BeforeLoadEvent.h" 63 #include "core/events/BeforeLoadEvent.h"
63 #include "core/events/Event.h" 64 #include "core/events/Event.h"
64 #include "core/events/EventDispatchMediator.h" 65 #include "core/events/EventDispatchMediator.h"
65 #include "core/events/EventDispatcher.h" 66 #include "core/events/EventDispatcher.h"
66 #include "core/events/EventListener.h" 67 #include "core/events/EventListener.h"
67 #include "core/events/GestureEvent.h" 68 #include "core/events/GestureEvent.h"
68 #include "core/events/KeyboardEvent.h" 69 #include "core/events/KeyboardEvent.h"
69 #include "core/events/MouseEvent.h" 70 #include "core/events/MouseEvent.h"
70 #include "core/events/MutationEvent.h" 71 #include "core/events/MutationEvent.h"
71 #include "core/events/TextEvent.h" 72 #include "core/events/TextEvent.h"
(...skipping 1418 matching lines...) Expand 10 before | Expand all | Expand 10 after
1490 switch (nodeType()) { 1491 switch (nodeType()) {
1491 case TEXT_NODE: 1492 case TEXT_NODE:
1492 case CDATA_SECTION_NODE: 1493 case CDATA_SECTION_NODE:
1493 case COMMENT_NODE: 1494 case COMMENT_NODE:
1494 case PROCESSING_INSTRUCTION_NODE: 1495 case PROCESSING_INSTRUCTION_NODE:
1495 setNodeValue(text); 1496 setNodeValue(text);
1496 return; 1497 return;
1497 case ELEMENT_NODE: 1498 case ELEMENT_NODE:
1498 case ATTRIBUTE_NODE: 1499 case ATTRIBUTE_NODE:
1499 case DOCUMENT_FRAGMENT_NODE: { 1500 case DOCUMENT_FRAGMENT_NODE: {
1501 // FIXME: Merge this logic into replaceChildrenWithText.
1500 RefPtr<ContainerNode> container = toContainerNode(this); 1502 RefPtr<ContainerNode> container = toContainerNode(this);
1503 // No need to do anything if the text is identical.
1504 if (container->hasOneTextChild() && toText(container->firstChild())- >data() == text)
1505 return;
1501 ChildListMutationScope mutation(*this); 1506 ChildListMutationScope mutation(*this);
1502 container->removeChildren(); 1507 container->removeChildren();
1508 // Note: This API will not insert empty text nodes:
1509 // http://dom.spec.whatwg.org/#dom-node-textcontent
1503 if (!text.isEmpty()) 1510 if (!text.isEmpty())
1504 container->appendChild(document().createTextNode(text), ASSERT_N O_EXCEPTION); 1511 container->appendChild(document().createTextNode(text), ASSERT_N O_EXCEPTION);
1505 return; 1512 return;
1506 } 1513 }
1507 case DOCUMENT_NODE: 1514 case DOCUMENT_NODE:
1508 case DOCUMENT_TYPE_NODE: 1515 case DOCUMENT_TYPE_NODE:
1509 // Do nothing. 1516 // Do nothing.
1510 return; 1517 return;
1511 } 1518 }
1512 ASSERT_NOT_REACHED(); 1519 ASSERT_NOT_REACHED();
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after
2535 node->showTreeForThis(); 2542 node->showTreeForThis();
2536 } 2543 }
2537 2544
2538 void showNodePath(const WebCore::Node* node) 2545 void showNodePath(const WebCore::Node* node)
2539 { 2546 {
2540 if (node) 2547 if (node)
2541 node->showNodePathForThis(); 2548 node->showNodePathForThis();
2542 } 2549 }
2543 2550
2544 #endif 2551 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698