2 * Copyright (C) 2004 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef __htmlediting_h__
27 #define __htmlediting_h__
29 #include "dom_nodeimpl.h"
30 #include "editing/edit_actions.h"
32 #include "qvaluelist.h"
33 #include "selection.h"
37 class CSSMutableStyleDeclarationImpl;
39 class CSSStyleDeclarationImpl;
40 class DocumentFragmentImpl;
41 class HTMLElementImpl;
49 class VisiblePosition;
51 //------------------------------------------------------------------------------------------
54 class EditCommandPtr : public SharedPtr<EditCommand>
58 EditCommandPtr(EditCommand *);
59 EditCommandPtr(const EditCommandPtr &);
62 EditCommandPtr &operator=(const EditCommandPtr &);
64 bool isCompositeStep() const;
70 EditAction editingAction() const;
72 DOM::DocumentImpl * const document() const;
74 Selection startingSelection() const;
75 Selection endingSelection() const;
77 void setStartingSelection(const Selection &s) const;
78 void setEndingSelection(const Selection &s) const;
80 DOM::CSSMutableStyleDeclarationImpl *typingStyle() const;
81 void setTypingStyle(DOM::CSSMutableStyleDeclarationImpl *) const;
83 EditCommandPtr parent() const;
84 void setParent(const EditCommandPtr &) const;
86 bool isInsertTextCommand() const;
87 bool isInsertLineBreakCommand() const;
88 bool isTypingCommand() const;
90 static EditCommandPtr &emptyCommand();
93 //------------------------------------------------------------------------------------------
98 enum ELegacyHTMLStyles { DoNotUseLegacyHTMLStyles, UseLegacyHTMLStyles };
100 explicit StyleChange(DOM::CSSStyleDeclarationImpl *, ELegacyHTMLStyles usesLegacyStyles=UseLegacyHTMLStyles);
101 StyleChange(DOM::CSSStyleDeclarationImpl *, const DOM::Position &, ELegacyHTMLStyles usesLegacyStyles=UseLegacyHTMLStyles);
103 DOM::DOMString cssStyle() const { return m_cssStyle; }
104 bool applyBold() const { return m_applyBold; }
105 bool applyItalic() const { return m_applyItalic; }
106 bool usesLegacyStyles() const { return m_usesLegacyStyles; }
109 void init(DOM::CSSStyleDeclarationImpl *, const DOM::Position &);
110 bool checkForLegacyHTMLStyleChange(const DOM::CSSProperty *);
111 static bool currentlyHasStyle(const DOM::Position &, const DOM::CSSProperty *);
113 DOM::DOMString m_cssStyle;
116 bool m_usesLegacyStyles;
119 //------------------------------------------------------------------------------------------
122 class EditCommand : public Shared<EditCommand>
125 EditCommand(DOM::DocumentImpl *);
126 virtual ~EditCommand();
128 bool isCompositeStep() const { return m_parent != 0; }
129 EditCommand *parent() const { return m_parent; }
130 void setParent(EditCommand *parent) { m_parent = parent; }
132 enum ECommandState { NotApplied, Applied };
138 virtual void doApply() = 0;
139 virtual void doUnapply() = 0;
140 virtual void doReapply(); // calls doApply()
142 virtual EditAction editingAction() const;
144 virtual DOM::DocumentImpl * const document() const { return m_document; }
146 Selection startingSelection() const { return m_startingSelection; }
147 Selection endingSelection() const { return m_endingSelection; }
149 void setEndingSelectionNeedsLayout(bool flag=true) { m_endingSelection.setNeedsLayout(flag); }
151 ECommandState state() const { return m_state; }
152 void setState(ECommandState state) { m_state = state; }
154 void setStartingSelection(const Selection &s);
155 void setEndingSelection(const Selection &s);
157 DOM::CSSMutableStyleDeclarationImpl *typingStyle() const { return m_typingStyle; };
158 void setTypingStyle(DOM::CSSMutableStyleDeclarationImpl *);
160 virtual bool isInsertTextCommand() const;
161 virtual bool isTypingCommand() const;
164 void assignTypingStyle(DOM::CSSMutableStyleDeclarationImpl *);
166 virtual bool preservesTypingStyle() const;
168 DOM::DocumentImpl *m_document;
169 ECommandState m_state;
170 Selection m_startingSelection;
171 Selection m_endingSelection;
172 DOM::CSSMutableStyleDeclarationImpl *m_typingStyle;
173 EditCommand *m_parent;
176 //------------------------------------------------------------------------------------------
177 // CompositeEditCommand
179 class CompositeEditCommand : public EditCommand
182 CompositeEditCommand(DOM::DocumentImpl *);
184 virtual void doUnapply();
185 virtual void doReapply();
189 // sugary-sweet convenience functions to help create and apply edit commands in composite commands
191 void appendNode(DOM::NodeImpl *appendChild, DOM::NodeImpl *parentNode);
192 void applyCommandToComposite(EditCommandPtr &);
193 void deleteKeyPressed();
194 void deleteSelection(bool smartDelete=false, bool mergeBlocksAfterDelete=true);
195 void deleteSelection(const Selection &selection, bool smartDelete=false, bool mergeBlocksAfterDelete=true);
196 void deleteTextFromNode(DOM::TextImpl *node, long offset, long count);
197 void inputText(const DOM::DOMString &text, bool selectInsertedText = false);
198 void insertNodeAfter(DOM::NodeImpl *insertChild, DOM::NodeImpl *refChild);
199 void insertNodeAt(DOM::NodeImpl *insertChild, DOM::NodeImpl *refChild, long offset);
200 void insertNodeBefore(DOM::NodeImpl *insertChild, DOM::NodeImpl *refChild);
201 void insertParagraphSeparator();
202 void insertTextIntoNode(DOM::TextImpl *node, long offset, const DOM::DOMString &text);
203 void joinTextNodes(DOM::TextImpl *text1, DOM::TextImpl *text2);
204 void rebalanceWhitespace();
205 void removeCSSProperty(DOM::CSSStyleDeclarationImpl *, int property);
206 void removeFullySelectedNode(DOM::NodeImpl *);
207 void removeNodeAttribute(DOM::ElementImpl *, int attribute);
208 void removeNode(DOM::NodeImpl *removeChild);
209 void removeNodePreservingChildren(DOM::NodeImpl *node);
210 void replaceTextInNode(DOM::TextImpl *node, long offset, long count, const DOM::DOMString &replacementText);
211 void setNodeAttribute(DOM::ElementImpl *, int attribute, const DOM::DOMString &);
212 void splitTextNode(DOM::TextImpl *text, long offset);
214 DOM::NodeImpl *applyTypingStyle(DOM::NodeImpl *) const;
216 void deleteInsignificantText(DOM::TextImpl *, int start, int end);
217 void deleteInsignificantText(const DOM::Position &start, const DOM::Position &end);
218 void deleteInsignificantTextDownstream(const DOM::Position &);
220 void insertBlockPlaceholderIfNeeded(DOM::NodeImpl *);
221 bool removeBlockPlaceholderIfNeeded(DOM::NodeImpl *);
223 QValueList<EditCommandPtr> m_cmds;
226 //==========================================================================================
228 //------------------------------------------------------------------------------------------
231 class AppendNodeCommand : public EditCommand
234 AppendNodeCommand(DOM::DocumentImpl *, DOM::NodeImpl *appendChild, DOM::NodeImpl *parentNode);
235 virtual ~AppendNodeCommand();
237 virtual void doApply();
238 virtual void doUnapply();
240 DOM::NodeImpl *appendChild() const { return m_appendChild; }
241 DOM::NodeImpl *parentNode() const { return m_parentNode; }
244 DOM::NodeImpl *m_appendChild;
245 DOM::NodeImpl *m_parentNode;
248 //------------------------------------------------------------------------------------------
251 class ApplyStyleCommand : public CompositeEditCommand
254 ApplyStyleCommand(DOM::DocumentImpl *, DOM::CSSStyleDeclarationImpl *style, EditAction editingAction=EditActionChangeAttributes);
255 virtual ~ApplyStyleCommand();
257 virtual void doApply();
258 virtual EditAction editingAction() const;
260 DOM::CSSMutableStyleDeclarationImpl *style() const { return m_style; }
263 // style-removal helpers
264 bool isHTMLStyleNode(DOM::CSSMutableStyleDeclarationImpl *, DOM::HTMLElementImpl *);
265 void removeHTMLStyleNode(DOM::HTMLElementImpl *);
266 void removeCSSStyle(DOM::CSSMutableStyleDeclarationImpl *, DOM::HTMLElementImpl *);
267 void removeBlockStyle(DOM::CSSMutableStyleDeclarationImpl *, const DOM::Position &start, const DOM::Position &end);
268 void removeInlineStyle(DOM::CSSMutableStyleDeclarationImpl *, const DOM::Position &start, const DOM::Position &end);
269 bool nodeFullySelected(DOM::NodeImpl *, const DOM::Position &start, const DOM::Position &end) const;
271 // style-application helpers
272 void applyBlockStyle(DOM::CSSMutableStyleDeclarationImpl *);
273 void applyInlineStyle(DOM::CSSMutableStyleDeclarationImpl *);
274 void addBlockStyleIfNeeded(DOM::CSSMutableStyleDeclarationImpl *, DOM::HTMLElementImpl *);
275 void addInlineStyleIfNeeded(DOM::CSSMutableStyleDeclarationImpl *, DOM::NodeImpl *start, DOM::NodeImpl *end);
276 bool splitTextAtStartIfNeeded(const DOM::Position &start, const DOM::Position &end);
277 DOM::NodeImpl *splitTextAtEndIfNeeded(const DOM::Position &start, const DOM::Position &end);
278 void surroundNodeRangeWithElement(DOM::NodeImpl *start, DOM::NodeImpl *end, DOM::ElementImpl *element);
279 DOM::Position positionInsertionPoint(DOM::Position);
281 DOM::CSSMutableStyleDeclarationImpl *m_style;
282 EditAction m_editingAction;
285 //------------------------------------------------------------------------------------------
286 // DeleteFromTextNodeCommand
288 class DeleteFromTextNodeCommand : public EditCommand
291 DeleteFromTextNodeCommand(DOM::DocumentImpl *document, DOM::TextImpl *node, long offset, long count);
292 virtual ~DeleteFromTextNodeCommand();
294 virtual void doApply();
295 virtual void doUnapply();
297 DOM::TextImpl *node() const { return m_node; }
298 long offset() const { return m_offset; }
299 long count() const { return m_count; }
302 DOM::TextImpl *m_node;
305 DOM::DOMString m_text;
308 //------------------------------------------------------------------------------------------
309 // DeleteSelectionCommand
311 class DeleteSelectionCommand : public CompositeEditCommand
314 DeleteSelectionCommand(DOM::DocumentImpl *document, bool smartDelete=false, bool mergeBlocksAfterDelete=true);
315 DeleteSelectionCommand(DOM::DocumentImpl *document, const Selection &selection, bool smartDelete=false, bool mergeBlocksAfterDelete=true);
317 virtual void doApply();
318 virtual EditAction editingAction() const;
321 virtual bool preservesTypingStyle() const;
323 void initializePositionData();
324 void saveTypingStyleState();
325 void insertPlaceholderForAncestorBlockContent();
326 bool handleSpecialCaseAllContentDelete();
327 bool handleSpecialCaseBRDelete();
328 void handleGeneralDelete();
329 void fixupWhitespace();
330 void moveNodesAfterNode();
331 void calculateEndingPosition();
332 void calculateTypingStyleAfterDelete();
333 void clearTransientState();
335 bool m_hasSelectionToDelete;
337 bool m_mergeBlocksAfterDelete;
338 bool m_trailingWhitespaceValid;
340 // This data is transient and should be cleared at the end of the doApply function.
341 Selection m_selectionToDelete;
342 DOM::Position m_upstreamStart;
343 DOM::Position m_downstreamStart;
344 DOM::Position m_upstreamEnd;
345 DOM::Position m_downstreamEnd;
346 DOM::Position m_endingPosition;
347 DOM::Position m_leadingWhitespace;
348 DOM::Position m_trailingWhitespace;
349 DOM::NodeImpl *m_startBlock;
350 DOM::NodeImpl *m_endBlock;
351 DOM::NodeImpl *m_startNode;
352 DOM::CSSMutableStyleDeclarationImpl *m_typingStyle;
355 //------------------------------------------------------------------------------------------
356 // InsertIntoTextNode
358 class InsertIntoTextNode : public EditCommand
361 InsertIntoTextNode(DOM::DocumentImpl *document, DOM::TextImpl *, long, const DOM::DOMString &);
362 virtual ~InsertIntoTextNode();
364 virtual void doApply();
365 virtual void doUnapply();
367 DOM::TextImpl *node() const { return m_node; }
368 long offset() const { return m_offset; }
369 DOM::DOMString text() const { return m_text; }
372 DOM::TextImpl *m_node;
374 DOM::DOMString m_text;
377 //------------------------------------------------------------------------------------------
378 // InsertNodeBeforeCommand
380 class InsertNodeBeforeCommand : public EditCommand
383 InsertNodeBeforeCommand(DOM::DocumentImpl *, DOM::NodeImpl *insertChild, DOM::NodeImpl *refChild);
384 virtual ~InsertNodeBeforeCommand();
386 virtual void doApply();
387 virtual void doUnapply();
389 DOM::NodeImpl *insertChild() const { return m_insertChild; }
390 DOM::NodeImpl *refChild() const { return m_refChild; }
393 DOM::NodeImpl *m_insertChild;
394 DOM::NodeImpl *m_refChild;
397 //------------------------------------------------------------------------------------------
398 // InsertLineBreakCommand
400 class InsertLineBreakCommand : public CompositeEditCommand
403 InsertLineBreakCommand(DOM::DocumentImpl *document);
405 virtual void doApply();
408 void insertNodeAfterPosition(DOM::NodeImpl *node, const DOM::Position &pos);
409 void insertNodeBeforePosition(DOM::NodeImpl *node, const DOM::Position &pos);
412 //------------------------------------------------------------------------------------------
413 // InsertParagraphSeparatorCommand
415 class InsertParagraphSeparatorCommand : public CompositeEditCommand
418 InsertParagraphSeparatorCommand(DOM::DocumentImpl *document);
419 virtual ~InsertParagraphSeparatorCommand();
421 virtual void doApply();
424 DOM::ElementImpl *createParagraphElement();
426 QPtrList<DOM::NodeImpl> ancestors;
427 QPtrList<DOM::NodeImpl> clonedNodes;
430 //------------------------------------------------------------------------------------------
431 // InsertParagraphSeparatorInQuotedContentCommand
433 class InsertParagraphSeparatorInQuotedContentCommand : public CompositeEditCommand
436 InsertParagraphSeparatorInQuotedContentCommand(DOM::DocumentImpl *);
437 virtual ~InsertParagraphSeparatorInQuotedContentCommand();
439 virtual void doApply();
442 bool isMailBlockquote(const DOM::NodeImpl *) const;
444 QPtrList<DOM::NodeImpl> ancestors;
445 QPtrList<DOM::NodeImpl> clonedNodes;
446 DOM::ElementImpl *m_breakNode;
449 //------------------------------------------------------------------------------------------
452 class InsertTextCommand : public CompositeEditCommand
455 InsertTextCommand(DOM::DocumentImpl *document);
457 virtual void doApply();
459 void deleteCharacter();
460 void input(const DOM::DOMString &text, bool selectInsertedText = false);
462 unsigned long charactersAdded() const { return m_charactersAdded; }
465 virtual bool isInsertTextCommand() const;
467 DOM::Position prepareForTextInsertion(bool adjustDownstream);
468 void insertSpace(DOM::TextImpl *textNode, unsigned long offset);
470 unsigned long m_charactersAdded;
473 //------------------------------------------------------------------------------------------
474 // JoinTextNodesCommand
476 class JoinTextNodesCommand : public EditCommand
479 JoinTextNodesCommand(DOM::DocumentImpl *, DOM::TextImpl *, DOM::TextImpl *);
480 virtual ~JoinTextNodesCommand();
482 virtual void doApply();
483 virtual void doUnapply();
485 DOM::TextImpl *firstNode() const { return m_text1; }
486 DOM::TextImpl *secondNode() const { return m_text2; }
489 DOM::TextImpl *m_text1;
490 DOM::TextImpl *m_text2;
491 unsigned long m_offset;
494 //------------------------------------------------------------------------------------------
495 // MoveSelectionCommand
497 class MoveSelectionCommand : public CompositeEditCommand
500 MoveSelectionCommand(DOM::DocumentImpl *document, DOM::DocumentFragmentImpl *fragment, DOM::Position &position, bool smartMove=false);
501 virtual ~MoveSelectionCommand();
503 virtual void doApply();
504 virtual EditAction editingAction() const;
507 DOM::DocumentFragmentImpl *m_fragment;
508 DOM::Position m_position;
512 //------------------------------------------------------------------------------------------
513 // RebalanceWhitespaceCommand
515 class RebalanceWhitespaceCommand : public EditCommand
518 RebalanceWhitespaceCommand(DOM::DocumentImpl *, const DOM::Position &);
519 virtual ~RebalanceWhitespaceCommand();
521 virtual void doApply();
522 virtual void doUnapply();
525 enum { InvalidOffset = -1 };
527 virtual bool preservesTypingStyle() const;
529 DOM::DOMString m_beforeString;
530 DOM::DOMString m_afterString;
531 DOM::Position m_position;
532 long m_upstreamOffset;
533 long m_downstreamOffset;
536 //------------------------------------------------------------------------------------------
537 // RemoveCSSPropertyCommand
539 class RemoveCSSPropertyCommand : public EditCommand
542 RemoveCSSPropertyCommand(DOM::DocumentImpl *, DOM::CSSStyleDeclarationImpl *, int property);
543 virtual ~RemoveCSSPropertyCommand();
545 virtual void doApply();
546 virtual void doUnapply();
548 DOM::CSSMutableStyleDeclarationImpl *styleDeclaration() const { return m_decl; }
549 int property() const { return m_property; }
552 DOM::CSSMutableStyleDeclarationImpl *m_decl;
554 DOM::DOMString m_oldValue;
558 //------------------------------------------------------------------------------------------
559 // RemoveNodeAttributeCommand
561 class RemoveNodeAttributeCommand : public EditCommand
564 RemoveNodeAttributeCommand(DOM::DocumentImpl *, DOM::ElementImpl *, DOM::NodeImpl::Id attribute);
565 virtual ~RemoveNodeAttributeCommand();
567 virtual void doApply();
568 virtual void doUnapply();
570 DOM::ElementImpl *element() const { return m_element; }
571 DOM::NodeImpl::Id attribute() const { return m_attribute; }
574 DOM::ElementImpl *m_element;
575 DOM::NodeImpl::Id m_attribute;
576 DOM::DOMString m_oldValue;
579 //------------------------------------------------------------------------------------------
582 class RemoveNodeCommand : public EditCommand
585 RemoveNodeCommand(DOM::DocumentImpl *, DOM::NodeImpl *);
586 virtual ~RemoveNodeCommand();
588 virtual void doApply();
589 virtual void doUnapply();
591 DOM::NodeImpl *node() const { return m_removeChild; }
594 DOM::NodeImpl *m_parent;
595 DOM::NodeImpl *m_removeChild;
596 DOM::NodeImpl *m_refChild;
599 //------------------------------------------------------------------------------------------
600 // RemoveNodePreservingChildrenCommand
602 class RemoveNodePreservingChildrenCommand : public CompositeEditCommand
605 RemoveNodePreservingChildrenCommand(DOM::DocumentImpl *, DOM::NodeImpl *);
606 virtual ~RemoveNodePreservingChildrenCommand();
608 virtual void doApply();
610 DOM::NodeImpl *node() const { return m_node; }
613 DOM::NodeImpl *m_node;
616 //------------------------------------------------------------------------------------------
617 // ReplaceSelectionCommand
619 // --- ReplacementFragment helper class
621 class ReplacementFragment
624 ReplacementFragment(DOM::DocumentFragmentImpl *fragment);
625 ~ReplacementFragment();
627 enum EFragmentType { EmptyFragment, SingleTextNodeFragment, TreeFragment };
629 DOM::DocumentFragmentImpl *root() const { return m_fragment; }
630 DOM::NodeImpl *firstChild() const;
631 DOM::NodeImpl *lastChild() const;
633 DOM::NodeImpl *mergeStartNode() const;
634 DOM::NodeImpl *mergeEndNode() const;
636 void pruneEmptyNodes();
638 EFragmentType type() const { return m_type; }
639 bool isEmpty() const { return m_type == EmptyFragment; }
640 bool isSingleTextNode() const { return m_type == SingleTextNodeFragment; }
641 bool isTreeFragment() const { return m_type == TreeFragment; }
643 bool hasMoreThanOneBlock() const { return m_hasMoreThanOneBlock; }
644 bool hasInterchangeNewline() const { return m_hasInterchangeNewline; }
647 // no copy construction or assignment
648 ReplacementFragment(const ReplacementFragment &);
649 ReplacementFragment &operator=(const ReplacementFragment &);
651 static bool isInterchangeNewlineNode(const DOM::NodeImpl *);
652 static bool isInterchangeConvertedSpaceSpan(const DOM::NodeImpl *);
654 // A couple simple DOM helpers
655 DOM::NodeImpl *enclosingBlock(DOM::NodeImpl *) const;
656 void removeNode(DOM::NodeImpl *);
657 void insertNodeBefore(DOM::NodeImpl *node, DOM::NodeImpl *refNode);
659 EFragmentType m_type;
660 DOM::DocumentFragmentImpl *m_fragment;
661 bool m_hasInterchangeNewline;
662 bool m_hasMoreThanOneBlock;
665 // free-floating helper functions
666 bool isProbablyBlock(const DOM::NodeImpl *);
668 class ReplaceSelectionCommand : public CompositeEditCommand
671 ReplaceSelectionCommand(DOM::DocumentImpl *document, DOM::DocumentFragmentImpl *fragment, bool selectReplacement=true, bool smartReplace=false);
672 virtual ~ReplaceSelectionCommand();
674 virtual void doApply();
675 virtual EditAction editingAction() const;
678 void completeHTMLReplacement(const DOM::Position &, const DOM::Position &);
679 void completeHTMLReplacement(DOM::NodeImpl *, DOM::NodeImpl *);
681 ReplacementFragment m_fragment;
682 bool m_selectReplacement;
686 //------------------------------------------------------------------------------------------
687 // SetNodeAttributeCommand
689 class SetNodeAttributeCommand : public EditCommand
692 SetNodeAttributeCommand(DOM::DocumentImpl *, DOM::ElementImpl *, DOM::NodeImpl::Id attribute, const DOM::DOMString &value);
693 virtual ~SetNodeAttributeCommand();
695 virtual void doApply();
696 virtual void doUnapply();
698 DOM::ElementImpl *element() const { return m_element; }
699 DOM::NodeImpl::Id attribute() const { return m_attribute; }
700 DOM::DOMString value() const { return m_value; }
703 DOM::ElementImpl *m_element;
704 DOM::NodeImpl::Id m_attribute;
705 DOM::DOMString m_value;
706 DOM::DOMString m_oldValue;
709 //------------------------------------------------------------------------------------------
710 // SplitTextNodeCommand
712 class SplitTextNodeCommand : public EditCommand
715 SplitTextNodeCommand(DOM::DocumentImpl *, DOM::TextImpl *, long);
716 virtual ~SplitTextNodeCommand();
718 virtual void doApply();
719 virtual void doUnapply();
721 DOM::TextImpl *node() const { return m_text2; }
722 long offset() const { return m_offset; }
725 DOM::TextImpl *m_text1;
726 DOM::TextImpl *m_text2;
727 unsigned long m_offset;
730 //------------------------------------------------------------------------------------------
733 class TypingCommand : public CompositeEditCommand
736 enum ETypingCommand {
740 InsertParagraphSeparator,
741 InsertParagraphSeparatorInQuotedContent,
744 TypingCommand(DOM::DocumentImpl *document, ETypingCommand, const DOM::DOMString &text = "", bool selectInsertedText = false);
746 static void deleteKeyPressed(DOM::DocumentImpl *);
747 static void insertText(DOM::DocumentImpl *, const DOM::DOMString &, bool selectInsertedText = false);
748 static void insertLineBreak(DOM::DocumentImpl *);
749 static void insertParagraphSeparator(DOM::DocumentImpl *);
750 static void insertParagraphSeparatorInQuotedContent(DOM::DocumentImpl *);
751 static bool isOpenForMoreTypingCommand(const EditCommandPtr &);
752 static void closeTyping(const EditCommandPtr &);
754 virtual void doApply();
755 virtual EditAction editingAction() const;
757 bool openForMoreTyping() const { return m_openForMoreTyping; }
758 void closeTyping() { m_openForMoreTyping = false; }
760 void insertText(const DOM::DOMString &text, bool selectInsertedText);
761 void insertLineBreak();
762 void insertParagraphSeparatorInQuotedContent();
763 void insertParagraphSeparator();
764 void deleteKeyPressed();
767 virtual bool isTypingCommand() const;
768 virtual bool preservesTypingStyle() const;
770 void issueCommandForDeleteKey();
771 void removeCommand(const EditCommandPtr &);
772 void markMisspellingsAfterTyping();
773 void typingAddedToOpenCommand();
775 ETypingCommand m_commandType;
776 DOM::DOMString m_textToInsert;
777 bool m_openForMoreTyping;
779 bool m_selectInsertedText;
782 //------------------------------------------------------------------------------------------
784 DOM::ElementImpl *createDefaultParagraphElement(DOM::DocumentImpl *document);
785 DOM::ElementImpl *createBlockPlaceholderElement(DOM::DocumentImpl *document);
786 DOM::ElementImpl *createBreakElement(DOM::DocumentImpl *document);
788 //------------------------------------------------------------------------------------------
790 } // end namespace khtml