| 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 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 class EditorInternalCommand; | 50 class EditorInternalCommand; |
| 51 class LocalFrame; | 51 class LocalFrame; |
| 52 class HitTestResult; | 52 class HitTestResult; |
| 53 class KillRing; | 53 class KillRing; |
| 54 class Pasteboard; | 54 class Pasteboard; |
| 55 class SpellChecker; | 55 class SpellChecker; |
| 56 class StylePropertySet; | 56 class StylePropertySet; |
| 57 class TextEvent; | 57 class TextEvent; |
| 58 class UndoStack; | 58 class UndoStack; |
| 59 | 59 |
| 60 enum class CommandSource; |
| 60 enum class DeleteDirection; | 61 enum class DeleteDirection; |
| 61 enum class DeleteMode { Simple, Smart }; | 62 enum class DeleteMode { Simple, Smart }; |
| 62 enum class InsertMode { Simple, Smart }; | 63 enum class InsertMode { Simple, Smart }; |
| 63 enum class DragSourceType { HTMLSource, PlainTextSource }; | 64 enum class DragSourceType { HTMLSource, PlainTextSource }; |
| 64 | 65 |
| 65 enum EditorCommandSource { CommandFromMenuOrKeyBinding, CommandFromDOM }; | |
| 66 enum EditorParagraphSeparator { | 66 enum EditorParagraphSeparator { |
| 67 EditorParagraphSeparatorIsDiv, | 67 EditorParagraphSeparatorIsDiv, |
| 68 EditorParagraphSeparatorIsP | 68 EditorParagraphSeparatorIsP |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 class CORE_EXPORT Editor final : public GarbageCollectedFinalized<Editor> { | 71 class CORE_EXPORT Editor final : public GarbageCollectedFinalized<Editor> { |
| 72 WTF_MAKE_NONCOPYABLE(Editor); | 72 WTF_MAKE_NONCOPYABLE(Editor); |
| 73 | 73 |
| 74 public: | 74 public: |
| 75 static Editor* create(LocalFrame&); | 75 static Editor* create(LocalFrame&); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 87 | 87 |
| 88 bool canDHTMLCut(); | 88 bool canDHTMLCut(); |
| 89 bool canDHTMLCopy(); | 89 bool canDHTMLCopy(); |
| 90 | 90 |
| 91 bool canCut() const; | 91 bool canCut() const; |
| 92 bool canCopy() const; | 92 bool canCopy() const; |
| 93 bool canPaste() const; | 93 bool canPaste() const; |
| 94 bool canDelete() const; | 94 bool canDelete() const; |
| 95 bool canSmartCopyOrDelete() const; | 95 bool canSmartCopyOrDelete() const; |
| 96 | 96 |
| 97 void cut(EditorCommandSource); | 97 void cut(CommandSource); |
| 98 void copy(); | 98 void copy(); |
| 99 void paste(EditorCommandSource); | 99 void paste(CommandSource); |
| 100 void pasteAsPlainText(EditorCommandSource); | 100 void pasteAsPlainText(CommandSource); |
| 101 void performDelete(); | 101 void performDelete(CommandSource); |
| 102 | 102 |
| 103 static void countEvent(ExecutionContext*, const Event*); | 103 static void countEvent(ExecutionContext*, const Event*); |
| 104 void copyImage(const HitTestResult&); | 104 void copyImage(const HitTestResult&); |
| 105 | 105 |
| 106 void transpose(); | 106 void transpose(CommandSource); |
| 107 | 107 |
| 108 void respondToChangedContents(const VisibleSelection& endingSelection); | 108 void respondToChangedContents(const VisibleSelection& endingSelection); |
| 109 | 109 |
| 110 bool selectionStartHasStyle(CSSPropertyID, const String& value) const; | 110 bool selectionStartHasStyle(CSSPropertyID, const String& value) const; |
| 111 TriState selectionHasStyle(CSSPropertyID, const String& value) const; | 111 TriState selectionHasStyle(CSSPropertyID, const String& value) const; |
| 112 String selectionStartCSSPropertyValue(CSSPropertyID); | 112 String selectionStartCSSPropertyValue(CSSPropertyID); |
| 113 | 113 |
| 114 void removeFormattingAndStyle(); | 114 void removeFormattingAndStyle(CommandSource); |
| 115 | 115 |
| 116 void registerCommandGroup(CompositeEditCommand* commandGroupWrapper); | 116 void registerCommandGroup(CompositeEditCommand* commandGroupWrapper); |
| 117 void clearLastEditCommand(); | 117 void clearLastEditCommand(); |
| 118 | 118 |
| 119 bool deleteWithDirection(DeleteDirection, | 119 bool deleteWithDirection(CommandSource, |
| 120 DeleteDirection, |
| 120 TextGranularity, | 121 TextGranularity, |
| 121 bool killRing, | 122 bool killRing, |
| 122 bool isTypingAction); | 123 bool isTypingAction); |
| 123 void deleteSelectionWithSmartDelete( | 124 void deleteSelectionWithSmartDelete( |
| 125 CommandSource, |
| 124 DeleteMode, | 126 DeleteMode, |
| 125 InputEvent::InputType, | 127 InputEvent::InputType, |
| 126 const Position& referenceMovePosition = Position()); | 128 const Position& referenceMovePosition = Position()); |
| 127 | 129 |
| 128 void applyStyle(StylePropertySet*, InputEvent::InputType); | 130 void applyStyle(CommandSource, StylePropertySet*, InputEvent::InputType); |
| 129 void applyParagraphStyle(StylePropertySet*, InputEvent::InputType); | 131 void applyParagraphStyle(CommandSource, |
| 130 void applyStyleToSelection(StylePropertySet*, InputEvent::InputType); | 132 StylePropertySet*, |
| 131 void applyParagraphStyleToSelection(StylePropertySet*, InputEvent::InputType); | 133 InputEvent::InputType); |
| 134 void applyStyleToSelection(CommandSource, |
| 135 StylePropertySet*, |
| 136 InputEvent::InputType); |
| 137 void applyParagraphStyleToSelection(CommandSource, |
| 138 StylePropertySet*, |
| 139 InputEvent::InputType); |
| 132 | 140 |
| 133 void appliedEditing(CompositeEditCommand*); | 141 void appliedEditing(CompositeEditCommand*); |
| 134 void unappliedEditing(EditCommandComposition*); | 142 void unappliedEditing(EditCommandComposition*); |
| 135 void reappliedEditing(EditCommandComposition*); | 143 void reappliedEditing(EditCommandComposition*); |
| 136 | 144 |
| 137 void setShouldStyleWithCSS(bool flag) { m_shouldStyleWithCSS = flag; } | 145 void setShouldStyleWithCSS(bool flag) { m_shouldStyleWithCSS = flag; } |
| 138 bool shouldStyleWithCSS() const { return m_shouldStyleWithCSS; } | 146 bool shouldStyleWithCSS() const { return m_shouldStyleWithCSS; } |
| 139 | 147 |
| 140 class CORE_EXPORT Command { | 148 class CORE_EXPORT Command { |
| 141 STACK_ALLOCATED(); | 149 STACK_ALLOCATED(); |
| 142 | 150 |
| 143 public: | 151 public: |
| 144 Command(); | 152 Command(); |
| 145 Command(const EditorInternalCommand*, EditorCommandSource, LocalFrame*); | 153 Command(const EditorInternalCommand*, CommandSource, LocalFrame*); |
| 146 | 154 |
| 147 bool execute(const String& parameter = String(), | 155 bool execute(const String& parameter = String(), |
| 148 Event* triggeringEvent = nullptr) const; | 156 Event* triggeringEvent = nullptr) const; |
| 149 bool execute(Event* triggeringEvent) const; | 157 bool execute(Event* triggeringEvent) const; |
| 150 | 158 |
| 151 bool isSupported() const; | 159 bool isSupported() const; |
| 152 bool isEnabled(Event* triggeringEvent = nullptr) const; | 160 bool isEnabled(Event* triggeringEvent = nullptr) const; |
| 153 | 161 |
| 154 TriState state(Event* triggeringEvent = nullptr) const; | 162 TriState state(Event* triggeringEvent = nullptr) const; |
| 155 String value(Event* triggeringEvent = nullptr) const; | 163 String value(Event* triggeringEvent = nullptr) const; |
| 156 | 164 |
| 157 bool isTextInsertion() const; | 165 bool isTextInsertion() const; |
| 158 | 166 |
| 159 // Returns 0 if this Command is not supported. | 167 // Returns 0 if this Command is not supported. |
| 160 int idForHistogram() const; | 168 int idForHistogram() const; |
| 161 | 169 |
| 162 private: | 170 private: |
| 163 LocalFrame& frame() const { | 171 LocalFrame& frame() const { |
| 164 DCHECK(m_frame); | 172 DCHECK(m_frame); |
| 165 return *m_frame; | 173 return *m_frame; |
| 166 } | 174 } |
| 167 | 175 |
| 168 // Returns target ranges for the command, currently only supports delete | 176 // Returns target ranges for the command, currently only supports delete |
| 169 // related commands. Used by InputEvent. | 177 // related commands. Used by InputEvent. |
| 170 RangeVector* getTargetRanges() const; | 178 RangeVector* getTargetRanges() const; |
| 171 | 179 |
| 172 const EditorInternalCommand* m_command; | 180 const EditorInternalCommand* m_command; |
| 173 EditorCommandSource m_source; | 181 CommandSource m_source; |
| 174 Member<LocalFrame> m_frame; | 182 Member<LocalFrame> m_frame; |
| 175 }; | 183 }; |
| 176 Command createCommand( | 184 // Command source is |CommandSource::MenuOrKeyBinding|. |
| 177 const String& | 185 Command createCommand(const String& commandName); |
| 178 commandName); // Command source is CommandFromMenuOrKeyBinding. | 186 // Command source is |CommandSource::DOM|. |
| 179 Command createCommand(const String& commandName, EditorCommandSource); | 187 Command createCommandFromDOM(const String& commandName); |
| 180 | 188 |
| 181 // |Editor::executeCommand| is implementation of |WebFrame::executeCommand| | 189 // |Editor::executeCommand| is implementation of |WebFrame::executeCommand| |
| 182 // rather than |Document::execCommand|. | 190 // rather than |Document::execCommand|. |
| 183 bool executeCommand(const String&); | 191 bool executeCommand(const String&); |
| 184 bool executeCommand(const String& commandName, const String& value); | 192 bool executeCommand(const String& commandName, const String& value); |
| 185 | 193 |
| 186 bool insertText(const String&, KeyboardEvent* triggeringEvent); | 194 bool insertText(const String&, KeyboardEvent* triggeringEvent); |
| 187 bool insertTextWithoutSendingTextEvent(const String&, | 195 bool insertTextWithoutSendingTextEvent(CommandSource, |
| 196 const String&, |
| 188 bool selectInsertedText, | 197 bool selectInsertedText, |
| 189 TextEvent* triggeringEvent); | 198 TextEvent* triggeringEvent); |
| 190 bool insertLineBreak(); | 199 bool insertLineBreak(); |
| 191 bool insertParagraphSeparator(); | 200 bool insertParagraphSeparator(); |
| 192 | 201 |
| 193 bool isOverwriteModeEnabled() const { return m_overwriteModeEnabled; } | 202 bool isOverwriteModeEnabled() const { return m_overwriteModeEnabled; } |
| 194 void toggleOverwriteModeEnabled(); | 203 void toggleOverwriteModeEnabled(); |
| 195 | 204 |
| 196 bool canUndo(); | 205 bool canUndo(); |
| 197 void undo(); | 206 void undo(CommandSource); |
| 198 bool canRedo(); | 207 bool canRedo(); |
| 199 void redo(); | 208 void redo(CommandSource); |
| 200 | 209 |
| 201 void setBaseWritingDirection(WritingDirection); | 210 void setBaseWritingDirection(WritingDirection); |
| 202 | 211 |
| 203 // smartInsertDeleteEnabled and selectTrailingWhitespaceEnabled are | 212 // smartInsertDeleteEnabled and selectTrailingWhitespaceEnabled are |
| 204 // mutually exclusive, meaning that enabling one will disable the other. | 213 // mutually exclusive, meaning that enabling one will disable the other. |
| 205 bool smartInsertDeleteEnabled() const; | 214 bool smartInsertDeleteEnabled() const; |
| 206 bool isSelectTrailingWhitespaceEnabled() const; | 215 bool isSelectTrailingWhitespaceEnabled() const; |
| 207 | 216 |
| 208 bool preventRevealSelection() const { return m_preventRevealSelection; } | 217 bool preventRevealSelection() const { return m_preventRevealSelection; } |
| 209 | 218 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 233 Range* findRangeOfString(const String& target, | 242 Range* findRangeOfString(const String& target, |
| 234 const EphemeralRange& referenceRange, | 243 const EphemeralRange& referenceRange, |
| 235 FindOptions); | 244 FindOptions); |
| 236 Range* findRangeOfString(const String& target, | 245 Range* findRangeOfString(const String& target, |
| 237 const EphemeralRangeInFlatTree& referenceRange, | 246 const EphemeralRangeInFlatTree& referenceRange, |
| 238 FindOptions); | 247 FindOptions); |
| 239 | 248 |
| 240 const VisibleSelection& mark() const; // Mark, to be used as emacs uses it. | 249 const VisibleSelection& mark() const; // Mark, to be used as emacs uses it. |
| 241 void setMark(const VisibleSelection&); | 250 void setMark(const VisibleSelection&); |
| 242 | 251 |
| 243 void computeAndSetTypingStyle(StylePropertySet*, InputEvent::InputType); | 252 void computeAndSetTypingStyle(CommandSource, |
| 253 StylePropertySet*, |
| 254 InputEvent::InputType); |
| 244 | 255 |
| 245 // |firstRectForRange| requires up-to-date layout. | 256 // |firstRectForRange| requires up-to-date layout. |
| 246 IntRect firstRectForRange(const EphemeralRange&) const; | 257 IntRect firstRectForRange(const EphemeralRange&) const; |
| 247 | 258 |
| 248 void respondToChangedSelection(const Position& oldSelectionStart, | 259 void respondToChangedSelection(const Position& oldSelectionStart, |
| 249 FrameSelection::SetSelectionOptions); | 260 FrameSelection::SetSelectionOptions); |
| 250 | 261 |
| 251 bool markedTextMatchesAreHighlighted() const; | 262 bool markedTextMatchesAreHighlighted() const; |
| 252 void setMarkedTextMatchesAreHighlighted(bool); | 263 void setMarkedTextMatchesAreHighlighted(bool); |
| 253 | 264 |
| 254 void replaceSelectionWithFragment(DocumentFragment*, | 265 void replaceSelectionWithFragment(CommandSource, |
| 266 DocumentFragment*, |
| 255 bool selectReplacement, | 267 bool selectReplacement, |
| 256 bool smartReplace, | 268 bool smartReplace, |
| 257 bool matchStyle, | 269 bool matchStyle, |
| 258 InputEvent::InputType); | 270 InputEvent::InputType); |
| 259 void replaceSelectionWithText(const String&, | 271 void replaceSelectionWithText(CommandSource, |
| 272 const String&, |
| 260 bool selectReplacement, | 273 bool selectReplacement, |
| 261 bool smartReplace, | 274 bool smartReplace, |
| 262 InputEvent::InputType); | 275 InputEvent::InputType); |
| 263 | 276 |
| 264 // TODO(xiaochengh): Replace |bool| parameters by |enum|. | 277 // TODO(xiaochengh): Replace |bool| parameters by |enum|. |
| 265 void replaceSelectionAfterDragging(DocumentFragment*, | 278 void replaceSelectionAfterDragging(DocumentFragment*, |
| 266 InsertMode, | 279 InsertMode, |
| 267 DragSourceType); | 280 DragSourceType); |
| 268 | 281 |
| 269 // Return false if frame was destroyed by event handler, should stop executing | 282 // Return false if frame was destroyed by event handler, should stop executing |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 m_mark = selection; | 375 m_mark = selection; |
| 363 } | 376 } |
| 364 | 377 |
| 365 inline bool Editor::markedTextMatchesAreHighlighted() const { | 378 inline bool Editor::markedTextMatchesAreHighlighted() const { |
| 366 return m_areMarkedTextMatchesHighlighted; | 379 return m_areMarkedTextMatchesHighlighted; |
| 367 } | 380 } |
| 368 | 381 |
| 369 } // namespace blink | 382 } // namespace blink |
| 370 | 383 |
| 371 #endif // Editor_h | 384 #endif // Editor_h |
| OLD | NEW |