Commit 58342791 authored by Zhuoyu Qian's avatar Zhuoyu Qian Committed by Commit Bot

Introduce Editor::Command::CanExecute().

This CL introduces Editor::Command::CanExecute(), and move the predicate
in Editor::Command::Execute() to it, make Editor::Command::Execute()
simple and improve code health.
Signed-off-by: default avatarZhuoyu Qian <zhuoyu.qian@samsung.com>
Change-Id: Iae25f9ebd4d7554e83a9a819c562fae85c2dedc6
Reviewed-on: https://chromium-review.googlesource.com/954773Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543999}
parent 235e14d4
...@@ -112,6 +112,7 @@ class CORE_EXPORT Editor final : public GarbageCollectedFinalized<Editor> { ...@@ -112,6 +112,7 @@ class CORE_EXPORT Editor final : public GarbageCollectedFinalized<Editor> {
Event* triggering_event = nullptr) const; Event* triggering_event = nullptr) const;
bool Execute(Event* triggering_event) const; bool Execute(Event* triggering_event) const;
bool CanExecute(Event* triggering_event = nullptr) const;
bool IsSupported() const; bool IsSupported() const;
bool IsEnabled(Event* triggering_event = nullptr) const; bool IsEnabled(Event* triggering_event = nullptr) const;
......
...@@ -260,7 +260,7 @@ class EditorInternalCommand { ...@@ -260,7 +260,7 @@ class EditorInternalCommand {
EditingTriState (*state)(LocalFrame&, Event*); EditingTriState (*state)(LocalFrame&, Event*);
String (*value)(const EditorInternalCommand&, LocalFrame&, Event*); String (*value)(const EditorInternalCommand&, LocalFrame&, Event*);
bool is_text_insertion; bool is_text_insertion;
bool (*canExecute)(LocalFrame&, EditorCommandSource); bool (*can_execute)(LocalFrame&, EditorCommandSource);
}; };
static const bool kNotTextInsertion = false; static const bool kNotTextInsertion = false;
...@@ -3554,16 +3554,8 @@ Editor::Command::Command(const EditorInternalCommand* command, ...@@ -3554,16 +3554,8 @@ Editor::Command::Command(const EditorInternalCommand* command,
bool Editor::Command::Execute(const String& parameter, bool Editor::Command::Execute(const String& parameter,
Event* triggering_event) const { Event* triggering_event) const {
// TODO(yosin) We should move this logic into |canExecute()| member function if (!CanExecute(triggering_event))
// in |EditorInternalCommand| to replace |allowExecutionWhenDisabled|. return false;
// |allowExecutionWhenDisabled| is for "Copy", "Cut" and "Paste" commands
// only.
if (!IsEnabled(triggering_event)) {
// Let certain commands be executed when performed explicitly even if they
// are disabled.
if (!IsSupported() || !frame_ || !command_->canExecute(*frame_, source_))
return false;
}
if (source_ == EditorCommandSource::kMenuOrKeyBinding) { if (source_ == EditorCommandSource::kMenuOrKeyBinding) {
InputEvent::InputType input_type = InputEvent::InputType input_type =
...@@ -3590,6 +3582,12 @@ bool Editor::Command::Execute(Event* triggering_event) const { ...@@ -3590,6 +3582,12 @@ bool Editor::Command::Execute(Event* triggering_event) const {
return Execute(String(), triggering_event); return Execute(String(), triggering_event);
} }
bool Editor::Command::CanExecute(Event* triggering_event) const {
if (IsEnabled(triggering_event))
return true;
return IsSupported() && frame_ && command_->can_execute(*frame_, source_);
}
bool Editor::Command::IsSupported() const { bool Editor::Command::IsSupported() const {
if (!command_) if (!command_)
return false; return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment