diff options
Diffstat (limited to 'chromium/ui/views/controls/textfield')
5 files changed, 69 insertions, 72 deletions
diff --git a/chromium/ui/views/controls/textfield/textfield.cc b/chromium/ui/views/controls/textfield/textfield.cc index d8e8fd0ace0..d0c5e12a9d1 100644 --- a/chromium/ui/views/controls/textfield/textfield.cc +++ b/chromium/ui/views/controls/textfield/textfield.cc @@ -65,8 +65,8 @@ #endif #if defined(OS_LINUX) && !defined(OS_CHROMEOS) -#include "ui/base/ime/linux/text_edit_command_auralinux.h" -#include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" +#include "ui/base/ime/linux/text_edit_command_auralinux.h" // nogncheck +#include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" // nogncheck #endif #if defined(USE_X11) @@ -330,6 +330,12 @@ Textfield::Textfield() AddAccelerator(ui::Accelerator(ui::VKEY_C, ui::EF_CONTROL_DOWN)); AddAccelerator(ui::Accelerator(ui::VKEY_V, ui::EF_CONTROL_DOWN)); #endif + + // Sometimes there are additional ignored views, such as the View representing + // the cursor, inside the text field. These should always be ignored by + // accessibility since a plain text field should always be a leaf node in the + // accessibility trees of all the platforms we support. + GetViewAccessibility().OverrideIsLeaf(true); } Textfield::~Textfield() { @@ -677,8 +683,10 @@ gfx::Size Textfield::GetMinimumSize() const { void Textfield::SetBorder(std::unique_ptr<Border> b) { use_focus_ring_ = false; - if (focus_ring_) - focus_ring_.reset(); + if (focus_ring_) { + RemoveChildViewT(focus_ring_); + focus_ring_ = nullptr; + } View::SetBorder(std::move(b)); } @@ -1025,6 +1033,7 @@ void Textfield::OnDragDone() { void Textfield::GetAccessibleNodeData(ui::AXNodeData* node_data) { node_data->role = ax::mojom::Role::kTextField; + if (label_ax_id_) { node_data->AddIntListAttribute(ax::mojom::IntListAttribute::kLabelledbyIds, {label_ax_id_}); @@ -1427,7 +1436,7 @@ bool Textfield::GetAcceleratorForCommandId(int command_id, void Textfield::ExecuteCommand(int command_id, int event_flags) { if (text_services_context_menu_ && text_services_context_menu_->SupportsCommand(command_id)) { - text_services_context_menu_->ExecuteCommand(command_id); + text_services_context_menu_->ExecuteCommand(command_id, event_flags); return; } @@ -1786,8 +1795,11 @@ ukm::SourceId Textfield::GetClientSourceForMetrics() const { } bool Textfield::ShouldDoLearning() { - // TODO(https://crbug.com/311180): Implement this method. - NOTIMPLEMENTED_LOG_ONCE(); + if (should_do_learning_.has_value()) + return should_do_learning_.value(); + + NOTIMPLEMENTED_LOG_ONCE() << "A Textfield does not support ShouldDoLearning"; + DVLOG(1) << "This Textfield instance does not support ShouldDoLearning"; return false; } @@ -1806,6 +1818,14 @@ bool Textfield::SetCompositionFromExistingText( } #endif +#if defined(OS_CHROMEOS) +bool Textfield::SetAutocorrectRange(const base::string16& autocorrect_text, + const gfx::Range& range) { + // TODO(crbug.com/1091088) Implement autocorrect range textfield handling. + return false; +} +#endif + #if defined(OS_WIN) void Textfield::GetActiveTextInputControlLayoutBounds( base::Optional<gfx::Rect>* control_bounds, diff --git a/chromium/ui/views/controls/textfield/textfield.h b/chromium/ui/views/controls/textfield/textfield.h index 825c45513cf..775ce4f9683 100644 --- a/chromium/ui/views/controls/textfield/textfield.h +++ b/chromium/ui/views/controls/textfield/textfield.h @@ -377,12 +377,20 @@ class VIEWS_EXPORT Textfield : public View, ukm::SourceId GetClientSourceForMetrics() const override; bool ShouldDoLearning() override; + // Set whether the text should be used to improve typing suggestions. + void SetShouldDoLearning(bool value) { should_do_learning_ = value; } + #if defined(OS_WIN) || defined(OS_CHROMEOS) bool SetCompositionFromExistingText( const gfx::Range& range, const std::vector<ui::ImeTextSpan>& ui_ime_text_spans) override; #endif +#if defined(OS_CHROMEOS) + bool SetAutocorrectRange(const base::string16& autocorrect_text, + const gfx::Range& range) override; +#endif + #if defined(OS_WIN) void GetActiveTextInputControlLayoutBounds( base::Optional<gfx::Rect>* control_bounds, @@ -651,6 +659,9 @@ class VIEWS_EXPORT Textfield : public View, // True if this textfield should use a focus ring to indicate focus. bool use_focus_ring_ = true; + // Whether the text should be used to improve typing suggestions. + base::Optional<bool> should_do_learning_; + // Context menu related members. std::unique_ptr<ui::SimpleMenuModel> context_menu_contents_; std::unique_ptr<ViewsTextServicesContextMenu> text_services_context_menu_; @@ -669,7 +680,7 @@ class VIEWS_EXPORT Textfield : public View, ui::TextInputClient::FOCUS_REASON_NONE; // The focus ring for this TextField. - std::unique_ptr<FocusRing> focus_ring_; + FocusRing* focus_ring_ = nullptr; // The password char reveal index, for testing only. int password_char_reveal_index_ = -1; diff --git a/chromium/ui/views/controls/textfield/textfield_test_api.cc b/chromium/ui/views/controls/textfield/textfield_test_api.cc index 099f22e9bcf..40176fa3a73 100644 --- a/chromium/ui/views/controls/textfield/textfield_test_api.cc +++ b/chromium/ui/views/controls/textfield/textfield_test_api.cc @@ -5,7 +5,6 @@ #include "ui/views/controls/textfield/textfield_test_api.h" #include "ui/gfx/geometry/rect.h" -#include "ui/views/controls/views_text_services_context_menu.h" namespace views { @@ -34,12 +33,6 @@ void TextfieldTestApi::SetCursorViewRect(gfx::Rect bounds) { textfield_->cursor_view_->SetBoundsRect(bounds); } -bool TextfieldTestApi::IsTextDirectionCheckedInContextMenu( - base::i18n::TextDirection direction) const { - return ViewsTextServicesContextMenu::IsTextDirectionCheckedForTesting( - textfield_->text_services_context_menu_.get(), direction); -} - bool TextfieldTestApi::ShouldShowCursor() const { return textfield_->ShouldShowCursor(); } diff --git a/chromium/ui/views/controls/textfield/textfield_test_api.h b/chromium/ui/views/controls/textfield/textfield_test_api.h index 3f346da6059..78436bcb5a4 100644 --- a/chromium/ui/views/controls/textfield/textfield_test_api.h +++ b/chromium/ui/views/controls/textfield/textfield_test_api.h @@ -5,8 +5,6 @@ #ifndef UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_TEST_API_H_ #define UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_TEST_API_H_ -#include "base/i18n/rtl.h" -#include "base/macros.h" #include "ui/views/controls/textfield/textfield.h" namespace views { @@ -15,6 +13,9 @@ namespace views { class TextfieldTestApi { public: explicit TextfieldTestApi(Textfield* textfield); + TextfieldTestApi(const TextfieldTestApi&) = delete; + TextfieldTestApi& operator=(const TextfieldTestApi&) = delete; + ~TextfieldTestApi() = default; void UpdateContextMenu(); @@ -53,15 +54,10 @@ class TextfieldTestApi { return textfield_->cursor_view_->GetVisible(); } - bool IsTextDirectionCheckedInContextMenu( - base::i18n::TextDirection direction) const; - bool ShouldShowCursor() const; private: Textfield* textfield_; - - DISALLOW_COPY_AND_ASSIGN(TextfieldTestApi); }; } // namespace views diff --git a/chromium/ui/views/controls/textfield/textfield_unittest.cc b/chromium/ui/views/controls/textfield/textfield_unittest.cc index 456cecaba14..5a25faebf58 100644 --- a/chromium/ui/views/controls/textfield/textfield_unittest.cc +++ b/chromium/ui/views/controls/textfield/textfield_unittest.cc @@ -64,7 +64,7 @@ #endif #if defined(OS_LINUX) && !defined(OS_CHROMEOS) -#include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" +#include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" // nogncheck #endif #if defined(OS_CHROMEOS) @@ -74,6 +74,7 @@ #if defined(OS_MACOSX) #include "ui/base/cocoa/secure_password_input.h" +#include "ui/base/cocoa/text_services_context_menu.h" #endif using base::ASCIIToUTF16; @@ -459,8 +460,7 @@ class TextfieldTest : public ViewsTestBase, public TextfieldController { widget_->Init(std::move(params)); input_method_->SetDelegate( test::WidgetTest::GetInputMethodDelegateForWidget(widget_)); - View* container = new View(); - widget_->SetContentsView(container); + View* container = widget_->SetContentsView(std::make_unique<View>()); container->AddChildView(textfield_); textfield_->SetBoundsRect(params.bounds); textfield_->SetID(1); @@ -1395,6 +1395,17 @@ TEST_F(TextfieldTest, TextInputType_InsertionTest) { textfield_->GetText()); } +TEST_F(TextfieldTest, ShouldDoLearning) { + InitTextfield(); + + // Defaults to false. + EXPECT_EQ(false, textfield_->ShouldDoLearning()); + + // The value can be set. + textfield_->SetShouldDoLearning(true); + EXPECT_EQ(true, textfield_->ShouldDoLearning()); +} + TEST_F(TextfieldTest, TextInputType) { InitTextfield(); @@ -3478,13 +3489,12 @@ TEST_F(TextfieldTest, TextfieldBoundsChangeTest) { TEST_F(TextfieldTest, TextfieldInitialization) { TestTextfield* new_textfield = new TestTextfield(); new_textfield->set_controller(this); - View* container = new View(); Widget* widget(new Widget()); Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); params.bounds = gfx::Rect(100, 100, 100, 100); widget->Init(std::move(params)); - widget->SetContentsView(container); + View* container = widget->SetContentsView(std::make_unique<View>()); container->AddChildView(new_textfield); new_textfield->SetBoundsRect(params.bounds); @@ -3624,56 +3634,23 @@ TEST_F(TextfieldTest, TextServicesContextMenuTextDirectionTest) { base::i18n::TextDirection::LEFT_TO_RIGHT); test_api_->UpdateContextMenu(); - EXPECT_FALSE(test_api_->IsTextDirectionCheckedInContextMenu( - base::i18n::TextDirection::UNKNOWN_DIRECTION)); - EXPECT_TRUE(test_api_->IsTextDirectionCheckedInContextMenu( - base::i18n::TextDirection::LEFT_TO_RIGHT)); - EXPECT_FALSE(test_api_->IsTextDirectionCheckedInContextMenu( - base::i18n::TextDirection::RIGHT_TO_LEFT)); + EXPECT_FALSE(textfield_->IsCommandIdChecked( + ui::TextServicesContextMenu::kWritingDirectionDefault)); + EXPECT_TRUE(textfield_->IsCommandIdChecked( + ui::TextServicesContextMenu::kWritingDirectionLtr)); + EXPECT_FALSE(textfield_->IsCommandIdChecked( + ui::TextServicesContextMenu::kWritingDirectionRtl)); textfield_->ChangeTextDirectionAndLayoutAlignment( base::i18n::TextDirection::RIGHT_TO_LEFT); test_api_->UpdateContextMenu(); - EXPECT_FALSE(test_api_->IsTextDirectionCheckedInContextMenu( - base::i18n::TextDirection::UNKNOWN_DIRECTION)); - EXPECT_FALSE(test_api_->IsTextDirectionCheckedInContextMenu( - base::i18n::TextDirection::LEFT_TO_RIGHT)); - EXPECT_TRUE(test_api_->IsTextDirectionCheckedInContextMenu( - base::i18n::TextDirection::RIGHT_TO_LEFT)); -} - -// Tests to see if the look up item is updated when the textfield's selected -// text has changed. -TEST_F(TextfieldTest, LookUpItemUpdate) { - InitTextfield(); - EXPECT_TRUE(textfield_->context_menu_controller()); - - const base::string16 kTextOne = ASCIIToUTF16("crake"); - textfield_->SetText(kTextOne); - textfield_->SelectAll(false); - - ui::MenuModel* context_menu = GetContextMenuModel(); - EXPECT_TRUE(context_menu); - EXPECT_GT(context_menu->GetItemCount(), 0); - EXPECT_EQ(context_menu->GetLabelAt(0), - l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_LOOK_UP, kTextOne)); - -#if !defined(OS_MACOSX) - // Mac context menus don't behave this way: it's not possible to update the - // text while the menu is still "open", but also the selection can't change - // while the menu is open (because the user can't interact with the rest of - // the app). - const base::string16 kTextTwo = ASCIIToUTF16("rail"); - textfield_->SetText(kTextTwo); - textfield_->SelectAll(false); - - context_menu = GetContextMenuModel(); - EXPECT_TRUE(context_menu); - EXPECT_GT(context_menu->GetItemCount(), 0); - EXPECT_EQ(context_menu->GetLabelAt(0), - l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_LOOK_UP, kTextTwo)); -#endif + EXPECT_FALSE(textfield_->IsCommandIdChecked( + ui::TextServicesContextMenu::kWritingDirectionDefault)); + EXPECT_FALSE(textfield_->IsCommandIdChecked( + ui::TextServicesContextMenu::kWritingDirectionLtr)); + EXPECT_TRUE(textfield_->IsCommandIdChecked( + ui::TextServicesContextMenu::kWritingDirectionRtl)); } // Tests to see if the look up item is hidden for password fields. |