Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Brave News]: Uplift Subscribe Button Fixes to 1.47.x #16145

Merged
merged 3 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/vector_icons/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ aggregate_vector_icons("brave_vector_icons") {
"brave_ads_light_mode_info_button.icon",
"brave_news_arrow_right.icon",
"brave_news_follow_button.icon",
"brave_news_subscribe.icon",
"brave_news_unfollow_button.icon",
"brave_sad.icon",
"brave_today_subscribe.icon",
"brave_today_subscribed.icon",
"brave_tooltips_stopwatch.icon",
"brave_translate.icon",
"download_unlock.icon",
Expand Down
36 changes: 36 additions & 0 deletions app/vector_icons/brave_news_subscribe.icon
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2022 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.

CANVAS_DIMENSIONS, 16,
MOVE_TO, 1.68f, 2.38f,
CUBIC_TO, 1.68f, 2.01f, 1.99f, 1.7f, 2.37f, 1.7f,
LINE_TO, 2.93f, 1.7f,
CUBIC_TO, 9.23f, 1.7f, 14.35f, 6.81f, 14.35f, 13.12f,
LINE_TO, 14.35f, 13.68f,
CUBIC_TO, 14.35f, 14.06f, 14.04f, 14.37f, 13.66f, 14.37f,
CUBIC_TO, 13.28f, 14.37f, 12.97f, 14.06f, 12.97f, 13.68f,
LINE_TO, 12.97f, 13.12f,
CUBIC_TO, 12.97f, 7.57f, 8.48f, 3.07f, 2.93f, 3.07f,
LINE_TO, 2.37f, 3.07f,
CUBIC_TO, 1.99f, 3.07f, 1.68f, 2.76f, 1.68f, 2.38f,
CLOSE,
MOVE_TO, 1.68f, 7.47f,
CUBIC_TO, 1.68f, 7.09f, 1.99f, 6.78f, 2.37f, 6.78f,
LINE_TO, 2.93f, 6.78f,
CUBIC_TO, 6.43f, 6.78f, 9.26f, 9.62f, 9.26f, 13.12f,
LINE_TO, 9.26f, 13.68f,
CUBIC_TO, 9.26f, 14.06f, 8.96f, 14.37f, 8.58f, 14.37f,
CUBIC_TO, 8.2f, 14.37f, 7.89f, 14.06f, 7.89f, 13.68f,
LINE_TO, 7.89f, 13.12f,
CUBIC_TO, 7.89f, 10.37f, 5.67f, 8.15f, 2.93f, 8.15f,
LINE_TO, 2.37f, 8.15f,
CUBIC_TO, 1.99f, 8.15f, 1.68f, 7.85f, 1.68f, 7.47f,
CLOSE,
MOVE_TO, 1.68f, 13.12f,
CUBIC_TO, 1.68f, 12.42f, 2.24f, 11.86f, 2.93f, 11.86f,
CUBIC_TO, 3.62f, 11.86f, 4.18f, 12.42f, 4.18f, 13.12f,
CUBIC_TO, 4.18f, 13.81f, 3.62f, 14.37f, 2.93f, 14.37f,
CUBIC_TO, 2.24f, 14.37f, 1.68f, 13.81f, 1.68f, 13.12f,
CLOSE
66 changes: 0 additions & 66 deletions app/vector_icons/brave_today_subscribe.icon

This file was deleted.

85 changes: 0 additions & 85 deletions app/vector_icons/brave_today_subscribed.icon

This file was deleted.

14 changes: 12 additions & 2 deletions browser/brave_news/brave_news_tab_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,18 @@ BraveNewsTabHelper::GetAvailableFeeds() {
bool BraveNewsTabHelper::IsSubscribed(const FeedDetails& feed_details) {
auto* publisher = controller_->publisher_controller()->GetPublisherForFeed(
feed_details.feed_url);
return publisher && publisher->user_enabled_status ==
brave_news::mojom::UserEnabled::ENABLED;
if (!publisher)
return false;

// When a direct feed exists, it is always subscribed (there is no way to have
// an unsubscribed direct feed).
if (publisher->type == brave_news::mojom::PublisherType::DIRECT_SOURCE)
return true;

// Otherwise, it's a combined feed, so just return whether the user has
// enabled it.
return publisher->user_enabled_status ==
brave_news::mojom::UserEnabled::ENABLED;
}

bool BraveNewsTabHelper::IsSubscribed() {
Expand Down
17 changes: 8 additions & 9 deletions browser/ui/views/location_bar/brave_news_location_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "base/bind.h"
#include "brave/app/vector_icons/vector_icons.h"
#include "brave/browser/brave_news/brave_news_tab_helper.h"
#include "brave/browser/themes/brave_dark_mode_utils.h"
#include "brave/browser/ui/views/brave_news/brave_news_bubble_view.h"
#include "brave/components/brave_today/common/pref_names.h"
#include "chrome/browser/profiles/profile.h"
Expand All @@ -23,10 +22,12 @@
#include "components/grit/brave_components_strings.h"
#include "components/prefs/pref_member.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/skia_conversions.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/border.h"
#include "ui/views/controls/button/label_button.h"
Expand Down Expand Up @@ -108,9 +109,8 @@ class BraveNewsButtonView : public views::LabelButton,
has_feeds = !tab_helper->GetAvailableFeeds().empty();
}

auto image = gfx::CreateVectorIcon(
subscribed ? kBraveTodaySubscribedIcon : kBraveTodaySubscribeIcon, 16,
color_utils::DeriveDefaultIconColor(GetIconColor(subscribed)));
auto image = gfx::CreateVectorIcon(kBraveNewsSubscribeIcon, 16,
GetIconColor(subscribed));
SetImage(ButtonState::STATE_NORMAL, image);
SetVisible(has_feeds);
}
Expand Down Expand Up @@ -182,12 +182,11 @@ class BraveNewsButtonView : public views::LabelButton,

SkColor GetIconColor(bool subscribed) const {
if (!subscribed)
return GetCurrentTextColor();
return color_utils::DeriveDefaultIconColor(GetCurrentTextColor());

return dark_mode::GetActiveBraveDarkModeType() ==
dark_mode::BraveDarkModeType::BRAVE_DARK_MODE_TYPE_DARK
? kSubscribedDarkColor
: kSubscribedLightColor;
auto is_dark = GetNativeTheme()->GetPreferredColorScheme() ==
ui::NativeTheme::PreferredColorScheme::kDark;
return is_dark ? kSubscribedDarkColor : kSubscribedLightColor;
}

BooleanPrefMember should_show_;
Expand Down
9 changes: 9 additions & 0 deletions chromium_src/ui/views/controls/button/md_text_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@ void MdTextButton::SetLoading(bool loading) {
UpdateColors();
}

void MdTextButton::UpdateBackgroundColor() {
// Handled via |UpdateColorsForBrave|.
if (kind_ != kOld) {
return;
}

MdTextButtonBase::UpdateBackgroundColor();
}

void MdTextButton::UpdateOldColorsForBrave() {
if (GetProminent()) {
return;
Expand Down
21 changes: 12 additions & 9 deletions chromium_src/ui/views/controls/button/md_text_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,28 @@

#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/gfx/vector_icon_types.h"
#include "ui/views/controls/button/label_button.h"

// Rename MdTextButton to MdTextButtonBase
#define MdTextButton MdTextButtonBase

// Define a Brave-specific method we can get called from UpdateColors() to
// extend its functionality instead of defining UpdateColors() "virtual" and
// overriding it in our version of the MdTextButton class because there are some
// subclasses that define their own UpdateColors() method (OmniboxChipButton)
// now, which would not work with the virtual + override approach.
#define UpdateColors \
UpdateColors_Unused(); \
// Define a Brave-specific method to be called from UpdateColors() to extend its
// functionality instead of defining UpdateColors() "virtual" and overriding it
// in our version of the MdTextButton class because there are some subclasses
// that define their own UpdateColors() method (OmniboxChipButton) now, which
// would not work with the virtual + override approach.
// Note: We redefine UpdateBackgroundColor because we want it to be protected.
#define UpdateBackgroundColor \
UpdateBackgroundColor_Unused(); \
\
protected: \
virtual void UpdateColorsForBrave() = 0; \
virtual void UpdateIconForBrave() = 0; \
void UpdateColors
void UpdateBackgroundColor

#include "src/ui/views/controls/button/md_text_button.h"

#undef UpdateColors
#undef UpdateBackgroundColor
#undef MdTextButton

namespace views {
Expand Down Expand Up @@ -63,6 +65,7 @@ class VIEWS_EXPORT MdTextButton : public MdTextButtonBase {
void UpdateOldColorsForBrave();

// MdTextButtonBase:
void UpdateBackgroundColor() override;
void UpdateColorsForBrave() override;
void UpdateIconForBrave() override;

Expand Down