| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006 Apple Computer, 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 // FIXME: Need to merge text nodes when inserting just after or before text. | 92 // FIXME: Need to merge text nodes when inserting just after or before text. |
| 93 | 93 |
| 94 if (isEndOfParagraph(caret) && !lineBreakExistsAtVisiblePosition(caret)) { | 94 if (isEndOfParagraph(caret) && !lineBreakExistsAtVisiblePosition(caret)) { |
| 95 bool needExtraLineBreak = !isHTMLHRElement(*pos.anchorNode()) && !isHTML
TableElement(*pos.anchorNode()); | 95 bool needExtraLineBreak = !isHTMLHRElement(*pos.anchorNode()) && !isHTML
TableElement(*pos.anchorNode()); |
| 96 | 96 |
| 97 insertNodeAt(nodeToInsert.get(), pos); | 97 insertNodeAt(nodeToInsert.get(), pos); |
| 98 | 98 |
| 99 if (needExtraLineBreak) | 99 if (needExtraLineBreak) |
| 100 insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert); | 100 insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert); |
| 101 | 101 |
| 102 VisiblePosition endingPosition(positionBeforeNode(nodeToInsert.get())); | 102 VisiblePosition endingPosition = createVisiblePosition(positionBeforeNod
e(nodeToInsert.get())); |
| 103 setEndingSelection(VisibleSelection(endingPosition, endingSelection().is
Directional())); | 103 setEndingSelection(VisibleSelection(endingPosition, endingSelection().is
Directional())); |
| 104 } else if (pos.computeEditingOffset() <= caretMinOffset(pos.anchorNode())) { | 104 } else if (pos.computeEditingOffset() <= caretMinOffset(pos.anchorNode())) { |
| 105 insertNodeAt(nodeToInsert.get(), pos); | 105 insertNodeAt(nodeToInsert.get(), pos); |
| 106 | 106 |
| 107 // Insert an extra br or '\n' if the just inserted one collapsed. | 107 // Insert an extra br or '\n' if the just inserted one collapsed. |
| 108 if (!isStartOfParagraph(VisiblePosition(positionBeforeNode(nodeToInsert.
get())))) | 108 if (!isStartOfParagraph(createVisiblePosition(positionBeforeNode(nodeToI
nsert.get())))) |
| 109 insertNodeBefore(nodeToInsert->cloneNode(false).get(), nodeToInsert.
get()); | 109 insertNodeBefore(nodeToInsert->cloneNode(false).get(), nodeToInsert.
get()); |
| 110 | 110 |
| 111 setEndingSelection(VisibleSelection(positionInParentAfterNode(*nodeToIns
ert), TextAffinity::Downstream, endingSelection().isDirectional())); | 111 setEndingSelection(VisibleSelection(positionInParentAfterNode(*nodeToIns
ert), TextAffinity::Downstream, endingSelection().isDirectional())); |
| 112 // If we're inserting after all of the rendered text in a text node, or into
a non-text node, | 112 // If we're inserting after all of the rendered text in a text node, or into
a non-text node, |
| 113 // a simple insertion is sufficient. | 113 // a simple insertion is sufficient. |
| 114 } else if (!pos.anchorNode()->isTextNode() || pos.computeOffsetInContainerNo
de() >= caretMaxOffset(pos.anchorNode())) { | 114 } else if (!pos.anchorNode()->isTextNode() || pos.computeOffsetInContainerNo
de() >= caretMaxOffset(pos.anchorNode())) { |
| 115 insertNodeAt(nodeToInsert.get(), pos); | 115 insertNodeAt(nodeToInsert.get(), pos); |
| 116 setEndingSelection(VisibleSelection(positionInParentAfterNode(*nodeToIns
ert), TextAffinity::Downstream, endingSelection().isDirectional())); | 116 setEndingSelection(VisibleSelection(positionInParentAfterNode(*nodeToIns
ert), TextAffinity::Downstream, endingSelection().isDirectional())); |
| 117 } else if (pos.anchorNode()->isTextNode()) { | 117 } else if (pos.anchorNode()->isTextNode()) { |
| 118 // Split a text node | 118 // Split a text node |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 // before the line break (if the line break is at the end of a block it
isn't selectable). | 159 // before the line break (if the line break is at the end of a block it
isn't selectable). |
| 160 // So, this next call sets the endingSelection() to a caret just after t
he line break | 160 // So, this next call sets the endingSelection() to a caret just after t
he line break |
| 161 // that we inserted, or just before it if it's at the end of a block. | 161 // that we inserted, or just before it if it's at the end of a block. |
| 162 setEndingSelection(endingSelection().visibleEnd()); | 162 setEndingSelection(endingSelection().visibleEnd()); |
| 163 } | 163 } |
| 164 | 164 |
| 165 rebalanceWhitespace(); | 165 rebalanceWhitespace(); |
| 166 } | 166 } |
| 167 | 167 |
| 168 } | 168 } |
| OLD | NEW |