| 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 26 matching lines...) Expand all Loading... |
| 37 namespace blink { | 37 namespace blink { |
| 38 | 38 |
| 39 InsertTextCommand::InsertTextCommand(Document& document, const String& text, boo
l selectInsertedText, RebalanceType rebalanceType) | 39 InsertTextCommand::InsertTextCommand(Document& document, const String& text, boo
l selectInsertedText, RebalanceType rebalanceType) |
| 40 : CompositeEditCommand(document) | 40 : CompositeEditCommand(document) |
| 41 , m_text(text) | 41 , m_text(text) |
| 42 , m_selectInsertedText(selectInsertedText) | 42 , m_selectInsertedText(selectInsertedText) |
| 43 , m_rebalanceType(rebalanceType) | 43 , m_rebalanceType(rebalanceType) |
| 44 { | 44 { |
| 45 } | 45 } |
| 46 | 46 |
| 47 Position InsertTextCommand::positionInsideTextNode(const Position& p) | 47 Position InsertTextCommand::positionInsideTextNode(const Position& p, EditingSta
te* editingState) |
| 48 { | 48 { |
| 49 Position pos = p; | 49 Position pos = p; |
| 50 if (isTabHTMLSpanElementTextNode(pos.anchorNode())) { | 50 if (isTabHTMLSpanElementTextNode(pos.anchorNode())) { |
| 51 RefPtrWillBeRawPtr<Text> textNode = document().createEditingTextNode("")
; | 51 RefPtrWillBeRawPtr<Text> textNode = document().createEditingTextNode("")
; |
| 52 insertNodeAtTabSpanPosition(textNode.get(), pos); | 52 insertNodeAtTabSpanPosition(textNode.get(), pos, editingState); |
| 53 if (editingState->isAborted()) |
| 54 return Position(); |
| 53 return firstPositionInNode(textNode.get()); | 55 return firstPositionInNode(textNode.get()); |
| 54 } | 56 } |
| 55 | 57 |
| 56 // Prepare for text input by looking at the specified position. | 58 // Prepare for text input by looking at the specified position. |
| 57 // It may be necessary to insert a text node to receive characters. | 59 // It may be necessary to insert a text node to receive characters. |
| 58 if (!pos.computeContainerNode()->isTextNode()) { | 60 if (!pos.computeContainerNode()->isTextNode()) { |
| 59 RefPtrWillBeRawPtr<Text> textNode = document().createEditingTextNode("")
; | 61 RefPtrWillBeRawPtr<Text> textNode = document().createEditingTextNode("")
; |
| 60 insertNodeAt(textNode.get(), pos); | 62 insertNodeAt(textNode.get(), pos, editingState); |
| 63 if (editingState->isAborted()) |
| 64 return Position(); |
| 61 return firstPositionInNode(textNode.get()); | 65 return firstPositionInNode(textNode.get()); |
| 62 } | 66 } |
| 63 | 67 |
| 64 return pos; | 68 return pos; |
| 65 } | 69 } |
| 66 | 70 |
| 67 void InsertTextCommand::setEndingSelectionWithoutValidation(const Position& star
tPosition, const Position& endPosition) | 71 void InsertTextCommand::setEndingSelectionWithoutValidation(const Position& star
tPosition, const Position& endPosition) |
| 68 { | 72 { |
| 69 // We could have inserted a part of composed character sequence, | 73 // We could have inserted a part of composed character sequence, |
| 70 // so we are basically treating ending selection as a range to avoid validat
ion. | 74 // so we are basically treating ending selection as a range to avoid validat
ion. |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 endPosition = insertTab(startPosition, editingState); | 195 endPosition = insertTab(startPosition, editingState); |
| 192 if (editingState->isAborted()) | 196 if (editingState->isAborted()) |
| 193 return; | 197 return; |
| 194 // TODO(yosin) We should use |PositionMoveType::Character| for | 198 // TODO(yosin) We should use |PositionMoveType::Character| for |
| 195 // |previousPositionOf()|. | 199 // |previousPositionOf()|. |
| 196 startPosition = previousPositionOf(endPosition, PositionMoveType::Charac
ter); | 200 startPosition = previousPositionOf(endPosition, PositionMoveType::Charac
ter); |
| 197 if (placeholder.isNotNull()) | 201 if (placeholder.isNotNull()) |
| 198 removePlaceholderAt(placeholder); | 202 removePlaceholderAt(placeholder); |
| 199 } else { | 203 } else { |
| 200 // Make sure the document is set up to receive m_text | 204 // Make sure the document is set up to receive m_text |
| 201 startPosition = positionInsideTextNode(startPosition); | 205 startPosition = positionInsideTextNode(startPosition, editingState); |
| 206 if (editingState->isAborted()) |
| 207 return; |
| 202 ASSERT(startPosition.isOffsetInAnchor()); | 208 ASSERT(startPosition.isOffsetInAnchor()); |
| 203 ASSERT(startPosition.computeContainerNode()); | 209 ASSERT(startPosition.computeContainerNode()); |
| 204 ASSERT(startPosition.computeContainerNode()->isTextNode()); | 210 ASSERT(startPosition.computeContainerNode()->isTextNode()); |
| 205 if (placeholder.isNotNull()) | 211 if (placeholder.isNotNull()) |
| 206 removePlaceholderAt(placeholder); | 212 removePlaceholderAt(placeholder); |
| 207 RefPtrWillBeRawPtr<Text> textNode = toText(startPosition.computeContaine
rNode()); | 213 RefPtrWillBeRawPtr<Text> textNode = toText(startPosition.computeContaine
rNode()); |
| 208 const unsigned offset = startPosition.offsetInContainerNode(); | 214 const unsigned offset = startPosition.offsetInContainerNode(); |
| 209 | 215 |
| 210 insertTextIntoNode(textNode, offset, m_text); | 216 insertTextIntoNode(textNode, offset, m_text); |
| 211 endPosition = Position(textNode, offset + m_text.length()); | 217 endPosition = Position(textNode, offset + m_text.length()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 } | 282 } |
| 277 } | 283 } |
| 278 if (editingState->isAborted()) | 284 if (editingState->isAborted()) |
| 279 return Position(); | 285 return Position(); |
| 280 | 286 |
| 281 // return the position following the new tab | 287 // return the position following the new tab |
| 282 return lastPositionInNode(spanElement.get()); | 288 return lastPositionInNode(spanElement.get()); |
| 283 } | 289 } |
| 284 | 290 |
| 285 } // namespace blink | 291 } // namespace blink |
| OLD | NEW |