Commit e15cffe3 authored by Andy Paicu's avatar Andy Paicu Committed by Commit Bot

Ensure quiet notifications prompts are read out by screen readers

Bug: 1014899
Change-Id: Ib93a32e91b1fb6fb4dff5e3501e8289dc9271a69
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1868872
Commit-Queue: Andy Paicu <andypaicu@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711214}
parent 24cedd6e
......@@ -250,8 +250,11 @@ const ContentSettingsImageDetails* GetImageDetails(ContentSettingsType type) {
ContentSettingSimpleImageModel::ContentSettingSimpleImageModel(
ImageType image_type,
ContentSettingsType content_type)
: ContentSettingImageModel(image_type), content_type_(content_type) {}
ContentSettingsType content_type,
bool image_type_should_notify_accessibility)
: ContentSettingImageModel(image_type,
image_type_should_notify_accessibility),
content_type_(content_type) {}
std::unique_ptr<ContentSettingBubbleModel>
ContentSettingSimpleImageModel::CreateBubbleModelImpl(
......@@ -322,6 +325,10 @@ void ContentSettingImageModel::Update(content::WebContents* contents) {
if (contents && !is_visible_) {
ContentSettingImageModelStates::Get(contents)->SetAnimationHasRun(
image_type(), false);
if (image_type_should_notify_accessibility_) {
ContentSettingImageModelStates::Get(contents)->SetAccessibilityNotified(
image_type(), false);
}
}
}
......@@ -339,6 +346,19 @@ void ContentSettingImageModel::SetAnimationHasRun(
image_type(), true);
}
bool ContentSettingImageModel::ShouldNotifyAccessibility(
content::WebContents* contents) const {
return image_type_should_notify_accessibility_ &&
!ContentSettingImageModelStates::Get(contents)
->GetAccessibilityNotified(image_type());
}
void ContentSettingImageModel::AccessibilityWasNotified(
content::WebContents* contents) {
ContentSettingImageModelStates::Get(contents)->SetAccessibilityNotified(
image_type(), true);
}
// Generic blocked content settings --------------------------------------------
ContentSettingBlockedImageModel::ContentSettingBlockedImageModel(
......@@ -799,8 +819,10 @@ bool ContentSettingPopupImageModel::UpdateAndGetVisibility(
// Notifications --------------------------------------------------------------
ContentSettingNotificationsImageModel::ContentSettingNotificationsImageModel()
: ContentSettingSimpleImageModel(ImageType::NOTIFICATIONS_QUIET_PROMPT,
ContentSettingsType::NOTIFICATIONS) {
: ContentSettingSimpleImageModel(
ImageType::NOTIFICATIONS_QUIET_PROMPT,
ContentSettingsType::NOTIFICATIONS,
true /* image_type_should_notify_accessibility */) {
set_icon(vector_icons::kNotificationsOffIcon, gfx::kNoneIcon);
set_tooltip(
l10n_util::GetStringUTF16(IDS_NOTIFICATIONS_OFF_EXPLANATORY_TEXT));
......@@ -833,12 +855,14 @@ gfx::Image ContentSettingImageModel::GetIcon(SkColor icon_color) const {
icon_color, *icon_badge_));
}
ContentSettingImageModel::ContentSettingImageModel(ImageType image_type)
: is_visible_(false),
icon_(&gfx::kNoneIcon),
ContentSettingImageModel::ContentSettingImageModel(
ImageType image_type,
bool image_type_should_notify_accessibility)
: icon_(&gfx::kNoneIcon),
icon_badge_(&gfx::kNoneIcon),
explanatory_string_id_(0),
image_type_(image_type) {}
image_type_(image_type),
image_type_should_notify_accessibility_(
image_type_should_notify_accessibility) {}
std::unique_ptr<ContentSettingBubbleModel>
ContentSettingImageModel::CreateBubbleModel(
......
......@@ -101,8 +101,13 @@ class ContentSettingImageModel {
explanatory_string_id_ = text_id;
}
bool ShouldNotifyAccessibility(content::WebContents* contents) const;
void AccessibilityWasNotified(content::WebContents* contents);
protected:
explicit ContentSettingImageModel(ImageType type);
explicit ContentSettingImageModel(
ImageType type,
bool image_type_should_notify_accessibility = false);
// Notifies this model that its setting might have changed and it may need to
// update its visibility, icon and tooltip. This method returns whether the
......@@ -122,13 +127,14 @@ class ContentSettingImageModel {
void set_tooltip(const base::string16& tooltip) { tooltip_ = tooltip; }
private:
bool is_visible_;
bool is_visible_ = false;
const gfx::VectorIcon* icon_;
const gfx::VectorIcon* icon_badge_;
int explanatory_string_id_;
int explanatory_string_id_ = 0;
base::string16 tooltip_;
const ImageType image_type_;
const bool image_type_should_notify_accessibility_;
DISALLOW_COPY_AND_ASSIGN(ContentSettingImageModel);
};
......@@ -136,8 +142,10 @@ class ContentSettingImageModel {
// A subclass for an image model tied to a single content type.
class ContentSettingSimpleImageModel : public ContentSettingImageModel {
public:
ContentSettingSimpleImageModel(ImageType type,
ContentSettingsType content_type);
ContentSettingSimpleImageModel(
ImageType type,
ContentSettingsType content_type,
bool image_type_should_notify_accessibility = false);
// ContentSettingImageModel implementation.
std::unique_ptr<ContentSettingBubbleModel> CreateBubbleModelImpl(
......
......@@ -30,6 +30,24 @@ bool ContentSettingImageModelStates::AnimationHasRun(ImageType type) const {
return animations_[static_cast<int>(type)];
}
void ContentSettingImageModelStates::SetAccessibilityNotified(ImageType type,
bool notified) {
VerifyType(type);
// Currently only NOTIFICATIONS_QUIET_PROMPT will notify accessibility.
DCHECK_EQ(ImageType::NOTIFICATIONS_QUIET_PROMPT, type);
accessibility_notified_[static_cast<int>(type)] = notified;
}
bool ContentSettingImageModelStates::GetAccessibilityNotified(
ImageType type) const {
VerifyType(type);
// Currently only NOTIFICATIONS_QUIET_PROMPT will notify accessibility.
DCHECK_EQ(ImageType::NOTIFICATIONS_QUIET_PROMPT, type);
return accessibility_notified_[static_cast<int>(type)];
}
ContentSettingImageModelStates::ContentSettingImageModelStates(
content::WebContents* contents) {}
......
......@@ -24,6 +24,9 @@ class ContentSettingImageModelStates
void SetAnimationHasRun(ImageType type, bool animation_has_run);
bool AnimationHasRun(ImageType type) const;
void SetAccessibilityNotified(ImageType type, bool notified);
bool GetAccessibilityNotified(ImageType type) const;
private:
friend class content::WebContentsUserData<ContentSettingImageModelStates>;
explicit ContentSettingImageModelStates(content::WebContents* contents);
......@@ -36,6 +39,12 @@ class ContentSettingImageModelStates
// This bit is reset to false when the image is hidden.
bool animations_[static_cast<int>(ImageType::NUM_IMAGE_TYPES)] = {};
// Array of bool for whether accessibility has been notified when an image
// needs to be read out. Bit is stored per image type. This bit is reset to
// false when the image is hidden.
bool accessibility_notified_[static_cast<int>(ImageType::NUM_IMAGE_TYPES)] =
{};
WEB_CONTENTS_USER_DATA_KEY_DECL();
DISALLOW_COPY_AND_ASSIGN(ContentSettingImageModelStates);
......
......@@ -18,6 +18,7 @@
#include "ui/events/event_utils.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/controls/image_view.h"
......@@ -102,6 +103,13 @@ void ContentSettingImageView::Update() {
UpdateImage();
SetVisible(true);
if (content_setting_image_model_->ShouldNotifyAccessibility(web_contents)) {
GetViewAccessibility().OverrideName(l10n_util::GetStringUTF16(
content_setting_image_model_->explanatory_string_id()));
NotifyAccessibilityEvent(ax::mojom::Event::kAlert, true);
content_setting_image_model_->AccessibilityWasNotified(web_contents);
}
// If the content usage or blockage should be indicated to the user, start the
// animation and record that the icon has been shown.
if (!can_animate_ ||
......
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