File: jsediting.cpp

package info (click to toggle)
khtml 5.54.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 18,940 kB
  • sloc: cpp: 206,281; java: 4,060; ansic: 2,829; perl: 2,313; yacc: 1,497; python: 339; sh: 141; xml: 37; makefile: 7
file content (650 lines) | stat: -rw-r--r-- 21,053 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
/*
 * Copyright (C) 2004 Apple Computer, Inc.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "jsediting.h"
#include "editing/htmlediting_impl.h"
#include "editor.h"

#include "css/cssproperties.h"
#include "css/cssvalues.h"
#include "css/css_valueimpl.h"
#include "xml/dom_selection.h"
#include "xml/dom_docimpl.h"
#include "dom/dom_string.h"

#include "misc/khtml_partaccessor.h"

#include <QHash>
#include <QString>

using khtml::TypingCommandImpl;
using khtml::InsertListCommandImpl;
//
#define KPAC khtml::KHTMLPartAccessor

#define DEBUG_COMMANDS

namespace DOM
{

class DocumentImpl;

struct CommandImp {
    bool (*execFn)(KHTMLPart *part, bool userInterface, const DOMString &value);
    bool (*enabledFn)(KHTMLPart *part);
    Editor::TriState(*stateFn)(KHTMLPart *part);
    DOMString(*valueFn)(KHTMLPart *part);
};

typedef QHash<QString, const CommandImp *> CommandDict;
static CommandDict createCommandDictionary();

bool JSEditor::execCommand(const CommandImp *cmd, bool userInterface, const DOMString &value)
{
    if (!cmd || !cmd->enabledFn) {
        return false;
    }
    KHTMLPart *part = m_doc->part();
    if (!part) {
        return false;
    }
    m_doc->updateLayout();
    return cmd->enabledFn(part) && cmd->execFn(part, userInterface, value);
}

bool JSEditor::queryCommandEnabled(const CommandImp *cmd)
{
    if (!cmd || !cmd->enabledFn) {
        return false;
    }
    KHTMLPart *part = m_doc->part();
    if (!part) {
        return false;
    }
    m_doc->updateLayout();
    return cmd->enabledFn(part);
}

bool JSEditor::queryCommandIndeterm(const CommandImp *cmd)
{
    if (!cmd || !cmd->enabledFn) {
        return false;
    }
    KHTMLPart *part = m_doc->part();
    if (!part) {
        return false;
    }
    m_doc->updateLayout();
    return cmd->stateFn(part) == Editor::MixedTriState;
}

bool JSEditor::queryCommandState(const CommandImp *cmd)
{
    if (!cmd || !cmd->enabledFn) {
        return false;
    }
    KHTMLPart *part = m_doc->part();
    if (!part) {
        return false;
    }
    m_doc->updateLayout();
    return cmd->stateFn(part) != Editor::FalseTriState;
}

bool JSEditor::queryCommandSupported(const CommandImp *cmd)
{
    return cmd != nullptr;
}

DOMString JSEditor::queryCommandValue(const CommandImp *cmd)
{
    if (!cmd || !cmd->enabledFn) {
        return DOMString();
    }
    KHTMLPart *part = m_doc->part();
    if (!part) {
        return DOMString();
    }
    m_doc->updateLayout();
    return cmd->valueFn(part);
}

// =============================================================================================

// Private stuff

static bool execStyleChange(KHTMLPart *part, int propertyID, const DOMString &propertyValue)
{
    CSSStyleDeclarationImpl *style = new CSSStyleDeclarationImpl(nullptr);
    style->setProperty(propertyID, propertyValue);
    style->ref();
    part->editor()->applyStyle(style);
    style->deref();
    return true;
}

static bool execStyleChange(KHTMLPart *part, int propertyID, int propertyEnum)
{
    CSSStyleDeclarationImpl *style = new CSSStyleDeclarationImpl(nullptr);
    style->setProperty(propertyID, propertyEnum);
    style->ref();
    part->editor()->applyStyle(style);
    style->deref();
    return true;
}

static bool execStyleChange(KHTMLPart *part, int propertyID, const char *propertyValue)
{
    return execStyleChange(part, propertyID, DOMString(propertyValue));
}

static Editor::TriState stateStyle(KHTMLPart *part, int propertyID, const char *desiredValue)
{
    CSSStyleDeclarationImpl *style = new CSSStyleDeclarationImpl(nullptr);
    style->setProperty(propertyID, desiredValue);
    style->ref();
    Editor::TriState state = part->editor()->selectionHasStyle(style);
    style->deref();
    return state;
}

static bool selectionStartHasStyle(KHTMLPart *part, int propertyID, const char *desiredValue)
{
    CSSStyleDeclarationImpl *style = new CSSStyleDeclarationImpl(nullptr);
    style->setProperty(propertyID, desiredValue);
    style->ref();
    bool hasStyle = part->editor()->selectionStartHasStyle(style);
    style->deref();
    return hasStyle;
}

static DOMString valueStyle(KHTMLPart *part, int propertyID)
{
    return part->editor()->selectionStartStylePropertyValue(propertyID);
}

// =============================================================================================
//
// execCommand implementations
//

static bool execBackColor(KHTMLPart *part, bool /*userInterface*/, const DOMString &value)
{
    return execStyleChange(part, CSS_PROP_BACKGROUND_COLOR, value);
}

