Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 195 additions & 0 deletions patches/helium/ui/centered-address-bar.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
Index: src/chrome/app/settings_strings.grdp
===================================================================
--- src.orig/chrome/app/settings_strings.grdp
+++ src/chrome/app/settings_strings.grdp
@@ -211,6 +211,9 @@
<message name="IDS_SETTINGS_BEHAVIOR" desc="Name of the settings page which allows users to control browser behavior.">
Behavior
</message>
+ <message name="IDS_SETTINGS_USE_CENTERED_ADDRESS_BAR" desc="Label for the toggle to use a centered, narrower address bar.">
+ Use centered address bar
+ </message>
<message name="IDS_SETTINGS_CUSTOM_WEB_ADDRESS" desc="Sub label describing an empty custom web address for the Show home button setting.">
Custom
</message>
Index: src/chrome/browser/extensions/api/settings_private/prefs_util.cc
===================================================================
--- src.orig/chrome/browser/extensions/api/settings_private/prefs_util.cc
+++ src/chrome/browser/extensions/api/settings_private/prefs_util.cc
@@ -255,6 +255,9 @@ const PrefsUtil::TypedPrefMap& PrefsUtil
(*s_allowlist)[::prefs::kShowMenuButton] =
settings_api::PrefType::kBoolean;

+ (*s_allowlist)[::prefs::kLocationBarIsCentered] =
+ settings_api::PrefType::kBoolean;
+
// Appearance settings.
(*s_allowlist)[::prefs::kCurrentThemeID] = settings_api::PrefType::kString;
(*s_allowlist)[::prefs::kPinnedActions] = settings_api::PrefType::kList;
Index: src/chrome/browser/resources/settings/appearance_page/appearance_behavior_page.html
===================================================================
--- src.orig/chrome/browser/resources/settings/appearance_page/appearance_behavior_page.html
+++ src/chrome/browser/resources/settings/appearance_page/appearance_behavior_page.html
@@ -1,7 +1,12 @@
<style include="cr-shared-style settings-shared"></style>
<settings-section page-title="$i18n{behaviorPageTitle}">

