|
| 1 | +#include "flutter/shell/platform/tizen/nui_autofill_popup.h" |
| 2 | + |
| 3 | +#include <dali-toolkit/dali-toolkit.h> |
| 4 | +#include <dali-toolkit/devel-api/controls/table-view/table-view.h> |
| 5 | +#include <dali-toolkit/public-api/controls/text-controls/text-label.h> |
| 6 | + |
| 7 | +#include "flutter/shell/platform/tizen/tizen_autofill.h" |
| 8 | + |
| 9 | +#include "flutter/shell/platform/tizen/logger.h" |
| 10 | + |
| 11 | +namespace flutter { |
| 12 | +bool NuiAutofillPopup::OnTouch(Dali::Actor actor, |
| 13 | + const Dali::TouchEvent& event) { |
| 14 | + const Dali::PointState::Type state = event.GetState(0); |
| 15 | + if (Dali::PointState::DOWN == state) { |
| 16 | + auto t = actor.GetProperty(Dali::Actor::Property::NAME).Get<std::string>(); |
| 17 | + on_commit_(t); |
| 18 | + OnHide(); |
| 19 | + } |
| 20 | + return true; |
| 21 | +} |
| 22 | + |
| 23 | +void NuiAutofillPopup::OnHide() { |
| 24 | + // TODO : There is a phenomenon where white traces remain for a while when |
| 25 | + // popup disappears. |
| 26 | + popup_.SetDisplayState(Dali::Toolkit::Popup::HIDDEN); |
| 27 | +} |
| 28 | + |
| 29 | +void NuiAutofillPopup::OnHidden() { |
| 30 | + popup_.Unparent(); |
| 31 | + popup_.Reset(); |
| 32 | +} |
| 33 | + |
| 34 | +void NuiAutofillPopup::PrepareAutofill() { |
| 35 | + popup_ = Dali::Toolkit::Popup::New(); |
| 36 | + popup_.SetProperty(Dali::Actor::Property::NAME, "popup"); |
| 37 | + popup_.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, |
| 38 | + Dali::ParentOrigin::TOP_LEFT); |
| 39 | + popup_.SetProperty(Dali::Actor::Property::ANCHOR_POINT, |
| 40 | + Dali::AnchorPoint::TOP_LEFT); |
| 41 | + popup_.SetProperty(Dali::Toolkit::Popup::Property::TAIL_VISIBILITY, false); |
| 42 | + popup_.SetBackgroundColor(Dali::Color::WHITE_SMOKE); |
| 43 | + popup_.OutsideTouchedSignal().Connect(this, &NuiAutofillPopup::OnHide); |
| 44 | + popup_.HiddenSignal().Connect(this, &NuiAutofillPopup::OnHidden); |
| 45 | + popup_.SetProperty(Dali::Toolkit::Popup::Property::BACKING_ENABLED, false); |
| 46 | + popup_.SetProperty(Dali::Toolkit::Popup::Property::AUTO_HIDE_DELAY, 2500); |
| 47 | +} |
| 48 | + |
| 49 | +void NuiAutofillPopup::PopupAutofill(Dali::Actor* actor) { |
| 50 | + const auto& items = TizenAutofill::GetInstance().GetAutofillItems(); |
| 51 | + if (items.size() > 0) { |
| 52 | + PrepareAutofill(); |
| 53 | + Dali::Toolkit::TableView content = |
| 54 | + Dali::Toolkit::TableView::New(items.size(), 1); |
| 55 | + // content.SetCellPadding(Dali::Size(10.0f, 0)); |
| 56 | + content.SetResizePolicy(Dali::ResizePolicy::FILL_TO_PARENT, |
| 57 | + Dali::Dimension::ALL_DIMENSIONS); |
| 58 | + content.SetProperty(Dali::Actor::Property::PADDING, |
| 59 | + Dali::Vector4(10, 10, 0, 0)); |
| 60 | + for (uint32_t i = 0; i < items.size(); ++i) { |
| 61 | + auto label = Dali::Toolkit::TextLabel::New(items[i]->label_); |
| 62 | + label.SetProperty(Dali::Actor::Property::NAME, items[i]->value_); |
| 63 | + label.SetResizePolicy(Dali::ResizePolicy::DIMENSION_DEPENDENCY, |
| 64 | + Dali::Dimension::HEIGHT); |
| 65 | + label.SetProperty(Dali::Toolkit::TextLabel::Property::TEXT_COLOR, |
| 66 | + Dali::Color::WHITE_SMOKE); |
| 67 | + label.SetProperty(Dali::Toolkit::TextLabel::Property::POINT_SIZE, 7.0f); |
| 68 | + label.TouchedSignal().Connect(this, &NuiAutofillPopup::OnTouch); |
| 69 | + content.AddChild(label, Dali::Toolkit::TableView::CellPosition(i, 0)); |
| 70 | + content.SetFitHeight(i); |
| 71 | + } |
| 72 | + popup_.SetProperty(Dali::Actor::Property::SIZE, |
| 73 | + Dali::Vector2(140.0f, 35.0f * items.size())); |
| 74 | + popup_.SetContent(content); |
| 75 | + popup_.SetDisplayState(Dali::Toolkit::Popup::SHOWN); |
| 76 | + actor->Add(popup_); |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +} // namespace flutter |
0 commit comments