Commit 6103f375 authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

Revert "[omnibox] [rich-autocompletion] Add multi-sel & comp-text to OmniboxView"

This reverts commit 978f825e.

Reason for revert: Breaks Linux MSAN due to use-of-uninitialized-value: https://ci.chromium.org/p/chromium/builders/ci/Linux%20MSan%20Tests/24094

Original change's description:
> [omnibox] [rich-autocompletion] Add multi-sel & comp-text to OmniboxView
> 
> *Rich autocompletion background*
> 
> Currently, autocompletion is limited to when the user types a prefix of
> the URL. E.g. 'wiki' can autocomplete 'wiki.org/thecookinglist - top
> awesome recipes'.
> 
> Rich autocompletion will allow autocompletion even when the input is
> from the suggestion title or middle of the URL. E.g. 'thecoo' and
> 'recip' will also autocomplete 'wiki.org/thecookinglist - top awesome
> recipes'.
> 
> Design doc with further details: go/richomniboxautocompletion
> 
> Previous CLs:
> - crrev.com/c/2107796 added chrome://flags flags
> - crrev.com/c/2108780 supported multiselection in textfield views.
> - crrev.com/c/2199859 Add complementary omnibox view.
> 
> *This CL*
> 
> This is the 4th CL for rich autocompletion. It wires in the omnibox view
> to textfield's multiselection & location bar's complementary text.
> 
> This CL has no user facing changes. Followup CLs will wire in rich
> autocompletion to make use of these changes.
> 
> Bug: 1062446
> Change-Id: I919965049837fd5421fd2b8f0dabc6d3489dabf4
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2204545
> Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
> Auto-Submit: manuk hovanesian <manukh@chromium.org>
> Reviewed-by: Stepan Khapugin <stkhapugin@chromium.org>
> Reviewed-by: Tommy Li <tommycli@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#772612}

TBR=tommycli@chromium.org,stkhapugin@chromium.org,manukh@chromium.org

