Skip to content

Commit

Permalink
[UI] Make RichHoverButton accept a title string
Browse files Browse the repository at this point in the history
Before this CL:
RichHoverButton constructor accepted a title_resource_id while the
secondary text, subtitle, and the tooltip was passed as actualy strings.

After this CL:
The title has also been changed to a string:
1- For consistency with other parameters.
2- To make the RichHoverButton usable with non-constant strings as
titles.

This is a purely mechanical change.

Bug: 1382018
Change-Id: If5031fcabf724bb5c7936531fc29da1b00b255bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4024443
Reviewed-by: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1070712}
  • Loading branch information
mohamedamir authored and Chromium LUCI CQ committed Nov 12, 2022
1 parent 7656d59 commit 603f475
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 29 deletions.
10 changes: 5 additions & 5 deletions chrome/browser/ui/views/controls/rich_hover_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ std::unique_ptr<views::View> CreateIconView(const ui::ImageModel& icon_image) {
RichHoverButton::RichHoverButton(
views::Button::PressedCallback callback,
const ui::ImageModel& main_image_icon,
int title_resource_id,
const std::u16string& title_text,
const std::u16string& secondary_text,
int click_target_id,
const std::u16string& tooltip_text,
Expand Down Expand Up @@ -128,8 +128,8 @@ RichHoverButton::RichHoverButton(
AddChildView(std::make_unique<views::View>());
}

if (title_resource_id)
SetTitleText(title_resource_id, secondary_text);
if (!title_text.empty())
SetTitleText(title_text, secondary_text);

if (!subtitle_text.empty()) {
table_layout->AddRows(1, views::TableLayout::kFixedSize);
Expand All @@ -155,10 +155,10 @@ RichHoverButton::RichHoverButton(
Layout();
}

void RichHoverButton::SetTitleText(int title_resource_id,
void RichHoverButton::SetTitleText(const std::u16string& title_text,
const std::u16string& secondary_text) {
DCHECK(title_);
title_->SetText(l10n_util::GetStringUTF16(title_resource_id));
title_->SetText(title_text);
if (!secondary_text.empty()) {
secondary_label_->SetText(secondary_text);
}
Expand Down
15 changes: 7 additions & 8 deletions chrome/browser/ui/views/controls/rich_hover_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,19 @@ class RichHoverButton : public HoverButton {
METADATA_HEADER(RichHoverButton);

// Creates a hoverable button that displays the string given by
// |title_resource_id| and |secondary_text| and displays the latter part in
// the secondary text color. Optional |action_image_icon| is shown on right
// side. |secondary_text| is shown on right side before the
// |action_image_icon|. |tooltip_text| is used for the tooltip shown on
// hovering over the button.
// |title_text| and |secondary_text| and displays the latter part in the
// secondary text color. Optional |action_image_icon| is shown on right side.
// |secondary_text| is shown on right side before the |action_image_icon|.
// |tooltip_text| is used for the tooltip shown on hovering over the button.
// *-------------------------------------------------------------------------*
// | Icon | |title_resource_id| |secondary_text| State image | Action icon |
// | Icon | |title_text| |secondary_text| State image | Action icon |
// |-------------------------------------------------------------------------|
// | | |subtitle_text| |
// *-------------------------------------------------------------------------*
RichHoverButton(
views::Button::PressedCallback callback,
const ui::ImageModel& main_image_icon,
int title_resource_id,
const std::u16string& title_text,
const std::u16string& secondary_text,
int click_target_id,
const std::u16string& tooltip_text,
Expand All @@ -60,7 +59,7 @@ class RichHoverButton : public HoverButton {

// Updates the title text, and applies the secondary style to the secondary
// text portion, if present.
void SetTitleText(int title_resource_id,
void SetTitleText(const std::u16string& title_text,
const std::u16string& secondary_text);

void SetTitleText(const std::u16string& title_text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ PageInfoAdPersonalizationContentView::PageInfoAdPersonalizationContentView(
},
this),
PageInfoViewFactory::GetSiteSettingsIcon(),
IDS_PAGE_INFO_AD_PERSONALIZATION_SUBPAGE_MANAGE_BUTTON, std::u16string(),
0,
l10n_util::GetStringUTF16(
IDS_PAGE_INFO_AD_PERSONALIZATION_SUBPAGE_MANAGE_BUTTON),
std::u16string(), 0,
/*tooltip_text=*/std::u16string(), std::u16string(),
PageInfoViewFactory::GetLaunchIcon()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ void PageInfoCookiesContentView::InitCookiesDialogButton() {
view->presenter_->OpenCookiesDialog();
},
this),
icon, IDS_PAGE_INFO_COOKIES_DIALOG_BUTTON_TITLE, std::u16string(),
icon,
l10n_util::GetStringUTF16(IDS_PAGE_INFO_COOKIES_DIALOG_BUTTON_TITLE),
std::u16string(),
PageInfoViewFactory::VIEW_ID_PAGE_INFO_LINK_OR_BUTTON_COOKIE_DIALOG,
tooltip, /*subtitle_text=*/u" ",
PageInfoViewFactory::GetLaunchIcon()));
Expand Down Expand Up @@ -346,8 +348,8 @@ void PageInfoCookiesContentView::InitFpsButton(bool is_managed) {
base::BindRepeating(
&PageInfoCookiesContentView::FpsSettingsButtonClicked,
base::Unretained(this)),
PageInfoViewFactory::GetFpsIcon(), IDS_PAGE_INFO_COOKIES,
std::u16string(),
PageInfoViewFactory::GetFpsIcon(),
l10n_util::GetStringUTF16(IDS_PAGE_INFO_COOKIES), std::u16string(),
PageInfoViewFactory::VIEW_ID_PAGE_INFO_LINK_OR_BUTTON_FPS_SETTINGS,
tooltip, /*secondary_text=*/u" ",
PageInfoViewFactory::GetLaunchIcon(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "components/page_info/core/page_info_history_data_source.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/view.h"

PageInfoHistoryController::PageInfoHistoryController(
Expand Down Expand Up @@ -58,7 +59,8 @@ std::unique_ptr<views::View> PageInfoHistoryController::CreateHistoryButton(
return std::make_unique<RichHoverButton>(
base::BindRepeating(&PageInfoHistoryController::OpenHistoryPage,
weak_factory_.GetWeakPtr()),
PageInfoViewFactory::GetHistoryIcon(), IDS_PAGE_INFO_HISTORY, last_visit,
PageInfoViewFactory::GetHistoryIcon(),
l10n_util::GetStringUTF16(IDS_PAGE_INFO_HISTORY), last_visit,
PageInfoViewFactory::VIEW_ID_PAGE_INFO_HISTORY_BUTTON,
/*tooltip_text=*/std::u16string(), std::u16string(),
PageInfoViewFactory::GetLaunchIcon());
Expand Down
24 changes: 16 additions & 8 deletions chrome/browser/ui/views/page_info/page_info_main_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ PageInfoMainView::PageInfoMainView(
},
this),
PageInfoViewFactory::GetSiteSettingsIcon(),
/*title_resource_id=*/link_text_id, std::u16string(),
/*title_text=*/l10n_util::GetStringUTF16(link_text_id),
std::u16string(),
PageInfoViewFactory::VIEW_ID_PAGE_INFO_LINK_OR_BUTTON_SITE_SETTINGS,
/*tooltip_text=*/l10n_util::GetStringUTF16(tooltip_text_id),
std::u16string(), PageInfoViewFactory::GetLaunchIcon()));
Expand Down Expand Up @@ -152,7 +153,8 @@ void PageInfoMainView::EnsureCookieInfo() {
RichHoverButton>(
base::BindRepeating(&PageInfoNavigationHandler::OpenCookiesPage,
base::Unretained(navigation_handler_)),
icon, IDS_PAGE_INFO_COOKIES_HEADER, std::u16string(),
icon, l10n_util::GetStringUTF16(IDS_PAGE_INFO_COOKIES_HEADER),
std::u16string(),
PageInfoViewFactory::VIEW_ID_PAGE_INFO_LINK_OR_BUTTON_COOKIES_SUBPAGE,
tooltip, std::u16string(),
PageInfoViewFactory::GetOpenSubpageIcon()));
Expand All @@ -166,7 +168,8 @@ void PageInfoMainView::EnsureCookieInfo() {
view->HandleMoreInfoRequest(view->cookie_button_);
},
this),
icon, IDS_PAGE_INFO_COOKIES, /*secondary_text=*/u"",
icon, l10n_util::GetStringUTF16(IDS_PAGE_INFO_COOKIES),
/*secondary_text=*/u"",
PageInfoViewFactory::VIEW_ID_PAGE_INFO_LINK_OR_BUTTON_COOKIE_DIALOG,
tooltip, std::u16string(), PageInfoViewFactory::GetLaunchIcon()));
}
Expand Down Expand Up @@ -201,7 +204,8 @@ void PageInfoMainView::SetCookieInfo(const CookieInfoList& cookie_info_list) {

// Update the text displaying the number of allowed cookies.
if (!base::FeatureList::IsEnabled(page_info::kPageInfoCookiesSubpage))
cookie_button_->SetTitleText(IDS_PAGE_INFO_COOKIES, num_cookies_text);
cookie_button_->SetTitleText(
l10n_util::GetStringUTF16(IDS_PAGE_INFO_COOKIES), num_cookies_text);

PreferredSizeChanged();
}
Expand Down Expand Up @@ -359,7 +363,8 @@ void PageInfoMainView::SetIdentityInfo(const IdentityInfo& identity_info) {
std::make_unique<RichHoverButton>(
base::BindRepeating(&PageInfoNavigationHandler::OpenSecurityPage,
base::Unretained(navigation_handler_)),
PageInfoViewFactory::GetConnectionSecureIcon(), 0, std::u16string(),
PageInfoViewFactory::GetConnectionSecureIcon(), std::u16string(),
std::u16string(),
PageInfoViewFactory::
VIEW_ID_PAGE_INFO_LINK_OR_BUTTON_SECURITY_INFORMATION,
l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_SUBPAGE_BUTTON),
Expand Down Expand Up @@ -597,7 +602,8 @@ std::unique_ptr<views::View> PageInfoMainView::CreateAboutThisSiteSection(
},
this, GURL(info.more_about().url()), info.has_description()),
PageInfoViewFactory::GetAboutThisPageIcon(),
IDS_PAGE_INFO_ABOUT_THIS_PAGE_TITLE, std::u16string(),
l10n_util::GetStringUTF16(IDS_PAGE_INFO_ABOUT_THIS_PAGE_TITLE),
std::u16string(),
PageInfoViewFactory::VIEW_ID_PAGE_INFO_ABOUT_THIS_SITE_BUTTON,
l10n_util::GetStringUTF16(IDS_PAGE_INFO_ABOUT_THIS_PAGE_TOOLTIP),
description, PageInfoViewFactory::GetLaunchIcon()));
Expand All @@ -616,7 +622,8 @@ std::unique_ptr<views::View> PageInfoMainView::CreateAboutThisSiteSection(
},
this, info),
PageInfoViewFactory::GetAboutThisSiteIcon(),
IDS_PAGE_INFO_ABOUT_THIS_SITE_HEADER, std::u16string(),
l10n_util::GetStringUTF16(IDS_PAGE_INFO_ABOUT_THIS_SITE_HEADER),
std::u16string(),
PageInfoViewFactory::VIEW_ID_PAGE_INFO_ABOUT_THIS_SITE_BUTTON,
l10n_util::GetStringUTF16(IDS_PAGE_INFO_ABOUT_THIS_SITE_TOOLTIP),
base::UTF8ToUTF16(info.description().description()),
Expand All @@ -639,7 +646,8 @@ PageInfoMainView::CreateAdPersonalizationSection() {
},
this),
PageInfoViewFactory::GetAdPersonalizationIcon(),
IDS_PAGE_INFO_AD_PERSONALIZATION_HEADER, std::u16string(),
l10n_util::GetStringUTF16(IDS_PAGE_INFO_AD_PERSONALIZATION_HEADER),
std::u16string(),
PageInfoViewFactory::VIEW_ID_PAGE_INFO_AD_PERSONALIZATION_BUTTON,
l10n_util::GetStringUTF16(IDS_PAGE_INFO_AD_PERSONALIZATION_TOOLTIP),
std::u16string(), PageInfoViewFactory::GetOpenSubpageIcon()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ PageInfoPermissionContentView::PageInfoPermissionContentView(
},
this),
PageInfoViewFactory::GetSiteSettingsIcon(),
IDS_PAGE_INFO_PERMISSIONS_SUBPAGE_MANAGE_BUTTON, std::u16string(), 0,
l10n_util::GetStringUTF16(
IDS_PAGE_INFO_PERMISSIONS_SUBPAGE_MANAGE_BUTTON),
std::u16string(), 0,
l10n_util::GetStringUTF16(
IDS_PAGE_INFO_PERMISSIONS_SUBPAGE_MANAGE_BUTTON_TOOLTIP),
std::u16string(), PageInfoViewFactory::GetLaunchIcon()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void PageInfoSecurityContentView::SetIdentityInfo(
view->certificate_.get());
},
this),
icon, title_id, std::u16string(),
icon, l10n_util::GetStringUTF16(title_id), std::u16string(),
PageInfoViewFactory::
VIEW_ID_PAGE_INFO_LINK_OR_BUTTON_CERTIFICATE_VIEWER,
tooltip, subtitle_text, PageInfoViewFactory::GetLaunchIcon())
Expand Down

0 comments on commit 603f475

Please sign in to comment.