Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.h

Issue 2627103003: [EditCommandSource] Pass source through |CompositeEditCommand| ctor instead of |apply(source)| (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 24 matching lines...) Expand all
35 35
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 {
46 kMenuOrKeyBinding, // from menu, or keyboard shortcut
yosin_UTC9 2017/01/12 04:01:13 I prefer to use |kUserAction| instead of |kMenuOrK
chongz 2017/01/13 16:28:27 Will do.
47 kDOM, // document.execCommand()
yosin_UTC9 2017/01/12 04:01:13 I prefer to use |kExecCommand|, |kScriptAPI|, or a
chongz 2017/01/13 16:28:27 Will do.
48 kInternal, // Blink creates a command for implementation.
49 };
46 50
47 class EditCommandComposition final : public UndoStep { 51 class EditCommandComposition final : public UndoStep {
48 public: 52 public:
49 static EditCommandComposition* create(Document*, 53 static EditCommandComposition* create(Document*,
50 const VisibleSelection&, 54 const VisibleSelection&,
51 const VisibleSelection&); 55 const VisibleSelection&);
52 56
53 bool belongsTo(const LocalFrame&) const override; 57 bool belongsTo(const LocalFrame&) const override;
54 void unapply(EditCommandSource) override; 58 void unapply(EditCommandSource) override;
55 void reapply(EditCommandSource) override; 59 void reapply(EditCommandSource) override;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 }; 97 };
94 98
95 class CORE_EXPORT CompositeEditCommand : public EditCommand { 99 class CORE_EXPORT CompositeEditCommand : public EditCommand {
96 public: 100 public:
97 enum ShouldPreserveSelection { PreserveSelection, DoNotPreserveSelection }; 101 enum ShouldPreserveSelection { PreserveSelection, DoNotPreserveSelection };
98 enum ShouldPreserveStyle { PreserveStyle, DoNotPreserveStyle }; 102 enum ShouldPreserveStyle { PreserveStyle, DoNotPreserveStyle };
99 103
100 ~CompositeEditCommand() override; 104 ~CompositeEditCommand() override;
101 105
102 // Returns |false| if the command failed. e.g. It's aborted. 106 // Returns |false| if the command failed. e.g. It's aborted.
103 bool apply(EditCommandSource); 107 bool apply();
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(
128 Document&,
129 EditCommandSource = EditCommandSource::kInternal);
124 130
125 // TODO(chongz): Implement "beforeinput" as described below: 131 // TODO(chongz): Implement "beforeinput" as described below:
126 // Fires "beforeinput" and will return |false| to cancel applying editing if 132 // Fires "beforeinput" and will return |false| to cancel applying editing if
127 // * "beforeinput" was canceled, or 133 // * "beforeinput" was canceled, or
128 // * |frame| was destroyed by event handlers. 134 // * |frame| was destroyed by event handlers.
129 // |willApplyEditing()| should be called from 135 // |willApplyEditing()| should be called from
130 // * |CompositeEditCommand::apply()|, and 136 // * |CompositeEditCommand::apply()|, and
131 // * |TypingCommand::willAddTypingToOpenCommand()|. 137 // * |TypingCommand::willAddTypingToOpenCommand()|.
132 bool willApplyEditing(EditCommandSource); 138 bool willApplyEditing(EditCommandSource);
133 139
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 EditingState*); 280 EditingState*);
275 281
276 Node* splitTreeToNode(Node*, Node*, bool splitAncestor = false); 282 Node* splitTreeToNode(Node*, Node*, bool splitAncestor = false);
277 283
278 HeapVector<Member<EditCommand>> m_commands; 284 HeapVector<Member<EditCommand>> m_commands;
279 285
280 private: 286 private:
281 bool isCompositeEditCommand() const final { return true; } 287 bool isCompositeEditCommand() const final { return true; }
282 288
283 Member<EditCommandComposition> m_composition; 289 Member<EditCommandComposition> m_composition;
290 EditCommandSource m_source;
284 }; 291 };
285 292
286 DEFINE_TYPE_CASTS(CompositeEditCommand, 293 DEFINE_TYPE_CASTS(CompositeEditCommand,
287 EditCommand, 294 EditCommand,
288 command, 295 command,
289 command->isCompositeEditCommand(), 296 command->isCompositeEditCommand(),
290 command.isCompositeEditCommand()); 297 command.isCompositeEditCommand());
291 298
292 } // namespace blink 299 } // namespace blink
293 300
294 #endif // CompositeEditCommand_h 301 #endif // CompositeEditCommand_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698