| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1035 return; | 1035 return; |
| 1036 VisibleSelection newSelection(range.get(), DOWNSTREAM); | 1036 VisibleSelection newSelection(range.get(), DOWNSTREAM); |
| 1037 | 1037 |
| 1038 // Transpose the two characters. | 1038 // Transpose the two characters. |
| 1039 String text = plainText(range.get()); | 1039 String text = plainText(range.get()); |
| 1040 if (text.length() != 2) | 1040 if (text.length() != 2) |
| 1041 return; | 1041 return; |
| 1042 String transposed = text.right(1) + text.left(1); | 1042 String transposed = text.right(1) + text.left(1); |
| 1043 | 1043 |
| 1044 // Select the two characters. | 1044 // Select the two characters. |
| 1045 if (newSelection != frame().selection().selection()) | 1045 if (!VisibleSelection::InDOMTree::equalSelections(newSelection, frame().sele
ction().selection())) |
| 1046 frame().selection().setSelection(newSelection); | 1046 frame().selection().setSelection(newSelection); |
| 1047 | 1047 |
| 1048 // Insert the transposed characters. | 1048 // Insert the transposed characters. |
| 1049 replaceSelectionWithText(transposed, false, false); | 1049 replaceSelectionWithText(transposed, false, false); |
| 1050 } | 1050 } |
| 1051 | 1051 |
| 1052 void Editor::addToKillRing(Range* range, bool prepend) | 1052 void Editor::addToKillRing(Range* range, bool prepend) |
| 1053 { | 1053 { |
| 1054 if (m_shouldStartNewKillRingSequence) | 1054 if (m_shouldStartNewKillRingSequence) |
| 1055 killRing().startNewSequence(); | 1055 killRing().startNewSequence(); |
| 1056 | 1056 |
| 1057 String text = plainText(range); | 1057 String text = plainText(range); |
| 1058 if (prepend) | 1058 if (prepend) |
| 1059 killRing().prepend(text); | 1059 killRing().prepend(text); |
| 1060 else | 1060 else |
| 1061 killRing().append(text); | 1061 killRing().append(text); |
| 1062 m_shouldStartNewKillRingSequence = false; | 1062 m_shouldStartNewKillRingSequence = false; |
| 1063 } | 1063 } |
| 1064 | 1064 |
| 1065 void Editor::changeSelectionAfterCommand(const VisibleSelection& newSelection,
FrameSelection::SetSelectionOptions options) | 1065 void Editor::changeSelectionAfterCommand(const VisibleSelection& newSelection,
FrameSelection::SetSelectionOptions options) |
| 1066 { | 1066 { |
| 1067 // If the new selection is orphaned, then don't update the selection. | 1067 // If the new selection is orphaned, then don't update the selection. |
| 1068 if (newSelection.start().isOrphan() || newSelection.end().isOrphan()) | 1068 if (newSelection.start().isOrphan() || newSelection.end().isOrphan()) |
| 1069 return; | 1069 return; |
| 1070 | 1070 |
| 1071 // See <rdar://problem/5729315> Some shouldChangeSelectedDOMRange contain Ra
nges for selections that are no longer valid | 1071 // See <rdar://problem/5729315> Some shouldChangeSelectedDOMRange contain Ra
nges for selections that are no longer valid |
| 1072 bool selectionDidNotChangeDOMPosition = newSelection == frame().selection().
selection(); | 1072 bool selectionDidNotChangeDOMPosition = VisibleSelection::InDOMTree::equalSe
lections(newSelection, frame().selection().selection()); |
| 1073 frame().selection().setSelection(newSelection, options); | 1073 frame().selection().setSelection(newSelection, options); |
| 1074 | 1074 |
| 1075 // Some editing operations change the selection visually without affecting i
ts position within the DOM. | 1075 // Some editing operations change the selection visually without affecting i
ts position within the DOM. |
| 1076 // For example when you press return in the following (the caret is marked b
y ^): | 1076 // For example when you press return in the following (the caret is marked b
y ^): |
| 1077 // <div contentEditable="true"><div>^Hello</div></div> | 1077 // <div contentEditable="true"><div>^Hello</div></div> |
| 1078 // WebCore inserts <div><br></div> *before* the current block, which correct
ly moves the paragraph down but which doesn't | 1078 // WebCore inserts <div><br></div> *before* the current block, which correct
ly moves the paragraph down but which doesn't |
| 1079 // change the caret's DOM position (["hello", 0]). In these situations the a
bove FrameSelection::setSelection call | 1079 // change the caret's DOM position (["hello", 0]). In these situations the a
bove FrameSelection::setSelection call |
| 1080 // does not call EditorClient::respondToChangedSelection(), which, on the Ma
c, sends selection change notifications and | 1080 // does not call EditorClient::respondToChangedSelection(), which, on the Ma
c, sends selection change notifications and |
| 1081 // starts a new kill ring sequence, but we want to do these things (matches
AppKit). | 1081 // starts a new kill ring sequence, but we want to do these things (matches
AppKit). |
| 1082 if (selectionDidNotChangeDOMPosition) | 1082 if (selectionDidNotChangeDOMPosition) |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1267 } | 1267 } |
| 1268 | 1268 |
| 1269 DEFINE_TRACE(Editor) | 1269 DEFINE_TRACE(Editor) |
| 1270 { | 1270 { |
| 1271 visitor->trace(m_frame); | 1271 visitor->trace(m_frame); |
| 1272 visitor->trace(m_lastEditCommand); | 1272 visitor->trace(m_lastEditCommand); |
| 1273 visitor->trace(m_mark); | 1273 visitor->trace(m_mark); |
| 1274 } | 1274 } |
| 1275 | 1275 |
| 1276 } // namespace blink | 1276 } // namespace blink |
| OLD | NEW |