Skip to content

Commit

Permalink
[BraveNews] Rename brave_news_location_view.cc[h] -> brave_news_actio…
Browse files Browse the repository at this point in the history
…n_icon_view.cc[h]
  • Loading branch information
jagadeshjai committed Jun 21, 2024
1 parent 4b64794 commit c47a0bb
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 62 deletions.
4 changes: 2 additions & 2 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1050,10 +1050,10 @@ source_set("ui") {
"views/brave_help_bubble/brave_help_bubble_delegate_view.h",
"views/brave_help_bubble/brave_help_bubble_host_view.cc",
"views/brave_help_bubble/brave_help_bubble_host_view.h",
"views/brave_news/brave_news_action_icon_view.cc",
"views/brave_news/brave_news_action_icon_view.h",
"views/brave_news/brave_news_bubble_controller.cc",
"views/brave_news/brave_news_bubble_controller.h",
"views/brave_news/brave_news_location_view.cc",
"views/brave_news/brave_news_location_view.h",
"views/frame/vertical_tab_strip_region_view.cc",
"views/frame/vertical_tab_strip_region_view.h",
"views/frame/vertical_tab_strip_root_view.cc",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) 2022 The Brave Authors. All rights reserved.
// Copyright (c) 2024 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/.
// You can obtain one at https://mozilla.org/MPL/2.0/.

#include "brave/browser/ui/views/brave_news/brave_news_location_view.h"
#include "brave/browser/ui/views/brave_news/brave_news_action_icon_view.h"

#include <memory>
#include <utility>
Expand Down Expand Up @@ -34,7 +34,7 @@ constexpr SkColor kSubscribedDarkColor = SkColorSetRGB(115, 122, 222);

} // namespace

