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.
29 #include "core/editing/Editor.h"
31 #include "CSSPropertyNames.h"
32 #include "CSSValueKeywords.h"
33 #include "HTMLNames.h"
34 #include "bindings/v8/ExceptionState.h"
35 #include "bindings/v8/ExceptionStatePlaceholder.h"
36 #include "core/css/CSSValueList.h"
37 #include "core/css/StylePropertySet.h"
38 #include "core/dom/DocumentFragment.h"
39 #include "core/events/Event.h"
40 #include "core/editing/CreateLinkCommand.h"
41 #include "core/editing/FormatBlockCommand.h"
42 #include "core/editing/IndentOutdentCommand.h"
43 #include "core/editing/InsertListCommand.h"
44 #include "core/editing/ReplaceSelectionCommand.h"
45 #include "core/editing/SpellChecker.h"
46 #include "core/editing/TypingCommand.h"
47 #include "core/editing/UnlinkCommand.h"
48 #include "core/editing/markup.h"
49 #include "core/html/HTMLFontElement.h"
50 #include "core/html/HTMLHRElement.h"
51 #include "core/html/HTMLImageElement.h"
52 #include "core/page/Chrome.h"
53 #include "core/page/EditorClient.h"
54 #include "core/page/EventHandler.h"
55 #include "core/frame/Frame.h"
56 #include "core/frame/FrameView.h"
57 #include "core/page/Page.h"
58 #include "core/page/Settings.h"
59 #include "core/platform/KillRing.h"
60 #include "core/platform/Pasteboard.h"
61 #include "core/platform/Scrollbar.h"
62 #include "core/rendering/RenderBox.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<MutableStylePropertySet> style = MutableStylePropertySet::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, CSSValueID propertyValue)
126 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::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 RefPtr<EditingStyle> selectionStyle = EditingStyle::styleAtSelectionStart(frame.selection().selection());
137 if (!selectionStyle || !selectionStyle->style())
140 RefPtr<CSSValue> selectedCSSValue = selectionStyle->style()->getPropertyCSSValue(propertyID);
141 String newStyle("none");
142 if (selectedCSSValue->isValueList()) {
143 RefPtr<CSSValueList> selectedCSSValueList = toCSSValueList(selectedCSSValue.get());
144 if (!selectedCSSValueList->removeAll(value))
145 selectedCSSValueList->append(value);
146 if (selectedCSSValueList->length())
147 newStyle = selectedCSSValueList->cssText();
149 } else if (selectedCSSValue->cssText() == "none")
150 newStyle = value->cssText();
152 // FIXME: We shouldn't be having to convert new style into text. We should have setPropertyCSSValue.
153 RefPtr<MutableStylePropertySet> newMutableStyle = MutableStylePropertySet::create();
154 newMutableStyle->setProperty(propertyID, newStyle);
155 return applyCommandToFrame(frame, source, action, newMutableStyle.get());
158 static bool executeToggleStyle(Frame& frame, EditorCommandSource source, EditAction action, CSSPropertyID propertyID, const char* offValue, const char* onValue)
160 // Style is considered present when
161 // Mac: present at the beginning of selection
162 // other: present throughout the selection
165 if (frame.editor().behavior().shouldToggleStyleBasedOnStartOfSelection())
166 styleIsPresent = frame.editor().selectionStartHasStyle(propertyID, onValue);
168 styleIsPresent = frame.editor().selectionHasStyle(propertyID, onValue) == TrueTriState;
170 RefPtr<EditingStyle> style = EditingStyle::create(propertyID, styleIsPresent ? offValue : onValue);
171 return applyCommandToFrame(frame, source, action, style->style());
174 static bool executeApplyParagraphStyle(Frame& frame, EditorCommandSource source, EditAction action, CSSPropertyID propertyID, const String& propertyValue)
176 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
177 style->setProperty(propertyID, propertyValue);
178 // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a good reason for that?
180 case CommandFromMenuOrKeyBinding:
181 frame.editor().applyParagraphStyleToSelection(style.get(), action);
184 case CommandFromDOMWithUserInterface:
185 frame.editor().applyParagraphStyle(style.get());
188 ASSERT_NOT_REACHED();
192 static bool executeInsertFragment(Frame& frame, PassRefPtr<DocumentFragment> fragment)
194 ASSERT(frame.document());
195 ReplaceSelectionCommand::create(*frame.document(), fragment, ReplaceSelectionCommand::PreventNesting, EditActionUnspecified)->apply();
199 static bool executeInsertNode(Frame& frame, PassRefPtr<Node> content)
201 ASSERT(frame.document());
202 RefPtr<DocumentFragment> fragment = DocumentFragment::create(*frame.document());
203 TrackExceptionState es;
204 fragment->appendChild(content, es);
205 if (es.hadException())
207 return executeInsertFragment(frame, fragment.release());
210 static bool expandSelectionToGranularity(Frame& frame, TextGranularity granularity)
212 VisibleSelection selection = frame.selection().selection();
213 selection.expandUsingGranularity(granularity);
214 RefPtr<Range> newRange = selection.toNormalizedRange();
217 if (newRange->collapsed(IGNORE_EXCEPTION))
219 RefPtr<Range> oldRange = frame.selection().selection().toNormalizedRange();
220 EAffinity affinity = frame.selection().affinity();
221 frame.selection().setSelectedRange(newRange.get(), affinity, true);
225 static TriState stateStyle(Frame& frame, CSSPropertyID propertyID, const char* desiredValue)
227 if (frame.editor().behavior().shouldToggleStyleBasedOnStartOfSelection())
228 return frame.editor().selectionStartHasStyle(propertyID, desiredValue) ? TrueTriState : FalseTriState;
229 return frame.editor().selectionHasStyle(propertyID, desiredValue);
232 static String valueStyle(Frame& frame, CSSPropertyID propertyID)
234 // FIXME: Rather than retrieving the style at the start of the current selection,
235 // we should retrieve the style present throughout the selection for non-Mac platforms.
236 return frame.editor().selectionStartCSSPropertyValue(propertyID);
239 static TriState stateTextWritingDirection(Frame& frame, WritingDirection direction)
241 bool hasNestedOrMultipleEmbeddings;
242 WritingDirection selectionDirection = EditingStyle::textDirectionForSelection(frame.selection().selection(),
243 frame.selection().typingStyle(), hasNestedOrMultipleEmbeddings);
244 // FXIME: We should be returning MixedTriState when selectionDirection == direction && hasNestedOrMultipleEmbeddings
245 return (selectionDirection == direction && !hasNestedOrMultipleEmbeddings) ? TrueTriState : FalseTriState;
248 static unsigned verticalScrollDistance(Frame& frame)
250 Element* focusedElement = frame.document()->focusedElement();
253 RenderObject* renderer = focusedElement->renderer();
254 if (!renderer || !renderer->isBox())
256 RenderStyle* style = renderer->style();
259 if (!(style->overflowY() == OSCROLL || style->overflowY() == OAUTO || focusedElement->rendererIsEditable()))
261 int height = std::min<int>(toRenderBox(renderer)->clientHeight(), frame.view()->visibleHeight());
262 return static_cast<unsigned>(max(max<int>(height * ScrollableArea::minFractionToStepWhenPaging(), height - ScrollableArea::maxOverlapBetweenPages()), 1));
265 static RefPtr<Range> unionDOMRanges(Range* a, Range* b)
267 Range* start = a->compareBoundaryPoints(Range::START_TO_START, b, ASSERT_NO_EXCEPTION) <= 0 ? a : b;
268 Range* end = a->compareBoundaryPoints(Range::END_TO_END, b, ASSERT_NO_EXCEPTION) <= 0 ? b : a;
270 return Range::create(a->ownerDocument(), start->startContainer(), start->startOffset(), end->endContainer(), end->endOffset());
273 // Execute command functions
275 static bool executeBackColor(Frame& frame, Event*, EditorCommandSource source, const String& value)
277 return executeApplyStyle(frame, source, EditActionSetBackgroundColor, CSSPropertyBackgroundColor, value);
280 static bool executeCopy(Frame& frame, Event*, EditorCommandSource, const String&)
282 frame.editor().copy();
286 static bool executeCreateLink(Frame& frame, Event*, EditorCommandSource, const String& value)
288 // FIXME: If userInterface is true, we should display a dialog box to let the user enter a URL.
291 ASSERT(frame.document());
292 CreateLinkCommand::create(*frame.document(), value)->apply();
296 static bool executeCut(Frame& frame, Event*, EditorCommandSource, const String&)
298 frame.editor().cut();
302 static bool executeDefaultParagraphSeparator(Frame& frame, Event*, EditorCommandSource, const String& value)
304 if (equalIgnoringCase(value, "div"))
305 frame.editor().setDefaultParagraphSeparator(EditorParagraphSeparatorIsDiv);
306 else if (equalIgnoringCase(value, "p"))
307 frame.editor().setDefaultParagraphSeparator(EditorParagraphSeparatorIsP);
312 static bool executeDelete(Frame& frame, Event*, EditorCommandSource source, const String&)
315 case CommandFromMenuOrKeyBinding: {
316 // Doesn't modify the text if the current selection isn't a range.
317 frame.editor().performDelete();
321 case CommandFromDOMWithUserInterface:
322 // If the current selection is a caret, delete the preceding character. IE performs forwardDelete, but we currently side with Firefox.
323 // Doesn't scroll to make the selection visible, or modify the kill ring (this time, siding with IE, not Firefox).
324 ASSERT(frame.document());
325 TypingCommand::deleteKeyPressed(*frame.document(), frame.selection().granularity() == WordGranularity ? TypingCommand::SmartDelete : 0);
328 ASSERT_NOT_REACHED();
332 static bool executeDeleteBackward(Frame& frame, Event*, EditorCommandSource, const String&)
334 frame.editor().deleteWithDirection(DirectionBackward, CharacterGranularity, false, true);
338 static bool executeDeleteBackwardByDecomposingPreviousCharacter(Frame& frame, Event*, EditorCommandSource, const String&)
340 LOG_ERROR("DeleteBackwardByDecomposingPreviousCharacter is not implemented, doing DeleteBackward instead");
341 frame.editor().deleteWithDirection(DirectionBackward, CharacterGranularity, false, true);
345 static bool executeDeleteForward(Frame& frame, Event*, EditorCommandSource, const String&)
347 frame.editor().deleteWithDirection(DirectionForward, CharacterGranularity, false, true);
351 static bool executeDeleteToBeginningOfLine(Frame& frame, Event*, EditorCommandSource, const String&)
353 frame.editor().deleteWithDirection(DirectionBackward, LineBoundary, true, false);
357 static bool executeDeleteToBeginningOfParagraph(Frame& frame, Event*, EditorCommandSource, const String&)
359 frame.editor().deleteWithDirection(DirectionBackward, ParagraphBoundary, true, false);
363 static bool executeDeleteToEndOfLine(Frame& frame, Event*, EditorCommandSource, const String&)
365 // Despite its name, this command should delete the newline at the end of
366 // a paragraph if you are at the end of a paragraph (like DeleteToEndOfParagraph).
367 frame.editor().deleteWithDirection(DirectionForward, LineBoundary, true, false);
371 static bool executeDeleteToEndOfParagraph(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.
375 frame.editor().deleteWithDirection(DirectionForward, ParagraphBoundary, true, false);
379 static bool executeDeleteToMark(Frame& frame, Event*, EditorCommandSource, const String&)
381 RefPtr<Range> mark = frame.editor().mark().toNormalizedRange();
383 bool selected = frame.selection().setSelectedRange(unionDOMRanges(mark.get(), frame.editor().selectedRange().get()).get(), DOWNSTREAM, true);
388 frame.editor().performDelete();
389 frame.editor().setMark(frame.selection().selection());
393 static bool executeDeleteWordBackward(Frame& frame, Event*, EditorCommandSource, const String&)
395 frame.editor().deleteWithDirection(DirectionBackward, WordGranularity, true, false);
399 static bool executeDeleteWordForward(Frame& frame, Event*, EditorCommandSource, const String&)
401 frame.editor().deleteWithDirection(DirectionForward, WordGranularity, true, false);
405 static bool executeFindString(Frame& frame, Event*, EditorCommandSource, const String& value)
407 return frame.editor().findString(value, true, false, true, false);
410 static bool executeFontName(Frame& frame, Event*, EditorCommandSource source, const String& value)
412 return executeApplyStyle(frame, source, EditActionSetFont, CSSPropertyFontFamily, value);
415 static bool executeFontSize(Frame& frame, Event*, EditorCommandSource source, const String& value)
418 if (!HTMLFontElement::cssValueFromFontSizeNumber(value, size))
420 return executeApplyStyle(frame, source, EditActionChangeAttributes, CSSPropertyFontSize, size);
423 static bool executeFontSizeDelta(Frame& frame, Event*, EditorCommandSource source, const String& value)
425 return executeApplyStyle(frame, source, EditActionChangeAttributes, CSSPropertyWebkitFontSizeDelta, value);
428 static bool executeForeColor(Frame& frame, Event*, EditorCommandSource source, const String& value)
430 return executeApplyStyle(frame, source, EditActionSetColor, CSSPropertyColor, value);
433 static bool executeFormatBlock(Frame& frame, Event*, EditorCommandSource, const String& value)
435 String tagName = value.lower();
436 if (tagName[0] == '<' && tagName[tagName.length() - 1] == '>')
437 tagName = tagName.substring(1, tagName.length() - 2);
439 String localName, prefix;
440 if (!Document::parseQualifiedName(tagName, prefix, localName, IGNORE_EXCEPTION))
442 QualifiedName qualifiedTagName(prefix, localName, xhtmlNamespaceURI);
444 ASSERT(frame.document());
445 RefPtr<FormatBlockCommand> command = FormatBlockCommand::create(*frame.document(), qualifiedTagName);
447 return command->didApply();
450 static bool executeForwardDelete(Frame& frame, Event*, EditorCommandSource source, const String&)
453 case CommandFromMenuOrKeyBinding:
454 frame.editor().deleteWithDirection(DirectionForward, CharacterGranularity, false, true);
457 case CommandFromDOMWithUserInterface:
458 // Doesn't scroll to make the selection visible, or modify the kill ring.
459 // ForwardDelete is not implemented in IE or Firefox, so this behavior is only needed for
460 // backward compatibility with ourselves, and for consistency with Delete.
461 ASSERT(frame.document());
462 TypingCommand::forwardDeleteKeyPressed(*frame.document());
465 ASSERT_NOT_REACHED();
469 static bool executeIgnoreSpelling(Frame& frame, Event*, EditorCommandSource, const String&)
471 frame.spellChecker().ignoreSpelling();
475 static bool executeIndent(Frame& frame, Event*, EditorCommandSource, const String&)
477 ASSERT(frame.document());
478 IndentOutdentCommand::create(*frame.document(), IndentOutdentCommand::Indent)->apply();
482 static bool executeInsertBacktab(Frame& frame, Event* event, EditorCommandSource, const String&)
484 return targetFrame(frame, event)->eventHandler().handleTextInputEvent("\t", event, TextEventInputBackTab);
487 static bool executeInsertHorizontalRule(Frame& frame, Event*, EditorCommandSource, const String& value)
489 ASSERT(frame.document());
490 RefPtr<HTMLHRElement> rule = HTMLHRElement::create(*frame.document());
491 if (!value.isEmpty())
492 rule->setIdAttribute(value);
493 return executeInsertNode(frame, rule.release());
496 static bool executeInsertHTML(Frame& frame, Event*, EditorCommandSource, const String& value)
498 ASSERT(frame.document());
499 return executeInsertFragment(frame, createFragmentFromMarkup(*frame.document(), value, ""));
502 static bool executeInsertImage(Frame& frame, Event*, EditorCommandSource, const String& value)
504 // FIXME: If userInterface is true, we should display a dialog box and let the user choose a local image.
505 ASSERT(frame.document());
506 RefPtr<HTMLImageElement> image = HTMLImageElement::create(*frame.document());
507 image->setSrc(value);
508 return executeInsertNode(frame, image.release());
511 static bool executeInsertLineBreak(Frame& frame, Event* event, EditorCommandSource source, const String&)
514 case CommandFromMenuOrKeyBinding:
515 return targetFrame(frame, event)->eventHandler().handleTextInputEvent("\n", event, TextEventInputLineBreak);
517 case CommandFromDOMWithUserInterface:
518 // Doesn't scroll to make the selection visible, or modify the kill ring.
519 // InsertLineBreak is not implemented in IE or Firefox, so this behavior is only needed for
520 // backward compatibility with ourselves, and for consistency with other commands.
521 ASSERT(frame.document());
522 TypingCommand::insertLineBreak(*frame.document(), 0);
525 ASSERT_NOT_REACHED();
529 static bool executeInsertNewline(Frame& frame, Event* event, EditorCommandSource, const String&)
531 Frame* targetFrame = WebCore::targetFrame(frame, event);
532 return targetFrame->eventHandler().handleTextInputEvent("\n", event, targetFrame->editor().canEditRichly() ? TextEventInputKeyboard : TextEventInputLineBreak);
535 static bool executeInsertNewlineInQuotedContent(Frame& frame, Event*, EditorCommandSource, const String&)
537 ASSERT(frame.document());
538 TypingCommand::insertParagraphSeparatorInQuotedContent(*frame.document());
542 static bool executeInsertOrderedList(Frame& frame, Event*, EditorCommandSource, const String&)
544 ASSERT(frame.document());
545 InsertListCommand::create(*frame.document(), InsertListCommand::OrderedList)->apply();
549 static bool executeInsertParagraph(Frame& frame, Event*, EditorCommandSource, const String&)
551 ASSERT(frame.document());
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 ASSERT(frame.document());
564 TypingCommand::insertText(*frame.document(), value, 0);
568 static bool executeInsertUnorderedList(Frame& frame, Event*, EditorCommandSource, const String&)
570 ASSERT(frame.document());
571 InsertListCommand::create(*frame.document(), InsertListCommand::UnorderedList)->apply();
575 static bool executeJustifyCenter(Frame& frame, Event*, EditorCommandSource source, const String&)
577 return executeApplyParagraphStyle(frame, source, EditActionCenter, CSSPropertyTextAlign, "center");
580 static bool executeJustifyFull(Frame& frame, Event*, EditorCommandSource source, const String&)
582 return executeApplyParagraphStyle(frame, source, EditActionJustify, CSSPropertyTextAlign, "justify");
585 static bool executeJustifyLeft(Frame& frame, Event*, EditorCommandSource source, const String&)
587 return executeApplyParagraphStyle(frame, source, EditActionAlignLeft, CSSPropertyTextAlign, "left");
590 static bool executeJustifyRight(Frame& frame, Event*, EditorCommandSource source, const String&)
592 return executeApplyParagraphStyle(frame, source, EditActionAlignRight, CSSPropertyTextAlign, "right");
595 static bool executeMakeTextWritingDirectionLeftToRight(Frame& frame, Event*, EditorCommandSource, const String&)
597 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
598 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed);
599 style->setProperty(CSSPropertyDirection, CSSValueLtr);
600 frame.editor().applyStyle(style.get(), EditActionSetWritingDirection);
604 static bool executeMakeTextWritingDirectionNatural(Frame& frame, Event*, EditorCommandSource, const String&)
606 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
607 style->setProperty(CSSPropertyUnicodeBidi, CSSValueNormal);
608 frame.editor().applyStyle(style.get(), EditActionSetWritingDirection);
612 static bool executeMakeTextWritingDirectionRightToLeft(Frame& frame, Event*, EditorCommandSource, const String&)
614 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
615 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed);
616 style->setProperty(CSSPropertyDirection, CSSValueRtl);
617 frame.editor().applyStyle(style.get(), EditActionSetWritingDirection);
621 static bool executeMoveBackward(Frame& frame, Event*, EditorCommandSource, const String&)
623 frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, CharacterGranularity, UserTriggered);
627 static bool executeMoveBackwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
629 frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, CharacterGranularity, UserTriggered);
633 static bool executeMoveDown(Frame& frame, Event*, EditorCommandSource, const String&)
635 return frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, LineGranularity, UserTriggered);
638 static bool executeMoveDownAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
640 frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, LineGranularity, UserTriggered);
644 static bool executeMoveForward(Frame& frame, Event*, EditorCommandSource, const String&)
646 frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity, UserTriggered);
650 static bool executeMoveForwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
652 frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, CharacterGranularity, UserTriggered);
656 static bool executeMoveLeft(Frame& frame, Event*, EditorCommandSource, const String&)
658 return frame.selection().modify(FrameSelection::AlterationMove, DirectionLeft, CharacterGranularity, UserTriggered);
661 static bool executeMoveLeftAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
663 frame.selection().modify(FrameSelection::AlterationExtend, DirectionLeft, CharacterGranularity, UserTriggered);
667 static bool executeMovePageDown(Frame& frame, Event*, EditorCommandSource, const String&)
669 unsigned distance = verticalScrollDistance(frame);
672 return frame.selection().modify(FrameSelection::AlterationMove, distance, FrameSelection::DirectionDown,
673 UserTriggered, FrameSelection::AlignCursorOnScrollAlways);
676 static bool executeMovePageDownAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
678 unsigned distance = verticalScrollDistance(frame);
681 return frame.selection().modify(FrameSelection::AlterationExtend, distance, FrameSelection::DirectionDown,
682 UserTriggered, FrameSelection::AlignCursorOnScrollAlways);
685 static bool executeMovePageUp(Frame& frame, Event*, EditorCommandSource, const String&)
687 unsigned distance = verticalScrollDistance(frame);
690 return frame.selection().modify(FrameSelection::AlterationMove, distance, FrameSelection::DirectionUp,
691 UserTriggered, FrameSelection::AlignCursorOnScrollAlways);
694 static bool executeMovePageUpAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
696 unsigned distance = verticalScrollDistance(frame);
699 return frame.selection().modify(FrameSelection::AlterationExtend, distance, FrameSelection::DirectionUp,
700 UserTriggered, FrameSelection::AlignCursorOnScrollAlways);
703 static bool executeMoveRight(Frame& frame, Event*, EditorCommandSource, const String&)
705 return frame.selection().modify(FrameSelection::AlterationMove, DirectionRight, CharacterGranularity, UserTriggered);
708 static bool executeMoveRightAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
710 frame.selection().modify(FrameSelection::AlterationExtend, DirectionRight, CharacterGranularity, UserTriggered);
714 static bool executeMoveToBeginningOfDocument(Frame& frame, Event*, EditorCommandSource, const String&)
716 frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, DocumentBoundary, UserTriggered);
720 static bool executeMoveToBeginningOfDocumentAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
722 frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, DocumentBoundary, UserTriggered);
726 static bool executeMoveToBeginningOfLine(Frame& frame, Event*, EditorCommandSource, const String&)
728 frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, LineBoundary, UserTriggered);
732 static bool executeMoveToBeginningOfLineAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
734 frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, LineBoundary, UserTriggered);
738 static bool executeMoveToBeginningOfParagraph(Frame& frame, Event*, EditorCommandSource, const String&)
740 frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, ParagraphBoundary, UserTriggered);
744 static bool executeMoveToBeginningOfParagraphAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
746 frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, ParagraphBoundary, UserTriggered);
750 static bool executeMoveToBeginningOfSentence(Frame& frame, Event*, EditorCommandSource, const String&)
752 frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, SentenceBoundary, UserTriggered);
756 static bool executeMoveToBeginningOfSentenceAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
758 frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, SentenceBoundary, UserTriggered);
762 static bool executeMoveToEndOfDocument(Frame& frame, Event*, EditorCommandSource, const String&)
764 frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, DocumentBoundary, UserTriggered);
768 static bool executeMoveToEndOfDocumentAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
770 frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, DocumentBoundary, UserTriggered);
774 static bool executeMoveToEndOfSentence(Frame& frame, Event*, EditorCommandSource, const String&)
776 frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, SentenceBoundary, UserTriggered);
780 static bool executeMoveToEndOfSentenceAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
782 frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, SentenceBoundary, UserTriggered);
786 static bool executeMoveToEndOfLine(Frame& frame, Event*, EditorCommandSource, const String&)
788 frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, LineBoundary, UserTriggered);
792 static bool executeMoveToEndOfLineAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
794 frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, LineBoundary, UserTriggered);
798 static bool executeMoveToEndOfParagraph(Frame& frame, Event*, EditorCommandSource, const String&)
800 frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, ParagraphBoundary, UserTriggered);
804 static bool executeMoveToEndOfParagraphAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
806 frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, ParagraphBoundary, UserTriggered);
810 static bool executeMoveParagraphBackward(Frame& frame, Event*, EditorCommandSource, const String&)
812 frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, ParagraphGranularity, UserTriggered);
816 static bool executeMoveParagraphBackwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
818 frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, ParagraphGranularity, UserTriggered);
822 static bool executeMoveParagraphForward(Frame& frame, Event*, EditorCommandSource, const String&)
824 frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, ParagraphGranularity, UserTriggered);
828 static bool executeMoveParagraphForwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
830 frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, ParagraphGranularity, UserTriggered);
834 static bool executeMoveUp(Frame& frame, Event*, EditorCommandSource, const String&)
836 return frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, LineGranularity, UserTriggered);
839 static bool executeMoveUpAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
841 frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, LineGranularity, UserTriggered);
845 static bool executeMoveWordBackward(Frame& frame, Event*, EditorCommandSource, const String&)
847 frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, WordGranularity, UserTriggered);
851 static bool executeMoveWordBackwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
853 frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, WordGranularity, UserTriggered);
857 static bool executeMoveWordForward(Frame& frame, Event*, EditorCommandSource, const String&)
859 frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, WordGranularity, UserTriggered);
863 static bool executeMoveWordForwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
865 frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, WordGranularity, UserTriggered);
869 static bool executeMoveWordLeft(Frame& frame, Event*, EditorCommandSource, const String&)
871 frame.selection().modify(FrameSelection::AlterationMove, DirectionLeft, WordGranularity, UserTriggered);
875 static bool executeMoveWordLeftAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
877 frame.selection().modify(FrameSelection::AlterationExtend, DirectionLeft, WordGranularity, UserTriggered);
881 static bool executeMoveWordRight(Frame& frame, Event*, EditorCommandSource, const String&)
883 frame.selection().modify(FrameSelection::AlterationMove, DirectionRight, WordGranularity, UserTriggered);
887 static bool executeMoveWordRightAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
889 frame.selection().modify(FrameSelection::AlterationExtend, DirectionRight, WordGranularity, UserTriggered);
893 static bool executeMoveToLeftEndOfLine(Frame& frame, Event*, EditorCommandSource, const String&)
895 frame.selection().modify(FrameSelection::AlterationMove, DirectionLeft, LineBoundary, UserTriggered);
899 static bool executeMoveToLeftEndOfLineAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
901 frame.selection().modify(FrameSelection::AlterationExtend, DirectionLeft, LineBoundary, UserTriggered);
905 static bool executeMoveToRightEndOfLine(Frame& frame, Event*, EditorCommandSource, const String&)
907 frame.selection().modify(FrameSelection::AlterationMove, DirectionRight, LineBoundary, UserTriggered);
911 static bool executeMoveToRightEndOfLineAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
913 frame.selection().modify(FrameSelection::AlterationExtend, DirectionRight, LineBoundary, UserTriggered);
917 static bool executeOutdent(Frame& frame, Event*, EditorCommandSource, const String&)
919 ASSERT(frame.document());
920 IndentOutdentCommand::create(*frame.document(), IndentOutdentCommand::Outdent)->apply();
924 static bool executeToggleOverwrite(Frame& frame, Event*, EditorCommandSource, const String&)
926 frame.editor().toggleOverwriteModeEnabled();
930 static bool executePaste(Frame& frame, Event*, EditorCommandSource, const String&)
932 frame.editor().paste();
936 static bool executePasteGlobalSelection(Frame& frame, Event*, EditorCommandSource source, const String&)
938 if (!frame.editor().client().supportsGlobalSelection())
940 ASSERT_UNUSED(source, source == CommandFromMenuOrKeyBinding);
942 bool oldSelectionMode = Pasteboard::generalPasteboard()->isSelectionMode();
943 Pasteboard::generalPasteboard()->setSelectionMode(true);
944 frame.editor().paste();
945 Pasteboard::generalPasteboard()->setSelectionMode(oldSelectionMode);
949 static bool executePasteAndMatchStyle(Frame& frame, Event*, EditorCommandSource, const String&)
951 frame.editor().pasteAsPlainText();
955 static bool executePrint(Frame& frame, Event*, EditorCommandSource, const String&)
957 Page* page = frame.page();
960 page->chrome().print(&frame);
964 static bool executeRedo(Frame& frame, Event*, EditorCommandSource, const String&)
966 frame.editor().redo();
970 static bool executeRemoveFormat(Frame& frame, Event*, EditorCommandSource, const String&)
972 frame.editor().removeFormattingAndStyle();
976 static bool executeScrollPageBackward(Frame& frame, Event*, EditorCommandSource, const String&)
978 return frame.eventHandler().logicalScrollRecursively(ScrollBlockDirectionBackward, ScrollByPage);
981 static bool executeScrollPageForward(Frame& frame, Event*, EditorCommandSource, const String&)
983 return frame.eventHandler().logicalScrollRecursively(ScrollBlockDirectionForward, ScrollByPage);
986 static bool executeScrollLineUp(Frame& frame, Event*, EditorCommandSource, const String&)
988 return frame.eventHandler().scrollRecursively(ScrollUp, ScrollByLine);
991 static bool executeScrollLineDown(Frame& frame, Event*, EditorCommandSource, const String&)
993 return frame.eventHandler().scrollRecursively(ScrollDown, ScrollByLine);
996 static bool executeScrollToBeginningOfDocument(Frame& frame, Event*, EditorCommandSource, const String&)
998 return frame.eventHandler().logicalScrollRecursively(ScrollBlockDirectionBackward, ScrollByDocument);
1001 static bool executeScrollToEndOfDocument(Frame& frame, Event*, EditorCommandSource, const String&)
1003 return frame.eventHandler().logicalScrollRecursively(ScrollBlockDirectionForward, ScrollByDocument);
1006 static bool executeSelectAll(Frame& frame, Event*, EditorCommandSource, const String&)
1008 frame.selection().selectAll();
1012 static bool executeSelectLine(Frame& frame, Event*, EditorCommandSource, const String&)
1014 return expandSelectionToGranularity(frame, LineGranularity);
1017 static bool executeSelectParagraph(Frame& frame, Event*, EditorCommandSource, const String&)
1019 return expandSelectionToGranularity(frame, ParagraphGranularity);
1022 static bool executeSelectSentence(Frame& frame, Event*, EditorCommandSource, const String&)
1024 return expandSelectionToGranularity(frame, SentenceGranularity);
1027 static bool executeSelectToMark(Frame& frame, Event*, EditorCommandSource, const String&)
1029 RefPtr<Range> mark = frame.editor().mark().toNormalizedRange();
1030 RefPtr<Range> selection = frame.editor().selectedRange();
1031 if (!mark || !selection)
1033 frame.selection().setSelectedRange(unionDOMRanges(mark.get(), selection.get()).get(), DOWNSTREAM, true);
1037 static bool executeSelectWord(Frame& frame, Event*, EditorCommandSource, const String&)
1039 return expandSelectionToGranularity(frame, WordGranularity);
1042 static bool executeSetMark(Frame& frame, Event*, EditorCommandSource, const String&)
1044 frame.editor().setMark(frame.selection().selection());
1048 static bool executeStrikethrough(Frame& frame, Event*, EditorCommandSource source, const String&)
1050 RefPtr<CSSPrimitiveValue> lineThrough = CSSPrimitiveValue::createIdentifier(CSSValueLineThrough);
1051 return executeToggleStyleInList(frame, source, EditActionUnderline, CSSPropertyWebkitTextDecorationsInEffect, lineThrough.get());
1054 static bool executeStyleWithCSS(Frame& frame, Event*, EditorCommandSource, const String& value)
1056 frame.editor().setShouldStyleWithCSS(!equalIgnoringCase(value, "false"));
1060 static bool executeUseCSS(Frame& frame, Event*, EditorCommandSource, const String& value)
1062 frame.editor().setShouldStyleWithCSS(equalIgnoringCase(value, "false"));
1066 static bool executeSubscript(Frame& frame, Event*, EditorCommandSource source, const String&)
1068 return executeToggleStyle(frame, source, EditActionSubscript, CSSPropertyVerticalAlign, "baseline", "sub");
1071 static bool executeSuperscript(Frame& frame, Event*, EditorCommandSource source, const String&)
1073 return executeToggleStyle(frame, source, EditActionSuperscript, CSSPropertyVerticalAlign, "baseline", "super");
1076 static bool executeSwapWithMark(Frame& frame, Event*, EditorCommandSource, const String&)
1078 const VisibleSelection& mark = frame.editor().mark();
1079 const VisibleSelection& selection = frame.selection().selection();
1080 if (mark.isNone() || selection.isNone())
1082 frame.selection().setSelection(mark);
1083 frame.editor().setMark(selection);
1087 static bool executeToggleBold(Frame& frame, Event*, EditorCommandSource source, const String&)
1089 return executeToggleStyle(frame, source, EditActionBold, CSSPropertyFontWeight, "normal", "bold");
1092 static bool executeToggleItalic(Frame& frame, Event*, EditorCommandSource source, const String&)
1094 return executeToggleStyle(frame, source, EditActionItalics, CSSPropertyFontStyle, "normal", "italic");
1097 static bool executeTranspose(Frame& frame, Event*, EditorCommandSource, const String&)
1099 frame.editor().transpose();
1103 static bool executeUnderline(Frame& frame, Event*, EditorCommandSource source, const String&)
1105 RefPtr<CSSPrimitiveValue> underline = CSSPrimitiveValue::createIdentifier(CSSValueUnderline);
1106 return executeToggleStyleInList(frame, source, EditActionUnderline, CSSPropertyWebkitTextDecorationsInEffect, underline.get());
1109 static bool executeUndo(Frame& frame, Event*, EditorCommandSource, const String&)
1111 frame.editor().undo();
1115 static bool executeUnlink(Frame& frame, Event*, EditorCommandSource, const String&)
1117 ASSERT(frame.document());
1118 UnlinkCommand::create(*frame.document())->apply();
1122 static bool executeUnscript(Frame& frame, Event*, EditorCommandSource source, const String&)
1124 return executeApplyStyle(frame, source, EditActionUnscript, CSSPropertyVerticalAlign, "baseline");
1127 static bool executeUnselect(Frame& frame, Event*, EditorCommandSource, const String&)
1129 frame.selection().clear();
1133 static bool executeYank(Frame& frame, Event*, EditorCommandSource, const String&)
1135 frame.editor().insertTextWithoutSendingTextEvent(frame.editor().killRing()->yank(), false, 0);
1136 frame.editor().killRing()->setToYankedState();
1140 static bool executeYankAndSelect(Frame& frame, Event*, EditorCommandSource, const String&)
1142 frame.editor().insertTextWithoutSendingTextEvent(frame.editor().killRing()->yank(), true, 0);
1143 frame.editor().killRing()->setToYankedState();
1147 // Supported functions
1149 static bool supported(Frame*)
1154 static bool supportedFromMenuOrKeyBinding(Frame*)
1159 static bool supportedCopyCut(Frame* frame)
1164 Settings* settings = frame->settings();
1165 bool defaultValue = settings && settings->javaScriptCanAccessClipboard();
1166 return frame->editor().client().canCopyCut(frame, defaultValue);
1169 static bool supportedPaste(Frame* frame)
1174 Settings* settings = frame->settings();
1175 bool defaultValue = settings && settings->javaScriptCanAccessClipboard() && settings->DOMPasteAllowed();
1176 return frame->editor().client().canPaste(frame, defaultValue);
1179 // Enabled functions
1181 static bool enabled(Frame&, Event*, EditorCommandSource)
1186 static bool enabledVisibleSelection(Frame& frame, Event* event, EditorCommandSource)
1188 // The term "visible" here includes a caret in editable text or a range in any text.
1189 const VisibleSelection& selection = frame.editor().selectionForCommand(event);
1190 return (selection.isCaret() && selection.isContentEditable()) || selection.isRange();
1193 static bool caretBrowsingEnabled(Frame& frame)
1195 return frame.settings() && frame.settings()->caretBrowsingEnabled();
1198 static EditorCommandSource dummyEditorCommandSource = static_cast<EditorCommandSource>(0);
1200 static bool enabledVisibleSelectionOrCaretBrowsing(Frame& frame, Event* event, EditorCommandSource)
1202 // The EditorCommandSource parameter is unused in enabledVisibleSelection, so just pass a dummy variable
1203 return caretBrowsingEnabled(frame) || enabledVisibleSelection(frame, event, dummyEditorCommandSource);
1206 static bool enabledVisibleSelectionAndMark(Frame& frame, Event* event, EditorCommandSource)
1208 const VisibleSelection& selection = frame.editor().selectionForCommand(event);
1209 return ((selection.isCaret() && selection.isContentEditable()) || selection.isRange())
1210 && frame.editor().mark().isCaretOrRange();
1213 static bool enableCaretInEditableText(Frame& frame, Event* event, EditorCommandSource)
1215 const VisibleSelection& selection = frame.editor().selectionForCommand(event);
1216 return selection.isCaret() && selection.isContentEditable();
1219 static bool enabledCopy(Frame& frame, Event*, EditorCommandSource)
1221 return frame.editor().canDHTMLCopy() || frame.editor().canCopy();
1224 static bool enabledCut(Frame& frame, Event*, EditorCommandSource)
1226 return frame.editor().canDHTMLCut() || frame.editor().canCut();
1229 static bool enabledInEditableText(Frame& frame, Event* event, EditorCommandSource)
1231 return frame.editor().selectionForCommand(event).rootEditableElement();
1234 static bool enabledDelete(Frame& frame, Event* event, EditorCommandSource source)
1237 case CommandFromMenuOrKeyBinding:
1238 return frame.editor().canDelete();
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();
1280 static bool enabledUndo(Frame& frame, Event*, EditorCommandSource)
1282 return frame.editor().canUndo();
1287 static TriState stateNone(Frame&, Event*)
1289 return FalseTriState;
1292 static TriState stateBold(Frame& frame, Event*)
1294 return stateStyle(frame, CSSPropertyFontWeight, "bold");
1297 static TriState stateItalic(Frame& frame, Event*)
1299 return stateStyle(frame, CSSPropertyFontStyle, "italic");
1302 static TriState stateOrderedList(Frame& frame, Event*)
1304 return frame.editor().selectionOrderedListState();
1307 static TriState stateStrikethrough(Frame& frame, Event*)
1309 return stateStyle(frame, CSSPropertyWebkitTextDecorationsInEffect, "line-through");
1312 static TriState stateStyleWithCSS(Frame& frame, Event*)
1314 return frame.editor().shouldStyleWithCSS() ? TrueTriState : FalseTriState;
1317 static TriState stateSubscript(Frame& frame, Event*)
1319 return stateStyle(frame, CSSPropertyVerticalAlign, "sub");
1322 static TriState stateSuperscript(Frame& frame, Event*)
1324 return stateStyle(frame, CSSPropertyVerticalAlign, "super");
1327 static TriState stateTextWritingDirectionLeftToRight(Frame& frame, Event*)
1329 return stateTextWritingDirection(frame, LeftToRightWritingDirection);
1332 static TriState stateTextWritingDirectionNatural(Frame& frame, Event*)
1334 return stateTextWritingDirection(frame, NaturalWritingDirection);
1337 static TriState stateTextWritingDirectionRightToLeft(Frame& frame, Event*)
1339 return stateTextWritingDirection(frame, RightToLeftWritingDirection);
1342 static TriState stateUnderline(Frame& frame, Event*)
1344 return stateStyle(frame, CSSPropertyWebkitTextDecorationsInEffect, "underline");
1347 static TriState stateUnorderedList(Frame& frame, Event*)
1349 return frame.editor().selectionUnorderedListState();
1352 static TriState stateJustifyCenter(Frame& frame, Event*)
1354 return stateStyle(frame, CSSPropertyTextAlign, "center");
1357 static TriState stateJustifyFull(Frame& frame, Event*)
1359 return stateStyle(frame, CSSPropertyTextAlign, "justify");
1362 static TriState stateJustifyLeft(Frame& frame, Event*)
1364 return stateStyle(frame, CSSPropertyTextAlign, "left");
1367 static TriState stateJustifyRight(Frame& frame, Event*)
1369 return stateStyle(frame, CSSPropertyTextAlign, "right");
1374 static String valueNull(Frame&, Event*)
1379 static String valueBackColor(Frame& frame, Event*)
1381 return valueStyle(frame, CSSPropertyBackgroundColor);
1384 static String valueDefaultParagraphSeparator(Frame& frame, Event*)
1386 switch (frame.editor().defaultParagraphSeparator()) {
1387 case EditorParagraphSeparatorIsDiv:
1388 return divTag.localName();
1389 case EditorParagraphSeparatorIsP:
1390 return pTag.localName();
1393 ASSERT_NOT_REACHED();
1397 static String valueFontName(Frame& frame, Event*)
1399 return valueStyle(frame, CSSPropertyFontFamily);
1402 static String valueFontSize(Frame& frame, Event*)
1404 return valueStyle(frame, CSSPropertyFontSize);
1407 static String valueFontSizeDelta(Frame& frame, Event*)
1409 return valueStyle(frame, CSSPropertyWebkitFontSizeDelta);
1412 static String valueForeColor(Frame& frame, Event*)
1414 return valueStyle(frame, CSSPropertyColor);
1417 static String valueFormatBlock(Frame& frame, Event*)
1419 const VisibleSelection& selection = frame.selection().selection();
1420 if (!selection.isNonOrphanedCaretOrRange() || !selection.isContentEditable())
1422 Element* formatBlockElement = FormatBlockCommand::elementForFormatBlockCommand(selection.firstRange().get());
1423 if (!formatBlockElement)
1425 return formatBlockElement->localName();
1430 struct CommandEntry {
1432 EditorInternalCommand command;
1435 static const CommandMap& createCommandMap()
1437 static const CommandEntry commands[] = {
1438 { "AlignCenter", { executeJustifyCenter, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1439 { "AlignJustified", { executeJustifyFull, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1440 { "AlignLeft", { executeJustifyLeft, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1441 { "AlignRight", { executeJustifyRight, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1442 { "BackColor", { executeBackColor, supported, enabledInRichlyEditableText, stateNone, valueBackColor, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1443 { "BackwardDelete", { executeDeleteBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, // FIXME: remove BackwardDelete when Safari for Windows stops using it.
1444 { "Bold", { executeToggleBold, supported, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1445 { "Copy", { executeCopy, supportedCopyCut, enabledCopy, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1446 { "CreateLink", { executeCreateLink, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1447 { "Cut", { executeCut, supportedCopyCut, enabledCut, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1448 { "DefaultParagraphSeparator", { executeDefaultParagraphSeparator, supported, enabled, stateNone, valueDefaultParagraphSeparator, notTextInsertion, doNotAllowExecutionWhenDisabled} },
1449 { "Delete", { executeDelete, supported, enabledDelete, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1450 { "DeleteBackward", { executeDeleteBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1451 { "DeleteBackwardByDecomposingPreviousCharacter", { executeDeleteBackwardByDecomposingPreviousCharacter, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1452 { "DeleteForward", { executeDeleteForward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1453 { "DeleteToBeginningOfLine", { executeDeleteToBeginningOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1454 { "DeleteToBeginningOfParagraph", { executeDeleteToBeginningOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1455 { "DeleteToEndOfLine", { executeDeleteToEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1456 { "DeleteToEndOfParagraph", { executeDeleteToEndOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1457 { "DeleteToMark", { executeDeleteToMark, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1458 { "DeleteWordBackward", { executeDeleteWordBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1459 { "DeleteWordForward", { executeDeleteWordForward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1460 { "FindString", { executeFindString, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1461 { "FontName", { executeFontName, supported, enabledInEditableText, stateNone, valueFontName, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1462 { "FontSize", { executeFontSize, supported, enabledInEditableText, stateNone, valueFontSize, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1463 { "FontSizeDelta", { executeFontSizeDelta, supported, enabledInEditableText, stateNone, valueFontSizeDelta, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1464 { "ForeColor", { executeForeColor, supported, enabledInRichlyEditableText, stateNone, valueForeColor, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1465 { "FormatBlock", { executeFormatBlock, supported, enabledInRichlyEditableText, stateNone, valueFormatBlock, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1466 { "ForwardDelete", { executeForwardDelete, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1467 { "HiliteColor", { executeBackColor, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1468 { "IgnoreSpelling", { executeIgnoreSpelling, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1469 { "Indent", { executeIndent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1470 { "InsertBacktab", { executeInsertBacktab, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1471 { "InsertHTML", { executeInsertHTML, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1472 { "InsertHorizontalRule", { executeInsertHorizontalRule, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1473 { "InsertImage", { executeInsertImage, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1474 { "InsertLineBreak", { executeInsertLineBreak, supported, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1475 { "InsertNewline", { executeInsertNewline, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1476 { "InsertNewlineInQuotedContent", { executeInsertNewlineInQuotedContent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1477 { "InsertOrderedList", { executeInsertOrderedList, supported, enabledInRichlyEditableText, stateOrderedList, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1478 { "InsertParagraph", { executeInsertParagraph, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1479 { "InsertTab", { executeInsertTab, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1480 { "InsertText", { executeInsertText, supported, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1481 { "InsertUnorderedList", { executeInsertUnorderedList, supported, enabledInRichlyEditableText, stateUnorderedList, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1482 { "Italic", { executeToggleItalic, supported, enabledInRichlyEditableText, stateItalic, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1483 { "JustifyCenter", { executeJustifyCenter, supported, enabledInRichlyEditableText, stateJustifyCenter, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1484 { "JustifyFull", { executeJustifyFull, supported, enabledInRichlyEditableText, stateJustifyFull, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1485 { "JustifyLeft", { executeJustifyLeft, supported, enabledInRichlyEditableText, stateJustifyLeft, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1486 { "JustifyNone", { executeJustifyLeft, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1487 { "JustifyRight", { executeJustifyRight, supported, enabledInRichlyEditableText, stateJustifyRight, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1488 { "MakeTextWritingDirectionLeftToRight", { executeMakeTextWritingDirectionLeftToRight, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionLeftToRight, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1489 { "MakeTextWritingDirectionNatural", { executeMakeTextWritingDirectionNatural, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionNatural, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1490 { "MakeTextWritingDirectionRightToLeft", { executeMakeTextWritingDirectionRightToLeft, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionRightToLeft, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1491 { "MoveBackward", { executeMoveBackward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1492 { "MoveBackwardAndModifySelection", { executeMoveBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1493 { "MoveDown", { executeMoveDown, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1494 { "MoveDownAndModifySelection", { executeMoveDownAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1495 { "MoveForward", { executeMoveForward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1496 { "MoveForwardAndModifySelection", { executeMoveForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1497 { "MoveLeft", { executeMoveLeft, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1498 { "MoveLeftAndModifySelection", { executeMoveLeftAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1499 { "MovePageDown", { executeMovePageDown, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1500 { "MovePageDownAndModifySelection", { executeMovePageDownAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1501 { "MovePageUp", { executeMovePageUp, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1502 { "MovePageUpAndModifySelection", { executeMovePageUpAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1503 { "MoveParagraphBackward", { executeMoveParagraphBackward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1504 { "MoveParagraphBackwardAndModifySelection", { executeMoveParagraphBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1505 { "MoveParagraphForward", { executeMoveParagraphForward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1506 { "MoveParagraphForwardAndModifySelection", { executeMoveParagraphForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1507 { "MoveRight", { executeMoveRight, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1508 { "MoveRightAndModifySelection", { executeMoveRightAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1509 { "MoveToBeginningOfDocument", { executeMoveToBeginningOfDocument, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1510 { "MoveToBeginningOfDocumentAndModifySelection", { executeMoveToBeginningOfDocumentAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1511 { "MoveToBeginningOfLine", { executeMoveToBeginningOfLine, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1512 { "MoveToBeginningOfLineAndModifySelection", { executeMoveToBeginningOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1513 { "MoveToBeginningOfParagraph", { executeMoveToBeginningOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1514 { "MoveToBeginningOfParagraphAndModifySelection", { executeMoveToBeginningOfParagraphAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1515 { "MoveToBeginningOfSentence", { executeMoveToBeginningOfSentence, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1516 { "MoveToBeginningOfSentenceAndModifySelection", { executeMoveToBeginningOfSentenceAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1517 { "MoveToEndOfDocument", { executeMoveToEndOfDocument, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1518 { "MoveToEndOfDocumentAndModifySelection", { executeMoveToEndOfDocumentAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1519 { "MoveToEndOfLine", { executeMoveToEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1520 { "MoveToEndOfLineAndModifySelection", { executeMoveToEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1521 { "MoveToEndOfParagraph", { executeMoveToEndOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1522 { "MoveToEndOfParagraphAndModifySelection", { executeMoveToEndOfParagraphAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1523 { "MoveToEndOfSentence", { executeMoveToEndOfSentence, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1524 { "MoveToEndOfSentenceAndModifySelection", { executeMoveToEndOfSentenceAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1525 { "MoveToLeftEndOfLine", { executeMoveToLeftEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1526 { "MoveToLeftEndOfLineAndModifySelection", { executeMoveToLeftEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1527 { "MoveToRightEndOfLine", { executeMoveToRightEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1528 { "MoveToRightEndOfLineAndModifySelection", { executeMoveToRightEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1529 { "MoveUp", { executeMoveUp, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1530 { "MoveUpAndModifySelection", { executeMoveUpAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1531 { "MoveWordBackward", { executeMoveWordBackward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1532 { "MoveWordBackwardAndModifySelection", { executeMoveWordBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1533 { "MoveWordForward", { executeMoveWordForward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1534 { "MoveWordForwardAndModifySelection", { executeMoveWordForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1535 { "MoveWordLeft", { executeMoveWordLeft, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1536 { "MoveWordLeftAndModifySelection", { executeMoveWordLeftAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1537 { "MoveWordRight", { executeMoveWordRight, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1538 { "MoveWordRightAndModifySelection", { executeMoveWordRightAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1539 { "Outdent", { executeOutdent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1540 { "OverWrite", { executeToggleOverwrite, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1541 { "Paste", { executePaste, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1542 { "PasteAndMatchStyle", { executePasteAndMatchStyle, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1543 { "PasteGlobalSelection", { executePasteGlobalSelection, supportedFromMenuOrKeyBinding, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1544 { "Print", { executePrint, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1545 { "Redo", { executeRedo, supported, enabledRedo, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1546 { "RemoveFormat", { executeRemoveFormat, supported, enabledRangeInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1547 { "ScrollPageBackward", { executeScrollPageBackward, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1548 { "ScrollPageForward", { executeScrollPageForward, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1549 { "ScrollLineUp", { executeScrollLineUp, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1550 { "ScrollLineDown", { executeScrollLineDown, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1551 { "ScrollToBeginningOfDocument", { executeScrollToBeginningOfDocument, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1552 { "ScrollToEndOfDocument", { executeScrollToEndOfDocument, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1553 { "SelectAll", { executeSelectAll, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1554 { "SelectLine", { executeSelectLine, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1555 { "SelectParagraph", { executeSelectParagraph, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1556 { "SelectSentence", { executeSelectSentence, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1557 { "SelectToMark", { executeSelectToMark, supportedFromMenuOrKeyBinding, enabledVisibleSelectionAndMark, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1558 { "SelectWord", { executeSelectWord, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1559 { "SetMark", { executeSetMark, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1560 { "Strikethrough", { executeStrikethrough, supported, enabledInRichlyEditableText, stateStrikethrough, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1561 { "StyleWithCSS", { executeStyleWithCSS, supported, enabled, stateStyleWithCSS, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1562 { "Subscript", { executeSubscript, supported, enabledInRichlyEditableText, stateSubscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1563 { "Superscript", { executeSuperscript, supported, enabledInRichlyEditableText, stateSuperscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1564 { "SwapWithMark", { executeSwapWithMark, supportedFromMenuOrKeyBinding, enabledVisibleSelectionAndMark, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1565 { "ToggleBold", { executeToggleBold, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1566 { "ToggleItalic", { executeToggleItalic, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateItalic, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1567 { "ToggleUnderline", { executeUnderline, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateUnderline, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1568 { "Transpose", { executeTranspose, supported, enableCaretInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1569 { "Underline", { executeUnderline, supported, enabledInRichlyEditableText, stateUnderline, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1570 { "Undo", { executeUndo, supported, enabledUndo, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1571 { "Unlink", { executeUnlink, supported, enabledRangeInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1572 { "Unscript", { executeUnscript, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1573 { "Unselect", { executeUnselect, supported, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1574 { "UseCSS", { executeUseCSS, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1575 { "Yank", { executeYank, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1576 { "YankAndSelect", { executeYankAndSelect, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1579 // These unsupported commands are listed here since they appear in the Microsoft
1580 // documentation used as the starting point for our DOM executeCommand support.
1582 // 2D-Position (not supported)
1583 // AbsolutePosition (not supported)
1584 // BlockDirLTR (not supported)
1585 // BlockDirRTL (not supported)
1586 // BrowseMode (not supported)
1587 // ClearAuthenticationCache (not supported)
1588 // CreateBookmark (not supported)
1589 // DirLTR (not supported)
1590 // DirRTL (not supported)
1591 // EditMode (not supported)
1592 // InlineDirLTR (not supported)
1593 // InlineDirRTL (not supported)
1594 // InsertButton (not supported)
1595 // InsertFieldSet (not supported)
1596 // InsertIFrame (not supported)
1597 // InsertInputButton (not supported)
1598 // InsertInputCheckbox (not supported)
1599 // InsertInputFileUpload (not supported)
1600 // InsertInputHidden (not supported)
1601 // InsertInputImage (not supported)
1602 // InsertInputPassword (not supported)
1603 // InsertInputRadio (not supported)
1604 // InsertInputReset (not supported)
1605 // InsertInputSubmit (not supported)
1606 // InsertInputText (not supported)
1607 // InsertMarquee (not supported)
1608 // InsertSelectDropDown (not supported)
1609 // InsertSelectListBox (not supported)
1610 // InsertTextArea (not supported)
1611 // LiveResize (not supported)
1612 // MultipleSelection (not supported)
1613 // Open (not supported)
1614 // PlayImage (not supported)
1615 // Refresh (not supported)
1616 // RemoveParaFormat (not supported)
1617 // SaveAs (not supported)
1618 // SizeToControl (not supported)
1619 // SizeToControlHeight (not supported)
1620 // SizeToControlWidth (not supported)
1621 // Stop (not supported)
1622 // StopImage (not supported)
1623 // Unbookmark (not supported)
1625 CommandMap& commandMap = *new CommandMap;
1627 for (size_t i = 0; i < WTF_ARRAY_LENGTH(commands); ++i) {
1628 ASSERT(!commandMap.get(commands[i].name));
1629 commandMap.set(commands[i].name, &commands[i].command);
1635 static const EditorInternalCommand* internalCommand(const String& commandName)
1637 static const CommandMap& commandMap = createCommandMap();
1638 return commandName.isEmpty() ? 0 : commandMap.get(commandName);
1641 Editor::Command Editor::command(const String& commandName)
1643 return Command(internalCommand(commandName), CommandFromMenuOrKeyBinding, &m_frame);
1646 Editor::Command Editor::command(const String& commandName, EditorCommandSource source)
1648 return Command(internalCommand(commandName), source, &m_frame);
1651 bool Editor::commandIsSupportedFromMenuOrKeyBinding(const String& commandName)
1653 return internalCommand(commandName);
1656 Editor::Command::Command()
1661 Editor::Command::Command(const EditorInternalCommand* command, EditorCommandSource source, PassRefPtr<Frame> frame)
1662 : m_command(command)
1664 , m_frame(command ? frame : 0)
1666 // Use separate assertions so we can tell which bad thing happened.
1673 bool Editor::Command::execute(const String& parameter, Event* triggeringEvent) const
1675 if (!isEnabled(triggeringEvent)) {
1676 // Let certain commands be executed when performed explicitly even if they are disabled.
1677 if (!isSupported() || !m_frame || !m_command->allowExecutionWhenDisabled)
1680 m_frame->document()->updateLayoutIgnorePendingStylesheets();
1681 return m_command->execute(*m_frame, triggeringEvent, m_source, parameter);
1684 bool Editor::Command::execute(Event* triggeringEvent) const
1686 return execute(String(), triggeringEvent);
1689 bool Editor::Command::isSupported() const
1694 case CommandFromMenuOrKeyBinding:
1696 case CommandFromDOM:
1697 case CommandFromDOMWithUserInterface:
1698 return m_command->isSupportedFromDOM(m_frame.get());
1700 ASSERT_NOT_REACHED();
1704 bool Editor::Command::isEnabled(Event* triggeringEvent) const
1706 if (!isSupported() || !m_frame)
1708 return m_command->isEnabled(*m_frame, triggeringEvent, m_source);
1711 TriState Editor::Command::state(Event* triggeringEvent) const
1713 if (!isSupported() || !m_frame)
1714 return FalseTriState;
1715 return m_command->state(*m_frame, triggeringEvent);
1718 String Editor::Command::value(Event* triggeringEvent) const
1720 if (!isSupported() || !m_frame)
1722 if (m_command->value == valueNull && m_command->state != stateNone)
1723 return m_command->state(*m_frame, triggeringEvent) == TrueTriState ? "true" : "false";
1724 return m_command->value(*m_frame, triggeringEvent);
1727 bool Editor::Command::isTextInsertion() const
1729 return m_command && m_command->isTextInsertion;
1732 } // namespace WebCore