• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KHTML

htmlediting.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Apple Computer, Inc.  All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  * 1. Redistributions of source code must retain the above copyright
00008  *    notice, this list of conditions and the following disclaimer.
00009  * 2. Redistributions in binary form must reproduce the above copyright
00010  *    notice, this list of conditions and the following disclaimer in the
00011  *    documentation and/or other materials provided with the distribution.
00012  *
00013  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
00014  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00015  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00016  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
00017  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00018  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00019  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00020  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00021  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00022  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00023  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00024  */
00025 
00026 #include "htmlediting.h"
00027 #include "htmlediting_impl.h"
00028 
00029 #include "editor.h"
00030 #include "khtml_part.h"
00031 
00032 #include "xml/dom_position.h"
00033 #include "xml/dom_docimpl.h"
00034 #include "xml/dom_nodeimpl.h"
00035 #include "xml/dom_selection.h"
00036 #include "xml/dom_textimpl.h"
00037 
00038 using DOM::CSSStyleDeclarationImpl;
00039 using DOM::DocumentImpl;
00040 using DOM::ElementImpl;
00041 using DOM::Position;
00042 using DOM::Editor;
00043 using DOM::DOMString;
00044 using DOM::NodeImpl;
00045 using DOM::NodeListImpl;
00046 using DOM::Selection;
00047 using DOM::TextImpl;
00048 
00049 #define IF_IMPL_NULL_RETURN_ARG(arg) do { \
00050         if (isNull()) { return arg; } \
00051     } while (0)
00052         
00053 #define IF_IMPL_NULL_RETURN do { \
00054         if (isNull()) { return; } \
00055     } while (0)
00056 
00057 
00058 namespace khtml {
00059 
00060 //------------------------------------------------------------------------------------------
00061 // EditCommand
00062 
00063 EditCommand::EditCommand() : SharedPtr<SharedCommandImpl>()
00064 {
00065 }
00066 
00067 EditCommand::EditCommand(EditCommandImpl *impl) : SharedPtr<SharedCommandImpl>(impl)
00068 {
00069 }
00070 
00071 EditCommand::EditCommand(const EditCommand &o) : SharedPtr<SharedCommandImpl>(o.get())
00072 {
00073 }
00074 
00075 EditCommand::~EditCommand()
00076 {
00077 }
00078 
00079 int EditCommand::commandID() const
00080 {
00081     IF_IMPL_NULL_RETURN_ARG(0);        
00082     return get()->commandID();
00083 }
00084 
00085 bool EditCommand::isCompositeStep() const
00086 {
00087     IF_IMPL_NULL_RETURN_ARG(false);        
00088     return get()->isCompositeStep();
00089 }
00090 
00091 bool EditCommand::isNull() const
00092 {
00093     return get() == 0;
00094 }
00095 
00096 bool EditCommand::notNull() const
00097 {
00098     return !isNull();
00099 }
00100 
00101 void EditCommand::apply()
00102 {
00103     IF_IMPL_NULL_RETURN;
00104     get()->apply();
00105 }
00106 
00107 void EditCommand::unapply()
00108 {
00109     IF_IMPL_NULL_RETURN;
00110     get()->unapply();
00111 }
00112 
00113 void EditCommand::reapply()
00114 {
00115     IF_IMPL_NULL_RETURN;
00116     get()->reapply();
00117 }
00118 
00119 DocumentImpl * const EditCommand::document() const
00120 {
00121     IF_IMPL_NULL_RETURN_ARG(0);
00122     return get()->document();
00123 }
00124 
00125 Selection EditCommand::startingSelection() const
00126 {
00127     IF_IMPL_NULL_RETURN_ARG(Selection());
00128     return get()->startingSelection();
00129 }
00130 
00131 Selection EditCommand::endingSelection() const
00132 {
00133     IF_IMPL_NULL_RETURN_ARG(Selection());
00134     return get()->endingSelection();
00135 }
00136 
00137 void EditCommand::setStartingSelection(const Selection &s)
00138 {
00139     IF_IMPL_NULL_RETURN;
00140     get()->setStartingSelection(s);
00141 }
00142 
00143 void EditCommand::setEndingSelection(const Selection &s)
00144 {
00145     IF_IMPL_NULL_RETURN;
00146     get()->setEndingSelection(s);
00147 }
00148 
00149 EditCommand EditCommand::parent() const
00150 {
00151     IF_IMPL_NULL_RETURN_ARG(0);
00152     return get()->parent();
00153 }
00154 
00155 EditCommandImpl *EditCommand::handle() const
00156 {
00157     return static_cast<EditCommandImpl *>(get());
00158 }
00159 
00160 EditCommand &EditCommand::emptyCommand()
00161 {
00162     static EditCommand m_emptyCommand;
00163     return m_emptyCommand;
00164 }
00165 
00166 //------------------------------------------------------------------------------------------
00167 // CompositeEditCommand
00168 
00169 CompositeEditCommand::CompositeEditCommand() : EditCommand() 
00170 {
00171 }
00172 
00173 CompositeEditCommand::CompositeEditCommand(CompositeEditCommandImpl *impl) : EditCommand(impl) 
00174 {
00175 }
00176 
00177 CompositeEditCommand::CompositeEditCommand(const CompositeEditCommand &o) 
00178     : EditCommand(o.impl()) 
00179 {
00180 }
00181 
00182 CompositeEditCommand::~CompositeEditCommand()
00183 {
00184 }
00185 
00186 CompositeEditCommandImpl *CompositeEditCommand::impl() const
00187 {
00188     return static_cast<CompositeEditCommandImpl *>(get());
00189 }
00190 
00191 //==========================================================================================
00192 // Concrete commands
00193 //------------------------------------------------------------------------------------------
00194 // AppendNodeCommand
00195 
00196 AppendNodeCommand::AppendNodeCommand(DocumentImpl *document, NodeImpl *parentNode, NodeImpl *appendChild)
00197     : EditCommand(new AppendNodeCommandImpl(document, parentNode, appendChild))
00198 {
00199 }
00200 
00201 AppendNodeCommand::~AppendNodeCommand()
00202 {
00203 }
00204 
00205 AppendNodeCommandImpl *AppendNodeCommand::impl() const
00206 {
00207     return static_cast<AppendNodeCommandImpl *>(get());
00208 }
00209 
00210 NodeImpl *AppendNodeCommand::parentNode() const
00211 {
00212     IF_IMPL_NULL_RETURN_ARG(0);
00213     return impl()->parentNode();
00214 }
00215 
00216 NodeImpl *AppendNodeCommand::appendChild() const
00217 {
00218     IF_IMPL_NULL_RETURN_ARG(0);
00219     return impl()->appendChild();
00220 }
00221 
00222 //------------------------------------------------------------------------------------------
00223 // ApplyStyleCommand
00224 
00225 ApplyStyleCommand::ApplyStyleCommand(DocumentImpl *document, CSSStyleDeclarationImpl *style)
00226     : CompositeEditCommand(new ApplyStyleCommandImpl(document, style))
00227 {
00228 }
00229 
00230 ApplyStyleCommand::~ApplyStyleCommand()
00231 {
00232 }
00233 
00234 ApplyStyleCommandImpl *ApplyStyleCommand::impl() const
00235 {
00236     return static_cast<ApplyStyleCommandImpl *>(get());
00237 }
00238 
00239 CSSStyleDeclarationImpl *ApplyStyleCommand::style() const
00240 {
00241     IF_IMPL_NULL_RETURN_ARG(0);
00242     return impl()->style();
00243 }
00244 
00245 //------------------------------------------------------------------------------------------
00246 // DeleteCollapsibleWhitespaceCommand
00247 
00248 DeleteCollapsibleWhitespaceCommand::DeleteCollapsibleWhitespaceCommand(DocumentImpl *document)
00249     : CompositeEditCommand(new DeleteCollapsibleWhitespaceCommandImpl(document))
00250 {
00251 }
00252 
00253 DeleteCollapsibleWhitespaceCommand::DeleteCollapsibleWhitespaceCommand(DocumentImpl *document, const Selection &selection)
00254     : CompositeEditCommand(new DeleteCollapsibleWhitespaceCommandImpl(document, selection))
00255 {
00256 }
00257 
00258 DeleteCollapsibleWhitespaceCommand::~DeleteCollapsibleWhitespaceCommand()
00259 {
00260 }
00261     
00262 DeleteCollapsibleWhitespaceCommandImpl *DeleteCollapsibleWhitespaceCommand::impl() const
00263 {
00264     return static_cast<DeleteCollapsibleWhitespaceCommandImpl *>(get());
00265 }
00266 
00267 //------------------------------------------------------------------------------------------
00268 // DeleteSelectionCommand
00269 
00270 DeleteSelectionCommand::DeleteSelectionCommand(DocumentImpl *document)
00271     : CompositeEditCommand(new DeleteSelectionCommandImpl(document))
00272 {
00273 }
00274 
00275 DeleteSelectionCommand::DeleteSelectionCommand(DocumentImpl *document, const Selection &selection)
00276     : CompositeEditCommand(new DeleteSelectionCommandImpl(document, selection))
00277 {
00278 }
00279 
00280 DeleteSelectionCommand::~DeleteSelectionCommand()
00281 {
00282 }
00283     
00284 DeleteSelectionCommandImpl *DeleteSelectionCommand::impl() const
00285 {
00286     return static_cast<DeleteSelectionCommandImpl *>(get());
00287 }
00288 
00289 //------------------------------------------------------------------------------------------
00290 // DeleteTextCommand
00291 
00292 DeleteTextCommand::DeleteTextCommand(DocumentImpl *document, TextImpl *node, long offset, long count)
00293     : EditCommand(new DeleteTextCommandImpl(document, node, offset, count))
00294 {
00295 }
00296 
00297 DeleteTextCommand::DeleteTextCommand(const DeleteTextCommand &o)
00298     : EditCommand(o.impl())
00299 {
00300 }
00301 
00302 DeleteTextCommand::~DeleteTextCommand()
00303 {
00304 }
00305 
00306 DeleteTextCommandImpl *DeleteTextCommand::impl() const
00307 {
00308     return static_cast<DeleteTextCommandImpl *>(get());
00309 }
00310 
00311 TextImpl *DeleteTextCommand::node() const
00312 {
00313     IF_IMPL_NULL_RETURN_ARG(0);
00314     return impl()->node();
00315 }
00316 
00317 long DeleteTextCommand::offset() const
00318 {
00319     IF_IMPL_NULL_RETURN_ARG(0);
00320     return impl()->offset();
00321 }
00322 
00323 long DeleteTextCommand::count() const
00324 {
00325     IF_IMPL_NULL_RETURN_ARG(0);
00326     return impl()->count();
00327 }
00328 
00329 //------------------------------------------------------------------------------------------
00330 // InputNewlineCommand
00331 
00332 InputNewlineCommand::InputNewlineCommand(DocumentImpl *document) 
00333     : CompositeEditCommand(new InputNewlineCommandImpl(document))
00334 {
00335 }
00336 
00337 InputNewlineCommand::~InputNewlineCommand() 
00338 {
00339 }
00340 
00341 InputNewlineCommandImpl *InputNewlineCommand::impl() const
00342 {
00343     return static_cast<InputNewlineCommandImpl *>(get());
00344 }
00345 
00346 //------------------------------------------------------------------------------------------
00347 // InputTextCommand
00348 
00349 InputTextCommand::InputTextCommand(DocumentImpl *document) 
00350     : CompositeEditCommand(new InputTextCommandImpl(document))
00351 {
00352 }
00353 
00354 InputTextCommand::~InputTextCommand() 
00355 {
00356 }
00357 
00358 InputTextCommandImpl *InputTextCommand::impl() const
00359 {
00360     return static_cast<InputTextCommandImpl *>(get());
00361 }
00362 
00363 void InputTextCommand::deleteCharacter()
00364 {
00365     IF_IMPL_NULL_RETURN;
00366     impl()->deleteCharacter();
00367 }
00368 
00369 void InputTextCommand::input(const DOM::DOMString &text)
00370 {
00371     IF_IMPL_NULL_RETURN;
00372     impl()->input(text);
00373 }
00374 
00375 unsigned long InputTextCommand::charactersAdded() const
00376 {
00377     IF_IMPL_NULL_RETURN_ARG(0);
00378     return impl()->charactersAdded();
00379 }
00380 
00381 //------------------------------------------------------------------------------------------
00382 // InsertNodeBeforeCommand
00383 
00384 InsertNodeBeforeCommand::InsertNodeBeforeCommand() : EditCommand()
00385 {
00386 }
00387 
00388 InsertNodeBeforeCommand::InsertNodeBeforeCommand(DocumentImpl *document, NodeImpl *insertChild, NodeImpl *refChild)
00389     : EditCommand(new InsertNodeBeforeCommandImpl(document, insertChild, refChild))
00390 {
00391 }
00392 
00393 InsertNodeBeforeCommand::InsertNodeBeforeCommand(const InsertNodeBeforeCommand &o)
00394     : EditCommand(new InsertNodeBeforeCommandImpl(o.document(), o.insertChild(), o.refChild()))
00395 {
00396 }
00397 
00398 InsertNodeBeforeCommand::~InsertNodeBeforeCommand()
00399 {
00400 }
00401 
00402 InsertNodeBeforeCommandImpl *InsertNodeBeforeCommand::impl() const
00403 {
00404     return static_cast<InsertNodeBeforeCommandImpl *>(get());
00405 }
00406 
00407 NodeImpl *InsertNodeBeforeCommand::insertChild() const
00408 {
00409     IF_IMPL_NULL_RETURN_ARG(0);        
00410     return impl()->insertChild();
00411 }
00412 
00413 NodeImpl *InsertNodeBeforeCommand::refChild() const
00414 {
00415     IF_IMPL_NULL_RETURN_ARG(0);        
00416     return impl()->refChild();
00417 }
00418 
00419 //------------------------------------------------------------------------------------------
00420 // InsertTextCommand
00421 
00422 InsertTextCommand::InsertTextCommand(DocumentImpl *document, TextImpl *node, long offset, const DOMString &text)
00423     : EditCommand(new InsertTextCommandImpl(document, node, offset, text))
00424 {
00425 }
00426 
00427 InsertTextCommand::~InsertTextCommand()
00428 {
00429 }
00430 
00431 InsertTextCommandImpl *InsertTextCommand::impl() const
00432 {
00433     return static_cast<InsertTextCommandImpl *>(get());
00434 }
00435 
00436 TextImpl *InsertTextCommand::node() const
00437 {
00438     IF_IMPL_NULL_RETURN_ARG(0);
00439     return impl()->node();
00440 }
00441 
00442 long InsertTextCommand::offset() const
00443 {
00444     IF_IMPL_NULL_RETURN_ARG(0);
00445     return impl()->offset();
00446 }
00447 
00448 DOMString InsertTextCommand::text() const
00449 {
00450     IF_IMPL_NULL_RETURN_ARG(DOMString());
00451     return impl()->text();
00452 }
00453 
00454 //------------------------------------------------------------------------------------------
00455 // JoinTextNodesCommand
00456 
00457 JoinTextNodesCommand::JoinTextNodesCommand(DocumentImpl *document, TextImpl *text1, TextImpl *text2)
00458     : EditCommand(new JoinTextNodesCommandImpl(document, text1, text2))
00459 {
00460 }
00461 
00462 JoinTextNodesCommand::~JoinTextNodesCommand()
00463 {
00464 }
00465 
00466 JoinTextNodesCommandImpl *JoinTextNodesCommand::impl() const
00467 {
00468     return static_cast<JoinTextNodesCommandImpl *>(get());
00469 }
00470 
00471 TextImpl *JoinTextNodesCommand::firstNode() const
00472 {
00473     IF_IMPL_NULL_RETURN_ARG(0);
00474     return impl()->firstNode();
00475 }
00476 
00477 TextImpl *JoinTextNodesCommand::secondNode() const
00478 {
00479     IF_IMPL_NULL_RETURN_ARG(0);
00480     return impl()->secondNode();
00481 }
00482 
00483 //------------------------------------------------------------------------------------------
00484 // ReplaceSelectionCommand
00485 
00486 ReplaceSelectionCommand::ReplaceSelectionCommand(DocumentImpl *document, DOM::DocumentFragmentImpl *fragment, bool selectReplacement) 
00487     : CompositeEditCommand(new ReplaceSelectionCommandImpl(document, fragment, selectReplacement))
00488 {
00489 }
00490 
00491 ReplaceSelectionCommand::~ReplaceSelectionCommand() 
00492 {
00493 }
00494 
00495 ReplaceSelectionCommandImpl *ReplaceSelectionCommand::impl() const
00496 {
00497     return static_cast<ReplaceSelectionCommandImpl *>(get());
00498 }
00499 
00500 //------------------------------------------------------------------------------------------
00501 // MoveSelectionCommand
00502 
00503 MoveSelectionCommand::MoveSelectionCommand(DocumentImpl *document, DOM::DocumentFragmentImpl *fragment, DOM::Position &position) 
00504 : CompositeEditCommand(new MoveSelectionCommandImpl(document, fragment, position))
00505 {
00506 }
00507 
00508 MoveSelectionCommand::~MoveSelectionCommand() 
00509 {
00510 }
00511 
00512 MoveSelectionCommandImpl *MoveSelectionCommand::impl() const
00513 {
00514     return static_cast<MoveSelectionCommandImpl *>(get());
00515 }
00516 
00517 //------------------------------------------------------------------------------------------
00518 // RemoveCSSPropertyCommand
00519 
00520 RemoveCSSPropertyCommand::RemoveCSSPropertyCommand(DocumentImpl *document, CSSStyleDeclarationImpl *decl, int property)
00521     : EditCommand(new RemoveCSSPropertyCommandImpl(document, decl, property))
00522 {
00523 }
00524 
00525 RemoveCSSPropertyCommand::~RemoveCSSPropertyCommand()
00526 {
00527 }
00528 
00529 RemoveCSSPropertyCommandImpl *RemoveCSSPropertyCommand::impl() const
00530 {
00531     return static_cast<RemoveCSSPropertyCommandImpl *>(get());
00532 }
00533 
00534 CSSStyleDeclarationImpl *RemoveCSSPropertyCommand::styleDeclaration() const
00535 {
00536     IF_IMPL_NULL_RETURN_ARG(0);
00537     return impl()->styleDeclaration();
00538 }
00539 
00540 int RemoveCSSPropertyCommand::property() const
00541 {
00542     IF_IMPL_NULL_RETURN_ARG(0);
00543     return impl()->property();
00544 }
00545 
00546 //------------------------------------------------------------------------------------------
00547 // RemoveNodeAttributeCommand
00548 
00549 RemoveNodeAttributeCommand::RemoveNodeAttributeCommand(DocumentImpl *document, ElementImpl *element, NodeImpl::Id attribute)
00550     : EditCommand(new RemoveNodeAttributeCommandImpl(document, element, attribute))
00551 {
00552 }
00553 
00554 RemoveNodeAttributeCommand::~RemoveNodeAttributeCommand()
00555 {
00556 }
00557 
00558 RemoveNodeAttributeCommandImpl *RemoveNodeAttributeCommand::impl() const
00559 {
00560     return static_cast<RemoveNodeAttributeCommandImpl *>(get());
00561 }
00562 
00563 ElementImpl *RemoveNodeAttributeCommand::element() const
00564 {
00565     IF_IMPL_NULL_RETURN_ARG(0);
00566     return impl()->element();
00567 }
00568 
00569 NodeImpl::Id RemoveNodeAttributeCommand::attribute() const
00570 {
00571     IF_IMPL_NULL_RETURN_ARG(0);
00572     return impl()->attribute();
00573 }
00574 
00575 //------------------------------------------------------------------------------------------
00576 // RemoveNodeCommand
00577 
00578 RemoveNodeCommand::RemoveNodeCommand(DocumentImpl *document, NodeImpl *node)
00579     : EditCommand(new RemoveNodeCommandImpl(document, node))
00580 {
00581 }
00582 
00583 RemoveNodeCommand::~RemoveNodeCommand()
00584 {
00585 }
00586 
00587 RemoveNodeCommandImpl *RemoveNodeCommand::impl() const
00588 {
00589     return static_cast<RemoveNodeCommandImpl *>(get());
00590 }
00591 
00592 NodeImpl *RemoveNodeCommand::node() const
00593 {
00594     IF_IMPL_NULL_RETURN_ARG(0);
00595     return impl()->node();
00596 }
00597 
00598 //------------------------------------------------------------------------------------------
00599 // RemoveNodeAndPruneCommand
00600 
00601 RemoveNodeAndPruneCommand::RemoveNodeAndPruneCommand(DocumentImpl *document, NodeImpl *pruneNode, NodeImpl *stopNode)
00602     : CompositeEditCommand(new RemoveNodeAndPruneCommandImpl(document, pruneNode, stopNode))
00603 {
00604 }
00605 
00606 RemoveNodeAndPruneCommand::~RemoveNodeAndPruneCommand()
00607 {
00608 }
00609 
00610 RemoveNodeAndPruneCommandImpl *RemoveNodeAndPruneCommand::impl() const
00611 {
00612     return static_cast<RemoveNodeAndPruneCommandImpl *>(get());
00613 }
00614 
00615 NodeImpl *RemoveNodeAndPruneCommand::pruneNode() const
00616 {
00617     IF_IMPL_NULL_RETURN_ARG(0);
00618     return impl()->pruneNode();
00619 }
00620 
00621 NodeImpl *RemoveNodeAndPruneCommand::stopNode() const
00622 {
00623     IF_IMPL_NULL_RETURN_ARG(0);
00624     return impl()->stopNode();
00625 }
00626 
00627 //------------------------------------------------------------------------------------------
00628 // RemoveNodePreservingChildrenCommand
00629 
00630 RemoveNodePreservingChildrenCommand::RemoveNodePreservingChildrenCommand(DocumentImpl *document, NodeImpl *node)
00631     : CompositeEditCommand(new RemoveNodePreservingChildrenCommandImpl(document, node))
00632 {
00633 }
00634 
00635 RemoveNodePreservingChildrenCommand::~RemoveNodePreservingChildrenCommand()
00636 {
00637 }
00638 
00639 RemoveNodePreservingChildrenCommandImpl *RemoveNodePreservingChildrenCommand::impl() const
00640 {
00641     return static_cast<RemoveNodePreservingChildrenCommandImpl *>(get());
00642 }
00643 
00644 NodeImpl *RemoveNodePreservingChildrenCommand::node() const
00645 {
00646     IF_IMPL_NULL_RETURN_ARG(0);
00647     return impl()->node();
00648 }
00649 
00650 //------------------------------------------------------------------------------------------
00651 // SetNodeAttributeCommand
00652 
00653 SetNodeAttributeCommand::SetNodeAttributeCommand(DocumentImpl *document, ElementImpl *element, NodeImpl::Id attribute, const DOM::DOMString &value)
00654     : EditCommand(new SetNodeAttributeCommandImpl(document, element, attribute, value))
00655 {
00656 }
00657 
00658 SetNodeAttributeCommand::~SetNodeAttributeCommand()
00659 {
00660 }
00661 
00662 SetNodeAttributeCommandImpl *SetNodeAttributeCommand::impl() const
00663 {
00664     return static_cast<SetNodeAttributeCommandImpl *>(get());
00665 }
00666 
00667 ElementImpl *SetNodeAttributeCommand::element() const
00668 {
00669     IF_IMPL_NULL_RETURN_ARG(0);
00670     return impl()->element();
00671 }
00672 
00673 NodeImpl::Id SetNodeAttributeCommand::attribute() const
00674 {
00675     IF_IMPL_NULL_RETURN_ARG(0);
00676     return impl()->attribute();
00677 }
00678 
00679 DOMString SetNodeAttributeCommand::value() const
00680 {
00681     IF_IMPL_NULL_RETURN_ARG("");
00682     return impl()->value();
00683 }
00684 
00685 //------------------------------------------------------------------------------------------
00686 // SplitTextNodeCommand
00687 
00688 SplitTextNodeCommand::SplitTextNodeCommand(DocumentImpl *document, TextImpl *text, long offset)
00689     : EditCommand(new SplitTextNodeCommandImpl(document, text, offset))
00690 {
00691 }
00692 
00693 SplitTextNodeCommand::~SplitTextNodeCommand()
00694 {
00695 }
00696 
00697 SplitTextNodeCommandImpl *SplitTextNodeCommand::impl() const
00698 {
00699     return static_cast<SplitTextNodeCommandImpl *>(get());
00700 }
00701 
00702 TextImpl *SplitTextNodeCommand::node() const
00703 {
00704     IF_IMPL_NULL_RETURN_ARG(0);
00705     return impl()->node();
00706 }
00707 
00708 long SplitTextNodeCommand::offset() const
00709 {
00710     IF_IMPL_NULL_RETURN_ARG(0);
00711     return impl()->offset();
00712 }
00713 
00714 //------------------------------------------------------------------------------------------
00715 // TypingCommand
00716 
00717 TypingCommand::TypingCommand(DocumentImpl *document) 
00718     : CompositeEditCommand(new TypingCommandImpl(document))
00719 {
00720 }
00721 
00722 TypingCommand::~TypingCommand() 
00723 {
00724 }
00725 
00726 TypingCommandImpl *TypingCommand::impl() const
00727 {
00728     return static_cast<TypingCommandImpl *>(get());
00729 }
00730 
00731 void TypingCommand::insertText(DocumentImpl *document, const DOMString &text)
00732 {
00733     assert(document);
00734     
00735     Editor *ed = document->part()->editor();
00736     assert(ed);
00737     
00738     EditCommand lastEditCommand = ed->lastEditCommand();
00739     if (isOpenForMoreTypingCommand(lastEditCommand)) {
00740         static_cast<TypingCommand &>(lastEditCommand).insertText(text);
00741     }
00742     else {
00743         TypingCommand typingCommand(document);
00744         typingCommand.apply();
00745         typingCommand.insertText(text);
00746     }
00747 }
00748 
00749 void TypingCommand::insertNewline(DocumentImpl *document)
00750 {
00751     assert(document);
00752     
00753     Editor *ed = document->part()->editor();
00754     assert(ed);
00755     
00756     EditCommand lastEditCommand = ed->lastEditCommand();
00757     if (isOpenForMoreTypingCommand(lastEditCommand)) {
00758         static_cast<TypingCommand &>(lastEditCommand).insertNewline();
00759     }
00760     else {
00761         TypingCommand typingCommand(document);
00762         typingCommand.apply();
00763         typingCommand.insertNewline();
00764     }
00765 }
00766 
00767 void TypingCommand::deleteKeyPressed(DocumentImpl *document)
00768 {
00769     assert(document);
00770     
00771     Editor *ed = document->part()->editor();
00772     assert(ed);
00773     
00774     EditCommand lastEditCommand = ed->lastEditCommand();
00775     if (isOpenForMoreTypingCommand(lastEditCommand)) {
00776         static_cast<TypingCommand &>(lastEditCommand).deleteKeyPressed();
00777     }
00778     else {
00779         TypingCommand typingCommand(document);
00780         typingCommand.apply();
00781         typingCommand.deleteKeyPressed();
00782     }
00783 }
00784 
00785 bool TypingCommand::isOpenForMoreTypingCommand(const EditCommand &cmd)
00786 {
00787     return cmd.commandID() == TypingCommandID && 
00788         static_cast<const TypingCommand &>(cmd).openForMoreTyping();
00789 }
00790 
00791 void TypingCommand::closeTyping(EditCommand cmd)
00792 {
00793     if (isOpenForMoreTypingCommand(cmd))
00794         static_cast<TypingCommand &>(cmd).closeTyping();
00795 }
00796 
00797 void TypingCommand::closeTyping()
00798 {
00799     IF_IMPL_NULL_RETURN;
00800     return impl()->closeTyping();
00801 }
00802 
00803 bool TypingCommand::openForMoreTyping() const
00804 {
00805     IF_IMPL_NULL_RETURN_ARG(false);
00806     return impl()->openForMoreTyping();
00807 }
00808 
00809 void TypingCommand::insertText(const DOMString &text)
00810 {
00811     IF_IMPL_NULL_RETURN;
00812     return impl()->insertText(text);
00813 }
00814 
00815 void TypingCommand::insertNewline()
00816 {
00817     IF_IMPL_NULL_RETURN;
00818     return impl()->insertNewline();
00819 }
00820 
00821 void TypingCommand::deleteKeyPressed()
00822 {
00823     IF_IMPL_NULL_RETURN;
00824     return impl()->deleteKeyPressed();
00825 }
00826 
00827 } // namespace khtml

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal