1 | /* |
2 | * Copyright (C) 2006-2008, 2014, 2016 Apple Inc. All rights reserved. |
3 | * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
4 | * Copyright (C) 2009 Igalia S.L. |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
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. |
14 | * |
15 | * THIS SOFTWARE IS PROVIDED BY APPLE 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 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. |
26 | */ |
27 | |
28 | #include "config.h" |
29 | #include "Editor.h" |
30 | |
31 | #include "CSSComputedStyleDeclaration.h" |
32 | #include "CSSValueList.h" |
33 | #include "Chrome.h" |
34 | #include "CreateLinkCommand.h" |
35 | #include "DocumentFragment.h" |
36 | #include "Editing.h" |
37 | #include "EditorClient.h" |
38 | #include "Event.h" |
39 | #include "EventHandler.h" |
40 | #include "FormatBlockCommand.h" |
41 | #include "Frame.h" |
42 | #include "FrameLoader.h" |
43 | #include "FrameView.h" |
44 | #include "HTMLFontElement.h" |
45 | #include "HTMLHRElement.h" |
46 | #include "HTMLImageElement.h" |
47 | #include "HTMLNames.h" |
48 | #include "IndentOutdentCommand.h" |
49 | #include "InsertEditableImageCommand.h" |
50 | #include "InsertListCommand.h" |
51 | #include "InsertNestedListCommand.h" |
52 | #include "Page.h" |
53 | #include "Pasteboard.h" |
54 | #include "RenderBox.h" |
55 | #include "ReplaceSelectionCommand.h" |
56 | #include "Scrollbar.h" |
57 | #include "Settings.h" |
58 | #include "StyleProperties.h" |
59 | #include "TypingCommand.h" |
60 | #include "UnlinkCommand.h" |
61 | #include "UserGestureIndicator.h" |
62 | #include "UserTypingGestureIndicator.h" |
63 | #include "markup.h" |
64 | #include <pal/system/Sound.h> |
65 | #include <pal/text/KillRing.h> |
66 | #include <wtf/text/AtomicString.h> |
67 | |
68 | namespace WebCore { |
69 | |
70 | using namespace HTMLNames; |
71 | |
72 | class EditorInternalCommand { |
73 | public: |
74 | bool (*execute)(Frame&, Event*, EditorCommandSource, const String&); |
75 | bool (*isSupportedFromDOM)(Frame*); |
76 | bool (*isEnabled)(Frame&, Event*, EditorCommandSource); |
77 | TriState (*state)(Frame&, Event*); |
78 | String (*value)(Frame&, Event*); |
79 | bool isTextInsertion; |
80 | bool (*allowExecutionWhenDisabled)(Frame&, EditorCommandSource); |
81 | }; |
82 | |
83 | typedef HashMap<String, const EditorInternalCommand*, ASCIICaseInsensitiveHash> CommandMap; |
84 | |
85 | static const bool notTextInsertion = false; |
86 | static const bool isTextInsertion = true; |
87 | |
88 | // Related to Editor::selectionForCommand. |
89 | // Certain operations continue to use the target control's selection even if the event handler |
90 | // already moved the selection outside of the text control. |
91 | static Frame* targetFrame(Frame& frame, Event* event) |
92 | { |
93 | if (!event) |
94 | return &frame; |
95 | if (!is<Node>(event->target())) |
96 | return &frame; |
97 | return downcast<Node>(*event->target()).document().frame(); |
98 | } |
99 | |
100 | static bool applyCommandToFrame(Frame& frame, EditorCommandSource source, EditAction action, Ref<EditingStyle>&& style) |
101 | { |
102 | // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a good reason for that? |
103 | switch (source) { |
104 | case CommandFromMenuOrKeyBinding: |
105 | // Use InvertColor for testing purposes. foreColor and backColor are never triggered with CommandFromMenuOrKeyBinding outside DRT/WTR. |
106 | frame.editor().applyStyleToSelection(WTFMove(style), action, Editor::ColorFilterMode::InvertColor); |
107 | return true; |
108 | case CommandFromDOM: |
109 | case CommandFromDOMWithUserInterface: |
110 | frame.editor().applyStyle(WTFMove(style), EditAction::Unspecified, Editor::ColorFilterMode::UseOriginalColor); |
111 | return true; |
112 | } |
113 | ASSERT_NOT_REACHED(); |
114 | return false; |
115 | } |
116 | |
117 | static bool isStylePresent(Editor& editor, CSSPropertyID propertyID, const char* onValue) |
118 | { |
119 | // Style is considered present when |
120 | // Mac: present at the beginning of selection |
121 | // Windows: present throughout the selection |
122 | if (editor.behavior().shouldToggleStyleBasedOnStartOfSelection()) |
123 | return editor.selectionStartHasStyle(propertyID, onValue); |
124 | return editor.selectionHasStyle(propertyID, onValue) == TrueTriState; |
125 | } |
126 | |
127 | static bool executeApplyStyle(Frame& frame, EditorCommandSource source, EditAction action, CSSPropertyID propertyID, const String& propertyValue) |
128 | { |
129 | return applyCommandToFrame(frame, source, action, EditingStyle::create(propertyID, propertyValue)); |
130 | } |
131 | |
132 | static bool executeApplyStyle(Frame& frame, EditorCommandSource source, EditAction action, CSSPropertyID propertyID, CSSValueID propertyValue) |
133 | { |
134 | return applyCommandToFrame(frame, source, action, EditingStyle::create(propertyID, propertyValue)); |
135 | } |
136 | |
137 | static bool executeToggleStyle(Frame& frame, EditorCommandSource source, EditAction action, CSSPropertyID propertyID, const char* offValue, const char* onValue) |
138 | { |
139 | bool styleIsPresent = isStylePresent(frame.editor(), propertyID, onValue); |
140 | return applyCommandToFrame(frame, source, action, EditingStyle::create(propertyID, styleIsPresent ? offValue : onValue)); |
141 | } |
142 | |
143 | static bool executeApplyParagraphStyle(Frame& frame, EditorCommandSource source, EditAction action, CSSPropertyID propertyID, const String& propertyValue) |
144 | { |
145 | auto style = MutableStyleProperties::create(); |
146 | style->setProperty(propertyID, propertyValue); |
147 | // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a good reason for that? |
148 | switch (source) { |
149 | case CommandFromMenuOrKeyBinding: |
150 | frame.editor().applyParagraphStyleToSelection(style.ptr(), action); |
151 | return true; |
152 | case CommandFromDOM: |
153 | case CommandFromDOMWithUserInterface: |
154 | frame.editor().applyParagraphStyle(style.ptr()); |
155 | return true; |
156 | } |
157 | ASSERT_NOT_REACHED(); |
158 | return false; |
159 | } |
160 | |
161 | static bool executeInsertFragment(Frame& frame, Ref<DocumentFragment>&& fragment) |
162 | { |
163 | ASSERT(frame.document()); |
164 | ReplaceSelectionCommand::create(*frame.document(), WTFMove(fragment), ReplaceSelectionCommand::PreventNesting, EditAction::Insert)->apply(); |
165 | return true; |
166 | } |
167 | |
168 | static bool executeInsertNode(Frame& frame, Ref<Node>&& content) |
169 | { |
170 | auto fragment = DocumentFragment::create(*frame.document()); |
171 | if (fragment->appendChild(content).hasException()) |
172 | return false; |
173 | return executeInsertFragment(frame, WTFMove(fragment)); |
174 | } |
175 | |
176 | static bool expandSelectionToGranularity(Frame& frame, TextGranularity granularity) |
177 | { |
178 | VisibleSelection selection = frame.selection().selection(); |
179 | selection.expandUsingGranularity(granularity); |
180 | RefPtr<Range> newRange = selection.toNormalizedRange(); |
181 | if (!newRange) |
182 | return false; |
183 | if (newRange->collapsed()) |
184 | return false; |
185 | RefPtr<Range> oldRange = selection.toNormalizedRange(); |
186 | EAffinity affinity = selection.affinity(); |
187 | if (!frame.editor().client()->shouldChangeSelectedRange(oldRange.get(), newRange.get(), affinity, false)) |
188 | return false; |
189 | frame.selection().setSelectedRange(newRange.get(), affinity, FrameSelection::ShouldCloseTyping::Yes); |
190 | return true; |
191 | } |
192 | |
193 | static TriState stateStyle(Frame& frame, CSSPropertyID propertyID, const char* desiredValue) |
194 | { |
195 | if (frame.editor().behavior().shouldToggleStyleBasedOnStartOfSelection()) |
196 | return frame.editor().selectionStartHasStyle(propertyID, desiredValue) ? TrueTriState : FalseTriState; |
197 | return frame.editor().selectionHasStyle(propertyID, desiredValue); |
198 | } |
199 | |
200 | static String valueStyle(Frame& frame, CSSPropertyID propertyID) |
201 | { |
202 | // FIXME: Rather than retrieving the style at the start of the current selection, |
203 | // we should retrieve the style present throughout the selection for non-Mac platforms. |
204 | return frame.editor().selectionStartCSSPropertyValue(propertyID); |
205 | } |
206 | |
207 | static TriState stateTextWritingDirection(Frame& frame, WritingDirection direction) |
208 | { |
209 | bool hasNestedOrMultipleEmbeddings; |
210 | WritingDirection selectionDirection = EditingStyle::textDirectionForSelection(frame.selection().selection(), |
211 | frame.selection().typingStyle(), hasNestedOrMultipleEmbeddings); |
212 | // FXIME: We should be returning MixedTriState when selectionDirection == direction && hasNestedOrMultipleEmbeddings |
213 | return (selectionDirection == direction && !hasNestedOrMultipleEmbeddings) ? TrueTriState : FalseTriState; |
214 | } |
215 | |
216 | static unsigned verticalScrollDistance(Frame& frame) |
217 | { |
218 | Element* focusedElement = frame.document()->focusedElement(); |
219 | if (!focusedElement) |
220 | return 0; |
221 | auto* renderer = focusedElement->renderer(); |
222 | if (!is<RenderBox>(renderer)) |
223 | return 0; |
224 | const RenderStyle& style = renderer->style(); |
225 | if (!(style.overflowY() == Overflow::Scroll || style.overflowY() == Overflow::Auto || focusedElement->hasEditableStyle())) |
226 | return 0; |
227 | int height = std::min<int>(downcast<RenderBox>(*renderer).clientHeight(), frame.view()->visibleHeight()); |
228 | return static_cast<unsigned>(Scrollbar::pageStep(height)); |
229 | } |
230 | |
231 | static RefPtr<Range> unionDOMRanges(Range& a, Range& b) |
232 | { |
233 | Range& start = a.compareBoundaryPoints(Range::START_TO_START, b).releaseReturnValue() <= 0 ? a : b; |
234 | Range& end = a.compareBoundaryPoints(Range::END_TO_END, b).releaseReturnValue() <= 0 ? b : a; |
235 | return Range::create(a.ownerDocument(), &start.startContainer(), start.startOffset(), &end.endContainer(), end.endOffset()); |
236 | } |
237 | |
238 | // Execute command functions |
239 | |
240 | static bool executeBackColor(Frame& frame, Event*, EditorCommandSource source, const String& value) |
241 | { |
242 | return executeApplyStyle(frame, source, EditAction::SetBackgroundColor, CSSPropertyBackgroundColor, value); |
243 | } |
244 | |
245 | static bool executeCopy(Frame& frame, Event*, EditorCommandSource, const String&) |
246 | { |
247 | frame.editor().copy(); |
248 | return true; |
249 | } |
250 | |
251 | static bool executeCreateLink(Frame& frame, Event*, EditorCommandSource, const String& value) |
252 | { |
253 | // FIXME: If userInterface is true, we should display a dialog box to let the user enter a URL. |
254 | if (value.isEmpty()) |
255 | return false; |
256 | ASSERT(frame.document()); |
257 | CreateLinkCommand::create(*frame.document(), value)->apply(); |
258 | return true; |
259 | } |
260 | |
261 | static bool executeCut(Frame& frame, Event*, EditorCommandSource source, const String&) |
262 | { |
263 | if (source == CommandFromMenuOrKeyBinding) { |
264 | UserTypingGestureIndicator typingGestureIndicator(frame); |
265 | frame.editor().cut(); |
266 | } else |
267 | frame.editor().cut(); |
268 | return true; |
269 | } |
270 | |
271 | static bool executeClearText(Frame& frame, Event*, EditorCommandSource, const String&) |
272 | { |
273 | frame.editor().clearText(); |
274 | return true; |
275 | } |
276 | |
277 | static bool executeDefaultParagraphSeparator(Frame& frame, Event*, EditorCommandSource, const String& value) |
278 | { |
279 | if (equalLettersIgnoringASCIICase(value, "div" )) |
280 | frame.editor().setDefaultParagraphSeparator(EditorParagraphSeparatorIsDiv); |
281 | else if (equalLettersIgnoringASCIICase(value, "p" )) |
282 | frame.editor().setDefaultParagraphSeparator(EditorParagraphSeparatorIsP); |
283 | |
284 | return true; |
285 | } |
286 | |
287 | static bool executeDelete(Frame& frame, Event*, EditorCommandSource source, const String&) |
288 | { |
289 | switch (source) { |
290 | case CommandFromMenuOrKeyBinding: { |
291 | // Doesn't modify the text if the current selection isn't a range. |
292 | UserTypingGestureIndicator typingGestureIndicator(frame); |
293 | frame.editor().performDelete(); |
294 | return true; |
295 | } |
296 | case CommandFromDOM: |
297 | case CommandFromDOMWithUserInterface: |
298 | // If the current selection is a caret, delete the preceding character. IE performs forwardDelete, but we currently side with Firefox. |
299 | // Doesn't scroll to make the selection visible, or modify the kill ring (this time, siding with IE, not Firefox). |
300 | TypingCommand::deleteKeyPressed(*frame.document(), frame.editor().shouldSmartDelete() ? TypingCommand::SmartDelete : 0); |
301 | return true; |
302 | } |
303 | ASSERT_NOT_REACHED(); |
304 | return false; |
305 | } |
306 | |
307 | static bool executeDeleteBackward(Frame& frame, Event*, EditorCommandSource, const String&) |
308 | { |
309 | frame.editor().deleteWithDirection(DirectionBackward, CharacterGranularity, false, true); |
310 | return true; |
311 | } |
312 | |
313 | static bool executeDeleteBackwardByDecomposingPreviousCharacter(Frame& frame, Event*, EditorCommandSource, const String&) |
314 | { |
315 | LOG_ERROR("DeleteBackwardByDecomposingPreviousCharacter is not implemented, doing DeleteBackward instead" ); |
316 | frame.editor().deleteWithDirection(DirectionBackward, CharacterGranularity, false, true); |
317 | return true; |
318 | } |
319 | |
320 | static bool executeDeleteForward(Frame& frame, Event*, EditorCommandSource, const String&) |
321 | { |
322 | frame.editor().deleteWithDirection(DirectionForward, CharacterGranularity, false, true); |
323 | return true; |
324 | } |
325 | |
326 | static bool executeDeleteToBeginningOfLine(Frame& frame, Event*, EditorCommandSource, const String&) |
327 | { |
328 | frame.editor().deleteWithDirection(DirectionBackward, LineBoundary, true, false); |
329 | return true; |
330 | } |
331 | |
332 | static bool executeDeleteToBeginningOfParagraph(Frame& frame, Event*, EditorCommandSource, const String&) |
333 | { |
334 | frame.editor().deleteWithDirection(DirectionBackward, ParagraphBoundary, true, false); |
335 | return true; |
336 | } |
337 | |
338 | static bool executeDeleteToEndOfLine(Frame& frame, Event*, EditorCommandSource, const String&) |
339 | { |
340 | // Despite its name, this command should delete the newline at the end of |
341 | // a paragraph if you are at the end of a paragraph (like DeleteToEndOfParagraph). |
342 | frame.editor().deleteWithDirection(DirectionForward, LineBoundary, true, false); |
343 | return true; |
344 | } |
345 | |
346 | static bool executeDeleteToEndOfParagraph(Frame& frame, Event*, EditorCommandSource, const String&) |
347 | { |
348 | // Despite its name, this command should delete the newline at the end of |
349 | // a paragraph if you are at the end of a paragraph. |
350 | frame.editor().deleteWithDirection(DirectionForward, ParagraphBoundary, true, false); |
351 | return true; |
352 | } |
353 | |
354 | static bool executeDeleteToMark(Frame& frame, Event*, EditorCommandSource, const String&) |
355 | { |
356 | RefPtr<Range> mark = frame.editor().mark().toNormalizedRange(); |
357 | FrameSelection& selection = frame.selection(); |
358 | if (mark && frame.editor().selectedRange()) { |
359 | bool selected = selection.setSelectedRange(unionDOMRanges(*mark, *frame.editor().selectedRange()).get(), DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes); |
360 | ASSERT(selected); |
361 | if (!selected) |
362 | return false; |
363 | } |
364 | frame.editor().performDelete(); |
365 | frame.editor().setMark(selection.selection()); |
366 | return true; |
367 | } |
368 | |
369 | static bool executeDeleteWordBackward(Frame& frame, Event*, EditorCommandSource, const String&) |
370 | { |
371 | frame.editor().deleteWithDirection(DirectionBackward, WordGranularity, true, false); |
372 | return true; |
373 | } |
374 | |
375 | static bool executeDeleteWordForward(Frame& frame, Event*, EditorCommandSource, const String&) |
376 | { |
377 | frame.editor().deleteWithDirection(DirectionForward, WordGranularity, true, false); |
378 | return true; |
379 | } |
380 | |
381 | static bool executeFindString(Frame& frame, Event*, EditorCommandSource, const String& value) |
382 | { |
383 | return frame.editor().findString(value, { CaseInsensitive, WrapAround, DoNotTraverseFlatTree }); |
384 | } |
385 | |
386 | static bool executeFontName(Frame& frame, Event*, EditorCommandSource source, const String& value) |
387 | { |
388 | return executeApplyStyle(frame, source, EditAction::SetFont, CSSPropertyFontFamily, value); |
389 | } |
390 | |
391 | static bool executeFontSize(Frame& frame, Event*, EditorCommandSource source, const String& value) |
392 | { |
393 | CSSValueID size; |
394 | if (!HTMLFontElement::cssValueFromFontSizeNumber(value, size)) |
395 | return false; |
396 | return executeApplyStyle(frame, source, EditAction::ChangeAttributes, CSSPropertyFontSize, size); |
397 | } |
398 | |
399 | static bool executeFontSizeDelta(Frame& frame, Event*, EditorCommandSource source, const String& value) |
400 | { |
401 | return executeApplyStyle(frame, source, EditAction::ChangeAttributes, CSSPropertyWebkitFontSizeDelta, value); |
402 | } |
403 | |
404 | static bool executeForeColor(Frame& frame, Event*, EditorCommandSource source, const String& value) |
405 | { |
406 | return executeApplyStyle(frame, source, EditAction::SetColor, CSSPropertyColor, value); |
407 | } |
408 | |
409 | static bool executeFormatBlock(Frame& frame, Event*, EditorCommandSource, const String& value) |
410 | { |
411 | String tagName = value.convertToASCIILowercase(); |
412 | if (tagName[0] == '<' && tagName[tagName.length() - 1] == '>') |
413 | tagName = tagName.substring(1, tagName.length() - 2); |
414 | |
415 | auto qualifiedTagName = Document::parseQualifiedName(xhtmlNamespaceURI, tagName); |
416 | if (qualifiedTagName.hasException()) |
417 | return false; |
418 | |
419 | ASSERT(frame.document()); |
420 | auto command = FormatBlockCommand::create(*frame.document(), qualifiedTagName.releaseReturnValue()); |
421 | command->apply(); |
422 | return command->didApply(); |
423 | } |
424 | |
425 | static bool executeForwardDelete(Frame& frame, Event*, EditorCommandSource source, const String&) |
426 | { |
427 | switch (source) { |
428 | case CommandFromMenuOrKeyBinding: |
429 | frame.editor().deleteWithDirection(DirectionForward, CharacterGranularity, false, true); |
430 | return true; |
431 | case CommandFromDOM: |
432 | case CommandFromDOMWithUserInterface: |
433 | // Doesn't scroll to make the selection visible, or modify the kill ring. |
434 | // ForwardDelete is not implemented in IE or Firefox, so this behavior is only needed for |
435 | // backward compatibility with ourselves, and for consistency with Delete. |
436 | TypingCommand::forwardDeleteKeyPressed(*frame.document()); |
437 | return true; |
438 | } |
439 | ASSERT_NOT_REACHED(); |
440 | return false; |
441 | } |
442 | |
443 | static bool executeIgnoreSpelling(Frame& frame, Event*, EditorCommandSource, const String&) |
444 | { |
445 | frame.editor().ignoreSpelling(); |
446 | return true; |
447 | } |
448 | |
449 | static bool executeIndent(Frame& frame, Event*, EditorCommandSource, const String&) |
450 | { |
451 | ASSERT(frame.document()); |
452 | IndentOutdentCommand::create(*frame.document(), IndentOutdentCommand::Indent)->apply(); |
453 | return true; |
454 | } |
455 | |
456 | static bool executeInsertBacktab(Frame& frame, Event* event, EditorCommandSource, const String&) |
457 | { |
458 | return targetFrame(frame, event)->eventHandler().handleTextInputEvent("\t"_s , event, TextEventInputBackTab); |
459 | } |
460 | |
461 | static bool executeInsertHorizontalRule(Frame& frame, Event*, EditorCommandSource, const String& value) |
462 | { |
463 | Ref<HTMLHRElement> rule = HTMLHRElement::create(*frame.document()); |
464 | if (!value.isEmpty()) |
465 | rule->setIdAttribute(value); |
466 | return executeInsertNode(frame, WTFMove(rule)); |
467 | } |
468 | |
469 | static bool executeInsertHTML(Frame& frame, Event*, EditorCommandSource, const String& value) |
470 | { |
471 | return executeInsertFragment(frame, createFragmentFromMarkup(*frame.document(), value, emptyString())); |
472 | } |
473 | |
474 | static bool executeInsertImage(Frame& frame, Event*, EditorCommandSource, const String& value) |
475 | { |
476 | // FIXME: If userInterface is true, we should display a dialog box and let the user choose a local image. |
477 | Ref<HTMLImageElement> image = HTMLImageElement::create(*frame.document()); |
478 | image->setSrc(value); |
479 | return executeInsertNode(frame, WTFMove(image)); |
480 | } |
481 | |
482 | static bool executeInsertEditableImage(Frame& frame, Event*, EditorCommandSource, const String&) |
483 | { |
484 | ASSERT(frame.document()); |
485 | InsertEditableImageCommand::create(*frame.document())->apply(); |
486 | return true; |
487 | } |
488 | |
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"_s , event, TextEventInputLineBreak); |
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(), 0); |
500 | return true; |
501 | } |
502 | ASSERT_NOT_REACHED(); |
503 | return false; |
504 | } |
505 | |
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"_s , event, targetFrame->editor().canEditRichly() ? TextEventInputKeyboard : TextEventInputLineBreak); |
510 | } |
511 | |
512 | static bool executeInsertNewlineInQuotedContent(Frame& frame, Event*, EditorCommandSource, const String&) |
513 | { |
514 | TypingCommand::insertParagraphSeparatorInQuotedContent(*frame.document()); |
515 | return true; |
516 | } |
517 | |
518 | static bool executeInsertOrderedList(Frame& frame, Event*, EditorCommandSource, const String&) |
519 | { |
520 | ASSERT(frame.document()); |
521 | InsertListCommand::create(*frame.document(), InsertListCommand::Type::OrderedList)->apply(); |
522 | return true; |
523 | } |
524 | |
525 | static bool executeInsertParagraph(Frame& frame, Event*, EditorCommandSource, const String&) |
526 | { |
527 | TypingCommand::insertParagraphSeparator(*frame.document(), 0); |
528 | return true; |
529 | } |
530 | |
531 | static bool executeInsertTab(Frame& frame, Event* event, EditorCommandSource, const String&) |
532 | { |
533 | return targetFrame(frame, event)->eventHandler().handleTextInputEvent("\t"_s , event); |
534 | } |
535 | |
536 | static bool executeInsertText(Frame& frame, Event*, EditorCommandSource, const String& value) |
537 | { |
538 | TypingCommand::insertText(*frame.document(), value, 0); |
539 | return true; |
540 | } |
541 | |
542 | static bool executeInsertUnorderedList(Frame& frame, Event*, EditorCommandSource, const String&) |
543 | { |
544 | ASSERT(frame.document()); |
545 | InsertListCommand::create(*frame.document(), InsertListCommand::Type::UnorderedList)->apply(); |
546 | return true; |
547 | } |
548 | |
549 | static bool executeInsertNestedUnorderedList(Frame& frame, Event*, EditorCommandSource, const String&) |
550 | { |
551 | ASSERT(frame.document()); |
552 | InsertNestedListCommand::insertUnorderedList(*frame.document()); |
553 | return true; |
554 | } |
555 | |
556 | static bool executeInsertNestedOrderedList(Frame& frame, Event*, EditorCommandSource, const String&) |
557 | { |
558 | ASSERT(frame.document()); |
559 | InsertNestedListCommand::insertOrderedList(*frame.document()); |
560 | return true; |
561 | } |
562 | |
563 | static bool executeJustifyCenter(Frame& frame, Event*, EditorCommandSource source, const String&) |
564 | { |
565 | return executeApplyParagraphStyle(frame, source, EditAction::Center, CSSPropertyTextAlign, "center"_s ); |
566 | } |
567 | |
568 | static bool executeJustifyFull(Frame& frame, Event*, EditorCommandSource source, const String&) |
569 | { |
570 | return executeApplyParagraphStyle(frame, source, EditAction::Justify, CSSPropertyTextAlign, "justify"_s ); |
571 | } |
572 | |
573 | static bool executeJustifyLeft(Frame& frame, Event*, EditorCommandSource source, const String&) |
574 | { |
575 | return executeApplyParagraphStyle(frame, source, EditAction::AlignLeft, CSSPropertyTextAlign, "left"_s ); |
576 | } |
577 | |
578 | static bool executeJustifyRight(Frame& frame, Event*, EditorCommandSource source, const String&) |
579 | { |
580 | return executeApplyParagraphStyle(frame, source, EditAction::AlignRight, CSSPropertyTextAlign, "right"_s ); |
581 | } |
582 | |
583 | static bool executeMakeTextWritingDirectionLeftToRight(Frame& frame, Event*, EditorCommandSource, const String&) |
584 | { |
585 | auto style = MutableStyleProperties::create(); |
586 | style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed); |
587 | style->setProperty(CSSPropertyDirection, CSSValueLtr); |
588 | frame.editor().applyStyle(style.ptr(), EditAction::SetInlineWritingDirection); |
589 | return true; |
590 | } |
591 | |
592 | static bool executeMakeTextWritingDirectionNatural(Frame& frame, Event*, EditorCommandSource, const String&) |
593 | { |
594 | auto style = MutableStyleProperties::create(); |
595 | style->setProperty(CSSPropertyUnicodeBidi, CSSValueNormal); |
596 | frame.editor().applyStyle(style.ptr(), EditAction::SetInlineWritingDirection); |
597 | return true; |
598 | } |
599 | |
600 | static bool executeMakeTextWritingDirectionRightToLeft(Frame& frame, Event*, EditorCommandSource, const String&) |
601 | { |
602 | auto style = MutableStyleProperties::create(); |
603 | style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed); |
604 | style->setProperty(CSSPropertyDirection, CSSValueRtl); |
605 | frame.editor().applyStyle(style.ptr(), EditAction::SetInlineWritingDirection); |
606 | return true; |
607 | } |
608 | |
609 | static bool executeMoveBackward(Frame& frame, Event*, EditorCommandSource, const String&) |
610 | { |
611 | frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, CharacterGranularity, UserTriggered); |
612 | return true; |
613 | } |
614 | |
615 | static bool executeMoveBackwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
616 | { |
617 | frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, CharacterGranularity, UserTriggered); |
618 | return true; |
619 | } |
620 | |
621 | static bool executeMoveDown(Frame& frame, Event*, EditorCommandSource, const String&) |
622 | { |
623 | return frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, LineGranularity, UserTriggered); |
624 | } |
625 | |
626 | static bool executeMoveDownAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
627 | { |
628 | frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, LineGranularity, UserTriggered); |
629 | return true; |
630 | } |
631 | |
632 | static bool executeMoveForward(Frame& frame, Event*, EditorCommandSource, const String&) |
633 | { |
634 | frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity, UserTriggered); |
635 | return true; |
636 | } |
637 | |
638 | static bool executeMoveForwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
639 | { |
640 | frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, CharacterGranularity, UserTriggered); |
641 | return true; |
642 | } |
643 | |
644 | static bool executeMoveLeft(Frame& frame, Event*, EditorCommandSource, const String&) |
645 | { |
646 | return frame.selection().modify(FrameSelection::AlterationMove, DirectionLeft, CharacterGranularity, UserTriggered); |
647 | } |
648 | |
649 | static bool executeMoveLeftAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
650 | { |
651 | frame.selection().modify(FrameSelection::AlterationExtend, DirectionLeft, CharacterGranularity, UserTriggered); |
652 | return true; |
653 | } |
654 | |
655 | static bool executeMovePageDown(Frame& frame, Event*, EditorCommandSource, const String&) |
656 | { |
657 | unsigned distance = verticalScrollDistance(frame); |
658 | if (!distance) |
659 | return false; |
660 | return frame.selection().modify(FrameSelection::AlterationMove, distance, FrameSelection::DirectionDown, |
661 | UserTriggered, FrameSelection::AlignCursorOnScrollAlways); |
662 | } |
663 | |
664 | static bool executeMovePageDownAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
665 | { |
666 | unsigned distance = verticalScrollDistance(frame); |
667 | if (!distance) |
668 | return false; |
669 | return frame.selection().modify(FrameSelection::AlterationExtend, distance, FrameSelection::DirectionDown, |
670 | UserTriggered, FrameSelection::AlignCursorOnScrollAlways); |
671 | } |
672 | |
673 | static bool executeMovePageUp(Frame& frame, Event*, EditorCommandSource, const String&) |
674 | { |
675 | unsigned distance = verticalScrollDistance(frame); |
676 | if (!distance) |
677 | return false; |
678 | return frame.selection().modify(FrameSelection::AlterationMove, distance, FrameSelection::DirectionUp, |
679 | UserTriggered, FrameSelection::AlignCursorOnScrollAlways); |
680 | } |
681 | |
682 | static bool executeMovePageUpAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
683 | { |
684 | unsigned distance = verticalScrollDistance(frame); |
685 | if (!distance) |
686 | return false; |
687 | return frame.selection().modify(FrameSelection::AlterationExtend, distance, FrameSelection::DirectionUp, |
688 | UserTriggered, FrameSelection::AlignCursorOnScrollAlways); |
689 | } |
690 | |
691 | static bool executeMoveRight(Frame& frame, Event*, EditorCommandSource, const String&) |
692 | { |
693 | return frame.selection().modify(FrameSelection::AlterationMove, DirectionRight, CharacterGranularity, UserTriggered); |
694 | } |
695 | |
696 | static bool executeMoveRightAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
697 | { |
698 | frame.selection().modify(FrameSelection::AlterationExtend, DirectionRight, CharacterGranularity, UserTriggered); |
699 | return true; |
700 | } |
701 | |
702 | static bool executeMoveToBeginningOfDocument(Frame& frame, Event*, EditorCommandSource, const String&) |
703 | { |
704 | frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, DocumentBoundary, UserTriggered); |
705 | return true; |
706 | } |
707 | |
708 | static bool executeMoveToBeginningOfDocumentAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
709 | { |
710 | frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, DocumentBoundary, UserTriggered); |
711 | return true; |
712 | } |
713 | |
714 | static bool executeMoveToBeginningOfLine(Frame& frame, Event*, EditorCommandSource, const String&) |
715 | { |
716 | frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, LineBoundary, UserTriggered); |
717 | return true; |
718 | } |
719 | |
720 | static bool executeMoveToBeginningOfLineAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
721 | { |
722 | frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, LineBoundary, UserTriggered); |
723 | return true; |
724 | } |
725 | |
726 | static bool executeMoveToBeginningOfParagraph(Frame& frame, Event*, EditorCommandSource, const String&) |
727 | { |
728 | frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, ParagraphBoundary, UserTriggered); |
729 | return true; |
730 | } |
731 | |
732 | static bool executeMoveToBeginningOfParagraphAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
733 | { |
734 | frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, ParagraphBoundary, UserTriggered); |
735 | return true; |
736 | } |
737 | |
738 | static bool executeMoveToBeginningOfSentence(Frame& frame, Event*, EditorCommandSource, const String&) |
739 | { |
740 | frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, SentenceBoundary, UserTriggered); |
741 | return true; |
742 | } |
743 | |
744 | static bool executeMoveToBeginningOfSentenceAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
745 | { |
746 | frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, SentenceBoundary, UserTriggered); |
747 | return true; |
748 | } |
749 | |
750 | static bool executeMoveToEndOfDocument(Frame& frame, Event*, EditorCommandSource, const String&) |
751 | { |
752 | frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, DocumentBoundary, UserTriggered); |
753 | return true; |
754 | } |
755 | |
756 | static bool executeMoveToEndOfDocumentAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
757 | { |
758 | frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, DocumentBoundary, UserTriggered); |
759 | return true; |
760 | } |
761 | |
762 | static bool executeMoveToEndOfSentence(Frame& frame, Event*, EditorCommandSource, const String&) |
763 | { |
764 | frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, SentenceBoundary, UserTriggered); |
765 | return true; |
766 | } |
767 | |
768 | static bool executeMoveToEndOfSentenceAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
769 | { |
770 | frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, SentenceBoundary, UserTriggered); |
771 | return true; |
772 | } |
773 | |
774 | static bool executeMoveToEndOfLine(Frame& frame, Event*, EditorCommandSource, const String&) |
775 | { |
776 | frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, LineBoundary, UserTriggered); |
777 | return true; |
778 | } |
779 | |
780 | static bool executeMoveToEndOfLineAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
781 | { |
782 | frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, LineBoundary, UserTriggered); |
783 | return true; |
784 | } |
785 | |
786 | static bool executeMoveToEndOfParagraph(Frame& frame, Event*, EditorCommandSource, const String&) |
787 | { |
788 | frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, ParagraphBoundary, UserTriggered); |
789 | return true; |
790 | } |
791 | |
792 | static bool executeMoveToEndOfParagraphAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
793 | { |
794 | frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, ParagraphBoundary, UserTriggered); |
795 | return true; |
796 | } |
797 | |
798 | static bool executeMoveParagraphBackwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
799 | { |
800 | frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, ParagraphGranularity, UserTriggered); |
801 | return true; |
802 | } |
803 | |
804 | static bool executeMoveParagraphForwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
805 | { |
806 | frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, ParagraphGranularity, UserTriggered); |
807 | return true; |
808 | } |
809 | |
810 | static bool executeMoveUp(Frame& frame, Event*, EditorCommandSource, const String&) |
811 | { |
812 | return frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, LineGranularity, UserTriggered); |
813 | } |
814 | |
815 | static bool executeMoveUpAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
816 | { |
817 | frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, LineGranularity, UserTriggered); |
818 | return true; |
819 | } |
820 | |
821 | static bool executeMoveWordBackward(Frame& frame, Event*, EditorCommandSource, const String&) |
822 | { |
823 | frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward, WordGranularity, UserTriggered); |
824 | return true; |
825 | } |
826 | |
827 | static bool executeMoveWordBackwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
828 | { |
829 | frame.selection().modify(FrameSelection::AlterationExtend, DirectionBackward, WordGranularity, UserTriggered); |
830 | return true; |
831 | } |
832 | |
833 | static bool executeMoveWordForward(Frame& frame, Event*, EditorCommandSource, const String&) |
834 | { |
835 | frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, WordGranularity, UserTriggered); |
836 | return true; |
837 | } |
838 | |
839 | static bool executeMoveWordForwardAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
840 | { |
841 | frame.selection().modify(FrameSelection::AlterationExtend, DirectionForward, WordGranularity, UserTriggered); |
842 | return true; |
843 | } |
844 | |
845 | static bool executeMoveWordLeft(Frame& frame, Event*, EditorCommandSource, const String&) |
846 | { |
847 | frame.selection().modify(FrameSelection::AlterationMove, DirectionLeft, WordGranularity, UserTriggered); |
848 | return true; |
849 | } |
850 | |
851 | static bool executeMoveWordLeftAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
852 | { |
853 | frame.selection().modify(FrameSelection::AlterationExtend, DirectionLeft, WordGranularity, UserTriggered); |
854 | return true; |
855 | } |
856 | |
857 | static bool executeMoveWordRight(Frame& frame, Event*, EditorCommandSource, const String&) |
858 | { |
859 | frame.selection().modify(FrameSelection::AlterationMove, DirectionRight, WordGranularity, UserTriggered); |
860 | return true; |
861 | } |
862 | |
863 | static bool executeMoveWordRightAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
864 | { |
865 | frame.selection().modify(FrameSelection::AlterationExtend, DirectionRight, WordGranularity, UserTriggered); |
866 | return true; |
867 | } |
868 | |
869 | static bool executeMoveToLeftEndOfLine(Frame& frame, Event*, EditorCommandSource, const String&) |
870 | { |
871 | frame.selection().modify(FrameSelection::AlterationMove, DirectionLeft, LineBoundary, UserTriggered); |
872 | return true; |
873 | } |
874 | |
875 | static bool executeMoveToLeftEndOfLineAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
876 | { |
877 | frame.selection().modify(FrameSelection::AlterationExtend, DirectionLeft, LineBoundary, UserTriggered); |
878 | return true; |
879 | } |
880 | |
881 | static bool executeMoveToRightEndOfLine(Frame& frame, Event*, EditorCommandSource, const String&) |
882 | { |
883 | frame.selection().modify(FrameSelection::AlterationMove, DirectionRight, LineBoundary, UserTriggered); |
884 | return true; |
885 | } |
886 | |
887 | static bool executeMoveToRightEndOfLineAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) |
888 | { |
889 | frame.selection().modify(FrameSelection::AlterationExtend, DirectionRight, LineBoundary, UserTriggered); |
890 | return true; |
891 | } |
892 | |
893 | static bool executeOutdent(Frame& frame, Event*, EditorCommandSource, const String&) |
894 | { |
895 | ASSERT(frame.document()); |
896 | IndentOutdentCommand::create(*frame.document(), IndentOutdentCommand::Outdent)->apply(); |
897 | return true; |
898 | } |
899 | |
900 | static bool executeToggleOverwrite(Frame& frame, Event*, EditorCommandSource, const String&) |
901 | { |
902 | frame.editor().toggleOverwriteModeEnabled(); |
903 | return true; |
904 | } |
905 | |
906 | static bool executePaste(Frame& frame, Event*, EditorCommandSource source, const String&) |
907 | { |
908 | if (source == CommandFromMenuOrKeyBinding) { |
909 | UserTypingGestureIndicator typingGestureIndicator(frame); |
910 | frame.editor().paste(); |
911 | return true; |
912 | } |
913 | |
914 | if (!frame.requestDOMPasteAccess()) |
915 | return false; |
916 | |
917 | frame.editor().paste(); |
918 | return true; |
919 | } |
920 | |
921 | #if PLATFORM(GTK) |
922 | |
923 | static bool executePasteGlobalSelection(Frame& frame, Event*, EditorCommandSource source, const String&) |
924 | { |
925 | // FIXME: This check should be in an enable function, not here. |
926 | if (!frame.editor().client()->supportsGlobalSelection()) |
927 | return false; |
928 | |
929 | ASSERT_UNUSED(source, source == CommandFromMenuOrKeyBinding); |
930 | UserTypingGestureIndicator typingGestureIndicator(frame); |
931 | frame.editor().paste(*Pasteboard::createForGlobalSelection()); |
932 | return true; |
933 | } |
934 | |
935 | #endif |
936 | |
937 | static bool executePasteAndMatchStyle(Frame& frame, Event*, EditorCommandSource source, const String&) |
938 | { |
939 | if (source == CommandFromMenuOrKeyBinding) { |
940 | UserTypingGestureIndicator typingGestureIndicator(frame); |
941 | frame.editor().pasteAsPlainText(); |
942 | return true; |
943 | } |
944 | |
945 | if (!frame.requestDOMPasteAccess()) |
946 | return false; |
947 | |
948 | frame.editor().pasteAsPlainText(); |
949 | return true; |
950 | } |
951 | |
952 | static bool executePasteAsPlainText(Frame& frame, Event*, EditorCommandSource source, const String&) |
953 | { |
954 | if (source == CommandFromMenuOrKeyBinding) { |
955 | UserTypingGestureIndicator typingGestureIndicator(frame); |
956 | frame.editor().pasteAsPlainText(); |
957 | return true; |
958 | } |
959 | |
960 | if (!frame.requestDOMPasteAccess()) |
961 | return false; |
962 | |
963 | frame.editor().pasteAsPlainText(); |
964 | return true; |
965 | } |
966 | |
967 | static bool executePasteAsQuotation(Frame& frame, Event*, EditorCommandSource source, const String&) |
968 | { |
969 | if (source == CommandFromMenuOrKeyBinding) { |
970 | UserTypingGestureIndicator typingGestureIndicator(frame); |
971 | frame.editor().pasteAsQuotation(); |
972 | return true; |
973 | } |
974 | |
975 | if (!frame.requestDOMPasteAccess()) |
976 | return false; |
977 | |
978 | frame.editor().pasteAsQuotation(); |
979 | return true; |
980 | } |
981 | |
982 | static bool executePrint(Frame& frame, Event*, EditorCommandSource, const String&) |
983 | { |
984 | Page* page = frame.page(); |
985 | if (!page) |
986 | return false; |
987 | return page->chrome().print(frame); |
988 | } |
989 | |
990 | static bool executeRedo(Frame& frame, Event*, EditorCommandSource, const String&) |
991 | { |
992 | frame.editor().redo(); |
993 | return true; |
994 | } |
995 | |
996 | static bool executeRemoveFormat(Frame& frame, Event*, EditorCommandSource, const String&) |
997 | { |
998 | frame.editor().removeFormattingAndStyle(); |
999 | return true; |
1000 | } |
1001 | |
1002 | static bool executeScrollPageBackward(Frame& frame, Event*, EditorCommandSource, const String&) |
1003 | { |
1004 | return frame.eventHandler().logicalScrollRecursively(ScrollBlockDirectionBackward, ScrollByPage); |
1005 | } |
1006 | |
1007 | static bool executeScrollPageForward(Frame& frame, Event*, EditorCommandSource, const String&) |
1008 | { |
1009 | return frame.eventHandler().logicalScrollRecursively(ScrollBlockDirectionForward, ScrollByPage); |
1010 | } |
1011 | |
1012 | static bool executeScrollLineUp(Frame& frame, Event*, EditorCommandSource, const String&) |
1013 | { |
1014 | return frame.eventHandler().scrollRecursively(ScrollUp, ScrollByLine); |
1015 | } |
1016 | |
1017 | static bool executeScrollLineDown(Frame& frame, Event*, EditorCommandSource, const String&) |
1018 | { |
1019 | return frame.eventHandler().scrollRecursively(ScrollDown, ScrollByLine); |
1020 | } |
1021 | |
1022 | static bool executeScrollToBeginningOfDocument(Frame& frame, Event*, EditorCommandSource, const String&) |
1023 | { |
1024 | return frame.eventHandler().logicalScrollRecursively(ScrollBlockDirectionBackward, ScrollByDocument); |
1025 | } |
1026 | |
1027 | static bool executeScrollToEndOfDocument(Frame& frame, Event*, EditorCommandSource, const String&) |
1028 | { |
1029 | return frame.eventHandler().logicalScrollRecursively(ScrollBlockDirectionForward, ScrollByDocument); |
1030 | } |
1031 | |
1032 | static bool executeSelectAll(Frame& frame, Event*, EditorCommandSource, const String&) |
1033 | { |
1034 | frame.selection().selectAll(); |
1035 | return true; |
1036 | } |
1037 | |
1038 | static bool executeSelectLine(Frame& frame, Event*, EditorCommandSource, const String&) |
1039 | { |
1040 | return expandSelectionToGranularity(frame, LineGranularity); |
1041 | } |
1042 | |
1043 | static bool executeSelectParagraph(Frame& frame, Event*, EditorCommandSource, const String&) |
1044 | { |
1045 | return expandSelectionToGranularity(frame, ParagraphGranularity); |
1046 | } |
1047 | |
1048 | static bool executeSelectSentence(Frame& frame, Event*, EditorCommandSource, const String&) |
1049 | { |
1050 | return expandSelectionToGranularity(frame, SentenceGranularity); |
1051 | } |
1052 | |
1053 | static bool executeSelectToMark(Frame& frame, Event*, EditorCommandSource, const String&) |
1054 | { |
1055 | RefPtr<Range> mark = frame.editor().mark().toNormalizedRange(); |
1056 | RefPtr<Range> selection = frame.editor().selectedRange(); |
1057 | if (!mark || !selection) { |
1058 | PAL::systemBeep(); |
1059 | return false; |
1060 | } |
1061 | frame.selection().setSelectedRange(unionDOMRanges(*mark, *selection).get(), DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes); |
1062 | return true; |
1063 | } |
1064 | |
1065 | static bool executeSelectWord(Frame& frame, Event*, EditorCommandSource, const String&) |
1066 | { |
1067 | return expandSelectionToGranularity(frame, WordGranularity); |
1068 | } |
1069 | |
1070 | static bool executeSetMark(Frame& frame, Event*, EditorCommandSource, const String&) |
1071 | { |
1072 | frame.editor().setMark(frame.selection().selection()); |
1073 | return true; |
1074 | } |
1075 | |
1076 | static TextDecorationChange textDecorationChangeForToggling(Editor& editor, CSSPropertyID propertyID, const char* onValue) |
1077 | { |
1078 | return isStylePresent(editor, propertyID, onValue) ? TextDecorationChange::Remove : TextDecorationChange::Add; |
1079 | } |
1080 | |
1081 | static bool executeStrikethrough(Frame& frame, Event*, EditorCommandSource source, const String&) |
1082 | { |
1083 | Ref<EditingStyle> style = EditingStyle::create(); |
1084 | style->setStrikeThroughChange(textDecorationChangeForToggling(frame.editor(), CSSPropertyWebkitTextDecorationsInEffect, "line-through"_s )); |
1085 | // FIXME: Needs a new EditAction! |
1086 | return applyCommandToFrame(frame, source, EditAction::Underline, WTFMove(style)); |
1087 | } |
1088 | |
1089 | static bool executeStyleWithCSS(Frame& frame, Event*, EditorCommandSource, const String& value) |
1090 | { |
1091 | frame.editor().setShouldStyleWithCSS(!equalLettersIgnoringASCIICase(value, "false" )); |
1092 | return true; |
1093 | } |
1094 | |
1095 | static bool executeUseCSS(Frame& frame, Event*, EditorCommandSource, const String& value) |
1096 | { |
1097 | frame.editor().setShouldStyleWithCSS(equalLettersIgnoringASCIICase(value, "false" )); |
1098 | return true; |
1099 | } |
1100 | |
1101 | static bool executeSubscript(Frame& frame, Event*, EditorCommandSource source, const String&) |
1102 | { |
1103 | return executeToggleStyle(frame, source, EditAction::Subscript, CSSPropertyVerticalAlign, "baseline"_s , "sub"_s ); |
1104 | } |
1105 | |
1106 | static bool executeSuperscript(Frame& frame, Event*, EditorCommandSource source, const String&) |
1107 | { |
1108 | return executeToggleStyle(frame, source, EditAction::Superscript, CSSPropertyVerticalAlign, "baseline"_s , "super"_s ); |
1109 | } |
1110 | |
1111 | static bool executeSwapWithMark(Frame& frame, Event*, EditorCommandSource, const String&) |
1112 | { |
1113 | Ref<Frame> protector(frame); |
1114 | const VisibleSelection& mark = frame.editor().mark(); |
1115 | const VisibleSelection& selection = frame.selection().selection(); |
1116 | if (mark.isNone() || selection.isNone()) { |
1117 | PAL::systemBeep(); |
1118 | return false; |
1119 | } |
1120 | frame.selection().setSelection(mark); |
1121 | frame.editor().setMark(selection); |
1122 | return true; |
1123 | } |
1124 | |
1125 | #if PLATFORM(COCOA) |
1126 | |
1127 | static bool executeTakeFindStringFromSelection(Frame& frame, Event*, EditorCommandSource, const String&) |
1128 | { |
1129 | frame.editor().takeFindStringFromSelection(); |
1130 | return true; |
1131 | } |
1132 | |
1133 | #endif // PLATFORM(COCOA) |
1134 | |
1135 | static bool executeToggleBold(Frame& frame, Event*, EditorCommandSource source, const String&) |
1136 | { |
1137 | return executeToggleStyle(frame, source, EditAction::Bold, CSSPropertyFontWeight, "normal"_s , "bold"_s ); |
1138 | } |
1139 | |
1140 | static bool executeToggleItalic(Frame& frame, Event*, EditorCommandSource source, const String&) |
1141 | { |
1142 | return executeToggleStyle(frame, source, EditAction::Italics, CSSPropertyFontStyle, "normal"_s , "italic"_s ); |
1143 | } |
1144 | |
1145 | static bool executeTranspose(Frame& frame, Event*, EditorCommandSource, const String&) |
1146 | { |
1147 | frame.editor().transpose(); |
1148 | return true; |
1149 | } |
1150 | |
1151 | static bool executeUnderline(Frame& frame, Event*, EditorCommandSource source, const String&) |
1152 | { |
1153 | Ref<EditingStyle> style = EditingStyle::create(); |
1154 | TextDecorationChange change = textDecorationChangeForToggling(frame.editor(), CSSPropertyWebkitTextDecorationsInEffect, "underline"_s ); |
1155 | style->setUnderlineChange(change); |
1156 | return applyCommandToFrame(frame, source, EditAction::Underline, WTFMove(style)); |
1157 | } |
1158 | |
1159 | static bool executeUndo(Frame& frame, Event*, EditorCommandSource, const String&) |
1160 | { |
1161 | frame.editor().undo(); |
1162 | return true; |
1163 | } |
1164 | |
1165 | static bool executeUnlink(Frame& frame, Event*, EditorCommandSource, const String&) |
1166 | { |
1167 | ASSERT(frame.document()); |
1168 | UnlinkCommand::create(*frame.document())->apply(); |
1169 | return true; |
1170 | } |
1171 | |
1172 | static bool executeUnscript(Frame& frame, Event*, EditorCommandSource source, const String&) |
1173 | { |
1174 | return executeApplyStyle(frame, source, EditAction::Unscript, CSSPropertyVerticalAlign, "baseline"_s ); |
1175 | } |
1176 | |
1177 | static bool executeUnselect(Frame& frame, Event*, EditorCommandSource, const String&) |
1178 | { |
1179 | frame.selection().clear(); |
1180 | return true; |
1181 | } |
1182 | |
1183 | static bool executeYank(Frame& frame, Event*, EditorCommandSource, const String&) |
1184 | { |
1185 | frame.editor().insertTextWithoutSendingTextEvent(frame.editor().killRing().yank(), false, 0); |
1186 | frame.editor().killRing().setToYankedState(); |
1187 | return true; |
1188 | } |
1189 | |
1190 | static bool executeYankAndSelect(Frame& frame, Event*, EditorCommandSource, const String&) |
1191 | { |
1192 | frame.editor().insertTextWithoutSendingTextEvent(frame.editor().killRing().yank(), true, 0); |
1193 | frame.editor().killRing().setToYankedState(); |
1194 | return true; |
1195 | } |
1196 | |
1197 | // Supported functions |
1198 | |
1199 | static bool supported(Frame*) |
1200 | { |
1201 | return true; |
1202 | } |
1203 | |
1204 | static bool (Frame*) |
1205 | { |
1206 | return false; |
1207 | } |
1208 | |
1209 | static bool defaultValueForSupportedCopyCut(Frame& frame) |
1210 | { |
1211 | auto& settings = frame.settings(); |
1212 | if (settings.javaScriptCanAccessClipboard()) |
1213 | return true; |
1214 | |
1215 | switch (settings.clipboardAccessPolicy()) { |
1216 | case ClipboardAccessPolicy::Allow: |
1217 | case ClipboardAccessPolicy::RequiresUserGesture: |
1218 | return true; |
1219 | case ClipboardAccessPolicy::Deny: |
1220 | return false; |
1221 | } |
1222 | |
1223 | ASSERT_NOT_REACHED(); |
1224 | return false; |
1225 | } |
1226 | |
1227 | static bool supportedCopyCut(Frame* frame) |
1228 | { |
1229 | if (!frame) |
1230 | return false; |
1231 | |
1232 | bool defaultValue = defaultValueForSupportedCopyCut(*frame); |
1233 | |
1234 | EditorClient* client = frame->editor().client(); |
1235 | return client ? client->canCopyCut(frame, defaultValue) : defaultValue; |
1236 | } |
1237 | |
1238 | static bool supportedPaste(Frame* frame) |
1239 | { |
1240 | if (!frame) |
1241 | return false; |
1242 | |
1243 | auto& settings = frame->settings(); |
1244 | bool defaultValue = (settings.javaScriptCanAccessClipboard() && settings.DOMPasteAllowed()) || settings.domPasteAccessRequestsEnabled(); |
1245 | |
1246 | EditorClient* client = frame->editor().client(); |
1247 | return client ? client->canPaste(frame, defaultValue) : defaultValue; |
1248 | } |
1249 | |
1250 | // Enabled functions |
1251 | |
1252 | static bool enabled(Frame&, Event*, EditorCommandSource) |
1253 | { |
1254 | return true; |
1255 | } |
1256 | |
1257 | static bool enabledVisibleSelection(Frame& frame, Event* event, EditorCommandSource) |
1258 | { |
1259 | // The term "visible" here includes a caret in editable text or a range in any text. |
1260 | const VisibleSelection& selection = frame.editor().selectionForCommand(event); |
1261 | return (selection.isCaret() && selection.isContentEditable()) || selection.isRange(); |
1262 | } |
1263 | |
1264 | static bool caretBrowsingEnabled(Frame& frame) |
1265 | { |
1266 | return frame.settings().caretBrowsingEnabled(); |
1267 | } |
1268 | |
1269 | static EditorCommandSource dummyEditorCommandSource = static_cast<EditorCommandSource>(0); |
1270 | |
1271 | static bool enabledVisibleSelectionOrCaretBrowsing(Frame& frame, Event* event, EditorCommandSource) |
1272 | { |
1273 | // The EditorCommandSource parameter is unused in enabledVisibleSelection, so just pass a dummy variable |
1274 | return caretBrowsingEnabled(frame) || enabledVisibleSelection(frame, event, dummyEditorCommandSource); |
1275 | } |
1276 | |
1277 | static bool enabledVisibleSelectionAndMark(Frame& frame, Event* event, EditorCommandSource) |
1278 | { |
1279 | const VisibleSelection& selection = frame.editor().selectionForCommand(event); |
1280 | return ((selection.isCaret() && selection.isContentEditable()) || selection.isRange()) |
1281 | && frame.editor().mark().isCaretOrRange(); |
1282 | } |
1283 | |
1284 | static bool enableCaretInEditableText(Frame& frame, Event* event, EditorCommandSource) |
1285 | { |
1286 | const VisibleSelection& selection = frame.editor().selectionForCommand(event); |
1287 | return selection.isCaret() && selection.isContentEditable(); |
1288 | } |
1289 | |
1290 | static bool allowCopyCutFromDOM(Frame& frame) |
1291 | { |
1292 | auto& settings = frame.settings(); |
1293 | if (settings.javaScriptCanAccessClipboard()) |
1294 | return true; |
1295 | |
1296 | switch (settings.clipboardAccessPolicy()) { |
1297 | case ClipboardAccessPolicy::Allow: |
1298 | return true; |
1299 | case ClipboardAccessPolicy::Deny: |
1300 | return false; |
1301 | case ClipboardAccessPolicy::RequiresUserGesture: |
1302 | return UserGestureIndicator::processingUserGesture(); |
1303 | } |
1304 | |
1305 | ASSERT_NOT_REACHED(); |
1306 | return false; |
1307 | } |
1308 | |
1309 | static bool enabledCopy(Frame& frame, Event*, EditorCommandSource source) |
1310 | { |
1311 | switch (source) { |
1312 | case CommandFromMenuOrKeyBinding: |
1313 | return frame.editor().canDHTMLCopy() || frame.editor().canCopy(); |
1314 | case CommandFromDOM: |
1315 | case CommandFromDOMWithUserInterface: |
1316 | return allowCopyCutFromDOM(frame) && (frame.editor().canDHTMLCopy() || frame.editor().canCopy()); |
1317 | } |
1318 | ASSERT_NOT_REACHED(); |
1319 | return false; |
1320 | } |
1321 | |
1322 | static bool enabledCut(Frame& frame, Event*, EditorCommandSource source) |
1323 | { |
1324 | switch (source) { |
1325 | case CommandFromMenuOrKeyBinding: |
1326 | return frame.editor().canDHTMLCut() || frame.editor().canCut(); |
1327 | case CommandFromDOM: |
1328 | case CommandFromDOMWithUserInterface: |
1329 | return allowCopyCutFromDOM(frame) && (frame.editor().canDHTMLCut() || frame.editor().canCut()); |
1330 | } |
1331 | ASSERT_NOT_REACHED(); |
1332 | return false; |
1333 | } |
1334 | |
1335 | static bool enabledClearText(Frame& frame, Event*, EditorCommandSource) |
1336 | { |
1337 | UNUSED_PARAM(frame); |
1338 | return false; |
1339 | } |
1340 | |
1341 | static bool enabledInEditableText(Frame& frame, Event* event, EditorCommandSource) |
1342 | { |
1343 | return frame.editor().selectionForCommand(event).rootEditableElement(); |
1344 | } |
1345 | |
1346 | static bool enabledDelete(Frame& frame, Event* event, EditorCommandSource source) |
1347 | { |
1348 | switch (source) { |
1349 | case CommandFromMenuOrKeyBinding: |
1350 | return frame.editor().canDelete(); |
1351 | case CommandFromDOM: |
1352 | case CommandFromDOMWithUserInterface: |
1353 | // "Delete" from DOM is like delete/backspace keypress, affects selected range if non-empty, |
1354 | // otherwise removes a character |
1355 | return enabledInEditableText(frame, event, source); |
1356 | } |
1357 | ASSERT_NOT_REACHED(); |
1358 | return false; |
1359 | } |
1360 | |
1361 | static bool enabledInEditableTextOrCaretBrowsing(Frame& frame, Event* event, EditorCommandSource) |
1362 | { |
1363 | // The EditorCommandSource parameter is unused in enabledInEditableText, so just pass a dummy variable |
1364 | return caretBrowsingEnabled(frame) || enabledInEditableText(frame, event, dummyEditorCommandSource); |
1365 | } |
1366 | |
1367 | static bool enabledInRichlyEditableText(Frame& frame, Event*, EditorCommandSource) |
1368 | { |
1369 | const VisibleSelection& selection = frame.selection().selection(); |
1370 | return selection.isCaretOrRange() && selection.isContentRichlyEditable() && selection.rootEditableElement(); |
1371 | } |
1372 | |
1373 | static bool enabledPaste(Frame& frame, Event*, EditorCommandSource) |
1374 | { |
1375 | return frame.editor().canPaste(); |
1376 | } |
1377 | |
1378 | static bool enabledRangeInEditableText(Frame& frame, Event*, EditorCommandSource) |
1379 | { |
1380 | return frame.selection().isRange() && frame.selection().selection().isContentEditable(); |
1381 | } |
1382 | |
1383 | static bool enabledRangeInRichlyEditableText(Frame& frame, Event*, EditorCommandSource) |
1384 | { |
1385 | return frame.selection().isRange() && frame.selection().selection().isContentRichlyEditable(); |
1386 | } |
1387 | |
1388 | static bool enabledRedo(Frame& frame, Event*, EditorCommandSource) |
1389 | { |
1390 | return frame.editor().canRedo(); |
1391 | } |
1392 | |
1393 | #if PLATFORM(COCOA) |
1394 | |
1395 | static bool enabledTakeFindStringFromSelection(Frame& frame, Event*, EditorCommandSource) |
1396 | { |
1397 | return frame.editor().canCopyExcludingStandaloneImages(); |
1398 | } |
1399 | |
1400 | #endif // PLATFORM(COCOA) |
1401 | |
1402 | static bool enabledUndo(Frame& frame, Event*, EditorCommandSource) |
1403 | { |
1404 | return frame.editor().canUndo(); |
1405 | } |
1406 | |
1407 | static bool enabledInRichlyEditableTextWithEditableImagesEnabled(Frame& frame, Event* event, EditorCommandSource source) |
1408 | { |
1409 | if (!frame.settings().editableImagesEnabled()) |
1410 | return false; |
1411 | return enabledInRichlyEditableText(frame, event, source); |
1412 | } |
1413 | |
1414 | // State functions |
1415 | |
1416 | static TriState stateNone(Frame&, Event*) |
1417 | { |
1418 | return FalseTriState; |
1419 | } |
1420 | |
1421 | static TriState stateBold(Frame& frame, Event*) |
1422 | { |
1423 | return stateStyle(frame, CSSPropertyFontWeight, "bold"_s ); |
1424 | } |
1425 | |
1426 | static TriState stateItalic(Frame& frame, Event*) |
1427 | { |
1428 | return stateStyle(frame, CSSPropertyFontStyle, "italic"_s ); |
1429 | } |
1430 | |
1431 | static TriState stateOrderedList(Frame& frame, Event*) |
1432 | { |
1433 | return frame.editor().selectionOrderedListState(); |
1434 | } |
1435 | |
1436 | static TriState stateStrikethrough(Frame& frame, Event*) |
1437 | { |
1438 | return stateStyle(frame, CSSPropertyWebkitTextDecorationsInEffect, "line-through"_s ); |
1439 | } |
1440 | |
1441 | static TriState stateStyleWithCSS(Frame& frame, Event*) |
1442 | { |
1443 | return frame.editor().shouldStyleWithCSS() ? TrueTriState : FalseTriState; |
1444 | } |
1445 | |
1446 | static TriState stateSubscript(Frame& frame, Event*) |
1447 | { |
1448 | return stateStyle(frame, CSSPropertyVerticalAlign, "sub"_s ); |
1449 | } |
1450 | |
1451 | static TriState stateSuperscript(Frame& frame, Event*) |
1452 | { |
1453 | return stateStyle(frame, CSSPropertyVerticalAlign, "super"_s ); |
1454 | } |
1455 | |
1456 | static TriState stateTextWritingDirectionLeftToRight(Frame& frame, Event*) |
1457 | { |
1458 | return stateTextWritingDirection(frame, WritingDirection::LeftToRight); |
1459 | } |
1460 | |
1461 | static TriState stateTextWritingDirectionNatural(Frame& frame, Event*) |
1462 | { |
1463 | return stateTextWritingDirection(frame, WritingDirection::Natural); |
1464 | } |
1465 | |
1466 | static TriState stateTextWritingDirectionRightToLeft(Frame& frame, Event*) |
1467 | { |
1468 | return stateTextWritingDirection(frame, WritingDirection::RightToLeft); |
1469 | } |
1470 | |
1471 | static TriState stateUnderline(Frame& frame, Event*) |
1472 | { |
1473 | return stateStyle(frame, CSSPropertyWebkitTextDecorationsInEffect, "underline"_s ); |
1474 | } |
1475 | |
1476 | static TriState stateUnorderedList(Frame& frame, Event*) |
1477 | { |
1478 | return frame.editor().selectionUnorderedListState(); |
1479 | } |
1480 | |
1481 | static TriState stateJustifyCenter(Frame& frame, Event*) |
1482 | { |
1483 | return stateStyle(frame, CSSPropertyTextAlign, "center"_s ); |
1484 | } |
1485 | |
1486 | static TriState stateJustifyFull(Frame& frame, Event*) |
1487 | { |
1488 | return stateStyle(frame, CSSPropertyTextAlign, "justify"_s ); |
1489 | } |
1490 | |
1491 | static TriState stateJustifyLeft(Frame& frame, Event*) |
1492 | { |
1493 | return stateStyle(frame, CSSPropertyTextAlign, "left"_s ); |
1494 | } |
1495 | |
1496 | static TriState stateJustifyRight(Frame& frame, Event*) |
1497 | { |
1498 | return stateStyle(frame, CSSPropertyTextAlign, "right"_s ); |
1499 | } |
1500 | |
1501 | // Value functions |
1502 | |
1503 | static String valueNull(Frame&, Event*) |
1504 | { |
1505 | return String(); |
1506 | } |
1507 | |
1508 | static String valueBackColor(Frame& frame, Event*) |
1509 | { |
1510 | return valueStyle(frame, CSSPropertyBackgroundColor); |
1511 | } |
1512 | |
1513 | static String valueDefaultParagraphSeparator(Frame& frame, Event*) |
1514 | { |
1515 | switch (frame.editor().defaultParagraphSeparator()) { |
1516 | case EditorParagraphSeparatorIsDiv: |
1517 | return divTag->localName(); |
1518 | case EditorParagraphSeparatorIsP: |
1519 | return pTag->localName(); |
1520 | } |
1521 | |
1522 | ASSERT_NOT_REACHED(); |
1523 | return String(); |
1524 | } |
1525 | |
1526 | static String valueFontName(Frame& frame, Event*) |
1527 | { |
1528 | return valueStyle(frame, CSSPropertyFontFamily); |
1529 | } |
1530 | |
1531 | static String valueFontSize(Frame& frame, Event*) |
1532 | { |
1533 | return valueStyle(frame, CSSPropertyFontSize); |
1534 | } |
1535 | |
1536 | static String valueFontSizeDelta(Frame& frame, Event*) |
1537 | { |
1538 | return valueStyle(frame, CSSPropertyWebkitFontSizeDelta); |
1539 | } |
1540 | |
1541 | static String valueForeColor(Frame& frame, Event*) |
1542 | { |
1543 | return valueStyle(frame, CSSPropertyColor); |
1544 | } |
1545 | |
1546 | static String valueFormatBlock(Frame& frame, Event*) |
1547 | { |
1548 | const VisibleSelection& selection = frame.selection().selection(); |
1549 | if (selection.isNoneOrOrphaned() || !selection.isContentEditable()) |
1550 | return emptyString(); |
1551 | Element* formatBlockElement = FormatBlockCommand::elementForFormatBlockCommand(selection.firstRange().get()); |
1552 | if (!formatBlockElement) |
1553 | return emptyString(); |
1554 | return formatBlockElement->localName(); |
1555 | } |
1556 | |
1557 | // allowExecutionWhenDisabled functions |
1558 | |
1559 | static bool allowExecutionWhenDisabled(Frame&, EditorCommandSource) |
1560 | { |
1561 | return true; |
1562 | } |
1563 | |
1564 | static bool doNotAllowExecutionWhenDisabled(Frame&, EditorCommandSource) |
1565 | { |
1566 | return false; |
1567 | } |
1568 | |
1569 | static bool allowExecutionWhenDisabledCopyCut(Frame&, EditorCommandSource source) |
1570 | { |
1571 | switch (source) { |
1572 | case CommandFromMenuOrKeyBinding: |
1573 | return true; |
1574 | case CommandFromDOM: |
1575 | case CommandFromDOMWithUserInterface: |
1576 | return false; |
1577 | } |
1578 | |
1579 | ASSERT_NOT_REACHED(); |
1580 | return false; |
1581 | } |
1582 | |
1583 | static bool allowExecutionWhenDisabledPaste(Frame& frame, EditorCommandSource) |
1584 | { |
1585 | if (frame.mainFrame().loader().shouldSuppressTextInputFromEditing()) |
1586 | return false; |
1587 | return true; |
1588 | } |
1589 | |
1590 | // Map of functions |
1591 | |
1592 | struct CommandEntry { |
1593 | const char* name; |
1594 | EditorInternalCommand command; |
1595 | }; |
1596 | |
1597 | static const CommandMap& createCommandMap() |
1598 | { |
1599 | static const CommandEntry commands[] = { |
1600 | { "AlignCenter" , { executeJustifyCenter, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1601 | { "AlignJustified" , { executeJustifyFull, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1602 | { "AlignLeft" , { executeJustifyLeft, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1603 | { "AlignRight" , { executeJustifyRight, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1604 | { "BackColor" , { executeBackColor, supported, enabledInRichlyEditableText, stateNone, valueBackColor, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1605 | { "Bold" , { executeToggleBold, supported, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1606 | { "ClearText" , { executeClearText, supported, enabledClearText, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } }, |
1607 | { "Copy" , { executeCopy, supportedCopyCut, enabledCopy, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabledCopyCut } }, |
1608 | { "CreateLink" , { executeCreateLink, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1609 | { "Cut" , { executeCut, supportedCopyCut, enabledCut, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabledCopyCut } }, |
1610 | { "DefaultParagraphSeparator" , { executeDefaultParagraphSeparator, supported, enabled, stateNone, valueDefaultParagraphSeparator, notTextInsertion, doNotAllowExecutionWhenDisabled} }, |
1611 | { "Delete" , { executeDelete, supported, enabledDelete, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1612 | { "DeleteBackward" , { executeDeleteBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1613 | { "DeleteBackwardByDecomposingPreviousCharacter" , { executeDeleteBackwardByDecomposingPreviousCharacter, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1614 | { "DeleteForward" , { executeDeleteForward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1615 | { "DeleteToBeginningOfLine" , { executeDeleteToBeginningOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1616 | { "DeleteToBeginningOfParagraph" , { executeDeleteToBeginningOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1617 | { "DeleteToEndOfLine" , { executeDeleteToEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1618 | { "DeleteToEndOfParagraph" , { executeDeleteToEndOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1619 | { "DeleteToMark" , { executeDeleteToMark, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1620 | { "DeleteWordBackward" , { executeDeleteWordBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1621 | { "DeleteWordForward" , { executeDeleteWordForward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1622 | { "FindString" , { executeFindString, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1623 | { "FontName" , { executeFontName, supported, enabledInEditableText, stateNone, valueFontName, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1624 | { "FontSize" , { executeFontSize, supported, enabledInEditableText, stateNone, valueFontSize, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1625 | { "FontSizeDelta" , { executeFontSizeDelta, supported, enabledInEditableText, stateNone, valueFontSizeDelta, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1626 | { "ForeColor" , { executeForeColor, supported, enabledInRichlyEditableText, stateNone, valueForeColor, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1627 | { "FormatBlock" , { executeFormatBlock, supported, enabledInRichlyEditableText, stateNone, valueFormatBlock, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1628 | { "ForwardDelete" , { executeForwardDelete, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1629 | { "HiliteColor" , { executeBackColor, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1630 | { "IgnoreSpelling" , { executeIgnoreSpelling, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1631 | { "Indent" , { executeIndent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1632 | { "InsertBacktab" , { executeInsertBacktab, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1633 | { "InsertEditableImage" , { executeInsertEditableImage, supported, enabledInRichlyEditableTextWithEditableImagesEnabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1634 | { "InsertHTML" , { executeInsertHTML, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1635 | { "InsertHorizontalRule" , { executeInsertHorizontalRule, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1636 | { "InsertImage" , { executeInsertImage, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1637 | { "InsertLineBreak" , { executeInsertLineBreak, supported, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1638 | { "InsertNewline" , { executeInsertNewline, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1639 | { "InsertNewlineInQuotedContent" , { executeInsertNewlineInQuotedContent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1640 | { "InsertOrderedList" , { executeInsertOrderedList, supported, enabledInRichlyEditableText, stateOrderedList, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1641 | { "InsertNestedOrderedList" , { executeInsertNestedOrderedList, supported, enabledInRichlyEditableText, stateOrderedList, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1642 | { "InsertParagraph" , { executeInsertParagraph, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1643 | { "InsertTab" , { executeInsertTab, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1644 | { "InsertText" , { executeInsertText, supported, enabledInEditableText, stateNone, valueNull, isTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1645 | { "InsertUnorderedList" , { executeInsertUnorderedList, supported, enabledInRichlyEditableText, stateUnorderedList, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1646 | { "InsertNestedUnorderedList" , { executeInsertNestedUnorderedList, supported, enabledInRichlyEditableText, stateUnorderedList, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1647 | { "Italic" , { executeToggleItalic, supported, enabledInRichlyEditableText, stateItalic, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1648 | { "JustifyCenter" , { executeJustifyCenter, supported, enabledInRichlyEditableText, stateJustifyCenter, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1649 | { "JustifyFull" , { executeJustifyFull, supported, enabledInRichlyEditableText, stateJustifyFull, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1650 | { "JustifyLeft" , { executeJustifyLeft, supported, enabledInRichlyEditableText, stateJustifyLeft, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1651 | { "JustifyNone" , { executeJustifyLeft, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1652 | { "JustifyRight" , { executeJustifyRight, supported, enabledInRichlyEditableText, stateJustifyRight, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1653 | { "MakeTextWritingDirectionLeftToRight" , { executeMakeTextWritingDirectionLeftToRight, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionLeftToRight, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1654 | { "MakeTextWritingDirectionNatural" , { executeMakeTextWritingDirectionNatural, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionNatural, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1655 | { "MakeTextWritingDirectionRightToLeft" , { executeMakeTextWritingDirectionRightToLeft, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateTextWritingDirectionRightToLeft, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1656 | { "MoveBackward" , { executeMoveBackward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1657 | { "MoveBackwardAndModifySelection" , { executeMoveBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1658 | { "MoveDown" , { executeMoveDown, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1659 | { "MoveDownAndModifySelection" , { executeMoveDownAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1660 | { "MoveForward" , { executeMoveForward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1661 | { "MoveForwardAndModifySelection" , { executeMoveForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1662 | { "MoveLeft" , { executeMoveLeft, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1663 | { "MoveLeftAndModifySelection" , { executeMoveLeftAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1664 | { "MovePageDown" , { executeMovePageDown, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1665 | { "MovePageDownAndModifySelection" , { executeMovePageDownAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1666 | { "MovePageUp" , { executeMovePageUp, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1667 | { "MovePageUpAndModifySelection" , { executeMovePageUpAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1668 | { "MoveParagraphBackwardAndModifySelection" , { executeMoveParagraphBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1669 | { "MoveParagraphForwardAndModifySelection" , { executeMoveParagraphForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1670 | { "MoveRight" , { executeMoveRight, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1671 | { "MoveRightAndModifySelection" , { executeMoveRightAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1672 | { "MoveToBeginningOfDocument" , { executeMoveToBeginningOfDocument, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1673 | { "MoveToBeginningOfDocumentAndModifySelection" , { executeMoveToBeginningOfDocumentAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1674 | { "MoveToBeginningOfLine" , { executeMoveToBeginningOfLine, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1675 | { "MoveToBeginningOfLineAndModifySelection" , { executeMoveToBeginningOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1676 | { "MoveToBeginningOfParagraph" , { executeMoveToBeginningOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1677 | { "MoveToBeginningOfParagraphAndModifySelection" , { executeMoveToBeginningOfParagraphAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1678 | { "MoveToBeginningOfSentence" , { executeMoveToBeginningOfSentence, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1679 | { "MoveToBeginningOfSentenceAndModifySelection" , { executeMoveToBeginningOfSentenceAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1680 | { "MoveToEndOfDocument" , { executeMoveToEndOfDocument, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1681 | { "MoveToEndOfDocumentAndModifySelection" , { executeMoveToEndOfDocumentAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1682 | { "MoveToEndOfLine" , { executeMoveToEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1683 | { "MoveToEndOfLineAndModifySelection" , { executeMoveToEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1684 | { "MoveToEndOfParagraph" , { executeMoveToEndOfParagraph, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1685 | { "MoveToEndOfParagraphAndModifySelection" , { executeMoveToEndOfParagraphAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1686 | { "MoveToEndOfSentence" , { executeMoveToEndOfSentence, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1687 | { "MoveToEndOfSentenceAndModifySelection" , { executeMoveToEndOfSentenceAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1688 | { "MoveToLeftEndOfLine" , { executeMoveToLeftEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1689 | { "MoveToLeftEndOfLineAndModifySelection" , { executeMoveToLeftEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1690 | { "MoveToRightEndOfLine" , { executeMoveToRightEndOfLine, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1691 | { "MoveToRightEndOfLineAndModifySelection" , { executeMoveToRightEndOfLineAndModifySelection, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1692 | { "MoveUp" , { executeMoveUp, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1693 | { "MoveUpAndModifySelection" , { executeMoveUpAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1694 | { "MoveWordBackward" , { executeMoveWordBackward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1695 | { "MoveWordBackwardAndModifySelection" , { executeMoveWordBackwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1696 | { "MoveWordForward" , { executeMoveWordForward, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1697 | { "MoveWordForwardAndModifySelection" , { executeMoveWordForwardAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1698 | { "MoveWordLeft" , { executeMoveWordLeft, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1699 | { "MoveWordLeftAndModifySelection" , { executeMoveWordLeftAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1700 | { "MoveWordRight" , { executeMoveWordRight, supportedFromMenuOrKeyBinding, enabledInEditableTextOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1701 | { "MoveWordRightAndModifySelection" , { executeMoveWordRightAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1702 | { "Outdent" , { executeOutdent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1703 | { "OverWrite" , { executeToggleOverwrite, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1704 | { "Paste" , { executePaste, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabledPaste } }, |
1705 | { "PasteAndMatchStyle" , { executePasteAndMatchStyle, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabledPaste } }, |
1706 | { "PasteAsPlainText" , { executePasteAsPlainText, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabledPaste } }, |
1707 | { "PasteAsQuotation" , { executePasteAsQuotation, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabledPaste } }, |
1708 | { "Print" , { executePrint, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1709 | { "Redo" , { executeRedo, supported, enabledRedo, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1710 | { "RemoveFormat" , { executeRemoveFormat, supported, enabledRangeInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1711 | { "ScrollPageBackward" , { executeScrollPageBackward, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1712 | { "ScrollPageForward" , { executeScrollPageForward, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1713 | { "ScrollLineUp" , { executeScrollLineUp, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1714 | { "ScrollLineDown" , { executeScrollLineDown, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1715 | { "ScrollToBeginningOfDocument" , { executeScrollToBeginningOfDocument, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1716 | { "ScrollToEndOfDocument" , { executeScrollToEndOfDocument, supportedFromMenuOrKeyBinding, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1717 | { "SelectAll" , { executeSelectAll, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1718 | { "SelectLine" , { executeSelectLine, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1719 | { "SelectParagraph" , { executeSelectParagraph, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1720 | { "SelectSentence" , { executeSelectSentence, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1721 | { "SelectToMark" , { executeSelectToMark, supportedFromMenuOrKeyBinding, enabledVisibleSelectionAndMark, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1722 | { "SelectWord" , { executeSelectWord, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1723 | { "SetMark" , { executeSetMark, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1724 | { "Strikethrough" , { executeStrikethrough, supported, enabledInRichlyEditableText, stateStrikethrough, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1725 | { "StyleWithCSS" , { executeStyleWithCSS, supported, enabled, stateStyleWithCSS, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1726 | { "Subscript" , { executeSubscript, supported, enabledInRichlyEditableText, stateSubscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1727 | { "Superscript" , { executeSuperscript, supported, enabledInRichlyEditableText, stateSuperscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1728 | { "SwapWithMark" , { executeSwapWithMark, supportedFromMenuOrKeyBinding, enabledVisibleSelectionAndMark, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1729 | { "ToggleBold" , { executeToggleBold, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1730 | { "ToggleItalic" , { executeToggleItalic, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateItalic, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1731 | { "ToggleUnderline" , { executeUnderline, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateUnderline, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1732 | { "Transpose" , { executeTranspose, supported, enableCaretInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1733 | { "Underline" , { executeUnderline, supported, enabledInRichlyEditableText, stateUnderline, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1734 | { "Undo" , { executeUndo, supported, enabledUndo, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1735 | { "Unlink" , { executeUnlink, supported, enabledRangeInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1736 | { "Unscript" , { executeUnscript, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1737 | { "Unselect" , { executeUnselect, supported, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1738 | { "UseCSS" , { executeUseCSS, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1739 | { "Yank" , { executeYank, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1740 | { "YankAndSelect" , { executeYankAndSelect, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1741 | |
1742 | #if PLATFORM(GTK) |
1743 | { "PasteGlobalSelection" , { executePasteGlobalSelection, supportedFromMenuOrKeyBinding, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } }, |
1744 | #endif |
1745 | |
1746 | #if PLATFORM(COCOA) |
1747 | { "TakeFindStringFromSelection" , { executeTakeFindStringFromSelection, supportedFromMenuOrKeyBinding, enabledTakeFindStringFromSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
1748 | #endif |
1749 | }; |
1750 | |
1751 | // These unsupported commands are listed here since they appear in the Microsoft |
1752 | // documentation used as the starting point for our DOM executeCommand support. |
1753 | // |
1754 | // 2D-Position (not supported) |
1755 | // AbsolutePosition (not supported) |
1756 | // BlockDirLTR (not supported) |
1757 | // BlockDirRTL (not supported) |
1758 | // BrowseMode (not supported) |
1759 | // ClearAuthenticationCache (not supported) |
1760 | // CreateBookmark (not supported) |
1761 | // DirLTR (not supported) |
1762 | // DirRTL (not supported) |
1763 | // EditMode (not supported) |
1764 | // InlineDirLTR (not supported) |
1765 | // InlineDirRTL (not supported) |
1766 | // InsertButton (not supported) |
1767 | // InsertFieldSet (not supported) |
1768 | // InsertIFrame (not supported) |
1769 | // InsertInputButton (not supported) |
1770 | // InsertInputCheckbox (not supported) |
1771 | // InsertInputFileUpload (not supported) |
1772 | // InsertInputHidden (not supported) |
1773 | // InsertInputImage (not supported) |
1774 | // InsertInputPassword (not supported) |
1775 | // InsertInputRadio (not supported) |
1776 | // InsertInputReset (not supported) |
1777 | // InsertInputSubmit (not supported) |
1778 | // InsertInputText (not supported) |
1779 | // InsertMarquee (not supported) |
1780 | // InsertSelectDropDown (not supported) |
1781 | // InsertSelectListBox (not supported) |
1782 | // InsertTextArea (not supported) |
1783 | // LiveResize (not supported) |
1784 | // MultipleSelection (not supported) |
1785 | // Open (not supported) |
1786 | // PlayImage (not supported) |
1787 | // Refresh (not supported) |
1788 | // RemoveParaFormat (not supported) |
1789 | // SaveAs (not supported) |
1790 | // SizeToControl (not supported) |
1791 | // SizeToControlHeight (not supported) |
1792 | // SizeToControlWidth (not supported) |
1793 | // Stop (not supported) |
1794 | // StopImage (not supported) |
1795 | // Unbookmark (not supported) |
1796 | |
1797 | CommandMap& commandMap = *new CommandMap; |
1798 | |
1799 | for (auto& command : commands) { |
1800 | ASSERT(!commandMap.get(command.name)); |
1801 | commandMap.set(command.name, &command.command); |
1802 | } |
1803 | |
1804 | return commandMap; |
1805 | } |
1806 | |
1807 | static const EditorInternalCommand* internalCommand(const String& commandName) |
1808 | { |
1809 | static const CommandMap& commandMap = createCommandMap(); |
1810 | return commandName.isEmpty() ? 0 : commandMap.get(commandName); |
1811 | } |
1812 | |
1813 | Editor::Command Editor::command(const String& commandName) |
1814 | { |
1815 | return Command(internalCommand(commandName), CommandFromMenuOrKeyBinding, m_frame); |
1816 | } |
1817 | |
1818 | Editor::Command Editor::command(const String& commandName, EditorCommandSource source) |
1819 | { |
1820 | return Command(internalCommand(commandName), source, m_frame); |
1821 | } |
1822 | |
1823 | bool Editor::commandIsSupportedFromMenuOrKeyBinding(const String& commandName) |
1824 | { |
1825 | return internalCommand(commandName); |
1826 | } |
1827 | |
1828 | Editor::Command::Command() |
1829 | { |
1830 | } |
1831 | |
1832 | Editor::Command::Command(const EditorInternalCommand* command, EditorCommandSource source, Frame& frame) |
1833 | : m_command(command) |
1834 | , m_source(source) |
1835 | , m_frame(command ? &frame : nullptr) |
1836 | { |
1837 | ASSERT(command || !m_frame); |
1838 | } |
1839 | |
1840 | bool Editor::Command::execute(const String& parameter, Event* triggeringEvent) const |
1841 | { |
1842 | if (!isEnabled(triggeringEvent)) { |
1843 | // Let certain commands be executed when performed explicitly even if they are disabled. |
1844 | if (!allowExecutionWhenDisabled()) |
1845 | return false; |
1846 | } |
1847 | auto document = m_frame->document(); |
1848 | document->updateLayoutIgnorePendingStylesheets(); |
1849 | if (m_frame->document() != document) |
1850 | return false; |
1851 | |
1852 | return m_command->execute(*m_frame, triggeringEvent, m_source, parameter); |
1853 | } |
1854 | |
1855 | bool Editor::Command::execute(Event* triggeringEvent) const |
1856 | { |
1857 | return execute(String(), triggeringEvent); |
1858 | } |
1859 | |
1860 | bool Editor::Command::isSupported() const |
1861 | { |
1862 | if (!m_command) |
1863 | return false; |
1864 | switch (m_source) { |
1865 | case CommandFromMenuOrKeyBinding: |
1866 | return true; |
1867 | case CommandFromDOM: |
1868 | case CommandFromDOMWithUserInterface: |
1869 | return m_command->isSupportedFromDOM(m_frame.get()); |
1870 | } |
1871 | ASSERT_NOT_REACHED(); |
1872 | return false; |
1873 | } |
1874 | |
1875 | bool Editor::Command::isEnabled(Event* triggeringEvent) const |
1876 | { |
1877 | if (!isSupported() || !m_frame) |
1878 | return false; |
1879 | return m_command->isEnabled(*m_frame, triggeringEvent, m_source); |
1880 | } |
1881 | |
1882 | TriState Editor::Command::state(Event* triggeringEvent) const |
1883 | { |
1884 | if (!isSupported() || !m_frame) |
1885 | return FalseTriState; |
1886 | return m_command->state(*m_frame, triggeringEvent); |
1887 | } |
1888 | |
1889 | String Editor::Command::value(Event* triggeringEvent) const |
1890 | { |
1891 | if (!isSupported() || !m_frame) |
1892 | return String(); |
1893 | if (m_command->value == valueNull && m_command->state != stateNone) |
1894 | return m_command->state(*m_frame, triggeringEvent) == TrueTriState ? "true"_s : "false"_s ; |
1895 | return m_command->value(*m_frame, triggeringEvent); |
1896 | } |
1897 | |
1898 | bool Editor::Command::isTextInsertion() const |
1899 | { |
1900 | return m_command && m_command->isTextInsertion; |
1901 | } |
1902 | |
1903 | bool Editor::Command::allowExecutionWhenDisabled() const |
1904 | { |
1905 | if (!isSupported() || !m_frame) |
1906 | return false; |
1907 | return m_command->allowExecutionWhenDisabled(*m_frame, m_source); |
1908 | } |
1909 | |
1910 | } // namespace WebCore |
1911 | |