2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Trolltech ASA
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "AtomicString.h"
30 #include "CSSPropertyNames.h"
31 #include "CreateLinkCommand.h"
32 #include "DocumentFragment.h"
34 #include "EditorClient.h"
36 #include "EventHandler.h"
37 #include "FormatBlockCommand.h"
38 #include "HTMLFontElement.h"
39 #include "HTMLImageElement.h"
40 #include "IndentOutdentCommand.h"
41 #include "InsertListCommand.h"
43 #include "ReplaceSelectionCommand.h"
46 #include "TypingCommand.h"
47 #include "UnlinkCommand.h"
48 #include "htmlediting.h"
53 using namespace HTMLNames;
55 class EditorInternalCommand {
57 bool (*execute)(Frame*, Event*, EditorCommandSource, const String&);
58 bool (*isSupported)(Frame*, EditorCommandSource);
59 bool (*isEnabled)(Frame*, Event*);
60 TriState (*state)(Frame*, Event*);
61 String (*value)(Frame*, Event*);
65 typedef HashMap<String, const EditorInternalCommand*, CaseFoldingHash> CommandMap;
67 static const bool notTextInsertion = false;
68 static const bool isTextInsertion = true;
70 // Related to Editor::selectionForCommand.
71 // Certain operations continue to use the target control's selection even if the event handler
72 // already moved the selection outside of the text control.
73 static Frame* targetFrame(Frame* frame, Event* event)
77 Node* node = event->target()->toNode();
80 return node->document()->frame();
83 static bool executeApplyStyle(Frame* frame, EditorCommandSource source, EditAction action, int propertyID, const String& propertyValue)
85 RefPtr<CSSMutableStyleDeclaration> style = new CSSMutableStyleDeclaration;
86 style->setProperty(propertyID, propertyValue);
87 // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a good reason for that?
89 case CommandFromMenuOrKeyBinding:
90 frame->editor()->applyStyleToSelection(style.get(), action);
93 case CommandFromDOMWithUserInterface:
94 frame->editor()->applyStyle(style.get());
101 static bool executeApplyStyle(Frame* frame, EditorCommandSource source, EditAction action, int propertyID, const char* propertyValue)
103 return executeApplyStyle(frame, source, action, propertyID, String(propertyValue));
106 static bool executeApplyStyle(Frame* frame, EditorCommandSource source, EditAction action, int propertyID, int propertyValue)
108 RefPtr<CSSMutableStyleDeclaration> style = new CSSMutableStyleDeclaration;
109 style->setProperty(propertyID, propertyValue);
110 // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a good reason for that?
112 case CommandFromMenuOrKeyBinding:
113 frame->editor()->applyStyleToSelection(style.get(), action);
116 case CommandFromDOMWithUserInterface:
117 frame->editor()->applyStyle(style.get());
120 ASSERT_NOT_REACHED();
124 static bool executeToggleStyle(Frame* frame, EditorCommandSource source, EditAction action, int propertyID, const char* offValue, const char* onValue)
126 RefPtr<CSSMutableStyleDeclaration> style = new CSSMutableStyleDeclaration;
127 style->setProperty(propertyID, onValue);
128 style->setProperty(propertyID, frame->editor()->selectionStartHasStyle(style.get()) ? offValue : onValue);
129 // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a good reason for that?
131 case CommandFromMenuOrKeyBinding:
132 frame->editor()->applyStyleToSelection(style.get(), action);
135 case CommandFromDOMWithUserInterface:
136 frame->editor()->applyStyle(style.get());
139 ASSERT_NOT_REACHED();
143 static bool executeApplyParagraphStyle(Frame* frame, EditorCommandSource source, EditAction action, int propertyID, const String& propertyValue)
145 RefPtr<CSSMutableStyleDeclaration> style = new CSSMutableStyleDeclaration;
146 style->setProperty(propertyID, propertyValue);
147 // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a good reason for that?
149 case CommandFromMenuOrKeyBinding:
150 frame->editor()->applyParagraphStyleToSelection(style.get(), action);
153 case CommandFromDOMWithUserInterface:
154 frame->editor()->applyParagraphStyle(style.get());
157 ASSERT_NOT_REACHED();
161 static bool executeInsertFragment(Frame* frame, PassRefPtr<DocumentFragment> fragment)
163 applyCommand(new ReplaceSelectionCommand(frame->document(), fragment,
164 false, false, false, true, false, EditActionUnspecified));
168 static bool executeInsertNode(Frame* frame, PassRefPtr<Node> content)
170 RefPtr<DocumentFragment> fragment = new DocumentFragment(frame->document());
171 ExceptionCode ec = 0;
172 fragment->appendChild(content, ec);
175 return executeInsertFragment(frame, fragment.release());
178 static bool expandSelectionToGranularity(Frame* frame, TextGranularity granularity)
180 Selection selection = frame->selectionController()->selection();
181 selection.expandUsingGranularity(granularity);
182 RefPtr<Range> newRange = selection.toRange();
185 ExceptionCode ec = 0;
186 if (newRange->collapsed(ec))
188 RefPtr<Range> oldRange = frame->selectionController()->selection().toRange();
189 EAffinity affinity = frame->selectionController()->affinity();
190 if (!frame->editor()->client()->shouldChangeSelectedRange(oldRange.get(), newRange.get(), affinity, false))
192 frame->selectionController()->setSelectedRange(newRange.get(), affinity, true);
196 static TriState stateStyle(Frame* frame, int propertyID, const char* desiredValue)
198 RefPtr<CSSMutableStyleDeclaration> style = new CSSMutableStyleDeclaration;
199 style->setProperty(propertyID, desiredValue);
200 return frame->editor()->selectionHasStyle(style.get());
203 static String valueStyle(Frame* frame, int propertyID)
205 return frame->selectionStartStylePropertyValue(propertyID);
208 static int verticalScrollDistance(Frame* frame)
210 Node* focusedNode = frame->document()->focusedNode();
213 RenderObject* renderer = focusedNode->renderer();
216 RenderStyle* style = renderer->style();
219 if (!(style->overflowY() == OSCROLL || style->overflowY() == OAUTO || renderer->isTextArea()))
221 int height = renderer->clientHeight();
222 return max((height + 1) / 2, height - PAGE_KEEP);
225 static RefPtr<Range> unionDOMRanges(Range* a, Range* b)
227 ExceptionCode ec = 0;
228 Range* start = a->compareBoundaryPoints(Range::START_TO_START, b, ec) <= 0 ? a : b;
230 Range* end = a->compareBoundaryPoints(Range::END_TO_END, b, ec) <= 0 ? b : a;
233 return new Range(a->startContainer(ec)->ownerDocument(), start->startContainer(ec), start->startOffset(ec), end->endContainer(ec), end->endOffset(ec));
236 // Execute command functions
238 static bool executeBackColor(Frame* frame, Event*, EditorCommandSource source, const String& value)
240 return executeApplyStyle(frame, source, EditActionSetBackgroundColor, CSS_PROP_BACKGROUND_COLOR, value);
243 static bool executeBackwardDelete(Frame* frame, Event*, EditorCommandSource, const String&)
245 frame->editor()->deleteWithDirection(SelectionController::BACKWARD, CharacterGranularity, false, true);
249 static bool executeCopy(Frame* frame, Event*, EditorCommandSource, const String&)
251 frame->editor()->copy();
255 static bool executeCreateLink(Frame* frame, Event*, EditorCommandSource, const String& value)
257 // FIXME: If userInterface is true, we should display a dialog box to let the user enter a URL.
260 applyCommand(new CreateLinkCommand(frame->document(), value));
264 static bool executeCut(Frame* frame, Event*, EditorCommandSource, const String&)
266 frame->editor()->cut();
270 static bool executeDelete(Frame* frame, Event*, EditorCommandSource source, const String&)
272 // FIXME: Not sure there's a real reason to have this do something different when invoked from DOM.
273 // At some point we should either merge these or remove this comment.
275 case CommandFromMenuOrKeyBinding:
276 frame->editor()->performDelete();
279 case CommandFromDOMWithUserInterface:
280 TypingCommand::deleteKeyPressed(frame->document(), frame->selectionGranularity() == WordGranularity);
283 ASSERT_NOT_REACHED();
287 static bool executeDeleteBackward(Frame* frame, Event*, EditorCommandSource, const String&)
289 frame->editor()->deleteWithDirection(SelectionController::BACKWARD, CharacterGranularity, false, true);
293 static bool executeDeleteBackwardByDecomposingPreviousCharacter(Frame* frame, Event*, EditorCommandSource, const String&)
295 LOG_ERROR("DeleteBackwardByDecomposingPreviousCharacter is not implemented, doing DeleteBackward instead");
296 frame->editor()->deleteWithDirection(SelectionController::BACKWARD, CharacterGranularity, false, true);
300 static bool executeDeleteForward(Frame* frame, Event*, EditorCommandSource source, const String&)
302 frame->editor()->deleteWithDirection(SelectionController::FORWARD, CharacterGranularity, false, true);
306 static bool executeDeleteToBeginningOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
308 frame->editor()->deleteWithDirection(SelectionController::BACKWARD, LineBoundary, true, false);
312 static bool executeDeleteToBeginningOfParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
314 frame->editor()->deleteWithDirection(SelectionController::BACKWARD, ParagraphBoundary, true, false);
318 static bool executeDeleteToEndOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
320 // Despite its name, this command should delete the newline at the end of
321 // a paragraph if you are at the end of a paragraph (like DeleteToEndOfParagraph).
322 frame->editor()->deleteWithDirection(SelectionController::FORWARD, LineBoundary, true, false);
326 static bool executeDeleteToEndOfParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
328 // Despite its name, this command should delete the newline at the end of
329 // a paragraph if you are at the end of a paragraph.
330 frame->editor()->deleteWithDirection(SelectionController::FORWARD, ParagraphBoundary, true, false);
334 static bool executeDeleteToMark(Frame* frame, Event*, EditorCommandSource, const String&)
336 RefPtr<Range> mark = frame->mark().toRange();
338 SelectionController* selectionController = frame->selectionController();
339 bool selected = selectionController->setSelectedRange(unionDOMRanges(mark.get(), frame->editor()->selectedRange().get()).get(), DOWNSTREAM, true);
344 frame->editor()->performDelete();
345 frame->setMark(frame->selectionController()->selection());
349 static bool executeDeleteWordBackward(Frame* frame, Event*, EditorCommandSource, const String&)
351 frame->editor()->deleteWithDirection(SelectionController::BACKWARD, WordGranularity, true, false);
355 static bool executeDeleteWordForward(Frame* frame, Event*, EditorCommandSource, const String&)
357 frame->editor()->deleteWithDirection(SelectionController::FORWARD, WordGranularity, true, false);
361 static bool executeFindString(Frame* frame, Event*, EditorCommandSource, const String& value)
363 return frame->findString(value, true, false, true, false);
366 static bool executeFontName(Frame* frame, Event*, EditorCommandSource source, const String& value)
368 return executeApplyStyle(frame, source, EditActionSetFont, CSS_PROP_FONT_FAMILY, value);
371 static bool executeFontSize(Frame* frame, Event*, EditorCommandSource source, const String& value)
374 if (!HTMLFontElement::cssValueFromFontSizeNumber(value, size))
376 return executeApplyStyle(frame, source, EditActionChangeAttributes, CSS_PROP_FONT_SIZE, size);
379 static bool executeFontSizeDelta(Frame* frame, Event*, EditorCommandSource source, const String& value)
381 return executeApplyStyle(frame, source, EditActionChangeAttributes, CSS_PROP__WEBKIT_FONT_SIZE_DELTA, value);
384 static bool executeForeColor(Frame* frame, Event*, EditorCommandSource source, const String& value)
386 return executeApplyStyle(frame, source, EditActionSetColor, CSS_PROP_COLOR, value);
389 static bool executeFormatBlock(Frame* frame, Event*, EditorCommandSource, const String& value)
391 String tagName = value.lower();
392 if (tagName[0] == '<' && tagName[tagName.length() - 1] == '>')
393 tagName = tagName.substring(1, tagName.length() - 2);
394 if (!validBlockTag(tagName))
396 applyCommand(new FormatBlockCommand(frame->document(), tagName));
400 static bool executeForwardDelete(Frame* frame, Event*, EditorCommandSource source, const String&)
402 // FIXME: Not sure there's a real reason to have this do something different when invoked from DOM.
403 // At some point we should either merge these or remove this comment.
405 case CommandFromMenuOrKeyBinding:
406 frame->editor()->deleteWithDirection(SelectionController::FORWARD, CharacterGranularity, false, true);
409 case CommandFromDOMWithUserInterface:
410 TypingCommand::forwardDeleteKeyPressed(frame->document());
413 ASSERT_NOT_REACHED();
417 static bool executeIndent(Frame* frame, Event*, EditorCommandSource, const String&)
419 applyCommand(new IndentOutdentCommand(frame->document(), IndentOutdentCommand::Indent));
423 static bool executeInsertBacktab(Frame* frame, Event* event, EditorCommandSource, const String&)
425 return targetFrame(frame, event)->eventHandler()->handleTextInputEvent("\t", event, false, true);
428 static bool executeInsertHorizontalRule(Frame* frame, Event*, EditorCommandSource, const String& value)
430 RefPtr<HTMLElement> hr = new HTMLElement(hrTag, frame->document());
431 if (!value.isEmpty())
433 return executeInsertNode(frame, hr.release());
436 static bool executeInsertHTML(Frame* frame, Event*, EditorCommandSource, const String& value)
438 return executeInsertFragment(frame, createFragmentFromMarkup(frame->document(), value, ""));
441 static bool executeInsertImage(Frame* frame, Event*, EditorCommandSource, const String& value)
443 // FIXME: If userInterface is true, we should display a dialog box and let the user choose a local image.
444 RefPtr<HTMLImageElement> image = new HTMLImageElement(imgTag, frame->document());
445 image->setSrc(value);
446 return executeInsertNode(frame, image.release());
449 static bool executeInsertLineBreak(Frame* frame, Event* event, EditorCommandSource source, const String&)
451 // FIXME: Not sure there's a real reason to have this do something different when invoked from DOM.
452 // At some point we should either merge these or remove this comment.
454 case CommandFromMenuOrKeyBinding:
455 return targetFrame(frame, event)->eventHandler()->handleTextInputEvent("\n", event, true);
457 case CommandFromDOMWithUserInterface:
458 TypingCommand::insertLineBreak(frame->document());
461 ASSERT_NOT_REACHED();
465 static bool executeInsertNewline(Frame* frame, Event* event, EditorCommandSource, const String&)
467 Frame* targetFrame = WebCore::targetFrame(frame, event);
468 return targetFrame->eventHandler()->handleTextInputEvent("\n", event, !targetFrame->editor()->canEditRichly());
471 static bool executeInsertNewlineInQuotedContent(Frame* frame, Event*, EditorCommandSource, const String&)
473 TypingCommand::insertParagraphSeparatorInQuotedContent(frame->document());
477 static bool executeInsertOrderedList(Frame* frame, Event*, EditorCommandSource, const String& value)
479 applyCommand(new InsertListCommand(frame->document(), InsertListCommand::OrderedList, value));
483 static bool executeInsertParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
485 TypingCommand::insertParagraphSeparator(frame->document());
489 static bool executeInsertTab(Frame* frame, Event* event, EditorCommandSource, const String&)
491 return targetFrame(frame, event)->eventHandler()->handleTextInputEvent("\t", event, false, false);
494 static bool executeInsertText(Frame* frame, Event*, EditorCommandSource, const String& value)
496 TypingCommand::insertText(frame->document(), value);
500 static bool executeInsertUnorderedList(Frame* frame, Event*, EditorCommandSource, const String& value)
502 applyCommand(new InsertListCommand(frame->document(), InsertListCommand::UnorderedList, value));
506 static bool executeJustifyCenter(Frame* frame, Event*, EditorCommandSource source, const String&)
508 return executeApplyParagraphStyle(frame, source, EditActionCenter, CSS_PROP_TEXT_ALIGN, "center");
511 static bool executeJustifyFull(Frame* frame, Event*, EditorCommandSource source, const String&)
513 return executeApplyParagraphStyle(frame, source, EditActionJustify, CSS_PROP_TEXT_ALIGN, "justify");
516 static bool executeJustifyLeft(Frame* frame, Event*, EditorCommandSource source, const String&)
518 return executeApplyParagraphStyle(frame, source, EditActionAlignLeft, CSS_PROP_TEXT_ALIGN, "left");
521 static bool executeJustifyRight(Frame* frame, Event*, EditorCommandSource source, const String&)
523 return executeApplyParagraphStyle(frame, source, EditActionAlignRight, CSS_PROP_TEXT_ALIGN, "right");
526 static bool executeMoveBackward(Frame* frame, Event*, EditorCommandSource, const String&)
528 frame->selectionController()->modify(SelectionController::MOVE, SelectionController::BACKWARD, CharacterGranularity, true);
532 static bool executeMoveBackwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
534 frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::BACKWARD, CharacterGranularity, true);
538 static bool executeMoveDown(Frame* frame, Event*, EditorCommandSource, const String&)
540 frame->selectionController()->modify(SelectionController::MOVE, SelectionController::FORWARD, LineGranularity, true);
544 static bool executeMoveDownAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
546 frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::FORWARD, LineGranularity, true);
550 static bool executeMoveForward(Frame* frame, Event*, EditorCommandSource, const String&)
552 frame->selectionController()->modify(SelectionController::MOVE, SelectionController::FORWARD, CharacterGranularity, true);
556 static bool executeMoveForwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
558 frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::FORWARD, CharacterGranularity, true);
562 static bool executeMoveLeft(Frame* frame, Event*, EditorCommandSource, const String&)
564 frame->selectionController()->modify(SelectionController::MOVE, SelectionController::LEFT, CharacterGranularity, true);
568 static bool executeMoveLeftAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
570 frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::LEFT, CharacterGranularity, true);
574 static bool executeMovePageDown(Frame* frame, Event*, EditorCommandSource, const String&)
576 int distance = verticalScrollDistance(frame);
579 return frame->selectionController()->modify(SelectionController::MOVE, distance, true);
582 static bool executeMovePageDownAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
584 int distance = verticalScrollDistance(frame);
587 return frame->selectionController()->modify(SelectionController::EXTEND, distance, true);
590 static bool executeMovePageUp(Frame* frame, Event*, EditorCommandSource, const String&)
592 int distance = verticalScrollDistance(frame);
595 return frame->selectionController()->modify(SelectionController::MOVE, -distance, true);
598 static bool executeMovePageUpAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
600 int distance = verticalScrollDistance(frame);
603 return frame->selectionController()->modify(SelectionController::EXTEND, -distance, true);
606 static bool executeMoveRight(Frame* frame, Event*, EditorCommandSource, const String&)
608 frame->selectionController()->modify(SelectionController::MOVE, SelectionController::RIGHT, CharacterGranularity, true);
612 static bool executeMoveRightAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
614 frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::RIGHT, CharacterGranularity, true);
618 static bool executeMoveToBeginningOfDocument(Frame* frame, Event*, EditorCommandSource, const String&)
620 frame->selectionController()->modify(SelectionController::MOVE, SelectionController::BACKWARD, DocumentBoundary, true);
624 static bool executeMoveToBeginningOfDocumentAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
626 frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::BACKWARD, DocumentBoundary, true);
630 static bool executeMoveToBeginningOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
632 frame->selectionController()->modify(SelectionController::MOVE, SelectionController::BACKWARD, LineBoundary, true);
636 static bool executeMoveToBeginningOfLineAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
638 frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::BACKWARD, LineBoundary, true);
642 static bool executeMoveToBeginningOfParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
644 frame->selectionController()->modify(SelectionController::MOVE, SelectionController::BACKWARD, ParagraphBoundary, true);
648 static bool executeMoveToBeginningOfParagraphAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
650 frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::BACKWARD, ParagraphBoundary, true);
654 static bool executeMoveToBeginningOfSentence(Frame* frame, Event*, EditorCommandSource, const String&)
656 frame->selectionController()->modify(SelectionController::MOVE, SelectionController::BACKWARD, SentenceBoundary, true);
660 static bool executeMoveToBeginningOfSentenceAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
662 frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::BACKWARD, SentenceBoundary, true);
666 static bool executeMoveToEndOfDocument(Frame* frame, Event*, EditorCommandSource, const String&)
668 frame->selectionController()->modify(SelectionController::MOVE, SelectionController::FORWARD, DocumentBoundary, true);
672 static bool executeMoveToEndOfDocumentAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
674 frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::FORWARD, DocumentBoundary, true);
678 static bool executeMoveToEndOfSentence(Frame* frame, Event*, EditorCommandSource, const String&)
680 frame->selectionController()->modify(SelectionController::MOVE, SelectionController::FORWARD, SentenceBoundary, true);
684 static bool executeMoveToEndOfSentenceAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
686 frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::FORWARD, SentenceBoundary, true);
690 static bool executeMoveToEndOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
692 frame->selectionController()->modify(SelectionController::MOVE, SelectionController::FORWARD, LineBoundary, true);
696 static bool executeMoveToEndOfLineAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
698 frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::FORWARD, LineBoundary, true);
702 static bool executeMoveToEndOfParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
704 frame->selectionController()->modify(SelectionController::MOVE, SelectionController::FORWARD, ParagraphBoundary, true);
708 static bool executeMoveToEndOfParagraphAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
710 frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::FORWARD, ParagraphBoundary, true);
714 static bool executeMoveParagraphBackwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
716 frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::BACKWARD, ParagraphGranularity, true);
720 static bool executeMoveParagraphForwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
722 frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::FORWARD, ParagraphGranularity, true);
726 static bool executeMoveUp(Frame* frame, Event*, EditorCommandSource, const String&)
728 frame->selectionController()->modify(SelectionController::MOVE, SelectionController::BACKWARD, LineGranularity, true);
732 static bool executeMoveUpAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
734 frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::BACKWARD, LineGranularity, true);
738 static bool executeMoveWordBackward(Frame* frame, Event*, EditorCommandSource, const String&)
740 frame->selectionController()->modify(SelectionController::MOVE, SelectionController::BACKWARD, WordGranularity, true);
744 static bool executeMoveWordBackwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
746 frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::BACKWARD, WordGranularity, true);
750 static bool executeMoveWordForward(Frame* frame, Event*, EditorCommandSource, const String&)
752 frame->selectionController()->modify(SelectionController::MOVE, SelectionController::FORWARD, WordGranularity, true);
756 static bool executeMoveWordForwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
758 frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::FORWARD, WordGranularity, true);
762 static bool executeMoveWordLeft(Frame* frame, Event*, EditorCommandSource, const String&)
764 frame->selectionController()->modify(SelectionController::MOVE, SelectionController::LEFT, WordGranularity, true);
768 static bool executeMoveWordLeftAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
770 frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::LEFT, WordGranularity, true);
774 static bool executeMoveWordRight(Frame* frame, Event*, EditorCommandSource, const String&)
776 frame->selectionController()->modify(SelectionController::MOVE, SelectionController::RIGHT, WordGranularity, true);
780 static bool executeMoveWordRightAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
782 frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::RIGHT, WordGranularity, true);
786 static bool executeOutdent(Frame* frame, Event*, EditorCommandSource, const String&)
788 applyCommand(new IndentOutdentCommand(frame->document(), IndentOutdentCommand::Outdent));
792 static bool executePaste(Frame* frame, Event*, EditorCommandSource, const String&)
794 frame->editor()->paste();
798 static bool executePasteAndMatchStyle(Frame* frame, Event*, EditorCommandSource, const String&)
800 frame->editor()->pasteAsPlainText();
804 static bool executePrint(Frame* frame, Event*, EditorCommandSource, const String&)
806 Page* page = frame->page();
809 page->chrome()->print(frame);
813 static bool executeRedo(Frame* frame, Event*, EditorCommandSource, const String&)
815 frame->editor()->redo();
819 static bool executeRemoveFormat(Frame* frame, Event*, EditorCommandSource, const String&)
821 frame->editor()->removeFormattingAndStyle();
825 static bool executeSelectAll(Frame* frame, Event*, EditorCommandSource, const String&)
827 frame->selectionController()->selectAll();
831 static bool executeSelectLine(Frame* frame, Event*, EditorCommandSource, const String&)
833 return expandSelectionToGranularity(frame, LineGranularity);
836 static bool executeSelectParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
838 return expandSelectionToGranularity(frame, ParagraphGranularity);
841 static bool executeSelectSentence(Frame* frame, Event*, EditorCommandSource, const String&)
843 return expandSelectionToGranularity(frame, SentenceGranularity);
846 static bool executeSelectToMark(Frame* frame, Event*, EditorCommandSource, const String&)
848 RefPtr<Range> mark = frame->mark().toRange();
849 RefPtr<Range> selection = frame->editor()->selectedRange();
850 if (!mark || !selection) {
854 frame->selectionController()->setSelectedRange(unionDOMRanges(mark.get(), selection.get()).get(), DOWNSTREAM, true);
858 static bool executeSelectWord(Frame* frame, Event*, EditorCommandSource, const String&)
860 return expandSelectionToGranularity(frame, WordGranularity);
863 static bool executeSetMark(Frame* frame, Event*, EditorCommandSource, const String&)
865 frame->setMark(frame->selectionController()->selection());
869 static bool executeStrikethrough(Frame* frame, Event*, EditorCommandSource source, const String&)
871 return executeToggleStyle(frame, source, EditActionChangeAttributes, CSS_PROP__WEBKIT_TEXT_DECORATIONS_IN_EFFECT, "none", "line-through");
874 static bool executeSubscript(Frame* frame, Event*, EditorCommandSource source, const String&)
876 return executeApplyStyle(frame, source, EditActionSubscript, CSS_PROP_VERTICAL_ALIGN, "sub");
879 static bool executeSuperscript(Frame* frame, Event*, EditorCommandSource source, const String&)
881 return executeApplyStyle(frame, source, EditActionSuperscript, CSS_PROP_VERTICAL_ALIGN, "super");
884 static bool executeSwapWithMark(Frame* frame, Event*, EditorCommandSource, const String&)
886 const Selection& mark = frame->mark();
887 const Selection& selection = frame->selectionController()->selection();
888 if (mark.isNone() || selection.isNone()) {
892 frame->selectionController()->setSelection(mark);
893 frame->setMark(selection);
897 static bool executeToggleBold(Frame* frame, Event*, EditorCommandSource source, const String&)
899 return executeToggleStyle(frame, source, EditActionChangeAttributes, CSS_PROP_FONT_WEIGHT, "normal", "bold");
902 static bool executeToggleItalic(Frame* frame, Event*, EditorCommandSource source, const String&)
904 return executeToggleStyle(frame, source, EditActionChangeAttributes, CSS_PROP_FONT_STYLE, "normal", "italic");
907 static bool executeTranspose(Frame* frame, Event*, EditorCommandSource, const String&)
909 frame->editor()->transpose();
913 static bool executeUnderline(Frame* frame, Event*, EditorCommandSource source, const String&)
915 // FIXME: This currently clears overline, line-through, and blink as an unwanted side effect.
916 return executeToggleStyle(frame, source, EditActionUnderline, CSS_PROP__WEBKIT_TEXT_DECORATIONS_IN_EFFECT, "none", "underline");
919 static bool executeUndo(Frame* frame, Event*, EditorCommandSource, const String&)
921 frame->editor()->undo();
925 static bool executeUnlink(Frame* frame, Event*, EditorCommandSource, const String&)
927 applyCommand(new UnlinkCommand(frame->document()));
931 static bool executeUnscript(Frame* frame, Event*, EditorCommandSource source, const String&)
933 return executeApplyStyle(frame, source, EditActionUnscript, CSS_PROP_VERTICAL_ALIGN, "baseline");
936 static bool executeUnselect(Frame* frame, Event*, EditorCommandSource, const String&)
938 frame->selectionController()->clear();
942 static bool executeYank(Frame* frame, Event*, EditorCommandSource, const String&)
944 frame->editor()->insertTextWithoutSendingTextEvent(frame->editor()->yankFromKillRing(), false);
945 frame->editor()->setKillRingToYankedState();
949 static bool executeYankAndSelect(Frame* frame, Event*, EditorCommandSource, const String&)
951 frame->editor()->insertTextWithoutSendingTextEvent(frame->editor()->yankFromKillRing(), true);
952 frame->editor()->setKillRingToYankedState();
956 // Supported functions
958 static bool supported(Frame*, EditorCommandSource)
963 static bool supportedPaste(Frame* frame, EditorCommandSource source)
966 case CommandFromMenuOrKeyBinding:
969 case CommandFromDOMWithUserInterface: {
970 Settings* settings = frame ? frame->settings() : 0;
971 return settings && settings->isDOMPasteAllowed();
974 ASSERT_NOT_REACHED();
980 static bool enabled(Frame*, Event*)
985 static bool enabledAnySelection(Frame* frame, Event*)
987 return frame->selectionController()->isCaretOrRange();
990 static bool enabledAnySelectionAndMark(Frame* frame, Event*)
992 return frame->selectionController()->isCaretOrRange() && frame->mark().isCaretOrRange();
995 static bool enableCaretInEditableText(Frame* frame, Event* event)
997 const Selection& selection = frame->editor()->selectionForCommand(event);
998 return selection.isCaret() && selection.isContentEditable();
1001 static bool enabledCopy(Frame* frame, Event* source)
1003 return frame->editor()->canDHTMLCopy() || frame->editor()->canCopy();
1006 static bool enabledCut(Frame* frame, Event* source)
1008 return frame->editor()->canDHTMLCut() || frame->editor()->canCut();
1011 static bool enabledInEditableText(Frame* frame, Event* event)
1013 return frame->editor()->selectionForCommand(event).isContentEditable();
1016 static bool enabledInRichlyEditableText(Frame* frame, Event*)
1018 return frame->selectionController()->isCaretOrRange() && frame->selectionController()->isContentRichlyEditable();
1021 static bool enabledPaste(Frame* frame, Event*)
1023 return frame->editor()->canPaste();
1026 static bool enabledRangeInEditableText(Frame* frame, Event*)
1028 return frame->selectionController()->isRange() && frame->selectionController()->isContentEditable();
1031 static bool enabledRangeInRichlyEditableText(Frame* frame, Event*)
1033 return frame->selectionController()->isRange() && frame->selectionController()->isContentRichlyEditable();
1036 static bool enabledRedo(Frame* frame, Event*)
1038 return frame->editor()->canRedo();
1041 static bool enabledUndo(Frame* frame, Event*)
1043 return frame->editor()->canUndo();
1048 static TriState stateNone(Frame*, Event*)
1050 return FalseTriState;
1053 static TriState stateBold(Frame* frame, Event*)
1055 return stateStyle(frame, CSS_PROP_FONT_WEIGHT, "bold");
1058 static TriState stateItalic(Frame* frame, Event*)
1060 return stateStyle(frame, CSS_PROP_FONT_STYLE, "italic");
1063 static TriState stateOrderedList(Frame* frame, Event*)
1065 return frame->editor()->selectionOrderedListState();
1068 static TriState stateStrikethrough(Frame* frame, Event*)
1070 return stateStyle(frame, CSS_PROP_TEXT_DECORATION, "line-through");
1073 static TriState stateSubscript(Frame* frame, Event*)
1075 return stateStyle(frame, CSS_PROP_VERTICAL_ALIGN, "sub");
1078 static TriState stateSuperscript(Frame* frame, Event*)
1080 return stateStyle(frame, CSS_PROP_VERTICAL_ALIGN, "super");
1083 static TriState stateUnderline(Frame* frame, Event*)
1085 return stateStyle(frame, CSS_PROP_TEXT_DECORATION, "underline");
1088 static TriState stateUnorderedList(Frame* frame, Event*)
1090 return frame->editor()->selectionUnorderedListState();
1095 static String valueNull(Frame*, Event*)
1100 String valueBackColor(Frame* frame, Event*)
1102 return valueStyle(frame, CSS_PROP_BACKGROUND_COLOR);
1105 String valueFontName(Frame* frame, Event*)
1107 return valueStyle(frame, CSS_PROP_FONT_FAMILY);
1110 String valueFontSize(Frame* frame, Event*)
1112 return valueStyle(frame, CSS_PROP_FONT_SIZE);
1115 String valueFontSizeDelta(Frame* frame, Event*)
1117 return valueStyle(frame, CSS_PROP__WEBKIT_FONT_SIZE_DELTA);
1120 String valueForeColor(Frame* frame, Event*)
1122 return valueStyle(frame, CSS_PROP_COLOR);
1127 static const CommandMap& createCommandMap()
1129 struct CommandEntry { const char* name; EditorInternalCommand command; };
1131 static const CommandEntry commands[] = {
1132 { "AlignCenter", { executeJustifyCenter, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion } },
1133 { "AlignJustified", { executeJustifyFull, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion } },
1134 { "AlignLeft", { executeJustifyLeft, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion } },
1135 { "AlignRight", { executeJustifyRight, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion } },
1136 { "BackColor", { executeBackColor, supported, enabledRangeInRichlyEditableText, stateNone, valueBackColor, notTextInsertion } },
1137 { "BackwardDelete", { executeBackwardDelete, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1138 { "Bold", { executeToggleBold, supported, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion } },
1139 { "Copy", { executeCopy, supported, enabledCopy, stateNone, valueNull, notTextInsertion } },
1140 { "CreateLink", { executeCreateLink, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion } },
1141 { "Cut", { executeCut, supported, enabledCut, stateNone, valueNull, notTextInsertion } },
1142 { "Delete", { executeDelete, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1143 { "DeleteBackward", { executeDeleteBackward, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1144 { "DeleteBackwardByDecomposingPreviousCharacter", { executeDeleteBackwardByDecomposingPreviousCharacter, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1145 { "DeleteForward", { executeDeleteForward, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1146 { "DeleteToBeginningOfLine", { executeDeleteToBeginningOfLine, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1147 { "DeleteToBeginningOfParagraph", { executeDeleteToBeginningOfParagraph, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1148 { "DeleteToEndOfLine", { executeDeleteToEndOfLine, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1149 { "DeleteToEndOfParagraph", { executeDeleteToEndOfParagraph, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1150 { "DeleteToMark", { executeDeleteToMark, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1151 { "DeleteWordBackward", { executeDeleteWordBackward, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1152 { "DeleteWordForward", { executeDeleteWordForward, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1153 { "FindString", { executeFindString, supported, enabled, stateNone, valueNull, notTextInsertion } },
1154 { "FontName", { executeFontName, supported, enabledInEditableText, stateNone, valueFontName, notTextInsertion } },
1155 { "FontSize", { executeFontSize, supported, enabledInEditableText, stateNone, valueFontSize, notTextInsertion } },
1156 { "FontSizeDelta", { executeFontSizeDelta, supported, enabledInEditableText, stateNone, valueFontSizeDelta, notTextInsertion } },
1157 { "ForeColor", { executeForeColor, supported, enabledInEditableText, stateNone, valueForeColor, notTextInsertion } },
1158 { "FormatBlock", { executeFormatBlock, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion } },
1159 { "ForwardDelete", { executeForwardDelete, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1160 { "HiliteColor", { executeBackColor, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion } },
1161 { "Indent", { executeIndent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion } },
1162 { "InsertBacktab", { executeInsertBacktab, supported, enabledInEditableText, stateNone, valueNull, isTextInsertion } },
1163 { "InsertHTML", { executeInsertHTML, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1164 { "InsertHorizontalRule", { executeInsertHorizontalRule, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion } },
1165 { "InsertImage", { executeInsertImage, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion } },
1166 { "InsertLineBreak", { executeInsertLineBreak, supported, enabledInEditableText, stateNone, valueNull, isTextInsertion } },
1167 { "InsertNewline", { executeInsertNewline, supported, enabledInEditableText, stateNone, valueNull, isTextInsertion } },
1168 { "InsertNewlineInQuotedContent", { executeInsertNewlineInQuotedContent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion } },
1169 { "InsertOrderedList", { executeInsertOrderedList, supported, enabledInRichlyEditableText, stateOrderedList, valueNull, notTextInsertion } },
1170 { "InsertParagraph", { executeInsertParagraph, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1171 { "InsertTab", { executeInsertTab, supported, enabledInEditableText, stateNone, valueNull, isTextInsertion } },
1172 { "InsertText", { executeInsertText, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1173 { "InsertUnorderedList", { executeInsertUnorderedList, supported, enabledInRichlyEditableText, stateUnorderedList, valueNull, notTextInsertion } },
1174 { "Italic", { executeToggleItalic, supported, enabledInRichlyEditableText, stateItalic, valueNull, notTextInsertion } },
1175 { "JustifyCenter", { executeJustifyCenter, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion } },
1176 { "JustifyFull", { executeJustifyFull, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion } },
1177 { "JustifyLeft", { executeJustifyLeft, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion } },
1178 { "JustifyNone", { executeJustifyLeft, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion } },
1179 { "JustifyRight", { executeJustifyRight, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion } },
1180 { "MoveBackward", { executeMoveBackward, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1181 { "MoveBackwardAndModifySelection", { executeMoveBackwardAndModifySelection, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1182 { "MoveDown", { executeMoveDown, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1183 { "MoveDownAndModifySelection", { executeMoveDownAndModifySelection, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1184 { "MoveForward", { executeMoveForward, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1185 { "MoveForwardAndModifySelection", { executeMoveForwardAndModifySelection, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1186 { "MoveLeft", { executeMoveLeft, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1187 { "MoveLeftAndModifySelection", { executeMoveLeftAndModifySelection, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1188 { "MovePageDown", { executeMovePageDown, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1189 { "MovePageDownAndModifySelection", { executeMovePageDownAndModifySelection, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1190 { "MovePageUp", { executeMovePageUp, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1191 { "MovePageUpAndModifySelection", { executeMovePageUpAndModifySelection, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1192 { "MoveParagraphBackwardAndModifySelection", { executeMoveParagraphBackwardAndModifySelection, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1193 { "MoveParagraphForwardAndModifySelection", { executeMoveParagraphForwardAndModifySelection, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1194 { "MoveRight", { executeMoveRight, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1195 { "MoveRightAndModifySelection", { executeMoveRightAndModifySelection, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1196 { "MoveToBeginningOfDocument", { executeMoveToBeginningOfDocument, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1197 { "MoveToBeginningOfDocumentAndModifySelection", { executeMoveToBeginningOfDocumentAndModifySelection, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1198 { "MoveToBeginningOfLine", { executeMoveToBeginningOfLine, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1199 { "MoveToBeginningOfLineAndModifySelection", { executeMoveToBeginningOfLineAndModifySelection, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1200 { "MoveToBeginningOfParagraph", { executeMoveToBeginningOfParagraph, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1201 { "MoveToBeginningOfParagraphAndModifySelection", { executeMoveToBeginningOfParagraphAndModifySelection, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1202 { "MoveToBeginningOfSentence", { executeMoveToBeginningOfSentence, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1203 { "MoveToBeginningOfSentenceAndModifySelection", { executeMoveToBeginningOfSentenceAndModifySelection, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1204 { "MoveToEndOfDocument", { executeMoveToEndOfDocument, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1205 { "MoveToEndOfDocumentAndModifySelection", { executeMoveToEndOfDocumentAndModifySelection, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1206 { "MoveToEndOfLine", { executeMoveToEndOfLine, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1207 { "MoveToEndOfLineAndModifySelection", { executeMoveToEndOfLineAndModifySelection, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1208 { "MoveToEndOfParagraph", { executeMoveToEndOfParagraph, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1209 { "MoveToEndOfParagraphAndModifySelection", { executeMoveToEndOfParagraphAndModifySelection, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1210 { "MoveToEndOfSentence", { executeMoveToEndOfSentence, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1211 { "MoveToEndOfSentenceAndModifySelection", { executeMoveToEndOfSentenceAndModifySelection, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1212 { "MoveUp", { executeMoveUp, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1213 { "MoveUpAndModifySelection", { executeMoveUpAndModifySelection, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1214 { "MoveWordBackward", { executeMoveWordBackward, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1215 { "MoveWordBackwardAndModifySelection", { executeMoveWordBackwardAndModifySelection, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1216 { "MoveWordForward", { executeMoveWordForward, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1217 { "MoveWordForwardAndModifySelection", { executeMoveWordForwardAndModifySelection, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1218 { "MoveWordLeft", { executeMoveWordLeft, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1219 { "MoveWordLeftAndModifySelection", { executeMoveWordLeftAndModifySelection, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1220 { "MoveWordRight", { executeMoveWordRight, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1221 { "MoveWordRightAndModifySelection", { executeMoveWordRightAndModifySelection, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1222 { "Outdent", { executeOutdent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion } },
1223 { "Paste", { executePaste, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion } },
1224 { "PasteAndMatchStyle", { executePasteAndMatchStyle, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion } },
1225 { "Print", { executePrint, supported, enabled, stateNone, valueNull, notTextInsertion } },
1226 { "Redo", { executeRedo, supported, enabledRedo, stateNone, valueNull, notTextInsertion } },
1227 { "RemoveFormat", { executeRemoveFormat, supported, enabledRangeInEditableText, stateNone, valueNull, notTextInsertion } },
1228 { "SelectAll", { executeSelectAll, supported, enabled, stateNone, valueNull, notTextInsertion } },
1229 { "SelectLine", { executeSelectLine, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1230 { "SelectParagraph", { executeSelectParagraph, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1231 { "SelectSentence", { executeSelectSentence, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1232 { "SelectToMark", { executeSelectToMark, supported, enabledAnySelectionAndMark, stateNone, valueNull, notTextInsertion } },
1233 { "SelectWord", { executeSelectWord, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1234 { "SetMark", { executeSetMark, supported, enabledAnySelection, stateNone, valueNull, notTextInsertion } },
1235 { "Strikethrough", { executeStrikethrough, supported, enabledInRichlyEditableText, stateStrikethrough, valueNull, notTextInsertion } },
1236 { "Subscript", { executeSubscript, supported, enabledInRichlyEditableText, stateSubscript, valueNull, notTextInsertion } },
1237 { "Superscript", { executeSuperscript, supported, enabledInRichlyEditableText, stateSuperscript, valueNull, notTextInsertion } },
1238 { "SwapWithMark", { executeSwapWithMark, supported, enabledAnySelectionAndMark, stateNone, valueNull, notTextInsertion } },
1239 { "ToggleBold", { executeToggleBold, supported, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion } },
1240 { "ToggleItalic", { executeToggleItalic, supported, enabledInRichlyEditableText, stateItalic, valueNull, notTextInsertion } },
1241 { "ToggleUnderline", { executeUnderline, supported, enabledInRichlyEditableText, stateUnderline, valueNull, notTextInsertion } },
1242 { "Transpose", { executeTranspose, supported, enableCaretInEditableText, stateNone, valueNull, notTextInsertion } },
1243 { "Underline", { executeUnderline, supported, enabledInRichlyEditableText, stateUnderline, valueNull, notTextInsertion } },
1244 { "Undo", { executeUndo, supported, enabledUndo, stateNone, valueNull, notTextInsertion } },
1245 { "Unlink", { executeUnlink, supported, enabledRangeInRichlyEditableText, stateNone, valueNull, notTextInsertion } },
1246 { "Unscript", { executeUnscript, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion } },
1247 { "Unselect", { executeUnselect, supported, enabledAnySelection, stateNone, valueNull, notTextInsertion } },
1248 { "Yank", { executeYank, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1249 { "YankAndSelect", { executeYankAndSelect, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion } },
1252 // These unsupported commands are listed here since they appear in the Microsoft
1253 // documentation used as the starting point for our DOM executeCommand support.
1255 // 2D-Position (not supported)
1256 // AbsolutePosition (not supported)
1257 // BlockDirLTR (not supported)
1258 // BlockDirRTL (not supported)
1259 // BrowseMode (not supported)
1260 // ClearAuthenticationCache (not supported)
1261 // CreateBookmark (not supported)
1262 // DirLTR (not supported)
1263 // DirRTL (not supported)
1264 // EditMode (not supported)
1265 // InlineDirLTR (not supported)
1266 // InlineDirRTL (not supported)
1267 // InsertButton (not supported)
1268 // InsertFieldSet (not supported)
1269 // InsertIFrame (not supported)
1270 // InsertInputButton (not supported)
1271 // InsertInputCheckbox (not supported)
1272 // InsertInputFileUpload (not supported)
1273 // InsertInputHidden (not supported)
1274 // InsertInputImage (not supported)
1275 // InsertInputPassword (not supported)
1276 // InsertInputRadio (not supported)
1277 // InsertInputReset (not supported)
1278 // InsertInputSubmit (not supported)
1279 // InsertInputText (not supported)
1280 // InsertMarquee (not supported)
1281 // InsertSelectDropDown (not supported)
1282 // InsertSelectListBox (not supported)
1283 // InsertTextArea (not supported)
1284 // LiveResize (not supported)
1285 // MultipleSelection (not supported)
1286 // Open (not supported)
1287 // Overwrite (not supported)
1288 // PlayImage (not supported)
1289 // Refresh (not supported)
1290 // RemoveParaFormat (not supported)
1291 // SaveAs (not supported)
1292 // SizeToControl (not supported)
1293 // SizeToControlHeight (not supported)
1294 // SizeToControlWidth (not supported)
1295 // Stop (not supported)
1296 // StopImage (not supported)
1297 // Unbookmark (not supported)
1299 CommandMap& commandMap = *new CommandMap;
1301 const unsigned numCommands = sizeof(commands) / sizeof(commands[0]);
1302 for (unsigned i = 0; i < numCommands; i++) {
1303 ASSERT(!commandMap.get(commands[i].name));
1304 commandMap.set(commands[i].name, &commands[i].command);
1310 Editor::Command Editor::command(const String& commandName)
1312 return command(commandName, CommandFromMenuOrKeyBinding);
1315 Editor::Command Editor::command(const String& commandName, EditorCommandSource source)
1317 if (commandName.isEmpty())
1320 static const CommandMap& commandMap = createCommandMap();
1321 const EditorInternalCommand* internalCommand = commandMap.get(commandName);
1322 return internalCommand ? Command(m_frame, internalCommand, source) : Command();
1325 Editor::Command::Command()
1331 Editor::Command::Command(PassRefPtr<Frame> frame, const EditorInternalCommand* command, EditorCommandSource source)
1333 , m_command(command)
1340 bool Editor::Command::execute(const String& parameter, Event* triggeringEvent) const
1342 if (!isEnabled(triggeringEvent))
1344 m_frame->document()->updateLayoutIgnorePendingStylesheets();
1345 return m_command->execute(m_frame.get(), triggeringEvent, m_source, parameter);
1348 bool Editor::Command::execute(Event* triggeringEvent) const
1350 return execute(String(), triggeringEvent);
1353 bool Editor::Command::isSupported() const
1355 return m_command && m_command->isSupported(m_frame.get(), m_source);
1358 bool Editor::Command::isEnabled(Event* triggeringEvent) const
1360 if (!isSupported() || !m_frame || !m_frame->document())
1362 return m_command->isEnabled(m_frame.get(), triggeringEvent);
1365 TriState Editor::Command::state(Event* triggeringEvent) const
1367 if (!isSupported() || !m_frame || !m_frame->document())
1368 return FalseTriState;
1369 return m_command->state(m_frame.get(), triggeringEvent);
1372 String Editor::Command::value(Event* triggeringEvent) const
1374 if (!isSupported() || !m_frame || !m_frame->document())
1376 return m_command->value(m_frame.get(), triggeringEvent);
1379 bool Editor::Command::isTextInsertion() const
1381 return m_command && m_command->isTextInsertion;
1384 } // namespace WebCore