IWithPopups.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (c) 2024 Vuplex Inc. All rights reserved.
  2. //
  3. // Licensed under the Vuplex Commercial Software Library License, you may
  4. // not use this file except in compliance with the License. You may obtain
  5. // a copy of the License at
  6. //
  7. // https://vuplex.com/commercial-library-license
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. using System;
  15. namespace Vuplex.WebView {
  16. /// <summary>
  17. /// An interface implemented by a webview if it supports opening popups.
  18. /// For detailed examples, please see 3D WebView's PopupDemo and CanvasPopupDemo
  19. /// scenes.
  20. /// </summary>
  21. /// <remarks>
  22. /// There are several approaches that a web page can use to open a URL in a popup.
  23. /// For example, it can load a new URL using the window.open() JavaScript API or
  24. /// use the target="_blank" attribute on a link. In a normal web browser, these
  25. /// approaches cause the browser to open the new URL in a new tab or window. In
  26. /// 3D WebView, the default behavior is to load the new URL in the existing webview
  27. /// without creating a new webview. However, an application can change this by
  28. /// using the IWithPopups interface to make popup URLs open in a new popup webview.
  29. /// </remarks>
  30. /// <example>
  31. /// <code>
  32. /// await webViewPrefab.WaitUntilInitialized;
  33. /// var webViewWithPopups = webViewPrefab.WebView as IWithPopups;
  34. /// if (webViewWithPopups != null) {
  35. /// webViewWithPopups.SetPopupMode(PopupMode.LoadInNewWebView);
  36. ///
  37. /// webViewWithPopups.PopupRequested += async (sender, eventArgs) => {
  38. /// Debug.Log("Popup opened with URL: " + eventArgs.Url);
  39. /// // Create and display a new WebViewPrefab for the popup.
  40. /// var popupPrefab = WebViewPrefab.Instantiate(eventArgs.WebView);
  41. /// popupPrefab.transform.parent = transform;
  42. /// popupPrefab.transform.localPosition = Vector3.zero;
  43. /// popupPrefab.transform.localEulerAngles = new Vector3(0, 180, 0);
  44. /// await popupPrefab.WaitUntilInitialized();
  45. /// popupPrefab.WebView.CloseRequested += (popupWebView, closeEventArgs) => {
  46. /// Debug.Log("Closing the popup");
  47. /// popupPrefab.Destroy();
  48. /// };
  49. /// };
  50. /// }
  51. /// </code>
  52. /// </example>
  53. public interface IWithPopups {
  54. /// <summary>
  55. /// Sets how the webview handles popups.
  56. /// </summary>
  57. void SetPopupMode(PopupMode popupMode);
  58. /// <summary>
  59. /// Indicates that the webview requested a popup.
  60. /// </summary>
  61. event EventHandler<PopupRequestedEventArgs> PopupRequested;
  62. }
  63. }