Skip to content

Commit

Permalink
Hide page action icons when editing the Omnibox (#16243)
Browse files Browse the repository at this point in the history
  • Loading branch information
fallaciousreasoning committed Dec 7, 2022
1 parent 16e4b27 commit a0da9e3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
22 changes: 14 additions & 8 deletions browser/ui/views/location_bar/brave_location_bar_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,15 @@ void BraveLocationBarView::Update(content::WebContents* contents) {
if (brave_actions_) {
brave_actions_->Update();
}

auto show_page_actions = !ShouldHidePageActionIcons();
#if BUILDFLAG(ENABLE_TOR)
if (onion_location_view_)
onion_location_view_->Update(contents);
onion_location_view_->Update(contents, show_page_actions);
#endif
#if BUILDFLAG(ENABLE_IPFS)
if (ipfs_location_view_)
ipfs_location_view_->Update(contents);
ipfs_location_view_->Update(contents, show_page_actions);
#endif

LocationBarView::Update(contents);
Expand Down Expand Up @@ -172,23 +174,27 @@ ui::ImageModel BraveLocationBarView::GetLocationIcon(
}

void BraveLocationBarView::OnChanged() {
auto hide_page_actions = ShouldHidePageActionIcons();
if (brave_actions_) {
// Do not show actions whilst omnibar is open or url is being edited
const bool should_hide =
ShouldHidePageActionIcons() && !omnibox_view_->GetText().empty();
brave_actions_->SetShouldHide(should_hide);
brave_actions_->SetShouldHide(hide_page_actions);
}
#if BUILDFLAG(ENABLE_TOR)
if (onion_location_view_)
onion_location_view_->Update(
browser_->tab_strip_model()->GetActiveWebContents());
browser_->tab_strip_model()->GetActiveWebContents(),
!hide_page_actions);
#endif
#if BUILDFLAG(ENABLE_IPFS)
if (ipfs_location_view_)
ipfs_location_view_->Update(
browser_->tab_strip_model()->GetActiveWebContents());
browser_->tab_strip_model()->GetActiveWebContents(),
!hide_page_actions);
#endif

if (brave_news_location_view_) {
brave_news_location_view_->SetVisible(!hide_page_actions);
}

// OnChanged calls Layout
LocationBarView::OnChanged();
}
Expand Down
5 changes: 3 additions & 2 deletions browser/ui/views/location_bar/ipfs_location_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,16 @@ IPFSLocationView::IPFSLocationView(Profile* profile) {

IPFSLocationView::~IPFSLocationView() = default;

void IPFSLocationView::Update(content::WebContents* web_contents) {
void IPFSLocationView::Update(content::WebContents* web_contents,
bool show_page_actions) {
if (!web_contents)
return;
ipfs::IPFSTabHelper* helper =
ipfs::IPFSTabHelper::FromWebContents(web_contents);
if (!helper)
return;
auto ipfs_resolved_url = helper->GetIPFSResolvedURL();
SetVisible(ipfs_resolved_url.is_valid());
SetVisible(ipfs_resolved_url.is_valid() && show_page_actions);
reinterpret_cast<IPFSLocationButtonView*>(button_)->SetIPFSLocation(
ipfs_resolved_url);
}
2 changes: 1 addition & 1 deletion browser/ui/views/location_bar/ipfs_location_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class IPFSLocationView : public views::View {
explicit IPFSLocationView(Profile* profile);
~IPFSLocationView() override;

void Update(content::WebContents* web_contents);
void Update(content::WebContents* web_contents, bool show_page_actions);

views::LabelButton* GetButton() { return button_; }

Expand Down
5 changes: 3 additions & 2 deletions browser/ui/views/location_bar/onion_location_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,15 @@ OnionLocationView::OnionLocationView(Profile* profile) {

OnionLocationView::~OnionLocationView() = default;

void OnionLocationView::Update(content::WebContents* web_contents) {
void OnionLocationView::Update(content::WebContents* web_contents,
bool show_page_actions) {
if (!web_contents)
return;
tor::OnionLocationTabHelper* helper =
tor::OnionLocationTabHelper::FromWebContents(web_contents);
if (!helper)
return;
SetVisible(helper->should_show_icon());
SetVisible(helper->should_show_icon() && show_page_actions);
reinterpret_cast<OnionLocationButtonView*>(button_)->SetOnionLocation(
helper->onion_location());
}
2 changes: 1 addition & 1 deletion browser/ui/views/location_bar/onion_location_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class OnionLocationView : public views::View {
explicit OnionLocationView(Profile* profile);
~OnionLocationView() override;

void Update(content::WebContents* web_contents);
void Update(content::WebContents* web_contents, bool show_page_actions);

views::LabelButton* GetButton() { return button_; }

Expand Down

0 comments on commit a0da9e3

Please sign in to comment.