UIPlatformWebView.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include "../../Core/CoreEvents.h"
  2. #include "../../IO/Log.h"
  3. #include "../UI.h"
  4. #include "UIPlatformWebView.h"
  5. namespace Atomic
  6. {
  7. AtomicWebViewHandle UIPlatformWebView::webViewHandleCounter_ = 1;
  8. HashMap<AtomicWebViewHandle, WeakPtr<UIPlatformWebView>> UIPlatformWebView::webViewLookup_;
  9. UIPlatformWebView::UIPlatformWebView(Context* context, bool createWidget) : UIWidget(context, false),
  10. webViewHandle_(UI_PLATFORM_WEBVIEW_INVALID_HANDLE)
  11. {
  12. if (createWidget)
  13. {
  14. widget_ = new tb::TBWidget();
  15. widget_->SetDelegate(this);
  16. widget_->SetIsFocusable(true);
  17. GetSubsystem<UI>()->WrapWidget(this, widget_);
  18. }
  19. SubscribeToEvent(E_ENDFRAME, ATOMIC_HANDLER(UIPlatformWebView, HandleEndFrame));
  20. }
  21. UIPlatformWebView::~UIPlatformWebView()
  22. {
  23. if (webViewHandle_ != UI_PLATFORM_WEBVIEW_INVALID_HANDLE)
  24. {
  25. PlatformDestroyWebView();
  26. }
  27. }
  28. void UIPlatformWebView::OnFocusChanged(bool focused)
  29. {
  30. UIWidget::OnFocusChanged(focused);
  31. // ATOMIC_LOGINFOF("UIPlatformWebView::OnFocusChanged(%s)", focused ? "true" : "false");
  32. }
  33. void UIPlatformWebView::OnRequestSent(const String& request)
  34. {
  35. }
  36. void UIPlatformWebView::OnError(const String& request)
  37. {
  38. }
  39. void UIPlatformWebView::HandleEndFrame(StringHash eventType, VariantMap& eventData)
  40. {
  41. if (webViewHandle_ == UI_PLATFORM_WEBVIEW_INVALID_HANDLE)
  42. {
  43. if (!GetWidth() || !GetHeight())
  44. {
  45. return;
  46. }
  47. if (!PlatformCreateWebView())
  48. {
  49. return;
  50. }
  51. PlatformShowWebView();
  52. }
  53. if (!widget_->GetVisibilityCombined())
  54. {
  55. PlatformHideWebView();
  56. }
  57. else
  58. {
  59. PlatformShowWebView();
  60. }
  61. PlatformPositionWebView();
  62. }
  63. }