OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 } |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1059 } | 1050 } |
1060 } | 1051 } |
1061 | 1052 |
1062 void Editor::copyImage(const HitTestResult& result) | 1053 void Editor::copyImage(const HitTestResult& result) |
1063 { | 1054 { |
1064 writeImageNodeToPasteboard(Pasteboard::generalPasteboard(), result.innerNode OrImageMapImage(), result.altDisplayString()); | 1055 writeImageNodeToPasteboard(Pasteboard::generalPasteboard(), result.innerNode OrImageMapImage(), result.altDisplayString()); |
1065 } | 1056 } |
1066 | 1057 |
1067 bool Editor::canUndo() | 1058 bool Editor::canUndo() |
1068 { | 1059 { |
1069 if (UndoStack* undoStack = this->undoStack()) | 1060 return m_undoStack->canUndo(); |
1070 return undoStack->canUndo(); | |
1071 return false; | |
1072 } | 1061 } |
1073 | 1062 |
1074 void Editor::undo() | 1063 void Editor::undo() |
1075 { | 1064 { |
1076 if (UndoStack* undoStack = this->undoStack()) | 1065 m_undoStack->undo(); |
1077 undoStack->undo(); | |
1078 } | 1066 } |
1079 | 1067 |
1080 bool Editor::canRedo() | 1068 bool Editor::canRedo() |
1081 { | 1069 { |
1082 if (UndoStack* undoStack = this->undoStack()) | 1070 return m_undoStack->canRedo(); |
1083 return undoStack->canRedo(); | |
1084 return false; | |
1085 } | 1071 } |
1086 | 1072 |
1087 void Editor::redo() | 1073 void Editor::redo() |
1088 { | 1074 { |
1089 if (UndoStack* undoStack = this->undoStack()) | 1075 m_undoStack->redo(); |
1090 undoStack->redo(); | 1076 } |
1077 | |
1078 void Editor::clearUndoStack() | |
1079 { | |
1080 return m_undoStack->clear(); | |
yosin_UTC9
2016/07/06 01:04:51
How about doing |m_undoStack->clear()| to move |Ed
Xiaocheng
2016/07/06 04:18:32
It seems a saner idea as now UndoStack is just an
| |
1091 } | 1081 } |
1092 | 1082 |
1093 void Editor::setBaseWritingDirection(WritingDirection direction) | 1083 void Editor::setBaseWritingDirection(WritingDirection direction) |
1094 { | 1084 { |
1095 Element* focusedElement = frame().document()->focusedElement(); | 1085 Element* focusedElement = frame().document()->focusedElement(); |
1096 if (isHTMLTextFormControlElement(focusedElement)) { | 1086 if (isHTMLTextFormControlElement(focusedElement)) { |
1097 if (direction == NaturalWritingDirection) | 1087 if (direction == NaturalWritingDirection) |
1098 return; | 1088 return; |
1099 focusedElement->setAttribute(dirAttr, direction == LeftToRightWritingDir ection ? "ltr" : "rtl"); | 1089 focusedElement->setAttribute(dirAttr, direction == LeftToRightWritingDir ection ? "ltr" : "rtl"); |
1100 focusedElement->dispatchInputEvent(); | 1090 focusedElement->dispatchInputEvent(); |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1433 DCHECK(!document.documentElement()); | 1423 DCHECK(!document.documentElement()); |
1434 document.appendChild(root); | 1424 document.appendChild(root); |
1435 | 1425 |
1436 // TODO(tkent): Should we check and move Text node children of <html>? | 1426 // TODO(tkent): Should we check and move Text node children of <html>? |
1437 } | 1427 } |
1438 | 1428 |
1439 DEFINE_TRACE(Editor) | 1429 DEFINE_TRACE(Editor) |
1440 { | 1430 { |
1441 visitor->trace(m_frame); | 1431 visitor->trace(m_frame); |
1442 visitor->trace(m_lastEditCommand); | 1432 visitor->trace(m_lastEditCommand); |
1433 visitor->trace(m_undoStack); | |
1443 visitor->trace(m_mark); | 1434 visitor->trace(m_mark); |
1444 } | 1435 } |
1445 | 1436 |
1446 } // namespace blink | 1437 } // namespace blink |
OLD | NEW |