DISTRHO Plugin Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
4.5KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2024 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #if !defined(DISTRHO_WEB_VIEW_HPP_INCLUDED) && !defined(DGL_WEB_VIEW_HPP_INCLUDED)
  17. # error bad include
  18. #endif
  19. #if !defined(DGL_UI_USE_WEB_VIEW) && defined(DISTRHO_UI_WEB_VIEW) && DISTRHO_UI_WEB_VIEW == 0
  20. # error To use WebViews in DPF plugins please set DISTRHO_UI_WEB_VIEW to 1
  21. #endif
  22. // --------------------------------------------------------------------------------------------------------------------
  23. // Web View stuff
  24. struct WebViewData;
  25. typedef WebViewData* WebViewHandle;
  26. typedef void (*WebViewMessageCallback)(void* arg, char* msg);
  27. // --------------------------------------------------------------------------------------------------------------------
  28. /**
  29. Web view options, for customizing web view details.
  30. */
  31. struct WebViewOptions {
  32. /**
  33. Position offset, for cases of mixing regular widgets with web views.
  34. */
  35. struct PositionOffset {
  36. /** Horizontal offset, with scale factor pre-applied */
  37. int x;
  38. /** Vertical offset, with scale factor pre-applied */
  39. int y;
  40. /** Constructor for default values */
  41. PositionOffset() : x(0), y(0) {}
  42. } offset;
  43. /**
  44. Set some JavaScript to evalute on every new page load.
  45. */
  46. const char* initialJS;
  47. /**
  48. Message callback triggered from JavaScript code inside the WebView.
  49. */
  50. WebViewMessageCallback callback;
  51. void* callbackPtr;
  52. /** Constructor for default values */
  53. WebViewOptions()
  54. : offset(),
  55. initialJS(nullptr),
  56. callback(nullptr),
  57. callbackPtr(nullptr) {}
  58. /** Constructor providing a callback */
  59. WebViewOptions(const WebViewMessageCallback cb, void* const ptr)
  60. : offset(),
  61. initialJS(nullptr),
  62. callback(cb),
  63. callbackPtr(ptr) {}
  64. };
  65. // --------------------------------------------------------------------------------------------------------------------
  66. /**
  67. Create a new web view.
  68. The web view will be added on top of an existing platform-specific view/window.
  69. This means it will draw on top of whatever is below it,
  70. something to take into consideration if mixing regular widgets with web views.
  71. Provided metrics must have scale factor pre-applied.
  72. @p url: The URL to open, assumed to be in encoded form (e.g spaces converted to %20)
  73. @p windowId: The native window id to attach this view to (X11 Window, HWND or NSView*)
  74. @p scaleFactor: Scale factor in use
  75. @p options: Extra options, optional
  76. */
  77. WebViewHandle webViewCreate(const char* url,
  78. uintptr_t windowId,
  79. uint initialWidth,
  80. uint initialHeight,
  81. double scaleFactor,
  82. const WebViewOptions& options = WebViewOptions());
  83. /**
  84. Destroy the web view, handle must not be used afterwards.
  85. */
  86. void webViewDestroy(WebViewHandle webview);
  87. /**
  88. Idle the web view, to be called on regular intervals.
  89. Can cause callbacks to trigger.
  90. */
  91. void webViewIdle(WebViewHandle webview);
  92. /**
  93. Evaluate/run JavaScript on the web view.
  94. */
  95. void webViewEvaluateJS(WebViewHandle webview, const char* js);
  96. /**
  97. Reload the web view current page.
  98. */
  99. void webViewReload(WebViewHandle webview);
  100. /**
  101. Resize the web view.
  102. */
  103. void webViewResize(WebViewHandle webview, uint width, uint height, double scaleFactor);
  104. // --------------------------------------------------------------------------------------------------------------------
  105. /**
  106. Helper class for usage in std::shared_ptr and std::unique_ptr.
  107. */
  108. struct WebViewDestroy {
  109. void operator()(WebViewHandle handle) { webViewDestroy(handle); }
  110. };
  111. // --------------------------------------------------------------------------------------------------------------------