| 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
! |
| 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
! Example: |
| 1033 // <div>foo</div> |
| 1034 // <script> |
| 1035 // var oldText = div.firstChild; |
| 1036 // console.log(oldText.data); // foo |
| 1037 // div.innerText = "bar"; |
| 1038 // console.log(oldText.data); // bar!?! |
| 1039 // </script> |
| 1040 // I believe this is an intentional benchmark cheat from years ago. |
| 1041 // We should re-visit if we actually want this still. |
| 1030 if (containerNode->hasOneTextChild()) { | 1042 if (containerNode->hasOneTextChild()) { |
| 1031 toText(containerNode->firstChild())->setData(text); | 1043 toText(containerNode->firstChild())->setData(text); |
| 1032 return; | 1044 return; |
| 1033 } | 1045 } |
| 1034 | 1046 |
| 1047 // 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); | 1048 RefPtr<Text> textNode = Text::create(containerNode->document(), text); |
| 1036 | 1049 |
| 1050 // FIXME: No need to replace the child it is a text node and its contents ar
e already == text. |
| 1037 if (containerNode->hasOneChild()) { | 1051 if (containerNode->hasOneChild()) { |
| 1038 containerNode->replaceChild(textNode.release(), containerNode->firstChil
d(), exceptionState); | 1052 containerNode->replaceChild(textNode.release(), containerNode->firstChil
d(), exceptionState); |
| 1039 return; | 1053 return; |
| 1040 } | 1054 } |
| 1041 | 1055 |
| 1042 containerNode->removeChildren(); | 1056 containerNode->removeChildren(); |
| 1043 containerNode->appendChild(textNode.release(), exceptionState); | 1057 containerNode->appendChild(textNode.release(), exceptionState); |
| 1044 } | 1058 } |
| 1045 | 1059 |
| 1046 void mergeWithNextTextNode(PassRefPtr<Node> node, ExceptionState& exceptionState
) | 1060 void mergeWithNextTextNode(PassRefPtr<Node> node, ExceptionState& exceptionState
) |
| 1047 { | 1061 { |
| 1048 ASSERT(node && node->isTextNode()); | 1062 ASSERT(node && node->isTextNode()); |
| 1049 Node* next = node->nextSibling(); | 1063 Node* next = node->nextSibling(); |
| 1050 if (!next || !next->isTextNode()) | 1064 if (!next || !next->isTextNode()) |
| 1051 return; | 1065 return; |
| 1052 | 1066 |
| 1053 RefPtr<Text> textNode = toText(node.get()); | 1067 RefPtr<Text> textNode = toText(node.get()); |
| 1054 RefPtr<Text> textNext = toText(next); | 1068 RefPtr<Text> textNext = toText(next); |
| 1055 textNode->appendData(textNext->data()); | 1069 textNode->appendData(textNext->data()); |
| 1056 if (textNext->parentNode()) // Might have been removed by mutation event. | 1070 if (textNext->parentNode()) // Might have been removed by mutation event. |
| 1057 textNext->remove(exceptionState); | 1071 textNext->remove(exceptionState); |
| 1058 } | 1072 } |
| 1059 | 1073 |
| 1060 } | 1074 } |
| OLD | NEW |