1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_PICKER_BASE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_PICKER_BASE_H 18 19 #include "core/components/picker/picker_date_component.h" 20 #include "core/components/picker/picker_datetime_component.h" 21 #include "core/components/picker/picker_multitext_component.h" 22 #include "core/components/picker/picker_text_component.h" 23 #include "core/components/picker/picker_theme.h" 24 #include "core/components/picker/picker_time_component.h" 25 #include "core/components/picker/picker_value_component.h" 26 #include "core/components/text/text_component.h" 27 #include "core/components/theme/theme_manager.h" 28 #include "frameworks/bridge/common/dom/dom_node.h" 29 #include "frameworks/bridge/common/dom/dom_type.h" 30 31 namespace OHOS::Ace::Framework { 32 33 class DOMPickerBase : public DOMNode { 34 DECLARE_ACE_TYPE(DOMPickerBase, DOMNode); 35 36 public: 37 DOMPickerBase(NodeId nodeId, const std::string& nodeName, bool hasValue); 38 ~DOMPickerBase() override = default; 39 40 RefPtr<Component> GetSpecializedComponent() override; 41 42 void InitializeStyle() override; 43 44 void ResetInitializedStyle() override; 45 46 bool SetStart(const std::string& value); 47 bool SetEnd(const std::string& value); 48 bool SetSelected(const std::string& value); 49 bool SetHasSecond(const std::string& value); 50 bool SetRange(const std::string& value); 51 bool SetColumnCount(const std::string& value); 52 bool SetHour24(const std::string& value); 53 bool SetLunar(const std::string& value); 54 bool SetShowLunar(const std::string& value); 55 bool SetPrefix(const std::string& value); 56 bool SetSuffix(const std::string& value); 57 bool SetVibrate(const std::string& value); 58 59 protected: 60 bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override; 61 bool AddSpecializedEvent(int32_t pageId, const std::string& event) override; 62 bool SetSpecializedStyle(const std::pair<std::string, std::string>& style) override; 63 void CallSpecializedMethod(const std::string& method, const std::string& args) override; 64 void CompositeComponents() override; 65 void PrepareSpecializedComponent() override; 66 67 private: 68 void HandleClickCallback() const; 69 70 void ShowDialog() const; 71 72 bool GetPickerDate(const std::string& strDate, PickerDate& outDate) const; 73 bool GetPickerTime(const std::string& strDate, PickerTime& outTime) const; 74 bool GetPickerDateTime(const std::string& strDate, PickerDateTime& outDateTime) const; 75 76 bool CreatePicker(); 77 78 bool SetTextSelected(const std::string& value); 79 80 bool SetDateTimeSelected(const std::string& value); 81 82 bool SetOptionStyleOperators(const std::pair<std::string, std::string>& style); 83 84 bool SetTextStyleOperators(const std::pair<std::string, std::string>& style); 85 86 bool SetTextBackgroundColor(const std::pair<std::string, std::string>& style); 87 bool SetColumnHeight(const std::pair<std::string, std::string>& style); 88 89 bool hasValue_ = true; 90 // used for inspector node in PC preview 91 int32_t pickerId_ = -1; 92 std::string type_ { DOM_PICKER_TYPE_TEXT }; 93 94 std::list<std::pair<std::string, std::string>> storeAttributes_; 95 std::list<std::pair<int32_t, std::string>> storeEvents_; 96 std::list<std::pair<std::string, std::string>> storeStyles_; 97 98 RefPtr<PickerTheme> theme_; 99 RefPtr<PickerBaseComponent> basePickerChild_; 100 RefPtr<PickerValueComponent> valuePickerChild_; 101 }; 102 103 } // namespace OHOS::Ace::Framework 104 105 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_PICKER_BASE_H 106