OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
4 * Copyright (C) 2009 Igalia S.L. | 4 * Copyright (C) 2009 Igalia S.L. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 case CommandType::DeleteToBeginningOfParagraph: | 154 case CommandType::DeleteToBeginningOfParagraph: |
155 case CommandType::DeleteToEndOfParagraph: | 155 case CommandType::DeleteToEndOfParagraph: |
156 case CommandType::DeleteToMark: | 156 case CommandType::DeleteToMark: |
157 return InputType::None; | 157 return InputType::None; |
158 | 158 |
159 // Command. | 159 // Command. |
160 case CommandType::Undo: | 160 case CommandType::Undo: |
161 return InputType::Undo; | 161 return InputType::Undo; |
162 case CommandType::Redo: | 162 case CommandType::Redo: |
163 return InputType::Redo; | 163 return InputType::Redo; |
164 case CommandType::Copy: | 164 // Cut and Paste will be handled in |Editor::dispatchCPPEvent()|. |
165 return InputType::Copy; | |
166 case CommandType::Cut: | |
167 return InputType::Cut; | |
168 case CommandType::Paste: | |
169 return InputType::Paste; | |
170 | 165 |
171 // Styling. | 166 // Styling. |
172 case CommandType::Bold: | 167 case CommandType::Bold: |
173 case CommandType::ToggleBold: | 168 case CommandType::ToggleBold: |
174 return InputType::Bold; | 169 return InputType::Bold; |
175 case CommandType::Italic: | 170 case CommandType::Italic: |
176 case CommandType::ToggleItalic: | 171 case CommandType::ToggleItalic: |
177 return InputType::Italic; | 172 return InputType::Italic; |
178 case CommandType::Underline: | 173 case CommandType::Underline: |
179 case CommandType::ToggleUnderline: | 174 case CommandType::ToggleUnderline: |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
472 | 467 |
473 static bool executeCut(LocalFrame& frame, Event*, EditorCommandSource source, co nst String&) | 468 static bool executeCut(LocalFrame& frame, Event*, EditorCommandSource source, co nst String&) |
474 { | 469 { |
475 // To support |allowExecutionWhenDisabled|, we need to check clipboard | 470 // To support |allowExecutionWhenDisabled|, we need to check clipboard |
476 // accessibility here rather than |Editor::Command::execute()|. | 471 // accessibility here rather than |Editor::Command::execute()|. |
477 // TODO(yosin) We should move checking |canWriteClipboard()| to | 472 // TODO(yosin) We should move checking |canWriteClipboard()| to |
478 // |Editor::Command::execute()| with introducing appropriate predicate, e.g. | 473 // |Editor::Command::execute()| with introducing appropriate predicate, e.g. |
479 // |canExecute()|. See also "Copy", and "Paste" command. | 474 // |canExecute()|. See also "Copy", and "Paste" command. |
480 if (!canWriteClipboard(frame, source)) | 475 if (!canWriteClipboard(frame, source)) |
481 return false; | 476 return false; |
482 frame.editor().cut(); | 477 frame.editor().cut(source); |
483 return true; | 478 return true; |
484 } | 479 } |
485 | 480 |
486 static bool executeDefaultParagraphSeparator(LocalFrame& frame, Event*, EditorCo mmandSource, const String& value) | 481 static bool executeDefaultParagraphSeparator(LocalFrame& frame, Event*, EditorCo mmandSource, const String& value) |
487 { | 482 { |
488 if (equalIgnoringCase(value, "div")) | 483 if (equalIgnoringCase(value, "div")) |
489 frame.editor().setDefaultParagraphSeparator(EditorParagraphSeparatorIsDi v); | 484 frame.editor().setDefaultParagraphSeparator(EditorParagraphSeparatorIsDi v); |
490 else if (equalIgnoringCase(value, "p")) | 485 else if (equalIgnoringCase(value, "p")) |
491 frame.editor().setDefaultParagraphSeparator(EditorParagraphSeparatorIsP) ; | 486 frame.editor().setDefaultParagraphSeparator(EditorParagraphSeparatorIsP) ; |
492 | 487 |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1119 | 1114 |
1120 static bool executePaste(LocalFrame& frame, Event*, EditorCommandSource source, const String&) | 1115 static bool executePaste(LocalFrame& frame, Event*, EditorCommandSource source, const String&) |
1121 { | 1116 { |
1122 // To support |allowExecutionWhenDisabled|, we need to check clipboard | 1117 // To support |allowExecutionWhenDisabled|, we need to check clipboard |
1123 // accessibility here rather than |Editor::Command::execute()|. | 1118 // accessibility here rather than |Editor::Command::execute()|. |
1124 // TODO(yosin) We should move checking |canReadClipboard()| to | 1119 // TODO(yosin) We should move checking |canReadClipboard()| to |
1125 // |Editor::Command::execute()| with introducing appropriate predicate, e.g. | 1120 // |Editor::Command::execute()| with introducing appropriate predicate, e.g. |
1126 // |canExecute()|. See also "Copy", and "Cut" command. | 1121 // |canExecute()|. See also "Copy", and "Cut" command. |
1127 if (!canReadClipboard(frame, source)) | 1122 if (!canReadClipboard(frame, source)) |
1128 return false; | 1123 return false; |
1129 frame.editor().paste(); | 1124 frame.editor().paste(source); |
1130 return true; | 1125 return true; |
1131 } | 1126 } |
1132 | 1127 |
1133 static bool executePasteGlobalSelection(LocalFrame& frame, Event*, EditorCommand Source source, const String&) | 1128 static bool executePasteGlobalSelection(LocalFrame& frame, Event*, EditorCommand Source source, const String&) |
1134 { | 1129 { |
1135 // To support |allowExecutionWhenDisabled|, we need to check clipboard | 1130 // To support |allowExecutionWhenDisabled|, we need to check clipboard |
1136 // accessibility here rather than |Editor::Command::execute()|. | 1131 // accessibility here rather than |Editor::Command::execute()|. |
1137 // TODO(yosin) We should move checking |canReadClipboard()| to | 1132 // TODO(yosin) We should move checking |canReadClipboard()| to |
1138 // |Editor::Command::execute()| with introducing appropriate predicate, e.g. | 1133 // |Editor::Command::execute()| with introducing appropriate predicate, e.g. |
1139 // |canExecute()|. See also "Copy", and "Cut" command. | 1134 // |canExecute()|. See also "Copy", and "Cut" command. |
1140 if (!canReadClipboard(frame, source)) | 1135 if (!canReadClipboard(frame, source)) |
1141 return false; | 1136 return false; |
1142 if (!frame.editor().behavior().supportsGlobalSelection()) | 1137 if (!frame.editor().behavior().supportsGlobalSelection()) |
1143 return false; | 1138 return false; |
1144 ASSERT_UNUSED(source, source == CommandFromMenuOrKeyBinding); | 1139 ASSERT_UNUSED(source, source == CommandFromMenuOrKeyBinding); |
1145 | 1140 |
1146 bool oldSelectionMode = Pasteboard::generalPasteboard()->isSelectionMode(); | 1141 bool oldSelectionMode = Pasteboard::generalPasteboard()->isSelectionMode(); |
1147 Pasteboard::generalPasteboard()->setSelectionMode(true); | 1142 Pasteboard::generalPasteboard()->setSelectionMode(true); |
1148 frame.editor().paste(); | 1143 frame.editor().paste(source); |
1149 Pasteboard::generalPasteboard()->setSelectionMode(oldSelectionMode); | 1144 Pasteboard::generalPasteboard()->setSelectionMode(oldSelectionMode); |
1150 return true; | 1145 return true; |
1151 } | 1146 } |
1152 | 1147 |
1153 static bool executePasteAndMatchStyle(LocalFrame& frame, Event*, EditorCommandSo urce, const String&) | 1148 static bool executePasteAndMatchStyle(LocalFrame& frame, Event*, EditorCommandSo urce source, const String&) |
1154 { | 1149 { |
1155 frame.editor().pasteAsPlainText(); | 1150 frame.editor().pasteAsPlainText(source); |
1156 return true; | 1151 return true; |
1157 } | 1152 } |
1158 | 1153 |
1159 static bool executePrint(LocalFrame& frame, Event*, EditorCommandSource, const S tring&) | 1154 static bool executePrint(LocalFrame& frame, Event*, EditorCommandSource, const S tring&) |
1160 { | 1155 { |
1161 FrameHost* host = frame.host(); | 1156 FrameHost* host = frame.host(); |
1162 if (!host) | 1157 if (!host) |
1163 return false; | 1158 return false; |
1164 host->chromeClient().print(&frame); | 1159 host->chromeClient().print(&frame); |
1165 return true; | 1160 return true; |
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1879 } | 1874 } |
1880 | 1875 |
1881 if (m_source == CommandFromMenuOrKeyBinding) { | 1876 if (m_source == CommandFromMenuOrKeyBinding) { |
1882 InputEvent::InputType inputType = InputTypeFromCommandType(m_command->co mmandType, *m_frame); | 1877 InputEvent::InputType inputType = InputTypeFromCommandType(m_command->co mmandType, *m_frame); |
1883 if (inputType != InputEvent::InputType::None) { | 1878 if (inputType != InputEvent::InputType::None) { |
1884 if (dispatchBeforeInputEditorCommand(eventTargetNodeForDocument(m_fr ame->document()), inputType, emptyString(), getRanges()) != DispatchEventResult: :NotCanceled) | 1879 if (dispatchBeforeInputEditorCommand(eventTargetNodeForDocument(m_fr ame->document()), inputType, emptyString(), getRanges()) != DispatchEventResult: :NotCanceled) |
1885 return true; | 1880 return true; |
1886 } | 1881 } |
1887 } | 1882 } |
1888 | 1883 |
1889 // 'beforeinput' event handler may destroy |frame()|. | 1884 // 'beforeinput' event handler may destroy target frame. |
1890 if (!m_frame || !frame().document()) | 1885 if (!m_frame->document()->frame()) |
chongz
2016/08/24 01:43:27
Same here for other editing commands.
| |
1891 return false; | 1886 return false; |
1892 | 1887 |
1893 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 1888 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
1894 DEFINE_STATIC_LOCAL(SparseHistogram, commandHistogram, ("WebCore.Editing.Com mands")); | 1889 DEFINE_STATIC_LOCAL(SparseHistogram, commandHistogram, ("WebCore.Editing.Com mands")); |
1895 commandHistogram.sample(static_cast<int>(m_command->commandType)); | 1890 commandHistogram.sample(static_cast<int>(m_command->commandType)); |
1896 return m_command->execute(*m_frame, triggeringEvent, m_source, parameter); | 1891 return m_command->execute(*m_frame, triggeringEvent, m_source, parameter); |
1897 } | 1892 } |
1898 | 1893 |
1899 bool Editor::Command::execute(Event* triggeringEvent) const | 1894 bool Editor::Command::execute(Event* triggeringEvent) const |
1900 { | 1895 { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1970 case WebEditingCommandType::DeleteWordBackward: | 1965 case WebEditingCommandType::DeleteWordBackward: |
1971 return RangesFromCurrentSelectionOrExtendCaret(*m_frame, DirectionBackwa rd, WordGranularity); | 1966 return RangesFromCurrentSelectionOrExtendCaret(*m_frame, DirectionBackwa rd, WordGranularity); |
1972 case WebEditingCommandType::DeleteWordForward: | 1967 case WebEditingCommandType::DeleteWordForward: |
1973 return RangesFromCurrentSelectionOrExtendCaret(*m_frame, DirectionForwar d, WordGranularity); | 1968 return RangesFromCurrentSelectionOrExtendCaret(*m_frame, DirectionForwar d, WordGranularity); |
1974 default: | 1969 default: |
1975 return nullptr; | 1970 return nullptr; |
1976 } | 1971 } |
1977 } | 1972 } |
1978 | 1973 |
1979 } // namespace blink | 1974 } // namespace blink |
OLD | NEW |