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") {
"input_method/ui/input_method_menu_item.h",
"input_method/ui/input_method_menu_manager.cc",
"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.h",
"input_method/ui/suggestion_window_view.cc",
......
......@@ -14,6 +14,7 @@
#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_properties.h"
#include "chrome/browser/chromeos/input_method/ui/suggestion_details.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/settings_window_manager_chromeos.h"
#include "chrome/browser/ui/webui/settings/chromeos/constants/routes.mojom.h"
......@@ -152,14 +153,13 @@ void AssistiveWindowController::FocusStateChanged() {
undo_window_->Hide();
}
void AssistiveWindowController::ShowSuggestion(const base::string16& text,
const size_t confirmed_length,
const bool show_tab) {
void AssistiveWindowController::ShowSuggestion(
const ui::ime::SuggestionDetails& details) {
if (!suggestion_window_view_)
InitSuggestionWindow();
suggestion_text_ = text;
confirmed_length_ = confirmed_length;
suggestion_window_view_->Show(text, confirmed_length, show_tab);
suggestion_text_ = details.text;
confirmed_length_ = details.confirmed_length;
suggestion_window_view_->Show(details);
}
void AssistiveWindowController::ShowMultipleSuggestions(
......
......@@ -72,9 +72,7 @@ class AssistiveWindowController : public views::WidgetObserver,
void SetBounds(const gfx::Rect& cursor_bounds) override;
void SetAssistiveWindowProperties(
const AssistiveWindowProperties& window) override;
void ShowSuggestion(const base::string16& text,
const size_t confirmed_length,
const bool show_tab) override;
void ShowSuggestion(const ui::ime::SuggestionDetails& details) override;
void ShowMultipleSuggestions(
const std::vector<base::string16>& suggestions) override;
void HighlightSuggestionCandidate(int index) override;
......
......@@ -5,6 +5,7 @@
#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/ui/suggestion_details.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/test/base/chrome_ash_test_base.h"
#include "chrome/test/base/testing_profile.h"
......@@ -54,8 +55,10 @@ class AssistiveWindowControllerTest : public ChromeAshTestBase {
TEST_F(AssistiveWindowControllerTest, ConfirmedLength0SetsSuggestionViewBound) {
// Sets up suggestion_view with confirmed_length = 0.
ui::IMEBridge::Get()->GetAssistiveWindowHandler()->ShowSuggestion(suggestion_,
0, false);
ui::ime::SuggestionDetails details;
details.text = suggestion_;
details.confirmed_length = 0;
ui::IMEBridge::Get()->GetAssistiveWindowHandler()->ShowSuggestion(details);
ui::ime::SuggestionWindowView* suggestion_view =
controller_->GetSuggestionWindowViewForTesting();
EXPECT_EQ(
......@@ -71,8 +74,10 @@ TEST_F(AssistiveWindowControllerTest, ConfirmedLength0SetsSuggestionViewBound) {
TEST_F(AssistiveWindowControllerTest,
ConfirmedLengthNot0DoesNotSetSuggestionViewBound) {
// Sets up suggestion_view with confirmed_length = 1.
ui::IMEBridge::Get()->GetAssistiveWindowHandler()->ShowSuggestion(suggestion_,
1, false);
ui::ime::SuggestionDetails details;
details.text = suggestion_;
details.confirmed_length = 1;
ui::IMEBridge::Get()->GetAssistiveWindowHandler()->ShowSuggestion(details);
ui::ime::SuggestionWindowView* suggestion_view =
controller_->GetSuggestionWindowViewForTesting();
EXPECT_EQ(
......@@ -88,8 +93,10 @@ TEST_F(AssistiveWindowControllerTest,
TEST_F(AssistiveWindowControllerTest,
SuggestionViewBoundIsResetAfterHideSuggestionThenShowAgain) {
// Sets up suggestion_view with confirmed_length = 1.
ui::IMEBridge::Get()->GetAssistiveWindowHandler()->ShowSuggestion(suggestion_,
1, false);
ui::ime::SuggestionDetails details;
details.text = suggestion_;
details.confirmed_length = 1;
ui::IMEBridge::Get()->GetAssistiveWindowHandler()->ShowSuggestion(details);
EXPECT_EQ(
1u,
ui::IMEBridge::Get()->GetAssistiveWindowHandler()->GetConfirmedLength());
......
......@@ -319,9 +319,7 @@ bool InputMethodEngine::SetCursorPosition(int context_id,
}
bool InputMethodEngine::SetSuggestion(int context_id,
const base::string16& text,
const size_t confirmed_length,
const bool show_tab,
const ui::ime::SuggestionDetails& details,
std::string* error) {
if (!IsActive()) {
*error = kErrorNotActive;
......@@ -335,7 +333,7 @@ bool InputMethodEngine::SetSuggestion(int context_id,
IMEAssistiveWindowHandlerInterface* aw_handler =
ui::IMEBridge::Get()->GetAssistiveWindowHandler();
if (aw_handler)
aw_handler->ShowSuggestion(text, confirmed_length, show_tab);
aw_handler->ShowSuggestion(details);
return true;
}
......
......@@ -29,6 +29,7 @@ namespace ime {
enum class AssistiveWindowType;
enum class ButtonId;
struct InputMethodMenuItem;
struct SuggestionDetails;
} // namespace ime
} // namespace ui
......@@ -113,9 +114,7 @@ class InputMethodEngine : public InputMethodEngineBase,
// SuggestionHandlerInterface overrides.
bool DismissSuggestion(int context_id, std::string* error) override;
bool SetSuggestion(int context_id,
const base::string16& text,
const size_t confirmed_length,
const bool show_tab,
const ui::ime::SuggestionDetails& details,
std::string* error) override;
bool AcceptSuggestion(int context_id, std::string* error) override;
void OnSuggestionsChanged(
......
......@@ -11,6 +11,7 @@
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.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/ui/ash/keyboard/chrome_keyboard_controller_client.h"
#include "chromeos/constants/chromeos_pref_names.h"
......@@ -236,8 +237,11 @@ void PersonalInfoSuggester::ShowSuggestion(const base::string16& text,
std::string error;
bool show_tab = GetTabAcceptanceCount() < kMaxTabAcceptanceCount;
suggestion_handler_->SetSuggestion(context_id_, text, confirmed_length,
show_tab, &error);
ui::ime::SuggestionDetails details;
details.text = text;
details.confirmed_length = confirmed_length;
details.show_tab = show_tab;
suggestion_handler_->SetSuggestion(context_id_, details, &error);
if (!error.empty()) {
LOG(ERROR) << "Fail to show suggestion. " << error;
}
......
......@@ -7,6 +7,7 @@
#include "ash/public/cpp/ash_pref_names.h"
#include "base/guid.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/test/base/testing_profile.h"
#include "chromeos/constants/chromeos_pref_names.h"
......@@ -32,13 +33,11 @@ class TestSuggestionHandler : public SuggestionHandlerInterface {
}
bool SetSuggestion(int context_id,
const base::string16& text,
const size_t confirmed_length,
const bool show_tab,
const ui::ime::SuggestionDetails& details,
std::string* error) override {
suggestion_text_ = text;
confirmed_length_ = confirmed_length;
show_tab_ = show_tab;
suggestion_text_ = details.text;
confirmed_length_ = details.confirmed_length;
show_tab_ = details.show_tab;
return true;
}
......
......@@ -8,6 +8,12 @@
#include <string>
#include "base/strings/string16.h"
namespace ui {
namespace ime {
struct SuggestionDetails;
} // namespace ime
} // namespace ui
namespace chromeos {
// An interface to handler suggestion related calls from assistive suggester.
......@@ -23,9 +29,7 @@ class SuggestionHandlerInterface {
// confirmed_text - the confirmed text that the user has typed so far.
// show_tab - whether to show "tab" in the suggestion window.
virtual bool SetSuggestion(int context_id,
const base::string16& text,
const size_t confirmed_length,
const bool show_tab,
const ui::ime::SuggestionDetails& details,
std::string* error) = 0;
// 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 @@
#include "chrome/browser/chromeos/input_method/ui/suggestion_view.h"
#include "base/macros.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/gfx/color_utils.h"
#include "ui/native_theme/native_theme.h"
......@@ -77,12 +78,10 @@ SuggestionView::SuggestionView() {
SuggestionView::~SuggestionView() = default;
void SuggestionView::SetView(const base::string16& text,
const size_t confirmed_length,
const bool show_tab) {
SetSuggestionText(text, confirmed_length);
void SuggestionView::SetView(const SuggestionDetails& details) {
SetSuggestionText(details.text, details.confirmed_length);
suggestion_width_ = suggestion_label_->GetPreferredSize().width();
annotation_label_->SetVisible(show_tab);
annotation_label_->SetVisible(details.show_tab);
}
void SuggestionView::SetViewWithIndex(const base::string16& index,
......
......@@ -14,6 +14,9 @@
namespace ui {
namespace ime {
struct SuggestionDetails;
// Font-related constants
constexpr char kFontStyle[] = "Roboto";
constexpr int kSuggestionFontSize = 14;
......@@ -34,9 +37,7 @@ class UI_CHROMEOS_EXPORT SuggestionView : public views::View {
SuggestionView();
~SuggestionView() override;
void SetView(const base::string16& text,
const size_t confirmed_length,
const bool show_tab);
void SetView(const SuggestionDetails& details);
void SetViewWithIndex(const base::string16& index,
const base::string16& text);
......
......@@ -139,12 +139,10 @@ void SuggestionWindowView::MakeVisible() {
SizeToContents();
}
void SuggestionWindowView::Show(const base::string16& text,
const size_t confirmed_length,
const bool show_tab) {
void SuggestionWindowView::Show(const SuggestionDetails& details) {
MaybeInitializeSuggestionViews(1);
candidate_views_[0]->SetEnabled(true);
candidate_views_[0]->SetView(text, confirmed_length, show_tab);
candidate_views_[0]->SetView(details);
candidate_views_[0]->SetMinWidth(
setting_link_view_->GetPreferredSize().width());
setting_link_view_->SetVisible(true);
......
......@@ -18,6 +18,8 @@ class AssistiveDelegate;
class SettingLinkView;
class SuggestionView;
struct SuggestionDetails;
// SuggestionWindowView is the main container of the suggestion window UI.
class UI_CHROMEOS_EXPORT SuggestionWindowView
: public views::BubbleDialogDelegateView {
......@@ -30,9 +32,7 @@ class UI_CHROMEOS_EXPORT SuggestionWindowView
void Hide();
// Shows suggestion text.
void Show(const base::string16& text,
const size_t confirmed_length,
const bool show_tab);
void Show(const SuggestionDetails& details);
void ShowMultipleCandidates(const std::vector<base::string16>& candidates);
......
......@@ -14,6 +14,12 @@ namespace gfx {
class Rect;
} // namespace gfx
namespace ui {
namespace ime {
struct SuggestionDetails;
} // namespace ime
} // namespace ui
namespace chromeos {
struct AssistiveWindowProperties;
......@@ -27,9 +33,7 @@ class COMPONENT_EXPORT(UI_BASE_IME) IMEAssistiveWindowHandlerInterface {
virtual void SetAssistiveWindowProperties(
const AssistiveWindowProperties& window) {}
virtual void ShowSuggestion(const base::string16& text,
const size_t confirmed_length,
const bool show_tab) {}
virtual void ShowSuggestion(const ui::ime::SuggestionDetails& details) {}
virtual void ShowMultipleSuggestions(
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