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

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

Powered by Google App Engine
This is Rietveld 408576698