Skip to content

Commit 695b8b6

Browse files
committed
Add enum class State for checking TizenAutofill ready
1 parent 9f93270 commit 695b8b6

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: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,37 @@
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+
state_ = State::kNone;
2425

25-
int ret = autofill_connect(
26+
int ret = AUTOFILL_ERROR_NONE;
27+
if (!autofill_) {
28+
ret = autofill_create(&autofill_);
29+
if (ret != AUTOFILL_ERROR_NONE) {
30+
FT_LOG(Error) << "Fail to create autofill handle.";
31+
return;
32+
}
33+
}
34+
35+
ret = autofill_connect(
2636
autofill_,
2737
[](autofill_h autofill, autofill_connection_status_e status,
28-
void* user_data) {},
38+
void* user_data) { TizenAutofill::GetInstance().Connected(); },
2939
nullptr);
3040
if (ret != AUTOFILL_ERROR_NONE) {
31-
FT_LOG(Error) << "connect_autofill_daemon error";
41+
FT_LOG(Error) << "Fail to connect to the autofill daemon.";
42+
return;
3243
}
3344

34-
autofill_fill_response_set_received_cb(
45+
ret = autofill_fill_response_set_received_cb(
3546
autofill_,
3647
[](autofill_h autofill, autofill_fill_response_h fill_response,
3748
void* data) {
@@ -45,18 +56,18 @@ void TizenAutofill::InitailizeAutofill() {
4556
[](autofill_fill_response_item_h item, void* user_data) {
4657
char* id = nullptr;
4758
char* value = nullptr;
48-
char* presentation_text = nullptr;
59+
char* label = nullptr;
4960

5061
autofill_fill_response_item_get_id(item, &id);
51-
autofill_fill_response_item_get_presentation_text(
52-
item, &presentation_text);
62+
autofill_fill_response_item_get_presentation_text(item,
63+
&label);
5364
autofill_fill_response_item_get_value(item, &value);
5465

5566
std::unique_ptr<AutofillItem> response_item =
5667
std::make_unique<AutofillItem>();
57-
response_item->label_ = std::string(presentation_text);
5868
response_item->id_ = std::string(id);
5969
response_item->value_ = std::string(value);
70+
response_item->label_ = std::string(label);
6071

6172
TizenAutofill::GetInstance().StoreResponseItem(
6273
move(response_item));
@@ -69,8 +80,8 @@ void TizenAutofill::InitailizeAutofill() {
6980
free(value);
7081
}
7182

72-
if (presentation_text) {
73-
free(presentation_text);
83+
if (label) {
84+
free(label);
7485
}
7586

7687
return true;
@@ -82,12 +93,22 @@ void TizenAutofill::InitailizeAutofill() {
8293
TizenAutofill::GetInstance().OnPopup();
8394
},
8495
nullptr);
96+
if (ret != AUTOFILL_ERROR_NONE) {
97+
FT_LOG(Error) << "Fail to set fill response received callback.";
98+
return;
99+
}
85100

86101
response_items_.clear();
102+
Initialized();
87103
}
88104

89105
void TizenAutofill::RequestAutofill(std::vector<std::string> hints,
90106
std::string id) {
107+
if (state_ != State::kReady) {
108+
Initailize();
109+
return;
110+
}
111+
91112
char* app_id = nullptr;
92113
app_get_id(&app_id);
93114

@@ -115,17 +136,20 @@ void TizenAutofill::RequestAutofill(std::vector<std::string> hints,
115136

116137
int ret = autofill_fill_request(autofill_, view_info);
117138
if (ret != AUTOFILL_ERROR_NONE) {
118-
FT_LOG(Error) << "autofill_fill_request error";
139+
FT_LOG(Error) << "Fail to request autofill";
119140
}
120141
autofill_view_info_destroy(view_info);
121142

122143
response_items_.clear();
123144
}
124145

125-
void TizenAutofill::RegisterAutofillItem(std::string view_id,
126-
AutofillItem item) {
127-
autofill_save_item_h save_item = nullptr;
146+
void TizenAutofill::RegisterItem(std::string view_id, AutofillItem item) {
147+
if (state_ != State::kReady) {
148+
Initailize();
149+
return;
150+
}
128151

152+
autofill_save_item_h save_item = nullptr;
129153
autofill_save_item_create(&save_item);
130154
autofill_save_item_set_autofill_hint(save_item, item.hint_);
131155
autofill_save_item_set_id(save_item, item.id_.c_str());
@@ -137,11 +161,9 @@ void TizenAutofill::RegisterAutofillItem(std::string view_id,
137161
app_get_id(&app_id);
138162

139163
autofill_save_view_info_h save_view_info = nullptr;
140-
141164
autofill_save_view_info_create(&save_view_info);
142165
autofill_save_view_info_set_app_id(save_view_info, app_id);
143166
autofill_save_view_info_set_view_id(save_view_info, view_id.c_str());
144-
145167
autofill_save_view_info_add_item(save_view_info, save_item);
146168

147169
if (app_id) {
@@ -150,7 +172,7 @@ void TizenAutofill::RegisterAutofillItem(std::string view_id,
150172

151173
int ret = autofill_commit(autofill_, save_view_info);
152174
if (ret != AUTOFILL_ERROR_NONE) {
153-
FT_LOG(Error) << "autofill_commit error";
175+
FT_LOG(Error) << "Fail to register autofill item.";
154176
}
155177

156178
autofill_save_view_info_destroy(save_view_info);

flutter/shell/platform/tizen/tizen_autofill.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ struct AutofillItem {
2222
};
2323

2424
class TizenAutofill {
25+
enum class State : unsigned char { kNone, kInitialized, kConnected, kReady };
26+
2527
public:
2628
static TizenAutofill& GetInstance() {
2729
static TizenAutofill instance = TizenAutofill();
@@ -30,23 +32,31 @@ class TizenAutofill {
3032

3133
void RequestAutofill(std::vector<std::string> hints, std::string id);
3234

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

3537
void StoreResponseItem(std::unique_ptr<AutofillItem> item) {
3638
response_items_.push_back(move(item));
3739
}
3840

41+
void Connected() {
42+
state_ = state_ == State::kInitialized ? State::kReady : State::kConnected;
43+
};
44+
45+
void Initialized() {
46+
state_ = state_ == State::kConnected ? State::kReady : State::kInitialized;
47+
}
48+
3949
void SetOnPopup(std::function<void()> on_popup) { on_popup_ = on_popup; }
4050

41-
void SetOnCommit(std::function<void(std::string)> on_commit) {
51+
void SetOnCommit(std::function<void(const std::string&)> on_commit) {
4252
on_commit_ = on_commit;
4353
}
4454

4555
void OnCommit(std::string str) { on_commit_(str); }
4656

4757
void OnPopup() { on_popup_(); }
4858

49-
const std::vector<std::unique_ptr<AutofillItem>>& GetAutofillItems() {
59+
const std::vector<std::unique_ptr<AutofillItem>>& GetResponseItems() {
5060
return response_items_;
5161
}
5262

@@ -55,17 +65,19 @@ class TizenAutofill {
5565

5666
~TizenAutofill();
5767

58-
void InitailizeAutofill();
68+
void Initailize();
5969

6070
std::optional<autofill_hint_e> ConvertAutofillHint(std::string hint);
6171

62-
autofill_h autofill_;
72+
State state_ = State::kNone;
73+
74+
autofill_h autofill_ = nullptr;
6375

6476
std::vector<std::unique_ptr<AutofillItem>> response_items_;
6577

6678
std::function<void()> on_popup_;
6779

68-
std::function<void(std::string)> on_commit_;
80+
std::function<void(const std::string&)> on_commit_;
6981
};
7082

7183
#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)