| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2005 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 if (text.contains('\t') || text.contains(' ') || text.contains('\n')) | 94 if (text.contains('\t') || text.contains(' ') || text.contains('\n')) |
| 95 return false; | 95 return false; |
| 96 | 96 |
| 97 Position start = endingSelection().start(); | 97 Position start = endingSelection().start(); |
| 98 Position endPosition = replaceSelectedTextInNode(text); | 98 Position endPosition = replaceSelectedTextInNode(text); |
| 99 if (endPosition.isNull()) | 99 if (endPosition.isNull()) |
| 100 return false; | 100 return false; |
| 101 | 101 |
| 102 setEndingSelectionWithoutValidation(start, endPosition); | 102 setEndingSelectionWithoutValidation(start, endPosition); |
| 103 if (!selectInsertedText) | 103 if (!selectInsertedText) |
| 104 setEndingSelection(VisibleSelection(endingSelection().visibleEndDeprecat
ed(), endingSelection().isDirectional())); | 104 setEndingSelection(createVisibleSelectionDeprecated(endingSelection().vi
sibleEndDeprecated(), endingSelection().isDirectional())); |
| 105 | 105 |
| 106 return true; | 106 return true; |
| 107 } | 107 } |
| 108 | 108 |
| 109 bool InsertTextCommand::performOverwrite(const String& text, bool selectInserted
Text) | 109 bool InsertTextCommand::performOverwrite(const String& text, bool selectInserted
Text) |
| 110 { | 110 { |
| 111 Position start = endingSelection().start(); | 111 Position start = endingSelection().start(); |
| 112 if (start.isNull() || !start.isOffsetInAnchor() || !start.computeContainerNo
de()->isTextNode()) | 112 if (start.isNull() || !start.isOffsetInAnchor() || !start.computeContainerNo
de()->isTextNode()) |
| 113 return false; | 113 return false; |
| 114 Text* textNode = toText(start.computeContainerNode()); | 114 Text* textNode = toText(start.computeContainerNode()); |
| 115 if (!textNode) | 115 if (!textNode) |
| 116 return false; | 116 return false; |
| 117 | 117 |
| 118 unsigned count = std::min(text.length(), textNode->length() - start.offsetIn
ContainerNode()); | 118 unsigned count = std::min(text.length(), textNode->length() - start.offsetIn
ContainerNode()); |
| 119 if (!count) | 119 if (!count) |
| 120 return false; | 120 return false; |
| 121 | 121 |
| 122 replaceTextInNode(textNode, start.offsetInContainerNode(), count, text); | 122 replaceTextInNode(textNode, start.offsetInContainerNode(), count, text); |
| 123 | 123 |
| 124 Position endPosition = Position(textNode, start.offsetInContainerNode() + te
xt.length()); | 124 Position endPosition = Position(textNode, start.offsetInContainerNode() + te
xt.length()); |
| 125 setEndingSelectionWithoutValidation(start, endPosition); | 125 setEndingSelectionWithoutValidation(start, endPosition); |
| 126 if (!selectInsertedText) | 126 if (!selectInsertedText) |
| 127 setEndingSelection(VisibleSelection(endingSelection().visibleEndDeprecat
ed(), endingSelection().isDirectional())); | 127 setEndingSelection(createVisibleSelectionDeprecated(endingSelection().vi
sibleEndDeprecated(), endingSelection().isDirectional())); |
| 128 | 128 |
| 129 return true; | 129 return true; |
| 130 } | 130 } |
| 131 | 131 |
| 132 void InsertTextCommand::doApply(EditingState* editingState) | 132 void InsertTextCommand::doApply(EditingState* editingState) |
| 133 { | 133 { |
| 134 DCHECK_EQ(m_text.find('\n'), kNotFound); | 134 DCHECK_EQ(m_text.find('\n'), kNotFound); |
| 135 | 135 |
| 136 if (!endingSelection().isNonOrphanedCaretOrRange()) | 136 if (!endingSelection().isNonOrphanedCaretOrRange()) |
| 137 return; | 137 return; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 if (EditingStyle* typingStyle = document().frame()->selection().typingStyle(
)) { | 238 if (EditingStyle* typingStyle = document().frame()->selection().typingStyle(
)) { |
| 239 typingStyle->prepareToApplyAt(endPosition, EditingStyle::PreserveWriting
Direction); | 239 typingStyle->prepareToApplyAt(endPosition, EditingStyle::PreserveWriting
Direction); |
| 240 if (!typingStyle->isEmpty()) { | 240 if (!typingStyle->isEmpty()) { |
| 241 applyStyle(typingStyle, editingState); | 241 applyStyle(typingStyle, editingState); |
| 242 if (editingState->isAborted()) | 242 if (editingState->isAborted()) |
| 243 return; | 243 return; |
| 244 } | 244 } |
| 245 } | 245 } |
| 246 | 246 |
| 247 if (!m_selectInsertedText) | 247 if (!m_selectInsertedText) |
| 248 setEndingSelection(VisibleSelection(endingSelection().end(), endingSelec
tion().affinity(), endingSelection().isDirectional())); | 248 setEndingSelection(createVisibleSelectionDeprecated(endingSelection().en
d(), endingSelection().affinity(), endingSelection().isDirectional())); |
| 249 } | 249 } |
| 250 | 250 |
| 251 Position InsertTextCommand::insertTab(const Position& pos, EditingState* editing
State) | 251 Position InsertTextCommand::insertTab(const Position& pos, EditingState* editing
State) |
| 252 { | 252 { |
| 253 Position insertPos = createVisiblePositionDeprecated(pos).deepEquivalent(); | 253 Position insertPos = createVisiblePositionDeprecated(pos).deepEquivalent(); |
| 254 if (insertPos.isNull()) | 254 if (insertPos.isNull()) |
| 255 return pos; | 255 return pos; |
| 256 | 256 |
| 257 Node* node = insertPos.computeContainerNode(); | 257 Node* node = insertPos.computeContainerNode(); |
| 258 unsigned offset = node->isTextNode() ? insertPos.offsetInContainerNode() : 0
; | 258 unsigned offset = node->isTextNode() ? insertPos.offsetInContainerNode() : 0
; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 285 } | 285 } |
| 286 } | 286 } |
| 287 if (editingState->isAborted()) | 287 if (editingState->isAborted()) |
| 288 return Position(); | 288 return Position(); |
| 289 | 289 |
| 290 // return the position following the new tab | 290 // return the position following the new tab |
| 291 return Position::lastPositionInNode(spanElement); | 291 return Position::lastPositionInNode(spanElement); |
| 292 } | 292 } |
| 293 | 293 |
| 294 } // namespace blink | 294 } // namespace blink |
| OLD | NEW |