1 /* 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef EditCommand_h 27 #define EditCommand_h 28 29 #include "core/editing/EditAction.h" 30 #include "core/editing/VisibleSelection.h" 31 #include "platform/heap/Handle.h" 32 33 #ifndef NDEBUG 34 #include "wtf/HashSet.h" 35 #endif 36 37 namespace WebCore { 38 39 class CompositeEditCommand; 40 class Document; 41 class Element; 42 43 class EditCommand : public RefCountedWillBeGarbageCollectedFinalized<EditCommand> { 44 public: 45 virtual ~EditCommand(); 46 47 void setParent(CompositeEditCommand*); 48 49 virtual EditAction editingAction() const; 50 51 const VisibleSelection& startingSelection() const { return m_startingSelection; } 52 const VisibleSelection& endingSelection() const { return m_endingSelection; } 53 54 virtual bool isSimpleEditCommand() const { return false; } 55 virtual bool isCompositeEditCommand() const { return false; } 56 bool isTopLevelCommand() const { return !m_parent; } 57 58 virtual void doApply() = 0; 59 60 virtual void trace(Visitor*); 61 62 protected: 63 explicit EditCommand(Document&); 64 EditCommand(Document*, const VisibleSelection&, const VisibleSelection&); 65 66 Document& document() const { return *m_document.get(); } 67 CompositeEditCommand* parent() const { return m_parent; } 68 void setStartingSelection(const VisibleSelection&); 69 void setStartingSelection(const VisiblePosition&); 70 void setEndingSelection(const VisibleSelection&); 71 void setEndingSelection(const VisiblePosition&); 72 73 private: 74 RefPtrWillBeMember<Document> m_document; 75 VisibleSelection m_startingSelection; 76 VisibleSelection m_endingSelection; 77 RawPtrWillBeMember<CompositeEditCommand> m_parent; 78 }; 79 80 enum ShouldAssumeContentIsAlwaysEditable { 81 AssumeContentIsAlwaysEditable, 82 DoNotAssumeContentIsAlwaysEditable, 83 }; 84 85 class SimpleEditCommand : public EditCommand { 86 public: 87 virtual void doUnapply() = 0; 88 virtual void doReapply(); // calls doApply() 89 90 protected: 91 explicit SimpleEditCommand(Document& document) : EditCommand(document) { } 92 93 private: 94 virtual bool isSimpleEditCommand() const OVERRIDE FINAL { return true; } 95 }; 96 97 DEFINE_TYPE_CASTS(SimpleEditCommand, EditCommand, command, command->isSimpleEditCommand(), command.isSimpleEditCommand()); 98 99 } // namespace WebCore 100 101 #endif // EditCommand_h 102