Skip to content

Commit

Permalink
Updates Open in Tor view in location bar.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkarolin committed Jul 2, 2024
1 parent 8b1ea86 commit 1337912
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 56 deletions.
2 changes: 1 addition & 1 deletion app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ Or change later at <ph name="SETTINGS_EXTENIONS_LINK">$2<ex>brave://settings/ext
Open Private Window with Tor
</message>
<message name="IDS_LOCATION_BAR_OPEN_IN_TOR" desc="Button in location bar to open onion available site in tor window.">
Tor
Open in Tor
</message>
<message name="IDS_PROFILES_TOR_PROFILE_NAME" desc="Name of the Tor profile.">
Tor
Expand Down
1 change: 0 additions & 1 deletion app/vector_icons/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ aggregate_vector_icons("brave_vector_icons") {
"brave_translate.icon",
"download_unlock.icon",
"open_in_ipfs.icon",
"open_in_tor.icon",
"sidebar_toolbar_button.icon",
"sidebar_toolbar_button_right.icon",
"web_discovery_infobar_close_button.icon",
Expand Down
36 changes: 0 additions & 36 deletions app/vector_icons/open_in_tor.icon

This file was deleted.

44 changes: 26 additions & 18 deletions browser/ui/views/location_bar/onion_location_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

#include "base/memory/raw_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "brave/app/vector_icons/vector_icons.h"
#include "brave/browser/tor/tor_profile_manager.h"
#include "brave/components/l10n/common/localization_util.h"
#include "brave/components/tor/onion_location_tab_helper.h"
#include "brave/components/vector_icons/vector_icons.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_window.h"
Expand Down Expand Up @@ -43,10 +43,15 @@

namespace {

constexpr SkColor kOpenInTorBg = SkColorSetRGB(0x6a, 0x37, 0x85);
constexpr SkColor kIconColor = SkColorSetRGB(0xf0, 0xf2, 0xff);
constexpr SkColor kOpenInTorBg = SkColorSetRGB(0x8c, 0x30, 0xbb);
constexpr SkColor kIconColor = SK_ColorWHITE;
constexpr SkColor kTextColor = SK_ColorWHITE;
constexpr int kIconSize = 12;
constexpr int kFontSize = 18;
constexpr int kIconSize = 18;
constexpr int kIconLabelSpacing = 4;
constexpr int kCornerRadius = 8;
constexpr auto kButtonInsets = gfx::Insets::TLBR(5, 4, 5, 8);
constexpr auto kViewInsets = gfx::Insets::VH(1, 3);

// Sets the focus and ink drop highlight path to match the background
// along with it's corner radius.
Expand All @@ -60,8 +65,7 @@ class HighlightPathGenerator : public views::HighlightPathGenerator {
SkPath GetHighlightPath(const views::View* view) override {
const gfx::Rect highlight_bounds = view->GetLocalBounds();
const SkRect rect = RectToSkRect(highlight_bounds);
const int corner_radius = view->height() / 2;
return SkPath().addRoundRect(rect, corner_radius, corner_radius);
return SkPath().addRoundRect(rect, kCornerRadius, kCornerRadius);
}
};

Expand All @@ -79,21 +83,25 @@ class OnionLocationButtonView : public views::LabelButton {
SetTooltipText(brave_l10n::GetLocalizedResourceUTF16String(
IDS_LOCATION_BAR_ONION_AVAILABLE_TOOLTIP_TEXT));
}
// Render vector icon
const gfx::ImageSkia image =
gfx::CreateVectorIcon(kOpenInTorIcon, kIconSize, kIconColor);
SetImageModel(views::Button::STATE_NORMAL,
ui::ImageModel::FromImageSkia(image));
// Set style specifics

// Set text style specifics
SetEnabledTextColors(kTextColor);
SetTextColor(views::Button::STATE_DISABLED, kTextColor);
SetHorizontalAlignment(gfx::ALIGN_RIGHT);
SetImageLabelSpacing(6);
label()->SetFontList(
label()->font_list().DeriveWithHeightUpperBound(kFontSize));

// Render vector icon
SetImageModel(views::Button::STATE_NORMAL,
ui::ImageModel::FromVectorIcon(kLeoProductTorIcon, kIconColor,
kIconSize));

// Show icon on the left
SetHorizontalAlignment(gfx::ALIGN_LEFT);
SetImageLabelSpacing(kIconLabelSpacing);

auto* ink_drop = views::InkDrop::Get(this);
ink_drop->SetMode(views::InkDropHost::InkDropMode::ON);
SetBorder(views::CreateEmptyBorder(
GetLayoutInsets(LOCATION_BAR_ICON_INTERIOR_PADDING)));
SetBorder(views::CreateEmptyBorder(kButtonInsets));
SetHasInkDropActionOnClick(true);
ink_drop->SetVisibleOpacity(kToolbarInkDropVisibleOpacity);
UpdateBorder();
Expand Down Expand Up @@ -121,7 +129,7 @@ class OnionLocationButtonView : public views::LabelButton {

void UpdateBorder() {
SetBackground(
views::CreateRoundedRectBackground(kOpenInTorBg, height() / 2));
views::CreateRoundedRectBackground(kOpenInTorBg, kCornerRadius));
}

void ButtonPressed() {
Expand All @@ -135,7 +143,7 @@ class OnionLocationButtonView : public views::LabelButton {
} // namespace

OnionLocationView::OnionLocationView(Profile* profile) {
SetBorder(views::CreateEmptyBorder(gfx::Insets::VH(1, 3)));
SetBorder(views::CreateEmptyBorder(kViewInsets));
SetVisible(false);
// automatic layout
auto vertical_container_layout = std::make_unique<views::BoxLayout>(
Expand Down

0 comments on commit 1337912

Please sign in to comment.