| 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 25 matching lines...) Expand all Loading... |
| 36 #include "core/editing/htmlediting.h" | 36 #include "core/editing/htmlediting.h" |
| 37 #include "core/html/HTMLElement.h" | 37 #include "core/html/HTMLElement.h" |
| 38 #include "core/html/HTMLTableElement.h" | 38 #include "core/html/HTMLTableElement.h" |
| 39 #include "core/page/Frame.h" | 39 #include "core/page/Frame.h" |
| 40 #include "core/rendering/RenderObject.h" | 40 #include "core/rendering/RenderObject.h" |
| 41 | 41 |
| 42 namespace WebCore { | 42 namespace WebCore { |
| 43 | 43 |
| 44 using namespace HTMLNames; | 44 using namespace HTMLNames; |
| 45 | 45 |
| 46 InsertLineBreakCommand::InsertLineBreakCommand(Document* document) | 46 InsertLineBreakCommand::InsertLineBreakCommand(Document& document) |
| 47 : CompositeEditCommand(document) | 47 : CompositeEditCommand(document) |
| 48 { | 48 { |
| 49 } | 49 } |
| 50 | 50 |
| 51 bool InsertLineBreakCommand::preservesTypingStyle() const | 51 bool InsertLineBreakCommand::preservesTypingStyle() const |
| 52 { | 52 { |
| 53 return true; | 53 return true; |
| 54 } | 54 } |
| 55 | 55 |
| 56 void InsertLineBreakCommand::insertNodeAfterPosition(Node* node, const Position&
pos) | 56 void InsertLineBreakCommand::insertNodeAfterPosition(Node* node, const Position&
pos) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 return; | 101 return; |
| 102 | 102 |
| 103 Position pos(caret.deepEquivalent()); | 103 Position pos(caret.deepEquivalent()); |
| 104 | 104 |
| 105 pos = positionAvoidingSpecialElementBoundary(pos); | 105 pos = positionAvoidingSpecialElementBoundary(pos); |
| 106 | 106 |
| 107 pos = positionOutsideTabSpan(pos); | 107 pos = positionOutsideTabSpan(pos); |
| 108 | 108 |
| 109 RefPtr<Node> nodeToInsert; | 109 RefPtr<Node> nodeToInsert; |
| 110 if (shouldUseBreakElement(pos)) | 110 if (shouldUseBreakElement(pos)) |
| 111 nodeToInsert = createBreakElement(document()); | 111 nodeToInsert = createBreakElement(&document()); |
| 112 else | 112 else |
| 113 nodeToInsert = document()->createTextNode("\n"); | 113 nodeToInsert = document().createTextNode("\n"); |
| 114 | 114 |
| 115 // FIXME: Need to merge text nodes when inserting just after or before text. | 115 // FIXME: Need to merge text nodes when inserting just after or before text. |
| 116 | 116 |
| 117 if (isEndOfParagraph(caret) && !lineBreakExistsAtVisiblePosition(caret)) { | 117 if (isEndOfParagraph(caret) && !lineBreakExistsAtVisiblePosition(caret)) { |
| 118 bool needExtraLineBreak = !pos.deprecatedNode()->hasTagName(hrTag) && !i
sHTMLTableElement(pos.deprecatedNode()); | 118 bool needExtraLineBreak = !pos.deprecatedNode()->hasTagName(hrTag) && !i
sHTMLTableElement(pos.deprecatedNode()); |
| 119 | 119 |
| 120 insertNodeAt(nodeToInsert.get(), pos); | 120 insertNodeAt(nodeToInsert.get(), pos); |
| 121 | 121 |
| 122 if (needExtraLineBreak) | 122 if (needExtraLineBreak) |
| 123 insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert); | 123 insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 138 insertNodeAt(nodeToInsert.get(), pos); | 138 insertNodeAt(nodeToInsert.get(), pos); |
| 139 setEndingSelection(VisibleSelection(positionInParentAfterNode(nodeToInse
rt.get()), DOWNSTREAM, endingSelection().isDirectional())); | 139 setEndingSelection(VisibleSelection(positionInParentAfterNode(nodeToInse
rt.get()), DOWNSTREAM, endingSelection().isDirectional())); |
| 140 } else if (pos.deprecatedNode()->isTextNode()) { | 140 } else if (pos.deprecatedNode()->isTextNode()) { |
| 141 // Split a text node | 141 // Split a text node |
| 142 Text* textNode = toText(pos.deprecatedNode()); | 142 Text* textNode = toText(pos.deprecatedNode()); |
| 143 splitTextNode(textNode, pos.deprecatedEditingOffset()); | 143 splitTextNode(textNode, pos.deprecatedEditingOffset()); |
| 144 insertNodeBefore(nodeToInsert, textNode); | 144 insertNodeBefore(nodeToInsert, textNode); |
| 145 Position endingPosition = firstPositionInNode(textNode); | 145 Position endingPosition = firstPositionInNode(textNode); |
| 146 | 146 |
| 147 // Handle whitespace that occurs after the split | 147 // Handle whitespace that occurs after the split |
| 148 document()->updateLayoutIgnorePendingStylesheets(); | 148 document().updateLayoutIgnorePendingStylesheets(); |
| 149 if (!endingPosition.isRenderedCharacter()) { | 149 if (!endingPosition.isRenderedCharacter()) { |
| 150 Position positionBeforeTextNode(positionInParentBeforeNode(textNode)
); | 150 Position positionBeforeTextNode(positionInParentBeforeNode(textNode)
); |
| 151 // Clear out all whitespace and insert one non-breaking space | 151 // Clear out all whitespace and insert one non-breaking space |
| 152 deleteInsignificantTextDownstream(endingPosition); | 152 deleteInsignificantTextDownstream(endingPosition); |
| 153 ASSERT(!textNode->renderer() || textNode->renderer()->style()->colla
pseWhiteSpace()); | 153 ASSERT(!textNode->renderer() || textNode->renderer()->style()->colla
pseWhiteSpace()); |
| 154 // Deleting insignificant whitespace will remove textNode if it cont
ains nothing but insignificant whitespace. | 154 // Deleting insignificant whitespace will remove textNode if it cont
ains nothing but insignificant whitespace. |
| 155 if (textNode->inDocument()) | 155 if (textNode->inDocument()) |
| 156 insertTextIntoNode(textNode, 0, nonBreakingSpaceString()); | 156 insertTextIntoNode(textNode, 0, nonBreakingSpaceString()); |
| 157 else { | 157 else { |
| 158 RefPtr<Text> nbspNode = document()->createTextNode(nonBreakingSp
aceString()); | 158 RefPtr<Text> nbspNode = document().createTextNode(nonBreakingSpa
ceString()); |
| 159 insertNodeAt(nbspNode.get(), positionBeforeTextNode); | 159 insertNodeAt(nbspNode.get(), positionBeforeTextNode); |
| 160 endingPosition = firstPositionInNode(nbspNode.get()); | 160 endingPosition = firstPositionInNode(nbspNode.get()); |
| 161 } | 161 } |
| 162 } | 162 } |
| 163 | 163 |
| 164 setEndingSelection(VisibleSelection(endingPosition, DOWNSTREAM, endingSe
lection().isDirectional())); | 164 setEndingSelection(VisibleSelection(endingPosition, DOWNSTREAM, endingSe
lection().isDirectional())); |
| 165 } | 165 } |
| 166 | 166 |
| 167 // Handle the case where there is a typing style. | 167 // Handle the case where there is a typing style. |
| 168 | 168 |
| 169 RefPtr<EditingStyle> typingStyle = document()->frame()->selection()->typingS
tyle(); | 169 RefPtr<EditingStyle> typingStyle = document().frame()->selection()->typingSt
yle(); |
| 170 | 170 |
| 171 if (typingStyle && !typingStyle->isEmpty()) { | 171 if (typingStyle && !typingStyle->isEmpty()) { |
| 172 // Apply the typing style to the inserted line break, so that if the sel
ection | 172 // Apply the typing style to the inserted line break, so that if the sel
ection |
| 173 // leaves and then comes back, new input will have the right style. | 173 // leaves and then comes back, new input will have the right style. |
| 174 // FIXME: We shouldn't always apply the typing style to the line break h
ere, | 174 // FIXME: We shouldn't always apply the typing style to the line break h
ere, |
| 175 // see <rdar://problem/5794462>. | 175 // see <rdar://problem/5794462>. |
| 176 applyStyle(typingStyle.get(), firstPositionInOrBeforeNode(nodeToInsert.g
et()), lastPositionInOrAfterNode(nodeToInsert.get())); | 176 applyStyle(typingStyle.get(), firstPositionInOrBeforeNode(nodeToInsert.g
et()), lastPositionInOrAfterNode(nodeToInsert.get())); |
| 177 // Even though this applyStyle operates on a Range, it still sets an end
ingSelection(). | 177 // Even though this applyStyle operates on a Range, it still sets an end
ingSelection(). |
| 178 // It tries to set a VisibleSelection around the content it operated on.
So, that VisibleSelection | 178 // It tries to set a VisibleSelection around the content it operated on.
So, that VisibleSelection |
| 179 // will either (a) select the line break we inserted, or it will (b) be
a caret just | 179 // will either (a) select the line break we inserted, or it will (b) be
a caret just |
| 180 // before the line break (if the line break is at the end of a block it
isn't selectable). | 180 // before the line break (if the line break is at the end of a block it
isn't selectable). |
| 181 // So, this next call sets the endingSelection() to a caret just after t
he line break | 181 // So, this next call sets the endingSelection() to a caret just after t
he line break |
| 182 // that we inserted, or just before it if it's at the end of a block. | 182 // that we inserted, or just before it if it's at the end of a block. |
| 183 setEndingSelection(endingSelection().visibleEnd()); | 183 setEndingSelection(endingSelection().visibleEnd()); |
| 184 } | 184 } |
| 185 | 185 |
| 186 rebalanceWhitespace(); | 186 rebalanceWhitespace(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 } | 189 } |
| OLD | NEW |