UIPlatformWebView.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // Copyright (c) 2014-2017, THUNDERBEAST GAMES LLC All rights reserved
  3. // Copyright (c) 2011-2017, The Game Engine Company LLC (Apache License 2.0)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #include "../UIWidget.h"
  24. namespace Atomic
  25. {
  26. typedef int AtomicWebViewHandle;
  27. static const int UI_PLATFORM_WEBVIEW_INVALID_HANDLE = 0;
  28. // A platform WebView which always displays on top of other UIWidgets as it is, by necessity, a platform window
  29. class ATOMIC_API UIPlatformWebView : public UIWidget
  30. {
  31. ATOMIC_OBJECT(UIPlatformWebView, UIWidget)
  32. public:
  33. UIPlatformWebView(Context* context, bool createWidget = true);
  34. virtual ~UIPlatformWebView();
  35. /// Load the specified url into the main frame of the browser
  36. void LoadURL(const String& url);
  37. /// Reload the current page
  38. void Reload();
  39. /// Attempt to go back in the WebView associated with the specified handle. Returns false if there is nothing to go back to.
  40. bool GoBack();
  41. /// Attempt to go forward in the WebView associated with the specified handle. Returns false if there is nothing to go forward to.
  42. bool GoForward();
  43. /// Returns false if there is nothing to go back to. True otherwise.
  44. bool CanGoBack() const;
  45. /// Returns true if there is nothing to go back to. True otherwise.
  46. bool CanGoForward() const;
  47. /// Removes all listeners and stops interacting with WebViews on platforms that require it (iOS).
  48. static void PauseAll();
  49. /// Resumes normal operation of WebViews after pausing.
  50. static void ResumeAll();
  51. void OnRequestSent(const String& request);
  52. void OnError(const String& request);
  53. void OnFocusChanged(bool focused);
  54. private:
  55. void HandleEndFrame(StringHash eventType, VariantMap& eventData);
  56. void PlatformShowWebView(bool visible = true);
  57. void PlatformHideWebView() { PlatformShowWebView(false); }
  58. bool PlatformCreateWebView();
  59. void PlatformDestroyWebView();
  60. void PlatformPositionWebView();
  61. AtomicWebViewHandle webViewHandle_;
  62. static HashMap<AtomicWebViewHandle, WeakPtr<UIPlatformWebView>> webViewLookup_;
  63. static AtomicWebViewHandle webViewHandleCounter_;
  64. static void DestroyAll();
  65. String queuedRequest_;
  66. };
  67. }