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 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::P
reventNesting | ReplaceSelectionCommand::SanitizeFragment; | 502 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::P
reventNesting | ReplaceSelectionCommand::SanitizeFragment; |
503 if (selectReplacement) | 503 if (selectReplacement) |
504 options |= ReplaceSelectionCommand::SelectReplacement; | 504 options |= ReplaceSelectionCommand::SelectReplacement; |
505 if (smartReplace) | 505 if (smartReplace) |
506 options |= ReplaceSelectionCommand::SmartReplace; | 506 options |= ReplaceSelectionCommand::SmartReplace; |
507 if (matchStyle) | 507 if (matchStyle) |
508 options |= ReplaceSelectionCommand::MatchStyle; | 508 options |= ReplaceSelectionCommand::MatchStyle; |
509 ASSERT(frame().document()); | 509 ASSERT(frame().document()); |
510 ReplaceSelectionCommand::create(*frame().document(), fragment, options, Edit
ActionPaste)->apply(); | 510 ReplaceSelectionCommand::create(*frame().document(), fragment, options, Edit
ActionPaste)->apply(); |
511 revealSelectionAfterEditingOperation(); | 511 revealSelectionAfterEditingOperation(); |
512 | |
513 if (frame().selection().isInPasswordField() || !spellChecker().isContinuousS
pellCheckingEnabled()) | |
514 return; | |
515 ASSERT(lastEditCommand()->isReplaceSelectionCommand()); | |
516 const EphemeralRange& insertedRange = toReplaceSelectionCommand(lastEditComm
and())->insertedRange(); | |
517 if (insertedRange.isNull()) | |
518 return; | |
519 spellChecker().chunkAndMarkAllMisspellingsAndBadGrammar(frame().selection().
rootEditableElement(), insertedRange); | |
520 } | 512 } |
521 | 513 |
522 void Editor::replaceSelectionWithText(const String& text, bool selectReplacement
, bool smartReplace) | 514 void Editor::replaceSelectionWithText(const String& text, bool selectReplacement
, bool smartReplace) |
523 { | 515 { |
524 replaceSelectionWithFragment(createFragmentFromText(selectedRange(), text),
selectReplacement, smartReplace, true); | 516 replaceSelectionWithFragment(createFragmentFromText(selectedRange(), text),
selectReplacement, smartReplace, true); |
525 } | 517 } |
526 | 518 |
527 EphemeralRange Editor::selectedRange() | 519 EphemeralRange Editor::selectedRange() |
528 { | 520 { |
529 return frame().selection().selection().toNormalizedEphemeralRange(); | 521 return frame().selection().selection().toNormalizedEphemeralRange(); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 } | 638 } |
647 | 639 |
648 static void dispatchEditableContentChangedEvents(PassRefPtrWillBeRawPtr<Element>
startRoot, PassRefPtrWillBeRawPtr<Element> endRoot) | 640 static void dispatchEditableContentChangedEvents(PassRefPtrWillBeRawPtr<Element>
startRoot, PassRefPtrWillBeRawPtr<Element> endRoot) |
649 { | 641 { |
650 if (startRoot) | 642 if (startRoot) |
651 startRoot->dispatchEvent(Event::create(EventTypeNames::webkitEditableCon
tentChanged)); | 643 startRoot->dispatchEvent(Event::create(EventTypeNames::webkitEditableCon
tentChanged)); |
652 if (endRoot && endRoot != startRoot) | 644 if (endRoot && endRoot != startRoot) |
653 endRoot->dispatchEvent(Event::create(EventTypeNames::webkitEditableConte
ntChanged)); | 645 endRoot->dispatchEvent(Event::create(EventTypeNames::webkitEditableConte
ntChanged)); |
654 } | 646 } |
655 | 647 |
| 648 void Editor::requestSpellcheckingAfterApplyingCommand(CompositeEditCommand* cmd) |
| 649 { |
| 650 // Note: Request spell checking for and only for |ReplaceSelectionCommand|s |
| 651 // created in |Editor::replaceSelectionWithFragment()|. |
| 652 // TODO(xiaochengh): May also need to do this after dragging crbug.com/29804
6. |
| 653 if (cmd->editingAction() != EditActionPaste) |
| 654 return; |
| 655 if (!frame().selection().isInPasswordField() && spellChecker().isContinuousS
pellCheckingEnabled()) |
| 656 return; |
| 657 ASSERT(cmd->isReplaceSelectionCommand()); |
| 658 const EphemeralRange& insertedRange = toReplaceSelectionCommand(cmd)->insert
edRange(); |
| 659 if (insertedRange.isNotNull()) |
| 660 spellChecker().chunkAndMarkAllMisspellingsAndBadGrammar(cmd->endingSelec
tion().rootEditableElement(), insertedRange); |
| 661 } |
| 662 |
656 void Editor::appliedEditing(PassRefPtrWillBeRawPtr<CompositeEditCommand> cmd) | 663 void Editor::appliedEditing(PassRefPtrWillBeRawPtr<CompositeEditCommand> cmd) |
657 { | 664 { |
658 EventQueueScope scope; | 665 EventQueueScope scope; |
659 frame().document()->updateLayout(); | 666 frame().document()->updateLayout(); |
660 | 667 |
| 668 // Request spell checking after pasting before any further DOM change. |
| 669 requestSpellcheckingAfterApplyingCommand(cmd.get()); |
| 670 |
661 EditCommandComposition* composition = cmd->composition(); | 671 EditCommandComposition* composition = cmd->composition(); |
662 ASSERT(composition); | 672 ASSERT(composition); |
663 dispatchEditableContentChangedEvents(composition->startingRootEditableElemen
t(), composition->endingRootEditableElement()); | 673 dispatchEditableContentChangedEvents(composition->startingRootEditableElemen
t(), composition->endingRootEditableElement()); |
664 VisibleSelection newSelection(cmd->endingSelection()); | 674 VisibleSelection newSelection(cmd->endingSelection()); |
665 | 675 |
666 // Don't clear the typing style with this selection change. We do those thin
gs elsewhere if necessary. | 676 // Don't clear the typing style with this selection change. We do those thin
gs elsewhere if necessary. |
667 changeSelectionAfterCommand(newSelection, 0); | 677 changeSelectionAfterCommand(newSelection, 0); |
668 | 678 |
669 if (!cmd->preservesTypingStyle()) | 679 if (!cmd->preservesTypingStyle()) |
670 frame().selection().clearTypingStyle(); | 680 frame().selection().clearTypingStyle(); |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1304 } | 1314 } |
1305 | 1315 |
1306 DEFINE_TRACE(Editor) | 1316 DEFINE_TRACE(Editor) |
1307 { | 1317 { |
1308 visitor->trace(m_frame); | 1318 visitor->trace(m_frame); |
1309 visitor->trace(m_lastEditCommand); | 1319 visitor->trace(m_lastEditCommand); |
1310 visitor->trace(m_mark); | 1320 visitor->trace(m_mark); |
1311 } | 1321 } |
1312 | 1322 |
1313 } // namespace blink | 1323 } // namespace blink |
OLD | NEW |