static bool execBold(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    bool isBold = selectionStartHasStyle(part, CSS_PROP_FONT_WEIGHT, "bold");
    return execStyleChange(part, CSS_PROP_FONT_WEIGHT, isBold ? "normal" : "bold");
}

static bool execCopy(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    part->editor()->copy();
    return true;
}

static bool execCut(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    part->editor()->cut();
    return true;
}

static bool execDelete(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    TypingCommandImpl::deleteKeyPressed0(KPAC::xmlDocImpl(part));
    return true;
}

static bool execFontName(KHTMLPart *part, bool /*userInterface*/, const DOMString &value)
{
    return execStyleChange(part, CSS_PROP_FONT_FAMILY, value);
}

static bool execFontSize(KHTMLPart *part, bool /*userInterface*/, const DOMString &value)
{
    // This should handle sizes 1-7 like <font> does. Who the heck designed this interface? (Rhetorical question)
    bool ok;
    int val = value.string().toInt(&ok);
    if (ok && val >= 1 && val <= 7) {
        int size;
        switch (val) {
        case 1: size = CSS_VAL_XX_SMALL; break;
        case 2: size = CSS_VAL_SMALL; break;
        case 3: size = CSS_VAL_MEDIUM; break;
        case 4: size = CSS_VAL_LARGE; break;
        case 5: size = CSS_VAL_X_LARGE;  break;
        case 6: size = CSS_VAL_XX_LARGE; break;
        default: size = CSS_VAL__KHTML_XXX_LARGE;
        }
        return execStyleChange(part, CSS_PROP_FONT_SIZE, size);
    }

    return execStyleChange(part, CSS_PROP_FONT_SIZE, value);
}

static bool execForeColor(KHTMLPart *part, bool /*userInterface*/, const DOMString &value)
{
    return execStyleChange(part, CSS_PROP_COLOR, value);
}

static bool execIndent(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    part->editor()->indent();
    return true;
}

static bool execInsertNewline(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    TypingCommandImpl::insertNewline0(KPAC::xmlDocImpl(part));
    return true;
}

static bool execInsertParagraph(KHTMLPart * /*part*/, bool /*userInterface*/, const DOMString &/*value*/)
{
    // FIXME: Implement.
    return false;
}

static bool execInsertText(KHTMLPart *part, bool /*userInterface*/, const DOMString &value)
{
    TypingCommandImpl::insertText0(KPAC::xmlDocImpl(part), value);
    return true;
}

static bool execInsertOrderedList(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    InsertListCommandImpl::insertList(KPAC::xmlDocImpl(part), InsertListCommandImpl::OrderedList);
    return true;
}

