don't discard iframe children.
[kdelibs.git] / khtml / editing / htmlediting.h
blob1b1113f24b6a23f14e7079144ee3fcb9d6071963
1 /*
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
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.
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 "edit_command.h"
31 #include "xml/dom_nodeimpl.h"
33 namespace DOM {
34 class CSSStyleDeclarationImpl;
35 class DocumentFragmentImpl;
36 class DocumentImpl;
37 class DOMString;
38 class ElementImpl;
39 class NodeImpl;
40 class Position;
41 class Selection;
42 class TextImpl;
45 namespace khtml {
47 class AppendNodeCommandImpl;
48 class ApplyStyleCommandImpl;
49 class CompositeEditCommandImpl;
50 class DeleteCollapsibleWhitespaceCommandImpl;
51 class DeleteSelectionCommandImpl;
52 class DeleteTextCommandImpl;
53 class EditCommand;
54 class EditCommandImpl;
55 class InputNewlineCommandImpl;
56 class InputTextCommandImpl;
57 class InsertNodeBeforeCommandImpl;
58 class InsertTextCommandImpl;
59 class JoinTextNodesCommandImpl;
60 class MoveSelectionCommandImpl;
61 class ReplaceSelectionCommandImpl;
62 class RemoveCSSPropertyCommandImpl;
63 class RemoveNodeAttributeCommandImpl;
64 class RemoveNodeCommandImpl;
65 class RemoveNodeAndPruneCommandImpl;
66 class RemoveNodePreservingChildrenCommandImpl;
67 class SetNodeAttributeCommandImpl;
68 class SplitTextNodeCommandImpl;
69 class TypingCommandImpl;
71 //------------------------------------------------------------------------------------------
72 // CompositeEditCommand
74 class CompositeEditCommand : public EditCommand
76 public:
77 CompositeEditCommand();
78 CompositeEditCommand(CompositeEditCommandImpl *);
79 CompositeEditCommand(const CompositeEditCommand &);
80 ~CompositeEditCommand();
82 private:
83 inline CompositeEditCommandImpl *impl() const;
86 //==========================================================================================
87 // Concrete commands
88 //------------------------------------------------------------------------------------------
89 // AppendNodeCommand
91 class AppendNodeCommand : public EditCommand
93 public:
94 AppendNodeCommand(DOM::DocumentImpl *, DOM::NodeImpl *parentNode, DOM::NodeImpl *appendChild);
95 ~AppendNodeCommand();
97 DOM::NodeImpl *parentNode() const;
98 DOM::NodeImpl *appendChild() const;
100 private:
101 inline AppendNodeCommandImpl *impl() const;
104 //------------------------------------------------------------------------------------------
105 // ApplyStyleCommand
107 class ApplyStyleCommand : public CompositeEditCommand
109 public:
110 ApplyStyleCommand(DOM::DocumentImpl *, DOM::CSSStyleDeclarationImpl *);
111 ~ApplyStyleCommand();
113 DOM::CSSStyleDeclarationImpl *style() const;
115 private:
116 inline ApplyStyleCommandImpl *impl() const;
119 //------------------------------------------------------------------------------------------
120 // DeleteCollapsibleWhitespaceCommand
122 class DeleteCollapsibleWhitespaceCommand : public CompositeEditCommand
124 public:
125 DeleteCollapsibleWhitespaceCommand(DOM::DocumentImpl *document);
126 DeleteCollapsibleWhitespaceCommand(DOM::DocumentImpl *document, const DOM::Selection &selection);
128 ~DeleteCollapsibleWhitespaceCommand();
130 private:
131 inline DeleteCollapsibleWhitespaceCommandImpl *impl() const;
134 //------------------------------------------------------------------------------------------
135 // DeleteSelectionCommand
137 class DeleteSelectionCommand : public CompositeEditCommand
139 public:
140 DeleteSelectionCommand(DOM::DocumentImpl *document);
141 DeleteSelectionCommand(DOM::DocumentImpl *document, const DOM::Selection &selection);
142 ~DeleteSelectionCommand();
144 private:
145 inline DeleteSelectionCommandImpl *impl() const;
148 //------------------------------------------------------------------------------------------
149 // DeleteTextCommand
151 class DeleteTextCommand : public EditCommand
153 public:
154 DeleteTextCommand(DOM::DocumentImpl *document, DOM::TextImpl *, long offset, long count);
155 DeleteTextCommand(const DeleteTextCommand &);
156 ~DeleteTextCommand();
158 DOM::TextImpl *node() const;
159 long offset() const;
160 long count() const;
162 private:
163 inline DeleteTextCommandImpl *impl() const;
166 //------------------------------------------------------------------------------------------
167 // InputNewlineCommand
169 class InputNewlineCommand : public CompositeEditCommand
171 public:
172 InputNewlineCommand(DOM::DocumentImpl *document);
173 ~InputNewlineCommand();
175 private:
176 inline InputNewlineCommandImpl *impl() const;
179 //------------------------------------------------------------------------------------------
180 // InputTextCommand
182 class InputTextCommand : public CompositeEditCommand
184 public:
185 InputTextCommand(DOM::DocumentImpl *document);
186 ~InputTextCommand();
188 void deleteCharacter();
189 void input(const DOM::DOMString &text);
191 unsigned long charactersAdded() const;
193 private:
194 inline InputTextCommandImpl *impl() const;
197 //------------------------------------------------------------------------------------------
198 // InsertNodeBeforeCommand
200 class InsertNodeBeforeCommand : public EditCommand
202 public:
203 InsertNodeBeforeCommand();
204 InsertNodeBeforeCommand(DOM::DocumentImpl *, DOM::NodeImpl *insertChild, DOM::NodeImpl *refChild);
205 InsertNodeBeforeCommand(const InsertNodeBeforeCommand &);
206 ~InsertNodeBeforeCommand();
208 DOM::NodeImpl *insertChild() const;
209 DOM::NodeImpl *refChild() const;
211 private:
212 inline InsertNodeBeforeCommandImpl *impl() const;
215 //------------------------------------------------------------------------------------------
216 // InsertTextCommand
218 class InsertTextCommand : public EditCommand
220 public:
221 InsertTextCommand(DOM::DocumentImpl *document, DOM::TextImpl *, long, const DOM::DOMString &);
222 ~InsertTextCommand();
224 DOM::TextImpl *node() const;
225 long offset() const;
226 DOM::DOMString text() const;
228 private:
229 inline InsertTextCommandImpl *impl() const;
232 //------------------------------------------------------------------------------------------
233 // JoinTextNodesCommand
235 class JoinTextNodesCommand : public EditCommand
237 public:
238 JoinTextNodesCommand(DOM::DocumentImpl *, DOM::TextImpl *, DOM::TextImpl *);
239 ~JoinTextNodesCommand();
241 DOM::TextImpl *firstNode() const;
242 DOM::TextImpl *secondNode() const;
244 private:
245 inline JoinTextNodesCommandImpl *impl() const;
248 //------------------------------------------------------------------------------------------
249 // ReplaceSelectionCommand
251 class ReplaceSelectionCommand : public CompositeEditCommand
253 public:
254 ReplaceSelectionCommand(DOM::DocumentImpl *document, DOM::DocumentFragmentImpl *fragment, bool selectReplacement=true);
255 ~ReplaceSelectionCommand();
257 private:
258 inline ReplaceSelectionCommandImpl *impl() const;
261 //------------------------------------------------------------------------------------------
262 // MoveSelectionCommand
264 class MoveSelectionCommand : public CompositeEditCommand
266 public:
267 MoveSelectionCommand(DOM::DocumentImpl *document, DOM::DocumentFragmentImpl *fragment, DOM::Position &position);
268 ~MoveSelectionCommand();
270 private:
271 inline MoveSelectionCommandImpl *impl() const;
274 //------------------------------------------------------------------------------------------
275 // RemoveCSSPropertyCommand
277 class RemoveCSSPropertyCommand : public EditCommand
279 public:
280 RemoveCSSPropertyCommand(DOM::DocumentImpl *, DOM::CSSStyleDeclarationImpl *, int property);
281 ~RemoveCSSPropertyCommand();
283 DOM::CSSStyleDeclarationImpl *styleDeclaration() const;
284 int property() const;
286 private:
287 inline RemoveCSSPropertyCommandImpl *impl() const;
290 //------------------------------------------------------------------------------------------
291 // RemoveNodeAttributeCommand
293 class RemoveNodeAttributeCommand : public EditCommand
295 public:
296 RemoveNodeAttributeCommand(DOM::DocumentImpl *, DOM::ElementImpl *, DOM::NodeImpl::Id attribute);
297 ~RemoveNodeAttributeCommand();
299 DOM::ElementImpl *element() const;
300 DOM::NodeImpl::Id attribute() const;
302 private:
303 inline RemoveNodeAttributeCommandImpl *impl() const;
306 //------------------------------------------------------------------------------------------
307 // RemoveNodeCommand
309 class RemoveNodeCommand : public EditCommand
311 public:
312 RemoveNodeCommand(DOM::DocumentImpl *, DOM::NodeImpl *node);
313 ~RemoveNodeCommand();
315 DOM::NodeImpl *node() const;
317 private:
318 inline RemoveNodeCommandImpl *impl() const;
321 //------------------------------------------------------------------------------------------
322 // RemoveNodeAndPruneCommand
324 class RemoveNodeAndPruneCommand : public CompositeEditCommand
326 public:
327 RemoveNodeAndPruneCommand(DOM::DocumentImpl *, DOM::NodeImpl *pruneNode, DOM::NodeImpl *stopNode=0);
328 ~RemoveNodeAndPruneCommand();
330 DOM::NodeImpl *pruneNode() const;
331 DOM::NodeImpl *stopNode() const;
333 private:
334 inline RemoveNodeAndPruneCommandImpl *impl() const;
337 //------------------------------------------------------------------------------------------
338 // RemoveNodePreservingChildrenCommand
340 class RemoveNodePreservingChildrenCommand : public CompositeEditCommand
342 public:
343 RemoveNodePreservingChildrenCommand(DOM::DocumentImpl *document, DOM::NodeImpl *node);
344 ~RemoveNodePreservingChildrenCommand();
346 DOM::NodeImpl *node() const;
348 private:
349 inline RemoveNodePreservingChildrenCommandImpl *impl() const;
352 //------------------------------------------------------------------------------------------
353 // SetNodeAttributeCommand
355 class SetNodeAttributeCommand : public EditCommand
357 public:
358 SetNodeAttributeCommand(DOM::DocumentImpl *, DOM::ElementImpl *, DOM::NodeImpl::Id attribute, const DOM::DOMString &value);
359 ~SetNodeAttributeCommand();
361 DOM::ElementImpl *element() const;
362 DOM::NodeImpl::Id attribute() const;
363 DOM::DOMString value() const;
365 private:
366 inline SetNodeAttributeCommandImpl *impl() const;
369 //------------------------------------------------------------------------------------------
370 // SplitTextNodeCommand
372 class SplitTextNodeCommand : public EditCommand
374 public:
375 SplitTextNodeCommand(DOM::DocumentImpl *, DOM::TextImpl *, long);
376 ~SplitTextNodeCommand();
378 DOM::TextImpl *node() const;
379 long offset() const;
381 private:
382 inline SplitTextNodeCommandImpl *impl() const;
385 //------------------------------------------------------------------------------------------
386 // TypingCommand
388 class TypingCommand : public CompositeEditCommand
390 public:
391 static void deleteKeyPressed(DOM::DocumentImpl *document);
392 static void insertText(DOM::DocumentImpl *document, const DOM::DOMString &text);
393 static void insertNewline(DOM::DocumentImpl *document);
394 static bool isOpenForMoreTypingCommand(const EditCommand &);
395 static void closeTyping(EditCommand);
397 bool openForMoreTyping() const;
398 void closeTyping();
400 private:
401 TypingCommand(DOM::DocumentImpl *document);
402 TypingCommand(TypingCommand *);
403 TypingCommand(const TypingCommand &);
404 ~TypingCommand();
406 void deleteKeyPressed();
407 void insertText(const DOM::DOMString &text);
408 void insertNewline();
410 inline TypingCommandImpl *impl() const;
413 //------------------------------------------------------------------------------------------
415 } // end namespace khtml
417 #endif