Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: Source/core/editing/Editor.cpp

Issue 21030005: Editor: Deffer event dispatch after selection change. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Added event order test Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 23 matching lines...) Expand all
34 #include "core/css/CSSComputedStyleDeclaration.h" 34 #include "core/css/CSSComputedStyleDeclaration.h"
35 #include "core/css/StylePropertySet.h" 35 #include "core/css/StylePropertySet.h"
36 #include "core/dom/Clipboard.h" 36 #include "core/dom/Clipboard.h"
37 #include "core/dom/ClipboardEvent.h" 37 #include "core/dom/ClipboardEvent.h"
38 #include "core/dom/DocumentFragment.h" 38 #include "core/dom/DocumentFragment.h"
39 #include "core/dom/DocumentMarkerController.h" 39 #include "core/dom/DocumentMarkerController.h"
40 #include "core/dom/EventNames.h" 40 #include "core/dom/EventNames.h"
41 #include "core/dom/KeyboardEvent.h" 41 #include "core/dom/KeyboardEvent.h"
42 #include "core/dom/NodeList.h" 42 #include "core/dom/NodeList.h"
43 #include "core/dom/NodeTraversal.h" 43 #include "core/dom/NodeTraversal.h"
44 #include "core/dom/ScopedEventQueue.h"
44 #include "core/dom/Text.h" 45 #include "core/dom/Text.h"
45 #include "core/dom/TextEvent.h" 46 #include "core/dom/TextEvent.h"
46 #include "core/editing/ApplyStyleCommand.h" 47 #include "core/editing/ApplyStyleCommand.h"
47 #include "core/editing/DeleteSelectionCommand.h" 48 #include "core/editing/DeleteSelectionCommand.h"
48 #include "core/editing/IndentOutdentCommand.h" 49 #include "core/editing/IndentOutdentCommand.h"
49 #include "core/editing/InputMethodController.h" 50 #include "core/editing/InputMethodController.h"
50 #include "core/editing/InsertListCommand.h" 51 #include "core/editing/InsertListCommand.h"
51 #include "core/editing/ModifySelectionListLevel.h" 52 #include "core/editing/ModifySelectionListLevel.h"
52 #include "core/editing/RemoveFormatCommand.h" 53 #include "core/editing/RemoveFormatCommand.h"
53 #include "core/editing/RenderedPosition.h" 54 #include "core/editing/RenderedPosition.h"
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 static void dispatchEditableContentChangedEvents(PassRefPtr<Element> startRoot, PassRefPtr<Element> endRoot) 753 static void dispatchEditableContentChangedEvents(PassRefPtr<Element> startRoot, PassRefPtr<Element> endRoot)
753 { 754 {
754 if (startRoot) 755 if (startRoot)
755 startRoot->dispatchEvent(Event::create(eventNames().webkitEditableConten tChangedEvent), IGNORE_EXCEPTION); 756 startRoot->dispatchEvent(Event::create(eventNames().webkitEditableConten tChangedEvent), IGNORE_EXCEPTION);
756 if (endRoot && endRoot != startRoot) 757 if (endRoot && endRoot != startRoot)
757 endRoot->dispatchEvent(Event::create(eventNames().webkitEditableContentC hangedEvent), IGNORE_EXCEPTION); 758 endRoot->dispatchEvent(Event::create(eventNames().webkitEditableContentC hangedEvent), IGNORE_EXCEPTION);
758 } 759 }
759 760
760 void Editor::appliedEditing(PassRefPtr<CompositeEditCommand> cmd) 761 void Editor::appliedEditing(PassRefPtr<CompositeEditCommand> cmd)
761 { 762 {
763 EventQueueScope scope;
762 m_frame->document()->updateLayout(); 764 m_frame->document()->updateLayout();
763 765
764 EditCommandComposition* composition = cmd->composition(); 766 EditCommandComposition* composition = cmd->composition();
765 ASSERT(composition); 767 ASSERT(composition);
768 dispatchEditableContentChangedEvents(composition->startingRootEditableElemen t(), composition->endingRootEditableElement());
766 VisibleSelection newSelection(cmd->endingSelection()); 769 VisibleSelection newSelection(cmd->endingSelection());
767 770
768 // Don't clear the typing style with this selection change. We do those thi ngs elsewhere if necessary. 771 // Don't clear the typing style with this selection change. We do those thi ngs elsewhere if necessary.
769 changeSelectionAfterCommand(newSelection, 0); 772 changeSelectionAfterCommand(newSelection, 0);
770 dispatchEditableContentChangedEvents(composition->startingRootEditableElemen t(), composition->endingRootEditableElement());
771 773
772 if (!cmd->preservesTypingStyle()) 774 if (!cmd->preservesTypingStyle())
773 m_frame->selection().clearTypingStyle(); 775 m_frame->selection().clearTypingStyle();
774 776
775 // Command will be equal to last edit command only in the case of typing 777 // Command will be equal to last edit command only in the case of typing
776 if (m_lastEditCommand.get() == cmd) 778 if (m_lastEditCommand.get() == cmd)
777 ASSERT(cmd->isTypingCommand()); 779 ASSERT(cmd->isTypingCommand());
778 else { 780 else {
779 // Only register a new undo command if the command passed in is 781 // Only register a new undo command if the command passed in is
780 // different from the last command 782 // different from the last command
781 m_lastEditCommand = cmd; 783 m_lastEditCommand = cmd;
782 client().registerUndoStep(m_lastEditCommand->ensureComposition()); 784 client().registerUndoStep(m_lastEditCommand->ensureComposition());
783 } 785 }
784 786
785 respondToChangedContents(newSelection); 787 respondToChangedContents(newSelection);
786 } 788 }
787 789
788 void Editor::unappliedEditing(PassRefPtr<EditCommandComposition> cmd) 790 void Editor::unappliedEditing(PassRefPtr<EditCommandComposition> cmd)
789 { 791 {
792 EventQueueScope scope;
790 m_frame->document()->updateLayout(); 793 m_frame->document()->updateLayout();
791 794
795 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd ->endingRootEditableElement());
796
792 VisibleSelection newSelection(cmd->startingSelection()); 797 VisibleSelection newSelection(cmd->startingSelection());
793 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | Fram eSelection::ClearTypingStyle); 798 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | Fram eSelection::ClearTypingStyle);
794 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd ->endingRootEditableElement());
795 799
796 m_lastEditCommand = 0; 800 m_lastEditCommand = 0;
797 client().registerRedoStep(cmd); 801 client().registerRedoStep(cmd);
798 respondToChangedContents(newSelection); 802 respondToChangedContents(newSelection);
799 } 803 }
800 804
801 void Editor::reappliedEditing(PassRefPtr<EditCommandComposition> cmd) 805 void Editor::reappliedEditing(PassRefPtr<EditCommandComposition> cmd)
802 { 806 {
807 EventQueueScope scope;
803 m_frame->document()->updateLayout(); 808 m_frame->document()->updateLayout();
804 809
810 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd ->endingRootEditableElement());
811
805 VisibleSelection newSelection(cmd->endingSelection()); 812 VisibleSelection newSelection(cmd->endingSelection());
806 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | Fram eSelection::ClearTypingStyle); 813 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | Fram eSelection::ClearTypingStyle);
807 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd ->endingRootEditableElement());
808 814
809 m_lastEditCommand = 0; 815 m_lastEditCommand = 0;
810 client().registerUndoStep(cmd); 816 client().registerUndoStep(cmd);
811 respondToChangedContents(newSelection); 817 respondToChangedContents(newSelection);
812 } 818 }
813 819
814 Editor::Editor(Frame& frame) 820 Editor::Editor(Frame& frame)
815 : FrameDestructionObserver(&frame) 821 : FrameDestructionObserver(&frame)
816 , m_preventRevealSelection(0) 822 , m_preventRevealSelection(0)
817 , m_shouldStartNewKillRingSequence(false) 823 , m_shouldStartNewKillRingSequence(false)
(...skipping 1395 matching lines...) Expand 10 before | Expand all | Expand 10 after
2213 return WebCore::unifiedTextCheckerEnabled(m_frame); 2219 return WebCore::unifiedTextCheckerEnabled(m_frame);
2214 } 2220 }
2215 2221
2216 void Editor::toggleOverwriteModeEnabled() 2222 void Editor::toggleOverwriteModeEnabled()
2217 { 2223 {
2218 m_overwriteModeEnabled = !m_overwriteModeEnabled; 2224 m_overwriteModeEnabled = !m_overwriteModeEnabled;
2219 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled); 2225 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled);
2220 }; 2226 };
2221 2227
2222 } // namespace WebCore 2228 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698