Skip to content

Commit

Permalink
Apply reviewer's comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
Swanseo0 committed Feb 23, 2023
1 parent f37e3fd commit 9f3b843
Show file tree
Hide file tree
Showing 14 changed files with 170 additions and 128 deletions.
2 changes: 0 additions & 2 deletions flutter/shell/platform/tizen/channels/text_input_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ TextInputChannel::TextInputChannel(

#ifndef WEARABLE_PROFILE
TizenAutofill& autofill = TizenAutofill::GetInstance();
autofill.SetOnPopup(
[this]() { input_method_context_->PopupAutofillItems(); });
autofill.SetOnCommit([this](std::string value) { OnCommit(value); });
#endif
}
Expand Down
60 changes: 33 additions & 27 deletions flutter/shell/platform/tizen/nui_autofill_popup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
#include "flutter/shell/platform/tizen/nui_autofill_popup.h"

#include <dali-toolkit/dali-toolkit.h>
#include <dali-toolkit/devel-api/controls/table-view/table-view.h>
#include <dali-toolkit/public-api/controls/text-controls/text-label.h>

#include "flutter/shell/platform/tizen/tizen_autofill.h"

namespace flutter {

bool NuiAutofillPopup::Touched(Dali::Actor actor,
Expand All @@ -35,7 +32,32 @@ void NuiAutofillPopup::OutsideTouched() {
popup_.SetDisplayState(Dali::Toolkit::Popup::HIDDEN);
}

void NuiAutofillPopup::Prepare() {
Dali::Toolkit::TableView NuiAutofillPopup::MakeContent(
const std::vector<std::unique_ptr<AutofillItem>>& items) {
Dali::Toolkit::TableView content =
Dali::Toolkit::TableView::New(items.size(), 1);
content.SetResizePolicy(Dali::ResizePolicy::FILL_TO_PARENT,
Dali::Dimension::ALL_DIMENSIONS);
content.SetProperty(Dali::Actor::Property::PADDING,
Dali::Vector4(10, 10, 0, 0));
for (uint32_t i = 0; i < items.size(); ++i) {
Dali::Toolkit::TextLabel label =
Dali::Toolkit::TextLabel::New(items[i]->label);
label.SetProperty(Dali::Actor::Property::NAME, items[i]->value);
label.SetResizePolicy(Dali::ResizePolicy::DIMENSION_DEPENDENCY,
Dali::Dimension::HEIGHT);
label.SetProperty(Dali::Toolkit::TextLabel::Property::TEXT_COLOR,
Dali::Color::WHITE_SMOKE);
label.SetProperty(Dali::Toolkit::TextLabel::Property::POINT_SIZE, 7.0f);
label.TouchedSignal().Connect(this, &NuiAutofillPopup::Touched);
content.AddChild(label, Dali::Toolkit::TableView::CellPosition(i, 0));
content.SetFitHeight(i);
}
return content;
}

void NuiAutofillPopup::Prepare(
const std::vector<std::unique_ptr<AutofillItem>>& items) {
popup_ = Dali::Toolkit::Popup::New();
popup_.SetProperty(Dali::Actor::Property::NAME, "popup");
popup_.SetProperty(Dali::Actor::Property::PARENT_ORIGIN,
Expand All @@ -49,6 +71,11 @@ void NuiAutofillPopup::Prepare() {
popup_.HiddenSignal().Connect(this, &NuiAutofillPopup::Hidden);
popup_.SetProperty(Dali::Toolkit::Popup::Property::BACKING_ENABLED, false);
popup_.SetProperty(Dali::Toolkit::Popup::Property::AUTO_HIDE_DELAY, 2500);
popup_.SetProperty(Dali::Actor::Property::SIZE,
Dali::Vector2(140.0f, 35.0f * items.size()));

Dali::Toolkit::TableView content = MakeContent(items);
popup_.SetContent(content);
}

void NuiAutofillPopup::Show(Dali::Actor* actor) {
Expand All @@ -58,29 +85,8 @@ void NuiAutofillPopup::Show(Dali::Actor* actor) {
return;
}

Prepare();
Dali::Toolkit::TableView content =
Dali::Toolkit::TableView::New(items.size(), 1);
content.SetResizePolicy(Dali::ResizePolicy::FILL_TO_PARENT,
Dali::Dimension::ALL_DIMENSIONS);
content.SetProperty(Dali::Actor::Property::PADDING,
Dali::Vector4(10, 10, 0, 0));
for (uint32_t i = 0; i < items.size(); ++i) {
Dali::Toolkit::TextLabel label =
Dali::Toolkit::TextLabel::New(items[i]->label_);
label.SetProperty(Dali::Actor::Property::NAME, items[i]->value_);
label.SetResizePolicy(Dali::ResizePolicy::DIMENSION_DEPENDENCY,
Dali::Dimension::HEIGHT);
label.SetProperty(Dali::Toolkit::TextLabel::Property::TEXT_COLOR,
Dali::Color::WHITE_SMOKE);
label.SetProperty(Dali::Toolkit::TextLabel::Property::POINT_SIZE, 7.0f);
label.TouchedSignal().Connect(this, &NuiAutofillPopup::Touched);
content.AddChild(label, Dali::Toolkit::TableView::CellPosition(i, 0));
content.SetFitHeight(i);
}
popup_.SetProperty(Dali::Actor::Property::SIZE,
Dali::Vector2(140.0f, 35.0f * items.size()));
popup_.SetContent(content);
Prepare(items);

popup_.SetDisplayState(Dali::Toolkit::Popup::SHOWN);
actor->Add(popup_);
}
Expand Down
18 changes: 12 additions & 6 deletions flutter/shell/platform/tizen/nui_autofill_popup.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,38 @@
#define EMBEDDER_NUI_AUTOFILL_POPUP_H_

#include <dali-toolkit/devel-api/controls/popup/popup.h>
#include <dali-toolkit/devel-api/controls/table-view/table-view.h>

#include <functional>

#include "flutter/shell/platform/tizen/tizen_autofill.h"

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

namespace flutter {

class NuiAutofillPopup : public Dali::ConnectionTracker {
public:
void Show(Dali::Actor* actor);

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

private:
void Prepare();
void Prepare(const std::vector<std::unique_ptr<AutofillItem>>& items);

void Hidden();

void OutsideTouched();

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

Dali::Toolkit::TableView MakeContent(
const std::vector<std::unique_ptr<AutofillItem>>& items);

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

} // namespace flutter

#endif
#endif // EMBEDDER_NUI_AUTOFILL_POPUP_H_
52 changes: 29 additions & 23 deletions flutter/shell/platform/tizen/tizen_autofill.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ std::optional<autofill_hint_e> ConvertAutofillHint(std::string hint) {
return std::nullopt;
}

bool StoreFillResponseItem(autofill_fill_response_item_h item, void* data) {
bool StoreFillResponseItem(autofill_fill_response_item_h item,
void* user_data) {
char* id = nullptr;
char* value = nullptr;
char* label = nullptr;
Expand All @@ -55,12 +56,12 @@ bool StoreFillResponseItem(autofill_fill_response_item_h item, void* data) {
autofill_fill_response_item_get_value(item, &value);
std::unique_ptr<AutofillItem> response_item =
std::make_unique<AutofillItem>();
response_item->id_ = std::string(id);
response_item->value_ = std::string(value);
response_item->label_ = std::string(label);
response_item->id = std::string(id);
response_item->value = std::string(value);
response_item->label = std::string(label);

TizenAutofill* tizen_autofill = static_cast<TizenAutofill*>(data);
tizen_autofill->StoreResponseItem(move(response_item));
TizenAutofill* self = static_cast<TizenAutofill*>(user_data);
self->StoreResponseItem(std::move(response_item));
if (id) {
free(id);
}
Expand All @@ -75,17 +76,19 @@ bool StoreFillResponseItem(autofill_fill_response_item_h item, void* data) {
return true;
}

bool StoreForeachItem(autofill_fill_response_group_h group, void* data) {
autofill_fill_response_group_foreach_item(group, StoreFillResponseItem, data);
bool StoreForeachItem(autofill_fill_response_group_h group, void* user_data) {
autofill_fill_response_group_foreach_item(group, StoreFillResponseItem,
user_data);
return true;
};

void ResponseReceived(autofill_h autofill,
autofill_fill_response_h fill_response,
void* data) {
autofill_fill_response_foreach_group(fill_response, StoreForeachItem, data);
TizenAutofill* tizen_autofill = static_cast<TizenAutofill*>(data);
tizen_autofill->OnPopup();
void* user_data) {
autofill_fill_response_foreach_group(fill_response, StoreForeachItem,
user_data);
TizenAutofill* self = static_cast<TizenAutofill*>(user_data);
self->OnPopup();
};

autofill_save_item_h CreateSaveItem(const AutofillItem& item) {
Expand All @@ -96,11 +99,11 @@ autofill_save_item_h CreateSaveItem(const AutofillItem& item) {
return nullptr;
}

autofill_save_item_set_autofill_hint(save_item, item.hint_);
autofill_save_item_set_id(save_item, item.id_.c_str());
autofill_save_item_set_label(save_item, item.label_.c_str());
autofill_save_item_set_sensitive_data(save_item, item.sensitive_data_);
autofill_save_item_set_value(save_item, item.value_.c_str());
autofill_save_item_set_autofill_hint(save_item, item.hint);
autofill_save_item_set_id(save_item, item.id.c_str());
autofill_save_item_set_label(save_item, item.label.c_str());
autofill_save_item_set_sensitive_data(save_item, item.sensitive_data);
autofill_save_item_set_value(save_item, item.value.c_str());

return save_item;
}
Expand Down Expand Up @@ -132,8 +135,8 @@ autofill_save_view_info_h CreateSaveViewInfo(const std::string& view_id,
return save_view_info;
}

void AddItemsToViewInfo(const autofill_view_info_h& view_info,
const std::string id,
void AddItemsToViewInfo(autofill_view_info_h view_info,
const std::string& id,
const std::vector<std::string>& hints) {
for (auto hint : hints) {
std::optional<autofill_hint_e> autofill_hint = ConvertAutofillHint(hint);
Expand Down Expand Up @@ -199,17 +202,20 @@ void TizenAutofill::Initialize() {

ret = autofill_connect(
autofill_,
[](autofill_h autofill, autofill_connection_status_e status, void* data) {
TizenAutofill* tizen_autofill = static_cast<TizenAutofill*>(data);
[](autofill_h autofill, autofill_connection_status_e status,
void* user_data) {
TizenAutofill* self = static_cast<TizenAutofill*>(user_data);
if (status == AUTOFILL_CONNECTION_STATUS_CONNECTED) {
tizen_autofill->SetConnected(true);
self->SetConnected(true);
} else {
tizen_autofill->SetConnected(false);
self->SetConnected(false);
}
},
this);
if (ret != AUTOFILL_ERROR_NONE) {
FT_LOG(Error) << "Failed to connect to the autofill daemon.";
autofill_destroy(autofill_);
autofill_ = nullptr;
return;
}

Expand Down
18 changes: 11 additions & 7 deletions flutter/shell/platform/tizen/tizen_autofill.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
namespace flutter {

struct AutofillItem {
autofill_hint_e hint_;
bool sensitive_data_;
std::string label_;
std::string id_;
std::string value_;
autofill_hint_e hint;
bool sensitive_data;
std::string label;
std::string id;
std::string value;
};

class TizenAutofill {
Expand All @@ -36,7 +36,7 @@ class TizenAutofill {
void RegisterItem(const std::string& view_id, const AutofillItem& item);

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

void SetConnected(bool connected) { is_connected_ = connected; };
Expand All @@ -49,7 +49,11 @@ class TizenAutofill {

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

void OnPopup() { on_popup_(); }
void OnPopup() {
if (on_popup_) {
on_popup_();
}
}

const std::vector<std::unique_ptr<AutofillItem>>& GetResponseItems() {
return response_items_;
Expand Down
6 changes: 2 additions & 4 deletions flutter/shell/platform/tizen/tizen_input_method_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ void TizenInputMethodContext::SetInputAction(const std::string& input_action) {
Ecore_IMF_Input_Panel_Return_Key_Type return_key_type =
ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT;

// Not support : none, previous, continueAction, route, emergencycall, newline
// Not supported : none, previous, continueAction, route, emergencyCall,
// newline
if (input_action == "TextInputAction.unspecified") {
return_key_type = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT;
} else if (input_action == "TextInputAction.done") {
Expand Down Expand Up @@ -423,15 +424,12 @@ void TizenInputMethodContext::SetContextOptions() {
FT_ASSERT(imf_context_);
ecore_imf_context_autocapital_type_set(imf_context_,
ECORE_IMF_AUTOCAPITAL_TYPE_NONE);
ecore_imf_context_prediction_allow_set(imf_context_, EINA_FALSE);
}

void TizenInputMethodContext::SetInputPanelOptions() {
FT_ASSERT(imf_context_);
ecore_imf_context_input_panel_layout_set(imf_context_,
ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL);
ecore_imf_context_input_panel_return_key_type_set(
imf_context_, ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT);
ecore_imf_context_input_panel_language_set(
imf_context_, ECORE_IMF_INPUT_PANEL_LANG_AUTOMATIC);
}
Expand Down
15 changes: 3 additions & 12 deletions flutter/shell/platform/tizen/tizen_input_method_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

namespace flutter {

using OnCommit = std::function<void(std::string str)>;
using OnPreeditChanged = std::function<void(std::string str, int cursor_pos)>;
using OnCommit = std::function<void(const std::string& str)>;
using OnPreeditChanged =
std::function<void(const std::string& str, int cursor_pos)>;
using OnPreeditStart = std::function<void()>;
using OnPreeditEnd = std::function<void()>;
using OnPopupAutofillContext = std::function<void()>;
Expand Down Expand Up @@ -82,16 +83,6 @@ class TizenInputMethodContext {

void SetOnPreeditEnd(OnPreeditEnd callback) { on_preedit_end_ = callback; }

void SetOnPopupAutofillContext(OnPopupAutofillContext callback) {
on_popup_autofill_context_ = callback;
}

void PopupAutofillItems() {
if (on_popup_autofill_context_) {
on_popup_autofill_context_();
}
}

private:
void RegisterEventCallbacks();
void UnregisterEventCallbacks();
Expand Down
Loading

0 comments on commit 9f3b843

Please sign in to comment.