diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 1625063c76..f7439b20ab 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -1850,6 +1850,19 @@ NativeWindowViews::CreateNonClientFrameView(views::Widget* widget) { #endif } +#if BUILDFLAG(IS_LINUX) +electron::ClientFrameViewLinux* NativeWindowViews::GetClientFrameViewLinux() { + // Check to make sure this window's non-client frame view is a + // ClientFrameViewLinux. If either has_frame() or has_client_frame() + // are false, it will be an OpaqueFrameView or NativeFrameView instead. + // See NativeWindowViews::CreateNonClientFrameView. + if (!has_frame() || !has_client_frame()) + return {}; + return static_cast( + widget()->non_client_view()->frame_view()); +} +#endif + void NativeWindowViews::OnWidgetMove() { NotifyWindowMove(); } diff --git a/shell/browser/native_window_views.h b/shell/browser/native_window_views.h index 801d8f5fc0..b101c8bb32 100644 --- a/shell/browser/native_window_views.h +++ b/shell/browser/native_window_views.h @@ -31,6 +31,7 @@ class Arguments; namespace electron { #if BUILDFLAG(IS_LINUX) +class ClientFrameViewLinux; class GlobalMenuBarX11; #endif @@ -182,6 +183,12 @@ class NativeWindowViews : public NativeWindow, SkColor overlay_button_color() const { return overlay_button_color_; } SkColor overlay_symbol_color() const { return overlay_symbol_color_; } +#if BUILDFLAG(IS_LINUX) + // returns the ClientFrameViewLinux iff that is our NonClientFrameView type, + // nullptr otherwise. + ClientFrameViewLinux* GetClientFrameViewLinux(); +#endif + private: void set_overlay_button_color(SkColor color) { overlay_button_color_ = color; diff --git a/shell/browser/ui/electron_desktop_window_tree_host_linux.cc b/shell/browser/ui/electron_desktop_window_tree_host_linux.cc index dd7a5e2b64..b6dfb312ac 100644 --- a/shell/browser/ui/electron_desktop_window_tree_host_linux.cc +++ b/shell/browser/ui/electron_desktop_window_tree_host_linux.cc @@ -64,13 +64,9 @@ gfx::Insets ElectronDesktopWindowTreeHostLinux::CalculateInsetsInDIP( return gfx::Insets(); } - if (!native_window_view_->has_frame() || - !native_window_view_->has_client_frame()) { - return gfx::Insets(); - } - - auto* view = static_cast( - native_window_view_->widget()->non_client_view()->frame_view()); + auto* const view = native_window_view_->GetClientFrameViewLinux(); + if (!view) + return {}; gfx::Insets insets = view->RestoredMirroredFrameBorderInsets(); if (base::i18n::IsRTL()) @@ -102,19 +98,12 @@ void ElectronDesktopWindowTreeHostLinux::OnWindowStateChanged( void ElectronDesktopWindowTreeHostLinux::OnWindowTiledStateChanged( ui::WindowTiledEdges new_tiled_edges) { - // CreateNonClientFrameView creates `ClientFrameViewLinux` only when both - // frame and client_frame booleans are set, otherwise it is a different type - // of view. - if (native_window_view_->has_frame() && - native_window_view_->has_client_frame()) { - ClientFrameViewLinux* frame = static_cast( - native_window_view_->widget()->non_client_view()->frame_view()); - + if (auto* const view = native_window_view_->GetClientFrameViewLinux()) { bool maximized = new_tiled_edges.top && new_tiled_edges.left && new_tiled_edges.bottom && new_tiled_edges.right; bool tiled = new_tiled_edges.top || new_tiled_edges.left || new_tiled_edges.bottom || new_tiled_edges.right; - frame->set_tiled(tiled && !maximized); + view->set_tiled(tiled && !maximized); } UpdateFrameHints(); } @@ -166,15 +155,13 @@ void ElectronDesktopWindowTreeHostLinux::OnDeviceScaleFactorChanged() { void ElectronDesktopWindowTreeHostLinux::UpdateFrameHints() { if (base::FeatureList::IsEnabled(features::kWaylandWindowDecorations)) { - if (!native_window_view_->has_frame() || - !native_window_view_->has_client_frame()) + auto* const view = native_window_view_->GetClientFrameViewLinux(); + if (!view) return; ui::PlatformWindow* window = platform_window(); auto window_state = window->GetPlatformWindowState(); float scale = device_scale_factor(); - auto* view = static_cast( - native_window_view_->widget()->non_client_view()->frame_view()); const gfx::Size widget_size = view->GetWidget()->GetWindowBoundsInScreen().size();