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 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 if (Node* firstChild = element->firstChild()) | 1021 if (Node* firstChild = element->firstChild()) |
1022 nextNode = firstChild; | 1022 nextNode = firstChild; |
1023 removeElementPreservingChildren(fragment, element); | 1023 removeElementPreservingChildren(fragment, element); |
1024 } | 1024 } |
1025 } | 1025 } |
1026 return fragment.release(); | 1026 return fragment.release(); |
1027 } | 1027 } |
1028 | 1028 |
1029 void replaceChildrenWithFragment(ContainerNode* container, PassRefPtr<DocumentFr
agment> fragment, ExceptionState& es) | 1029 void replaceChildrenWithFragment(ContainerNode* container, PassRefPtr<DocumentFr
agment> fragment, ExceptionState& es) |
1030 { | 1030 { |
| 1031 ASSERT(container); |
1031 RefPtr<ContainerNode> containerNode(container); | 1032 RefPtr<ContainerNode> containerNode(container); |
1032 | 1033 |
1033 ChildListMutationScope mutation(containerNode.get()); | 1034 ChildListMutationScope mutation(*containerNode); |
1034 | 1035 |
1035 if (!fragment->firstChild()) { | 1036 if (!fragment->firstChild()) { |
1036 containerNode->removeChildren(); | 1037 containerNode->removeChildren(); |
1037 return; | 1038 return; |
1038 } | 1039 } |
1039 | 1040 |
1040 if (containerNode->hasOneTextChild() && fragment->hasOneTextChild()) { | 1041 if (containerNode->hasOneTextChild() && fragment->hasOneTextChild()) { |
1041 toText(containerNode->firstChild())->setData(toText(fragment->firstChild
())->data()); | 1042 toText(containerNode->firstChild())->setData(toText(fragment->firstChild
())->data()); |
1042 return; | 1043 return; |
1043 } | 1044 } |
1044 | 1045 |
1045 if (containerNode->hasOneChild()) { | 1046 if (containerNode->hasOneChild()) { |
1046 containerNode->replaceChild(fragment, containerNode->firstChild(), es); | 1047 containerNode->replaceChild(fragment, containerNode->firstChild(), es); |
1047 return; | 1048 return; |
1048 } | 1049 } |
1049 | 1050 |
1050 containerNode->removeChildren(); | 1051 containerNode->removeChildren(); |
1051 containerNode->appendChild(fragment, es); | 1052 containerNode->appendChild(fragment, es); |
1052 } | 1053 } |
1053 | 1054 |
1054 void replaceChildrenWithText(ContainerNode* container, const String& text, Excep
tionState& es) | 1055 void replaceChildrenWithText(ContainerNode* container, const String& text, Excep
tionState& es) |
1055 { | 1056 { |
| 1057 ASSERT(container); |
1056 RefPtr<ContainerNode> containerNode(container); | 1058 RefPtr<ContainerNode> containerNode(container); |
1057 | 1059 |
1058 ChildListMutationScope mutation(containerNode.get()); | 1060 ChildListMutationScope mutation(*containerNode); |
1059 | 1061 |
1060 if (containerNode->hasOneTextChild()) { | 1062 if (containerNode->hasOneTextChild()) { |
1061 toText(containerNode->firstChild())->setData(text); | 1063 toText(containerNode->firstChild())->setData(text); |
1062 return; | 1064 return; |
1063 } | 1065 } |
1064 | 1066 |
1065 RefPtr<Text> textNode = Text::create(containerNode->document(), text); | 1067 RefPtr<Text> textNode = Text::create(containerNode->document(), text); |
1066 | 1068 |
1067 if (containerNode->hasOneChild()) { | 1069 if (containerNode->hasOneChild()) { |
1068 containerNode->replaceChild(textNode.release(), containerNode->firstChil
d(), es); | 1070 containerNode->replaceChild(textNode.release(), containerNode->firstChil
d(), es); |
1069 return; | 1071 return; |
1070 } | 1072 } |
1071 | 1073 |
1072 containerNode->removeChildren(); | 1074 containerNode->removeChildren(); |
1073 containerNode->appendChild(textNode.release(), es); | 1075 containerNode->appendChild(textNode.release(), es); |
1074 } | 1076 } |
1075 | 1077 |
1076 } | 1078 } |
OLD | NEW |