Commit 6824206f authored by Olivier Yiptong's avatar Olivier Yiptong Committed by Chromium LUCI CQ

FontAccess: Implement a "Select All" feature for the font chooser

Implements the ability to select all fonts in the font chooser as a
checkbox. Unselecting the checkbox will cause all selection to
disappear.

Bug: 1159246
Change-Id: Ia3ecda193457a70e8c5b3282362c4439945943ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2594510
Commit-Queue: Olivier Yiptong <oyiptong@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#838471}
parent 0457e760
...@@ -10251,6 +10251,9 @@ Please help our engineers fix this problem. Tell us what happened right before y ...@@ -10251,6 +10251,9 @@ Please help our engineers fix this problem. Tell us what happened right before y
<message name="IDS_FONT_ACCESS_CHOOSER_CANCEL_BUTTON_TEXT" desc="Label on the button that closes the chooser popup without selecting an option."> <message name="IDS_FONT_ACCESS_CHOOSER_CANCEL_BUTTON_TEXT" desc="Label on the button that closes the chooser popup without selecting an option.">
Cancel Cancel
</message> </message>
<message name="IDS_FONT_ACCESS_CHOOSER_SELECT_ALL_CHECKBOX_TEXT" desc="Label for the checkbox that allows the selection of all fonts.">
Select all fonts
</message>
</if> </if>
<!-- Chrome IME API activated bubble. --> <!-- Chrome IME API activated bubble. -->
......
310ac15fc23be1a1d0496c2cf1d71dfcaa17797e
\ No newline at end of file
...@@ -84,10 +84,18 @@ bool ChooserController::AllowMultipleSelection() const { ...@@ -84,10 +84,18 @@ bool ChooserController::AllowMultipleSelection() const {
return false; return false;
} }
bool ChooserController::ShouldShowSelectAllCheckbox() const {
return false;
}
base::string16 ChooserController::GetCancelButtonLabel() const { base::string16 ChooserController::GetCancelButtonLabel() const {
return l10n_util::GetStringUTF16(IDS_DEVICE_CHOOSER_CANCEL_BUTTON_TEXT); return l10n_util::GetStringUTF16(IDS_DEVICE_CHOOSER_CANCEL_BUTTON_TEXT);
} }
base::string16 ChooserController::GetSelectAllCheckboxLabel() const {
return base::string16();
}
bool ChooserController::BothButtonsAlwaysEnabled() const { bool ChooserController::BothButtonsAlwaysEnabled() const {
return false; return false;
} }
......
...@@ -79,6 +79,9 @@ class ChooserController { ...@@ -79,6 +79,9 @@ class ChooserController {
// Returns whether the chooser allows multiple items to be selected. // Returns whether the chooser allows multiple items to be selected.
virtual bool AllowMultipleSelection() const; virtual bool AllowMultipleSelection() const;
// Returns whether the chooser needs to show a select-all checkbox.
virtual bool ShouldShowSelectAllCheckbox() const;
// Returns the text to be displayed in the chooser when there are no options. // Returns the text to be displayed in the chooser when there are no options.
virtual base::string16 GetNoOptionsText() const = 0; virtual base::string16 GetNoOptionsText() const = 0;
...@@ -88,6 +91,9 @@ class ChooserController { ...@@ -88,6 +91,9 @@ class ChooserController {
// Returns the label for Cancel button. // Returns the label for Cancel button.
virtual base::string16 GetCancelButtonLabel() const; virtual base::string16 GetCancelButtonLabel() const;
// Returns the label for SelectAll checkbox.
virtual base::string16 GetSelectAllCheckboxLabel() const;
// Returns whether both OK and Cancel buttons are enabled. // Returns whether both OK and Cancel buttons are enabled.
// //
// For chooser used in Web APIs such as WebBluetooth, WebUSB, // For chooser used in Web APIs such as WebBluetooth, WebUSB,
......
...@@ -71,6 +71,11 @@ base::string16 FontAccessChooserController::GetOption(size_t index) const { ...@@ -71,6 +71,11 @@ base::string16 FontAccessChooserController::GetOption(size_t index) const {
return base::UTF8ToUTF16(items_[index]); return base::UTF8ToUTF16(items_[index]);
} }
base::string16 FontAccessChooserController::GetSelectAllCheckboxLabel() const {
return l10n_util::GetStringUTF16(
IDS_FONT_ACCESS_CHOOSER_SELECT_ALL_CHECKBOX_TEXT);
}
bool FontAccessChooserController::ShouldShowHelpButton() const { bool FontAccessChooserController::ShouldShowHelpButton() const {
return false; return false;
} }
...@@ -88,6 +93,10 @@ bool FontAccessChooserController::AllowMultipleSelection() const { ...@@ -88,6 +93,10 @@ bool FontAccessChooserController::AllowMultipleSelection() const {
return true; return true;
} }
bool FontAccessChooserController::ShouldShowSelectAllCheckbox() const {
return true;
}
bool FontAccessChooserController::TableViewAlwaysDisabled() const { bool FontAccessChooserController::TableViewAlwaysDisabled() const {
return false; return false;
} }
......
...@@ -32,12 +32,14 @@ class FontAccessChooserController : public ChooserController { ...@@ -32,12 +32,14 @@ class FontAccessChooserController : public ChooserController {
base::string16 GetOkButtonLabel() const override; base::string16 GetOkButtonLabel() const override;
size_t NumOptions() const override; size_t NumOptions() const override;
base::string16 GetOption(size_t index) const override; base::string16 GetOption(size_t index) const override;
base::string16 GetSelectAllCheckboxLabel() const override;
bool ShouldShowHelpButton() const override; bool ShouldShowHelpButton() const override;
bool ShouldShowReScanButton() const override; bool ShouldShowReScanButton() const override;
bool BothButtonsAlwaysEnabled() const override; bool BothButtonsAlwaysEnabled() const override;
bool TableViewAlwaysDisabled() const override; bool TableViewAlwaysDisabled() const override;
bool AllowMultipleSelection() const override; bool AllowMultipleSelection() const override;
bool ShouldShowSelectAllCheckbox() const override;
void Select(const std::vector<size_t>& indices) override; void Select(const std::vector<size_t>& indices) override;
void Cancel() override; void Cancel() override;
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/resources/grit/ui_resources.h" #include "ui/resources/grit/ui_resources.h"
#include "ui/views/accessibility/view_accessibility.h" #include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/button/checkbox.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"
#include "ui/views/controls/button/label_button.h" #include "ui/views/controls/button/label_button.h"
...@@ -118,7 +119,22 @@ DeviceChooserContentView::DeviceChooserContentView( ...@@ -118,7 +119,22 @@ DeviceChooserContentView::DeviceChooserContentView(
chooser_controller_->set_view(this); chooser_controller_->set_view(this);
SetPreferredSize({402, 320}); SetPreferredSize({402, 320});
SetLayoutManager(std::make_unique<views::FillLayout>());
if (chooser_controller_->ShouldShowSelectAllCheckbox()) {
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical));
auto select_all_view = std::make_unique<views::Checkbox>(
chooser_controller_->GetSelectAllCheckboxLabel());
select_all_view->SetVisible(false);
select_all_subscription_ = select_all_view->AddCheckedChangedCallback(
base::BindRepeating(&DeviceChooserContentView::SelectAllCheckboxChanged,
base::Unretained(this)));
select_all_view_ = AddChildView(std::move(select_all_view));
} else {
// FillLayout is the default. There will only be the ScrollView,
// therefore there's no point to have a BoxLayout.
SetLayoutManager(std::make_unique<views::FillLayout>());
}
std::vector<ui::TableColumn> table_columns = {ui::TableColumn()}; std::vector<ui::TableColumn> table_columns = {ui::TableColumn()};
auto table_view = std::make_unique<views::TableView>( auto table_view = std::make_unique<views::TableView>(
...@@ -134,6 +150,12 @@ DeviceChooserContentView::DeviceChooserContentView( ...@@ -134,6 +150,12 @@ DeviceChooserContentView::DeviceChooserContentView(
table_parent_ = AddChildView( table_parent_ = AddChildView(
views::TableView::CreateScrollViewWithTable(std::move(table_view))); views::TableView::CreateScrollViewWithTable(std::move(table_view)));
if (chooser_controller_->ShouldShowSelectAllCheckbox()) {
// This will be using the BoxLayout manager.
// Set min and max height, otherwise CalculatePreferredSize() will be
// called, returning 0, 0 always.
table_parent_->ClipHeightTo(320, 320);
}
const auto add_centering_view = [this](auto view) { const auto add_centering_view = [this](auto view) {
auto* container = AddChildView(std::make_unique<views::View>()); auto* container = AddChildView(std::make_unique<views::View>());
...@@ -342,6 +364,12 @@ void DeviceChooserContentView::UpdateTableView() { ...@@ -342,6 +364,12 @@ void DeviceChooserContentView::UpdateTableView() {
GetWidget()->GetFocusManager()->GetFocusedView()) { GetWidget()->GetFocusManager()->GetFocusedView()) {
is_initialized_ = true; // Can show no_options_view_ after initial focus. is_initialized_ = true; // Can show no_options_view_ after initial focus.
} }
if (select_all_view_) {
select_all_view_->SetVisible(
has_options && chooser_controller_->ShouldShowSelectAllCheckbox());
}
table_parent_->SetVisible(has_options); table_parent_->SetVisible(has_options);
table_view_->SetEnabled(has_options && table_view_->SetEnabled(has_options &&
!chooser_controller_->TableViewAlwaysDisabled()); !chooser_controller_->TableViewAlwaysDisabled());
...@@ -352,6 +380,11 @@ void DeviceChooserContentView::UpdateTableView() { ...@@ -352,6 +380,11 @@ void DeviceChooserContentView::UpdateTableView() {
adapter_off_view_->SetVisible(!adapter_enabled_); adapter_off_view_->SetVisible(!adapter_enabled_);
} }
void DeviceChooserContentView::SelectAllCheckboxChanged() {
DCHECK(select_all_view_ && table_view_);
table_view_->SetSelectionAll(/*select=*/select_all_view_->GetChecked());
}
views::LabelButton* DeviceChooserContentView::ReScanButtonForTesting() { views::LabelButton* DeviceChooserContentView::ReScanButtonForTesting() {
return bluetooth_status_container_->re_scan_button_; return bluetooth_status_container_->re_scan_button_;
} }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
class BluetoothStatusContainer; class BluetoothStatusContainer;
namespace views { namespace views {
class Checkbox;
class Label; class Label;
class LabelButton; class LabelButton;
class TableView; class TableView;
...@@ -61,6 +62,7 @@ class DeviceChooserContentView : public views::View, ...@@ -61,6 +62,7 @@ class DeviceChooserContentView : public views::View,
void Cancel(); void Cancel();
void Close(); void Close();
void UpdateTableView(); void UpdateTableView();
void SelectAllCheckboxChanged();
// Test-only accessors to children. // Test-only accessors to children.
views::TableView* table_view_for_testing() { return table_view_; } views::TableView* table_view_for_testing() { return table_view_; }
...@@ -75,13 +77,15 @@ class DeviceChooserContentView : public views::View, ...@@ -75,13 +77,15 @@ class DeviceChooserContentView : public views::View,
bool adapter_enabled_ = true; bool adapter_enabled_ = true;
views::View* table_parent_ = nullptr; views::ScrollView* table_parent_ = nullptr;
views::Checkbox* select_all_view_ = nullptr;
views::TableView* table_view_ = nullptr; views::TableView* table_view_ = nullptr;
views::View* no_options_view_ = nullptr; views::View* no_options_view_ = nullptr;
views::View* adapter_off_view_ = nullptr; views::View* adapter_off_view_ = nullptr;
BluetoothStatusContainer* bluetooth_status_container_ = nullptr; BluetoothStatusContainer* bluetooth_status_container_ = nullptr;
bool is_initialized_ = false; bool is_initialized_ = false;
base::CallbackListSubscription select_all_subscription_;
DISALLOW_COPY_AND_ASSIGN(DeviceChooserContentView); DISALLOW_COPY_AND_ASSIGN(DeviceChooserContentView);
}; };
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "ui/events/base_event_utils.h" #include "ui/events/base_event_utils.h"
#include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/label_button.h" #include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/styled_label.h" #include "ui/views/controls/styled_label.h"
#include "ui/views/controls/table/table_view.h" #include "ui/views/controls/table/table_view.h"
#include "ui/views/controls/table/table_view_observer.h" #include "ui/views/controls/table/table_view_observer.h"
...@@ -76,7 +77,7 @@ class DeviceChooserContentViewTest : public ChromeViewsTestBase { ...@@ -76,7 +77,7 @@ class DeviceChooserContentViewTest : public ChromeViewsTestBase {
views::TableView* table_view() { views::TableView* table_view() {
return content_view_->table_view_for_testing(); return content_view_->table_view_for_testing();
} }
views::View* table_parent() { return content_view_->table_parent_; } views::ScrollView* table_parent() { return content_view_->table_parent_; }
ui::TableModel* table_model() { return table_view()->model(); } ui::TableModel* table_model() { return table_view()->model(); }
views::View* no_options_view() { return content_view_->no_options_view_; } views::View* no_options_view() { return content_view_->no_options_view_; }
views::View* adapter_off_view() { return content_view_->adapter_off_view_; } views::View* adapter_off_view() { return content_view_->adapter_off_view_; }
......
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