From c47a0bba0a3cc5ba5b7bad63d33c8e11d0b7669b Mon Sep 17 00:00:00 2001 From: Jagadesh P Date: Wed, 19 Jun 2024 04:32:32 +0530 Subject: [PATCH] [BraveNews] Rename brave_news_location_view.cc[h] -> brave_news_action_icon_view.cc[h] --- browser/ui/BUILD.gn | 4 +- ...view.cc => brave_news_action_icon_view.cc} | 44 +++++++++---------- ...n_view.h => brave_news_action_icon_view.h} | 31 +++++++------ .../brave_news_bubble_controller.cc | 4 +- .../brave_news/brave_news_bubble_controller.h | 6 +-- .../location_bar/brave_location_bar_view.cc | 30 +++++++------ .../location_bar/brave_location_bar_view.h | 4 +- 7 files changed, 61 insertions(+), 62 deletions(-) rename browser/ui/views/brave_news/{brave_news_location_view.cc => brave_news_action_icon_view.cc} (78%) rename browser/ui/views/brave_news/{brave_news_location_view.h => brave_news_action_icon_view.h} (67%) diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn index 25476512970a..3899da45e0a4 100644 --- a/browser/ui/BUILD.gn +++ b/browser/ui/BUILD.gn @@ -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", diff --git a/browser/ui/views/brave_news/brave_news_location_view.cc b/browser/ui/views/brave_news/brave_news_action_icon_view.cc similarity index 78% rename from browser/ui/views/brave_news/brave_news_location_view.cc rename to browser/ui/views/brave_news/brave_news_action_icon_view.cc index c7e1a865fe5b..8c9a24f87e13 100644 --- a/browser/ui/views/brave_news/brave_news_location_view.cc +++ b/browser/ui/views/brave_news/brave_news_action_icon_view.cc @@ -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 #include @@ -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) @@ -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; @@ -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& feeds) { Update(); } -void BraveNewsLocationView::OnThemeChanged() { +void BraveNewsActionIconView::OnThemeChanged() { bool subscribed = false; if (auto* contents = GetWebContents()) { subscribed = BraveNewsTabHelper::FromWebContents(contents)->IsSubscribed(); @@ -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() == @@ -160,7 +160,7 @@ 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:: @@ -168,20 +168,20 @@ brave_news::BraveNewsBubbleController* BraveNewsLocationView::GetController() : 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::AsWeakPtr() { +base::WeakPtr BraveNewsActionIconView::AsWeakPtr() { return weak_ptr_factory_.GetWeakPtr(); } -BEGIN_METADATA(BraveNewsLocationView) +BEGIN_METADATA(BraveNewsActionIconView) END_METADATA diff --git a/browser/ui/views/brave_news/brave_news_location_view.h b/browser/ui/views/brave_news/brave_news_action_icon_view.h similarity index 67% rename from browser/ui/views/brave_news/brave_news_location_view.h rename to browser/ui/views/brave_news/brave_news_action_icon_view.h index 227f7e41e02b..32303f125b3d 100644 --- a/browser/ui/views/brave_news/brave_news_location_view.h +++ b/browser/ui/views/brave_news/brave_news_action_icon_view.h @@ -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 #include @@ -18,7 +18,6 @@ #include "ui/views/view.h" class Profile; -class BraveNewsBubbleView; namespace brave_news { class BraveNewsBubbleController; @@ -26,20 +25,20 @@ 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 AsWeakPtr(); + base::WeakPtr AsWeakPtr(); // PageActionIconView: views::BubbleDialogDelegate* GetBubble() const override; @@ -74,7 +73,7 @@ class BraveNewsLocationView : public PageActionIconView, BooleanPrefMember opted_in_; BooleanPrefMember news_enabled_; - base::WeakPtrFactory weak_ptr_factory_{this}; + base::WeakPtrFactory 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_ diff --git a/browser/ui/views/brave_news/brave_news_bubble_controller.cc b/browser/ui/views/brave_news/brave_news_bubble_controller.cc index 1410a07bd8fa..75abe2700c83 100644 --- a/browser/ui/views/brave_news/brave_news_bubble_controller.cc +++ b/browser/ui/views/brave_news/brave_news_bubble_controller.cc @@ -8,8 +8,8 @@ #include #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 { @@ -25,7 +25,7 @@ BraveNewsBubbleController::CreateOrGetFromWebContents( BraveNewsBubbleController::~BraveNewsBubbleController() = default; void BraveNewsBubbleController::ShowBubble( - base::WeakPtr anchor_view) { + base::WeakPtr anchor_view) { if (!anchor_view) { return; } diff --git a/browser/ui/views/brave_news/brave_news_bubble_controller.h b/browser/ui/views/brave_news/brave_news_bubble_controller.h index 5952f2561495..0bb6c9301066 100644 --- a/browser/ui/views/brave_news/brave_news_bubble_controller.h +++ b/browser/ui/views/brave_news/brave_news_bubble_controller.h @@ -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 { @@ -29,7 +27,7 @@ class BraveNewsBubbleController ~BraveNewsBubbleController() override; - void ShowBubble(base::WeakPtr anchor_view); + void ShowBubble(base::WeakPtr anchor_view); BraveNewsBubbleView* GetBubble(); void OnBubbleClosed(); base::WeakPtr AsWeakPtr(); diff --git a/browser/ui/views/location_bar/brave_location_bar_view.cc b/browser/ui/views/location_bar/brave_location_bar_view.cc index 607d0306b85e..aebba9fb603b 100644 --- a/browser/ui/views/location_bar/brave_location_bar_view.cc +++ b/browser/ui/views/location_bar/brave_location_bar_view.cc @@ -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" @@ -120,11 +120,11 @@ void BraveLocationBarView::Init() { } if (!browser_->profile()->IsOffTheRecord()) { - brave_news_location_view_ = - AddChildView(std::make_unique( + brave_news_action_icon_view_ = + AddChildView(std::make_unique( 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) @@ -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); @@ -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 @@ -273,8 +273,8 @@ void BraveLocationBarView::OnChanged() { std::vector BraveLocationBarView::GetTrailingViews() { std::vector 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_) { @@ -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) diff --git a/browser/ui/views/location_bar/brave_location_bar_view.h b/browser/ui/views/location_bar/brave_location_bar_view.h index 4e7f37d2c286..b71069dae513 100644 --- a/browser/ui/views/location_bar/brave_location_bar_view.h +++ b/browser/ui/views/location_bar/brave_location_bar_view.h @@ -10,7 +10,7 @@ #include #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" @@ -117,7 +117,7 @@ class BraveLocationBarView : public LocationBarView { std::unique_ptr shadow_; raw_ptr brave_actions_ = nullptr; - raw_ptr brave_news_location_view_ = nullptr; + raw_ptr brave_news_action_icon_view_ = nullptr; #if BUILDFLAG(ENABLE_TOR) raw_ptr onion_location_view_ = nullptr; #endif