Commit b1d0fc82 authored by My Nguyen's avatar My Nguyen Committed by Commit Bot

Use SuggestionDetails struct for showing suggestion

In preparation for adding show_setting_link param for personal info
suggestion.

Bug: 1094267
Change-Id: Id9e4a5d5de335613df93bf80142a3df8bb564fd0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2243073
Commit-Queue: My Nguyen <myy@chromium.org>
Reviewed-by: default avatarKeith Lee <keithlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779566}
parent 94f5103c
...@@ -1329,6 +1329,7 @@ source_set("chromeos") { ...@@ -1329,6 +1329,7 @@ source_set("chromeos") {
"input_method/ui/input_method_menu_item.h", "input_method/ui/input_method_menu_item.h",
"input_method/ui/input_method_menu_manager.cc", "input_method/ui/input_method_menu_manager.cc",
"input_method/ui/input_method_menu_manager.h", "input_method/ui/input_method_menu_manager.h",
"input_method/ui/suggestion_details.h",
"input_method/ui/suggestion_view.cc", "input_method/ui/suggestion_view.cc",
"input_method/ui/suggestion_view.h", "input_method/ui/suggestion_view.h",
"input_method/ui/suggestion_window_view.cc", "input_method/ui/suggestion_window_view.cc",
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
#include "chrome/browser/chromeos/input_method/assistive_window_controller_delegate.h" #include "chrome/browser/chromeos/input_method/assistive_window_controller_delegate.h"
#include "chrome/browser/chromeos/input_method/assistive_window_properties.h" #include "chrome/browser/chromeos/input_method/assistive_window_properties.h"
#include "chrome/browser/chromeos/input_method/ui/suggestion_details.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/settings_window_manager_chromeos.h" #include "chrome/browser/ui/settings_window_manager_chromeos.h"
#include "chrome/browser/ui/webui/settings/chromeos/constants/routes.mojom.h" #include "chrome/browser/ui/webui/settings/chromeos/constants/routes.mojom.h"
...@@ -152,14 +153,13 @@ void AssistiveWindowController::FocusStateChanged() { ...@@ -152,14 +153,13 @@ void AssistiveWindowController::FocusStateChanged() {
undo_window_->Hide(); undo_window_->Hide();
} }
void AssistiveWindowController::ShowSuggestion(const base::string16& text, void AssistiveWindowController::ShowSuggestion(
const size_t confirmed_length, const ui::ime::SuggestionDetails& details) {
const bool show_tab) {
if (!suggestion_window_view_) if (!suggestion_window_view_)
InitSuggestionWindow(); InitSuggestionWindow();
suggestion_text_ = text; suggestion_text_ = details.text;
confirmed_length_ = confirmed_length; confirmed_length_ = details.confirmed_length;
suggestion_window_view_->Show(text, confirmed_length, show_tab); suggestion_window_view_->Show(details);
} }
void AssistiveWindowController::ShowMultipleSuggestions( void AssistiveWindowController::ShowMultipleSuggestions(
......
...@@ -72,9 +72,7 @@ class AssistiveWindowController : public views::WidgetObserver, ...@@ -72,9 +72,7 @@ class AssistiveWindowController : public views::WidgetObserver,
void SetBounds(const gfx::Rect& cursor_bounds) override; void SetBounds(const gfx::Rect& cursor_bounds) override;
void SetAssistiveWindowProperties( void SetAssistiveWindowProperties(
const AssistiveWindowProperties& window) override; const AssistiveWindowProperties& window) override;
void ShowSuggestion(const base::string16& text, void ShowSuggestion(const ui::ime::SuggestionDetails& details) override;
const size_t confirmed_length,
const bool show_tab) override;
void ShowMultipleSuggestions( void ShowMultipleSuggestions(
const std::vector<base::string16>& suggestions) override; const std::vector<base::string16>& suggestions) override;
void HighlightSuggestionCandidate(int index) override; void HighlightSuggestionCandidate(int index) override;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/chromeos/input_method/assistive_window_controller.h" #include "chrome/browser/chromeos/input_method/assistive_window_controller.h"
#include "chrome/browser/chromeos/input_method/assistive_window_controller_delegate.h" #include "chrome/browser/chromeos/input_method/assistive_window_controller_delegate.h"
#include "chrome/browser/chromeos/input_method/ui/suggestion_details.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/test/base/chrome_ash_test_base.h" #include "chrome/test/base/chrome_ash_test_base.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
...@@ -54,8 +55,10 @@ class AssistiveWindowControllerTest : public ChromeAshTestBase { ...@@ -54,8 +55,10 @@ class AssistiveWindowControllerTest : public ChromeAshTestBase {
TEST_F(AssistiveWindowControllerTest, ConfirmedLength0SetsSuggestionViewBound) { TEST_F(AssistiveWindowControllerTest, ConfirmedLength0SetsSuggestionViewBound) {
// Sets up suggestion_view with confirmed_length = 0. // Sets up suggestion_view with confirmed_length = 0.
ui::IMEBridge::Get()->GetAssistiveWindowHandler()->ShowSuggestion(suggestion_, ui::ime::SuggestionDetails details;
0, false); details.text = suggestion_;
details.confirmed_length = 0;
ui::IMEBridge::Get()->GetAssistiveWindowHandler()->ShowSuggestion(details);
ui::ime::SuggestionWindowView* suggestion_view = ui::ime::SuggestionWindowView* suggestion_view =
controller_->GetSuggestionWindowViewForTesting(); controller_->GetSuggestionWindowViewForTesting();
EXPECT_EQ( EXPECT_EQ(
...@@ -71,8 +74,10 @@ TEST_F(AssistiveWindowControllerTest, ConfirmedLength0SetsSuggestionViewBound) { ...@@ -71,8 +74,10 @@ TEST_F(AssistiveWindowControllerTest, ConfirmedLength0SetsSuggestionViewBound) {
TEST_F(AssistiveWindowControllerTest, TEST_F(AssistiveWindowControllerTest,
ConfirmedLengthNot0DoesNotSetSuggestionViewBound) { ConfirmedLengthNot0DoesNotSetSuggestionViewBound) {
// Sets up suggestion_view with confirmed_length = 1. // Sets up suggestion_view with confirmed_length = 1.
ui::IMEBridge::Get()->GetAssistiveWindowHandler()->ShowSuggestion(suggestion_, ui::ime::SuggestionDetails details;
1, false); details.text = suggestion_;
details.confirmed_length = 1;
ui::IMEBridge::Get()->GetAssistiveWindowHandler()->ShowSuggestion(details);
ui::ime::SuggestionWindowView* suggestion_view = ui::ime::SuggestionWindowView* suggestion_view =
controller_->GetSuggestionWindowViewForTesting(); controller_->GetSuggestionWindowViewForTesting();
EXPECT_EQ( EXPECT_EQ(
...@@ -88,8 +93,10 @@ TEST_F(AssistiveWindowControllerTest, ...@@ -88,8 +93,10 @@ TEST_F(AssistiveWindowControllerTest,
TEST_F(AssistiveWindowControllerTest, TEST_F(AssistiveWindowControllerTest,
SuggestionViewBoundIsResetAfterHideSuggestionThenShowAgain) { SuggestionViewBoundIsResetAfterHideSuggestionThenShowAgain) {
// Sets up suggestion_view with confirmed_length = 1. // Sets up suggestion_view with confirmed_length = 1.
ui::IMEBridge::Get()->GetAssistiveWindowHandler()->ShowSuggestion(suggestion_, ui::ime::SuggestionDetails details;
1, false); details.text = suggestion_;
details.confirmed_length = 1;
ui::IMEBridge::Get()->GetAssistiveWindowHandler()->ShowSuggestion(details);
EXPECT_EQ( EXPECT_EQ(
1u, 1u,
ui::IMEBridge::Get()->GetAssistiveWindowHandler()->GetConfirmedLength()); ui::IMEBridge::Get()->GetAssistiveWindowHandler()->GetConfirmedLength());
......
...@@ -319,9 +319,7 @@ bool InputMethodEngine::SetCursorPosition(int context_id, ...@@ -319,9 +319,7 @@ bool InputMethodEngine::SetCursorPosition(int context_id,
} }
bool InputMethodEngine::SetSuggestion(int context_id, bool InputMethodEngine::SetSuggestion(int context_id,
const base::string16& text, const ui::ime::SuggestionDetails& details,
const size_t confirmed_length,
const bool show_tab,
std::string* error) { std::string* error) {
if (!IsActive()) { if (!IsActive()) {
*error = kErrorNotActive; *error = kErrorNotActive;
...@@ -335,7 +333,7 @@ bool InputMethodEngine::SetSuggestion(int context_id, ...@@ -335,7 +333,7 @@ bool InputMethodEngine::SetSuggestion(int context_id,
IMEAssistiveWindowHandlerInterface* aw_handler = IMEAssistiveWindowHandlerInterface* aw_handler =
ui::IMEBridge::Get()->GetAssistiveWindowHandler(); ui::IMEBridge::Get()->GetAssistiveWindowHandler();
if (aw_handler) if (aw_handler)
aw_handler->ShowSuggestion(text, confirmed_length, show_tab); aw_handler->ShowSuggestion(details);
return true; return true;
} }
......
...@@ -29,6 +29,7 @@ namespace ime { ...@@ -29,6 +29,7 @@ namespace ime {
enum class AssistiveWindowType; enum class AssistiveWindowType;
enum class ButtonId; enum class ButtonId;
struct InputMethodMenuItem; struct InputMethodMenuItem;
struct SuggestionDetails;
} // namespace ime } // namespace ime
} // namespace ui } // namespace ui
...@@ -113,9 +114,7 @@ class InputMethodEngine : public InputMethodEngineBase, ...@@ -113,9 +114,7 @@ class InputMethodEngine : public InputMethodEngineBase,
// SuggestionHandlerInterface overrides. // SuggestionHandlerInterface overrides.
bool DismissSuggestion(int context_id, std::string* error) override; bool DismissSuggestion(int context_id, std::string* error) override;
bool SetSuggestion(int context_id, bool SetSuggestion(int context_id,
const base::string16& text, const ui::ime::SuggestionDetails& details,
const size_t confirmed_length,
const bool show_tab,
std::string* error) override; std::string* error) override;
bool AcceptSuggestion(int context_id, std::string* error) override; bool AcceptSuggestion(int context_id, std::string* error) override;
void OnSuggestionsChanged( void OnSuggestionsChanged(
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h" #include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/chromeos/input_method/ui/suggestion_details.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ash/keyboard/chrome_keyboard_controller_client.h" #include "chrome/browser/ui/ash/keyboard/chrome_keyboard_controller_client.h"
#include "chromeos/constants/chromeos_pref_names.h" #include "chromeos/constants/chromeos_pref_names.h"
...@@ -236,8 +237,11 @@ void PersonalInfoSuggester::ShowSuggestion(const base::string16& text, ...@@ -236,8 +237,11 @@ void PersonalInfoSuggester::ShowSuggestion(const base::string16& text,
std::string error; std::string error;
bool show_tab = GetTabAcceptanceCount() < kMaxTabAcceptanceCount; bool show_tab = GetTabAcceptanceCount() < kMaxTabAcceptanceCount;
suggestion_handler_->SetSuggestion(context_id_, text, confirmed_length, ui::ime::SuggestionDetails details;
show_tab, &error); details.text = text;
details.confirmed_length = confirmed_length;
details.show_tab = show_tab;
suggestion_handler_->SetSuggestion(context_id_, details, &error);
if (!error.empty()) { if (!error.empty()) {
LOG(ERROR) << "Fail to show suggestion. " << error; LOG(ERROR) << "Fail to show suggestion. " << error;
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "ash/public/cpp/ash_pref_names.h" #include "ash/public/cpp/ash_pref_names.h"
#include "base/guid.h" #include "base/guid.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chromeos/input_method/ui/suggestion_details.h"
#include "chrome/browser/ui/ash/keyboard/chrome_keyboard_controller_client.h" #include "chrome/browser/ui/ash/keyboard/chrome_keyboard_controller_client.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "chromeos/constants/chromeos_pref_names.h" #include "chromeos/constants/chromeos_pref_names.h"
...@@ -32,13 +33,11 @@ class TestSuggestionHandler : public SuggestionHandlerInterface { ...@@ -32,13 +33,11 @@ class TestSuggestionHandler : public SuggestionHandlerInterface {
} }
bool SetSuggestion(int context_id, bool SetSuggestion(int context_id,
const base::string16& text, const ui::ime::SuggestionDetails& details,
const size_t confirmed_length,
const bool show_tab,
std::string* error) override { std::string* error) override {
suggestion_text_ = text; suggestion_text_ = details.text;
confirmed_length_ = confirmed_length; confirmed_length_ = details.confirmed_length;
show_tab_ = show_tab; show_tab_ = details.show_tab;
return true; return true;
} }
......
...@@ -8,6 +8,12 @@ ...@@ -8,6 +8,12 @@
#include <string> #include <string>
#include "base/strings/string16.h" #include "base/strings/string16.h"
namespace ui {
namespace ime {
struct SuggestionDetails;
} // namespace ime
} // namespace ui
namespace chromeos { namespace chromeos {
// An interface to handler suggestion related calls from assistive suggester. // An interface to handler suggestion related calls from assistive suggester.
...@@ -23,9 +29,7 @@ class SuggestionHandlerInterface { ...@@ -23,9 +29,7 @@ class SuggestionHandlerInterface {
// confirmed_text - the confirmed text that the user has typed so far. // confirmed_text - the confirmed text that the user has typed so far.
// show_tab - whether to show "tab" in the suggestion window. // show_tab - whether to show "tab" in the suggestion window.
virtual bool SetSuggestion(int context_id, virtual bool SetSuggestion(int context_id,
const base::string16& text, const ui::ime::SuggestionDetails& details,
const size_t confirmed_length,
const bool show_tab,
std::string* error) = 0; std::string* error) = 0;
// Commit the suggestion and hide the window. // Commit the suggestion and hide the window.
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_UI_SUGGESTION_DETAILS_H_
#define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_UI_SUGGESTION_DETAILS_H_
#include "base/strings/string16.h"
namespace ui {
namespace ime {
struct SuggestionDetails {
base::string16 text;
size_t confirmed_length;
bool show_tab;
};
} // namespace ime
} // namespace ui
#endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_UI_SUGGESTION_DETAILS_H_
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/chromeos/input_method/ui/suggestion_view.h" #include "chrome/browser/chromeos/input_method/ui/suggestion_view.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chromeos/input_method/ui/suggestion_details.h"
#include "ui/accessibility/ax_enums.mojom.h" #include "ui/accessibility/ax_enums.mojom.h"
#include "ui/gfx/color_utils.h" #include "ui/gfx/color_utils.h"
#include "ui/native_theme/native_theme.h" #include "ui/native_theme/native_theme.h"
...@@ -77,12 +78,10 @@ SuggestionView::SuggestionView() { ...@@ -77,12 +78,10 @@ SuggestionView::SuggestionView() {
SuggestionView::~SuggestionView() = default; SuggestionView::~SuggestionView() = default;
void SuggestionView::SetView(const base::string16& text, void SuggestionView::SetView(const SuggestionDetails& details) {
const size_t confirmed_length, SetSuggestionText(details.text, details.confirmed_length);
const bool show_tab) {
SetSuggestionText(text, confirmed_length);
suggestion_width_ = suggestion_label_->GetPreferredSize().width(); suggestion_width_ = suggestion_label_->GetPreferredSize().width();
annotation_label_->SetVisible(show_tab); annotation_label_->SetVisible(details.show_tab);
} }
void SuggestionView::SetViewWithIndex(const base::string16& index, void SuggestionView::SetViewWithIndex(const base::string16& index,
......
...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
namespace ui { namespace ui {
namespace ime { namespace ime {
struct SuggestionDetails;
// Font-related constants // Font-related constants
constexpr char kFontStyle[] = "Roboto"; constexpr char kFontStyle[] = "Roboto";
constexpr int kSuggestionFontSize = 14; constexpr int kSuggestionFontSize = 14;
...@@ -34,9 +37,7 @@ class UI_CHROMEOS_EXPORT SuggestionView : public views::View { ...@@ -34,9 +37,7 @@ class UI_CHROMEOS_EXPORT SuggestionView : public views::View {
SuggestionView(); SuggestionView();
~SuggestionView() override; ~SuggestionView() override;
void SetView(const base::string16& text, void SetView(const SuggestionDetails& details);
const size_t confirmed_length,
const bool show_tab);
void SetViewWithIndex(const base::string16& index, void SetViewWithIndex(const base::string16& index,
const base::string16& text); const base::string16& text);
......
...@@ -139,12 +139,10 @@ void SuggestionWindowView::MakeVisible() { ...@@ -139,12 +139,10 @@ void SuggestionWindowView::MakeVisible() {
SizeToContents(); SizeToContents();
} }
void SuggestionWindowView::Show(const base::string16& text, void SuggestionWindowView::Show(const SuggestionDetails& details) {
const size_t confirmed_length,
const bool show_tab) {
MaybeInitializeSuggestionViews(1); MaybeInitializeSuggestionViews(1);
candidate_views_[0]->SetEnabled(true); candidate_views_[0]->SetEnabled(true);
candidate_views_[0]->SetView(text, confirmed_length, show_tab); candidate_views_[0]->SetView(details);
candidate_views_[0]->SetMinWidth( candidate_views_[0]->SetMinWidth(
setting_link_view_->GetPreferredSize().width()); setting_link_view_->GetPreferredSize().width());
setting_link_view_->SetVisible(true); setting_link_view_->SetVisible(true);
......
...@@ -18,6 +18,8 @@ class AssistiveDelegate; ...@@ -18,6 +18,8 @@ class AssistiveDelegate;
class SettingLinkView; class SettingLinkView;
class SuggestionView; class SuggestionView;
struct SuggestionDetails;
// SuggestionWindowView is the main container of the suggestion window UI. // SuggestionWindowView is the main container of the suggestion window UI.
class UI_CHROMEOS_EXPORT SuggestionWindowView class UI_CHROMEOS_EXPORT SuggestionWindowView
: public views::BubbleDialogDelegateView { : public views::BubbleDialogDelegateView {
...@@ -30,9 +32,7 @@ class UI_CHROMEOS_EXPORT SuggestionWindowView ...@@ -30,9 +32,7 @@ class UI_CHROMEOS_EXPORT SuggestionWindowView
void Hide(); void Hide();
// Shows suggestion text. // Shows suggestion text.
void Show(const base::string16& text, void Show(const SuggestionDetails& details);
const size_t confirmed_length,
const bool show_tab);
void ShowMultipleCandidates(const std::vector<base::string16>& candidates); void ShowMultipleCandidates(const std::vector<base::string16>& candidates);
......
...@@ -14,6 +14,12 @@ namespace gfx { ...@@ -14,6 +14,12 @@ namespace gfx {
class Rect; class Rect;
} // namespace gfx } // namespace gfx
namespace ui {
namespace ime {
struct SuggestionDetails;
} // namespace ime
} // namespace ui
namespace chromeos { namespace chromeos {
struct AssistiveWindowProperties; struct AssistiveWindowProperties;
...@@ -27,9 +33,7 @@ class COMPONENT_EXPORT(UI_BASE_IME) IMEAssistiveWindowHandlerInterface { ...@@ -27,9 +33,7 @@ class COMPONENT_EXPORT(UI_BASE_IME) IMEAssistiveWindowHandlerInterface {
virtual void SetAssistiveWindowProperties( virtual void SetAssistiveWindowProperties(
const AssistiveWindowProperties& window) {} const AssistiveWindowProperties& window) {}
virtual void ShowSuggestion(const base::string16& text, virtual void ShowSuggestion(const ui::ime::SuggestionDetails& details) {}
const size_t confirmed_length,
const bool show_tab) {}
virtual void ShowMultipleSuggestions( virtual void ShowMultipleSuggestions(
const std::vector<base::string16>& suggestions) {} const std::vector<base::string16>& suggestions) {}
......
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