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/dom/Pasteboard.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/events/Event.h"
50 #include "core/frame/Frame.h"
51 #include "core/frame/FrameHost.h"
52 #include "core/frame/FrameView.h"
53 #include "core/frame/Settings.h"
54 #include "core/html/HTMLFontElement.h"
55 #include "core/html/HTMLHRElement.h"
56 #include "core/html/HTMLImageElement.h"
57 #include "core/page/Chrome.h"
58 #include "core/page/EditorClient.h"
59 #include "core/page/EventHandler.h"
60 #include "core/rendering/RenderBox.h"
61 #include "platform/KillRing.h"
62 #include "platform/scroll/Scrollbar.h"
63 #include "public/platform/Platform.h"
64 #include "wtf/text/AtomicString.h"
68 using namespace HTMLNames;
70 class EditorInternalCommand {
73 bool (*execute)(Frame&, Event*, EditorCommandSource, const String&);
74 bool (*isSupportedFromDOM)(Frame*);
75 bool (*isEnabled)(Frame&, Event*, EditorCommandSource);
76 TriState (*state)(Frame&, Event*);
77 String (*value)(Frame&, Event*);
79 bool allowExecutionWhenDisabled;
82 typedef HashMap<String, const EditorInternalCommand*, CaseFoldingHash> CommandMap;
84 static const bool notTextInsertion = false;
85 static const bool isTextInsertion = true;
87 static const bool allowExecutionWhenDisabled = true;
88 static const bool doNotAllowExecutionWhenDisabled = false;
90 // Related to Editor::selectionForCommand.
91 // Certain operations continue to use the target control's selection even if the event handler
92 // already moved the selection outside of the text control.
93 static Frame* targetFrame(Frame& frame, Event* event)
97 Node* node = event->target()->toNode();
100 return node->document().frame();
103 static bool applyCommandToFrame(Frame& frame, EditorCommandSource source, EditAction action, StylePropertySet* style)
105 // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a good reason for that?
107 case CommandFromMenuOrKeyBinding:
108 frame.editor().applyStyleToSelection(style, action);
111 case CommandFromDOMWithUserInterface:
112 frame.editor().applyStyle(style);
115 ASSERT_NOT_REACHED();
119 static bool executeApplyStyle(Frame& frame, EditorCommandSource source, EditAction action, CSSPropertyID propertyID, const String& propertyValue)
121 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
122 style->setProperty(propertyID, propertyValue);
123 return applyCommandToFrame(frame, source, action, style.get());
126 static bool executeApplyStyle(Frame& frame, EditorCommandSource source, EditAction action, CSSPropertyID propertyID, CSSValueID propertyValue)
128 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
129 style->setProperty(propertyID, propertyValue);
130 return applyCommandToFrame(frame, source, action, style.get());
133 // FIXME: executeToggleStyleInList does not handle complicated cases such as <b><u>hello</u>world</b> properly.
134 // This function must use Editor::selectionHasStyle to determine the current style but we cannot fix this
135 // until https://bugs.webkit.org/show_bug.cgi?id=27818 is resolved.
136 static bool executeToggleStyleInList(Frame& frame, EditorCommandSource source, EditAction action, CSSPropertyID propertyID, CSSValue* value)
138 RefPtr<EditingStyle> selectionStyle = EditingStyle::styleAtSelectionStart(frame.selection().selection());
139 if (!selectionStyle || !selectionStyle->style())
142 RefPtr<CSSValue> selectedCSSValue = selectionStyle->style()->getPropertyCSSValue(propertyID);
143 String newStyle("none");
144 if (selectedCSSValue->isValueList()) {
145 RefPtr<CSSValueList> selectedCSSValueList = toCSSValueList(selectedCSSValue.get());
146 if (!selectedCSSValueList->removeAll(value))
147 selectedCSSValueList->append(value);
148 if (selectedCSSValueList->length())
149 newStyle = selectedCSSValueList->cssText();
151 } else if (selectedCSSValue->cssText() == "none")
152 newStyle = value->cssText();
154 // FIXME: We shouldn't be having to convert new style into text. We should have setPropertyCSSValue.
155 RefPtr<MutableStylePropertySet> newMutableStyle = MutableStylePropertySet::create();
156 newMutableStyle->setProperty(propertyID, newStyle);
157 return applyCommandToFrame(frame, source, action, newMutableStyle.get());
160 static bool executeToggleStyle(Frame& frame, EditorCommandSource source, EditAction action, CSSPropertyID propertyID, const char* offValue, const char* onValue)
162 // Style is considered present when
163 // Mac: present at the beginning of selection
164 // other: present throughout the selection
167 if (frame.editor().behavior().shouldToggleStyleBasedOnStartOfSelection())
168 styleIsPresent = frame.editor().selectionStartHasStyle(propertyID, onValue);
170 styleIsPresent = frame.editor().selectionHasStyle(propertyID, onValue) == TrueTriState;
172 RefPtr<EditingStyle> style = EditingStyle::create(propertyID, styleIsPresent ? offValue : onValue);
173 return applyCommandToFrame(frame, source, action, style->style());
176 static bool executeApplyParagraphStyle(Frame& frame, EditorCommandSource source, EditAction action, CSSPropertyID propertyID, const String& propertyValue)
178 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
179 style->setProperty(propertyID, propertyValue);
180 // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a good reason for that?
182 case CommandFromMenuOrKeyBinding:
183 frame.editor().applyParagraphStyleToSelection(style.get(), action);
186 case CommandFromDOMWithUserInterface:
187 frame.editor().applyParagraphStyle(style.get());
190 ASSERT_NOT_REACHED();
194 static bool executeInsertFragment(Frame& frame, PassRefPtr<DocumentFragment> fragment)
196 ASSERT(frame.document());
197 ReplaceSelectionCommand::create(*frame.document(), fragment, ReplaceSelectionCommand::PreventNesting, EditActionUnspecified)->apply();
201 static bool executeInsertNode(Frame& frame, PassRefPtr<Node> content)
203 ASSERT(frame.document());
204 RefPtr<DocumentFragment> fragment = DocumentFragment::create(*frame.document());
205 TrackExceptionState exceptionState;
206 fragment->appendChild(content, exceptionState);
207 if (exceptionState.hadException())
209 return executeInsertFragment(frame, fragment.release());
212 static bool expandSelectionToGranularity(Frame& frame, TextGranularity granularity)
214 VisibleSelection selection = frame.selection().selection();
215 selection.expandUsingGranularity(granularity);
216 RefPtr<Range> newRange = selection.toNormalizedRange();
219 if (newRange->collapsed(IGNORE_EXCEPTION))
221 RefPtr<Range> oldRange = frame.selection().selection().toNormalizedRange();
222 EAffinity affinity = frame.selection().affinity();
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 Element* focusedElement = frame.document()->focusedElement();
255 RenderObject* renderer = focusedElement->renderer();
256 if (!renderer || !renderer->isBox())
258 RenderStyle* style = renderer->style();
261 if (!(style->overflowY() == OSCROLL || style->overflowY() == OAUTO || focusedElement->rendererIsEditable()))
263 int height = std::min<int>(toRenderBox(renderer)->clientHeight(), frame.view()->visibleHeight());
264 return static_cast<unsigned>(max(max<int>(height * ScrollableArea::minFractionToStepWhenPaging(), height - ScrollableArea::maxOverlapBetweenPages()), 1));
267 static RefPtr<Range> unionDOMRanges(Range* a, Range* b)
269 Range* start = a->compareBoundaryPoints(Range::START_TO_START, b, ASSERT_NO_EXCEPTION) <= 0 ? a : b;
270 Range* end = a->compareBoundaryPoints(Range::END_TO_END, b, ASSERT_NO_EXCEPTION) <= 0 ? b : a;
272 return Range::create(a->ownerDocument(), start->startContainer(), start->startOffset(), end->endContainer(), end->endOffset());
275 // Execute command functions
277 static bool executeBackColor(Frame& frame, Event*, EditorCommandSource source, const String& value)
279 return executeApplyStyle(frame, source, EditActionSetBackgroundColor, CSSPropertyBackgroundColor, value);
282 static bool executeCopy(Frame& frame, Event*, EditorCommandSource, const String&)
284 frame.editor().copy();
288 static bool executeCreateLink(Frame& frame, Event*, EditorCommandSource, const String& value)
290 // FIXME: If userInterface is true, we should display a dialog box to let the user enter a URL.
293 ASSERT(frame.document());
294 CreateLinkCommand::create(*frame.document(), value)->apply();
298 static bool executeCut(Frame& frame, Event*, EditorCommandSource, const String&)
300 frame.editor().cut();
304 static bool executeDefaultParagraphSeparator(Frame& frame, Event*, EditorCommandSource, const String& value)
306 if (equalIgnoringCase(value, "div"))
307 frame.editor().setDefaultParagraphSeparator(EditorParagraphSeparatorIsDiv);
308 else if (equalIgnoringCase(value, "p"))
309 frame.editor().setDefaultParagraphSeparator(EditorParagraphSeparatorIsP);
314 static bool executeDelete(Frame& frame, Event*, EditorCommandSource source, const String&)
317 case CommandFromMenuOrKeyBinding: {
318 // Doesn't modify the text if the current selection isn't a range.
319 frame.editor().performDelete();
323 case CommandFromDOMWithUserInterface:
324 // If the current selection is a caret, delete the preceding character. IE performs forwardDelete, but we currently side with Firefox.
325 // Doesn't scroll to make the selection visible, or modify the kill ring (this time, siding with IE, not Firefox).
326 ASSERT(frame.document());
327 TypingCommand::deleteKeyPressed(*frame.document(), frame.selection().granularity() == WordGranularity ? TypingCommand::SmartDelete : 0);
330 ASSERT_NOT_REACHED();
334 static bool executeDeleteBackward(Frame& frame, Event*, EditorCommandSource, const String&)
336 frame.editor().deleteWithDirection(DirectionBackward, CharacterGranularity, false, true);
340 static bool executeDeleteBackwardByDecomposingPreviousCharacter(Frame& frame, Event*, EditorCommandSource, const String&)
342 WTF_LOG_ERROR("DeleteBackwardByDecomposingPreviousCharacter is not implemented, doing DeleteBackward instead");
343 frame.editor().deleteWithDirection(DirectionBackward, CharacterGranularity, false, true);
347 static bool executeDeleteForward(Frame& frame, Event*, EditorCommandSource, const String&)
349 frame.editor().deleteWithDirection(DirectionForward, CharacterGranularity, false, true);
353 static bool executeDeleteToBeginningOfLine(Frame& frame, Event*, EditorCommandSource, const String&)
355 frame.editor().deleteWithDirection(DirectionBackward, LineBoundary, true, false);
359 static bool executeDeleteToBeginningOfParagraph(Frame& frame, Event*, EditorCommandSource, const String&)
361 frame.editor().deleteWithDirection(DirectionBackward, ParagraphBoundary, true, false);
365 static bool executeDeleteToEndOfLine(Frame& frame, Event*, EditorCommandSource, const String&)
367 // Despite its name, this command should delete the newline at the end of
368 // a paragraph if you are at the end of a paragraph (like DeleteToEndOfParagraph).
369 frame.editor().deleteWithDirection(DirectionForward, LineBoundary, true, false);
373 static bool executeDeleteToEndOfParagraph(Frame& frame, Event*, EditorCommandSource, const String&)
375 // Despite its name, this command should delete the newline at the end of
376 // a paragraph if you are at the end of a paragraph.
377 frame.editor().deleteWithDirection(DirectionForward, ParagraphBoundary, true, false);
381 static bool executeDeleteToMark(Frame& frame, Event*, EditorCommandSource, const String&)
383 RefPtr<Range> mark = frame.editor().mark().toNormalizedRange();
385 bool selected = frame.selection().setSelectedRange(unionDOMRanges(mark.get(), frame.editor().selectedRange().get()).get(), DOWNSTREAM, true);
390 frame.editor().performDelete();
391 frame.editor().setMark(frame.selection().selection());
395 static bool executeDeleteWordBackward(Frame& frame, Event*, EditorCommandSource, const String&)
397 frame.editor().deleteWithDirection(DirectionBackward, WordGranularity, true, false);
401 static bool executeDeleteWordForward(Frame& frame, Event*, EditorCommandSource, const String&)
403 frame.editor().deleteWithDirection(DirectionForward, WordGranularity, true, false);
407 static bool executeFindString(Frame& frame, Event*, EditorCommandSource, const String& value)
409 return frame.editor().findString(value, true, false, true, false);
412 static bool executeFontName(Frame& frame, Event*, EditorCommandSource source, const String& value)
414 return executeApplyStyle(frame, source, EditActionSetFont, CSSPropertyFontFamily, value);
417 static bool executeFontSize(Frame& frame, Event*, EditorCommandSource source, const String& value)
420 if (!HTMLFontElement::cssValueFromFontSizeNumber(value, size))
422 return executeApplyStyle(frame, source, EditActionChangeAttributes, CSSPropertyFontSize, size);
425 static bool executeFontSizeDelta(Frame& frame, Event*, EditorCommandSource source, const String& value)
427 return executeApplyStyle(frame, source, EditActionChangeAttributes, CSSPropertyWebkitFontSizeDelta, value);
430 static bool executeForeColor(Frame& frame, Event*, EditorCommandSource source, const String& value)
432 return executeApplyStyle(frame, source, EditActionSetColor, CSSPropertyColor, value);
435 static bool executeFormatBlock(Frame& frame, Event*, EditorCommandSource, const String& value)
437 String tagName = value.lower();
438 if (tagName[0] == '<' && tagName[tagName.length() - 1] == '>')
439 tagName = tagName.substring(1, tagName.length() - 2);
441 AtomicString localName, prefix;
442 if (!Document::parseQualifiedName(AtomicString(tagName), prefix, localName, IGNORE_EXCEPTION))
444 QualifiedName qualifiedTagName(prefix, localName, xhtmlNamespaceURI);
446 ASSERT(frame.document());
447 RefPtr<FormatBlockCommand> command = FormatBlockCommand::create(*frame.document(), qualifiedTagName);
449 return command->didApply();
452 static bool executeForwardDelete(Frame& frame, Event*, EditorCommandSource source, const String&)
455 case CommandFromMenuOrKeyBinding:
456 frame.editor().deleteWithDirection(DirectionForward, CharacterGranularity, false, true);
459 case CommandFromDOMWithUserInterface:
460 // Doesn't scroll to make the selection visible, or modify the kill ring.
461 // ForwardDelete is not implemented in IE or Firefox, so this behavior is only needed for
462 // backward compatibility with ourselves, and for consistency with Delete.
463 ASSERT(frame.document());
464 TypingCommand::forwardDeleteKeyPressed(*frame.document());
467 ASSERT_NOT_REACHED();
471 static bool executeIgnoreSpelling(Frame& frame, Event*, EditorCommandSource, const String&)
473 frame.spellChecker().ignoreSpelling();
477 static bool executeIndent(Frame& frame, Event*, EditorCommandSource, const String&)
479 ASSERT(frame.document());
480 IndentOutdentCommand::create(*frame.document(), IndentOutdentCommand::Indent)->apply();
484 static bool executeInsertBacktab(Frame& frame, Event* event, EditorCommandSource, const String&)
486 return targetFrame(frame, event)->eventHandler().handleTextInputEvent("\t", event, TextEventInputBackTab);
489 static bool executeInsertHorizontalRule(Frame& frame, Event*, EditorCommandSource, const String& value)
491 ASSERT(frame.document());
492 RefPtr<HTMLHRElement> rule = HTMLHRElement::create(*frame.document());
493 if (!value.isEmpty())
494 rule->setIdAttribute(AtomicString(value));
495 return executeInsertNode(frame, rule.release());
498 static bool executeInsertHTML(Frame& frame, Event*, EditorCommandSource, const String& value)
500 ASSERT(frame.document());
501 return executeInsertFragment(frame, createFragmentFromMarkup(*frame.document(), value, ""));
504 static bool executeInsertImage(Frame& frame, Event*, EditorCommandSource, const String& value)
506 // FIXME: If userInterface is true, we should display a dialog box and let the user choose a local image.
507 ASSERT(frame.document());
508 RefPtr<HTMLImageElement> image = HTMLImageElement::create(*frame.document());
509 image->setSrc(value);
510 return executeInsertNode(frame, image.release());
513 static bool executeInsertLineBreak(Frame& frame, Event* event, EditorCommandSource source, const String&)
516 case CommandFromMenuOrKeyBinding:
517 return targetFrame(frame, event)->eventHandler().handleTextInputEvent("\n", event, TextEventInputLineBreak);
519 case CommandFromDOMWithUserInterface:
520 // Doesn't scroll to make the selection visible, or modify the kill ring.
521 // InsertLineBreak is not implemented in IE or Firefox, so this behavior is only needed for
522 // backward compatibility with ourselves, and for consistency with other commands.
523 ASSERT(frame.document());
524 TypingCommand::insertLineBreak(*frame.document(), 0);
527 ASSERT_NOT_REACHED();
531 static bool executeInsertNewline(Frame& frame, Event* event, EditorCommandSource, const String&)
533 Frame* targetFrame = WebCore::targetFrame(frame, event);
534 return targetFrame->eventHandler().handleTextInputEvent("\n", event, targetFrame->editor().canEditRichly() ? TextEventInputKeyboard : TextEventInputLineBreak);
537 static bool executeInsertNewlineInQuotedContent(Frame& frame, Event*, EditorCommandSource, const String&)
539 ASSERT(frame.document());
540 TypingCommand::insertParagraphSeparatorInQuotedContent(*frame.document());
544 static bool executeInsertOrderedList(Frame& frame, Event*, EditorCommandSource, const String&)
546 ASSERT(frame.document());
547 InsertListCommand::create(*frame.document(), InsertListCommand::OrderedList)->apply();
551 static bool executeInsertParagraph(Frame& frame, Event*, EditorCommandSource, const String&)
553 ASSERT(frame.document());
554 TypingCommand::insertParagraphSeparator(*frame.document(), 0);
558 static bool executeInsertTab(Frame& frame, Event* event, EditorCommandSource, const String&)
560 return targetFrame(frame, event)->eventHandler().handleTextInputEvent("\t", event);
563 static bool executeInsertText(Frame& frame, Event*, EditorCommandSource, const String& value)
565 ASSERT(frame.document());
566 TypingCommand::insertText(*frame.document(), value, 0);
570 static bool executeInsertUnorderedList(Frame& frame, Event*, EditorCommandSource, const String&)
572 ASSERT(frame.document());
573 InsertListCommand::create(*frame.document(), InsertListCommand::UnorderedList)->apply();
577 static bool executeJustifyCenter(Frame& frame, Event*, EditorCommandSource source, const String&)
579 return executeApplyParagraphStyle(frame, source, EditActionCenter, CSSPropertyTextAlign, "center");
582 static bool executeJustifyFull(Frame& frame, Event*, EditorCommandSource source, const String&)
584 return executeApplyParagraphStyle(frame, source, EditActionJustify, CSSPropertyTextAlign, "justify");
587 static bool executeJustifyLeft(Frame& frame, Event*, EditorCommandSource source, const String&)
589 return executeApplyParagraphStyle(frame, source, EditActionAlignLeft, CSSPropertyTextAlign, "left");
592 static bool executeJustifyRight(Frame& frame, Event*, EditorCommandSource source, const String&)
594 return executeApplyParagraphStyle(frame, source, EditActionAlignRight, CSSPropertyTextAlign, "right");
597 static bool executeMakeTextWritingDirectionLeftToRight(Frame& frame, Event*, EditorCommandSource, const String&)
599 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
600 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed);
601 style->setProperty(CSSPropertyDirection, CSSValueLtr);
602 frame.editor().applyStyle(style.get(), EditActionSetWritingDirection);
606 static bool executeMakeTextWritingDirectionNatural(Frame& frame, Event*, EditorCommandSource, const String&)
608 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
609 style->setProperty(CSSPropertyUnicodeBidi, CSSValueNormal);
610 frame.editor().applyStyle(style.get(), EditActionSetWritingDirection);
614 static bool executeMakeTextWritingDirectionRightToLeft(Frame& frame, Event*, EditorCommandSource, const String&)
616 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
617 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed);
618 style->setProperty(CSSPropertyDirection, CSSValueRtl);
619 frame.editor().applyStyle(style.get(), EditActionSetWritingDirection);
623 static bool executeMoveBackward(Frame& frame, Event*, EditorCommandSource, const String&)
625 frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, CharacterGranularity, UserTriggered);
629 static bool executeMoveBackwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
631 frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, CharacterGranularity, UserTriggered);
635 static bool executeMoveDown(Frame& frame, Event*, EditorCommandSource, const String&)
637 return frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, LineGranularity, UserTriggered);
640 static bool executeMoveDownAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
642 frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, LineGranularity, UserTriggered);
646 static bool executeMoveForward(Frame& frame, Event*, EditorCommandSource, const String&)
648 frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity, UserTriggered);
652 static bool executeMoveForwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
654 frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, CharacterGranularity, UserTriggered);
658 static bool executeMoveLeft(Frame& frame, Event*, EditorCommandSource, const String&)
660 return frame.selection().modify(FrameSelection::AlterationMove, DirectionLeft, CharacterGranularity, UserTriggered);
663 static bool executeMoveLeftAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
665 frame.selection().modify(FrameSelection::AlterationExtend, DirectionLeft, CharacterGranularity, UserTriggered);
669 static bool executeMovePageDown(Frame& frame, Event*, EditorCommandSource, const String&)
671 unsigned distance = verticalScrollDistance(frame);
674 return frame.selection().modify(FrameSelection::AlterationMove, distance, FrameSelection::DirectionDown,
675 UserTriggered, FrameSelection::AlignCursorOnScrollAlways);
678 static bool executeMovePageDownAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
680 unsigned distance = verticalScrollDistance(frame);
683 return frame.selection().modify(FrameSelection::AlterationExtend, distance, FrameSelection::DirectionDown,
684 UserTriggered, FrameSelection::AlignCursorOnScrollAlways);
687 static bool executeMovePageUp(Frame& frame, Event*, EditorCommandSource, const String&)
689 unsigned distance = verticalScrollDistance(frame);
692 return frame.selection().modify(FrameSelection::AlterationMove, distance, FrameSelection::DirectionUp,
693 UserTriggered, FrameSelection::AlignCursorOnScrollAlways);
696 static bool executeMovePageUpAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
698 unsigned distance = verticalScrollDistance(frame);
701 return frame.selection().modify(FrameSelection::AlterationExtend, distance, FrameSelection::DirectionUp,
702 UserTriggered, FrameSelection::AlignCursorOnScrollAlways);
705 static bool executeMoveRight(Frame& frame, Event*, EditorCommandSource, const String&)
707 return frame.selection().modify(FrameSelection::AlterationMove, DirectionRight, CharacterGranularity, UserTriggered);
710 static bool executeMoveRightAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
712 frame.selection().modify(FrameSelection::AlterationExtend, DirectionRight, CharacterGranularity, UserTriggered);
716 static bool executeMoveToBeginningOfDocument(Frame& frame, Event*, EditorCommandSource, const String&)
718 frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, DocumentBoundary, UserTriggered);
722 static bool executeMoveToBeginningOfDocumentAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
724 frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, DocumentBoundary, UserTriggered);
728 static bool executeMoveToBeginningOfLine(Frame& frame, Event*, EditorCommandSource, const String&)
730 frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, LineBoundary, UserTriggered);
734 static bool executeMoveToBeginningOfLineAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
736 frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, LineBoundary, UserTriggered);
740 static bool executeMoveToBeginningOfParagraph(Frame& frame, Event*, EditorCommandSource, const String&)
742 frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, ParagraphBoundary, UserTriggered);
746 static bool executeMoveToBeginningOfParagraphAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
748 frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, ParagraphBoundary, UserTriggered);
752 static bool executeMoveToBeginningOfSentence(Frame& frame, Event*, EditorCommandSource, const String&)
754 frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, SentenceBoundary, UserTriggered);
758 static bool executeMoveToBeginningOfSentenceAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
760 frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, SentenceBoundary, UserTriggered);
764 static bool executeMoveToEndOfDocument(Frame& frame, Event*, EditorCommandSource, const String&)
766 frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, DocumentBoundary, UserTriggered);
770 static bool executeMoveToEndOfDocumentAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
772 frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, DocumentBoundary, UserTriggered);
776 static bool executeMoveToEndOfSentence(Frame& frame, Event*, EditorCommandSource, const String&)
778 frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, SentenceBoundary, UserTriggered);
782 static bool executeMoveToEndOfSentenceAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
784 frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, SentenceBoundary, UserTriggered);
788 static bool executeMoveToEndOfLine(Frame& frame, Event*, EditorCommandSource, const String&)
790 frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, LineBoundary, UserTriggered);
794 static bool executeMoveToEndOfLineAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
796 frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, LineBoundary, UserTriggered);
800 static bool executeMoveToEndOfParagraph(Frame& frame, Event*, EditorCommandSource, const String&)
802 frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, ParagraphBoundary, UserTriggered);
806 static bool executeMoveToEndOfParagraphAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
808 frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, ParagraphBoundary, UserTriggered);
812 static bool executeMoveParagraphBackward(Frame& frame, Event*, EditorCommandSource, const String&)
814 frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, ParagraphGranularity, UserTriggered);
818 static bool executeMoveParagraphBackwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
820 frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, ParagraphGranularity, UserTriggered);
824 static bool executeMoveParagraphForward(Frame& frame, Event*, EditorCommandSource, const String&)
826 frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, ParagraphGranularity, UserTriggered);
830 static bool executeMoveParagraphForwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
832 frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, ParagraphGranularity, UserTriggered);
836 static bool executeMoveUp(Frame& frame, Event*, EditorCommandSource, const String&)
838 return frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, LineGranularity, UserTriggered);
841 static bool executeMoveUpAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
843 frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, LineGranularity, UserTriggered);
847 static bool executeMoveWordBackward(Frame& frame, Event*, EditorCommandSource, const String&)
849 frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, WordGranularity, UserTriggered);
853 static bool executeMoveWordBackwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
855 frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, WordGranularity, UserTriggered);
859 static bool executeMoveWordForward(Frame& frame, Event*, EditorCommandSource, const String&)
861 frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, WordGranularity, UserTriggered);
865 static bool executeMoveWordForwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
867 frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, WordGranularity, UserTriggered);
871 static bool executeMoveWordLeft(Frame& frame, Event*, EditorCommandSource, const String&)
873 frame.selection().modify(FrameSelection::AlterationMove, DirectionLeft, WordGranularity, UserTriggered);
877 static bool executeMoveWordLeftAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
879 frame.selection().modify(FrameSelection::AlterationExtend, DirectionLeft, WordGranularity, UserTriggered);
883 static bool executeMoveWordRight(Frame& frame, Event*, EditorCommandSource, const String&)
885 frame.selection().modify(FrameSelection::AlterationMove, DirectionRight, WordGranularity, UserTriggered);
889 static bool executeMoveWordRightAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
891 frame.selection().modify(FrameSelection::AlterationExtend, DirectionRight, WordGranularity, UserTriggered);
895 static bool executeMoveToLeftEndOfLine(Frame& frame, Event*, EditorCommandSource, const String&)
897 frame.selection().modify(FrameSelection::AlterationMove, DirectionLeft, LineBoundary, UserTriggered);
901 static bool executeMoveToLeftEndOfLineAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
903 frame.selection().modify(FrameSelection::AlterationExtend, DirectionLeft, LineBoundary, UserTriggered);
907 static bool executeMoveToRightEndOfLine(Frame& frame, Event*, EditorCommandSource, const String&)
909 frame.selection().modify(FrameSelection::AlterationMove, DirectionRight, LineBoundary, UserTriggered);
913 static bool executeMoveToRightEndOfLineAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
915 frame.selection().modify(FrameSelection::AlterationExtend, DirectionRight, LineBoundary, UserTriggered);
919 static bool executeOutdent(Frame& frame, Event*, EditorCommandSource, const String&)
921 ASSERT(frame.document());
922 IndentOutdentCommand::create(*frame.document(), IndentOutdentCommand::Outdent)->apply();
926 static bool executeToggleOverwrite(Frame& frame, Event*, EditorCommandSource, const String&)
928 frame.editor().toggleOverwriteModeEnabled();
932 static bool executePaste(Frame& frame, Event*, EditorCommandSource, const String&)
934 frame.editor().paste();
938 static bool executePasteGlobalSelection(Frame& frame, Event*, EditorCommandSource source, const String&)
940 if (!frame.editor().behavior().supportsGlobalSelection())
942 ASSERT_UNUSED(source, source == CommandFromMenuOrKeyBinding);
944 bool oldSelectionMode = Pasteboard::generalPasteboard()->isSelectionMode();
945 Pasteboard::generalPasteboard()->setSelectionMode(true);
946 frame.editor().paste();
947 Pasteboard::generalPasteboard()->setSelectionMode(oldSelectionMode);
951 static bool executePasteAndMatchStyle(Frame& frame, Event*, EditorCommandSource, const String&)
953 frame.editor().pasteAsPlainText();
957 static bool executePrint(Frame& frame, Event*, EditorCommandSource, const String&)
959 FrameHost* host = frame.host();
962 host->chrome().print(&frame);
966 static bool executeRedo(Frame& frame, Event*, EditorCommandSource, const String&)
968 frame.editor().redo();
972 static bool executeRemoveFormat(Frame& frame, Event*, EditorCommandSource, const String&)
974 frame.editor().removeFormattingAndStyle();
978 static bool executeScrollPageBackward(Frame& frame, Event*, EditorCommandSource, const String&)
980 return frame.eventHandler().bubblingScroll(ScrollBlockDirectionBackward, ScrollByPage);
983 static bool executeScrollPageForward(Frame& frame, Event*, EditorCommandSource, const String&)
985 return frame.eventHandler().bubblingScroll(ScrollBlockDirectionForward, ScrollByPage);
988 static bool executeScrollLineUp(Frame& frame, Event*, EditorCommandSource, const String&)
990 return frame.eventHandler().bubblingScroll(ScrollUp, ScrollByLine);
993 static bool executeScrollLineDown(Frame& frame, Event*, EditorCommandSource, const String&)
995 return frame.eventHandler().bubblingScroll(ScrollDown, ScrollByLine);
998 static bool executeScrollToBeginningOfDocument(Frame& frame, Event*, EditorCommandSource, const String&)
1000 return frame.eventHandler().bubblingScroll(ScrollBlockDirectionBackward, ScrollByDocument);
1003 static bool executeScrollToEndOfDocument(Frame& frame, Event*, EditorCommandSource, const String&)
1005 return frame.eventHandler().bubblingScroll(ScrollBlockDirectionForward, ScrollByDocument);
1008 static bool executeSelectAll(Frame& frame, Event*, EditorCommandSource, const String&)
1010 frame.selection().selectAll();
1014 static bool executeSelectLine(Frame& frame, Event*, EditorCommandSource, const String&)
1016 return expandSelectionToGranularity(frame, LineGranularity);
1019 static bool executeSelectParagraph(Frame& frame, Event*, EditorCommandSource, const String&)
1021 return expandSelectionToGranularity(frame, ParagraphGranularity);
1024 static bool executeSelectSentence(Frame& frame, Event*, EditorCommandSource, const String&)
1026 return expandSelectionToGranularity(frame, SentenceGranularity);
1029 static bool executeSelectToMark(Frame& frame, Event*, EditorCommandSource, const String&)
1031 RefPtr<Range> mark = frame.editor().mark().toNormalizedRange();
1032 RefPtr<Range> selection = frame.editor().selectedRange();
1033 if (!mark || !selection)
1035 frame.selection().setSelectedRange(unionDOMRanges(mark.get(), selection.get()).get(), DOWNSTREAM, true);
1039 static bool executeSelectWord(Frame& frame, Event*, EditorCommandSource, const String&)
1041 return expandSelectionToGranularity(frame, WordGranularity);
1044 static bool executeSetMark(Frame& frame, Event*, EditorCommandSource, const String&)
1046 frame.editor().setMark(frame.selection().selection());
1050 static bool executeStrikethrough(Frame& frame, Event*, EditorCommandSource source, const String&)
1052 RefPtr<CSSPrimitiveValue> lineThrough = CSSPrimitiveValue::createIdentifier(CSSValueLineThrough);
1053 return executeToggleStyleInList(frame, source, EditActionUnderline, CSSPropertyWebkitTextDecorationsInEffect, lineThrough.get());
1056 static bool executeStyleWithCSS(Frame& frame, Event*, EditorCommandSource, const String& value)
1058 frame.editor().setShouldStyleWithCSS(!equalIgnoringCase(value, "false"));
1062 static bool executeUseCSS(Frame& frame, Event*, EditorCommandSource, const String& value)
1064 frame.editor().setShouldStyleWithCSS(equalIgnoringCase(value, "false"));
1068 static bool executeSubscript(Frame& frame, Event*, EditorCommandSource source, const String&)
1070 return executeToggleStyle(frame, source, EditActionSubscript, CSSPropertyVerticalAlign, "baseline", "sub");
1073 static bool executeSuperscript(Frame& frame, Event*, EditorCommandSource source, const String&)
1075 return executeToggleStyle(frame, source, EditActionSuperscript, CSSPropertyVerticalAlign, "baseline", "super");
1078 static bool executeSwapWithMark(Frame& frame, Event*, EditorCommandSource, const String&)
1080 const VisibleSelection& mark = frame.editor().mark();
1081 const VisibleSelection& selection = frame.selection().selection();
1082 if (mark.isNone() || selection.isNone())
1084 frame.selection().setSelection(mark);
1085 frame.editor().setMark(selection);
1089 static bool executeToggleBold(Frame& frame, Event*, EditorCommandSource source, const String&)
1091 return executeToggleStyle(frame, source, EditActionBold, CSSPropertyFontWeight, "normal", "bold");
1094 static bool executeToggleItalic(Frame& frame, Event*, EditorCommandSource source, const String&)
1096 return executeToggleStyle(frame, source, EditActionItalics, CSSPropertyFontStyle, "normal", "italic");
1099 static bool executeTranspose(Frame& frame, Event*, EditorCommandSource, const String&)
1101 frame.editor().transpose();
1105 static bool executeUnderline(Frame& frame, Event*, EditorCommandSource source, const String&)
1107 RefPtr<CSSPrimitiveValue> underline = CSSPrimitiveValue::createIdentifier(CSSValueUnderline);
1108 return executeToggleStyleInList(frame, source, EditActionUnderline, CSSPropertyWebkitTextDecorationsInEffect, underline.get());
1111 static bool executeUndo(Frame& frame, Event*, EditorCommandSource, const String&)
1113 frame.editor().undo();
1117 static bool executeUnlink(Frame& frame, Event*, EditorCommandSource, const String&)
1119 ASSERT(frame.document());
1120 UnlinkCommand::create(*frame.document())->apply();
1124 static bool executeUnscript(Frame& frame, Event*, EditorCommandSource source, const String&)
1126 return executeApplyStyle(frame, source, EditActionUnscript, CSSPropertyVerticalAlign, "baseline");
1129 static bool executeUnselect(Frame& frame, Event*, EditorCommandSource, const String&)
1131 frame.selection().clear();
1135 static bool executeYank(Frame& frame, Event*, EditorCommandSource, const String&)
1137 frame.editor().insertTextWithoutSendingTextEvent(frame.editor().killRing().yank(), false, 0);
1138 frame.editor().killRing().setToYankedState();
1142 static bool executeYankAndSelect(Frame& frame, Event*, EditorCommandSource, const String&)
1144 frame.editor().insertTextWithoutSendingTextEvent(frame.editor().killRing().yank(), true, 0);
1145 frame.editor().killRing().setToYankedState();
1149 // Supported functions
1151 static bool supported(Frame*)
1156 static bool supportedFromMenuOrKeyBinding(Frame*)
1161 static bool supportedCopyCut(Frame* frame)
1166 Settings* settings = frame->settings();
1167 bool defaultValue = settings && settings->javaScriptCanAccessClipboard();
1168 return frame->editor().client().canCopyCut(frame, defaultValue);
1171 static bool supportedPaste(Frame* frame)
1176 Settings* settings = frame->settings();
1177 bool defaultValue = settings && settings->javaScriptCanAccessClipboard() && settings->DOMPasteAllowed();
1178 return frame->editor().client().canPaste(frame, defaultValue);
1181 // Enabled functions
1183 static bool enabled(Frame&, Event*, EditorCommandSource)
1188 static bool enabledVisibleSelection(Frame& frame, Event* event, EditorCommandSource)
1190 // The term "visible" here includes a caret in editable text or a range in any text.
1191 const VisibleSelection& selection = frame.editor().selectionForCommand(event);
1192 return (selection.isCaret() && selection.isContentEditable()) || selection.isRange();
1195 static bool caretBrowsingEnabled(Frame& frame)
1197 return frame.settings() && frame.settings()->caretBrowsingEnabled();
1200 static EditorCommandSource dummyEditorCommandSource = static_cast<EditorCommandSource>(0);
1202 static bool enabledVisibleSelectionOrCaretBrowsing(Frame& frame, Event* event, EditorCommandSource)
1204 // The EditorCommandSource parameter is unused in enabledVisibleSelection, so just pass a dummy variable
1205 return caretBrowsingEnabled(frame) || enabledVisibleSelection(frame, event, dummyEditorCommandSource);
1208 static bool enabledVisibleSelectionAndMark(Frame& frame, Event* event, EditorCommandSource)
1210 const VisibleSelection& selection = frame.editor().selectionForCommand(event);
1211 return ((selection.isCaret() && selection.isContentEditable()) || selection.isRange())
1212 && frame.editor().mark().isCaretOrRange();
1215 static bool enableCaretInEditableText(Frame& frame, Event* event, EditorCommandSource)
1217 const VisibleSelection& selection = frame.editor().selectionForCommand(event);
1218 return selection.isCaret() && selection.isContentEditable();
1221 static bool enabledCopy(Frame& frame, Event*, EditorCommandSource)
1223 return frame.editor().canDHTMLCopy() || frame.editor().canCopy();
1226 static bool enabledCut(Frame& frame, Event*, EditorCommandSource)
1228 return frame.editor().canDHTMLCut() || frame.editor().canCut();
1231 static bool enabledInEditableText(Frame& frame, Event* event, EditorCommandSource)
1233 return frame.editor().selectionForCommand(event).rootEditableElement();
1236 static bool enabledDelete(Frame& frame, Event* event, EditorCommandSource source)
1239 case CommandFromMenuOrKeyBinding:
1240 return frame.editor().canDelete();
1241 case CommandFromDOM:
1242 case CommandFromDOMWithUserInterface:
1243 // "Delete" from DOM is like delete/backspace keypress, affects selected range if non-empty,
1244 // otherwise removes a character
1245 return enabledInEditableText(frame, event, source);
1247 ASSERT_NOT_REACHED();
1251 static bool enabledInEditableTextOrCaretBrowsing(Frame& frame, Event* event, EditorCommandSource)
1253 // The EditorCommandSource parameter is unused in enabledInEditableText, so just pass a dummy variable
1254 return caretBrowsingEnabled(frame) || enabledInEditableText(frame, event, dummyEditorCommandSource);
1257 static bool enabledInRichlyEditableText(Frame& frame, Event*, EditorCommandSource)
1259 return frame.selection().isCaretOrRange() && frame.selection().isContentRichlyEditable() && frame.selection().rootEditableElement();
1262 static bool enabledPaste(Frame& frame, Event*, EditorCommandSource)
1264 return frame.editor().canPaste();
1267 static bool enabledRangeInEditableText(Frame& frame, Event*, EditorCommandSource)
1269 return frame.selection().isRange() && frame.selection().isContentEditable();
1272 static bool enabledRangeInRichlyEditableText(Frame& frame, Event*, EditorCommandSource)
1274 return frame.selection().isRange() && frame.selection().isContentRichlyEditable();
1277 static bool enabledRedo(Frame& frame, Event*, EditorCommandSource)
1279 return frame.editor().canRedo();
1282 static bool enabledUndo(Frame& frame, Event*, EditorCommandSource)
1284 return frame.editor().canUndo();
1289 static TriState stateNone(Frame&, Event*)
1291 return FalseTriState;
1294 static TriState stateBold(Frame& frame, Event*)
1296 return stateStyle(frame, CSSPropertyFontWeight, "bold");
1299 static TriState stateItalic(Frame& frame, Event*)
1301 return stateStyle(frame, CSSPropertyFontStyle, "italic");
1304 static TriState stateOrderedList(Frame& frame, Event*)
1306 return frame.editor().selectionOrderedListState();
1309 static TriState stateStrikethrough(Frame& frame, Event*)
1311 return stateStyle(frame, CSSPropertyWebkitTextDecorationsInEffect, "line-through");
1314 static TriState stateStyleWithCSS(Frame& frame, Event*)
1316 return frame.editor().shouldStyleWithCSS() ? TrueTriState : FalseTriState;
1319 static TriState stateSubscript(Frame& frame, Event*)
1321 return stateStyle(frame, CSSPropertyVerticalAlign, "sub");
1324 static TriState stateSuperscript(Frame& frame, Event*)
1326 return stateStyle(frame, CSSPropertyVerticalAlign, "super");
1329 static TriState stateTextWritingDirectionLeftToRight(Frame& frame, Event*)
1331 return stateTextWritingDirection(frame, LeftToRightWritingDirection);
1334 static TriState stateTextWritingDirectionNatural(Frame& frame, Event*)
1336 return stateTextWritingDirection(frame, NaturalWritingDirection);
1339 static TriState stateTextWritingDirectionRightToLeft(Frame& frame, Event*)
1341 return stateTextWritingDirection(frame, RightToLeftWritingDirection);
1344 static TriState stateUnderline(Frame& frame, Event*)
1346 return stateStyle(frame, CSSPropertyWebkitTextDecorationsInEffect, "underline");
1349 static TriState stateUnorderedList(Frame& frame, Event*)
1351 return frame.editor().selectionUnorderedListState();
1354 static TriState stateJustifyCenter(Frame& frame, Event*)
1356 return stateStyle(frame, CSSPropertyTextAlign, "center");
1359 static TriState stateJustifyFull(Frame& frame, Event*)
1361 return stateStyle(frame, CSSPropertyTextAlign, "justify");
1364 static TriState stateJustifyLeft(Frame& frame, Event*)
1366 return stateStyle(frame, CSSPropertyTextAlign, "left");
1369 static TriState stateJustifyRight(Frame& frame, Event*)
1371 return stateStyle(frame, CSSPropertyTextAlign, "right");
1376 static String valueNull(Frame&, Event*)
1381 static String valueBackColor(Frame& frame, Event*)
1383 return valueStyle(frame, CSSPropertyBackgroundColor);
1386 static String valueDefaultParagraphSeparator(Frame& frame, Event*)
1388 switch (frame.editor().defaultParagraphSeparator()) {
1389 case EditorParagraphSeparatorIsDiv:
1390 return divTag.localName();
1391 case EditorParagraphSeparatorIsP:
1392 return pTag.localName();
1395 ASSERT_NOT_REACHED();
1399 static String valueFontName(Frame& frame, Event*)
1401 return valueStyle(frame, CSSPropertyFontFamily);
1404 static String valueFontSize(Frame& frame, Event*)
1406 return valueStyle(frame, CSSPropertyFontSize);
1409 static String valueFontSizeDelta(Frame& frame, Event*)
1411 return valueStyle(frame, CSSPropertyWebkitFontSizeDelta);
1414 static String valueForeColor(Frame& frame, Event*)
1416 return valueStyle(frame, CSSPropertyColor);
1419 static String valueFormatBlock(Frame& frame, Event*)
1421 const VisibleSelection& selection = frame.selection().selection();
1422 if (!selection.isNonOrphanedCaretOrRange() || !selection.isContentEditable())
1424 Element* formatBlockElement = FormatBlockCommand::elementForFormatBlockCommand(selection.firstRange().get());
1425 if (!formatBlockElement)
1427 return formatBlockElement->localName();
1432 struct CommandEntry {
1434 EditorInternalCommand command;
1437 static const CommandMap& createCommandMap()
1439 // If you add new commands, you should assign new Id to each idForUserMetrics and update MappedEditingCommands
1440 // in chrome/trunk/src/tools/metrics/histograms/histograms.xml.
1441 static const CommandEntry commands[] = {
1442 { "AlignCenter", {139, executeJustifyCenter, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1443 { "AlignJustified", {1, executeJustifyFull, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1444 { "AlignLeft", {2, executeJustifyLeft, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1445 { "AlignRight", {3, executeJustifyRight, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1446 { "BackColor", {4, executeBackColor, supported, enabledInRichlyEditableText, stateNone, valueBackColor, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1447 { "BackwardDelete", {5, executeDeleteBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, // FIXME: remove BackwardDelete when Safari for Windows stops using it.
1448 { "Bold", {6, executeToggleBold, supported, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1449 { "Copy", {7, executeCopy, supportedCopyCut, enabledCopy, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1450 { "CreateLink", {8, executeCreateLink, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1451 { "Cut", {9, executeCut, supportedCopyCut, enabledCut, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1452 { "DefaultParagraphSeparator", {10, executeDefaultParagraphSeparator, supported, enabled, stateNone, valueDefaultParagraphSeparator, notTextInsertion, doNotAllowExecutionWhenDisabled} },
1453 { "Delete", {11, executeDelete, supported, enabledDelete, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1454 { "DeleteBackward", {12, executeDeleteBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1455 { "DeleteBackwardByDecomposingPreviousCharacter", {13, executeDeleteBackwardByDecomposingPreviousCharacter, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1456 { "DeleteForward", {14, executeDeleteForward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1457 { "DeleteToBeginningOfLine", {15, executeDeleteToBeginningOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1458 { "DeleteToBeginningOfParagraph", {16, executeDeleteToBeginningOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1459 { "DeleteToEndOfLine", {17, executeDeleteToEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1460 { "DeleteToEndOfParagraph", {18, executeDeleteToEndOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1461 { "DeleteToMark", {19, executeDeleteToMark, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1462 { "DeleteWordBackward", {20, executeDeleteWordBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1463 { "DeleteWordForward", {21, executeDeleteWordForward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1464 { "FindString", {22, executeFindString, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1465 { "FontName", {23, executeFontName, supported, enabledInEditableText, stateNone, valueFontName, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1466 { "FontSize", {24, executeFontSize, supported, enabledInEditableText, stateNone, valueFontSize, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1467 { "FontSizeDelta", {25, executeFontSizeDelta, supported, enabledInEditableText, stateNone, valueFontSizeDelta, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1468 { "ForeColor", {26, executeForeColor, supported, enabledInRichlyEditableText, stateNone, valueForeColor, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1469 { "FormatBlock", {27, executeFormatBlock, supported, enabledInRichlyEditableText, stateNone, valueFormatBlock, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1470 { "ForwardDelete", {28, executeForwardDelete, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1471 { "HiliteColor", {29, executeBackColor, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1472 { "IgnoreSpelling", {30, executeIgnoreSpelling, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1473 { "Indent", {31, executeIndent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1474 { "InsertBacktab", {32, executeInsertBacktab, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1475 { "InsertHTML", {33, executeInsertHTML, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1476 { "InsertHorizontalRule", {34, executeInsertHorizontalRule, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1477 { "InsertImage", {35, executeInsertImage, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1478 { "InsertLineBreak", {36, executeInsertLineBreak, supported, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1479 { "InsertNewline", {37, executeInsertNewline, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1480 { "InsertNewlineInQuotedContent", {38, executeInsertNewlineInQuotedContent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1481 { "InsertOrderedList", {39, executeInsertOrderedList, supported, enabledInRichlyEditableText, stateOrderedList, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1482 { "InsertParagraph", {40, executeInsertParagraph, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1483 { "InsertTab", {41, executeInsertTab, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1484 { "InsertText", {42, executeInsertText, supported, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1485 { "InsertUnorderedList", {43, executeInsertUnorderedList, supported, enabledInRichlyEditableText, stateUnorderedList, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1486 { "Italic", {44, executeToggleItalic, supported, enabledInRichlyEditableText, stateItalic, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1487 { "JustifyCenter", {45, executeJustifyCenter, supported, enabledInRichlyEditableText, stateJustifyCenter, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1488 { "JustifyFull", {46, executeJustifyFull, supported, enabledInRichlyEditableText, stateJustifyFull, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1489 { "JustifyLeft", {47, executeJustifyLeft, supported, enabledInRichlyEditableText, stateJustifyLeft, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1490 { "JustifyNone", {48, executeJustifyLeft, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1491 { "JustifyRight", {49, executeJustifyRight, supported, enabledInRichlyEditableText, stateJustifyRight, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1492 { "MakeTextWritingDirectionLeftToRight", {50, executeMakeTextWritingDirectionLeftToRight, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionLeftToRight, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1493 { "MakeTextWritingDirectionNatural", {51, executeMakeTextWritingDirectionNatural, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionNatural, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1494 { "MakeTextWritingDirectionRightToLeft", {52, executeMakeTextWritingDirectionRightToLeft, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionRightToLeft, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1495 { "MoveBackward", {53, executeMoveBackward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1496 { "MoveBackwardAndModifySelection", {54, executeMoveBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1497 { "MoveDown", {55, executeMoveDown, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1498 { "MoveDownAndModifySelection", {56, executeMoveDownAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1499 { "MoveForward", {57, executeMoveForward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1500 { "MoveForwardAndModifySelection", {58, executeMoveForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1501 { "MoveLeft", {59, executeMoveLeft, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1502 { "MoveLeftAndModifySelection", {60, executeMoveLeftAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1503 { "MovePageDown", {61, executeMovePageDown, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1504 { "MovePageDownAndModifySelection", {62, executeMovePageDownAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1505 { "MovePageUp", {63, executeMovePageUp, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1506 { "MovePageUpAndModifySelection", {64, executeMovePageUpAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1507 { "MoveParagraphBackward", {65, executeMoveParagraphBackward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1508 { "MoveParagraphBackwardAndModifySelection", {66, executeMoveParagraphBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1509 { "MoveParagraphForward", {67, executeMoveParagraphForward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1510 { "MoveParagraphForwardAndModifySelection", {68, executeMoveParagraphForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1511 { "MoveRight", {69, executeMoveRight, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1512 { "MoveRightAndModifySelection", {70, executeMoveRightAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1513 { "MoveToBeginningOfDocument", {71, executeMoveToBeginningOfDocument, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1514 { "MoveToBeginningOfDocumentAndModifySelection", {72, executeMoveToBeginningOfDocumentAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1515 { "MoveToBeginningOfLine", {73, executeMoveToBeginningOfLine, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1516 { "MoveToBeginningOfLineAndModifySelection", {74, executeMoveToBeginningOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1517 { "MoveToBeginningOfParagraph", {75, executeMoveToBeginningOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1518 { "MoveToBeginningOfParagraphAndModifySelection", {76, executeMoveToBeginningOfParagraphAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1519 { "MoveToBeginningOfSentence", {77, executeMoveToBeginningOfSentence, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1520 { "MoveToBeginningOfSentenceAndModifySelection", {78, executeMoveToBeginningOfSentenceAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1521 { "MoveToEndOfDocument", {79, executeMoveToEndOfDocument, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1522 { "MoveToEndOfDocumentAndModifySelection", {80, executeMoveToEndOfDocumentAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1523 { "MoveToEndOfLine", {81, executeMoveToEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1524 { "MoveToEndOfLineAndModifySelection", {82, executeMoveToEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1525 { "MoveToEndOfParagraph", {83, executeMoveToEndOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1526 { "MoveToEndOfParagraphAndModifySelection", {84, executeMoveToEndOfParagraphAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1527 { "MoveToEndOfSentence", {85, executeMoveToEndOfSentence, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1528 { "MoveToEndOfSentenceAndModifySelection", {86, executeMoveToEndOfSentenceAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1529 { "MoveToLeftEndOfLine", {87, executeMoveToLeftEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1530 { "MoveToLeftEndOfLineAndModifySelection", {88, executeMoveToLeftEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1531 { "MoveToRightEndOfLine", {89, executeMoveToRightEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1532 { "MoveToRightEndOfLineAndModifySelection", {90, executeMoveToRightEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1533 { "MoveUp", {91, executeMoveUp, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1534 { "MoveUpAndModifySelection", {92, executeMoveUpAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1535 { "MoveWordBackward", {93, executeMoveWordBackward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1536 { "MoveWordBackwardAndModifySelection", {94, executeMoveWordBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1537 { "MoveWordForward", {95, executeMoveWordForward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1538 { "MoveWordForwardAndModifySelection", {96, executeMoveWordForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1539 { "MoveWordLeft", {97, executeMoveWordLeft, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1540 { "MoveWordLeftAndModifySelection", {98, executeMoveWordLeftAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1541 { "MoveWordRight", {99, executeMoveWordRight, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1542 { "MoveWordRightAndModifySelection", {100, executeMoveWordRightAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1543 { "Outdent", {101, executeOutdent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1544 { "OverWrite", {102, executeToggleOverwrite, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1545 { "Paste", {103, executePaste, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1546 { "PasteAndMatchStyle", {104, executePasteAndMatchStyle, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1547 { "PasteGlobalSelection", {105, executePasteGlobalSelection, supportedFromMenuOrKeyBinding, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1548 { "Print", {106, executePrint, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1549 { "Redo", {107, executeRedo, supported, enabledRedo, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1550 { "RemoveFormat", {108, executeRemoveFormat, supported, enabledRangeInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1551 { "ScrollPageBackward", {109, executeScrollPageBackward, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1552 { "ScrollPageForward", {110, executeScrollPageForward, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1553 { "ScrollLineUp", {111, executeScrollLineUp, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1554 { "ScrollLineDown", {112, executeScrollLineDown, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1555 { "ScrollToBeginningOfDocument", {113, executeScrollToBeginningOfDocument, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1556 { "ScrollToEndOfDocument", {114, executeScrollToEndOfDocument, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1557 { "SelectAll", {115, executeSelectAll, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1558 { "SelectLine", {116, executeSelectLine, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1559 { "SelectParagraph", {117, executeSelectParagraph, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1560 { "SelectSentence", {118, executeSelectSentence, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1561 { "SelectToMark", {119, executeSelectToMark, supportedFromMenuOrKeyBinding, enabledVisibleSelectionAndMark, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1562 { "SelectWord", {120, executeSelectWord, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1563 { "SetMark", {121, executeSetMark, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1564 { "Strikethrough", {122, executeStrikethrough, supported, enabledInRichlyEditableText, stateStrikethrough, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1565 { "StyleWithCSS", {123, executeStyleWithCSS, supported, enabled, stateStyleWithCSS, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1566 { "Subscript", {124, executeSubscript, supported, enabledInRichlyEditableText, stateSubscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1567 { "Superscript", {125, executeSuperscript, supported, enabledInRichlyEditableText, stateSuperscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1568 { "SwapWithMark", {126, executeSwapWithMark, supportedFromMenuOrKeyBinding, enabledVisibleSelectionAndMark, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1569 { "ToggleBold", {127, executeToggleBold, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1570 { "ToggleItalic", {128, executeToggleItalic, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateItalic, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1571 { "ToggleUnderline", {129, executeUnderline, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateUnderline, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1572 { "Transpose", {130, executeTranspose, supported, enableCaretInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1573 { "Underline", {131, executeUnderline, supported, enabledInRichlyEditableText, stateUnderline, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1574 { "Undo", {132, executeUndo, supported, enabledUndo, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1575 { "Unlink", {133, executeUnlink, supported, enabledRangeInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1576 { "Unscript", {134, executeUnscript, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1577 { "Unselect", {135, executeUnselect, supported, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1578 { "UseCSS", {136, executeUseCSS, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1579 { "Yank", {137, executeYank, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1580 { "YankAndSelect", {138, executeYankAndSelect, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1583 // These unsupported commands are listed here since they appear in the Microsoft
1584 // documentation used as the starting point for our DOM executeCommand support.
1586 // 2D-Position (not supported)
1587 // AbsolutePosition (not supported)
1588 // BlockDirLTR (not supported)
1589 // BlockDirRTL (not supported)
1590 // BrowseMode (not supported)
1591 // ClearAuthenticationCache (not supported)
1592 // CreateBookmark (not supported)
1593 // DirLTR (not supported)
1594 // DirRTL (not supported)
1595 // EditMode (not supported)
1596 // InlineDirLTR (not supported)
1597 // InlineDirRTL (not supported)
1598 // InsertButton (not supported)
1599 // InsertFieldSet (not supported)
1600 // InsertIFrame (not supported)
1601 // InsertInputButton (not supported)
1602 // InsertInputCheckbox (not supported)
1603 // InsertInputFileUpload (not supported)
1604 // InsertInputHidden (not supported)
1605 // InsertInputImage (not supported)
1606 // InsertInputPassword (not supported)
1607 // InsertInputRadio (not supported)
1608 // InsertInputReset (not supported)
1609 // InsertInputSubmit (not supported)
1610 // InsertInputText (not supported)
1611 // InsertMarquee (not supported)
1612 // InsertSelectDropDown (not supported)
1613 // InsertSelectListBox (not supported)
1614 // InsertTextArea (not supported)
1615 // LiveResize (not supported)
1616 // MultipleSelection (not supported)
1617 // Open (not supported)
1618 // PlayImage (not supported)
1619 // Refresh (not supported)
1620 // RemoveParaFormat (not supported)
1621 // SaveAs (not supported)
1622 // SizeToControl (not supported)
1623 // SizeToControlHeight (not supported)
1624 // SizeToControlWidth (not supported)
1625 // Stop (not supported)
1626 // StopImage (not supported)
1627 // Unbookmark (not supported)
1629 CommandMap& commandMap = *new CommandMap;
1630 #if !ASSERT_DISABLED
1633 for (size_t i = 0; i < WTF_ARRAY_LENGTH(commands); ++i) {
1634 const CommandEntry& command = commands[i];
1635 ASSERT(!commandMap.get(command.name));
1636 commandMap.set(command.name, &command.command);
1637 #if !ASSERT_DISABLED
1638 ASSERT(!idSet.contains(command.command.idForUserMetrics));
1639 idSet.add(command.command.idForUserMetrics);
1646 static const EditorInternalCommand* internalCommand(const String& commandName)
1648 static const CommandMap& commandMap = createCommandMap();
1649 return commandName.isEmpty() ? 0 : commandMap.get(commandName);
1652 Editor::Command Editor::command(const String& commandName)
1654 return Command(internalCommand(commandName), CommandFromMenuOrKeyBinding, &m_frame);
1657 Editor::Command Editor::command(const String& commandName, EditorCommandSource source)
1659 return Command(internalCommand(commandName), source, &m_frame);
1662 Editor::Command::Command()
1667 Editor::Command::Command(const EditorInternalCommand* command, EditorCommandSource source, PassRefPtr<Frame> frame)
1668 : m_command(command)
1670 , m_frame(command ? frame : 0)
1672 // Use separate assertions so we can tell which bad thing happened.
1679 bool Editor::Command::execute(const String& parameter, Event* triggeringEvent) const
1681 if (!isEnabled(triggeringEvent)) {
1682 // Let certain commands be executed when performed explicitly even if they are disabled.
1683 if (!isSupported() || !m_frame || !m_command->allowExecutionWhenDisabled)
1686 m_frame->document()->updateLayoutIgnorePendingStylesheets();
1687 blink::Platform::current()->histogramSparse("WebCore.Editing.Commands", m_command->idForUserMetrics);
1688 return m_command->execute(*m_frame, triggeringEvent, m_source, parameter);
1691 bool Editor::Command::execute(Event* triggeringEvent) const
1693 return execute(String(), triggeringEvent);
1696 bool Editor::Command::isSupported() const
1701 case CommandFromMenuOrKeyBinding:
1703 case CommandFromDOM:
1704 case CommandFromDOMWithUserInterface:
1705 return m_command->isSupportedFromDOM(m_frame.get());
1707 ASSERT_NOT_REACHED();
1711 bool Editor::Command::isEnabled(Event* triggeringEvent) const
1713 if (!isSupported() || !m_frame)
1715 return m_command->isEnabled(*m_frame, triggeringEvent, m_source);
1718 TriState Editor::Command::state(Event* triggeringEvent) const
1720 if (!isSupported() || !m_frame)
1721 return FalseTriState;
1722 return m_command->state(*m_frame, triggeringEvent);
1725 String Editor::Command::value(Event* triggeringEvent) const
1727 if (!isSupported() || !m_frame)
1729 if (m_command->value == valueNull && m_command->state != stateNone)
1730 return m_command->state(*m_frame, triggeringEvent) == TrueTriState ? "true" : "false";
1731 return m_command->value(*m_frame, triggeringEvent);
1734 bool Editor::Command::isTextInsertion() const
1736 return m_command && m_command->isTextInsertion;
1739 } // namespace WebCore