Skip to content

[webview_flutter] Apply PlatformView's Intreface #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/webview_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@
## 0.2.2
* Update lightweight web engine binary & header file (6263be6c888d5cb9dcca5466dfc3941a70b424eb)
* Activate resizing function
* Apply embedder's texture APIs change
* Apply embedder's texture APIs change

## 0.3.0
* Apply PlatformView, PlatformViewFactory APIs change
2 changes: 1 addition & 1 deletion packages/webview_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
59 changes: 39 additions & 20 deletions packages/webview_flutter/tizen/src/webview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<flutter::EncodableMap>(arguments)) {
flutter::EncodableMap values = std::get<flutter::EncodableMap>(arguments);
flutter::EncodableValue value = values[flutter::EncodableValue(key)];
if (std::holds_alternative<double>(value)) return std::get<double>(value);

template <typename T>
bool GetValueFromEncodableMap(const flutter::EncodableValue& arguments,
std::string key, T* out) {
if (auto pmap = std::get_if<flutter::EncodableMap>(&arguments)) {
auto iter = pmap->find(flutter::EncodableValue(key));
if (iter != pmap->end() && !iter->second.IsNull()) {
if (auto pval = std::get_if<T>(&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),
Expand Down Expand Up @@ -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<flutter::EncodableMap>(arguments)) {
auto settings = std::get<flutter::EncodableMap>(arguments);
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 4 additions & 5 deletions packages/webview_flutter/tizen/src/webview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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_; }

Expand Down
2 changes: 1 addition & 1 deletion packages/webview_flutter/tizen/src/webview_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down