Chromium Code Reviews| 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 13 matching lines...) Expand all Loading... | |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef CompositeEditCommand_h | 26 #ifndef CompositeEditCommand_h |
| 27 #define CompositeEditCommand_h | 27 #define CompositeEditCommand_h |
| 28 | 28 |
| 29 #include "core/CSSPropertyNames.h" | 29 #include "core/CSSPropertyNames.h" |
| 30 #include "core/CoreExport.h" | 30 #include "core/CoreExport.h" |
| 31 #include "core/editing/commands/EditCommand.h" | 31 #include "core/editing/commands/EditCommand.h" |
| 32 #include "core/editing/commands/EditingState.h" | 32 #include "core/editing/commands/EditingState.h" |
| 33 #include "core/editing/commands/UndoStep.h" | 33 #include "core/editing/commands/UndoStep.h" |
| 34 #include "core/events/InputEvent.h" | |
| 34 #include "wtf/Vector.h" | 35 #include "wtf/Vector.h" |
| 35 | 36 |
| 36 namespace blink { | 37 namespace blink { |
| 37 | 38 |
| 38 class EditingStyle; | 39 class EditingStyle; |
| 39 class Element; | 40 class Element; |
| 40 class HTMLBRElement; | 41 class HTMLBRElement; |
| 41 class HTMLElement; | 42 class HTMLElement; |
| 42 class HTMLSpanElement; | 43 class HTMLSpanElement; |
| 43 class Text; | 44 class Text; |
| 44 | 45 |
| 45 enum class EditCommandSource { kMenuOrKeyBinding, kDOM }; | 46 enum class EditCommandSource { kMenuOrKeyBinding, kDOM }; |
| 46 | 47 |
| 47 class EditCommandComposition final : public UndoStep { | 48 class EditCommandComposition final : public UndoStep { |
| 48 public: | 49 public: |
| 49 static EditCommandComposition* create(Document*, | 50 static EditCommandComposition* create(Document*, |
| 50 const VisibleSelection&, | 51 const VisibleSelection&, |
| 51 const VisibleSelection&, | 52 const VisibleSelection&); |
| 52 InputEvent::InputType); | |
| 53 | 53 |
| 54 bool belongsTo(const LocalFrame&) const override; | 54 bool belongsTo(const LocalFrame&) const override; |
| 55 void unapply(EditCommandSource) override; | 55 void unapply(EditCommandSource) override; |
| 56 void reapply(EditCommandSource) override; | 56 void reapply(EditCommandSource) override; |
| 57 InputEvent::InputType inputType() const override; | |
|
chongz
2016/12/20 04:48:58
We don't need |inputType()| for |EditCommandCompos
| |
| 58 void append(SimpleEditCommand*); | 57 void append(SimpleEditCommand*); |
| 59 void append(EditCommandComposition*); | 58 void append(EditCommandComposition*); |
| 60 | 59 |
| 61 const VisibleSelection& startingSelection() const { | 60 const VisibleSelection& startingSelection() const { |
| 62 return m_startingSelection; | 61 return m_startingSelection; |
| 63 } | 62 } |
| 64 const VisibleSelection& endingSelection() const { return m_endingSelection; } | 63 const VisibleSelection& endingSelection() const { return m_endingSelection; } |
| 65 void setStartingSelection(const VisibleSelection&); | 64 void setStartingSelection(const VisibleSelection&); |
| 66 void setEndingSelection(const VisibleSelection&); | 65 void setEndingSelection(const VisibleSelection&); |
| 67 Element* startingRootEditableElement() const { | 66 Element* startingRootEditableElement() const { |
| 68 return m_startingRootEditableElement.get(); | 67 return m_startingRootEditableElement.get(); |
| 69 } | 68 } |
| 70 Element* endingRootEditableElement() const { | 69 Element* endingRootEditableElement() const { |
| 71 return m_endingRootEditableElement.get(); | 70 return m_endingRootEditableElement.get(); |
| 72 } | 71 } |
| 73 | 72 |
| 74 DECLARE_VIRTUAL_TRACE(); | 73 DECLARE_VIRTUAL_TRACE(); |
| 75 | 74 |
| 76 private: | 75 private: |
| 77 EditCommandComposition(Document*, | 76 EditCommandComposition(Document*, |
| 78 const VisibleSelection& startingSelection, | 77 const VisibleSelection& startingSelection, |
| 79 const VisibleSelection& endingSelection, | 78 const VisibleSelection& endingSelection); |
| 80 InputEvent::InputType); | |
| 81 | 79 |
| 82 // TODO(chongz): Implement "beforeinput" as described below: | |
| 83 // Fires "beforeinput" and will returns |false| to cancel unapply / reapply if | 80 // Fires "beforeinput" and will returns |false| to cancel unapply / reapply if |
| 84 // * "beforeinput" was canceled, or | 81 // * "beforeinput" was canceled, or |
| 85 // * |frame| was destroyed by event handlers. | 82 // * |frame| was destroyed by event handlers. |
| 86 // Note: Undo stack will always get popped. | 83 // Note: Undo stack will always get popped. |
| 87 bool willUnapply(EditCommandSource); | 84 bool willUnapply(EditCommandSource); |
| 88 bool willReapply(EditCommandSource); | 85 bool willReapply(EditCommandSource); |
| 89 | 86 |
| 90 Member<Document> m_document; | 87 Member<Document> m_document; |
| 91 VisibleSelection m_startingSelection; | 88 VisibleSelection m_startingSelection; |
| 92 VisibleSelection m_endingSelection; | 89 VisibleSelection m_endingSelection; |
| 93 HeapVector<Member<SimpleEditCommand>> m_commands; | 90 HeapVector<Member<SimpleEditCommand>> m_commands; |
| 94 Member<Element> m_startingRootEditableElement; | 91 Member<Element> m_startingRootEditableElement; |
| 95 Member<Element> m_endingRootEditableElement; | 92 Member<Element> m_endingRootEditableElement; |
| 96 InputEvent::InputType m_inputType; | |
| 97 }; | 93 }; |
| 98 | 94 |
| 99 class CORE_EXPORT CompositeEditCommand : public EditCommand { | 95 class CORE_EXPORT CompositeEditCommand : public EditCommand { |
| 100 public: | 96 public: |
| 101 enum ShouldPreserveSelection { PreserveSelection, DoNotPreserveSelection }; | 97 enum ShouldPreserveSelection { PreserveSelection, DoNotPreserveSelection }; |
| 102 enum ShouldPreserveStyle { PreserveStyle, DoNotPreserveStyle }; | 98 enum ShouldPreserveStyle { PreserveStyle, DoNotPreserveStyle }; |
| 103 | 99 |
| 104 ~CompositeEditCommand() override; | 100 ~CompositeEditCommand() override; |
| 105 | 101 |
| 106 // Returns |false| if the command failed. e.g. It's aborted. | 102 // Returns |false| if the command failed. e.g. It's aborted. |
| 107 bool apply(EditCommandSource); | 103 bool apply(EditCommandSource); |
| 108 bool isFirstCommand(EditCommand* command) { | 104 bool isFirstCommand(EditCommand* command) { |
| 109 return !m_commands.isEmpty() && m_commands.front() == command; | 105 return !m_commands.isEmpty() && m_commands.front() == command; |
| 110 } | 106 } |
| 111 EditCommandComposition* composition() { return m_composition.get(); } | 107 EditCommandComposition* composition() { return m_composition.get(); } |
| 112 EditCommandComposition* ensureComposition(); | 108 EditCommandComposition* ensureComposition(); |
| 113 // Append composition from an already applied command. | 109 // Append composition from an already applied command. |
| 114 void appendCommandToComposite(CompositeEditCommand*); | 110 void appendCommandToComposite(CompositeEditCommand*); |
| 115 | 111 |
| 116 virtual bool isReplaceSelectionCommand() const; | 112 virtual bool isReplaceSelectionCommand() const; |
| 117 virtual bool isTypingCommand() const; | 113 virtual bool isTypingCommand() const; |
| 118 virtual bool isCommandGroupWrapper() const; | 114 virtual bool isCommandGroupWrapper() const; |
| 119 virtual bool isDragAndDropCommand() const; | 115 virtual bool isDragAndDropCommand() const; |
| 120 virtual bool preservesTypingStyle() const; | 116 virtual bool preservesTypingStyle() const; |
| 121 virtual void setShouldRetainAutocorrectionIndicator(bool); | 117 virtual void setShouldRetainAutocorrectionIndicator(bool); |
| 122 virtual bool shouldStopCaretBlinking() const { return false; } | 118 virtual bool shouldStopCaretBlinking() const { return false; } |
| 123 | 119 |
| 120 virtual InputEvent::InputType inputType() const; | |
| 121 // |TypingCommand| will return the text of the last |m_commands|. | |
| 122 virtual String textDataForInputEvent() const; | |
| 123 virtual DataTransfer* dataTransferForInputEvent() const; | |
| 124 virtual RangeVector* targetRangesForInputEvent() const; | |
| 125 | |
| 124 DECLARE_VIRTUAL_TRACE(); | 126 DECLARE_VIRTUAL_TRACE(); |
| 125 | 127 |
| 126 protected: | 128 protected: |
| 127 explicit CompositeEditCommand(Document&); | 129 explicit CompositeEditCommand(Document&); |
| 128 | 130 |
| 129 // TODO(chongz): Implement "beforeinput" as described below: | |
| 130 // Fires "beforeinput" and will return |false| to cancel applying editing if | 131 // Fires "beforeinput" and will return |false| to cancel applying editing if |
| 131 // * "beforeinput" was canceled, or | 132 // * "beforeinput" was canceled, or |
| 132 // * |frame| was destroyed by event handlers. | 133 // * |frame| was destroyed by event handlers. |
| 133 // |willApplyEditing()| should be called from | 134 // |willApplyEditing()| should be called from |
| 134 // * |CompositeEditCommand::apply()|, and | 135 // * |CompositeEditCommand::apply()|, and |
| 135 // * |TypingCommand::willAddTypingToOpenCommand()|. | 136 // * |TypingCommand::willAddTypingToOpenCommand()|. |
| 136 bool willApplyEditing(EditCommandSource); | 137 bool willApplyEditing(EditCommandSource); |
| 137 | 138 |
| 138 // | 139 // |
| 139 // sugary-sweet convenience functions to help create and apply edit commands | 140 // sugary-sweet convenience functions to help create and apply edit commands |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 | 290 |
| 290 DEFINE_TYPE_CASTS(CompositeEditCommand, | 291 DEFINE_TYPE_CASTS(CompositeEditCommand, |
| 291 EditCommand, | 292 EditCommand, |
| 292 command, | 293 command, |
| 293 command->isCompositeEditCommand(), | 294 command->isCompositeEditCommand(), |
| 294 command.isCompositeEditCommand()); | 295 command.isCompositeEditCommand()); |
| 295 | 296 |
| 296 } // namespace blink | 297 } // namespace blink |
| 297 | 298 |
| 298 #endif // CompositeEditCommand_h | 299 #endif // CompositeEditCommand_h |
| OLD | NEW |