[cr146] LocationBarView::Update already virtualised

This method is now an abstract method from `LocationBar`, which makes
the virtual patching unnecessary.

Another aspect in this CL is that `ToolbarView::location_bar_` got
renamed to `location_bar_view_`, and a different `location_bar_` member
was introduced in its place. This change corrects all references to the
new name.

Chromium changes:
https://chromium.googlesource.com/chromium/src/+/da5f63b7460799641c75c85ad8cc792118a22a02

commit da5f63b7460799641c75c85ad8cc792118a22a02
Author: Maks Orlovich <morlovich@chromium.org>
Date:   Thu Jan 15 06:10:29 2026 -0800

    Shift some LocationBarView dependencies to LocationBar...

    ... to permit a different implementation of LocationBar based on WebUI.
    As part of prep work this also tries to split up uses in ToolbarView
    between those that are likely views impl specific and those that are
    likely cross-impl. Some of those guesses may turn out wrong; but this
    should bring us closer to being able to start an implementation that can
    then make the definite judgement.

    Heavily based on Paul Jensen's
    https://chromium-review.googlesource.com/c/chromium/src/+/7445719

    Bug: 474582476
    Change-Id: Ia36162c004954c27f1fbe75e4eb6dcdd439eebbb
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7452590
    Reviewed-by: Tom Lukaszewicz <tluk@chromium.org>
    Commit-Queue: Maks Orlovich <morlovich@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#1569691}
