Skip to content

Commit

Permalink
Merge pull request #3617 from brave/translate_dont_ask_again
Browse files Browse the repository at this point in the history
Add don't ask again to translate bubble
  • Loading branch information
yrliou authored Oct 8, 2019
2 parents 51c7358 + 626748e commit 9c448c7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_BRAVE_TRANSLATE_BUBBLE_CANCEL" desc="Text to show for the translate bubble's cancel button to dismiss the bubble.">
Cancel
</message>
<message name="IDS_BRAVE_TRANSLATE_BUBBLE_DONT_ASK_AGAIN" desc="Text to show for the don't ask again button.">
Don't ask me again
</message>
<!-- App shortcuts -->
<if expr="not is_win">
<message name="IDS_APP_SHORTCUTS_SUBDIR_NAME_BRAVE_NIGHTLY" desc="Name for the Brave Apps Start Menu folder name.">
Expand Down
6 changes: 6 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,10 @@ source_set("ui") {
]
deps += [ "//brave/components/brave_wallet_ui:generated_resources" ]
}

if (toolkit_views) {
if (enable_brave_translate_extension) {
deps += [ "//components/translate/core/browser" ]
}
}
}
39 changes: 38 additions & 1 deletion browser/ui/views/translate/brave_translate_bubble_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
#include "brave/browser/ui/views/translate/brave_translate_icon_view.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/browser/extensions/webstore_install_with_prompt.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/page_action/page_action_icon_container.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/toolbar_button_provider.h"
#include "chrome/browser/ui/views/page_action/omnibox_page_action_icon_container_view.h"
#include "chrome/browser/ui/page_action/page_action_icon_container.h"
#include "components/prefs/pref_service.h"
#include "components/translate/core/browser/translate_pref_names.h"
#include "extensions/browser/extension_registry.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/button/md_text_button.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/style/platform_style.h"
Expand All @@ -42,6 +46,9 @@ views::View* BraveTranslateBubbleView::BraveCreateViewBeforeTranslate() {

constexpr int kButtonColumnSetId = 0;
views::ColumnSet* cs = layout->AddColumnSet(kButtonColumnSetId);
cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER,
views::GridLayout::kFixedSize, views::GridLayout::USE_PREF, 0,
0);
cs->AddPaddingColumn(1.0, 0);
cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER,
views::GridLayout::kFixedSize, views::GridLayout::USE_PREF, 0,
Expand All @@ -53,6 +60,17 @@ views::View* BraveTranslateBubbleView::BraveCreateViewBeforeTranslate() {
views::GridLayout::kFixedSize, views::GridLayout::USE_PREF, 0,
0);

auto dont_ask_button = std::make_unique<views::LabelButton>(
this,
l10n_util::GetStringUTF16(IDS_BRAVE_TRANSLATE_BUBBLE_DONT_ASK_AGAIN));
dont_ask_button->SetID(BUTTON_ID_ALWAYS_TRANSLATE);

// Use the same text color as the cancel button.
const auto color =
views::style::GetColor(*dont_ask_button, views::style::CONTEXT_BUTTON_MD,
views::style::STYLE_PRIMARY);
dont_ask_button->SetTextColor(views::Button::STATE_NORMAL, color);

auto accept_button = views::MdTextButton::CreateSecondaryUiButton(
this, l10n_util::GetStringUTF16(IDS_BRAVE_TRANSLATE_BUBBLE_INSTALL));
accept_button->SetID(BUTTON_ID_TRANSLATE);
Expand All @@ -67,6 +85,8 @@ views::View* BraveTranslateBubbleView::BraveCreateViewBeforeTranslate() {
views::GridLayout::kFixedSize,
provider->GetDistanceMetric(views::DISTANCE_UNRELATED_CONTROL_VERTICAL));

layout->AddView(std::move(dont_ask_button));

if (views::PlatformStyle::kIsOkButtonLeading) {
layout->AddView(std::move(accept_button));
layout->AddView(std::move(cancel_button));
Expand Down Expand Up @@ -96,6 +116,18 @@ void BraveTranslateBubbleView::InstallGoogleTranslate() {
translate_icon->InstallGoogleTranslate();
}

void BraveTranslateBubbleView::DisableOfferTranslatePref() {
if (!web_contents())
return;

Profile* profile =
Profile::FromBrowserContext(web_contents()->GetBrowserContext());
PrefService* const prefs = profile->GetPrefs();
DCHECK(prefs);

prefs->SetBoolean(prefs::kOfferTranslateEnabled, false);
}

void BraveTranslateBubbleView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
switch (static_cast<ButtonID>(sender->GetID())) {
Expand All @@ -107,6 +139,11 @@ void BraveTranslateBubbleView::ButtonPressed(views::Button* sender,
CloseBubble();
break;
}
case BUTTON_ID_ALWAYS_TRANSLATE: {
DisableOfferTranslatePref();
CloseBubble();
break;
}
default: {
// We don't expect other buttons used by chromium's original views.
NOTREACHED();
Expand Down
1 change: 1 addition & 0 deletions browser/ui/views/translate/brave_translate_bubble_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class BraveTranslateBubbleView : public TranslateBubbleView {
private:
friend class BraveTranslateBubbleViewTest;
views::View* BraveCreateViewBeforeTranslate();
void DisableOfferTranslatePref();

DISALLOW_COPY_AND_ASSIGN(BraveTranslateBubbleView);
};
Expand Down

0 comments on commit 9c448c7

Please sign in to comment.