From 9e0616c4280fec19d3b1f0335245aee676e57e59 Mon Sep 17 00:00:00 2001 From: Simon Hong Date: Mon, 25 Nov 2024 22:55:40 +0900 Subject: [PATCH] Handle split view location bar in SplitView --- browser/ui/views/frame/brave_browser_view.cc | 9 --------- browser/ui/views/frame/brave_browser_view.h | 4 ---- browser/ui/views/split_view/split_view.cc | 14 +++++++++++++- browser/ui/views/split_view/split_view.h | 7 +++++++ .../split_view_location_bar_browsertest.cc | 2 ++ 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/browser/ui/views/frame/brave_browser_view.cc b/browser/ui/views/frame/brave_browser_view.cc index 3a464490b01d..a3b86ca18066 100644 --- a/browser/ui/views/frame/brave_browser_view.cc +++ b/browser/ui/views/frame/brave_browser_view.cc @@ -44,8 +44,6 @@ #include "brave/browser/ui/views/sidebar/sidebar_container_view.h" #include "brave/browser/ui/views/speedreader/reader_mode_toolbar_view.h" #include "brave/browser/ui/views/split_view/split_view.h" -#include "brave/browser/ui/views/split_view/split_view_location_bar.h" -#include "brave/browser/ui/views/split_view/split_view_separator.h" #include "brave/browser/ui/views/tabs/vertical_tab_utils.h" #include "brave/browser/ui/views/toolbar/bookmark_button.h" #include "brave/browser/ui/views/toolbar/brave_toolbar_view.h" @@ -652,13 +650,6 @@ void BraveBrowserView::AddedToWidget() { vertical_tab_strip_host_view_.get()); } - if (secondary_location_bar_widget_) { - CHECK(secondary_location_bar_); - secondary_location_bar_widget_->Init( - SplitViewLocationBar::GetWidgetInitParams( - GetWidget()->GetNativeView(), secondary_location_bar_.get())); - } - if (split_view_) { GetBrowserViewLayout()->set_contents_container(split_view_); } diff --git a/browser/ui/views/frame/brave_browser_view.h b/browser/ui/views/frame/brave_browser_view.h index 969c5de4dcfa..ce8deb440e30 100644 --- a/browser/ui/views/frame/brave_browser_view.h +++ b/browser/ui/views/frame/brave_browser_view.h @@ -59,7 +59,6 @@ class ContentsLayoutManager; class SidebarContainerView; class SidePanelEntry; class SplitView; -class SplitViewLocationBar; class VerticalTabStripWidgetDelegateView; class ViewShadow; class WalletButton; @@ -220,9 +219,6 @@ class BraveBrowserView : public BrowserView, raw_ptr split_view_ = nullptr; - std::unique_ptr secondary_location_bar_; - std::unique_ptr secondary_location_bar_widget_; - PrefChangeRegistrar pref_change_registrar_; base::ScopedObservation diff --git a/browser/ui/views/split_view/split_view.cc b/browser/ui/views/split_view/split_view.cc index 080a7ef23548..7a5c3dc7bea5 100644 --- a/browser/ui/views/split_view/split_view.cc +++ b/browser/ui/views/split_view/split_view.cc @@ -5,7 +5,6 @@ #include "brave/browser/ui/views/split_view/split_view.h" -#include #include #include "brave/browser/ui/brave_browser.h" @@ -14,6 +13,7 @@ #include "brave/browser/ui/views/frame/brave_browser_view.h" #include "brave/browser/ui/views/frame/brave_contents_view_util.h" #include "brave/browser/ui/views/split_view/split_view_layout_manager.h" +#include "brave/browser/ui/views/split_view/split_view_location_bar.h" #include "brave/browser/ui/views/split_view/split_view_separator.h" #include "brave/ui/color/nala/nala_color_id.h" #include "chrome/browser/devtools/devtools_window.h" @@ -200,6 +200,16 @@ void SplitView::Layout(PassKey key) { browser_view->NotifyDialogPositionRequiresUpdate(); } +void SplitView::AddedToWidget() { + secondary_location_bar_ = std::make_unique( + browser_->profile()->GetPrefs(), secondary_contents_container_); + secondary_location_bar_widget_ = std::make_unique(); + + secondary_location_bar_widget_->Init( + SplitViewLocationBar::GetWidgetInitParams(GetWidget()->GetNativeView(), + secondary_location_bar_.get())); +} + void SplitView::OnTileTabs(const TabTile& tile) { if (!IsActiveWebContentsTiled(tile)) { return; @@ -369,6 +379,7 @@ void SplitView::UpdateSecondaryContentsWebViewVisibility() { if (secondary_contents_web_view_->web_contents() != contents) { secondary_contents_web_view_->SetWebContents(nullptr); secondary_contents_web_view_->SetWebContents(contents); + secondary_location_bar_->SetWebContents(contents); } secondary_contents_container_->SetVisible(true); @@ -377,6 +388,7 @@ void SplitView::UpdateSecondaryContentsWebViewVisibility() { GetSplitViewLayoutManager()->show_main_web_contents_at_tail( second_tile_is_active_web_contents); } else { + secondary_location_bar_->SetWebContents(nullptr); secondary_contents_web_view_->SetWebContents(nullptr); secondary_devtools_web_view_->SetWebContents(nullptr); secondary_contents_container_->SetVisible(false); diff --git a/browser/ui/views/split_view/split_view.h b/browser/ui/views/split_view/split_view.h index 50bf0fec9b87..185264be5829 100644 --- a/browser/ui/views/split_view/split_view.h +++ b/browser/ui/views/split_view/split_view.h @@ -6,6 +6,7 @@ #ifndef BRAVE_BROWSER_UI_VIEWS_SPLIT_VIEW_SPLIT_VIEW_H_ #define BRAVE_BROWSER_UI_VIEWS_SPLIT_VIEW_SPLIT_VIEW_H_ +#include #include #include "base/functional/callback_forward.h" @@ -31,6 +32,7 @@ class Browser; class ContentsWebView; class DevToolsContentsResizingStrategy; class SplitViewLayoutManager; +class SplitViewLocationBar; class SplitViewSeparator; // Contains a pair of contents container view. @@ -88,6 +90,7 @@ class SplitView : public views::View, public SplitViewBrowserDataObserver { // views::View: void OnThemeChanged() override; void Layout(PassKey) override; + void AddedToWidget() override; // SplitViewBrowserDataObserver: void OnTileTabs(const TabTile& tile) override; @@ -96,6 +99,7 @@ class SplitView : public views::View, public SplitViewBrowserDataObserver { private: friend class SplitViewBrowserTest; + friend class SplitViewLocationBarBrowserTest; void DidSwapActiveWebContents(bool need_to_reset_fast_resize, content::WebContents* old_contents, @@ -123,6 +127,9 @@ class SplitView : public views::View, public SplitViewBrowserDataObserver { raw_ptr split_view_separator_ = nullptr; + std::unique_ptr secondary_location_bar_; + std::unique_ptr secondary_location_bar_widget_; + base::ScopedObservation split_view_observation_{this}; diff --git a/browser/ui/views/split_view/split_view_location_bar_browsertest.cc b/browser/ui/views/split_view/split_view_location_bar_browsertest.cc index 012ebb016ab8..b6551850dd34 100644 --- a/browser/ui/views/split_view/split_view_location_bar_browsertest.cc +++ b/browser/ui/views/split_view/split_view_location_bar_browsertest.cc @@ -16,6 +16,7 @@ #include "brave/browser/ui/tabs/features.h" #include "brave/browser/ui/tabs/split_view_browser_data.h" #include "brave/browser/ui/views/frame/brave_browser_view.h" +#include "brave/browser/ui/views/split_view/split_view.h" #include "chrome/browser/ui/browser_tabstrip.h" #include "chrome/test/base/chrome_test_utils.h" #include "chrome/test/base/in_process_browser_test.h" @@ -34,6 +35,7 @@ class SplitViewLocationBarBrowserTest : public InProcessBrowserTest { SplitViewLocationBar& split_view_location_bar() { return *static_cast( BrowserView::GetBrowserViewForBrowser(browser())) + ->split_view() ->secondary_location_bar_; }