Commit ff51b23d authored by Collin Baker's avatar Collin Baker Committed by Commit Bot

Set tab counter a11y name on button instead of label

Fixed: 1028827
Change-Id: I8d3d3b3134a9f91d86289f16c70d730f0ded34b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1948084
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Auto-Submit: Collin Baker <collinbaker@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721100}
parent d639d090
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "chrome/browser/ui/views/toolbar/webui_tab_counter_button.h" #include "chrome/browser/ui/views/toolbar/webui_tab_counter_button.h"
#include <memory>
#include "base/i18n/message_formatter.h" #include "base/i18n/message_formatter.h"
#include "base/i18n/number_formatting.h" #include "base/i18n/number_formatting.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -25,16 +27,16 @@ ...@@ -25,16 +27,16 @@
namespace { namespace {
class TabCounterLabelUpdater : public TabStripModelObserver { class TabCounterUpdater : public TabStripModelObserver {
public: public:
explicit TabCounterLabelUpdater(views::Label* tab_counter) TabCounterUpdater(views::Button* button, views::Label* tab_counter)
: tab_counter_(tab_counter) {} : button_(button), tab_counter_(tab_counter) {}
~TabCounterLabelUpdater() override = default; ~TabCounterUpdater() override = default;
void UpdateCounter(TabStripModel* model) { void UpdateCounter(TabStripModel* model) {
const int num_tabs = model->count(); const int num_tabs = model->count();
tab_counter_->SetTooltipText( button_->SetTooltipText(
base::i18n::MessageFormatter::FormatWithNumberedArgs( base::i18n::MessageFormatter::FormatWithNumberedArgs(
l10n_util::GetStringUTF16(IDS_TOOLTIP_WEBUI_TAB_STRIP_TAB_COUNTER), l10n_util::GetStringUTF16(IDS_TOOLTIP_WEBUI_TAB_STRIP_TAB_COUNTER),
num_tabs)); num_tabs));
...@@ -51,7 +53,8 @@ class TabCounterLabelUpdater : public TabStripModelObserver { ...@@ -51,7 +53,8 @@ class TabCounterLabelUpdater : public TabStripModelObserver {
} }
private: private:
views::Label* tab_counter_; views::Button* const button_;
views::Label* const tab_counter_;
}; };
class WebUITabCounterButton : public views::Button { class WebUITabCounterButton : public views::Button {
...@@ -64,7 +67,7 @@ class WebUITabCounterButton : public views::Button { ...@@ -64,7 +67,7 @@ class WebUITabCounterButton : public views::Button {
void OnThemeChanged() override; void OnThemeChanged() override;
std::unique_ptr<TabCounterLabelUpdater> label_updater_; std::unique_ptr<TabCounterUpdater> counter_updater_;
views::InkDropContainerView* ink_drop_container_; views::InkDropContainerView* ink_drop_container_;
views::Label* label_; views::Label* label_;
}; };
...@@ -77,9 +80,6 @@ std::unique_ptr<views::View> CreateWebUITabCounterButton( ...@@ -77,9 +80,6 @@ std::unique_ptr<views::View> CreateWebUITabCounterButton(
auto tab_counter = std::make_unique<WebUITabCounterButton>(listener); auto tab_counter = std::make_unique<WebUITabCounterButton>(listener);
tab_counter->SetID(VIEW_ID_WEBUI_TAB_STRIP_TAB_COUNTER); tab_counter->SetID(VIEW_ID_WEBUI_TAB_STRIP_TAB_COUNTER);
// TODO(crbug.com/1028827): replace this with production string and provide
// tab count.
tab_counter->SetAccessibleName(base::ASCIIToUTF16("Open tab strip"));
// TODO(999557): Create a custom text style to get the correct size/weight. // TODO(999557): Create a custom text style to get the correct size/weight.
// TODO(999557): Figure out how to get the right font. // TODO(999557): Figure out how to get the right font.
...@@ -107,9 +107,10 @@ std::unique_ptr<views::View> CreateWebUITabCounterButton( ...@@ -107,9 +107,10 @@ std::unique_ptr<views::View> CreateWebUITabCounterButton(
label->SetBounds(inset_height, inset_height, kDesiredBorderHeight, label->SetBounds(inset_height, inset_height, kDesiredBorderHeight,
kDesiredBorderHeight); kDesiredBorderHeight);
tab_counter->label_updater_ = std::make_unique<TabCounterLabelUpdater>(label); tab_counter->counter_updater_ =
tab_strip_model->AddObserver(tab_counter->label_updater_.get()); std::make_unique<TabCounterUpdater>(tab_counter.get(), label);
tab_counter->label_updater_->UpdateCounter(tab_strip_model); tab_strip_model->AddObserver(tab_counter->counter_updater_.get());
tab_counter->counter_updater_->UpdateCounter(tab_strip_model);
return tab_counter; return tab_counter;
} }
......
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