static bool execInsertUnorderedList(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    InsertListCommandImpl::insertList(KPAC::xmlDocImpl(part), InsertListCommandImpl::UnorderedList);
    return true;
}

static bool execItalic(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    bool isItalic = selectionStartHasStyle(part, CSS_PROP_FONT_STYLE, "italic");
    return execStyleChange(part, CSS_PROP_FONT_STYLE, isItalic ? "normal" : "italic");
}

static bool execJustifyCenter(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    return execStyleChange(part, CSS_PROP_TEXT_ALIGN, "center");
}

static bool execJustifyFull(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    return execStyleChange(part, CSS_PROP_TEXT_ALIGN, "justify");
}

static bool execJustifyLeft(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    return execStyleChange(part, CSS_PROP_TEXT_ALIGN, "left");
}

static bool execJustifyRight(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    return execStyleChange(part, CSS_PROP_TEXT_ALIGN, "right");
}

static bool execOutdent(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    part->editor()->outdent();
    return true;
}

#ifndef NO_SUPPORT_PASTE

static bool execPaste(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    part->editor()->paste();
    return true;
}

#endif

static bool execPrint(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    part->editor()->print();
    return true;
}

static bool execRedo(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    part->editor()->redo();
    return true;
}

static bool execSelectAll(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    part->selectAll();
    return true;
}

static bool execStrikeThrough(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    bool isStriked = selectionStartHasStyle(part, CSS_PROP_TEXT_DECORATION, "line-through");
    return execStyleChange(part, CSS_PROP_TEXT_DECORATION, isStriked ? "none" : "line-through");
}

static bool execSubscript(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    return execStyleChange(part, CSS_PROP_VERTICAL_ALIGN, "sub");
}

static bool execSuperscript(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    return execStyleChange(part, CSS_PROP_VERTICAL_ALIGN, "super");
}

static bool execUndo(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    part->editor()->undo();
    return true;
}

static bool execUnderline(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    bool isUnderline = selectionStartHasStyle(part, CSS_PROP_TEXT_DECORATION, "underline");
    return execStyleChange(part, CSS_PROP_TEXT_DECORATION, isUnderline ? "none" : "underline");
}

static bool execUnselect(KHTMLPart *part, bool /*userInterface*/, const DOMString &/*value*/)
{
    KPAC::clearSelection(part);
    return true;
}

// =============================================================================================
//
// queryCommandEnabled implementations
//
// It's a bit difficult to get a clear notion of the difference between
// "supported" and "enabled" from reading the Microsoft documentation, but
// what little I could glean from that seems to make some sense.
//     Supported = The command is supported by this object.
//     Enabled =   The command is available and enabled.

static bool enabled(KHTMLPart * /*part*/)
{
    return true;
}

static bool enabledAnySelection(KHTMLPart *part)
{
    return KPAC::caret(part).notEmpty();
}

#ifndef NO_SUPPORT_PASTE

static bool enabledPaste(KHTMLPart *part)
{
    return part->editor()->canPaste();
}

#endif

static bool enabledRangeSelection(KHTMLPart *part)
{
    return KPAC::caret(part).state() == Selection::RANGE;
}

static bool enabledRedo(KHTMLPart *part)
{
    return part->editor()->canRedo();
}

static bool enabledUndo(KHTMLPart *part)
{
    return part->editor()->canUndo();
}

// =============================================================================================
//
// queryCommandIndeterm/State implementations
//
// It's a bit difficult to get a clear notion of what these methods are supposed
// to do from reading the Microsoft documentation, but my current guess is this:
//
//     queryCommandState and queryCommandIndeterm work in concert to return
//     the two bits of information that are needed to tell, for instance,
//     if the text of a selection is bold. The answer can be "yes", "no", or
//     "partially".
//
// If this is so, then queryCommandState should return "yes" in the case where
// all the text is bold and "no" for non-bold or partially-bold text.
// Then, queryCommandIndeterm should return "no" in the case where
// all the text is either all bold or not-bold and and "yes" for partially-bold text.

