Skip to content

Commit 3918e15

Browse files
authored
[webview_flutter] Apply PlatformView's Intreface (#146)
* [webview_flutter] Apply PlatformView's Intreface Signed-off-by: MuHong Byun <mh.byun@samsung.com> * Apply's review's comment Signed-off-by: MuHong Byun <mh.byun@samsung.com> * Refactor helper function for EncodableMap value Signed-off-by: MuHong Byun <mh.byun@samsung.com> * Apply PlatformView's Intreface #2 Signed-off-by: MuHong Byun <mh.byun@samsung.com>
1 parent c5d820d commit 3918e15

File tree

5 files changed

+49
-28
lines changed

5 files changed

+49
-28
lines changed

packages/webview_flutter/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@
1515
## 0.2.2
1616
* Update lightweight web engine binary & header file (6263be6c888d5cb9dcca5466dfc3941a70b424eb)
1717
* Activate resizing function
18-
* Apply embedder's texture APIs change
18+
* Apply embedder's texture APIs change
19+
20+
## 0.3.0
21+
* Apply PlatformView, PlatformViewFactory APIs change

packages/webview_flutter/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: webview_flutter_tizen
22
description: Tizen implementation of the webview plugin
33
homepage: https://github.com/flutter-tizen/plugins
4-
version: 0.2.2
4+
version: 0.3.0
55

66
environment:
77
sdk: ">=2.12.0 <3.0.0"

packages/webview_flutter/tizen/src/webview.cc

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,27 @@ int ExtractIntFromMap(const flutter::EncodableValue& arguments,
145145
}
146146
return -1;
147147
}
148-
double ExtractDoubleFromMap(const flutter::EncodableValue& arguments,
149-
const char* key) {
150-
if (std::holds_alternative<flutter::EncodableMap>(arguments)) {
151-
flutter::EncodableMap values = std::get<flutter::EncodableMap>(arguments);
152-
flutter::EncodableValue value = values[flutter::EncodableValue(key)];
153-
if (std::holds_alternative<double>(value)) return std::get<double>(value);
148+
149+
template <typename T>
150+
bool GetValueFromEncodableMap(const flutter::EncodableValue& arguments,
151+
std::string key, T* out) {
152+
if (auto pmap = std::get_if<flutter::EncodableMap>(&arguments)) {
153+
auto iter = pmap->find(flutter::EncodableValue(key));
154+
if (iter != pmap->end() && !iter->second.IsNull()) {
155+
if (auto pval = std::get_if<T>(&iter->second)) {
156+
*out = *pval;
157+
return true;
158+
}
159+
}
154160
}
155-
return -1;
161+
return false;
156162
}
157163

158164
WebView::WebView(flutter::PluginRegistrar* registrar, int viewId,
159165
flutter::TextureRegistrar* texture_registrar, double width,
160-
double height, flutter::EncodableMap& params)
161-
: PlatformView(registrar, viewId),
166+
double height, flutter::EncodableMap& params,
167+
void* platform_window)
168+
: PlatformView(registrar, viewId, platform_window),
162169
texture_registrar_(texture_registrar),
163170
webview_instance_(nullptr),
164171
width_(width),
@@ -823,9 +830,13 @@ void WebView::HandleMethodCall(
823830
LOG_DEBUG("WebView::HandleMethodCall : %s \n ", method_name.c_str());
824831

825832
if (method_name.compare("loadUrl") == 0) {
826-
std::string url = ExtractStringFromMap(arguments, "url");
827-
webview_instance_->LoadURL(url);
828-
result->Success();
833+
std::string url;
834+
if (GetValueFromEncodableMap(arguments, "viewType", &url)) {
835+
webview_instance_->LoadURL(url);
836+
result->Success();
837+
return;
838+
}
839+
result->Error("Invalid Arguments", "Invalid Arguments");
829840
} else if (method_name.compare("updateSettings") == 0) {
830841
if (std::holds_alternative<flutter::EncodableMap>(arguments)) {
831842
auto settings = std::get<flutter::EncodableMap>(arguments);
@@ -896,15 +907,23 @@ void WebView::HandleMethodCall(
896907
} else if (method_name.compare("getTitle") == 0) {
897908
result->Success(flutter::EncodableValue(webview_instance_->GetTitle()));
898909
} else if (method_name.compare("scrollTo") == 0) {
899-
int x = ExtractIntFromMap(arguments, "x");
900-
int y = ExtractIntFromMap(arguments, "y");
901-
webview_instance_->ScrollTo(x, y);
902-
result->Success();
910+
int x = 0, y = 0;
911+
if (GetValueFromEncodableMap(arguments, "x", &x) &&
912+
GetValueFromEncodableMap(arguments, "y", &y)) {
913+
webview_instance_->ScrollTo(x, y);
914+
result->Success();
915+
return;
916+
}
917+
result->Error("Invalid Arguments", "Invalid Arguments");
903918
} else if (method_name.compare("scrollBy") == 0) {
904-
int x = ExtractIntFromMap(arguments, "x");
905-
int y = ExtractIntFromMap(arguments, "y");
906-
webview_instance_->ScrollBy(x, y);
907-
result->Success();
919+
int x = 0, y = 0;
920+
if (GetValueFromEncodableMap(arguments, "x", &x) &&
921+
GetValueFromEncodableMap(arguments, "y", &y)) {
922+
webview_instance_->ScrollBy(x, y);
923+
result->Success();
924+
return;
925+
}
926+
result->Error("Invalid Arguments", "Invalid Arguments");
908927
} else if (method_name.compare("getScrollX") == 0) {
909928
result->Success(flutter::EncodableValue(webview_instance_->GetScrollX()));
910929
} else if (method_name.compare("getScrollY") == 0) {

packages/webview_flutter/tizen/src/webview.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class WebView : public PlatformView {
2727
public:
2828
WebView(flutter::PluginRegistrar* registrar, int viewId,
2929
flutter::TextureRegistrar* textureRegistrar, double width,
30-
double height, flutter::EncodableMap& params);
30+
double height, flutter::EncodableMap& params, void* platform_window);
3131
~WebView();
3232
virtual void Dispose() override;
3333
virtual void Resize(double width, double height) override;
@@ -39,11 +39,10 @@ class WebView : public PlatformView {
3939
// Key input event
4040
virtual void DispatchKeyDownEvent(Ecore_Event_Key* key) override;
4141
virtual void DispatchKeyUpEvent(Ecore_Event_Key* key) override;
42-
virtual void DispatchCompositionUpdateEvent(const char* str,
43-
int size) override;
44-
virtual void DispatchCompositionEndEvent(const char* str, int size) override;
4542

46-
virtual void SetSoftwareKeyboardContext(Ecore_IMF_Context* context) override;
43+
void DispatchCompositionUpdateEvent(const char* str, int size);
44+
void DispatchCompositionEndEvent(const char* str, int size);
45+
void SetSoftwareKeyboardContext(Ecore_IMF_Context* context);
4746

4847
LWE::WebContainer* GetWebViewInstance() { return webview_instance_; }
4948

packages/webview_flutter/tizen/src/webview_factory.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ PlatformView* WebViewFactory::Create(int viewId, double width, double height,
5151

5252
try {
5353
return new WebView(GetPluginRegistrar(), viewId, texture_registrar_, width,
54-
height, params);
54+
height, params, platform_window_);
5555
} catch (const std::invalid_argument& ex) {
5656
LOG_ERROR("[Exception] %s\n", ex.what());
5757
return nullptr;

0 commit comments

Comments
 (0)