OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed. |
3 * Copyright (C) 2008, 2009, 2010, 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2008, 2009, 2010, 2011 Google Inc. All rights reserved. |
4 * Copyright (C) 2011 Igalia S.L. | 4 * Copyright (C) 2011 Igalia S.L. |
5 * Copyright (C) 2011 Motorola Mobility. All rights reserved. | 5 * Copyright (C) 2011 Motorola Mobility. All rights reserved. |
6 * | 6 * |
7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
9 * are met: | 9 * are met: |
10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
999 ASSERT(container); | 999 ASSERT(container); |
1000 RefPtr<ContainerNode> containerNode(container); | 1000 RefPtr<ContainerNode> containerNode(container); |
1001 | 1001 |
1002 ChildListMutationScope mutation(*containerNode); | 1002 ChildListMutationScope mutation(*containerNode); |
1003 | 1003 |
1004 if (!fragment->firstChild()) { | 1004 if (!fragment->firstChild()) { |
1005 containerNode->removeChildren(); | 1005 containerNode->removeChildren(); |
1006 return; | 1006 return; |
1007 } | 1007 } |
1008 | 1008 |
1009 // FIXME: This is wrong if containerNode->firstChild() has more than one ref ! | |
Julien - ping for review
2014/03/18 22:55:55
I am not sure I understand this comment. All refer
| |
1009 if (containerNode->hasOneTextChild() && fragment->hasOneTextChild()) { | 1010 if (containerNode->hasOneTextChild() && fragment->hasOneTextChild()) { |
1010 toText(containerNode->firstChild())->setData(toText(fragment->firstChild ())->data()); | 1011 toText(containerNode->firstChild())->setData(toText(fragment->firstChild ())->data()); |
1011 return; | 1012 return; |
1012 } | 1013 } |
1013 | 1014 |
1015 // FIXME: No need to replace the child it is a text node and its contents ar e already == text. | |
1014 if (containerNode->hasOneChild()) { | 1016 if (containerNode->hasOneChild()) { |
1015 containerNode->replaceChild(fragment, containerNode->firstChild(), excep tionState); | 1017 containerNode->replaceChild(fragment, containerNode->firstChild(), excep tionState); |
1016 return; | 1018 return; |
1017 } | 1019 } |
1018 | 1020 |
1019 containerNode->removeChildren(); | 1021 containerNode->removeChildren(); |
1020 containerNode->appendChild(fragment, exceptionState); | 1022 containerNode->appendChild(fragment, exceptionState); |
1021 } | 1023 } |
1022 | 1024 |
1023 void replaceChildrenWithText(ContainerNode* container, const String& text, Excep tionState& exceptionState) | 1025 void replaceChildrenWithText(ContainerNode* container, const String& text, Excep tionState& exceptionState) |
1024 { | 1026 { |
1025 ASSERT(container); | 1027 ASSERT(container); |
1026 RefPtr<ContainerNode> containerNode(container); | 1028 RefPtr<ContainerNode> containerNode(container); |
1027 | 1029 |
1028 ChildListMutationScope mutation(*containerNode); | 1030 ChildListMutationScope mutation(*containerNode); |
1029 | 1031 |
1032 // FIXME: This is wrong if containerNode->firstChild() has more than one ref ! | |
1030 if (containerNode->hasOneTextChild()) { | 1033 if (containerNode->hasOneTextChild()) { |
1031 toText(containerNode->firstChild())->setData(text); | 1034 toText(containerNode->firstChild())->setData(text); |
1032 return; | 1035 return; |
1033 } | 1036 } |
1034 | 1037 |
1038 // NOTE: This method currently always creates a text node, even if that text node will be empty. | |
1035 RefPtr<Text> textNode = Text::create(containerNode->document(), text); | 1039 RefPtr<Text> textNode = Text::create(containerNode->document(), text); |
1036 | 1040 |
1041 // FIXME: No need to replace the child it is a text node and its contents ar e already == text. | |
1037 if (containerNode->hasOneChild()) { | 1042 if (containerNode->hasOneChild()) { |
1038 containerNode->replaceChild(textNode.release(), containerNode->firstChil d(), exceptionState); | 1043 containerNode->replaceChild(textNode.release(), containerNode->firstChil d(), exceptionState); |
1039 return; | 1044 return; |
1040 } | 1045 } |
1041 | 1046 |
1042 containerNode->removeChildren(); | 1047 containerNode->removeChildren(); |
1043 containerNode->appendChild(textNode.release(), exceptionState); | 1048 containerNode->appendChild(textNode.release(), exceptionState); |
1044 } | 1049 } |
1045 | 1050 |
1046 void mergeWithNextTextNode(PassRefPtr<Node> node, ExceptionState& exceptionState ) | 1051 void mergeWithNextTextNode(PassRefPtr<Node> node, ExceptionState& exceptionState ) |
1047 { | 1052 { |
1048 ASSERT(node && node->isTextNode()); | 1053 ASSERT(node && node->isTextNode()); |
1049 Node* next = node->nextSibling(); | 1054 Node* next = node->nextSibling(); |
1050 if (!next || !next->isTextNode()) | 1055 if (!next || !next->isTextNode()) |
1051 return; | 1056 return; |
1052 | 1057 |
1053 RefPtr<Text> textNode = toText(node.get()); | 1058 RefPtr<Text> textNode = toText(node.get()); |
1054 RefPtr<Text> textNext = toText(next); | 1059 RefPtr<Text> textNext = toText(next); |
1055 textNode->appendData(textNext->data()); | 1060 textNode->appendData(textNext->data()); |
1056 if (textNext->parentNode()) // Might have been removed by mutation event. | 1061 if (textNext->parentNode()) // Might have been removed by mutation event. |
1057 textNext->remove(exceptionState); | 1062 textNext->remove(exceptionState); |
1058 } | 1063 } |
1059 | 1064 |
1060 } | 1065 } |
OLD | NEW |