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

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

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