BraveNewsLocationView::BraveNewsLocationView(
BraveNewsActionIconView::BraveNewsActionIconView(
Profile* profile,
IconLabelBubbleView::Delegate* icon_label_bubble_delegate,
PageActionIconView::Delegate* page_action_icon_delegate)
Expand All @@ -47,22 +47,22 @@ BraveNewsLocationView::BraveNewsLocationView(

should_show_.Init(brave_news::prefs::kShouldShowToolbarButton,
profile->GetPrefs(),
base::BindRepeating(&BraveNewsLocationView::UpdateImpl,
base::BindRepeating(&BraveNewsActionIconView::UpdateImpl,
base::Unretained(this)));
opted_in_.Init(brave_news::prefs::kBraveNewsOptedIn, profile->GetPrefs(),
base::BindRepeating(&BraveNewsLocationView::UpdateImpl,
base::BindRepeating(&BraveNewsActionIconView::UpdateImpl,
base::Unretained(this)));
news_enabled_.Init(brave_news::prefs::kNewTabPageShowToday,
profile->GetPrefs(),
base::BindRepeating(&BraveNewsLocationView::UpdateImpl,
base::BindRepeating(&BraveNewsActionIconView::UpdateImpl,
base::Unretained(this)));

Update();
}

BraveNewsLocationView::~BraveNewsLocationView() = default;
BraveNewsActionIconView::~BraveNewsActionIconView() = default;

void BraveNewsLocationView::UpdateImpl() {
void BraveNewsActionIconView::UpdateImpl() {
auto* contents = GetWebContents();
BraveNewsTabHelper* tab_helper =
contents ? BraveNewsTabHelper::FromWebContents(contents) : nullptr;
Expand Down Expand Up @@ -111,30 +111,30 @@ void BraveNewsLocationView::UpdateImpl() {
SetVisible(is_visible);
}

void BraveNewsLocationView::WebContentsDestroyed() {
void BraveNewsActionIconView::WebContentsDestroyed() {
page_feeds_observer_.Reset();
Observe(nullptr);
}

const gfx::VectorIcon& BraveNewsLocationView::GetVectorIcon() const {
const gfx::VectorIcon& BraveNewsActionIconView::GetVectorIcon() const {
return kLeoRssIcon;
}

std::u16string BraveNewsLocationView::GetTextForTooltipAndAccessibleName()
std::u16string BraveNewsActionIconView::GetTextForTooltipAndAccessibleName()
const {
return l10n_util::GetStringUTF16(IDS_BRAVE_NEWS_ACTION_VIEW_TOOLTIP);
}

bool BraveNewsLocationView::ShouldShowLabel() const {
bool BraveNewsActionIconView::ShouldShowLabel() const {
return false;
}

void BraveNewsLocationView::OnAvailableFeedsChanged(
void BraveNewsActionIconView::OnAvailableFeedsChanged(
const std::vector<GURL>& feeds) {
Update();
}

void BraveNewsLocationView::OnThemeChanged() {
void BraveNewsActionIconView::OnThemeChanged() {
bool subscribed = false;
if (auto* contents = GetWebContents()) {
subscribed = BraveNewsTabHelper::FromWebContents(contents)->IsSubscribed();
Expand All @@ -143,12 +143,12 @@ void BraveNewsLocationView::OnThemeChanged() {
PageActionIconView::OnThemeChanged();
}

void BraveNewsLocationView::OnExecuting(
void BraveNewsActionIconView::OnExecuting(
PageActionIconView::ExecuteSource execute_source) {
ShowBraveNewsBubble();
}

void BraveNewsLocationView::UpdateIconColor(bool subscribed) {
void BraveNewsActionIconView::UpdateIconColor(bool subscribed) {
SkColor icon_color;
if (subscribed) {
auto is_dark = GetNativeTheme()->GetPreferredColorScheme() ==
Expand All @@ -160,28 +160,28 @@ void BraveNewsLocationView::UpdateIconColor(bool subscribed) {
SetIconColor(icon_color);
}

brave_news::BraveNewsBubbleController* BraveNewsLocationView::GetController()
brave_news::BraveNewsBubbleController* BraveNewsActionIconView::GetController()
const {
auto* web_contents = GetWebContents();
return web_contents ? brave_news::BraveNewsBubbleController::
CreateOrGetFromWebContents(web_contents)
: nullptr;
}

views::BubbleDialogDelegate* BraveNewsLocationView::GetBubble() const {
views::BubbleDialogDelegate* BraveNewsActionIconView::GetBubble() const {
auto* controller = GetController();
return controller ? controller->GetBubble() : nullptr;
}

void BraveNewsLocationView::ShowBraveNewsBubble() {
void BraveNewsActionIconView::ShowBraveNewsBubble() {
if (auto* controller = GetController()) {
controller->ShowBubble(AsWeakPtr());
}
}

base::WeakPtr<BraveNewsLocationView> BraveNewsLocationView::AsWeakPtr() {
base::WeakPtr<BraveNewsActionIconView> BraveNewsActionIconView::AsWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
}

BEGIN_METADATA(BraveNewsLocationView)
BEGIN_METADATA(BraveNewsActionIconView)
END_METADATA
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) 2022 The Brave Authors. All rights reserved.
// Copyright (c) 2024 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/.
// You can obtain one at https://mozilla.org/MPL/2.0/.

#ifndef BRAVE_BROWSER_UI_VIEWS_BRAVE_NEWS_BRAVE_NEWS_LOCATION_VIEW_H_
#define BRAVE_BROWSER_UI_VIEWS_BRAVE_NEWS_BRAVE_NEWS_LOCATION_VIEW_H_
#ifndef BRAVE_BROWSER_UI_VIEWS_BRAVE_NEWS_BRAVE_NEWS_ACTION_ICON_VIEW_H_
#define BRAVE_BROWSER_UI_VIEWS_BRAVE_NEWS_BRAVE_NEWS_ACTION_ICON_VIEW_H_

#include <string>
#include <vector>
Expand All @@ -18,28 +18,27 @@
#include "ui/views/view.h"

class Profile;
class BraveNewsBubbleView;

namespace brave_news {
class BraveNewsBubbleController;
}

// LocationBar action for Brave News which shows a bubble allowing the user to
// manage feed subscriptions for the current Tab
class BraveNewsLocationView : public PageActionIconView,
public BraveNewsTabHelper::PageFeedsObserver,
public content::WebContentsObserver {
METADATA_HEADER(BraveNewsLocationView, PageActionIconView)
class BraveNewsActionIconView : public PageActionIconView,
public BraveNewsTabHelper::PageFeedsObserver,
public content::WebContentsObserver {
METADATA_HEADER(BraveNewsActionIconView, PageActionIconView)
public:
BraveNewsLocationView(
BraveNewsActionIconView(
Profile* profile,
IconLabelBubbleView::Delegate* icon_label_bubble_delegate,
PageActionIconView::Delegate* page_action_icon_delegate);
BraveNewsLocationView(const BraveNewsLocationView&) = delete;
BraveNewsLocationView& operator=(const BraveNewsLocationView&) = delete;
~BraveNewsLocationView() override;
BraveNewsActionIconView(const BraveNewsActionIconView&) = delete;
BraveNewsActionIconView& operator=(const BraveNewsActionIconView&) = delete;
~BraveNewsActionIconView() override;

base::WeakPtr<BraveNewsLocationView> AsWeakPtr();
base::WeakPtr<BraveNewsActionIconView> AsWeakPtr();

// PageActionIconView:
views::BubbleDialogDelegate* GetBubble() const override;
Expand Down Expand Up @@ -74,7 +73,7 @@ class BraveNewsLocationView : public PageActionIconView,
BooleanPrefMember opted_in_;
BooleanPrefMember news_enabled_;

base::WeakPtrFactory<BraveNewsLocationView> weak_ptr_factory_{this};
base::WeakPtrFactory<BraveNewsActionIconView> weak_ptr_factory_{this};
};

#endif // BRAVE_BROWSER_UI_VIEWS_BRAVE_NEWS_BRAVE_NEWS_LOCATION_VIEW_H_
#endif // BRAVE_BROWSER_UI_VIEWS_BRAVE_NEWS_BRAVE_NEWS_ACTION_ICON_VIEW_H_
4 changes: 2 additions & 2 deletions browser/ui/views/brave_news/brave_news_bubble_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <vector>

#include "base/memory/ptr_util.h"
#include "brave/browser/ui/views/brave_news/brave_news_action_icon_view.h"
#include "brave/browser/ui/views/brave_news/brave_news_bubble_view.h"
#include "brave/browser/ui/views/brave_news/brave_news_location_view.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"

namespace brave_news {
Expand All @@ -25,7 +25,7 @@ BraveNewsBubbleController::CreateOrGetFromWebContents(
BraveNewsBubbleController::~BraveNewsBubbleController() = default;

void BraveNewsBubbleController::ShowBubble(
base::WeakPtr<BraveNewsLocationView> anchor_view) {
base::WeakPtr<BraveNewsActionIconView> anchor_view) {
if (!anchor_view) {
return;
}
Expand Down
6 changes: 2 additions & 4 deletions browser/ui/views/brave_news/brave_news_bubble_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
#include "base/memory/weak_ptr.h"
#include "content/public/browser/web_contents_user_data.h"

class PlaylistActionIconView;

namespace content {
class WebContents;
}

class BraveNewsBubbleView;
class BraveNewsLocationView;
class BraveNewsActionIconView;

namespace brave_news {

Expand All @@ -29,7 +27,7 @@ class BraveNewsBubbleController

~BraveNewsBubbleController() override;

void ShowBubble(base::WeakPtr<BraveNewsLocationView> anchor_view);
void ShowBubble(base::WeakPtr<BraveNewsActionIconView> anchor_view);
BraveNewsBubbleView* GetBubble();
void OnBubbleClosed();
base::WeakPtr<BraveNewsBubbleController> AsWeakPtr();
Expand Down
30 changes: 16 additions & 14 deletions browser/ui/views/location_bar/brave_location_bar_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "brave/browser/ui/tabs/brave_tab_prefs.h"
#include "brave/browser/ui/tabs/features.h"
#include "brave/browser/ui/views/brave_actions/brave_actions_container.h"
#include "brave/browser/ui/views/brave_news/brave_news_location_view.h"
#include "brave/browser/ui/views/brave_news/brave_news_action_icon_view.h"
#include "brave/browser/ui/views/playlist/playlist_action_icon_view.h"
#include "brave/browser/ui/views/toolbar/brave_toolbar_view.h"
#include "brave/components/commander/common/buildflags/buildflags.h"
Expand Down Expand Up @@ -120,11 +120,11 @@ void BraveLocationBarView::Init() {
}

if (!browser_->profile()->IsOffTheRecord()) {
brave_news_location_view_ =
AddChildView(std::make_unique<BraveNewsLocationView>(
brave_news_action_icon_view_ =
AddChildView(std::make_unique<BraveNewsActionIconView>(
browser_->profile(), this, this));
brave_news_location_view_->SetVisible(false);
views::InkDrop::Get(brave_news_location_view_)
brave_news_action_icon_view_->SetVisible(false);
views::InkDrop::Get(brave_news_action_icon_view_)
->SetVisibleOpacity(GetPageActionInkDropVisibleOpacity());
}
#if BUILDFLAG(ENABLE_TOR)
Expand Down Expand Up @@ -199,8 +199,8 @@ void BraveLocationBarView::Update(content::WebContents* contents) {
}
#endif

if (brave_news_location_view_) {
brave_news_location_view_->Update();
if (brave_news_action_icon_view_) {
brave_news_action_icon_view_->Update();
}

LocationBarView::Update(contents);
Expand Down Expand Up @@ -263,8 +263,8 @@ void BraveLocationBarView::OnChanged() {
}
#endif

if (brave_news_location_view_) {
brave_news_location_view_->Update();
if (brave_news_action_icon_view_) {
brave_news_action_icon_view_->Update();
}

// OnChanged calls Layout
Expand All @@ -273,8 +273,8 @@ void BraveLocationBarView::OnChanged() {

std::vector<views::View*> BraveLocationBarView::GetTrailingViews() {
std::vector<views::View*> views;
if (brave_news_location_view_) {
views.push_back(brave_news_location_view_);
if (brave_news_action_icon_view_) {
views.push_back(brave_news_action_icon_view_);
}
#if BUILDFLAG(ENABLE_TOR)
if (onion_location_view_) {
Expand Down Expand Up @@ -314,9 +314,11 @@ gfx::Size BraveLocationBarView::CalculatePreferredSize(
brave_actions_min + GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING);
min_size.Enlarge(extra_width, 0);
}
if (brave_news_location_view_ && brave_news_location_view_->GetVisible()) {
const int extra_width = GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING) +
brave_news_location_view_->GetMinimumSize().width();
if (brave_news_action_icon_view_ &&
brave_news_action_icon_view_->GetVisible()) {
const int extra_width =
GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING) +
brave_news_action_icon_view_->GetMinimumSize().width();
min_size.Enlarge(extra_width, 0);
}
#if BUILDFLAG(ENABLE_TOR)
Expand Down
4 changes: 2 additions & 2 deletions browser/ui/views/location_bar/brave_location_bar_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <vector>

#include "base/gtest_prod_util.h"
#include "brave/browser/ui/views/brave_news/brave_news_location_view.h"
#include "brave/browser/ui/views/brave_news/brave_news_action_icon_view.h"
#include "brave/browser/ui/views/view_shadow.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
#include "brave/components/tor/buildflags/buildflags.h"
Expand Down Expand Up @@ -117,7 +117,7 @@ class BraveLocationBarView : public LocationBarView {

std::unique_ptr<ViewShadow> shadow_;
raw_ptr<BraveActionsContainer> brave_actions_ = nullptr;
raw_ptr<BraveNewsLocationView> brave_news_location_view_ = nullptr;
raw_ptr<BraveNewsActionIconView> brave_news_action_icon_view_ = nullptr;
#if BUILDFLAG(ENABLE_TOR)
raw_ptr<OnionLocationView> onion_location_view_ = nullptr;
#endif
Expand Down

0 comments on commit c47a0bb

Please sign in to comment.