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 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::P
reventNesting | ReplaceSelectionCommand::SanitizeFragment; | 503 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::P
reventNesting | ReplaceSelectionCommand::SanitizeFragment; |
504 if (selectReplacement) | 504 if (selectReplacement) |
505 options |= ReplaceSelectionCommand::SelectReplacement; | 505 options |= ReplaceSelectionCommand::SelectReplacement; |
506 if (smartReplace) | 506 if (smartReplace) |
507 options |= ReplaceSelectionCommand::SmartReplace; | 507 options |= ReplaceSelectionCommand::SmartReplace; |
508 if (matchStyle) | 508 if (matchStyle) |
509 options |= ReplaceSelectionCommand::MatchStyle; | 509 options |= ReplaceSelectionCommand::MatchStyle; |
510 ASSERT(frame().document()); | 510 ASSERT(frame().document()); |
511 ReplaceSelectionCommand::create(*frame().document(), fragment, options, Edit
ActionPaste)->apply(); | 511 ReplaceSelectionCommand::create(*frame().document(), fragment, options, Edit
ActionPaste)->apply(); |
512 revealSelectionAfterEditingOperation(); | 512 revealSelectionAfterEditingOperation(); |
513 | |
514 if (frame().selection().isInPasswordField() || !spellChecker().isContinuousS
pellCheckingEnabled()) | |
515 return; | |
516 ASSERT(lastEditCommand()->isReplaceSelectionCommand()); | |
517 const EphemeralRange& insertedRange = toReplaceSelectionCommand(lastEditComm
and())->insertedRange(); | |
518 if (insertedRange.isNull()) | |
519 return; | |
520 spellChecker().chunkAndMarkAllMisspellingsAndBadGrammar(frame().selection().
rootEditableElement(), insertedRange); | |
521 } | 513 } |
522 | 514 |
523 void Editor::replaceSelectionWithText(const String& text, bool selectReplacement
, bool smartReplace) | 515 void Editor::replaceSelectionWithText(const String& text, bool selectReplacement
, bool smartReplace) |
524 { | 516 { |
525 replaceSelectionWithFragment(createFragmentFromText(selectedRange(), text),
selectReplacement, smartReplace, true); | 517 replaceSelectionWithFragment(createFragmentFromText(selectedRange(), text),
selectReplacement, smartReplace, true); |
526 } | 518 } |
527 | 519 |
528 // TODO(xiaochengh): Merge it with |replaceSelectionWithFragment()|. | 520 // TODO(xiaochengh): Merge it with |replaceSelectionWithFragment()|. |
529 void Editor::replaceSelectionAfterDragging(PassRefPtrWillBeRawPtr<DocumentFragme
nt> fragment, bool smartReplace, bool plainText) | 521 void Editor::replaceSelectionAfterDragging(PassRefPtrWillBeRawPtr<DocumentFragme
nt> fragment, bool smartReplace, bool plainText) |
530 { | 522 { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 } | 656 } |
665 | 657 |
666 static void dispatchEditableContentChangedEvents(PassRefPtrWillBeRawPtr<Element>
startRoot, PassRefPtrWillBeRawPtr<Element> endRoot) | 658 static void dispatchEditableContentChangedEvents(PassRefPtrWillBeRawPtr<Element>
startRoot, PassRefPtrWillBeRawPtr<Element> endRoot) |
667 { | 659 { |
668 if (startRoot) | 660 if (startRoot) |
669 startRoot->dispatchEvent(Event::create(EventTypeNames::webkitEditableCon
tentChanged)); | 661 startRoot->dispatchEvent(Event::create(EventTypeNames::webkitEditableCon
tentChanged)); |
670 if (endRoot && endRoot != startRoot) | 662 if (endRoot && endRoot != startRoot) |
671 endRoot->dispatchEvent(Event::create(EventTypeNames::webkitEditableConte
ntChanged)); | 663 endRoot->dispatchEvent(Event::create(EventTypeNames::webkitEditableConte
ntChanged)); |
672 } | 664 } |
673 | 665 |
| 666 void Editor::requestSpellcheckingAfterApplyingCommand(CompositeEditCommand* cmd) |
| 667 { |
| 668 // Note: Request spell checking for and only for |ReplaceSelectionCommand|s |
| 669 // created in |Editor::replaceSelectionWithFragment()|. |
| 670 // TODO(xiaochengh): May also need to do this after dragging crbug.com/29804
6. |
| 671 if (cmd->editingAction() != EditActionPaste) |
| 672 return; |
| 673 if (frame().selection().isInPasswordField() || !spellChecker().isContinuousS
pellCheckingEnabled()) |
| 674 return; |
| 675 ASSERT(cmd->isReplaceSelectionCommand()); |
| 676 const EphemeralRange& insertedRange = toReplaceSelectionCommand(cmd)->insert
edRange(); |
| 677 if (insertedRange.isNull()) |
| 678 return; |
| 679 spellChecker().chunkAndMarkAllMisspellingsAndBadGrammar(cmd->endingSelection
().rootEditableElement(), insertedRange); |
| 680 } |
| 681 |
674 void Editor::appliedEditing(PassRefPtrWillBeRawPtr<CompositeEditCommand> cmd) | 682 void Editor::appliedEditing(PassRefPtrWillBeRawPtr<CompositeEditCommand> cmd) |
675 { | 683 { |
676 EventQueueScope scope; | 684 EventQueueScope scope; |
677 frame().document()->updateLayout(); | 685 frame().document()->updateLayout(); |
678 | 686 |
| 687 // Request spell checking after pasting before any further DOM change. |
| 688 requestSpellcheckingAfterApplyingCommand(cmd.get()); |
| 689 |
679 EditCommandComposition* composition = cmd->composition(); | 690 EditCommandComposition* composition = cmd->composition(); |
680 ASSERT(composition); | 691 ASSERT(composition); |
681 dispatchEditableContentChangedEvents(composition->startingRootEditableElemen
t(), composition->endingRootEditableElement()); | 692 dispatchEditableContentChangedEvents(composition->startingRootEditableElemen
t(), composition->endingRootEditableElement()); |
682 VisibleSelection newSelection(cmd->endingSelection()); | 693 VisibleSelection newSelection(cmd->endingSelection()); |
683 | 694 |
684 // Don't clear the typing style with this selection change. We do those thin
gs elsewhere if necessary. | 695 // Don't clear the typing style with this selection change. We do those thin
gs elsewhere if necessary. |
685 changeSelectionAfterCommand(newSelection, 0); | 696 changeSelectionAfterCommand(newSelection, 0); |
686 | 697 |
687 if (!cmd->preservesTypingStyle()) | 698 if (!cmd->preservesTypingStyle()) |
688 frame().selection().clearTypingStyle(); | 699 frame().selection().clearTypingStyle(); |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1322 } | 1333 } |
1323 | 1334 |
1324 DEFINE_TRACE(Editor) | 1335 DEFINE_TRACE(Editor) |
1325 { | 1336 { |
1326 visitor->trace(m_frame); | 1337 visitor->trace(m_frame); |
1327 visitor->trace(m_lastEditCommand); | 1338 visitor->trace(m_lastEditCommand); |
1328 visitor->trace(m_mark); | 1339 visitor->trace(m_mark); |
1329 } | 1340 } |
1330 | 1341 |
1331 } // namespace blink | 1342 } // namespace blink |
OLD | NEW |