static Editor::TriState stateNone(KHTMLPart * /*part*/)
{
    return Editor::FalseTriState;
}

static Editor::TriState stateBold(KHTMLPart *part)
{
    return stateStyle(part, CSS_PROP_FONT_WEIGHT, "bold");
}

static Editor::TriState stateItalic(KHTMLPart *part)
{
    return stateStyle(part, CSS_PROP_FONT_STYLE, "italic");
}

static Editor::TriState stateStrike(KHTMLPart *part)
{
    return stateStyle(part, CSS_PROP_TEXT_DECORATION, "line-through");
}

static Editor::TriState stateSubscript(KHTMLPart *part)
{
    return stateStyle(part, CSS_PROP_VERTICAL_ALIGN, "sub");
}

static Editor::TriState stateSuperscript(KHTMLPart *part)
{
    return stateStyle(part, CSS_PROP_VERTICAL_ALIGN, "super");
}

static Editor::TriState stateUnderline(KHTMLPart *part)
{
    return stateStyle(part, CSS_PROP_TEXT_DECORATION, "underline");
}

// =============================================================================================
//
// queryCommandValue implementations
//

static DOMString valueNull(KHTMLPart * /*part*/)
{
    return DOMString();
}

static DOMString valueBackColor(KHTMLPart *part)
{
    return valueStyle(part, CSS_PROP_BACKGROUND_COLOR);
}

static DOMString valueFontName(KHTMLPart *part)
{
    return valueStyle(part, CSS_PROP_FONT_FAMILY);
}

static DOMString valueFontSize(KHTMLPart *part)
{
    return valueStyle(part, CSS_PROP_FONT_SIZE);
}

static DOMString valueForeColor(KHTMLPart *part)
{
    return valueStyle(part, CSS_PROP_COLOR);
}

// =============================================================================================

struct EditorCommandInfo {
    const char *name;
    CommandImp imp;
};

