mirror of
https://github.com/electron/electron.git
synced 2026-01-08 23:18:06 -05:00
refactor: add NativeWindowViews::GetClientFrameViewLinux() (#47130)
* refactor: add NativeWindowViews::GetClientFrameViewLinux() * chore: clarify code comment
This commit is contained in:
@@ -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<ClientFrameViewLinux*>(
|
||||
widget()->non_client_view()->frame_view());
|
||||
}
|
||||
#endif
|
||||
|
||||
void NativeWindowViews::OnWidgetMove() {
|
||||
NotifyWindowMove();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<ClientFrameViewLinux*>(
|
||||
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<ClientFrameViewLinux*>(
|
||||
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<ClientFrameViewLinux*>(
|
||||
native_window_view_->widget()->non_client_view()->frame_view());
|
||||
const gfx::Size widget_size =
|
||||
view->GetWidget()->GetWindowBoundsInScreen().size();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user