62985bfbbf6ee77aa4648b10f590ccd9063ba0fd
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / editing / EditorCommand.cpp
1 /*
2  * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3  * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4  * Copyright (C) 2009 Igalia S.L.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 #include "config.h"
29 #include "core/editing/Editor.h"
30
31 #include "CSSPropertyNames.h"
32 #include "CSSValueKeywords.h"
33 #include "HTMLNames.h"
34 #include "bindings/v8/ExceptionState.h"
35 #include "bindings/v8/ExceptionStatePlaceholder.h"
36 #include "core/css/CSSValueList.h"
37 #include "core/css/StylePropertySet.h"
38 #include "core/dom/DocumentFragment.h"
39 #include "core/dom/Pasteboard.h"
40 #include "core/editing/CreateLinkCommand.h"
41 #include "core/editing/FormatBlockCommand.h"
42 #include "core/editing/IndentOutdentCommand.h"
43 #include "core/editing/InsertListCommand.h"
44 #include "core/editing/ReplaceSelectionCommand.h"
45 #include "core/editing/SpellChecker.h"
46 #include "core/editing/TypingCommand.h"
47 #include "core/editing/UnlinkCommand.h"
48 #include "core/editing/markup.h"
49 #include "core/events/Event.h"
50 #include "core/frame/Frame.h"
51 #include "core/frame/FrameHost.h"
52 #include "core/frame/FrameView.h"
53 #include "core/frame/Settings.h"
54 #include "core/html/HTMLFontElement.h"
55 #include "core/html/HTMLHRElement.h"
56 #include "core/html/HTMLImageElement.h"
57 #include "core/page/Chrome.h"
58 #include "core/page/EditorClient.h"
59 #include "core/page/EventHandler.h"
60 #include "core/rendering/RenderBox.h"
61 #include "platform/KillRing.h"
62 #include "platform/scroll/Scrollbar.h"
63 #include "public/platform/Platform.h"
64 #include "wtf/text/AtomicString.h"
65
66 namespace WebCore {
67
68 using namespace HTMLNames;
69
70 class EditorInternalCommand {
71 public:
72     int idForUserMetrics;
73     bool (*execute)(Frame&, Event*, EditorCommandSource, const String&);
74     bool (*isSupportedFromDOM)(Frame*);
75     bool (*isEnabled)(Frame&, Event*, EditorCommandSource);
76     TriState (*state)(Frame&, Event*);
77     String (*value)(Frame&, Event*);
78     bool isTextInsertion;
79     bool allowExecutionWhenDisabled;
80 };
81
82 typedef HashMap<String, const EditorInternalCommand*, CaseFoldingHash> CommandMap;
83
84 static const bool notTextInsertion = false;
85 static const bool isTextInsertion = true;
86
87 static const bool allowExecutionWhenDisabled = true;
88 static const bool doNotAllowExecutionWhenDisabled = false;
89
90 // Related to Editor::selectionForCommand.
91 // Certain operations continue to use the target control's selection even if the event handler
92 // already moved the selection outside of the text control.
93 static Frame* targetFrame(Frame& frame, Event* event)
94 {
95     if (!event)
96         return &frame;
97     Node* node = event->target()->toNode();
98     if (!node)
99         return &frame;
100     return node->document().frame();
101 }
102
103 static bool applyCommandToFrame(Frame& frame, EditorCommandSource source, EditAction action, StylePropertySet* style)
104 {
105     // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a good reason for that?
106     switch (source) {
107     case CommandFromMenuOrKeyBinding:
108         frame.editor().applyStyleToSelection(style, action);
109         return true;
110     case CommandFromDOM:
111     case CommandFromDOMWithUserInterface:
112         frame.editor().applyStyle(style);
113         return true;
114     }
115     ASSERT_NOT_REACHED();
116     return false;
117 }
118
119 static bool executeApplyStyle(Frame& frame, EditorCommandSource source, EditAction action, CSSPropertyID propertyID, const String& propertyValue)
120 {
121     RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
122     style->setProperty(propertyID, propertyValue);
123     return applyCommandToFrame(frame, source, action, style.get());
124 }
125
126 static bool executeApplyStyle(Frame& frame, EditorCommandSource source, EditAction action, CSSPropertyID propertyID, CSSValueID propertyValue)
127 {
128     RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
129     style->setProperty(propertyID, propertyValue);
130     return applyCommandToFrame(frame, source, action, style.get());
131 }
132
133 // FIXME: executeToggleStyleInList does not handle complicated cases such as <b><u>hello</u>world</b> properly.
134 //        This function must use Editor::selectionHasStyle to determine the current style but we cannot fix this
135 //        until https://bugs.webkit.org/show_bug.cgi?id=27818 is resolved.
136 static bool executeToggleStyleInList(Frame& frame, EditorCommandSource source, EditAction action, CSSPropertyID propertyID, CSSValue* value)
137 {
138     RefPtr<EditingStyle> selectionStyle = EditingStyle::styleAtSelectionStart(frame.selection().selection());
139     if (!selectionStyle || !selectionStyle->style())
140         return false;
141
142     RefPtr<CSSValue> selectedCSSValue = selectionStyle->style()->getPropertyCSSValue(propertyID);
143     String newStyle("none");
144     if (selectedCSSValue->isValueList()) {
145         RefPtr<CSSValueList> selectedCSSValueList = toCSSValueList(selectedCSSValue.get());
146         if (!selectedCSSValueList->removeAll(value))
147             selectedCSSValueList->append(value);
148         if (selectedCSSValueList->length())
149             newStyle = selectedCSSValueList->cssText();
150
151     } else if (selectedCSSValue->cssText() == "none")
152         newStyle = value->cssText();
153
154     // FIXME: We shouldn't be having to convert new style into text.  We should have setPropertyCSSValue.
155     RefPtr<MutableStylePropertySet> newMutableStyle = MutableStylePropertySet::create();
156     newMutableStyle->setProperty(propertyID, newStyle);
157     return applyCommandToFrame(frame, source, action, newMutableStyle.get());
158 }
159
160 static bool executeToggleStyle(Frame& frame, EditorCommandSource source, EditAction action, CSSPropertyID propertyID, const char* offValue, const char* onValue)
161 {
162     // Style is considered present when
163     // Mac: present at the beginning of selection
164     // other: present throughout the selection
165
166     bool styleIsPresent;
167     if (frame.editor().behavior().shouldToggleStyleBasedOnStartOfSelection())
168         styleIsPresent = frame.editor().selectionStartHasStyle(propertyID, onValue);
169     else
170         styleIsPresent = frame.editor().selectionHasStyle(propertyID, onValue) == TrueTriState;
171
172     RefPtr<EditingStyle> style = EditingStyle::create(propertyID, styleIsPresent ? offValue : onValue);
173     return applyCommandToFrame(frame, source, action, style->style());
174 }
175
176 static bool executeApplyParagraphStyle(Frame& frame, EditorCommandSource source, EditAction action, CSSPropertyID propertyID, const String& propertyValue)
177 {
178     RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
179     style->setProperty(propertyID, propertyValue);
180     // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a good reason for that?
181     switch (source) {
182     case CommandFromMenuOrKeyBinding:
183         frame.editor().applyParagraphStyleToSelection(style.get(), action);
184         return true;
185     case CommandFromDOM:
186     case CommandFromDOMWithUserInterface:
187         frame.editor().applyParagraphStyle(style.get());
188         return true;
189     }
190     ASSERT_NOT_REACHED();
191     return false;
192 }
193
194 static bool executeInsertFragment(Frame& frame, PassRefPtr<DocumentFragment> fragment)
195 {
196     ASSERT(frame.document());
197     ReplaceSelectionCommand::create(*frame.document(), fragment, ReplaceSelectionCommand::PreventNesting, EditActionUnspecified)->apply();
198     return true;
199 }
200
201 static bool executeInsertNode(Frame& frame, PassRefPtr<Node> content)
202 {
203     ASSERT(frame.document());
204     RefPtr<DocumentFragment> fragment = DocumentFragment::create(*frame.document());
205     TrackExceptionState exceptionState;
206     fragment->appendChild(content, exceptionState);
207     if (exceptionState.hadException())
208         return false;
209     return executeInsertFragment(frame, fragment.release());
210 }
211
212 static bool expandSelectionToGranularity(Frame& frame, TextGranularity granularity)
213 {
214     VisibleSelection selection = frame.selection().selection();
215     selection.expandUsingGranularity(granularity);
216     RefPtr<Range> newRange = selection.toNormalizedRange();
217     if (!newRange)
218         return false;
219     if (newRange->collapsed(IGNORE_EXCEPTION))
220         return false;
221     RefPtr<Range> oldRange = frame.selection().selection().toNormalizedRange();
222     EAffinity affinity = frame.selection().affinity();
223     frame.selection().setSelectedRange(newRange.get(), affinity, true);
224     return true;
225 }
226
227 static TriState stateStyle(Frame& frame, CSSPropertyID propertyID, const char* desiredValue)
228 {
229     if (frame.editor().behavior().shouldToggleStyleBasedOnStartOfSelection())
230         return frame.editor().selectionStartHasStyle(propertyID, desiredValue) ? TrueTriState : FalseTriState;
231     return frame.editor().selectionHasStyle(propertyID, desiredValue);
232 }
233
234 static String valueStyle(Frame& frame, CSSPropertyID propertyID)
235 {
236     // FIXME: Rather than retrieving the style at the start of the current selection,
237     // we should retrieve the style present throughout the selection for non-Mac platforms.
238     return frame.editor().selectionStartCSSPropertyValue(propertyID);
239 }
240
241 static TriState stateTextWritingDirection(Frame& frame, WritingDirection direction)
242 {
243     bool hasNestedOrMultipleEmbeddings;
244     WritingDirection selectionDirection = EditingStyle::textDirectionForSelection(frame.selection().selection(),
245         frame.selection().typingStyle(), hasNestedOrMultipleEmbeddings);
246     // FXIME: We should be returning MixedTriState when selectionDirection == direction && hasNestedOrMultipleEmbeddings
247     return (selectionDirection == direction && !hasNestedOrMultipleEmbeddings) ? TrueTriState : FalseTriState;
248 }
249
250 static unsigned verticalScrollDistance(Frame& frame)
251 {
252     Element* focusedElement = frame.document()->focusedElement();
253     if (!focusedElement)
254         return 0;
255     RenderObject* renderer = focusedElement->renderer();
256     if (!renderer || !renderer->isBox())
257         return 0;
258     RenderStyle* style = renderer->style();
259     if (!style)
260         return 0;
261     if (!(style->overflowY() == OSCROLL || style->overflowY() == OAUTO || focusedElement->rendererIsEditable()))
262         return 0;
263     int height = std::min<int>(toRenderBox(renderer)->clientHeight(), frame.view()->visibleHeight());
264     return static_cast<unsigned>(max(max<int>(height * ScrollableArea::minFractionToStepWhenPaging(), height - ScrollableArea::maxOverlapBetweenPages()), 1));
265 }
266
267 static RefPtr<Range> unionDOMRanges(Range* a, Range* b)
268 {
269     Range* start = a->compareBoundaryPoints(Range::START_TO_START, b, ASSERT_NO_EXCEPTION) <= 0 ? a : b;
270     Range* end = a->compareBoundaryPoints(Range::END_TO_END, b, ASSERT_NO_EXCEPTION) <= 0 ? b : a;
271
272     return Range::create(a->ownerDocument(), start->startContainer(), start->startOffset(), end->endContainer(), end->endOffset());
273 }
274
275 // Execute command functions
276
277 static bool executeBackColor(Frame& frame, Event*, EditorCommandSource source, const String& value)
278 {
279     return executeApplyStyle(frame, source, EditActionSetBackgroundColor, CSSPropertyBackgroundColor, value);
280 }
281
282 static bool executeCopy(Frame& frame, Event*, EditorCommandSource, const String&)
283 {
284     frame.editor().copy();
285     return true;
286 }
287
288 static bool executeCreateLink(Frame& frame, Event*, EditorCommandSource, const String& value)
289 {
290     // FIXME: If userInterface is true, we should display a dialog box to let the user enter a URL.
291     if (value.isEmpty())
292         return false;
293     ASSERT(frame.document());
294     CreateLinkCommand::create(*frame.document(), value)->apply();
295     return true;
296 }
297
298 static bool executeCut(Frame& frame, Event*, EditorCommandSource, const String&)
299 {
300     frame.editor().cut();
301     return true;
302 }
303
304 static bool executeDefaultParagraphSeparator(Frame& frame, Event*, EditorCommandSource, const String& value)
305 {
306     if (equalIgnoringCase(value, "div"))
307         frame.editor().setDefaultParagraphSeparator(EditorParagraphSeparatorIsDiv);
308     else if (equalIgnoringCase(value, "p"))
309         frame.editor().setDefaultParagraphSeparator(EditorParagraphSeparatorIsP);
310
311     return true;
312 }
313
314 static bool executeDelete(Frame& frame, Event*, EditorCommandSource source, const String&)
315 {
316     switch (source) {
317     case CommandFromMenuOrKeyBinding: {
318         // Doesn't modify the text if the current selection isn't a range.
319         frame.editor().performDelete();
320         return true;
321     }
322     case CommandFromDOM:
323     case CommandFromDOMWithUserInterface:
324         // If the current selection is a caret, delete the preceding character. IE performs forwardDelete, but we currently side with Firefox.
325         // Doesn't scroll to make the selection visible, or modify the kill ring (this time, siding with IE, not Firefox).
326         ASSERT(frame.document());
327         TypingCommand::deleteKeyPressed(*frame.document(), frame.selection().granularity() == WordGranularity ? TypingCommand::SmartDelete : 0);
328         return true;
329     }
330     ASSERT_NOT_REACHED();
331     return false;
332 }
333
334 static bool executeDeleteBackward(Frame& frame, Event*, EditorCommandSource, const String&)
335 {
336     frame.editor().deleteWithDirection(DirectionBackward, CharacterGranularity, false, true);
337     return true;
338 }
339
340 static bool executeDeleteBackwardByDecomposingPreviousCharacter(Frame& frame, Event*, EditorCommandSource, const String&)
341 {
342     WTF_LOG_ERROR("DeleteBackwardByDecomposingPreviousCharacter is not implemented, doing DeleteBackward instead");
343     frame.editor().deleteWithDirection(DirectionBackward, CharacterGranularity, false, true);
344     return true;
345 }
346
347 static bool executeDeleteForward(Frame& frame, Event*, EditorCommandSource, const String&)
348 {
349     frame.editor().deleteWithDirection(DirectionForward, CharacterGranularity, false, true);
350     return true;
351 }
352
353 static bool executeDeleteToBeginningOfLine(Frame& frame, Event*, EditorCommandSource, const String&)
354 {
355     frame.editor().deleteWithDirection(DirectionBackward, LineBoundary, true, false);
356     return true;
357 }
358
359 static bool executeDeleteToBeginningOfParagraph(Frame& frame, Event*, EditorCommandSource, const String&)
360 {
361     frame.editor().deleteWithDirection(DirectionBackward, ParagraphBoundary, true, false);
362     return true;
363 }
364
365 static bool executeDeleteToEndOfLine(Frame& frame, Event*, EditorCommandSource, const String&)
366 {
367     // Despite its name, this command should delete the newline at the end of
368     // a paragraph if you are at the end of a paragraph (like DeleteToEndOfParagraph).
369     frame.editor().deleteWithDirection(DirectionForward, LineBoundary, true, false);
370     return true;
371 }
372
373 static bool executeDeleteToEndOfParagraph(Frame& frame, Event*, EditorCommandSource, const String&)
374 {
375     // Despite its name, this command should delete the newline at the end of
376     // a paragraph if you are at the end of a paragraph.
377     frame.editor().deleteWithDirection(DirectionForward, ParagraphBoundary, true, false);
378     return true;
379 }
380
381 static bool executeDeleteToMark(Frame& frame, Event*, EditorCommandSource, const String&)
382 {
383     RefPtr<Range> mark = frame.editor().mark().toNormalizedRange();
384     if (mark) {
385         bool selected = frame.selection().setSelectedRange(unionDOMRanges(mark.get(), frame.editor().selectedRange().get()).get(), DOWNSTREAM, true);
386         ASSERT(selected);
387         if (!selected)
388             return false;
389     }
390     frame.editor().performDelete();
391     frame.editor().setMark(frame.selection().selection());
392     return true;
393 }
394
395 static bool executeDeleteWordBackward(Frame& frame, Event*, EditorCommandSource, const String&)
396 {
397     frame.editor().deleteWithDirection(DirectionBackward, WordGranularity, true, false);
398     return true;
399 }
400
401 static bool executeDeleteWordForward(Frame& frame, Event*, EditorCommandSource, const String&)
402 {
403     frame.editor().deleteWithDirection(DirectionForward, WordGranularity, true, false);
404     return true;
405 }
406
407 static bool executeFindString(Frame& frame, Event*, EditorCommandSource, const String& value)
408 {
409     return frame.editor().findString(value, true, false, true, false);
410 }
411
412 static bool executeFontName(Frame& frame, Event*, EditorCommandSource source, const String& value)
413 {
414     return executeApplyStyle(frame, source, EditActionSetFont, CSSPropertyFontFamily, value);
415 }
416
417 static bool executeFontSize(Frame& frame, Event*, EditorCommandSource source, const String& value)
418 {
419     CSSValueID size;
420     if (!HTMLFontElement::cssValueFromFontSizeNumber(value, size))
421         return false;
422     return executeApplyStyle(frame, source, EditActionChangeAttributes, CSSPropertyFontSize, size);
423 }
424
425 static bool executeFontSizeDelta(Frame& frame, Event*, EditorCommandSource source, const String& value)
426 {
427     return executeApplyStyle(frame, source, EditActionChangeAttributes, CSSPropertyWebkitFontSizeDelta, value);
428 }
429
430 static bool executeForeColor(Frame& frame, Event*, EditorCommandSource source, const String& value)
431 {
432     return executeApplyStyle(frame, source, EditActionSetColor, CSSPropertyColor, value);
433 }
434
435 static bool executeFormatBlock(Frame& frame, Event*, EditorCommandSource, const String& value)
436 {
437     String tagName = value.lower();
438     if (tagName[0] == '<' && tagName[tagName.length() - 1] == '>')
439         tagName = tagName.substring(1, tagName.length() - 2);
440
441     AtomicString localName, prefix;
442     if (!Document::parseQualifiedName(AtomicString(tagName), prefix, localName, IGNORE_EXCEPTION))
443         return false;
444     QualifiedName qualifiedTagName(prefix, localName, xhtmlNamespaceURI);
445
446     ASSERT(frame.document());
447     RefPtr<FormatBlockCommand> command = FormatBlockCommand::create(*frame.document(), qualifiedTagName);
448     command->apply();
449     return command->didApply();
450 }
451
452 static bool executeForwardDelete(Frame& frame, Event*, EditorCommandSource source, const String&)
453 {
454     switch (source) {
455     case CommandFromMenuOrKeyBinding:
456         frame.editor().deleteWithDirection(DirectionForward, CharacterGranularity, false, true);
457         return true;
458     case CommandFromDOM:
459     case CommandFromDOMWithUserInterface:
460         // Doesn't scroll to make the selection visible, or modify the kill ring.
461         // ForwardDelete is not implemented in IE or Firefox, so this behavior is only needed for
462         // backward compatibility with ourselves, and for consistency with Delete.
463         ASSERT(frame.document());
464         TypingCommand::forwardDeleteKeyPressed(*frame.document());
465         return true;
466     }
467     ASSERT_NOT_REACHED();
468     return false;
469 }
470
471 static bool executeIgnoreSpelling(Frame& frame, Event*, EditorCommandSource, const String&)
472 {
473     frame.spellChecker().ignoreSpelling();
474     return true;
475 }
476
477 static bool executeIndent(Frame& frame, Event*, EditorCommandSource, const String&)
478 {
479     ASSERT(frame.document());
480     IndentOutdentCommand::create(*frame.document(), IndentOutdentCommand::Indent)->apply();
481     return true;
482 }
483
484 static bool executeInsertBacktab(Frame& frame, Event* event, EditorCommandSource, const String&)
485 {
486     return targetFrame(frame, event)->eventHandler().handleTextInputEvent("\t", event, TextEventInputBackTab);
487 }
488
489 static bool executeInsertHorizontalRule(Frame& frame, Event*, EditorCommandSource, const String& value)
490 {
491     ASSERT(frame.document());
492     RefPtr<HTMLHRElement> rule = HTMLHRElement::create(*frame.document());
493     if (!value.isEmpty())
494         rule->setIdAttribute(AtomicString(value));
495     return executeInsertNode(frame, rule.release());
496 }
497
498 static bool executeInsertHTML(Frame& frame, Event*, EditorCommandSource, const String& value)
499 {
500     ASSERT(frame.document());
501     return executeInsertFragment(frame, createFragmentFromMarkup(*frame.document(), value, ""));
502 }
503
504 static bool executeInsertImage(Frame& frame, Event*, EditorCommandSource, const String& value)
505 {
506     // FIXME: If userInterface is true, we should display a dialog box and let the user choose a local image.
507     ASSERT(frame.document());
508     RefPtr<HTMLImageElement> image = HTMLImageElement::create(*frame.document());
509     image->setSrc(value);
510     return executeInsertNode(frame, image.release());
511 }
512
513 static bool executeInsertLineBreak(Frame& frame, Event* event, EditorCommandSource source, const String&)
514 {
515     switch (source) {
516     case CommandFromMenuOrKeyBinding:
517         return targetFrame(frame, event)->eventHandler().handleTextInputEvent("\n", event, TextEventInputLineBreak);
518     case CommandFromDOM:
519     case CommandFromDOMWithUserInterface:
520         // Doesn't scroll to make the selection visible, or modify the kill ring.
521         // InsertLineBreak is not implemented in IE or Firefox, so this behavior is only needed for
522         // backward compatibility with ourselves, and for consistency with other commands.
523         ASSERT(frame.document());
524         TypingCommand::insertLineBreak(*frame.document(), 0);
525         return true;
526     }
527     ASSERT_NOT_REACHED();
528     return false;
529 }
530
531 static bool executeInsertNewline(Frame& frame, Event* event, EditorCommandSource, const String&)
532 {
533     Frame* targetFrame = WebCore::targetFrame(frame, event);
534     return targetFrame->eventHandler().handleTextInputEvent("\n", event, targetFrame->editor().canEditRichly() ? TextEventInputKeyboard : TextEventInputLineBreak);
535 }
536
537 static bool executeInsertNewlineInQuotedContent(Frame& frame, Event*, EditorCommandSource, const String&)
538 {
539     ASSERT(frame.document());
540     TypingCommand::insertParagraphSeparatorInQuotedContent(*frame.document());
541     return true;
542 }
543
544 static bool executeInsertOrderedList(Frame& frame, Event*, EditorCommandSource, const String&)
545 {
546     ASSERT(frame.document());
547     InsertListCommand::create(*frame.document(), InsertListCommand::OrderedList)->apply();
548     return true;
549 }
550
551 static bool executeInsertParagraph(Frame& frame, Event*, EditorCommandSource, const String&)
552 {
553     ASSERT(frame.document());
554     TypingCommand::insertParagraphSeparator(*frame.document(), 0);
555     return true;
556 }
557
558 static bool executeInsertTab(Frame& frame, Event* event, EditorCommandSource, const String&)
559 {
560     return targetFrame(frame, event)->eventHandler().handleTextInputEvent("\t", event);
561 }
562
563 static bool executeInsertText(Frame& frame, Event*, EditorCommandSource, const String& value)
564 {
565     ASSERT(frame.document());
566     TypingCommand::insertText(*frame.document(), value, 0);
567     return true;
568 }
569
570 static bool executeInsertUnorderedList(Frame& frame, Event*, EditorCommandSource, const String&)
571 {
572     ASSERT(frame.document());
573     InsertListCommand::create(*frame.document(), InsertListCommand::UnorderedList)->apply();
574     return true;
575 }
576
577 static bool executeJustifyCenter(Frame& frame, Event*, EditorCommandSource source, const String&)
578 {
579     return executeApplyParagraphStyle(frame, source, EditActionCenter, CSSPropertyTextAlign, "center");
580 }
581
582 static bool executeJustifyFull(Frame& frame, Event*, EditorCommandSource source, const String&)
583 {
584     return executeApplyParagraphStyle(frame, source, EditActionJustify, CSSPropertyTextAlign, "justify");
585 }
586
587 static bool executeJustifyLeft(Frame& frame, Event*, EditorCommandSource source, const String&)
588 {
589     return executeApplyParagraphStyle(frame, source, EditActionAlignLeft, CSSPropertyTextAlign, "left");
590 }
591
592 static bool executeJustifyRight(Frame& frame, Event*, EditorCommandSource source, const String&)
593 {
594     return executeApplyParagraphStyle(frame, source, EditActionAlignRight, CSSPropertyTextAlign, "right");
595 }
596
597 static bool executeMakeTextWritingDirectionLeftToRight(Frame& frame, Event*, EditorCommandSource, const String&)
598 {
599     RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
600     style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed);
601     style->setProperty(CSSPropertyDirection, CSSValueLtr);
602     frame.editor().applyStyle(style.get(), EditActionSetWritingDirection);
603     return true;
604 }
605
606 static bool executeMakeTextWritingDirectionNatural(Frame& frame, Event*, EditorCommandSource, const String&)
607 {
608     RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
609     style->setProperty(CSSPropertyUnicodeBidi, CSSValueNormal);
610     frame.editor().applyStyle(style.get(), EditActionSetWritingDirection);
611     return true;
612 }
613
614 static bool executeMakeTextWritingDirectionRightToLeft(Frame& frame, Event*, EditorCommandSource, const String&)
615 {
616     RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
617     style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed);
618     style->setProperty(CSSPropertyDirection, CSSValueRtl);
619     frame.editor().applyStyle(style.get(), EditActionSetWritingDirection);
620     return true;
621 }
622
623 static bool executeMoveBackward(Frame& frame, Event*, EditorCommandSource, const String&)
624 {
625     frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, CharacterGranularity, UserTriggered);
626     return true;
627 }
628
629 static bool executeMoveBackwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
630 {
631     frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, CharacterGranularity, UserTriggered);
632     return true;
633 }
634
635 static bool executeMoveDown(Frame& frame, Event*, EditorCommandSource, const String&)
636 {
637     return frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, LineGranularity, UserTriggered);
638 }
639
640 static bool executeMoveDownAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
641 {
642     frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, LineGranularity, UserTriggered);
643     return true;
644 }
645
646 static bool executeMoveForward(Frame& frame, Event*, EditorCommandSource, const String&)
647 {
648     frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity, UserTriggered);
649     return true;
650 }
651
652 static bool executeMoveForwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
653 {
654     frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, CharacterGranularity, UserTriggered);
655     return true;
656 }
657
658 static bool executeMoveLeft(Frame& frame, Event*, EditorCommandSource, const String&)
659 {
660     return frame.selection().modify(FrameSelection::AlterationMove, DirectionLeft, CharacterGranularity, UserTriggered);
661 }
662
663 static bool executeMoveLeftAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
664 {
665     frame.selection().modify(FrameSelection::AlterationExtend, DirectionLeft, CharacterGranularity, UserTriggered);
666     return true;
667 }
668
669 static bool executeMovePageDown(Frame& frame, Event*, EditorCommandSource, const String&)
670 {
671     unsigned distance = verticalScrollDistance(frame);
672     if (!distance)
673         return false;
674     return frame.selection().modify(FrameSelection::AlterationMove, distance, FrameSelection::DirectionDown,
675         UserTriggered, FrameSelection::AlignCursorOnScrollAlways);
676 }
677
678 static bool executeMovePageDownAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
679 {
680     unsigned distance = verticalScrollDistance(frame);
681     if (!distance)
682         return false;
683     return frame.selection().modify(FrameSelection::AlterationExtend, distance, FrameSelection::DirectionDown,
684         UserTriggered, FrameSelection::AlignCursorOnScrollAlways);
685 }
686
687 static bool executeMovePageUp(Frame& frame, Event*, EditorCommandSource, const String&)
688 {
689     unsigned distance = verticalScrollDistance(frame);
690     if (!distance)
691         return false;
692     return frame.selection().modify(FrameSelection::AlterationMove, distance, FrameSelection::DirectionUp,
693         UserTriggered, FrameSelection::AlignCursorOnScrollAlways);
694 }
695
696 static bool executeMovePageUpAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
697 {
698     unsigned distance = verticalScrollDistance(frame);
699     if (!distance)
700         return false;
701     return frame.selection().modify(FrameSelection::AlterationExtend, distance, FrameSelection::DirectionUp,
702         UserTriggered, FrameSelection::AlignCursorOnScrollAlways);
703 }
704
705 static bool executeMoveRight(Frame& frame, Event*, EditorCommandSource, const String&)
706 {
707     return frame.selection().modify(FrameSelection::AlterationMove, DirectionRight, CharacterGranularity, UserTriggered);
708 }
709
710 static bool executeMoveRightAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
711 {
712     frame.selection().modify(FrameSelection::AlterationExtend, DirectionRight, CharacterGranularity, UserTriggered);
713     return true;
714 }
715
716 static bool executeMoveToBeginningOfDocument(Frame& frame, Event*, EditorCommandSource, const String&)
717 {
718     frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, DocumentBoundary, UserTriggered);
719     return true;
720 }
721
722 static bool executeMoveToBeginningOfDocumentAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
723 {
724     frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, DocumentBoundary, UserTriggered);
725     return true;
726 }
727
728 static bool executeMoveToBeginningOfLine(Frame& frame, Event*, EditorCommandSource, const String&)
729 {
730     frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, LineBoundary, UserTriggered);
731     return true;
732 }
733
734 static bool executeMoveToBeginningOfLineAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
735 {
736     frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, LineBoundary, UserTriggered);
737     return true;
738 }
739
740 static bool executeMoveToBeginningOfParagraph(Frame& frame, Event*, EditorCommandSource, const String&)
741 {
742     frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, ParagraphBoundary, UserTriggered);
743     return true;
744 }
745
746 static bool executeMoveToBeginningOfParagraphAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
747 {
748     frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, ParagraphBoundary, UserTriggered);
749     return true;
750 }
751
752 static bool executeMoveToBeginningOfSentence(Frame& frame, Event*, EditorCommandSource, const String&)
753 {
754     frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, SentenceBoundary, UserTriggered);
755     return true;
756 }
757
758 static bool executeMoveToBeginningOfSentenceAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
759 {
760     frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, SentenceBoundary, UserTriggered);
761     return true;
762 }
763
764 static bool executeMoveToEndOfDocument(Frame& frame, Event*, EditorCommandSource, const String&)
765 {
766     frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, DocumentBoundary, UserTriggered);
767     return true;
768 }
769
770 static bool executeMoveToEndOfDocumentAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
771 {
772     frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, DocumentBoundary, UserTriggered);
773     return true;
774 }
775
776 static bool executeMoveToEndOfSentence(Frame& frame, Event*, EditorCommandSource, const String&)
777 {
778     frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, SentenceBoundary, UserTriggered);
779     return true;
780 }
781
782 static bool executeMoveToEndOfSentenceAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
783 {
784     frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, SentenceBoundary, UserTriggered);
785     return true;
786 }
787
788 static bool executeMoveToEndOfLine(Frame& frame, Event*, EditorCommandSource, const String&)
789 {
790     frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, LineBoundary, UserTriggered);
791     return true;
792 }
793
794 static bool executeMoveToEndOfLineAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
795 {
796     frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, LineBoundary, UserTriggered);
797     return true;
798 }
799
800 static bool executeMoveToEndOfParagraph(Frame& frame, Event*, EditorCommandSource, const String&)
801 {
802     frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, ParagraphBoundary, UserTriggered);
803     return true;
804 }
805
806 static bool executeMoveToEndOfParagraphAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
807 {
808     frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, ParagraphBoundary, UserTriggered);
809     return true;
810 }
811
812 static bool executeMoveParagraphBackward(Frame& frame, Event*, EditorCommandSource, const String&)
813 {
814     frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, ParagraphGranularity, UserTriggered);
815     return true;
816 }
817
818 static bool executeMoveParagraphBackwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
819 {
820     frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, ParagraphGranularity, UserTriggered);
821     return true;
822 }
823
824 static bool executeMoveParagraphForward(Frame& frame, Event*, EditorCommandSource, const String&)
825 {
826     frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, ParagraphGranularity, UserTriggered);
827     return true;
828 }
829
830 static bool executeMoveParagraphForwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
831 {
832     frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, ParagraphGranularity, UserTriggered);
833     return true;
834 }
835
836 static bool executeMoveUp(Frame& frame, Event*, EditorCommandSource, const String&)
837 {
838     return frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, LineGranularity, UserTriggered);
839 }
840
841 static bool executeMoveUpAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
842 {
843     frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, LineGranularity, UserTriggered);
844     return true;
845 }
846
847 static bool executeMoveWordBackward(Frame& frame, Event*, EditorCommandSource, const String&)
848 {
849     frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, WordGranularity, UserTriggered);
850     return true;
851 }
852
853 static bool executeMoveWordBackwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
854 {
855     frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, WordGranularity, UserTriggered);
856     return true;
857 }
858
859 static bool executeMoveWordForward(Frame& frame, Event*, EditorCommandSource, const String&)
860 {
861     frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, WordGranularity, UserTriggered);
862     return true;
863 }
864
865 static bool executeMoveWordForwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
866 {
867     frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, WordGranularity, UserTriggered);
868     return true;
869 }
870
871 static bool executeMoveWordLeft(Frame& frame, Event*, EditorCommandSource, const String&)
872 {
873     frame.selection().modify(FrameSelection::AlterationMove, DirectionLeft, WordGranularity, UserTriggered);
874     return true;
875 }
876
877 static bool executeMoveWordLeftAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
878 {
879     frame.selection().modify(FrameSelection::AlterationExtend, DirectionLeft, WordGranularity, UserTriggered);
880     return true;
881 }
882
883 static bool executeMoveWordRight(Frame& frame, Event*, EditorCommandSource, const String&)
884 {
885     frame.selection().modify(FrameSelection::AlterationMove, DirectionRight, WordGranularity, UserTriggered);
886     return true;
887 }
888
889 static bool executeMoveWordRightAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
890 {
891     frame.selection().modify(FrameSelection::AlterationExtend, DirectionRight, WordGranularity, UserTriggered);
892     return true;
893 }
894
895 static bool executeMoveToLeftEndOfLine(Frame& frame, Event*, EditorCommandSource, const String&)
896 {
897     frame.selection().modify(FrameSelection::AlterationMove, DirectionLeft, LineBoundary, UserTriggered);
898     return true;
899 }
900
901 static bool executeMoveToLeftEndOfLineAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
902 {
903     frame.selection().modify(FrameSelection::AlterationExtend, DirectionLeft, LineBoundary, UserTriggered);
904     return true;
905 }
906
907 static bool executeMoveToRightEndOfLine(Frame& frame, Event*, EditorCommandSource, const String&)
908 {
909     frame.selection().modify(FrameSelection::AlterationMove, DirectionRight, LineBoundary, UserTriggered);
910     return true;
911 }
912
913 static bool executeMoveToRightEndOfLineAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
914 {
915     frame.selection().modify(FrameSelection::AlterationExtend, DirectionRight, LineBoundary, UserTriggered);
916     return true;
917 }
918
919 static bool executeOutdent(Frame& frame, Event*, EditorCommandSource, const String&)
920 {
921     ASSERT(frame.document());
922     IndentOutdentCommand::create(*frame.document(), IndentOutdentCommand::Outdent)->apply();
923     return true;
924 }
925
926 static bool executeToggleOverwrite(Frame& frame, Event*, EditorCommandSource, const String&)
927 {
928     frame.editor().toggleOverwriteModeEnabled();
929     return true;
930 }
931
932 static bool executePaste(Frame& frame, Event*, EditorCommandSource, const String&)
933 {
934     frame.editor().paste();
935     return true;
936 }
937
938 static bool executePasteGlobalSelection(Frame& frame, Event*, EditorCommandSource source, const String&)
939 {
940     if (!frame.editor().behavior().supportsGlobalSelection())
941         return false;
942     ASSERT_UNUSED(source, source == CommandFromMenuOrKeyBinding);
943
944     bool oldSelectionMode = Pasteboard::generalPasteboard()->isSelectionMode();
945     Pasteboard::generalPasteboard()->setSelectionMode(true);
946     frame.editor().paste();
947     Pasteboard::generalPasteboard()->setSelectionMode(oldSelectionMode);
948     return true;
949 }
950
951 static bool executePasteAndMatchStyle(Frame& frame, Event*, EditorCommandSource, const String&)
952 {
953     frame.editor().pasteAsPlainText();
954     return true;
955 }
956
957 static bool executePrint(Frame& frame, Event*, EditorCommandSource, const String&)
958 {
959     FrameHost* host = frame.host();
960     if (!host)
961         return false;
962     host->chrome().print(&frame);
963     return true;
964 }
965
966 static bool executeRedo(Frame& frame, Event*, EditorCommandSource, const String&)
967 {
968     frame.editor().redo();
969     return true;
970 }
971
972 static bool executeRemoveFormat(Frame& frame, Event*, EditorCommandSource, const String&)
973 {
974     frame.editor().removeFormattingAndStyle();
975     return true;
976 }
977
978 static bool executeScrollPageBackward(Frame& frame, Event*, EditorCommandSource, const String&)
979 {
980     return frame.eventHandler().bubblingScroll(ScrollBlockDirectionBackward, ScrollByPage);
981 }
982
983 static bool executeScrollPageForward(Frame& frame, Event*, EditorCommandSource, const String&)
984 {
985     return frame.eventHandler().bubblingScroll(ScrollBlockDirectionForward, ScrollByPage);
986 }
987
988 static bool executeScrollLineUp(Frame& frame, Event*, EditorCommandSource, const String&)
989 {
990     return frame.eventHandler().bubblingScroll(ScrollUp, ScrollByLine);
991 }
992
993 static bool executeScrollLineDown(Frame& frame, Event*, EditorCommandSource, const String&)
994 {
995     return frame.eventHandler().bubblingScroll(ScrollDown, ScrollByLine);
996 }
997
998 static bool executeScrollToBeginningOfDocument(Frame& frame, Event*, EditorCommandSource, const String&)
999 {
1000     return frame.eventHandler().bubblingScroll(ScrollBlockDirectionBackward, ScrollByDocument);
1001 }
1002
1003 static bool executeScrollToEndOfDocument(Frame& frame, Event*, EditorCommandSource, const String&)
1004 {
1005     return frame.eventHandler().bubblingScroll(ScrollBlockDirectionForward, ScrollByDocument);
1006 }
1007
1008 static bool executeSelectAll(Frame& frame, Event*, EditorCommandSource, const String&)
1009 {
1010     frame.selection().selectAll();
1011     return true;
1012 }
1013
1014 static bool executeSelectLine(Frame& frame, Event*, EditorCommandSource, const String&)
1015 {
1016     return expandSelectionToGranularity(frame, LineGranularity);
1017 }
1018
1019 static bool executeSelectParagraph(Frame& frame, Event*, EditorCommandSource, const String&)
1020 {
1021     return expandSelectionToGranularity(frame, ParagraphGranularity);
1022 }
1023
1024 static bool executeSelectSentence(Frame& frame, Event*, EditorCommandSource, const String&)
1025 {
1026     return expandSelectionToGranularity(frame, SentenceGranularity);
1027 }
1028
1029 static bool executeSelectToMark(Frame& frame, Event*, EditorCommandSource, const String&)
1030 {
1031     RefPtr<Range> mark = frame.editor().mark().toNormalizedRange();
1032     RefPtr<Range> selection = frame.editor().selectedRange();
1033     if (!mark || !selection)
1034         return false;
1035     frame.selection().setSelectedRange(unionDOMRanges(mark.get(), selection.get()).get(), DOWNSTREAM, true);
1036     return true;
1037 }
1038
1039 static bool executeSelectWord(Frame& frame, Event*, EditorCommandSource, const String&)
1040 {
1041     return expandSelectionToGranularity(frame, WordGranularity);
1042 }
1043
1044 static bool executeSetMark(Frame& frame, Event*, EditorCommandSource, const String&)
1045 {
1046     frame.editor().setMark(frame.selection().selection());
1047     return true;
1048 }
1049
1050 static bool executeStrikethrough(Frame& frame, Event*, EditorCommandSource source, const String&)
1051 {
1052     RefPtr<CSSPrimitiveValue> lineThrough = CSSPrimitiveValue::createIdentifier(CSSValueLineThrough);
1053     return executeToggleStyleInList(frame, source, EditActionUnderline, CSSPropertyWebkitTextDecorationsInEffect, lineThrough.get());
1054 }
1055
1056 static bool executeStyleWithCSS(Frame& frame, Event*, EditorCommandSource, const String& value)
1057 {
1058     frame.editor().setShouldStyleWithCSS(!equalIgnoringCase(value, "false"));
1059     return true;
1060 }
1061
1062 static bool executeUseCSS(Frame& frame, Event*, EditorCommandSource, const String& value)
1063 {
1064     frame.editor().setShouldStyleWithCSS(equalIgnoringCase(value, "false"));
1065     return true;
1066 }
1067
1068 static bool executeSubscript(Frame& frame, Event*, EditorCommandSource source, const String&)
1069 {
1070     return executeToggleStyle(frame, source, EditActionSubscript, CSSPropertyVerticalAlign, "baseline", "sub");
1071 }
1072
1073 static bool executeSuperscript(Frame& frame, Event*, EditorCommandSource source, const String&)
1074 {
1075     return executeToggleStyle(frame, source, EditActionSuperscript, CSSPropertyVerticalAlign, "baseline", "super");
1076 }
1077
1078 static bool executeSwapWithMark(Frame& frame, Event*, EditorCommandSource, const String&)
1079 {
1080     const VisibleSelection& mark = frame.editor().mark();
1081     const VisibleSelection& selection = frame.selection().selection();
1082     if (mark.isNone() || selection.isNone())
1083         return false;
1084     frame.selection().setSelection(mark);
1085     frame.editor().setMark(selection);
1086     return true;
1087 }
1088
1089 static bool executeToggleBold(Frame& frame, Event*, EditorCommandSource source, const String&)
1090 {
1091     return executeToggleStyle(frame, source, EditActionBold, CSSPropertyFontWeight, "normal", "bold");
1092 }
1093
1094 static bool executeToggleItalic(Frame& frame, Event*, EditorCommandSource source, const String&)
1095 {
1096     return executeToggleStyle(frame, source, EditActionItalics, CSSPropertyFontStyle, "normal", "italic");
1097 }
1098
1099 static bool executeTranspose(Frame& frame, Event*, EditorCommandSource, const String&)
1100 {
1101     frame.editor().transpose();
1102     return true;
1103 }
1104
1105 static bool executeUnderline(Frame& frame, Event*, EditorCommandSource source, const String&)
1106 {
1107     RefPtr<CSSPrimitiveValue> underline = CSSPrimitiveValue::createIdentifier(CSSValueUnderline);
1108     return executeToggleStyleInList(frame, source, EditActionUnderline, CSSPropertyWebkitTextDecorationsInEffect, underline.get());
1109 }
1110
1111 static bool executeUndo(Frame& frame, Event*, EditorCommandSource, const String&)
1112 {
1113     frame.editor().undo();
1114     return true;
1115 }
1116
1117 static bool executeUnlink(Frame& frame, Event*, EditorCommandSource, const String&)
1118 {
1119     ASSERT(frame.document());
1120     UnlinkCommand::create(*frame.document())->apply();
1121     return true;
1122 }
1123
1124 static bool executeUnscript(Frame& frame, Event*, EditorCommandSource source, const String&)
1125 {
1126     return executeApplyStyle(frame, source, EditActionUnscript, CSSPropertyVerticalAlign, "baseline");
1127 }
1128
1129 static bool executeUnselect(Frame& frame, Event*, EditorCommandSource, const String&)
1130 {
1131     frame.selection().clear();
1132     return true;
1133 }
1134
1135 static bool executeYank(Frame& frame, Event*, EditorCommandSource, const String&)
1136 {
1137     frame.editor().insertTextWithoutSendingTextEvent(frame.editor().killRing().yank(), false, 0);
1138     frame.editor().killRing().setToYankedState();
1139     return true;
1140 }
1141
1142 static bool executeYankAndSelect(Frame& frame, Event*, EditorCommandSource, const String&)
1143 {
1144     frame.editor().insertTextWithoutSendingTextEvent(frame.editor().killRing().yank(), true, 0);
1145     frame.editor().killRing().setToYankedState();
1146     return true;
1147 }
1148
1149 // Supported functions
1150
1151 static bool supported(Frame*)
1152 {
1153     return true;
1154 }
1155
1156 static bool supportedFromMenuOrKeyBinding(Frame*)
1157 {
1158     return false;
1159 }
1160
1161 static bool supportedCopyCut(Frame* frame)
1162 {
1163     if (!frame)
1164         return false;
1165
1166     Settings* settings = frame->settings();
1167     bool defaultValue = settings && settings->javaScriptCanAccessClipboard();
1168     return frame->editor().client().canCopyCut(frame, defaultValue);
1169 }
1170
1171 static bool supportedPaste(Frame* frame)
1172 {
1173     if (!frame)
1174         return false;
1175
1176     Settings* settings = frame->settings();
1177     bool defaultValue = settings && settings->javaScriptCanAccessClipboard() && settings->DOMPasteAllowed();
1178     return frame->editor().client().canPaste(frame, defaultValue);
1179 }
1180
1181 // Enabled functions
1182
1183 static bool enabled(Frame&, Event*, EditorCommandSource)
1184 {
1185     return true;
1186 }
1187
1188 static bool enabledVisibleSelection(Frame& frame, Event* event, EditorCommandSource)
1189 {
1190     // The term "visible" here includes a caret in editable text or a range in any text.
1191     const VisibleSelection& selection = frame.editor().selectionForCommand(event);
1192     return (selection.isCaret() && selection.isContentEditable()) || selection.isRange();
1193 }
1194
1195 static bool caretBrowsingEnabled(Frame& frame)
1196 {
1197     return frame.settings() && frame.settings()->caretBrowsingEnabled();
1198 }
1199
1200 static EditorCommandSource dummyEditorCommandSource = static_cast<EditorCommandSource>(0);
1201
1202 static bool enabledVisibleSelectionOrCaretBrowsing(Frame& frame, Event* event, EditorCommandSource)
1203 {
1204     // The EditorCommandSource parameter is unused in enabledVisibleSelection, so just pass a dummy variable
1205     return caretBrowsingEnabled(frame) || enabledVisibleSelection(frame, event, dummyEditorCommandSource);
1206 }
1207
1208 static bool enabledVisibleSelectionAndMark(Frame& frame, Event* event, EditorCommandSource)
1209 {
1210     const VisibleSelection& selection = frame.editor().selectionForCommand(event);
1211     return ((selection.isCaret() && selection.isContentEditable()) || selection.isRange())
1212         && frame.editor().mark().isCaretOrRange();
1213 }
1214
1215 static bool enableCaretInEditableText(Frame& frame, Event* event, EditorCommandSource)
1216 {
1217     const VisibleSelection& selection = frame.editor().selectionForCommand(event);
1218     return selection.isCaret() && selection.isContentEditable();
1219 }
1220
1221 static bool enabledCopy(Frame& frame, Event*, EditorCommandSource)
1222 {
1223     return frame.editor().canDHTMLCopy() || frame.editor().canCopy();
1224 }
1225
1226 static bool enabledCut(Frame& frame, Event*, EditorCommandSource)
1227 {
1228     return frame.editor().canDHTMLCut() || frame.editor().canCut();
1229 }
1230
1231 static bool enabledInEditableText(Frame& frame, Event* event, EditorCommandSource)
1232 {
1233     return frame.editor().selectionForCommand(event).rootEditableElement();
1234 }
1235
1236 static bool enabledDelete(Frame& frame, Event* event, EditorCommandSource source)
1237 {
1238     switch (source) {
1239     case CommandFromMenuOrKeyBinding:
1240         return frame.editor().canDelete();
1241     case CommandFromDOM:
1242     case CommandFromDOMWithUserInterface:
1243         // "Delete" from DOM is like delete/backspace keypress, affects selected range if non-empty,
1244         // otherwise removes a character
1245         return enabledInEditableText(frame, event, source);
1246     }
1247     ASSERT_NOT_REACHED();
1248     return false;
1249 }
1250
1251 static bool enabledInEditableTextOrCaretBrowsing(Frame& frame, Event* event, EditorCommandSource)
1252 {
1253     // The EditorCommandSource parameter is unused in enabledInEditableText, so just pass a dummy variable
1254     return caretBrowsingEnabled(frame) || enabledInEditableText(frame, event, dummyEditorCommandSource);
1255 }
1256
1257 static bool enabledInRichlyEditableText(Frame& frame, Event*, EditorCommandSource)
1258 {
1259     return frame.selection().isCaretOrRange() && frame.selection().isContentRichlyEditable() && frame.selection().rootEditableElement();
1260 }
1261
1262 static bool enabledPaste(Frame& frame, Event*, EditorCommandSource)
1263 {
1264     return frame.editor().canPaste();
1265 }
1266
1267 static bool enabledRangeInEditableText(Frame& frame, Event*, EditorCommandSource)
1268 {
1269     return frame.selection().isRange() && frame.selection().isContentEditable();
1270 }
1271
1272 static bool enabledRangeInRichlyEditableText(Frame& frame, Event*, EditorCommandSource)
1273 {
1274     return frame.selection().isRange() && frame.selection().isContentRichlyEditable();
1275 }
1276
1277 static bool enabledRedo(Frame& frame, Event*, EditorCommandSource)
1278 {
1279     return frame.editor().canRedo();
1280 }
1281
1282 static bool enabledUndo(Frame& frame, Event*, EditorCommandSource)
1283 {
1284     return frame.editor().canUndo();
1285 }
1286
1287 // State functions
1288
1289 static TriState stateNone(Frame&, Event*)
1290 {
1291     return FalseTriState;
1292 }
1293
1294 static TriState stateBold(Frame& frame, Event*)
1295 {
1296     return stateStyle(frame, CSSPropertyFontWeight, "bold");
1297 }
1298
1299 static TriState stateItalic(Frame& frame, Event*)
1300 {
1301     return stateStyle(frame, CSSPropertyFontStyle, "italic");
1302 }
1303
1304 static TriState stateOrderedList(Frame& frame, Event*)
1305 {
1306     return frame.editor().selectionOrderedListState();
1307 }
1308
1309 static TriState stateStrikethrough(Frame& frame, Event*)
1310 {
1311     return stateStyle(frame, CSSPropertyWebkitTextDecorationsInEffect, "line-through");
1312 }
1313
1314 static TriState stateStyleWithCSS(Frame& frame, Event*)
1315 {
1316     return frame.editor().shouldStyleWithCSS() ? TrueTriState : FalseTriState;
1317 }
1318
1319 static TriState stateSubscript(Frame& frame, Event*)
1320 {
1321     return stateStyle(frame, CSSPropertyVerticalAlign, "sub");
1322 }
1323
1324 static TriState stateSuperscript(Frame& frame, Event*)
1325 {
1326     return stateStyle(frame, CSSPropertyVerticalAlign, "super");
1327 }
1328
1329 static TriState stateTextWritingDirectionLeftToRight(Frame& frame, Event*)
1330 {
1331     return stateTextWritingDirection(frame, LeftToRightWritingDirection);
1332 }
1333
1334 static TriState stateTextWritingDirectionNatural(Frame& frame, Event*)
1335 {
1336     return stateTextWritingDirection(frame, NaturalWritingDirection);
1337 }
1338
1339 static TriState stateTextWritingDirectionRightToLeft(Frame& frame, Event*)
1340 {
1341     return stateTextWritingDirection(frame, RightToLeftWritingDirection);
1342 }
1343
1344 static TriState stateUnderline(Frame& frame, Event*)
1345 {
1346     return stateStyle(frame, CSSPropertyWebkitTextDecorationsInEffect, "underline");
1347 }
1348
1349 static TriState stateUnorderedList(Frame& frame, Event*)
1350 {
1351     return frame.editor().selectionUnorderedListState();
1352 }
1353
1354 static TriState stateJustifyCenter(Frame& frame, Event*)
1355 {
1356     return stateStyle(frame, CSSPropertyTextAlign, "center");
1357 }
1358
1359 static TriState stateJustifyFull(Frame& frame, Event*)
1360 {
1361     return stateStyle(frame, CSSPropertyTextAlign, "justify");
1362 }
1363
1364 static TriState stateJustifyLeft(Frame& frame, Event*)
1365 {
1366     return stateStyle(frame, CSSPropertyTextAlign, "left");
1367 }
1368
1369 static TriState stateJustifyRight(Frame& frame, Event*)
1370 {
1371     return stateStyle(frame, CSSPropertyTextAlign, "right");
1372 }
1373
1374 // Value functions
1375
1376 static String valueNull(Frame&, Event*)
1377 {
1378     return String();
1379 }
1380
1381 static String valueBackColor(Frame& frame, Event*)
1382 {
1383     return valueStyle(frame, CSSPropertyBackgroundColor);
1384 }
1385
1386 static String valueDefaultParagraphSeparator(Frame& frame, Event*)
1387 {
1388     switch (frame.editor().defaultParagraphSeparator()) {
1389     case EditorParagraphSeparatorIsDiv:
1390         return divTag.localName();
1391     case EditorParagraphSeparatorIsP:
1392         return pTag.localName();
1393     }
1394
1395     ASSERT_NOT_REACHED();
1396     return String();
1397 }
1398
1399 static String valueFontName(Frame& frame, Event*)
1400 {
1401     return valueStyle(frame, CSSPropertyFontFamily);
1402 }
1403
1404 static String valueFontSize(Frame& frame, Event*)
1405 {
1406     return valueStyle(frame, CSSPropertyFontSize);
1407 }
1408
1409 static String valueFontSizeDelta(Frame& frame, Event*)
1410 {
1411     return valueStyle(frame, CSSPropertyWebkitFontSizeDelta);
1412 }
1413
1414 static String valueForeColor(Frame& frame, Event*)
1415 {
1416     return valueStyle(frame, CSSPropertyColor);
1417 }
1418
1419 static String valueFormatBlock(Frame& frame, Event*)
1420 {
1421     const VisibleSelection& selection = frame.selection().selection();
1422     if (!selection.isNonOrphanedCaretOrRange() || !selection.isContentEditable())
1423         return "";
1424     Element* formatBlockElement = FormatBlockCommand::elementForFormatBlockCommand(selection.firstRange().get());
1425     if (!formatBlockElement)
1426         return "";
1427     return formatBlockElement->localName();
1428 }
1429
1430 // Map of functions
1431
1432 struct CommandEntry {
1433     const char* name;
1434     EditorInternalCommand command;
1435 };
1436
1437 static const CommandMap& createCommandMap()
1438 {
1439     // If you add new commands, you should assign new Id to each idForUserMetrics and update MappedEditingCommands
1440     // in chrome/trunk/src/tools/metrics/histograms/histograms.xml.
1441     static const CommandEntry commands[] = {
1442         { "AlignCenter", {139, executeJustifyCenter, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1443         { "AlignJustified", {1, executeJustifyFull, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1444         { "AlignLeft", {2, executeJustifyLeft, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1445         { "AlignRight", {3, executeJustifyRight, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1446         { "BackColor", {4, executeBackColor, supported, enabledInRichlyEditableText, stateNone, valueBackColor, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1447         { "BackwardDelete", {5, executeDeleteBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, // FIXME: remove BackwardDelete when Safari for Windows stops using it.
1448         { "Bold", {6, executeToggleBold, supported, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1449         { "Copy", {7, executeCopy, supportedCopyCut, enabledCopy, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1450         { "CreateLink", {8, executeCreateLink, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1451         { "Cut", {9, executeCut, supportedCopyCut, enabledCut, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1452         { "DefaultParagraphSeparator", {10, executeDefaultParagraphSeparator, supported, enabled, stateNone, valueDefaultParagraphSeparator, notTextInsertion, doNotAllowExecutionWhenDisabled} },
1453         { "Delete", {11, executeDelete, supported, enabledDelete, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1454         { "DeleteBackward", {12, executeDeleteBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1455         { "DeleteBackwardByDecomposingPreviousCharacter", {13, executeDeleteBackwardByDecomposingPreviousCharacter, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1456         { "DeleteForward", {14, executeDeleteForward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1457         { "DeleteToBeginningOfLine", {15, executeDeleteToBeginningOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1458         { "DeleteToBeginningOfParagraph", {16, executeDeleteToBeginningOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1459         { "DeleteToEndOfLine", {17, executeDeleteToEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1460         { "DeleteToEndOfParagraph", {18, executeDeleteToEndOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1461         { "DeleteToMark", {19, executeDeleteToMark, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1462         { "DeleteWordBackward", {20, executeDeleteWordBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1463         { "DeleteWordForward", {21, executeDeleteWordForward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1464         { "FindString", {22, executeFindString, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1465         { "FontName", {23, executeFontName, supported, enabledInEditableText, stateNone, valueFontName, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1466         { "FontSize", {24, executeFontSize, supported, enabledInEditableText, stateNone, valueFontSize, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1467         { "FontSizeDelta", {25, executeFontSizeDelta, supported, enabledInEditableText, stateNone, valueFontSizeDelta, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1468         { "ForeColor", {26, executeForeColor, supported, enabledInRichlyEditableText, stateNone, valueForeColor, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1469         { "FormatBlock", {27, executeFormatBlock, supported, enabledInRichlyEditableText, stateNone, valueFormatBlock, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1470         { "ForwardDelete", {28, executeForwardDelete, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1471         { "HiliteColor", {29, executeBackColor, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1472         { "IgnoreSpelling", {30, executeIgnoreSpelling, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1473         { "Indent", {31, executeIndent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1474         { "InsertBacktab", {32, executeInsertBacktab, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1475         { "InsertHTML", {33, executeInsertHTML, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1476         { "InsertHorizontalRule", {34, executeInsertHorizontalRule, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1477         { "InsertImage", {35, executeInsertImage, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1478         { "InsertLineBreak", {36, executeInsertLineBreak, supported, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1479         { "InsertNewline", {37, executeInsertNewline, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1480         { "InsertNewlineInQuotedContent", {38, executeInsertNewlineInQuotedContent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1481         { "InsertOrderedList", {39, executeInsertOrderedList, supported, enabledInRichlyEditableText, stateOrderedList, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1482         { "InsertParagraph", {40, executeInsertParagraph, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1483         { "InsertTab", {41, executeInsertTab, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1484         { "InsertText", {42, executeInsertText, supported, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1485         { "InsertUnorderedList", {43, executeInsertUnorderedList, supported, enabledInRichlyEditableText, stateUnorderedList, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1486         { "Italic", {44, executeToggleItalic, supported, enabledInRichlyEditableText, stateItalic, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1487         { "JustifyCenter", {45, executeJustifyCenter, supported, enabledInRichlyEditableText, stateJustifyCenter, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1488         { "JustifyFull", {46, executeJustifyFull, supported, enabledInRichlyEditableText, stateJustifyFull, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1489         { "JustifyLeft", {47, executeJustifyLeft, supported, enabledInRichlyEditableText, stateJustifyLeft, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1490         { "JustifyNone", {48, executeJustifyLeft, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1491         { "JustifyRight", {49, executeJustifyRight, supported, enabledInRichlyEditableText, stateJustifyRight, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1492         { "MakeTextWritingDirectionLeftToRight", {50, executeMakeTextWritingDirectionLeftToRight, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionLeftToRight, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1493         { "MakeTextWritingDirectionNatural", {51, executeMakeTextWritingDirectionNatural, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionNatural, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1494         { "MakeTextWritingDirectionRightToLeft", {52, executeMakeTextWritingDirectionRightToLeft, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionRightToLeft, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1495         { "MoveBackward", {53, executeMoveBackward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1496         { "MoveBackwardAndModifySelection", {54, executeMoveBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1497         { "MoveDown", {55, executeMoveDown, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1498         { "MoveDownAndModifySelection", {56, executeMoveDownAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1499         { "MoveForward", {57, executeMoveForward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1500         { "MoveForwardAndModifySelection", {58, executeMoveForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1501         { "MoveLeft", {59, executeMoveLeft, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1502         { "MoveLeftAndModifySelection", {60, executeMoveLeftAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1503         { "MovePageDown", {61, executeMovePageDown, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1504         { "MovePageDownAndModifySelection", {62, executeMovePageDownAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1505         { "MovePageUp", {63, executeMovePageUp, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1506         { "MovePageUpAndModifySelection", {64, executeMovePageUpAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1507         { "MoveParagraphBackward", {65, executeMoveParagraphBackward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1508         { "MoveParagraphBackwardAndModifySelection", {66, executeMoveParagraphBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1509         { "MoveParagraphForward", {67, executeMoveParagraphForward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1510         { "MoveParagraphForwardAndModifySelection", {68, executeMoveParagraphForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1511         { "MoveRight", {69, executeMoveRight, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1512         { "MoveRightAndModifySelection", {70, executeMoveRightAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1513         { "MoveToBeginningOfDocument", {71, executeMoveToBeginningOfDocument, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1514         { "MoveToBeginningOfDocumentAndModifySelection", {72, executeMoveToBeginningOfDocumentAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1515         { "MoveToBeginningOfLine", {73, executeMoveToBeginningOfLine, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1516         { "MoveToBeginningOfLineAndModifySelection", {74, executeMoveToBeginningOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1517         { "MoveToBeginningOfParagraph", {75, executeMoveToBeginningOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1518         { "MoveToBeginningOfParagraphAndModifySelection", {76, executeMoveToBeginningOfParagraphAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1519         { "MoveToBeginningOfSentence", {77, executeMoveToBeginningOfSentence, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1520         { "MoveToBeginningOfSentenceAndModifySelection", {78, executeMoveToBeginningOfSentenceAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1521         { "MoveToEndOfDocument", {79, executeMoveToEndOfDocument, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1522         { "MoveToEndOfDocumentAndModifySelection", {80, executeMoveToEndOfDocumentAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1523         { "MoveToEndOfLine", {81, executeMoveToEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1524         { "MoveToEndOfLineAndModifySelection", {82, executeMoveToEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1525         { "MoveToEndOfParagraph", {83, executeMoveToEndOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1526         { "MoveToEndOfParagraphAndModifySelection", {84, executeMoveToEndOfParagraphAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1527         { "MoveToEndOfSentence", {85, executeMoveToEndOfSentence, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1528         { "MoveToEndOfSentenceAndModifySelection", {86, executeMoveToEndOfSentenceAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1529         { "MoveToLeftEndOfLine", {87, executeMoveToLeftEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1530         { "MoveToLeftEndOfLineAndModifySelection", {88, executeMoveToLeftEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1531         { "MoveToRightEndOfLine", {89, executeMoveToRightEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1532         { "MoveToRightEndOfLineAndModifySelection", {90, executeMoveToRightEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1533         { "MoveUp", {91, executeMoveUp, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1534         { "MoveUpAndModifySelection", {92, executeMoveUpAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1535         { "MoveWordBackward", {93, executeMoveWordBackward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1536         { "MoveWordBackwardAndModifySelection", {94, executeMoveWordBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1537         { "MoveWordForward", {95, executeMoveWordForward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1538         { "MoveWordForwardAndModifySelection", {96, executeMoveWordForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1539         { "MoveWordLeft", {97, executeMoveWordLeft, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1540         { "MoveWordLeftAndModifySelection", {98, executeMoveWordLeftAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1541         { "MoveWordRight", {99, executeMoveWordRight, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1542         { "MoveWordRightAndModifySelection", {100, executeMoveWordRightAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1543         { "Outdent", {101, executeOutdent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1544         { "OverWrite", {102, executeToggleOverwrite, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1545         { "Paste", {103, executePaste, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1546         { "PasteAndMatchStyle", {104, executePasteAndMatchStyle, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1547         { "PasteGlobalSelection", {105, executePasteGlobalSelection, supportedFromMenuOrKeyBinding, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1548         { "Print", {106, executePrint, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1549         { "Redo", {107, executeRedo, supported, enabledRedo, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1550         { "RemoveFormat", {108, executeRemoveFormat, supported, enabledRangeInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1551         { "ScrollPageBackward", {109, executeScrollPageBackward, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1552         { "ScrollPageForward", {110, executeScrollPageForward, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1553         { "ScrollLineUp", {111, executeScrollLineUp, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1554         { "ScrollLineDown", {112, executeScrollLineDown, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1555         { "ScrollToBeginningOfDocument", {113, executeScrollToBeginningOfDocument, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1556         { "ScrollToEndOfDocument", {114, executeScrollToEndOfDocument, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1557         { "SelectAll", {115, executeSelectAll, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1558         { "SelectLine", {116, executeSelectLine, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1559         { "SelectParagraph", {117, executeSelectParagraph, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1560         { "SelectSentence", {118, executeSelectSentence, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1561         { "SelectToMark", {119, executeSelectToMark, supportedFromMenuOrKeyBinding, enabledVisibleSelectionAndMark, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1562         { "SelectWord", {120, executeSelectWord, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1563         { "SetMark", {121, executeSetMark, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1564         { "Strikethrough", {122, executeStrikethrough, supported, enabledInRichlyEditableText, stateStrikethrough, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1565         { "StyleWithCSS", {123, executeStyleWithCSS, supported, enabled, stateStyleWithCSS, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1566         { "Subscript", {124, executeSubscript, supported, enabledInRichlyEditableText, stateSubscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1567         { "Superscript", {125, executeSuperscript, supported, enabledInRichlyEditableText, stateSuperscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1568         { "SwapWithMark", {126, executeSwapWithMark, supportedFromMenuOrKeyBinding, enabledVisibleSelectionAndMark, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1569         { "ToggleBold", {127, executeToggleBold, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1570         { "ToggleItalic", {128, executeToggleItalic, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateItalic, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1571         { "ToggleUnderline", {129, executeUnderline, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateUnderline, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1572         { "Transpose", {130, executeTranspose, supported, enableCaretInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1573         { "Underline", {131, executeUnderline, supported, enabledInRichlyEditableText, stateUnderline, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1574         { "Undo", {132, executeUndo, supported, enabledUndo, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1575         { "Unlink", {133, executeUnlink, supported, enabledRangeInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1576         { "Unscript", {134, executeUnscript, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1577         { "Unselect", {135, executeUnselect, supported, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1578         { "UseCSS", {136, executeUseCSS, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1579         { "Yank", {137, executeYank, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1580         { "YankAndSelect", {138, executeYankAndSelect, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1581     };
1582
1583     // These unsupported commands are listed here since they appear in the Microsoft
1584     // documentation used as the starting point for our DOM executeCommand support.
1585     //
1586     // 2D-Position (not supported)
1587     // AbsolutePosition (not supported)
1588     // BlockDirLTR (not supported)
1589     // BlockDirRTL (not supported)
1590     // BrowseMode (not supported)
1591     // ClearAuthenticationCache (not supported)
1592     // CreateBookmark (not supported)
1593     // DirLTR (not supported)
1594     // DirRTL (not supported)
1595     // EditMode (not supported)
1596     // InlineDirLTR (not supported)
1597     // InlineDirRTL (not supported)
1598     // InsertButton (not supported)
1599     // InsertFieldSet (not supported)
1600     // InsertIFrame (not supported)
1601     // InsertInputButton (not supported)
1602     // InsertInputCheckbox (not supported)
1603     // InsertInputFileUpload (not supported)
1604     // InsertInputHidden (not supported)
1605     // InsertInputImage (not supported)
1606     // InsertInputPassword (not supported)
1607     // InsertInputRadio (not supported)
1608     // InsertInputReset (not supported)
1609     // InsertInputSubmit (not supported)
1610     // InsertInputText (not supported)
1611     // InsertMarquee (not supported)
1612     // InsertSelectDropDown (not supported)
1613     // InsertSelectListBox (not supported)
1614     // InsertTextArea (not supported)
1615     // LiveResize (not supported)
1616     // MultipleSelection (not supported)
1617     // Open (not supported)
1618     // PlayImage (not supported)
1619     // Refresh (not supported)
1620     // RemoveParaFormat (not supported)
1621     // SaveAs (not supported)
1622     // SizeToControl (not supported)
1623     // SizeToControlHeight (not supported)
1624     // SizeToControlWidth (not supported)
1625     // Stop (not supported)
1626     // StopImage (not supported)
1627     // Unbookmark (not supported)
1628
1629     CommandMap& commandMap = *new CommandMap;
1630 #if !ASSERT_DISABLED
1631     HashSet<int> idSet;
1632 #endif
1633     for (size_t i = 0; i < WTF_ARRAY_LENGTH(commands); ++i) {
1634         const CommandEntry& command = commands[i];
1635         ASSERT(!commandMap.get(command.name));
1636         commandMap.set(command.name, &command.command);
1637 #if !ASSERT_DISABLED
1638         ASSERT(!idSet.contains(command.command.idForUserMetrics));
1639         idSet.add(command.command.idForUserMetrics);
1640 #endif
1641     }
1642
1643     return commandMap;
1644 }
1645
1646 static const EditorInternalCommand* internalCommand(const String& commandName)
1647 {
1648     static const CommandMap& commandMap = createCommandMap();
1649     return commandName.isEmpty() ? 0 : commandMap.get(commandName);
1650 }
1651
1652 Editor::Command Editor::command(const String& commandName)
1653 {
1654     return Command(internalCommand(commandName), CommandFromMenuOrKeyBinding, &m_frame);
1655 }
1656
1657 Editor::Command Editor::command(const String& commandName, EditorCommandSource source)
1658 {
1659     return Command(internalCommand(commandName), source, &m_frame);
1660 }
1661
1662 Editor::Command::Command()
1663     : m_command(0)
1664 {
1665 }
1666
1667 Editor::Command::Command(const EditorInternalCommand* command, EditorCommandSource source, PassRefPtr<Frame> frame)
1668     : m_command(command)
1669     , m_source(source)
1670     , m_frame(command ? frame : 0)
1671 {
1672     // Use separate assertions so we can tell which bad thing happened.
1673     if (!command)
1674         ASSERT(!m_frame);
1675     else
1676         ASSERT(m_frame);
1677 }
1678
1679 bool Editor::Command::execute(const String& parameter, Event* triggeringEvent) const
1680 {
1681     if (!isEnabled(triggeringEvent)) {
1682         // Let certain commands be executed when performed explicitly even if they are disabled.
1683         if (!isSupported() || !m_frame || !m_command->allowExecutionWhenDisabled)
1684             return false;
1685     }
1686     m_frame->document()->updateLayoutIgnorePendingStylesheets();
1687     blink::Platform::current()->histogramSparse("WebCore.Editing.Commands", m_command->idForUserMetrics);
1688     return m_command->execute(*m_frame, triggeringEvent, m_source, parameter);
1689 }
1690
1691 bool Editor::Command::execute(Event* triggeringEvent) const
1692 {
1693     return execute(String(), triggeringEvent);
1694 }
1695
1696 bool Editor::Command::isSupported() const
1697 {
1698     if (!m_command)
1699         return false;
1700     switch (m_source) {
1701     case CommandFromMenuOrKeyBinding:
1702         return true;
1703     case CommandFromDOM:
1704     case CommandFromDOMWithUserInterface:
1705         return m_command->isSupportedFromDOM(m_frame.get());
1706     }
1707     ASSERT_NOT_REACHED();
1708     return false;
1709 }
1710
1711 bool Editor::Command::isEnabled(Event* triggeringEvent) const
1712 {
1713     if (!isSupported() || !m_frame)
1714         return false;
1715     return m_command->isEnabled(*m_frame, triggeringEvent, m_source);
1716 }
1717
1718 TriState Editor::Command::state(Event* triggeringEvent) const
1719 {
1720     if (!isSupported() || !m_frame)
1721         return FalseTriState;
1722     return m_command->state(*m_frame, triggeringEvent);
1723 }
1724
1725 String Editor::Command::value(Event* triggeringEvent) const
1726 {
1727     if (!isSupported() || !m_frame)
1728         return String();
1729     if (m_command->value == valueNull && m_command->state != stateNone)
1730         return m_command->state(*m_frame, triggeringEvent) == TrueTriState ? "true" : "false";
1731     return m_command->value(*m_frame, triggeringEvent);
1732 }
1733
1734 bool Editor::Command::isTextInsertion() const
1735 {
1736     return m_command && m_command->isTextInsertion;
1737 }
1738
1739 } // namespace WebCore