Commit 22c96c77 authored by Tommy Li's avatar Tommy Li Committed by Commit Bot

[omnibox] Add kExpanded / kCollapsed AX events to section headers

Adds the kExpanded / kCollapsed accessibility header node data to
section headers.

Also fires off the kExpandedChanged event when this changes.

Bug: 1078183, 1052522
Change-Id: Ie037ebede9003ebf486ec3e3ba0124e3b1b0057b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2247139
Commit-Queue: Tommy Li <tommycli@chromium.org>
Reviewed-by: default avatarAaron Leventhal <aleventhal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780506}
parent 685cb7c1
...@@ -16,10 +16,12 @@ ...@@ -16,10 +16,12 @@
#include "components/prefs/pref_change_registrar.h" #include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/color_palette.h" #include "ui/gfx/color_palette.h"
#include "ui/gfx/image/image_skia_operations.h" #include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/image_button_factory.h" #include "ui/views/controls/button/image_button_factory.h"
...@@ -65,9 +67,8 @@ class OmniboxRowView::HeaderView : public views::View, ...@@ -65,9 +67,8 @@ class OmniboxRowView::HeaderView : public views::View,
if (row_view_->pref_service_) { if (row_view_->pref_service_) {
pref_change_registrar_.Init(row_view_->pref_service_); pref_change_registrar_.Init(row_view_->pref_service_);
// Unretained is appropriate here. 'this' will outlive the registrar. // Unretained is appropriate here. 'this' will outlive the registrar.
pref_change_registrar_.Add( pref_change_registrar_.Add(omnibox::kOmniboxHiddenGroupIds,
omnibox::kOmniboxHiddenGroupIds, base::BindRepeating(&HeaderView::OnPrefChanged,
base::BindRepeating(&HeaderView::UpdateHideButtonToggleState,
base::Unretained(this))); base::Unretained(this)));
} }
} }
...@@ -80,8 +81,12 @@ class OmniboxRowView::HeaderView : public views::View, ...@@ -80,8 +81,12 @@ class OmniboxRowView::HeaderView : public views::View,
// Moreover, it seems unusual to do case conversion in Views in general. // Moreover, it seems unusual to do case conversion in Views in general.
header_text_->SetText(base::i18n::ToUpper(header_text)); header_text_->SetText(base::i18n::ToUpper(header_text));
if (row_view_->pref_service_) if (row_view_->pref_service_) {
UpdateHideButtonToggleState(); suggestion_group_hidden_ = omnibox::IsSuggestionGroupIdHidden(
row_view_->pref_service_, suggestion_group_id_);
header_toggle_button_->SetToggled(suggestion_group_hidden_);
}
} }
// views::View: // views::View:
...@@ -110,6 +115,15 @@ class OmniboxRowView::HeaderView : public views::View, ...@@ -110,6 +115,15 @@ class OmniboxRowView::HeaderView : public views::View,
// all of the UI. // all of the UI.
UpdateUI(); UpdateUI();
} }
void GetAccessibleNodeData(ui::AXNodeData* node_data) override {
// Hidden HeaderView instances are not associated with any group ID, so they
// are neither collapsed or expanded.s
if (!GetVisible())
return;
node_data->AddState(suggestion_group_hidden_ ? ax::mojom::State::kCollapsed
: ax::mojom::State::kExpanded);
}
// views::ButtonListener: // views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override { void ButtonPressed(views::Button* sender, const ui::Event& event) override {
...@@ -166,10 +180,16 @@ class OmniboxRowView::HeaderView : public views::View, ...@@ -166,10 +180,16 @@ class OmniboxRowView::HeaderView : public views::View,
private: private:
// Updates the hide button's toggle state. // Updates the hide button's toggle state.
void UpdateHideButtonToggleState() { void OnPrefChanged() {
DCHECK(row_view_->pref_service_); DCHECK(row_view_->pref_service_);
header_toggle_button_->SetToggled(omnibox::IsSuggestionGroupIdHidden( bool was_hidden = suggestion_group_hidden_;
row_view_->pref_service_, suggestion_group_id_)); suggestion_group_hidden_ = omnibox::IsSuggestionGroupIdHidden(
row_view_->pref_service_, suggestion_group_id_);
if (was_hidden != suggestion_group_hidden_)
NotifyAccessibilityEvent(ax::mojom::Event::kExpandedChanged, true);
header_toggle_button_->SetToggled(suggestion_group_hidden_);
} }
// Non-owning pointer our parent row view. We access a lot of private members // Non-owning pointer our parent row view. We access a lot of private members
...@@ -186,6 +206,10 @@ class OmniboxRowView::HeaderView : public views::View, ...@@ -186,6 +206,10 @@ class OmniboxRowView::HeaderView : public views::View,
// The group ID associated with this header. // The group ID associated with this header.
int suggestion_group_id_ = 0; int suggestion_group_id_ = 0;
// Stores whether or not the group was hidden. This is used to fire correct
// accessibility change events.
bool suggestion_group_hidden_ = false;
// A pref change registrar for toggling the toggle button's state. This is // A pref change registrar for toggling the toggle button's state. This is
// needed because the preference state can change through multiple UIs. // needed because the preference state can change through multiple UIs.
PrefChangeRegistrar pref_change_registrar_; PrefChangeRegistrar pref_change_registrar_;
......
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