Commit 4200d6cc authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

views: add setters for accessible widget properties

This change adds setters for:
* Accessible role & title on Widget
* Initially focused view on Dialog

At first glance these might appear unrelated, but in fact bubbles use
the presence or absence of an initially focused view to decide what role
they should have.

Bug: 1011446, 1075649
Change-Id: I1ad2b8b333c46c9252cc8d5667a21d6b9b7a0d5f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2218688
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772415}
parent 671511b0
...@@ -75,11 +75,12 @@ ui::ModalType WidgetDelegate::GetModalType() const { ...@@ -75,11 +75,12 @@ ui::ModalType WidgetDelegate::GetModalType() const {
} }
ax::mojom::Role WidgetDelegate::GetAccessibleWindowRole() { ax::mojom::Role WidgetDelegate::GetAccessibleWindowRole() {
return ax::mojom::Role::kWindow; return params_.accessible_role;
} }
base::string16 WidgetDelegate::GetAccessibleWindowTitle() const { base::string16 WidgetDelegate::GetAccessibleWindowTitle() const {
return GetWindowTitle(); return params_.accessible_title.empty() ? GetWindowTitle()
: params_.accessible_title;
} }
base::string16 WidgetDelegate::GetWindowTitle() const { base::string16 WidgetDelegate::GetWindowTitle() const {
...@@ -223,6 +224,14 @@ bool WidgetDelegate::ShouldDescendIntoChildForEventHandling( ...@@ -223,6 +224,14 @@ bool WidgetDelegate::ShouldDescendIntoChildForEventHandling(
return true; return true;
} }
void WidgetDelegate::SetAccessibleRole(ax::mojom::Role role) {
params_.accessible_role = role;
}
void WidgetDelegate::SetAccessibleTitle(base::string16 title) {
params_.accessible_title = std::move(title);
}
void WidgetDelegate::SetCanMaximize(bool can_maximize) { void WidgetDelegate::SetCanMaximize(bool can_maximize) {
params_.can_maximize = can_maximize; params_.can_maximize = can_maximize;
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include <vector> #include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "ui/accessibility/ax_enums.mojom-forward.h" #include "ui/accessibility/ax_enums.mojom.h"
#include "ui/base/ui_base_types.h" #include "ui/base/ui_base_types.h"
#include "ui/views/view.h" #include "ui/views/view.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
...@@ -33,6 +33,17 @@ class VIEWS_EXPORT WidgetDelegate { ...@@ -33,6 +33,17 @@ class VIEWS_EXPORT WidgetDelegate {
Params(); Params();
~Params(); ~Params();
// The window's role. Useful values include kWindow (a plain window),
// kDialog (a dialog), and kAlertDialog (a high-priority dialog whose body
// is read when it appears). Using a role outside this set is not likely to
// work across platforms.
ax::mojom::Role accessible_role = ax::mojom::Role::kWindow;
// The accessible title for the window, often more descriptive than the
// plain title. If no accessible title is present the result of
// GetWindowTitle() will be used.
base::string16 accessible_title;
// Whether the window should display controls for the user to minimize, // Whether the window should display controls for the user to minimize,
// maximize, or resize it. // maximize, or resize it.
bool can_maximize = false; bool can_maximize = false;
...@@ -255,6 +266,8 @@ class VIEWS_EXPORT WidgetDelegate { ...@@ -255,6 +266,8 @@ class VIEWS_EXPORT WidgetDelegate {
// Setters for data parameters of the WidgetDelegate. If you use these // Setters for data parameters of the WidgetDelegate. If you use these
// setters, there is no need to override the corresponding virtual getters. // setters, there is no need to override the corresponding virtual getters.
void SetAccessibleRole(ax::mojom::Role role);
void SetAccessibleTitle(base::string16 title);
void SetCanMaximize(bool can_maximize); void SetCanMaximize(bool can_maximize);
void SetCanMinimize(bool can_minimize); void SetCanMinimize(bool can_minimize);
void SetCanResize(bool can_resize); void SetCanResize(bool can_resize);
......
...@@ -162,6 +162,9 @@ void DialogDelegate::RunCloseCallback(base::OnceClosure callback) { ...@@ -162,6 +162,9 @@ void DialogDelegate::RunCloseCallback(base::OnceClosure callback) {
} }
View* DialogDelegate::GetInitiallyFocusedView() { View* DialogDelegate::GetInitiallyFocusedView() {
if (params_.initially_focused_view.has_value())
return *params_.initially_focused_view;
// Focus the default button if any. // Focus the default button if any.
const DialogClientView* dcv = GetDialogClientView(); const DialogClientView* dcv = GetDialogClientView();
if (!dcv) if (!dcv)
...@@ -370,6 +373,10 @@ void DialogDelegate::SetCloseCallback(base::OnceClosure callback) { ...@@ -370,6 +373,10 @@ void DialogDelegate::SetCloseCallback(base::OnceClosure callback) {
close_callback_ = std::move(callback); close_callback_ = std::move(callback);
} }
void DialogDelegate::SetInitiallyFocusedView(View* view) {
params_.initially_focused_view = view;
}
std::unique_ptr<View> DialogDelegate::DisownExtraView() { std::unique_ptr<View> DialogDelegate::DisownExtraView() {
return std::move(extra_view_); return std::move(extra_view_);
} }
......
...@@ -64,6 +64,11 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate { ...@@ -64,6 +64,11 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate {
// dialog. It's legal for a button to be marked enabled that isn't present // dialog. It's legal for a button to be marked enabled that isn't present
// in |buttons| (see above). // in |buttons| (see above).
int enabled_buttons = ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; int enabled_buttons = ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
// The view that should receive initial focus in the dialog. If not set, the
// default button will receive initial focus. If explicitly set to nullptr,
// no view will receive focus.
base::Optional<View*> initially_focused_view;
}; };
DialogDelegate(); DialogDelegate();
...@@ -195,6 +200,7 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate { ...@@ -195,6 +200,7 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate {
void SetAcceptCallback(base::OnceClosure callback); void SetAcceptCallback(base::OnceClosure callback);
void SetCancelCallback(base::OnceClosure callback); void SetCancelCallback(base::OnceClosure callback);
void SetCloseCallback(base::OnceClosure callback); void SetCloseCallback(base::OnceClosure callback);
void SetInitiallyFocusedView(View* view);
// Returns ownership of the extra view for this dialog, if one was provided // Returns ownership of the extra view for this dialog, if one was provided
// via SetExtraView(). This is only for use by DialogClientView; don't call // via SetExtraView(). This is only for use by DialogClientView; don't call
......
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