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_CORE_COMPONENTS_DECLARATION_COMMON_ATTRIBUTE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_COMMON_ATTRIBUTE_H
18 
19 #include "core/components/common/layout/constants.h"
20 #include "core/event/multimodal/voice_event.h"
21 #include "frameworks/core/components/transform/click_spring_effect.h"
22 
23 namespace OHOS::Ace {
24 
25 enum class AttributeTag {
26     COMMON_ATTR = 0,
27     COMMON_DISABLED_ATTR,
28     COMMON_FOCUSABLE_ATTR,
29     COMMON_TOUCHABLE_ATTR,
30     COMMON_DATA_ATTR,
31     COMMON_CLICK_EFFECT_ATTR,
32     COMMON_RENDER_ATTR,
33     COMMON_MULTIMODAL_ATTR,
34     SPECIALIZED_ATTR,
35     UNKNOWN,
36     DEFAULT,
37 };
38 
39 struct Attribute {
IsValidAttribute40     bool IsValid() const
41     {
42         return tag != AttributeTag::UNKNOWN;
43     }
44 
IsSharedAttribute45     bool IsShared() const
46     {
47         return isShared;
48     }
49 
50     bool isShared = true;
51     AttributeTag tag = AttributeTag::DEFAULT;
52 };
53 
54 struct CommonAttribute : Attribute {
55     std::string id;
56     std::string style;
57     std::string className;
58     std::string ref;
59     bool isRightToLeft = false;
60     TextDirection direction = TextDirection::AUTO;
61 };
62 
63 struct CommonDisabledAttribute : Attribute {
64     bool disabled = false;
65 };
66 
67 struct CommonFocusableAttribute : Attribute {
68     std::pair<bool, bool> focusable = { false, false };
69 };
70 
71 struct CommonTouchableAttribute : Attribute {
72     bool touchable = true;
73 };
74 
75 struct CommonDataAttribute : Attribute {
76     std::string data;
77 };
78 
79 struct CommonClickEffectAttribute : Attribute {
80     ClickSpringEffectType clickEffect = ClickSpringEffectType::NONE;
81 };
82 
83 struct CommonRenderAttribute : Attribute {
84     std::string forAttr;
85     std::string ifAttr;
86     std::string show;
87 };
88 
89 struct CommonMultimodalAttribute : Attribute {
90     std::string voiceLabel;
91     std::string subscriptLabel;
92     bool useSubscript = false;
93     SceneLabel scene = SceneLabel::PAGE;
94 
IsUnavailableCommonMultimodalAttribute95     bool IsUnavailable() const
96     {
97         return voiceLabel.empty() && !useSubscript;
98     }
99 };
100 
101 } // namespace OHOS::Ace
102 
103 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_COMMON_ATTRIBUTE_H
104