- <settings-toggle-button id="newTabNextToActive"
+ <settings-toggle-button id="centeredAddressBar"
+ pref="{{prefs.helium.browser.use_centered_location_bar}}"
+ label="$i18n{useCenteredAddressBar}">
+ </settings-toggle-button>
+
+ <settings-toggle-button class="hr" id="newTabNextToActive"
pref="{{prefs.helium.browser.new_tab_next_to_active}}"
label="$i18n{openNewTabNextToActive}">
</settings-toggle-button>
Index: src/chrome/browser/ui/browser_ui_prefs.cc
===================================================================
--- src.orig/chrome/browser/ui/browser_ui_prefs.cc
+++ src/chrome/browser/ui/browser_ui_prefs.cc
@@ -137,6 +137,8 @@ void RegisterBrowserUserPrefs(user_prefs
registry->RegisterBooleanPref(prefs::kShowExtensionsButton, true);
registry->RegisterBooleanPref(prefs::kShowMenuButton, true);

+ registry->RegisterBooleanPref(prefs::kLocationBarIsCentered, false);
+
registry->RegisterInt64Pref(prefs::kDefaultBrowserLastDeclined, 0);
registry->RegisterBooleanPref(prefs::kWebAppCreateOnDesktop, true);
registry->RegisterBooleanPref(prefs::kWebAppCreateInAppsMenu, true);
Index: src/chrome/browser/ui/views/toolbar/toolbar_view.cc
===================================================================
--- src.orig/chrome/browser/ui/views/toolbar/toolbar_view.cc
+++ src/chrome/browser/ui/views/toolbar/toolbar_view.cc
@@ -563,6 +563,11 @@ void ToolbarView::Init() {
app_menu_button_->SetVisible(show_menu_button_.GetValue());
}

+ location_bar_is_centered_.Init(
+ prefs::kLocationBarIsCentered, prefs,
+ base::BindRepeating(&ToolbarView::OnLocationBarIsCenteredChanged,
+ base::Unretained(this)));
+
InitLayout();

for (auto* button : std::array<views::Button*, 5>{back_, forward_, reload_,
@@ -916,6 +921,7 @@ void ToolbarView::Layout(PassKey) {
// Call super implementation to ensure layout manager and child layouts
// happen.
LayoutSuperclass<AccessiblePaneView>(this);
+ MaybeNarrowLocationBar();
}

void ToolbarView::OnThemeChanged() {
@@ -1307,6 +1313,60 @@ void ToolbarView::OnShowMenuButtonChange
InvalidateLayout();
}

+void ToolbarView::OnLocationBarIsCenteredChanged() {
+ InvalidateLayout();
+}
+
+void ToolbarView::MaybeNarrowLocationBar() {
+ if (features::IsHeliumCatEnabled()) {
+ return;
+ }
+
+ if (!location_bar_is_centered_.GetValue()) {
+ return;
+ }
+
+ if (display_mode_ != DisplayMode::kNormal || !location_bar_ ||
+ !location_bar_->GetVisible()) {
+ return;
+ }
+
+ const int toolbar_width = container_view_->width();
+
+ double margin_pct = 0.0;
+ if (toolbar_width >= 1000) {
+ margin_pct = 0.12;
+ } else if (toolbar_width >= 850) {
+ margin_pct = 0.09;
+ } else if (toolbar_width >= 700) {
+ margin_pct = 0.05;
+ }
+
+ if (margin_pct == 0.0) {
+ return;
+ }
+
+ gfx::Rect bounds = location_bar_->bounds();
+ const int total_margin = static_cast<int>(toolbar_width * margin_pct);
+ constexpr int kMaxLocationBarWidth = 900;
+
+ int new_width = std::min(bounds.width() - total_margin, kMaxLocationBarWidth);
+ new_width = std::max(new_width, location_bar_->GetMinimumSize().width());
+
+ int desired_x = (toolbar_width - new_width) / 2;
+ int left_limit = bounds.x() + total_margin / 3;
+ int right_limit = bounds.x() + bounds.width() - new_width - total_margin / 2;
+ if (left_limit <= right_limit) {
+ desired_x = std::clamp(desired_x, left_limit, right_limit);
+ } else {
+ desired_x = bounds.x() + (bounds.width() - new_width) / 2;
+ }
+ bounds.set_x(desired_x);
+ bounds.set_width(new_width);
+
+ location_bar_->SetBoundsRect(bounds);
+}
+
void ToolbarView::OnTouchUiChanged() {
if (display_mode_ == DisplayMode::kNormal) {
// Update the internal margins for touch layout.
Index: src/chrome/browser/ui/views/toolbar/toolbar_view.h
===================================================================
--- src.orig/chrome/browser/ui/views/toolbar/toolbar_view.h
+++ src/chrome/browser/ui/views/toolbar/toolbar_view.h
@@ -290,6 +290,10 @@ class ToolbarView : public views::Access

void OnShowMenuButtonChanged();

+ void OnLocationBarIsCenteredChanged();
+
+ void MaybeNarrowLocationBar();
+
void OnTouchUiChanged();

void UpdateClipPath();
@@ -351,6 +355,8 @@ class ToolbarView : public views::Access

BooleanPrefMember show_menu_button_;

+ BooleanPrefMember location_bar_is_centered_;
+
BooleanPrefMember show_chrome_labs_button_;

// The display mode used when laying out the toolbar.
Index: src/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc
===================================================================
--- src.orig/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc
+++ src/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc
@@ -510,6 +510,7 @@ void AddAppearanceStrings(content::WebUI
{"appearancePageTitle", IDS_SETTINGS_APPEARANCE},
{"appearanceBehaviorPageTitle", IDS_SETTINGS_APPEARANCE_AND_BEHAVIOR},
{"behaviorPageTitle", IDS_SETTINGS_BEHAVIOR},
+ {"useCenteredAddressBar", IDS_SETTINGS_USE_CENTERED_ADDRESS_BAR},
{"customWebAddress", IDS_SETTINGS_CUSTOM_WEB_ADDRESS},
{"enterCustomWebAddress", IDS_SETTINGS_ENTER_CUSTOM_WEB_ADDRESS},
{"homeButtonDisabled", IDS_SETTINGS_HOME_BUTTON_DISABLED},
Index: src/chrome/common/pref_names.h
===================================================================
--- src.orig/chrome/common/pref_names.h
+++ src/chrome/common/pref_names.h
@@ -1371,6 +1371,10 @@ inline constexpr char kShowExtensionsBut
// toolbar.
inline constexpr char kShowMenuButton[] = "helium.browser.show_menu_button";

+// A boolean pref set to true if the address bar should be centered and narrowed.
+// When false (default), the address bar uses its full width.
+inline constexpr char kLocationBarIsCentered[] = "helium.browser.use_centered_location_bar";
+
// A boolean pref set to true if Gemini integration be enabled. This is managed
// by enterprise policy.
inline constexpr char kGeminiSettings[] = "browser.gemini_settings";
10 changes: 5 additions & 5 deletions patches/helium/ui/experiments/compact-action-toolbar.patch
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
show_avatar_button_.Init(
prefs::kShowAvatarButton, prefs,
base::BindRepeating(&ToolbarView::OnShowAvatarButtonChanged,
@@ -565,12 +588,30 @@ void ToolbarView::Init() {
@@ -570,12 +593,30 @@ void ToolbarView::Init() {

InitLayout();

Expand Down Expand Up @@ -197,7 +197,7 @@
if (browser_view_->GetSupportsTabStrip()) {
browser()->GetTabStripModel()->AddObserver(this);
}
@@ -695,6 +736,24 @@ bool ToolbarView::IsRectInWindowCaption(
@@ -700,6 +741,24 @@ bool ToolbarView::IsRectInWindowCaption(
return gfx::ToEnclosingRect(rect_in_target_coords_f);
};

Expand All @@ -222,7 +222,7 @@
// Check each child view in container_view_ to see if the rect intersects with
// any clickable elements. If it does, check if the click is actually on that
// element. False if on a clickable element, true if not on a clickable element.
@@ -974,8 +1033,12 @@ void ToolbarView::InitLayout() {
@@ -980,8 +1039,12 @@ void ToolbarView::InitLayout() {
constexpr int kToolbarActionsFlexOrder = kOrderOffset + 2;
constexpr int kExtensionsFlexOrder = kOrderOffset + 3;

Expand All @@ -236,7 +236,7 @@
views::MaximumFlexSizeRule::kUnbounded)
.WithOrder(kLocationBarFlexOrder);

@@ -991,6 +1054,12 @@ void ToolbarView::InitLayout() {
@@ -997,6 +1060,12 @@ void ToolbarView::InitLayout() {
location_bar_->SetProperty(views::kMarginsKey,
gfx::Insets::VH(0, location_bar_margin));

Expand All @@ -261,7 +261,7 @@
// Accessors.
Browser* browser() const { return browser_; }
views::Button* GetChromeLabsButton() const;
@@ -326,6 +329,7 @@ class ToolbarView : public views::Access
@@ -330,6 +333,7 @@ class ToolbarView : public views::Access
raw_ptr<BrowserAppMenuButton> app_menu_button_ = nullptr;
raw_ptr<views::View> new_tab_button_ = nullptr;
raw_ptr<PinnedActionToolbarButton> tab_search_button_ = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion patches/helium/ui/find-bar.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- a/chrome/browser/ui/views/toolbar/toolbar_view.cc
+++ b/chrome/browser/ui/views/toolbar/toolbar_view.cc
@@ -1155,6 +1155,8 @@ AppMenuButton* ToolbarView::GetAppMenuBu
@@ -1161,6 +1161,8 @@ AppMenuButton* ToolbarView::GetAppMenuBu
}

gfx::Rect ToolbarView::GetFindBarBoundingBox(int contents_bottom) {
Expand Down
1 change: 1 addition & 0 deletions patches/series
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ helium/ui/tab-strip-controls.patch
helium/ui/toolbar.patch
helium/ui/toolbar-window-frame-hit-test.patch
helium/ui/toolbar-button-prefs.patch
helium/ui/centered-address-bar.patch
helium/ui/omnibox.patch
helium/ui/app-menu-style.patch
helium/ui/app-menu-model.patch
Expand Down