| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 99 |
| 100 Position start = EndingSelection().Start(); | 100 Position start = EndingSelection().Start(); |
| 101 Position end_position = ReplaceSelectedTextInNode(text); | 101 Position end_position = ReplaceSelectedTextInNode(text); |
| 102 if (end_position.IsNull()) | 102 if (end_position.IsNull()) |
| 103 return false; | 103 return false; |
| 104 | 104 |
| 105 SetEndingSelectionWithoutValidation(start, end_position); | 105 SetEndingSelectionWithoutValidation(start, end_position); |
| 106 if (select_inserted_text) | 106 if (select_inserted_text) |
| 107 return true; | 107 return true; |
| 108 SetEndingSelection(SelectionInDOMTree::Builder() | 108 SetEndingSelection(SelectionInDOMTree::Builder() |
| 109 .Collapse(EndingSelection().end()) | 109 .Collapse(EndingSelection().End()) |
| 110 .SetIsDirectional(EndingSelection().IsDirectional()) | 110 .SetIsDirectional(EndingSelection().IsDirectional()) |
| 111 .Build()); | 111 .Build()); |
| 112 return true; | 112 return true; |
| 113 } | 113 } |
| 114 | 114 |
| 115 bool InsertTextCommand::PerformOverwrite(const String& text, | 115 bool InsertTextCommand::PerformOverwrite(const String& text, |
| 116 bool select_inserted_text) { | 116 bool select_inserted_text) { |
| 117 Position start = EndingSelection().Start(); | 117 Position start = EndingSelection().Start(); |
| 118 if (start.IsNull() || !start.IsOffsetInAnchor() || | 118 if (start.IsNull() || !start.IsOffsetInAnchor() || |
| 119 !start.ComputeContainerNode()->IsTextNode()) | 119 !start.ComputeContainerNode()->IsTextNode()) |
| 120 return false; | 120 return false; |
| 121 Text* text_node = ToText(start.ComputeContainerNode()); | 121 Text* text_node = ToText(start.ComputeContainerNode()); |
| 122 if (!text_node) | 122 if (!text_node) |
| 123 return false; | 123 return false; |
| 124 | 124 |
| 125 unsigned count = std::min( | 125 unsigned count = std::min( |
| 126 text.length(), text_node->length() - start.OffsetInContainerNode()); | 126 text.length(), text_node->length() - start.OffsetInContainerNode()); |
| 127 if (!count) | 127 if (!count) |
| 128 return false; | 128 return false; |
| 129 | 129 |
| 130 ReplaceTextInNode(text_node, start.OffsetInContainerNode(), count, text); | 130 ReplaceTextInNode(text_node, start.OffsetInContainerNode(), count, text); |
| 131 | 131 |
| 132 Position end_position = | 132 Position end_position = |
| 133 Position(text_node, start.OffsetInContainerNode() + text.length()); | 133 Position(text_node, start.OffsetInContainerNode() + text.length()); |
| 134 SetEndingSelectionWithoutValidation(start, end_position); | 134 SetEndingSelectionWithoutValidation(start, end_position); |
| 135 if (select_inserted_text || EndingSelection().IsNone()) | 135 if (select_inserted_text || EndingSelection().IsNone()) |
| 136 return true; | 136 return true; |
| 137 SetEndingSelection(SelectionInDOMTree::Builder() | 137 SetEndingSelection(SelectionInDOMTree::Builder() |
| 138 .Collapse(EndingSelection().end()) | 138 .Collapse(EndingSelection().End()) |
| 139 .SetIsDirectional(EndingSelection().IsDirectional()) | 139 .SetIsDirectional(EndingSelection().IsDirectional()) |
| 140 .Build()); | 140 .Build()); |
| 141 return true; | 141 return true; |
| 142 } | 142 } |
| 143 | 143 |
| 144 void InsertTextCommand::DoApply(EditingState* editing_state) { | 144 void InsertTextCommand::DoApply(EditingState* editing_state) { |
| 145 DCHECK_EQ(text_.find('\n'), kNotFound); | 145 DCHECK_EQ(text_.find('\n'), kNotFound); |
| 146 | 146 |
| 147 if (!EndingSelection().IsNonOrphanedCaretOrRange()) | 147 if (!EndingSelection().IsNonOrphanedCaretOrRange()) |
| 148 return; | 148 return; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 ApplyStyle(typing_style, editing_state); | 280 ApplyStyle(typing_style, editing_state); |
| 281 if (editing_state->IsAborted()) | 281 if (editing_state->IsAborted()) |
| 282 return; | 282 return; |
| 283 } | 283 } |
| 284 } | 284 } |
| 285 | 285 |
| 286 if (!select_inserted_text_) { | 286 if (!select_inserted_text_) { |
| 287 SelectionInDOMTree::Builder builder; | 287 SelectionInDOMTree::Builder builder; |
| 288 builder.SetAffinity(EndingSelection().Affinity()); | 288 builder.SetAffinity(EndingSelection().Affinity()); |
| 289 builder.SetIsDirectional(EndingSelection().IsDirectional()); | 289 builder.SetIsDirectional(EndingSelection().IsDirectional()); |
| 290 if (EndingSelection().end().IsNotNull()) | 290 if (EndingSelection().End().IsNotNull()) |
| 291 builder.Collapse(EndingSelection().end()); | 291 builder.Collapse(EndingSelection().End()); |
| 292 SetEndingSelection(builder.Build()); | 292 SetEndingSelection(builder.Build()); |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 | 295 |
| 296 Position InsertTextCommand::InsertTab(const Position& pos, | 296 Position InsertTextCommand::InsertTab(const Position& pos, |
| 297 EditingState* editing_state) { | 297 EditingState* editing_state) { |
| 298 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets(); | 298 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets(); |
| 299 | 299 |
| 300 Position insert_pos = CreateVisiblePosition(pos).DeepEquivalent(); | 300 Position insert_pos = CreateVisiblePosition(pos).DeepEquivalent(); |
| 301 if (insert_pos.IsNull()) | 301 if (insert_pos.IsNull()) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 332 } | 332 } |
| 333 } | 333 } |
| 334 if (editing_state->IsAborted()) | 334 if (editing_state->IsAborted()) |
| 335 return Position(); | 335 return Position(); |
| 336 | 336 |
| 337 // return the position following the new tab | 337 // return the position following the new tab |
| 338 return Position::LastPositionInNode(span_element); | 338 return Position::LastPositionInNode(span_element); |
| 339 } | 339 } |
| 340 | 340 |
| 341 } // namespace blink | 341 } // namespace blink |
| OLD | NEW |