Skip to content

Commit

Permalink
speedreader: icon: Fix accessible text
Browse files Browse the repository at this point in the history
In 85a5f8b we removed the label from the Speedreader icon. To make up
for this, we need more descriptive accessible text. This is taken from
the figma document linked in the issue.

Resolves brave/brave-browser#16881
  • Loading branch information
Kevin Kuehler committed Jul 10, 2021
1 parent 84a5f8b commit 7b25be4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 22 deletions.
9 changes: 9 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,15 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_PAGE_IS_DISTILLED" desc="Speedreader is enabled on this page">
in Speedreader
</message>
<message name="IDS_SPEEDREADER_ICON_TURN_OFF_READER_MODE" desc="Accessible text shown when a page is in Reader Mode">
Turn off reader mode
</message>
<message name="IDS_SPEEDREADER_ICON_TURN_ON_READER_MODE" desc="Accessible text shown when a page can be distilled">
Turn on reader mode
</message>
<message name="IDS_SPEEDREADER_ICON_SPEEDREADER_SETTINGS" desc="Accessible text shown when a page is in Speedreader Mode">
Speedreader settings
</message>
</if>

<!-- Stats -->
Expand Down
3 changes: 3 additions & 0 deletions browser/speedreader/speedreader_tab_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class SpeedreaderTabHelper
public content::WebContentsUserData<SpeedreaderTabHelper> {
public:
enum class DistillState {
// Used as an initialization state
kUnknown,

// The web contents is not distilled
kNone,

Expand Down
50 changes: 28 additions & 22 deletions browser/ui/views/speedreader/speedreader_icon_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
#include "ui/views/animation/ink_drop_host_view.h"
#include "ui/views/animation/ink_drop_state.h"

using DistillState = speedreader::SpeedreaderTabHelper::DistillState;

SpeedreaderIconView::SpeedreaderIconView(
CommandUpdater* command_updater,
IconLabelBubbleView::Delegate* icon_label_bubble_delegate,
Expand Down Expand Up @@ -58,15 +56,8 @@ void SpeedreaderIconView::UpdateImpl() {
if (ink_drop()->GetHighlighted() && !IsBubbleShowing())
ink_drop()->AnimateToState(views::InkDropState::HIDDEN, nullptr);

auto* tab_helper =
speedreader::SpeedreaderTabHelper::FromWebContents(contents);
if (!tab_helper) {
SetVisible(false);
return;
}

const ui::ThemeProvider* theme_provider = GetThemeProvider();
const DistillState state = tab_helper->PageDistillState();
const DistillState state = GetDistillState();
const bool is_distilled =
speedreader::SpeedreaderTabHelper::PageStateIsDistilled(state);

Expand Down Expand Up @@ -99,16 +90,7 @@ void SpeedreaderIconView::UpdateImpl() {
}

const gfx::VectorIcon& SpeedreaderIconView::GetVectorIcon() const {
auto* web_contents = GetWebContents();
if (!web_contents)
return kBraveReaderModeIcon;

auto* tab_helper =
speedreader::SpeedreaderTabHelper::FromWebContents(web_contents);
if (!tab_helper)
return kBraveReaderModeIcon;

const DistillState state = tab_helper->PageDistillState();
const DistillState state = GetDistillState();
if (state == DistillState::kSpeedreaderMode ||
state == DistillState::kSpeedreaderOnDisabledPage) {
return kBraveSpeedreaderModeIcon;
Expand All @@ -118,8 +100,20 @@ const gfx::VectorIcon& SpeedreaderIconView::GetVectorIcon() const {
}

std::u16string SpeedreaderIconView::GetTextForTooltipAndAccessibleName() const {
return l10n_util::GetStringUTF16(GetActive() ? IDS_EXIT_DISTILLED_PAGE
: IDS_DISTILL_PAGE);
int id;
const DistillState state = GetDistillState();
switch (state) {
case DistillState::kSpeedreaderMode:
case DistillState::kSpeedreaderOnDisabledPage:
id = IDS_SPEEDREADER_ICON_SPEEDREADER_SETTINGS;
break;
case DistillState::kReaderMode:
id = IDS_SPEEDREADER_ICON_TURN_OFF_READER_MODE;
break;
default:
id = IDS_SPEEDREADER_ICON_TURN_ON_READER_MODE;
}
return l10n_util::GetStringUTF16(id);
}

void SpeedreaderIconView::OnExecuting(
Expand All @@ -139,5 +133,17 @@ views::BubbleDialogDelegate* SpeedreaderIconView::GetBubble() const {
tab_helper->speedreader_bubble_view());
}

DistillState SpeedreaderIconView::GetDistillState() const {
DistillState state = DistillState::kUnknown;
auto* web_contents = GetWebContents();
if (web_contents) {
auto* tab_helper =
speedreader::SpeedreaderTabHelper::FromWebContents(web_contents);
if (tab_helper)
state = tab_helper->PageDistillState();
}
return state;
}

BEGIN_METADATA(SpeedreaderIconView, PageActionIconView)
END_METADATA
5 changes: 5 additions & 0 deletions browser/ui/views/speedreader/speedreader_icon_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
#ifndef BRAVE_BROWSER_UI_VIEWS_SPEEDREADER_SPEEDREADER_ICON_VIEW_H_
#define BRAVE_BROWSER_UI_VIEWS_SPEEDREADER_SPEEDREADER_ICON_VIEW_H_

#include "brave/browser/speedreader/speedreader_tab_helper.h"
#include "chrome/browser/ui/views/page_action/page_action_icon_view.h"
#include "content/public/browser/web_contents_observer.h"
#include "ui/base/metadata/metadata_header_macros.h"

using DistillState = speedreader::SpeedreaderTabHelper::DistillState;

namespace content {
class NavigationHandle;
} // namespace content
Expand All @@ -34,6 +37,8 @@ class SpeedreaderIconView : public PageActionIconView {
views::BubbleDialogDelegate* GetBubble() const override;
std::u16string GetTextForTooltipAndAccessibleName() const override;
void UpdateImpl() override;
private:
DistillState GetDistillState() const;
};

#endif // BRAVE_BROWSER_UI_VIEWS_SPEEDREADER_SPEEDREADER_ICON_VIEW_H_

0 comments on commit 7b25be4

Please sign in to comment.