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.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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.
31 #include "CSSComputedStyleDeclaration.h"
32 #include "CSSMutableStyleDeclaration.h"
33 #include "CSSPropertyNames.h"
34 #include "CSSValueKeywords.h"
35 #include "CSSValueList.h"
37 #include "CreateLinkCommand.h"
38 #include "DocumentFragment.h"
39 #include "EditorClient.h"
41 #include "EventHandler.h"
42 #include "FormatBlockCommand.h"
44 #include "FrameView.h"
45 #include "HTMLFontElement.h"
46 #include "HTMLHRElement.h"
47 #include "HTMLImageElement.h"
48 #include "IndentOutdentCommand.h"
49 #include "InsertListCommand.h"
52 #include "RenderBox.h"
53 #include "ReplaceSelectionCommand.h"
54 #include "Scrollbar.h"
57 #include "TypingCommand.h"
58 #include "UnlinkCommand.h"
59 #include "htmlediting.h"
61 #include <wtf/text/AtomicString.h>
65 using namespace HTMLNames;
67 class EditorInternalCommand {
69 bool (*execute)(Frame*, Event*, EditorCommandSource, const String&);
70 bool (*isSupportedFromDOM)(Frame*);
71 bool (*isEnabled)(Frame*, Event*, EditorCommandSource);
72 TriState (*state)(Frame*, Event*);
73 String (*value)(Frame*, Event*);
75 bool allowExecutionWhenDisabled;
78 typedef HashMap<String, const EditorInternalCommand*, CaseFoldingHash> CommandMap;
80 static const bool notTextInsertion = false;
81 static const bool isTextInsertion = true;
83 static const bool allowExecutionWhenDisabled = true;
84 static const bool doNotAllowExecutionWhenDisabled = false;
86 // Related to Editor::selectionForCommand.
87 // Certain operations continue to use the target control's selection even if the event handler
88 // already moved the selection outside of the text control.
89 static Frame* targetFrame(Frame* frame, Event* event)
93 Node* node = event->target()->toNode();
96 return node->document()->frame();
99 static bool applyCommandToFrame(Frame* frame, EditorCommandSource source, EditAction action, CSSMutableStyleDeclaration* style)
101 // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a good reason for that?
103 case CommandFromMenuOrKeyBinding:
104 frame->editor()->applyStyleToSelection(style, action);
107 case CommandFromDOMWithUserInterface:
108 frame->editor()->applyStyle(style);
111 ASSERT_NOT_REACHED();
115 static bool executeApplyStyle(Frame* frame, EditorCommandSource source, EditAction action, int propertyID, const String& propertyValue)
117 RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
118 style->setProperty(propertyID, propertyValue);
119 return applyCommandToFrame(frame, source, action, style.get());
122 static bool executeApplyStyle(Frame* frame, EditorCommandSource source, EditAction action, int propertyID, int propertyValue)
124 RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
125 style->setProperty(propertyID, propertyValue);
126 return applyCommandToFrame(frame, source, action, style.get());
129 // FIXME: executeToggleStyleInList does not handle complicated cases such as <b><u>hello</u>world</b> properly.
130 // This function must use Editor::selectionHasStyle to determine the current style but we cannot fix this
131 // until https://bugs.webkit.org/show_bug.cgi?id=27818 is resolved.
132 static bool executeToggleStyleInList(Frame* frame, EditorCommandSource source, EditAction action, int propertyID, CSSValue* value)
134 ExceptionCode ec = 0;
135 RefPtr<EditingStyle> selectionStyle = frame->editor()->selectionStartStyle();
136 if (!selectionStyle || !selectionStyle->style())
139 RefPtr<CSSValue> selectedCSSValue = selectionStyle->style()->getPropertyCSSValue(propertyID);
140 String newStyle = "none";
141 if (selectedCSSValue->isValueList()) {
142 RefPtr<CSSValueList> selectedCSSValueList = static_cast<CSSValueList*>(selectedCSSValue.get());
143 if (!selectedCSSValueList->removeAll(value))
144 selectedCSSValueList->append(value);
145 if (selectedCSSValueList->length())
146 newStyle = selectedCSSValueList->cssText();
148 } else if (selectedCSSValue->cssText() == "none")
149 newStyle = value->cssText();
151 // FIXME: We shouldn't be having to convert new style into text. We should have setPropertyCSSValue.
152 RefPtr<CSSMutableStyleDeclaration> newMutableStyle = CSSMutableStyleDeclaration::create();
153 newMutableStyle->setProperty(propertyID, newStyle, ec);
154 return applyCommandToFrame(frame, source, action, newMutableStyle.get());
157 static bool executeToggleStyle(Frame* frame, EditorCommandSource source, EditAction action, int propertyID, const char* offValue, const char* onValue)
159 // Style is considered present when
160 // Mac: present at the beginning of selection
161 // other: present throughout the selection
164 if (frame->editor()->behavior().shouldToggleStyleBasedOnStartOfSelection())
165 styleIsPresent = frame->editor()->selectionStartHasStyle(propertyID, onValue);
167 styleIsPresent = frame->editor()->selectionHasStyle(propertyID, onValue) == TrueTriState;
169 RefPtr<EditingStyle> style = EditingStyle::create(propertyID, styleIsPresent ? offValue : onValue);
170 return applyCommandToFrame(frame, source, action, style->style());
173 static bool executeApplyParagraphStyle(Frame* frame, EditorCommandSource source, EditAction action, int propertyID, const String& propertyValue)
175 RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
176 style->setProperty(propertyID, propertyValue);
177 // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a good reason for that?
179 case CommandFromMenuOrKeyBinding:
180 frame->editor()->applyParagraphStyleToSelection(style.get(), action);
183 case CommandFromDOMWithUserInterface:
184 frame->editor()->applyParagraphStyle(style.get());
187 ASSERT_NOT_REACHED();
191 static bool executeInsertFragment(Frame* frame, PassRefPtr<DocumentFragment> fragment)
193 applyCommand(ReplaceSelectionCommand::create(frame->document(), fragment, ReplaceSelectionCommand::PreventNesting, EditActionUnspecified));
197 static bool executeInsertNode(Frame* frame, PassRefPtr<Node> content)
199 RefPtr<DocumentFragment> fragment = DocumentFragment::create(frame->document());
200 ExceptionCode ec = 0;
201 fragment->appendChild(content, ec);
204 return executeInsertFragment(frame, fragment.release());
207 static bool expandSelectionToGranularity(Frame* frame, TextGranularity granularity)
209 VisibleSelection selection = frame->selection()->selection();
210 selection.expandUsingGranularity(granularity);
211 RefPtr<Range> newRange = selection.toNormalizedRange();
214 ExceptionCode ec = 0;
215 if (newRange->collapsed(ec))
217 RefPtr<Range> oldRange = frame->selection()->selection().toNormalizedRange();
218 EAffinity affinity = frame->selection()->affinity();
219 if (!frame->editor()->client()->shouldChangeSelectedRange(oldRange.get(), newRange.get(), affinity, false))
221 frame->selection()->setSelectedRange(newRange.get(), affinity, true);
225 static TriState stateStyle(Frame* frame, int propertyID, const char* desiredValue)
227 if (frame->editor()->behavior().shouldToggleStyleBasedOnStartOfSelection())
228 return frame->editor()->selectionStartHasStyle(propertyID, desiredValue) ? TrueTriState : FalseTriState;
229 return frame->editor()->selectionHasStyle(propertyID, desiredValue);
232 static String valueStyle(Frame* frame, int propertyID)
234 // FIXME: Rather than retrieving the style at the start of the current selection,
235 // we should retrieve the style present throughout the selection for non-Mac platforms.
236 return frame->editor()->selectionStartCSSPropertyValue(propertyID);
239 static TriState stateTextWritingDirection(Frame* frame, WritingDirection direction)
241 bool hasNestedOrMultipleEmbeddings;
242 WritingDirection selectionDirection = frame->editor()->textDirectionForSelection(hasNestedOrMultipleEmbeddings);
243 return (selectionDirection == direction && !hasNestedOrMultipleEmbeddings) ? TrueTriState : FalseTriState;
246 static int verticalScrollDistance(Frame* frame)
248 Node* focusedNode = frame->document()->focusedNode();
251 RenderObject* renderer = focusedNode->renderer();
252 if (!renderer || !renderer->isBox())
254 RenderStyle* style = renderer->style();
257 if (!(style->overflowY() == OSCROLL || style->overflowY() == OAUTO || focusedNode->isContentEditable()))
259 int height = std::min<int>(toRenderBox(renderer)->clientHeight(),
260 frame->view()->visibleHeight());
261 return max(max<int>(height * Scrollbar::minFractionToStepWhenPaging(), height - Scrollbar::maxOverlapBetweenPages()), 1);
264 static RefPtr<Range> unionDOMRanges(Range* a, Range* b)
266 ExceptionCode ec = 0;
267 Range* start = a->compareBoundaryPoints(Range::START_TO_START, b, ec) <= 0 ? a : b;
269 Range* end = a->compareBoundaryPoints(Range::END_TO_END, b, ec) <= 0 ? b : a;
272 return Range::create(a->startContainer(ec)->ownerDocument(), start->startContainer(ec), start->startOffset(ec), end->endContainer(ec), end->endOffset(ec));
275 // Execute command functions
277 static bool executeBackColor(Frame* frame, Event*, EditorCommandSource source, const String& value)
279 return executeApplyStyle(frame, source, EditActionSetBackgroundColor, CSSPropertyBackgroundColor, value);
282 static bool executeCopy(Frame* frame, Event*, EditorCommandSource, const String&)
284 frame->editor()->copy();
288 static bool executeCreateLink(Frame* frame, Event*, EditorCommandSource, const String& value)
290 // FIXME: If userInterface is true, we should display a dialog box to let the user enter a URL.
293 applyCommand(CreateLinkCommand::create(frame->document(), value));
297 static bool executeCut(Frame* frame, Event*, EditorCommandSource, const String&)
299 frame->editor()->cut();
303 static bool executeDelete(Frame* frame, Event*, EditorCommandSource source, const String&)
306 case CommandFromMenuOrKeyBinding:
307 // Doesn't modify the text if the current selection isn't a range.
308 frame->editor()->performDelete();
311 case CommandFromDOMWithUserInterface:
312 // If the current selection is a caret, delete the preceding character. IE performs forwardDelete, but we currently side with Firefox.
313 // Doesn't scroll to make the selection visible, or modify the kill ring (this time, siding with IE, not Firefox).
314 TypingCommand::deleteKeyPressed(frame->document(), frame->selection()->granularity() == WordGranularity);
317 ASSERT_NOT_REACHED();
321 static bool executeDeleteBackward(Frame* frame, Event*, EditorCommandSource, const String&)
323 frame->editor()->deleteWithDirection(DirectionBackward, CharacterGranularity, false, true);
327 static bool executeDeleteBackwardByDecomposingPreviousCharacter(Frame* frame, Event*, EditorCommandSource, const String&)
329 LOG_ERROR("DeleteBackwardByDecomposingPreviousCharacter is not implemented, doing DeleteBackward instead");
330 frame->editor()->deleteWithDirection(DirectionBackward, CharacterGranularity, false, true);
334 static bool executeDeleteForward(Frame* frame, Event*, EditorCommandSource, const String&)
336 frame->editor()->deleteWithDirection(DirectionForward, CharacterGranularity, false, true);
340 static bool executeDeleteToBeginningOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
342 frame->editor()->deleteWithDirection(DirectionBackward, LineBoundary, true, false);
346 static bool executeDeleteToBeginningOfParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
348 frame->editor()->deleteWithDirection(DirectionBackward, ParagraphBoundary, true, false);
352 static bool executeDeleteToEndOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
354 // Despite its name, this command should delete the newline at the end of
355 // a paragraph if you are at the end of a paragraph (like DeleteToEndOfParagraph).
356 frame->editor()->deleteWithDirection(DirectionForward, LineBoundary, true, false);
360 static bool executeDeleteToEndOfParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
362 // Despite its name, this command should delete the newline at the end of
363 // a paragraph if you are at the end of a paragraph.
364 frame->editor()->deleteWithDirection(DirectionForward, ParagraphBoundary, true, false);
368 static bool executeDeleteToMark(Frame* frame, Event*, EditorCommandSource, const String&)
370 RefPtr<Range> mark = frame->editor()->mark().toNormalizedRange();
372 SelectionController* selection = frame->selection();
373 bool selected = selection->setSelectedRange(unionDOMRanges(mark.get(), frame->editor()->selectedRange().get()).get(), DOWNSTREAM, true);
378 frame->editor()->performDelete();
379 frame->editor()->setMark(frame->selection()->selection());
383 static bool executeDeleteWordBackward(Frame* frame, Event*, EditorCommandSource, const String&)
385 frame->editor()->deleteWithDirection(DirectionBackward, WordGranularity, true, false);
389 static bool executeDeleteWordForward(Frame* frame, Event*, EditorCommandSource, const String&)
391 frame->editor()->deleteWithDirection(DirectionForward, WordGranularity, true, false);
395 static bool executeFindString(Frame* frame, Event*, EditorCommandSource, const String& value)
397 return frame->editor()->findString(value, true, false, true, false);
400 static bool executeFontName(Frame* frame, Event*, EditorCommandSource source, const String& value)
402 return executeApplyStyle(frame, source, EditActionSetFont, CSSPropertyFontFamily, value);
405 static bool executeFontSize(Frame* frame, Event*, EditorCommandSource source, const String& value)
408 if (!HTMLFontElement::cssValueFromFontSizeNumber(value, size))
410 return executeApplyStyle(frame, source, EditActionChangeAttributes, CSSPropertyFontSize, size);
413 static bool executeFontSizeDelta(Frame* frame, Event*, EditorCommandSource source, const String& value)
415 return executeApplyStyle(frame, source, EditActionChangeAttributes, CSSPropertyWebkitFontSizeDelta, value);
418 static bool executeForeColor(Frame* frame, Event*, EditorCommandSource source, const String& value)
420 return executeApplyStyle(frame, source, EditActionSetColor, CSSPropertyColor, value);
423 static bool executeFormatBlock(Frame* frame, Event*, EditorCommandSource, const String& value)
425 String tagName = value.lower();
426 if (tagName[0] == '<' && tagName[tagName.length() - 1] == '>')
427 tagName = tagName.substring(1, tagName.length() - 2);
430 String localName, prefix;
431 if (!Document::parseQualifiedName(tagName, prefix, localName, ec))
433 QualifiedName qualifiedTagName(prefix, localName, xhtmlNamespaceURI);
435 RefPtr<FormatBlockCommand> command = FormatBlockCommand::create(frame->document(), qualifiedTagName);
436 applyCommand(command);
437 return command->didApply();
440 static bool executeForwardDelete(Frame* frame, Event*, EditorCommandSource source, const String&)
443 case CommandFromMenuOrKeyBinding:
444 frame->editor()->deleteWithDirection(DirectionForward, CharacterGranularity, false, true);
447 case CommandFromDOMWithUserInterface:
448 // Doesn't scroll to make the selection visible, or modify the kill ring.
449 // ForwardDelete is not implemented in IE or Firefox, so this behavior is only needed for
450 // backward compatibility with ourselves, and for consistency with Delete.
451 TypingCommand::forwardDeleteKeyPressed(frame->document());
454 ASSERT_NOT_REACHED();
458 static bool executeIgnoreSpelling(Frame* frame, Event*, EditorCommandSource, const String&)
460 frame->editor()->ignoreSpelling();
464 static bool executeIndent(Frame* frame, Event*, EditorCommandSource, const String&)
466 applyCommand(IndentOutdentCommand::create(frame->document(), IndentOutdentCommand::Indent));
470 static bool executeInsertBacktab(Frame* frame, Event* event, EditorCommandSource, const String&)
472 return targetFrame(frame, event)->eventHandler()->handleTextInputEvent("\t", event, TextEventInputBackTab);
475 static bool executeInsertHorizontalRule(Frame* frame, Event*, EditorCommandSource, const String& value)
477 RefPtr<HTMLHRElement> rule = HTMLHRElement::create(frame->document());
478 if (!value.isEmpty())
479 rule->setIdAttribute(value);
480 return executeInsertNode(frame, rule.release());
483 static bool executeInsertHTML(Frame* frame, Event*, EditorCommandSource, const String& value)
485 return executeInsertFragment(frame, createFragmentFromMarkup(frame->document(), value, ""));
488 static bool executeInsertImage(Frame* frame, Event*, EditorCommandSource, const String& value)
490 // FIXME: If userInterface is true, we should display a dialog box and let the user choose a local image.
491 RefPtr<HTMLImageElement> image = HTMLImageElement::create(frame->document());
492 image->setSrc(value);
493 return executeInsertNode(frame, image.release());
496 static bool executeInsertLineBreak(Frame* frame, Event* event, EditorCommandSource source, const String&)
499 case CommandFromMenuOrKeyBinding:
500 return targetFrame(frame, event)->eventHandler()->handleTextInputEvent("\n", event, TextEventInputLineBreak);
502 case CommandFromDOMWithUserInterface:
503 // Doesn't scroll to make the selection visible, or modify the kill ring.
504 // InsertLineBreak is not implemented in IE or Firefox, so this behavior is only needed for
505 // backward compatibility with ourselves, and for consistency with other commands.
506 TypingCommand::insertLineBreak(frame->document(), 0);
509 ASSERT_NOT_REACHED();
513 static bool executeInsertNewline(Frame* frame, Event* event, EditorCommandSource, const String&)
515 Frame* targetFrame = WebCore::targetFrame(frame, event);
516 return targetFrame->eventHandler()->handleTextInputEvent("\n", event, targetFrame->editor()->canEditRichly() ? TextEventInputKeyboard : TextEventInputLineBreak);
519 static bool executeInsertNewlineInQuotedContent(Frame* frame, Event*, EditorCommandSource, const String&)
521 TypingCommand::insertParagraphSeparatorInQuotedContent(frame->document());
525 static bool executeInsertOrderedList(Frame* frame, Event*, EditorCommandSource, const String&)
527 applyCommand(InsertListCommand::create(frame->document(), InsertListCommand::OrderedList));
531 static bool executeInsertParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
533 TypingCommand::insertParagraphSeparator(frame->document(), 0);
537 static bool executeInsertTab(Frame* frame, Event* event, EditorCommandSource, const String&)
539 return targetFrame(frame, event)->eventHandler()->handleTextInputEvent("\t", event);
542 static bool executeInsertText(Frame* frame, Event*, EditorCommandSource, const String& value)
544 TypingCommand::insertText(frame->document(), value, 0);
548 static bool executeInsertUnorderedList(Frame* frame, Event*, EditorCommandSource, const String&)
550 applyCommand(InsertListCommand::create(frame->document(), InsertListCommand::UnorderedList));
554 static bool executeJustifyCenter(Frame* frame, Event*, EditorCommandSource source, const String&)
556 return executeApplyParagraphStyle(frame, source, EditActionCenter, CSSPropertyTextAlign, "center");
559 static bool executeJustifyFull(Frame* frame, Event*, EditorCommandSource source, const String&)
561 return executeApplyParagraphStyle(frame, source, EditActionJustify, CSSPropertyTextAlign, "justify");
564 static bool executeJustifyLeft(Frame* frame, Event*, EditorCommandSource source, const String&)
566 return executeApplyParagraphStyle(frame, source, EditActionAlignLeft, CSSPropertyTextAlign, "left");
569 static bool executeJustifyRight(Frame* frame, Event*, EditorCommandSource source, const String&)
571 return executeApplyParagraphStyle(frame, source, EditActionAlignRight, CSSPropertyTextAlign, "right");
574 static bool executeMakeTextWritingDirectionLeftToRight(Frame* frame, Event*, EditorCommandSource, const String&)
576 RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
577 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed);
578 style->setProperty(CSSPropertyDirection, CSSValueLtr);
579 frame->editor()->applyStyle(style.get(), EditActionSetWritingDirection);
583 static bool executeMakeTextWritingDirectionNatural(Frame* frame, Event*, EditorCommandSource, const String&)
585 RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
586 style->setProperty(CSSPropertyUnicodeBidi, CSSValueNormal);
587 frame->editor()->applyStyle(style.get(), EditActionSetWritingDirection);
591 static bool executeMakeTextWritingDirectionRightToLeft(Frame* frame, Event*, EditorCommandSource, const String&)
593 RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
594 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed);
595 style->setProperty(CSSPropertyDirection, CSSValueRtl);
596 frame->editor()->applyStyle(style.get(), EditActionSetWritingDirection);
600 static bool executeMoveBackward(Frame* frame, Event*, EditorCommandSource, const String&)
602 frame->selection()->modify(SelectionController::AlterationMove, DirectionBackward, CharacterGranularity, true);
606 static bool executeMoveBackwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
608 frame->selection()->modify(SelectionController::AlterationExtend, DirectionBackward, CharacterGranularity, true);
612 static bool executeMoveDown(Frame* frame, Event*, EditorCommandSource, const String&)
614 return frame->selection()->modify(SelectionController::AlterationMove, DirectionForward, LineGranularity, true);
617 static bool executeMoveDownAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
619 frame->selection()->modify(SelectionController::AlterationExtend, DirectionForward, LineGranularity, true);
623 static bool executeMoveForward(Frame* frame, Event*, EditorCommandSource, const String&)
625 frame->selection()->modify(SelectionController::AlterationMove, DirectionForward, CharacterGranularity, true);
629 static bool executeMoveForwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
631 frame->selection()->modify(SelectionController::AlterationExtend, DirectionForward, CharacterGranularity, true);
635 static bool executeMoveLeft(Frame* frame, Event*, EditorCommandSource, const String&)
637 return frame->selection()->modify(SelectionController::AlterationMove, DirectionLeft, CharacterGranularity, true);
640 static bool executeMoveLeftAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
642 frame->selection()->modify(SelectionController::AlterationExtend, DirectionLeft, CharacterGranularity, true);
646 static bool executeMovePageDown(Frame* frame, Event*, EditorCommandSource, const String&)
648 int distance = verticalScrollDistance(frame);
651 return frame->selection()->modify(SelectionController::AlterationMove, distance, true, SelectionController::AlignCursorOnScrollAlways);
654 static bool executeMovePageDownAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
656 int distance = verticalScrollDistance(frame);
659 return frame->selection()->modify(SelectionController::AlterationExtend, distance, true, SelectionController::AlignCursorOnScrollAlways);
662 static bool executeMovePageUp(Frame* frame, Event*, EditorCommandSource, const String&)
664 int distance = verticalScrollDistance(frame);
667 return frame->selection()->modify(SelectionController::AlterationMove, -distance, true, SelectionController::AlignCursorOnScrollAlways);
670 static bool executeMovePageUpAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
672 int distance = verticalScrollDistance(frame);
675 return frame->selection()->modify(SelectionController::AlterationExtend, -distance, true, SelectionController::AlignCursorOnScrollAlways);
678 static bool executeMoveRight(Frame* frame, Event*, EditorCommandSource, const String&)
680 return frame->selection()->modify(SelectionController::AlterationMove, DirectionRight, CharacterGranularity, true);
683 static bool executeMoveRightAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
685 frame->selection()->modify(SelectionController::AlterationExtend, DirectionRight, CharacterGranularity, true);
689 static bool executeMoveToBeginningOfDocument(Frame* frame, Event*, EditorCommandSource, const String&)
691 frame->selection()->modify(SelectionController::AlterationMove, DirectionBackward, DocumentBoundary, true);
695 static bool executeMoveToBeginningOfDocumentAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
697 frame->selection()->modify(SelectionController::AlterationExtend, DirectionBackward, DocumentBoundary, true);
701 static bool executeMoveToBeginningOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
703 frame->selection()->modify(SelectionController::AlterationMove, DirectionBackward, LineBoundary, true);
707 static bool executeMoveToBeginningOfLineAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
709 frame->selection()->modify(SelectionController::AlterationExtend, DirectionBackward, LineBoundary, true);
713 static bool executeMoveToBeginningOfParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
715 frame->selection()->modify(SelectionController::AlterationMove, DirectionBackward, ParagraphBoundary, true);
719 static bool executeMoveToBeginningOfParagraphAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
721 frame->selection()->modify(SelectionController::AlterationExtend, DirectionBackward, ParagraphBoundary, true);
725 static bool executeMoveToBeginningOfSentence(Frame* frame, Event*, EditorCommandSource, const String&)
727 frame->selection()->modify(SelectionController::AlterationMove, DirectionBackward, SentenceBoundary, true);
731 static bool executeMoveToBeginningOfSentenceAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
733 frame->selection()->modify(SelectionController::AlterationExtend, DirectionBackward, SentenceBoundary, true);
737 static bool executeMoveToEndOfDocument(Frame* frame, Event*, EditorCommandSource, const String&)
739 frame->selection()->modify(SelectionController::AlterationMove, DirectionForward, DocumentBoundary, true);
743 static bool executeMoveToEndOfDocumentAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
745 frame->selection()->modify(SelectionController::AlterationExtend, DirectionForward, DocumentBoundary, true);
749 static bool executeMoveToEndOfSentence(Frame* frame, Event*, EditorCommandSource, const String&)
751 frame->selection()->modify(SelectionController::AlterationMove, DirectionForward, SentenceBoundary, true);
755 static bool executeMoveToEndOfSentenceAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
757 frame->selection()->modify(SelectionController::AlterationExtend, DirectionForward, SentenceBoundary, true);
761 static bool executeMoveToEndOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
763 frame->selection()->modify(SelectionController::AlterationMove, DirectionForward, LineBoundary, true);
767 static bool executeMoveToEndOfLineAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
769 frame->selection()->modify(SelectionController::AlterationExtend, DirectionForward, LineBoundary, true);
773 static bool executeMoveToEndOfParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
775 frame->selection()->modify(SelectionController::AlterationMove, DirectionForward, ParagraphBoundary, true);
779 static bool executeMoveToEndOfParagraphAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
781 frame->selection()->modify(SelectionController::AlterationExtend, DirectionForward, ParagraphBoundary, true);
785 static bool executeMoveParagraphBackwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
787 frame->selection()->modify(SelectionController::AlterationExtend, DirectionBackward, ParagraphGranularity, true);
791 static bool executeMoveParagraphForwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
793 frame->selection()->modify(SelectionController::AlterationExtend, DirectionForward, ParagraphGranularity, true);
797 static bool executeMoveUp(Frame* frame, Event*, EditorCommandSource, const String&)
799 return frame->selection()->modify(SelectionController::AlterationMove, DirectionBackward, LineGranularity, true);
802 static bool executeMoveUpAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
804 frame->selection()->modify(SelectionController::AlterationExtend, DirectionBackward, LineGranularity, true);
808 static bool executeMoveWordBackward(Frame* frame, Event*, EditorCommandSource, const String&)
810 frame->selection()->modify(SelectionController::AlterationMove, DirectionBackward, WordGranularity, true);
814 static bool executeMoveWordBackwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
816 frame->selection()->modify(SelectionController::AlterationExtend, DirectionBackward, WordGranularity, true);
820 static bool executeMoveWordForward(Frame* frame, Event*, EditorCommandSource, const String&)
822 frame->selection()->modify(SelectionController::AlterationMove, DirectionForward, WordGranularity, true);
826 static bool executeMoveWordForwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
828 frame->selection()->modify(SelectionController::AlterationExtend, DirectionForward, WordGranularity, true);
832 static bool executeMoveWordLeft(Frame* frame, Event*, EditorCommandSource, const String&)
834 frame->selection()->modify(SelectionController::AlterationMove, DirectionLeft, WordGranularity, true);
838 static bool executeMoveWordLeftAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
840 frame->selection()->modify(SelectionController::AlterationExtend, DirectionLeft, WordGranularity, true);
844 static bool executeMoveWordRight(Frame* frame, Event*, EditorCommandSource, const String&)
846 frame->selection()->modify(SelectionController::AlterationMove, DirectionRight, WordGranularity, true);
850 static bool executeMoveWordRightAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
852 frame->selection()->modify(SelectionController::AlterationExtend, DirectionRight, WordGranularity, true);
856 static bool executeMoveToLeftEndOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
858 frame->selection()->modify(SelectionController::AlterationMove, DirectionLeft, LineBoundary, true);
862 static bool executeMoveToLeftEndOfLineAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
864 frame->selection()->modify(SelectionController::AlterationExtend, DirectionLeft, LineBoundary, true);
868 static bool executeMoveToRightEndOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
870 frame->selection()->modify(SelectionController::AlterationMove, DirectionRight, LineBoundary, true);
874 static bool executeMoveToRightEndOfLineAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
876 frame->selection()->modify(SelectionController::AlterationExtend, DirectionRight, LineBoundary, true);
880 static bool executeOutdent(Frame* frame, Event*, EditorCommandSource, const String&)
882 applyCommand(IndentOutdentCommand::create(frame->document(), IndentOutdentCommand::Outdent));
886 static bool executePaste(Frame* frame, Event*, EditorCommandSource, const String&)
888 frame->editor()->paste();
892 static bool executePasteAndMatchStyle(Frame* frame, Event*, EditorCommandSource, const String&)
894 frame->editor()->pasteAsPlainText();
898 static bool executePasteAsPlainText(Frame* frame, Event*, EditorCommandSource, const String&)
900 frame->editor()->pasteAsPlainText();
904 static bool executePrint(Frame* frame, Event*, EditorCommandSource, const String&)
906 Page* page = frame->page();
909 page->chrome()->print(frame);
913 static bool executeRedo(Frame* frame, Event*, EditorCommandSource, const String&)
915 frame->editor()->redo();
919 static bool executeRemoveFormat(Frame* frame, Event*, EditorCommandSource, const String&)
921 frame->editor()->removeFormattingAndStyle();
925 static bool executeScrollPageBackward(Frame* frame, Event*, EditorCommandSource, const String&)
927 return frame->eventHandler()->logicalScrollRecursively(ScrollBlockDirectionBackward, ScrollByPage);
930 static bool executeScrollPageForward(Frame* frame, Event*, EditorCommandSource, const String&)
932 return frame->eventHandler()->logicalScrollRecursively(ScrollBlockDirectionForward, ScrollByPage);
935 static bool executeScrollToBeginningOfDocument(Frame* frame, Event*, EditorCommandSource, const String&)
937 return frame->eventHandler()->logicalScrollRecursively(ScrollBlockDirectionBackward, ScrollByDocument);
940 static bool executeScrollToEndOfDocument(Frame* frame, Event*, EditorCommandSource, const String&)
942 return frame->eventHandler()->logicalScrollRecursively(ScrollBlockDirectionForward, ScrollByDocument);
945 static bool executeSelectAll(Frame* frame, Event*, EditorCommandSource, const String&)
947 frame->selection()->selectAll();
951 static bool executeSelectLine(Frame* frame, Event*, EditorCommandSource, const String&)
953 return expandSelectionToGranularity(frame, LineGranularity);
956 static bool executeSelectParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
958 return expandSelectionToGranularity(frame, ParagraphGranularity);
961 static bool executeSelectSentence(Frame* frame, Event*, EditorCommandSource, const String&)
963 return expandSelectionToGranularity(frame, SentenceGranularity);
966 static bool executeSelectToMark(Frame* frame, Event*, EditorCommandSource, const String&)
968 RefPtr<Range> mark = frame->editor()->mark().toNormalizedRange();
969 RefPtr<Range> selection = frame->editor()->selectedRange();
970 if (!mark || !selection) {
974 frame->selection()->setSelectedRange(unionDOMRanges(mark.get(), selection.get()).get(), DOWNSTREAM, true);
978 static bool executeSelectWord(Frame* frame, Event*, EditorCommandSource, const String&)
980 return expandSelectionToGranularity(frame, WordGranularity);
983 static bool executeSetMark(Frame* frame, Event*, EditorCommandSource, const String&)
985 frame->editor()->setMark(frame->selection()->selection());
989 static bool executeStrikethrough(Frame* frame, Event*, EditorCommandSource source, const String&)
991 RefPtr<CSSPrimitiveValue> lineThrough = CSSPrimitiveValue::createIdentifier(CSSValueLineThrough);
992 return executeToggleStyleInList(frame, source, EditActionUnderline, CSSPropertyWebkitTextDecorationsInEffect, lineThrough.get());
995 static bool executeStyleWithCSS(Frame* frame, Event*, EditorCommandSource, const String& value)
997 if (value != "false" && value != "true")
1000 frame->editor()->setShouldStyleWithCSS(value == "true" ? true : false);
1004 static bool executeSubscript(Frame* frame, Event*, EditorCommandSource source, const String&)
1006 return executeToggleStyle(frame, source, EditActionSubscript, CSSPropertyVerticalAlign, "baseline", "sub");
1009 static bool executeSuperscript(Frame* frame, Event*, EditorCommandSource source, const String&)
1011 return executeToggleStyle(frame, source, EditActionSuperscript, CSSPropertyVerticalAlign, "baseline", "super");
1014 static bool executeSwapWithMark(Frame* frame, Event*, EditorCommandSource, const String&)
1016 const VisibleSelection& mark = frame->editor()->mark();
1017 const VisibleSelection& selection = frame->selection()->selection();
1018 if (mark.isNone() || selection.isNone()) {
1022 frame->selection()->setSelection(mark);
1023 frame->editor()->setMark(selection);
1028 static bool executeTakeFindStringFromSelection(Frame* frame, Event*, EditorCommandSource, const String&)
1030 frame->editor()->takeFindStringFromSelection();
1035 static bool executeToggleBold(Frame* frame, Event*, EditorCommandSource source, const String&)
1037 return executeToggleStyle(frame, source, EditActionChangeAttributes, CSSPropertyFontWeight, "normal", "bold");
1040 static bool executeToggleItalic(Frame* frame, Event*, EditorCommandSource source, const String&)
1042 return executeToggleStyle(frame, source, EditActionChangeAttributes, CSSPropertyFontStyle, "normal", "italic");
1045 static bool executeTranspose(Frame* frame, Event*, EditorCommandSource, const String&)
1047 frame->editor()->transpose();
1051 static bool executeUnderline(Frame* frame, Event*, EditorCommandSource source, const String&)
1053 RefPtr<CSSPrimitiveValue> underline = CSSPrimitiveValue::createIdentifier(CSSValueUnderline);
1054 return executeToggleStyleInList(frame, source, EditActionUnderline, CSSPropertyWebkitTextDecorationsInEffect, underline.get());
1057 static bool executeUndo(Frame* frame, Event*, EditorCommandSource, const String&)
1059 frame->editor()->undo();
1063 static bool executeUnlink(Frame* frame, Event*, EditorCommandSource, const String&)
1065 applyCommand(UnlinkCommand::create(frame->document()));
1069 static bool executeUnscript(Frame* frame, Event*, EditorCommandSource source, const String&)
1071 return executeApplyStyle(frame, source, EditActionUnscript, CSSPropertyVerticalAlign, "baseline");
1074 static bool executeUnselect(Frame* frame, Event*, EditorCommandSource, const String&)
1076 frame->selection()->clear();
1080 static bool executeYank(Frame* frame, Event*, EditorCommandSource, const String&)
1082 frame->editor()->insertTextWithoutSendingTextEvent(frame->editor()->killRing()->yank(), false, 0);
1083 frame->editor()->killRing()->setToYankedState();
1087 static bool executeYankAndSelect(Frame* frame, Event*, EditorCommandSource, const String&)
1089 frame->editor()->insertTextWithoutSendingTextEvent(frame->editor()->killRing()->yank(), true, 0);
1090 frame->editor()->killRing()->setToYankedState();
1094 #if SUPPORT_AUTOCORRECTION_PANEL
1095 static bool executeCancelOperation(Frame* frame, Event*, EditorCommandSource, const String&)
1097 frame->editor()->handleCancelOperation();
1102 // Supported functions
1104 static bool supported(Frame*)
1109 static bool supportedFromMenuOrKeyBinding(Frame*)
1114 static bool supportedCopyCut(Frame* frame)
1119 Settings* settings = frame->settings();
1120 bool defaultValue = settings && settings->javaScriptCanAccessClipboard();
1122 EditorClient* client = frame->editor()->client();
1123 return client ? client->canCopyCut(defaultValue) : defaultValue;
1126 static bool supportedPaste(Frame* frame)
1131 Settings* settings = frame->settings();
1132 bool defaultValue = settings && settings->javaScriptCanAccessClipboard() && settings->isDOMPasteAllowed();
1134 EditorClient* client = frame->editor()->client();
1135 return client ? client->canPaste(defaultValue) : defaultValue;
1138 // Enabled functions
1140 static bool enabled(Frame*, Event*, EditorCommandSource)
1145 static bool enabledVisibleSelection(Frame* frame, Event* event, EditorCommandSource)
1147 // The term "visible" here includes a caret in editable text or a range in any text.
1148 const VisibleSelection& selection = frame->editor()->selectionForCommand(event);
1149 return (selection.isCaret() && selection.isContentEditable()) || selection.isRange();
1152 static bool caretBrowsingEnabled(Frame* frame)
1154 return frame->settings() && frame->settings()->caretBrowsingEnabled();
1157 static EditorCommandSource dummyEditorCommandSource = static_cast<EditorCommandSource>(0);
1159 static bool enabledVisibleSelectionOrCaretBrowsing(Frame* frame, Event* event, EditorCommandSource)
1161 // The EditorCommandSource parameter is unused in enabledVisibleSelection, so just pass a dummy variable
1162 return caretBrowsingEnabled(frame) || enabledVisibleSelection(frame, event, dummyEditorCommandSource);
1165 static bool enabledVisibleSelectionAndMark(Frame* frame, Event* event, EditorCommandSource)
1167 const VisibleSelection& selection = frame->editor()->selectionForCommand(event);
1168 return ((selection.isCaret() && selection.isContentEditable()) || selection.isRange())
1169 && frame->editor()->mark().isCaretOrRange();
1172 static bool enableCaretInEditableText(Frame* frame, Event* event, EditorCommandSource)
1174 const VisibleSelection& selection = frame->editor()->selectionForCommand(event);
1175 return selection.isCaret() && selection.isContentEditable();
1178 static bool enabledCopy(Frame* frame, Event*, EditorCommandSource)
1180 return frame->editor()->canDHTMLCopy() || frame->editor()->canCopy();
1183 static bool enabledCut(Frame* frame, Event*, EditorCommandSource)
1185 return frame->editor()->canDHTMLCut() || frame->editor()->canCut();
1188 static bool enabledDelete(Frame* frame, Event* event, EditorCommandSource source)
1191 case CommandFromMenuOrKeyBinding:
1192 // "Delete" from menu only affects selected range, just like Cut but without affecting pasteboard
1193 return frame->editor()->canDHTMLCut() || frame->editor()->canCut();
1194 case CommandFromDOM:
1195 case CommandFromDOMWithUserInterface:
1196 // "Delete" from DOM is like delete/backspace keypress, affects selected range if non-empty,
1197 // otherwise removes a character
1198 return frame->editor()->selectionForCommand(event).isContentEditable();
1200 ASSERT_NOT_REACHED();
1204 static bool enabledInEditableText(Frame* frame, Event* event, EditorCommandSource)
1206 return frame->editor()->selectionForCommand(event).isContentEditable();
1209 static bool enabledInEditableTextOrCaretBrowsing(Frame* frame, Event* event, EditorCommandSource)
1211 // The EditorCommandSource parameter is unused in enabledInEditableText, so just pass a dummy variable
1212 return caretBrowsingEnabled(frame) || enabledInEditableText(frame, event, dummyEditorCommandSource);
1215 static bool enabledInRichlyEditableText(Frame* frame, Event*, EditorCommandSource)
1217 return frame->selection()->isCaretOrRange() && frame->selection()->isContentRichlyEditable();
1220 static bool enabledPaste(Frame* frame, Event*, EditorCommandSource)
1222 return frame->editor()->canPaste();
1225 static bool enabledRangeInEditableText(Frame* frame, Event*, EditorCommandSource)
1227 return frame->selection()->isRange() && frame->selection()->isContentEditable();
1230 static bool enabledRangeInRichlyEditableText(Frame* frame, Event*, EditorCommandSource)
1232 return frame->selection()->isRange() && frame->selection()->isContentRichlyEditable();
1235 static bool enabledRedo(Frame* frame, Event*, EditorCommandSource)
1237 return frame->editor()->canRedo();
1241 static bool enabledTakeFindStringFromSelection(Frame* frame, Event*, EditorCommandSource)
1243 return frame->editor()->canCopyExcludingStandaloneImages();
1247 static bool enabledUndo(Frame* frame, Event*, EditorCommandSource)
1249 return frame->editor()->canUndo();
1252 #if SUPPORT_AUTOCORRECTION_PANEL
1253 static bool enabledDismissCorrectionPanel(Frame* frame, Event*, EditorCommandSource)
1255 return frame->editor()->isShowingCorrectionPanel();
1261 static TriState stateNone(Frame*, Event*)
1263 return FalseTriState;
1266 static TriState stateBold(Frame* frame, Event*)
1268 return stateStyle(frame, CSSPropertyFontWeight, "bold");
1271 static TriState stateItalic(Frame* frame, Event*)
1273 return stateStyle(frame, CSSPropertyFontStyle, "italic");
1276 static TriState stateOrderedList(Frame* frame, Event*)
1278 return frame->editor()->selectionOrderedListState();
1281 static TriState stateStrikethrough(Frame* frame, Event*)
1283 return stateStyle(frame, CSSPropertyWebkitTextDecorationsInEffect, "line-through");
1286 static TriState stateStyleWithCSS(Frame* frame, Event*)
1288 return frame->editor()->shouldStyleWithCSS() ? TrueTriState : FalseTriState;
1291 static TriState stateSubscript(Frame* frame, Event*)
1293 return stateStyle(frame, CSSPropertyVerticalAlign, "sub");
1296 static TriState stateSuperscript(Frame* frame, Event*)
1298 return stateStyle(frame, CSSPropertyVerticalAlign, "super");
1301 static TriState stateTextWritingDirectionLeftToRight(Frame* frame, Event*)
1303 return stateTextWritingDirection(frame, LeftToRightWritingDirection);
1306 static TriState stateTextWritingDirectionNatural(Frame* frame, Event*)
1308 return stateTextWritingDirection(frame, NaturalWritingDirection);
1311 static TriState stateTextWritingDirectionRightToLeft(Frame* frame, Event*)
1313 return stateTextWritingDirection(frame, RightToLeftWritingDirection);
1316 static TriState stateUnderline(Frame* frame, Event*)
1318 return stateStyle(frame, CSSPropertyWebkitTextDecorationsInEffect, "underline");
1321 static TriState stateUnorderedList(Frame* frame, Event*)
1323 return frame->editor()->selectionUnorderedListState();
1326 static TriState stateJustifyCenter(Frame* frame, Event*)
1328 return stateStyle(frame, CSSPropertyTextAlign, "center");
1331 static TriState stateJustifyFull(Frame* frame, Event*)
1333 return stateStyle(frame, CSSPropertyTextAlign, "justify");
1336 static TriState stateJustifyLeft(Frame* frame, Event*)
1338 return stateStyle(frame, CSSPropertyTextAlign, "left");
1341 static TriState stateJustifyRight(Frame* frame, Event*)
1343 return stateStyle(frame, CSSPropertyTextAlign, "right");
1348 static String valueNull(Frame*, Event*)
1353 static String valueBackColor(Frame* frame, Event*)
1355 return valueStyle(frame, CSSPropertyBackgroundColor);
1358 static String valueFontName(Frame* frame, Event*)
1360 return valueStyle(frame, CSSPropertyFontFamily);
1363 static String valueFontSize(Frame* frame, Event*)
1365 return valueStyle(frame, CSSPropertyFontSize);
1368 static String valueFontSizeDelta(Frame* frame, Event*)
1370 return valueStyle(frame, CSSPropertyWebkitFontSizeDelta);
1373 static String valueForeColor(Frame* frame, Event*)
1375 return valueStyle(frame, CSSPropertyColor);
1378 static String valueFormatBlock(Frame* frame, Event*)
1380 const VisibleSelection& selection = frame->selection()->selection();
1381 if (!selection.isNonOrphanedCaretOrRange() || !selection.isContentEditable())
1383 Element* formatBlockElement = FormatBlockCommand::elementForFormatBlockCommand(selection.firstRange().get());
1384 if (!formatBlockElement)
1386 return formatBlockElement->localName();
1391 struct CommandEntry {
1393 EditorInternalCommand command;
1396 static const CommandMap& createCommandMap()
1398 static const CommandEntry commands[] = {
1399 { "AlignCenter", { executeJustifyCenter, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1400 { "AlignJustified", { executeJustifyFull, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1401 { "AlignLeft", { executeJustifyLeft, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1402 { "AlignRight", { executeJustifyRight, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1403 { "BackColor", { executeBackColor, supported, enabledInRichlyEditableText, stateNone, valueBackColor, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1404 { "BackwardDelete", { executeDeleteBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, // FIXME: remove BackwardDelete when Safari for Windows stops using it.
1405 { "Bold", { executeToggleBold, supported, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1406 { "Copy", { executeCopy, supportedCopyCut, enabledCopy, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1407 { "CreateLink", { executeCreateLink, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1408 { "Cut", { executeCut, supportedCopyCut, enabledCut, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1409 { "Delete", { executeDelete, supported, enabledDelete, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1410 { "DeleteBackward", { executeDeleteBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1411 { "DeleteBackwardByDecomposingPreviousCharacter", { executeDeleteBackwardByDecomposingPreviousCharacter, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1412 { "DeleteForward", { executeDeleteForward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1413 { "DeleteToBeginningOfLine", { executeDeleteToBeginningOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1414 { "DeleteToBeginningOfParagraph", { executeDeleteToBeginningOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1415 { "DeleteToEndOfLine", { executeDeleteToEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1416 { "DeleteToEndOfParagraph", { executeDeleteToEndOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1417 { "DeleteToMark", { executeDeleteToMark, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1418 { "DeleteWordBackward", { executeDeleteWordBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1419 { "DeleteWordForward", { executeDeleteWordForward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1420 { "FindString", { executeFindString, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1421 { "FontName", { executeFontName, supported, enabledInEditableText, stateNone, valueFontName, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1422 { "FontSize", { executeFontSize, supported, enabledInEditableText, stateNone, valueFontSize, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1423 { "FontSizeDelta", { executeFontSizeDelta, supported, enabledInEditableText, stateNone, valueFontSizeDelta, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1424 { "ForeColor", { executeForeColor, supported, enabledInRichlyEditableText, stateNone, valueForeColor, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1425 { "FormatBlock", { executeFormatBlock, supported, enabledInRichlyEditableText, stateNone, valueFormatBlock, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1426 { "ForwardDelete", { executeForwardDelete, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1427 { "HiliteColor", { executeBackColor, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1428 { "IgnoreSpelling", { executeIgnoreSpelling, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1429 { "Indent", { executeIndent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1430 { "InsertBacktab", { executeInsertBacktab, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1431 { "InsertHTML", { executeInsertHTML, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1432 { "InsertHorizontalRule", { executeInsertHorizontalRule, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1433 { "InsertImage", { executeInsertImage, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1434 { "InsertLineBreak", { executeInsertLineBreak, supported, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1435 { "InsertNewline", { executeInsertNewline, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1436 { "InsertNewlineInQuotedContent", { executeInsertNewlineInQuotedContent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1437 { "InsertOrderedList", { executeInsertOrderedList, supported, enabledInRichlyEditableText, stateOrderedList, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1438 { "InsertParagraph", { executeInsertParagraph, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1439 { "InsertTab", { executeInsertTab, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1440 { "InsertText", { executeInsertText, supported, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1441 { "InsertUnorderedList", { executeInsertUnorderedList, supported, enabledInRichlyEditableText, stateUnorderedList, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1442 { "Italic", { executeToggleItalic, supported, enabledInRichlyEditableText, stateItalic, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1443 { "JustifyCenter", { executeJustifyCenter, supported, enabledInRichlyEditableText, stateJustifyCenter, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1444 { "JustifyFull", { executeJustifyFull, supported, enabledInRichlyEditableText, stateJustifyFull, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1445 { "JustifyLeft", { executeJustifyLeft, supported, enabledInRichlyEditableText, stateJustifyLeft, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1446 { "JustifyNone", { executeJustifyLeft, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1447 { "JustifyRight", { executeJustifyRight, supported, enabledInRichlyEditableText, stateJustifyRight, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1448 { "MakeTextWritingDirectionLeftToRight", { executeMakeTextWritingDirectionLeftToRight, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionLeftToRight, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1449 { "MakeTextWritingDirectionNatural", { executeMakeTextWritingDirectionNatural, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionNatural, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1450 { "MakeTextWritingDirectionRightToLeft", { executeMakeTextWritingDirectionRightToLeft, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionRightToLeft, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1451 { "MoveBackward", { executeMoveBackward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1452 { "MoveBackwardAndModifySelection", { executeMoveBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1453 { "MoveDown", { executeMoveDown, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1454 { "MoveDownAndModifySelection", { executeMoveDownAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1455 { "MoveForward", { executeMoveForward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1456 { "MoveForwardAndModifySelection", { executeMoveForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1457 { "MoveLeft", { executeMoveLeft, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1458 { "MoveLeftAndModifySelection", { executeMoveLeftAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1459 { "MovePageDown", { executeMovePageDown, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1460 { "MovePageDownAndModifySelection", { executeMovePageDownAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1461 { "MovePageUp", { executeMovePageUp, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1462 { "MovePageUpAndModifySelection", { executeMovePageUpAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1463 { "MoveParagraphBackwardAndModifySelection", { executeMoveParagraphBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1464 { "MoveParagraphForwardAndModifySelection", { executeMoveParagraphForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1465 { "MoveRight", { executeMoveRight, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1466 { "MoveRightAndModifySelection", { executeMoveRightAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1467 { "MoveToBeginningOfDocument", { executeMoveToBeginningOfDocument, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1468 { "MoveToBeginningOfDocumentAndModifySelection", { executeMoveToBeginningOfDocumentAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1469 { "MoveToBeginningOfLine", { executeMoveToBeginningOfLine, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1470 { "MoveToBeginningOfLineAndModifySelection", { executeMoveToBeginningOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1471 { "MoveToBeginningOfParagraph", { executeMoveToBeginningOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1472 { "MoveToBeginningOfParagraphAndModifySelection", { executeMoveToBeginningOfParagraphAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1473 { "MoveToBeginningOfSentence", { executeMoveToBeginningOfSentence, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1474 { "MoveToBeginningOfSentenceAndModifySelection", { executeMoveToBeginningOfSentenceAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1475 { "MoveToEndOfDocument", { executeMoveToEndOfDocument, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1476 { "MoveToEndOfDocumentAndModifySelection", { executeMoveToEndOfDocumentAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1477 { "MoveToEndOfLine", { executeMoveToEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1478 { "MoveToEndOfLineAndModifySelection", { executeMoveToEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1479 { "MoveToEndOfParagraph", { executeMoveToEndOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1480 { "MoveToEndOfParagraphAndModifySelection", { executeMoveToEndOfParagraphAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1481 { "MoveToEndOfSentence", { executeMoveToEndOfSentence, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1482 { "MoveToEndOfSentenceAndModifySelection", { executeMoveToEndOfSentenceAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1483 { "MoveToLeftEndOfLine", { executeMoveToLeftEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1484 { "MoveToLeftEndOfLineAndModifySelection", { executeMoveToLeftEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1485 { "MoveToRightEndOfLine", { executeMoveToRightEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1486 { "MoveToRightEndOfLineAndModifySelection", { executeMoveToRightEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1487 { "MoveUp", { executeMoveUp, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1488 { "MoveUpAndModifySelection", { executeMoveUpAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1489 { "MoveWordBackward", { executeMoveWordBackward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1490 { "MoveWordBackwardAndModifySelection", { executeMoveWordBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1491 { "MoveWordForward", { executeMoveWordForward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1492 { "MoveWordForwardAndModifySelection", { executeMoveWordForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1493 { "MoveWordLeft", { executeMoveWordLeft, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1494 { "MoveWordLeftAndModifySelection", { executeMoveWordLeftAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1495 { "MoveWordRight", { executeMoveWordRight, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1496 { "MoveWordRightAndModifySelection", { executeMoveWordRightAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1497 { "Outdent", { executeOutdent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1498 { "Paste", { executePaste, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1499 { "PasteAndMatchStyle", { executePasteAndMatchStyle, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1500 { "PasteAsPlainText", { executePasteAsPlainText, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1501 { "Print", { executePrint, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1502 { "Redo", { executeRedo, supported, enabledRedo, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1503 { "RemoveFormat", { executeRemoveFormat, supported, enabledRangeInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1504 { "ScrollPageBackward", { executeScrollPageBackward, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1505 { "ScrollPageForward", { executeScrollPageForward, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1506 { "ScrollToBeginningOfDocument", { executeScrollToBeginningOfDocument, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1507 { "ScrollToEndOfDocument", { executeScrollToEndOfDocument, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1508 { "SelectAll", { executeSelectAll, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1509 { "SelectLine", { executeSelectLine, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1510 { "SelectParagraph", { executeSelectParagraph, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1511 { "SelectSentence", { executeSelectSentence, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1512 { "SelectToMark", { executeSelectToMark, supportedFromMenuOrKeyBinding, enabledVisibleSelectionAndMark, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1513 { "SelectWord", { executeSelectWord, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1514 { "SetMark", { executeSetMark, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1515 { "Strikethrough", { executeStrikethrough, supported, enabledInRichlyEditableText, stateStrikethrough, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1516 { "StyleWithCSS", { executeStyleWithCSS, supported, enabled, stateStyleWithCSS, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1517 { "Subscript", { executeSubscript, supported, enabledInRichlyEditableText, stateSubscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1518 { "Superscript", { executeSuperscript, supported, enabledInRichlyEditableText, stateSuperscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1519 { "SwapWithMark", { executeSwapWithMark, supportedFromMenuOrKeyBinding, enabledVisibleSelectionAndMark, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1520 { "ToggleBold", { executeToggleBold, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1521 { "ToggleItalic", { executeToggleItalic, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateItalic, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1522 { "ToggleUnderline", { executeUnderline, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateUnderline, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1523 { "Transpose", { executeTranspose, supported, enableCaretInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1524 { "Underline", { executeUnderline, supported, enabledInRichlyEditableText, stateUnderline, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1525 { "Undo", { executeUndo, supported, enabledUndo, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1526 { "Unlink", { executeUnlink, supported, enabledRangeInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1527 { "Unscript", { executeUnscript, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1528 { "Unselect", { executeUnselect, supported, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1529 { "Yank", { executeYank, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1530 { "YankAndSelect", { executeYankAndSelect, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1533 { "TakeFindStringFromSelection", { executeTakeFindStringFromSelection, supportedFromMenuOrKeyBinding, enabledTakeFindStringFromSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1536 #if SUPPORT_AUTOCORRECTION_PANEL
1537 { "CancelOperation", { executeCancelOperation, supportedFromMenuOrKeyBinding, enabledDismissCorrectionPanel, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1541 // These unsupported commands are listed here since they appear in the Microsoft
1542 // documentation used as the starting point for our DOM executeCommand support.
1544 // 2D-Position (not supported)
1545 // AbsolutePosition (not supported)
1546 // BlockDirLTR (not supported)
1547 // BlockDirRTL (not supported)
1548 // BrowseMode (not supported)
1549 // ClearAuthenticationCache (not supported)
1550 // CreateBookmark (not supported)
1551 // DirLTR (not supported)
1552 // DirRTL (not supported)
1553 // EditMode (not supported)
1554 // InlineDirLTR (not supported)
1555 // InlineDirRTL (not supported)
1556 // InsertButton (not supported)
1557 // InsertFieldSet (not supported)
1558 // InsertIFrame (not supported)
1559 // InsertInputButton (not supported)
1560 // InsertInputCheckbox (not supported)
1561 // InsertInputFileUpload (not supported)
1562 // InsertInputHidden (not supported)
1563 // InsertInputImage (not supported)
1564 // InsertInputPassword (not supported)
1565 // InsertInputRadio (not supported)
1566 // InsertInputReset (not supported)
1567 // InsertInputSubmit (not supported)
1568 // InsertInputText (not supported)
1569 // InsertMarquee (not supported)
1570 // InsertSelectDropDown (not supported)
1571 // InsertSelectListBox (not supported)
1572 // InsertTextArea (not supported)
1573 // LiveResize (not supported)
1574 // MultipleSelection (not supported)
1575 // Open (not supported)
1576 // Overwrite (not supported)
1577 // PlayImage (not supported)
1578 // Refresh (not supported)
1579 // RemoveParaFormat (not supported)
1580 // SaveAs (not supported)
1581 // SizeToControl (not supported)
1582 // SizeToControlHeight (not supported)
1583 // SizeToControlWidth (not supported)
1584 // Stop (not supported)
1585 // StopImage (not supported)
1586 // Unbookmark (not supported)
1588 CommandMap& commandMap = *new CommandMap;
1590 for (size_t i = 0; i < WTF_ARRAY_LENGTH(commands); ++i) {
1591 ASSERT(!commandMap.get(commands[i].name));
1592 commandMap.set(commands[i].name, &commands[i].command);
1598 static const EditorInternalCommand* internalCommand(const String& commandName)
1600 static const CommandMap& commandMap = createCommandMap();
1601 return commandName.isEmpty() ? 0 : commandMap.get(commandName);
1604 Editor::Command Editor::command(const String& commandName)
1606 return Command(internalCommand(commandName), CommandFromMenuOrKeyBinding, m_frame);
1609 Editor::Command Editor::command(const String& commandName, EditorCommandSource source)
1611 return Command(internalCommand(commandName), source, m_frame);
1614 bool Editor::commandIsSupportedFromMenuOrKeyBinding(const String& commandName)
1616 return internalCommand(commandName);
1619 Editor::Command::Command()
1624 Editor::Command::Command(const EditorInternalCommand* command, EditorCommandSource source, PassRefPtr<Frame> frame)
1625 : m_command(command)
1627 , m_frame(command ? frame : 0)
1629 // Use separate assertions so we can tell which bad thing happened.
1636 bool Editor::Command::execute(const String& parameter, Event* triggeringEvent) const
1638 if (!isEnabled(triggeringEvent)) {
1639 // Let certain commands be executed when performed explicitly even if they are disabled.
1640 if (!isSupported() || !m_frame || !m_command->allowExecutionWhenDisabled)
1643 m_frame->document()->updateLayoutIgnorePendingStylesheets();
1644 return m_command->execute(m_frame.get(), triggeringEvent, m_source, parameter);
1647 bool Editor::Command::execute(Event* triggeringEvent) const
1649 return execute(String(), triggeringEvent);
1652 bool Editor::Command::isSupported() const
1657 case CommandFromMenuOrKeyBinding:
1659 case CommandFromDOM:
1660 case CommandFromDOMWithUserInterface:
1661 return m_command->isSupportedFromDOM(m_frame.get());
1663 ASSERT_NOT_REACHED();
1667 bool Editor::Command::isEnabled(Event* triggeringEvent) const
1669 if (!isSupported() || !m_frame)
1671 return m_command->isEnabled(m_frame.get(), triggeringEvent, m_source);
1674 TriState Editor::Command::state(Event* triggeringEvent) const
1676 if (!isSupported() || !m_frame)
1677 return FalseTriState;
1678 return m_command->state(m_frame.get(), triggeringEvent);
1681 String Editor::Command::value(Event* triggeringEvent) const
1683 if (!isSupported() || !m_frame)
1685 if (m_command->value == valueNull && m_command->state != stateNone)
1686 return m_command->state(m_frame.get(), triggeringEvent) == TrueTriState ? "true" : "false";
1687 return m_command->value(m_frame.get(), triggeringEvent);
1690 bool Editor::Command::isTextInsertion() const
1692 return m_command && m_command->isTextInsertion;
1695 } // namespace WebCore