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

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

Issue 2110543008: Move UndoStack from Page to Editor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments and rewrite test Created 4 years, 5 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
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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 return client; 199 return client;
200 } 200 }
201 201
202 EditorClient& Editor::client() const 202 EditorClient& Editor::client() const
203 { 203 {
204 if (Page* page = frame().page()) 204 if (Page* page = frame().page())
205 return page->editorClient(); 205 return page->editorClient();
206 return emptyEditorClient(); 206 return emptyEditorClient();
207 } 207 }
208 208
209 UndoStack* Editor::undoStack() const
210 {
211 if (Page* page = frame().page())
212 return &page->undoStack();
213 return 0;
214 }
215
216 bool Editor::handleTextEvent(TextEvent* event) 209 bool Editor::handleTextEvent(TextEvent* event)
217 { 210 {
218 // Default event handling for Drag and Drop will be handled by DragControlle r 211 // Default event handling for Drag and Drop will be handled by DragControlle r
219 // so we leave the event for it. 212 // so we leave the event for it.
220 if (event->isDrop()) 213 if (event->isDrop())
221 return false; 214 return false;
222 215
223 if (event->isPaste()) { 216 if (event->isPaste()) {
224 if (event->pastingFragment()) 217 if (event->pastingFragment())
225 replaceSelectionWithFragment(event->pastingFragment(), false, event- >shouldSmartReplace(), event->shouldMatchStyle()); 218 replaceSelectionWithFragment(event->pastingFragment(), false, event- >shouldSmartReplace(), event->shouldMatchStyle());
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 if (!cmd->preservesTypingStyle()) 762 if (!cmd->preservesTypingStyle())
770 frame().selection().clearTypingStyle(); 763 frame().selection().clearTypingStyle();
771 764
772 // Command will be equal to last edit command only in the case of typing 765 // Command will be equal to last edit command only in the case of typing
773 if (m_lastEditCommand.get() == cmd) { 766 if (m_lastEditCommand.get() == cmd) {
774 DCHECK(cmd->isTypingCommand()); 767 DCHECK(cmd->isTypingCommand());
775 } else { 768 } else {
776 // Only register a new undo command if the command passed in is 769 // Only register a new undo command if the command passed in is
777 // different from the last command 770 // different from the last command
778 m_lastEditCommand = cmd; 771 m_lastEditCommand = cmd;
779 if (UndoStack* undoStack = this->undoStack()) 772 m_undoStack->registerUndoStep(m_lastEditCommand->ensureComposition());
780 undoStack->registerUndoStep(m_lastEditCommand->ensureComposition());
781 } 773 }
782 774
783 respondToChangedContents(newSelection); 775 respondToChangedContents(newSelection);
784 } 776 }
785 777
786 void Editor::unappliedEditing(EditCommandComposition* cmd) 778 void Editor::unappliedEditing(EditCommandComposition* cmd)
787 { 779 {
788 EventQueueScope scope; 780 EventQueueScope scope;
789 frame().document()->updateStyleAndLayout(); 781 frame().document()->updateStyleAndLayout();
790 782
791 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd ->endingRootEditableElement()); 783 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd ->endingRootEditableElement());
792 dispatchInputEventEditableContentChanged(cmd->startingRootEditableElement(), cmd->endingRootEditableElement(), InputEvent::InputType::Undo, emptyString(), I nputEvent::EventIsComposing::NotComposing); 784 dispatchInputEventEditableContentChanged(cmd->startingRootEditableElement(), cmd->endingRootEditableElement(), InputEvent::InputType::Undo, emptyString(), I nputEvent::EventIsComposing::NotComposing);
793 785
794 VisibleSelection newSelection(cmd->startingSelection()); 786 VisibleSelection newSelection(cmd->startingSelection());
795 newSelection.validatePositionsIfNeeded(); 787 newSelection.validatePositionsIfNeeded();
796 if (newSelection.start().document() == frame().document() && newSelection.en d().document() == frame().document()) 788 if (newSelection.start().document() == frame().document() && newSelection.en d().document() == frame().document())
797 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle); 789 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle);
798 790
799 m_lastEditCommand = nullptr; 791 m_lastEditCommand = nullptr;
800 if (UndoStack* undoStack = this->undoStack()) 792 m_undoStack->registerRedoStep(cmd);
801 undoStack->registerRedoStep(cmd);
802 respondToChangedContents(newSelection); 793 respondToChangedContents(newSelection);
803 } 794 }
804 795
805 void Editor::reappliedEditing(EditCommandComposition* cmd) 796 void Editor::reappliedEditing(EditCommandComposition* cmd)
806 { 797 {
807 EventQueueScope scope; 798 EventQueueScope scope;
808 frame().document()->updateStyleAndLayout(); 799 frame().document()->updateStyleAndLayout();
809 800
810 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd ->endingRootEditableElement()); 801 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd ->endingRootEditableElement());
811 dispatchInputEventEditableContentChanged(cmd->startingRootEditableElement(), cmd->endingRootEditableElement(), InputEvent::InputType::Redo, emptyString(), I nputEvent::EventIsComposing::NotComposing); 802 dispatchInputEventEditableContentChanged(cmd->startingRootEditableElement(), cmd->endingRootEditableElement(), InputEvent::InputType::Redo, emptyString(), I nputEvent::EventIsComposing::NotComposing);
812 803
813 VisibleSelection newSelection(cmd->endingSelection()); 804 VisibleSelection newSelection(cmd->endingSelection());
814 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | Fram eSelection::ClearTypingStyle); 805 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | Fram eSelection::ClearTypingStyle);
815 806
816 m_lastEditCommand = nullptr; 807 m_lastEditCommand = nullptr;
817 if (UndoStack* undoStack = this->undoStack()) 808 m_undoStack->registerUndoStep(cmd);
818 undoStack->registerUndoStep(cmd);
819 respondToChangedContents(newSelection); 809 respondToChangedContents(newSelection);
820 } 810 }
821 811
822 Editor* Editor::create(LocalFrame& frame) 812 Editor* Editor::create(LocalFrame& frame)
823 { 813 {
824 return new Editor(frame); 814 return new Editor(frame);
825 } 815 }
826 816
827 Editor::Editor(LocalFrame& frame) 817 Editor::Editor(LocalFrame& frame)
828 : m_frame(&frame) 818 : m_frame(&frame)
819 , m_undoStack(UndoStack::create())
829 , m_preventRevealSelection(0) 820 , m_preventRevealSelection(0)
830 , m_shouldStartNewKillRingSequence(false) 821 , m_shouldStartNewKillRingSequence(false)
831 // This is off by default, since most editors want this behavior (this match es IE but not FF). 822 // This is off by default, since most editors want this behavior (this match es IE but not FF).
832 , m_shouldStyleWithCSS(false) 823 , m_shouldStyleWithCSS(false)
833 , m_killRing(wrapUnique(new KillRing)) 824 , m_killRing(wrapUnique(new KillRing))
834 , m_areMarkedTextMatchesHighlighted(false) 825 , m_areMarkedTextMatchesHighlighted(false)
835 , m_defaultParagraphSeparator(EditorParagraphSeparatorIsDiv) 826 , m_defaultParagraphSeparator(EditorParagraphSeparatorIsDiv)
836 , m_overwriteModeEnabled(false) 827 , m_overwriteModeEnabled(false)
837 { 828 {
838 } 829 }
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 } 1044 }
1054 } 1045 }
1055 1046
1056 void Editor::copyImage(const HitTestResult& result) 1047 void Editor::copyImage(const HitTestResult& result)
1057 { 1048 {
1058 writeImageNodeToPasteboard(Pasteboard::generalPasteboard(), result.innerNode OrImageMapImage(), result.altDisplayString()); 1049 writeImageNodeToPasteboard(Pasteboard::generalPasteboard(), result.innerNode OrImageMapImage(), result.altDisplayString());
1059 } 1050 }
1060 1051
1061 bool Editor::canUndo() 1052 bool Editor::canUndo()
1062 { 1053 {
1063 if (UndoStack* undoStack = this->undoStack()) 1054 return m_undoStack->canUndo();
1064 return undoStack->canUndo();
1065 return false;
1066 } 1055 }
1067 1056
1068 void Editor::undo() 1057 void Editor::undo()
1069 { 1058 {
1070 if (UndoStack* undoStack = this->undoStack()) 1059 m_undoStack->undo();
1071 undoStack->undo();
1072 } 1060 }
1073 1061
1074 bool Editor::canRedo() 1062 bool Editor::canRedo()
1075 { 1063 {
1076 if (UndoStack* undoStack = this->undoStack()) 1064 return m_undoStack->canRedo();
1077 return undoStack->canRedo();
1078 return false;
1079 } 1065 }
1080 1066
1081 void Editor::redo() 1067 void Editor::redo()
1082 { 1068 {
1083 if (UndoStack* undoStack = this->undoStack()) 1069 m_undoStack->redo();
1084 undoStack->redo();
1085 } 1070 }
1086 1071
1087 void Editor::setBaseWritingDirection(WritingDirection direction) 1072 void Editor::setBaseWritingDirection(WritingDirection direction)
1088 { 1073 {
1089 Element* focusedElement = frame().document()->focusedElement(); 1074 Element* focusedElement = frame().document()->focusedElement();
1090 if (isHTMLTextFormControlElement(focusedElement)) { 1075 if (isHTMLTextFormControlElement(focusedElement)) {
1091 if (direction == NaturalWritingDirection) 1076 if (direction == NaturalWritingDirection)
1092 return; 1077 return;
1093 focusedElement->setAttribute(dirAttr, direction == LeftToRightWritingDir ection ? "ltr" : "rtl"); 1078 focusedElement->setAttribute(dirAttr, direction == LeftToRightWritingDir ection ? "ltr" : "rtl");
1094 focusedElement->dispatchInputEvent(); 1079 focusedElement->dispatchInputEvent();
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 DCHECK(!document.documentElement()); 1412 DCHECK(!document.documentElement());
1428 document.appendChild(root); 1413 document.appendChild(root);
1429 1414
1430 // TODO(tkent): Should we check and move Text node children of <html>? 1415 // TODO(tkent): Should we check and move Text node children of <html>?
1431 } 1416 }
1432 1417
1433 DEFINE_TRACE(Editor) 1418 DEFINE_TRACE(Editor)
1434 { 1419 {
1435 visitor->trace(m_frame); 1420 visitor->trace(m_frame);
1436 visitor->trace(m_lastEditCommand); 1421 visitor->trace(m_lastEditCommand);
1422 visitor->trace(m_undoStack);
1437 visitor->trace(m_mark); 1423 visitor->trace(m_mark);
1438 } 1424 }
1439 1425
1440 } // namespace blink 1426 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698