Skip to content

Commit

Permalink
Add enum class State for checking TizenAutofill ready
Browse files Browse the repository at this point in the history
  • Loading branch information
Swanseo0 committed Feb 10, 2023
1 parent 9f93270 commit 695b8b6
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 58 deletions.
22 changes: 9 additions & 13 deletions flutter/shell/platform/tizen/nui_autofill_popup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,23 @@ bool NuiAutofillPopup::Touched(Dali::Actor actor,
std::string text =
actor.GetProperty(Dali::Actor::Property::NAME).Get<std::string>();
on_commit_(text);
Hide();
popup_.SetDisplayState(Dali::Toolkit::Popup::HIDDEN);
}
return true;
}

void NuiAutofillPopup::Hide() {
// TODO(Swanseo0) : There is a phenomenon where white traces remain for a
// while when popup disappears.
popup_.SetDisplayState(Dali::Toolkit::Popup::HIDDEN);
}

void NuiAutofillPopup::Hidden() {
// TODO(Swanseo0): There is a phenomenon where white traces remain for a
// while when popup disappears.
popup_.Unparent();
popup_.Reset();
}

void NuiAutofillPopup::OutsideTouched() {
Hide();
popup_.SetDisplayState(Dali::Toolkit::Popup::HIDDEN);
}

