1 /*
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 #include "config.h"
28
29 #include "AtomicString.h"
30 #include "CSSComputedStyleDeclaration.h"
31 #include "CSSMutableStyleDeclaration.h"
32 #include "CSSPropertyNames.h"
33 #include "CSSValueKeywords.h"
34 #include "CreateLinkCommand.h"
35 #include "DocumentFragment.h"
36 #include "Editor.h"
37 #include "EditorClient.h"
38 #include "Event.h"
39 #include "EventHandler.h"
40 #include "FormatBlockCommand.h"
41 #include "Frame.h"
42 #include "HTMLFontElement.h"
43 #include "HTMLImageElement.h"
44 #include "IndentOutdentCommand.h"
45 #include "InsertListCommand.h"
46 #include "Page.h"
47 #include "RenderBox.h"
48 #include "ReplaceSelectionCommand.h"
49 #include "Scrollbar.h"
50 #include "Settings.h"
51 #include "Sound.h"
52 #include "TypingCommand.h"
53 #include "UnlinkCommand.h"
54 #include "htmlediting.h"
55 #include "markup.h"
56
57 namespace WebCore {
58
59 using namespace HTMLNames;
60
61 class EditorInternalCommand {
62 public:
63 bool (*execute)(Frame*, Event*, EditorCommandSource, const String&);
64 bool (*isSupported)(Frame*, EditorCommandSource);
65 bool (*isEnabled)(Frame*, Event*, EditorCommandSource);
66 TriState (*state)(Frame*, Event*);
67 String (*value)(Frame*, Event*);
68 bool isTextInsertion;
69 bool allowExecutionWhenDisabled;
70 };
71
72 typedef HashMap<String, const EditorInternalCommand*, CaseFoldingHash> CommandMap;
73
74 static const bool notTextInsertion = false;
75 static const bool isTextInsertion = true;
76
77 static const bool allowExecutionWhenDisabled = true;
78 static const bool doNotAllowExecutionWhenDisabled = false;
79
80 // Related to Editor::selectionForCommand.
81 // Certain operations continue to use the target control's selection even if the event handler
82 // already moved the selection outside of the text control.
targetFrame(Frame * frame,Event * event)83 static Frame* targetFrame(Frame* frame, Event* event)
84 {
85 if (!event)
86 return frame;
87 Node* node = event->target()->toNode();
88 if (!node)
89 return frame;
90 return node->document()->frame();
91 }
92
applyCommandToFrame(Frame * frame,EditorCommandSource source,EditAction action,CSSMutableStyleDeclaration * style)93 static bool applyCommandToFrame(Frame* frame, EditorCommandSource source, EditAction action, CSSMutableStyleDeclaration* style)
94 {
95 // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a good reason for that?
96 switch (source) {
97 case CommandFromMenuOrKeyBinding:
98 frame->editor()->applyStyleToSelection(style, action);
99 return true;
100 case CommandFromDOM:
101 case CommandFromDOMWithUserInterface:
102 frame->editor()->applyStyle(style);
103 return true;
104 }
105 ASSERT_NOT_REACHED();
106 return false;
107 }
108
executeApplyStyle(Frame * frame,EditorCommandSource source,EditAction action,int propertyID,const String & propertyValue)109 static bool executeApplyStyle(Frame* frame, EditorCommandSource source, EditAction action, int propertyID, const String& propertyValue)
110 {
111 RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
112 style->setProperty(propertyID, propertyValue);
113 return applyCommandToFrame(frame, source, action, style.get());
114 }
115
executeApplyStyle(Frame * frame,EditorCommandSource source,EditAction action,int propertyID,int propertyValue)116 static bool executeApplyStyle(Frame* frame, EditorCommandSource source, EditAction action, int propertyID, int propertyValue)
117 {
118 RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
119 style->setProperty(propertyID, propertyValue);
120 return applyCommandToFrame(frame, source, action, style.get());
121 }
122
123 // FIXME: executeToggleStyleInList does not handle complicated cases such as <b><u>hello</u>world</b> properly.
124 // This function must use Editor::selectionHasStyle to determine the current style but we cannot fix this
125 // until https://bugs.webkit.org/show_bug.cgi?id=27818 is resolved.
executeToggleStyleInList(Frame * frame,EditorCommandSource source,EditAction action,int propertyID,CSSValue * value)126 static bool executeToggleStyleInList(Frame* frame, EditorCommandSource source, EditAction action, int propertyID, CSSValue* value)
127 {
128 ExceptionCode ec = 0;
129 Node* nodeToRemove = 0;
130 RefPtr<CSSComputedStyleDeclaration> selectionStyle = frame->selectionComputedStyle(nodeToRemove);
131 RefPtr<CSSValue> selectedCSSValue = selectionStyle->getPropertyCSSValue(propertyID);
132 String newStyle = "none";
133 if (selectedCSSValue->isValueList()) {
134 RefPtr<CSSValueList> selectedCSSValueList = static_cast<CSSValueList*>(selectedCSSValue.get());
135 if (!selectedCSSValueList->removeAll(value))
136 selectedCSSValueList->append(value);
137 if (selectedCSSValueList->length())
138 newStyle = selectedCSSValueList->cssText();
139
140 } else if (selectedCSSValue->cssText() == "none")
141 newStyle = value->cssText();
142
143 ASSERT(ec == 0);
144 if (nodeToRemove) {
145 nodeToRemove->remove(ec);
146 ASSERT(ec == 0);
147 }
148
149 // FIXME: We shouldn't be having to convert new style into text. We should have setPropertyCSSValue.
150 RefPtr<CSSMutableStyleDeclaration> newMutableStyle = CSSMutableStyleDeclaration::create();
151 newMutableStyle->setProperty(propertyID, newStyle,ec);
152 return applyCommandToFrame(frame, source, action, newMutableStyle.get());
153 }
154
executeToggleStyle(Frame * frame,EditorCommandSource source,EditAction action,int propertyID,const char * offValue,const char * onValue)155 static bool executeToggleStyle(Frame* frame, EditorCommandSource source, EditAction action, int propertyID, const char* offValue, const char* onValue)
156 {
157 RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
158 style->setProperty(propertyID, onValue); // We need to add this style to pass it to selectionStartHasStyle / selectionHasStyle
159
160 // Style is considered present when
161 // mac: present at the beginning of selection
162 // other: present throughout the selection
163 Settings* settings = frame->document()->settings();
164 bool styleIsPresent;
165 if (settings && settings->editingBehavior() == EditingMacBehavior)
166 styleIsPresent = frame->editor()->selectionStartHasStyle(style.get());
167 else
168 styleIsPresent = frame->editor()->selectionHasStyle(style.get()) == TrueTriState;
169
170 style->setProperty(propertyID, styleIsPresent ? offValue : onValue);
171 return applyCommandToFrame(frame, source, action, style.get());
172 }
173
executeApplyParagraphStyle(Frame * frame,EditorCommandSource source,EditAction action,int propertyID,const String & propertyValue)174 static bool executeApplyParagraphStyle(Frame* frame, EditorCommandSource source, EditAction action, int propertyID, const String& propertyValue)
175 {
176 RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::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?
179 switch (source) {
180 case CommandFromMenuOrKeyBinding:
181 frame->editor()->applyParagraphStyleToSelection(style.get(), action);
182 return true;
183 case CommandFromDOM:
184 case CommandFromDOMWithUserInterface:
185 frame->editor()->applyParagraphStyle(style.get());
186 return true;
187 }
188 ASSERT_NOT_REACHED();
189 return false;
190 }
191
executeInsertFragment(Frame * frame,PassRefPtr<DocumentFragment> fragment)192 static bool executeInsertFragment(Frame* frame, PassRefPtr<DocumentFragment> fragment)
193 {
194 applyCommand(ReplaceSelectionCommand::create(frame->document(), fragment,
195 false, false, false, true, false, EditActionUnspecified));
196 return true;
197 }
198
executeInsertNode(Frame * frame,PassRefPtr<Node> content)199 static bool executeInsertNode(Frame* frame, PassRefPtr<Node> content)
200 {
201 RefPtr<DocumentFragment> fragment = new DocumentFragment(frame->document());
202 ExceptionCode ec = 0;
203 fragment->appendChild(content, ec);
204 if (ec)
205 return false;
206 return executeInsertFragment(frame, fragment.release());
207 }
208
expandSelectionToGranularity(Frame * frame,TextGranularity granularity)209 static bool expandSelectionToGranularity(Frame* frame, TextGranularity granularity)
210 {
211 VisibleSelection selection = frame->selection()->selection();
212 selection.expandUsingGranularity(granularity);
213 RefPtr<Range> newRange = selection.toNormalizedRange();
214 if (!newRange)
215 return false;
216 ExceptionCode ec = 0;
217 if (newRange->collapsed(ec))
218 return false;
219 RefPtr<Range> oldRange = frame->selection()->selection().toNormalizedRange();
220 EAffinity affinity = frame->selection()->affinity();
221 if (!frame->editor()->client()->shouldChangeSelectedRange(oldRange.get(), newRange.get(), affinity, false))
222 return false;
223 frame->selection()->setSelectedRange(newRange.get(), affinity, true);
224 return true;
225 }
226
stateStyle(Frame * frame,int propertyID,const char * desiredValue)227 static TriState stateStyle(Frame* frame, int propertyID, const char* desiredValue)
228 {
229 RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
230 style->setProperty(propertyID, desiredValue);
231 return frame->editor()->selectionHasStyle(style.get());
232 }
233
valueStyle(Frame * frame,int propertyID)234 static String valueStyle(Frame* frame, int propertyID)
235 {
236 return frame->selectionStartStylePropertyValue(propertyID);
237 }
238
stateTextWritingDirection(Frame * frame,WritingDirection direction)239 static TriState stateTextWritingDirection(Frame* frame, WritingDirection direction)
240 {
241 bool hasNestedOrMultipleEmbeddings;
242 WritingDirection selectionDirection = frame->editor()->textDirectionForSelection(hasNestedOrMultipleEmbeddings);
243 return (selectionDirection == direction && !hasNestedOrMultipleEmbeddings) ? TrueTriState : FalseTriState;
244 }
245
verticalScrollDistance(Frame * frame)246 static int verticalScrollDistance(Frame* frame)
247 {
248 Node* focusedNode = frame->document()->focusedNode();
249 if (!focusedNode)
250 return 0;
251 RenderObject* renderer = focusedNode->renderer();
252 if (!renderer || !renderer->isBox())
253 return 0;
254 RenderStyle* style = renderer->style();
255 if (!style)
256 return 0;
257 if (!(style->overflowY() == OSCROLL || style->overflowY() == OAUTO || renderer->isTextArea()))
258 return 0;
259 int height = toRenderBox(renderer)->clientHeight();
260 return max((height + 1) / 2, height - cAmountToKeepWhenPaging);
261 }
262
unionDOMRanges(Range * a,Range * b)263 static RefPtr<Range> unionDOMRanges(Range* a, Range* b)
264 {
265 ExceptionCode ec = 0;
266 Range* start = a->compareBoundaryPoints(Range::START_TO_START, b, ec) <= 0 ? a : b;
267 ASSERT(!ec);
268 Range* end = a->compareBoundaryPoints(Range::END_TO_END, b, ec) <= 0 ? b : a;
269 ASSERT(!ec);
270
271 return Range::create(a->startContainer(ec)->ownerDocument(), start->startContainer(ec), start->startOffset(ec), end->endContainer(ec), end->endOffset(ec));
272 }
273
274 // Execute command functions
275
executeBackColor(Frame * frame,Event *,EditorCommandSource source,const String & value)276 static bool executeBackColor(Frame* frame, Event*, EditorCommandSource source, const String& value)
277 {
278 return executeApplyStyle(frame, source, EditActionSetBackgroundColor, CSSPropertyBackgroundColor, value);
279 }
280
executeCopy(Frame * frame,Event *,EditorCommandSource,const String &)281 static bool executeCopy(Frame* frame, Event*, EditorCommandSource, const String&)
282 {
283 frame->editor()->copy();
284 return true;
285 }
286
executeCreateLink(Frame * frame,Event *,EditorCommandSource,const String & value)287 static bool executeCreateLink(Frame* frame, Event*, EditorCommandSource, const String& value)
288 {
289 // FIXME: If userInterface is true, we should display a dialog box to let the user enter a URL.
290 if (value.isEmpty())
291 return false;
292 applyCommand(CreateLinkCommand::create(frame->document(), value));
293 return true;
294 }
295
executeCut(Frame * frame,Event *,EditorCommandSource,const String &)296 static bool executeCut(Frame* frame, Event*, EditorCommandSource, const String&)
297 {
298 frame->editor()->cut();
299 return true;
300 }
301
executeDelete(Frame * frame,Event *,EditorCommandSource source,const String &)302 static bool executeDelete(Frame* frame, Event*, EditorCommandSource source, const String&)
303 {
304 switch (source) {
305 case CommandFromMenuOrKeyBinding:
306 // Doesn't modify the text if the current selection isn't a range.
307 frame->editor()->performDelete();
308 return true;
309 case CommandFromDOM:
310 case CommandFromDOMWithUserInterface:
311 // If the current selection is a caret, delete the preceding character. IE performs forwardDelete, but we currently side with Firefox.
312 // Doesn't scroll to make the selection visible, or modify the kill ring (this time, siding with IE, not Firefox).
313 TypingCommand::deleteKeyPressed(frame->document(), frame->selectionGranularity() == WordGranularity);
314 return true;
315 }
316 ASSERT_NOT_REACHED();
317 return false;
318 }
319
executeDeleteBackward(Frame * frame,Event *,EditorCommandSource,const String &)320 static bool executeDeleteBackward(Frame* frame, Event*, EditorCommandSource, const String&)
321 {
322 frame->editor()->deleteWithDirection(SelectionController::BACKWARD, CharacterGranularity, false, true);
323 return true;
324 }
325
executeDeleteBackwardByDecomposingPreviousCharacter(Frame * frame,Event *,EditorCommandSource,const String &)326 static bool executeDeleteBackwardByDecomposingPreviousCharacter(Frame* frame, Event*, EditorCommandSource, const String&)
327 {
328 LOG_ERROR("DeleteBackwardByDecomposingPreviousCharacter is not implemented, doing DeleteBackward instead");
329 frame->editor()->deleteWithDirection(SelectionController::BACKWARD, CharacterGranularity, false, true);
330 return true;
331 }
332
executeDeleteForward(Frame * frame,Event *,EditorCommandSource,const String &)333 static bool executeDeleteForward(Frame* frame, Event*, EditorCommandSource, const String&)
334 {
335 frame->editor()->deleteWithDirection(SelectionController::FORWARD, CharacterGranularity, false, true);
336 return true;
337 }
338
executeDeleteToBeginningOfLine(Frame * frame,Event *,EditorCommandSource,const String &)339 static bool executeDeleteToBeginningOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
340 {
341 frame->editor()->deleteWithDirection(SelectionController::BACKWARD, LineBoundary, true, false);
342 return true;
343 }
344
executeDeleteToBeginningOfParagraph(Frame * frame,Event *,EditorCommandSource,const String &)345 static bool executeDeleteToBeginningOfParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
346 {
347 frame->editor()->deleteWithDirection(SelectionController::BACKWARD, ParagraphBoundary, true, false);
348 return true;
349 }
350
executeDeleteToEndOfLine(Frame * frame,Event *,EditorCommandSource,const String &)351 static bool executeDeleteToEndOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
352 {
353 // Despite its name, this command should delete the newline at the end of
354 // a paragraph if you are at the end of a paragraph (like DeleteToEndOfParagraph).
355 frame->editor()->deleteWithDirection(SelectionController::FORWARD, LineBoundary, true, false);
356 return true;
357 }
358
executeDeleteToEndOfParagraph(Frame * frame,Event *,EditorCommandSource,const String &)359 static bool executeDeleteToEndOfParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
360 {
361 // Despite its name, this command should delete the newline at the end of
362 // a paragraph if you are at the end of a paragraph.
363 frame->editor()->deleteWithDirection(SelectionController::FORWARD, ParagraphBoundary, true, false);
364 return true;
365 }
366
executeDeleteToMark(Frame * frame,Event *,EditorCommandSource,const String &)367 static bool executeDeleteToMark(Frame* frame, Event*, EditorCommandSource, const String&)
368 {
369 RefPtr<Range> mark = frame->mark().toNormalizedRange();
370 if (mark) {
371 SelectionController* selection = frame->selection();
372 bool selected = selection->setSelectedRange(unionDOMRanges(mark.get(), frame->editor()->selectedRange().get()).get(), DOWNSTREAM, true);
373 ASSERT(selected);
374 if (!selected)
375 return false;
376 }
377 frame->editor()->performDelete();
378 frame->setMark(frame->selection()->selection());
379 return true;
380 }
381
executeDeleteWordBackward(Frame * frame,Event *,EditorCommandSource,const String &)382 static bool executeDeleteWordBackward(Frame* frame, Event*, EditorCommandSource, const String&)
383 {
384 frame->editor()->deleteWithDirection(SelectionController::BACKWARD, WordGranularity, true, false);
385 return true;
386 }
387
executeDeleteWordForward(Frame * frame,Event *,EditorCommandSource,const String &)388 static bool executeDeleteWordForward(Frame* frame, Event*, EditorCommandSource, const String&)
389 {
390 frame->editor()->deleteWithDirection(SelectionController::FORWARD, WordGranularity, true, false);
391 return true;
392 }
393
executeFindString(Frame * frame,Event *,EditorCommandSource,const String & value)394 static bool executeFindString(Frame* frame, Event*, EditorCommandSource, const String& value)
395 {
396 return frame->findString(value, true, false, true, false);
397 }
398
executeFontName(Frame * frame,Event *,EditorCommandSource source,const String & value)399 static bool executeFontName(Frame* frame, Event*, EditorCommandSource source, const String& value)
400 {
401 return executeApplyStyle(frame, source, EditActionSetFont, CSSPropertyFontFamily, value);
402 }
403
executeFontSize(Frame * frame,Event *,EditorCommandSource source,const String & value)404 static bool executeFontSize(Frame* frame, Event*, EditorCommandSource source, const String& value)
405 {
406 int size;
407 if (!HTMLFontElement::cssValueFromFontSizeNumber(value, size))
408 return false;
409 return executeApplyStyle(frame, source, EditActionChangeAttributes, CSSPropertyFontSize, size);
410 }
411
executeFontSizeDelta(Frame * frame,Event *,EditorCommandSource source,const String & value)412 static bool executeFontSizeDelta(Frame* frame, Event*, EditorCommandSource source, const String& value)
413 {
414 return executeApplyStyle(frame, source, EditActionChangeAttributes, CSSPropertyWebkitFontSizeDelta, value);
415 }
416
executeForeColor(Frame * frame,Event *,EditorCommandSource source,const String & value)417 static bool executeForeColor(Frame* frame, Event*, EditorCommandSource source, const String& value)
418 {
419 return executeApplyStyle(frame, source, EditActionSetColor, CSSPropertyColor, value);
420 }
421
executeFormatBlock(Frame * frame,Event *,EditorCommandSource,const String & value)422 static bool executeFormatBlock(Frame* frame, Event*, EditorCommandSource, const String& value)
423 {
424 String tagName = value.lower();
425 if (tagName[0] == '<' && tagName[tagName.length() - 1] == '>')
426 tagName = tagName.substring(1, tagName.length() - 2);
427 if (!validBlockTag(tagName))
428 return false;
429 applyCommand(FormatBlockCommand::create(frame->document(), tagName));
430 return true;
431 }
432
executeForwardDelete(Frame * frame,Event *,EditorCommandSource source,const String &)433 static bool executeForwardDelete(Frame* frame, Event*, EditorCommandSource source, const String&)
434 {
435 switch (source) {
436 case CommandFromMenuOrKeyBinding:
437 frame->editor()->deleteWithDirection(SelectionController::FORWARD, CharacterGranularity, false, true);
438 return true;
439 case CommandFromDOM:
440 case CommandFromDOMWithUserInterface:
441 // Doesn't scroll to make the selection visible, or modify the kill ring.
442 // ForwardDelete is not implemented in IE or Firefox, so this behavior is only needed for
443 // backward compatibility with ourselves, and for consistency with Delete.
444 TypingCommand::forwardDeleteKeyPressed(frame->document());
445 return true;
446 }
447 ASSERT_NOT_REACHED();
448 return false;
449 }
450
executeIgnoreSpelling(Frame * frame,Event *,EditorCommandSource,const String &)451 static bool executeIgnoreSpelling(Frame* frame, Event*, EditorCommandSource, const String&)
452 {
453 frame->editor()->ignoreSpelling();
454 return true;
455 }
456
executeIndent(Frame * frame,Event *,EditorCommandSource,const String &)457 static bool executeIndent(Frame* frame, Event*, EditorCommandSource, const String&)
458 {
459 applyCommand(IndentOutdentCommand::create(frame->document(), IndentOutdentCommand::Indent));
460 return true;
461 }
462
executeInsertBacktab(Frame * frame,Event * event,EditorCommandSource,const String &)463 static bool executeInsertBacktab(Frame* frame, Event* event, EditorCommandSource, const String&)
464 {
465 return targetFrame(frame, event)->eventHandler()->handleTextInputEvent("\t", event, false, true);
466 }
467
executeInsertHorizontalRule(Frame * frame,Event *,EditorCommandSource,const String & value)468 static bool executeInsertHorizontalRule(Frame* frame, Event*, EditorCommandSource, const String& value)
469 {
470 RefPtr<HTMLElement> hr = new HTMLElement(hrTag, frame->document());
471 if (!value.isEmpty())
472 hr->setId(value);
473 return executeInsertNode(frame, hr.release());
474 }
475
executeInsertHTML(Frame * frame,Event *,EditorCommandSource,const String & value)476 static bool executeInsertHTML(Frame* frame, Event*, EditorCommandSource, const String& value)
477 {
478 return executeInsertFragment(frame, createFragmentFromMarkup(frame->document(), value, ""));
479 }
480
executeInsertImage(Frame * frame,Event *,EditorCommandSource,const String & value)481 static bool executeInsertImage(Frame* frame, Event*, EditorCommandSource, const String& value)
482 {
483 // FIXME: If userInterface is true, we should display a dialog box and let the user choose a local image.
484 RefPtr<HTMLImageElement> image = new HTMLImageElement(imgTag, frame->document());
485 image->setSrc(value);
486 return executeInsertNode(frame, image.release());
487 }
488
executeInsertLineBreak(Frame * frame,Event * event,EditorCommandSource source,const String &)489 static bool executeInsertLineBreak(Frame* frame, Event* event, EditorCommandSource source, const String&)
490 {
491 switch (source) {
492 case CommandFromMenuOrKeyBinding:
493 return targetFrame(frame, event)->eventHandler()->handleTextInputEvent("\n", event, true);
494 case CommandFromDOM:
495 case CommandFromDOMWithUserInterface:
496 // Doesn't scroll to make the selection visible, or modify the kill ring.
497 // InsertLineBreak is not implemented in IE or Firefox, so this behavior is only needed for
498 // backward compatibility with ourselves, and for consistency with other commands.
499 TypingCommand::insertLineBreak(frame->document());
500 return true;
501 }
502 ASSERT_NOT_REACHED();
503 return false;
504 }
505
executeInsertNewline(Frame * frame,Event * event,EditorCommandSource,const String &)506 static bool executeInsertNewline(Frame* frame, Event* event, EditorCommandSource, const String&)
507 {
508 Frame* targetFrame = WebCore::targetFrame(frame, event);
509 return targetFrame->eventHandler()->handleTextInputEvent("\n", event, !targetFrame->editor()->canEditRichly());
510 }
511
executeInsertNewlineInQuotedContent(Frame * frame,Event *,EditorCommandSource,const String &)512 static bool executeInsertNewlineInQuotedContent(Frame* frame, Event*, EditorCommandSource, const String&)
513 {
514 TypingCommand::insertParagraphSeparatorInQuotedContent(frame->document());
515 return true;
516 }
517
executeInsertOrderedList(Frame * frame,Event *,EditorCommandSource,const String &)518 static bool executeInsertOrderedList(Frame* frame, Event*, EditorCommandSource, const String&)
519 {
520 applyCommand(InsertListCommand::create(frame->document(), InsertListCommand::OrderedList));
521 return true;
522 }
523
executeInsertParagraph(Frame * frame,Event *,EditorCommandSource,const String &)524 static bool executeInsertParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
525 {
526 TypingCommand::insertParagraphSeparator(frame->document());
527 return true;
528 }
529
executeInsertTab(Frame * frame,Event * event,EditorCommandSource,const String &)530 static bool executeInsertTab(Frame* frame, Event* event, EditorCommandSource, const String&)
531 {
532 return targetFrame(frame, event)->eventHandler()->handleTextInputEvent("\t", event, false, false);
533 }
534
executeInsertText(Frame * frame,Event *,EditorCommandSource,const String & value)535 static bool executeInsertText(Frame* frame, Event*, EditorCommandSource, const String& value)
536 {
537 TypingCommand::insertText(frame->document(), value);
538 return true;
539 }
540
executeInsertUnorderedList(Frame * frame,Event *,EditorCommandSource,const String &)541 static bool executeInsertUnorderedList(Frame* frame, Event*, EditorCommandSource, const String&)
542 {
543 applyCommand(InsertListCommand::create(frame->document(), InsertListCommand::UnorderedList));
544 return true;
545 }
546
executeJustifyCenter(Frame * frame,Event *,EditorCommandSource source,const String &)547 static bool executeJustifyCenter(Frame* frame, Event*, EditorCommandSource source, const String&)
548 {
549 return executeApplyParagraphStyle(frame, source, EditActionCenter, CSSPropertyTextAlign, "center");
550 }
551
executeJustifyFull(Frame * frame,Event *,EditorCommandSource source,const String &)552 static bool executeJustifyFull(Frame* frame, Event*, EditorCommandSource source, const String&)
553 {
554 return executeApplyParagraphStyle(frame, source, EditActionJustify, CSSPropertyTextAlign, "justify");
555 }
556
executeJustifyLeft(Frame * frame,Event *,EditorCommandSource source,const String &)557 static bool executeJustifyLeft(Frame* frame, Event*, EditorCommandSource source, const String&)
558 {
559 return executeApplyParagraphStyle(frame, source, EditActionAlignLeft, CSSPropertyTextAlign, "left");
560 }
561
executeJustifyRight(Frame * frame,Event *,EditorCommandSource source,const String &)562 static bool executeJustifyRight(Frame* frame, Event*, EditorCommandSource source, const String&)
563 {
564 return executeApplyParagraphStyle(frame, source, EditActionAlignRight, CSSPropertyTextAlign, "right");
565 }
566
executeMakeTextWritingDirectionLeftToRight(Frame * frame,Event *,EditorCommandSource,const String &)567 static bool executeMakeTextWritingDirectionLeftToRight(Frame* frame, Event*, EditorCommandSource, const String&)
568 {
569 RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
570 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed);
571 style->setProperty(CSSPropertyDirection, CSSValueLtr);
572 frame->editor()->applyStyle(style.get(), EditActionSetWritingDirection);
573 return true;
574 }
575
executeMakeTextWritingDirectionNatural(Frame * frame,Event *,EditorCommandSource,const String &)576 static bool executeMakeTextWritingDirectionNatural(Frame* frame, Event*, EditorCommandSource, const String&)
577 {
578 RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
579 style->setProperty(CSSPropertyUnicodeBidi, CSSValueNormal);
580 frame->editor()->applyStyle(style.get(), EditActionSetWritingDirection);
581 return true;
582 }
583
executeMakeTextWritingDirectionRightToLeft(Frame * frame,Event *,EditorCommandSource,const String &)584 static bool executeMakeTextWritingDirectionRightToLeft(Frame* frame, Event*, EditorCommandSource, const String&)
585 {
586 RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
587 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed);
588 style->setProperty(CSSPropertyDirection, CSSValueRtl);
589 frame->editor()->applyStyle(style.get(), EditActionSetWritingDirection);
590 return true;
591 }
592
executeMoveBackward(Frame * frame,Event *,EditorCommandSource,const String &)593 static bool executeMoveBackward(Frame* frame, Event*, EditorCommandSource, const String&)
594 {
595 frame->selection()->modify(SelectionController::MOVE, SelectionController::BACKWARD, CharacterGranularity, true);
596 return true;
597 }
598
executeMoveBackwardAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)599 static bool executeMoveBackwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
600 {
601 frame->selection()->modify(SelectionController::EXTEND, SelectionController::BACKWARD, CharacterGranularity, true);
602 return true;
603 }
604
executeMoveDown(Frame * frame,Event *,EditorCommandSource,const String &)605 static bool executeMoveDown(Frame* frame, Event*, EditorCommandSource, const String&)
606 {
607 frame->selection()->modify(SelectionController::MOVE, SelectionController::FORWARD, LineGranularity, true);
608 return true;
609 }
610
executeMoveDownAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)611 static bool executeMoveDownAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
612 {
613 frame->selection()->modify(SelectionController::EXTEND, SelectionController::FORWARD, LineGranularity, true);
614 return true;
615 }
616
executeMoveForward(Frame * frame,Event *,EditorCommandSource,const String &)617 static bool executeMoveForward(Frame* frame, Event*, EditorCommandSource, const String&)
618 {
619 frame->selection()->modify(SelectionController::MOVE, SelectionController::FORWARD, CharacterGranularity, true);
620 return true;
621 }
622
executeMoveForwardAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)623 static bool executeMoveForwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
624 {
625 frame->selection()->modify(SelectionController::EXTEND, SelectionController::FORWARD, CharacterGranularity, true);
626 return true;
627 }
628
executeMoveLeft(Frame * frame,Event *,EditorCommandSource,const String &)629 static bool executeMoveLeft(Frame* frame, Event*, EditorCommandSource, const String&)
630 {
631 frame->selection()->modify(SelectionController::MOVE, SelectionController::LEFT, CharacterGranularity, true);
632 return true;
633 }
634
executeMoveLeftAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)635 static bool executeMoveLeftAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
636 {
637 frame->selection()->modify(SelectionController::EXTEND, SelectionController::LEFT, CharacterGranularity, true);
638 return true;
639 }
640
executeMovePageDown(Frame * frame,Event *,EditorCommandSource,const String &)641 static bool executeMovePageDown(Frame* frame, Event*, EditorCommandSource, const String&)
642 {
643 int distance = verticalScrollDistance(frame);
644 if (!distance)
645 return false;
646 return frame->selection()->modify(SelectionController::MOVE, distance, true);
647 }
648
executeMovePageDownAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)649 static bool executeMovePageDownAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
650 {
651 int distance = verticalScrollDistance(frame);
652 if (!distance)
653 return false;
654 return frame->selection()->modify(SelectionController::EXTEND, distance, true);
655 }
656
executeMovePageUp(Frame * frame,Event *,EditorCommandSource,const String &)657 static bool executeMovePageUp(Frame* frame, Event*, EditorCommandSource, const String&)
658 {
659 int distance = verticalScrollDistance(frame);
660 if (!distance)
661 return false;
662 return frame->selection()->modify(SelectionController::MOVE, -distance, true);
663 }
664
executeMovePageUpAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)665 static bool executeMovePageUpAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
666 {
667 int distance = verticalScrollDistance(frame);
668 if (!distance)
669 return false;
670 return frame->selection()->modify(SelectionController::EXTEND, -distance, true);
671 }
672
executeMoveRight(Frame * frame,Event *,EditorCommandSource,const String &)673 static bool executeMoveRight(Frame* frame, Event*, EditorCommandSource, const String&)
674 {
675 frame->selection()->modify(SelectionController::MOVE, SelectionController::RIGHT, CharacterGranularity, true);
676 return true;
677 }
678
executeMoveRightAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)679 static bool executeMoveRightAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
680 {
681 frame->selection()->modify(SelectionController::EXTEND, SelectionController::RIGHT, CharacterGranularity, true);
682 return true;
683 }
684
executeMoveToBeginningOfDocument(Frame * frame,Event *,EditorCommandSource,const String &)685 static bool executeMoveToBeginningOfDocument(Frame* frame, Event*, EditorCommandSource, const String&)
686 {
687 frame->selection()->modify(SelectionController::MOVE, SelectionController::BACKWARD, DocumentBoundary, true);
688 return true;
689 }
690
executeMoveToBeginningOfDocumentAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)691 static bool executeMoveToBeginningOfDocumentAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
692 {
693 frame->selection()->modify(SelectionController::EXTEND, SelectionController::BACKWARD, DocumentBoundary, true);
694 return true;
695 }
696
executeMoveToBeginningOfLine(Frame * frame,Event *,EditorCommandSource,const String &)697 static bool executeMoveToBeginningOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
698 {
699 frame->selection()->modify(SelectionController::MOVE, SelectionController::BACKWARD, LineBoundary, true);
700 return true;
701 }
702
executeMoveToBeginningOfLineAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)703 static bool executeMoveToBeginningOfLineAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
704 {
705 frame->selection()->modify(SelectionController::EXTEND, SelectionController::BACKWARD, LineBoundary, true);
706 return true;
707 }
708
executeMoveToBeginningOfParagraph(Frame * frame,Event *,EditorCommandSource,const String &)709 static bool executeMoveToBeginningOfParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
710 {
711 frame->selection()->modify(SelectionController::MOVE, SelectionController::BACKWARD, ParagraphBoundary, true);
712 return true;
713 }
714
executeMoveToBeginningOfParagraphAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)715 static bool executeMoveToBeginningOfParagraphAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
716 {
717 frame->selection()->modify(SelectionController::EXTEND, SelectionController::BACKWARD, ParagraphBoundary, true);
718 return true;
719 }
720
executeMoveToBeginningOfSentence(Frame * frame,Event *,EditorCommandSource,const String &)721 static bool executeMoveToBeginningOfSentence(Frame* frame, Event*, EditorCommandSource, const String&)
722 {
723 frame->selection()->modify(SelectionController::MOVE, SelectionController::BACKWARD, SentenceBoundary, true);
724 return true;
725 }
726
executeMoveToBeginningOfSentenceAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)727 static bool executeMoveToBeginningOfSentenceAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
728 {
729 frame->selection()->modify(SelectionController::EXTEND, SelectionController::BACKWARD, SentenceBoundary, true);
730 return true;
731 }
732
executeMoveToEndOfDocument(Frame * frame,Event *,EditorCommandSource,const String &)733 static bool executeMoveToEndOfDocument(Frame* frame, Event*, EditorCommandSource, const String&)
734 {
735 frame->selection()->modify(SelectionController::MOVE, SelectionController::FORWARD, DocumentBoundary, true);
736 return true;
737 }
738
executeMoveToEndOfDocumentAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)739 static bool executeMoveToEndOfDocumentAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
740 {
741 frame->selection()->modify(SelectionController::EXTEND, SelectionController::FORWARD, DocumentBoundary, true);
742 return true;
743 }
744
executeMoveToEndOfSentence(Frame * frame,Event *,EditorCommandSource,const String &)745 static bool executeMoveToEndOfSentence(Frame* frame, Event*, EditorCommandSource, const String&)
746 {
747 frame->selection()->modify(SelectionController::MOVE, SelectionController::FORWARD, SentenceBoundary, true);
748 return true;
749 }
750
executeMoveToEndOfSentenceAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)751 static bool executeMoveToEndOfSentenceAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
752 {
753 frame->selection()->modify(SelectionController::EXTEND, SelectionController::FORWARD, SentenceBoundary, true);
754 return true;
755 }
756
executeMoveToEndOfLine(Frame * frame,Event *,EditorCommandSource,const String &)757 static bool executeMoveToEndOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
758 {
759 frame->selection()->modify(SelectionController::MOVE, SelectionController::FORWARD, LineBoundary, true);
760 return true;
761 }
762
executeMoveToEndOfLineAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)763 static bool executeMoveToEndOfLineAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
764 {
765 frame->selection()->modify(SelectionController::EXTEND, SelectionController::FORWARD, LineBoundary, true);
766 return true;
767 }
768
executeMoveToEndOfParagraph(Frame * frame,Event *,EditorCommandSource,const String &)769 static bool executeMoveToEndOfParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
770 {
771 frame->selection()->modify(SelectionController::MOVE, SelectionController::FORWARD, ParagraphBoundary, true);
772 return true;
773 }
774
executeMoveToEndOfParagraphAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)775 static bool executeMoveToEndOfParagraphAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
776 {
777 frame->selection()->modify(SelectionController::EXTEND, SelectionController::FORWARD, ParagraphBoundary, true);
778 return true;
779 }
780
executeMoveParagraphBackwardAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)781 static bool executeMoveParagraphBackwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
782 {
783 frame->selection()->modify(SelectionController::EXTEND, SelectionController::BACKWARD, ParagraphGranularity, true);
784 return true;
785 }
786
executeMoveParagraphForwardAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)787 static bool executeMoveParagraphForwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
788 {
789 frame->selection()->modify(SelectionController::EXTEND, SelectionController::FORWARD, ParagraphGranularity, true);
790 return true;
791 }
792
executeMoveUp(Frame * frame,Event *,EditorCommandSource,const String &)793 static bool executeMoveUp(Frame* frame, Event*, EditorCommandSource, const String&)
794 {
795 frame->selection()->modify(SelectionController::MOVE, SelectionController::BACKWARD, LineGranularity, true);
796 return true;
797 }
798
executeMoveUpAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)799 static bool executeMoveUpAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
800 {
801 frame->selection()->modify(SelectionController::EXTEND, SelectionController::BACKWARD, LineGranularity, true);
802 return true;
803 }
804
executeMoveWordBackward(Frame * frame,Event *,EditorCommandSource,const String &)805 static bool executeMoveWordBackward(Frame* frame, Event*, EditorCommandSource, const String&)
806 {
807 frame->selection()->modify(SelectionController::MOVE, SelectionController::BACKWARD, WordGranularity, true);
808 return true;
809 }
810
executeMoveWordBackwardAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)811 static bool executeMoveWordBackwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
812 {
813 frame->selection()->modify(SelectionController::EXTEND, SelectionController::BACKWARD, WordGranularity, true);
814 return true;
815 }
816
executeMoveWordForward(Frame * frame,Event *,EditorCommandSource,const String &)817 static bool executeMoveWordForward(Frame* frame, Event*, EditorCommandSource, const String&)
818 {
819 frame->selection()->modify(SelectionController::MOVE, SelectionController::FORWARD, WordGranularity, true);
820 return true;
821 }
822
executeMoveWordForwardAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)823 static bool executeMoveWordForwardAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
824 {
825 frame->selection()->modify(SelectionController::EXTEND, SelectionController::FORWARD, WordGranularity, true);
826 return true;
827 }
828
executeMoveWordLeft(Frame * frame,Event *,EditorCommandSource,const String &)829 static bool executeMoveWordLeft(Frame* frame, Event*, EditorCommandSource, const String&)
830 {
831 frame->selection()->modify(SelectionController::MOVE, SelectionController::LEFT, WordGranularity, true);
832 return true;
833 }
834
executeMoveWordLeftAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)835 static bool executeMoveWordLeftAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
836 {
837 frame->selection()->modify(SelectionController::EXTEND, SelectionController::LEFT, WordGranularity, true);
838 return true;
839 }
840
executeMoveWordRight(Frame * frame,Event *,EditorCommandSource,const String &)841 static bool executeMoveWordRight(Frame* frame, Event*, EditorCommandSource, const String&)
842 {
843 frame->selection()->modify(SelectionController::MOVE, SelectionController::RIGHT, WordGranularity, true);
844 return true;
845 }
846
executeMoveWordRightAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)847 static bool executeMoveWordRightAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
848 {
849 frame->selection()->modify(SelectionController::EXTEND, SelectionController::RIGHT, WordGranularity, true);
850 return true;
851 }
852
executeMoveToLeftEndOfLine(Frame * frame,Event *,EditorCommandSource,const String &)853 static bool executeMoveToLeftEndOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
854 {
855 frame->selection()->modify(SelectionController::MOVE, SelectionController::LEFT, LineBoundary, true);
856 return true;
857 }
858
executeMoveToLeftEndOfLineAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)859 static bool executeMoveToLeftEndOfLineAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
860 {
861 frame->selection()->modify(SelectionController::EXTEND, SelectionController::LEFT, LineBoundary, true);
862 return true;
863 }
864
executeMoveToRightEndOfLine(Frame * frame,Event *,EditorCommandSource,const String &)865 static bool executeMoveToRightEndOfLine(Frame* frame, Event*, EditorCommandSource, const String&)
866 {
867 frame->selection()->modify(SelectionController::MOVE, SelectionController::RIGHT, LineBoundary, true);
868 return true;
869 }
870
executeMoveToRightEndOfLineAndModifySelection(Frame * frame,Event *,EditorCommandSource,const String &)871 static bool executeMoveToRightEndOfLineAndModifySelection(Frame* frame, Event*, EditorCommandSource, const String&)
872 {
873 frame->selection()->modify(SelectionController::EXTEND, SelectionController::RIGHT, LineBoundary, true);
874 return true;
875 }
876
executeOutdent(Frame * frame,Event *,EditorCommandSource,const String &)877 static bool executeOutdent(Frame* frame, Event*, EditorCommandSource, const String&)
878 {
879 applyCommand(IndentOutdentCommand::create(frame->document(), IndentOutdentCommand::Outdent));
880 return true;
881 }
882
executePaste(Frame * frame,Event *,EditorCommandSource,const String &)883 static bool executePaste(Frame* frame, Event*, EditorCommandSource, const String&)
884 {
885 frame->editor()->paste();
886 return true;
887 }
888
executePasteAndMatchStyle(Frame * frame,Event *,EditorCommandSource,const String &)889 static bool executePasteAndMatchStyle(Frame* frame, Event*, EditorCommandSource, const String&)
890 {
891 frame->editor()->pasteAsPlainText();
892 return true;
893 }
894
executePrint(Frame * frame,Event *,EditorCommandSource,const String &)895 static bool executePrint(Frame* frame, Event*, EditorCommandSource, const String&)
896 {
897 Page* page = frame->page();
898 if (!page)
899 return false;
900 page->chrome()->print(frame);
901 return true;
902 }
903
executeRedo(Frame * frame,Event *,EditorCommandSource,const String &)904 static bool executeRedo(Frame* frame, Event*, EditorCommandSource, const String&)
905 {
906 frame->editor()->redo();
907 return true;
908 }
909
executeRemoveFormat(Frame * frame,Event *,EditorCommandSource,const String &)910 static bool executeRemoveFormat(Frame* frame, Event*, EditorCommandSource, const String&)
911 {
912 frame->editor()->removeFormattingAndStyle();
913 return true;
914 }
915
executeSelectAll(Frame * frame,Event *,EditorCommandSource,const String &)916 static bool executeSelectAll(Frame* frame, Event*, EditorCommandSource, const String&)
917 {
918 frame->selection()->selectAll();
919 return true;
920 }
921
executeSelectLine(Frame * frame,Event *,EditorCommandSource,const String &)922 static bool executeSelectLine(Frame* frame, Event*, EditorCommandSource, const String&)
923 {
924 return expandSelectionToGranularity(frame, LineGranularity);
925 }
926
executeSelectParagraph(Frame * frame,Event *,EditorCommandSource,const String &)927 static bool executeSelectParagraph(Frame* frame, Event*, EditorCommandSource, const String&)
928 {
929 return expandSelectionToGranularity(frame, ParagraphGranularity);
930 }
931
executeSelectSentence(Frame * frame,Event *,EditorCommandSource,const String &)932 static bool executeSelectSentence(Frame* frame, Event*, EditorCommandSource, const String&)
933 {
934 return expandSelectionToGranularity(frame, SentenceGranularity);
935 }
936
executeSelectToMark(Frame * frame,Event *,EditorCommandSource,const String &)937 static bool executeSelectToMark(Frame* frame, Event*, EditorCommandSource, const String&)
938 {
939 RefPtr<Range> mark = frame->mark().toNormalizedRange();
940 RefPtr<Range> selection = frame->editor()->selectedRange();
941 if (!mark || !selection) {
942 systemBeep();
943 return false;
944 }
945 frame->selection()->setSelectedRange(unionDOMRanges(mark.get(), selection.get()).get(), DOWNSTREAM, true);
946 return true;
947 }
948
executeSelectWord(Frame * frame,Event *,EditorCommandSource,const String &)949 static bool executeSelectWord(Frame* frame, Event*, EditorCommandSource, const String&)
950 {
951 return expandSelectionToGranularity(frame, WordGranularity);
952 }
953
executeSetMark(Frame * frame,Event *,EditorCommandSource,const String &)954 static bool executeSetMark(Frame* frame, Event*, EditorCommandSource, const String&)
955 {
956 frame->setMark(frame->selection()->selection());
957 return true;
958 }
959
executeStrikethrough(Frame * frame,Event *,EditorCommandSource source,const String &)960 static bool executeStrikethrough(Frame* frame, Event*, EditorCommandSource source, const String&)
961 {
962 RefPtr<CSSPrimitiveValue> lineThrough = CSSPrimitiveValue::createIdentifier(CSSValueLineThrough);
963 return executeToggleStyleInList(frame, source, EditActionUnderline, CSSPropertyWebkitTextDecorationsInEffect, lineThrough.get());
964 }
965
executeStyleWithCSS(Frame * frame,Event *,EditorCommandSource,const String & value)966 static bool executeStyleWithCSS(Frame* frame, Event*, EditorCommandSource, const String& value)
967 {
968 if (value != "false" && value != "true")
969 return false;
970
971 frame->editor()->setShouldStyleWithCSS(value == "true" ? true : false);
972 return true;
973 }
974
executeSubscript(Frame * frame,Event *,EditorCommandSource source,const String &)975 static bool executeSubscript(Frame* frame, Event*, EditorCommandSource source, const String&)
976 {
977 return executeToggleStyle(frame, source, EditActionSubscript, CSSPropertyVerticalAlign, "baseline", "sub");
978 }
979
executeSuperscript(Frame * frame,Event *,EditorCommandSource source,const String &)980 static bool executeSuperscript(Frame* frame, Event*, EditorCommandSource source, const String&)
981 {
982 return executeToggleStyle(frame, source, EditActionSuperscript, CSSPropertyVerticalAlign, "baseline", "super");
983 }
984
executeSwapWithMark(Frame * frame,Event *,EditorCommandSource,const String &)985 static bool executeSwapWithMark(Frame* frame, Event*, EditorCommandSource, const String&)
986 {
987 const VisibleSelection& mark = frame->mark();
988 const VisibleSelection& selection = frame->selection()->selection();
989 if (mark.isNone() || selection.isNone()) {
990 systemBeep();
991 return false;
992 }
993 frame->selection()->setSelection(mark);
994 frame->setMark(selection);
995 return true;
996 }
997
executeToggleBold(Frame * frame,Event *,EditorCommandSource source,const String &)998 static bool executeToggleBold(Frame* frame, Event*, EditorCommandSource source, const String&)
999 {
1000 return executeToggleStyle(frame, source, EditActionChangeAttributes, CSSPropertyFontWeight, "normal", "bold");
1001 }
1002
executeToggleItalic(Frame * frame,Event *,EditorCommandSource source,const String &)1003 static bool executeToggleItalic(Frame* frame, Event*, EditorCommandSource source, const String&)
1004 {
1005 return executeToggleStyle(frame, source, EditActionChangeAttributes, CSSPropertyFontStyle, "normal", "italic");
1006 }
1007
executeTranspose(Frame * frame,Event *,EditorCommandSource,const String &)1008 static bool executeTranspose(Frame* frame, Event*, EditorCommandSource, const String&)
1009 {
1010 frame->editor()->transpose();
1011 return true;
1012 }
1013
executeUnderline(Frame * frame,Event *,EditorCommandSource source,const String &)1014 static bool executeUnderline(Frame* frame, Event*, EditorCommandSource source, const String&)
1015 {
1016 RefPtr<CSSPrimitiveValue> underline = CSSPrimitiveValue::createIdentifier(CSSValueUnderline);
1017 return executeToggleStyleInList(frame, source, EditActionUnderline, CSSPropertyWebkitTextDecorationsInEffect, underline.get());
1018 }
1019
executeUndo(Frame * frame,Event *,EditorCommandSource,const String &)1020 static bool executeUndo(Frame* frame, Event*, EditorCommandSource, const String&)
1021 {
1022 frame->editor()->undo();
1023 return true;
1024 }
1025
executeUnlink(Frame * frame,Event *,EditorCommandSource,const String &)1026 static bool executeUnlink(Frame* frame, Event*, EditorCommandSource, const String&)
1027 {
1028 applyCommand(UnlinkCommand::create(frame->document()));
1029 return true;
1030 }
1031
executeUnscript(Frame * frame,Event *,EditorCommandSource source,const String &)1032 static bool executeUnscript(Frame* frame, Event*, EditorCommandSource source, const String&)
1033 {
1034 return executeApplyStyle(frame, source, EditActionUnscript, CSSPropertyVerticalAlign, "baseline");
1035 }
1036
executeUnselect(Frame * frame,Event *,EditorCommandSource,const String &)1037 static bool executeUnselect(Frame* frame, Event*, EditorCommandSource, const String&)
1038 {
1039 frame->selection()->clear();
1040 return true;
1041 }
1042
executeYank(Frame * frame,Event *,EditorCommandSource,const String &)1043 static bool executeYank(Frame* frame, Event*, EditorCommandSource, const String&)
1044 {
1045 frame->editor()->insertTextWithoutSendingTextEvent(frame->editor()->yankFromKillRing(), false, 0);
1046 frame->editor()->setKillRingToYankedState();
1047 return true;
1048 }
1049
executeYankAndSelect(Frame * frame,Event *,EditorCommandSource,const String &)1050 static bool executeYankAndSelect(Frame* frame, Event*, EditorCommandSource, const String&)
1051 {
1052 frame->editor()->insertTextWithoutSendingTextEvent(frame->editor()->yankFromKillRing(), true, 0);
1053 frame->editor()->setKillRingToYankedState();
1054 return true;
1055 }
1056
1057 // Supported functions
1058
supported(Frame *,EditorCommandSource)1059 static bool supported(Frame*, EditorCommandSource)
1060 {
1061 return true;
1062 }
1063
supportedFromMenuOrKeyBinding(Frame *,EditorCommandSource source)1064 static bool supportedFromMenuOrKeyBinding(Frame*, EditorCommandSource source)
1065 {
1066 return source == CommandFromMenuOrKeyBinding;
1067 }
1068
supportedPaste(Frame * frame,EditorCommandSource source)1069 static bool supportedPaste(Frame* frame, EditorCommandSource source)
1070 {
1071 switch (source) {
1072 case CommandFromMenuOrKeyBinding:
1073 return true;
1074 case CommandFromDOM:
1075 case CommandFromDOMWithUserInterface: {
1076 Settings* settings = frame ? frame->settings() : 0;
1077 return settings && settings->isDOMPasteAllowed();
1078 }
1079 }
1080 ASSERT_NOT_REACHED();
1081 return false;
1082 }
1083
1084 // Enabled functions
1085
enabled(Frame *,Event *,EditorCommandSource)1086 static bool enabled(Frame*, Event*, EditorCommandSource)
1087 {
1088 return true;
1089 }
1090
enabledVisibleSelection(Frame * frame,Event * event,EditorCommandSource)1091 static bool enabledVisibleSelection(Frame* frame, Event* event, EditorCommandSource)
1092 {
1093 // The term "visible" here includes a caret in editable text or a range in any text.
1094 const VisibleSelection& selection = frame->editor()->selectionForCommand(event);
1095 return (selection.isCaret() && selection.isContentEditable()) || selection.isRange();
1096 }
1097
enabledVisibleSelectionAndMark(Frame * frame,Event * event,EditorCommandSource)1098 static bool enabledVisibleSelectionAndMark(Frame* frame, Event* event, EditorCommandSource)
1099 {
1100 const VisibleSelection& selection = frame->editor()->selectionForCommand(event);
1101 return ((selection.isCaret() && selection.isContentEditable()) || selection.isRange())
1102 && frame->mark().isCaretOrRange();
1103 }
1104
enableCaretInEditableText(Frame * frame,Event * event,EditorCommandSource)1105 static bool enableCaretInEditableText(Frame* frame, Event* event, EditorCommandSource)
1106 {
1107 const VisibleSelection& selection = frame->editor()->selectionForCommand(event);
1108 return selection.isCaret() && selection.isContentEditable();
1109 }
1110
enabledCopy(Frame * frame,Event *,EditorCommandSource)1111 static bool enabledCopy(Frame* frame, Event*, EditorCommandSource)
1112 {
1113 return frame->editor()->canDHTMLCopy() || frame->editor()->canCopy();
1114 }
1115
enabledCut(Frame * frame,Event *,EditorCommandSource)1116 static bool enabledCut(Frame* frame, Event*, EditorCommandSource)
1117 {
1118 return frame->editor()->canDHTMLCut() || frame->editor()->canCut();
1119 }
1120
enabledDelete(Frame * frame,Event * event,EditorCommandSource source)1121 static bool enabledDelete(Frame* frame, Event* event, EditorCommandSource source)
1122 {
1123 switch (source) {
1124 case CommandFromMenuOrKeyBinding:
1125 // "Delete" from menu only affects selected range, just like Cut but without affecting pasteboard
1126 return frame->editor()->canDHTMLCut() || frame->editor()->canCut();
1127 case CommandFromDOM:
1128 case CommandFromDOMWithUserInterface:
1129 // "Delete" from DOM is like delete/backspace keypress, affects selected range if non-empty,
1130 // otherwise removes a character
1131 return frame->editor()->selectionForCommand(event).isContentEditable();
1132 }
1133 ASSERT_NOT_REACHED();
1134 return false;
1135 }
1136
enabledInEditableText(Frame * frame,Event * event,EditorCommandSource)1137 static bool enabledInEditableText(Frame* frame, Event* event, EditorCommandSource)
1138 {
1139 return frame->editor()->selectionForCommand(event).isContentEditable();
1140 }
1141
enabledInRichlyEditableText(Frame * frame,Event *,EditorCommandSource)1142 static bool enabledInRichlyEditableText(Frame* frame, Event*, EditorCommandSource)
1143 {
1144 return frame->selection()->isCaretOrRange() && frame->selection()->isContentRichlyEditable();
1145 }
1146
enabledPaste(Frame * frame,Event *,EditorCommandSource)1147 static bool enabledPaste(Frame* frame, Event*, EditorCommandSource)
1148 {
1149 return frame->editor()->canPaste();
1150 }
1151
enabledRangeInEditableText(Frame * frame,Event *,EditorCommandSource)1152 static bool enabledRangeInEditableText(Frame* frame, Event*, EditorCommandSource)
1153 {
1154 return frame->selection()->isRange() && frame->selection()->isContentEditable();
1155 }
1156
enabledRangeInRichlyEditableText(Frame * frame,Event *,EditorCommandSource)1157 static bool enabledRangeInRichlyEditableText(Frame* frame, Event*, EditorCommandSource)
1158 {
1159 return frame->selection()->isRange() && frame->selection()->isContentRichlyEditable();
1160 }
1161
enabledRedo(Frame * frame,Event *,EditorCommandSource)1162 static bool enabledRedo(Frame* frame, Event*, EditorCommandSource)
1163 {
1164 return frame->editor()->canRedo();
1165 }
1166
enabledUndo(Frame * frame,Event *,EditorCommandSource)1167 static bool enabledUndo(Frame* frame, Event*, EditorCommandSource)
1168 {
1169 return frame->editor()->canUndo();
1170 }
1171
1172 // State functions
1173
stateNone(Frame *,Event *)1174 static TriState stateNone(Frame*, Event*)
1175 {
1176 return FalseTriState;
1177 }
1178
stateBold(Frame * frame,Event *)1179 static TriState stateBold(Frame* frame, Event*)
1180 {
1181 return stateStyle(frame, CSSPropertyFontWeight, "bold");
1182 }
1183
stateItalic(Frame * frame,Event *)1184 static TriState stateItalic(Frame* frame, Event*)
1185 {
1186 return stateStyle(frame, CSSPropertyFontStyle, "italic");
1187 }
1188
stateOrderedList(Frame * frame,Event *)1189 static TriState stateOrderedList(Frame* frame, Event*)
1190 {
1191 return frame->editor()->selectionOrderedListState();
1192 }
1193
stateStrikethrough(Frame * frame,Event *)1194 static TriState stateStrikethrough(Frame* frame, Event*)
1195 {
1196 return stateStyle(frame, CSSPropertyTextDecoration, "line-through");
1197 }
1198
stateStyleWithCSS(Frame * frame,Event *)1199 static TriState stateStyleWithCSS(Frame* frame, Event*)
1200 {
1201 return frame->editor()->shouldStyleWithCSS() ? TrueTriState : FalseTriState;
1202 }
1203
stateSubscript(Frame * frame,Event *)1204 static TriState stateSubscript(Frame* frame, Event*)
1205 {
1206 return stateStyle(frame, CSSPropertyVerticalAlign, "sub");
1207 }
1208
stateSuperscript(Frame * frame,Event *)1209 static TriState stateSuperscript(Frame* frame, Event*)
1210 {
1211 return stateStyle(frame, CSSPropertyVerticalAlign, "super");
1212 }
1213
stateTextWritingDirectionLeftToRight(Frame * frame,Event *)1214 static TriState stateTextWritingDirectionLeftToRight(Frame* frame, Event*)
1215 {
1216 return stateTextWritingDirection(frame, LeftToRightWritingDirection);
1217 }
1218
stateTextWritingDirectionNatural(Frame * frame,Event *)1219 static TriState stateTextWritingDirectionNatural(Frame* frame, Event*)
1220 {
1221 return stateTextWritingDirection(frame, NaturalWritingDirection);
1222 }
1223
stateTextWritingDirectionRightToLeft(Frame * frame,Event *)1224 static TriState stateTextWritingDirectionRightToLeft(Frame* frame, Event*)
1225 {
1226 return stateTextWritingDirection(frame, RightToLeftWritingDirection);
1227 }
1228
stateUnderline(Frame * frame,Event *)1229 static TriState stateUnderline(Frame* frame, Event*)
1230 {
1231 return stateStyle(frame, CSSPropertyTextDecoration, "underline");
1232 }
1233
stateUnorderedList(Frame * frame,Event *)1234 static TriState stateUnorderedList(Frame* frame, Event*)
1235 {
1236 return frame->editor()->selectionUnorderedListState();
1237 }
1238
1239 // Value functions
1240
valueNull(Frame *,Event *)1241 static String valueNull(Frame*, Event*)
1242 {
1243 return String();
1244 }
1245
valueBackColor(Frame * frame,Event *)1246 static String valueBackColor(Frame* frame, Event*)
1247 {
1248 return valueStyle(frame, CSSPropertyBackgroundColor);
1249 }
1250
valueFontName(Frame * frame,Event *)1251 static String valueFontName(Frame* frame, Event*)
1252 {
1253 return valueStyle(frame, CSSPropertyFontFamily);
1254 }
1255
valueFontSize(Frame * frame,Event *)1256 static String valueFontSize(Frame* frame, Event*)
1257 {
1258 return valueStyle(frame, CSSPropertyFontSize);
1259 }
1260
valueFontSizeDelta(Frame * frame,Event *)1261 static String valueFontSizeDelta(Frame* frame, Event*)
1262 {
1263 return valueStyle(frame, CSSPropertyWebkitFontSizeDelta);
1264 }
1265
valueForeColor(Frame * frame,Event *)1266 static String valueForeColor(Frame* frame, Event*)
1267 {
1268 return valueStyle(frame, CSSPropertyColor);
1269 }
1270
1271 // Map of functions
1272
createCommandMap()1273 static const CommandMap& createCommandMap()
1274 {
1275 struct CommandEntry { const char* name; EditorInternalCommand command; };
1276
1277 static const CommandEntry commands[] = {
1278 { "AlignCenter", { executeJustifyCenter, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1279 { "AlignJustified", { executeJustifyFull, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1280 { "AlignLeft", { executeJustifyLeft, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1281 { "AlignRight", { executeJustifyRight, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1282 { "BackColor", { executeBackColor, supported, enabledInRichlyEditableText, stateNone, valueBackColor, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1283 { "BackwardDelete", { executeDeleteBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, // FIXME: remove BackwardDelete when Safari for Windows stops using it.
1284 { "Bold", { executeToggleBold, supported, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1285 { "Copy", { executeCopy, supported, enabledCopy, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1286 { "CreateLink", { executeCreateLink, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1287 { "Cut", { executeCut, supported, enabledCut, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1288 { "Delete", { executeDelete, supported, enabledDelete, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1289 { "DeleteBackward", { executeDeleteBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1290 { "DeleteBackwardByDecomposingPreviousCharacter", { executeDeleteBackwardByDecomposingPreviousCharacter, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1291 { "DeleteForward", { executeDeleteForward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1292 { "DeleteToBeginningOfLine", { executeDeleteToBeginningOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1293 { "DeleteToBeginningOfParagraph", { executeDeleteToBeginningOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1294 { "DeleteToEndOfLine", { executeDeleteToEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1295 { "DeleteToEndOfParagraph", { executeDeleteToEndOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1296 { "DeleteToMark", { executeDeleteToMark, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1297 { "DeleteWordBackward", { executeDeleteWordBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1298 { "DeleteWordForward", { executeDeleteWordForward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1299 { "FindString", { executeFindString, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1300 { "FontName", { executeFontName, supported, enabledInEditableText, stateNone, valueFontName, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1301 { "FontSize", { executeFontSize, supported, enabledInEditableText, stateNone, valueFontSize, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1302 { "FontSizeDelta", { executeFontSizeDelta, supported, enabledInEditableText, stateNone, valueFontSizeDelta, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1303 { "ForeColor", { executeForeColor, supported, enabledInRichlyEditableText, stateNone, valueForeColor, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1304 { "FormatBlock", { executeFormatBlock, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1305 { "ForwardDelete", { executeForwardDelete, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1306 { "HiliteColor", { executeBackColor, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1307 { "IgnoreSpelling", { executeIgnoreSpelling, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1308 { "Indent", { executeIndent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1309 { "InsertBacktab", { executeInsertBacktab, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1310 { "InsertHTML", { executeInsertHTML, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1311 { "InsertHorizontalRule", { executeInsertHorizontalRule, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1312 { "InsertImage", { executeInsertImage, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1313 { "InsertLineBreak", { executeInsertLineBreak, supported, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1314 { "InsertNewline", { executeInsertNewline, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1315 { "InsertNewlineInQuotedContent", { executeInsertNewlineInQuotedContent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1316 { "InsertOrderedList", { executeInsertOrderedList, supported, enabledInRichlyEditableText, stateOrderedList, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1317 { "InsertParagraph", { executeInsertParagraph, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1318 { "InsertTab", { executeInsertTab, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1319 { "InsertText", { executeInsertText, supported, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } },
1320 { "InsertUnorderedList", { executeInsertUnorderedList, supported, enabledInRichlyEditableText, stateUnorderedList, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1321 { "Italic", { executeToggleItalic, supported, enabledInRichlyEditableText, stateItalic, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1322 { "JustifyCenter", { executeJustifyCenter, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1323 { "JustifyFull", { executeJustifyFull, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1324 { "JustifyLeft", { executeJustifyLeft, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1325 { "JustifyNone", { executeJustifyLeft, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1326 { "JustifyRight", { executeJustifyRight, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1327 { "MakeTextWritingDirectionLeftToRight", { executeMakeTextWritingDirectionLeftToRight, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionLeftToRight, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1328 { "MakeTextWritingDirectionNatural", { executeMakeTextWritingDirectionNatural, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionNatural, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1329 { "MakeTextWritingDirectionRightToLeft", { executeMakeTextWritingDirectionRightToLeft, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionRightToLeft, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1330 { "MoveBackward", { executeMoveBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1331 { "MoveBackwardAndModifySelection", { executeMoveBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1332 { "MoveDown", { executeMoveDown, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1333 { "MoveDownAndModifySelection", { executeMoveDownAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1334 { "MoveForward", { executeMoveForward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1335 { "MoveForwardAndModifySelection", { executeMoveForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1336 { "MoveLeft", { executeMoveLeft, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1337 { "MoveLeftAndModifySelection", { executeMoveLeftAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1338 { "MovePageDown", { executeMovePageDown, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1339 { "MovePageDownAndModifySelection", { executeMovePageDownAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1340 { "MovePageUp", { executeMovePageUp, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1341 { "MovePageUpAndModifySelection", { executeMovePageUpAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1342 { "MoveParagraphBackwardAndModifySelection", { executeMoveParagraphBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1343 { "MoveParagraphForwardAndModifySelection", { executeMoveParagraphForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1344 { "MoveRight", { executeMoveRight, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1345 { "MoveRightAndModifySelection", { executeMoveRightAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1346 { "MoveToBeginningOfDocument", { executeMoveToBeginningOfDocument, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1347 { "MoveToBeginningOfDocumentAndModifySelection", { executeMoveToBeginningOfDocumentAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1348 { "MoveToBeginningOfLine", { executeMoveToBeginningOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1349 { "MoveToBeginningOfLineAndModifySelection", { executeMoveToBeginningOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1350 { "MoveToBeginningOfParagraph", { executeMoveToBeginningOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1351 { "MoveToBeginningOfParagraphAndModifySelection", { executeMoveToBeginningOfParagraphAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1352 { "MoveToBeginningOfSentence", { executeMoveToBeginningOfSentence, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1353 { "MoveToBeginningOfSentenceAndModifySelection", { executeMoveToBeginningOfSentenceAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1354 { "MoveToEndOfDocument", { executeMoveToEndOfDocument, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1355 { "MoveToEndOfDocumentAndModifySelection", { executeMoveToEndOfDocumentAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1356 { "MoveToEndOfLine", { executeMoveToEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1357 { "MoveToEndOfLineAndModifySelection", { executeMoveToEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1358 { "MoveToEndOfParagraph", { executeMoveToEndOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1359 { "MoveToEndOfParagraphAndModifySelection", { executeMoveToEndOfParagraphAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1360 { "MoveToEndOfSentence", { executeMoveToEndOfSentence, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1361 { "MoveToEndOfSentenceAndModifySelection", { executeMoveToEndOfSentenceAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1362 { "MoveToLeftEndOfLine", { executeMoveToLeftEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1363 { "MoveToLeftEndOfLineAndModifySelection", { executeMoveToLeftEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1364 { "MoveToRightEndOfLine", { executeMoveToRightEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1365 { "MoveToRightEndOfLineAndModifySelection", { executeMoveToRightEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1366 { "MoveUp", { executeMoveUp, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1367 { "MoveUpAndModifySelection", { executeMoveUpAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1368 { "MoveWordBackward", { executeMoveWordBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1369 { "MoveWordBackwardAndModifySelection", { executeMoveWordBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1370 { "MoveWordForward", { executeMoveWordForward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1371 { "MoveWordForwardAndModifySelection", { executeMoveWordForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1372 { "MoveWordLeft", { executeMoveWordLeft, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1373 { "MoveWordLeftAndModifySelection", { executeMoveWordLeftAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1374 { "MoveWordRight", { executeMoveWordRight, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1375 { "MoveWordRightAndModifySelection", { executeMoveWordRightAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1376 { "Outdent", { executeOutdent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1377 { "Paste", { executePaste, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1378 { "PasteAndMatchStyle", { executePasteAndMatchStyle, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
1379 { "Print", { executePrint, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1380 { "Redo", { executeRedo, supported, enabledRedo, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1381 { "RemoveFormat", { executeRemoveFormat, supported, enabledRangeInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1382 { "SelectAll", { executeSelectAll, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1383 { "SelectLine", { executeSelectLine, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1384 { "SelectParagraph", { executeSelectParagraph, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1385 { "SelectSentence", { executeSelectSentence, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1386 { "SelectToMark", { executeSelectToMark, supportedFromMenuOrKeyBinding, enabledVisibleSelectionAndMark, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1387 { "SelectWord", { executeSelectWord, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1388 { "SetMark", { executeSetMark, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1389 { "Strikethrough", { executeStrikethrough, supported, enabledInRichlyEditableText, stateStrikethrough, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1390 { "StyleWithCSS", { executeStyleWithCSS, supported, enabledInRichlyEditableText, stateStyleWithCSS, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1391 { "Subscript", { executeSubscript, supported, enabledInRichlyEditableText, stateSubscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1392 { "Superscript", { executeSuperscript, supported, enabledInRichlyEditableText, stateSuperscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1393 { "SwapWithMark", { executeSwapWithMark, supportedFromMenuOrKeyBinding, enabledVisibleSelectionAndMark, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1394 { "ToggleBold", { executeToggleBold, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1395 { "ToggleItalic", { executeToggleItalic, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateItalic, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1396 { "ToggleUnderline", { executeUnderline, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateUnderline, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1397 { "Transpose", { executeTranspose, supported, enableCaretInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1398 { "Underline", { executeUnderline, supported, enabledInRichlyEditableText, stateUnderline, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1399 { "Undo", { executeUndo, supported, enabledUndo, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1400 { "Unlink", { executeUnlink, supported, enabledRangeInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1401 { "Unscript", { executeUnscript, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1402 { "Unselect", { executeUnselect, supported, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1403 { "Yank", { executeYank, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1404 { "YankAndSelect", { executeYankAndSelect, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1405 };
1406
1407 // These unsupported commands are listed here since they appear in the Microsoft
1408 // documentation used as the starting point for our DOM executeCommand support.
1409 //
1410 // 2D-Position (not supported)
1411 // AbsolutePosition (not supported)
1412 // BlockDirLTR (not supported)
1413 // BlockDirRTL (not supported)
1414 // BrowseMode (not supported)
1415 // ClearAuthenticationCache (not supported)
1416 // CreateBookmark (not supported)
1417 // DirLTR (not supported)
1418 // DirRTL (not supported)
1419 // EditMode (not supported)
1420 // InlineDirLTR (not supported)
1421 // InlineDirRTL (not supported)
1422 // InsertButton (not supported)
1423 // InsertFieldSet (not supported)
1424 // InsertIFrame (not supported)
1425 // InsertInputButton (not supported)
1426 // InsertInputCheckbox (not supported)
1427 // InsertInputFileUpload (not supported)
1428 // InsertInputHidden (not supported)
1429 // InsertInputImage (not supported)
1430 // InsertInputPassword (not supported)
1431 // InsertInputRadio (not supported)
1432 // InsertInputReset (not supported)
1433 // InsertInputSubmit (not supported)
1434 // InsertInputText (not supported)
1435 // InsertMarquee (not supported)
1436 // InsertSelectDropDown (not supported)
1437 // InsertSelectListBox (not supported)
1438 // InsertTextArea (not supported)
1439 // LiveResize (not supported)
1440 // MultipleSelection (not supported)
1441 // Open (not supported)
1442 // Overwrite (not supported)
1443 // PlayImage (not supported)
1444 // Refresh (not supported)
1445 // RemoveParaFormat (not supported)
1446 // SaveAs (not supported)
1447 // SizeToControl (not supported)
1448 // SizeToControlHeight (not supported)
1449 // SizeToControlWidth (not supported)
1450 // Stop (not supported)
1451 // StopImage (not supported)
1452 // Unbookmark (not supported)
1453
1454 CommandMap& commandMap = *new CommandMap;
1455
1456 const unsigned numCommands = sizeof(commands) / sizeof(commands[0]);
1457 for (unsigned i = 0; i < numCommands; i++) {
1458 ASSERT(!commandMap.get(commands[i].name));
1459 commandMap.set(commands[i].name, &commands[i].command);
1460 }
1461
1462 return commandMap;
1463 }
1464
command(const String & commandName)1465 Editor::Command Editor::command(const String& commandName)
1466 {
1467 return command(commandName, CommandFromMenuOrKeyBinding);
1468 }
1469
command(const String & commandName,EditorCommandSource source)1470 Editor::Command Editor::command(const String& commandName, EditorCommandSource source)
1471 {
1472 if (commandName.isEmpty())
1473 return Command();
1474
1475 static const CommandMap& commandMap = createCommandMap();
1476 const EditorInternalCommand* internalCommand = commandMap.get(commandName);
1477 return internalCommand ? Command(m_frame, internalCommand, source) : Command();
1478 }
1479
Command()1480 Editor::Command::Command()
1481 : m_command(0)
1482 , m_source()
1483 {
1484 }
1485
Command(PassRefPtr<Frame> frame,const EditorInternalCommand * command,EditorCommandSource source)1486 Editor::Command::Command(PassRefPtr<Frame> frame, const EditorInternalCommand* command, EditorCommandSource source)
1487 : m_frame(frame)
1488 , m_command(command)
1489 , m_source(source)
1490 {
1491 ASSERT(m_frame);
1492 ASSERT(m_command);
1493 }
1494
execute(const String & parameter,Event * triggeringEvent) const1495 bool Editor::Command::execute(const String& parameter, Event* triggeringEvent) const
1496 {
1497 if (!isEnabled(triggeringEvent)) {
1498 // Let certain commands be executed when performed explicitly even if they are disabled.
1499 if (!isSupported() || !m_frame || !m_command->allowExecutionWhenDisabled)
1500 return false;
1501 }
1502 m_frame->document()->updateLayoutIgnorePendingStylesheets();
1503 return m_command->execute(m_frame.get(), triggeringEvent, m_source, parameter);
1504 }
1505
execute(Event * triggeringEvent) const1506 bool Editor::Command::execute(Event* triggeringEvent) const
1507 {
1508 return execute(String(), triggeringEvent);
1509 }
1510
isSupported() const1511 bool Editor::Command::isSupported() const
1512 {
1513 return m_command && m_command->isSupported(m_frame.get(), m_source);
1514 }
1515
isEnabled(Event * triggeringEvent) const1516 bool Editor::Command::isEnabled(Event* triggeringEvent) const
1517 {
1518 if (!isSupported() || !m_frame)
1519 return false;
1520 return m_command->isEnabled(m_frame.get(), triggeringEvent, m_source);
1521 }
1522
state(Event * triggeringEvent) const1523 TriState Editor::Command::state(Event* triggeringEvent) const
1524 {
1525 if (!isSupported() || !m_frame)
1526 return FalseTriState;
1527 return m_command->state(m_frame.get(), triggeringEvent);
1528 }
1529
value(Event * triggeringEvent) const1530 String Editor::Command::value(Event* triggeringEvent) const
1531 {
1532 if (!isSupported() || !m_frame)
1533 return String();
1534 return m_command->value(m_frame.get(), triggeringEvent);
1535 }
1536
isTextInsertion() const1537 bool Editor::Command::isTextInsertion() const
1538 {
1539 return m_command && m_command->isTextInsertion;
1540 }
1541
1542 } // namespace WebCore
1543