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

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

Issue 2124723002: Reland of "Move UndoStack from Page to Editor" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Hide UndoStack::clear in Editor::clear 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 // TODO(yosin): Since |dispatchEditableContentChangedEvents()| and 804 // TODO(yosin): Since |dispatchEditableContentChangedEvents()| and
814 // |dispatchInputEventEditableContentChanged()|, we would like to know 805 // |dispatchInputEventEditableContentChanged()|, we would like to know
815 // such case. Once we have a case, this |DCHECK()| should be replaced 806 // such case. Once we have a case, this |DCHECK()| should be replaced
816 // with if-statement. 807 // with if-statement.
817 DCHECK(frame().document()); 808 DCHECK(frame().document());
818 VisibleSelection newSelection(cmd->endingSelection()); 809 VisibleSelection newSelection(cmd->endingSelection());
819 if (newSelection.isValidFor(*frame().document())) 810 if (newSelection.isValidFor(*frame().document()))
820 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle); 811 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle);
821 812
822 m_lastEditCommand = nullptr; 813 m_lastEditCommand = nullptr;
823 if (UndoStack* undoStack = this->undoStack()) 814 m_undoStack->registerUndoStep(cmd);
824 undoStack->registerUndoStep(cmd);
825 respondToChangedContents(newSelection); 815 respondToChangedContents(newSelection);
826 } 816 }
827 817
828 Editor* Editor::create(LocalFrame& frame) 818 Editor* Editor::create(LocalFrame& frame)
829 { 819 {
830 return new Editor(frame); 820 return new Editor(frame);
831 } 821 }
832 822
833 Editor::Editor(LocalFrame& frame) 823 Editor::Editor(LocalFrame& frame)
834 : m_frame(&frame) 824 : m_frame(&frame)
825 , m_undoStack(UndoStack::create())
835 , m_preventRevealSelection(0) 826 , m_preventRevealSelection(0)
836 , m_shouldStartNewKillRingSequence(false) 827 , m_shouldStartNewKillRingSequence(false)
837 // This is off by default, since most editors want this behavior (this match es IE but not FF). 828 // This is off by default, since most editors want this behavior (this match es IE but not FF).
838 , m_shouldStyleWithCSS(false) 829 , m_shouldStyleWithCSS(false)
839 , m_killRing(wrapUnique(new KillRing)) 830 , m_killRing(wrapUnique(new KillRing))
840 , m_areMarkedTextMatchesHighlighted(false) 831 , m_areMarkedTextMatchesHighlighted(false)
841 , m_defaultParagraphSeparator(EditorParagraphSeparatorIsDiv) 832 , m_defaultParagraphSeparator(EditorParagraphSeparatorIsDiv)
842 , m_overwriteModeEnabled(false) 833 , m_overwriteModeEnabled(false)
843 { 834 {
844 } 835 }
845 836
846 Editor::~Editor() 837 Editor::~Editor()
847 { 838 {
848 } 839 }
849 840
850 void Editor::clear() 841 void Editor::clear()
851 { 842 {
852 frame().inputMethodController().clear(); 843 frame().inputMethodController().clear();
853 m_shouldStyleWithCSS = false; 844 m_shouldStyleWithCSS = false;
854 m_defaultParagraphSeparator = EditorParagraphSeparatorIsDiv; 845 m_defaultParagraphSeparator = EditorParagraphSeparatorIsDiv;
846 m_undoStack->clear();
855 } 847 }
856 848
857 bool Editor::insertText(const String& text, KeyboardEvent* triggeringEvent) 849 bool Editor::insertText(const String& text, KeyboardEvent* triggeringEvent)
858 { 850 {
859 return frame().eventHandler().handleTextInputEvent(text, triggeringEvent); 851 return frame().eventHandler().handleTextInputEvent(text, triggeringEvent);
860 } 852 }
861 853
862 bool Editor::insertTextWithoutSendingTextEvent(const String& text, bool selectIn sertedText, TextEvent* triggeringEvent) 854 bool Editor::insertTextWithoutSendingTextEvent(const String& text, bool selectIn sertedText, TextEvent* triggeringEvent)
863 { 855 {
864 if (text.isEmpty()) 856 if (text.isEmpty())
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 } 1051 }
1060 } 1052 }
1061 1053
1062 void Editor::copyImage(const HitTestResult& result) 1054 void Editor::copyImage(const HitTestResult& result)
1063 { 1055 {
1064 writeImageNodeToPasteboard(Pasteboard::generalPasteboard(), result.innerNode OrImageMapImage(), result.altDisplayString()); 1056 writeImageNodeToPasteboard(Pasteboard::generalPasteboard(), result.innerNode OrImageMapImage(), result.altDisplayString());
1065 } 1057 }
1066 1058
1067 bool Editor::canUndo() 1059 bool Editor::canUndo()
1068 { 1060 {
1069 if (UndoStack* undoStack = this->undoStack()) 1061 return m_undoStack->canUndo();
1070 return undoStack->canUndo();
1071 return false;
1072 } 1062 }
1073 1063
1074 void Editor::undo() 1064 void Editor::undo()
1075 { 1065 {
1076 if (UndoStack* undoStack = this->undoStack()) 1066 m_undoStack->undo();
1077 undoStack->undo();
1078 } 1067 }
1079 1068
1080 bool Editor::canRedo() 1069 bool Editor::canRedo()
1081 { 1070 {
1082 if (UndoStack* undoStack = this->undoStack()) 1071 return m_undoStack->canRedo();
1083 return undoStack->canRedo();
1084 return false;
1085 } 1072 }
1086 1073
1087 void Editor::redo() 1074 void Editor::redo()
1088 { 1075 {
1089 if (UndoStack* undoStack = this->undoStack()) 1076 m_undoStack->redo();
1090 undoStack->redo();
1091 } 1077 }
1092 1078
1093 void Editor::setBaseWritingDirection(WritingDirection direction) 1079 void Editor::setBaseWritingDirection(WritingDirection direction)
1094 { 1080 {
1095 Element* focusedElement = frame().document()->focusedElement(); 1081 Element* focusedElement = frame().document()->focusedElement();
1096 if (isHTMLTextFormControlElement(focusedElement)) { 1082 if (isHTMLTextFormControlElement(focusedElement)) {
1097 if (direction == NaturalWritingDirection) 1083 if (direction == NaturalWritingDirection)
1098 return; 1084 return;
1099 focusedElement->setAttribute(dirAttr, direction == LeftToRightWritingDir ection ? "ltr" : "rtl"); 1085 focusedElement->setAttribute(dirAttr, direction == LeftToRightWritingDir ection ? "ltr" : "rtl");
1100 focusedElement->dispatchInputEvent(); 1086 focusedElement->dispatchInputEvent();
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1433 DCHECK(!document.documentElement()); 1419 DCHECK(!document.documentElement());
1434 document.appendChild(root); 1420 document.appendChild(root);
1435 1421
1436 // TODO(tkent): Should we check and move Text node children of <html>? 1422 // TODO(tkent): Should we check and move Text node children of <html>?
1437 } 1423 }
1438 1424
1439 DEFINE_TRACE(Editor) 1425 DEFINE_TRACE(Editor)
1440 { 1426 {
1441 visitor->trace(m_frame); 1427 visitor->trace(m_frame);
1442 visitor->trace(m_lastEditCommand); 1428 visitor->trace(m_lastEditCommand);
1429 visitor->trace(m_undoStack);
1443 visitor->trace(m_mark); 1430 visitor->trace(m_mark);
1444 } 1431 }
1445 1432
1446 } // namespace blink 1433 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/Editor.h ('k') | third_party/WebKit/Source/core/editing/commands/UndoStack.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698