Commit 9e34d76b authored by My Nguyen's avatar My Nguyen Committed by Commit Bot

Use SuggestionHandlerInterface for Emoji Suggester

This is in preparation for testing of Learn More Button in
emoji suggestion.

Bug: 1101195
Change-Id: I2cffeef7a34290f328e85ed790c00509218d3004
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2281766
Commit-Queue: My Nguyen <myy@chromium.org>
Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#785248}
parent 1e5f38e0
......@@ -69,7 +69,8 @@ std::string GetLastWord(const std::string& str) {
} // namespace
EmojiSuggester::EmojiSuggester(InputMethodEngine* engine) : engine_(engine) {
EmojiSuggester::EmojiSuggester(SuggestionHandlerInterface* engine)
: engine_(engine) {
LoadEmojiMap();
properties_.type = ui::ime::AssistiveWindowType::kEmojiSuggestion;
current_candidate_.id = ui::ime::ButtonId::kSuggestion;
......
......@@ -7,10 +7,10 @@
#include <string>
#include "chrome/browser/chromeos/input_method/input_method_engine.h"
#include "chrome/browser/chromeos/input_method/input_method_engine_base.h"
#include "chrome/browser/chromeos/input_method/suggester.h"
#include "chrome/browser/chromeos/input_method/suggestion_enums.h"
#include "chrome/browser/chromeos/input_method/suggestion_handler_interface.h"
#include "chrome/browser/chromeos/input_method/ui/assistive_delegate.h"
namespace chromeos {
......@@ -19,7 +19,7 @@ namespace chromeos {
// dismiss the suggestion according to the user action.
class EmojiSuggester : public Suggester {
public:
explicit EmojiSuggester(InputMethodEngine* engine);
explicit EmojiSuggester(SuggestionHandlerInterface* engine);
~EmojiSuggester() override;
// Suggester overrides:
......@@ -43,7 +43,7 @@ class EmojiSuggester : public Suggester {
void ResetState();
void BuildCandidateAnnounceString();
InputMethodEngine* const engine_;
SuggestionHandlerInterface* const engine_;
// ID of the focused text field, 0 if none is focused.
int context_id_ = -1;
......
......@@ -14,10 +14,56 @@ namespace chromeos {
const char kEmojiData[] = "happy,😀;😃;😄";
class TestSuggestionHandler : public SuggestionHandlerInterface {
public:
bool SetButtonHighlighted(int context_id,
const ui::ime::AssistiveWindowButton& button,
bool highlighted,
std::string* error) override {
return false;
}
bool SetAssistiveWindowProperties(
int context_id,
const AssistiveWindowProperties& assistive_window,
std::string* error) override {
return false;
}
bool DismissSuggestion(int context_id, std::string* error) override {
return false;
}
bool AcceptSuggestion(int context_id, std::string* error) override {
return false;
}
void OnSuggestionsChanged(
const std::vector<std::string>& suggestions) override {}
bool ShowMultipleSuggestions(int context_id,
const std::vector<base::string16>& candidates,
std::string* error) override {
return false;
}
bool AcceptSuggestionCandidate(int context_id,
const base::string16& candidate,
std::string* error) override {
return false;
}
bool SetSuggestion(int context_id,
const ui::ime::SuggestionDetails& details,
std::string* error) override {
return false;
}
};
class EmojiSuggesterTest : public testing::Test {
protected:
void SetUp() override {
engine_ = std::make_unique<InputMethodEngine>();
engine_ = std::make_unique<TestSuggestionHandler>();
emoji_suggester_ = std::make_unique<EmojiSuggester>(engine_.get());
emoji_suggester_->LoadEmojiMapForTesting(kEmojiData);
chrome_keyboard_controller_client_ =
......@@ -26,7 +72,7 @@ class EmojiSuggesterTest : public testing::Test {
}
std::unique_ptr<EmojiSuggester> emoji_suggester_;
std::unique_ptr<InputMethodEngine> engine_;
std::unique_ptr<TestSuggestionHandler> engine_;
base::test::TaskEnvironment task_environment_;
std::unique_ptr<ChromeKeyboardControllerClient>
chrome_keyboard_controller_client_;
......
......@@ -131,6 +131,11 @@ class InputMethodEngine : public InputMethodEngineBase,
const base::string16& candidate,
std::string* error) override;
bool SetAssistiveWindowProperties(
int context_id,
const AssistiveWindowProperties& assistive_window,
std::string* error) override;
// This function returns the current property of the candidate window of the
// corresponding engine_id. If the CandidateWindowProperty is not set for the
// engine_id, a default value is set. The caller can use the returned value as
......@@ -154,12 +159,6 @@ class InputMethodEngine : public InputMethodEngineBase,
// Set the position of the cursor in the candidate window.
bool SetCursorPosition(int context_id, int candidate_id, std::string* error);
// Show/Hide given assistive window.
bool SetAssistiveWindowProperties(
int context_id,
const AssistiveWindowProperties& assistive_window,
std::string* error);
// Set the list of items that appears in the language menu when this IME is
// active.
bool SetMenuItems(
......
......@@ -86,6 +86,13 @@ class TestSuggestionHandler : public SuggestionHandlerInterface {
return false;
}
bool SetAssistiveWindowProperties(
int context_id,
const AssistiveWindowProperties& assistive_window,
std::string* error) override {
return false;
}
void VerifyShowTab(const bool show_tab) { EXPECT_EQ(show_tab_, show_tab); }
void VerifyShowSettingLink(const bool show_setting_link) {
EXPECT_EQ(show_setting_link_, show_setting_link);
......
......@@ -55,6 +55,13 @@ class SuggestionHandlerInterface {
virtual bool AcceptSuggestionCandidate(int context_id,
const base::string16& candidate,
std::string* error) = 0;
// Shows/Hides given assistive window. No-op if context_id doesn't match or
// engine is not active.
virtual bool SetAssistiveWindowProperties(
int context_id,
const AssistiveWindowProperties& assistive_window,
std::string* error) = 0;
};
} // namespace chromeos
......
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