// NOTE: strictly keep in sync with EditorCommand in editor_command.h
static const EditorCommandInfo commands[] = {

    { "backColor", { execBackColor, enabled, stateNone, valueBackColor } },
    { "bold", { execBold, enabledAnySelection, stateBold, valueNull } },
    { "copy", { execCopy, enabledRangeSelection, stateNone, valueNull } },
    { "cut", { execCut, enabledRangeSelection, stateNone, valueNull } },
    { "delete", { execDelete, enabledAnySelection, stateNone, valueNull } },
    { "fontName", { execFontName, enabledAnySelection, stateNone, valueFontName } },
    { "fontSize", { execFontSize, enabledAnySelection, stateNone, valueFontSize } },
    { "foreColor", { execForeColor, enabledAnySelection, stateNone, valueForeColor } },
    { "indent", { execIndent, enabledAnySelection, stateNone, valueNull } },
    { "insertNewline", { execInsertNewline, enabledAnySelection, stateNone, valueNull } },
    { "insertOrderedList", { execInsertOrderedList, enabledAnySelection, stateNone, valueNull } },
    { "insertParagraph", { execInsertParagraph, enabledAnySelection, stateNone, valueNull } },
    { "insertText", { execInsertText, enabledAnySelection, stateNone, valueNull } },
    { "insertUnorderedList", { execInsertUnorderedList, enabledAnySelection, stateNone, valueNull } },
    { "italic", { execItalic, enabledAnySelection, stateItalic, valueNull } },
    { "justifyCenter", { execJustifyCenter, enabledAnySelection, stateNone, valueNull } },
    { "justifyFull", { execJustifyFull, enabledAnySelection, stateNone, valueNull } },
    { "justifyLeft", { execJustifyLeft, enabledAnySelection, stateNone, valueNull } },
    { "justifyNone", { execJustifyLeft, enabledAnySelection, stateNone, valueNull } },
    { "justifyRight", { execJustifyRight, enabledAnySelection, stateNone, valueNull } },
    { "outdent", { execOutdent, enabledAnySelection, stateNone, valueNull } },
#ifndef NO_SUPPORT_PASTE
    { "paste", { execPaste, enabledPaste, stateNone, valueNull } },
#else
    { 0, { 0, 0, 0, 0 } },
#endif
    { "print", { execPrint, enabled, stateNone, valueNull } },
    { "redo", { execRedo, enabledRedo, stateNone, valueNull } },
    { "selectAll", { execSelectAll, enabled, stateNone, valueNull } },
    { "StrikeThrough", {execStrikeThrough, enabled, stateStrike, valueNull } },
    { "subscript", { execSubscript, enabledAnySelection, stateSubscript, valueNull } },
    { "superscript", { execSuperscript, enabledAnySelection, stateSuperscript, valueNull } },
    { "underline", { execUnderline, enabledAnySelection, stateUnderline, valueNull } },
    { "undo", { execUndo, enabledUndo, stateNone, valueNull } },
    { "unselect", { execUnselect, enabledAnySelection, stateNone, valueNull } }

    //
    // The "unsupported" commands are listed here since they appear in the Microsoft
    // documentation used as the basis for the list.
    //

    // 2d-position (not supported)
    // absolutePosition (not supported)
    // blockDirLTR (not supported)
    // blockDirRTL (not supported)
    // browseMode (not supported)
    // clearAuthenticationCache (not supported)
    // createBookmark (not supported)
    // createLink (not supported)
    // dirLTR (not supported)
    // dirRTL (not supported)
    // editMode (not supported)
    // formatBlock (not supported)
    // inlineDirLTR (not supported)
    // inlineDirRTL (not supported)
    // insertButton (not supported)
    // insertFieldSet (not supported)
    // insertHorizontalRule (not supported)
    // insertIFrame (not supported)
    // insertImage (not supported)
    // insertInputButton (not supported)
    // insertInputCheckbox (not supported)
    // insertInputFileUpload (not supported)
    // insertInputHidden (not supported)
    // insertInputImage (not supported)
    // insertInputPassword (not supported)
    // insertInputRadio (not supported)
    // insertInputReset (not supported)
    // insertInputSubmit (not supported)
    // insertInputText (not supported)
    // insertMarquee (not supported)
    // insertOrderedList (not supported)
    // insertSelectDropDown (not supported)
    // insertSelectListBox (not supported)
    // insertTextArea (not supported)
    // insertUnorderedList (not supported)
    // liveResize (not supported)
    // multipleSelection (not supported)
    // open (not supported)
    // overwrite (not supported)
    // playImage (not supported)
    // refresh (not supported)
    // removeFormat (not supported)
    // removeParaFormat (not supported)
    // saveAs (not supported)
    // sizeToControl (not supported)
    // sizeToControlHeight (not supported)
    // sizeToControlWidth (not supported)
    // stop (not supported)
    // stopimage (not supported)
    // strikethrough (not supported)
    // unbookmark (not supported)
    // underline (not supported)
    // unlink (not supported)
};

static CommandDict createCommandDictionary()
{
    const int numCommands = sizeof(commands) / sizeof(commands[0]);
    CommandDict commandDictionary; // case-insensitive dictionary
    for (int i = 0; i < numCommands; ++i) {
        if (commands[i].name) {
            commandDictionary.insert(QString(commands[i].name).toLower(), &commands[i].imp);
        }
    }
    return commandDictionary;
}

const CommandImp *JSEditor::commandImp(const DOMString &command)
{
    static CommandDict commandDictionary = createCommandDictionary();
    const CommandImp *result = commandDictionary.value(command.string().toLower());
#ifdef DEBUG_COMMANDS
    if (!result) {
        qCDebug(KHTML_LOG) << "[Command is not supported yet]" << command;
    }
#endif
    return result;
}

const CommandImp *JSEditor::commandImp(int command)
{
    if (command < 0 || command >= int(sizeof commands / sizeof commands[0])) {
        return nullptr;
    }
    return &commands[command].imp;
}

} // namespace DOM

#undef KPAC