This commit is contained in:
Claudio DeSouza
2026-02-26 13:47:44 +00:00
parent 30df438407
commit 34bb26e4e1
3 changed files with 27 additions and 46 deletions
+16 -15
View File
@@ -163,10 +163,10 @@ void BraveToolbarView::Init() {
// See brave_non_client_hit_test_helper.h
views::SetHitTestComponent(this, HTCAPTION);
DCHECK(location_bar_);
// Get ToolbarView's container_view as a parent of location_bar_ because
DCHECK(location_bar_view_);
// Get ToolbarView's container_view as a parent of location_bar_view_ because
// container_view's type in ToolbarView is internal to toolbar_view.cc.
views::View* container_view = location_bar_->parent();
views::View* container_view = location_bar_view_->parent();
DCHECK(container_view);
views::SetHitTestComponent(container_view, HTCAPTION);
@@ -258,7 +258,7 @@ void BraveToolbarView::Init() {
bookmark_ = container_view->AddChildViewAt(
std::make_unique<BraveBookmarkButton>(
base::BindRepeating(callback, browser_, IDC_BOOKMARK_THIS_TAB)),
*container_view->GetIndexOf(location_bar_));
*container_view->GetIndexOf(location_bar_view_));
bookmark_->SetTriggerableEventFlags(ui::EF_LEFT_MOUSE_BUTTON |
ui::EF_MIDDLE_MOUSE_BUTTON);
bookmark_->UpdateImageAndText();
@@ -440,10 +440,10 @@ void BraveToolbarView::UpdateHorizontalPadding() {
return;
}
// Get ToolbarView's container_view as a parent of location_bar_ because
// Get ToolbarView's container_view as a parent of location_bar_view_ because
// container_view's type in ToolbarView is internal to toolbar_view.cc.
DCHECK(location_bar_ && location_bar_->parent());
views::View* container_view = location_bar_->parent();
DCHECK(location_bar_view_ && location_bar_view_->parent());
views::View* container_view = location_bar_view_->parent();
if (!tabs::utils::ShouldShowBraveVerticalTabs(browser()) ||
tabs::utils::ShouldShowWindowTitleForVerticalTabs(browser())) {
@@ -462,7 +462,7 @@ void BraveToolbarView::ShowBookmarkBubble(const GURL& url,
// Show BookmarkBubble attached to Brave's bookmark button
// or the location bar if there is no bookmark button
// (i.e. in non-normal display mode).
views::View* anchor_view = location_bar_;
views::View* anchor_view = location_bar_view_;
if (bookmark_ && bookmark_->GetVisible()) {
anchor_view = bookmark_;
}
@@ -504,7 +504,7 @@ void BraveToolbarView::Layout(PassKey) {
// if wide address bar option is off.
// TODO(https://github.com/brave/brave-browser/issues/48810): Refactor to do
// layout once.
LayoutGuard guard(static_cast<BraveLocationBarView*>(location_bar_));
LayoutGuard guard(static_cast<BraveLocationBarView*>(location_bar_view_));
if (!location_bar_is_wide_.GetValue()) {
guard.set_ignore_layout(true);
}
@@ -523,12 +523,13 @@ void BraveToolbarView::ResetLocationBarBounds() {
// Calculate proper location bar's margin and set its bounds.
const gfx::Insets margin = CalcLocationBarMargin(
width(), location_bar_->width(), location_bar_->GetMinimumSize().width(),
location_bar_->x());
width(), location_bar_view_->width(),
location_bar_view_->GetMinimumSize().width(), location_bar_view_->x());
location_bar_->SetBounds(
location_bar_->x() + margin.left(), location_bar_->y(),
location_bar_->width() - margin.width(), location_bar_->height());
location_bar_view_->SetBounds(location_bar_view_->x() + margin.left(),
location_bar_view_->y(),
location_bar_view_->width() - margin.width(),
location_bar_view_->height());
}
void BraveToolbarView::ResetBookmarkButtonBounds() {
@@ -540,7 +541,7 @@ void BraveToolbarView::ResetBookmarkButtonBounds() {
if (bookmark_ && bookmark_->GetVisible()) {
const int bookmark_width = bookmark_->GetPreferredSize().width();
const int bookmark_x =
location_bar_->x() - bookmark_width - button_right_margin;
location_bar_view_->x() - bookmark_width - button_right_margin;
bookmark_->SetX(bookmark_x);
}
}
@@ -6,15 +6,22 @@
#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_LOCATION_BAR_VIEW_H_
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_LOCATION_BAR_VIEW_H_
#define BRAVE_LOCATION_BAR_VIEW_H_ \
#include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
#include "third_party/metrics_proto/omnibox_event.pb.h"
#define GetBackgroundColorForTesting \
Unused(); \
\
private: \
friend class BraveLocationBarView; \
\
public: \
virtual views::View* GetSearchPromotionButton() const; \
virtual std::vector<views::View*> GetRightMostTrailingViews(); \
virtual std::vector<views::View*> GetLeftMostTrailingViews();
virtual std::vector<views::View*> GetLeftMostTrailingViews(); \
SkColor GetBackgroundColorForTesting
#define Init virtual Init
#define OnOmniboxBlurred virtual OnOmniboxBlurred
#define GetBorderRadius virtual GetBorderRadius
#define RefreshBackground virtual RefreshBackground
@@ -22,6 +29,7 @@
#undef RefreshBackground
#undef GetBorderRadius
#undef OnOmniboxBlurred
#undef BRAVE_LOCATION_BAR_VIEW_H_
#undef Init
#undef GetBackgroundColorForTesting
#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_LOCATION_BAR_VIEW_H_
@@ -1,28 +0,0 @@
diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.h b/chrome/browser/ui/views/location_bar/location_bar_view.h
index 7b11704e9f09fcf6500feabe000754a056762c5f..778680a9a805311be70fd07561b71cc1bd8000b8 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.h
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.h
@@ -138,6 +138,7 @@ class LocationBarView
int GetBorderRadius() const;
// Initializes the LocationBarView.
+ virtual
void Init();
bool in_popup_state_transition() const { return in_popup_state_transition_; }
@@ -201,6 +202,7 @@ class LocationBarView
// Updates the controller, and, if |contents| is non-null, restores saved
// state that the tab holds.
+ virtual
void Update(content::WebContents* contents);
// Clears the location bar's state for |contents|.
@@ -299,6 +301,7 @@ class LocationBarView
GetContentSettingViewsForTest() {
return content_setting_views_;
}
+ BRAVE_LOCATION_BAR_VIEW_H_
SkColor GetBackgroundColorForTesting() const { return background_color_; }