diff --git a/packages/webview_flutter/CHANGELOG.md b/packages/webview_flutter/CHANGELOG.md index 540b0b123..5c741f444 100644 --- a/packages/webview_flutter/CHANGELOG.md +++ b/packages/webview_flutter/CHANGELOG.md @@ -15,4 +15,7 @@ ## 0.2.2 * Update lightweight web engine binary & header file (6263be6c888d5cb9dcca5466dfc3941a70b424eb) * Activate resizing function -* Apply embedder's texture APIs change \ No newline at end of file +* Apply embedder's texture APIs change + +## 0.3.0 +* Apply PlatformView, PlatformViewFactory APIs change \ No newline at end of file diff --git a/packages/webview_flutter/pubspec.yaml b/packages/webview_flutter/pubspec.yaml index 1a4418272..35e2a6c4e 100644 --- a/packages/webview_flutter/pubspec.yaml +++ b/packages/webview_flutter/pubspec.yaml @@ -1,7 +1,7 @@ name: webview_flutter_tizen description: Tizen implementation of the webview plugin homepage: https://github.com/flutter-tizen/plugins -version: 0.2.2 +version: 0.3.0 environment: sdk: ">=2.12.0 <3.0.0" diff --git a/packages/webview_flutter/tizen/src/webview.cc b/packages/webview_flutter/tizen/src/webview.cc index fcf966c7d..e9ffc9f44 100644 --- a/packages/webview_flutter/tizen/src/webview.cc +++ b/packages/webview_flutter/tizen/src/webview.cc @@ -145,20 +145,27 @@ int ExtractIntFromMap(const flutter::EncodableValue& arguments, } return -1; } -double ExtractDoubleFromMap(const flutter::EncodableValue& arguments, - const char* key) { - if (std::holds_alternative(arguments)) { - flutter::EncodableMap values = std::get(arguments); - flutter::EncodableValue value = values[flutter::EncodableValue(key)]; - if (std::holds_alternative(value)) return std::get(value); + +template +bool GetValueFromEncodableMap(const flutter::EncodableValue& arguments, + std::string key, T* out) { + if (auto pmap = std::get_if(&arguments)) { + auto iter = pmap->find(flutter::EncodableValue(key)); + if (iter != pmap->end() && !iter->second.IsNull()) { + if (auto pval = std::get_if(&iter->second)) { + *out = *pval; + return true; + } + } } - return -1; + return false; } WebView::WebView(flutter::PluginRegistrar* registrar, int viewId, flutter::TextureRegistrar* texture_registrar, double width, - double height, flutter::EncodableMap& params) - : PlatformView(registrar, viewId), + double height, flutter::EncodableMap& params, + void* platform_window) + : PlatformView(registrar, viewId, platform_window), texture_registrar_(texture_registrar), webview_instance_(nullptr), width_(width), @@ -823,9 +830,13 @@ void WebView::HandleMethodCall( LOG_DEBUG("WebView::HandleMethodCall : %s \n ", method_name.c_str()); if (method_name.compare("loadUrl") == 0) { - std::string url = ExtractStringFromMap(arguments, "url"); - webview_instance_->LoadURL(url); - result->Success(); + std::string url; + if (GetValueFromEncodableMap(arguments, "viewType", &url)) { + webview_instance_->LoadURL(url); + result->Success(); + return; + } + result->Error("Invalid Arguments", "Invalid Arguments"); } else if (method_name.compare("updateSettings") == 0) { if (std::holds_alternative(arguments)) { auto settings = std::get(arguments); @@ -896,15 +907,23 @@ void WebView::HandleMethodCall( } else if (method_name.compare("getTitle") == 0) { result->Success(flutter::EncodableValue(webview_instance_->GetTitle())); } else if (method_name.compare("scrollTo") == 0) { - int x = ExtractIntFromMap(arguments, "x"); - int y = ExtractIntFromMap(arguments, "y"); - webview_instance_->ScrollTo(x, y); - result->Success(); + int x = 0, y = 0; + if (GetValueFromEncodableMap(arguments, "x", &x) && + GetValueFromEncodableMap(arguments, "y", &y)) { + webview_instance_->ScrollTo(x, y); + result->Success(); + return; + } + result->Error("Invalid Arguments", "Invalid Arguments"); } else if (method_name.compare("scrollBy") == 0) { - int x = ExtractIntFromMap(arguments, "x"); - int y = ExtractIntFromMap(arguments, "y"); - webview_instance_->ScrollBy(x, y); - result->Success(); + int x = 0, y = 0; + if (GetValueFromEncodableMap(arguments, "x", &x) && + GetValueFromEncodableMap(arguments, "y", &y)) { + webview_instance_->ScrollBy(x, y); + result->Success(); + return; + } + result->Error("Invalid Arguments", "Invalid Arguments"); } else if (method_name.compare("getScrollX") == 0) { result->Success(flutter::EncodableValue(webview_instance_->GetScrollX())); } else if (method_name.compare("getScrollY") == 0) { diff --git a/packages/webview_flutter/tizen/src/webview.h b/packages/webview_flutter/tizen/src/webview.h index dafbe5947..e88cc2f88 100644 --- a/packages/webview_flutter/tizen/src/webview.h +++ b/packages/webview_flutter/tizen/src/webview.h @@ -27,7 +27,7 @@ class WebView : public PlatformView { public: WebView(flutter::PluginRegistrar* registrar, int viewId, flutter::TextureRegistrar* textureRegistrar, double width, - double height, flutter::EncodableMap& params); + double height, flutter::EncodableMap& params, void* platform_window); ~WebView(); virtual void Dispose() override; virtual void Resize(double width, double height) override; @@ -39,11 +39,10 @@ class WebView : public PlatformView { // Key input event virtual void DispatchKeyDownEvent(Ecore_Event_Key* key) override; virtual void DispatchKeyUpEvent(Ecore_Event_Key* key) override; - virtual void DispatchCompositionUpdateEvent(const char* str, - int size) override; - virtual void DispatchCompositionEndEvent(const char* str, int size) override; - virtual void SetSoftwareKeyboardContext(Ecore_IMF_Context* context) override; + void DispatchCompositionUpdateEvent(const char* str, int size); + void DispatchCompositionEndEvent(const char* str, int size); + void SetSoftwareKeyboardContext(Ecore_IMF_Context* context); LWE::WebContainer* GetWebViewInstance() { return webview_instance_; } diff --git a/packages/webview_flutter/tizen/src/webview_factory.cc b/packages/webview_flutter/tizen/src/webview_factory.cc index 362341c94..0c3e2ee4d 100644 --- a/packages/webview_flutter/tizen/src/webview_factory.cc +++ b/packages/webview_flutter/tizen/src/webview_factory.cc @@ -51,7 +51,7 @@ PlatformView* WebViewFactory::Create(int viewId, double width, double height, try { return new WebView(GetPluginRegistrar(), viewId, texture_registrar_, width, - height, params); + height, params, platform_window_); } catch (const std::invalid_argument& ex) { LOG_ERROR("[Exception] %s\n", ex.what()); return nullptr;