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"
36 #include "CreateLinkCommand.h"
37 #include "DocumentFragment.h"
38 #include "EditorClient.h"
40 #include "EventHandler.h"
41 #include "FormatBlockCommand.h"
43 #include "FrameView.h"
44 #include "HTMLFontElement.h"
45 #include "HTMLHRElement.h"
46 #include "HTMLImageElement.h"
47 #include "IndentOutdentCommand.h"
48 #include "InsertListCommand.h"
51 #include "RenderBox.h"
52 #include "ReplaceSelectionCommand.h"
53 #include "Scrollbar.h"
56 #include "TypingCommand.h"
57 #include "UnlinkCommand.h"
58 #include "htmlediting.h"
60 #include <wtf/text/AtomicString.h>
64 using namespace HTMLNames;
66 class EditorInternalCommand {
68 bool (*execute)(Frame*, Event*, EditorCommandSource, const String&);
69 bool (*isSupported)(Frame*, EditorCommandSource);
70 bool (*isEnabled)(Frame*, Event*, EditorCommandSource);
71 TriState (*state)(Frame*, Event*);
72 String (*value)(Frame*, Event*);
74 bool allowExecutionWhenDisabled;
77 typedef HashMap<String, const EditorInternalCommand*, CaseFoldingHash> CommandMap;
79 static const bool notTextInsertion = false;
80 static const bool isTextInsertion = true;
82 static const bool allowExecutionWhenDisabled = true;
83 static const bool doNotAllowExecutionWhenDisabled = false;
85 // Related to Editor::selectionForCommand.
86 // Certain operations continue to use the target control's selection even if the event handler
87 // already moved the selection outside of the text control.
88 static Frame* targetFrame(Frame* frame, Event* event)
92 Node* node = event->target()->toNode();
95 return node->document()->frame();
98 static bool applyCommandToFrame(Frame* frame, EditorCommandSource source, EditAction action, CSSMutableStyleDeclaration* style)
100 // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a good reason for that?
102 case CommandFromMenuOrKeyBinding:
103 frame->editor()->applyStyleToSelection(style, action);
106 case CommandFromDOMWithUserInterface:
107 frame->editor()->applyStyle(style);
110 ASSERT_NOT_REACHED();
114 static bool executeApplyStyle(Frame* frame, EditorCommandSource source, EditAction action, int propertyID, const String& propertyValue)
116 RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
117 style->setProperty(propertyID, propertyValue);
118 return applyCommandToFrame(frame, source, action, style.get());
121 static bool executeApplyStyle(Frame* frame, EditorCommandSource source, EditAction action, int propertyID, int propertyValue)
123 RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
124 style->setProperty(propertyID, propertyValue);
125 return applyCommandToFrame(frame, source, action, style.get());
128 // FIXME: executeToggleStyleInList does not handle complicated cases such as <b><u>hello</u>world</b> properly.
129 // This function must use Editor::selectionHasStyle to determine the current style but we cannot fix this
130 // until https://bugs.webkit.org/show_bug.cgi?id=27818 is resolved.
131 static bool executeToggleStyleInList(Frame* frame, EditorCommandSource source, EditAction action, int propertyID, CSSValue* value)
133 ExceptionCode ec = 0;
134 bool shouldUseFixedFontDefaultSize;
135 RefPtr<CSSMutableStyleDeclaration> selectionStyle = frame->editor()->selectionComputedStyle(shouldUseFixedFontDefaultSize);
139 RefPtr<CSSValue> selectedCSSValue = selectionStyle->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 RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
160 style->setProperty(propertyID, onValue); // We need to add this style to pass it to selectionStartHasStyle / selectionHasStyle
162 // Style is considered present when
163 // Mac: present at the beginning of selection
164 // other: present throughout the selection
167 if (frame->editor()->behavior().shouldToggleStyleBasedOnStartOfSelection())
168 styleIsPresent = frame->editor()->selectionStartHasStyle(style.get());
170 styleIsPresent = frame->editor()->selectionHasStyle(style.get()) == TrueTriState;
172 style->setProperty(propertyID, styleIsPresent ? offValue : onValue);
173 return applyCommandToFrame(frame, source, action, style.get());
176 static bool executeApplyParagraphStyle(Frame* frame, EditorCommandSource source, EditAction action, int propertyID, const String& propertyValue)
178 RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::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?
182 case CommandFromMenuOrKeyBinding:
183 frame->editor()->applyParagraphStyleToSelection(style.get(), action);
186 case CommandFromDOMWithUserInterface:
187 frame->editor()->applyParagraphStyle(style.get());
190 ASSERT_NOT_REACHED();
194 static bool executeInsertFragment(Frame* frame, PassRefPtr<DocumentFragment> fragment)
196 applyCommand(ReplaceSelectionCommand::create(frame->document(), fragment,
197 false, false, false, true, false, EditActionUnspecified));
201 static bool executeInsertNode(Frame* frame, PassRefPtr<Node> content)
203 RefPtr<DocumentFragment> fragment = DocumentFragment::create(frame->document());
204 ExceptionCode ec = 0;
205 fragment->appendChild(content, ec);
208 return executeInsertFragment(frame, fragment.release());
211 static bool expandSelectionToGranularity(Frame* frame, TextGranularity granularity)
213 VisibleSelection selection = frame->selection()->selection();
214 selection.expandUsingGranularity(granularity);
215 RefPtr<Range> newRange = selection.toNormalizedRange();
218 ExceptionCode ec = 0;
219 if (newRange->collapsed(ec))
221 RefPtr<Range> oldRange = frame->selection()->selection().toNormalizedRange();
222 EAffinity affinity = frame->selection()->affinity();
223 if (!frame->editor()->client()->shouldChangeSelectedRange(oldRange.get(), newRange.get(), affinity, false))
225 frame->selection()->setSelectedRange(newRange.get(), affinity, true);
229 static TriState stateStyle(Frame* frame, int propertyID, const char* desiredValue)
231 RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
232 style->setProperty(propertyID, desiredValue);
234 if (frame->editor()->behavior().shouldToggleStyleBasedOnStartOfSelection())
235 return frame->editor()->selectionStartHasStyle(style.get()) ? TrueTriState : FalseTriState;
236 return frame->editor()->selectionHasStyle(style.get());
239 static String valueStyle(Frame* frame, int propertyID)
241 // FIXME: Rather than retrieving the style at the start of the current selection,
242 // we should retrieve the style present throughout the selection for non-Mac platforms.
243 return frame->editor()->selectionStartCSSPropertyValue(propertyID);
246 static TriState stateTextWritingDirection(Frame* frame, WritingDirection direction)
248 bool hasNestedOrMultipleEmbeddings;
249 WritingDirection selectionDirection = frame->editor()->textDirectionForSelection(hasNestedOrMultipleEmbeddings);
250 return (selectionDirection == direction && !hasNestedOrMultipleEmbeddings) ? TrueTriState : FalseTriState;
253 static int verticalScrollDistance(Frame* frame)
255 Node* focusedNode = frame->document()->focusedNode();
258 RenderObject* renderer = focusedNode->renderer();
259 if (!renderer || !renderer->isBox())
261 RenderStyle* style = renderer->style();
264 if (!(style->overflowY() == OSCROLL || style->overflowY() == OAUTO || focusedNode->isContentEditable()))
266 int height = std::min<int>(toRenderBox(renderer)->clientHeight(),
267 frame->view()->visibleHeight());
268 return max(max<int>(height * Scrollbar::minFractionToStepWhenPaging(), height - Scrollbar::maxOverlapBetweenPages()), 1);
271 static RefPtr<Range> unionDOMRanges(Range* a, Range* b)
273 ExceptionCode ec = 0;
274 Range* start = a->compareBoundaryPoints(Range::START_TO_START, b, ec) <= 0 ? a : b;
276 Range* end = a->compareBoundaryPoints(Range::END_TO_END, b, ec) <= 0 ? b : a;
279 return Range::create(a->startContainer(ec)->ownerDocument(), start->startContainer(ec), start->startOffset(ec), end->endContainer(ec), end->endOffset(ec));
282 // Execute command functions
284 static bool executeBackColor(Frame* frame, Event*, EditorCommandSource source, const String& value)
286 return executeApplyStyle(frame, source, EditActionSetBackgroundColor, CSSPropertyBackgroundColor, value);
289 static bool executeCopy(Frame* frame, Event*, EditorCommandSource, const String&)
291 frame->editor()->copy();
295 static bool executeCreateLink(Frame* frame, Event*, EditorCommandSource, const String& value)
297 // FIXME: If userInterface is true, we should display a dialog box to let the user enter a URL.
300 applyCommand(CreateLinkCommand::create(frame->document(), value));
304 static bool executeCut(Frame* frame, Event*, EditorCommandSource, const String&)
306 frame->editor()->cut();
310 static bool executeDelete(Frame* frame, Event*, EditorCommandSource source, const String&)
313 case CommandFromMenuOrKeyBinding:
314 // Doesn't modify the text if the current selection isn't a range.
315 frame->editor()->performDelete();
318 case CommandFromDOMWithUserInterface:
319 // If the current selection is a caret, delete the preceding character. IE performs forwardDelete, but we currently side with Firefox.
320 // Doesn't scroll to make the selection visible, or modify the kill ring (this time, siding with IE, not Firefox).
321 TypingCommand::deleteKeyPressed(frame->document(), frame->selection()->granularity() == WordGranularity);
324 ASSERT_NOT_REACHED();
328 static bool executeDeleteBackward(Frame* frame, Event*, EditorCommandSource, const String&)
330 frame->editor()->deleteWithDirection(SelectionController::DirectionBackward, CharacterGranularity, false, true);
334 static bool executeDeleteBackwardByDecomposingPreviousCharacter(Frame* frame, Event*, EditorCommandSource, const String&)
336 LOG_ERROR("DeleteBackwardByDecomposingPreviousCharacter is not implemented, doing DeleteBackward instead");
337 frame->editor()->deleteWithDirection(SelectionController::DirectionBackward, CharacterGranularity, false, true);
341 static bool executeDeleteForward(Frame* frame, Event*, EditorCommandSource, const String&)
343 frame->editor()->deleteWithDirection(SelectionController::DirectionForward, CharacterGranularity, false, true);
347 static bool executeDeleteToBeginningOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
349 frame->editor()->deleteWithDirection(SelectionController::DirectionBackward, LineBoundary, true, false);
353 static bool executeDeleteToBeginningOfParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
355 frame->editor()->deleteWithDirection(SelectionController::DirectionBackward, ParagraphBoundary, true, false);
359 static bool executeDeleteToEndOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
361 // Despite its name, this command should delete the newline at the end of
362 // a paragraph if you are at the end of a paragraph (like DeleteToEndOfParagraph).
363 frame->editor()->deleteWithDirection(SelectionController::DirectionForward, LineBoundary, true, false);
367 static bool executeDeleteToEndOfParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
369 // Despite its name, this command should delete the newline at the end of
370 // a paragraph if you are at the end of a paragraph.
371 frame->editor()->deleteWithDirection(SelectionController::DirectionForward, ParagraphBoundary, true, false);
375 static bool executeDeleteToMark(Frame* frame, Event*, EditorCommandSource, const String&)
377 RefPtr<Range> mark = frame->editor()->mark().toNormalizedRange();
379 SelectionController* selection = frame->selection();
380 bool selected = selection->setSelectedRange(unionDOMRanges(mark.get(), frame->editor()->selectedRange().get()).get(), DOWNSTREAM, true);
385 frame->editor()->performDelete();
386 frame->editor()->setMark(frame->selection()->selection());
390 static bool executeDeleteWordBackward(Frame* frame, Event*, EditorCommandSource, const String&)
392 frame->editor()->deleteWithDirection(SelectionController::DirectionBackward, WordGranularity, true, false);
396 static bool executeDeleteWordForward(Frame* frame, Event*, EditorCommandSource, const String&)
398 frame->editor()->deleteWithDirection(SelectionController::DirectionForward, WordGranularity, true, false);
402 static bool executeFindString(Frame* frame, Event*, EditorCommandSource, const String& value)
404 return frame->editor()->findString(value, true, false, true, false);
407 static bool executeFontName(Frame* frame, Event*, EditorCommandSource source, const String& value)
409 return executeApplyStyle(frame, source, EditActionSetFont, CSSPropertyFontFamily, value);
412 static bool executeFontSize(Frame* frame, Event*, EditorCommandSource source, const String& value)
415 if (!HTMLFontElement::cssValueFromFontSizeNumber(value, size))
417 return executeApplyStyle(frame, source, EditActionChangeAttributes, CSSPropertyFontSize, size);
420 static bool executeFontSizeDelta(Frame* frame, Event*, EditorCommandSource source, const String& value)
422 return executeApplyStyle(frame, source, EditActionChangeAttributes, CSSPropertyWebkitFontSizeDelta, value);
425 static bool executeForeColor(Frame* frame, Event*, EditorCommandSource source, const String& value)
427 return executeApplyStyle(frame, source, EditActionSetColor, CSSPropertyColor, value);
430 static bool executeFormatBlock(Frame* frame, Event*, EditorCommandSource, const String& value)
432 String tagName = value.lower();
433 if (tagName[0] == '<' && tagName[tagName.length() - 1] == '>')
434 tagName = tagName.substring(1, tagName.length() - 2);
437 String localName, prefix;
438 if (!Document::parseQualifiedName(tagName, prefix, localName, ec))
440 QualifiedName qualifiedTagName(prefix, localName, xhtmlNamespaceURI);
442 RefPtr<FormatBlockCommand> command = FormatBlockCommand::create(frame->document(), qualifiedTagName);
443 applyCommand(command);
444 return command->didApply();
447 static bool executeForwardDelete(Frame* frame, Event*, EditorCommandSource source, const String&)
450 case CommandFromMenuOrKeyBinding:
451 frame->editor()->deleteWithDirection(SelectionController::DirectionForward, CharacterGranularity, false, true);
454 case CommandFromDOMWithUserInterface:
455 // Doesn't scroll to make the selection visible, or modify the kill ring.
456 // ForwardDelete is not implemented in IE or Firefox, so this behavior is only needed for
457 // backward compatibility with ourselves, and for consistency with Delete.
458 TypingCommand::forwardDeleteKeyPressed(frame->document());
461 ASSERT_NOT_REACHED();
465 static bool executeIgnoreSpelling(Frame* frame, Event*, EditorCommandSource, const String&)
467 frame->editor()->ignoreSpelling();
471 static bool executeIndent(Frame* frame, Event*, EditorCommandSource, const String&)
473 applyCommand(IndentOutdentCommand::create(frame->document(), IndentOutdentCommand::Indent));
477 static bool executeInsertBacktab(Frame* frame, Event* event, EditorCommandSource, const String&)
479 return targetFrame(frame, event)->eventHandler()->handleTextInputEvent("\t", event, false, true);
482 static bool executeInsertHorizontalRule(Frame* frame, Event*, EditorCommandSource, const String& value)
484 RefPtr<HTMLHRElement> rule = HTMLHRElement::create(frame->document());
485 if (!value.isEmpty())
486 rule->setIdAttribute(value);
487 return executeInsertNode(frame, rule.release());
490 static bool executeInsertHTML(Frame* frame, Event*, EditorCommandSource, const String& value)
492 return executeInsertFragment(frame, createFragmentFromMarkup(frame->document(), value, ""));
495 static bool executeInsertImage(Frame* frame, Event*, EditorCommandSource, const String& value)
497 // FIXME: If userInterface is true, we should display a dialog box and let the user choose a local image.
498 RefPtr<HTMLImageElement> image = HTMLImageElement::create(frame->document());
499 image->setSrc(value);
500 return executeInsertNode(frame, image.release());
503 static bool executeInsertLineBreak(Frame* frame, Event* event, EditorCommandSource source, const String&)
506 case CommandFromMenuOrKeyBinding:
507 return targetFrame(frame, event)->eventHandler()->handleTextInputEvent("\n", event, true);
509 case CommandFromDOMWithUserInterface:
510 // Doesn't scroll to make the selection visible, or modify the kill ring.
511 // InsertLineBreak is not implemented in IE or Firefox, so this behavior is only needed for
512 // backward compatibility with ourselves, and for consistency with other commands.
513 TypingCommand::insertLineBreak(frame->document());
516 ASSERT_NOT_REACHED();
520 static bool executeInsertNewline(Frame* frame, Event* event, EditorCommandSource, const String&)
522 Frame* targetFrame = WebCore::targetFrame(frame, event);
523 return targetFrame->eventHandler()->handleTextInputEvent("\n", event, !targetFrame->editor()->canEditRichly());
526 static bool executeInsertNewlineInQuotedContent(Frame* frame, Event*, EditorCommandSource, const String&)
528 TypingCommand::insertParagraphSeparatorInQuotedContent(frame->document());
532 static bool executeInsertOrderedList(Frame* frame, Event*, EditorCommandSource, const String&)
534 applyCommand(InsertListCommand::create(frame->document(), InsertListCommand::OrderedList));
538 static bool executeInsertParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
540 TypingCommand::insertParagraphSeparator(frame->document());
544 static bool executeInsertTab(Frame* frame, Event* event, EditorCommandSource, const String&)
546 return targetFrame(frame, event)->eventHandler()->handleTextInputEvent("\t", event, false, false);
549 static bool executeInsertText(Frame* frame, Event*, EditorCommandSource, const String& value)
551 TypingCommand::insertText(frame->document(), value);
555 static bool executeInsertUnorderedList(Frame* frame, Event*, EditorCommandSource, const String&)
557 applyCommand(InsertListCommand::create(frame->document(), InsertListCommand::UnorderedList));
561 static bool executeJustifyCenter(Frame* frame, Event*, EditorCommandSource source, const String&)
563 return executeApplyParagraphStyle(frame, source, EditActionCenter, CSSPropertyTextAlign, "center");
566 static bool executeJustifyFull(Frame* frame, Event*, EditorCommandSource source, const String&)
568 return executeApplyParagraphStyle(frame, source, EditActionJustify, CSSPropertyTextAlign, "justify");
571 static bool executeJustifyLeft(Frame* frame, Event*, EditorCommandSource source, const String&)
573 return executeApplyParagraphStyle(frame, source, EditActionAlignLeft, CSSPropertyTextAlign, "left");
576 static bool executeJustifyRight(Frame* frame, Event*, EditorCommandSource source, const String&)
578 return executeApplyParagraphStyle(frame, source, EditActionAlignRight, CSSPropertyTextAlign, "right");
581 static bool executeMakeTextWritingDirectionLeftToRight(Frame* frame, Event*, EditorCommandSource, const String&)
583 RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
584 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed);
585 style->setProperty(CSSPropertyDirection, CSSValueLtr);
586 frame->editor()->applyStyle(style.get(), EditActionSetWritingDirection);
590 static bool executeMakeTextWritingDirectionNatural(Frame* frame, Event*, EditorCommandSource, const String&)
592 RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
593 style->setProperty(CSSPropertyUnicodeBidi, CSSValueNormal);
594 frame->editor()->applyStyle(style.get(), EditActionSetWritingDirection);
598 static bool executeMakeTextWritingDirectionRightToLeft(Frame* frame, Event*, EditorCommandSource, const String&)
600 RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
601 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed);
602 style->setProperty(CSSPropertyDirection, CSSValueRtl);
603 frame->editor()->applyStyle(style.get(), EditActionSetWritingDirection);
607 static bool executeMoveBackward(Frame* frame, Event*, EditorCommandSource, const String&)
609 frame->selection()->modify(SelectionController::AlterationMove, SelectionController::DirectionBackward, CharacterGranularity, true);
613 static bool executeMoveBackwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
615 frame->selection()->modify(SelectionController::AlterationExtend, SelectionController::DirectionBackward, CharacterGranularity, true);
619 static bool executeMoveDown(Frame* frame, Event*, EditorCommandSource, const String&)
621 return frame->selection()->modify(SelectionController::AlterationMove, SelectionController::DirectionForward, LineGranularity, true);
624 static bool executeMoveDownAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
626 frame->selection()->modify(SelectionController::AlterationExtend, SelectionController::DirectionForward, LineGranularity, true);
630 static bool executeMoveForward(Frame* frame, Event*, EditorCommandSource, const String&)
632 frame->selection()->modify(SelectionController::AlterationMove, SelectionController::DirectionForward, CharacterGranularity, true);
636 static bool executeMoveForwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
638 frame->selection()->modify(SelectionController::AlterationExtend, SelectionController::DirectionForward, CharacterGranularity, true);
642 static bool executeMoveLeft(Frame* frame, Event*, EditorCommandSource, const String&)
644 return frame->selection()->modify(SelectionController::AlterationMove, SelectionController::DirectionLeft, CharacterGranularity, true);
647 static bool executeMoveLeftAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
649 frame->selection()->modify(SelectionController::AlterationExtend, SelectionController::DirectionLeft, CharacterGranularity, true);
653 static bool executeMovePageDown(Frame* frame, Event*, EditorCommandSource, const String&)
655 int distance = verticalScrollDistance(frame);
658 return frame->selection()->modify(SelectionController::AlterationMove, distance, true, SelectionController::AlignCursorOnScrollAlways);
661 static bool executeMovePageDownAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
663 int distance = verticalScrollDistance(frame);
666 return frame->selection()->modify(SelectionController::AlterationExtend, distance, true, SelectionController::AlignCursorOnScrollAlways);
669 static bool executeMovePageUp(Frame* frame, Event*, EditorCommandSource, const String&)
671 int distance = verticalScrollDistance(frame);
674 return frame->selection()->modify(SelectionController::AlterationMove, -distance, true, SelectionController::AlignCursorOnScrollAlways);
677 static bool executeMovePageUpAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
679 int distance = verticalScrollDistance(frame);
682 return frame->selection()->modify(SelectionController::AlterationExtend, -distance, true, SelectionController::AlignCursorOnScrollAlways);
685 static bool executeMoveRight(Frame* frame, Event*, EditorCommandSource, const String&)
687 return frame->selection()->modify(SelectionController::AlterationMove, SelectionController::DirectionRight, CharacterGranularity, true);
690 static bool executeMoveRightAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
692 frame->selection()->modify(SelectionController::AlterationExtend, SelectionController::DirectionRight, CharacterGranularity, true);
696 static bool executeMoveToBeginningOfDocument(Frame* frame, Event*, EditorCommandSource, const String&)
698 frame->selection()->modify(SelectionController::AlterationMove, SelectionController::DirectionBackward, DocumentBoundary, true);
702 static bool executeMoveToBeginningOfDocumentAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
704 frame->selection()->modify(SelectionController::AlterationExtend, SelectionController::DirectionBackward, DocumentBoundary, true);
708 static bool executeMoveToBeginningOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
710 frame->selection()->modify(SelectionController::AlterationMove, SelectionController::DirectionBackward, LineBoundary, true);
714 static bool executeMoveToBeginningOfLineAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
716 frame->selection()->modify(SelectionController::AlterationExtend, SelectionController::DirectionBackward, LineBoundary, true);
720 static bool executeMoveToBeginningOfParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
722 frame->selection()->modify(SelectionController::AlterationMove, SelectionController::DirectionBackward, ParagraphBoundary, true);
726 static bool executeMoveToBeginningOfParagraphAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
728 frame->selection()->modify(SelectionController::AlterationExtend, SelectionController::DirectionBackward, ParagraphBoundary, true);
732 static bool executeMoveToBeginningOfSentence(Frame* frame, Event*, EditorCommandSource, const String&)
734 frame->selection()->modify(SelectionController::AlterationMove, SelectionController::DirectionBackward, SentenceBoundary, true);
738 static bool executeMoveToBeginningOfSentenceAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
740 frame->selection()->modify(SelectionController::AlterationExtend, SelectionController::DirectionBackward, SentenceBoundary, true);
744 static bool executeMoveToEndOfDocument(Frame* frame, Event*, EditorCommandSource, const String&)
746 frame->selection()->modify(SelectionController::AlterationMove, SelectionController::DirectionForward, DocumentBoundary, true);
750 static bool executeMoveToEndOfDocumentAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
752 frame->selection()->modify(SelectionController::AlterationExtend, SelectionController::DirectionForward, DocumentBoundary, true);
756 static bool executeMoveToEndOfSentence(Frame* frame, Event*, EditorCommandSource, const String&)
758 frame->selection()->modify(SelectionController::AlterationMove, SelectionController::DirectionForward, SentenceBoundary, true);
762 static bool executeMoveToEndOfSentenceAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
764 frame->selection()->modify(SelectionController::AlterationExtend, SelectionController::DirectionForward, SentenceBoundary, true);
768 static bool executeMoveToEndOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
770 frame->selection()->modify(SelectionController::AlterationMove, SelectionController::DirectionForward, LineBoundary, true);
774 static bool executeMoveToEndOfLineAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
776 frame->selection()->modify(SelectionController::AlterationExtend, SelectionController::DirectionForward, LineBoundary, true);
780 static bool executeMoveToEndOfParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
782 frame->selection()->modify(SelectionController::AlterationMove, SelectionController::DirectionForward, ParagraphBoundary, true);
786 static bool executeMoveToEndOfParagraphAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
788 frame->selection()->modify(SelectionController::AlterationExtend, SelectionController::DirectionForward, ParagraphBoundary, true);
792 static bool executeMoveParagraphBackwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
794 frame->selection()->modify(SelectionController::AlterationExtend, SelectionController::DirectionBackward, ParagraphGranularity, true);
798 static bool executeMoveParagraphForwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
800 frame->selection()->modify(SelectionController::AlterationExtend, SelectionController::DirectionForward, ParagraphGranularity, true);
804 static bool executeMoveUp(Frame* frame, Event*, EditorCommandSource, const String&)
806 return frame->selection()->modify(SelectionController::AlterationMove, SelectionController::DirectionBackward, LineGranularity, true);
809 static bool executeMoveUpAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
811 frame->selection()->modify(SelectionController::AlterationExtend, SelectionController::DirectionBackward, LineGranularity, true);
815 static bool executeMoveWordBackward(Frame* frame, Event*, EditorCommandSource, const String&)
817 frame->selection()->modify(SelectionController::AlterationMove, SelectionController::DirectionBackward, WordGranularity, true);
821 static bool executeMoveWordBackwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
823 frame->selection()->modify(SelectionController::AlterationExtend, SelectionController::DirectionBackward, WordGranularity, true);
827 static bool executeMoveWordForward(Frame* frame, Event*, EditorCommandSource, const String&)
829 frame->selection()->modify(SelectionController::AlterationMove, SelectionController::DirectionForward, WordGranularity, true);
833 static bool executeMoveWordForwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
835 frame->selection()->modify(SelectionController::AlterationExtend, SelectionController::DirectionForward, WordGranularity, true);
839 static bool executeMoveWordLeft(Frame* frame, Event*, EditorCommandSource, const String&)
841 frame->selection()->modify(SelectionController::AlterationMove, SelectionController::DirectionLeft, WordGranularity, true);
845 static bool executeMoveWordLeftAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
847 frame->selection()->modify(SelectionController::AlterationExtend, SelectionController::DirectionLeft, WordGranularity, true);
851 static bool executeMoveWordRight(Frame* frame, Event*, EditorCommandSource, const String&)
853 frame->selection()->modify(SelectionController::AlterationMove, SelectionController::DirectionRight, WordGranularity, true);
857 static bool executeMoveWordRightAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
859 frame->selection()->modify(SelectionController::AlterationExtend, SelectionController::DirectionRight, WordGranularity, true);
863 static bool executeMoveToLeftEndOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
865 frame->selection()->modify(SelectionController::AlterationMove, SelectionController::DirectionLeft, LineBoundary, true);
869 static bool executeMoveToLeftEndOfLineAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
871 frame->selection()->modify(SelectionController::AlterationExtend, SelectionController::DirectionLeft, LineBoundary, true);
875 static bool executeMoveToRightEndOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
877 frame->selection()->modify(SelectionController::AlterationMove, SelectionController::DirectionRight, LineBoundary, true);
881 static bool executeMoveToRightEndOfLineAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
883 frame->selection()->modify(SelectionController::AlterationExtend, SelectionController::DirectionRight, LineBoundary, true);
887 static bool executeOutdent(Frame* frame, Event*, EditorCommandSource, const String&)
889 applyCommand(IndentOutdentCommand::create(frame->document(), IndentOutdentCommand::Outdent));
893 static bool executePaste(Frame* frame, Event*, EditorCommandSource, const String&)
895 frame->editor()->paste();
899 static bool executePasteAndMatchStyle(Frame* frame, Event*, EditorCommandSource, const String&)
901 frame->editor()->pasteAsPlainText();
905 static bool executePasteAsPlainText(Frame* frame, Event*, EditorCommandSource, const String&)
907 frame->editor()->pasteAsPlainText();
911 static bool executePrint(Frame* frame, Event*, EditorCommandSource, const String&)
913 Page* page = frame->page();
916 page->chrome()->print(frame);
920 static bool executeRedo(Frame* frame, Event*, EditorCommandSource, const String&)
922 frame->editor()->redo();
926 static bool executeRemoveFormat(Frame* frame, Event*, EditorCommandSource, const String&)
928 frame->editor()->removeFormattingAndStyle();
932 static bool executeSelectAll(Frame* frame, Event*, EditorCommandSource, const String&)
934 frame->selection()->selectAll();
938 static bool executeSelectLine(Frame* frame, Event*, EditorCommandSource, const String&)
940 return expandSelectionToGranularity(frame, LineGranularity);
943 static bool executeSelectParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
945 return expandSelectionToGranularity(frame, ParagraphGranularity);
948 static bool executeSelectSentence(Frame* frame, Event*, EditorCommandSource, const String&)
950 return expandSelectionToGranularity(frame, SentenceGranularity);
953 static bool executeSelectToMark(Frame* frame, Event*, EditorCommandSource, const String&)
955 RefPtr<Range> mark = frame->editor()->mark().toNormalizedRange();
956 RefPtr<Range> selection = frame->editor()->selectedRange();
957 if (!mark || !selection) {
961 frame->selection()->setSelectedRange(unionDOMRanges(mark.get(), selection.get()).get(), DOWNSTREAM, true);
965 static bool executeSelectWord(Frame* frame, Event*, EditorCommandSource, const String&)
967 return expandSelectionToGranularity(frame, WordGranularity);
970 static bool executeSetMark(Frame* frame, Event*, EditorCommandSource, const String&)
972 frame->editor()->setMark(frame->selection()->selection());
976 static bool executeStrikethrough(Frame* frame, Event*, EditorCommandSource source, const String&)
978 RefPtr<CSSPrimitiveValue> lineThrough = CSSPrimitiveValue::createIdentifier(CSSValueLineThrough);
979 return executeToggleStyleInList(frame, source, EditActionUnderline, CSSPropertyWebkitTextDecorationsInEffect, lineThrough.get());
982 static bool executeStyleWithCSS(Frame* frame, Event*, EditorCommandSource, const String& value)
984 if (value != "false" && value != "true")
987 frame->editor()->setShouldStyleWithCSS(value == "true" ? true : false);
991 static bool executeSubscript(Frame* frame, Event*, EditorCommandSource source, const String&)
993 return executeToggleStyle(frame, source, EditActionSubscript, CSSPropertyVerticalAlign, "baseline", "sub");
996 static bool executeSuperscript(Frame* frame, Event*, EditorCommandSource source, const String&)
998 return executeToggleStyle(frame, source, EditActionSuperscript, CSSPropertyVerticalAlign, "baseline", "super");
1001 static bool executeSwapWithMark(Frame* frame, Event*, EditorCommandSource, const String&)
1003 const VisibleSelection& mark = frame->editor()->mark();
1004 const VisibleSelection& selection = frame->selection()->selection();
1005 if (mark.isNone() || selection.isNone()) {
1009 frame->selection()->setSelection(mark);
1010 frame->editor()->setMark(selection);
1014 static bool executeToggleBold(Frame* frame, Event*, EditorCommandSource source, const String&)
1016 return executeToggleStyle(frame, source, EditActionChangeAttributes, CSSPropertyFontWeight, "normal", "bold");
1019 static bool executeToggleItalic(Frame* frame, Event*, EditorCommandSource source, const String&)
1021 return executeToggleStyle(frame, source, EditActionChangeAttributes, CSSPropertyFontStyle, "normal", "italic");
1024 static bool executeTranspose(Frame* frame, Event*, EditorCommandSource, const String&)
1026 frame->editor()->transpose();
1030 static bool executeUnderline(Frame* frame, Event*, EditorCommandSource source, const String&)
1032 RefPtr<CSSPrimitiveValue> underline = CSSPrimitiveValue::createIdentifier(CSSValueUnderline);
1033 return executeToggleStyleInList(frame, source, EditActionUnderline, CSSPropertyWebkitTextDecorationsInEffect, underline.get());
1036 static bool executeUndo(Frame* frame, Event*, EditorCommandSource, const String&)
1038 frame->editor()->undo();
1042 static bool executeUnlink(Frame* frame, Event*, EditorCommandSource, const String&)
1044 applyCommand(UnlinkCommand::create(frame->document()));
1048 static bool executeUnscript(Frame* frame, Event*, EditorCommandSource source, const String&)
1050 return executeApplyStyle(frame, source, EditActionUnscript, CSSPropertyVerticalAlign, "baseline");
1053 static bool executeUnselect(Frame* frame, Event*, EditorCommandSource, const String&)
1055 frame->selection()->clear();
1059 static bool executeYank(Frame* frame, Event*, EditorCommandSource, const String&)
1061 frame->editor()->insertTextWithoutSendingTextEvent(frame->editor()->killRing()->yank(), false, 0);
1062 frame->editor()->killRing()->setToYankedState();
1066 static bool executeYankAndSelect(Frame* frame, Event*, EditorCommandSource, const String&)
1068 frame->editor()->insertTextWithoutSendingTextEvent(frame->editor()->killRing()->yank(), true, 0);
1069 frame->editor()->killRing()->setToYankedState();
1073 #if SUPPORT_AUTOCORRECTION_PANEL
1074 static bool executeCancelOperation(Frame* frame, Event*, EditorCommandSource, const String&)
1076 frame->editor()->handleCancelOperation();
1081 // Supported functions
1083 static bool supported(Frame*, EditorCommandSource)
1088 static bool supportedFromMenuOrKeyBinding(Frame*, EditorCommandSource source)
1090 return source == CommandFromMenuOrKeyBinding;
1093 static bool supportedCopyCut(Frame* frame, EditorCommandSource source)
1096 case CommandFromMenuOrKeyBinding:
1098 case CommandFromDOM:
1099 case CommandFromDOMWithUserInterface: {
1100 Settings* settings = frame ? frame->settings() : 0;
1101 return settings && settings->javaScriptCanAccessClipboard();
1104 ASSERT_NOT_REACHED();
1108 static bool supportedPaste(Frame* frame, EditorCommandSource source)
1111 case CommandFromMenuOrKeyBinding:
1113 case CommandFromDOM:
1114 case CommandFromDOMWithUserInterface: {
1115 Settings* settings = frame ? frame->settings() : 0;
1116 return settings && (settings->javaScriptCanAccessClipboard() ? settings->isDOMPasteAllowed() : 0);
1119 ASSERT_NOT_REACHED();
1123 #if SUPPORT_AUTOCORRECTION_PANEL
1124 static bool supportedDismissCorrectionPanel(Frame* frame, EditorCommandSource source)
1126 return supportedFromMenuOrKeyBinding(frame, source) && frame->editor()->isShowingCorrectionPanel();
1130 // Enabled functions
1132 static bool enabled(Frame*, Event*, EditorCommandSource)
1137 static bool enabledVisibleSelection(Frame* frame, Event* event, EditorCommandSource)
1139 // The term "visible" here includes a caret in editable text or a range in any text.
1140 const VisibleSelection& selection = frame->editor()->selectionForCommand(event);
1141 return (selection.isCaret() && selection.isContentEditable()) || selection.isRange();
1144 static bool caretBrowsingEnabled(Frame* frame)
1146 return frame->settings() && frame->settings()->caretBrowsingEnabled();
1149 static EditorCommandSource dummyEditorCommandSource = static_cast<EditorCommandSource>(0);
1151 static bool enabledVisibleSelectionOrCaretBrowsing(Frame* frame, Event* event, EditorCommandSource)
1153 // The EditorCommandSource parameter is unused in enabledVisibleSelection, so just pass a dummy variable
1154 return caretBrowsingEnabled(frame) || enabledVisibleSelection(frame, event, dummyEditorCommandSource);
1157 static bool enabledVisibleSelectionAndMark(Frame* frame, Event* event, EditorCommandSource)
1159 const VisibleSelection& selection = frame->editor()->selectionForCommand(event);
1160 return ((selection.isCaret() && selection.isContentEditable()) || selection.isRange())
1161 && frame->editor()->mark().isCaretOrRange();
1164 static bool enableCaretInEditableText(Frame* frame, Event* event, EditorCommandSource)
1166 const VisibleSelection& selection = frame->editor()->selectionForCommand(event);
1167 return selection.isCaret() && selection.isContentEditable();
1170 static bool enabledCopy(Frame* frame, Event*, EditorCommandSource)
1172 return frame->editor()->canDHTMLCopy() || frame->editor()->canCopy();
1175 static bool enabledCut(Frame* frame, Event*, EditorCommandSource)
1177 return frame->editor()->canDHTMLCut() || frame->editor()->canCut();
1180 static bool enabledDelete(Frame* frame, Event* event, EditorCommandSource source)
1183 case CommandFromMenuOrKeyBinding:
1184 // "Delete" from menu only affects selected range, just like Cut but without affecting pasteboard
1185 return frame->editor()->canDHTMLCut() || frame->editor()->canCut();
1186 case CommandFromDOM:
1187 case CommandFromDOMWithUserInterface:
1188 // "Delete" from DOM is like delete/backspace keypress, affects selected range if non-empty,
1189 // otherwise removes a character
1190 return frame->editor()->selectionForCommand(event).isContentEditable();
1192 ASSERT_NOT_REACHED();
1196 static bool enabledInEditableText(Frame* frame, Event* event, EditorCommandSource)
1198 return frame->editor()->selectionForCommand(event).isContentEditable();
1201 static bool enabledInEditableTextOrCaretBrowsing(Frame* frame, Event* event, EditorCommandSource)
1203 // The EditorCommandSource parameter is unused in enabledInEditableText, so just pass a dummy variable
1204 return caretBrowsingEnabled(frame) || enabledInEditableText(frame, event, dummyEditorCommandSource);
1207 static bool enabledInRichlyEditableText(Frame* frame, Event*, EditorCommandSource)
1209 return frame->selection()->isCaretOrRange() && frame->selection()->isContentRichlyEditable();
1212 static bool enabledPaste(Frame* frame, Event*, EditorCommandSource)
1214 return frame->editor()->canPaste();
1217 static bool enabledRangeInEditableText(Frame* frame, Event*, EditorCommandSource)
1219 return frame->selection()->isRange() && frame->selection()->isContentEditable();
1222 static bool enabledRangeInRichlyEditableText(Frame* frame, Event*, EditorCommandSource)
1224 return frame->selection()->isRange() && frame->selection()->isContentRichlyEditable();
1227 static bool enabledRedo(Frame* frame, Event*, EditorCommandSource)
1229 return frame->editor()->canRedo();
1232 static bool enabledUndo(Frame* frame, Event*, EditorCommandSource)
1234 return frame->editor()->canUndo();
1239 static TriState stateNone(Frame*, Event*)
1241 return FalseTriState;
1244 static TriState stateBold(Frame* frame, Event*)
1246 return stateStyle(frame, CSSPropertyFontWeight, "bold");
1249 static TriState stateItalic(Frame* frame, Event*)
1251 return stateStyle(frame, CSSPropertyFontStyle, "italic");
1254 static TriState stateOrderedList(Frame* frame, Event*)
1256 return frame->editor()->selectionOrderedListState();
1259 static TriState stateStrikethrough(Frame* frame, Event*)
1261 return stateStyle(frame, CSSPropertyWebkitTextDecorationsInEffect, "line-through");
1264 static TriState stateStyleWithCSS(Frame* frame, Event*)
1266 return frame->editor()->shouldStyleWithCSS() ? TrueTriState : FalseTriState;
1269 static TriState stateSubscript(Frame* frame, Event*)
1271 return stateStyle(frame, CSSPropertyVerticalAlign, "sub");
1274 static TriState stateSuperscript(Frame* frame, Event*)
1276 return stateStyle(frame, CSSPropertyVerticalAlign, "super");
1279 static TriState stateTextWritingDirectionLeftToRight(Frame* frame, Event*)
1281 return stateTextWritingDirection(frame, LeftToRightWritingDirection);
1284 static TriState stateTextWritingDirectionNatural(Frame* frame, Event*)
1286 return stateTextWritingDirection(frame, NaturalWritingDirection);
1289 static TriState stateTextWritingDirectionRightToLeft(Frame* frame, Event*)
1291 return stateTextWritingDirection(frame, RightToLeftWritingDirection);
1294 static TriState stateUnderline(Frame* frame, Event*)
1296 return stateStyle(frame, CSSPropertyWebkitTextDecorationsInEffect, "underline");
1299 static TriState stateUnorderedList(Frame* frame, Event*)
1301 return frame->editor()->selectionUnorderedListState();
1304 static TriState stateJustifyCenter(Frame* frame, Event*)
1306 return stateStyle(frame, CSSPropertyTextAlign, "center");
1309 static TriState stateJustifyFull(Frame* frame, Event*)
1311 return stateStyle(frame, CSSPropertyTextAlign, "justify");
1314 static TriState stateJustifyLeft(Frame* frame, Event*)
1316 return stateStyle(frame, CSSPropertyTextAlign, "left");
1319 static TriState stateJustifyRight(Frame* frame, Event*)
1321 return stateStyle(frame, CSSPropertyTextAlign, "right");
1326 static String valueNull(Frame*, Event*)
1331 static String valueBackColor(Frame* frame, Event*)
1333 return valueStyle(frame, CSSPropertyBackgroundColor);
1336 static String valueFontName(Frame* frame, Event*)
1338 return valueStyle(frame, CSSPropertyFontFamily);
1341 static String valueFontSize(Frame* frame, Event*)
1343 return valueStyle(frame, CSSPropertyFontSize);
1346 static String valueFontSizeDelta(Frame* frame, Event*)
1348 return valueStyle(frame, CSSPropertyWebkitFontSizeDelta);
1351 static String valueForeColor(Frame* frame, Event*)
1353 return valueStyle(frame, CSSPropertyColor);
1356 static String valueFormatBlock(Frame* frame, Event*)
1358 const VisibleSelection& selection = frame->selection()->selection();
1359 if (!selection.isNonOrphanedCaretOrRange() || !selection.isContentEditable())
1361 Element* formatBlockElement = FormatBlockCommand::elementForFormatBlockCommand(selection.firstRange().get());
1362 if (!formatBlockElement)
1364 return formatBlockElement->localName();
1369 struct CommandEntry {
1371 EditorInternalCommand command;
1374 static const CommandMap& createCommandMap()
1376 static const CommandEntry commands[] = {
1377 { "AlignCenter", { executeJustifyCenter, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1378 { "AlignJustified", { executeJustifyFull, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1379 { "AlignLeft", { executeJustifyLeft, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1380 { "AlignRight", { executeJustifyRight, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1381 { "BackColor", { executeBackColor, supported, enabledInRichlyEditableText, stateNone, valueBackColor, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1382 { "BackwardDelete", { executeDeleteBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, // FIXME: remove BackwardDelete when Safari for Windows stops using it.
1383 { "Bold", { executeToggleBold, supported, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1384 { "Copy", { executeCopy, supportedCopyCut, enabledCopy, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1385 { "CreateLink", { executeCreateLink, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1386 { "Cut", { executeCut, supportedCopyCut, enabledCut, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1387 { "Delete", { executeDelete, supported, enabledDelete, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1388 { "DeleteBackward", { executeDeleteBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1389 { "DeleteBackwardByDecomposingPreviousCharacter", { executeDeleteBackwardByDecomposingPreviousCharacter, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1390 { "DeleteForward", { executeDeleteForward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1391 { "DeleteToBeginningOfLine", { executeDeleteToBeginningOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1392 { "DeleteToBeginningOfParagraph", { executeDeleteToBeginningOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1393 { "DeleteToEndOfLine", { executeDeleteToEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1394 { "DeleteToEndOfParagraph", { executeDeleteToEndOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1395 { "DeleteToMark", { executeDeleteToMark, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1396 { "DeleteWordBackward", { executeDeleteWordBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1397 { "DeleteWordForward", { executeDeleteWordForward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1398 { "FindString", { executeFindString, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1399 { "FontName", { executeFontName, supported, enabledInEditableText, stateNone, valueFontName, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1400 { "FontSize", { executeFontSize, supported, enabledInEditableText, stateNone, valueFontSize, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1401 { "FontSizeDelta", { executeFontSizeDelta, supported, enabledInEditableText, stateNone, valueFontSizeDelta, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1402 { "ForeColor", { executeForeColor, supported, enabledInRichlyEditableText, stateNone, valueForeColor, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1403 { "FormatBlock", { executeFormatBlock, supported, enabledInRichlyEditableText, stateNone, valueFormatBlock, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1404 { "ForwardDelete", { executeForwardDelete, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1405 { "HiliteColor", { executeBackColor, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1406 { "IgnoreSpelling", { executeIgnoreSpelling, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1407 { "Indent", { executeIndent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1408 { "InsertBacktab", { executeInsertBacktab, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1409 { "InsertHTML", { executeInsertHTML, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1410 { "InsertHorizontalRule", { executeInsertHorizontalRule, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1411 { "InsertImage", { executeInsertImage, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1412 { "InsertLineBreak", { executeInsertLineBreak, supported, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1413 { "InsertNewline", { executeInsertNewline, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1414 { "InsertNewlineInQuotedContent", { executeInsertNewlineInQuotedContent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1415 { "InsertOrderedList", { executeInsertOrderedList, supported, enabledInRichlyEditableText, stateOrderedList, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1416 { "InsertParagraph", { executeInsertParagraph, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1417 { "InsertTab", { executeInsertTab, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1418 { "InsertText", { executeInsertText, supported, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1419 { "InsertUnorderedList", { executeInsertUnorderedList, supported, enabledInRichlyEditableText, stateUnorderedList, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1420 { "Italic", { executeToggleItalic, supported, enabledInRichlyEditableText, stateItalic, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1421 { "JustifyCenter", { executeJustifyCenter, supported, enabledInRichlyEditableText, stateJustifyCenter, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1422 { "JustifyFull", { executeJustifyFull, supported, enabledInRichlyEditableText, stateJustifyFull, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1423 { "JustifyLeft", { executeJustifyLeft, supported, enabledInRichlyEditableText, stateJustifyLeft, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1424 { "JustifyNone", { executeJustifyLeft, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1425 { "JustifyRight", { executeJustifyRight, supported, enabledInRichlyEditableText, stateJustifyRight, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1426 { "MakeTextWritingDirectionLeftToRight", { executeMakeTextWritingDirectionLeftToRight, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionLeftToRight, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1427 { "MakeTextWritingDirectionNatural", { executeMakeTextWritingDirectionNatural, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionNatural, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1428 { "MakeTextWritingDirectionRightToLeft", { executeMakeTextWritingDirectionRightToLeft, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionRightToLeft, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1429 { "MoveBackward", { executeMoveBackward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1430 { "MoveBackwardAndModifySelection", { executeMoveBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1431 { "MoveDown", { executeMoveDown, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1432 { "MoveDownAndModifySelection", { executeMoveDownAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1433 { "MoveForward", { executeMoveForward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1434 { "MoveForwardAndModifySelection", { executeMoveForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1435 { "MoveLeft", { executeMoveLeft, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1436 { "MoveLeftAndModifySelection", { executeMoveLeftAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1437 { "MovePageDown", { executeMovePageDown, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1438 { "MovePageDownAndModifySelection", { executeMovePageDownAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1439 { "MovePageUp", { executeMovePageUp, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1440 { "MovePageUpAndModifySelection", { executeMovePageUpAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1441 { "MoveParagraphBackwardAndModifySelection", { executeMoveParagraphBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1442 { "MoveParagraphForwardAndModifySelection", { executeMoveParagraphForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1443 { "MoveRight", { executeMoveRight, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1444 { "MoveRightAndModifySelection", { executeMoveRightAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1445 { "MoveToBeginningOfDocument", { executeMoveToBeginningOfDocument, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1446 { "MoveToBeginningOfDocumentAndModifySelection", { executeMoveToBeginningOfDocumentAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1447 { "MoveToBeginningOfLine", { executeMoveToBeginningOfLine, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1448 { "MoveToBeginningOfLineAndModifySelection", { executeMoveToBeginningOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1449 { "MoveToBeginningOfParagraph", { executeMoveToBeginningOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1450 { "MoveToBeginningOfParagraphAndModifySelection", { executeMoveToBeginningOfParagraphAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1451 { "MoveToBeginningOfSentence", { executeMoveToBeginningOfSentence, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1452 { "MoveToBeginningOfSentenceAndModifySelection", { executeMoveToBeginningOfSentenceAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1453 { "MoveToEndOfDocument", { executeMoveToEndOfDocument, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1454 { "MoveToEndOfDocumentAndModifySelection", { executeMoveToEndOfDocumentAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1455 { "MoveToEndOfLine", { executeMoveToEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1456 { "MoveToEndOfLineAndModifySelection", { executeMoveToEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1457 { "MoveToEndOfParagraph", { executeMoveToEndOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1458 { "MoveToEndOfParagraphAndModifySelection", { executeMoveToEndOfParagraphAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1459 { "MoveToEndOfSentence", { executeMoveToEndOfSentence, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1460 { "MoveToEndOfSentenceAndModifySelection", { executeMoveToEndOfSentenceAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1461 { "MoveToLeftEndOfLine", { executeMoveToLeftEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1462 { "MoveToLeftEndOfLineAndModifySelection", { executeMoveToLeftEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1463 { "MoveToRightEndOfLine", { executeMoveToRightEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1464 { "MoveToRightEndOfLineAndModifySelection", { executeMoveToRightEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1465 { "MoveUp", { executeMoveUp, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1466 { "MoveUpAndModifySelection", { executeMoveUpAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1467 { "MoveWordBackward", { executeMoveWordBackward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1468 { "MoveWordBackwardAndModifySelection", { executeMoveWordBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1469 { "MoveWordForward", { executeMoveWordForward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1470 { "MoveWordForwardAndModifySelection", { executeMoveWordForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1471 { "MoveWordLeft", { executeMoveWordLeft, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1472 { "MoveWordLeftAndModifySelection", { executeMoveWordLeftAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1473 { "MoveWordRight", { executeMoveWordRight, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1474 { "MoveWordRightAndModifySelection", { executeMoveWordRightAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1475 { "Outdent", { executeOutdent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1476 { "Paste", { executePaste, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1477 { "PasteAndMatchStyle", { executePasteAndMatchStyle, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1478 { "PasteAsPlainText", { executePasteAsPlainText, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1479 { "Print", { executePrint, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1480 { "Redo", { executeRedo, supported, enabledRedo, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1481 { "RemoveFormat", { executeRemoveFormat, supported, enabledRangeInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1482 { "SelectAll", { executeSelectAll, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1483 { "SelectLine", { executeSelectLine, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1484 { "SelectParagraph", { executeSelectParagraph, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1485 { "SelectSentence", { executeSelectSentence, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1486 { "SelectToMark", { executeSelectToMark, supportedFromMenuOrKeyBinding, enabledVisibleSelectionAndMark, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1487 { "SelectWord", { executeSelectWord, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1488 { "SetMark", { executeSetMark, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1489 { "Strikethrough", { executeStrikethrough, supported, enabledInRichlyEditableText, stateStrikethrough, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1490 { "StyleWithCSS", { executeStyleWithCSS, supported, enabledInRichlyEditableText, stateStyleWithCSS, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1491 { "Subscript", { executeSubscript, supported, enabledInRichlyEditableText, stateSubscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1492 { "Superscript", { executeSuperscript, supported, enabledInRichlyEditableText, stateSuperscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1493 { "SwapWithMark", { executeSwapWithMark, supportedFromMenuOrKeyBinding, enabledVisibleSelectionAndMark, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1494 { "ToggleBold", { executeToggleBold, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1495 { "ToggleItalic", { executeToggleItalic, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateItalic, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1496 { "ToggleUnderline", { executeUnderline, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateUnderline, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1497 { "Transpose", { executeTranspose, supported, enableCaretInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1498 { "Underline", { executeUnderline, supported, enabledInRichlyEditableText, stateUnderline, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1499 { "Undo", { executeUndo, supported, enabledUndo, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1500 { "Unlink", { executeUnlink, supported, enabledRangeInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1501 { "Unscript", { executeUnscript, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1502 { "Unselect", { executeUnselect, supported, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1503 { "Yank", { executeYank, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1504 { "YankAndSelect", { executeYankAndSelect, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1505 #if SUPPORT_AUTOCORRECTION_PANEL
1506 { "CancelOperation", { executeCancelOperation, supportedDismissCorrectionPanel, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1510 // These unsupported commands are listed here since they appear in the Microsoft
1511 // documentation used as the starting point for our DOM executeCommand support.
1513 // 2D-Position (not supported)
1514 // AbsolutePosition (not supported)
1515 // BlockDirLTR (not supported)
1516 // BlockDirRTL (not supported)
1517 // BrowseMode (not supported)
1518 // ClearAuthenticationCache (not supported)
1519 // CreateBookmark (not supported)
1520 // DirLTR (not supported)
1521 // DirRTL (not supported)
1522 // EditMode (not supported)
1523 // InlineDirLTR (not supported)
1524 // InlineDirRTL (not supported)
1525 // InsertButton (not supported)
1526 // InsertFieldSet (not supported)
1527 // InsertIFrame (not supported)
1528 // InsertInputButton (not supported)
1529 // InsertInputCheckbox (not supported)
1530 // InsertInputFileUpload (not supported)
1531 // InsertInputHidden (not supported)
1532 // InsertInputImage (not supported)
1533 // InsertInputPassword (not supported)
1534 // InsertInputRadio (not supported)
1535 // InsertInputReset (not supported)
1536 // InsertInputSubmit (not supported)
1537 // InsertInputText (not supported)
1538 // InsertMarquee (not supported)
1539 // InsertSelectDropDown (not supported)
1540 // InsertSelectListBox (not supported)
1541 // InsertTextArea (not supported)
1542 // LiveResize (not supported)
1543 // MultipleSelection (not supported)
1544 // Open (not supported)
1545 // Overwrite (not supported)
1546 // PlayImage (not supported)
1547 // Refresh (not supported)
1548 // RemoveParaFormat (not supported)
1549 // SaveAs (not supported)
1550 // SizeToControl (not supported)
1551 // SizeToControlHeight (not supported)
1552 // SizeToControlWidth (not supported)
1553 // Stop (not supported)
1554 // StopImage (not supported)
1555 // Unbookmark (not supported)
1557 CommandMap& commandMap = *new CommandMap;
1559 const unsigned numCommands = sizeof(commands) / sizeof(commands[0]);
1560 for (unsigned i = 0; i < numCommands; i++) {
1561 ASSERT(!commandMap.get(commands[i].name));
1562 commandMap.set(commands[i].name, &commands[i].command);
1568 Editor::Command Editor::command(const String& commandName)
1570 return command(commandName, CommandFromMenuOrKeyBinding);
1573 Editor::Command Editor::command(const String& commandName, EditorCommandSource source)
1575 if (commandName.isEmpty())
1578 static const CommandMap& commandMap = createCommandMap();
1579 const EditorInternalCommand* internalCommand = commandMap.get(commandName);
1580 return internalCommand ? Command(m_frame, internalCommand, source) : Command();
1583 Editor::Command::Command()
1589 Editor::Command::Command(PassRefPtr<Frame> frame, const EditorInternalCommand* command, EditorCommandSource source)
1591 , m_command(command)
1598 bool Editor::Command::execute(const String& parameter, Event* triggeringEvent) const
1600 if (!isEnabled(triggeringEvent)) {
1601 // Let certain commands be executed when performed explicitly even if they are disabled.
1602 if (!isSupported() || !m_frame || !m_command->allowExecutionWhenDisabled)
1605 m_frame->document()->updateLayoutIgnorePendingStylesheets();
1606 return m_command->execute(m_frame.get(), triggeringEvent, m_source, parameter);
1609 bool Editor::Command::execute(Event* triggeringEvent) const
1611 return execute(String(), triggeringEvent);
1614 bool Editor::Command::isSupported() const
1616 return m_command && m_command->isSupported(m_frame.get(), m_source);
1619 bool Editor::Command::isEnabled(Event* triggeringEvent) const
1621 if (!isSupported() || !m_frame)
1623 return m_command->isEnabled(m_frame.get(), triggeringEvent, m_source);
1626 TriState Editor::Command::state(Event* triggeringEvent) const
1628 if (!isSupported() || !m_frame)
1629 return FalseTriState;
1630 return m_command->state(m_frame.get(), triggeringEvent);
1633 String Editor::Command::value(Event* triggeringEvent) const
1635 if (!isSupported() || !m_frame)
1637 if (m_command->value == valueNull && m_command->state != stateNone)
1638 return m_command->state(m_frame.get(), triggeringEvent) == TrueTriState ? "true" : "false";
1639 return m_command->value(m_frame.get(), triggeringEvent);
1642 bool Editor::Command::isTextInsertion() const
1644 return m_command && m_command->isTextInsertion;
1647 } // namespace WebCore