The Webview Univeral Flutter package for Appeto SDK.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

99 lignes
2.6 KiB

  1. //
  2. // Created by yangbin on 2021/10/20.
  3. //
  4. #ifndef _WEBVIEW_WINDOW_WEBVIEW_WINDOW_H_
  5. #define _WEBVIEW_WINDOW_WEBVIEW_WINDOW_H_
  6. #include <Windows.h>
  7. #include <flutter/dart_project.h>
  8. #include <flutter/method_channel.h>
  9. #include <flutter/encodable_value.h>
  10. #include <flutter/flutter_view_controller.h>
  11. #include <string>
  12. #include <memory>
  13. #include <functional>
  14. #include <wrl.h>
  15. #include "wil/com.h"
  16. #include "WebView2.h"
  17. #include "flutter_view.h"
  18. #include "web_view.h"
  19. class WebviewWindow {
  20. public:
  21. using MethodChannelPtr = std::shared_ptr<flutter::MethodChannel<flutter::EncodableValue>>;
  22. WebviewWindow(MethodChannelPtr method_channel,
  23. int64_t window_id,
  24. int title_bar_height,
  25. std::function<void()> on_close_callback);
  26. virtual ~WebviewWindow();
  27. using CreateCallback = std::function<void(bool success)>;
  28. void CreateAndShow(const std::wstring &title, int height, int width,
  29. const std::wstring &userDataFolder,
  30. CreateCallback callback);
  31. // OS callback called by message pump. Handles the WM_NCCREATE message which
  32. // is passed when the non-client area is being created and enables automatic
  33. // non-client DPI scaling so that the non-client area automatically
  34. // responsponds to changes in DPI. All other messages are handled by
  35. // MessageHandler.
  36. static LRESULT CALLBACK WndProc(HWND window,
  37. UINT message,
  38. WPARAM wparam,
  39. LPARAM lparam) noexcept;
  40. void SetBrightness(int brightness);
  41. [[nodiscard]] const std::unique_ptr<webview_window::WebView> &GetWebView() const {
  42. return web_view_;
  43. }
  44. private:
  45. // Retrieves a class instance pointer for |window|
  46. static WebviewWindow *GetThisFromHandle(HWND window) noexcept;
  47. MethodChannelPtr method_channel_;
  48. wil::unique_hwnd hwnd_;
  49. int64_t window_id_;
  50. std::function<void()> on_close_callback_;
  51. std::unique_ptr<webview_window::FlutterView> flutter_action_bar_;
  52. std::unique_ptr<webview_window::WebView> web_view_;
  53. int last_title_bar_width_ = 0;
  54. bool destroyed_ = false;
  55. int title_bar_height_;
  56. // Processes and route salient window messages for mouse handling,
  57. // size change and DPI. Delegates handling of these to member overloads that
  58. // inheriting classes can handle.
  59. LRESULT MessageHandler(HWND window,
  60. UINT message,
  61. WPARAM wparam,
  62. LPARAM lparam) noexcept;
  63. LRESULT HandleNCHitTest(int x, int y) noexcept;
  64. void SetBorderless() noexcept;
  65. };
  66. #endif //_WEBVIEW_WINDOW_WEBVIEW_WINDOW_H_