From 3362db0655ec743c0b7b9b24e68837411714540d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 5 May 2025 09:28:49 -0500 Subject: [PATCH] refactor: remove some `NativeWindow` public API (#46919) * refactor: make NativeWindow::titlebar_overlay_height_ private * refactor: make NativeWindow::set_has_frame() protected * refactor: remove NativeWindow::background_material() It's only used once, in NativeWindow, so use |background_material_| directly. * refactor: remove NativeWindow::vibrancy() It's only used once, in a NativeWindow method, so use |vibrancy_| directly. * refactor: unfriend api::BrowserView It was added in Oct 2022 by 23d4a25 for access to protected NativeWindow methods add_inspectable_view() and remove_inspectable_view(). That dependency was removed in Nov 2022 by 184ac2b, so BrowserView doesn't need access to NativeWindow's private fields & methods anymore. * refactor: make NativeWindow::ContentBoundsToWindowBounds() protected refactor: make NativeWindow::WindowBoundsToContentBounds() protected --- shell/browser/native_window.cc | 7 ++----- shell/browser/native_window.h | 27 +++++++++++---------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/shell/browser/native_window.cc b/shell/browser/native_window.cc index 03b383ac5ff6..829a93a1a6c9 100644 --- a/shell/browser/native_window.cc +++ b/shell/browser/native_window.cc @@ -830,17 +830,14 @@ bool NativeWindow::IsTranslucent() const { #if BUILDFLAG(IS_MAC) // Windows with vibrancy set are translucent - if (!vibrancy().empty()) { + if (!vibrancy_.empty()) return true; - } #endif #if BUILDFLAG(IS_WIN) // Windows with certain background materials may be translucent - const std::string& bg_material = background_material(); - if (!bg_material.empty() && bg_material != "none") { + if (!background_material_.empty() && background_material_ != "none") return true; - } #endif return false; diff --git a/shell/browser/native_window.h b/shell/browser/native_window.h index b0826a50d3e6..a85b9bed2717 100644 --- a/shell/browser/native_window.h +++ b/shell/browser/native_window.h @@ -223,12 +223,8 @@ class NativeWindow : public base::SupportsUserData, virtual void SetAutoHideCursor(bool auto_hide) {} // Vibrancy API - const std::string& vibrancy() const { return vibrancy_; } virtual void SetVibrancy(const std::string& type, int duration); - const std::string& background_material() const { - return background_material_; - } virtual void SetBackgroundMaterial(const std::string& type); // Traffic Light API @@ -284,12 +280,6 @@ class NativeWindow : public base::SupportsUserData, virtual void SetGTKDarkThemeEnabled(bool use_dark_theme) {} - // Converts between content bounds and window bounds. - virtual gfx::Rect ContentBoundsToWindowBounds( - const gfx::Rect& bounds) const = 0; - virtual gfx::Rect WindowBoundsToContentBounds( - const gfx::Rect& bounds) const = 0; - base::WeakPtr GetWeakPtr() { return weak_factory_.GetWeakPtr(); } @@ -400,7 +390,6 @@ class NativeWindow : public base::SupportsUserData, } bool has_frame() const { return has_frame_; } - void set_has_frame(bool has_frame) { has_frame_ = has_frame; } bool has_client_frame() const { return has_client_frame_; } bool transparent() const { return transparent_; } @@ -433,7 +422,7 @@ class NativeWindow : public base::SupportsUserData, void UpdateBackgroundThrottlingState(); protected: - friend class api::BrowserView; + constexpr void set_has_frame(const bool val) { has_frame_ = val; } [[nodiscard]] constexpr bool is_closed() const { return is_closed_; } @@ -441,6 +430,12 @@ class NativeWindow : public base::SupportsUserData, virtual void OnTitleChanged() {} + // Converts between content bounds and window bounds. + virtual gfx::Rect ContentBoundsToWindowBounds( + const gfx::Rect& bounds) const = 0; + virtual gfx::Rect WindowBoundsToContentBounds( + const gfx::Rect& bounds) const = 0; + // views::WidgetDelegate: views::Widget* GetWidget() override; const views::Widget* GetWidget() const override; @@ -457,10 +452,6 @@ class NativeWindow : public base::SupportsUserData, // The boolean parsing of the "titleBarOverlay" option bool titlebar_overlay_ = false; - // The custom height parsed from the "height" option in a Object - // "titleBarOverlay" - int titlebar_overlay_height_ = 0; - // The "titleBarStyle" option. TitleBarStyle title_bar_style_ = TitleBarStyle::kNormal; @@ -486,6 +477,10 @@ class NativeWindow : public base::SupportsUserData, // The content view, weak ref. raw_ptr content_view_ = nullptr; + // The custom height parsed from the "height" option in a Object + // "titleBarOverlay" + int titlebar_overlay_height_ = 0; + // Whether window has standard frame. bool has_frame_ = true;