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_OPTION_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_OPTION_H
18 
19 #include "core/components/option/option_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 DOMOption final : public DOMNode {
28     DECLARE_ACE_TYPE(DOMOption, DOMNode);
29 
30 public:
31     DOMOption(NodeId nodeId, const std::string& nodeName);
32     ~DOMOption() override = default;
33 
GetSpecializedComponent()34     RefPtr<Component> GetSpecializedComponent() override
35     {
36         return selectOptionComponent_;
37     }
38 
39     void InitializeStyle() override;
40 
41     void PrepareSpecializedComponent() override;
42     void ResetInitializedStyle() override;
43 
44 protected:
45     bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override;
46     bool SetSpecializedStyle(const std::pair<std::string, std::string>& style) override;
47 #if defined(PREVIEW)
48     void OnSetStyleFinished() override;
49 #endif
50 
51 private:
52     RefPtr<SelectTheme> theme_;
53     RefPtr<OptionComponent> selectOptionComponent_;
54     RefPtr<TextComponent> content_;
55     RefPtr<ImageComponent> icon_;
56     // used for inspector node in PC preview
57     std::vector<std::pair<std::string, std::string>> styles_;
58     std::vector<std::pair<std::string, std::string>> attrs_;
59 };
60 
61 } // namespace OHOS::Ace::Framework
62 
63 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_OPTION_H
64