Commit 4f34e798 authored by Aaron Leventhal's avatar Aaron Leventhal Committed by Commit Bot

Do not fire accessible selection events for unfocused textfields

Deselecting the omnibox when the location bar is blurred causes
confusing screen reader verbalizations when switching tabs. This
behavior can be suppressed by only firing the selection event in a
textfield when it is actually focused.

This general fix makes sense as it would be confusing for screen
reader users to hear any selection-related information for a
textfield that is not currently focused.

Bug: 817967
Change-Id: I945383c27f51b5bc791ab2c35327862fdac32179
Reviewed-on: https://chromium-review.googlesource.com/944014
Commit-Queue: Aaron Leventhal <aleventhal@chromium.org>
Reviewed-by: default avatarMatt Giuca <mgiuca@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#540949}
parent 51704b89
...@@ -2080,7 +2080,9 @@ void Textfield::OnCaretBoundsChanged() { ...@@ -2080,7 +2080,9 @@ void Textfield::OnCaretBoundsChanged() {
GetInputMethod()->OnCaretBoundsChanged(this); GetInputMethod()->OnCaretBoundsChanged(this);
if (touch_selection_controller_) if (touch_selection_controller_)
touch_selection_controller_->SelectionChanged(); touch_selection_controller_->SelectionChanged();
NotifyAccessibilityEvent(ax::mojom::Event::kTextSelectionChanged, true); // Screen reader users don't expect notifications about unfocused textfields.
if (HasFocus())
NotifyAccessibilityEvent(ax::mojom::Event::kTextSelectionChanged, true);
} }
void Textfield::OnBeforeUserAction() { void Textfield::OnBeforeUserAction() {
......
...@@ -286,6 +286,15 @@ class TestTextfield : public views::Textfield { ...@@ -286,6 +286,15 @@ class TestTextfield : public views::Textfield {
event_flags_ = 0; event_flags_ = 0;
} }
void OnAccessibilityEvent(ax::mojom::Event event_type) override {
if (event_type == ax::mojom::Event::kTextSelectionChanged)
++accessibility_selection_fired_count_;
}
int GetAccessibilitySelectionFiredCount() {
return accessibility_selection_fired_count_;
}
private: private:
// views::View override: // views::View override:
void OnKeyEvent(ui::KeyEvent* event) override { void OnKeyEvent(ui::KeyEvent* event) override {
...@@ -310,6 +319,7 @@ class TestTextfield : public views::Textfield { ...@@ -310,6 +319,7 @@ class TestTextfield : public views::Textfield {
bool key_handled_ = false; bool key_handled_ = false;
bool key_received_ = false; bool key_received_ = false;
int event_flags_ = 0; int event_flags_ = 0;
int accessibility_selection_fired_count_ = 0;
base::WeakPtrFactory<TestTextfield> weak_ptr_factory_{this}; base::WeakPtrFactory<TestTextfield> weak_ptr_factory_{this};
...@@ -3438,4 +3448,28 @@ TEST_F(TextfieldTest, TextServicesContextMenuTextDirectionTest) { ...@@ -3438,4 +3448,28 @@ TEST_F(TextfieldTest, TextServicesContextMenuTextDirectionTest) {
} }
#endif // defined(OS_MACOSX) #endif // defined(OS_MACOSX)
TEST_F(TextfieldTest, AccessibilitySelectionEvents) {
const std::string& kText = "abcdef";
InitTextfield();
textfield_->SetText(ASCIIToUTF16(kText));
EXPECT_TRUE(textfield_->HasFocus());
int previous_selection_fired_count =
textfield_->GetAccessibilitySelectionFiredCount();
textfield_->SelectAll(false);
EXPECT_LT(previous_selection_fired_count,
textfield_->GetAccessibilitySelectionFiredCount());
previous_selection_fired_count =
textfield_->GetAccessibilitySelectionFiredCount();
// No selection event when textfield blurred, even though text is
// deselected.
widget_->GetFocusManager()->ClearFocus();
EXPECT_FALSE(textfield_->HasFocus());
textfield_->ClearSelection();
EXPECT_FALSE(textfield_->HasSelection());
// Has not changed.
EXPECT_EQ(previous_selection_fired_count,
textfield_->GetAccessibilitySelectionFiredCount());
}
} // namespace views } // namespace views
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