Chromium Code Reviews| 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 // Default event handling for Drag and Drop will be handled by DragController | 205 // Default event handling for Drag and Drop will be handled by DragController |
| 206 // so we leave the event for it. | 206 // so we leave the event for it. |
| 207 if (event->isDrop()) | 207 if (event->isDrop()) |
| 208 return false; | 208 return false; |
| 209 | 209 |
| 210 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 210 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 211 // needs to be audited. See http://crbug.com/590369 for more details. | 211 // needs to be audited. See http://crbug.com/590369 for more details. |
| 212 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 212 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 213 | 213 |
| 214 if (event->isPaste()) { | 214 if (event->isPaste()) { |
| 215 if (event->pastingFragment()) | 215 if (event->pastingFragment()) { |
| 216 replaceSelectionWithFragment(event->pastingFragment(), false, | 216 replaceSelectionWithFragment( |
| 217 event->shouldSmartReplace(), | 217 event->pastingFragment(), false, event->shouldSmartReplace(), |
| 218 event->shouldMatchStyle()); | 218 event->shouldMatchStyle(), InputEvent::InputType::InsertFromPaste); |
| 219 else | 219 } else { |
| 220 replaceSelectionWithText(event->data(), false, | 220 replaceSelectionWithText(event->data(), false, |
| 221 event->shouldSmartReplace()); | 221 event->shouldSmartReplace(), |
| 222 InputEvent::InputType::InsertFromPaste); | |
| 223 } | |
| 222 return true; | 224 return true; |
| 223 } | 225 } |
| 224 | 226 |
| 225 String data = event->data(); | 227 String data = event->data(); |
| 226 if (data == "\n") { | 228 if (data == "\n") { |
| 227 if (event->isLineBreak()) | 229 if (event->isLineBreak()) |
| 228 return insertLineBreak(); | 230 return insertLineBreak(); |
| 229 return insertParagraphSeparator(); | 231 return insertParagraphSeparator(); |
| 230 } | 232 } |
| 231 | 233 |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 return !noDefaultProcessing; | 554 return !noDefaultProcessing; |
| 553 } | 555 } |
| 554 | 556 |
| 555 bool Editor::canSmartReplaceWithPasteboard(Pasteboard* pasteboard) { | 557 bool Editor::canSmartReplaceWithPasteboard(Pasteboard* pasteboard) { |
| 556 return smartInsertDeleteEnabled() && pasteboard->canSmartReplace(); | 558 return smartInsertDeleteEnabled() && pasteboard->canSmartReplace(); |
| 557 } | 559 } |
| 558 | 560 |
| 559 void Editor::replaceSelectionWithFragment(DocumentFragment* fragment, | 561 void Editor::replaceSelectionWithFragment(DocumentFragment* fragment, |
| 560 bool selectReplacement, | 562 bool selectReplacement, |
| 561 bool smartReplace, | 563 bool smartReplace, |
| 562 bool matchStyle) { | 564 bool matchStyle, |
| 565 InputEvent::InputType inputType) { | |
| 563 DCHECK(!frame().document()->needsLayoutTreeUpdate()); | 566 DCHECK(!frame().document()->needsLayoutTreeUpdate()); |
| 564 if (frame().selection().isNone() || | 567 if (frame().selection().isNone() || |
| 565 !frame().selection().isContentEditable() || !fragment) | 568 !frame().selection().isContentEditable() || !fragment) |
| 566 return; | 569 return; |
| 567 | 570 |
| 568 ReplaceSelectionCommand::CommandOptions options = | 571 ReplaceSelectionCommand::CommandOptions options = |
| 569 ReplaceSelectionCommand::PreventNesting | | 572 ReplaceSelectionCommand::PreventNesting | |
| 570 ReplaceSelectionCommand::SanitizeFragment; | 573 ReplaceSelectionCommand::SanitizeFragment; |
| 571 if (selectReplacement) | 574 if (selectReplacement) |
| 572 options |= ReplaceSelectionCommand::SelectReplacement; | 575 options |= ReplaceSelectionCommand::SelectReplacement; |
| 573 if (smartReplace) | 576 if (smartReplace) |
| 574 options |= ReplaceSelectionCommand::SmartReplace; | 577 options |= ReplaceSelectionCommand::SmartReplace; |
| 575 if (matchStyle) | 578 if (matchStyle) |
| 576 options |= ReplaceSelectionCommand::MatchStyle; | 579 options |= ReplaceSelectionCommand::MatchStyle; |
| 577 DCHECK(frame().document()); | 580 DCHECK(frame().document()); |
| 578 ReplaceSelectionCommand::create(*frame().document(), fragment, options, | 581 ReplaceSelectionCommand::create(*frame().document(), fragment, options, |
| 579 InputEvent::InputType::InsertFromPaste) | 582 inputType) |
| 580 ->apply(); | 583 ->apply(); |
| 581 revealSelectionAfterEditingOperation(); | 584 revealSelectionAfterEditingOperation(); |
| 582 } | 585 } |
| 583 | 586 |
| 584 void Editor::replaceSelectionWithText(const String& text, | 587 void Editor::replaceSelectionWithText(const String& text, |
| 585 bool selectReplacement, | 588 bool selectReplacement, |
| 586 bool smartReplace) { | 589 bool smartReplace, |
| 590 InputEvent::InputType inputType) { | |
| 587 replaceSelectionWithFragment(createFragmentFromText(selectedRange(), text), | 591 replaceSelectionWithFragment(createFragmentFromText(selectedRange(), text), |
| 588 selectReplacement, smartReplace, true); | 592 selectReplacement, smartReplace, true, |
| 593 inputType); | |
| 589 } | 594 } |
| 590 | 595 |
| 591 // TODO(xiaochengh): Merge it with |replaceSelectionWithFragment()|. | 596 // TODO(xiaochengh): Merge it with |replaceSelectionWithFragment()|. |
| 592 void Editor::replaceSelectionAfterDragging(DocumentFragment* fragment, | 597 void Editor::replaceSelectionAfterDragging(DocumentFragment* fragment, |
| 593 InsertMode insertMode, | 598 InsertMode insertMode, |
| 594 DragSourceType dragSourceType) { | 599 DragSourceType dragSourceType) { |
| 595 ReplaceSelectionCommand::CommandOptions options = | 600 ReplaceSelectionCommand::CommandOptions options = |
| 596 ReplaceSelectionCommand::SelectReplacement | | 601 ReplaceSelectionCommand::SelectReplacement | |
| 597 ReplaceSelectionCommand::PreventNesting; | 602 ReplaceSelectionCommand::PreventNesting; |
| 598 if (insertMode == InsertMode::Smart) | 603 if (insertMode == InsertMode::Smart) |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1292 String text = plainText(range); | 1297 String text = plainText(range); |
| 1293 if (text.length() != 2) | 1298 if (text.length() != 2) |
| 1294 return; | 1299 return; |
| 1295 String transposed = text.right(1) + text.left(1); | 1300 String transposed = text.right(1) + text.left(1); |
| 1296 | 1301 |
| 1297 // Select the two characters. | 1302 // Select the two characters. |
| 1298 if (newSelection != frame().selection().selection()) | 1303 if (newSelection != frame().selection().selection()) |
| 1299 frame().selection().setSelection(newSelection); | 1304 frame().selection().setSelection(newSelection); |
| 1300 | 1305 |
| 1301 // Insert the transposed characters. | 1306 // Insert the transposed characters. |
| 1302 replaceSelectionWithText(transposed, false, false); | 1307 // TODO(chongz) Support |InsertTranspose| |
|
yosin_UTC9
2016/11/17 04:06:48
nit: Please write TODO comment more descriptive wi
| |
| 1308 replaceSelectionWithText(transposed, false, false, | |
| 1309 InputEvent::InputType::InsertFromPaste); | |
| 1303 } | 1310 } |
| 1304 | 1311 |
| 1305 void Editor::addToKillRing(const EphemeralRange& range) { | 1312 void Editor::addToKillRing(const EphemeralRange& range) { |
| 1306 if (m_shouldStartNewKillRingSequence) | 1313 if (m_shouldStartNewKillRingSequence) |
| 1307 killRing().startNewSequence(); | 1314 killRing().startNewSequence(); |
| 1308 | 1315 |
| 1309 DCHECK(!frame().document()->needsLayoutTreeUpdate()); | 1316 DCHECK(!frame().document()->needsLayoutTreeUpdate()); |
| 1310 String text = plainText(range); | 1317 String text = plainText(range); |
| 1311 killRing().append(text); | 1318 killRing().append(text); |
| 1312 m_shouldStartNewKillRingSequence = false; | 1319 m_shouldStartNewKillRingSequence = false; |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1648 } | 1655 } |
| 1649 | 1656 |
| 1650 DEFINE_TRACE(Editor) { | 1657 DEFINE_TRACE(Editor) { |
| 1651 visitor->trace(m_frame); | 1658 visitor->trace(m_frame); |
| 1652 visitor->trace(m_lastEditCommand); | 1659 visitor->trace(m_lastEditCommand); |
| 1653 visitor->trace(m_undoStack); | 1660 visitor->trace(m_undoStack); |
| 1654 visitor->trace(m_mark); | 1661 visitor->trace(m_mark); |
| 1655 } | 1662 } |
| 1656 | 1663 |
| 1657 } // namespace blink | 1664 } // namespace blink |
| OLD | NEW |