1 /* 2 * Copyright (c) 2021-2022 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_SELECT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_SELECT_H 18 19 #include "core/components/select/select_component.h" 20 #include "core/components/select/select_theme.h" 21 #include "core/components/theme/theme_manager.h" 22 #include "frameworks/bridge/common/dom/dom_node.h" 23 #include "frameworks/bridge/common/dom/dom_type.h" 24 25 namespace OHOS::Ace::Framework { 26 27 class DOMSelect final : public DOMNode { 28 DECLARE_ACE_TYPE(DOMSelect, DOMNode); 29 30 public: 31 DOMSelect(NodeId nodeId, const std::string& nodeName); 32 ~DOMSelect() override = default; 33 void PrepareSpecializedComponent() override; 34 GetSpecializedComponent()35 RefPtr<Component> GetSpecializedComponent() override 36 { 37 return selectComponent_; 38 } 39 40 void InitializeStyle() override; 41 42 void ResetInitializedStyle() override; 43 44 protected: 45 bool SetSpecializedStyle(const std::pair<std::string, std::string>& style) override; 46 bool AddSpecializedEvent(int32_t pageId, const std::string& event) override; 47 void OnChildNodeAdded(const RefPtr<DOMNode>& child, int32_t slot) override; 48 void OnChildNodeRemoved(const RefPtr<DOMNode>& child) override; 49 SetSpecializedAttr(const std::pair<std::string,std::string> & attr)50 bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override 51 { 52 if (attr.first == DOM_DISABLED) { 53 if (selectComponent_) { 54 selectComponent_->SetDisabled((attr.second == "true")); 55 } 56 return true; 57 } 58 return false; 59 } 60 OnSetStyleFinished()61 void OnSetStyleFinished() override 62 { 63 if (!selectComponent_) { 64 return; 65 } 66 selectComponent_->FlushRefresh(); 67 } 68 69 void UpdateBoxSize(const CalcDimension& width, const CalcDimension& height) override; 70 void UpdateBoxPadding(const Edge& padding) override; 71 void UpdateBoxBorder(const Border& border) override; 72 73 private: 74 bool IsParentNavigation() const; 75 76 EventMarker onChanged_; 77 RefPtr<SelectTheme> theme_; 78 RefPtr<SelectComponent> selectComponent_; 79 RefPtr<TextComponent> tipText_; 80 }; 81 82 } // namespace OHOS::Ace::Framework 83 84 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_SELECT_H 85