| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 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 25 matching lines...) Expand all Loading... |
| 36 namespace blink { | 36 namespace blink { |
| 37 | 37 |
| 38 class EditingStyle; | 38 class EditingStyle; |
| 39 class Element; | 39 class Element; |
| 40 class HTMLBRElement; | 40 class HTMLBRElement; |
| 41 class HTMLElement; | 41 class HTMLElement; |
| 42 class HTMLSpanElement; | 42 class HTMLSpanElement; |
| 43 class Text; | 43 class Text; |
| 44 | 44 |
| 45 enum class EditCommandSource { kMenuOrKeyBinding, kDOM }; | 45 enum class EditCommandSource { kMenuOrKeyBinding, kDOM }; |
| 46 // TODO(chongz): Remove after we have moved all 'beforeinput' logic here. |
| 47 // https://crbug.com/670035. |
| 48 enum class BeforeInputTiming { kHasFiredBeforeCommand, kShouldFireInCommand }; |
| 46 | 49 |
| 47 class EditCommandComposition final : public UndoStep { | 50 class EditCommandComposition final : public UndoStep { |
| 48 public: | 51 public: |
| 49 static EditCommandComposition* create(Document*, | 52 static EditCommandComposition* create(Document*, |
| 50 const VisibleSelection&, | 53 const VisibleSelection&, |
| 51 const VisibleSelection&); | 54 const VisibleSelection&); |
| 52 | 55 |
| 53 bool belongsTo(const LocalFrame&) const override; | 56 bool belongsTo(const LocalFrame&) const override; |
| 54 void unapply(EditCommandSource) override; | 57 void unapply(EditCommandSource) override; |
| 55 void reapply(EditCommandSource) override; | 58 void reapply(EditCommandSource) override; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 74 private: | 77 private: |
| 75 EditCommandComposition(Document*, | 78 EditCommandComposition(Document*, |
| 76 const VisibleSelection& startingSelection, | 79 const VisibleSelection& startingSelection, |
| 77 const VisibleSelection& endingSelection); | 80 const VisibleSelection& endingSelection); |
| 78 | 81 |
| 79 // TODO(chongz): Implement "beforeinput" as described below: | 82 // TODO(chongz): Implement "beforeinput" as described below: |
| 80 // Fires "beforeinput" and will returns |false| to cancel unapply / reapply if | 83 // Fires "beforeinput" and will returns |false| to cancel unapply / reapply if |
| 81 // * "beforeinput" was canceled, or | 84 // * "beforeinput" was canceled, or |
| 82 // * |frame| was destroyed by event handlers. | 85 // * |frame| was destroyed by event handlers. |
| 83 // Note: Undo stack will always get popped. | 86 // Note: Undo stack will always get popped. |
| 84 bool willUnapply(EditCommandSource); | 87 bool willUnapply(EditCommandSource, BeforeInputTiming); |
| 85 bool willReapply(EditCommandSource); | 88 bool willReapply(EditCommandSource, BeforeInputTiming); |
| 86 | 89 |
| 87 Member<Document> m_document; | 90 Member<Document> m_document; |
| 88 VisibleSelection m_startingSelection; | 91 VisibleSelection m_startingSelection; |
| 89 VisibleSelection m_endingSelection; | 92 VisibleSelection m_endingSelection; |
| 90 HeapVector<Member<SimpleEditCommand>> m_commands; | 93 HeapVector<Member<SimpleEditCommand>> m_commands; |
| 91 Member<Element> m_startingRootEditableElement; | 94 Member<Element> m_startingRootEditableElement; |
| 92 Member<Element> m_endingRootEditableElement; | 95 Member<Element> m_endingRootEditableElement; |
| 93 }; | 96 }; |
| 94 | 97 |
| 95 class CORE_EXPORT CompositeEditCommand : public EditCommand { | 98 class CORE_EXPORT CompositeEditCommand : public EditCommand { |
| 96 public: | 99 public: |
| 97 enum ShouldPreserveSelection { PreserveSelection, DoNotPreserveSelection }; | 100 enum ShouldPreserveSelection { PreserveSelection, DoNotPreserveSelection }; |
| 98 enum ShouldPreserveStyle { PreserveStyle, DoNotPreserveStyle }; | 101 enum ShouldPreserveStyle { PreserveStyle, DoNotPreserveStyle }; |
| 99 | 102 |
| 100 ~CompositeEditCommand() override; | 103 ~CompositeEditCommand() override; |
| 101 | 104 |
| 102 // Returns |false| if the command failed. e.g. It's aborted. | 105 // Returns |false| if the command failed. e.g. It's aborted. |
| 103 bool apply(EditCommandSource); | 106 bool apply(EditCommandSource, |
| 107 BeforeInputTiming = BeforeInputTiming::kHasFiredBeforeCommand); |
| 104 bool isFirstCommand(EditCommand* command) { | 108 bool isFirstCommand(EditCommand* command) { |
| 105 return !m_commands.isEmpty() && m_commands.front() == command; | 109 return !m_commands.isEmpty() && m_commands.front() == command; |
| 106 } | 110 } |
| 107 EditCommandComposition* composition() { return m_composition.get(); } | 111 EditCommandComposition* composition() { return m_composition.get(); } |
| 108 EditCommandComposition* ensureComposition(); | 112 EditCommandComposition* ensureComposition(); |
| 109 // Append composition from an already applied command. | 113 // Append composition from an already applied command. |
| 110 void appendCommandToComposite(CompositeEditCommand*); | 114 void appendCommandToComposite(CompositeEditCommand*); |
| 111 | 115 |
| 112 virtual bool isReplaceSelectionCommand() const; | 116 virtual bool isReplaceSelectionCommand() const; |
| 113 virtual bool isTypingCommand() const; | 117 virtual bool isTypingCommand() const; |
| 114 virtual bool isCommandGroupWrapper() const; | 118 virtual bool isCommandGroupWrapper() const; |
| 115 virtual bool isDragAndDropCommand() const; | 119 virtual bool isDragAndDropCommand() const; |
| 116 virtual bool preservesTypingStyle() const; | 120 virtual bool preservesTypingStyle() const; |
| 117 virtual void setShouldRetainAutocorrectionIndicator(bool); | 121 virtual void setShouldRetainAutocorrectionIndicator(bool); |
| 118 virtual bool shouldStopCaretBlinking() const { return false; } | 122 virtual bool shouldStopCaretBlinking() const { return false; } |
| 119 | 123 |
| 120 DECLARE_VIRTUAL_TRACE(); | 124 DECLARE_VIRTUAL_TRACE(); |
| 121 | 125 |
| 122 protected: | 126 protected: |
| 123 explicit CompositeEditCommand(Document&); | 127 explicit CompositeEditCommand(Document&); |
| 124 | 128 |
| 125 // TODO(chongz): Implement "beforeinput" as described below: | 129 // TODO(chongz): Implement "beforeinput" as described below: |
| 126 // Fires "beforeinput" and will return |false| to cancel applying editing if | 130 // Fires "beforeinput" and will return |false| to cancel applying editing if |
| 127 // * "beforeinput" was canceled, or | 131 // * "beforeinput" was canceled, or |
| 128 // * |frame| was destroyed by event handlers. | 132 // * |frame| was destroyed by event handlers. |
| 129 // |willApplyEditing()| should be called from | 133 // |willApplyEditing()| should be called from |
| 130 // * |CompositeEditCommand::apply()|, and | 134 // * |CompositeEditCommand::apply()|, and |
| 131 // * |TypingCommand::willAddTypingToOpenCommand()|. | 135 // * |TypingCommand::willAddTypingToOpenCommand()|. |
| 132 bool willApplyEditing(EditCommandSource); | 136 bool willApplyEditing(EditCommandSource, BeforeInputTiming); |
| 133 | 137 |
| 134 // | 138 // |
| 135 // sugary-sweet convenience functions to help create and apply edit commands | 139 // sugary-sweet convenience functions to help create and apply edit commands |
| 136 // in composite commands | 140 // in composite commands |
| 137 // | 141 // |
| 138 void appendNode(Node*, ContainerNode* parent, EditingState*); | 142 void appendNode(Node*, ContainerNode* parent, EditingState*); |
| 139 void applyCommandToComposite(EditCommand*, EditingState*); | 143 void applyCommandToComposite(EditCommand*, EditingState*); |
| 140 void applyCommandToComposite(CompositeEditCommand*, | 144 void applyCommandToComposite(CompositeEditCommand*, |
| 141 const VisibleSelection&, | 145 const VisibleSelection&, |
| 142 EditingState*); | 146 EditingState*); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 289 |
| 286 DEFINE_TYPE_CASTS(CompositeEditCommand, | 290 DEFINE_TYPE_CASTS(CompositeEditCommand, |
| 287 EditCommand, | 291 EditCommand, |
| 288 command, | 292 command, |
| 289 command->isCompositeEditCommand(), | 293 command->isCompositeEditCommand(), |
| 290 command.isCompositeEditCommand()); | 294 command.isCompositeEditCommand()); |
| 291 | 295 |
| 292 } // namespace blink | 296 } // namespace blink |
| 293 | 297 |
| 294 #endif // CompositeEditCommand_h | 298 #endif // CompositeEditCommand_h |
| OLD | NEW |