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 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1021 m_shouldStyleWithCSS = false; | 1021 m_shouldStyleWithCSS = false; |
| 1022 m_defaultParagraphSeparator = EditorParagraphSeparatorIsDiv; | 1022 m_defaultParagraphSeparator = EditorParagraphSeparatorIsDiv; |
| 1023 m_lastEditCommand = nullptr; | 1023 m_lastEditCommand = nullptr; |
| 1024 m_undoStack->clear(); | 1024 m_undoStack->clear(); |
| 1025 } | 1025 } |
| 1026 | 1026 |
| 1027 bool Editor::insertText(const String& text, KeyboardEvent* triggeringEvent) { | 1027 bool Editor::insertText(const String& text, KeyboardEvent* triggeringEvent) { |
| 1028 return frame().eventHandler().handleTextInputEvent(text, triggeringEvent); | 1028 return frame().eventHandler().handleTextInputEvent(text, triggeringEvent); |
| 1029 } | 1029 } |
| 1030 | 1030 |
| 1031 bool Editor::insertTextWithoutSendingTextEvent(const String& text, | 1031 bool Editor::insertTextWithoutSendingTextEvent( |
| 1032 bool selectInsertedText, | 1032 const String& text, |
| 1033 TextEvent* triggeringEvent) { | 1033 bool selectInsertedText, |
| 1034 TextEvent* triggeringEvent, | |
| 1035 InputEvent::InputType inputType) { | |
| 1034 if (text.isEmpty()) | 1036 if (text.isEmpty()) |
| 1035 return false; | 1037 return false; |
| 1036 | 1038 |
| 1037 const VisibleSelection& selection = selectionForCommand(triggeringEvent); | 1039 const VisibleSelection& selection = selectionForCommand(triggeringEvent); |
| 1038 if (!selection.isContentEditable()) | 1040 if (!selection.isContentEditable()) |
| 1039 return false; | 1041 return false; |
| 1040 | 1042 |
| 1041 spellChecker().updateMarkersForWordsAffectedByEditing( | 1043 spellChecker().updateMarkersForWordsAffectedByEditing( |
| 1042 isSpaceOrNewline(text[0])); | 1044 isSpaceOrNewline(text[0])); |
| 1043 | 1045 |
| 1044 // Insert the text | 1046 // Insert the text |
| 1045 TypingCommand::insertText( | 1047 TypingCommand::insertText( |
| 1046 *selection.start().document(), text, selection.asSelection(), | 1048 *selection.start().document(), text, selection.asSelection(), |
| 1047 selectInsertedText ? TypingCommand::SelectInsertedText : 0, | 1049 selectInsertedText ? TypingCommand::SelectInsertedText : 0, |
| 1048 triggeringEvent && triggeringEvent->isComposition() | 1050 triggeringEvent && triggeringEvent->isComposition() |
| 1049 ? TypingCommand::TextCompositionConfirm | 1051 ? TypingCommand::TextCompositionConfirm |
| 1050 : TypingCommand::TextCompositionNone); | 1052 : TypingCommand::TextCompositionNone, |
| 1053 false, inputType); | |
| 1051 | 1054 |
| 1052 // Reveal the current selection | 1055 // Reveal the current selection |
| 1053 if (LocalFrame* editedFrame = selection.start().document()->frame()) { | 1056 if (LocalFrame* editedFrame = selection.start().document()->frame()) { |
| 1054 if (Page* page = editedFrame->page()) { | 1057 if (Page* page = editedFrame->page()) { |
| 1055 LocalFrame* focusedOrMainFrame = | 1058 LocalFrame* focusedOrMainFrame = |
| 1056 toLocalFrame(page->focusController().focusedOrMainFrame()); | 1059 toLocalFrame(page->focusController().focusedOrMainFrame()); |
| 1057 focusedOrMainFrame->selection().revealSelection( | 1060 focusedOrMainFrame->selection().revealSelection( |
| 1058 ScrollAlignment::alignCenterIfNeeded); | 1061 ScrollAlignment::alignCenterIfNeeded); |
| 1059 } | 1062 } |
| 1060 } | 1063 } |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1398 String text = plainText(range); | 1401 String text = plainText(range); |
| 1399 if (text.length() != 2) | 1402 if (text.length() != 2) |
| 1400 return; | 1403 return; |
| 1401 String transposed = text.right(1) + text.left(1); | 1404 String transposed = text.right(1) + text.left(1); |
| 1402 | 1405 |
| 1403 // Select the two characters. | 1406 // Select the two characters. |
| 1404 if (createVisibleSelection(newSelection) != | 1407 if (createVisibleSelection(newSelection) != |
| 1405 frame().selection().computeVisibleSelectionInDOMTreeDeprecated()) | 1408 frame().selection().computeVisibleSelectionInDOMTreeDeprecated()) |
| 1406 frame().selection().setSelection(newSelection); | 1409 frame().selection().setSelection(newSelection); |
| 1407 | 1410 |
| 1411 if (dispatchBeforeInputInsertText( | |
| 1412 eventTargetNodeForDocument(frame().document()), transposed, | |
| 1413 InputEvent::InputType::InsertTranspose) != | |
| 1414 DispatchEventResult::NotCanceled) | |
| 1415 return; | |
| 1416 | |
| 1417 // 'beforeinput' event handler may destroy document. | |
| 1418 if (m_frame->document()->frame() != m_frame) | |
| 1419 return; | |
| 1420 | |
| 1421 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | |
|
yosin_UTC9
2017/03/09 03:49:11
nit: s/xiaochengh/editing-dev/
chongz
2017/03/09 21:31:36
Done.
| |
| 1422 // needs to be audited. see http://crbug.com/590369 for more details. | |
| 1423 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); | |
| 1424 | |
| 1408 // Insert the transposed characters. | 1425 // Insert the transposed characters. |
| 1409 // TODO(chongz): Once we add |InsertTranspose| in |InputEvent::InputType|, we | |
| 1410 // should use it instead of |InsertFromPaste|. | |
| 1411 replaceSelectionWithText(transposed, false, false, | 1426 replaceSelectionWithText(transposed, false, false, |
| 1412 InputEvent::InputType::InsertFromPaste); | 1427 InputEvent::InputType::InsertTranspose); |
| 1413 } | 1428 } |
| 1414 | 1429 |
| 1415 void Editor::addToKillRing(const EphemeralRange& range) { | 1430 void Editor::addToKillRing(const EphemeralRange& range) { |
| 1416 if (m_shouldStartNewKillRingSequence) | 1431 if (m_shouldStartNewKillRingSequence) |
| 1417 killRing().startNewSequence(); | 1432 killRing().startNewSequence(); |
| 1418 | 1433 |
| 1419 DCHECK(!frame().document()->needsLayoutTreeUpdate()); | 1434 DCHECK(!frame().document()->needsLayoutTreeUpdate()); |
| 1420 String text = plainText(range); | 1435 String text = plainText(range); |
| 1421 killRing().append(text); | 1436 killRing().append(text); |
| 1422 m_shouldStartNewKillRingSequence = false; | 1437 m_shouldStartNewKillRingSequence = false; |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1776 | 1791 |
| 1777 DEFINE_TRACE(Editor) { | 1792 DEFINE_TRACE(Editor) { |
| 1778 visitor->trace(m_frame); | 1793 visitor->trace(m_frame); |
| 1779 visitor->trace(m_lastEditCommand); | 1794 visitor->trace(m_lastEditCommand); |
| 1780 visitor->trace(m_undoStack); | 1795 visitor->trace(m_undoStack); |
| 1781 visitor->trace(m_mark); | 1796 visitor->trace(m_mark); |
| 1782 visitor->trace(m_typingStyle); | 1797 visitor->trace(m_typingStyle); |
| 1783 } | 1798 } |
| 1784 | 1799 |
| 1785 } // namespace blink | 1800 } // namespace blink |
| OLD | NEW |