Repository: electron/electron
File: shell/browser/ui/electron_desktop_window_tree_host_linux.h (C/C++)

Code before:
  void OnWindowStateChanged(ui::PlatformWindowState old_state,
                            ui::PlatformWindowState new_state) override;
  void OnWindowTiledStateChanged(ui::WindowTiledEdges new_tiled_edges) override;

  // ui::NativeThemeObserver:
  void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) override;

  // views::OnDeviceScaleFactorChanged:
  void OnDeviceScaleFactorChanged() override;

  // views::DesktopWindowTreeHostLinux:
  void UpdateFrameHints() override;
  void DispatchEvent(ui::Event* event) override;
  void AddAdditionalInitProperties(
      const views::Widget::InitParams& params,
      ui::PlatformWindowInitProperties* properties) override;

 private:
  void UpdateWindowState(ui::PlatformWindowState new_state);

  bool IsShowingFrame(ui::PlatformWindowState window_state) const;

  raw_ptr<NativeWindowViews> native_window_view_;  // weak ref

  base::ScopedObservation<ui::NativeTheme, ui::NativeThemeObserver>
      theme_observation_{this};
  base::ScopedObservation<ui::LinuxUi, ui::DeviceScaleFactorObserver>
      scale_observation_{this};
  ui::PlatformWindowState window_state_ = ui::PlatformWindowState::kUnknown;
};

}  // namespace electron

#endif  // ELECTRON_SHELL_BROWSER_UI_ELECTRON_DESKTOP_WINDOW_TREE_HOST_LINUX_H_


Review comment (performance):
The change to `IsShowingFrame` mirrors how the function is implemented in Chromium. It now computes bounds accurately when the window is transitioning between states (e.g. minimized to restored). Previously the cached window state was used, which was out of date during transitions and could cause the window to suddenly shrink or grow.

Code after:

  // ui::PlatformWindowDelegate
  gfx::Insets CalculateInsetsInDIP(
      ui::PlatformWindowState window_state) const override;
  void OnBoundsChanged(const BoundsChange& change) override;
  void OnWindowStateChanged(ui::PlatformWindowState old_state,
                            ui::PlatformWindowState new_state) override;
  void OnWindowTiledStateChanged(ui::WindowTiledEdges new_tiled_edges) override;

  // ui::NativeThemeObserver:
  void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) override;

  // views::OnDeviceScaleFactorChanged:
  void OnDeviceScaleFactorChanged() override;

  // views::DesktopWindowTreeHostLinux:
  void UpdateFrameHints() override;
  void DispatchEvent(ui::Event* event) override;
  void AddAdditionalInitProperties(
      const views::Widget::InitParams& params,
      ui::PlatformWindowInitProperties* properties) override;

 private:
  void UpdateWindowState(ui::PlatformWindowState new_state);

  bool IsShowingFrame(ui::PlatformWindowState window_state) const;

  gfx::ImageSkia saved_window_icon_;

  raw_ptr<NativeWindowViews> native_window_view_;  // weak ref

  base::ScopedObservation<ui::NativeTheme, ui::NativeThemeObserver>
      theme_observation_{this};
  base::ScopedObservation<ui::LinuxUi, ui::DeviceScaleFactorObserver>
      scale_observation_{this};
  ui::PlatformWindowState window_state_ = ui::PlatformWindowState::kUnknown;
};

}  // namespace electron

#endif  // ELECTRON_SHELL_BROWSER_UI_ELECTRON_DESKTOP_WINDOW_TREE_HOST_LINUX_H_