electron_desktop_window_tree_host_linux.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright (c) 2021 Ryan Gonzalez.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. // Portions of this file are sourced from
  5. // chrome/browser/ui/views/frame/browser_desktop_window_tree_host_linux.h,
  6. // Copyright (c) 2019 The Chromium Authors,
  7. // which is governed by a BSD-style license
  8. #ifndef ELECTRON_SHELL_BROWSER_UI_ELECTRON_DESKTOP_WINDOW_TREE_HOST_LINUX_H_
  9. #define ELECTRON_SHELL_BROWSER_UI_ELECTRON_DESKTOP_WINDOW_TREE_HOST_LINUX_H_
  10. #include "base/memory/raw_ptr.h"
  11. #include "base/scoped_observation.h"
  12. #include "ui/linux/device_scale_factor_observer.h"
  13. #include "ui/linux/linux_ui.h"
  14. #include "ui/native_theme/native_theme_observer.h"
  15. #include "ui/platform_window/platform_window.h"
  16. #include "ui/views/widget/desktop_aura/desktop_window_tree_host_linux.h"
  17. namespace electron {
  18. class ClientFrameViewLinux;
  19. class NativeWindowViews;
  20. class ElectronDesktopWindowTreeHostLinux
  21. : public views::DesktopWindowTreeHostLinux,
  22. private ui::NativeThemeObserver,
  23. private ui::DeviceScaleFactorObserver {
  24. public:
  25. ElectronDesktopWindowTreeHostLinux(
  26. NativeWindowViews* native_window_view,
  27. views::DesktopNativeWidgetAura* desktop_native_widget_aura);
  28. ~ElectronDesktopWindowTreeHostLinux() override;
  29. // disable copy
  30. ElectronDesktopWindowTreeHostLinux(
  31. const ElectronDesktopWindowTreeHostLinux&) = delete;
  32. ElectronDesktopWindowTreeHostLinux& operator=(
  33. const ElectronDesktopWindowTreeHostLinux&) = delete;
  34. bool SupportsClientFrameShadow() const;
  35. protected:
  36. // views::DesktopWindowTreeHostLinuxImpl:
  37. void OnWidgetInitDone() override;
  38. // ui::PlatformWindowDelegate
  39. gfx::Insets CalculateInsetsInDIP(
  40. ui::PlatformWindowState window_state) const override;
  41. void OnBoundsChanged(const BoundsChange& change) override;
  42. void OnWindowStateChanged(ui::PlatformWindowState old_state,
  43. ui::PlatformWindowState new_state) override;
  44. void OnWindowTiledStateChanged(ui::WindowTiledEdges new_tiled_edges) override;
  45. // ui::NativeThemeObserver:
  46. void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) override;
  47. // views::OnDeviceScaleFactorChanged:
  48. void OnDeviceScaleFactorChanged() override;
  49. // views::DesktopWindowTreeHostLinux:
  50. void UpdateFrameHints() override;
  51. void DispatchEvent(ui::Event* event) override;
  52. private:
  53. void UpdateWindowState(ui::PlatformWindowState new_state);
  54. bool IsShowingFrame() const;
  55. raw_ptr<NativeWindowViews> native_window_view_; // weak ref
  56. base::ScopedObservation<ui::NativeTheme, ui::NativeThemeObserver>
  57. theme_observation_{this};
  58. base::ScopedObservation<ui::LinuxUi, ui::DeviceScaleFactorObserver>
  59. scale_observation_{this};
  60. ui::PlatformWindowState window_state_ = ui::PlatformWindowState::kUnknown;
  61. };
  62. } // namespace electron
  63. #endif // ELECTRON_SHELL_BROWSER_UI_ELECTRON_DESKTOP_WINDOW_TREE_HOST_LINUX_H_