Commit b4760e81 authored by Jing Wang's avatar Jing Wang Committed by Commit Bot

Fix nits in AssistiveSuggester.

A bunch of nits were raised in https://crrev.com/c/2049013 post-commit,
so making another change to fix them.

Test: tested with Linux emulator.
Bug: 1042084
Change-Id: I44d5835c21658e475dbba33c49a92c4b2e40d816
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2109573
Commit-Queue: Jing Wang <jiwan@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751905}
parent 08c6d4dd
...@@ -179,7 +179,7 @@ source_set("chromeos") { ...@@ -179,7 +179,7 @@ source_set("chromeos") {
"//components/arc", "//components/arc",
"//components/arc/media_session", "//components/arc/media_session",
"//components/arc/mojom:mojom_traits", "//components/arc/mojom:mojom_traits",
"//components/autofill/core/browser:browser", "//components/autofill/core/browser",
"//components/browser_sync", "//components/browser_sync",
"//components/captive_portal/core", "//components/captive_portal/core",
"//components/component_updater:crl_set_remover", "//components/component_updater:crl_set_remover",
......
// Copyright 2013 The Chromium Authors. All rights reserved. // Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -65,10 +65,10 @@ AssistiveType ProposeAssistiveAction(const std::string& text) { ...@@ -65,10 +65,10 @@ AssistiveType ProposeAssistiveAction(const std::string& text) {
AssistiveSuggester::AssistiveSuggester(InputMethodEngine* engine, AssistiveSuggester::AssistiveSuggester(InputMethodEngine* engine,
Profile* profile) Profile* profile)
: engine_(engine), profile_(profile) { : engine_(engine),
personal_data_manager_ = profile_(profile),
autofill::PersonalDataManagerFactory::GetForProfile(profile_); personal_data_manager_(
} autofill::PersonalDataManagerFactory::GetForProfile(profile)) {}
void AssistiveSuggester::OnFocus(int context_id) { void AssistiveSuggester::OnFocus(int context_id) {
context_id_ = context_id; context_id_ = context_id;
...@@ -94,10 +94,9 @@ bool AssistiveSuggester::OnKeyEvent( ...@@ -94,10 +94,9 @@ bool AssistiveSuggester::OnKeyEvent(
if (event.key == "Tab" || event.key == "Right") { if (event.key == "Tab" || event.key == "Right") {
engine_->ConfirmCompositionText(false, false); engine_->ConfirmCompositionText(false, false);
return true; return true;
} else {
DismissSuggestion();
suggestion_dismissed_ = true;
} }
DismissSuggestion();
suggestion_dismissed_ = true;
} }
return false; return false;
...@@ -126,15 +125,10 @@ bool AssistiveSuggester::OnSurroundingTextChanged(const std::string& text, ...@@ -126,15 +125,10 @@ bool AssistiveSuggester::OnSurroundingTextChanged(const std::string& text,
return false; return false;
} }
if (context_id_ == -1) if (context_id_ == -1 || suggestion_shown_)
return false; return false;
Suggest(text, cursor_pos, anchor_pos);
bool surrounding_text_changed = false; return suggestion_shown_;
if (!suggestion_shown_) {
Suggest(text, cursor_pos, anchor_pos);
surrounding_text_changed = suggestion_shown_;
}
return surrounding_text_changed;
} }
void AssistiveSuggester::Suggest(const std::string& text, void AssistiveSuggester::Suggest(const std::string& text,
...@@ -164,36 +158,34 @@ std::string AssistiveSuggester::GetPersonalInfoSuggestion( ...@@ -164,36 +158,34 @@ std::string AssistiveSuggester::GetPersonalInfoSuggestion(
if (action == AssistiveType::kGenericAction) if (action == AssistiveType::kGenericAction)
return ""; return "";
if (action == AssistiveType::kPersonalEmail) { if (action == AssistiveType::kPersonalEmail)
std::string email = profile_->GetProfileUserName(); return profile_->GetProfileUserName();
return email;
} else { auto autofill_profiles = personal_data_manager_->GetProfilesToSuggest();
auto autofill_profiles = personal_data_manager_->GetProfilesToSuggest(); if (autofill_profiles.empty())
if (autofill_profiles.size() > 0) { return "";
// Currently, we are just picking the first candidate, will improve the
// strategy in the future. // Currently, we are just picking the first candidate, will improve the
auto* data = autofill_profiles[0]; // strategy in the future.
base::string16 suggestion; auto* data = autofill_profiles[0];
switch (action) { base::string16 suggestion;
case AssistiveType::kPersonalName: switch (action) {
suggestion = data->GetRawInfo(autofill::ServerFieldType::NAME_FULL); case AssistiveType::kPersonalName:
break; suggestion = data->GetRawInfo(autofill::ServerFieldType::NAME_FULL);
case AssistiveType::kPersonalAddress: break;
suggestion = data->GetRawInfo( case AssistiveType::kPersonalAddress:
autofill::ServerFieldType::ADDRESS_HOME_STREET_ADDRESS); suggestion = data->GetRawInfo(
break; autofill::ServerFieldType::ADDRESS_HOME_STREET_ADDRESS);
case AssistiveType::kPersonalPhoneNumber: break;
suggestion = data->GetRawInfo( case AssistiveType::kPersonalPhoneNumber:
autofill::ServerFieldType::PHONE_HOME_WHOLE_NUMBER); suggestion =
break; data->GetRawInfo(autofill::ServerFieldType::PHONE_HOME_WHOLE_NUMBER);
default: break;
NOTREACHED(); default:
break; NOTREACHED();
} break;
return base::UTF16ToUTF8(suggestion);
}
} }
return ""; return base::UTF16ToUTF8(suggestion);
} }
void AssistiveSuggester::ShowSuggestion(const std::string& text) { void AssistiveSuggester::ShowSuggestion(const std::string& text) {
......
// Copyright 2013 The Chromium Authors. All rights reserved. // Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -59,16 +59,16 @@ class AssistiveSuggester { ...@@ -59,16 +59,16 @@ class AssistiveSuggester {
void ShowSuggestion(const std::string& text); void ShowSuggestion(const std::string& text);
void DismissSuggestion(); void DismissSuggestion();
InputMethodEngine* engine_; InputMethodEngine* const engine_;
// ID of the focused text field, 0 if none is focused. // ID of the focused text field, 0 if none is focused.
int context_id_ = -1; int context_id_ = -1;
// User's Chrome user profile. // User's Chrome user profile.
Profile* profile_; Profile* const profile_;
// Personal data manager provided by autofill service. // Personal data manager provided by autofill service.
autofill::PersonalDataManager* personal_data_manager_; autofill::PersonalDataManager* const personal_data_manager_;
// If we are showing a suggestion right now. // If we are showing a suggestion right now.
bool suggestion_shown_ = false; bool suggestion_shown_ = false;
......
...@@ -205,8 +205,9 @@ void NativeInputMethodEngine::ImeObserver::OnSurroundingTextChanged( ...@@ -205,8 +205,9 @@ void NativeInputMethodEngine::ImeObserver::OnSurroundingTextChanged(
// If |assistive_suggester_| changes the surrounding text, no longer need // If |assistive_suggester_| changes the surrounding text, no longer need
// to call the following function, as the information is out-dated. // to call the following function, as the information is out-dated.
if (assistive_suggester_->OnSurroundingTextChanged(text, cursor_pos, if (assistive_suggester_->OnSurroundingTextChanged(text, cursor_pos,
anchor_pos)) anchor_pos)) {
return; return;
}
} }
base_observer_->OnSurroundingTextChanged(engine_id, text, cursor_pos, base_observer_->OnSurroundingTextChanged(engine_id, text, cursor_pos,
anchor_pos, offset_pos); anchor_pos, offset_pos);
......
...@@ -48,9 +48,8 @@ class NativeInputMethodEngine : public InputMethodEngine { ...@@ -48,9 +48,8 @@ class NativeInputMethodEngine : public InputMethodEngine {
public: public:
// |base_observer| is to forward events to extension during this migration. // |base_observer| is to forward events to extension during this migration.
// It will be removed when the official extension is completely migrated. // It will be removed when the official extension is completely migrated.
explicit ImeObserver( ImeObserver(std::unique_ptr<InputMethodEngineBase::Observer> base_observer,
std::unique_ptr<InputMethodEngineBase::Observer> base_observer, std::unique_ptr<AssistiveSuggester> assistive_suggester);
std::unique_ptr<AssistiveSuggester> assistive_suggester);
~ImeObserver() override; ~ImeObserver() override;
// InputMethodEngineBase::Observer: // InputMethodEngineBase::Observer:
......
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