• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KHTML

jsediting.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 "jsediting.h"
00027 #include "editing/htmlediting_impl.h"
00028 #include "editor.h"
00029 
00030 #include "css/cssproperties.h"
00031 #include "css/cssvalues.h"
00032 #include "css/css_valueimpl.h"
00033 #include "xml/dom_selection.h"
00034 #include "xml/dom_docimpl.h"
00035 #include "dom/dom_string.h"
00036 
00037 #include "misc/khtml_partaccessor.h"
00038 
00039 #include <QHash>
00040 #include <QString>
00041 
00042 using khtml::TypingCommandImpl;
00043 using khtml::InsertListCommandImpl;
00044 //
00045 #define KPAC khtml::KHTMLPartAccessor
00046 
00047 #define DEBUG_COMMANDS
00048 
00049 namespace DOM {
00050 
00051 class DocumentImpl;
00052 
00053 struct CommandImp {
00054     bool (*execFn)(KHTMLPart *part, bool userInterface, const DOMString &value);
00055     bool (*enabledFn)(KHTMLPart *part);
00056     Editor::TriState (*stateFn)(KHTMLPart *part);
00057     DOMString (*valueFn)(KHTMLPart *part);
00058 };
00059 
00060 typedef QHash<QString,const CommandImp*> CommandDict;
00061 static CommandDict createCommandDictionary();
00062 
00063 bool JSEditor::execCommand(const CommandImp *cmd, bool userInterface, const DOMString &value)
00064 {
00065     if (!cmd || !cmd->enabledFn)
00066         return false;
00067     KHTMLPart *part = m_doc->part();
00068     if (!part)
00069         return false;
00070     m_doc->updateLayout();
00071     return cmd->enabledFn(part) && cmd->execFn(part, userInterface, value);
00072 }
00073 
00074 bool JSEditor::queryCommandEnabled(const CommandImp *cmd)
00075 {
00076     if (!cmd || !cmd->enabledFn)
00077         return false;
00078     KHTMLPart *part = m_doc->part();
00079     if (!part)
00080         return false;
00081     m_doc->updateLayout();
00082     return cmd->enabledFn(part);
00083 }
00084 
00085 bool JSEditor::queryCommandIndeterm(const CommandImp *cmd)
00086 {
00087     if (!cmd || !cmd->enabledFn)
00088         return false;
00089     KHTMLPart *part = m_doc->part();
00090     if (!part)
00091         return false;
00092     m_doc->updateLayout();
00093     return cmd->stateFn(part) == Editor::MixedTriState;
00094 }
00095 
00096 bool JSEditor::queryCommandState(const CommandImp *cmd)
00097 {
00098     if (!cmd || !cmd->enabledFn)
00099         return false;
00100     KHTMLPart *part = m_doc->part();
00101     if (!part)
00102         return false;
00103     m_doc->updateLayout();
00104     return cmd->stateFn(part) != Editor::FalseTriState;
00105 }
00106 
00107 bool JSEditor::queryCommandSupported(const CommandImp *cmd)
00108 {
00109     return cmd != 0;
00110 }
00111 
00112 DOMString JSEditor::queryCommandValue(const CommandImp *cmd)
00113 {
00114     if (!cmd || !cmd->enabledFn)
00115         return DOMString();
00116     KHTMLPart *part = m_doc->part();
00117     if (!part)
00118         return DOMString();
00119     m_doc->updateLayout();
00120     return cmd->valueFn(part);
00121 }
00122 
00123 // =============================================================================================
00124 
00125 // Private stuff
00126 
00127 static bool execStyleChange(KHTMLPart *part, int propertyID, const DOMString &propertyValue)
00128 {
00129     CSSStyleDeclarationImpl *style = new CSSStyleDeclarationImpl(0);
00130     style->setProperty(propertyID, propertyValue);
00131     style->ref();
00132     part->editor()->applyStyle(style);
00133     style->deref();
00134     return true;
00135 }
00136 
00137 static bool execStyleChange(KHTMLPart *part, int propertyID, int propertyEnum)
00138 {
00139     CSSStyleDeclarationImpl *style = new CSSStyleDeclarationImpl(0);
00140     style->setProperty(propertyID, propertyEnum);
00141     style->ref();
00142     part->editor()->applyStyle(style);
00143     style->deref();
00144     return true;
00145 }
00146 
00147 static bool execStyleChange(KHTMLPart *part, int propertyID, const char *propertyValue)
00148 {
00149     return execStyleChange(part, propertyID, DOMString(propertyValue));
00150 }
00151 
00152 static Editor::TriState stateStyle(KHTMLPart *part, int propertyID, const char *desiredValue)
00153 {
00154     CSSStyleDeclarationImpl *style = new CSSStyleDeclarationImpl(0);
00155     style->setProperty(propertyID, desiredValue);
00156     style->ref();
00157     Editor::TriState state = part->editor()->selectionHasStyle(style);
00158     style->deref();
00159     return state;
00160 }
00161 
00162 static bool selectionStartHasStyle(KHTMLPart *part, int propertyID, const char *desiredValue)
00163 {
00164     CSSStyleDeclarationImpl *style = new CSSStyleDeclarationImpl(0);
00165     style->setProperty(propertyID, desiredValue);
00166     style->ref();
00167     bool hasStyle = part->editor()->selectionStartHasStyle(style);
00168     style->deref();
00169     return hasStyle;
00170 }
00171 
00172 static DOMString valueStyle(KHTMLPart *part, int propertyID)
00173 {
00174     return part->editor()->selectionStartStylePropertyValue(propertyID);
00175 }
00176 
00177 // =============================================================================================
00178 //
00179 // execCommand implementations
00180 //
00181 
00182 static bool execBackColor(KHTMLPart *part, bool /*userInterface*/, const DOMString &value)
00183 {
00184     return execStyleChange(part, CSS_PROP_BACKGROUND_COLOR, value);
00185 }
00186 
00187 static bool execBold(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00188 {
00189     bool isBold = selectionStartHasStyle(part, CSS_PROP_FONT_WEIGHT, "bold");
00190     return execStyleChange(part, CSS_PROP_FONT_WEIGHT, isBold ? "normal" : "bold");
00191 }
00192 
00193 static bool execCopy(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00194 {
00195     part->editor()->copy();
00196     return true;
00197 }
00198 
00199 static bool execCut(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00200 {
00201     part->editor()->cut();
00202     return true;
00203 }
00204 
00205 static bool execDelete(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00206 {
00207     TypingCommandImpl::deleteKeyPressed0(KPAC::xmlDocImpl(part));
00208     return true;
00209 }
00210 
00211 static bool execFontName(KHTMLPart *part, bool /*userInterface*/, const DOMString &value)
00212 {
00213     return execStyleChange(part, CSS_PROP_FONT_FAMILY, value);
00214 }
00215 
00216 static bool execFontSize(KHTMLPart *part, bool /*userInterface*/, const DOMString &value)
00217 {
00218     // This should handle sizes 1-7 like <font> does. Who the heck designed this interface? (Rhetorical question)
00219     bool ok;
00220     int val = value.string().toInt(&ok);
00221     if (ok && val >= 1 && val <= 7) {
00222         int size;
00223         switch (val) {
00224         case 1: size = CSS_VAL_XX_SMALL; break;
00225         case 2: size = CSS_VAL_SMALL; break;
00226         case 3: size = CSS_VAL_MEDIUM; break;
00227         case 4: size = CSS_VAL_LARGE; break;
00228         case 5: size = CSS_VAL_X_LARGE;  break;
00229         case 6: size = CSS_VAL_XX_LARGE; break;
00230         default: size = CSS_VAL__KHTML_XXX_LARGE;
00231         }
00232         return execStyleChange(part, CSS_PROP_FONT_SIZE, size);
00233     }
00234     
00235     return execStyleChange(part, CSS_PROP_FONT_SIZE, value);
00236 }
00237 
00238 static bool execForeColor(KHTMLPart *part, bool /*userInterface*/, const DOMString &value)
00239 {
00240     return execStyleChange(part, CSS_PROP_COLOR, value);
00241 }
00242 
00243 static bool execIndent(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00244 {
00245     part->editor()->indent();
00246     return true;
00247 }
00248 
00249 static bool execInsertNewline(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00250 {
00251     TypingCommandImpl::insertNewline0(KPAC::xmlDocImpl(part));
00252     return true;
00253 }
00254 
00255 static bool execInsertParagraph(KHTMLPart * /*part*/, bool /*userInterface*/, const DOMString &/*value*/)
00256 {
00257     // FIXME: Implement.
00258     return false;
00259 }
00260 
00261 static bool execInsertText(KHTMLPart *part, bool /*userInterface*/, const DOMString &value)
00262 {
00263     TypingCommandImpl::insertText0(KPAC::xmlDocImpl(part), value);
00264     return true;
00265 }
00266 
00267 static bool execInsertOrderedList(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00268 {
00269     InsertListCommandImpl::insertList(KPAC::xmlDocImpl(part), InsertListCommandImpl::OrderedList);
00270     return true;
00271 }
00272 
00273 static bool execInsertUnorderedList(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00274 {
00275     InsertListCommandImpl::insertList(KPAC::xmlDocImpl(part), InsertListCommandImpl::UnorderedList);
00276     return true;
00277 }
00278 
00279 static bool execItalic(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00280 {
00281     bool isItalic = selectionStartHasStyle(part, CSS_PROP_FONT_STYLE, "italic");
00282     return execStyleChange(part, CSS_PROP_FONT_STYLE, isItalic ? "normal" : "italic");
00283 }
00284 
00285 static bool execJustifyCenter(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00286 {
00287     return execStyleChange(part, CSS_PROP_TEXT_ALIGN, "center");
00288 }
00289 
00290 static bool execJustifyFull(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00291 {
00292     return execStyleChange(part, CSS_PROP_TEXT_ALIGN, "justify");
00293 }
00294 
00295 static bool execJustifyLeft(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00296 {
00297     return execStyleChange(part, CSS_PROP_TEXT_ALIGN, "left");
00298 }
00299 
00300 static bool execJustifyRight(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00301 {
00302     return execStyleChange(part, CSS_PROP_TEXT_ALIGN, "right");
00303 }
00304 
00305 static bool execOutdent(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00306 {
00307     part->editor()->outdent();
00308     return true;
00309 }
00310 
00311 #ifndef NO_SUPPORT_PASTE
00312 
00313 static bool execPaste(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00314 {
00315     part->editor()->paste();
00316     return true;
00317 }
00318 
00319 #endif
00320 
00321 static bool execPrint(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00322 {
00323     part->editor()->print();
00324     return true;
00325 }
00326 
00327 static bool execRedo(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00328 {
00329     part->editor()->redo();
00330     return true;
00331 }
00332 
00333 static bool execSelectAll(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00334 {
00335     part->selectAll();
00336     return true;
00337 }
00338 
00339 static bool execStrikeThrough(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00340 {
00341     bool isStriked = selectionStartHasStyle(part, CSS_PROP_TEXT_DECORATION, "line-through");
00342     return execStyleChange(part, CSS_PROP_TEXT_DECORATION, isStriked ? "none" : "line-through");
00343 }
00344 
00345 static bool execSubscript(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00346 {
00347     return execStyleChange(part, CSS_PROP_VERTICAL_ALIGN, "sub");
00348 }
00349 
00350 static bool execSuperscript(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00351 {
00352     return execStyleChange(part, CSS_PROP_VERTICAL_ALIGN, "super");
00353 }
00354 
00355 static bool execUndo(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00356 {
00357     part->editor()->undo();
00358     return true;
00359 }
00360 
00361 static bool execUnderline(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00362 {
00363     bool isUnderline = selectionStartHasStyle(part, CSS_PROP_TEXT_DECORATION, "underline");
00364     return execStyleChange(part, CSS_PROP_TEXT_DECORATION, isUnderline ? "none" : "underline");
00365 }
00366 
00367 static bool execUnselect(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
00368 {
00369     KPAC::clearSelection(part);
00370     return true;
00371 }
00372 
00373 // =============================================================================================
00374 //
00375 // queryCommandEnabled implementations
00376 //
00377 // It's a bit difficult to get a clear notion of the difference between
00378 // "supported" and "enabled" from reading the Microsoft documentation, but
00379 // what little I could glean from that seems to make some sense.
00380 //     Supported = The command is supported by this object.
00381 //     Enabled =   The command is available and enabled.
00382 
00383 static bool enabled(KHTMLPart * /*part*/)
00384 {
00385     return true;
00386 }
00387 
00388 static bool enabledAnySelection(KHTMLPart *part)
00389 {
00390     return KPAC::caret(part).notEmpty();
00391 }
00392 
00393 #ifndef NO_SUPPORT_PASTE
00394 
00395 static bool enabledPaste(KHTMLPart *part)
00396 {
00397     return part->editor()->canPaste();
00398 }
00399 
00400 #endif
00401 
00402 static bool enabledRangeSelection(KHTMLPart *part)
00403 {
00404     return KPAC::caret(part).state() == Selection::RANGE;
00405 }
00406 
00407 static bool enabledRedo(KHTMLPart *part)
00408 {
00409     return part->editor()->canRedo();
00410 }
00411 
00412 static bool enabledUndo(KHTMLPart *part)
00413 {
00414     return part->editor()->canUndo();
00415 }
00416 
00417 // =============================================================================================
00418 //
00419 // queryCommandIndeterm/State implementations
00420 //
00421 // It's a bit difficult to get a clear notion of what these methods are supposed
00422 // to do from reading the Microsoft documentation, but my current guess is this:
00423 //
00424 //     queryCommandState and queryCommandIndeterm work in concert to return
00425 //     the two bits of information that are needed to tell, for instance,
00426 //     if the text of a selection is bold. The answer can be "yes", "no", or
00427 //     "partially".
00428 //
00429 // If this is so, then queryCommandState should return "yes" in the case where
00430 // all the text is bold and "no" for non-bold or partially-bold text.
00431 // Then, queryCommandIndeterm should return "no" in the case where
00432 // all the text is either all bold or not-bold and and "yes" for partially-bold text.
00433 
00434 static Editor::TriState stateNone(KHTMLPart * /*part*/)
00435 {
00436     return Editor::FalseTriState;
00437 }
00438 
00439 static Editor::TriState stateBold(KHTMLPart *part)
00440 {
00441     return stateStyle(part, CSS_PROP_FONT_WEIGHT, "bold");
00442 }
00443 
00444 static Editor::TriState stateItalic(KHTMLPart *part)
00445 {
00446     return stateStyle(part, CSS_PROP_FONT_STYLE, "italic");
00447 }
00448 
00449 static Editor::TriState stateStrike(KHTMLPart *part)
00450 {
00451     return stateStyle(part, CSS_PROP_TEXT_DECORATION, "line-through");
00452 }
00453 
00454 static Editor::TriState stateSubscript(KHTMLPart *part)
00455 {
00456     return stateStyle(part, CSS_PROP_VERTICAL_ALIGN, "sub");
00457 }
00458 
00459 static Editor::TriState stateSuperscript(KHTMLPart *part)
00460 {
00461     return stateStyle(part, CSS_PROP_VERTICAL_ALIGN, "super");
00462 }
00463 
00464 static Editor::TriState stateUnderline(KHTMLPart *part)
00465 {
00466     return stateStyle(part, CSS_PROP_TEXT_DECORATION, "underline");
00467 }
00468 
00469 // =============================================================================================
00470 //
00471 // queryCommandValue implementations
00472 //
00473 
00474 static DOMString valueNull(KHTMLPart * /*part*/)
00475 {
00476     return DOMString();
00477 }
00478 
00479 static DOMString valueBackColor(KHTMLPart *part)
00480 {
00481     return valueStyle(part, CSS_PROP_BACKGROUND_COLOR);
00482 }
00483 
00484 static DOMString valueFontName(KHTMLPart *part)
00485 {
00486     return valueStyle(part, CSS_PROP_FONT_FAMILY);
00487 }
00488 
00489 static DOMString valueFontSize(KHTMLPart *part)
00490 {
00491     return valueStyle(part, CSS_PROP_FONT_SIZE);
00492 }
00493 
00494 static DOMString valueForeColor(KHTMLPart *part)
00495 {
00496     return valueStyle(part, CSS_PROP_COLOR);
00497 }
00498 
00499 // =============================================================================================
00500 
00501 struct EditorCommandInfo { const char *name; CommandImp imp; };
00502 
00503 // NOTE: strictly keep in sync with EditorCommand in editor_command.h
00504 static const EditorCommandInfo commands[] = {
00505 
00506     { "backColor", { execBackColor, enabled, stateNone, valueBackColor } },
00507     { "bold", { execBold, enabledAnySelection, stateBold, valueNull } },
00508     { "copy", { execCopy, enabledRangeSelection, stateNone, valueNull } },
00509     { "cut", { execCut, enabledRangeSelection, stateNone, valueNull } },
00510     { "delete", { execDelete, enabledAnySelection, stateNone, valueNull } },
00511     { "fontName", { execFontName, enabledAnySelection, stateNone, valueFontName } },
00512     { "fontSize", { execFontSize, enabledAnySelection, stateNone, valueFontSize } },
00513     { "foreColor", { execForeColor, enabledAnySelection, stateNone, valueForeColor } },
00514     { "indent", { execIndent, enabledAnySelection, stateNone, valueNull } },
00515     { "insertNewline", { execInsertNewline, enabledAnySelection, stateNone, valueNull } },
00516     { "insertOrderedList", { execInsertOrderedList, enabledAnySelection, stateNone, valueNull } },
00517     { "insertParagraph", { execInsertParagraph, enabledAnySelection, stateNone, valueNull } },
00518     { "insertText", { execInsertText, enabledAnySelection, stateNone, valueNull } },
00519     { "insertUnorderedList", { execInsertUnorderedList, enabledAnySelection, stateNone, valueNull } },
00520     { "italic", { execItalic, enabledAnySelection, stateItalic, valueNull } },
00521     { "justifyCenter", { execJustifyCenter, enabledAnySelection, stateNone, valueNull } },
00522     { "justifyFull", { execJustifyFull, enabledAnySelection, stateNone, valueNull } },
00523     { "justifyLeft", { execJustifyLeft, enabledAnySelection, stateNone, valueNull } },
00524     { "justifyNone", { execJustifyLeft, enabledAnySelection, stateNone, valueNull } },
00525     { "justifyRight", { execJustifyRight, enabledAnySelection, stateNone, valueNull } },
00526     { "outdent", { execOutdent, enabledAnySelection, stateNone, valueNull } },
00527 #ifndef NO_SUPPORT_PASTE
00528     { "paste", { execPaste, enabledPaste, stateNone, valueNull } },
00529 #else
00530     { 0, { 0, 0, 0, 0 } },
00531 #endif
00532     { "print", { execPrint, enabled, stateNone, valueNull } },
00533     { "redo", { execRedo, enabledRedo, stateNone, valueNull } },
00534     { "selectAll", { execSelectAll, enabled, stateNone, valueNull } },
00535     { "StrikeThrough", {execStrikeThrough, enabled, stateStrike, valueNull } },
00536     { "subscript", { execSubscript, enabledAnySelection, stateSubscript, valueNull } },
00537     { "superscript", { execSuperscript, enabledAnySelection, stateSuperscript, valueNull } },
00538     { "underline", { execUnderline, enabledAnySelection, stateUnderline, valueNull } },
00539     { "undo", { execUndo, enabledUndo, stateNone, valueNull } },
00540     { "unselect", { execUnselect, enabledAnySelection, stateNone, valueNull } }
00541 
00542     //
00543     // The "unsupported" commands are listed here since they appear in the Microsoft
00544     // documentation used as the basis for the list.
00545     //
00546 
00547     // 2d-position (not supported)
00548     // absolutePosition (not supported)
00549     // blockDirLTR (not supported)
00550     // blockDirRTL (not supported)
00551     // browseMode (not supported)
00552     // clearAuthenticationCache (not supported)
00553     // createBookmark (not supported)
00554     // createLink (not supported)
00555     // dirLTR (not supported)
00556     // dirRTL (not supported)
00557     // editMode (not supported)
00558     // formatBlock (not supported)
00559     // inlineDirLTR (not supported)
00560     // inlineDirRTL (not supported)
00561     // insertButton (not supported)
00562     // insertFieldSet (not supported)
00563     // insertHorizontalRule (not supported)
00564     // insertIFrame (not supported)
00565     // insertImage (not supported)
00566     // insertInputButton (not supported)
00567     // insertInputCheckbox (not supported)
00568     // insertInputFileUpload (not supported)
00569     // insertInputHidden (not supported)
00570     // insertInputImage (not supported)
00571     // insertInputPassword (not supported)
00572     // insertInputRadio (not supported)
00573     // insertInputReset (not supported)
00574     // insertInputSubmit (not supported)
00575     // insertInputText (not supported)
00576     // insertMarquee (not supported)
00577     // insertOrderedList (not supported)
00578     // insertSelectDropDown (not supported)
00579     // insertSelectListBox (not supported)
00580     // insertTextArea (not supported)
00581     // insertUnorderedList (not supported)
00582     // liveResize (not supported)
00583     // multipleSelection (not supported)
00584     // open (not supported)
00585     // overwrite (not supported)
00586     // playImage (not supported)
00587     // refresh (not supported)
00588     // removeFormat (not supported)
00589     // removeParaFormat (not supported)
00590     // saveAs (not supported)
00591     // sizeToControl (not supported)
00592     // sizeToControlHeight (not supported)
00593     // sizeToControlWidth (not supported)
00594     // stop (not supported)
00595     // stopimage (not supported)
00596     // strikethrough (not supported)
00597     // unbookmark (not supported)
00598     // underline (not supported)
00599     // unlink (not supported)
00600 };
00601 
00602 static CommandDict createCommandDictionary()
00603 {
00604     const int numCommands = sizeof(commands) / sizeof(commands[0]);
00605     CommandDict commandDictionary; // case-insensitive dictionary
00606     for (int i = 0; i < numCommands; ++i) {
00607         if (commands[i].name)
00608             commandDictionary.insert(QString(commands[i].name).toLower(), &commands[i].imp);
00609     }
00610     return commandDictionary;
00611 }
00612 
00613 const CommandImp *JSEditor::commandImp(const DOMString &command)
00614 {
00615     static CommandDict commandDictionary = createCommandDictionary();
00616     CommandDict::const_iterator it = commandDictionary.constFind(command.string().toLower());
00617     const CommandImp *result = commandDictionary.value( command.string().toLower() );
00618 #ifdef DEBUG_COMMANDS
00619     if (!result)
00620         kDebug() << "[Command is not supported yet]" << command << endl;
00621 #endif
00622     return result;
00623 }
00624 
00625 const CommandImp *JSEditor::commandImp(int command)
00626 {
00627     if (command < 0 || command >= int(sizeof commands / sizeof commands[0]) )
00628         return 0;
00629     return &commands[command].imp;
00630 }
00631 
00632 
00633 
00634 } // namespace DOM
00635 
00636 #undef KPAC

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
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
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