[omnibox] Make IPH Chrome Tip links accessible by selecting with tab key
Screenshots: - [IPH link not selected](http://screen/BVbLuBpBgpY3j4q) - [IPH link selected, focus ring around clickable area](http://screen/628oUQocJedaAEa) Bug: 376545774 Change-Id: I6f6425c772162839a411e0df19ed1460365a34f4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6014231 Commit-Queue: Orin Jaworski <orinj@chromium.org> Reviewed-by: Orin Jaworski <orinj@chromium.org> Reviewed-by: Moe Ahmadi <mahmadi@chromium.org> Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com> Cr-Commit-Position: refs/heads/main@{#1382652}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
a6f032fab6
commit
cc3acee2a7
chrome/browser/ui/views/omnibox
components
@ -221,6 +221,18 @@ OmniboxResultView::OmniboxResultView(OmniboxPopupViewViews* popup_view,
|
||||
std::make_unique<OmniboxMatchCellView>(this));
|
||||
suggestion_view_->iph_link_view()->SetCallback(base::BindRepeating(
|
||||
&OmniboxResultView::OpenIphLink, weak_factory_.GetWeakPtr()));
|
||||
|
||||
auto* const iph_link_focus_ring =
|
||||
views::FocusRing::Get(suggestion_view_->iph_link_view());
|
||||
iph_link_focus_ring->SetHasFocusPredicate(base::BindRepeating(
|
||||
[](const OmniboxResultView* result_view, const View* view) {
|
||||
return view->GetVisible() && result_view->GetMatchSelected() &&
|
||||
result_view->popup_view_->GetSelection().state ==
|
||||
OmniboxPopupSelection::FOCUSED_IPH_LINK;
|
||||
},
|
||||
base::Unretained(this)));
|
||||
iph_link_focus_ring->SetColorId(kColorOmniboxResultsFocusIndicator);
|
||||
|
||||
// Allocate space for the suggestion text only after accounting
|
||||
// for the space needed to render the inline action chip row.
|
||||
suggestion_view_->SetProperty(
|
||||
@ -488,6 +500,10 @@ void OmniboxResultView::ApplyThemeAndRefreshIcons(bool force_reapply_styles) {
|
||||
popup_view_->GetSelection().state ==
|
||||
OmniboxPopupSelection::NORMAL);
|
||||
}
|
||||
|
||||
if (suggestion_view_->iph_link_view()->GetVisible()) {
|
||||
views::FocusRing::Get(suggestion_view_->iph_link_view())->SchedulePaint();
|
||||
}
|
||||
}
|
||||
|
||||
void OmniboxResultView::OnSelectionStateChanged() {
|
||||
|
@ -858,6 +858,8 @@ void OmniboxEditModel::OpenSelection(OmniboxPopupSelection selection,
|
||||
} else if (selection.state ==
|
||||
OmniboxPopupSelection::FOCUSED_BUTTON_REMOVE_SUGGESTION) {
|
||||
TryDeletingPopupLine(selection.line);
|
||||
} else if (selection.state == OmniboxPopupSelection::FOCUSED_IPH_LINK) {
|
||||
controller_->client()->OpenIphLink(match.iph_link_url);
|
||||
} else {
|
||||
// Open the match.
|
||||
GURL alternate_nav_url = AutocompleteResult::ComputeAlternateNavUrl(
|
||||
@ -1968,7 +1970,7 @@ std::u16string OmniboxEditModel::GetPopupAccessibilityLabelForCurrentSelection(
|
||||
int additional_message_id = 0;
|
||||
std::u16string additional_message;
|
||||
// This switch statement should be updated when new selection types are added.
|
||||
static_assert(OmniboxPopupSelection::LINE_STATE_MAX_VALUE == 7);
|
||||
static_assert(OmniboxPopupSelection::LINE_STATE_MAX_VALUE == 8);
|
||||
switch (popup_selection_.state) {
|
||||
case OmniboxPopupSelection::FOCUSED_BUTTON_HEADER: {
|
||||
bool group_hidden = controller_->IsSuggestionGroupHidden(
|
||||
@ -2053,6 +2055,11 @@ std::u16string OmniboxEditModel::GetPopupAccessibilityLabelForCurrentSelection(
|
||||
? IDS_ACC_DISMISS_CHROME_TIP_FOCUSED_PREFIX
|
||||
: IDS_ACC_REMOVE_SUGGESTION_FOCUSED_PREFIX;
|
||||
break;
|
||||
case OmniboxPopupSelection::FOCUSED_IPH_LINK:
|
||||
return AutocompleteMatchType::ToAccessibilityLabel(
|
||||
match, match.iph_link_text, line, 0,
|
||||
l10n_util::GetStringUTF16(IDS_ACC_OMNIBOX_IPH_LINK_SELECTED),
|
||||
label_prefix_length);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -4,13 +4,14 @@
|
||||
|
||||
#include "components/omnibox/browser/omnibox_popup_selection.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "build/build_config.h"
|
||||
#include "components/omnibox/browser/actions/omnibox_action.h"
|
||||
#include "components/omnibox/browser/autocomplete_match.h"
|
||||
#include "components/omnibox/browser/autocomplete_result.h"
|
||||
#include "components/search_engines/template_url_service.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
constexpr bool kIsDesktop = !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS);
|
||||
|
||||
const size_t OmniboxPopupSelection::kNoMatch = static_cast<size_t>(-1);
|
||||
@ -99,6 +100,8 @@ bool OmniboxPopupSelection::IsControlPresentOnMatch(
|
||||
return match.type == AutocompleteMatchType::HISTORY_EMBEDDINGS;
|
||||
case FOCUSED_BUTTON_REMOVE_SUGGESTION:
|
||||
return match.SupportsDeletion();
|
||||
case FOCUSED_IPH_LINK:
|
||||
return match.IsIPHSuggestion() && !match.iph_link_url.is_empty();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -203,6 +206,7 @@ OmniboxPopupSelection::GetAllAvailableSelectionsSorted(
|
||||
all_states.push_back(FOCUSED_BUTTON_THUMBS_UP);
|
||||
all_states.push_back(FOCUSED_BUTTON_THUMBS_DOWN);
|
||||
all_states.push_back(FOCUSED_BUTTON_REMOVE_SUGGESTION);
|
||||
all_states.push_back(FOCUSED_IPH_LINK);
|
||||
}
|
||||
DCHECK(std::is_sorted(all_states.begin(), all_states.end()))
|
||||
<< "This algorithm depends on a sorted list of line states.";
|
||||
|
@ -63,6 +63,11 @@ struct OmniboxPopupSelection {
|
||||
// button is focused. Pressing enter will attempt to remove this suggestion.
|
||||
FOCUSED_BUTTON_REMOVE_SUGGESTION,
|
||||
|
||||
// `NULL_RESULT_MESSAGE` IPH match types are not normally focusable, but
|
||||
// their links still need to be tab-accessible, so this state is available
|
||||
// when such a match has an IPH URL link.
|
||||
FOCUSED_IPH_LINK,
|
||||
|
||||
// Whenever new line state is added, accessibility label for current
|
||||
// selection should be revisited
|
||||
// (`OmniboxEditModel::GetPopupAccessibilityLabelForCurrentSelection()`).
|
||||
|
@ -357,6 +357,9 @@
|
||||
<message name="IDS_OMNIBOX_HISTORY_EMBEDDINGS_DISCLAIMER_IPH_LINK_TEXT" desc="The link displayed on the last row in the Omnibox as IPH informing them their info is sent to Google.">
|
||||
Learn more
|
||||
</message>
|
||||
<message name="IDS_ACC_OMNIBOX_IPH_LINK_SELECTED" desc="Announcement when an IPH Chrome Tip link is selected." translateable="false">
|
||||
Chrome Tip link, press Enter to open <ph name="IPH_LINK_FOCUSED_LINK_TEXT">$1<ex>Learn more</ex></ph>
|
||||
</message>
|
||||
|
||||
<message name="IDS_OMNIBOX_HISTORY_SCOPE_PROMO_IPH" desc="The string displayed as the last row in the Omnibox as IPH encouraging users to try the @history scope.">
|
||||
Type @history to search your browsing history
|
||||
|
Reference in New Issue
Block a user