Change-Id: I0ee50606f616c59fe7233ada53518c3d01b3c2a3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1062446
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2219891Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772648}
parent 146cb492
...@@ -120,17 +120,14 @@ class OmniboxViewViews : public OmniboxView, ...@@ -120,17 +120,14 @@ class OmniboxViewViews : public OmniboxView,
using OmniboxView::SetUserText; using OmniboxView::SetUserText;
void SetUserText(const base::string16& text, void SetUserText(const base::string16& text,
bool update_popup) override; bool update_popup) override;
void SetWindowTextAndCaretPos( void SetWindowTextAndCaretPos(const base::string16& text,
const base::string16& text, size_t caret_pos,
size_t caret_pos, bool update_popup,
bool update_popup, bool notify_text_changed) override;
bool notify_text_changed,
const base::string16& additional_text = base::string16()) override;
void EnterKeywordModeForDefaultSearchProvider() override; void EnterKeywordModeForDefaultSearchProvider() override;
bool IsSelectAll() const override; bool IsSelectAll() const override;
void GetSelectionBounds(base::string16::size_type* start, void GetSelectionBounds(base::string16::size_type* start,
base::string16::size_type* end) const override; base::string16::size_type* end) const override;
size_t GetAllSelectionsLength() const override;
void SelectAll(bool reversed) override; void SelectAll(bool reversed) override;
void RevertAll() override; void RevertAll() override;
void SetFocus(bool is_user_initiated) override; void SetFocus(bool is_user_initiated) override;
...@@ -177,15 +174,9 @@ class OmniboxViewViews : public OmniboxView, ...@@ -177,15 +174,9 @@ class OmniboxViewViews : public OmniboxView,
OTHER, OTHER,
}; };
// Update the field with |text| and set the selection. |ranges| should not be // Update the field with |text| and set the selection.
// empty; even text with no selections must have at least 1 empty range in void SetTextAndSelectedRange(const base::string16& text,
// |ranges| to indicate the cursor position. const gfx::Range& range);
void SetTextAndSelectedRanges(
const base::string16& text,
const std::vector<gfx::Range>& ranges,
const base::string16& additional_text = base::string16());
void SetSelectedRanges(const std::vector<gfx::Range>& ranges);
// Returns the selected text. // Returns the selected text.
base::string16 GetSelectedText() const; base::string16 GetSelectedText() const;
...@@ -232,11 +223,8 @@ class OmniboxViewViews : public OmniboxView, ...@@ -232,11 +223,8 @@ class OmniboxViewViews : public OmniboxView,
const AutocompleteMatch& match, const AutocompleteMatch& match,
bool save_original_selection, bool save_original_selection,
bool notify_text_changed) override; bool notify_text_changed) override;
void OnInlineAutocompleteTextMaybeChanged( bool OnInlineAutocompleteTextMaybeChanged(const base::string16& display_text,
const base::string16& display_text, size_t user_text_length) override;
size_t user_text_length,
size_t user_text_start = 0,
const base::string16& additional_text = base::string16()) override;
void OnInlineAutocompleteTextCleared() override; void OnInlineAutocompleteTextCleared() override;
void OnRevertTemporaryText(const base::string16& display_text, void OnRevertTemporaryText(const base::string16& display_text,
const AutocompleteMatch& match) override; const AutocompleteMatch& match) override;
...@@ -316,11 +304,11 @@ class OmniboxViewViews : public OmniboxView, ...@@ -316,11 +304,11 @@ class OmniboxViewViews : public OmniboxView,
std::unique_ptr<PathFadeAnimation> path_fade_animation_; std::unique_ptr<PathFadeAnimation> path_fade_animation_;
// Selection persisted across temporary text changes, like popup suggestions. // Selection persisted across temporary text changes, like popup suggestions.
std::vector<gfx::Range> saved_temporary_selection_; gfx::Range saved_temporary_selection_;
// Holds the user's selection across focus changes. There is only a saved // Holds the user's selection across focus changes. There is only a saved
// selection if this range IsValid(). // selection if this range IsValid().
std::vector<gfx::Range> saved_selection_for_focus_change_; gfx::Range saved_selection_for_focus_change_;
// Tracking state before and after a possible change. // Tracking state before and after a possible change.
State state_before_change_; State state_before_change_;
......
...@@ -706,38 +706,6 @@ TEST_F(OmniboxViewViewsTest, SelectAllDuringMouseDown) { ...@@ -706,38 +706,6 @@ TEST_F(OmniboxViewViewsTest, SelectAllDuringMouseDown) {
EXPECT_TRUE(omnibox_view()->IsSelectAll()); EXPECT_TRUE(omnibox_view()->IsSelectAll());
} }
TEST_F(OmniboxViewViewsTest, SetWindowTextAndCaretPos) {
// googl|e.com
omnibox_view()->SetWindowTextAndCaretPos(base::UTF8ToUTF16("google.com"), 5,
false, false);
EXPECT_EQ(base::ASCIIToUTF16("google.com"), omnibox_view()->GetText());
EXPECT_EQ(omnibox_view()->GetRenderText()->GetAllSelections(),
(std::vector<Range>{{5, 5}}));
}
TEST_F(OmniboxViewViewsTest, OnInlineAutocompleteTextMaybeChanged) {
// No selection, google.com|
omnibox_view()->OnInlineAutocompleteTextMaybeChanged(
base::UTF8ToUTF16("google.com"), 10);
EXPECT_EQ(base::ASCIIToUTF16("google.com"), omnibox_view()->GetText());
EXPECT_EQ(omnibox_view()->GetRenderText()->GetAllSelections(),
(std::vector<Range>{{10, 10}}));
// Single selection, gmai[l.com]
omnibox_view()->OnInlineAutocompleteTextMaybeChanged(
base::UTF8ToUTF16("gmail.com"), 4);
EXPECT_EQ(base::ASCIIToUTF16("gmail.com"), omnibox_view()->GetText());
EXPECT_EQ(omnibox_view()->GetRenderText()->GetAllSelections(),
(std::vector<Range>{{9, 4}}));
// Multiselection, [go]ogl[e.com]
omnibox_view()->OnInlineAutocompleteTextMaybeChanged(
base::UTF8ToUTF16("google.com"), 3, 2);
EXPECT_EQ(base::ASCIIToUTF16("google.com"), omnibox_view()->GetText());
EXPECT_EQ(omnibox_view()->GetRenderText()->GetAllSelections(),
(std::vector<Range>{{10, 5}, {0, 2}}));
}
class OmniboxViewViewsClipboardTest class OmniboxViewViewsClipboardTest
: public OmniboxViewViewsTest, : public OmniboxViewViewsTest,
public ::testing::WithParamInterface<ui::TextEditCommand> { public ::testing::WithParamInterface<ui::TextEditCommand> {
...@@ -1346,7 +1314,6 @@ TEST_F(OmniboxViewViewsSteadyStateElisionsAndQueryInOmniboxTest, ...@@ -1346,7 +1314,6 @@ TEST_F(OmniboxViewViewsSteadyStateElisionsAndQueryInOmniboxTest,
EXPECT_FALSE(omnibox_view()->scheme_range().IsValid()); EXPECT_FALSE(omnibox_view()->scheme_range().IsValid());
} }
// TODO (manukh) move up to where the other OmniboxViewViewsTest tests are.
TEST_F(OmniboxViewViewsTest, OverflowingAutocompleteText) { TEST_F(OmniboxViewViewsTest, OverflowingAutocompleteText) {
// Make the Omnibox narrow so it can't fit the entire string (~650px), but // Make the Omnibox narrow so it can't fit the entire string (~650px), but
// wide enough to fit the user text (~65px). // wide enough to fit the user text (~65px).
......
...@@ -1330,6 +1330,7 @@ void OmniboxEditModel::OnPopupDataChanged(const base::string16& text, ...@@ -1330,6 +1330,7 @@ void OmniboxEditModel::OnPopupDataChanged(const base::string16& text,
return; return;
} }
bool call_controller_onchanged = true;
inline_autocomplete_text_ = text; inline_autocomplete_text_ = text;
if (inline_autocomplete_text_.empty()) if (inline_autocomplete_text_.empty())
view_->OnInlineAutocompleteTextCleared(); view_->OnInlineAutocompleteTextCleared();
...@@ -1355,13 +1356,15 @@ void OmniboxEditModel::OnPopupDataChanged(const base::string16& text, ...@@ -1355,13 +1356,15 @@ void OmniboxEditModel::OnPopupDataChanged(const base::string16& text,
// caret or selection correctly so the caret positioning we do here won't // caret or selection correctly so the caret positioning we do here won't
// matter. // matter.
view_->SetWindowTextAndCaretPos(user_text, 0, false, true); view_->SetWindowTextAndCaretPos(user_text, 0, false, true);
} else } else if (view_->OnInlineAutocompleteTextMaybeChanged(
view_->OnInlineAutocompleteTextMaybeChanged( user_text + inline_autocomplete_text_, user_text.length())) {
user_text + inline_autocomplete_text_, user_text.length()); call_controller_onchanged = false;
}
// We need to invoke OnChanged in case the destination url changed (as could // We need to invoke OnChanged in case the destination url changed (as could
// happen when control is toggled). // happen when control is toggled).
OnChanged(); if (call_controller_onchanged)
OnChanged();
} }
bool OmniboxEditModel::OnAfterPossibleChange( bool OmniboxEditModel::OnAfterPossibleChange(
......
...@@ -19,20 +19,14 @@ ...@@ -19,20 +19,14 @@
#include "components/omnibox/browser/location_bar_model.h" #include "components/omnibox/browser/location_bar_model.h"
#include "components/omnibox/browser/omnibox_edit_controller.h" #include "components/omnibox/browser/omnibox_edit_controller.h"
#include "components/omnibox/browser/omnibox_edit_model.h" #include "components/omnibox/browser/omnibox_edit_model.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/omnibox/common/omnibox_features.h" #include "components/omnibox/common/omnibox_features.h"
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#if !defined(OS_ANDROID) && !defined(OS_IOS) #if !defined(OS_ANDROID) && !defined(OS_IOS)
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#endif #endif
OmniboxView::State::State() = default;
OmniboxView::State::State(const State& state) = default;
// static // static
base::string16 OmniboxView::StripJavascriptSchemas(const base::string16& text) { base::string16 OmniboxView::StripJavascriptSchemas(const base::string16& text) {
const base::string16 kJsPrefix( const base::string16 kJsPrefix(
...@@ -270,8 +264,6 @@ void OmniboxView::GetState(State* state) { ...@@ -270,8 +264,6 @@ void OmniboxView::GetState(State* state) {
state->keyword = model()->keyword(); state->keyword = model()->keyword();
state->is_keyword_selected = model()->is_keyword_selected(); state->is_keyword_selected = model()->is_keyword_selected();
GetSelectionBounds(&state->sel_start, &state->sel_end); GetSelectionBounds(&state->sel_start, &state->sel_end);
if (OmniboxFieldTrial::RichAutocompletionAutocompleteNonPrefix())
state->all_sel_length = GetAllSelectionsLength();
} }
OmniboxView::StateChanges OmniboxView::GetStateChanges(const State& before, OmniboxView::StateChanges OmniboxView::GetStateChanges(const State& before,
...@@ -302,14 +294,8 @@ OmniboxView::StateChanges OmniboxView::GetStateChanges(const State& before, ...@@ -302,14 +294,8 @@ OmniboxView::StateChanges OmniboxView::GetStateChanges(const State& before,
// sure the caret, which should be after any insertion, hasn't moved // sure the caret, which should be after any insertion, hasn't moved
// forward of the old selection start.) // forward of the old selection start.)
state_changes.just_deleted_text = state_changes.just_deleted_text =
before.text.length() > after.text.length() && (before.text.length() > after.text.length()) &&
after.sel_start <= std::min(before.sel_start, before.sel_end); (after.sel_start <= std::min(before.sel_start, before.sel_end));
if (OmniboxFieldTrial::RichAutocompletionAutocompleteNonPrefix()) {
state_changes.just_deleted_text =
state_changes.just_deleted_text &&
after.sel_start <=
std::max(before.sel_start, before.sel_end) - before.all_sel_length;
}
return state_changes; return state_changes;
} }
......
...@@ -103,15 +103,11 @@ class OmniboxView { ...@@ -103,15 +103,11 @@ class OmniboxView {
bool update_popup); bool update_popup);
// Sets the window text and the caret position. |notify_text_changed| is true // Sets the window text and the caret position. |notify_text_changed| is true
// if the model should be notified of the change. If rich autocompletion is // if the model should be notified of the change.
// enabled, |additional_text| is displayed in a non-editable views::Label virtual void SetWindowTextAndCaretPos(const base::string16& text,
// adjacent to the omnibox. size_t caret_pos,
virtual void SetWindowTextAndCaretPos( bool update_popup,
const base::string16& text, bool notify_text_changed) = 0;
size_t caret_pos,
bool update_popup,
bool notify_text_changed,
const base::string16& additional_text = base::string16()) = 0;
// Sets the caret position. Removes any selection. Clamps the requested caret // Sets the caret position. Removes any selection. Clamps the requested caret
// position to the length of the current text. // position to the length of the current text.
...@@ -130,11 +126,6 @@ class OmniboxView { ...@@ -130,11 +126,6 @@ class OmniboxView {
// to the current cursor position. // to the current cursor position.
virtual void GetSelectionBounds(size_t* start, size_t* end) const = 0; virtual void GetSelectionBounds(size_t* start, size_t* end) const = 0;
// Returns the sum of all selections' lengths. This is used to detect when
// the user has deleted text, and therefore, their input should not be
// autocompleted.
virtual size_t GetAllSelectionsLength() const = 0;
// Selects all the text in the edit. Use this in place of SetSelAll() to // Selects all the text in the edit. Use this in place of SetSelAll() to
// avoid selecting the "phantom newline" at the end of the edit. // avoid selecting the "phantom newline" at the end of the edit.
virtual void SelectAll(bool reversed) = 0; virtual void SelectAll(bool reversed) = 0;
...@@ -177,17 +168,11 @@ class OmniboxView { ...@@ -177,17 +168,11 @@ class OmniboxView {
bool notify_text_changed) = 0; bool notify_text_changed) = 0;
// Called when the inline autocomplete text in the model may have changed. // Called when the inline autocomplete text in the model may have changed.
// |display_text| is the new text to show. |user_text_start| and // |display_text| is the new text to show; |user_text_length| is the length of
// |user_text_length| are the start position and length of the user input // the user input portion of that (so, up to but not including the inline
// portion of the text (not including the inline autocompletion or prefix // autocompletion). Returns whether the display text actually changed.
// inline autocompletion). If rich autocompletion is enabled, virtual bool OnInlineAutocompleteTextMaybeChanged(
// |additional_text| is displayed in a non-editable views::Label adjacent to const base::string16& display_text, size_t user_text_length) = 0;
// the omnibox.
virtual void OnInlineAutocompleteTextMaybeChanged(
const base::string16& display_text,
size_t user_text_length,
size_t user_text_start = 0,
const base::string16& additional_text = base::string16()) = 0;
// Called when the inline autocomplete text in the model has been cleared. // Called when the inline autocomplete text in the model has been cleared.
virtual void OnInlineAutocompleteTextCleared() = 0; virtual void OnInlineAutocompleteTextCleared() = 0;
...@@ -266,10 +251,6 @@ class OmniboxView { ...@@ -266,10 +251,6 @@ class OmniboxView {
bool is_keyword_selected; bool is_keyword_selected;
size_t sel_start; size_t sel_start;
size_t sel_end; size_t sel_end;
size_t all_sel_length;
State();
State(const State& state);
}; };
OmniboxView(OmniboxEditController* controller, OmniboxView(OmniboxEditController* controller,
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_model.h"
...@@ -21,7 +20,6 @@ ...@@ -21,7 +20,6 @@
#include "components/omnibox/browser/test_omnibox_edit_controller.h" #include "components/omnibox/browser/test_omnibox_edit_controller.h"
#include "components/omnibox/browser/test_omnibox_edit_model.h" #include "components/omnibox/browser/test_omnibox_edit_model.h"
#include "components/omnibox/browser/test_omnibox_view.h" #include "components/omnibox/browser/test_omnibox_view.h"
#include "components/omnibox/common/omnibox_features.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/color_palette.h" #include "ui/gfx/color_palette.h"
#include "ui/gfx/favicon_size.h" #include "ui/gfx/favicon_size.h"
...@@ -212,148 +210,4 @@ TEST_F(OmniboxViewTest, GetIcon_Favicon) { ...@@ -212,148 +210,4 @@ TEST_F(OmniboxViewTest, GetIcon_Favicon) {
} }
#endif // !defined(OS_IOS) #endif // !defined(OS_IOS)
// Tests GetStateChanges correctly determines if text was deleted.
TEST_F(OmniboxViewTest, GetStateChanges_DeletedText) {
{
// Continuing autocompletion
auto state_before =
TestOmniboxView::CreateState("google.com", 10, 3, 0); // goo[gle.com]
auto state_after = TestOmniboxView::CreateState("goog", 4, 4, 0); // goog|
auto state_changes = view()->GetStateChanges(state_before, state_after);
EXPECT_FALSE(state_changes.just_deleted_text);
}
{
// Typing not the autocompletion
auto state_before =
TestOmniboxView::CreateState("google.com", 1, 10, 0); // g[oogle.com]
auto state_after = TestOmniboxView::CreateState("gi", 2, 2, 0); // gi|
auto state_changes = view()->GetStateChanges(state_before, state_after);
EXPECT_FALSE(state_changes.just_deleted_text);
}
{
// Deleting autocompletion
auto state_before =
TestOmniboxView::CreateState("google.com", 1, 10, 0); // g[oogle.com]
auto state_after = TestOmniboxView::CreateState("g", 1, 1, 0); // g|
auto state_changes = view()->GetStateChanges(state_before, state_after);
EXPECT_TRUE(state_changes.just_deleted_text);
}
{
// Inserting
auto state_before =
TestOmniboxView::CreateState("goole.com", 3, 3, 0); // goo|le.com
auto state_after =
TestOmniboxView::CreateState("google.com", 4, 4, 0); // goog|le.com
auto state_changes = view()->GetStateChanges(state_before, state_after);
EXPECT_FALSE(state_changes.just_deleted_text);
}
{
// Deleting
auto state_before =
TestOmniboxView::CreateState("googgle.com", 5, 5, 0); // googg|le.com
auto state_after =
TestOmniboxView::CreateState("google.com", 4, 4, 0); // goog|le.com
auto state_changes = view()->GetStateChanges(state_before, state_after);
EXPECT_TRUE(state_changes.just_deleted_text);
}
{
// Replacing
auto state_before =
TestOmniboxView::CreateState("goojle.com", 3, 4, 0); // goo[j]le.com
auto state_after =
TestOmniboxView::CreateState("google.com", 4, 4, 0); // goog|le.com
auto state_changes = view()->GetStateChanges(state_before, state_after);
EXPECT_FALSE(state_changes.just_deleted_text);
}
}
// Tests GetStateChanges correctly determines if text was deleted.
TEST_F(OmniboxViewTest, GetStateChanges_DeletedText_RichAutocompletion) {
base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeatureWithParameters(
omnibox::kRichAutocompletion,
{{OmniboxFieldTrial::kRichAutocompletionAutocompleteNonPrefix, "true"}});
// Cases with single selection
{
// Continuing autocompletion
auto state_before =
TestOmniboxView::CreateState("google.com", 10, 3, 7); // goo[gle.com]
auto state_after = TestOmniboxView::CreateState("goog", 4, 4, 0); // goog|
auto state_changes = view()->GetStateChanges(state_before, state_after);
EXPECT_FALSE(state_changes.just_deleted_text);
}
{
// Typing not the autocompletion
auto state_before =
TestOmniboxView::CreateState("google.com", 1, 10, 9); // g[oogle.com]
auto state_after = TestOmniboxView::CreateState("gi", 2, 2, 0); // gi|
auto state_changes = view()->GetStateChanges(state_before, state_after);
EXPECT_FALSE(state_changes.just_deleted_text);
}
{
// Deleting autocompletion
auto state_before =
TestOmniboxView::CreateState("google.com", 1, 10, 9); // g[oogle.com]
auto state_after = TestOmniboxView::CreateState("g", 1, 1, 0); // g|
auto state_changes = view()->GetStateChanges(state_before, state_after);
EXPECT_TRUE(state_changes.just_deleted_text);
}
{
// Inserting
auto state_before =
TestOmniboxView::CreateState("goole.com", 3, 3, 6); // goo|le.com
auto state_after =
TestOmniboxView::CreateState("google.com", 4, 4, 0); // goog|le.com
auto state_changes = view()->GetStateChanges(state_before, state_after);
EXPECT_FALSE(state_changes.just_deleted_text);
}
{
// Deleting
auto state_before =
TestOmniboxView::CreateState("googgle.com", 5, 5, 0); // googg|le.com
auto state_after =
TestOmniboxView::CreateState("google.com", 4, 4, 0); // goog|le.com
auto state_changes = view()->GetStateChanges(state_before, state_after);
EXPECT_TRUE(state_changes.just_deleted_text);
}
{
// Replacing
auto state_before =
TestOmniboxView::CreateState("goojle.com", 3, 4, 1); // goo[j]le.com
auto state_after =
TestOmniboxView::CreateState("google.com", 4, 4, 0); // goog|le.com
auto state_changes = view()->GetStateChanges(state_before, state_after);
EXPECT_FALSE(state_changes.just_deleted_text);
}
// Cases with multiselection
{
// Continuing autocompletion with multiselection
auto state_before =
TestOmniboxView::CreateState("google.com", 4, 10, 7); // [g]oog[le.com]
auto state_after = TestOmniboxView::CreateState("oogl", 4, 4, 0); // oogl|
auto state_changes = view()->GetStateChanges(state_before, state_after);
EXPECT_FALSE(state_changes.just_deleted_text);
}
{
// Typing not the autocompletion with multiselection
auto state_before =
TestOmniboxView::CreateState("google.com", 4, 10, 7); // [g]oog[le.com]
auto state_after = TestOmniboxView::CreateState("oogm", 4, 4, 0); // oogm|
auto state_changes = view()->GetStateChanges(state_before, state_after);
EXPECT_FALSE(state_changes.just_deleted_text);
}
{
// Deleting autocompletion with multiselection
auto state_before =
TestOmniboxView::CreateState("google.com", 4, 10, 7); // [g]oog[le.com]
auto state_after = TestOmniboxView::CreateState("oog", 3, 3, 0); // oog|
auto state_changes = view()->GetStateChanges(state_before, state_after);
EXPECT_TRUE(state_changes.just_deleted_text);
}
}
} // namespace } // namespace
...@@ -8,19 +8,6 @@ ...@@ -8,19 +8,6 @@
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
// static
OmniboxView::State TestOmniboxView::CreateState(std::string text,
size_t sel_start,
size_t sel_end,
size_t all_sel_length) {
OmniboxView::State state;
state.text = base::UTF8ToUTF16(text);
state.sel_start = sel_start;
state.sel_end = sel_end;
state.all_sel_length = all_sel_length;
return state;
}
void TestOmniboxView::SetModel(std::unique_ptr<OmniboxEditModel> model) { void TestOmniboxView::SetModel(std::unique_ptr<OmniboxEditModel> model) {
model_ = std::move(model); model_ = std::move(model);
} }
...@@ -29,12 +16,10 @@ base::string16 TestOmniboxView::GetText() const { ...@@ -29,12 +16,10 @@ base::string16 TestOmniboxView::GetText() const {
return text_; return text_;
} }
void TestOmniboxView::SetWindowTextAndCaretPos( void TestOmniboxView::SetWindowTextAndCaretPos(const base::string16& text,
const base::string16& text, size_t caret_pos,
size_t caret_pos, bool update_popup,
bool update_popup, bool notify_text_changed) {
bool notify_text_changed,
const base::string16& additional_text) {
text_ = text; text_ = text;
selection_ = gfx::Range(caret_pos); selection_ = gfx::Range(caret_pos);
} }
...@@ -48,10 +33,6 @@ void TestOmniboxView::GetSelectionBounds(size_t* start, size_t* end) const { ...@@ -48,10 +33,6 @@ void TestOmniboxView::GetSelectionBounds(size_t* start, size_t* end) const {
*end = selection_.end(); *end = selection_.end();
} }
size_t TestOmniboxView::GetAllSelectionsLength() const {
return 0;
}
void TestOmniboxView::SelectAll(bool reversed) { void TestOmniboxView::SelectAll(bool reversed) {
if (reversed) if (reversed)
selection_ = gfx::Range(text_.size(), 0); selection_ = gfx::Range(text_.size(), 0);
...@@ -70,11 +51,9 @@ void TestOmniboxView::OnTemporaryTextMaybeChanged( ...@@ -70,11 +51,9 @@ void TestOmniboxView::OnTemporaryTextMaybeChanged(
saved_temporary_selection_ = selection_; saved_temporary_selection_ = selection_;
} }
void TestOmniboxView::OnInlineAutocompleteTextMaybeChanged( bool TestOmniboxView::OnInlineAutocompleteTextMaybeChanged(
const base::string16& display_text, const base::string16& display_text,
size_t user_text_length, size_t user_text_length) {
size_t user_text_start,
const base::string16& additional_text) {
const bool text_changed = text_ != display_text; const bool text_changed = text_ != display_text;
text_ = display_text; text_ = display_text;
inline_autocomplete_text_ = display_text.substr(user_text_length); inline_autocomplete_text_ = display_text.substr(user_text_length);
...@@ -83,6 +62,8 @@ void TestOmniboxView::OnInlineAutocompleteTextMaybeChanged( ...@@ -83,6 +62,8 @@ void TestOmniboxView::OnInlineAutocompleteTextMaybeChanged(
// actually changed. // actually changed.
if (text_changed) if (text_changed)
selection_ = gfx::Range(text_.size(), user_text_length); selection_ = gfx::Range(text_.size(), user_text_length);
return text_changed;
} }
void TestOmniboxView::OnInlineAutocompleteTextCleared() { void TestOmniboxView::OnInlineAutocompleteTextCleared() {
......
...@@ -28,11 +28,6 @@ class TestOmniboxView : public OmniboxView { ...@@ -28,11 +28,6 @@ class TestOmniboxView : public OmniboxView {
return inline_autocomplete_text_; return inline_autocomplete_text_;
} }
static State CreateState(std::string text,
size_t sel_start,
size_t sel_end,
size_t all_sel_length);
// OmniboxView: // OmniboxView:
void Update() override {} void Update() override {}
void OpenMatch(const AutocompleteMatch& match, void OpenMatch(const AutocompleteMatch& match,
...@@ -42,17 +37,14 @@ class TestOmniboxView : public OmniboxView { ...@@ -42,17 +37,14 @@ class TestOmniboxView : public OmniboxView {
size_t selected_line, size_t selected_line,
base::TimeTicks match_selection_timestamp) override {} base::TimeTicks match_selection_timestamp) override {}
base::string16 GetText() const override; base::string16 GetText() const override;
void SetWindowTextAndCaretPos( void SetWindowTextAndCaretPos(const base::string16& text,
const base::string16& text, size_t caret_pos,
size_t caret_pos, bool update_popup,
bool update_popup, bool notify_text_changed) override;
bool notify_text_changed,
const base::string16& additional_text = base::string16()) override;
void SetCaretPos(size_t caret_pos) override {} void SetCaretPos(size_t caret_pos) override {}
void EnterKeywordModeForDefaultSearchProvider() override {} void EnterKeywordModeForDefaultSearchProvider() override {}
bool IsSelectAll() const override; bool IsSelectAll() const override;
void GetSelectionBounds(size_t* start, size_t* end) const override; void GetSelectionBounds(size_t* start, size_t* end) const override;
size_t GetAllSelectionsLength() const override;
void SelectAll(bool reversed) override; void SelectAll(bool reversed) override;
void RevertAll() override {} void RevertAll() override {}
void UpdatePopup() override {} void UpdatePopup() override {}
...@@ -62,11 +54,8 @@ class TestOmniboxView : public OmniboxView { ...@@ -62,11 +54,8 @@ class TestOmniboxView : public OmniboxView {
const AutocompleteMatch& match, const AutocompleteMatch& match,
bool save_original_selection, bool save_original_selection,
bool notify_text_changed) override; bool notify_text_changed) override;
void OnInlineAutocompleteTextMaybeChanged( bool OnInlineAutocompleteTextMaybeChanged(const base::string16& display_text,
const base::string16& display_text, size_t user_text_length) override;
size_t user_text_length,
size_t user_text_start = 0,
const base::string16& additional_text = base::string16()) override;
void OnInlineAutocompleteTextCleared() override; void OnInlineAutocompleteTextCleared() override;
void OnRevertTemporaryText(const base::string16& display_text, void OnRevertTemporaryText(const base::string16& display_text,
const AutocompleteMatch& match) override; const AutocompleteMatch& match) override;
...@@ -79,7 +68,6 @@ class TestOmniboxView : public OmniboxView { ...@@ -79,7 +68,6 @@ class TestOmniboxView : public OmniboxView {
void EmphasizeURLComponents() override {} void EmphasizeURLComponents() override {}
void SetEmphasis(bool emphasize, const gfx::Range& range) override {} void SetEmphasis(bool emphasize, const gfx::Range& range) override {}
void UpdateSchemeStyle(const gfx::Range& range) override {} void UpdateSchemeStyle(const gfx::Range& range) override {}
using OmniboxView::GetStateChanges;
private: private:
base::string16 text_; base::string16 text_;
......
...@@ -57,12 +57,10 @@ class OmniboxViewIOS : public OmniboxView, ...@@ -57,12 +57,10 @@ class OmniboxViewIOS : public OmniboxView,
size_t selected_line, size_t selected_line,
base::TimeTicks match_selection_timestamp) override; base::TimeTicks match_selection_timestamp) override;
base::string16 GetText() const override; base::string16 GetText() const override;
void SetWindowTextAndCaretPos( void SetWindowTextAndCaretPos(const base::string16& text,
const base::string16& text, size_t caret_pos,
size_t caret_pos, bool update_popup,
bool update_popup, bool notify_text_changed) override;
bool notify_text_changed,
const base::string16& additional_text = base::string16()) override;
void SetCaretPos(size_t caret_pos) override; void SetCaretPos(size_t caret_pos) override;
void RevertAll() override; void RevertAll() override;
void UpdatePopup() override; void UpdatePopup() override;
...@@ -70,11 +68,8 @@ class OmniboxViewIOS : public OmniboxView, ...@@ -70,11 +68,8 @@ class OmniboxViewIOS : public OmniboxView,
const AutocompleteMatch& match, const AutocompleteMatch& match,
bool save_original_selection, bool save_original_selection,
bool notify_text_changed) override; bool notify_text_changed) override;
void OnInlineAutocompleteTextMaybeChanged( bool OnInlineAutocompleteTextMaybeChanged(const base::string16& display_text,
const base::string16& display_text, size_t user_text_length) override;
size_t user_text_length,
size_t user_text_start = 0,
const base::string16& additional_text = base::string16()) override;
void OnBeforePossibleChange() override; void OnBeforePossibleChange() override;
bool OnAfterPossibleChange(bool allow_keyword_ui_change) override; bool OnAfterPossibleChange(bool allow_keyword_ui_change) override;
bool IsImeComposing() const override; bool IsImeComposing() const override;
...@@ -86,7 +81,6 @@ class OmniboxViewIOS : public OmniboxView, ...@@ -86,7 +81,6 @@ class OmniboxViewIOS : public OmniboxView,
bool IsSelectAll() const override; bool IsSelectAll() const override;
void GetSelectionBounds(base::string16::size_type* start, void GetSelectionBounds(base::string16::size_type* start,
base::string16::size_type* end) const override; base::string16::size_type* end) const override;
size_t GetAllSelectionsLength() const override;
void SelectAll(bool reversed) override {} void SelectAll(bool reversed) override {}
void SetFocus(bool is_user_initiated) override {} void SetFocus(bool is_user_initiated) override {}
void ApplyCaretVisibility() override {} void ApplyCaretVisibility() override {}
......
...@@ -114,12 +114,10 @@ base::string16 OmniboxViewIOS::GetText() const { ...@@ -114,12 +114,10 @@ base::string16 OmniboxViewIOS::GetText() const {
return base::SysNSStringToUTF16([field_ displayedText]); return base::SysNSStringToUTF16([field_ displayedText]);
} }
void OmniboxViewIOS::SetWindowTextAndCaretPos( void OmniboxViewIOS::SetWindowTextAndCaretPos(const base::string16& text,
const base::string16& text, size_t caret_pos,
size_t caret_pos, bool update_popup,
bool update_popup, bool notify_text_changed) {
bool notify_text_changed,
const base::string16& additional_text) {
// Do not call SetUserText() here, as the user has not triggered this change. // Do not call SetUserText() here, as the user has not triggered this change.
// Instead, set the field's text directly. // Instead, set the field's text directly.
// Set the field_ value before calling ApplyTextAttributes(), because that // Set the field_ value before calling ApplyTextAttributes(), because that
...@@ -190,16 +188,17 @@ void OmniboxViewIOS::OnTemporaryTextMaybeChanged( ...@@ -190,16 +188,17 @@ void OmniboxViewIOS::OnTemporaryTextMaybeChanged(
model()->OnChanged(); model()->OnChanged();
} }
void OmniboxViewIOS::OnInlineAutocompleteTextMaybeChanged( bool OmniboxViewIOS::OnInlineAutocompleteTextMaybeChanged(
const base::string16& display_text, const base::string16& display_text,
size_t user_text_length, size_t user_text_length) {
size_t user_text_start,
const base::string16& additional_text) {
if (display_text == GetText()) if (display_text == GetText())
return; return false;
NSAttributedString* as = ApplyTextAttributes(display_text); NSAttributedString* as = ApplyTextAttributes(display_text);
[field_ setText:as userTextLength:user_text_length]; [field_ setText:as userTextLength:user_text_length];
if (model())
model()->OnChanged();
return true;
} }
void OmniboxViewIOS::OnBeforePossibleChange() { void OmniboxViewIOS::OnBeforePossibleChange() {
...@@ -254,10 +253,6 @@ void OmniboxViewIOS::GetSelectionBounds(base::string16::size_type* start, ...@@ -254,10 +253,6 @@ void OmniboxViewIOS::GetSelectionBounds(base::string16::size_type* start,
} }
} }
size_t OmniboxViewIOS::GetAllSelectionsLength() const {
return 0;
}
gfx::NativeView OmniboxViewIOS::GetNativeView() const { gfx::NativeView OmniboxViewIOS::GetNativeView() const {
return nullptr; return nullptr;
} }
......
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