void NuiAutofillPopup::PrepareAutofill() {
void NuiAutofillPopup::Prepare() {
popup_ = Dali::Toolkit::Popup::New();
popup_.SetProperty(Dali::Actor::Property::NAME, "popup");
popup_.SetProperty(Dali::Actor::Property::PARENT_ORIGIN,
Expand All @@ -55,11 +51,11 @@ void NuiAutofillPopup::PrepareAutofill() {
popup_.SetProperty(Dali::Toolkit::Popup::Property::AUTO_HIDE_DELAY, 2500);
}

void NuiAutofillPopup::PopupAutofill(Dali::Actor* actor) {
void NuiAutofillPopup::Show(Dali::Actor* actor) {
const std::vector<std::unique_ptr<AutofillItem>>& items =
TizenAutofill::GetInstance().GetAutofillItems();
if (items.size() > 0) {
PrepareAutofill();
TizenAutofill::GetInstance().GetResponseItems();
if (!items.empty()) {
Prepare();
Dali::Toolkit::TableView content =
Dali::Toolkit::TableView::New(items.size(), 1);
content.SetResizePolicy(Dali::ResizePolicy::FILL_TO_PARENT,
Expand Down
21 changes: 9 additions & 12 deletions flutter/shell/platform/tizen/nui_autofill_popup.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,25 @@

namespace flutter {

using OnCommit = std::function<void(std::string str)>;
using OnRendering = std::function<void()>;

class NuiAutofillPopup : public Dali::ConnectionTracker {
public:
void Hide();

void Hidden();
void Prepare();

void OutsideTouched();
void Show(Dali::Actor* actor);

void PrepareAutofill();
void SetOnCommit(std::function<void(const std::string&)> callback) {
on_commit_ = callback;
}

void PopupAutofill(Dali::Actor* actor);
private:
void Hidden();

void SetOnCommit(OnCommit callback) { on_commit_ = callback; }
void OutsideTouched();

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

private:
Dali::Toolkit::Popup popup_;
OnCommit on_commit_;
std::function<void(const std::string&)> on_commit_;
};

} // namespace flutter
Expand Down
62 changes: 42 additions & 20 deletions flutter/shell/platform/tizen/tizen_autofill.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,37 @@
#include "flutter/shell/platform/tizen/logger.h"

TizenAutofill::TizenAutofill() {
InitailizeAutofill();
Initailize();
}

TizenAutofill::~TizenAutofill() {
autofill_fill_response_unset_received_cb(autofill_);
autofill_destroy(autofill_);
}

void TizenAutofill::InitailizeAutofill() {
autofill_create(&autofill_);
void TizenAutofill::Initailize() {
state_ = State::kNone;

int ret = autofill_connect(
int ret = AUTOFILL_ERROR_NONE;
if (!autofill_) {
ret = autofill_create(&autofill_);
if (ret != AUTOFILL_ERROR_NONE) {
FT_LOG(Error) << "Fail to create autofill handle.";
return;
}
}

ret = autofill_connect(
autofill_,
[](autofill_h autofill, autofill_connection_status_e status,
void* user_data) {},
void* user_data) { TizenAutofill::GetInstance().Connected(); },
nullptr);
if (ret != AUTOFILL_ERROR_NONE) {
FT_LOG(Error) << "connect_autofill_daemon error";
FT_LOG(Error) << "Fail to connect to the autofill daemon.";
return;
}

autofill_fill_response_set_received_cb(
ret = autofill_fill_response_set_received_cb(
autofill_,
[](autofill_h autofill, autofill_fill_response_h fill_response,
void* data) {
Expand All @@ -45,18 +56,18 @@ void TizenAutofill::InitailizeAutofill() {
[](autofill_fill_response_item_h item, void* user_data) {
char* id = nullptr;
char* value = nullptr;
char* presentation_text = nullptr;
char* label = nullptr;

autofill_fill_response_item_get_id(item, &id);
autofill_fill_response_item_get_presentation_text(
item, &presentation_text);
autofill_fill_response_item_get_presentation_text(item,
&label);
autofill_fill_response_item_get_value(item, &value);

std::unique_ptr<AutofillItem> response_item =
std::make_unique<AutofillItem>();
response_item->label_ = std::string(presentation_text);
response_item->id_ = std::string(id);
response_item->value_ = std::string(value);
response_item->label_ = std::string(label);

TizenAutofill::GetInstance().StoreResponseItem(
move(response_item));
Expand All @@ -69,8 +80,8 @@ void TizenAutofill::InitailizeAutofill() {
free(value);
}

if (presentation_text) {
free(presentation_text);
if (label) {
free(label);
}

return true;
Expand All @@ -82,12 +93,22 @@ void TizenAutofill::InitailizeAutofill() {
TizenAutofill::GetInstance().OnPopup();
},
nullptr);
if (ret != AUTOFILL_ERROR_NONE) {
FT_LOG(Error) << "Fail to set fill response received callback.";
return;
}

response_items_.clear();
Initialized();
}

void TizenAutofill::RequestAutofill(std::vector<std::string> hints,
std::string id) {
if (state_ != State::kReady) {
Initailize();
return;
}

char* app_id = nullptr;
app_get_id(&app_id);

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

int ret = autofill_fill_request(autofill_, view_info);
if (ret != AUTOFILL_ERROR_NONE) {
FT_LOG(Error) << "autofill_fill_request error";
FT_LOG(Error) << "Fail to request autofill";
}
autofill_view_info_destroy(view_info);

response_items_.clear();
}

void TizenAutofill::RegisterAutofillItem(std::string view_id,
AutofillItem item) {
autofill_save_item_h save_item = nullptr;
void TizenAutofill::RegisterItem(std::string view_id, AutofillItem item) {
if (state_ != State::kReady) {
Initailize();
return;
}

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

autofill_save_view_info_h save_view_info = nullptr;

autofill_save_view_info_create(&save_view_info);
autofill_save_view_info_set_app_id(save_view_info, app_id);
autofill_save_view_info_set_view_id(save_view_info, view_id.c_str());

autofill_save_view_info_add_item(save_view_info, save_item);

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

int ret = autofill_commit(autofill_, save_view_info);
if (ret != AUTOFILL_ERROR_NONE) {
FT_LOG(Error) << "autofill_commit error";
FT_LOG(Error) << "Fail to register autofill item.";
}

autofill_save_view_info_destroy(save_view_info);
Expand Down
24 changes: 18 additions & 6 deletions flutter/shell/platform/tizen/tizen_autofill.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ struct AutofillItem {
};

class TizenAutofill {
enum class State : unsigned char { kNone, kInitialized, kConnected, kReady };

public:
static TizenAutofill& GetInstance() {
static TizenAutofill instance = TizenAutofill();
Expand All @@ -30,23 +32,31 @@ class TizenAutofill {

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

void RegisterAutofillItem(std::string view_id, AutofillItem item);
void RegisterItem(std::string view_id, AutofillItem item);

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

void Connected() {
state_ = state_ == State::kInitialized ? State::kReady : State::kConnected;
};

void Initialized() {
state_ = state_ == State::kConnected ? State::kReady : State::kInitialized;
}

void SetOnPopup(std::function<void()> on_popup) { on_popup_ = on_popup; }

void SetOnCommit(std::function<void(std::string)> on_commit) {
void SetOnCommit(std::function<void(const std::string&)> on_commit) {
on_commit_ = on_commit;
}

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

void OnPopup() { on_popup_(); }

const std::vector<std::unique_ptr<AutofillItem>>& GetAutofillItems() {
const std::vector<std::unique_ptr<AutofillItem>>& GetResponseItems() {
return response_items_;
}

Expand All @@ -55,17 +65,19 @@ class TizenAutofill {

~TizenAutofill();

void InitailizeAutofill();
void Initailize();

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

autofill_h autofill_;
State state_ = State::kNone;

autofill_h autofill_ = nullptr;

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

std::function<void()> on_popup_;

std::function<void(std::string)> on_commit_;
std::function<void(const std::string&)> on_commit_;
};

#endif
6 changes: 3 additions & 3 deletions flutter/shell/platform/tizen/tizen_view_elementary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ void TizenViewElementary::PrepareInputMethod() {
[this](std::string str) { view_delegate_->OnCommit(str); });
#ifndef WEARABLE_PROFILE
input_method_context_->SetOnPopupAutofillContext([this]() {
if (TizenAutofill::GetInstance().GetAutofillItems().size() > 0) {
for (auto& item : TizenAutofill::GetInstance().GetAutofillItems()) {
if (!TizenAutofill::GetInstance().GetResponseItems().empty()) {
for (auto& item : TizenAutofill::GetInstance().GetResponseItems()) {
elm_ctxpopup_item_append(
ctxpopup_, item->label_.c_str(), nullptr,
[](void* data, Evas_Object* obj, void* event_info) {
Expand All @@ -389,7 +389,7 @@ void TizenViewElementary::PrepareInputMethod() {
item.get());
}
}
// TODO(Swanseo0) : Change ctxpopup's position to focused input field.
// TODO(Swanseo0): Change ctxpopup's position to focused input field.
evas_object_move(ctxpopup_, 0, 0);
evas_object_show(ctxpopup_);
});
Expand Down
2 changes: 1 addition & 1 deletion flutter/shell/platform/tizen/tizen_view_nui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void TizenViewNui::PrepareInputMethod() {
[this](std::string str) { view_delegate_->OnCommit(str); });

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

autofill_.SetOnCommit(
[this](std::string str) { view_delegate_->OnCommit(str); });
Expand Down
6 changes: 3 additions & 3 deletions flutter/shell/platform/tizen/tizen_window_elementary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ void TizenWindowElementary::PrepareInputMethod() {

#ifndef WEARABLE_PROFILE
input_method_context_->SetOnPopupAutofillContext([this]() {
if (TizenAutofill::GetInstance().GetAutofillItems().size() > 0) {
for (auto& item : TizenAutofill::GetInstance().GetAutofillItems()) {
if (!TizenAutofill::GetInstance().GetResponseItems().empty()) {
for (auto& item : TizenAutofill::GetInstance().GetResponseItems()) {
elm_ctxpopup_item_append(
ctxpopup_, item->label_.c_str(), nullptr,
[](void* data, Evas_Object* obj, void* event_info) {
Expand All @@ -468,7 +468,7 @@ void TizenWindowElementary::PrepareInputMethod() {
item.get());
}
}
// TODO(Swanseo0) : Change ctxpopup's position to focused input field.
// TODO(Swanseo0): Change ctxpopup's position to focused input field.
evas_object_move(ctxpopup_, initial_geometry_.left, initial_geometry_.top);
evas_object_show(ctxpopup_);
});
Expand Down

0 comments on commit 695b8b6

Please sign in to comment.