Skip to content

Commit 5aca9c2

Browse files
committed
Add initailized, connected to TizenAutofill
1 parent 9f93270 commit 5aca9c2

File tree

7 files changed

+85
-58
lines changed

7 files changed

+85
-58
lines changed

flutter/shell/platform/tizen/nui_autofill_popup.cc

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,23 @@ bool NuiAutofillPopup::Touched(Dali::Actor actor,
1919
std::string text =
2020
actor.GetProperty(Dali::Actor::Property::NAME).Get<std::string>();
2121
on_commit_(text);
22-
Hide();
22+
popup_.SetDisplayState(Dali::Toolkit::Popup::HIDDEN);
2323
}
2424
return true;
2525
}
2626

27-
void NuiAutofillPopup::Hide() {
28-
// TODO(Swanseo0) : There is a phenomenon where white traces remain for a
29-
// while when popup disappears.
30-
popup_.SetDisplayState(Dali::Toolkit::Popup::HIDDEN);
31-
}
32-
3327
void NuiAutofillPopup::Hidden() {
28+
// TODO(Swanseo0): There is a phenomenon where white traces remain for a
29+
// while when popup disappears.
3430
popup_.Unparent();
3531
popup_.Reset();
3632
}
3733

3834
void NuiAutofillPopup::OutsideTouched() {
39-
Hide();
35+
popup_.SetDisplayState(Dali::Toolkit::Popup::HIDDEN);
4036
}
4137

