OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2008, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2008, 2009 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 addInlineStyleIfNeeded(newInlineStyle.get(), node, node, DoNotAddStyledEleme
nt); | 967 addInlineStyleIfNeeded(newInlineStyle.get(), node, node, DoNotAddStyledEleme
nt); |
968 } | 968 } |
969 | 969 |
970 void ApplyStyleCommand::pushDownInlineStyleAroundNode(EditingStyle* style, Node*
targetNode) | 970 void ApplyStyleCommand::pushDownInlineStyleAroundNode(EditingStyle* style, Node*
targetNode) |
971 { | 971 { |
972 HTMLElement* highestAncestor = highestAncestorWithConflictingInlineStyle(sty
le, targetNode); | 972 HTMLElement* highestAncestor = highestAncestorWithConflictingInlineStyle(sty
le, targetNode); |
973 if (!highestAncestor) | 973 if (!highestAncestor) |
974 return; | 974 return; |
975 | 975 |
976 // The outer loop is traversing the tree vertically from highestAncestor to
targetNode | 976 // The outer loop is traversing the tree vertically from highestAncestor to
targetNode |
977 Node* current = highestAncestor; | 977 RefPtr<Node> current = highestAncestor; |
978 // Along the way, styled elements that contain targetNode are removed and ac
cumulated into elementsToPushDown. | 978 // Along the way, styled elements that contain targetNode are removed and ac
cumulated into elementsToPushDown. |
979 // Each child of the removed element, exclusing ancestors of targetNode, is
then wrapped by clones of elements in elementsToPushDown. | 979 // Each child of the removed element, exclusing ancestors of targetNode, is
then wrapped by clones of elements in elementsToPushDown. |
980 Vector<RefPtr<Element> > elementsToPushDown; | 980 Vector<RefPtr<Element> > elementsToPushDown; |
981 while (current != targetNode) { | 981 while (current && current != targetNode && current->contains(targetNode)) { |
982 ASSERT(current); | |
983 ASSERT(current->contains(targetNode)); | |
984 NodeVector currentChildren; | 982 NodeVector currentChildren; |
985 getChildNodes(current, currentChildren); | 983 getChildNodes(current.get(), currentChildren); |
986 RefPtr<StyledElement> styledElement; | 984 RefPtr<StyledElement> styledElement; |
987 if (current->isStyledElement() && isStyledInlineElementToRemove(static_c
ast<Element*>(current))) { | 985 if (current->isStyledElement() && isStyledInlineElementToRemove(static_c
ast<Element*>(current.get()))) { |
988 styledElement = static_cast<StyledElement*>(current); | 986 styledElement = static_cast<StyledElement*>(current.get()); |
989 elementsToPushDown.append(styledElement); | 987 elementsToPushDown.append(styledElement); |
990 } | 988 } |
991 | 989 |
992 RefPtr<EditingStyle> styleToPushDown = EditingStyle::create(); | 990 RefPtr<EditingStyle> styleToPushDown = EditingStyle::create(); |
993 if (current->isHTMLElement()) | 991 if (current->isHTMLElement()) |
994 removeInlineStyleFromElement(style, toHTMLElement(current), RemoveIf
Needed, styleToPushDown.get()); | 992 removeInlineStyleFromElement(style, toHTMLElement(current.get()), Re
moveIfNeeded, styleToPushDown.get()); |
995 | 993 |
996 // The inner loop will go through children on each level | 994 // The inner loop will go through children on each level |
997 // FIXME: we should aggregate inline child elements together so that we
don't wrap each child separately. | 995 // FIXME: we should aggregate inline child elements together so that we
don't wrap each child separately. |
998 for (size_t i = 0; i < currentChildren.size(); ++i) { | 996 for (size_t i = 0; i < currentChildren.size(); ++i) { |
999 Node* child = currentChildren[i].get(); | 997 Node* child = currentChildren[i].get(); |
1000 if (!child->parentNode()) | 998 if (!child->parentNode()) |
1001 continue; | 999 continue; |
1002 if (!child->contains(targetNode) && elementsToPushDown.size()) { | 1000 if (!child->contains(targetNode) && elementsToPushDown.size()) { |
1003 for (size_t i = 0; i < elementsToPushDown.size(); i++) { | 1001 for (size_t i = 0; i < elementsToPushDown.size(); i++) { |
1004 RefPtr<Element> wrapper = elementsToPushDown[i]->cloneElemen
tWithoutChildren(); | 1002 RefPtr<Element> wrapper = elementsToPushDown[i]->cloneElemen
tWithoutChildren(); |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1477 String textToMove = nextText->data(); | 1475 String textToMove = nextText->data(); |
1478 insertTextIntoNode(childText, childText->length(), textToMove); | 1476 insertTextIntoNode(childText, childText->length(), textToMove); |
1479 removeNode(next); | 1477 removeNode(next); |
1480 // don't move child node pointer. it may want to merge with more text no
des. | 1478 // don't move child node pointer. it may want to merge with more text no
des. |
1481 } | 1479 } |
1482 | 1480 |
1483 updateStartEnd(newStart, newEnd); | 1481 updateStartEnd(newStart, newEnd); |
1484 } | 1482 } |
1485 | 1483 |
1486 } | 1484 } |
OLD | NEW |