native_window_observer.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Copyright (c) 2013 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ELECTRON_SHELL_BROWSER_NATIVE_WINDOW_OBSERVER_H_
  5. #define ELECTRON_SHELL_BROWSER_NATIVE_WINDOW_OBSERVER_H_
  6. #include <string>
  7. #include <string_view>
  8. #include "base/observer_list_types.h"
  9. #include "base/values.h"
  10. #include "ui/base/window_open_disposition.h"
  11. #if BUILDFLAG(IS_WIN)
  12. #include <windows.h>
  13. #endif
  14. class GURL;
  15. namespace gfx {
  16. class Rect;
  17. enum class ResizeEdge;
  18. } // namespace gfx
  19. namespace electron {
  20. class NativeWindowObserver : public base::CheckedObserver {
  21. public:
  22. ~NativeWindowObserver() override = default;
  23. // Called when the web page in window wants to create a popup window.
  24. virtual void WillCreatePopupWindow(const std::u16string& frame_name,
  25. const GURL& target_url,
  26. const std::string& partition_id,
  27. WindowOpenDisposition disposition) {}
  28. // Called when user is starting an navigation in web page.
  29. virtual void WillNavigate(bool* prevent_default, const GURL& url) {}
  30. // Called when the window is gonna closed.
  31. virtual void WillCloseWindow(bool* prevent_default) {}
  32. // Called when the window wants to know the preferred width.
  33. virtual void RequestPreferredWidth(int* width) {}
  34. // Called when closed button is clicked.
  35. virtual void OnCloseButtonClicked(bool* prevent_default) {}
  36. // Called when the window is closed.
  37. virtual void OnWindowClosed() {}
  38. // Called when Windows sends WM_QUERYENDSESSION message.
  39. virtual void OnWindowQueryEndSession(const std::vector<std::string>& reasons,
  40. bool* prevent_default) {}
  41. // Called when Windows sends WM_ENDSESSION message
  42. virtual void OnWindowEndSession(const std::vector<std::string>& reasons) {}
  43. // Called when window loses focus.
  44. virtual void OnWindowBlur() {}
  45. // Called when window gains focus.
  46. virtual void OnWindowFocus() {}
  47. // Called when window gained or lost key window status.
  48. virtual void OnWindowIsKeyChanged(bool is_key) {}
  49. // Called when window is shown.
  50. virtual void OnWindowShow() {}
  51. // Called when window is hidden.
  52. virtual void OnWindowHide() {}
  53. // Called when window state changed.
  54. virtual void OnWindowMaximize() {}
  55. virtual void OnWindowUnmaximize() {}
  56. virtual void OnWindowMinimize() {}
  57. virtual void OnWindowRestore() {}
  58. virtual void OnWindowWillResize(const gfx::Rect& new_bounds,
  59. const gfx::ResizeEdge& edge,
  60. bool* prevent_default) {}
  61. virtual void OnWindowResize() {}
  62. virtual void OnWindowResized() {}
  63. virtual void OnWindowWillMove(const gfx::Rect& new_bounds,
  64. bool* prevent_default) {}
  65. virtual void OnWindowMove() {}
  66. virtual void OnWindowMoved() {}
  67. virtual void OnWindowSwipe(const std::string& direction) {}
  68. virtual void OnWindowRotateGesture(float rotation) {}
  69. virtual void OnWindowSheetBegin() {}
  70. virtual void OnWindowSheetEnd() {}
  71. virtual void OnWindowEnterFullScreen() {}
  72. virtual void OnWindowLeaveFullScreen() {}
  73. virtual void OnWindowEnterHtmlFullScreen() {}
  74. virtual void OnWindowLeaveHtmlFullScreen() {}
  75. virtual void OnWindowAlwaysOnTopChanged() {}
  76. virtual void OnTouchBarItemResult(const std::string& item_id,
  77. const base::Value::Dict& details) {}
  78. virtual void OnNewWindowForTab() {}
  79. virtual void OnSystemContextMenu(int x, int y, bool* prevent_default) {}
  80. // Called when window message received
  81. #if BUILDFLAG(IS_WIN)
  82. virtual void OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) {}
  83. #endif
  84. // Called on Windows when App Commands arrive (WM_APPCOMMAND)
  85. // Some commands are implemented on on other platforms as well
  86. virtual void OnExecuteAppCommand(std::string_view command_name) {}
  87. virtual void UpdateWindowControlsOverlay(const gfx::Rect& bounding_rect) {}
  88. };
  89. } // namespace electron
  90. #endif // ELECTRON_SHELL_BROWSER_NATIVE_WINDOW_OBSERVER_H_