Skip to content

Commit

Permalink
Move error state to separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
spylogsster committed Oct 5, 2023
1 parent 82a623c commit 11c8aae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
25 changes: 14 additions & 11 deletions browser/ui/views/toolbar/brave_vpn_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,18 @@ void BraveVPNButton::OnConnectionStateChanged(ConnectionState state) {
// the button in the error state until we get it clearly fixed.
return;
}
UpdateButtonState();
UpdateColorsAndInsets();
}

void BraveVPNButton::UpdateButtonState() {
is_error_state_ = IsConnectError();
}

void BraveVPNButton::OnPurchasedStateChanged(
brave_vpn::mojom::PurchasedState state,
const absl::optional<std::string>& description) {
UpdateButtonState();
if (IsPurchased()) {
UpdateColorsAndInsets();
}
Expand All @@ -227,23 +233,20 @@ std::unique_ptr<views::Border> BraveVPNButton::GetBorder(
}

void BraveVPNButton::UpdateColorsAndInsets() {
const bool is_connect_error = IsConnectError();
is_error_state_ = is_connect_error;

ui::ColorProvider* cp = GetColorProvider();
if (!cp) {
return;
}

const auto bg_color =
cp->GetColor(is_connect_error ? kColorBraveVpnButtonErrorBackgroundNormal
: kColorBraveVpnButtonBackgroundNormal);
cp->GetColor(is_error_state_ ? kColorBraveVpnButtonErrorBackgroundNormal
: kColorBraveVpnButtonBackgroundNormal);
SetBackground(views::CreateRoundedRectBackground(bg_color, kButtonRadius));

SetEnabledTextColors(cp->GetColor(is_connect_error
SetEnabledTextColors(cp->GetColor(is_error_state_
? kColorBraveVpnButtonTextError
: kColorBraveVpnButtonText));
if (is_connect_error) {
if (is_error_state_) {
SetImage(
views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(kVpnIndicatorErrorIcon,
Expand Down Expand Up @@ -271,16 +274,16 @@ void BraveVPNButton::UpdateColorsAndInsets() {
// border color are mixed as both have alpha value.
// Draw border only for error state.
SetBorder(GetBorder(color_utils::GetResultingPaintColor(
cp->GetColor(is_connect_error ? kColorBraveVpnButtonErrorBorder
: kColorBraveVpnButtonBorder),
cp->GetColor(is_error_state_ ? kColorBraveVpnButtonErrorBorder
: kColorBraveVpnButtonBorder),
bg_color)));

auto* ink_drop_host = views::InkDrop::Get(this);

// Use different ink drop hover color for each themes.
auto target_base_color = color_utils::GetResultingPaintColor(
cp->GetColor(is_connect_error ? kColorBraveVpnButtonErrorBackgroundHover
: kColorBraveVpnButtonBorder),
cp->GetColor(is_error_state_ ? kColorBraveVpnButtonErrorBackgroundHover
: kColorBraveVpnButtonBorder),
bg_color);
bool need_ink_drop_color_update =
target_base_color != ink_drop_host->GetBaseColor();
Expand Down
1 change: 1 addition & 0 deletions browser/ui/views/toolbar/brave_vpn_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class BraveVPNButton : public ToolbarButton,
bool IsPurchased() const;
std::unique_ptr<views::Border> GetBorder(SkColor border_color) const;
void OnButtonPressed(const ui::Event& event);
void UpdateButtonState();

bool is_error_state_ = false;
absl::optional<brave_vpn::mojom::ConnectionState>
Expand Down

0 comments on commit 11c8aae

Please sign in to comment.