42-
void NuiAutofillPopup::PrepareAutofill() {
38+
void NuiAutofillPopup::Prepare() {
4339
popup_ = Dali::Toolkit::Popup::New();
4440
popup_.SetProperty(Dali::Actor::Property::NAME, "popup");
4541
popup_.SetProperty(Dali::Actor::Property::PARENT_ORIGIN,
@@ -55,11 +51,11 @@ void NuiAutofillPopup::PrepareAutofill() {
5551
popup_.SetProperty(Dali::Toolkit::Popup::Property::AUTO_HIDE_DELAY, 2500);
5652
}
5753

58-
void NuiAutofillPopup::PopupAutofill(Dali::Actor* actor) {
54+
void NuiAutofillPopup::Show(Dali::Actor* actor) {
5955
const std::vector<std::unique_ptr<AutofillItem>>& items =
60-
TizenAutofill::GetInstance().GetAutofillItems();
61-
if (items.size() > 0) {
62-
PrepareAutofill();
56+
TizenAutofill::GetInstance().GetResponseItems();
57+
if (!items.empty()) {
58+
Prepare();
6359
Dali::Toolkit::TableView content =
6460
Dali::Toolkit::TableView::New(items.size(), 1);
6561
content.SetResizePolicy(Dali::ResizePolicy::FILL_TO_PARENT,

flutter/shell/platform/tizen/nui_autofill_popup.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,25 @@
1111

1212
namespace flutter {
1313

14-
using OnCommit = std::function<void(std::string str)>;
15-
using OnRendering = std::function<void()>;
16-
1714
class NuiAutofillPopup : public Dali::ConnectionTracker {
1815
public:
19-
void Hide();
20-
21-
void Hidden();
16+
void Prepare();
2217

23-
void OutsideTouched();
18+
void Show(Dali::Actor* actor);
2419

25-
void PrepareAutofill();
20+
void SetOnCommit(std::function<void(const std::string&)> callback) {
21+
on_commit_ = callback;
22+
}
2623

27-
void PopupAutofill(Dali::Actor* actor);
24+
private:
25+
void Hidden();
2826

29-
void SetOnCommit(OnCommit callback) { on_commit_ = callback; }
27+
void OutsideTouched();
3028

3129
bool Touched(Dali::Actor actor, const Dali::TouchEvent& event);
3230

33-
private:
3431
Dali::Toolkit::Popup popup_;
35-
OnCommit on_commit_;
32+
std::function<void(const std::string&)> on_commit_;
3633
};
3734

3835
} // namespace flutter

flutter/shell/platform/tizen/tizen_autofill.cc

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,35 @@
1212
#include "flutter/shell/platform/tizen/logger.h"
1313

1414
TizenAutofill::TizenAutofill() {
15-
InitailizeAutofill();
15+
Initailize();
1616
}
1717

1818
TizenAutofill::~TizenAutofill() {
19+
autofill_fill_response_unset_received_cb(autofill_);
1920
autofill_destroy(autofill_);
2021
}
2122

22-
void TizenAutofill::InitailizeAutofill() {
23-
autofill_create(&autofill_);
23+
void TizenAutofill::Initailize() {
24+
int ret = AUTOFILL_ERROR_NONE;
25+
if (!autofill_) {
26+
ret = autofill_create(&autofill_);
27+
if (ret != AUTOFILL_ERROR_NONE) {
28+
FT_LOG(Error) << "Fail to create autofill handle.";
29+
return;
30+
}
31+
}
2432

25-
int ret = autofill_connect(
33+
ret = autofill_connect(
2634
autofill_,
2735
[](autofill_h autofill, autofill_connection_status_e status,
28-
void* user_data) {},
36+
void* user_data) { TizenAutofill::GetInstance().SetConnected(true); },
2937
nullptr);
3038
if (ret != AUTOFILL_ERROR_NONE) {
31-
FT_LOG(Error) << "connect_autofill_daemon error";
39+
FT_LOG(Error) << "Fail to connect to the autofill daemon.";
40+
return;
3241
}
3342

34-
autofill_fill_response_set_received_cb(
43+
ret = autofill_fill_response_set_received_cb(
3544
autofill_,
3645
[](autofill_h autofill, autofill_fill_response_h fill_response,
3746
void* data) {
@@ -45,18 +54,18 @@ void TizenAutofill::InitailizeAutofill() {
4554
[](autofill_fill_response_item_h item, void* user_data) {
4655
char* id = nullptr;
4756
char* value = nullptr;
48-
char* presentation_text = nullptr;
57+
char* label = nullptr;
4958

5059
autofill_fill_response_item_get_id(item, &id);
51-
autofill_fill_response_item_get_presentation_text(
52-
item, &presentation_text);
60+
autofill_fill_response_item_get_presentation_text(item,
61+
&label);
5362
autofill_fill_response_item_get_value(item, &value);
5463

5564
std::unique_ptr<AutofillItem> response_item =
5665
std::make_unique<AutofillItem>();
57-
response_item->label_ = std::string(presentation_text);
5866
response_item->id_ = std::string(id);
5967
response_item->value_ = std::string(value);
68+
response_item->label_ = std::string(label);
6069

6170
TizenAutofill::GetInstance().StoreResponseItem(
6271
move(response_item));
@@ -69,8 +78,8 @@ void TizenAutofill::InitailizeAutofill() {
6978
free(value);
7079
}
7180

72-
if (presentation_text) {
73-
free(presentation_text);
81+
if (label) {
82+
free(label);
7483
}
7584

7685
return true;
@@ -82,12 +91,26 @@ void TizenAutofill::InitailizeAutofill() {
8291
TizenAutofill::GetInstance().OnPopup();
8392
},
8493
nullptr);
94+
if (ret != AUTOFILL_ERROR_NONE) {
95+
FT_LOG(Error) << "Fail to set fill response received callback.";
96+
return;
97+
}
8598

8699
response_items_.clear();
100+
initailzed_ = true;
87101
}
88102

89103
void TizenAutofill::RequestAutofill(std::vector<std::string> hints,
90104
std::string id) {
105+
if (!initailzed_) {
106+
Initailize();
107+
return;
108+
}
109+
110+
if (!connected_) {
111+
return;
112+
}
113+
91114
char* app_id = nullptr;
92115
app_get_id(&app_id);
93116

@@ -115,17 +138,24 @@ void TizenAutofill::RequestAutofill(std::vector<std::string> hints,
115138

116139
int ret = autofill_fill_request(autofill_, view_info);
117140
if (ret != AUTOFILL_ERROR_NONE) {
118-
FT_LOG(Error) << "autofill_fill_request error";
141+
FT_LOG(Error) << "Fail to request autofill";
119142
}
120143
autofill_view_info_destroy(view_info);
121144

122145
response_items_.clear();
123146
}
124147

125-
void TizenAutofill::RegisterAutofillItem(std::string view_id,
126-
AutofillItem item) {
127-
autofill_save_item_h save_item = nullptr;
148+
void TizenAutofill::RegisterItem(std::string view_id, AutofillItem item) {
149+
if (!initailzed_) {
150+
Initailize();
151+
return;
152+
}
153+
154+
if (!connected_) {
155+
return;
156+
}
128157

158+
autofill_save_item_h save_item = nullptr;
129159
autofill_save_item_create(&save_item);
130160
autofill_save_item_set_autofill_hint(save_item, item.hint_);
131161
autofill_save_item_set_id(save_item, item.id_.c_str());
@@ -137,11 +167,9 @@ void TizenAutofill::RegisterAutofillItem(std::string view_id,
137167
app_get_id(&app_id);
138168

139169
autofill_save_view_info_h save_view_info = nullptr;
140-
141170
autofill_save_view_info_create(&save_view_info);
142171
autofill_save_view_info_set_app_id(save_view_info, app_id);
143172
autofill_save_view_info_set_view_id(save_view_info, view_id.c_str());
144-
145173
autofill_save_view_info_add_item(save_view_info, save_item);
146174

147175
if (app_id) {
@@ -150,7 +178,7 @@ void TizenAutofill::RegisterAutofillItem(std::string view_id,
150178

151179
int ret = autofill_commit(autofill_, save_view_info);
152180
if (ret != AUTOFILL_ERROR_NONE) {
153-
FT_LOG(Error) << "autofill_commit error";
181+
FT_LOG(Error) << "Fail to register autofill item.";
154182
}
155183

156184
autofill_save_view_info_destroy(save_view_info);

flutter/shell/platform/tizen/tizen_autofill.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,25 @@ class TizenAutofill {
3030

3131
void RequestAutofill(std::vector<std::string> hints, std::string id);
3232

33-
void RegisterAutofillItem(std::string view_id, AutofillItem item);
33+
void RegisterItem(std::string view_id, AutofillItem item);
3434

3535
void StoreResponseItem(std::unique_ptr<AutofillItem> item) {
3636
response_items_.push_back(move(item));
3737
}
3838

39+
void SetConnected(bool connected) { connected_ = connected; };
40+
3941
void SetOnPopup(std::function<void()> on_popup) { on_popup_ = on_popup; }
4042

41-
void SetOnCommit(std::function<void(std::string)> on_commit) {
43+
void SetOnCommit(std::function<void(const std::string&)> on_commit) {
4244
on_commit_ = on_commit;
4345
}
4446

4547
void OnCommit(std::string str) { on_commit_(str); }
4648

4749
void OnPopup() { on_popup_(); }
4850

49-
const std::vector<std::unique_ptr<AutofillItem>>& GetAutofillItems() {
51+
const std::vector<std::unique_ptr<AutofillItem>>& GetResponseItems() {
5052
return response_items_;
5153
}
5254

@@ -55,17 +57,21 @@ class TizenAutofill {
5557

5658
~TizenAutofill();
5759

58-
void InitailizeAutofill();
60+
void Initailize();
5961

6062
std::optional<autofill_hint_e> ConvertAutofillHint(std::string hint);
6163

62-
autofill_h autofill_;
64+
bool connected_ = false;
65+
66+
bool initailzed_ = false;
67+
68+
autofill_h autofill_ = nullptr;
6369

6470
std::vector<std::unique_ptr<AutofillItem>> response_items_;
6571

6672
std::function<void()> on_popup_;
6773

68-
std::function<void(std::string)> on_commit_;
74+
std::function<void(const std::string&)> on_commit_;
6975
};
7076

7177
#endif

flutter/shell/platform/tizen/tizen_view_elementary.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,8 @@ void TizenViewElementary::PrepareInputMethod() {
377377
[this](std::string str) { view_delegate_->OnCommit(str); });
378378
#ifndef WEARABLE_PROFILE
379379
input_method_context_->SetOnPopupAutofillContext([this]() {
380-
if (TizenAutofill::GetInstance().GetAutofillItems().size() > 0) {
381-
for (auto& item : TizenAutofill::GetInstance().GetAutofillItems()) {
380+
if (!TizenAutofill::GetInstance().GetResponseItems().empty()) {
381+
for (auto& item : TizenAutofill::GetInstance().GetResponseItems()) {
382382
elm_ctxpopup_item_append(
383383
ctxpopup_, item->label_.c_str(), nullptr,
384384
[](void* data, Evas_Object* obj, void* event_info) {
@@ -389,7 +389,7 @@ void TizenViewElementary::PrepareInputMethod() {
389389
item.get());
390390
}
391391
}
392-
// TODO(Swanseo0) : Change ctxpopup's position to focused input field.
392+
// TODO(Swanseo0): Change ctxpopup's position to focused input field.
393393
evas_object_move(ctxpopup_, 0, 0);
394394
evas_object_show(ctxpopup_);
395395
});

flutter/shell/platform/tizen/tizen_view_nui.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void TizenViewNui::PrepareInputMethod() {
114114
[this](std::string str) { view_delegate_->OnCommit(str); });
115115

116116
input_method_context_->SetOnPopupAutofillContext(
117-
[this]() { autofill_.PopupAutofill(image_view_); });
117+
[this]() { autofill_.Show(image_view_); });
118118

119119
autofill_.SetOnCommit(
120120
[this](std::string str) { view_delegate_->OnCommit(str); });

flutter/shell/platform/tizen/tizen_window_elementary.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,8 @@ void TizenWindowElementary::PrepareInputMethod() {
456456

457457
#ifndef WEARABLE_PROFILE
458458
input_method_context_->SetOnPopupAutofillContext([this]() {
459-
if (TizenAutofill::GetInstance().GetAutofillItems().size() > 0) {
460-
for (auto& item : TizenAutofill::GetInstance().GetAutofillItems()) {
459+
if (!TizenAutofill::GetInstance().GetResponseItems().empty()) {
460+
for (auto& item : TizenAutofill::GetInstance().GetResponseItems()) {
461461
elm_ctxpopup_item_append(
462462
ctxpopup_, item->label_.c_str(), nullptr,
463463
[](void* data, Evas_Object* obj, void* event_info) {
@@ -468,7 +468,7 @@ void TizenWindowElementary::PrepareInputMethod() {
468468
item.get());
469469
}
470470
}
471-
// TODO(Swanseo0) : Change ctxpopup's position to focused input field.
471+
// TODO(Swanseo0): Change ctxpopup's position to focused input field.
472472
evas_object_move(ctxpopup_, initial_geometry_.left, initial_geometry_.top);
473473
evas_object_show(ctxpopup_);
474474
});

0 commit comments

Comments
 (0)