Skip to content

Commit

Permalink
Handle split view location bar in SplitView
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhong committed Nov 26, 2024
1 parent 5a436e2 commit 9e0616c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
9 changes: 0 additions & 9 deletions browser/ui/views/frame/brave_browser_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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_);
}
Expand Down
4 changes: 0 additions & 4 deletions browser/ui/views/frame/brave_browser_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class ContentsLayoutManager;
class SidebarContainerView;
class SidePanelEntry;
class SplitView;
class SplitViewLocationBar;
class VerticalTabStripWidgetDelegateView;
class ViewShadow;
class WalletButton;
Expand Down Expand Up @@ -220,9 +219,6 @@ class BraveBrowserView : public BrowserView,

raw_ptr<SplitView> split_view_ = nullptr;

std::unique_ptr<SplitViewLocationBar> secondary_location_bar_;
std::unique_ptr<views::Widget> secondary_location_bar_widget_;

PrefChangeRegistrar pref_change_registrar_;
base::ScopedObservation<commands::AcceleratorService,
commands::AcceleratorService::Observer>
Expand Down
14 changes: 13 additions & 1 deletion browser/ui/views/split_view/split_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include "brave/browser/ui/views/split_view/split_view.h"

#include <memory>
#include <utility>

#include "brave/browser/ui/brave_browser.h"
Expand All @@ -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"
Expand Down Expand Up @@ -200,6 +200,16 @@ void SplitView::Layout(PassKey key) {
browser_view->NotifyDialogPositionRequiresUpdate();
}

void SplitView::AddedToWidget() {
secondary_location_bar_ = std::make_unique<SplitViewLocationBar>(
browser_->profile()->GetPrefs(), secondary_contents_container_);
secondary_location_bar_widget_ = std::make_unique<views::Widget>();

secondary_location_bar_widget_->Init(
SplitViewLocationBar::GetWidgetInitParams(GetWidget()->GetNativeView(),
secondary_location_bar_.get()));
}

void SplitView::OnTileTabs(const TabTile& tile) {
if (!IsActiveWebContentsTiled(tile)) {
return;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions browser/ui/views/split_view/split_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>
#include <vector>

#include "base/functional/callback_forward.h"
Expand All @@ -31,6 +32,7 @@ class Browser;
class ContentsWebView;
class DevToolsContentsResizingStrategy;
class SplitViewLayoutManager;
class SplitViewLocationBar;
class SplitViewSeparator;

// Contains a pair of contents container view.
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -123,6 +127,9 @@ class SplitView : public views::View, public SplitViewBrowserDataObserver {

raw_ptr<SplitViewSeparator> split_view_separator_ = nullptr;

std::unique_ptr<SplitViewLocationBar> secondary_location_bar_;
std::unique_ptr<views::Widget> secondary_location_bar_widget_;

base::ScopedObservation<SplitViewBrowserData, SplitViewBrowserDataObserver>
split_view_observation_{this};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -34,6 +35,7 @@ class SplitViewLocationBarBrowserTest : public InProcessBrowserTest {
SplitViewLocationBar& split_view_location_bar() {
return *static_cast<BraveBrowserView*>(
BrowserView::GetBrowserViewForBrowser(browser()))
->split_view()
->secondary_location_bar_;
}

Expand Down

0 comments on commit 9e0616c

Please sign in to comment.