| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 DCHECK(m_editor->m_preventRevealSelection); | 145 DCHECK(m_editor->m_preventRevealSelection); |
| 146 --m_editor->m_preventRevealSelection; | 146 --m_editor->m_preventRevealSelection; |
| 147 if (!m_editor->m_preventRevealSelection) { | 147 if (!m_editor->m_preventRevealSelection) { |
| 148 m_editor->frame().selection().revealSelection( | 148 m_editor->frame().selection().revealSelection( |
| 149 ScrollAlignment::alignToEdgeIfNeeded, RevealExtent); | 149 ScrollAlignment::alignToEdgeIfNeeded, RevealExtent); |
| 150 } | 150 } |
| 151 } | 151 } |
| 152 | 152 |
| 153 // When an event handler has moved the selection outside of a text control | 153 // When an event handler has moved the selection outside of a text control |
| 154 // we should use the target control's selection for this editing operation. | 154 // we should use the target control's selection for this editing operation. |
| 155 // TODO(yosin): We should make |Editor::selectionForCommand()| to return |
| 156 // |SelectionInDOMTree| instead of |VisibleSelection|. |
| 155 VisibleSelection Editor::selectionForCommand(Event* event) { | 157 VisibleSelection Editor::selectionForCommand(Event* event) { |
| 156 frame().selection().updateIfNeeded(); | 158 frame().selection().updateIfNeeded(); |
| 157 VisibleSelection selection = frame().selection().selection(); | 159 VisibleSelection selection = frame().selection().selection(); |
| 158 if (!event) | 160 if (!event) |
| 159 return selection; | 161 return selection; |
| 160 // If the target is a text control, and the current selection is outside of | 162 // If the target is a text control, and the current selection is outside of |
| 161 // its shadow tree, then use the saved selection for that text control. | 163 // its shadow tree, then use the saved selection for that text control. |
| 162 HTMLTextFormControlElement* textFormControlOfSelectionStart = | 164 HTMLTextFormControlElement* textFormControlOfSelectionStart = |
| 163 enclosingTextFormControl(selection.start()); | 165 enclosingTextFormControl(selection.start()); |
| 164 HTMLTextFormControlElement* textFromControlOfTarget = | 166 HTMLTextFormControlElement* textFromControlOfTarget = |
| 165 isHTMLTextFormControlElement(*event->target()->toNode()) | 167 isHTMLTextFormControlElement(*event->target()->toNode()) |
| 166 ? toHTMLTextFormControlElement(event->target()->toNode()) | 168 ? toHTMLTextFormControlElement(event->target()->toNode()) |
| 167 : 0; | 169 : 0; |
| 168 if (textFromControlOfTarget && | 170 if (textFromControlOfTarget && |
| 169 (selection.start().isNull() || | 171 (selection.start().isNull() || |
| 170 textFromControlOfTarget != textFormControlOfSelectionStart)) { | 172 textFromControlOfTarget != textFormControlOfSelectionStart)) { |
| 171 if (Range* range = textFromControlOfTarget->selection()) { | 173 if (Range* range = textFromControlOfTarget->selection()) { |
| 172 return createVisibleSelection(EphemeralRange(range), | 174 return createVisibleSelection( |
| 173 TextAffinity::Downstream, | 175 SelectionInDOMTree::Builder() |
| 174 selection.isDirectional()); | 176 .setBaseAndExtent(EphemeralRange(range)) |
| 177 .setIsDirectional(selection.isDirectional()) |
| 178 .build()); |
| 175 } | 179 } |
| 176 } | 180 } |
| 177 return selection; | 181 return selection; |
| 178 } | 182 } |
| 179 | 183 |
| 180 // Function considers Mac editing behavior a fallback when Page or Settings is | 184 // Function considers Mac editing behavior a fallback when Page or Settings is |
| 181 // not available. | 185 // not available. |
| 182 EditingBehavior Editor::behavior() const { | 186 EditingBehavior Editor::behavior() const { |
| 183 if (!frame().settings()) | 187 if (!frame().settings()) |
| 184 return EditingBehavior(EditingMacBehavior); | 188 return EditingBehavior(EditingMacBehavior); |
| (...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1274 isEndOfParagraph(caret) ? caret : nextPositionOf(caret); | 1278 isEndOfParagraph(caret) ? caret : nextPositionOf(caret); |
| 1275 VisiblePosition previous = previousPositionOf(next); | 1279 VisiblePosition previous = previousPositionOf(next); |
| 1276 if (next.deepEquivalent() == previous.deepEquivalent()) | 1280 if (next.deepEquivalent() == previous.deepEquivalent()) |
| 1277 return; | 1281 return; |
| 1278 previous = previousPositionOf(previous); | 1282 previous = previousPositionOf(previous); |
| 1279 if (!inSameParagraph(next, previous)) | 1283 if (!inSameParagraph(next, previous)) |
| 1280 return; | 1284 return; |
| 1281 const EphemeralRange range = makeRange(previous, next); | 1285 const EphemeralRange range = makeRange(previous, next); |
| 1282 if (range.isNull()) | 1286 if (range.isNull()) |
| 1283 return; | 1287 return; |
| 1284 VisibleSelection newSelection = createVisibleSelection(range); | 1288 VisibleSelection newSelection = createVisibleSelection( |
| 1289 SelectionInDOMTree::Builder().setBaseAndExtent(range).build()); |
| 1285 | 1290 |
| 1286 // Transpose the two characters. | 1291 // Transpose the two characters. |
| 1287 String text = plainText(range); | 1292 String text = plainText(range); |
| 1288 if (text.length() != 2) | 1293 if (text.length() != 2) |
| 1289 return; | 1294 return; |
| 1290 String transposed = text.right(1) + text.left(1); | 1295 String transposed = text.right(1) + text.left(1); |
| 1291 | 1296 |
| 1292 // Select the two characters. | 1297 // Select the two characters. |
| 1293 if (newSelection != frame().selection().selection()) | 1298 if (newSelection != frame().selection().selection()) |
| 1294 frame().selection().setSelection(newSelection); | 1299 frame().selection().setSelection(newSelection); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1412 // TODO(yosin) We should make |findRangeOfString()| to return | 1417 // TODO(yosin) We should make |findRangeOfString()| to return |
| 1413 // |EphemeralRange| rather than|Range| object. | 1418 // |EphemeralRange| rather than|Range| object. |
| 1414 Range* resultRange = findRangeOfString( | 1419 Range* resultRange = findRangeOfString( |
| 1415 target, EphemeralRange(selection.start(), selection.end()), | 1420 target, EphemeralRange(selection.start(), selection.end()), |
| 1416 static_cast<FindOptions>(options | FindAPICall)); | 1421 static_cast<FindOptions>(options | FindAPICall)); |
| 1417 | 1422 |
| 1418 if (!resultRange) | 1423 if (!resultRange) |
| 1419 return false; | 1424 return false; |
| 1420 | 1425 |
| 1421 frame().selection().setSelection( | 1426 frame().selection().setSelection( |
| 1422 createVisibleSelection(EphemeralRange(resultRange))); | 1427 SelectionInDOMTree::Builder() |
| 1428 .setBaseAndExtent(EphemeralRange(resultRange)) |
| 1429 .build()); |
| 1423 frame().selection().revealSelection(); | 1430 frame().selection().revealSelection(); |
| 1424 return true; | 1431 return true; |
| 1425 } | 1432 } |
| 1426 | 1433 |
| 1427 Range* Editor::findStringAndScrollToVisible(const String& target, | 1434 Range* Editor::findStringAndScrollToVisible(const String& target, |
| 1428 Range* previousMatch, | 1435 Range* previousMatch, |
| 1429 FindOptions options) { | 1436 FindOptions options) { |
| 1430 Range* nextMatch = findRangeOfString( | 1437 Range* nextMatch = findRangeOfString( |
| 1431 target, EphemeralRangeInFlatTree(previousMatch), options); | 1438 target, EphemeralRangeInFlatTree(previousMatch), options); |
| 1432 if (!nextMatch) | 1439 if (!nextMatch) |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1641 } | 1648 } |
| 1642 | 1649 |
| 1643 DEFINE_TRACE(Editor) { | 1650 DEFINE_TRACE(Editor) { |
| 1644 visitor->trace(m_frame); | 1651 visitor->trace(m_frame); |
| 1645 visitor->trace(m_lastEditCommand); | 1652 visitor->trace(m_lastEditCommand); |
| 1646 visitor->trace(m_undoStack); | 1653 visitor->trace(m_undoStack); |
| 1647 visitor->trace(m_mark); | 1654 visitor->trace(m_mark); |
| 1648 } | 1655 } |
| 1649 | 1656 |
| 1650 } // namespace blink | 1657 } // namespace blink |
| OLD | NEW |