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 "CSSPropertyNames.h"
33 #include "CSSValueKeywords.h"
34 #include "CSSValueList.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 "HTMLNames.h"
48 #include "IndentOutdentCommand.h"
49 #include "InsertListCommand.h"
52 #include "RenderBox.h"
53 #include "ReplaceSelectionCommand.h"
54 #include "Scrollbar.h"
57 #include "StylePropertySet.h"
58 #include "TypingCommand.h"
59 #include "UnlinkCommand.h"
60 #include "UserTypingGestureIndicator.h"
61 #include "htmlediting.h"
63 #include <wtf/text/AtomicString.h>
67 using namespace HTMLNames;
69 class EditorInternalCommand {
71 bool (*execute)(Frame*, Event*, EditorCommandSource, const String&);
72 bool (*isSupportedFromDOM)(Frame*);
73 bool (*isEnabled)(Frame*, Event*, EditorCommandSource);
74 TriState (*state)(Frame*, Event*);
75 String (*value)(Frame*, Event*);
77 bool allowExecutionWhenDisabled;
80 typedef HashMap<String, const EditorInternalCommand*, CaseFoldingHash> CommandMap;
82 static const bool notTextInsertion = false;
83 static const bool isTextInsertion = true;
85 static const bool allowExecutionWhenDisabled = true;
86 static const bool doNotAllowExecutionWhenDisabled = false;
88 // Related to Editor::selectionForCommand.
89 // Certain operations continue to use the target control's selection even if the event handler
90 // already moved the selection outside of the text control.
91 static Frame* targetFrame(Frame* frame, Event* event)
95 Node* node = event->target()->toNode();
98 return node->document()->frame();
101 static bool applyCommandToFrame(Frame* frame, EditorCommandSource source, EditAction action, StylePropertySet* style)
103 // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a good reason for that?
105 case CommandFromMenuOrKeyBinding:
106 frame->editor()->applyStyleToSelection(style, action);
109 case CommandFromDOMWithUserInterface:
110 frame->editor()->applyStyle(style);
113 ASSERT_NOT_REACHED();
117 static bool executeApplyStyle(Frame* frame, EditorCommandSource source, EditAction action, CSSPropertyID propertyID, const String& propertyValue)
119 RefPtr<StylePropertySet> style = StylePropertySet::create();
120 style->setProperty(propertyID, propertyValue);
121 return applyCommandToFrame(frame, source, action, style.get());
124 static bool executeApplyStyle(Frame* frame, EditorCommandSource source, EditAction action, CSSPropertyID propertyID, int propertyValue)
126 RefPtr<StylePropertySet> style = StylePropertySet::create();
127 style->setProperty(propertyID, propertyValue);
128 return applyCommandToFrame(frame, source, action, style.get());
131 // FIXME: executeToggleStyleInList does not handle complicated cases such as <b><u>hello</u>world</b> properly.
132 // This function must use Editor::selectionHasStyle to determine the current style but we cannot fix this
133 // until https://bugs.webkit.org/show_bug.cgi?id=27818 is resolved.
134 static bool executeToggleStyleInList(Frame* frame, EditorCommandSource source, EditAction action, CSSPropertyID propertyID, CSSValue* value)
136 ExceptionCode ec = 0;
137 RefPtr<EditingStyle> selectionStyle = EditingStyle::styleAtSelectionStart(frame->selection()->selection());
138 if (!selectionStyle || !selectionStyle->style())
141 RefPtr<CSSValue> selectedCSSValue = selectionStyle->style()->getPropertyCSSValue(propertyID);
142 String newStyle = "none";
143 if (selectedCSSValue->isValueList()) {
144 RefPtr<CSSValueList> selectedCSSValueList = static_cast<CSSValueList*>(selectedCSSValue.get());
145 if (!selectedCSSValueList->removeAll(value))
146 selectedCSSValueList->append(value);
147 if (selectedCSSValueList->length())
148 newStyle = selectedCSSValueList->cssText();
150 } else if (selectedCSSValue->cssText() == "none")
151 newStyle = value->cssText();
153 // FIXME: We shouldn't be having to convert new style into text. We should have setPropertyCSSValue.
154 RefPtr<StylePropertySet> newMutableStyle = StylePropertySet::create();
155 newMutableStyle->setProperty(propertyID, newStyle, ec);
156 return applyCommandToFrame(frame, source, action, newMutableStyle.get());
159 static bool executeToggleStyle(Frame* frame, EditorCommandSource source, EditAction action, CSSPropertyID propertyID, const char* offValue, const char* onValue)
161 // Style is considered present when
162 // Mac: present at the beginning of selection
163 // other: present throughout the selection
166 if (frame->editor()->behavior().shouldToggleStyleBasedOnStartOfSelection())
167 styleIsPresent = frame->editor()->selectionStartHasStyle(propertyID, onValue);
169 styleIsPresent = frame->editor()->selectionHasStyle(propertyID, onValue) == TrueTriState;
171 RefPtr<EditingStyle> style = EditingStyle::create(propertyID, styleIsPresent ? offValue : onValue);
172 return applyCommandToFrame(frame, source, action, style->style());
175 static bool executeApplyParagraphStyle(Frame* frame, EditorCommandSource source, EditAction action, CSSPropertyID propertyID, const String& propertyValue)
177 RefPtr<StylePropertySet> style = StylePropertySet::create();
178 style->setProperty(propertyID, propertyValue);
179 // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a good reason for that?
181 case CommandFromMenuOrKeyBinding:
182 frame->editor()->applyParagraphStyleToSelection(style.get(), action);
185 case CommandFromDOMWithUserInterface:
186 frame->editor()->applyParagraphStyle(style.get());
189 ASSERT_NOT_REACHED();
193 static bool executeInsertFragment(Frame* frame, PassRefPtr<DocumentFragment> fragment)
195 applyCommand(ReplaceSelectionCommand::create(frame->document(), fragment, ReplaceSelectionCommand::PreventNesting, EditActionUnspecified));
199 static bool executeInsertNode(Frame* frame, PassRefPtr<Node> content)
201 RefPtr<DocumentFragment> fragment = DocumentFragment::create(frame->document());
202 ExceptionCode ec = 0;
203 fragment->appendChild(content, ec);
206 return executeInsertFragment(frame, fragment.release());
209 static bool expandSelectionToGranularity(Frame* frame, TextGranularity granularity)
211 VisibleSelection selection = frame->selection()->selection();
212 selection.expandUsingGranularity(granularity);
213 RefPtr<Range> newRange = selection.toNormalizedRange();
216 ExceptionCode ec = 0;
217 if (newRange->collapsed(ec))
219 RefPtr<Range> oldRange = frame->selection()->selection().toNormalizedRange();
220 EAffinity affinity = frame->selection()->affinity();
221 if (!frame->editor()->client()->shouldChangeSelectedRange(oldRange.get(), newRange.get(), affinity, false))
223 frame->selection()->setSelectedRange(newRange.get(), affinity, true);
227 static TriState stateStyle(Frame* frame, CSSPropertyID propertyID, const char* desiredValue)
229 if (frame->editor()->behavior().shouldToggleStyleBasedOnStartOfSelection())
230 return frame->editor()->selectionStartHasStyle(propertyID, desiredValue) ? TrueTriState : FalseTriState;
231 return frame->editor()->selectionHasStyle(propertyID, desiredValue);
234 static String valueStyle(Frame* frame, CSSPropertyID propertyID)
236 // FIXME: Rather than retrieving the style at the start of the current selection,
237 // we should retrieve the style present throughout the selection for non-Mac platforms.
238 return frame->editor()->selectionStartCSSPropertyValue(propertyID);
241 static TriState stateTextWritingDirection(Frame* frame, WritingDirection direction)
243 bool hasNestedOrMultipleEmbeddings;
244 WritingDirection selectionDirection = EditingStyle::textDirectionForSelection(frame->selection()->selection(),
245 frame->selection()->typingStyle(), hasNestedOrMultipleEmbeddings);
246 // FXIME: We should be returning MixedTriState when selectionDirection == direction && hasNestedOrMultipleEmbeddings
247 return (selectionDirection == direction && !hasNestedOrMultipleEmbeddings) ? TrueTriState : FalseTriState;
250 static unsigned verticalScrollDistance(Frame* frame)
252 Node* focusedNode = frame->document()->focusedNode();
255 RenderObject* renderer = focusedNode->renderer();
256 if (!renderer || !renderer->isBox())
258 RenderStyle* style = renderer->style();
261 if (!(style->overflowY() == OSCROLL || style->overflowY() == OAUTO || focusedNode->rendererIsEditable()))
263 int height = std::min<int>(toRenderBox(renderer)->clientHeight(), frame->view()->visibleHeight());
264 return static_cast<unsigned>(max(max<int>(height * Scrollbar::minFractionToStepWhenPaging(), height - Scrollbar::maxOverlapBetweenPages()), 1));
267 static RefPtr<Range> unionDOMRanges(Range* a, Range* b)
269 ExceptionCode ec = 0;
270 Range* start = a->compareBoundaryPoints(Range::START_TO_START, b, ec) <= 0 ? a : b;
272 Range* end = a->compareBoundaryPoints(Range::END_TO_END, b, ec) <= 0 ? b : a;
275 return Range::create(a->startContainer(ec)->ownerDocument(), start->startContainer(ec), start->startOffset(ec), end->endContainer(ec), end->endOffset(ec));
278 // Execute command functions
280 static bool executeBackColor(Frame* frame, Event*, EditorCommandSource source, const String& value)
282 return executeApplyStyle(frame, source, EditActionSetBackgroundColor, CSSPropertyBackgroundColor, value);
285 static bool executeCopy(Frame* frame, Event*, EditorCommandSource, const String&)
287 frame->editor()->copy();
291 static bool executeCreateLink(Frame* frame, Event*, EditorCommandSource, const String& value)
293 // FIXME: If userInterface is true, we should display a dialog box to let the user enter a URL.
296 applyCommand(CreateLinkCommand::create(frame->document(), value));
300 static bool executeCut(Frame* frame, Event*, EditorCommandSource source, const String&)
302 if (source == CommandFromMenuOrKeyBinding) {
303 UserTypingGestureIndicator typingGestureIndicator(frame);
304 frame->editor()->cut();
306 frame->editor()->cut();
310 static bool executeDefaultParagraphSeparator(Frame* frame, Event*, EditorCommandSource, const String& value)
312 if (equalIgnoringCase(value, "div"))
313 frame->editor()->setDefaultParagraphSeparator(EditorParagraphSeparatorIsDiv);
314 else if (equalIgnoringCase(value, "p"))
315 frame->editor()->setDefaultParagraphSeparator(EditorParagraphSeparatorIsP);
320 static bool executeDelete(Frame* frame, Event*, EditorCommandSource source, const String&)
323 case CommandFromMenuOrKeyBinding: {
324 // Doesn't modify the text if the current selection isn't a range.
325 UserTypingGestureIndicator typingGestureIndicator(frame);
326 frame->editor()->performDelete();
330 case CommandFromDOMWithUserInterface:
331 // If the current selection is a caret, delete the preceding character. IE performs forwardDelete, but we currently side with Firefox.
332 // Doesn't scroll to make the selection visible, or modify the kill ring (this time, siding with IE, not Firefox).
333 TypingCommand::deleteKeyPressed(frame->document(), frame->selection()->granularity() == WordGranularity ? TypingCommand::SmartDelete : 0);
336 ASSERT_NOT_REACHED();
340 static bool executeDeleteBackward(Frame* frame, Event*, EditorCommandSource, const String&)
342 frame->editor()->deleteWithDirection(DirectionBackward, CharacterGranularity, false, true);
346 static bool executeDeleteBackwardByDecomposingPreviousCharacter(Frame* frame, Event*, EditorCommandSource, const String&)
348 LOG_ERROR("DeleteBackwardByDecomposingPreviousCharacter is not implemented, doing DeleteBackward instead");
349 frame->editor()->deleteWithDirection(DirectionBackward, CharacterGranularity, false, true);
353 static bool executeDeleteForward(Frame* frame, Event*, EditorCommandSource, const String&)
355 frame->editor()->deleteWithDirection(DirectionForward, CharacterGranularity, false, true);
359 static bool executeDeleteToBeginningOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
361 frame->editor()->deleteWithDirection(DirectionBackward, LineBoundary, true, false);
365 static bool executeDeleteToBeginningOfParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
367 frame->editor()->deleteWithDirection(DirectionBackward, ParagraphBoundary, true, false);
371 static bool executeDeleteToEndOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
373 // Despite its name, this command should delete the newline at the end of
374 // a paragraph if you are at the end of a paragraph (like DeleteToEndOfParagraph).
375 frame->editor()->deleteWithDirection(DirectionForward, LineBoundary, true, false);
379 static bool executeDeleteToEndOfParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
381 // Despite its name, this command should delete the newline at the end of
382 // a paragraph if you are at the end of a paragraph.
383 frame->editor()->deleteWithDirection(DirectionForward, ParagraphBoundary, true, false);
387 static bool executeDeleteToMark(Frame* frame, Event*, EditorCommandSource, const String&)
389 RefPtr<Range> mark = frame->editor()->mark().toNormalizedRange();
391 FrameSelection* selection = frame->selection();
392 bool selected = selection->setSelectedRange(unionDOMRanges(mark.get(), frame->editor()->selectedRange().get()).get(), DOWNSTREAM, true);
397 frame->editor()->performDelete();
398 frame->editor()->setMark(frame->selection()->selection());
402 static bool executeDeleteWordBackward(Frame* frame, Event*, EditorCommandSource, const String&)
404 frame->editor()->deleteWithDirection(DirectionBackward, WordGranularity, true, false);
408 static bool executeDeleteWordForward(Frame* frame, Event*, EditorCommandSource, const String&)
410 frame->editor()->deleteWithDirection(DirectionForward, WordGranularity, true, false);
414 static bool executeFindString(Frame* frame, Event*, EditorCommandSource, const String& value)
416 return frame->editor()->findString(value, true, false, true, false);
419 static bool executeFontName(Frame* frame, Event*, EditorCommandSource source, const String& value)
421 return executeApplyStyle(frame, source, EditActionSetFont, CSSPropertyFontFamily, value);
424 static bool executeFontSize(Frame* frame, Event*, EditorCommandSource source, const String& value)
427 if (!HTMLFontElement::cssValueFromFontSizeNumber(value, size))
429 return executeApplyStyle(frame, source, EditActionChangeAttributes, CSSPropertyFontSize, size);
432 static bool executeFontSizeDelta(Frame* frame, Event*, EditorCommandSource source, const String& value)
434 return executeApplyStyle(frame, source, EditActionChangeAttributes, CSSPropertyWebkitFontSizeDelta, value);
437 static bool executeForeColor(Frame* frame, Event*, EditorCommandSource source, const String& value)
439 return executeApplyStyle(frame, source, EditActionSetColor, CSSPropertyColor, value);
442 static bool executeFormatBlock(Frame* frame, Event*, EditorCommandSource, const String& value)
444 String tagName = value.lower();
445 if (tagName[0] == '<' && tagName[tagName.length() - 1] == '>')
446 tagName = tagName.substring(1, tagName.length() - 2);
449 String localName, prefix;
450 if (!Document::parseQualifiedName(tagName, prefix, localName, ec))
452 QualifiedName qualifiedTagName(prefix, localName, xhtmlNamespaceURI);
454 RefPtr<FormatBlockCommand> command = FormatBlockCommand::create(frame->document(), qualifiedTagName);
455 applyCommand(command);
456 return command->didApply();
459 static bool executeForwardDelete(Frame* frame, Event*, EditorCommandSource source, const String&)
462 case CommandFromMenuOrKeyBinding:
463 frame->editor()->deleteWithDirection(DirectionForward, CharacterGranularity, false, true);
466 case CommandFromDOMWithUserInterface:
467 // Doesn't scroll to make the selection visible, or modify the kill ring.
468 // ForwardDelete is not implemented in IE or Firefox, so this behavior is only needed for
469 // backward compatibility with ourselves, and for consistency with Delete.
470 TypingCommand::forwardDeleteKeyPressed(frame->document());
473 ASSERT_NOT_REACHED();
477 static bool executeIgnoreSpelling(Frame* frame, Event*, EditorCommandSource, const String&)
479 frame->editor()->ignoreSpelling();
483 static bool executeIndent(Frame* frame, Event*, EditorCommandSource, const String&)
485 applyCommand(IndentOutdentCommand::create(frame->document(), IndentOutdentCommand::Indent));
489 static bool executeInsertBacktab(Frame* frame, Event* event, EditorCommandSource, const String&)
491 return targetFrame(frame, event)->eventHandler()->handleTextInputEvent("\t", event, TextEventInputBackTab);
494 static bool executeInsertHorizontalRule(Frame* frame, Event*, EditorCommandSource, const String& value)
496 RefPtr<HTMLHRElement> rule = HTMLHRElement::create(frame->document());
497 if (!value.isEmpty())
498 rule->setIdAttribute(value);
499 return executeInsertNode(frame, rule.release());
502 static bool executeInsertHTML(Frame* frame, Event*, EditorCommandSource, const String& value)
504 return executeInsertFragment(frame, createFragmentFromMarkup(frame->document(), value, ""));
507 static bool executeInsertImage(Frame* frame, Event*, EditorCommandSource, const String& value)
509 // FIXME: If userInterface is true, we should display a dialog box and let the user choose a local image.
510 RefPtr<HTMLImageElement> image = HTMLImageElement::create(frame->document());
511 image->setSrc(value);
512 return executeInsertNode(frame, image.release());
515 static bool executeInsertLineBreak(Frame* frame, Event* event, EditorCommandSource source, const String&)
518 case CommandFromMenuOrKeyBinding:
519 return targetFrame(frame, event)->eventHandler()->handleTextInputEvent("\n", event, TextEventInputLineBreak);
521 case CommandFromDOMWithUserInterface:
522 // Doesn't scroll to make the selection visible, or modify the kill ring.
523 // InsertLineBreak is not implemented in IE or Firefox, so this behavior is only needed for
524 // backward compatibility with ourselves, and for consistency with other commands.
525 TypingCommand::insertLineBreak(frame->document(), 0);
528 ASSERT_NOT_REACHED();
532 static bool executeInsertNewline(Frame* frame, Event* event, EditorCommandSource, const String&)
534 Frame* targetFrame = WebCore::targetFrame(frame, event);
535 return targetFrame->eventHandler()->handleTextInputEvent("\n", event, targetFrame->editor()->canEditRichly() ? TextEventInputKeyboard : TextEventInputLineBreak);
538 static bool executeInsertNewlineInQuotedContent(Frame* frame, Event*, EditorCommandSource, const String&)
540 TypingCommand::insertParagraphSeparatorInQuotedContent(frame->document());
544 static bool executeInsertOrderedList(Frame* frame, Event*, EditorCommandSource, const String&)
546 applyCommand(InsertListCommand::create(frame->document(), InsertListCommand::OrderedList));
550 static bool executeInsertParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
552 TypingCommand::insertParagraphSeparator(frame->document(), 0);
556 static bool executeInsertTab(Frame* frame, Event* event, EditorCommandSource, const String&)
558 return targetFrame(frame, event)->eventHandler()->handleTextInputEvent("\t", event);
561 static bool executeInsertText(Frame* frame, Event*, EditorCommandSource, const String& value)
563 TypingCommand::insertText(frame->document(), value, 0);
567 static bool executeInsertUnorderedList(Frame* frame, Event*, EditorCommandSource, const String&)
569 applyCommand(InsertListCommand::create(frame->document(), InsertListCommand::UnorderedList));
573 static bool executeJustifyCenter(Frame* frame, Event*, EditorCommandSource source, const String&)
575 return executeApplyParagraphStyle(frame, source, EditActionCenter, CSSPropertyTextAlign, "center");
578 static bool executeJustifyFull(Frame* frame, Event*, EditorCommandSource source, const String&)
580 return executeApplyParagraphStyle(frame, source, EditActionJustify, CSSPropertyTextAlign, "justify");
583 static bool executeJustifyLeft(Frame* frame, Event*, EditorCommandSource source, const String&)
585 return executeApplyParagraphStyle(frame, source, EditActionAlignLeft, CSSPropertyTextAlign, "left");
588 static bool executeJustifyRight(Frame* frame, Event*, EditorCommandSource source, const String&)
590 return executeApplyParagraphStyle(frame, source, EditActionAlignRight, CSSPropertyTextAlign, "right");
593 static bool executeMakeTextWritingDirectionLeftToRight(Frame* frame, Event*, EditorCommandSource, const String&)
595 RefPtr<StylePropertySet> style = StylePropertySet::create();
596 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed);
597 style->setProperty(CSSPropertyDirection, CSSValueLtr);
598 frame->editor()->applyStyle(style.get(), EditActionSetWritingDirection);
602 static bool executeMakeTextWritingDirectionNatural(Frame* frame, Event*, EditorCommandSource, const String&)
604 RefPtr<StylePropertySet> style = StylePropertySet::create();
605 style->setProperty(CSSPropertyUnicodeBidi, CSSValueNormal);
606 frame->editor()->applyStyle(style.get(), EditActionSetWritingDirection);
610 static bool executeMakeTextWritingDirectionRightToLeft(Frame* frame, Event*, EditorCommandSource, const String&)
612 RefPtr<StylePropertySet> style = StylePropertySet::create();
613 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed);
614 style->setProperty(CSSPropertyDirection, CSSValueRtl);
615 frame->editor()->applyStyle(style.get(), EditActionSetWritingDirection);
619 static bool executeMoveBackward(Frame* frame, Event*, EditorCommandSource, const String&)
621 frame->selection()->modify(FrameSelection::AlterationMove, DirectionBackward, CharacterGranularity, UserTriggered);
625 static bool executeMoveBackwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
627 frame->selection()->modify(FrameSelection::AlterationExtend, DirectionBackward, CharacterGranularity, UserTriggered);
631 static bool executeMoveDown(Frame* frame, Event*, EditorCommandSource, const String&)
633 return frame->selection()->modify(FrameSelection::AlterationMove, DirectionForward, LineGranularity, UserTriggered);
636 static bool executeMoveDownAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
638 frame->selection()->modify(FrameSelection::AlterationExtend, DirectionForward, LineGranularity, UserTriggered);
642 static bool executeMoveForward(Frame* frame, Event*, EditorCommandSource, const String&)
644 frame->selection()->modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity, UserTriggered);
648 static bool executeMoveForwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
650 frame->selection()->modify(FrameSelection::AlterationExtend, DirectionForward, CharacterGranularity, UserTriggered);
654 static bool executeMoveLeft(Frame* frame, Event*, EditorCommandSource, const String&)
656 return frame->selection()->modify(FrameSelection::AlterationMove, DirectionLeft, CharacterGranularity, UserTriggered);
659 static bool executeMoveLeftAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
661 frame->selection()->modify(FrameSelection::AlterationExtend, DirectionLeft, CharacterGranularity, UserTriggered);
665 static bool executeMovePageDown(Frame* frame, Event*, EditorCommandSource, const String&)
667 unsigned distance = verticalScrollDistance(frame);
670 return frame->selection()->modify(FrameSelection::AlterationMove, distance, FrameSelection::DirectionDown,
671 UserTriggered, FrameSelection::AlignCursorOnScrollAlways);
674 static bool executeMovePageDownAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
676 unsigned distance = verticalScrollDistance(frame);
679 return frame->selection()->modify(FrameSelection::AlterationExtend, distance, FrameSelection::DirectionDown,
680 UserTriggered, FrameSelection::AlignCursorOnScrollAlways);
683 static bool executeMovePageUp(Frame* frame, Event*, EditorCommandSource, const String&)
685 unsigned distance = verticalScrollDistance(frame);
688 return frame->selection()->modify(FrameSelection::AlterationMove, distance, FrameSelection::DirectionUp,
689 UserTriggered, FrameSelection::AlignCursorOnScrollAlways);
692 static bool executeMovePageUpAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
694 unsigned distance = verticalScrollDistance(frame);
697 return frame->selection()->modify(FrameSelection::AlterationExtend, distance, FrameSelection::DirectionUp,
698 UserTriggered, FrameSelection::AlignCursorOnScrollAlways);
701 static bool executeMoveRight(Frame* frame, Event*, EditorCommandSource, const String&)
703 return frame->selection()->modify(FrameSelection::AlterationMove, DirectionRight, CharacterGranularity, UserTriggered);
706 static bool executeMoveRightAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
708 frame->selection()->modify(FrameSelection::AlterationExtend, DirectionRight, CharacterGranularity, UserTriggered);
712 static bool executeMoveToBeginningOfDocument(Frame* frame, Event*, EditorCommandSource, const String&)
714 frame->selection()->modify(FrameSelection::AlterationMove, DirectionBackward, DocumentBoundary, UserTriggered);
718 static bool executeMoveToBeginningOfDocumentAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
720 frame->selection()->modify(FrameSelection::AlterationExtend, DirectionBackward, DocumentBoundary, UserTriggered);
724 static bool executeMoveToBeginningOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
726 frame->selection()->modify(FrameSelection::AlterationMove, DirectionBackward, LineBoundary, UserTriggered);
730 static bool executeMoveToBeginningOfLineAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
732 frame->selection()->modify(FrameSelection::AlterationExtend, DirectionBackward, LineBoundary, UserTriggered);
736 static bool executeMoveToBeginningOfParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
738 frame->selection()->modify(FrameSelection::AlterationMove, DirectionBackward, ParagraphBoundary, UserTriggered);
742 static bool executeMoveToBeginningOfParagraphAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
744 frame->selection()->modify(FrameSelection::AlterationExtend, DirectionBackward, ParagraphBoundary, UserTriggered);
748 static bool executeMoveToBeginningOfSentence(Frame* frame, Event*, EditorCommandSource, const String&)
750 frame->selection()->modify(FrameSelection::AlterationMove, DirectionBackward, SentenceBoundary, UserTriggered);
754 static bool executeMoveToBeginningOfSentenceAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
756 frame->selection()->modify(FrameSelection::AlterationExtend, DirectionBackward, SentenceBoundary, UserTriggered);
760 static bool executeMoveToEndOfDocument(Frame* frame, Event*, EditorCommandSource, const String&)
762 frame->selection()->modify(FrameSelection::AlterationMove, DirectionForward, DocumentBoundary, UserTriggered);
766 static bool executeMoveToEndOfDocumentAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
768 frame->selection()->modify(FrameSelection::AlterationExtend, DirectionForward, DocumentBoundary, UserTriggered);
772 static bool executeMoveToEndOfSentence(Frame* frame, Event*, EditorCommandSource, const String&)
774 frame->selection()->modify(FrameSelection::AlterationMove, DirectionForward, SentenceBoundary, UserTriggered);
778 static bool executeMoveToEndOfSentenceAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
780 frame->selection()->modify(FrameSelection::AlterationExtend, DirectionForward, SentenceBoundary, UserTriggered);
784 static bool executeMoveToEndOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
786 frame->selection()->modify(FrameSelection::AlterationMove, DirectionForward, LineBoundary, UserTriggered);
790 static bool executeMoveToEndOfLineAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
792 frame->selection()->modify(FrameSelection::AlterationExtend, DirectionForward, LineBoundary, UserTriggered);
796 static bool executeMoveToEndOfParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
798 frame->selection()->modify(FrameSelection::AlterationMove, DirectionForward, ParagraphBoundary, UserTriggered);
802 static bool executeMoveToEndOfParagraphAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
804 frame->selection()->modify(FrameSelection::AlterationExtend, DirectionForward, ParagraphBoundary, UserTriggered);
808 static bool executeMoveParagraphBackwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
810 frame->selection()->modify(FrameSelection::AlterationExtend, DirectionBackward, ParagraphGranularity, UserTriggered);
814 static bool executeMoveParagraphForwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
816 frame->selection()->modify(FrameSelection::AlterationExtend, DirectionForward, ParagraphGranularity, UserTriggered);
820 static bool executeMoveUp(Frame* frame, Event*, EditorCommandSource, const String&)
822 return frame->selection()->modify(FrameSelection::AlterationMove, DirectionBackward, LineGranularity, UserTriggered);
825 static bool executeMoveUpAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
827 frame->selection()->modify(FrameSelection::AlterationExtend, DirectionBackward, LineGranularity, UserTriggered);
831 static bool executeMoveWordBackward(Frame* frame, Event*, EditorCommandSource, const String&)
833 frame->selection()->modify(FrameSelection::AlterationMove, DirectionBackward, WordGranularity, UserTriggered);
837 static bool executeMoveWordBackwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
839 frame->selection()->modify(FrameSelection::AlterationExtend, DirectionBackward, WordGranularity, UserTriggered);
843 static bool executeMoveWordForward(Frame* frame, Event*, EditorCommandSource, const String&)
845 frame->selection()->modify(FrameSelection::AlterationMove, DirectionForward, WordGranularity, UserTriggered);
849 static bool executeMoveWordForwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
851 frame->selection()->modify(FrameSelection::AlterationExtend, DirectionForward, WordGranularity, UserTriggered);
855 static bool executeMoveWordLeft(Frame* frame, Event*, EditorCommandSource, const String&)
857 frame->selection()->modify(FrameSelection::AlterationMove, DirectionLeft, WordGranularity, UserTriggered);
861 static bool executeMoveWordLeftAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
863 frame->selection()->modify(FrameSelection::AlterationExtend, DirectionLeft, WordGranularity, UserTriggered);
867 static bool executeMoveWordRight(Frame* frame, Event*, EditorCommandSource, const String&)
869 frame->selection()->modify(FrameSelection::AlterationMove, DirectionRight, WordGranularity, UserTriggered);
873 static bool executeMoveWordRightAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
875 frame->selection()->modify(FrameSelection::AlterationExtend, DirectionRight, WordGranularity, UserTriggered);
879 static bool executeMoveToLeftEndOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
881 frame->selection()->modify(FrameSelection::AlterationMove, DirectionLeft, LineBoundary, UserTriggered);
885 static bool executeMoveToLeftEndOfLineAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
887 frame->selection()->modify(FrameSelection::AlterationExtend, DirectionLeft, LineBoundary, UserTriggered);
891 static bool executeMoveToRightEndOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
893 frame->selection()->modify(FrameSelection::AlterationMove, DirectionRight, LineBoundary, UserTriggered);
897 static bool executeMoveToRightEndOfLineAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
899 frame->selection()->modify(FrameSelection::AlterationExtend, DirectionRight, LineBoundary, UserTriggered);
903 static bool executeOutdent(Frame* frame, Event*, EditorCommandSource, const String&)
905 applyCommand(IndentOutdentCommand::create(frame->document(), IndentOutdentCommand::Outdent));
909 static bool executePaste(Frame* frame, Event*, EditorCommandSource source, const String&)
911 if (source == CommandFromMenuOrKeyBinding) {
912 UserTypingGestureIndicator typingGestureIndicator(frame);
913 frame->editor()->paste();
915 frame->editor()->paste();
919 static bool executePasteAndMatchStyle(Frame* frame, Event*, EditorCommandSource source, const String&)
921 if (source == CommandFromMenuOrKeyBinding) {
922 UserTypingGestureIndicator typingGestureIndicator(frame);
923 frame->editor()->pasteAsPlainText();
925 frame->editor()->pasteAsPlainText();
929 static bool executePasteAsPlainText(Frame* frame, Event*, EditorCommandSource source, const String&)
931 if (source == CommandFromMenuOrKeyBinding) {
932 UserTypingGestureIndicator typingGestureIndicator(frame);
933 frame->editor()->pasteAsPlainText();
935 frame->editor()->pasteAsPlainText();
939 static bool executePrint(Frame* frame, Event*, EditorCommandSource, const String&)
941 Page* page = frame->page();
944 page->chrome()->print(frame);
948 static bool executeRedo(Frame* frame, Event*, EditorCommandSource, const String&)
950 frame->editor()->redo();
954 static bool executeRemoveFormat(Frame* frame, Event*, EditorCommandSource, const String&)
956 frame->editor()->removeFormattingAndStyle();
960 static bool executeScrollPageBackward(Frame* frame, Event*, EditorCommandSource, const String&)
962 return frame->eventHandler()->logicalScrollRecursively(ScrollBlockDirectionBackward, ScrollByPage);
965 static bool executeScrollPageForward(Frame* frame, Event*, EditorCommandSource, const String&)
967 return frame->eventHandler()->logicalScrollRecursively(ScrollBlockDirectionForward, ScrollByPage);
970 static bool executeScrollLineUp(Frame* frame, Event*, EditorCommandSource, const String&)
972 return frame->eventHandler()->scrollRecursively(ScrollUp, ScrollByLine);
975 static bool executeScrollLineDown(Frame* frame, Event*, EditorCommandSource, const String&)
977 return frame->eventHandler()->scrollRecursively(ScrollDown, ScrollByLine);
980 static bool executeScrollToBeginningOfDocument(Frame* frame, Event*, EditorCommandSource, const String&)
982 return frame->eventHandler()->logicalScrollRecursively(ScrollBlockDirectionBackward, ScrollByDocument);
985 static bool executeScrollToEndOfDocument(Frame* frame, Event*, EditorCommandSource, const String&)
987 return frame->eventHandler()->logicalScrollRecursively(ScrollBlockDirectionForward, ScrollByDocument);
990 static bool executeSelectAll(Frame* frame, Event*, EditorCommandSource, const String&)
992 frame->selection()->selectAll();
996 static bool executeSelectLine(Frame* frame, Event*, EditorCommandSource, const String&)
998 return expandSelectionToGranularity(frame, LineGranularity);
1001 static bool executeSelectParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
1003 return expandSelectionToGranularity(frame, ParagraphGranularity);
1006 static bool executeSelectSentence(Frame* frame, Event*, EditorCommandSource, const String&)
1008 return expandSelectionToGranularity(frame, SentenceGranularity);
1011 static bool executeSelectToMark(Frame* frame, Event*, EditorCommandSource, const String&)
1013 RefPtr<Range> mark = frame->editor()->mark().toNormalizedRange();
1014 RefPtr<Range> selection = frame->editor()->selectedRange();
1015 if (!mark || !selection) {
1019 frame->selection()->setSelectedRange(unionDOMRanges(mark.get(), selection.get()).get(), DOWNSTREAM, true);
1023 static bool executeSelectWord(Frame* frame, Event*, EditorCommandSource, const String&)
1025 return expandSelectionToGranularity(frame, WordGranularity);
1028 static bool executeSetMark(Frame* frame, Event*, EditorCommandSource, const String&)
1030 frame->editor()->setMark(frame->selection()->selection());
1034 static bool executeStrikethrough(Frame* frame, Event*, EditorCommandSource source, const String&)
1036 RefPtr<CSSPrimitiveValue> lineThrough = CSSPrimitiveValue::createIdentifier(CSSValueLineThrough);
1037 return executeToggleStyleInList(frame, source, EditActionUnderline, CSSPropertyWebkitTextDecorationsInEffect, lineThrough.get());
1040 static bool executeStyleWithCSS(Frame* frame, Event*, EditorCommandSource, const String& value)
1042 frame->editor()->setShouldStyleWithCSS(!equalIgnoringCase(value, "false"));
1046 static bool executeUseCSS(Frame* frame, Event*, EditorCommandSource, const String& value)
1048 frame->editor()->setShouldStyleWithCSS(equalIgnoringCase(value, "false"));
1052 static bool executeSubscript(Frame* frame, Event*, EditorCommandSource source, const String&)
1054 return executeToggleStyle(frame, source, EditActionSubscript, CSSPropertyVerticalAlign, "baseline", "sub");
1057 static bool executeSuperscript(Frame* frame, Event*, EditorCommandSource source, const String&)
1059 return executeToggleStyle(frame, source, EditActionSuperscript, CSSPropertyVerticalAlign, "baseline", "super");
1062 static bool executeSwapWithMark(Frame* frame, Event*, EditorCommandSource, const String&)
1064 const VisibleSelection& mark = frame->editor()->mark();
1065 const VisibleSelection& selection = frame->selection()->selection();
1066 if (mark.isNone() || selection.isNone()) {
1070 frame->selection()->setSelection(mark);
1071 frame->editor()->setMark(selection);
1076 static bool executeTakeFindStringFromSelection(Frame* frame, Event*, EditorCommandSource, const String&)
1078 frame->editor()->takeFindStringFromSelection();
1083 static bool executeToggleBold(Frame* frame, Event*, EditorCommandSource source, const String&)
1085 return executeToggleStyle(frame, source, EditActionChangeAttributes, CSSPropertyFontWeight, "normal", "bold");
1088 static bool executeToggleItalic(Frame* frame, Event*, EditorCommandSource source, const String&)
1090 return executeToggleStyle(frame, source, EditActionChangeAttributes, CSSPropertyFontStyle, "normal", "italic");
1093 static bool executeTranspose(Frame* frame, Event*, EditorCommandSource, const String&)
1095 frame->editor()->transpose();
1099 static bool executeUnderline(Frame* frame, Event*, EditorCommandSource source, const String&)
1101 RefPtr<CSSPrimitiveValue> underline = CSSPrimitiveValue::createIdentifier(CSSValueUnderline);
1102 return executeToggleStyleInList(frame, source, EditActionUnderline, CSSPropertyWebkitTextDecorationsInEffect, underline.get());
1105 static bool executeUndo(Frame* frame, Event*, EditorCommandSource, const String&)
1107 frame->editor()->undo();
1111 static bool executeUnlink(Frame* frame, Event*, EditorCommandSource, const String&)
1113 applyCommand(UnlinkCommand::create(frame->document()));
1117 static bool executeUnscript(Frame* frame, Event*, EditorCommandSource source, const String&)
1119 return executeApplyStyle(frame, source, EditActionUnscript, CSSPropertyVerticalAlign, "baseline");
1122 static bool executeUnselect(Frame* frame, Event*, EditorCommandSource, const String&)
1124 frame->selection()->clear();
1128 static bool executeYank(Frame* frame, Event*, EditorCommandSource, const String&)
1130 frame->editor()->insertTextWithoutSendingTextEvent(frame->editor()->killRing()->yank(), false, 0);
1131 frame->editor()->killRing()->setToYankedState();
1135 static bool executeYankAndSelect(Frame* frame, Event*, EditorCommandSource, const String&)
1137 frame->editor()->insertTextWithoutSendingTextEvent(frame->editor()->killRing()->yank(), true, 0);
1138 frame->editor()->killRing()->setToYankedState();
1142 // Supported functions
1144 static bool supported(Frame*)
1149 static bool supportedFromMenuOrKeyBinding(Frame*)
1154 static bool supportedCopyCut(Frame* frame)
1159 Settings* settings = frame->settings();
1160 bool defaultValue = settings && settings->javaScriptCanAccessClipboard();
1162 EditorClient* client = frame->editor()->client();
1163 return client ? client->canCopyCut(frame, defaultValue) : defaultValue;
1166 static bool supportedPaste(Frame* frame)
1171 Settings* settings = frame->settings();
1172 bool defaultValue = settings && settings->javaScriptCanAccessClipboard() && settings->isDOMPasteAllowed();
1174 EditorClient* client = frame->editor()->client();
1175 return client ? client->canPaste(frame, defaultValue) : defaultValue;
1178 // Enabled functions
1180 static bool enabled(Frame*, Event*, EditorCommandSource)
1185 static bool enabledVisibleSelection(Frame* frame, Event* event, EditorCommandSource)
1187 // The term "visible" here includes a caret in editable text or a range in any text.
1188 const VisibleSelection& selection = frame->editor()->selectionForCommand(event);
1189 return (selection.isCaret() && selection.isContentEditable()) || selection.isRange();
1192 static bool caretBrowsingEnabled(Frame* frame)
1194 return frame->settings() && frame->settings()->caretBrowsingEnabled();
1197 static EditorCommandSource dummyEditorCommandSource = static_cast<EditorCommandSource>(0);
1199 static bool enabledVisibleSelectionOrCaretBrowsing(Frame* frame, Event* event, EditorCommandSource)
1201 // The EditorCommandSource parameter is unused in enabledVisibleSelection, so just pass a dummy variable
1202 return caretBrowsingEnabled(frame) || enabledVisibleSelection(frame, event, dummyEditorCommandSource);
1205 static bool enabledVisibleSelectionAndMark(Frame* frame, Event* event, EditorCommandSource)
1207 const VisibleSelection& selection = frame->editor()->selectionForCommand(event);
1208 return ((selection.isCaret() && selection.isContentEditable()) || selection.isRange())
1209 && frame->editor()->mark().isCaretOrRange();
1212 static bool enableCaretInEditableText(Frame* frame, Event* event, EditorCommandSource)
1214 const VisibleSelection& selection = frame->editor()->selectionForCommand(event);
1215 return selection.isCaret() && selection.isContentEditable();
1218 static bool enabledCopy(Frame* frame, Event*, EditorCommandSource)
1220 return frame->editor()->canDHTMLCopy() || frame->editor()->canCopy();
1223 static bool enabledCut(Frame* frame, Event*, EditorCommandSource)
1225 return frame->editor()->canDHTMLCut() || frame->editor()->canCut();
1228 static bool enabledInEditableText(Frame* frame, Event* event, EditorCommandSource)
1230 return frame->editor()->selectionForCommand(event).rootEditableElement();
1233 static bool enabledDelete(Frame* frame, Event* event, EditorCommandSource source)
1236 case CommandFromMenuOrKeyBinding:
1237 // "Delete" from menu only affects selected range, just like Cut but without affecting pasteboard
1238 return enabledCut(frame, event, source);
1239 case CommandFromDOM:
1240 case CommandFromDOMWithUserInterface:
1241 // "Delete" from DOM is like delete/backspace keypress, affects selected range if non-empty,
1242 // otherwise removes a character
1243 return enabledInEditableText(frame, event, source);
1245 ASSERT_NOT_REACHED();
1249 static bool enabledInEditableTextOrCaretBrowsing(Frame* frame, Event* event, EditorCommandSource)
1251 // The EditorCommandSource parameter is unused in enabledInEditableText, so just pass a dummy variable
1252 return caretBrowsingEnabled(frame) || enabledInEditableText(frame, event, dummyEditorCommandSource);
1255 static bool enabledInRichlyEditableText(Frame* frame, Event*, EditorCommandSource)
1257 return frame->selection()->isCaretOrRange() && frame->selection()->isContentRichlyEditable() && frame->selection()->rootEditableElement();
1260 static bool enabledPaste(Frame* frame, Event*, EditorCommandSource)
1262 return frame->editor()->canPaste();
1265 static bool enabledRangeInEditableText(Frame* frame, Event*, EditorCommandSource)
1267 return frame->selection()->isRange() && frame->selection()->isContentEditable();
1270 static bool enabledRangeInRichlyEditableText(Frame* frame, Event*, EditorCommandSource)
1272 return frame->selection()->isRange() && frame->selection()->isContentRichlyEditable();
1275 static bool enabledRedo(Frame* frame, Event*, EditorCommandSource)
1277 return frame->editor()->canRedo();
1281 static bool enabledTakeFindStringFromSelection(Frame* frame, Event*, EditorCommandSource)
1283 return frame->editor()->canCopyExcludingStandaloneImages();
1287 static bool enabledUndo(Frame* frame, Event*, EditorCommandSource)
1289 return frame->editor()->canUndo();
1294 static TriState stateNone(Frame*, Event*)
1296 return FalseTriState;
1299 static TriState stateBold(Frame* frame, Event*)
1301 return stateStyle(frame, CSSPropertyFontWeight, "bold");
1304 static TriState stateItalic(Frame* frame, Event*)
1306 return stateStyle(frame, CSSPropertyFontStyle, "italic");
1309 static TriState stateOrderedList(Frame* frame, Event*)
1311 return frame->editor()->selectionOrderedListState();
1314 static TriState stateStrikethrough(Frame* frame, Event*)
1316 return stateStyle(frame, CSSPropertyWebkitTextDecorationsInEffect, "line-through");
1319 static TriState stateStyleWithCSS(Frame* frame, Event*)
1321 return frame->editor()->shouldStyleWithCSS() ? TrueTriState : FalseTriState;
1324 static TriState stateSubscript(Frame* frame, Event*)
1326 return stateStyle(frame, CSSPropertyVerticalAlign, "sub");
1329 static TriState stateSuperscript(Frame* frame, Event*)
1331 return stateStyle(frame, CSSPropertyVerticalAlign, "super");
1334 static TriState stateTextWritingDirectionLeftToRight(Frame* frame, Event*)
1336 return stateTextWritingDirection(frame, LeftToRightWritingDirection);
1339 static TriState stateTextWritingDirectionNatural(Frame* frame, Event*)
1341 return stateTextWritingDirection(frame, NaturalWritingDirection);
1344 static TriState stateTextWritingDirectionRightToLeft(Frame* frame, Event*)
1346 return stateTextWritingDirection(frame, RightToLeftWritingDirection);
1349 static TriState stateUnderline(Frame* frame, Event*)
1351 return stateStyle(frame, CSSPropertyWebkitTextDecorationsInEffect, "underline");
1354 static TriState stateUnorderedList(Frame* frame, Event*)
1356 return frame->editor()->selectionUnorderedListState();
1359 static TriState stateJustifyCenter(Frame* frame, Event*)
1361 return stateStyle(frame, CSSPropertyTextAlign, "center");
1364 static TriState stateJustifyFull(Frame* frame, Event*)
1366 return stateStyle(frame, CSSPropertyTextAlign, "justify");
1369 static TriState stateJustifyLeft(Frame* frame, Event*)
1371 return stateStyle(frame, CSSPropertyTextAlign, "left");
1374 static TriState stateJustifyRight(Frame* frame, Event*)
1376 return stateStyle(frame, CSSPropertyTextAlign, "right");
1381 static String valueNull(Frame*, Event*)
1386 static String valueBackColor(Frame* frame, Event*)
1388 return valueStyle(frame, CSSPropertyBackgroundColor);
1391 static String valueDefaultParagraphSeparator(Frame* frame, Event*)
1393 switch (frame->editor()->defaultParagraphSeparator()) {
1394 case EditorParagraphSeparatorIsDiv:
1395 return divTag.localName();
1396 case EditorParagraphSeparatorIsP:
1397 return pTag.localName();
1400 ASSERT_NOT_REACHED();
1404 static String valueFontName(Frame* frame, Event*)
1406 return valueStyle(frame, CSSPropertyFontFamily);
1409 static String valueFontSize(Frame* frame, Event*)
1411 return valueStyle(frame, CSSPropertyFontSize);
1414 static String valueFontSizeDelta(Frame* frame, Event*)
1416 return valueStyle(frame, CSSPropertyWebkitFontSizeDelta);
1419 static String valueForeColor(Frame* frame, Event*)
1421 return valueStyle(frame, CSSPropertyColor);
1424 static String valueFormatBlock(Frame* frame, Event*)
1426 const VisibleSelection& selection = frame->selection()->selection();
1427 if (!selection.isNonOrphanedCaretOrRange() || !selection.isContentEditable())
1429 Element* formatBlockElement = FormatBlockCommand::elementForFormatBlockCommand(selection.firstRange().get());
1430 if (!formatBlockElement)
1432 return formatBlockElement->localName();
1437 struct CommandEntry {
1439 EditorInternalCommand command;
1442 static const CommandMap& createCommandMap()
1444 static const CommandEntry commands[] = {
1445 { "AlignCenter", { executeJustifyCenter, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1446 { "AlignJustified", { executeJustifyFull, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1447 { "AlignLeft", { executeJustifyLeft, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1448 { "AlignRight", { executeJustifyRight, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1449 { "BackColor", { executeBackColor, supported, enabledInRichlyEditableText, stateNone, valueBackColor, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1450 { "BackwardDelete", { executeDeleteBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, // FIXME: remove BackwardDelete when Safari for Windows stops using it.
1451 { "Bold", { executeToggleBold, supported, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1452 { "Copy", { executeCopy, supportedCopyCut, enabledCopy, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1453 { "CreateLink", { executeCreateLink, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1454 { "Cut", { executeCut, supportedCopyCut, enabledCut, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1455 { "DefaultParagraphSeparator", { executeDefaultParagraphSeparator, supported, enabled, stateNone, valueDefaultParagraphSeparator, notTextInsertion, doNotAllowExecutionWhenDisabled} },
1456 { "Delete", { executeDelete, supported, enabledDelete, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1457 { "DeleteBackward", { executeDeleteBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1458 { "DeleteBackwardByDecomposingPreviousCharacter", { executeDeleteBackwardByDecomposingPreviousCharacter, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1459 { "DeleteForward", { executeDeleteForward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1460 { "DeleteToBeginningOfLine", { executeDeleteToBeginningOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1461 { "DeleteToBeginningOfParagraph", { executeDeleteToBeginningOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1462 { "DeleteToEndOfLine", { executeDeleteToEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1463 { "DeleteToEndOfParagraph", { executeDeleteToEndOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1464 { "DeleteToMark", { executeDeleteToMark, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1465 { "DeleteWordBackward", { executeDeleteWordBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1466 { "DeleteWordForward", { executeDeleteWordForward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1467 { "FindString", { executeFindString, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1468 { "FontName", { executeFontName, supported, enabledInEditableText, stateNone, valueFontName, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1469 { "FontSize", { executeFontSize, supported, enabledInEditableText, stateNone, valueFontSize, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1470 { "FontSizeDelta", { executeFontSizeDelta, supported, enabledInEditableText, stateNone, valueFontSizeDelta, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1471 { "ForeColor", { executeForeColor, supported, enabledInRichlyEditableText, stateNone, valueForeColor, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1472 { "FormatBlock", { executeFormatBlock, supported, enabledInRichlyEditableText, stateNone, valueFormatBlock, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1473 { "ForwardDelete", { executeForwardDelete, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1474 { "HiliteColor", { executeBackColor, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1475 { "IgnoreSpelling", { executeIgnoreSpelling, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1476 { "Indent", { executeIndent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1477 { "InsertBacktab", { executeInsertBacktab, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1478 { "InsertHTML", { executeInsertHTML, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1479 { "InsertHorizontalRule", { executeInsertHorizontalRule, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1480 { "InsertImage", { executeInsertImage, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1481 { "InsertLineBreak", { executeInsertLineBreak, supported, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1482 { "InsertNewline", { executeInsertNewline, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1483 { "InsertNewlineInQuotedContent", { executeInsertNewlineInQuotedContent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1484 { "InsertOrderedList", { executeInsertOrderedList, supported, enabledInRichlyEditableText, stateOrderedList, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1485 { "InsertParagraph", { executeInsertParagraph, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1486 { "InsertTab", { executeInsertTab, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1487 { "InsertText", { executeInsertText, supported, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1488 { "InsertUnorderedList", { executeInsertUnorderedList, supported, enabledInRichlyEditableText, stateUnorderedList, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1489 { "Italic", { executeToggleItalic, supported, enabledInRichlyEditableText, stateItalic, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1490 { "JustifyCenter", { executeJustifyCenter, supported, enabledInRichlyEditableText, stateJustifyCenter, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1491 { "JustifyFull", { executeJustifyFull, supported, enabledInRichlyEditableText, stateJustifyFull, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1492 { "JustifyLeft", { executeJustifyLeft, supported, enabledInRichlyEditableText, stateJustifyLeft, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1493 { "JustifyNone", { executeJustifyLeft, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1494 { "JustifyRight", { executeJustifyRight, supported, enabledInRichlyEditableText, stateJustifyRight, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1495 { "MakeTextWritingDirectionLeftToRight", { executeMakeTextWritingDirectionLeftToRight, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionLeftToRight, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1496 { "MakeTextWritingDirectionNatural", { executeMakeTextWritingDirectionNatural, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionNatural, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1497 { "MakeTextWritingDirectionRightToLeft", { executeMakeTextWritingDirectionRightToLeft, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionRightToLeft, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1498 { "MoveBackward", { executeMoveBackward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1499 { "MoveBackwardAndModifySelection", { executeMoveBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1500 { "MoveDown", { executeMoveDown, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1501 { "MoveDownAndModifySelection", { executeMoveDownAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1502 { "MoveForward", { executeMoveForward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1503 { "MoveForwardAndModifySelection", { executeMoveForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1504 { "MoveLeft", { executeMoveLeft, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1505 { "MoveLeftAndModifySelection", { executeMoveLeftAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1506 { "MovePageDown", { executeMovePageDown, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1507 { "MovePageDownAndModifySelection", { executeMovePageDownAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1508 { "MovePageUp", { executeMovePageUp, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1509 { "MovePageUpAndModifySelection", { executeMovePageUpAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1510 { "MoveParagraphBackwardAndModifySelection", { executeMoveParagraphBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1511 { "MoveParagraphForwardAndModifySelection", { executeMoveParagraphForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1512 { "MoveRight", { executeMoveRight, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1513 { "MoveRightAndModifySelection", { executeMoveRightAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1514 { "MoveToBeginningOfDocument", { executeMoveToBeginningOfDocument, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1515 { "MoveToBeginningOfDocumentAndModifySelection", { executeMoveToBeginningOfDocumentAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1516 { "MoveToBeginningOfLine", { executeMoveToBeginningOfLine, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1517 { "MoveToBeginningOfLineAndModifySelection", { executeMoveToBeginningOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1518 { "MoveToBeginningOfParagraph", { executeMoveToBeginningOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1519 { "MoveToBeginningOfParagraphAndModifySelection", { executeMoveToBeginningOfParagraphAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1520 { "MoveToBeginningOfSentence", { executeMoveToBeginningOfSentence, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1521 { "MoveToBeginningOfSentenceAndModifySelection", { executeMoveToBeginningOfSentenceAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1522 { "MoveToEndOfDocument", { executeMoveToEndOfDocument, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1523 { "MoveToEndOfDocumentAndModifySelection", { executeMoveToEndOfDocumentAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1524 { "MoveToEndOfLine", { executeMoveToEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1525 { "MoveToEndOfLineAndModifySelection", { executeMoveToEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1526 { "MoveToEndOfParagraph", { executeMoveToEndOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1527 { "MoveToEndOfParagraphAndModifySelection", { executeMoveToEndOfParagraphAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1528 { "MoveToEndOfSentence", { executeMoveToEndOfSentence, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1529 { "MoveToEndOfSentenceAndModifySelection", { executeMoveToEndOfSentenceAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1530 { "MoveToLeftEndOfLine", { executeMoveToLeftEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1531 { "MoveToLeftEndOfLineAndModifySelection", { executeMoveToLeftEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1532 { "MoveToRightEndOfLine", { executeMoveToRightEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1533 { "MoveToRightEndOfLineAndModifySelection", { executeMoveToRightEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1534 { "MoveUp", { executeMoveUp, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1535 { "MoveUpAndModifySelection", { executeMoveUpAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1536 { "MoveWordBackward", { executeMoveWordBackward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1537 { "MoveWordBackwardAndModifySelection", { executeMoveWordBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1538 { "MoveWordForward", { executeMoveWordForward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1539 { "MoveWordForwardAndModifySelection", { executeMoveWordForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1540 { "MoveWordLeft", { executeMoveWordLeft, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1541 { "MoveWordLeftAndModifySelection", { executeMoveWordLeftAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1542 { "MoveWordRight", { executeMoveWordRight, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1543 { "MoveWordRightAndModifySelection", { executeMoveWordRightAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1544 { "Outdent", { executeOutdent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1545 { "Paste", { executePaste, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1546 { "PasteAndMatchStyle", { executePasteAndMatchStyle, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1547 { "PasteAsPlainText", { executePasteAsPlainText, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1548 { "Print", { executePrint, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1549 { "Redo", { executeRedo, supported, enabledRedo, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1550 { "RemoveFormat", { executeRemoveFormat, supported, enabledRangeInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1551 { "ScrollPageBackward", { executeScrollPageBackward, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1552 { "ScrollPageForward", { executeScrollPageForward, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1553 { "ScrollLineUp", { executeScrollLineUp, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1554 { "ScrollLineDown", { executeScrollLineDown, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1555 { "ScrollToBeginningOfDocument", { executeScrollToBeginningOfDocument, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1556 { "ScrollToEndOfDocument", { executeScrollToEndOfDocument, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1557 { "SelectAll", { executeSelectAll, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1558 { "SelectLine", { executeSelectLine, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1559 { "SelectParagraph", { executeSelectParagraph, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1560 { "SelectSentence", { executeSelectSentence, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1561 { "SelectToMark", { executeSelectToMark, supportedFromMenuOrKeyBinding, enabledVisibleSelectionAndMark, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1562 { "SelectWord", { executeSelectWord, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1563 { "SetMark", { executeSetMark, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1564 { "Strikethrough", { executeStrikethrough, supported, enabledInRichlyEditableText, stateStrikethrough, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1565 { "StyleWithCSS", { executeStyleWithCSS, supported, enabled, stateStyleWithCSS, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1566 { "Subscript", { executeSubscript, supported, enabledInRichlyEditableText, stateSubscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1567 { "Superscript", { executeSuperscript, supported, enabledInRichlyEditableText, stateSuperscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1568 { "SwapWithMark", { executeSwapWithMark, supportedFromMenuOrKeyBinding, enabledVisibleSelectionAndMark, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1569 { "ToggleBold", { executeToggleBold, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1570 { "ToggleItalic", { executeToggleItalic, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateItalic, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1571 { "ToggleUnderline", { executeUnderline, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateUnderline, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1572 { "Transpose", { executeTranspose, supported, enableCaretInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1573 { "Underline", { executeUnderline, supported, enabledInRichlyEditableText, stateUnderline, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1574 { "Undo", { executeUndo, supported, enabledUndo, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1575 { "Unlink", { executeUnlink, supported, enabledRangeInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1576 { "Unscript", { executeUnscript, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1577 { "Unselect", { executeUnselect, supported, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1578 { "UseCSS", { executeUseCSS, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1579 { "Yank", { executeYank, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1580 { "YankAndSelect", { executeYankAndSelect, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1583 { "TakeFindStringFromSelection", { executeTakeFindStringFromSelection, supportedFromMenuOrKeyBinding, enabledTakeFindStringFromSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1587 // These unsupported commands are listed here since they appear in the Microsoft
1588 // documentation used as the starting point for our DOM executeCommand support.
1590 // 2D-Position (not supported)
1591 // AbsolutePosition (not supported)
1592 // BlockDirLTR (not supported)
1593 // BlockDirRTL (not supported)
1594 // BrowseMode (not supported)
1595 // ClearAuthenticationCache (not supported)
1596 // CreateBookmark (not supported)
1597 // DirLTR (not supported)
1598 // DirRTL (not supported)
1599 // EditMode (not supported)
1600 // InlineDirLTR (not supported)
1601 // InlineDirRTL (not supported)
1602 // InsertButton (not supported)
1603 // InsertFieldSet (not supported)
1604 // InsertIFrame (not supported)
1605 // InsertInputButton (not supported)
1606 // InsertInputCheckbox (not supported)
1607 // InsertInputFileUpload (not supported)
1608 // InsertInputHidden (not supported)
1609 // InsertInputImage (not supported)
1610 // InsertInputPassword (not supported)
1611 // InsertInputRadio (not supported)
1612 // InsertInputReset (not supported)
1613 // InsertInputSubmit (not supported)
1614 // InsertInputText (not supported)
1615 // InsertMarquee (not supported)
1616 // InsertSelectDropDown (not supported)
1617 // InsertSelectListBox (not supported)
1618 // InsertTextArea (not supported)
1619 // LiveResize (not supported)
1620 // MultipleSelection (not supported)
1621 // Open (not supported)
1622 // Overwrite (not supported)
1623 // PlayImage (not supported)
1624 // Refresh (not supported)
1625 // RemoveParaFormat (not supported)
1626 // SaveAs (not supported)
1627 // SizeToControl (not supported)
1628 // SizeToControlHeight (not supported)
1629 // SizeToControlWidth (not supported)
1630 // Stop (not supported)
1631 // StopImage (not supported)
1632 // Unbookmark (not supported)
1634 CommandMap& commandMap = *new CommandMap;
1636 for (size_t i = 0; i < WTF_ARRAY_LENGTH(commands); ++i) {
1637 ASSERT(!commandMap.get(commands[i].name));
1638 commandMap.set(commands[i].name, &commands[i].command);
1644 static const EditorInternalCommand* internalCommand(const String& commandName)
1646 static const CommandMap& commandMap = createCommandMap();
1647 return commandName.isEmpty() ? 0 : commandMap.get(commandName);
1650 Editor::Command Editor::command(const String& commandName)
1652 return Command(internalCommand(commandName), CommandFromMenuOrKeyBinding, m_frame);
1655 Editor::Command Editor::command(const String& commandName, EditorCommandSource source)
1657 return Command(internalCommand(commandName), source, m_frame);
1660 bool Editor::commandIsSupportedFromMenuOrKeyBinding(const String& commandName)
1662 return internalCommand(commandName);
1665 Editor::Command::Command()
1670 Editor::Command::Command(const EditorInternalCommand* command, EditorCommandSource source, PassRefPtr<Frame> frame)
1671 : m_command(command)
1673 , m_frame(command ? frame : 0)
1675 // Use separate assertions so we can tell which bad thing happened.
1682 bool Editor::Command::execute(const String& parameter, Event* triggeringEvent) const
1684 if (!isEnabled(triggeringEvent)) {
1685 // Let certain commands be executed when performed explicitly even if they are disabled.
1686 if (!isSupported() || !m_frame || !m_command->allowExecutionWhenDisabled)
1689 m_frame->document()->updateLayoutIgnorePendingStylesheets();
1690 #if ENABLE(TIZEN_ISF_PORT)
1691 EditorClient* client = m_frame->editor()->client();
1693 client->lockRespondToChangedSelection();
1694 bool result = m_command->execute(m_frame.get(), triggeringEvent, m_source, parameter);
1695 client->unlockRespondToChangedSelection();
1699 return m_command->execute(m_frame.get(), triggeringEvent, m_source, parameter);
1702 bool Editor::Command::execute(Event* triggeringEvent) const
1704 return execute(String(), triggeringEvent);
1707 bool Editor::Command::isSupported() const
1712 case CommandFromMenuOrKeyBinding:
1714 case CommandFromDOM:
1715 case CommandFromDOMWithUserInterface:
1716 return m_command->isSupportedFromDOM(m_frame.get());
1718 ASSERT_NOT_REACHED();
1722 bool Editor::Command::isEnabled(Event* triggeringEvent) const
1724 if (!isSupported() || !m_frame)
1726 return m_command->isEnabled(m_frame.get(), triggeringEvent, m_source);
1729 TriState Editor::Command::state(Event* triggeringEvent) const
1731 if (!isSupported() || !m_frame)
1732 return FalseTriState;
1733 return m_command->state(m_frame.get(), triggeringEvent);
1736 String Editor::Command::value(Event* triggeringEvent) const
1738 if (!isSupported() || !m_frame)
1740 if (m_command->value == valueNull && m_command->state != stateNone)
1741 return m_command->state(m_frame.get(), triggeringEvent) == TrueTriState ? "true" : "false";
1742 return m_command->value(m_frame.get(), triggeringEvent);
1745 bool Editor::Command::isTextInsertion() const
1747 return m_command && m_command->isTextInsertion;
1750 } // namespace WebCore